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


import cn.cecep.talroad.data.analyse.task.constant.DataConstantAbstractService;
import cn.cecep.talroad.domain.MonDevDlReal;
import cn.cecep.talroad.enums.DataTypeEnum;
import cn.cecep.talroad.enums.EnIndustry;
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 PowerDataConstantService extends DataConstantAbstractService<MonDevDlReal> {

    @Autowired
    private MonDevDlRealMapper mapper;

    @Override
    protected List<String> queryDeviceIds() {
        // 恒值
        return queryDeviceIds(EnIndustry.DL, DataTypeEnum.CONTANT.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)
                .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");
    }
}
