package com.gyee.frame.service.health;

import com.gyee.frame.common.exception.QiNiuException;
import com.gyee.frame.common.exception.enums.QiNiuErrorEnum;
import com.gyee.frame.mapper.auto.MetricsCodeMapper;
import com.gyee.frame.mapper.auto.MetricsUniformCodeMapper;
import com.gyee.frame.model.auto.MetricsCode;
import com.gyee.frame.model.auto.MetricsUniformCode;
import com.gyee.frame.model.auto.MetricsUniformCodeExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class MetricsUniformCodeService {

    @Resource
    private MetricsUniformCodeMapper uniformCodeMapper;
    @Autowired
    private MetricsCodeMapper codeMapper;


    /**
     * 使用场站、统一编码查询
     * @param station   场站
     * @param uniformCode 统一编码
     * @return
     */
    public List<MetricsUniformCode> getListByStationAndUniforCode(String station, String uniformCode){
        MetricsUniformCodeExample example = new MetricsUniformCodeExample();

        List<MetricsUniformCode> list;
        try{
            example.createCriteria().andStationidEqualTo(station)
                    .andUniformcodeEqualTo(uniformCode);

            list = uniformCodeMapper.selectByExample(example);

        }catch (Exception e){
            throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
        }

        return list;
    }
    public MetricsCode getListName(String station, String uniformCode){
        MetricsCode mc;
            try{
                mc = codeMapper.selectName(station,uniformCode);
                if(mc!=null){
                    return mc;
                }
            }catch (Exception e){
                throw new QiNiuException(QiNiuErrorEnum.ERROR_DATA);
            }
            return null;
    }

}
