From eae026a90011e77c1a3947021c87a2eea786d1b1 Mon Sep 17 00:00:00 2001
From: ZengTao <2773468879@qq.com>
Date: 星期六, 11 十月 2025 13:57:35 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/job/PlcLoadGlassTask.java | 152 +++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 123 insertions(+), 29 deletions(-)
diff --git a/hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/job/PlcLoadGlassTask.java b/hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/job/PlcLoadGlassTask.java
index 193de19..0518590 100644
--- a/hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/job/PlcLoadGlassTask.java
+++ b/hangzhoumesParent/moduleService/LoadGlassModule/src/main/java/com/mes/job/PlcLoadGlassTask.java
@@ -1,17 +1,30 @@
package com.mes.job;
+import cn.hutool.json.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mes.common.S7object;
import com.mes.device.PlcParameterObject;
import com.mes.engineering.entity.Engineering;
import com.mes.engineering.service.EngineeringService;
+import com.mes.opctask.entity.LoadGlassDeviceTask;
+import com.mes.opctask.service.LoadGlassDeviceTaskService;
+import com.mes.pp.service.OptimizeProjectService;
+import com.mes.rawglassdetails.entity.RawGlassStorageDetails;
+import com.mes.rawglassstation.service.RawGlassStorageStationService;
+import com.mes.tools.WebSocketUtils;
import com.mes.uppattenusage.entity.UpPattenUsage;
import com.mes.uppattenusage.service.UpPattenUsageService;
+import com.mes.utils.RedisUtil;
import com.mes.workstation.entity.UpWorkstation;
import com.mes.workstation.service.UpWorkstationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.stream.Collectors;
/**
* @author SNG-010
@@ -26,44 +39,65 @@
private EngineeringService engineeringService;
@Autowired
private UpPattenUsageService upPattenUsageService;
+ @Autowired
+ private OptimizeProjectService optimizeProjectService;
+ @Autowired
+ RedisUtil redisUtil;
+ @Resource
+ private LoadGlassDeviceTaskService loadGlassDeviceTaskService;
+ @Resource
+ private RawGlassStorageStationService rawGlassStorageStationService;
PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
+
+ private static final String LOAD_GLASS_DEVICE_ONE_TASK = "load_glass_device_one_task";
+
+ private static final String LOAD_GLASS_DEVICE_TWO_TASK = "load_glass_device_two_task";
+
+ @Resource
+ private WebSocketUtils webSocketUtils;
/**
* fixedRate : 涓婁竴涓皟鐢ㄥ紑濮嬪悗鍐嶆璋冪敤鐨勫欢鏃讹紙涓嶇敤绛夊緟涓婁竴娆¤皟鐢ㄥ畬鎴愶級
* fixedDelay : 涓婁竴涓皟鐢ㄧ粨鏉熷悗鍐嶆璋冪敤鐨勫欢鏃�
*/
- @Scheduled(fixedDelay = 3000000)
+// @Scheduled(fixedDelay = 300)
public void plcLoadGlassTask() throws InterruptedException {
try {
+ //鑾峰彇鑱旀満鐘舵��
+ String inkageStatus = plcParameterObject.getPlcParameter("InkageStatus").getValue();
//鑾峰彇鏄惁鏈変笂鐗囪姹�
String loadRequest = plcParameterObject.getPlcParameter("loadRequest").getValue();
+ //mes鐘舵��
String mesToPlc = plcParameterObject.getPlcParameter("MesToPlc").getValue();
- //鍒ゆ柇寮�濮嬩笂鐗囩殑宸ョ▼鍙�
- Engineering engineering = engineeringService.selectInitiate(1);
- if ("1".equals(loadRequest) && engineering != null) {
- log.info("寮�濮嬩笂鐗囦换鍔�");
- UpPattenUsage upPattenUsage = upWorkstationService.selectPriority(engineering);
- log.info("褰撴湁璇锋眰鏃舵煡璇㈠綋鍓嶄笂鐗囬『搴忕殑鐜荤拑淇℃伅{}", upPattenUsage);
- UpWorkstation upwork = upWorkstationService.selectWorkstation(upPattenUsage);
- log.info("绗﹀悎鐨勫昂瀵哥殑宸ヤ綅鐜荤拑锛歿}", upwork);
- if (upwork != null) {
- int workId = upwork.getWorkstationId();//宸ヤ綅id
- double width = upwork.getPatternWidth();//瀹藉害
- double height = upwork.getPatternHeight();//楂樺害
- S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("WorkId").getAddress(), workId);
- S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("GlassWidth").getAddress(), (long) width);
- S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("GlassHeight").getAddress(), (long) height);
- S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 1);
- //鏇存敼涓婄墖琛ㄧ姸鎬�
- upPattenUsageService.updateUpPattenUsageState(upPattenUsage, workId);
+ if ("1".equals(inkageStatus) && "1".equals(loadRequest)) {
+ //鍒ゆ柇寮�濮嬩笂鐗囩殑宸ョ▼鍙�
+ Engineering engineering = engineeringService.selectInitiate(1);
+ if (engineering != null) {
+ log.info("寮�濮嬩笂鐗囦换鍔�");
+ UpPattenUsage upPattenUsage = upWorkstationService.selectPriority(engineering);
+ log.info("褰撴湁璇锋眰鏃舵煡璇㈠綋鍓嶄笂鐗囬『搴忕殑鐜荤拑淇℃伅{}", upPattenUsage);
+ UpWorkstation upwork = upWorkstationService.selectWorkstation(upPattenUsage);
+ log.info("绗﹀悎鐨勫昂瀵哥殑宸ヤ綅鐜荤拑锛歿}", upwork);
+ if (upwork != null) {
+ int workId = upwork.getWorkstationId();//宸ヤ綅id
+ double width = upwork.getPatternWidth();//瀹藉害
+ double height = upwork.getPatternHeight();//楂樺害
+ S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("WorkId").getAddress(), workId);
+ S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("GlassWidth").getAddress(), (int) width);
+ S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("GlassHeight").getAddress(), (int) height);
+ S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 1);
+ //鏇存敼涓婄墖琛ㄧ姸鎬�
+ upPattenUsageService.updateUpPattenUsageState(upPattenUsage, workId);
+ }
}
+
}
- if("1".equals(mesToPlc)&& "0".equals(loadRequest)){
+ if ("1".equals(mesToPlc) && "0".equals(loadRequest)) {
//璇锋眰瀛椾负闆舵椂锛屼换鍔″瓧娓呴浂
- S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 0);
+ S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("MesToPlc").getAddress(), 0);
}
//鎵ц鍚庝紤鐪�300姣
//Thread.sleep(300);
@@ -72,8 +106,8 @@
}
}
- @Scheduled(fixedDelay = 30000000)
- public void plcLoadGlassReport(){
+ // @Scheduled(fixedDelay = 300)
+ public void plcLoadGlassReport() {
//鑾峰彇鏄惁鏈夋眹鎶�
String loadStatus = plcParameterObject.getPlcParameter("PlcStatus").getValue();
if (loadStatus != null) {
@@ -81,7 +115,8 @@
switch (loadStatus) {
case "1":
log.info("鏀跺埌姹囨姤浠诲姟瀹屾垚");
- S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlcStatus").getAddress(), 1);
+ //鍑忓皯宸ヤ綅鏁伴噺,瀹屾垚浠诲姟鐘舵��
+ overTask(loadStatus, 100);
break;
case "2":
log.info("鏀跺埌姹囨姤鏈畬鎴愪换鍔�");
@@ -93,15 +128,70 @@
overTask(loadStatus, 0);
break;
case "0":
- log.info("鏀跺埌姹囨姤娓�0鐘舵��");
- //鍑忓皯宸ヤ綅鏁伴噺,瀹屾垚浠诲姟鐘舵��
- overTask(loadStatus, 100);
+ S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("MesToPlcStatus").getAddress(), 0);
break;
}
}
}
- public void overTask(String loadStatus, int state) {
+ @Scheduled(fixedDelay = 10000)
+ public void loadOneGlass() {
+ loadGlassChild("loadGlassRequestOne", 5, LOAD_GLASS_DEVICE_ONE_TASK, "loadGlassOne");
+ }
+
+ @Scheduled(fixedDelay = 10000)
+ public void loadTwoGlass() {
+ loadGlassChild("loadGlassRequestTwo", 6, LOAD_GLASS_DEVICE_TWO_TASK, "loadGlassTwo");
+ }
+
+
+ public String loadGlassChild(String redisRequest, int stationCell, String tableName, String webSocketName) {
+ try {
+ JSONObject jsonObject = new JSONObject();
+ //褰撳墠绾胯矾姝e湪鎵ц鐨勫伐绋�
+ Engineering engineering = engineeringService.getOne(new LambdaQueryWrapper<Engineering>().eq(Engineering::getStationCell, stationCell)
+ .eq(Engineering::getState, 1).last("limit 1"));
+ if (null != engineering) {
+ jsonObject.append("engineering", engineering);
+ }
+ //鑾峰彇褰撳墠绾胯矾姝e湪鎵ц鐨勫伐绋嬪師鐗囦俊鎭�
+ Engineering request = redisUtil.getCacheObject(redisRequest);
+ if (request == null) {
+ request = new Engineering();
+ request.setStationCell(stationCell);
+ }
+ List<UpPattenUsage> upPattenUsages = upPattenUsageService.selectLoadTask(request);
+ jsonObject.append("upPattenUsages", upPattenUsages);
+
+ //鑱旀満鐘舵��
+ LoadGlassDeviceTask LoadTask = loadGlassDeviceTaskService.queryTaskMessage(tableName);
+ jsonObject.append("inkageState", LoadTask.getInkageState());
+ //宸ヤ綅淇℃伅
+ List<RawGlassStorageDetails> rawGlassStorageDetailList = rawGlassStorageStationService.listRawGlassDetails();
+ List<RawGlassStorageDetails> stationList = rawGlassStorageDetailList.stream().filter(item -> item.getDeviceId() == stationCell).collect(Collectors.toList());
+ jsonObject.append("stationList", stationList);
+
+ webSocketUtils.sendToWeb(webSocketName, jsonObject);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return "success";
+ }
+
+
+ // @Scheduled(fixedDelay = 5000)
+ public void loadGlassStatus() {
+ JSONObject jsonObject = new JSONObject();
+ //姝e湪杩涜鐨勪换鍔�
+ String inkageStatus = plcParameterObject.getPlcParameter("InkageStatus").getValue();
+// String inkageStatus ="1";
+ jsonObject.append("InkageStatus", inkageStatus);
+ webSocketUtils.sendToWeb("loadGlass", jsonObject);
+ }
+
+
+ public void overTask(String loadStatus, int state) {
+
UpPattenUsage upPattenUsage = upPattenUsageService.selectOverTask();
if (upPattenUsage != null) {
log.info("鏀跺埌姹囨姤娓厈}鐘舵��", loadStatus);
@@ -109,8 +199,12 @@
upWorkstationService.reduceWorkstationNumber(upPattenUsage.getState());
//瀹屾垚涓婄墖琛ㄧ姸鎬�
upPattenUsageService.updateUpPattenUsageState(upPattenUsage, state);
- S7object.getinstance().plccontrol.writetime(plcParameterObject.getPlcParameter("MesToPlcStatus").getAddress(), 0);
+ //鍒ゆ柇鏄惁鏄渶鍚庝竴鍧楃幓鐠�
+ UpPattenUsage sequence = upPattenUsageService.selectSequence(upPattenUsage);
+ //濡傛灉鏄渶鍚庝竴鍧楁椂瀹屾垚宸ョ▼浠诲姟
+ optimizeProjectService.overTask(sequence, 300);
}
+ S7object.getinstance().plccontrol.writeWord(plcParameterObject.getPlcParameter("MesToPlcStatus").getAddress(), 1);
}
}
\ No newline at end of file
--
Gitblit v1.8.0