From b10ed4245c671edbf3a0ef346d5b08ec854a277d Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期三, 07 一月 2026 14:50:40 +0800
Subject: [PATCH] 1
---
src/main/java/com/zy/asrs/service/impl/CtuMainServiceImpl.java | 421 +++++++++-------------------------------------------
1 files changed, 72 insertions(+), 349 deletions(-)
diff --git a/src/main/java/com/zy/asrs/service/impl/CtuMainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/CtuMainServiceImpl.java
index 6a96f58..d964520 100644
--- a/src/main/java/com/zy/asrs/service/impl/CtuMainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/CtuMainServiceImpl.java
@@ -2,10 +2,8 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
-import com.core.common.DateUtils;
import com.core.exception.CoolException;
-import com.zy.asrs.domain.param.OpenBusSubmitParam;
-import com.zy.asrs.domain.param.TaskDto;
+import com.zy.asrs.controller.requestParam.StationRequestParam;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.News;
import com.zy.core.cache.MessageQueue;
@@ -23,7 +21,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.TimeUnit;
/**
@@ -41,8 +40,8 @@
@Value("${ctu.url}")
private String ctuUrl;
- @Value("${ctu.sendTask}")
- private String sendTask;
+ @Value("${ctu.station}")
+ private String station;
@Value("${ctu.getLoc}")
private String getLoc;
@@ -54,116 +53,8 @@
private SlaveProperties slaveProperties;
- private boolean flag1001 = false;
-
- private boolean flag1007 = false;
-
- private Map<Integer, Long> staNoSet = new HashMap<>();
-
- public Map<Integer, Long> getStaNoSet() {
- return staNoSet;
- }
-
- public void setStaNoSet(Map<Integer, Long> staNoSet) {
- this.staNoSet = staNoSet;
- }
-
/**
- * 鍏ュ簱锛屼粠鎷f枡绔欏埌鍏ュ簱绔欙紙CTU鍙栬揣绔欙級
- */
- public synchronized void generateStoreWrkFile(Integer mark) {
- for (Map.Entry<Integer, Long> entry : staNoSet.entrySet()) {
- if (entry.getValue() != null && System.currentTimeMillis() - entry.getValue() > 1000 * 60 * 5) {
- log.info("瓒呮椂锛歿}", entry.getKey());
- staNoSet.remove(entry.getKey());
- }
- }
- // 鏍规嵁杈撻�佺嚎plc閬嶅巻
- SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
- StaProtocol staProtocol = devpThread.getStation().get(1004);
- if (staProtocol == null) {
- return;
- } else {
- staProtocol = staProtocol.clone();
- }
- // 鍒ゆ柇鏄惁婊¤冻鏉′欢
- if (!staProtocol.isLoading()) {
- return;
- }
- Long i = staNoSet.get(staProtocol.getWorkNo());
- if (i != null) {
- return;
- }
- // && staProtocol.isInEnable()
- if (staProtocol.getWorkNo() > 0 && staProtocol.isAutoing() && !staProtocol.isEmptyMk() && staProtocol.isPakMk()) {
- if (staProtocol.getStaNo() == 1004) {
- try {
- Thread.sleep(8000L);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- staProtocol.setStaNo((short) 1007);
- boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
- staNoSet.put(staProtocol.getWorkNo(), System.currentTimeMillis());
- log.info("鍏ュ簱杈撻�佺嚎涓嬪彂锛歿},{}", staProtocol.getWorkNo(), 1007);
-
- }
-// WrkMast wrkMast = wrkMastMapper.selectByWrkNo(staProtocol.getWorkNo());
-// if (wrkMast != null) {
-// //涓嬪彂绉诲姩浠诲姟锛屽苟鐢熸垚鍏ュ簱宸ヤ綔妗�
-// WrkMast in = new WrkMast();
-// wrkMast.setWrkSts(223L);
-// wrkMast.setModiTime(new Date());
-// wrkMastService.updateById(wrkMast);
-// in.setSourceLocNo("1007");
-// in.setLocNo(wrkMast.getSourceLocNo());
-// in.setIoType(10);
-// in.setIoTime(new Date());
-// in.setWrkSts(1L); // 宸ヤ綔鐘舵�侊細11.鐢熸垚鍑哄簱ID
-// in.setIoPri(13D); // 浼樺厛绾э細13
-// in.setFullPlt("Y"); // 婊℃澘锛歒
-// in.setPicking("N"); // 鎷f枡
-// in.setExitMk("N"); // 閫�鍑�
-// in.setEmptyMk("Y"); // 绌烘澘
-// in.setLinkMis("N");
-// in.setAppeTime(new Date());
-// in.setModiTime(new Date());
-// in.setBarcode(wrkMast.getBarcode());
-// in.setPlcWrkNo(wrkMast.getPlcWrkNo());
-// wrkMastService.insert(in);
-// LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());
-// locMast.setLocSts("S");
-// locMast.setModiTime(new Date());
-// locMastService.updateById(locMast);
-// }
-
- }
- }
-
-
- public synchronized void outToPlc(Integer mark) {
- // 鏍规嵁杈撻�佺嚎plc閬嶅巻
- SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
- StaProtocol staProtocol = devpThread.getStation().get(1007);
- if (staProtocol == null) {
- return;
- } else {
- staProtocol = staProtocol.clone();
- }
- // 鍒ゆ柇鏄惁婊¤冻鏉′欢
- if (!staProtocol.isLoading()) {
- return;
- }
- if (flag1007 && staProtocol.getWorkNo() > 0 && staProtocol.isAutoing() && !staProtocol.isEmptyMk() && staProtocol.isPakMk()) {
- staProtocol.setWorkNo(0);
- staProtocol.setStaNo((short) 0);
- boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
- log.info("鍙栬蛋鍐欏叆纭浣嶏細{},{}", staProtocol.getWorkNo(), 1007);
- }
- }
-
- /**
- * 鍑哄簱
+ * 鍑哄簱鐨勬椂鍊欙紝璁惧涓婅蛋
*/
public synchronized void out(Integer mark) {
// 鏍规嵁杈撻�佺嚎plc閬嶅巻
@@ -184,31 +75,23 @@
}
//&& staProtocol.isOutEnable()
if (staProtocol.isAutoing() && !staProtocol.isEmptyMk() && (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() == 9999) && staProtocol.isPakMk()) {
- News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�");
- // 鍒ゆ柇閲嶅宸ヤ綔妗�
- // 106涔熺畻涓婏紝浠ュ悗106-銆�107鐢ㄤ簬鏇存柊搴撳瓨
-// WrkMast wrkMast = wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("loc_no", "1001").in("wrk_sts", 106, 107));
-// if (wrkMast == null) {
-// continue;
-// }
-
- // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
-
- // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
- staProtocol.setWorkNo((int) (Math.random() * 10000));
- staProtocol.setStaNo((short) 1004);
- devpThread.setPakMk(staProtocol.getSiteId(), false);
- boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
- log.info("杈撻�佺嚎涓嬪彂3锛歿},{}", staProtocol.getWorkNo(), 1004);
- if (result) {
- try {
- Thread.sleep(8000L);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
+ if (station(1001)) {
+ News.warnNoLog("" + mark + " - 0" + " - 寮�濮嬫墽琛�");
+ // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
+ staProtocol.setWorkNo((int) (Math.random() * 10000));
+ staProtocol.setStaNo((short) 1004);
+ devpThread.setPakMk(staProtocol.getSiteId(), false);
+ boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+ log.info("杈撻�佺嚎涓嬪彂3锛歿},{}", staProtocol.getWorkNo(), 1004);
+ if (result) {
+ try {
+ Thread.sleep(8000L);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ News.error("" + mark + " - 2" + " - 鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
}
- setFlag1001(false);
- } else {
- News.error("" + mark + " - 2" + " - 鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
}
} else {
News.errorNoLog("" + mark + " - 6" + " - 绔欑偣淇℃伅涓嶇鍚堝叆搴撴潯浠讹紒锛侊紒" + " 鑷姩淇″彿锛�" + staProtocol.isLoading() + "銆佸彲鍏ヤ俊鍙凤細" + staProtocol.isInEnable() + "銆佺┖鏉夸俊鍙凤細" + staProtocol.isEmptyMk() + "銆佸伐浣滃彿锛�" + staProtocol.getWorkNo() + "銆侀攣瀹氭爣璁�" + staProtocol.isPakMk() + "銆佸叆搴撳嵃璁帮細" + staProtocol.getStamp());
@@ -217,132 +100,41 @@
}
}
- public static final ArrayList<Integer> staNos1 = new ArrayList<Integer>() {{
- add(1001);
- add(1002);
- add(1003);
- add(1004);
- add(1005);
- add(1006);
- add(1007);
-
- }};
-
- public static final ArrayList<Integer> staNos2 = new ArrayList<Integer>() {{
-
- add(101);
- add(102);
- add(103);
- add(104);
- add(105);
- add(106);
- add(107);
- add(108);
- }};
-
- public synchronized void in(Integer mark) {
- // 閬嶅巻鍏ュ簱鍙�
- for (Integer inSta : staNos2) {
- // 鑾峰彇鍏ュ簱绔欎俊鎭�
- SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
- StaProtocol staProtocol = devpThread.getStation().get(inSta);
- if (staProtocol == null) {
- continue;
- } else {
- staProtocol = staProtocol.clone();
- }
- // 鍒ゆ柇鏄惁婊¤冻鏉′欢
- if (!staProtocol.isAutoing() && !staProtocol.isLoading()) {
- continue;
- }
- // && staProtocol.isInEnable()
- if (staProtocol.isInEnable()) {
- OpenBusSubmitParam openBusSubmitParam = new OpenBusSubmitParam();
- openBusSubmitParam.setBatch(DateUtils.convert(new Date()));
- List<TaskDto> taskList = new ArrayList<>();
- TaskDto taskDto = new TaskDto();
- Random rand = new Random();
- taskDto.setSeqNum(rand.nextInt(10000) + "");
- taskDto.setDestLoc(getFLoc(staProtocol.getSiteId() + "-2", "15"));
- taskDto.setOriSta(staProtocol.getSiteId() + "-2");
- taskDto.setPriority(123);
- taskList.add(taskDto);
- openBusSubmitParam.setTaskList(taskList);
- sendTask(openBusSubmitParam, staProtocol);
- }
- if (staProtocol.isOutEnable()) {
- OpenBusSubmitParam openBusSubmitParam = new OpenBusSubmitParam();
- openBusSubmitParam.setBatch(DateUtils.convert(new Date()));
- List<TaskDto> taskList = new ArrayList<>();
- TaskDto taskDto = new TaskDto();
- Random rand = new Random();
- taskDto.setSeqNum(rand.nextInt(10000) + "");
- taskDto.setDestLoc(getFLoc(staProtocol.getSiteId() + "-3", "15"));
- taskDto.setOriSta(staProtocol.getSiteId() + "-3");
- taskDto.setPriority(123);
- taskList.add(taskDto);
- openBusSubmitParam.setTaskList(taskList);
- sendTask(openBusSubmitParam, staProtocol);
- }
- }
- }
-
- public synchronized void autoOut(Integer mark) {
- int i = 0;
- for (Integer staNo : staNos1) {
- SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
- StaProtocol staProtocol = devpThread.getStation().get(staNo);
- if (staProtocol == null) {
- continue;
- } else {
- staProtocol = staProtocol.clone();
- }
- // 鍒ゆ柇鏄惁婊¤冻鏉′欢
- if (!staProtocol.isAutoing()) {
- continue;
- }
- if (staProtocol.isLoading()) {
- continue;
- }
- if (staProtocol.getStaNo() != 0) {
- continue;
- }
- i++;
- }
- SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
- StaProtocol staProtocol = devpThread.getStation().get(1001);
- if (i >= 7) {
- OpenBusSubmitParam openBusSubmitParam = new OpenBusSubmitParam();
- openBusSubmitParam.setBatch(DateUtils.convert(new Date()));
- List<TaskDto> taskList = new ArrayList<>();
- Random rand = new Random();
- TaskDto taskDto = new TaskDto();
- taskDto.setSeqNum("SSX-CK" + rand.nextInt() * 10000);
- taskDto.setOriLoc(getFLoc("1001", "16"));
- taskDto.setDestSta("1001");
- taskDto.setPriority(123);
- taskList.add(taskDto);
- String fLoc = getFLoc("1001", "16");
- if (fLoc == taskDto.getOriLoc()) {
- fLoc = getFLoc("1001", "16");
- }
- taskDto = new TaskDto();
- taskDto.setSeqNum("SSX-CK" + rand.nextInt() * 10000);
- taskDto.setOriLoc(fLoc);
- taskDto.setDestSta("1001");
- taskDto.setPriority(123);
- taskList.add(taskDto);
- openBusSubmitParam.setTaskList(taskList);
- sendTask(openBusSubmitParam, staProtocol);
- }
- }
/**
- * 1007鍏ュ簱
- *
- * @param mark
+ * 鍏ュ簱锛屼粠鎷f枡绔欏埌鍏ュ簱绔欙紙CTU鍙栬揣绔欙級
*/
- public synchronized void autoIn(Integer mark) {
+ public synchronized void in(Integer mark) {
+ // 鏍规嵁杈撻�佺嚎plc閬嶅巻
+ SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
+ StaProtocol staProtocol = devpThread.getStation().get(1004);
+ if (staProtocol == null) {
+ return;
+ } else {
+ staProtocol = staProtocol.clone();
+ }
+ // 鍒ゆ柇鏄惁婊¤冻鏉′欢
+ if (!staProtocol.isLoading()) {
+ return;
+ }
+ // && staProtocol.isInEnable()
+ if (staProtocol.getWorkNo() > 0 && staProtocol.isAutoing() && !staProtocol.isEmptyMk() && staProtocol.isPakMk()) {
+ if (staProtocol.getStaNo() == 1004) {
+ try {
+ Thread.sleep(8000L);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ staProtocol.setStaNo((short) 1006);
+ boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
+ log.info("鍏ュ簱杈撻�佺嚎涓嬪彂锛歿},{}", staProtocol.getWorkNo(), 1007);
+ }
+ }
+ }
+
+
+ public synchronized void in2(Integer mark) {
+ // 鏍规嵁杈撻�佺嚎plc閬嶅巻
SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
StaProtocol staProtocol = devpThread.getStation().get(1007);
if (staProtocol == null) {
@@ -351,53 +143,37 @@
staProtocol = staProtocol.clone();
}
// 鍒ゆ柇鏄惁婊¤冻鏉′欢
- if (!staProtocol.isAutoing()) {
- return;
- }
if (!staProtocol.isLoading()) {
return;
}
- if (staProtocol.getStaNo() <= 0) {
- return;
+ if (staProtocol.getWorkNo() > 0 && staProtocol.isAutoing() && !staProtocol.isEmptyMk() && staProtocol.isPakMk()) {
+ Integer workNo = staProtocol.getWorkNo();
+ staProtocol.setWorkNo(0);
+ staProtocol.setStaNo((short) 0);
+ boolean result = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
+ log.info("鍙栬蛋鍐欏叆纭浣嶏細{},{}", staProtocol.getWorkNo(), 1006);
+ StaProtocol staProtocol1006 = devpThread.getStation().get(1006);
+ staProtocol1006.setWorkNo(workNo);
+ staProtocol1006.setStaNo((short) 1007);
+ boolean result2 = MessageQueue.offer(SlaveType.Devp, 1, new Task(2, staProtocol));
+ log.info("鍙栬蛋鍐欏叆纭浣嶏細{},{}", staProtocol.getWorkNo(), 1007);
}
- OpenBusSubmitParam openBusSubmitParam = new OpenBusSubmitParam();
- openBusSubmitParam.setBatch(DateUtils.convert(new Date()));
- List<TaskDto> taskList = new ArrayList<>();
- TaskDto taskDto = new TaskDto();
- taskDto.setSeqNum("SSX-RK" + staProtocol.getWorkNo());
- taskDto.setDestLoc(getFLoc("1007", "15"));
- taskDto.setOriSta("1007");
- taskDto.setPriority(123);
- taskList.add(taskDto);
- openBusSubmitParam.setTaskList(taskList);
- sendTask(openBusSubmitParam, staProtocol);
-
}
-
- public void updateSta(Integer mark) {
- SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 1);
- StaProtocol staProtocol1 = devpThread.getStation().get(1001);
- StaProtocol staProtocol7 = devpThread.getStation().get(1007);
- if (staProtocol1 == null) {
- return;
- }
- if (staProtocol7 == null) {
- return;
- }
- updateSta("1001", staProtocol1.isLoading() ? "16" : "15");
- updateSta("1007", staProtocol7.isLoading() ? "16" : "15");
- }
@Transactional
- public boolean sendTask(OpenBusSubmitParam openBusSubmitParam, StaProtocol staProtocol) {
+ public boolean station(Integer staNo) {
+ StationRequestParam stationRequestParam = new StationRequestParam();
+ List<String> staNos = new ArrayList<>();
+ staNos.add(staNo + "");
+ stationRequestParam.setStaNos(staNos);
String response = "";
try {
response = new HttpHandler.Builder()
.setUri(ctuUrl)
- .setPath(sendTask)
+ .setPath(station)
.setTimeout(1200, TimeUnit.SECONDS)
- .setJson(JSON.toJSONString(openBusSubmitParam))
+ .setJson(JSON.toJSONString(stationRequestParam))
.build()
.doPost();
JSONObject jsonObject = JSON.parseObject(response);
@@ -414,58 +190,5 @@
return false;
}
- @Transactional
- public void updateSta(String staNo, String sts) {
- Map<String, String> data = new HashMap<String, String>();
- data.put("staNo", staNo);
- data.put("sts", sts);
- String response = "";
- try {
- response = new HttpHandler.Builder()
- .setUri(ctuUrl)
- .setPath(updateSta)
- .setTimeout(1200, TimeUnit.SECONDS)
- .setJson(JSON.toJSONString(data))
- .build()
- .doPost();
- JSONObject jsonObject = JSON.parseObject(response);
- if (jsonObject.getInteger("code").equals(200)) {
- //log.info("涓嬪彂浠诲姟杩斿洖鏁版嵁锛歿}", response);
- } else {
- //log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", ctuUrl + sendTask, JSON.toJSONString(data), response);
- //throw new CoolException("璋冪敤涓嬪彂浠诲姟鎺ュ彛鎶ラ敊");
- }
- } catch (Exception e) {
- log.error("fail", e);
- }
- }
- @Transactional
- public String getFLoc(String staNo, String sts) {
- Map<String, String> data = new HashMap<String, String>();
- data.put("staNo", staNo);
- data.put("sts", sts);
- String response = "";
- try {
- response = new HttpHandler.Builder()
- .setUri(ctuUrl)
- .setPath(getLoc)
- .setTimeout(1200, TimeUnit.SECONDS)
- .setJson(JSON.toJSONString(data))
- .build()
- .doPost();
- JSONObject jsonObject = JSON.parseObject(response);
- if (jsonObject.getInteger("code").equals(200)) {
- //log.info("涓嬪彂浠诲姟杩斿洖鏁版嵁锛歿}", response);
- JSONObject loc = JSON.parseObject(jsonObject.getString("data"));
- return loc.getString("locNo");
- } else {
- //log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", ctuUrl + sendTask, JSON.toJSONString(data), response);
- throw new CoolException("璋冪敤涓嬪彂浠诲姟鎺ュ彛鎶ラ敊");
- }
- } catch (Exception e) {
- log.error("fail", e);
- }
- return null;
- }
}
--
Gitblit v1.9.1