From 314729da5f6f84a6112344a2210aadfeeb2bac0c Mon Sep 17 00:00:00 2001
From: zjj <3272660260@qq.com>
Date: 星期一, 21 四月 2025 10:35:43 +0800
Subject: [PATCH] #出库找待机位优化
---
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java | 143 ++++++++++++++++++++++++++++++++++-------------
1 files changed, 104 insertions(+), 39 deletions(-)
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java
index eac27b4..e4f79c6 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/SiemensDevpThread.java
@@ -9,12 +9,16 @@
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.DateUtils;
import com.zy.asrs.framework.common.SpringUtils;
-import com.zy.asrs.wcs.core.entity.Station;
-import com.zy.asrs.wcs.core.service.StationService;
+import com.zy.asrs.wcs.core.entity.BasConveyor;
+import com.zy.asrs.wcs.core.entity.BasConveyorSta;
+import com.zy.asrs.wcs.core.service.BasConveyorService;
+import com.zy.asrs.wcs.core.service.BasConveyorStaService;
import com.zy.asrs.wcs.core.utils.RedisUtil;
import com.zy.asrs.wcs.rcs.News;
import com.zy.asrs.wcs.rcs.cache.OutputQueue;
import com.zy.asrs.wcs.rcs.entity.Device;
+import com.zy.asrs.wcs.rcs.model.dto.WorkModeTypeDto;
+import com.zy.asrs.wcs.rcs.model.enums.WorkModeType;
import com.zy.asrs.wcs.rcs.model.protocol.StaProtocol;
import com.zy.asrs.wcs.rcs.thread.DevpThread;
import lombok.extern.slf4j.Slf4j;
@@ -35,27 +39,44 @@
private Map<Integer, StaProtocol> station = new ConcurrentHashMap<>();
- public static ArrayList<Station> stationList = new ArrayList<>();
+ public static ArrayList<BasConveyorSta> stationList = new ArrayList<>();
/**
* 鏉$爜鏁伴噺
*/
private int barcodeSize = 2;
+ /**
+ * 鍏ュ嚭搴撴ā寮�
+ * 0锛氭湭鐭�
+ * 1锛氬叆搴撳惎鍔ㄤ腑
+ * 2.鍏ュ簱妯″紡
+ * 3.鍑哄簱鍚姩涓� 锛堜笉鑳界敓鎴愬叆搴撳伐浣滄。锛�
+ * 4.鍑哄簱妯″紡
+ */
+ private Map<Integer, WorkModeTypeDto> workModeTypes = new ConcurrentHashMap<>();
+
public SiemensDevpThread(Device device, RedisUtil redisUtil) {
this.device = device;
this.redisUtil = redisUtil;
+
+ workModeTypes.put(101, new WorkModeTypeDto(101, WorkModeType.NONE, "DB1001.120"));
}
- private ArrayList<Station> getStaNo() {
+ private ArrayList<BasConveyorSta> getStaNo() {
try {
if (stationList.isEmpty()) {
- StationService stationService = SpringUtils.getBean(StationService.class);
- List<Station> stations = stationService.list(new LambdaQueryWrapper<Station>()
- .eq(Station::getDeviceId, device.getId())
- .eq(Station::getStatus, 1)
- .eq(Station::getHostId, device.getHostId()));
- stationList.addAll(stations);
+ BasConveyorService basConveyorService = SpringUtils.getBean(BasConveyorService.class);
+ BasConveyorStaService basConveyorStaService = SpringUtils.getBean(BasConveyorStaService.class);
+ BasConveyor basConveyor = basConveyorService.getOne(new LambdaQueryWrapper<BasConveyor>()
+ .eq(BasConveyor::getDeviceId, device.getId())
+ .eq(BasConveyor::getHostId, device.getHostId()));
+ if(basConveyor != null) {
+ List<BasConveyorSta> stations = basConveyorStaService.list(new LambdaQueryWrapper<BasConveyorSta>()
+ .eq(BasConveyorSta::getConveyorId, basConveyor.getId())
+ .eq(BasConveyorSta::getHostId, device.getHostId()));
+ stationList.addAll(stations);
+ }
}
return stationList;
} catch (Exception e) {
@@ -79,13 +100,13 @@
}
private void read() throws InterruptedException {
- ArrayList<Station> staNos = getStaNo();
+ ArrayList<BasConveyorSta> staNos = getStaNo();
int staNoSize = staNos.size();
OperateResultExOne<byte[]> result = siemensS7Net.Read("DB101.0", (short) (staNoSize*8));
if (result.IsSuccess) {
for (int i = 0; i < staNoSize; i++) {
- Station siteStation = staNos.get(i);
- int siteId = Integer.parseInt(siteStation.getStaNo());// 绔欑偣缂栧彿
+ BasConveyorSta siteStation = staNos.get(i);
+ int siteId = siteStation.getSiteNo();// 绔欑偣缂栧彿
StaProtocol staProtocol = station.get(siteId);
if (null == staProtocol) {
staProtocol = new StaProtocol();
@@ -112,27 +133,13 @@
}
}
- // 鏉$爜鎵弿鍣�
Thread.sleep(200);
- OperateResultExOne<byte[]> result2 = null;
- result2 = siemensS7Net.Read("DB101.840.0", (short) (barcodeSize * 8));
- if (result2.IsSuccess) {
- for (int i = 0; i < barcodeSize; i++) {
- String barcode = siemensS7Net.getByteTransform().TransString(result2.Content, i * 8, 8, "UTF-8");
-// BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, i + 1);
-// if (!Cools.isEmpty(barcodeThread) && !barcodeThread.getBarcode().equals(barcode)) {
-// barcodeThread.setBarcode(barcode);
-// }
- }
- }
-
- Thread.sleep(200);
- ArrayList<Station> errorStaNo = getStaNo();
+ ArrayList<BasConveyorSta> errorStaNo = getStaNo();
OperateResultExOne<byte[]> result3 = siemensS7Net.Read("DB101.800.0", (short) (errorStaNo.size() * 4));
if (result3.IsSuccess) {
for (int i = 0; i < errorStaNo.size(); i++) {
- Station siteStation = errorStaNo.get(i);
- Integer siteId = Integer.parseInt(siteStation.getStaNo()); // 绔欑偣缂栧彿
+ BasConveyorSta siteStation = errorStaNo.get(i);
+ Integer siteId = siteStation.getSiteNo(); // 绔欑偣缂栧彿
StaProtocol staProtocol = station.get(siteId);
boolean[] status = siemensS7Net.getByteTransform().TransBool(result3.Content, (i * 4 + 2), 2);
staProtocol.setFrontErr(status[0]);//鍓嶈秴闄�
@@ -151,16 +158,16 @@
// 鏍规嵁瀹炴椂淇℃伅鏇存柊鏁版嵁搴�
try {
- List<Station> stations = new ArrayList<>();
- for (Station sta : getStaNo()) {
- StaProtocol staProtocol = station.get(Integer.parseInt(sta.getStaNo()));
- Station sqlModel = staProtocol.toSqlModel(sta);
+ List<BasConveyorSta> stations = new ArrayList<>();
+ for (BasConveyorSta sta : getStaNo()) {
+ StaProtocol staProtocol = station.get(sta.getSiteNo());
+ BasConveyorSta sqlModel = staProtocol.toSqlModel(sta);
stations.add(sqlModel);
}
if (!stations.isEmpty()) {
- StationService stationService = SpringUtils.getBean(StationService.class);
- if (null != stationService && !stationService.updateBatchById(stations)) {
+ BasConveyorStaService basConveyorStaService = SpringUtils.getBean(BasConveyorStaService.class);
+ if (null != basConveyorStaService && !basConveyorStaService.updateBatchById(stations)) {
throw new Exception("鏇存柊鏁版嵁搴撴暟鎹け璐�");
}
}
@@ -244,21 +251,79 @@
}
@Override
+ public boolean writeWorkSta(int siteId, short workNo, short staNo) {
+ int index = findStaNosIndex(siteId);
+
+ OperateResult write1 = siemensS7Net.Write("DB100." + index*6, workNo); // 宸ヤ綔鍙�
+ OperateResult write2 = siemensS7Net.Write("DB100." + (index*6+4), staNo); // 鐩爣绔�
+
+ if (!(write1.IsSuccess && write2.IsSuccess)) {
+ StaProtocol staProtocol = station.get(siteId);
+ if (staProtocol.getWorkNo() == 0 && staProtocol.getStaNo() ==0) {
+ staProtocol.setPakMk(true);
+ }
+ OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆戝啓鍏ヨ緭閫佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={1}锛岀珯鐐规暟鎹�={2}", device.getId(), JSON.toJSON(staProtocol)));
+ log.error("鍐欏叆杈撻�佺嚎绔欑偣鏁版嵁澶辫触銆傝緭閫佺嚎plc缂栧彿={}锛岀珯鐐规暟鎹�={}", device.getId(), JSON.toJSON(staProtocol));
+ } else {
+ OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆� 杈撻�佺嚎鍛戒护涓嬪彂 [id:{1}] >>>>> {2}", DateUtils.convert(new Date()), device.getId(), JSON.toJSON(staNo)));
+ log.info("杈撻�佺嚎鍛戒护涓嬪彂 [id:{}] >>>>> 鍛戒护涓嬪彂锛� {}", device.getId(), JSON.toJSON(staNo));
+ return true;
+ }
+ return false;
+ }
+
+ @Override
public Map<Integer, StaProtocol> getStation() {
return this.station;
}
private int findStaNosIndex(int siteId) {
- ArrayList<Station> staNos = getStaNo();
+ ArrayList<BasConveyorSta> staNos = getStaNo();
int index = -1;
for (int i = 0; i < staNos.size(); i++) {
- Station sta = staNos.get(i);
- if (Integer.parseInt(sta.getStaNo()) == siteId) {
+ BasConveyorSta sta = staNos.get(i);
+ if (sta.getSiteNo() == siteId) {
index = i;
break;
}
}
return index;
}
+
+ /**
+ * 璁剧疆鍏ュ簱鏍囪
+ */
+ @Override
+ public void setPakMk(Integer siteId, boolean pakMk) {
+ StaProtocol staProtocol = station.get(siteId);
+ if (null != staProtocol) {
+ staProtocol.setPakMk(pakMk);
+ }
+ }
+
+ private void updateWorkMode() {
+ for (Map.Entry<Integer, WorkModeTypeDto> entry : workModeTypes.entrySet()) {
+ WorkModeTypeDto workModeTypeDto = entry.getValue();
+ WorkModeType workModeType = workModeTypeDto.getWorkModeType();
+ if (workModeType != WorkModeType.NONE) {
+ if (!siemensS7Net.Write(workModeTypeDto.getAddress(), workModeType.id).IsSuccess) {
+ OutputQueue.DEVP.offer(MessageFormat.format("鍐欏叆杈撻�佺嚎{1}鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎缂栧彿={0}", device.getId(), workModeTypeDto.getSiteId()));
+ log.error("鍐欏叆杈撻�佺嚎{1}鍏ュ嚭搴撴ā寮忓け璐ャ�傝緭閫佺嚎缂栧彿={0}", device.getId(), workModeTypeDto.getSiteId());
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean switchWorkMode(int siteId, int workMode) {
+ WorkModeTypeDto workModeTypeDto = workModeTypes.get(siteId);
+ if(workModeTypeDto == null) {
+ return false;
+ }
+
+ workModeTypeDto.setWorkModeType(WorkModeType.get((short) workMode));
+ workModeTypes.put(siteId, workModeTypeDto);
+ return false;
+ }
}
--
Gitblit v1.9.1