From 8d58c40af40493bd5f066cbfdb1ffd9f113c22fc Mon Sep 17 00:00:00 2001
From: 严智鑫 <test>
Date: 星期三, 03 九月 2025 16:37:21 +0800
Subject: [PATCH] 1.前端推数据使用了最新的webSokect客户现场总是掉线,修改为接口方式 2.设备交互整体增加异常处理以及PLC连接方式改为短连接
---
JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/MachineTask.java | 397 +++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 277 insertions(+), 120 deletions(-)
diff --git a/JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/MachineTask.java b/JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/MachineTask.java
index 680d651..5bced79 100644
--- a/JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/MachineTask.java
+++ b/JiuMuMesParent/moduleService/DeviceInteractionModule/src/main/java/com/mes/job/MachineTask.java
@@ -1,29 +1,27 @@
package com.mes.job;
import cn.hutool.json.JSONObject;
-import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
-import com.mes.common.S7objectFlipSlice;
-import com.mes.common.S7objectMachine;
-import com.mes.common.S7objectMarking;
-import com.mes.device.PlcParameterInfo;
-import com.mes.device.PlcParameterObject;
-import com.mes.md.entity.Machine;
-import com.mes.md.entity.Tasking;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import com.mes.md.entity.*;
import com.mes.md.mapper.GlassInfoMapper;
import com.mes.md.mapper.MachineMapper;
import com.mes.md.mapper.TaskingMapper;
-import com.mes.md.service.TaskingService;
-import com.mes.tools.WebSocketServer;
+import com.mes.md.service.*;
+import com.mes.websocket.WebSocketServer;
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.ArrayList;
import java.util.List;
+import java.util.Map;
/**
* 鑷姩鎵撴爣鏈�
+ *
* @Author : yanzhxiin
* @Date: 2024/8/20 11:19
* @Description:
@@ -41,128 +39,287 @@
@Autowired
TaskingService taskingService;
@Autowired
+ ProjectService projectService;
+ @Autowired
+ PrimitiveTaskService primitiveTaskService;
+ @Autowired
+ KBBTJPDrawingBPService kBBTJPDrawingBPService;
+ @Autowired
+ LineConfigurationService lineConfigurationService;
+ @Resource
+ WebSocketServer webSocketServer;
+ @Autowired
private GlassInfoMapper glassInfoMapper;
- public int a =1;
- public S7objectMachine s7objectMachine;
+ public List<Map> sendRecords = new ArrayList<>();
+ private List<Machine> machineListLoad;
+ private List<Machine> machineListEdging;
+ private List<Machine> machineListFlipSlice;
+ private List<Machine> machineListMarking;
+ private List<Machine> machineListSilkScreen;
+ private List<Machine> machineListRotate;
+ private List<Machine> machineListGlueDispenser;
+ private List<Machine> machineListScanQrCode;
+ private List<Machine> machineListLamination;
- //@Scheduled(fixedDelay = 1000)
- public void plcMachineTask() {
- Long machineId=12L;
- Machine machine=machineMapper.selectById(machineId);
- if (s7objectMachine==null){
- s7objectMachine=new S7objectMachine(machine.getIp(),machine.getPort(),"PlcMarking", EPlcType.S1500);
- s7objectMachine.start();
- }
- PlcParameterObject plcParameterObject = s7objectMachine.PlcMesObject;
- PlcParameterInfo plcRequest =plcParameterObject.getPlcParameter("plcRequest");//璇锋眰瀛�
- PlcParameterInfo plcRequestID =plcParameterObject.getPlcParameter("plcRequestID");//璇锋眰ID
- PlcParameterInfo mesSend =plcParameterObject.getPlcParameter("mesSend");//鍙戦�佸瓧
- PlcParameterInfo isMark =plcParameterObject.getPlcParameter("isMark");//鍙戦�両D銆�0 涓嶆墦鏍囷紝1鏍囧噯妯″紡锛�2瀹氬埗妯″紡銆�
- PlcParameterInfo drawingMark =plcParameterObject.getPlcParameter("drawingMark");//鎵撴爣鍥剧焊鍦板潃
- PlcParameterInfo lengthOutOfService =plcParameterObject.getPlcParameter("length(OutOfService)");//闀�
- PlcParameterInfo widthOutOfService =plcParameterObject.getPlcParameter("width(OutOfService)");//瀹�
- PlcParameterInfo markingMode =plcParameterObject.getPlcParameter("markingMode");//
-
- PlcParameterInfo plcReport =plcParameterObject.getPlcParameter("plcReport");//姹囨姤瀛�
- PlcParameterInfo plcReportID =plcParameterObject.getPlcParameter("plcReportID");//姹囨姤ID
- PlcParameterInfo mesConfirm =plcParameterObject.getPlcParameter("mesConfirm");//纭瀛�
- PlcParameterInfo mesConfirmID =plcParameterObject.getPlcParameter("mesConfirmID");//纭ID
-
- String str=S7objectMarking.getinstance().plccontrol.readString("DB14.30");
-
- //String width=S7objectMarking.getinstance().plccontrol.readWord(widthOutOfService.getAddress());
- log.info("plcRequest:{},plcRequestID:{},mesSend:{},mesSendID:{},drawingMark:{}," +
- "plcReport:{},plcReportID:{},mesConfirm:{},mesConfirmID:{}"
- ,plcRequest.getValue(),plcRequestID.getValue(),mesSend.getValue(),isMark.getValue(),drawingMark.getValue(),
- plcReport.getValue(),plcReportID.getValue(),mesConfirm.getValue(),mesConfirmID.getValue());
- if ("0".equals(plcRequest.getValue())&&"1".equals(mesSend.getValue())) {
- //鍙戦�佸瓧缃�0
- log.info("1.鍙戦�佸瓧缃浂,娓呴櫎涓婃鍙戦�佺殑鏁版嵁{},{},{},{},{}"
- ,markingMode.getValue()
- ,isMark.getValue()
- ,lengthOutOfService.getValue()
- ,widthOutOfService.getValue()
- ,mesSend.getValue());
- //S7objectMarking.getinstance().plccontrol.writeString(drawingMark.getAddress(),"");
- S7objectMarking.getinstance().plccontrol.writeWord(markingMode.getAddress(), 0);
- S7objectMarking.getinstance().plccontrol.writeWord(lengthOutOfService.getAddress(), 0);
- S7objectMarking.getinstance().plccontrol.writeWord(widthOutOfService.getAddress(), 0);
- S7objectMarking.getinstance().plccontrol.writeWord(isMark.getAddress(), 0);
- S7objectMarking.getinstance().plccontrol.writeWord(mesSend.getAddress(), 0);
- return;
- }
- if ("0".equals(plcReport.getValue())&&"1".equals(mesConfirm.getValue())) {
- log.info("2.纭瀛楃疆闆�");
- //鍙戦�佸瓧缃�0
- S7objectMarking.getinstance().plccontrol.writeWord(mesConfirm.getAddress(), 0);
- return;
- }
- if("1".equals(plcReport.getValue())&&"0".equals(mesConfirm.getValue())){
- int finishCount=taskingService.finishMachineTask(machine);
- log.info("3銆佷换鍔″畬鎴�");
- if(finishCount>0){//鏈変换鍔�
- S7objectMarking.getinstance().plccontrol.writeWord(mesConfirm.getAddress(), 1);
- return;
+ //鏈烘鎵�
+ //@Scheduled(fixedDelay = 500)
+ public void loadTasks() {
+ try {
+ machineListLoad = machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName, "涓婄墖"));
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.append("sessionMapName", "loadTask");
+ for (Machine machine : machineListLoad) {
+ JSONObject jsonObjectItem = new JSONObject();
+ //鏍囧噯妯″紡 鎵惧凡棰嗗彇鏈畬鎴愮殑绗竴鏉′换鍔�
+ LineConfiguration lineConfiguration = lineConfigurationService.machineLineConfiguration(machine);
+ //姝ょ嚎璺凡棰嗗彇鐨勪换鍔�
+ List<PrimitiveTask> findPrimitiveTasking = primitiveTaskService.findPrimitiveTasking(machine, lineConfiguration.getLineId());
+ //姝ょ嚎璺湭棰嗗彇鐨勪换鍔� 鏈湴
+ //List<PrimitiveTask> findPrimitiveTask=primitiveTaskService.findPrimitiveTaskNotFinish();
+ //姝ょ嚎璺湭棰嗗彇鐨勪换鍔� 瀹㈡埛鏁版嵁搴�
+ List<KBBTJPDrawingBP> list = kBBTJPDrawingBPService.notReceiveKBBTJPDrawingBP();
+ jsonObjectItem.append("findPrimitiveTask", list);
+ jsonObjectItem.append("findPrimitiveTasking", findPrimitiveTasking);
+ //jsonObject.append("findPrimitiveTask", findPrimitiveTask);
+ jsonObjectItem.append("machine", machine);
+ jsonObjectItem.append("sendRecords", sendRecords);
+ jsonObject.append(machine.getId().toString(), jsonObjectItem);
}
+ this.webSocketServer(jsonObject);
+ } catch (Exception exception) {
+ log.info("MarkingTasks:{}", exception.getMessage());
}
- if("1".equals(plcRequest.getValue())&&"0".equals(mesSend.getValue())&& !plcRequestID.getValue().isEmpty()&&"寮�宸�".equals(machine.getState())){
- Tasking tasking;
- if("0".equals(plcRequestID.getValue())){
- //鏍囧噯妯″紡
- tasking=taskingService.startMachineTask(machine);
- }else{
- //瀹氬埗妯″紡
- tasking=taskingService.startMachineTask(machine,plcRequestID.getValue());
+ }
+
+ //纾ㄨ竟鏈�
+ //@Scheduled(fixedDelay = 500)
+ public void edgingTasks() {
+ try {
+ machineListEdging = machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName, "纾ㄨ竟"));
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.append("sessionMapName", "edgingTask");
+ for (Machine machine : machineListEdging) {
+ JSONObject jsonObjectItem = new JSONObject();
+ List<Tasking> taskingList = taskingService.findMachineTask(machine);
+ jsonObjectItem.append("taskingList", taskingList);
+ jsonObjectItem.append("machine", machine);
+ jsonObjectItem.append("sendRecords", sendRecords);
+ jsonObject.append(machine.getId().toString(), jsonObjectItem);
}
- //log.info("4銆佸彂閫佷换鍔� 璁惧鐘舵��:{}, 鏁版嵁锛歿},",machine,tasking);
- if(tasking!=null){
- //妯″紡锛�1瀹氬埗 0 鎵归噺 鏄惁鎵撴爣锛�0涓嶆墦鏍� 1鎵撴爣
- int isMark_=tasking.getDrawingMarking()==null?0:1;
- int isMarkingMode_="瀹氬埗".equals(tasking.getTaskType()) ?1:0;
- log.info("4銆佸彂閫佹暟鎹�:{},{},{},{},{},{}"
- ,tasking.getProgramId()
- ,tasking.getLength().intValue(),tasking.getWidth().intValue(),isMark_,isMarkingMode_,1);
- if(isMark_==1){
- S7objectMarking.getinstance().plccontrol.writeString(drawingMark.getAddress(), tasking.getProgramId());
- }
- //S7objectMarking.getinstance().plccontrol.writeUInt32 (mesSendID.getAddress(), 2);
- S7objectMarking.getinstance().plccontrol.writeWord(lengthOutOfService.getAddress(), tasking.getLength().intValue());
- S7objectMarking.getinstance().plccontrol.writeWord(widthOutOfService.getAddress(), tasking.getWidth().intValue());
- S7objectMarking.getinstance().plccontrol.writeWord(isMark.getAddress(), isMark_);
- S7objectMarking.getinstance().plccontrol.writeWord(markingMode.getAddress(), isMarkingMode_);
- S7objectMarking.getinstance().plccontrol.writeWord(mesSend.getAddress(), 1);
- return;
- }
+ this.webSocketServer(jsonObject);
+ } catch (Exception exception) {
+ log.info("edgingTasks:{}", exception.getMessage());
}
- //log.info("鏃犲彲鎵ц鐨勬潯浠�");
+ }
+
+ //缈荤墖鍙�
+ //@Scheduled(fixedDelay = 500)
+ public void flipSliceTasks() {
+ try {
+ machineListFlipSlice = machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName, "缈荤墖"));
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.append("sessionMapName", "flipSlice");
+ for (Machine machine : machineListFlipSlice) {
+ JSONObject jsonObjectItem = new JSONObject();
+ List<Tasking> taskingList = taskingService.findMachineTask(machine);
+ jsonObjectItem.append("taskingList", taskingList);
+ jsonObjectItem.append("machine", machine);
+ jsonObjectItem.append("sendRecords", sendRecords);
+ jsonObject.append(machine.getId().toString(), jsonObjectItem);
+ }
+ this.webSocketServer(jsonObject);
+ } catch (Exception exception) {
+ log.info("flipSliceTasks:{}", exception.getMessage());
+ }
}
- //@Scheduled(fixedDelay = 1000)
+
+ //鎵撴爣鏈�
+ //@Scheduled(fixedDelay = 500)
public void markingTasks() {
- JSONObject jsonObject = new JSONObject();
- Machine machine=machineMapper.selectById(11L);
- List<Tasking> taskingList=taskingService.findMachineTask(machine);
- jsonObject.append("taskingList", taskingList);
- jsonObject.append("machine", machine);
- ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("marking");
- if (sendwServer != null) {
- for (WebSocketServer webserver : sendwServer) {
- if (webserver != null) {
- try {
- webserver.sendMessage(jsonObject.toString());
- List<String> messages = webserver.getMessages();
- if (!messages.isEmpty()) {
- // // 灏嗘渶鍚庝竴涓秷鎭浆鎹负鏁存暟绫诲瀷鐨勫垪琛�
- webserver.clearMessages();
- }
- }catch (Exception e) {
+ try {
+ machineListMarking = machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName, "鑷姩鎵撴爣鏈�"));
- }
- } else {
- log.info("Home is closed");
- }
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.append("sessionMapName", "marking");
+ for (Machine machine : machineListMarking) {
+ JSONObject jsonObjectItem = new JSONObject();
+ List<Tasking> taskingList = taskingService.findMachineTask(machine);
+ jsonObjectItem.append("taskingList", taskingList);
+ jsonObjectItem.append("machine", machine);
+ jsonObjectItem.append("sendRecords", sendRecords);
+ jsonObject.append(machine.getId().toString(), jsonObjectItem);
}
+ this.webSocketServer(jsonObject);
+ } catch (Exception exception) {
+ log.info("markingTasks:{}", exception.getMessage());
}
}
+ //涓濆嵃鏈�
+ //@Scheduled(fixedDelay = 500)
+ public void silkScreenTasks() {
+ try {
+ machineListSilkScreen = machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName, "鑷姩涓濆嵃鏈�"));
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.append("sessionMapName", "silkScreenTask");
+ for (Machine machine : machineListSilkScreen) {
+ JSONObject jsonObjectItem = new JSONObject();
+ List<Tasking> taskingList = taskingService.findMachineTask(machine);
+ jsonObjectItem.append("taskingList", taskingList);
+ jsonObjectItem.append("machine", machine);
+ jsonObjectItem.append("sendRecords", sendRecords);
+ jsonObject.append(machine.getId().toString(), jsonObjectItem);
+ }
+ this.webSocketServer(jsonObject);
+ } catch (Exception exception) {
+ log.info("silkScreenTasks:{}", exception.getMessage());
+ }
+ }
+
+ //鐐硅兌鏈�
+ //@Scheduled(fixedDelay = 500)
+ public void glueDispenserTasks() {
+ try {
+ machineListGlueDispenser = machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName, "鑷姩鐐硅兌鏈�"));
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.append("sessionMapName", "glueDispenser");
+ for (Machine machine : machineListGlueDispenser) {
+ JSONObject jsonObjectItem = new JSONObject();
+ List<Tasking> taskingList = taskingService.findMachineTask(machine);
+ jsonObjectItem.append("taskingList", taskingList);
+ jsonObjectItem.append("machine", machine);
+ jsonObjectItem.append("sendRecords", sendRecords);
+ jsonObject.append(machine.getId().toString(), jsonObjectItem);
+ }
+ this.webSocketServer(jsonObject);
+ } catch (Exception exception) {
+ log.info("glueDispenserTasks:{}", exception.getMessage());
+ }
+ }
+
+ //鏃嬭浆鍙�
+ //@Scheduled(fixedDelay = 500)
+ public void rotateTasks() {
+ try {
+ machineListRotate = machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName, "鏃嬭浆鍙�"));
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.append("sessionMapName", "rotate");
+ for (Machine machine : machineListRotate) {
+ JSONObject jsonObjectItem = new JSONObject();
+ List<Tasking> taskingList = taskingService.findMachineTask(machine);
+ jsonObjectItem.append("taskingList", taskingList);
+ jsonObjectItem.append("machine", machine);
+ jsonObjectItem.append("sendRecords", sendRecords);
+ jsonObject.append(machine.getId().toString(), jsonObjectItem);
+ }
+ this.webSocketServer(jsonObject);
+ } catch (Exception exception) {
+ log.info("rotateTasks:{}", exception.getMessage());
+ }
+ }
+
+ //璐磋啘鏈�
+ //@Scheduled(fixedDelay = 500)
+ public void laminationTasks() {
+ try {
+ machineListLamination = machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName, "鑷姩璐磋啘鏈�"));
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.append("sessionMapName", "lamination");
+ for (Machine machine : machineListLamination) {
+ JSONObject jsonObjectItem = new JSONObject();
+ List<Tasking> taskingList = taskingService.findMachineTask(machine);
+ jsonObjectItem.append("taskingList", taskingList);
+ jsonObjectItem.append("machine", machine);
+ jsonObjectItem.append("sendRecords", sendRecords);
+ jsonObject.append(machine.getId().toString(), jsonObjectItem);
+ }
+ this.webSocketServer(jsonObject);
+ } catch (Exception exception) {
+ log.info("laminationTasks:{}", exception.getMessage());
+ }
+ }
+
+
+ //鎶ュ伐椤甸潰鏌ヨ
+ //@Scheduled(fixedDelay = 1000)
+ public void manualReporting() {
+ try {
+ machineListScanQrCode = machineMapper.selectList(new QueryWrapper<Machine>().lambda().eq(Machine::getName, "璇嗗埆鎶ュ伐"));
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.append("sessionMapName", "manualReporting");
+ for (Machine machine : machineListScanQrCode) {
+ JSONObject jsonObjectItem = new JSONObject();
+ List<Tasking> taskingList = taskingMapper.selectJoinList(Tasking.class, new MPJLambdaWrapper<Tasking>()
+ .selectAll(Tasking.class)
+ .innerJoin(LineConfiguration.class, LineConfiguration::getId, Tasking::getLineConfigurationId)
+ .innerJoin(Machine.class, Machine::getId, LineConfiguration::getMachineId)
+ .eq(LineConfiguration::getMachineId, machine.getId())
+ .eq(Tasking::getGlassState, "姝e父")
+ .eq(Tasking::getState, "绾夸笂")
+ .ne(Tasking::getWorkState, "瀹屽伐")
+ .orderByDesc(Tasking::getOperationRecordTime));
+ jsonObjectItem.append("taskingList", taskingList);
+ jsonObjectItem.append("machine", machine);
+ jsonObject.append(machine.getId().toString(), jsonObjectItem);
+ }
+
+ this.webSocketServer(jsonObject);
+ } catch (Exception exception) {
+ log.info("manualReporting:{}", exception.getMessage());
+ }
+ }
+
+ //绾夸笅鐜荤拑鏌ヨ
+ //@Scheduled(fixedDelay = 1000)
+ public void downLineTask() {
+ try {
+ JSONObject jsonObject = new JSONObject();
+ List<Tasking> downLineTask = taskingService.findDownLineTask();
+ jsonObject.append("sessionMapName", "downLineTask");
+ jsonObject.append("downLineTask", downLineTask);
+ this.webSocketServer(jsonObject);
+ } catch (Exception exception) {
+ log.info("downLineTask:{}", exception.getMessage());
+ }
+ }
+
+ public void webSocketServer(JSONObject jsonObject) {
+ try {
+ log.info("鍙戦�佹暟鎹細{}", jsonObject.getJSONArray("sessionMapName").get(0).toString());
+ String sessionMapName = jsonObject.getJSONArray("sessionMapName").get(0).toString();
+ webSocketServer.sendToWeb(sessionMapName, jsonObject.toString());
+ } catch (Exception ex) {
+ log.info("{}鍙戦�佹暟鎹け璐ワ細{}", "rawGlassStorage", ex.getMessage());
+ }
+ }
+// public void webSocketServer(JSONObject jsonObject) {
+// try {
+// String sessionMapName=jsonObject.getJSONArray("sessionMapName").get(0).toString();
+// ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get(sessionMapName);
+// if (sendwServer != null) {
+// for (WebSocketServer webserver : sendwServer) {
+// try {
+// webserver.sendMessage(jsonObject.toString());
+// List<String> messages = webserver.getMessages();
+// if (!messages.isEmpty()) {
+// // // 灏嗘渶鍚庝竴涓秷鎭浆鎹负鏁存暟绫诲瀷鐨勫垪琛�
+// webserver.clearMessages();
+// }
+// }catch (Exception e) {
+// if (webserver != null) {
+//
+// } else {
+// log.info("Home is closed");
+// }
+// }
+//
+// }
+// }
+// }catch (Exception e) {
+//
+// }
+//
+// }
+
}
--
Gitblit v1.8.0