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.WaterConcentrationEnum;
import cn.cecep.talroad.data.analyse.task.real.concentration.online.OnlineRealTaskService;
import cn.cecep.talroad.domain.SEnvGasMonDay;
import cn.cecep.talroad.domain.SEnvWaterMonDay;
import cn.cecep.talroad.mapper.SEnvGasMonDayMapper;
import cn.cecep.talroad.mapper.SEnvWaterMonDayMapper;
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 WaterOnlineRealTaskService extends OnlineRealTaskService<SEnvWaterMonDay> {

    @Autowired
    private SEnvWaterMonDayMapper sEnvWaterMonDayMapper;

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

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

        return sEnvWaterMonDayMapper.selectList(sEnvGasMonDayLambdaQueryWrapper);
    }

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

    @Override
    public ConcentrationEntity getOnlineConcentration(SEnvWaterMonDay 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();
    }
}
