自动化立体仓库 - WCS系统
#
Junjie
2025-01-17 95872bb822de6a4510f7708ebb1ec5ea3aed35db
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;
@@ -22,11 +28,13 @@
import com.zy.core.model.command.ShuttleRedisCommand;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.thread.ShuttleThread;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -47,6 +55,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 +73,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 +81,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 +204,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 +238,7 @@
                }
                //删除redis
                redisUtil.del(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo());
                redisUtil.del(RedisKeyType.SHUTTLE_WORK_FLAG.key + redisCommand.getWrkNo());
                return false;//禁止再下发命令
            }
        }
@@ -264,10 +276,97 @@
        //更新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;
        }
        boolean demoSwitchLev = false;
        Config demoSwitchLevConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoSwitchLev"));
        if (demoSwitchLevConfig != null) {
            if (demoSwitchLevConfig.getValue().equals("Y")) {
                demoSwitchLev = true;
            }
        }
        Config demoRunLevConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "demoRunLev"));
        if (demoRunLevConfig == null) {
            return;
        }
        List<Integer> levList = JSON.parseArray(demoRunLevConfig.getValue(), Integer.class);
        if (!demoSwitchLev) {
            String currentLocNo = shuttleProtocol.getCurrentLocNo();
            levList = new ArrayList<>();
            levList.add(Utils.getLev(currentLocNo));
        }
        LocMast targetLoc = null;
        EntityWrapper<LocMast> wrapper = new EntityWrapper<>();
        wrapper.in("lev1", levList);
        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);