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


import cn.cecep.talroad.data.analyse.task.missing.DataMissingAbstractService;
import cn.cecep.talroad.domain.MonDevSnReal;
import cn.cecep.talroad.enums.DataTypeEnum;
import cn.cecep.talroad.enums.EnIndustry;
import cn.cecep.talroad.enums.TimeTypeEnum;
import cn.cecep.talroad.mapper.MonDevSnRealMapper;
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 CementDataMissingService extends DataMissingAbstractService<MonDevSnReal> {

    @Autowired
    private MonDevSnRealMapper mapper;

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

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

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

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