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


import cn.cecep.talroad.data.analyse.task.missing.DataMissingAbstractService;
import cn.cecep.talroad.domain.MonDevFsReal;
import cn.cecep.talroad.enums.DataTypeEnum;
import cn.cecep.talroad.enums.EnIndustry;
import cn.cecep.talroad.enums.TimeTypeEnum;
import cn.cecep.talroad.mapper.MonDevFsRealMapper;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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 BurnDataMissingService extends DataMissingAbstractService<MonDevFsReal> {

    @Autowired
    private MonDevFsRealMapper mapper;

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

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

    @Override
    protected List<MonDevFsReal> queryReal(List<String> deviceIds,Date startTime,Date endTime) {
        LambdaQueryWrapper<MonDevFsReal> lambdaQueryWrapper = Wrappers.<MonDevFsReal>lambdaQuery()
                .in(MonDevFsReal::getDeviceId, deviceIds)
                .eq(MonDevFsReal::getTimeType, TimeTypeEnum.REAL.getCode())
                .between(MonDevFsReal::getDataTime,startTime,endTime);
        return mapper.selectList(lambdaQueryWrapper);
    }

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