package com.iailab.module.ansteel.plant.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.iailab.module.ansteel.plant.dao.PlantIndexConfDao; import com.iailab.module.ansteel.plant.entity.PlantIndexConfEntity; import com.iailab.module.ansteel.plant.service.PlantIndexConfService; import com.iailab.module.ansteel.plant.vo.PlantIndexDataVO; import com.iailab.module.data.api.point.DataPointApi; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; /** * @description: * @author: dzd * @date: 2025/6/16 13:57 **/ @Slf4j @Service public class PlantIndexConfServiceImpl implements PlantIndexConfService { @Resource private PlantIndexConfDao plantIndexConfDao; @Resource private DataPointApi dataPointApi; private final BigDecimal badValue = new BigDecimal(-2); @Override public List getPlantIndexData(String businessType) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("business_type",businessType); List PlantIndexConfList = plantIndexConfDao.selectList(queryWrapper); // 筛选DATAPOINT一次性查询出全部 List pointNos = PlantIndexConfList.stream().flatMap(e -> Stream.of(e.getIndAvg(),e.getIndTheory(),e.getIndOptimal(),e.getIndReal(),e.getIndDeviationValue(),e.getIndDeviationRate(),e.getIndPrevious())).collect(Collectors.toList()); Map pointValues = new HashMap<>(); if (!CollectionUtils.isEmpty(pointNos)) { pointValues = dataPointApi.queryPointsRealValue(pointNos); } List result = new ArrayList<>(PlantIndexConfList.size()); for (PlantIndexConfEntity PlantIndexConf : PlantIndexConfList) { PlantIndexDataVO plantData = new PlantIndexDataVO(); plantData.setCode(PlantIndexConf.getIndCode()); plantData.setName(PlantIndexConf.getIndName()); plantData.setUnit(PlantIndexConf.getIndUnit()); plantData.setSort(PlantIndexConf.getSort()); plantData.setIndAvg(pointValues.containsKey(PlantIndexConf.getIndAvg()) ? new BigDecimal(pointValues.get(PlantIndexConf.getIndAvg()).toString()) : badValue); plantData.setIndTheory(pointValues.containsKey(PlantIndexConf.getIndTheory()) ? new BigDecimal(pointValues.get(PlantIndexConf.getIndTheory()).toString()) : badValue); plantData.setIndOptimal(pointValues.containsKey(PlantIndexConf.getIndOptimal()) ? new BigDecimal(pointValues.get(PlantIndexConf.getIndOptimal()).toString()) : badValue); plantData.setIndReal(pointValues.containsKey(PlantIndexConf.getIndReal()) ? new BigDecimal(pointValues.get(PlantIndexConf.getIndReal()).toString()) : badValue); plantData.setIndDeviationValue(pointValues.containsKey(PlantIndexConf.getIndDeviationValue()) ? new BigDecimal(pointValues.get(PlantIndexConf.getIndDeviationValue()).toString()) : badValue); plantData.setIndDeviationRate(pointValues.containsKey(PlantIndexConf.getIndDeviationRate()) ? new BigDecimal(pointValues.get(PlantIndexConf.getIndDeviationRate()).toString()) : badValue); plantData.setIndPrevious(pointValues.containsKey(PlantIndexConf.getIndPrevious()) ? new BigDecimal(pointValues.get(PlantIndexConf.getIndPrevious()).toString()) : badValue); result.add(plantData); } return result; } }