*
lsh
2024-10-23 11eaa61d046200bb5eeecfc35d1ca1964505136d
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -9,6 +9,7 @@
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.utils.SortTheExecutionOfTheCarUtil;
import com.zy.asrs.utils.TimeCalculatorUtils;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.*;
@@ -46,6 +47,77 @@
    private BasCircularShuttleService basCircularShuttleService;
    @Autowired
    private WrkMastService wrkMastService;
    /**
     * 站点任务检测  更新小车位置信息
     */
    public synchronized void updateStePositionNearby() {
        try{
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", 1L));
            if (wrkMasts.isEmpty()){
                return;
            }
            List<BasDevpPosition> basDevpPositions = basDevpPositionService.selectList(new EntityWrapper<BasDevpPosition>().orderBy("plc_position",false));
            if (basDevpPositions.isEmpty()){
                log.error("获取所有站点信息异常");
                return;
            }
            List<Integer> siteList = SortTheExecutionOfTheCarUtil.WrkMastExtractSites(wrkMasts);
            List<Integer> devpList = SortTheExecutionOfTheCarUtil.BasDevpPositionExtractSites(basDevpPositions);
            Integer siteNo = SortTheExecutionOfTheCarUtil.ObtainDenseAreasFirstPlace(siteList, devpList);
            if (siteNo == null){
                log.error("就近密集原则获取站点失败");
                return;
            }
            Long sitePosition = 0L;
            for (BasDevpPosition basDevpPosition : basDevpPositions){
                if (basDevpPosition.getDevNo().equals(siteNo)){
                    sitePosition = basDevpPosition.getPlcPosition();
                }
            }
            List<List<Long>> rgvPositionList = new ArrayList<>();
            for (RgvSlave rgvSlave:slaveProperties.getRgv()) {
                RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, rgvSlave.getId());
                RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();
                if (rgvProtocol == null) {
                    continue;
                }
                List<Long> rgvPosition = new ArrayList<>();
                rgvPosition.add(rgvProtocol.getRgvNo().longValue());
                rgvPosition.add(rgvProtocol.getRgvPos());
                rgvPositionList.add(rgvPosition);
            }
            Integer rgvNo = SortTheExecutionOfTheCarUtil.LatelyAndGreaterThan(rgvPositionList, sitePosition);
            List<BasCircularShuttle> basCircularShuttleList = basCircularShuttleService.selectList(new EntityWrapper<BasCircularShuttle>().orderBy("rgv_id", true));
            if (basCircularShuttleList.get(0).getRgvNo().equals(rgvNo)){
                return;
            }
            int[][] ints = new int[basCircularShuttleList.size()][2];
            for (BasCircularShuttle basCircularShuttle : basCircularShuttleList){
                ints[basCircularShuttle.getRgvNo()-1] = new int[]{basCircularShuttle.getRgvNo(),basCircularShuttle.getRgvId()};
            }
            String[] oldList = new String[ints.length];
            for (int[] rgv : ints){
                oldList[rgv[0]-1] = Arrays.toString(rgv);
            }
            int[][] rgvList = SortTheExecutionOfTheCarUtil.ReorderSteId(ints, rgvNo);
            String[] newList = new String[rgvList.length];
            for (int[] rgv : rgvList){
                newList[rgv[0]-1] = Arrays.toString(rgv);
            }
            log.info("更新小车排序信息:原始小车号rgvNo={},小车重新排序信息={},小车原始排序信息={}",rgvNo,Arrays.toString(newList),Arrays.toString(oldList));
            for (BasCircularShuttle basCircularShuttle : basCircularShuttleList){
                int[] rgv = rgvList[basCircularShuttle.getRgvNo() - 1];
                basCircularShuttle.setRgvId(rgv[1]);
                basCircularShuttleService.updateById(basCircularShuttle);
            }
        } catch (Exception e) {
            log.error("自动更新小车排序信息失败,异常:"+e);
        }
    }
    /**
     * 站点任务检测  更新小车位置信息
     */
@@ -98,6 +170,15 @@
     */
    public synchronized void DevpTaskNoRun() {
        try{
            List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts", 1L).orderBy("modi_time",true));
            if (wrkMasts.isEmpty()){
                return;
            }
            long differenceInSeconds = TimeCalculatorUtils.differenceInSeconds(wrkMasts.get(0).getModiTime(), new Date());
            if (differenceInSeconds<=5){
                return;
            }
            BasCircularShuttle basCircularShuttle = basCircularShuttleService.selectOne(new EntityWrapper<BasCircularShuttle>().eq("rgv_id", 1));
            RgvThread rgvThread = (RgvThread) SlaveConnection.get(SlaveType.Rgv, basCircularShuttle.getRgvNo());
            RgvProtocol rgvProtocol = rgvThread.getRgvProtocol();