package com.hfkj.service.impl;

import com.hfkj.dao.BsMerIndustryMapper;
import com.hfkj.entity.BsIndustry;
import com.hfkj.entity.BsIndustryExample;
import com.hfkj.entity.BsMerIndustry;
import com.hfkj.entity.BsMerIndustryExample;
import com.hfkj.service.BsMerIndustryService;
import org.springframework.stereotype.Service;

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

@Service("merIndustryService")
public class BsMerIndustryServiceImpl implements BsMerIndustryService {

    @Resource
    private BsMerIndustryMapper merIndustryMapper;

    @Override
    public void editMerIndustry(BsMerIndustry merIndustry) {
        if (merIndustry.getId() == null) {
            merIndustry.setStatus(1);
            merIndustry.setCreateTime(new Date());
            merIndustry.setUpdateTime(new Date());
            merIndustryMapper.insert(merIndustry);
        } else {
            merIndustry.setUpdateTime(new Date());
            merIndustryMapper.updateByPrimaryKey(merIndustry);
        }
    }

    @Override
    public BsMerIndustry getMerIndustryById(Long id) {
        return merIndustryMapper.selectByPrimaryKey(id);
    }

    @Override
    public BsMerIndustry getMerIndustryByMerId(Long merId) {
        BsMerIndustryExample example = new BsMerIndustryExample();
        example.createCriteria().andMerIdEqualTo(merId).andStatusEqualTo(1);
        List<BsMerIndustry> list = merIndustryMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
