From 9e97ded305585c0bdc22aef3468dd031567c38a3 Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期四, 09 五月 2024 14:04:00 +0800
Subject: [PATCH] 卧式理片笼线程改造优化
---
hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/CacheGlassTask.java | 250 +++++++++++++++++++++----------------------------
1 files changed, 106 insertions(+), 144 deletions(-)
diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/CacheGlassTask.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/CacheGlassTask.java
index cb8a805..d559304 100644
--- a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/CacheGlassTask.java
+++ b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/job/CacheGlassTask.java
@@ -1,13 +1,13 @@
package com.mes.job;
-import cn.hutool.core.date.DateTime;
-import cn.hutool.json.JSONObject;
-import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.lang.Assert;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mes.common.S7object;
-import com.mes.common.WebSocketServer;
+import com.mes.common.config.Const;
+import com.mes.device.PlcParameterObject;
import com.mes.edgstoragecage.entity.EdgStorageCage;
import com.mes.edgstoragecage.entity.EdgStorageCageDetails;
-import com.mes.edgstoragecage.mapper.EdgStorageCageDetailsMapper;
import com.mes.edgstoragecage.service.EdgStorageCageDetailsService;
import com.mes.edgstoragecage.service.EdgStorageCageService;
import com.mes.glassinfo.entity.GlassInfo;
@@ -15,15 +15,14 @@
import com.mes.taskcache.entity.TaskCache;
import com.mes.taskcache.service.TaskCacheService;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Date;
import java.util.List;
-import java.util.Map;
/**
* @Author : zhoush
@@ -42,161 +41,124 @@
EdgStorageCageService edgStorageCageService;
@Autowired
EdgStorageCageDetailsService edgStorageCageDetailsService;
- @Resource
- private EdgStorageCageDetailsMapper edgStorageCageDetailsMapper;
- private Map<String, String> mapParameter = new HashMap<>();
- private Map<String, String> mapValue = new HashMap<>();
- private Map<String, String> mapType = new HashMap<>();
- private Map<String, Object> mapSettings = new HashMap<>();
+ @Value("${mes.threshold}")
+ private int threshold;
- @Scheduled(fixedDelay = 1000)
+ @Scheduled(fixedDelay = 10000)
public void plcHomeEdgTask() {
- initialize();
- log.info("褰撳墠鍙傛暟鍊硷細{}", mapValue);
- JSONObject jsonObject = new JSONObject();
-// for (String key : mapParameter.keySet()) {
-// String value = "";
-// if ("String".equals(mapType.get(key))) {
-// value = S7object.getinstance().plccontrol.readString(mapParameter.get(key));
-// } else {
-// value = S7object.getinstance().plccontrol.readWord(mapParameter.get(key)) + "";
-// }
-// mapValue.put(key, value);
-// }
+ PlcParameterObject plcParameterObject = S7object.getinstance().PlcMesObject;
- if ("0".equals(mapValue.get("A06_request_word"))) {
- log.info("鑾峰彇鍒扮殑璇锋眰瀛椾负0锛屽皢纭瀛楁敼涓�0");
- //娓呴櫎
- S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short) 0);
- } else if ("1".equals(mapValue.get("A06_request_word")) &&
- "0".equals(mapValue.get("MES_confirmation_word"))) {
- log.info("杩涚墖璇锋眰锛屼笖纭瀛椾负0锛屾墽琛岃繘鐗囦换鍔�");
- inTo();
- } else if ("2".equals(mapValue.get("A06_request_word")) &&
- "0".equals(mapValue.get("MES_confirmation_word")) && !"0".equals(mapValue.get("A09_glass_status"))) {
+ String taskRequestTypeValue = plcParameterObject.getPlcParameter("A06_request_word").getValue();
+ String glassIdeValue = plcParameterObject.getPlcParameter("A05_scanning_ID").getValue();
+ String confirmationWrodValue = plcParameterObject.getPlcParameter("MES_confirmation_word").getValue();
+// 1涓篈09绌洪棽锛�2涓篈10绌洪棽锛�3涓篈09A10閮界┖闂�,0涓篈09A10閮芥湁鐜荤拑
+ String outGlassstate = plcParameterObject.getPlcParameter("A09_glass_status").getValue();
+
+ String confirmationWrodAddress = plcParameterObject.getPlcParameter("MES_confirmation_word").getAddress();
+
+ if ("0".equals(taskRequestTypeValue)) {
+ log.info("1銆佽幏鍙栧埌鐨勮姹傚瓧涓�0锛屽皢纭瀛楁敼涓�0");
+ S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 0);
+ return;
+ }
+ if (!"0".equals(confirmationWrodValue)) {
+ log.info("1銆佽幏鍙栧埌鐨勮姹傚瓧涓嶄负0锛屽皢纭瀛楁敼涓�0");
+ S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 0);
+ return;
+ }
+ if ("1".equals(taskRequestTypeValue)) {
+ log.info("2銆佽繘鐗囪姹傦紝涓旂‘璁ゅ瓧涓�0锛屾墽琛岃繘鐗囦换鍔�");
+ inTo(glassIdeValue, confirmationWrodAddress);
+ } else if ("2".equals(taskRequestTypeValue)) {
//09绌洪棽 锛�1 10绌洪棽 锛�2 閮界┖闂诧細3 鍏朵粬0
- log.info("鍑虹墖璇锋眰锛屼笖纭瀛椾负0锛屾墽琛岃繘鐗囦换鍔�");
- outTo(Integer.parseInt(mapValue.get("A09_glass_status")));
- } else if ("3".equals(mapValue.get("A06_request_word")) &&
- "0".equals(mapValue.get("MES_confirmation_word"))) {
-
- if ("0".equals(mapValue.get("A09_glass_status")) || "0".equals(mapValue.get("A10_glass_status"))) {
- outTo(Integer.parseInt(mapValue.get("A09_glass_status")));
+ log.info("2銆佸嚭鐗囪姹傦紝涓旂‘璁ゅ瓧涓�0锛屾墽琛岃繘鐗囦换鍔�");
+ outTo(Integer.parseInt(outGlassstate), confirmationWrodAddress);
+ } else if ("3".equals(taskRequestTypeValue)) {
+ log.info("2銆佽繘鐗囧拰鍑虹墖閮界┖闂诧紝鎵ц鍑虹墖浠诲姟");
+ if ("0".equals(outGlassstate)) {
+ inTo(glassIdeValue, confirmationWrodAddress);
} else {
- inTo();
- }
- }
-// log.info("鎺ㄦ暟鎹�");
- // jsonObject.append("params", new short[] { 30, 40, });
- ArrayList<WebSocketServer> sendwServer = WebSocketServer.sessionMap.get("Home");
- if (sendwServer != null) {
- for (WebSocketServer webserver : sendwServer) {
- webserver.sendMessage(jsonObject.toString());
- if (webserver != null) {
-
- List<String> messages = webserver.getMessages();
-
- if (!messages.isEmpty()) {
- // // 灏嗘渶鍚庝竴涓秷鎭浆鎹负鏁存暟绫诲瀷鐨勫垪琛�
- webserver.clearMessages();
- }
- }
+ outTo(Integer.parseInt(outGlassstate), confirmationWrodAddress);
}
}
}
- /**
- * 鍒濆鍖杙lc鏁版嵁
- */
- private void initialize() {
-// mapParameter.put("A06_request_word", "DB11.0"); //work
-// mapParameter.put("A05_scanning_ID", "DB11.2");
-// mapParameter.put("MES_confirmation_word", "DB11.40");
-// mapParameter.put("A09_glass_status", "DB11.70");
-// //mapParameter.put("A10_glass_status", "DB11.72");
-// mapParameter.put("A09_prohibit_film_production", "DB11.74");
-// mapParameter.put("A10_prohibit_film_production", "DB11.76");
-// mapSettings.put("territoryPoor", 3);
-// mapType.put("A06_request_word", "Word");
-// mapType.put("A05_scanning_ID", "String");
-// mapType.put("MES_confirmation_word", "Word");
-// mapType.put("A09_glass_status", "Word");
-// //mapType.put("A10_glass_status", "Word");
-// mapType.put("A09_prohibit_film_production", "Word");
-// mapType.put("A10_prohibit_film_production", "Word");
- mapValue.put("A06_request_word", "2");//璇锋眰瀛�
- mapValue.put("A05_scanning_ID", "11111111111");//璇锋眰ID
- mapValue.put("MES_confirmation_word", "0");//MES鍙戦�佸瓧
- mapValue.put("A09_glass_status", "1");//A09鐜荤拑鐘舵��
- mapValue.put("A10_glass_status", "0");//A09鐜荤拑鐘舵��
- mapValue.put("A09_prohibit_film_production", "0");//A9绂佹鍑虹墖
- mapValue.put("A10_prohibit_film_production", "0");//A10绂佹鍑虹墖
-
- }
-
- private void inTo() {
- List<GlassInfo> glassInfos = glassInfoService.selectId(mapValue.get("A05_scanning_ID"));
- if (glassInfos.size() < 1) {
- log.info("姝ょ幓鐠冪紪鍙蜂笉瀛樺湪");
- } else if (glassInfos.size() == 1) {
- //娣诲姞杩涚墖浠诲姟 鏌ユ壘绌烘牸
- log.info("姝e父");
- List<EdgStorageCage> list = edgStorageCageService.selectCacheEmpty();
-
- if (list.size() > 1) {
- EdgStorageCageDetails edgStorageCageDetails = edgStorageCageDetailsMapper.selectOne(new MPJLambdaWrapper<EdgStorageCageDetails>()
- .eq(EdgStorageCageDetails::getGlassId, glassInfos.get(0).getGlassId()));
- edgStorageCageDetails.setState(200);
-
- TaskCache taskCache = new TaskCache();
- EdgStorageCage edgStorageCage = list.get(0);
- taskCache.setGlassId(glassInfos.get(0).getGlassId());
- taskCache.setTaskStatus(0);
- taskCache.setStartCell(0);
- taskCache.setEndCell(edgStorageCage.getSlot());
- taskCache.setTaskType(1);
- taskCache.setCreateTime(new DateTime());
- edgStorageCageDetailsMapper.updateById(edgStorageCageDetails);
- taskCacheService.insertTaskCache(taskCache);
-// S7object.getinstance().plccontrol.WriteWord("DB11.40", (short) 1);
- } else {
- log.info("涓嶅瓨鍦ㄧ┖鏍�");
- }
- } else {
- log.info("姝ょ幓鐠冪紪鍙峰瓨鍦ㄥ涓�");
+ private void inTo(String glassId, String confirmationWrodAddress) {
+ log.info("1銆佹寜鐓х幓鐠僫d:{}鑾峰彇鐜荤拑灏忕墖淇℃伅", glassId);
+ GlassInfo glassInfo = glassInfoService.getOne(new LambdaQueryWrapper<GlassInfo>().eq(GlassInfo::getGlassId, glassId));
+ if (glassInfo == null) {
+ log.info("2銆佹鐜荤拑缂栧彿涓嶅瓨鍦�");
+ return;
}
+ log.info("2銆佽幏鍙栧埌鐨勭幓鐠冧俊鎭负{}", glassInfo);
+ //娣诲姞杩涚墖浠诲姟 鏌ユ壘绌烘牸
+ List<EdgStorageCage> list = edgStorageCageService.selectCacheEmpty();
+ log.info("3銆佹煡璇㈠崸寮忕悊鐗囩閲岄潰鐨勭┖鏍�:{}", list);
+ if (CollectionUtil.isEmpty(list)) {
+ log.info("4銆佷笉瀛樺湪绌烘牸");
+ return;
+ }
+ log.info("4銆佸皢鐜荤拑淇℃伅鎻掑叆鍗у紡鐞嗙墖绗�:{}", glassInfo);
+ EdgStorageCageDetails details = new EdgStorageCageDetails();
+ BeanUtils.copyProperties(glassInfo, details);
+ details.setState(100);
+ Integer slot = list.get(0).getSlot();
+ Integer deviceId = list.get(0).getDeviceId();
+ log.info("5銆佽幏鍙栫┖闂叉牸瀛愪负:{},璁惧鍙蜂负{}", slot, deviceId);
+ details.setSlot(slot);
+ details.setDeviceId(deviceId);
+ edgStorageCageDetailsService.save(details);
+
+ log.info("6銆佺敓鎴愯繘鐗囦换鍔′俊鎭瓨鍏ヤ换鍔¤〃");
+ TaskCache taskCache = new TaskCache();
+ taskCache.setGlassId(glassId);
+ taskCache.setTaskStatus(0);
+ taskCache.setStartCell(0);
+ taskCache.setEndCell(slot);
+ taskCache.setTaskType(1);
+ taskCache.setCreateTime(new Date());
+ taskCacheService.insertTaskCache(taskCache);
+ log.info("6銆佸彂閫佺‘璁ゅ瓧");
+ S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 1);
+
+
}
- private void outTo(int line) {
+ private void outTo(int line, String confirmationWrodAddress) {
+ Assert.isTrue(line != 0, "A09銆丄10閮芥湁鐜荤拑锛屾棤娉曞嚭鐗�");
+ log.info("1銆佸嚭鐗囦换鍔″嚭銆恵}銆戝彿绾�,澶囨敞(09绌洪棽锛�1;10绌洪棽锛�2;閮界┖闂诧細3)", line);
int endcell = 0;
- EdgStorageCageDetails outEdgStorageCageDetails = new EdgStorageCageDetails();
- TaskCache taskCacheA09 = taskCacheService.selectLastOutCacheInfo("");
- TaskCache taskCacheA10 = taskCacheService.selectLastOutCacheInfo("");
- //涓ょ嚎鍚勮嚜瑕佸嚭鐨勭幓鐠�
- EdgStorageCageDetails glassInfo09 = edgStorageCageDetailsService.selectConformGlass(taskCacheA09.getGlassId(), (int) mapSettings.get("territoryPoor"));
- EdgStorageCageDetails glassInfo10 = edgStorageCageDetailsService.selectConformGlass(taskCacheA10.getGlassId(), (int) mapSettings.get("territoryPoor"));
- //鍐冲畾绾胯矾
- if (line == 1) {
- endcell = 9000;
- outEdgStorageCageDetails = glassInfo09;
- } else if (line == 2) {
- endcell = 1000;
- outEdgStorageCageDetails = glassInfo10;
- } else if (line == 3) {
- endcell = 9000;//榛樿璧颁竴鍙风嚎 浼樺寲鏂瑰悜鍙牴鎹� 瀵规瘮涓ょ嚎閫熷害/涓ょ嚎褰撳墠浠诲姟鎯呭喌鍋�
- outEdgStorageCageDetails = glassInfo09;
+
+ List<TaskCache> oldTaskCacheList;
+ if (line == 2) {
+ endcell = Const.A10_OUT_TARGET_POSITION;
+ oldTaskCacheList = taskCacheService.selectLastOutCacheInfos(Const.A10_OUT_TARGET_POSITION);
+ } else {
+ endcell = Const.A09_OUT_TARGET_POSITION;
+ oldTaskCacheList = taskCacheService.selectLastOutCacheInfos(Const.A09_OUT_TARGET_POSITION);
}
- if (outEdgStorageCageDetails != null && endcell > 0) {
+ log.info("2銆佸垽鏂嚭鐗囩嚎璺瘂}锛岃幏鍙栨渶鍚庤鏉$嚎宸插嚭鐗囩殑浠诲姟淇℃伅{}(澶囨敞锛�0寰呮墽琛岋紝1宸叉墽琛�).閮界┖闂蹭紭鍏堝嚭A09绾�", endcell, oldTaskCacheList);
+
+ String glassId = "";
+ if (CollectionUtil.isNotEmpty(oldTaskCacheList)) {
+ glassId = oldTaskCacheList.get(0).getGlassId();
+ }
+ EdgStorageCageDetails glassInfo = edgStorageCageDetailsService.selectOutGlass(glassId, threshold);
+ log.info("3銆佹寜鐓у巻鍙插凡鍑虹幓鐠僫d{}鍜岄槇鍊納}锛屾嬁鍑虹悊鐗囩鍐呯殑鍑虹墖淇℃伅{}", glassId, threshold, glassInfo);
+
+ if (glassInfo != null) {
+ log.info("4銆佹坊鍔犲嚭鐗囦换鍔★紝鐜荤拑id锛歿}锛屼换鍔$被鍨嬶細{}锛岃捣濮嬩綅缃細{}锛岀粨鏉熶綅缃細{}", glassInfo.getGlassId(),
+ 2, glassInfo.getSlot(), endcell);
TaskCache taskCache = new TaskCache();
- taskCache.setGlassId(outEdgStorageCageDetails.getGlassId());
+ taskCache.setGlassId(glassInfo.getGlassId());
taskCache.setTaskStatus(0);
- taskCache.setStartCell(outEdgStorageCageDetails.getSlot());
+ taskCache.setStartCell(glassInfo.getSlot());
taskCache.setEndCell(endcell);
taskCache.setTaskType(2);
- taskCache.setCreateTime(new DateTime());
+ taskCache.setCreateTime(new Date());
taskCacheService.insertTaskCache(taskCache);
-// S7object.getinstance().plccontrol.WriteWord(mapParameter.get("MES_confirmation_word"), (short) 1);
+ S7object.getinstance().plccontrol.WriteWord(confirmationWrodAddress, (short) 1);
}
--
Gitblit v1.8.0