package com.hfkj.service.impl;

import com.hfkj.dao.BsStoreIndustryMapper;
import com.hfkj.entity.BsStoreIndustry;
import com.hfkj.entity.BsStoreIndustryExample;
import com.hfkj.service.BsStoreIndustryService;
import com.hfkj.sysenum.StoreStatusEnum;
import org.springframework.stereotype.Service;

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

@Service("storeIndustryService")
public class BsStoreIndustryServiceImpl implements BsStoreIndustryService {

    @Resource
    private BsStoreIndustryMapper storeIndustryMapper;

    @Override
    public void editStoreIndustry(BsStoreIndustry storeIndustry) {
        if (storeIndustry != null) {
            storeIndustry.setCreateTime(new Date());
            storeIndustry.setUpdateTime(new Date());
            storeIndustry.setStatus(StoreStatusEnum.status1.getNumber());
            storeIndustryMapper.insert(storeIndustry);
        } else {
            storeIndustry.setUpdateTime(new Date());
            storeIndustryMapper.updateByPrimaryKey(storeIndustry);
        }
    }

    @Override
    public BsStoreIndustry getIndustryByStoreId(Long storeId) {
        BsStoreIndustryExample example = new BsStoreIndustryExample();
        example.createCriteria().andStoreIdEqualTo(storeId).andStatusEqualTo(1);
        List<BsStoreIndustry> list = storeIndustryMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
