package cn.cecep.talroad.data.analyse.task.missing.impl;


import cn.cecep.talroad.data.analyse.task.missing.DataMissingAbstractService;
import cn.cecep.talroad.domain.MonDevJhReal;
import cn.cecep.talroad.enums.DataTypeEnum;
import cn.cecep.talroad.enums.EnIndustry;
import cn.cecep.talroad.enums.TimeTypeEnum;
import cn.cecep.talroad.mapper.MonDevJhRealMapper;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.Arrays;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 焦化
 */
@Slf4j
@Service
public class CokingDataMissingService extends DataMissingAbstractService<MonDevJhReal> {

    @Autowired
    private MonDevJhRealMapper mapper;

    @Override
    protected List<String> queryDeviceIds() {
        // 数据缺失
        return queryDeviceIds(EnIndustry.JH, DataTypeEnum.MISS.getCode());
    }

    @Override
    protected Map<String, List<MonDevJhReal>> groupDeviceRealList(List<MonDevJhReal> dataReal,List<String> deviceIds) {
        return dataReal.stream().collect(Collectors.groupingBy(MonDevJhReal::getDeviceId));
    }

    @Override
    protected List<MonDevJhReal> queryReal(List<String> deviceIds,Date startTime,Date endTime) {
        QueryWrapper<MonDevJhReal> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("data_id","factory_id","device_id","time_type","data_time","js100","js101","js102","js103","js104","jz100","jz101","jz102","jz103","jz105","jz106","jz107","jz108","jz109","jz110","js200","js201","js202","js203","g141","g314","g329","g330","g604","g605","g606","g942","g943","g944","g945","g949","g951","g952","g956","g957","g958","g960","g961","g962","g963","g964","g965","g966","g967","g968","g969","g970","g971","g972","g973","g974","g975","g976","g977","g978","g979","g980","g981","g982","g993","g994","g995","gb08","gb09","gb11","gb12","gb13","ppm_cc1","ppm_cc2","ppm_unit_cc1","ppm_unit_cc2","addi_param","a100","a101","a102","a103","a104","a105","a111","\"txjVol\"","a120","a121","a130","a131","a140","a141","g140","g318","g325","g601","g959","h959","h960","j959","j960");
        queryWrapper.in("device_id", deviceIds);
        queryWrapper.eq("time_type", TimeTypeEnum.REAL.getCode());
        queryWrapper.between("data_time",startTime,endTime);
        return mapper.selectList(queryWrapper);
    }

    @Override
    protected String getLogicExceptionsDate(MonDevJhReal entity) {
        return DateUtil.format(entity.getDataTime(),"yyyy-MM-dd HH:mm:ss");
    }
}
