Merge remote-tracking branch 'origin/master'
# Conflicts:
# shasteel-biz/src/main/java/com/iailab/module/shasteel/job/task/RunScheduleOnaOptTask.java
| | |
| | | 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; |
| | |
| | | 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 { |
| | | } |
对比新文件 |
| | |
| | | package com.iailab.module.shasteel.job.task; |
| | | |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO; |
| | | import com.iailab.module.model.api.mdk.MdkApi; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleReqDTO; |
| | | import com.iailab.module.model.api.mdk.dto.MdkScheduleRespDTO; |
| | | import com.iailab.module.model.enums.ScheduleTriggerMethodEnum; |
| | | 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 javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 压缩空气班次指标累积评价 |
| | | * 动态数据长度,月初到当天 |
| | | * 每天更新,10 0 0 1/1 * ? |
| | | * |
| | | * @author PanZhibao |
| | | * @Description |
| | | * @createTime 2024年12月31日 |
| | | */ |
| | | @Component("runScheduleAirClassAverageIndexTask") |
| | | public class RunScheduleAirClassAverageIndexTask implements ITask { |
| | | private Logger logger = LoggerFactory.getLogger(getClass()); |
| | | |
| | | @Resource |
| | | private McsApi mcsApi; |
| | | |
| | | @Autowired |
| | | private MdkApi mdkApi; |
| | | |
| | | @Override |
| | | public void run(String params) { |
| | | logger.info("RunScheduleAirClassAverageIndexTask,参数为:{}", params); |
| | | try { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | Date scheduleTime = calendar.getTime(); |
| | | if (StringUtils.isEmpty(params)) { |
| | | logger.info("参数为空"); |
| | | return; |
| | | } |
| | | // 根据条件查找方案 |
| | | List<StScheduleSchemeDTO> schemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.JOB.getCode(), params); |
| | | if (CollectionUtils.isEmpty(schemeList)) { |
| | | logger.info("方案为空"); |
| | | return; |
| | | } |
| | | |
| | | for (StScheduleSchemeDTO scheme : schemeList) { |
| | | MdkScheduleReqDTO dto = new MdkScheduleReqDTO(); |
| | | dto.setScheduleTime(scheduleTime); |
| | | dto.setScheduleCode(scheme.getCode()); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDate startOfMonth = LocalDate.now().withDayOfMonth(1); |
| | | LocalDateTime startOfMonthAtMidnight = startOfMonth.atStartOfDay(); |
| | | long timeDifference = ChronoUnit.MINUTES.between(startOfMonthAtMidnight, now); |
| | | Map<Integer, Integer> dynamicDataLength = new HashMap<>(); |
| | | dynamicDataLength.put(1, (int) timeDifference); |
| | | dynamicDataLength.put(2, (int) timeDifference); |
| | | dynamicDataLength.put(3, (int) timeDifference); |
| | | dynamicDataLength.put(4, (int) timeDifference); |
| | | dto.setDynamicDataLength(dynamicDataLength); |
| | | Map<String, String> dynamicSettings = new HashMap<>(); |
| | | dynamicSettings.put("embedDim", String.valueOf(timeDifference)); |
| | | dto.setDynamicSettings(dynamicSettings); |
| | | MdkScheduleRespDTO mdkScheduleRespDTO = mdkApi.doSchedule(dto); |
| | | // 结果写入测点 |
| | | mdkApi.scheduleModelOut(mdkScheduleRespDTO); |
| | | } |
| | | logger.info(params + "调度方案执行完成"); |
| | | } catch (Exception ex) { |
| | | logger.error("RunScheduleAirClassAverageIndexTask运行异常"); |
| | | ex.printStackTrace(); |
| | | } |
| | | logger.info("RunScheduleAirClassAverageIndexTask运行完成"); |
| | | } |
| | | } |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 压缩空气优化调度 |
| | |
| | | |
| | | @Autowired |
| | | private MdkApi mdkApi; |
| | | |
| | | /** |
| | | * 调度建议内容 |
| | | */ |
| | | private static Map<String, String> gasAdjustMode = new HashMap<>(); |
| | | |
| | | /** |
| | | * 调度建议时间 |
| | | */ |
| | | private static Map<String, Date> gasLastSugTime = new HashMap<>(); |
| | | |
| | | @Override |
| | | public void run(String params) { |
| | |
| | | logger.info("调度结果异常,STATUS=" + mdkScheduleRespDTO.getStatusCode()); |
| | | return; |
| | | } |
| | | |
| | | // 保存预警信息 |
| | | if (mdkScheduleRespDTO.getResult().get("pressureLWarning") != null && |
| | | StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("pressureLWarning").toString())) { |
| | |
| | | } |
| | | |
| | | // 保存调度建议 |
| | | if (mdkScheduleRespDTO.getResult().get("dispatchStart") != null && |
| | | StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("dispatchStart").toString())) { |
| | | String dispatchStart = mdkScheduleRespDTO.getResult().get("dispatchStart").toString(); |
| | | ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); |
| | | suggest.setTitle("空压机启动调度建议"); |
| | | suggest.setContent(dispatchStart); |
| | | suggest.setScheduleObj(scheme.getScheduleObj()); |
| | | suggest.setScheduleTime(scheduleTime); |
| | | suggest.setSort(0); |
| | | mcsApi.createScheduleSuggest(suggest); |
| | | } |
| | | |
| | | if (mdkScheduleRespDTO.getResult().get("dispatchClose") != null && |
| | | StringUtils.isNotEmpty(mdkScheduleRespDTO.getResult().get("dispatchClose").toString())) { |
| | | String dispatchClose = mdkScheduleRespDTO.getResult().get("dispatchClose").toString(); |
| | | ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); |
| | | suggest.setTitle("空压机关停调度建议"); |
| | | suggest.setContent(dispatchClose); |
| | | suggest.setScheduleObj(scheme.getScheduleObj()); |
| | | suggest.setScheduleTime(scheduleTime); |
| | | suggest.setSort(0); |
| | | mcsApi.createScheduleSuggest(suggest); |
| | | } |
| | | |
| | | this.saveScheduleSuggest("空压机启动调度建议", mdkScheduleRespDTO.getResult().get("dispatchStart"), scheme.getScheduleObj(), |
| | | scheduleTime, scheme.getAdjustRate()); |
| | | this.saveScheduleSuggest("空压机关停调度建议", mdkScheduleRespDTO.getResult().get("dispatchClose"), scheme.getScheduleObj(), |
| | | scheduleTime, scheme.getAdjustRate()); |
| | | logger.info(params + "调度方案执行完成"); |
| | | } catch (Exception ex) { |
| | | logger.error("RunScheduleAirDispatchTask运行异常"); |
| | |
| | | } |
| | | logger.info("RunScheduleAirDispatchTask运行完成"); |
| | | } |
| | | |
| | | private void saveScheduleSuggest(String title, Object content, String scheduleObj, Date scheduleTime, int adjustRate) { |
| | | if (content == null) { |
| | | logger.info(title + "调整值为空,不产生建议"); |
| | | return; |
| | | } |
| | | String contentStr = content.toString(); |
| | | if (StringUtils.isBlank(contentStr)) { |
| | | logger.info(title + "调整值为空,不产生建议"); |
| | | return; |
| | | } |
| | | if (gasAdjustMode.containsKey(title) && gasAdjustMode.get(title).equals(contentStr) && |
| | | gasLastSugTime.containsKey(title) && (scheduleTime.getTime() - gasLastSugTime.get(title).getTime() <= Integer.valueOf(adjustRate).longValue() * 60 * 1000)) { |
| | | logger.info("调整建议在有效期内"); |
| | | return; |
| | | } |
| | | gasAdjustMode.put(title, contentStr); |
| | | gasLastSugTime.put(title, scheduleTime); |
| | | |
| | | ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); |
| | | suggest.setTitle(title); |
| | | suggest.setContent(content.toString()); |
| | | suggest.setScheduleObj(scheduleObj); |
| | | suggest.setScheduleTime(scheduleTime); |
| | | suggest.setSort(0); |
| | | mcsApi.createScheduleSuggest(suggest); |
| | | } |
| | | } |
| | |
| | | package com.iailab.module.shasteel.job.task; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO; |
| | | import com.iailab.module.model.api.mcs.dto.ScheduleSuggestRespDTO; |
| | | import com.iailab.module.model.api.mcs.dto.StScheduleSchemeDTO; |
| | | import com.iailab.module.model.api.mdk.MdkApi; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | private MdkApi mdkApi; |
| | | |
| | | private Map<String, StScheduleSchemeDTO> schemeMap = new HashMap<>(); |
| | | |
| | | /** |
| | | * 调度调整方向 |
| | | * 1:调整值为正数;-1:调整值为负数 |
| | | */ |
| | | private static Map<String, Integer> gasAdjustMode = new HashMap<>(); |
| | | |
| | | /** |
| | | * 调度建议时间 |
| | | */ |
| | | private static Map<String, Date> gasLastSugTime = new HashMap<>(); |
| | | |
| | | private static final String CODE06 = "06"; |
| | | |
| | |
| | | mdkApi.scheduleModelOut(entry.getValue()); |
| | | logger.info("氧气班平衡计划下发参数: {}", entry.getValue()); |
| | | } else if (entry.getKey().equals(CODE05)) { |
| | | String scheduleObj = schemeMap.get(CODE05).getScheduleObj(); |
| | | // 氧气系统优化调度决策 |
| | | StScheduleSchemeDTO scheduleScheme = schemeMap.get(CODE05); |
| | | String scheduleObj = scheduleScheme.getScheduleObj(); |
| | | /*String yingdiAdvice = entry.getValue().getResult().get("yingdiAdvice").toString(); |
| | | String faAdvice = entry.getValue().getResult().get("faAdvice").toString(); |
| | | String hongAdvice = entry.getValue().getResult().get("hongAdvice").toString(); |
| | | String runAdvice = entry.getValue().getResult().get("runAdvice").toString(); |
| | | String yingdiAdvice = entry.getValue().getResult().get("yingdiAdvice").toString(); |
| | | if(!("压力正常".equals(yingdiAdvice)||"-2.0".equals(yingdiAdvice))){ |
| | | if(!yingdiAdvice.equals("压力正常")){ |
| | | saveScheduleSuggest("盈德中压调整建议", yingdiAdvice, scheduleObj, scheduleTime); |
| | | } |
| | | if(!("压力正常".equals(faAdvice)||"-2.0".equals(faAdvice))){ |
| | | if(!faAdvice.equals("压力正常")){ |
| | | saveScheduleSuggest("法夜空调整建议", faAdvice, scheduleObj, scheduleTime); |
| | | } |
| | | if(!("压力正常".equals(hongAdvice)||"-2.0".equals(hongAdvice))){ |
| | | if(!hongAdvice.equals("压力正常")){ |
| | | saveScheduleSuggest("宏昌调整建议", hongAdvice, scheduleObj, scheduleTime); |
| | | } |
| | | if(!("压力正常".equals(runAdvice)||"-2.0".equals(runAdvice))){ |
| | | if(!runAdvice.equals("压力正常")){ |
| | | saveScheduleSuggest("润忠调整建议", runAdvice, scheduleObj, scheduleTime); |
| | | } |
| | | } else if (entry.getKey().equals(CODE01)) { |
| | | String scheduleObj = schemeMap.get(CODE01).getScheduleObj(); |
| | | }*/ |
| | | |
| | | BigDecimal adviceValues = new BigDecimal(entry.getValue().getResult().get("adviceValues").toString()); |
| | | logger.info("各制氧机组建议 adviceValues=" + adviceValues); |
| | | |
| | | |
| | | String advice = entry.getValue().getResult().get("advice").toString(); |
| | | if(!("压力正常".equals(advice)||"-2.0".equals(advice))){ |
| | | saveScheduleSuggest("氮气预警", advice, scheduleObj, scheduleTime); |
| | | if(adviceValues.compareTo(BigDecimal.ZERO) != 0){ |
| | | saveScheduleSuggest("各制氧机组建议", advice, scheduleObj, scheduleTime, adviceValues, scheduleScheme.getAdjustRate()); |
| | | } |
| | | |
| | | } else if (entry.getKey().equals(CODE01)) { |
| | | StScheduleSchemeDTO scheduleScheme = schemeMap.get(CODE01); |
| | | String scheduleObj = scheduleScheme.getScheduleObj(); |
| | | BigDecimal adviceValues = new BigDecimal(entry.getValue().getResult().get("advicevalues").toString()); |
| | | logger.info("氮气预警 adviceValues=" + adviceValues); |
| | | |
| | | String advice = entry.getValue().getResult().get("advice").toString(); |
| | | if(adviceValues.compareTo(BigDecimal.ZERO) != 0){ |
| | | saveAlarmMessage("氮气预警", advice, scheduleObj, scheduleTime,adviceValues,scheduleScheme.getAdjustRate()); |
| | | } |
| | | } |
| | | } |
| | | logger.info(params + "调度方案执行完成"); |
| | | } catch (Exception ex) { |
| | | logger.error("RunScheduleOnaOptTask运行异常"); |
| | | logger.error("RunScheduleOnaOptTask运行异常",ex); |
| | | ex.printStackTrace(); |
| | | } |
| | | logger.info("RunScheduleOnaOptTask运行完成"); |
| | |
| | | |
| | | private void saveScheduleSuggest(String title, String content, String scheduleObj, Date scheduleTime) { |
| | | if (StringUtils.isBlank(content)) { |
| | | logger.info(title + "调整值为空,不产生建议"); |
| | | return; |
| | | } |
| | | |
| | | ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); |
| | | suggest.setTitle(title); |
| | | suggest.setContent(content); |
| | |
| | | suggest.setSort(0); |
| | | mcsApi.createScheduleSuggest(suggest); |
| | | } |
| | | |
| | | private void saveScheduleSuggest(String title, String content, String scheduleObj, Date scheduleTime, BigDecimal adjustValue, int adjustRate) { |
| | | if (StringUtils.isBlank(content)) { |
| | | logger.info(title + "调整值为空,不产生建议"); |
| | | return; |
| | | } |
| | | if (adjustValue == null || adjustValue.doubleValue() == 0) { |
| | | logger.info(title + "调整值为空,不产生建议"); |
| | | return; |
| | | } |
| | | if (gasAdjustMode.containsKey(title) && gasAdjustMode.get(title).equals(adjustValue.compareTo(BigDecimal.ZERO)) && |
| | | gasLastSugTime.containsKey(title) && (scheduleTime.getTime() - gasLastSugTime.get(title).getTime() <= Integer.valueOf(adjustRate).longValue() * 60 * 1000)) { |
| | | logger.info("调整建议在有效期内"); |
| | | return; |
| | | } |
| | | gasAdjustMode.put(title, adjustValue.compareTo(BigDecimal.ZERO)); |
| | | gasLastSugTime.put(title, scheduleTime); |
| | | |
| | | ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); |
| | | suggest.setTitle(title); |
| | | suggest.setContent(content); |
| | | suggest.setScheduleObj(scheduleObj); |
| | | suggest.setScheduleTime(scheduleTime); |
| | | suggest.setSort(0); |
| | | mcsApi.createScheduleSuggest(suggest); |
| | | } |
| | | private void saveAlarmMessage(String title, String content, String scheduleObj, Date scheduleTime, BigDecimal adjustValue, int adjustRate) { |
| | | if (StringUtils.isBlank(content)) { |
| | | logger.info(title + "预警值为空,不产生预警"); |
| | | return; |
| | | } |
| | | if (adjustValue == null || adjustValue.doubleValue() == 0) { |
| | | logger.info(title + "预警值为空,不产生预警"); |
| | | return; |
| | | } |
| | | if (gasAdjustMode.containsKey(title) && gasAdjustMode.get(title).equals(adjustValue.compareTo(BigDecimal.ZERO)) && |
| | | gasLastSugTime.containsKey(title) && (scheduleTime.getTime() - gasLastSugTime.get(title).getTime() <= Integer.valueOf(adjustRate).longValue() * 60 * 1000)) { |
| | | logger.info("预警在有效期内"); |
| | | return; |
| | | } |
| | | gasAdjustMode.put(title, adjustValue.compareTo(BigDecimal.ZERO)); |
| | | gasLastSugTime.put(title, scheduleTime); |
| | | |
| | | AlarmMessageRespDTO alarm = new AlarmMessageRespDTO(); |
| | | alarm.setTitle(title); |
| | | alarm.setContent(content); |
| | | alarm.setAlarmObj(scheduleObj); |
| | | alarm.setAlarmType(adjustValue.compareTo(BigDecimal.ZERO) > 0 ? "超上限" : "超下限"); |
| | | alarm.setAlarmTime(scheduleTime); |
| | | mcsApi.createAlarmMessage(alarm); |
| | | } |
| | | } |
| | |
| | | package com.iailab.module.shasteel.job.task; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | | import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO; |
| | | import com.iailab.module.model.api.mcs.dto.ScheduleSuggestRespDTO; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 蒸汽调度 |
| | |
| | | |
| | | @Autowired |
| | | private MdkApi mdkApi; |
| | | |
| | | /** |
| | | * 调度调整方向 |
| | | * 1:调整值为正数;-1:调整值为负数 |
| | | */ |
| | | private static Map<String, Integer> gasAdjustMode = new HashMap<>(); |
| | | |
| | | /** |
| | | * 调度建议时间 |
| | | */ |
| | | private static Map<String, Date> gasLastSugTime = new HashMap<>(); |
| | | |
| | | @Override |
| | | public void run(String params) { |
| | |
| | | logger.info("调度结果异常,STATUS=" + mdkScheduleRespDTO.getStatusCode()); |
| | | return; |
| | | } |
| | | // 用户调整量 |
| | | logger.info("user_adjust=" + mdkScheduleRespDTO.getResult().get("user_adjust")); |
| | | List<BigDecimal> adviceValues = new ArrayList<>(); |
| | | JSONArray ja0 = JSONArray.parseArray(mdkScheduleRespDTO.getResult().get("user_adjust").toString()); |
| | | JSONArray ja1 = ja0.getJSONArray(0); |
| | | for(int i = 0; i < ja1.size(); i++) { |
| | | adviceValues.add(new BigDecimal(ja1.get(i).toString())); |
| | | } |
| | | logger.info("adviceValues=" + JSONArray.toJSONString(adviceValues)); |
| | | |
| | | Object jinfengAdvice = mdkScheduleRespDTO.getResult().get("jinfengAdvice"); |
| | | saveScheduleSuggest("锦丰调度建议", jinfengAdvice, scheme.getScheduleObj(), scheduleTime); |
| | | saveScheduleSuggest("锦丰调度建议", jinfengAdvice, scheme.getScheduleObj(), scheduleTime, adviceValues.get(0), scheme.getAdjustRate()); |
| | | |
| | | Object daxinAdvice = mdkScheduleRespDTO.getResult().get("daxinAdvice"); |
| | | saveScheduleSuggest("大新调度建议", daxinAdvice, scheme.getScheduleObj(), scheduleTime); |
| | | saveScheduleSuggest("大新调度建议", daxinAdvice, scheme.getScheduleObj(), scheduleTime, adviceValues.get(1), scheme.getAdjustRate()); |
| | | |
| | | Object daxinWarning = mdkScheduleRespDTO.getResult().get("daxinWarning"); |
| | | saveAlarmMessage("大新预警", daxinWarning, scheme.getScheduleObj(), scheduleTime); |
| | |
| | | logger.info("RunScheduleSteamTask运行完成"); |
| | | } |
| | | |
| | | private void saveScheduleSuggest(String title, Object content, String scheduleObj, Date scheduleTime) { |
| | | if (content == null || StringUtils.isBlank(content.toString()) || "0".equals(content.toString())) { |
| | | logger.info(title + "content为空"); |
| | | private void saveScheduleSuggest(String title, Object content, String scheduleObj, Date scheduleTime, BigDecimal adjustValue, int adjustRate) { |
| | | if (content == null) { |
| | | return; |
| | | } |
| | | if (StringUtils.isBlank(content.toString())) { |
| | | return; |
| | | } |
| | | if (adjustValue == null || adjustValue.doubleValue() == 0) { |
| | | logger.info(title + "调整值为空,不产生建议"); |
| | | return; |
| | | } |
| | | if (gasAdjustMode.containsKey(title) && gasAdjustMode.get(title).equals(adjustValue.compareTo(BigDecimal.ZERO)) && |
| | | gasLastSugTime.containsKey(title) && (scheduleTime.getTime() - gasLastSugTime.get(title).getTime() <= Integer.valueOf(adjustRate).longValue() * 60 * 1000)) { |
| | | logger.info("调整建议在有效期内"); |
| | | return; |
| | | } |
| | | gasAdjustMode.put(title, adjustValue.compareTo(BigDecimal.ZERO)); |
| | | gasLastSugTime.put(title, scheduleTime); |
| | | |
| | | ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); |
| | | suggest.setTitle(title); |
| | | suggest.setContent(content.toString()); |
对比新文件 |
| | |
| | | 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); |
| | | logger.info("当前月天数:" + lengthOfMonth); |
| | | chartParamList.forEach(chartParam -> { |
| | | logger.info("指标编码:" + chartParam.getParamCode()); |
| | | List<ApiIndItemValueDTO> indItemlist = indItemApi.queryIndItemDefaultValue(chartParam.getParamCode()); |
| | | logger.info("查询到的指标值:" + indItemlist); |
| | | if (indItemlist != null && indItemlist.size() > 0) { |
| | | try { |
| | | ApiPointValueWriteDTO apiPointValueWriteDTO = new ApiPointValueWriteDTO(); |
| | | apiPointValueWriteDTO.setPointNo(chartParam.getParamValue()); |
| | | BigDecimal indValue = BigDecimal.valueOf((Double) indItemlist.get(0).getDataValue()); |
| | | logger.info("指标值:" + indValue); |
| | | BigDecimal pointValue = indValue.divide(new BigDecimal(lengthOfMonth), 3, RoundingMode.HALF_UP); |
| | | logger.info("测点值:" + pointValue); |
| | | apiPointValueWriteDTO.setValue(pointValue); |
| | | logger.info("写入测点值:" + apiPointValueWriteDTO); |
| | | dataPointApi.writePointRealValue(apiPointValueWriteDTO); |
| | | }catch (Exception ex){ |
| | | logger.error("SaveIndDataToPointDataTask运行异常" + ex); |
| | | ex.printStackTrace(); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | logger.info(params + "调度方案执行完成"); |
| | | } catch (Exception ex) { |
| | | logger.error("SaveIndDataToPointDataTask运行异常"); |
| | | ex.printStackTrace(); |
| | | } |
| | | logger.info("SaveIndDataToPointDataTask运行完成"); |
| | | } |
| | | } |
| | |
| | | String year = String.valueOf(date.getYear()); |
| | | paramsMap.put("clock", year); |
| | | logger.info("请求参数:" + JSON.toJSONString(paramsMap)); |
| | | String resp = HttpUtils.sendPost(QUERY_SEGMENTED_DATA_URL, JSON.toJSONString(paramsMap), accessToken); |
| | | String resp = HttpUtils.sendPostToken(QUERY_SEGMENTED_DATA_URL, JSON.toJSONString(paramsMap), accessToken); |
| | | logger.info("获取分段数据的返回值:" + resp); |
| | | JSONObject jsonObject = JSON.parseObject(resp); |
| | | List<ElectricityPriceSegmentedDTO> list = jsonObject.getJSONArray("data").toJavaList(ElectricityPriceSegmentedDTO.class); |
| | |
| | | cipher.init(Cipher.ENCRYPT_MODE, publicKey); |
| | | return Base64.getEncoder().encodeToString(cipher.doFinal(data.getBytes())); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.iailab.module.shasteel.mq.consumer; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | |
| | | private static String lastRunGasSchedule = ""; |
| | | |
| | | // 最早调度时间 |
| | | private static Date earliestScheduleTime = null; |
| | | /** |
| | | * 煤气调度调整方向 |
| | | * 1:调整值为正数;-1:调整值为负数 |
| | | */ |
| | | private static Map<String, Integer> gasAdjustMode = new HashMap<>(); |
| | | |
| | | /** |
| | | * 监听报警信息,执行调度 |
| | | * 煤气调度建议时间 |
| | | */ |
| | | private static Map<String, Date> gasLastSugTime = new HashMap<>(); |
| | | |
| | | /** |
| | | * 监听报警信息,执行煤气调度 |
| | | * |
| | | * @param message |
| | | */ |
| | | @RabbitListener(queues = QueueModelAlarmConfig.QUEUE_NAME) |
| | | public void listen(Message message) { |
| | | log.info("监听报警信息,执行煤气调度"); |
| | | String routingKey = message.getMessageProperties().getReceivedRoutingKey(); |
| | | log.info("routingKey:" + routingKey); |
| | | String messageBody = new String(message.getBody()); |
| | |
| | | log.info("过滤旧消息"); |
| | | return; |
| | | } |
| | | |
| | | // 判断predictTime 是否大于outTime,否则不执行调度 |
| | | if (earliestScheduleTime != null && predictTime.compareTo(earliestScheduleTime) < 0) { |
| | | if (!ModelPredictFinishConsumer.finishModuleMap.containsKey(predictTime.getTime())) { |
| | | log.info("finishModuleMap not containsKey:" + predictTime.getTime()); |
| | | return; |
| | | } |
| | | List<String> finishModuleList = ModelPredictFinishConsumer.finishModuleMap.get(predictTime.getTime()); |
| | | if (CollectionUtils.isEmpty(finishModuleList)) { |
| | | log.info("finishModuleList is empty"); |
| | | return; |
| | | } |
| | | if (!finishModuleList.contains(CommonConstant.NET_BFG) || !finishModuleList.contains(CommonConstant.NET_COG) || |
| | | !finishModuleList.contains(CommonConstant.NET_LDG)) { |
| | | log.info("finishModuleList:" + JSONArray.toJSONString(finishModuleList)); |
| | | log.info("等待全部预测完成"); |
| | | return; |
| | | } |
| | | log.info("已全部预测完成,清空finishModuleMap"); |
| | | ModelPredictFinishConsumer.finishModuleMap.clear(); |
| | | |
| | | List<AlarmMessageRespDTO> alarmList = JSONObject.parseArray(messageJson.get("alarmList").toString(),AlarmMessageRespDTO.class); |
| | | // 取出最小outTime |
| | | Date minOutTime = alarmList.stream().filter(e -> e.getOutTime() != null).map(AlarmMessageRespDTO::getOutTime).min(Date::compareTo).get(); |
| | | earliestScheduleTime = minOutTime; |
| | | |
| | | |
| | | // 查找需要执行的调度方案 |
| | | log.info("查找需要执行的调度方案"); |
| | | List<StScheduleSchemeDTO> scheduleSchemeList = mcsApi.listScheduleScheme(ScheduleTriggerMethodEnum.EVENT.getCode(), routingKey); |
| | | if (CollectionUtils.isEmpty(scheduleSchemeList)) { |
| | | log.info("routingKey:" + routingKey + ",调度方案为空。"); |
| | |
| | | log.info("runKey:" + runKey); |
| | | log.info("lastRunGasSchedule:" + lastRunGasSchedule); |
| | | if (lastRunGasSchedule.equals(runKey)) { |
| | | log.info("lastRunGasSchedule:" + lastRunGasSchedule + "已执行完成"); |
| | | continue; |
| | | } |
| | | lastRunGasSchedule = runKey; |
| | |
| | | mdkApi.scheduleModelOut(mdkScheduleRespDTO); |
| | | |
| | | // 保存调度建议 |
| | | saveScheduleSuggest("高炉煤气", result.get("adviceBFG"), "BFG", predictTime); |
| | | saveScheduleSuggest("焦炉煤气", result.get("adviceCOG"), "COG", predictTime); |
| | | saveScheduleSuggest("转炉5W+8W煤气柜", result.get("adviceLDG13W"), "LDG1", predictTime); |
| | | saveScheduleSuggest("宏发12W煤气柜", result.get("adviceLDG12W"), "LDG2", predictTime); |
| | | saveScheduleSuggest("转炉特钢煤气柜", result.get("adviceLDG12WT"), "LDGt", predictTime); |
| | | saveScheduleSuggest("高炉煤气", result.get("adviceBFG"), "BFG", predictTime, result.get("adjustValueBFG"), stScheduleSchemeDTO.getAdjustRate()); |
| | | saveScheduleSuggest("焦炉煤气", result.get("adviceCOG"), "COG", predictTime, result.get("adjustValueCOG"), stScheduleSchemeDTO.getAdjustRate()); |
| | | saveScheduleSuggest("转炉5W+8W煤气柜", result.get("adviceLDG13W"), "LDG1", predictTime, result.get("adjustValueLDG13W"), stScheduleSchemeDTO.getAdjustRate()); |
| | | saveScheduleSuggest("宏发12W煤气柜", result.get("adviceLDG12W"), "LDG2", predictTime, result.get("adjustValueLDG12W"), stScheduleSchemeDTO.getAdjustRate()); |
| | | saveScheduleSuggest("转炉特钢煤气柜", result.get("adviceLDG12WT"), "LDGt", predictTime, result.get("adjustValueLDG12WT"), stScheduleSchemeDTO.getAdjustRate()); |
| | | |
| | | // 模拟调整 |
| | | MdkPredictSimAdjustReqDTO simAdjustReqDTO = new MdkPredictSimAdjustReqDTO(); |
| | |
| | | } |
| | | } |
| | | |
| | | private void saveScheduleSuggest(String title, Object content, String scheduleObj, Date scheduleTime) { |
| | | /** |
| | | * 建议保持逻辑 |
| | | * <p> |
| | | * <p> |
| | | * BFG建议: |
| | | * 若触发第一条: |
| | | * 当前BFG建议 = adviceBFG |
| | | * 若后续BFG建议出现时间与当前BFG建议相差15分钟之内: |
| | | * 所后续BFG建议方向与当前BFG建议方向相反: |
| | | * 当前建议 = 后续BFG建议 |
| | | * 若不是: |
| | | * 当前建议保持不变 |
| | | * 若不是则: |
| | | * 当前建议 = 后续BFG建议 |
| | | * <p> |
| | | * COG建议: |
| | | * 若触发第一条: |
| | | * 当前COG建议 = adviceCOG |
| | | * 若后续COG建议出现时间与当前COG建议相差15分钟之内: |
| | | * 所后续COG建议方向与当前COG建议方向相反: |
| | | * 当前建议 = 后续COG建议 |
| | | * 若不是: |
| | | * 当前建议保持不变 |
| | | * 若不是则: |
| | | * 当前建议 = 后续COG建议 |
| | | * <p> |
| | | * LDG13W建议: |
| | | * 若触发第一条: |
| | | * 当前LDG13W建议 = adviceLDG13W |
| | | * 若后续LDG13W建议出现时间与当前LDG13W建议相差15分钟之内: |
| | | * 所后续LDG13W建议方向与当前LDG13W建议方向相反: |
| | | * 当前建议 = 后续LDG13W建议 |
| | | * 若不是: |
| | | * 当前建议保持不变 |
| | | * 若不是则: |
| | | * 当前建议 = 后续LDG13W建议 |
| | | * <p> |
| | | * LDG12W建议: |
| | | * 若触发第一条: |
| | | * 当前LDG12W建议 = adviceLDG12W |
| | | * 若后续LDG12W建议出现时间与当前LDG12W建议相差15分钟之内: |
| | | * 所后续LDG12W建议方向与当前LDG12W建议方向相反: |
| | | * 当前建议 = 后续LDG12W建议 |
| | | * 若不是: |
| | | * 当前建议保持不变 |
| | | * 若不是则: |
| | | * 当前建议 = 后续LDG12W建议 |
| | | * <p> |
| | | * LDG12WT建议: |
| | | * 若触发第一条: |
| | | * 当前LDG12WT建议 = adviceLDG12WT |
| | | * 若后续LDG12WT建议出现时间与当前LDG12WT建议相差15分钟之内: |
| | | * 所后续LDG12WT建议方向与当前LDG12WT建议方向相反: |
| | | * 当前建议 = 后续LDG12WT建议 |
| | | * 若不是: |
| | | * 当前建议保持不变 |
| | | * 若不是则: |
| | | * 当前建议 = 后续LDG12WT建议 |
| | | * |
| | | * @param title |
| | | * @param content |
| | | * @param scheduleObj |
| | | * @param scheduleTime |
| | | */ |
| | | private void saveScheduleSuggest(String title, Object content, String scheduleObj, Date scheduleTime, Object adjustObj, int adjustRate) { |
| | | if (content == null || StringUtils.isBlank(content.toString()) || "0".equals(content.toString())) { |
| | | log.info(title + "content为空"); |
| | | return; |
| | | } |
| | | if (adjustObj == null || StringUtils.isBlank(adjustObj.toString()) || "0".equals(adjustObj.toString())) { |
| | | log.info(title + "调整值为空,不产生建议"); |
| | | return; |
| | | } |
| | | BigDecimal adjustValue = new BigDecimal(adjustObj.toString()); |
| | | if (gasAdjustMode.containsKey(scheduleObj) && gasAdjustMode.get(scheduleObj).equals(adjustValue.compareTo(BigDecimal.ZERO)) && |
| | | gasLastSugTime.containsKey(scheduleObj) && (scheduleTime.getTime() - gasLastSugTime.get(scheduleObj).getTime() <= Integer.valueOf(adjustRate).longValue() * 60 * 1000)) { |
| | | log.info("调整建议在有效期内"); |
| | | return; |
| | | } |
| | | gasAdjustMode.put(scheduleObj, adjustValue.compareTo(BigDecimal.ZERO)); |
| | | gasLastSugTime.put(scheduleObj, scheduleTime); |
| | | ScheduleSuggestRespDTO suggest = new ScheduleSuggestRespDTO(); |
| | | suggest.setTitle(title); |
| | | suggest.setContent(content.toString()); |
| | | suggest.setAdjustValue(adjustValue); |
| | | suggest.setScheduleObj(scheduleObj); |
| | | suggest.setScheduleTime(scheduleTime); |
| | | suggest.setSort(0); |
| | |
| | | package com.iailab.module.shasteel.mq.consumer; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.model.api.mcs.McsApi; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Resource |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | private static String lastRunAlarm = ""; |
| | | private static Map<String, Long> lastRunTime = new ConcurrentHashMap<>(); |
| | | |
| | | public static Map<Long, List<String>> finishModuleMap = new ConcurrentHashMap<>(); |
| | | |
| | | /** |
| | | * 监听预测完成,产生预警消息 |
| | |
| | | } |
| | | // 预测时间 |
| | | Date predictTime = DateUtils.parse(messageJson.get("predictTime").toString(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
| | | // 预测模块/预测管网 |
| | | // 预测管网 |
| | | String moduleType = messageJson.get("moduleType").toString(); |
| | | if (moduleType.equals(CommonConstant.NET_BFG) || moduleType.equals(CommonConstant.NET_COG) || moduleType.equals(CommonConstant.NET_LDG1) || moduleType.equals(CommonConstant.NET_LDG2) || moduleType.equals(CommonConstant.NET_LDG3)) { |
| | | String runKey = "GasAlarm_" + predictTime.getTime(); |
| | | log.info("runKey:" + runKey); |
| | | log.info("lastRunAlarm:" + lastRunAlarm); |
| | | if (lastRunAlarm.equals(runKey)) { |
| | | if (!finishModuleMap.containsKey(predictTime.getTime())) { |
| | | List<String> mList = new ArrayList<>(); |
| | | finishModuleMap.put(predictTime.getTime(), mList); |
| | | } |
| | | finishModuleMap.get(predictTime.getTime()).add(moduleType); |
| | | log.info("finishModuleMap:" + JSONObject.toJSONString(finishModuleMap)); |
| | | |
| | | if (moduleType.equals(CommonConstant.NET_BFG) || moduleType.equals(CommonConstant.NET_COG) || |
| | | moduleType.equals(CommonConstant.NET_LDG) || |
| | | moduleType.equals(CommonConstant.NET_LDG1) || |
| | | moduleType.equals(CommonConstant.NET_LDG2) || |
| | | moduleType.equals(CommonConstant.NET_LDG3)) { |
| | | log.info("moduleType:" + moduleType); |
| | | if (lastRunTime.containsKey(moduleType) && lastRunTime.get(moduleType) == predictTime.getTime()) { |
| | | log.info("moduleType return"); |
| | | return; |
| | | } |
| | | lastRunAlarm = runKey; |
| | | |
| | | // 预警信息列表 |
| | | List<AlarmMessageRespDTO> alarmList = new ArrayList<>(); |
| | | // 根据管网查询相关预警配置 |
| | | lastRunTime.put(moduleType, predictTime.getTime()); |
| | | log.info("lastRunTime=" + JSONObject.toJSONString(lastRunTime)); |
| | | log.info("开始处理预警"); |
| | | Map<String,Object> params = new HashMap<>(); |
| | | params.put("alarmObj",moduleType); |
| | | List<AlarmConfigRespDTO> configList = mcsApi.listAlarmConfig(params); |
| | |
| | | log.info("AlarmConfigList is empty"); |
| | | return; |
| | | } |
| | | log.info("configList=" + JSONArray.toJSONString(configList)); |
| | | |
| | | // 预警信息列表 |
| | | List<AlarmMessageRespDTO> alarmList = new ArrayList<>(); |
| | | List<String> outputIdList = configList.stream().map(item -> { |
| | | return item.getOutId(); |
| | | }).collect(Collectors.toList()); |
| | |
| | | } |
| | | outerLoop: |
| | | for (AlarmConfigRespDTO configItem : configList) { |
| | | log.info("configItem: " + configItem); |
| | | log.info("AlarmConfigItem: " + configItem); |
| | | List<Object[]> result = preData.get(configItem.getOutId()); |
| | | if (CollectionUtils.isEmpty(result)) { |
| | | continue; |
| | | } |
| | | log.info("AlarmPreData: " + JSONArray.toJSONString(result)); |
| | | |
| | | // 对比预测值是否超限 |
| | | int toIndex = result.size(); |
| | |
| | | if (dataValue.compareTo(configItem.getLowerLimit()) >= 0 && dataValue.compareTo(configItem.getUpperLimit()) <= 0) { |
| | | continue; |
| | | } |
| | | log.info("AlarmOutValue: " + dataValue); |
| | | // 预警记录 |
| | | AlarmMessageRespDTO alarmMessage = new AlarmMessageRespDTO(); |
| | | alarmMessage.setConfigId(configItem.getId()); |
| | |
| | | content.append(","); |
| | | content.append("即将"); |
| | | if (dataValue.compareTo(configItem.getLowerLimit()) < 0) { |
| | | content.append("低与下限"); |
| | | content.append("低于下限"); |
| | | alarmMessage.setAlarmType(CommonConstant.EXCEEDING_LOWER_LIMIT); |
| | | |
| | | } else if (dataValue.compareTo(configItem.getUpperLimit()) > 0) { |
| | |
| | | } |
| | | } |
| | | |
| | | if (!CollectionUtils.isEmpty(alarmList)) { |
| | | if (CollectionUtils.isEmpty(alarmList)) { |
| | | log.info("alarmList is empty"); |
| | | return; |
| | | } |
| | | log.info("发送预警消息"); |
| | | Map<String, Object> msg = new HashMap<>(2); |
| | | msg.put("predictTime", DateUtils.format(predictTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); |
| | | msg.put("alarmList", alarmList); |
| | | msg.put("moduleType", moduleType); |
| | | rabbitTemplate.convertAndSend(RoutingConstant.EXCHANGE, RoutingConstant.Iailab_Model_Alarm, msg); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | } |