From cab87dcfaa7b1e2bc1298572b775026bb17ef38b Mon Sep 17 00:00:00 2001 From: Junjie <xjj@123> Date: 星期四, 17 十月 2024 13:54:41 +0800 Subject: [PATCH] # --- zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/websocket/MapRealTimeDataScheduler.java | 76 +++++++++++++++++++++++++++++++++++--- 1 files changed, 70 insertions(+), 6 deletions(-) diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/websocket/MapRealTimeDataScheduler.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/websocket/MapRealTimeDataScheduler.java index f9092d6..5b5eff6 100644 --- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/websocket/MapRealTimeDataScheduler.java +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/map/websocket/MapRealTimeDataScheduler.java @@ -1,25 +1,37 @@ package com.zy.asrs.wcs.core.map.websocket; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.zy.asrs.framework.common.Cools; +import com.zy.asrs.wcs.core.domain.dto.MapLockPathDto; +import com.zy.asrs.wcs.core.entity.BasConveyorSta; +import com.zy.asrs.wcs.core.entity.BasShuttle; import com.zy.asrs.wcs.core.map.entity.MapWsShuttleVo; import com.zy.asrs.wcs.core.map.entity.MapWsVo; +import com.zy.asrs.wcs.core.model.NavigateNode; import com.zy.asrs.wcs.core.model.enums.DeviceCtgType; +import com.zy.asrs.wcs.core.service.BasConveyorStaService; import com.zy.asrs.wcs.core.service.BasShuttleService; +import com.zy.asrs.wcs.core.utils.NavigateMapUtils; +import com.zy.asrs.wcs.core.utils.Utils; import com.zy.asrs.wcs.rcs.cache.SlaveConnection; import com.zy.asrs.wcs.rcs.entity.Device; import com.zy.asrs.wcs.rcs.model.enums.SlaveType; import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; import com.zy.asrs.wcs.rcs.service.DeviceService; import com.zy.asrs.wcs.rcs.service.DeviceTypeService; -import com.zy.asrs.wcs.rcs.service.ShuttleService; import com.zy.asrs.wcs.rcs.thread.ShuttleThread; +import com.zy.asrs.wcs.system.entity.Dict; +import com.zy.asrs.wcs.system.service.DictService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; +import java.util.stream.Collectors; /** * Created by vincent on 4/11/2024 @@ -33,12 +45,20 @@ private DeviceService deviceService; @Autowired private BasShuttleService basShuttleService; + @Autowired + private DictService dictService; + @Autowired + private NavigateMapUtils navigateMapUtils; + @Autowired + private BasConveyorStaService basConveyorStaService; @Scheduled(cron = "0/1 * * * * ? ") public void sync() { MapWsVo wsVo = new MapWsVo(); // shuttle wsVo.setShuttleVos(syncShuttle()); + wsVo.setLockPath(getMapLocPath()); + wsVo.setConveyorSta(getMapConveyorSta()); MapWebSocket.broadcast(JSON.toJSONString(wsVo)); } @@ -47,24 +67,68 @@ List<Device> deviceList = deviceService.list(new LambdaQueryWrapper<Device>().eq(Device::getDeviceType, DeviceCtgType.SHUTTLE.val())); for (Device device : deviceList) { - basShuttleService. + MapWsShuttleVo shuttleVo = new MapWsShuttleVo(); + shuttleVos.add(shuttleVo); + + shuttleVo.setShuttleNo(device.getDeviceNo()); + + Consumer<Device> consumer = new Consumer<Device>() { + @Override + public void accept(Device device) { + BasShuttle basShuttle = basShuttleService.getOne(new LambdaQueryWrapper<BasShuttle>().eq(BasShuttle::getDeviceId, device.getId())); + if (null != basShuttle && !Cools.isEmpty(basShuttle.getProtocol())) { + ShuttleProtocol protocol = JSON.parseObject(basShuttle.getProtocol(), ShuttleProtocol.class); + shuttleVo.setCurLocNo(protocol.getCurrentLocNo()); + } + } + }; + ShuttleThread thread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getId().intValue()); if (null == thread) { + consumer.accept(device); continue; } ShuttleProtocol protocol = thread.getStatus(); if (null == protocol) { + consumer.accept(device); continue; } - MapWsShuttleVo shuttleVo = new MapWsShuttleVo(); - shuttleVo.setShuttleNo(); + shuttleVo.setCurLocNo(protocol.getCurrentLocNo()); - - shuttleVos.add(shuttleVo); + List<NavigateNode> moveAdvancePath = thread.getMoveAdvancePath(); + if (!Cools.isEmpty(moveAdvancePath)) { + shuttleVo.setTravelPath(moveAdvancePath.stream() + .map(path -> Utils.getLocNo(path.getX(), path.getY(), path.getZ())) + .collect(Collectors.toList())); + } } return shuttleVos; } + private List<MapLockPathDto> getMapLocPath() { + List<MapLockPathDto> list = new ArrayList<>(); + Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>() + .eq(Dict::getFlag, "floor-list") + .eq(Dict::getStatus, 1)); + if (dict != null) { + for (Object o : JSON.parseArray(dict.getValue())) { + JSONObject jsonObject = JSON.parseObject(o.toString()); + Integer lev = jsonObject.getInteger("value"); + List<NavigateNode> path = navigateMapUtils.getLockPath(lev); + + MapLockPathDto lockPathDto = new MapLockPathDto(); + lockPathDto.setPath(path); + lockPathDto.setLev(lev); + list.add(lockPathDto); + } + } + return list; + } + + private List<BasConveyorSta> getMapConveyorSta() { + return basConveyorStaService.list(); + } + } -- Gitblit v1.9.1