鞍钢鲅鱼圈能源管控系统后端代码
潘志宝
4 天以前 e648e97ead73b1c5e9e7f0a51d8e6fd8d776a36f
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.iailab.module.ansteel.plant.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iailab.framework.common.util.date.DateUtils;
import com.iailab.module.ansteel.plant.dao.PlantChartConfDao;
import com.iailab.module.ansteel.plant.entity.PlantChartConfEntity;
import com.iailab.module.ansteel.plant.service.PlantChartConfService;
import com.iailab.module.ansteel.plant.vo.PlantChartDataVO;
import com.iailab.module.data.api.point.DataPointApi;
import com.iailab.module.data.api.point.dto.ApiPointsValueQueryDTO;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
 
import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
/**
 * @description:
 * @author: lirm
 * @date: 2025/6/20 13:59
 **/
@Slf4j
@Service
public class PlantChartConfServiceImpl implements PlantChartConfService {
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    @Resource
    private PlantChartConfDao plantChartConfDao;
    @Resource
    private DataPointApi dataPointApi;
 
    private String timeFormat = DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
 
    @Override
    public PlantChartDataVO getPlantChartData(Map tMap) {
        int granularity = 60;
        PlantChartDataVO result = new PlantChartDataVO();
        if (ObjectUtils.isEmpty(tMap.get("indType")) || ObjectUtils.isEmpty(tMap.get("indCode"))) {
            logger.info("输入参数为空");
            return result;
        }
        QueryWrapper<PlantChartConfEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ind_type", tMap.get("indType"));
        queryWrapper.eq("ind_code", tMap.get("indCode"));
        List<PlantChartConfEntity> plantChartConfList = plantChartConfDao.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(plantChartConfList)) {
            log.info("plantChartConfList is null");
            return result;
        }
        if("year".equals(tMap.get("indType"))){
            granularity = 60*1440;
        }
        Date[] timeArray = calResultTime(tMap.get("indType").toString());
        Date startTime = timeArray[0];
        Date endTime = timeArray[1];
        List<String> categories = DateUtils.getTimeScale(startTime, endTime, granularity, timeFormat);
 
        PlantChartConfEntity plantChartConfEntity = plantChartConfList.get(0);
        result.setIndType(tMap.get("indType").toString());
        result.setIndCode(plantChartConfEntity.getIndCode());
        result.setIndName(plantChartConfEntity.getIndName());
        result.setStartTime(startTime);
        result.setEndTime(endTime);
        result.setCategories(categories);
        // 筛选DATAPOINT一次性查询出全部
        List<String> pointNos = Stream.of(plantChartConfEntity.getIndAvg(), plantChartConfEntity.getIndTheory(), plantChartConfEntity.getIndOptimal(), plantChartConfEntity.getIndReal(), plantChartConfEntity.getIndPower()).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(pointNos)) {
            ApiPointsValueQueryDTO queryDTO = new ApiPointsValueQueryDTO();
            queryDTO.setPointNos(pointNos);
            Map<String, List<Map<String, Object>>> pointsHisValues = dataPointApi.queryPointsHistoryValue(queryDTO);
            if (CollectionUtils.isEmpty(pointsHisValues)) {
                log.info("pointsHisValues is null");
                return result;
            }
 
            result.setIndAvgHisList(pointsHisValues.get(plantChartConfEntity.getIndAvg()));
            result.setIndTheoryHisList(pointsHisValues.get(plantChartConfEntity.getIndTheory()));
            result.setIndOptimalHisList(pointsHisValues.get(plantChartConfEntity.getIndOptimal()));
            result.setIndRealHisList(pointsHisValues.get(plantChartConfEntity.getIndReal()));
            result.setIndPowerHisList(pointsHisValues.get(plantChartConfEntity.getIndPower()));
        }
        return result;
    }
 
    private Date[] calResultTime(String indType) {
        Date[] result = new Date[2];
        Date startTime = null;
        Date endTime = null;
        if("day".equals(indType)) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.add(Calendar.HOUR_OF_DAY, -8);
            startTime = calendar.getTime();
 
            calendar = Calendar.getInstance();
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.SECOND, 0);
            endTime = calendar.getTime();
 
        }else if("year".equals(indType)) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.DAY_OF_MONTH, 1);
            startTime = calendar.getTime();
 
            calendar = Calendar.getInstance();
            calendar.set(Calendar.MILLISECOND, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            endTime = calendar.getTime();
        }
 
        result[0] = startTime;
        result[1] = endTime;
        return result;
    }
}