package com.hfkj.service.impl;

import com.hfkj.dao.BsStoreRegionMapper;
import com.hfkj.entity.BsStoreRegion;
import com.hfkj.entity.BsStoreRegionExample;
import com.hfkj.service.BsStoreRegionService;
import org.springframework.stereotype.Service;

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

@Service("storeRegionService")
public class BsStoreRegionServiceImpl implements BsStoreRegionService {

    @Resource
    private BsStoreRegionMapper storeRegionMapper;

    @Override
    public void editStoreRegion(BsStoreRegion storeRegion) {
        if (storeRegion.getId() == null) {
            storeRegion.setStatus(1);
            storeRegion.setCreateTime(new Date());
            storeRegion.setUpdateTime(new Date());
            storeRegionMapper.insert(storeRegion);
        } else {
            storeRegion.setUpdateTime(new Date());
            storeRegionMapper.updateByPrimaryKey(storeRegion);
        }
    }

    @Override
    public BsStoreRegion getRegionByStoreId(Long storeId) {
        BsStoreRegionExample example = new BsStoreRegionExample();
        example.createCriteria().andStoreIdEqualTo(storeId).andStatusEqualTo(1);
        List<BsStoreRegion> list = storeRegionMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
