鞍钢鲅鱼圈能源管控系统后端代码
潘志宝
2025-06-15 31ef4e5133bca08144d8c8bf1fa17edebfa96bed
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
package com.iailab.module.ansteel.job.task;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iailab.framework.common.util.date.DateUtils;
import com.iailab.framework.common.util.http.HttpUtils;
import com.iailab.module.ansteel.report.entity.DutyReportEntity;
import com.iailab.module.ansteel.report.service.DutyReportService;
import com.iailab.module.data.api.point.DataPointApi;
import com.iailab.module.data.api.point.dto.ApiPointValueWriteDTO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
 
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 同步能源日报
 * 0 10 0 * * ?
 *
 *
 * @author PanZhibao
 * @Description
 * @createTime 2025年06月13日
 */
@Component("syncDutyReportTask")
public class SyncDutyReportTask implements ITask {
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    @Autowired
    private DutyReportService dutyReportService;
 
    @Autowired
    private DataPointApi dataPointApi;
 
    private final static String URL = "http://10.50.37.1:8806/batch/xxb/getDutyReportData";
 
    @Override
    public void run(String params) {
        logger.info("SyncDutyReportTask定时任务正在执行,参数为:{}", params);
        try {
            String date = params;
            if (StringUtils.isBlank(date)) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.MILLISECOND, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.add(Calendar.DAY_OF_YEAR, -1);
                date = DateUtils.format(calendar.getTime(), "yyyy-MM-dd");
            }
            Map<String, Object> queryMap = new HashMap<String, Object>();
            queryMap.put("date", date);
            String responseStr = HttpUtils.sendPost(URL, JSONObject.toJSONString(queryMap));
            if (StringUtils.isBlank(responseStr)) {
                logger.info("responseStr is null");
                return;
            }
            logger.info("responseStr={}", responseStr);
            Map<String, BigDecimal> dataMap1 = new HashMap<>();
            Map<String, BigDecimal> dataMap2 = new HashMap<>();
            JSONArray jsonArray = JSONArray.parseArray(responseStr);
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                dataMap1.put(jsonObject.getString("cdeIndex"), new BigDecimal(jsonObject.get("valAct").toString()));
                dataMap2.put(jsonObject.getString("cdeIndex"), new BigDecimal(jsonObject.get("monthAvgValue").toString()));
            }
 
            List<DutyReportEntity> list = dutyReportService.list();
            if (CollectionUtils.isEmpty(list)) {
                logger.info("DutyReportEntity list is empty");
                return;
            }
            logger.info("DutyReportEntity list size={}", list.size());
            logger.info("dataMap1={}", JSONObject.toJSONString(dataMap1));
            logger.info("dataMap2={}", JSONObject.toJSONString(dataMap2));
            for (DutyReportEntity dutyReportEntity : list) {
 
                if (dataMap1.get(dutyReportEntity.getCdeIndex()) != null && StringUtils.isNotBlank(dutyReportEntity.getPointNo1())) {
                    ApiPointValueWriteDTO writeDTO = new ApiPointValueWriteDTO();
                    writeDTO.setPointNo(dutyReportEntity.getPointNo1());
                    writeDTO.setValue(dataMap1.get(dutyReportEntity.getCdeIndex()));
                    logger.info("writeDTO={}", JSONObject.toJSONString(writeDTO));
                    dataPointApi.writePointRealValue(writeDTO);
                }
 
                if (dataMap2.get(dutyReportEntity.getCdeIndex()) != null && StringUtils.isNotBlank(dutyReportEntity.getPointNo2())) {
                    ApiPointValueWriteDTO writeDTO = new ApiPointValueWriteDTO();
                    writeDTO.setPointNo(dutyReportEntity.getPointNo2());
                    writeDTO.setValue(dataMap2.get(dutyReportEntity.getCdeIndex()));
                    logger.info("writeDTO={}", JSONObject.toJSONString(writeDTO));
                    dataPointApi.writePointRealValue(writeDTO);
                }
            }
        } catch (Exception ex) {
            logger.error("SyncDutyReportTask运行异常");
            ex.printStackTrace();
        }
        logger.info("SyncDutyReportTask运行完成");
    }
}