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


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

    @Autowired
    private MonDevBlRealMapper mapper;

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

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

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

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