From 1c3238b839423098a30ad62407a5c61266c04090 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 03 九月 2020 13:38:17 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 265 +++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 217 insertions(+), 48 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 6b2276e..0e21aec 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -9,28 +9,34 @@
import com.zy.asrs.mapper.WaitPakinMapper;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.*;
+import com.zy.common.model.MatDto;
import com.zy.common.model.StartupDto;
+import com.zy.common.service.CommonService;
+import com.zy.common.utils.CollectionUtils;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.*;
import com.zy.core.model.CrnSlave;
import com.zy.core.model.DevpSlave;
+import com.zy.core.model.LedSlave;
import com.zy.core.model.Task;
import com.zy.core.model.command.CrnCommand;
+import com.zy.core.model.command.LedCommand;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.thread.BarcodeThread;
import com.zy.core.thread.CrnThread;
import com.zy.core.thread.DevpThread;
+import com.zy.core.thread.LedThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -39,6 +45,7 @@
*/
@Slf4j
@Service("mainService")
+@Transactional
public class MainServiceImpl {
@Autowired
@@ -65,7 +72,7 @@
/**
* 鍏ュ簱绔欙紝鏍规嵁鏉$爜鎵弿鐢熸垚鍏ュ簱宸ヤ綔妗o紝宸ヤ綔鐘舵�� 2
*/
- @Transactional
+ @Async
public void generateStoreWrkFile() {
// 鏍规嵁杈撻�佺嚎plc閬嶅巻
for (DevpSlave devp : slaveProperties.getDevp()) {
@@ -77,9 +84,12 @@
// 鑾峰彇鍏ュ簱绔欎俊鎭�
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
+ if (staProtocol == null) {
+ continue;
+ }
// 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
if (staProtocol.isAutoing() && staProtocol.isLoading()
- && !staProtocol.isEmptyMk() && staProtocol.isInreq1() && staProtocol.getWorkNo()==0
+ && !staProtocol.isEmptyMk() && staProtocol.getWorkNo() == 0
&& staProtocol.isPakMk() && !Cools.isEmpty(barcode)) {
// 鍒ゆ柇閲嶅宸ヤ綔妗�
WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
@@ -88,7 +98,7 @@
continue;
}
// 鑾峰彇鍏ュ簱閫氱煡妗�
- List<WaitPakin> waitPakins = waitPakinMapper.selectList(new EntityWrapper<WaitPakin>().eq("barcode", barcode));
+ List<WaitPakin> waitPakins = waitPakinMapper.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("io_status", "N"));
if (waitPakins.isEmpty()) {
log.warn("鏃犳鍏ュ簱鏉$爜鏁版嵁銆傛潯鐮佸彿={}", barcode);
continue;
@@ -133,6 +143,10 @@
if (!locMastService.updateById(locMast)){
throw new CoolException("鏀瑰彉搴撲綅鐘舵�佸け璐�");
}
+ // 灏嗗叆搴撻�氱煡妗d慨鏀逛负宸插惎鍔�
+ if (wrkMastMapper.updateWaitPakInStep1(barcode) == 0) {
+ throw new CoolException("淇敼鍏ュ簱閫氱煡妗g姸鎬佷负宸插惎鍔�");
+ }
// 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
@@ -146,6 +160,7 @@
if (!result) {
throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
}
+ staProtocol.setPakMk(false);
}
@@ -155,10 +170,60 @@
}
+ /**
+ * 鍏ュ簱绔欙紝鏍规嵁鏉$爜鎵弿鐢熸垚鍏ュ簱宸ヤ綔妗o紝宸ヤ綔鐘舵�� 1 ==>> 2
+ */
+ @Async
+ public void generateStoreWrkFile2() {
+ // 鏍规嵁杈撻�佺嚎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; }
+ // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢
+ if (staProtocol.isAutoing() && staProtocol.isLoading()
+ && !staProtocol.isEmptyMk() && staProtocol.getWorkNo() == 0
+ && staProtocol.isPakMk()) {
+ // 鍒ゆ柇閲嶅宸ヤ綔妗�
+ WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
+ if (wrkMast == null) {
+ continue;
+ }
+
+ // 鏇存柊宸ヤ綔涓绘。
+ wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵�侊細2.璁惧涓婅蛋
+ wrkMast.setModiTime(new Date());
+ Integer update = wrkMastMapper.updateById(wrkMast);
+ if (update == 0) {
+ throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�");
+ }
+
+ // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
+
+ // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
+ staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
+ staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
+ boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+ if (!result) {
+ throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
+ }
+ staProtocol.setPakMk(false);
+
+ }
+
+
+ }
+ }
+
+ }
/**
* 鎷f枡銆佸苟鏉裤�佺洏鐐瑰啀鍏ュ簱
*/
+ @Async
public void stnToCrnStnPick(){
for (DevpSlave devp : slaveProperties.getDevp()) {
// 閬嶅巻鎷f枡鍏ュ簱鍙�
@@ -166,7 +231,7 @@
// 鑾峰彇鎷f枡鍏ュ簱绔欎俊鎭�
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
StaProtocol staProtocol = devpThread.getStation().get(pickSta.getStaNo());
-
+ if (staProtocol == null) { continue; }
if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInreq1()
&& staProtocol.getWorkNo() > 0 && staProtocol.isPakMk()){
WrkMast wrkMast = wrkMastMapper.selectPickStep(staProtocol.getWorkNo().intValue());
@@ -236,13 +301,15 @@
/**
* 鍫嗗灈鏈虹珯鍑哄簱鍒板嚭搴撶珯
*/
+ @Async
public void crnStnToOutStn() {
- for (DevpSlave devp : slaveProperties.getDevp()) {
- // 閬嶅巻鎷f枡鍏ュ簱鍙�
- for (DevpSlave.Sta outSta : devp.getOutSta()) {
+ for (CrnSlave crnSlave : slaveProperties.getCrn()) {
+ // 閬嶅巻鍫嗗灈鏈哄嚭搴撶珯
+ for (CrnSlave.CrnStn crnStn : crnSlave.getCrnOutStn()) {
// 鑾峰彇鍫嗗灈鏈哄嚭搴撶珯淇℃伅
- DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
- StaProtocol staProtocol = devpThread.getStation().get(outSta.getStaNo());
+ DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
+ StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
+ if (staProtocol == null) { continue; }
if (staProtocol.isAutoing() && staProtocol.isLoading() && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
// 鏌ヨ宸ヤ綔妗�
WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId());
@@ -260,32 +327,32 @@
// 绉诲姩涓�
continue;
}
- // 鏇存柊宸ヤ綔妗g姸鎬佷负14澶辫触 todo:luxiaotao
+ // 鍒ゆ柇鍫嗗灈鏈虹姸鎬佺瓑寰呯‘璁�
if (crnProtocol.modeType == CrnModeType.AUTO && crnProtocol.getTaskNo().equals(wrkMast.getWrkNo().shortValue())
- && crnProtocol.statusType == CrnStatusType.IDLE
+ && crnProtocol.statusType == CrnStatusType.WAITING
&& crnProtocol.forkPosType == CrnForkPosType.HOME) {
+
+ // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
+
+ // 1.澶嶄綅鍫嗗灈鏈�
+ crnThread.setResetFlag(true);
+
+ // 2.涓嬪彂绔欑偣淇℃伅
+ staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
+ staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
+ if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
+ throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
+ }
+
+ // 鏇存柊宸ヤ綔妗g姸鎬佷负14澶辫触
wrkMast.setWrkSts(14L);
wrkMast.setCrnEndTime(new Date());
if (wrkMastMapper.updateById(wrkMast) == 0) {
throw new CoolException("鏇存柊宸ヤ綔妗g殑宸ヤ綔鐘舵�佷负14澶辫触锛屽伐浣滃彿"+wrkMast.getWrkNo());
}
+
}
- // 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
-
- // 1.澶嶄綅鍫嗗灈鏈� 鏇存柊鍫嗗灈鏈轰俊鎭� 涓� 涓嬪彂plc鍛戒护 todo:luxiaotao
- crnProtocol.setStatus(CrnStatusType.IDLE);
- crnProtocol.setTaskNo((short)0);
- if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(4, crnProtocol))) {
- throw new CoolException("鏇存柊鍫嗗灈鏈轰俊鎭け璐�");
- }
-
- // 2.涓嬪彂绔欑偣淇℃伅
- staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
- staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
- if (!MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol))) {
- throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
- }
}
}
}
@@ -294,11 +361,13 @@
/**
* 鍏ュ嚭搴� ===>> 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂
*/
+ @Async
public void crnIoExecute(){
for (CrnSlave crn : slaveProperties.getCrn()) {
// 鑾峰彇鍫嗗灈鏈轰俊鎭�
CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
CrnProtocol crnProtocol = crnThread.getCrnProtocol();
+ if (crnProtocol == null) { continue; }
BasCrnp basCrnp = basCrnpService.selectById(crn.getId());
if (basCrnp == null) {
log.error("{}鍙峰爢鍨涙満灏氭湭鍦ㄦ暟鎹簱杩涜缁存姢锛�", crn.getId());
@@ -309,45 +378,48 @@
// 濡傛灉鏈�杩戜竴娆℃槸鍏ュ簱妯″紡
if (crnProtocol.getLastIo().equals("I")) {
if (basCrnp.getInEnable().equals("Y")) {
- this.crnStnToLoc(crn); // 鍏ュ簱
+ this.crnStnToLoc(crn, crnProtocol); // 鍏ュ簱
crnProtocol.setLastIo("O");
} else if (basCrnp.getOutEnable().equals("Y")) {
- this.locToCrnStn(crn); // 鍑哄簱
+ this.locToCrnStn(crn, crnProtocol); // 鍑哄簱
crnProtocol.setLastIo("I");
}
}
// 濡傛灉鏈�杩戜竴娆℃槸鍑哄簱妯″紡
else if (crnProtocol.getLastIo().equals("O")) {
if (basCrnp.getOutEnable().equals("Y")) {
- this.locToCrnStn(crn); // 鍑哄簱
+ this.locToCrnStn(crn, crnProtocol); // 鍑哄簱
crnProtocol.setLastIo("I");
} else if (basCrnp.getInEnable().equals("Y")) {
- this.crnStnToLoc(crn); // 鍏ュ簱
+ this.crnStnToLoc(crn, crnProtocol); // 鍏ュ簱
crnProtocol.setLastIo("O");
}
}
}
// 搴撲綅绉昏浆
- this.locToLoc(crn);
+ this.locToLoc(crn, crnProtocol);
}
}
/**
* 鍏ュ簱 ===>> 鍫嗗灈鏈虹珯鍒板簱浣�
*/
- private void crnStnToLoc(CrnSlave slave){
+ @Async
+ public void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol){
for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) {
boolean flag = false;
// 鑾峰彇鍫嗗灈鏈哄叆搴撶珯淇℃伅
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
+ if (staProtocol == null) { continue; }
// 鏌ヨ绔欑偣璇︾粏淇℃伅
BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
if (staDetl == null) {
log.error("鍏ュ簱 ===>> 鍫嗗灈鏈虹珯鐐瑰湪鏁版嵁搴撲笉瀛樺湪, 绔欑偣缂栧彿={}", crnStn.getStaNo());
continue;
}
- if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staDetl.getCanining().equals("Y")) {
+ if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0
+ && staDetl.getCanining()!=null && staDetl.getCanining().equals("Y")) {
flag = true;
}
if (!flag) {
@@ -367,6 +439,11 @@
}
if (!locMast.getLocSts().equals("S") && !locMast.getLocSts().equals("Q")) {
log.error("鍏ュ簱鎿嶄綔搴撲綅鐘舵�佷笉绗﹀悎--鐘舵��, 搴撲綅鍙�={}锛屽簱浣嶇姸鎬�={}", wrkMast.getLocNo(), locMast.getLocSts());
+ continue;
+ }
+
+ // 鍫嗗灈鏈烘帶鍒惰繃婊�
+ if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
continue;
}
@@ -400,7 +477,8 @@
/**
* 鍑哄簱 ===>> 搴撲綅鍒板爢鍨涙満绔�
*/
- private void locToCrnStn(CrnSlave slave){
+ @Async
+ public void locToCrnStn(CrnSlave slave, CrnProtocol crnProtocol){
for (CrnSlave.CrnStn crnStn : slave.getCrnOutStn()) {
// 鑾峰彇宸ヤ綔鐘舵�佷负11锛堢敓鎴愬嚭搴揑D锛夌殑鍑哄簱宸ヤ綔妗�
WrkMast wrkMast = wrkMastMapper.selectPakOutStep1(slave.getId());
@@ -421,6 +499,7 @@
// 鑾峰彇鍫嗗灈鏈哄嚭搴撶珯淇℃伅
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
+ if (staProtocol == null) { continue; }
// 鏌ヨ绔欑偣璇︾粏淇℃伅
BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
if (staDetl == null) {
@@ -428,9 +507,14 @@
continue;
}
// 鍒ゆ柇鍫嗗灈鏈哄嚭搴撶珯鐘舵��
- if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting().equals("Y")
+ if (staProtocol.isAutoing() && !staProtocol.isLoading() && staDetl.getCanouting() !=null && staDetl.getCanouting().equals("Y")
&& staProtocol.getWorkNo() == 0) {
// 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
+
+ // 鍫嗗灈鏈烘帶鍒惰繃婊�
+ if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
+ continue;
+ }
// 1.鍫嗗灈鏈哄紑濮嬬Щ鍔�
CrnCommand crnCommand = new CrnCommand();
@@ -463,7 +547,8 @@
/**
* 搴撲綅绉昏浆
*/
- private void locToLoc(CrnSlave slave){
+ @Async
+ public void locToLoc(CrnSlave slave, CrnProtocol crnProtocol){
// 鑾峰彇宸ヤ綔妗d俊鎭�
WrkMast wrkMast = wrkMastMapper.selectLocMove(slave.getId());
if (null == wrkMast) {
@@ -490,6 +575,12 @@
if (!basCrnp.getInEnable().equals("Y") && !basCrnp.getOutEnable().equals("Y")) {
return;
}
+
+ // 鍫嗗灈鏈烘帶鍒惰繃婊�
+ if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
+ return;
+ }
+
// 鍛戒护涓嬪彂鍖� --------------------------------------------------------------------------
CrnCommand crnCommand = new CrnCommand();
crnCommand.setCrnNo(slave.getId()); // 鍫嗗灈鏈虹紪鍙�
@@ -504,17 +595,29 @@
crnCommand.setDestinationPosZ(sta.getLev1().shortValue()); // 鐩爣搴撲綅灞�
if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
log.error("鍫嗗灈鏈哄懡浠や笅鍙戝け璐ワ紝鍫嗗灈鏈哄彿={}锛屼换鍔℃暟鎹�={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
+ } else {
+ // 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓�
+ Date now = new Date();
+ wrkMast.setWrkSts(12L);
+ wrkMast.setCrnStrTime(now);
+ wrkMast.setModiTime(now);
+ if (wrkMastMapper.updateById(wrkMast) == 0) {
+ log.error("銆愬簱浣嶇Щ杞�� 淇敼宸ヤ綔妗g姸鎬� 11.鐢熸垚鍑哄簱ID => 12.鍚婅溅鍑哄簱涓� 澶辫触锛侊紒锛屽伐浣滃彿={}", wrkMast.getWrkNo());
+ }
}
+
}
/**
* 鎵ц瀵瑰伐浣滄。鐨勫畬鎴愭搷浣�
*/
+ @Async
public void storeFinished() {
for (CrnSlave crn : slaveProperties.getCrn()) {
// 鑾峰彇鍫嗗灈鏈轰俊鎭�
CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
CrnProtocol crnProtocol = crnThread.getCrnProtocol();
+ if (crnProtocol == null) { continue; }
// 鐘舵�侊細绛夊緟纭 骞朵笖 浠诲姟瀹屾垚浣� = 1
if (crnProtocol.statusType == CrnStatusType.WAITING && crnProtocol.getTaskNo() != 0) {
// 鑾峰彇鍏ュ簱寰呯‘璁ゅ伐浣滄。
@@ -527,20 +630,26 @@
if (wrkMast.getWrkSts() == 3 || (wrkMast.getWrkSts() == 12 && wrkMast.getIoType() == 11)){
wrkMast.setWrkSts(4L);
// 鍑哄簱 + 鎷f枡/鐩樼偣/骞舵澘鍑哄簱涓細12.鍚婅溅鍑哄簱涓� ==> 14.鍑哄簱瀹屾垚
- } else if (wrkMast.getWrkSts() == 12) {
- wrkMast.setWrkSts(14L);
+ // todo:luxiaotao
+// } else if (wrkMast.getWrkSts() == 12) {
+// wrkMast.setWrkSts(14L);
+ } else {
+ continue;
}
Date now = new Date();
wrkMast.setCrnEndTime(now);
wrkMast.setModiTime(now);
// 淇敼鎴愬姛鍚庡浣嶅爢鍨涙満
if (wrkMastMapper.updateById(wrkMast) > 0) {
- // 鍛戒护涓嬪彂鍖� -------------------------------------------------------------------------
// 鍫嗗灈鏈哄浣�
- if (!MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(3, new CrnCommand()))) {
- log.error("鍫嗗灈鏈哄浣嶅懡浠や笅鍙戝け璐ワ紝宸ヤ綔鍙�={}", wrkMast.getWrkNo());
- }
+ crnThread.setResetFlag(true);
}
+
+ // 瀹屾垚閫氱煡妗�
+// if (wrkMastMapper.updateWaitPakInStep2(wrkMast.getBarcode()) == 0) {
+// log.error("鍏ュ簱閫氱煡妗d慨鏀圭粨鏉熺姸鎬佸け璐ワ紝workNo=[{}]", wrkMast.getWrkNo());
+// }
+
}
}
}
@@ -558,6 +667,7 @@
/**
* 绌烘爤鏉垮垵濮嬪寲鍏ュ簱,鍙夎溅鍏ュ簱绔欐斁璐�
*/
+ @Async
public void storeEmptyPlt(){
for (DevpSlave devp : slaveProperties.getDevp()) {
// 閬嶅巻绌烘澘鍏ュ簱鍙�
@@ -565,13 +675,14 @@
// 鑾峰彇绌烘澘鍏ュ簱绔欎俊鎭�
DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
StaProtocol staProtocol = devpThread.getStation().get(emptyInSta.getStaNo());
+ if (staProtocol == null) { continue; }
// 绔欑偣鏉′欢鍒ゆ柇
- if (staProtocol.isAutoing() && staProtocol.isLoading() && !staProtocol.isInreq1()
+ if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable()
&& staProtocol.isEmptyMk() && staProtocol.getWorkNo() == 0 && staProtocol.isPakMk()) {
// 宸ヤ綔鍙�
int workNo = commonService.getWorkNo(0);
// 妫�绱㈠簱浣�
- StartupDto startupDto = commonService.getLocNo(1, 1, emptyInSta.getStaNo(), null);
+ StartupDto startupDto = commonService.getLocNo(1, 10, emptyInSta.getStaNo(), null);
// 鎻掑叆宸ヤ綔涓绘。
WrkMast wrkMast = new WrkMast();
@@ -609,13 +720,12 @@
// 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
staProtocol.setWorkNo((short) workNo);
staProtocol.setStaNo(startupDto.getStaNo().shortValue());
- staProtocol.setPakMk(false);
- staProtocol.setInreq1(false);
boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
if (!result) {
throw new CoolException("鏇存柊plc绔欑偣淇℃伅澶辫触");
}
+ staProtocol.setPakMk(false);
}
@@ -623,4 +733,63 @@
}
}
+ /**
+ * 鍑哄簱 ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣�
+ */
+ @Async
+ public void ledExecute() {
+ 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<>();
+ for (Integer staNo : led.getStaArr()) {
+ // 鑾峰彇鍙夎溅绔欑偣
+ StaProtocol staProtocol = devpThread.getStation().get(staNo);
+ if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo()) { continue; }
+ // 鑾峰彇宸ヤ綔妗f暟鎹�
+ WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
+ if (wrkMast.getWrkSts() == 14L || wrkMast.getWrkSts() == 15L) {
+ wrkMasts.add(wrkMast);
+ // 娣诲姞鍛戒护
+ List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
+ LedCommand ledCommand = new LedCommand();
+ ledCommand.setWorkNo(wrkMast.getWrkNo());
+ ledCommand.setSourceLocNo(wrkMast.getSourceLocNo());
+ ledCommand.setStaNo(wrkMast.getStaNo());
+ wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMatnr(), wrkDetl.getAnfme())));
+ commands.add(ledCommand);
+ }
+ }
+ Set<Integer> workNos = wrkMasts.stream().map(WrkMast::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))) {
+ continue;
+ }
+ }
+
+ // 淇敼涓绘。led鏍囪
+ for (WrkMast wrkMast : wrkMasts) {
+ wrkMast.setOveMk("Y");
+ wrkMast.setModiTime(new Date());
+ if (wrkMastMapper.updateById(wrkMast) == 0) {
+ throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�");
+ }
+ }
+
+ // 鏇存柊绾跨▼褰撳墠宸ヤ綔鍙烽泦鍚�
+ ledThread.setWorkNos(workNos);
+
+ }
+ }
+
}
--
Gitblit v1.9.1