| | |
| | | import com.zy.core.network.DeviceConnectPool; |
| | | import com.zy.core.network.ZyStationConnectDriver; |
| | | import com.zy.core.network.entity.ZyStationStatusEntity; |
| | | import com.zy.core.task.DeviceAsyncLogPublisher; |
| | | import com.zy.core.thread.impl.v5.StationMoveSegmentExecutor; |
| | | import com.zy.core.thread.support.RecentStationArrivalTracker; |
| | | import com.zy.core.utils.DeviceLogRedisKeyBuilder; |
| | | import com.zy.core.thread.support.StationErrLogSupport; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | import lombok.Data; |
| | |
| | | private static final double DEFAULT_STATION_COMMAND_SEGMENT_ADVANCE_RATIO = 0.3d; |
| | | |
| | | private List<StationProtocol> statusList = new ArrayList<>(); |
| | | private volatile List<Integer> taskNoList = new ArrayList<>(); |
| | | private DeviceConfig deviceConfig; |
| | | private RedisUtil redisUtil; |
| | | private ZyStationConnectDriver zyStationConnectDriver; |
| | |
| | | private boolean initStatus = false; |
| | | private long deviceDataLogTime = System.currentTimeMillis(); |
| | | private ExecutorService executor = Executors.newFixedThreadPool(9999); |
| | | private final RecentStationArrivalTracker recentArrivalTracker = new RecentStationArrivalTracker(); |
| | | private final RecentStationArrivalTracker recentArrivalTracker; |
| | | private final DeviceAsyncLogPublisher devpAsyncLogPublisher; |
| | | |
| | | public ZyStationV4Thread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | | this.redisUtil = redisUtil; |
| | | this.recentArrivalTracker = new RecentStationArrivalTracker(redisUtil); |
| | | this.segmentExecutor = new StationMoveSegmentExecutor(deviceConfig, redisUtil, this::sendCommand); |
| | | this.devpAsyncLogPublisher = SpringUtils.getBean(DeviceAsyncLogPublisher.class); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | List<ZyStationStatusEntity> zyStationStatusEntities = zyStationConnectDriver.getStatus(); |
| | | LinkedHashSet<Integer> taskNoSet = new LinkedHashSet<>(); |
| | | for (ZyStationStatusEntity statusEntity : zyStationStatusEntities) { |
| | | for (StationProtocol stationProtocol : statusList) { |
| | | if (stationProtocol.getStationId().equals(statusEntity.getStationId())) { |
| | |
| | | stationProtocol.setBarcode(statusEntity.getBarcode()); |
| | | stationProtocol.setRunBlock(statusEntity.isRunBlock()); |
| | | stationProtocol.setEnableIn(statusEntity.isEnableIn()); |
| | | stationProtocol.setInBarcodeError(statusEntity.isInBarcodeError()); |
| | | stationProtocol.setWeight(statusEntity.getWeight()); |
| | | stationProtocol.setTaskWriteIdx(statusEntity.getTaskWriteIdx()); |
| | | stationProtocol.setTaskBufferItems(statusEntity.getTaskBufferItems()); |
| | | if (statusEntity.getTaskNo() != null && statusEntity.getTaskNo() > 0) { |
| | | taskNoSet.add(statusEntity.getTaskNo()); |
| | | } |
| | | if (statusEntity.getTaskBufferItems() != null) { |
| | | statusEntity.getTaskBufferItems().forEach(item -> { |
| | | Integer bufferTaskNo = item == null ? null : item.getTaskNo(); |
| | | if (bufferTaskNo != null && bufferTaskNo > 0) { |
| | | taskNoSet.add(bufferTaskNo); |
| | | } |
| | | }); |
| | | } |
| | | recentArrivalTracker.observe(statusEntity.getStationId(), statusEntity.getTaskNo(), statusEntity.isLoading()); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | 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(DeviceLogRedisKeyBuilder.build(deviceDataLog), 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 |
| | |
| | | map.put(stationProtocol.getStationId(), stationProtocol); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public List<Integer> getAllTaskNoList() { |
| | | return taskNoList; |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (navigateUtils == null) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return navigateUtils.calcByStationId(startStationId, targetStationId, taskNo, pathLenFactor); |
| | | return navigateUtils.calcOptimalPathByStationId(startStationId, targetStationId, taskNo, pathLenFactor); |
| | | } |
| | | |
| | | private void executeMoveWithSeg(StationCommand original) { |