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


import cn.cecep.talroad.data.analyse.task.logic.DataLogicAbstractService;
import cn.cecep.talroad.domain.MonDevDlReal;
import cn.cecep.talroad.enums.DataTypeEnum;
import cn.cecep.talroad.enums.EnIndustry;
import cn.cecep.talroad.enums.TimeTypeEnum;
import cn.cecep.talroad.mapper.MonDevDlRealMapper;
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 PowerDataLogicService extends DataLogicAbstractService<MonDevDlReal> {

    @Autowired
    private MonDevDlRealMapper mapper;

    @Override
    protected List<String> queryDeviceIds() {
        //数据逻辑异常
        return queryDeviceIds(EnIndustry.DL, DataTypeEnum.LOGIC.getCode());
    }

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

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

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