package com.hfkj.service.impl;

import com.hfkj.dao.BsMerRegionMapper;
import com.hfkj.entity.BsMerRegion;
import com.hfkj.entity.BsMerRegionExample;
import com.hfkj.service.BsMerRegionService;
import org.springframework.stereotype.Service;

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

@Service("merRegionService")
public class BsMerRegionServiceImpl implements BsMerRegionService {

    @Resource
    private BsMerRegionMapper merRegionMapper;

    @Override
    public void editMerRegion(BsMerRegion merRegion) {
        if (merRegion.getId() == null) {
            merRegion.setStatus(1);
            merRegion.setCreateTime(new Date());
            merRegion.setUpdateTime(new Date());
            merRegionMapper.insert(merRegion);
        } else {
            merRegion.setUpdateTime(new Date());
            merRegionMapper.updateByPrimaryKey(merRegion);
        }
    }

    @Override
    public BsMerRegion getMerRegionByMerId(Long merId) {
        BsMerRegionExample example = new BsMerRegionExample();
        example.createCriteria().andMerIdEqualTo(merId).andStatusEqualTo(1);
        List<BsMerRegion> list = merRegionMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
