package cn.cecep.talroad.data.analyse.task.real.concentration.online.impl;

import cn.cecep.talroad.data.analyse.task.entity.ConcentrationEntity;
import cn.cecep.talroad.data.analyse.task.entity.PollutantEntity;
import cn.cecep.talroad.data.analyse.task.real.concentration.GasConcentrationEnum;
import cn.cecep.talroad.data.analyse.task.real.concentration.online.OnlineRealTaskService;
import cn.cecep.talroad.domain.SEnvGasMonDay;
import cn.cecep.talroad.mapper.SEnvGasMonDayMapper;
import cn.cecep.talroad.util.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/***
 *
 * @Title:
 * @Author: xuxin
 * @CreateTime: 2023-07-03 17:18
 * @Description
 *
 **/
@Service
public class GasOnlineRealTaskService extends OnlineRealTaskService<SEnvGasMonDay> {

    @Autowired
    private SEnvGasMonDayMapper sEnvGasMonDayMapper;

    @Override
    public List<SEnvGasMonDay> queryRealData(List<String> outletId, Date findDate) {

        LambdaQueryWrapper<SEnvGasMonDay> sEnvGasMonDayLambdaQueryWrapper = new QueryWrapper<SEnvGasMonDay>().lambda()
                .in(SEnvGasMonDay::getOutletId, outletId)
                .eq(SEnvGasMonDay::getMonitoringTime, DateUtil.format(findDate, "yyyy-MM-dd"));

        return sEnvGasMonDayMapper.selectList(sEnvGasMonDayLambdaQueryWrapper);
    }

    @Override
    public List<PollutantEntity> getPollEntity() {
        return GasConcentrationEnum.getPollutantEntity();
    }

    @Override
    public ConcentrationEntity getOnlineConcentration(SEnvGasMonDay data , String pollCode, BigDecimal concentration) {
        return ConcentrationEntity.builder()
                .factoryId(data.getFactoryId())
                .pollCode(pollCode)
                .stationId(data.getOutletId())
                .date(DateUtil.parse(data.getMonitoringTime(),"yyyy-MM-dd"))
                .concentration(concentration).build();
    }
}
