package com.hai.service.impl;

import com.hai.dao.HighGasOilPriceMapper;
import com.hai.entity.HighGasOilPrice;
import com.hai.entity.HighGasOilPriceExample;
import com.hai.enum_type.GasOilPriceStatusEnum;
import com.hai.service.HighGasOilPriceService;
import org.springframework.stereotype.Service;

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

@Service("highGasOilPriceService")
public class HighGasOilPriceServiceImpl implements HighGasOilPriceService {

    @Resource
    private HighGasOilPriceMapper highGasOilPriceMapper;

    @Override
    public void editGasOilPrice(HighGasOilPrice highGasOilPrice) {
        if (highGasOilPrice.getId() != null) {
            highGasOilPriceMapper.updateByPrimaryKey(highGasOilPrice);
        } else {
            highGasOilPrice.setStatus(GasOilPriceStatusEnum.status1.getStatus());
            highGasOilPriceMapper.insert(highGasOilPrice);
        }
    }

    @Override
    public HighGasOilPrice getGasOilPriceById(Long id) {
        return highGasOilPriceMapper.selectByPrimaryKey(id);
    }

    @Override
    public HighGasOilPrice getGasOilPriceByStoreAndOilNo(Long storeId, Integer oilNo) {
        HighGasOilPriceExample example = new HighGasOilPriceExample();
        example.createCriteria().andMerchantStoreIdEqualTo(storeId).andOilNoEqualTo(oilNo).andStatusNotEqualTo(0);
        List<HighGasOilPrice> list = highGasOilPriceMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<HighGasOilPrice> getGasOilPriceByStore(Long storeId) {
        HighGasOilPriceExample example = new HighGasOilPriceExample();
        example.createCriteria().andMerchantStoreIdEqualTo(storeId).andStatusNotEqualTo(0);
        return highGasOilPriceMapper.selectByExample(example);
    }

    @Override
    public List<HighGasOilPrice> getPriceListByRegionAndOilNo(Long regionId, Integer oilNo) {
        return highGasOilPriceMapper.selectPriceListByRegionAndOilNo(regionId,oilNo);
    }

    @Override
    public List<Map<String,Object>> getStoreListByOilNo(String storeName,Long regionId, String oilNoName) {
        return highGasOilPriceMapper.selectStoreListByOilNo(storeName,regionId,oilNoName);
    }

    @Override
    public Map<String, Object> recentGasStation(String longitude, String latitude) {
        return highGasOilPriceMapper.recentGasStation(longitude, latitude);
    }


}
