From f44f00034483637a48c4cfedf7b6e93b83c8c6af Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期四, 30 十月 2025 03:36:24 +0800
Subject: [PATCH] 1、 中空理片笼任务优化:进片调度增加限制,避免重复生成调度任务
---
hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/PlcTemperingGlassTask.java | 210 ++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 155 insertions(+), 55 deletions(-)
diff --git a/hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/PlcTemperingGlassTask.java b/hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/PlcTemperingGlassTask.java
index f7e63e5..9e4c69a 100644
--- a/hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/PlcTemperingGlassTask.java
+++ b/hangzhoumesParent/moduleService/TemperingGlassModule/src/main/java/com/mes/job/PlcTemperingGlassTask.java
@@ -1,15 +1,30 @@
package com.mes.job;
+
+import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONObject;
-import com.mes.temperingglass.service.TemperingGlassInfoService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.github.xingshuangs.iot.protocol.s7.serializer.S7Serializer;
+import com.mes.common.config.Const;
+import com.mes.damage.service.DamageService;
+import com.mes.largenscreen.entity.PieChartVO;
+import com.mes.s7.entity.S7DataGHTwo;
import com.mes.temperingglass.entity.TemperingGlassInfo;
-import com.mes.tools.WebSocketServer;
+import com.mes.temperingglass.service.TemperingGlassInfoService;
+import com.mes.tools.WebSocketUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.time.ZoneId;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import java.util.stream.Collectors;
/**
* @author SNG-010
@@ -19,66 +34,151 @@
public class PlcTemperingGlassTask {
@Autowired
- private TemperingGlassInfoService temperingAgoService;
+ private TemperingGlassInfoService temperingGlassInfoService;
+ @Autowired
+ private DamageService damageService;
+
+ @Autowired
+ @Qualifier("s7SerializerGHTwo")
+ private S7Serializer s7SerializerGHTwo;
+ @Resource
+ private WebSocketUtils webSocketUtils;
+
+
+ @Scheduled(fixedDelay = 1000)
+ public void temperingGlassHome() {
+ JSONObject jsonObject = new JSONObject();
+ //姝e湪绛夊緟杩涚墖鐨勭幓鐠�
+ List<TemperingGlassInfo> waitingGlass = new ArrayList<>();
+ try {
+ waitingGlass = selectWaitingGlassByOpc();
+ if (CollectionUtil.isNotEmpty(waitingGlass)) {
+ jsonObject.append("waitingGlass", waitingGlass);
+ }
+ } catch (Exception e) {
+ log.info("閽㈠寲鍓嶈幏鍙栧紓甯革細{}", e.getMessage());
+ }
+ try {
+ List<TemperingGlassInfo> intoGlass = selectIntoGlass(waitingGlass);
+ if (CollectionUtil.isNotEmpty(intoGlass)) {
+ for (int i = 0; i < intoGlass.size(); i++) {
+ String jsonName = "intoGlass";
+ if (i != 0) {
+ jsonName = jsonName + i;
+ }
+ jsonObject.append(jsonName, temperingGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>()
+ .eq(TemperingGlassInfo::getEngineerId, intoGlass.get(i).getEngineerId())
+ .eq(TemperingGlassInfo::getTemperingLayoutId, intoGlass.get(i).getTemperingLayoutId())));
+ }
+
+ }
+ } catch (Exception e) {
+ log.info("閽㈠寲鍓嶈幏鍙栧紓甯革細{}", e.getMessage());
+ }
+ try {
+ //鍑虹倝鍚庣殑鐜荤拑
+ List<TemperingGlassInfo> outGlass = temperingGlassInfoService.selectOutGlass();
+ if (CollectionUtil.isNotEmpty(outGlass)) {
+ jsonObject.append("outGlass", outGlass);
+ }
+ } catch (Exception e) {
+ log.info("閽㈠寲鍓嶈幏鍙栧紓甯革細{}", e.getMessage());
+ }
+ webSocketUtils.sendToWeb("temperingGlass", jsonObject);
+
+ }
+
+ @Scheduled(fixedDelay = 1000)
+ public void temperingIsRun() {
+ JSONObject jsonObject = new JSONObject();
+ //姝e湪杩涜鐨勪换鍔�
+ List<TemperingGlassInfo> temperingTaskType = temperingGlassInfoService.selectTaskType();
+ jsonObject.append("temperingTaskType", temperingTaskType);
+ webSocketUtils.sendToWeb("temperingIsRun", jsonObject);
+ }
+
+ @Scheduled(fixedDelay = 1000)
+ public void largenScreen() {
+ JSONObject jsonObject = new JSONObject();
+ //澶у睆閽㈠寲淇℃伅
+ Date startOfToday = new Date(LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli());
+
+ Integer putGlass = temperingGlassInfoService.count(
+ new QueryWrapper<TemperingGlassInfo>()
+ .eq("state", Const.TEMPERING_NEW)
+ .gt("create_time", startOfToday)
+ );
+ jsonObject.append("temperingTaskType", putGlass);
+ //澶у睆閽㈠寲淇℃伅
+ List<TemperingGlassInfo> temperingGlassInfoList = temperingGlassInfoService.list(
+ new QueryWrapper<TemperingGlassInfo>()
+ .select("engineer_id", "tempering_layout_id")
+ .eq("state", Const.TEMPERING_START)
+ .gt("create_time", startOfToday)
+ .groupBy("engineer_id", "tempering_layout_id")
+ );
+ jsonObject.append("temperingGlassInfoList", temperingGlassInfoList.size());
+ //澶у睆閽㈠寲淇℃伅
+ List<TemperingGlassInfo> temperingGlassInfoInList = temperingGlassInfoService.list(
+ new LambdaQueryWrapper<TemperingGlassInfo>()
+ .select(TemperingGlassInfo::getEngineerId, TemperingGlassInfo::getTemperingLayoutId) // 閫夋嫨瑕佸幓閲嶇殑瀛楁
+ .eq(TemperingGlassInfo::getState, Const.TEMPERING_DROP)
+ .groupBy(TemperingGlassInfo::getEngineerId, TemperingGlassInfo::getTemperingLayoutId) // 鎸� engineerId 鍜� temperingLayoutId 鍒嗙粍
+ );
+ jsonObject.append("temperingGlassInfoInList", temperingGlassInfoInList.size());
+ //閽㈠寲楗煎浘鏁版嵁
+ List<PieChartVO> pieChartVOS = temperingGlassInfoService.queryPieChart();
+ jsonObject.append("pieChartVOS", pieChartVOS);
+ webSocketUtils.sendToWeb("largenScreen", jsonObject);
+ }
+
+
/**
* fixedRate : 涓婁竴涓皟鐢ㄥ紑濮嬪悗鍐嶆璋冪敤鐨勫欢鏃讹紙涓嶇敤绛夊緟涓婁竴娆¤皟鐢ㄥ畬鎴愶級
* fixedDelay : 涓婁竴涓皟鐢ㄧ粨鏉熷悗鍐嶆璋冪敤鐨勫欢鏃�
*/
-
- @Scheduled(fixedDelay = 1000)
- public void temperingGlassHome(){
- JSONObject jsonObject = new JSONObject();
- //姝e湪绛夊緟杩涚墖鐨勭幓鐠�
- List<TemperingGlassInfo> waitingGlass = temperingAgoService.selectWaitingGlass();
- jsonObject.append("waitingGlass", waitingGlass);
- //鑾峰彇鏁村湪鐐変腑鐨勪袱涓増鍥緄d
- List<TemperingGlassInfo> layoutId = temperingAgoService.selectLayoutId();
- //杩涚倝涓殑鐜荤拑
- if(!layoutId.isEmpty()) {
- List<TemperingGlassInfo> intoGlass = temperingAgoService.selectIntoGlass(layoutId.get(0));
- jsonObject.append("intoGlass", intoGlass);
- //杩涚倝涓殑绗簩涓増鍥�
- if (layoutId.size() > 1) {
- List<TemperingGlassInfo> intoGlass2 = temperingAgoService.selectIntoGlass(layoutId.get(1));
- jsonObject.append("intoGlass2", intoGlass2);
- }
- }
- //鍑虹倝鍚庣殑鐜荤拑
- List<TemperingGlassInfo> outGlass = temperingAgoService.selectOutGlass();
- jsonObject.append("outGlass", outGlass);
- //杩囨棆杞彴閽㈠寲鍚庣殑鐜荤拑
- List<TemperingGlassInfo> overGlass = temperingAgoService.selectOverGlass();
-
- jsonObject.append("overGlass", overGlass);
-
- ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("temperingGlass");
- if (sendwServer != null) {
- for (WebSocketServer webserver : sendwServer) {
- if (webserver != null) {
- webserver.sendMessage(jsonObject.toString());
- } else {
- log.info("Home is closed");
+ private List<TemperingGlassInfo> selectWaitingGlassByOpc() {
+ //鑾峰彇绛夊緟杩涚倝涓殑鐜荤拑淇℃伅
+ try {
+ S7DataGHTwo s7DataGHTwo = s7SerializerGHTwo.read(S7DataGHTwo.class);
+ String engineerEntity = s7DataGHTwo.getF09EngineerId();
+ Integer temperingLayoutIdEntity = s7DataGHTwo.getF09TemperingLayoutId();
+ if (null == engineerEntity || null == temperingLayoutIdEntity) {
+ engineerEntity = s7DataGHTwo.getF08EngineerId();
+ temperingLayoutIdEntity = s7DataGHTwo.getF08TemperingLayoutId();
+ if (null == engineerEntity || null == temperingLayoutIdEntity) {
+ log.info("鑾峰彇鍙傛暟寮傚父锛岀粨鏉熸湰娆′换鍔�");
+ return new ArrayList<>();
}
}
- }
- }
- @Scheduled(fixedDelay = 1000)
- public void temperingIsRun(){
- JSONObject jsonObject = new JSONObject();
- //姝e湪杩涜鐨勪换鍔�
- List<TemperingGlassInfo>temperingTaskType=temperingAgoService.selectTaskType();
- jsonObject.append("temperingTaskType", temperingTaskType);
- ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("isRun");
- if (sendwServer != null) {
- for (WebSocketServer webserver : sendwServer) {
- if (webserver != null) {
- webserver.sendMessage(jsonObject.toString());
- } else {
- log.info("Home is closed");
- }
- }
+ return temperingGlassInfoService.list(new LambdaQueryWrapper<TemperingGlassInfo>()
+ .eq(TemperingGlassInfo::getEngineerId, engineerEntity)
+ .eq(TemperingGlassInfo::getTemperingLayoutId, temperingLayoutIdEntity));
+ } catch (Exception e) {
+ log.info("鑾峰彇閽㈠寲鍙傛暟寮傚父锛歿}", e);
+ return new ArrayList<>();
}
}
-
+ /**
+ * 鑾峰彇姝e湪閽㈠寲鐨勭増鍥句俊鎭細鑾峰彇3鐐夊凡缁忔憜濂界殑鐜荤拑灏忕墖锛屾帓闄ゆ鍦ㄦ憜鐨�
+ *
+ * @param list
+ * @return
+ */
+ private List<TemperingGlassInfo> selectIntoGlass(List<TemperingGlassInfo> list) {
+ List<TemperingGlassInfo> temperingGlassInfoList = temperingGlassInfoService.queryEngineerAndLayoutId();
+ log.info("閽㈠寲涓幏鍙栧埌鐨勬暟鎹负{}", temperingGlassInfoList);
+ if (CollectionUtil.isEmpty(temperingGlassInfoList)) {
+ return new ArrayList<>();
+ }
+ if (CollectionUtil.isEmpty(list)) {
+ return temperingGlassInfoList;
+ } else {
+ String engineerId = list.get(0).getEngineerId();
+ int temperingLayoutId = list.get(0).getTemperingLayoutId();
+ List<TemperingGlassInfo> tempList = temperingGlassInfoList.stream().filter(e -> !(e.getEngineerId().equals(engineerId) && temperingLayoutId == e.getTemperingLayoutId())).collect(Collectors.toList());
+ return tempList;
+ }
+ }
}
\ No newline at end of file
--
Gitblit v1.8.0