鞍钢鲅鱼圈能源管控系统后端代码
liriming
4 天以前 00762deb0cb1350c83bb2c5f5f68ca1919ddb45e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.iailab.module.ansteel.plant.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iailab.module.ansteel.common.enums.ProcessConfDataTypeEnum;
import com.iailab.module.ansteel.plant.dao.PlantConfDao;
import com.iailab.module.ansteel.plant.entity.PlantConfEntity;
import com.iailab.module.ansteel.plant.service.PlantConfService;
import com.iailab.module.ansteel.plant.vo.PlantDataVO;
import com.iailab.module.data.api.arc.ArcDataApi;
import com.iailab.module.data.api.arc.dto.ApiArcDataDTO;
import com.iailab.module.data.api.ind.IndItemApi;
import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO;
import com.iailab.module.data.api.point.DataPointApi;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
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;
 
/**
 * @author PanZhibao
 * @Description
 * @createTime 2025年06月15日
 */
@Slf4j
@Service
public class PlantConfServiceImpl implements PlantConfService {
 
    @Resource
    private PlantConfDao plantConfDao;
    @Resource
    private DataPointApi dataPointApi;
    @Resource
    private IndItemApi indItemApi;
    @Resource
    private ArcDataApi arcDataApi;
 
    private final BigDecimal badValue = new BigDecimal(-2);
 
    @Override
    public List<PlantConfEntity> list(Map<String, Object> params) {
        String businessType = (String) params.get("businessType");
 
        QueryWrapper<PlantConfEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(businessType), "business_type", businessType);
        return plantConfDao.selectList(queryWrapper);
    }
 
    @Override
    public List<PlantDataVO> getPlantData(String businessType) {
        QueryWrapper<PlantConfEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("business_type",businessType);
        List<PlantConfEntity> plantConfList = plantConfDao.selectList(queryWrapper);
        // 筛选DATAPOINT一次性查询出全部
        List<String> pointNos = plantConfList.stream().filter(e -> e.getDataType().equals(ProcessConfDataTypeEnum.DATAPOINT.getCode())).map(PlantConfEntity::getDataNo).collect(Collectors.toList());
        Map<String, Object> pointValues = new HashMap<>();
        if (!CollectionUtils.isEmpty(pointNos)) {
            pointValues = dataPointApi.queryPointsRealValue(pointNos);
        }
        List<PlantDataVO> result = new ArrayList<>(plantConfList.size());
        for (PlantConfEntity plantConf : plantConfList) {
            String dataNo = plantConf.getDataNo();
            String dataType = plantConf.getDataType();
            PlantDataVO plantData = new PlantDataVO();
            plantData.setCode(plantConf.getIndCode());
            plantData.setName(plantConf.getIndName());
            plantData.setUnit(plantConf.getIndUnit());
            plantData.setSort(plantConf.getSort());
            switch (ProcessConfDataTypeEnum.getEumByCode(dataType)) {
                case DATAPOINT:
                    if (pointValues.containsKey(dataNo)) {
                        plantData.setValue(new BigDecimal(pointValues.get(dataNo).toString()));
                    }else {
                        plantData.setValue(badValue);
                    }
                    break;
                case IND:
                    List<ApiIndItemValueDTO> indValues = indItemApi.queryIndItemDefaultValue(dataNo);
                    if (!CollectionUtils.isEmpty(indValues)) {
                        plantData.setValue(new BigDecimal(indValues.get(0).getDataValue().toString()));
                    }else {
                        plantData.setValue(badValue);
                    }
                    break;
                case ARC:
                    ApiArcDataDTO apiArcDataDTO = arcDataApi.queryArcLastValue(dataNo);
                    if (apiArcDataDTO != null) {
                        plantData.setValue(apiArcDataDTO.getArcValue());
                    }else {
                        plantData.setValue(badValue);
                    }
                    break;
                default:
                    plantData.setValue(badValue);
                    break;
            }
            result.add(plantData);
        }
        return result;
    }
}