package com.hfkj.service.impl;

import com.hfkj.dao.BsMerRateMapper;
import com.hfkj.entity.BsMerRate;
import com.hfkj.entity.BsMerRateExample;
import com.hfkj.service.BsMerRateService;
import org.springframework.stereotype.Service;

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

/**
 * @author hurui
 */
@Service("merRateService")
public class BsMerRateServiceImpl implements BsMerRateService {

    @Resource
    private BsMerRateMapper merRateMapper;

    @Override
    public void editMerRate(BsMerRate merRate) {
        if (merRate.getId() == null) {
            merRate.setStatus(1);
            merRate.setCreateTime(new Date());
            merRate.setUpdateTime(new Date());
            merRateMapper.insert(merRate);
        } else {
            merRate.setUpdateTime(new Date());
            merRateMapper.updateByPrimaryKey(merRate);
        }
    }

    @Override
    public BsMerRate getDetail(Long merId, Integer rateTypeCode) {
        BsMerRateExample example = new BsMerRateExample();
        example.createCriteria().andMerIdEqualTo(merId).andRateTypeCodeEqualTo(rateTypeCode).andStatusEqualTo(1);
        List<BsMerRate> list = merRateMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<BsMerRate> getRateListByMerId(Long merId) {
        BsMerRateExample example = new BsMerRateExample();
        example.createCriteria().andMerIdEqualTo(merId).andStatusEqualTo(1);
        return merRateMapper.selectByExample(example);
    }
}
