From fc67e7de548d5fc4ba84a2c09d3e99aad2fc11d7 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 29 四月 2026 20:35:19 +0800
Subject: [PATCH] #堆垛机任务执行优先级修改
---
src/main/java/com/zy/core/thread/impl/ZyStationThread.java | 79 +++++++++++++++++++++++++++++++++------
1 files changed, 66 insertions(+), 13 deletions(-)
diff --git a/src/main/java/com/zy/core/thread/impl/ZyStationThread.java b/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
index 802f7e6..715b398 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationThread.java
@@ -1,13 +1,15 @@
package com.zy.core.thread.impl;
import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.utils.Utils;
import com.zy.core.network.DeviceConnectPool;
import com.zy.core.thread.StationThread;
+import com.zy.core.thread.support.RecentStationArrivalTracker;
+import com.zy.core.thread.support.StationErrLogSupport;
import com.alibaba.fastjson.JSON;
import com.core.common.DateUtils;
import com.core.common.SpringUtils;
@@ -27,6 +29,7 @@
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.network.entity.ZyStationStatusEntity;
+import com.zy.core.task.DeviceAsyncLogPublisher;
import java.text.MessageFormat;
import java.util.*;
@@ -42,15 +45,20 @@
public class ZyStationThread implements Runnable, StationThread {
private List<StationProtocol> statusList = new ArrayList<>();
+ private volatile List<Integer> taskNoList = new ArrayList<>();
private DeviceConfig deviceConfig;
private RedisUtil redisUtil;
private ZyStationConnectDriver zyStationConnectDriver;
private int deviceLogCollectTime = 200;
private long deviceDataLogTime = System.currentTimeMillis();
+ private final RecentStationArrivalTracker recentArrivalTracker;
+ private final DeviceAsyncLogPublisher devpAsyncLogPublisher;
public ZyStationThread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
this.deviceConfig = deviceConfig;
this.redisUtil = redisUtil;
+ this.recentArrivalTracker = new RecentStationArrivalTracker(redisUtil);
+ this.devpAsyncLogPublisher = SpringUtils.getBean(DeviceAsyncLogPublisher.class);
}
@Override
@@ -110,7 +118,7 @@
}
BasDevp basDevp = basDevpService
- .selectOne(new EntityWrapper<BasDevp>().eq("devp_no", deviceConfig.getDeviceNo()));
+ .getOne(new QueryWrapper<BasDevp>().eq("devp_no", deviceConfig.getDeviceNo()));
if (basDevp == null) {
return;
}
@@ -124,6 +132,7 @@
}
List<ZyStationStatusEntity> zyStationStatusEntities = zyStationConnectDriver.getStatus();
+ LinkedHashSet<Integer> taskNoSet = new LinkedHashSet<>();
for (ZyStationStatusEntity statusEntity : zyStationStatusEntities) {
for (StationProtocol stationProtocol : statusList) {
if(stationProtocol.getStationId().equals(statusEntity.getStationId())) {
@@ -142,33 +151,62 @@
stationProtocol.setRunBlock(statusEntity.isRunBlock());
stationProtocol.setEnableIn(statusEntity.isEnableIn());
stationProtocol.setWeight(statusEntity.getWeight());
+ stationProtocol.setIoMode(statusEntity.getIoMode());
+ if (statusEntity.getTaskNo() != null && statusEntity.getTaskNo() > 0) {
+ taskNoSet.add(statusEntity.getTaskNo());
+ }
+ recentArrivalTracker.observe(statusEntity.getStationId(), statusEntity.getTaskNo(), statusEntity.isLoading());
}
if (!Cools.isEmpty(stationProtocol.getSystemWarning())) {
if (stationProtocol.isAutoing()
&& !stationProtocol.isLoading()
+ && redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationProtocol.getStationId()) == null
) {
stationProtocol.setSystemWarning("");
}
}
}
}
+ taskNoList = new ArrayList<>(taskNoSet);
OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛",DateUtils.convert(new Date()), deviceConfig.getDeviceNo()));
+ StationErrLogSupport.sync(deviceConfig, redisUtil, statusList);
if (System.currentTimeMillis() - deviceDataLogTime > deviceLogCollectTime) {
- //淇濆瓨鏁版嵁璁板綍
- DeviceDataLog deviceDataLog = new DeviceDataLog();
- deviceDataLog.setOriginData(JSON.toJSONString(zyStationStatusEntities));
- deviceDataLog.setWcsData(JSON.toJSONString(statusList));
- deviceDataLog.setType(String.valueOf(SlaveType.Devp));
- deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo());
- deviceDataLog.setCreateTime(new Date());
-
- redisUtil.set(RedisKeyType.DEVICE_LOG_KEY.key + System.currentTimeMillis(), deviceDataLog, 60 * 60 * 24);
- //鏇存柊閲囬泦鏃堕棿
+ Date createTime = new Date();
+ HashMap<Integer, ZyStationStatusEntity> originDataMap = buildStationStatusMap(zyStationStatusEntities);
+ for (int i = 0; i < statusList.size(); i++) {
+ StationProtocol stationProtocol = statusList.get(i);
+ if (stationProtocol == null || stationProtocol.getStationId() == null) {
+ continue;
+ }
+ DeviceDataLog deviceDataLog = new DeviceDataLog();
+ ZyStationStatusEntity originEntity = originDataMap.get(stationProtocol.getStationId());
+ deviceDataLog.setOriginData(originEntity == null ? null : JSON.toJSONString(originEntity));
+ deviceDataLog.setWcsData(JSON.toJSONString(stationProtocol));
+ deviceDataLog.setType(String.valueOf(SlaveType.Devp));
+ deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo());
+ deviceDataLog.setStationId(stationProtocol.getStationId());
+ deviceDataLog.setCreateTime(createTime);
+ devpAsyncLogPublisher.publishLatest(deviceDataLog);
+ }
deviceDataLogTime = System.currentTimeMillis();
}
+ }
+
+ private HashMap<Integer, ZyStationStatusEntity> buildStationStatusMap(List<ZyStationStatusEntity> zyStationStatusEntities) {
+ HashMap<Integer, ZyStationStatusEntity> map = new HashMap<>();
+ if (zyStationStatusEntities == null) {
+ return map;
+ }
+ for (ZyStationStatusEntity statusEntity : zyStationStatusEntities) {
+ if (statusEntity == null || statusEntity.getStationId() == null) {
+ continue;
+ }
+ map.put(statusEntity.getStationId(), statusEntity);
+ }
+ return map;
}
@Override
@@ -189,6 +227,16 @@
@Override
public List<StationProtocol> getStatus() {
return statusList;
+ }
+
+ @Override
+ public boolean hasRecentArrival(Integer stationId, Integer taskNo) {
+ return recentArrivalTracker.hasRecentArrival(stationId, taskNo);
+ }
+
+ @Override
+ public List<Integer> getAllTaskNoList() {
+ return taskNoList;
}
@Override
@@ -236,7 +284,7 @@
JSON.toJSONString(commandResponse)
);
if (optService != null) {
- optService.insert(basStationOpt);
+ optService.save(basStationOpt);
}
}
}
@@ -259,4 +307,9 @@
public byte[] readOriginCommand(String address, int length) {
return zyStationConnectDriver.readOriginCommand(address, length);
}
+
+ @Override
+ public boolean clearPath(Integer taskNo) {
+ return false;
+ }
}
--
Gitblit v1.9.1