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运行完成");
|
}
|
}
|