#
Junjie
2025-01-14 ba77f258c619b296e51cadc0958bff23965dfc6d
src/main/java/com/zy/core/action/ShuttleAction.java
@@ -2,19 +2,25 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zy.asrs.entity.BasShuttleOpt;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasShuttleOptService;
import com.zy.asrs.service.BasShuttleService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.ExecuteSupport;
import com.zy.common.model.NavigateNode;
import com.zy.common.utils.NavigateMapUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.common.utils.ShuttleOperaUtils;
import com.zy.core.News;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.dispatcher.ShuttleDispatchUtils;
import com.zy.core.enums.*;
import com.zy.core.model.CommandResponse;
import com.zy.core.model.command.ShuttleAssignCommand;
@@ -27,6 +33,7 @@
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -47,6 +54,10 @@
    private ConfigService configService;
    @Autowired
    private BasShuttleOptService basShuttleOptService;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private ShuttleDispatchUtils shuttleDispatchUtils;
    public synchronized boolean assignWork(Integer shuttleNo, ShuttleAssignCommand assignCommand) {
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
@@ -61,7 +72,7 @@
        redisCommand.setCommandStep(0);//命令执行步序
        redisCommand.setAssignCommand(assignCommand);//命令
        //任务数据保存到redis
        if (redisUtil.set(RedisKeyType.SHUTTLE.key + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect))) {
        if (redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect))) {
            shuttleThread.setSyncTaskNo(assignCommand.getTaskNo());
            return true;
        }
@@ -69,7 +80,7 @@
    }
    public synchronized boolean executeWork(Integer shuttleNo, Integer taskNo) {
        Object obj = redisUtil.get(RedisKeyType.SHUTTLE.key + taskNo);
        Object obj = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + taskNo);
        if (obj == null) {
            return false;
        }
@@ -192,7 +203,7 @@
            if(updateCommand) {
                // 更新redis数据
                redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
                redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand, SerializerFeature.DisableCircularReferenceDetect));
            }
            if (!command.getComplete()) {
@@ -226,7 +237,7 @@
                }
                //删除redis
                redisUtil.del(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo());
                redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo());
                return false;//禁止再下发命令
            }
        }
@@ -264,10 +275,80 @@
        //更新redis数据
        redisCommand.setCommandStep(commandStep);
        //任务数据保存到redis
        redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
        redisUtil.set(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand));
        return true;
    }
    //演示模式
    public synchronized void demo(Integer shuttleNo) {
        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);
        if (shuttleThread == null) {
            return;
        }
        ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
        if (shuttleProtocol == null) {
            return;
        }
        if (!shuttleProtocol.getDemo()) {
            return;
        }
        WrkMast moveWorking = wrkMastService.selectShuttleHasMoveWorking(shuttleNo);
        if (moveWorking != null) {
            return;
        }
        WrkMast shuttleWorking = wrkMastService.selectShuttleWorking(shuttleNo);
        if(shuttleWorking != null) {
            return;
        }
        WrkMast chargeWorking = wrkMastService.selectChargeWorking(shuttleNo);
        if (chargeWorking != null) {
            return;
        }
        if (shuttleThread.isRequireCharge()) {
            return;
        }
        if (!shuttleThread.isIdle()) {
            return;
        }
        String currentLocNo = shuttleProtocol.getCurrentLocNo();
        int lev = Utils.getLev(currentLocNo);
        LocMast targetLoc = null;
        EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
        wrapper.eq("lev1", lev);
        wrapper.eq("loc_sts", "O");
        wrapper.last("ORDER BY RAND() LIMIT 1");
        for (int i = 0; i < 3; i++) {
            LocMast locMast = locMastService.selectOne(wrapper);
            if(locMast == null) {
                continue;
            }
            ArrayList<String> locs = new ArrayList<>();
            locs.add(locMast.getLocNo());
            Integer shuttle = Utils.checkGroupLocHasShuttle(locs);
            if(shuttle != null) {
                continue;
            }
            targetLoc = locMast;
        }
        if(targetLoc == null) {
            return;
        }
        shuttleDispatchUtils.dispatchShuttle(null, targetLoc.getLocNo(), shuttleNo);
    }
//    //跑库程序
//    public synchronized void moveLoc(Integer shuttleNo) {
//        ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo);