package com.hai.service.impl;

import com.hai.dao.HighGasOilGunNoMapper;
import com.hai.entity.HighGasOilGunNo;
import com.hai.entity.HighGasOilGunNoExample;
import com.hai.service.HighGasOilGunNoService;
import org.springframework.stereotype.Service;

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

@Service("gasOilGunNoService")
public class HighGasOilGunNoServiceImpl implements HighGasOilGunNoService {

    @Resource
    private HighGasOilGunNoMapper gasOilGunNoMapper;

    @Override
    public void editGunNo(HighGasOilGunNo gasOilGunNo) {
        if (gasOilGunNo.getId() == null) {
            gasOilGunNo.setCreateTime(new Date());
            gasOilGunNo.setStatus(1);
            gasOilGunNoMapper.insert(gasOilGunNo);
        } else {
            gasOilGunNoMapper.updateByPrimaryKey(gasOilGunNo);
        }
    }

    @Override
    public HighGasOilGunNo getGunNoById(Long id) {
        return gasOilGunNoMapper.selectByPrimaryKey(id);
    }

    @Override
    public HighGasOilGunNo getDetailByStoreAndGunNo(Long storeId, Integer gunNo) {
        HighGasOilGunNoExample example = new HighGasOilGunNoExample();
        example.createCriteria().andStoreIdEqualTo(storeId).andGunNoEqualTo(gunNo).andStatusEqualTo(1);
        List<HighGasOilGunNo> list = gasOilGunNoMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<HighGasOilGunNo> getGunNoListByOilPrice(Long oilPriceId) {
        HighGasOilGunNoExample example = new HighGasOilGunNoExample();
        example.createCriteria().andGasOilPriceIdEqualTo(oilPriceId).andStatusNotEqualTo(0);;
        return gasOilGunNoMapper.selectByExample(example);
    }

    @Override
    public List<HighGasOilGunNo> getGunNoListByStoreId(Long storeId) {
        HighGasOilGunNoExample example = new HighGasOilGunNoExample();
        example.createCriteria().andStoreIdEqualTo(storeId).andStatusNotEqualTo(0);
        return gasOilGunNoMapper.selectByExample(example);
    }
}
