package cn.cecep.talroad.data.analyse.task.real.device.impl;

import cn.cecep.talroad.data.analyse.task.entity.MainProductDeviceVo;
import cn.cecep.talroad.data.analyse.task.real.device.DeviceRealService;
import cn.cecep.talroad.domain.SEnvGasMonReal;
import cn.cecep.talroad.enums.PollutantTypeEnum;
import cn.cecep.talroad.mapper.BMainProductionInorgGasMapper;
import cn.cecep.talroad.mapper.SEnvGasRealMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class GasMonDataDeviceRealService extends DeviceRealService<SEnvGasMonReal> {

    @Autowired
    private BMainProductionInorgGasMapper bMainProductionInorgGasMapper;

    @Autowired
    private SEnvGasRealMapper sEnvGasRealMapper;

    @Override
    public List<SEnvGasMonReal> queryReal(List<String> deviceIds, Date startTime, Date endTime) {

//        List<MainProductDeviceVo> mainProductDeviceVos = MainProductDeviceVo.parse(deviceIds);
//
//        List<String> outletIds = mainProductDeviceVos.stream().map(MainProductDeviceVo::getOutletId).collect(Collectors.toList());
//
//        if (CollectionUtils.isEmpty(outletIds)){
//            return new ArrayList<>();
//        }
//        LambdaQueryWrapper<SEnvGasReal> sEnvGasRealLambdaQueryWrapper = new QueryWrapper<SEnvGasReal>().lambda()
//                .in(SEnvGasReal::getOutletId, outletIds)
//                .ge(SEnvGasReal::getMonitoringTime, DateUtil.format(startTime,"yyyy-MM-dd HH:mm:ss"))
//                .le(SEnvGasReal::getMonitoringTime, DateUtil.format(endTime,"yyyy-MM-dd HH:mm:ss"));
//
//        List<SEnvGasReal> sEnvGasMonReals = sEnvGasRealMapper.selectList(sEnvGasRealLambdaQueryWrapper);

        return null;
    }

    @Override
    public List<String> queryDeviceIds() {
        List<MainProductDeviceVo> deviceIdsData = bMainProductionInorgGasMapper.selectDeviceIdByPollutantType(PollutantTypeEnum.ORGANIZATION.getCode());

        deviceIdsData = MainProductDeviceVo.groupDevice(deviceIdsData);

        return MainProductDeviceVo.toJsonString(deviceIdsData);
    }

    @Override
    public Map<String, List<SEnvGasMonReal>> groupDeviceRealList(List<SEnvGasMonReal> dataReal,List<String> deviceIds) {
//        List<MainProductDeviceVo> mainProductDeviceVos = MainProductDeviceVo.parse(deviceIds);
//
//        Map<String, List<SEnvGasMonReal>> groupData = new HashMap<>();
//
//        for (SEnvGasMonReal sEnvWaterMonReal : dataReal) {
//
//            String outletId = sEnvWaterMonReal.getOutletId();
//
//            List<String> proDeviceIds = mainProductDeviceVos.stream()
//                    .filter(mainProductDeviceVo -> mainProductDeviceVo.getOutletId().equals(outletId))
//                    .map(MainProductDeviceVo::getProFacilityId).collect(Collectors.toList());
//
//            for (String proDeviceId : proDeviceIds) {
//                List<SEnvGasReal> sEnvWaterMonReals = groupData.get(proDeviceId);
//                if (sEnvWaterMonReals==null){
//                    sEnvWaterMonReals = new ArrayList<>();
//                    groupData.put(proDeviceId,sEnvWaterMonReals);
//                }
//                sEnvWaterMonReals.add(sEnvWaterMonReal);
//            }
//
//        }

        return null;
    }

    @Override
    public String getLogicExceptionsDate(SEnvGasMonReal entity) {
        return entity.getMonitoringTime();
    }
}
