From 5e1fbbd878af55a76e590510e0b08e9d84e72b4b Mon Sep 17 00:00:00 2001 From: Jay <csj123456> Date: 星期四, 13 三月 2025 16:29:49 +0800 Subject: [PATCH] 新增把指标数据存入测点的定时任务 --- shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/rpc/config/RpcConfiguration.java | 3 + shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/SaveIndDataToPointDataTask.java | 76 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletions(-) diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/rpc/config/RpcConfiguration.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/rpc/config/RpcConfiguration.java index 9a797c3..83d418d 100644 --- a/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/rpc/config/RpcConfiguration.java +++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/framework/rpc/config/RpcConfiguration.java @@ -1,5 +1,6 @@ package com.iailab.module.shasteel.framework.rpc.config; +import com.iailab.module.data.api.ind.IndItemApi; import com.iailab.module.data.api.point.DataPointApi; import com.iailab.module.infra.api.config.ConfigApi; import com.iailab.module.infra.api.db.DataSourceConfigServiceApi; @@ -12,6 +13,6 @@ import org.springframework.context.annotation.Configuration; @Configuration(proxyBeanMethods = false) -@EnableFeignClients(clients = {FileApi.class, WebSocketSenderApi.class, DataSourceConfigServiceApi.class, ConfigApi.class, TenantApi.class, McsApi.class, MdkApi.class, DataPointApi.class}) +@EnableFeignClients(clients = {FileApi.class, WebSocketSenderApi.class, DataSourceConfigServiceApi.class, ConfigApi.class, TenantApi.class, McsApi.class, MdkApi.class, DataPointApi.class, IndItemApi.class}) public class RpcConfiguration { } diff --git a/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/SaveIndDataToPointDataTask.java b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/SaveIndDataToPointDataTask.java new file mode 100644 index 0000000..8dc0654 --- /dev/null +++ b/shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/SaveIndDataToPointDataTask.java @@ -0,0 +1,76 @@ +package com.iailab.module.shasteel.job.task; + +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 com.iailab.module.data.api.point.dto.ApiPointValueWriteDTO; +import com.iailab.module.model.api.mcs.McsApi; +import com.iailab.module.model.api.mcs.dto.ChartParamDTO; +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 java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.YearMonth; +import java.util.Calendar; +import java.util.List; + +/** + * 蒸汽评价指标(汽耗率) + * + * @author Jay + */ +@Component("saveIndDataToPointDataTask") +public class SaveIndDataToPointDataTask implements ITask { + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private McsApi mcsApi; + + @Autowired + private DataPointApi dataPointApi; + + @Autowired + private IndItemApi indItemApi; + + @Override + public void run(String params) { + logger.info("SaveIndDataToPointDataTask,参数为:{}", params); + try { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.MILLISECOND, 0); + calendar.set(Calendar.SECOND, 0); + if (StringUtils.isEmpty(params)) { + logger.info("参数为空"); + return; + } + //获取当前月天数 + LocalDate today = LocalDate.now(); + // 使用YearMonth来获取当前年份和月份的天数 + YearMonth yearMonth = YearMonth.of(today.getYear(), today.getMonthValue()); + int lengthOfMonth = yearMonth.lengthOfMonth(); + List<ChartParamDTO> chartParamList = mcsApi.getChartParamList(params); + chartParamList.forEach(chartParam -> { + List<ApiIndItemValueDTO> indItemlist = indItemApi.queryIndItemDefaultValue(chartParam.getParamCode()); + if (indItemlist != null && indItemlist.size() > 0) { + ApiPointValueWriteDTO apiPointValueWriteDTO = new ApiPointValueWriteDTO(); + apiPointValueWriteDTO.setPointNo(chartParam.getParamValue()); + BigDecimal indValue = (BigDecimal) indItemlist.get(0).getDataValue(); + BigDecimal pointValue = indValue.divide(new BigDecimal(lengthOfMonth), 3, RoundingMode.HALF_UP); + apiPointValueWriteDTO.setValue(pointValue); + dataPointApi.writePointRealValue(apiPointValueWriteDTO); + } + }); + + logger.info(params + "调度方案执行完成"); + } catch (Exception ex) { + logger.error("SaveIndDataToPointDataTask运行异常"); + ex.printStackTrace(); + } + logger.info("SaveIndDataToPointDataTask运行完成"); + } +} -- Gitblit v1.9.3