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


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

    @Autowired
    private MonDevRealMapper mapper;

    @Override
    protected List<String> queryDeviceIds() {
        return queryDeviceIds(EnIndustry.GT, DataTypeEnum.MISS.getCode());
    }

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

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

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