package com.hfkj.service.impl;

import com.hfkj.dao.BsMerPlatformNoRateMapper;
import com.hfkj.entity.BsMerPlatformNoRate;
import com.hfkj.entity.BsMerPlatformNoRateExample;
import com.hfkj.service.BsMerPlatformNoRateService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author hurui
 */
@Service("merPlatformNoRateService")
public class BsMerPlatformNoRateServiceImpl implements BsMerPlatformNoRateService {

    @Resource
    private BsMerPlatformNoRateMapper merPlatformNoRateMapper;

    @Override
    public void editRate(BsMerPlatformNoRate merPlatformNoRate) {
        if (merPlatformNoRate.getId() == null) {
            merPlatformNoRate.setStatus(1);
            merPlatformNoRate.setCreateTime(new Date());
            merPlatformNoRate.setUpdateTime(new Date());
            merPlatformNoRateMapper.insert(merPlatformNoRate);
        } else {
            merPlatformNoRate.setUpdateTime(new Date());
            merPlatformNoRateMapper.updateByPrimaryKey(merPlatformNoRate);
        }
    }

    @Override
    public BsMerPlatformNoRate getDetail(Long merId, Integer platformType, Integer rateTypeCode) {
        BsMerPlatformNoRateExample example = new BsMerPlatformNoRateExample();
        BsMerPlatformNoRateExample.Criteria criteria = example.createCriteria()
                .andMerIdEqualTo(merId)
                .andPlatformTypeEqualTo(platformType)
                .andStatusEqualTo(1);

        if (rateTypeCode != null) {
            criteria.andRateTypeCodeEqualTo(rateTypeCode);
        }

        List<BsMerPlatformNoRate> list = merPlatformNoRateMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<BsMerPlatformNoRate> getMerPlatformNoRateList(Long merId, Integer platformType) {
        BsMerPlatformNoRateExample example = new BsMerPlatformNoRateExample();
        example.createCriteria().andStatusEqualTo(1).andMerIdEqualTo(merId).andPlatformTypeEqualTo(platformType);
        return merPlatformNoRateMapper.selectByExample(example);
    }
}
