From d8f361c9d69271aaa58ba19e75f38e0fee00f3bb Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 24 十二月 2024 08:36:33 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 960 +++++++++--------------------------------------------------
1 files changed, 150 insertions(+), 810 deletions(-)
diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index 0e18857..0d32709 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -3,10 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
-import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
-import com.core.common.SpringUtils;
-import com.core.exception.CoolException;
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.*;
import com.zy.asrs.service.*;
@@ -36,7 +33,6 @@
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.*;
-import java.util.stream.Collectors;
/**
* 绔嬩綋浠撳簱WCS绯荤粺涓绘祦绋嬩笟鍔�
@@ -55,11 +51,7 @@
@Autowired
private WrkMastService wrkMastService;
@Autowired
- private WrkDetlService wrkDetlService;
- @Autowired
private LocMastService locMastService;
- @Autowired
- private LocDetlService locDetlService;
@Autowired
private StaDescService staDescService;
@Autowired
@@ -93,10 +85,6 @@
@Autowired
private ErpService erpService;
@Autowired
- private OrderMapper orderMapper;
- @Autowired
- private OrderDetlMapper orderDetlMapper;
- @Autowired
private BasLiftService basLiftService;
@Autowired
private ShuttleDispatchUtils shuttleDispatchUtils;
@@ -110,10 +98,6 @@
private ConfigService configService;
@Autowired
private NavigateMapUtils navigateMapUtils;
- @Autowired
- private WrkDetlLogService wrkDetlLogService;
- @Autowired
- private MatService matService;
@Autowired
private NavigateMapData navigateMapData;
@@ -311,105 +295,6 @@
}
/**
- * wms鍏ュ簱
- * 鍏ュ簱绔欙紝鏍规嵁鏉$爜鎵弿鐢熸垚鍏ュ簱宸ヤ綔妗o紝宸ヤ綔鐘舵�� 1 ==>> 2
- */
- @Deprecated
- public void generateStoreWrkFile0() {
- // 鏍规嵁杈撻�佺嚎plc閬嶅巻
- for (DevpSlave devp : slaveProperties.getDevp()) {
- // 閬嶅巻鍏ュ簱鍙�
- for (DevpSlave.Sta inSta : devp.getInSta()) {
- // 鑾峰彇鍏ュ簱绔欎俊鎭�
- DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
- StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
- if (staProtocol == null) {
- continue;
- } else {
- staProtocol = staProtocol.clone();
- }
- Short workNo = staProtocol.getWorkNo();
- // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
- if (staProtocol.isAutoing() && staProtocol.isLoading()
- && staProtocol.isInEnable()
- && !staProtocol.isEmptyMk() && (workNo == 0 || (workNo >= 9990 && workNo <= 9999))
- && staProtocol.isPakMk()) {
-
- // 灏哄妫�娴嬪紓甯�
- boolean back = false;
- String errMsg = "";
- if (staProtocol.isFrontErr()) {
- errMsg = "鍓嶈秴闄�";
- back = true;
- }
- if (!back && staProtocol.isBackErr()) {
- errMsg = "鍚庤秴闄�";
- back = true;
- }
- if (!back && staProtocol.isHighErr()) {
- errMsg = "楂樿秴闄�";
- back = true;
- }
- if (!back && staProtocol.isLeftErr()) {
- errMsg = "宸﹁秴闄�";
- back = true;
- }
- if (!back && staProtocol.isRightErr()) {
- errMsg = "鍙宠秴闄�";
- back = true;
- }
- if (!back && staProtocol.isWeightErr()) {
- errMsg = "瓒呴噸";
- back = true;
- }
- if (!back && staProtocol.isBarcodeErr()) {
- errMsg = "鎵爜澶辫触";
- back = true;
- }
-
- // 閫�鍥�
- if (back) {
- News.warn("鎵爜鍏ュ簱澶辫触锛寋}鍏ュ簱绔欏洜{}寮傚父锛屾墭鐩樺凡琚��鍥�", inSta.getStaNo(), errMsg);
- staProtocol.setWorkNo((short) 32002);
- staProtocol.setStaNo(inSta.getBackSta().shortValue());
- devpThread.setPakMk(staProtocol.getSiteId(), false);
- MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
-
- // led 寮傚父鏄剧ず
- LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
- if (ledThread != null) {
- MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, errMsg));
- }
- continue;
- }
-
- // 鍒ゆ柇閲嶅宸ヤ綔妗�
- WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
- if (wrkMast == null) { continue; }
-
- // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
-
- // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
- staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
- staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
- devpThread.setPakMk(staProtocol.getSiteId(), false);
- boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
- if (result) {
- // 鏇存柊宸ヤ綔涓绘。
- wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵�侊細2.璁惧涓婅蛋
- wrkMast.setModiTime(new Date());
- if (wrkMastMapper.updateById(wrkMast) == 0) {
- News.error("鏇存柊宸ヤ綔妗eけ璐ワ紒锛侊紒 [宸ヤ綔鍙凤細{}]", wrkMast.getWrkNo());
- }
- } else {
- News.error("鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
- }
- }
- }
- }
- }
-
- /**
* 鎷f枡銆佸苟鏉垮啀鍏ュ簱
*/
@Transactional
@@ -529,49 +414,6 @@
} catch (Exception e) {
e.printStackTrace();
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- }
- }
- }
-
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * 鎷f枡銆佸苟鏉垮啀鍏ュ簱(325銆�331銆�333銆�339)
- */
- @Transactional
- public synchronized void stnToCrnStnPick2(){
- try {
- for (DevpSlave devp : slaveProperties.getDevp()) {
- // 閬嶅巻鎷f枡鍏ュ簱鍙�
- for (DevpSlave.Sta pickSta : devp.getPickInSta2()) {
- // 鑾峰彇鎷f枡鍏ュ簱绔欎俊鎭�
- DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
- StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
- if (staProtocol == null) {
- continue;
- } else {
- staProtocol = staProtocol.clone();
- }
- if (staProtocol.isAutoing()
- && staProtocol.isLoading()
- && staProtocol.isInEnable()
- && (staProtocol.getWorkNo() > 0)
- && staProtocol.isPakMk()) {
-
- WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
- if (wrkMast == null) {
- continue;
- }
- if (wrkMast.getSteNo() == null) {
- wrkMast.setSteNo(1);
- wrkMastMapper.updateById(wrkMast);
- staProtocol.setStaNo((short) 341);//鍐欏叆鐩爣绔�
- staProtocol.setPakMk(false);
- MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
}
}
}
@@ -2514,669 +2356,167 @@
}
/**
- * AGV琛ヨ揣 => 鐢熸垚鍏ュ簱閫氱煡妗�
- */
- public synchronized void robotGenerateAgvTask() {
- try {
- //妫�娴�300绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗┿�佸伐浣滃彿
- for (DevpSlave devp : slaveProperties.getDevp()) {
- // 鑾峰彇鍏ュ簱绔欎俊鎭�
- DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
- StaProtocol staProtocol = devpThread.getStation().get(300);
- if (staProtocol == null) {
- continue;
- }
- if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) {
- //鏌ヨ鏄惁鏈夊伐浣滄。
- WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
- if (wrkMast == null) {
- continue;
- }
-
- if (wrkMast.getWrkSts() != 25) {//25.鎻愬崌鏈烘惉杩愬畬鎴�
- continue;
- }
-
- if (wrkMast.getMk() != null && wrkMast.getMk().equals("Y")) {//鏍囪涓篩琛ㄧず闇�瑕佺敤鍒版満姊拌噦鎷f枡
- Short targetSta = null;//鐩爣绔�
- //鍒ゆ柇鏈烘鑷傛嫞鏂欑珯鏄惁绌洪棽
- StaProtocol staProtocol303 = devpThread.getStation().get(303);
- StaProtocol staProtocol317 = devpThread.getStation().get(317);
-
- List<WrkMast> wrkMasts303 = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", 25).eq("sta_no", 303));
- List<WrkMast> wrkMasts317 = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", 25).eq("sta_no", 317));
- if (staProtocol303.isAutoing() && !staProtocol303.isLoading() && wrkMasts303.isEmpty()) {
- //鑷姩銆佹棤鐗�
- targetSta = (short) 303;
- } else if (staProtocol317.isAutoing() && !staProtocol317.isLoading() && wrkMasts317.isEmpty()) {
- //鑷姩銆佹棤鐗�
- targetSta = (short) 317;
- } else {
- continue;//娌℃湁绌洪棽绔欑偣
- }
-
- if (wrkMast.getStaNo() != 303 && wrkMast.getStaNo() != 317) {
- //鍚慉GV鍙戣捣缁勬墭璇锋眰
- try {
- HashMap<String, Object> param = new HashMap<>();
- param.put("wrkNo", wrkMast.getWrkNo());
- String response = new HttpHandler.Builder()
- .setUri(wmsUrl)
- .setPath("/rpc/replenishment")
- .setJson(JSON.toJSONString(param))
- .build()
- .doPost();
- JSONObject jsonObject = JSON.parseObject(response);
- Integer code = jsonObject.getInteger("code");
- if (code.equals(200)) {//AGV缁勬墭鎴愬姛
- //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
- wrkMast.setStaNo(targetSta.intValue());
- wrkMast.setShuttleNo(null);//閲婃斁灏忚溅
- wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
- if (wrkMastMapper.updateById(wrkMast) > 0) {
- //鍚�300绔欏啓鍏ョ洰鏍囩珯
- staProtocol = staProtocol.clone();
- staProtocol.setStaNo(targetSta);//绉诲姩鍒扮洰鏍囩珯
- boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
- try {
- Thread.sleep(500);
- } catch (Exception e) {
- e.printStackTrace();
- }
- continue;
- }
- }
- } catch (Exception e) {
-// e.printStackTrace();
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- }
-
-// //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
-// wrkMast.setStaNo(targetSta.intValue());
-// wrkMast.setShuttleNo(null);//閲婃斁灏忚溅
-// wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
-// if (wrkMastMapper.updateById(wrkMast) > 0) {
-// //鍚�300绔欏啓鍏ョ洰鏍囩珯
-// staProtocol = staProtocol.clone();
-// staProtocol.setStaNo(targetSta);//绉诲姩鍒扮洰鏍囩珯
-// boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
-// try {
-// Thread.sleep(500);
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-// continue;
-// }
- }
- }
- }
- }
- } catch (Exception e) {
-// e.printStackTrace();
- }
- }
-
- /**
- * AGV琛ヨ揣 => 鏈烘鑷傛嫞鏂�
- */
- public synchronized void agvRestockByRobot() {
- try {
- //妫�娴�300绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗┿�佸伐浣滃彿
- for (DevpSlave devp : slaveProperties.getDevp()) {
- // 鑾峰彇鍏ュ簱绔欎俊鎭�
- DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
- StaProtocol staProtocol303 = devpThread.getStation().get(303);
- StaProtocol staProtocol317 = devpThread.getStation().get(317);
- if (staProtocol303 == null || staProtocol317 == null) {
- continue;
- }
-
- if (staProtocol303.isAutoing() && staProtocol303.isLoading() && staProtocol303.getWorkNo() != 0) {
- //璋冨害鏈烘鑷�
- //鏌ヨ鏄惁鏈夊伐浣滄。
- WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol303.getWorkNo().intValue());
- if (wrkMast == null) {
- continue;
- }
- List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
- if (wrkDetls.isEmpty()) {
- continue;
- }
-
- if (wrkMast.getInvWh() == null) {
- boolean result = RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetls.size(), "303");
- if (result) {
- wrkMast.setInvWh("Y");//鏍囪宸茬粡涓嬪彂鏈烘鑷備换鍔�
- wrkMastMapper.updateById(wrkMast);
- }
- }
- }
-
- if (staProtocol317.isAutoing() && staProtocol317.isLoading() && staProtocol317.getWorkNo() != 0) {
- //璋冨害鏈烘鑷�
- //鏌ヨ鏄惁鏈夊伐浣滄。
- WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol317.getWorkNo().intValue());
- if (wrkMast == null) {
- continue;
- }
- List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
- if (wrkDetls.isEmpty()) {
- continue;
- }
- if (wrkMast.getInvWh() == null) {
- boolean result = RobotUtils.sendTask(staProtocol317.getWorkNo().toString(), wrkDetls.size(), "317");
- if (result) {
- wrkMast.setInvWh("Y");//鏍囪宸茬粡涓嬪彂鏈烘鑷備换鍔�
- wrkMastMapper.updateById(wrkMast);
- }
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * AGV琛ヨ揣(閫氱煡AGV鍙栬揣)
- */
- public synchronized void agvRestockInto() {
- try {
- //妫�娴�309鍜�312绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗�
- for (DevpSlave devp : slaveProperties.getDevp()) {
- // 鑾峰彇鍏ュ簱绔欎俊鎭�
- DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
- StaProtocol staProtocol309 = devpThread.getStation().get(309);
- StaProtocol staProtocol312 = devpThread.getStation().get(312);
- if (staProtocol309 == null || staProtocol312 == null) {
- continue;
- }
-
- if (staProtocol309.isAutoing() && staProtocol309.isLoading() && staProtocol309.isInEnable()) {
- // 鑾峰彇鏉$爜鎵弿浠俊鎭�
- BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 9);//308绔欐潯鐮佸櫒
- if (barcodeThread == null) {
- continue;
- }
- String barcode = barcodeThread.getBarcode();
- if (!Cools.isEmpty(barcode)) {
- //閫氱煡AGV鍙栬揣
- boolean result = agvRestockCall("301-1", barcode);
- log.info("鏈烘鑷傞�氱煡AGV鍙栬揣锛屾潯鐮佸彿锛�" + barcode);
- if (result) {
- barcodeThread.setBarcode("");
- }
- }
- }
-
- if (staProtocol312.isAutoing() && staProtocol312.isLoading() && staProtocol312.isInEnable()) {
- // 鑾峰彇鏉$爜鎵弿浠俊鎭�
- BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 10);//311绔欐潯鐮佸櫒
- if (barcodeThread == null) {
- continue;
- }
- String barcode = barcodeThread.getBarcode();
- if (!Cools.isEmpty(barcode)) {
- //閫氱煡AGV鍙栬揣
- boolean result = agvRestockCall("302-1", barcode);
- log.info("鏈烘鑷傞�氱煡AGV鍙栬揣锛屾潯鐮佸彿锛�" + barcode);
- if (result) {
- barcodeThread.setBarcode("");
- }
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- //閫氱煡AGV鍙栬揣
- private boolean agvRestockCall(String staNo, String barcode) {
- try {
- HashMap<String, Object> param = new HashMap<>();
- param.put("devNo", staNo);
- param.put("containerCode", barcode);
- String response = new HttpHandler.Builder()
- .setUri(wmsUrl)
- .setPath("/rpc/start")
- .setJson(JSON.toJSONString(param))
- .build()
- .doPost();
- JSONObject jsonObject = JSON.parseObject(response);
- News.info("鎮寕绾匡紝WMS杩斿洖缁撴灉锛�" + jsonObject);
- Integer code = jsonObject.getInteger("code");
- if (code.equals(200)) {//鍛煎彨AGV
- return true;
- }
- } catch (Exception e) {
- e.printStackTrace();
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- }
- return false;
- }
-
- //閫氱煡WMS褰撳墠鎷f枡绔欑偣淇℃伅
- private boolean agvCureentCall(String staNo, String barcode) {
- try {
- HashMap<String, Object> param = new HashMap<>();
- param.put("devNo", staNo);
- param.put("containerCode", barcode);
- String response = new HttpHandler.Builder()
- .setUri(wmsUrl)
- .setPath("/rpc/current/containerCode")
- .setJson(JSON.toJSONString(param))
- .build()
- .doPost();
- JSONObject jsonObject = JSON.parseObject(response);
- News.info("鎮寕绾匡紝WMS杩斿洖缁撴灉锛�" + jsonObject);
- Integer code = jsonObject.getInteger("code");
- if (code.equals(200)) {//鍛煎彨AGV
- return true;
- }
- } catch (Exception e) {
- e.printStackTrace();
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- }
- return false;
- }
-
- /**
- * AGV琛ヨ揣(鎮寕绾块�氱煡AGV鍙栬揣)
- */
- public synchronized void agvRestockIntoByHangingWire() {
- try {
- //妫�娴�350鍜�351鎵爜鍣�
- int[] barcodeStaNo = {11, 12,14,16,18,20};//11 => 350绔欐壂鐮佸櫒,12 => 351绔欐壂鐮佸櫒
- for (int staNo : barcodeStaNo) {
- // 鑾峰彇鏉$爜鎵弿浠俊鎭�
- BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, staNo);
- if (barcodeThread == null) {
- continue;
- }
- String barcode = barcodeThread.getBarcode();
- if (!Cools.isEmpty(barcode)) {
- if (barcode.contains("NoRead")) {
- continue;
- }
-
- String agvStaNo = null;
- if (staNo == 11) {
- agvStaNo = "303-1";
- } else if(staNo == 12){
- agvStaNo = "304-1";
- } else if(staNo == 14){
- agvStaNo = "311-1";
- } else if(staNo == 16){
- agvStaNo = "313-1";
- } else if(staNo == 18){
- agvStaNo = "315-1";
- } else if(staNo == 20){
- agvStaNo = "317-1";
- }
- //閫氱煡AGV鍙栬揣
- boolean result = agvRestockCall(agvStaNo, barcode);
- if (result) {
- barcodeThread.setBarcode("");
- }
- log.info(barcodeThread.getSlave().getId() + "鍙锋壂鐮佸櫒锛岄�氱煡AGV鍙栬揣锛屾潯鐮佸彿锛�" + barcode);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * AGV鎷f枡绔欑偣淇℃伅
- */
- public synchronized void agvCurrentContainerCodeInfoWire() {
- try {
- //妫�娴�350鍜�351鎵爜鍣�
- int[] barcodeStaNo = {13, 15,17,19};//11 => 350绔欐壂鐮佸櫒,12 => 351绔欐壂鐮佸櫒
- for (int staNo : barcodeStaNo) {
- // 鑾峰彇鏉$爜鎵弿浠俊鎭�
- BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, staNo);
- if (barcodeThread == null) {
- continue;
- }
- String barcode = barcodeThread.getBarcode();
- if (!Cools.isEmpty(barcode)) {
- if (barcode.contains("NoRead")) {
- continue;
- }
-
- String agvStaNo = null;
- if (staNo == 13) {
- agvStaNo = "CS-310";
- } else if(staNo == 15){
- agvStaNo = "CS-311";
- } else if(staNo == 17){
- agvStaNo = "CS-312";
- } else if(staNo == 19){
- agvStaNo = "CS-313";
- }
- //閫氱煡WMS褰撳墠瀹瑰櫒鐮�
- boolean result = agvCureentCall(agvStaNo, barcode);
- if (result) {
- barcodeThread.setBarcode("");
- }
- log.info(barcodeThread.getSlave().getId() + "鍙锋壂鐮佸櫒锛岄�氱煡AGV鍙栬揣锛屾潯鐮佸彿锛�" + barcode);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- // 300绔欐嫞鏂�
- public void pick300() {
- try {
- //妫�娴�300绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗┿�佸伐浣滃彿
- for (DevpSlave devp : slaveProperties.getDevp()) {
- // 鑾峰彇鍏ュ簱绔欎俊鎭�
- DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
- StaProtocol staProtocol = devpThread.getStation().get(300);
- if (staProtocol == null) {
- continue;
- }else {
- staProtocol = staProtocol.clone();
- }
-
- if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) {
- //鏌ヨ鏄惁鏈夊伐浣滄。
- WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
- if (wrkMast == null) {
- continue;
- }
-
- if (wrkMast.getWrkSts() != 29) {//29.鍑哄簱瀹屾垚
- continue;
- }
-
- if (wrkMast.getMk() == null) {
- Integer sourceStaNo = wrkMast.getSourceStaNo();//婧愮珯
- Integer staNo = wrkMast.getStaNo();//鐩爣绔�
- //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
- wrkMast.setStaNo(sourceStaNo);
- wrkMast.setSourceStaNo(staNo);
- wrkMast.setMk("N");
- if (wrkMastMapper.updateById(wrkMast) > 0) {
- //鍚�300绔欏啓鍏ョ洰鏍囩珯
- staProtocol = staProtocol.clone();
- staProtocol.setStaNo(wrkMast.getStaNo().shortValue());//绉诲姩鍒扮洰鏍囩珯
- boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
- try {
- Thread.sleep(500);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
* 鍑哄簱 ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣�
*/
public void ledExecute() {
- try {
- for (LedSlave led : slaveProperties.getLed()) {
- // 鑾峰彇杈撻�佺嚎plc绾跨▼
- DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
- // 鍛戒护闆嗗悎
- List<LedCommand> commands = new ArrayList<>();
- // 宸ヤ綔妗i泦鍚�
- List<WrkMast> wrkMasts = new ArrayList<>();
- List<WrkMastLog> wrkMastLogs = new ArrayList<>();
- for (Integer staNo : led.getStaArr()) {
- // 鑾峰彇鍙夎溅绔欑偣
- StaProtocol staProtocol = devpThread.getStation().get(staNo);
- if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) {
- continue;
- } else {
- staProtocol = staProtocol.clone();
- }
- // 鑾峰彇宸ヤ綔妗f暟鎹�
- WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
- Integer wrkNo = staProtocol.getWorkNo().intValue();
- Integer ioType = null;
- String sourceLocNo = null;
- String locNo = null;
- Integer wrkStaNo = null;
- String barcode = null;
- if (wrkMast == null) {
- //鏌ヨ鍘嗗彶妗�
- WrkMastLog wrkMastLog = wrkMastLogMapper.selectLatestByWorkNo(staProtocol.getWorkNo().intValue());
- if (wrkMastLog == null) {
- continue;
- }
- ioType = wrkMastLog.getIoType();
- sourceLocNo = wrkMastLog.getSourceLocNo();
- locNo = wrkMastLog.getLocNo();
- wrkStaNo = wrkMastLog.getStaNo();
- barcode = wrkMastLog.getBarcode();
- wrkMastLogs.add(wrkMastLog);
- }else {
- if (wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) {
- continue;
- }
- ioType = wrkMast.getIoType();
- sourceLocNo = wrkMast.getSourceLocNo();
- locNo = wrkMast.getLocNo();
- wrkStaNo = wrkMast.getStaNo();
- barcode = wrkMast.getBarcode();
- wrkMasts.add(wrkMast);
- }
- // 缁勮鍛戒护
- LedCommand ledCommand = new LedCommand();
- ledCommand.setWorkNo(wrkNo);
- ledCommand.setIoType(ioType);
- // 鍑哄簱妯″紡
- switch (ioType) {
- case 101:
- ledCommand.setTitle("鍏ㄦ澘鍑哄簱");
- break;
- case 103:
- ledCommand.setTitle("鎷f枡鍑哄簱");
- break;
- case 104:
- ledCommand.setTitle("骞舵澘鍑哄簱");
- break;
- case 107:
- ledCommand.setTitle("鐩樼偣鍑哄簱");
- break;
- case 110:
- ledCommand.setTitle("绌烘澘鍑哄簱");
- ledCommand.setEmptyMk(true);
- break;
- default:
- News.error("浠诲姟鍏ュ嚭搴撶被鍨嬮敊璇紒锛侊紒[宸ヤ綔鍙凤細{}] [鍏ュ嚭搴撶被鍨嬶細{}]", wrkNo, ioType);
- break;
- }
- ledCommand.setSourceLocNo(sourceLocNo);
- ledCommand.setLocNo(locNo);
- ledCommand.setStaNo(wrkStaNo);
- ledCommand.setBarcode(barcode);
- if (ioType != 110 && ioType != 10) {
- List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo));
- if (!wrkDetls.isEmpty()) {
- wrkDetls.forEach(wrkDetl -> {
- double remainNum = wrkDetl.getStock() - wrkDetl.getAnfme();//鍓╀綑鏁伴噺
- if (remainNum < 0) {
- remainNum = 0;
- }
- String matnr = wrkDetl.getMatnr();
- Mat mat = matService.selectByMatnr(wrkDetl.getMatnr());
- if (mat != null) {
- if (!mat.getMatnr().equals(mat.getMatnr2())) {
- matnr += " - " + mat.getMatnr2();
- }
- }
- ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetl.getMaktx(), wrkDetl.getAnfme(), remainNum, wrkDetl.getSpecs(), wrkDetl.getSuppCode(), wrkDetl.getOrderNo()));
- });
- }else {
- List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode);
- for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
- double remainNum = wrkDetlLog.getStock() - wrkDetlLog.getAnfme();//鍓╀綑鏁伴噺
- if (remainNum < 0) {
- remainNum = 0;
- }
- String matnr = wrkDetlLog.getMatnr();
- Mat mat = matService.selectByMatnr(wrkDetlLog.getMatnr());
- if (mat != null) {
- if (!mat.getMatnr().equals(mat.getMatnr2())) {
- matnr += " - " + mat.getMatnr2();
- }
- }
- ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), remainNum, wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode()));
- }
- }
-
-// List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
-// if (ioType == 101) {
-// List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo));
-// wrkDetls.forEach(wrkDetl -> {
-// ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), 0D, wrkDetl.getSpecs(), wrkDetl.getSuppCode()));
-// });
-//// locDetls.forEach(locDetl -> {
-//// Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>().eq("matnr", locDetl.getMatnr()).eq("wrk_no", wrkNo);
-//// Utils.wapperSetCondition(wrapper, "batch", locDetl.getBatch());
-//// Utils.wapperSetCondition(wrapper, "three_code", locDetl.getThreeCode());
-//// Utils.wapperSetCondition(wrapper, "dead_time", locDetl.getDeadTime());
-//// Utils.wapperSetCondition(wrapper, "supp_code", locDetl.getSuppCode());//鏂欑鐮�
-//// List<WrkDetl> detl = wrkDetlService.selectList(wrapper);
-//// if (Cools.isEmpty(detl)) {
-//// String suppCode = "";
-//// if (locDetl.getSuppCode() != null) {
-//// suppCode = locDetl.getSuppCode();
-//// }
-//// ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode));
-//// } else {
-//// //鍑哄簱鏁伴噺绱
-//// Double conut = 0.0;
-//// for (WrkDetl wrkDetl : detl) {
-//// conut = conut + wrkDetl.getAnfme();
-//// }
-////
-//// for (WrkDetl wrkDetl : detl) {
-//// String suppCode = "";
-//// if (wrkDetl.getSuppCode() != null) {
-//// suppCode = wrkDetl.getSuppCode();
-//// }
-//// ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (locDetl.getAnfme() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo()));
-//// }
-//// }
-////
-//// });
-// } else {
-// locDetls.forEach(locDetl -> {
-// Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>().eq("matnr", locDetl.getMatnr()).eq("wrk_no", wrkNo);
-// Utils.wapperSetCondition(wrapper, "batch", locDetl.getBatch());
-// Utils.wapperSetCondition(wrapper, "three_code", locDetl.getThreeCode());
-// Utils.wapperSetCondition(wrapper, "dead_time", locDetl.getDeadTime());
-// Utils.wapperSetCondition(wrapper, "supp_code", locDetl.getSuppCode());//鏂欑鐮�
-// List<WrkDetl> detl = wrkDetlService.selectList(wrapper);
-// if (Cools.isEmpty(detl)) {
-// String suppCode = "";
-// if (locDetl.getSuppCode() != null) {
-// suppCode = locDetl.getSuppCode();
-// }
-// ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode));
-// } else {
-// //鍑哄簱鏁伴噺绱
-// Double conut = 0.0;
-// for (WrkDetl wrkDetl : detl) {
-// conut = conut + wrkDetl.getAnfme();
-// }
-//
-// for (WrkDetl wrkDetl : detl) {
-// String suppCode = "";
-// if (wrkDetl.getSuppCode() != null) {
-// suppCode = wrkDetl.getSuppCode();
-// }
-// ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), (wrkDetl.getStock() - conut), wrkDetl.getSpecs(), suppCode, wrkDetl.getOrderNo()));
-// }
-// }
-//
-// });
+// try {
+// for (LedSlave led : slaveProperties.getLed()) {
+// // 鑾峰彇杈撻�佺嚎plc绾跨▼
+// DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
+// // 鍛戒护闆嗗悎
+// List<LedCommand> commands = new ArrayList<>();
+// // 宸ヤ綔妗i泦鍚�
+// List<WrkMast> wrkMasts = new ArrayList<>();
+// List<WrkMastLog> wrkMastLogs = new ArrayList<>();
+// for (Integer staNo : led.getStaArr()) {
+// // 鑾峰彇鍙夎溅绔欑偣
+// StaProtocol staProtocol = devpThread.getStation().get(staNo);
+// if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) {
+// continue;
+// } else {
+// staProtocol = staProtocol.clone();
+// }
+// // 鑾峰彇宸ヤ綔妗f暟鎹�
+// WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
+// Integer wrkNo = staProtocol.getWorkNo().intValue();
+// Integer ioType = null;
+// String sourceLocNo = null;
+// String locNo = null;
+// Integer wrkStaNo = null;
+// String barcode = null;
+// if (wrkMast == null) {
+// //鏌ヨ鍘嗗彶妗�
+// WrkMastLog wrkMastLog = wrkMastLogMapper.selectLatestByWorkNo(staProtocol.getWorkNo().intValue());
+// if (wrkMastLog == null) {
+// continue;
// }
-//
-//
-// if (ioType == 107) {
-// locDetls = new ArrayList<>();
-// ledCommand.setMatDtos(new ArrayList<>());
+// ioType = wrkMastLog.getIoType();
+// sourceLocNo = wrkMastLog.getSourceLocNo();
+// locNo = wrkMastLog.getLocNo();
+// wrkStaNo = wrkMastLog.getStaNo();
+// barcode = wrkMastLog.getBarcode();
+// wrkMastLogs.add(wrkMastLog);
+// }else {
+// if (wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) {
+// continue;
// }
-//
-// if (locDetls.isEmpty() && ioType != 101) {
-// List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo));
+// ioType = wrkMast.getIoType();
+// sourceLocNo = wrkMast.getSourceLocNo();
+// locNo = wrkMast.getLocNo();
+// wrkStaNo = wrkMast.getStaNo();
+// barcode = wrkMast.getBarcode();
+// wrkMasts.add(wrkMast);
+// }
+// // 缁勮鍛戒护
+// LedCommand ledCommand = new LedCommand();
+// ledCommand.setWorkNo(wrkNo);
+// ledCommand.setIoType(ioType);
+// // 鍑哄簱妯″紡
+// switch (ioType) {
+// case 101:
+// ledCommand.setTitle("鍏ㄦ澘鍑哄簱");
+// break;
+// case 103:
+// ledCommand.setTitle("鎷f枡鍑哄簱");
+// break;
+// case 104:
+// ledCommand.setTitle("骞舵澘鍑哄簱");
+// break;
+// case 107:
+// ledCommand.setTitle("鐩樼偣鍑哄簱");
+// break;
+// case 110:
+// ledCommand.setTitle("绌烘澘鍑哄簱");
+// ledCommand.setEmptyMk(true);
+// break;
+// default:
+// News.error("浠诲姟鍏ュ嚭搴撶被鍨嬮敊璇紒锛侊紒[宸ヤ綔鍙凤細{}] [鍏ュ嚭搴撶被鍨嬶細{}]", wrkNo, ioType);
+// break;
+// }
+// ledCommand.setSourceLocNo(sourceLocNo);
+// ledCommand.setLocNo(locNo);
+// ledCommand.setStaNo(wrkStaNo);
+// ledCommand.setBarcode(barcode);
+// if (ioType != 110 && ioType != 10) {
+// List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo));
+// if (!wrkDetls.isEmpty()) {
// wrkDetls.forEach(wrkDetl -> {
-// if (wrkDetl.getAnfme() > 0D) {
-// ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(), wrkDetl.getAnfme(), wrkDetl.getSpecs(), wrkDetl.getSuppCode()));
+// double remainNum = wrkDetl.getStock() - wrkDetl.getAnfme();//鍓╀綑鏁伴噺
+// if (remainNum < 0) {
+// remainNum = 0;
// }
-// });
-//
-// if (wrkDetls.isEmpty()) {//浠庡巻鍙叉。鏌ヨ
-// List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode);
-// for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
-// if (wrkDetlLog.getAnfme() > 0D) {
-// ledCommand.getMatDtos().add(new MatDto(wrkDetlLog.getMatnr(), wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), wrkDetlLog.getAnfme(), wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode()));
+// String matnr = wrkDetl.getMatnr();
+// Mat mat = matService.selectByMatnr(wrkDetl.getMatnr());
+// if (mat != null) {
+// if (!mat.getMatnr().equals(mat.getMatnr2())) {
+// matnr += " - " + mat.getMatnr2();
// }
// }
+// ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetl.getMaktx(), wrkDetl.getAnfme(), remainNum, wrkDetl.getSpecs(), wrkDetl.getSuppCode(), wrkDetl.getOrderNo()));
+// });
+// }else {
+// List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode);
+// for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
+// double remainNum = wrkDetlLog.getStock() - wrkDetlLog.getAnfme();//鍓╀綑鏁伴噺
+// if (remainNum < 0) {
+// remainNum = 0;
+// }
+// String matnr = wrkDetlLog.getMatnr();
+// Mat mat = matService.selectByMatnr(wrkDetlLog.getMatnr());
+// if (mat != null) {
+// if (!mat.getMatnr().equals(mat.getMatnr2())) {
+// matnr += " - " + mat.getMatnr2();
+// }
+// }
+// ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), remainNum, wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode()));
// }
// }
- }
-
- commands.add(ledCommand);
- }
- Set<Integer> workNos = null;
- if (!wrkMasts.isEmpty()) {
- workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet());
- }else {
- workNos = wrkMastLogs.stream().map(WrkMastLog::getWrkNo).collect(Collectors.toSet());
- }
- // 鑾峰彇LED绾跨▼
- LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
- // 鐩稿悓宸ヤ綔鍙烽泦鍚堝垯杩囨护
- if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
- continue;
- }
- // 鍛戒护涓嬪彂 -------------------------------------------------------------------------------
- if (!commands.isEmpty()) {
- if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
- log.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
- continue;
- } else {
- ledThread.setLedMk(false);
- }
- }
-
- try {
- // 淇敼涓绘。led鏍囪
- for (WrkMast wrkMast : wrkMasts) {
- wrkMast.setOveMk("Y");
- wrkMast.setModiTime(new Date());
- if (wrkMastMapper.updateById(wrkMast) == 0) {
- throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�");
- }
- }
-
- // 鏇存柊绾跨▼褰撳墠宸ヤ綔鍙烽泦鍚�
- ledThread.setWorkNos(workNos);
-
- } catch (Exception e) {
- e.printStackTrace();
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- }
-
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
+// commands.add(ledCommand);
+// }
+// Set<Integer> workNos = null;
+// if (!wrkMasts.isEmpty()) {
+// workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet());
+// }else {
+// workNos = wrkMastLogs.stream().map(WrkMastLog::getWrkNo).collect(Collectors.toSet());
+// }
+// // 鑾峰彇LED绾跨▼
+// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
+// // 鐩稿悓宸ヤ綔鍙烽泦鍚堝垯杩囨护
+// if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
+// continue;
+// }
+// // 鍛戒护涓嬪彂 -------------------------------------------------------------------------------
+// if (!commands.isEmpty()) {
+// if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
+// log.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+// continue;
+// } else {
+// ledThread.setLedMk(false);
+// }
+// }
+//
+// try {
+// // 淇敼涓绘。led鏍囪
+// for (WrkMast wrkMast : wrkMasts) {
+// wrkMast.setOveMk("Y");
+// wrkMast.setModiTime(new Date());
+// if (wrkMastMapper.updateById(wrkMast) == 0) {
+// throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�");
+// }
+// }
+//
+// // 鏇存柊绾跨▼褰撳墠宸ヤ綔鍙烽泦鍚�
+// ledThread.setWorkNos(workNos);
+//
+// } catch (Exception e) {
+// e.printStackTrace();
+// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+// }
+//
+// }
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
}
/**
--
Gitblit v1.9.1