#
zjj
2024-06-22 1e9099671ba9f4f7a3a4481a67261fbdd62482bc
#
3个文件已修改
417 ■■■■■ 已修改文件
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/OpenController.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ConveyorCommandService.java 322 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/controller/OpenController.java
@@ -16,6 +16,7 @@
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.enums.WorkModeType;
import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
import com.zy.asrs.wcs.rcs.service.DeviceService;
import com.zy.asrs.wcs.rcs.thread.DevpThread;
@@ -58,6 +59,8 @@
    private BasLiftService basLiftService;
    @Autowired
    private BasConveyorService basConveyorService;
    @Autowired
    private BasConveyorStaService basConveyorStaService;
    //生成入库任务
    @PostMapping("/createInTask")
@@ -108,6 +111,40 @@
                return R.error("内置路径不存在");
            }
            destSite = String.valueOf(path.getDeviceStn());
        }
        //判断出入库模式
        BasConveyorSta basConveyorSta = basConveyorStaService.getOne(new LambdaQueryWrapper<BasConveyorSta>()
                .eq(BasConveyorSta::getSiteNo, destSite));
        if (!basConveyorSta.getWorkMode().equals((int) WorkModeType.PAKIN_MODE.id)) {
            //不是入库模式,检测是否可切换入库
            //获取出库任务类型
            TaskCtg taskInCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                    .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.OUT))
                    .eq(TaskCtg::getStatus, 1));
            if (taskInCtg == null) {
                return R.error("任务类型异常");
            }
            List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
                    .eq(Task::getTaskCtg, taskInCtg.getId()));
            if (!tasks.isEmpty()) {
                return R.error("当前存在出库任务,无法切换入库模式");
            }
            BasConveyor basConveyor = basConveyorService.getOne(new LambdaQueryWrapper<BasConveyor>().eq(BasConveyor::getConveyorNo, basConveyorSta.getConveyorNo()));
            if(basConveyor == null) {
                return R.error("输送线不存在");
            }
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, basConveyor.getDeviceId().intValue());
            if(devpThread == null) {
                return R.error("输送线线程不存在");
            }
            boolean result = devpThread.switchWorkMode(Integer.parseInt(destSite), WorkModeType.PAKIN_MODE.id);
            if (!result) {
                return R.error("模式切换失败");
            }
        }
        //优先级
@@ -211,6 +248,40 @@
            originSite = String.valueOf(originStaDto.getStaNo());
        }
        //判断出入库模式
        BasConveyorSta basConveyorSta = basConveyorStaService.getOne(new LambdaQueryWrapper<BasConveyorSta>()
                .eq(BasConveyorSta::getSiteNo, originSite));
        if (!basConveyorSta.getWorkMode().equals((int) WorkModeType.PAKOUT_MODE.id)) {
            //不是出库模式,检测是否可切换出库
            //获取入库任务类型
            TaskCtg taskInCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                    .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.IN))
                    .eq(TaskCtg::getStatus, 1));
            if (taskInCtg == null) {
                return R.error("任务类型异常");
            }
            List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
                    .eq(Task::getTaskCtg, taskInCtg.getId()));
            if (!tasks.isEmpty()) {
                return R.error("当前存在入库任务,无法切换出库模式");
            }
            BasConveyor basConveyor = basConveyorService.getOne(new LambdaQueryWrapper<BasConveyor>().eq(BasConveyor::getConveyorNo, basConveyorSta.getConveyorNo()));
            if(basConveyor == null) {
                return R.error("输送线不存在");
            }
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, basConveyor.getDeviceId().intValue());
            if(devpThread == null) {
                return R.error("输送线线程不存在");
            }
            boolean result = devpThread.switchWorkMode(Integer.parseInt(originSite), WorkModeType.PAKOUT_MODE.id);
            if (!result) {
                return R.error("模式切换失败");
            }
        }
        //优先级
        Integer priority = 10;
        if (param.getPriority() != null) {
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/AnalyzeService.java
@@ -2,27 +2,23 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.wcs.core.domain.dto.MotionDto;
import com.zy.asrs.wcs.core.entity.BasConveyorPath;
import com.zy.asrs.wcs.core.entity.ShuttleStandby;
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.entity.*;
import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
import com.zy.asrs.wcs.core.model.enums.TaskCtgType;
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
import com.zy.asrs.wcs.core.service.BasConveyorPathService;
import com.zy.asrs.wcs.core.service.ShuttleStandbyService;
import com.zy.asrs.wcs.core.service.TaskService;
import com.zy.asrs.wcs.core.service.*;
import com.zy.asrs.wcs.core.utils.ConveyorDispatcher;
import com.zy.asrs.wcs.core.utils.LiftDispatcher;
import com.zy.asrs.wcs.core.utils.ShuttleDispatcher;
import com.zy.asrs.wcs.core.utils.Utils;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.core.entity.Motion;
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.LiftProtocol;
import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol;
import com.zy.asrs.wcs.core.service.MotionService;
import com.zy.asrs.wcs.rcs.service.DeviceService;
import com.zy.asrs.wcs.rcs.thread.LiftThread;
import com.zy.asrs.wcs.rcs.thread.ShuttleThread;
@@ -57,6 +53,8 @@
    private ShuttleStandbyService shuttleStandbyService;
    @Autowired
    private BasConveyorPathService basConveyorPathService;
    @Autowired
    private TaskCtgService taskCtgService;
    public List<Motion> generateMotion(Task task) {
        List<Motion> motionList = new ArrayList<>();
@@ -496,10 +494,18 @@
            //穿梭车出提升机后小车待机位
            String shuttleFromLiftStandbyLoc = shuttleStandbyFrom.getStandbyLoc();
            //获取出库任务类型
            TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
                    .eq(TaskCtg::getFlag, String.valueOf(TaskCtgType.OUT))
                    .eq(TaskCtg::getStatus, 1));
            if (taskCtg == null) {
                return motionList;
            }
            //获取输送线路径
            BasConveyorPath basConveyorPath = basConveyorPathService.getOne(new LambdaQueryWrapper<BasConveyorPath>()
                    .eq(BasConveyorPath::getDeviceStn, task.getOriginSite())
                    .eq(BasConveyorPath::getDeviceNo, liftProtocol.getLiftNo()));
                    .eq(BasConveyorPath::getDeviceNo, liftProtocol.getLiftNo())
                    .eq(BasConveyorPath::getTypeNo, taskCtg.getId()));
            if (basConveyorPath == null) {
                return motionList;
            }
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/kernel/command/ConveyorCommandService.java
@@ -1,10 +1,16 @@
package com.zy.asrs.wcs.core.kernel.command;
import com.zy.asrs.wcs.core.entity.Motion;
import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
import com.zy.asrs.wcs.core.utils.ConveyorDispatcher;
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.thread.DevpThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
/**
 * Created by vincent on 2023/10/23
@@ -17,290 +23,46 @@
    private ConveyorDispatcher conveyorDispatcher;
    public Boolean accept(Motion motion) {
//        Integer deviceNo = Integer.parseInt(motion.getDevice());
//        SiemensDevpThread devpThread;
//        StaProtocol staProtocol;
//        BasDevp staDetl;
//        StaProtocol clone;
//        SiemensLiftThread liftThread;
//        LiftProtocol liftProtocol;
//        switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){
//            // 输送线指令下发
//            case CONVEYOR_INBOUND:
//                devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, deviceNo);
//
//                staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getOrigin()));
//                if (staProtocol == null) {
//                    return false;
//                }
//                // 查询站点详细信息
//                staDetl = basDevpService.selectById(staProtocol.getSiteId());
//                if (staDetl == null || Cools.isEmpty(staDetl.getCanining()) || !"Y".equals(staDetl.getCanining())) {
//                    News.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", staProtocol.getSiteId());
//                    return false;
//                }
//                if (!staProtocol.isAutoing()
//                        || !staProtocol.isLoading()
//                        || !staProtocol.isInEnable()
//                        || !(staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9990)) {
//                    return false;
//                }
//
//                if (!staProtocol.getWorkNo().equals(motion.getWrkNo().shortValue())) {
//                    return false;
//                }
//
//                clone = staProtocol.clone();
//
//                clone.setWorkNo(motion.getWrkNo().shortValue());
//                clone.setStaNo(Short.parseShort(motion.getTarget()));
//
//                devpThread.setPakMk(staProtocol.getSiteId(), false);
//
//                return MessageQueue.offer(SlaveType.Devp, deviceNo, new Task(2, clone));
//
//            case CONVEYOR_INBOUND_TO_LIFT:
//                // 输送线 -----------------------------------------------
//                devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, deviceNo);
//
//                staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getOrigin()));
//                if (staProtocol == null) {
//                    return false;
//                }
//                // 查询站点详细信息
//                staDetl = basDevpService.selectById(staProtocol.getSiteId());
//                if (staDetl == null || Cools.isEmpty(staDetl.getCanining()) || !"Y".equals(staDetl.getCanining())) {
//                    News.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", staProtocol.getSiteId());
//                    return false;
//                }
//                if (!staProtocol.isAutoing()
//                        || !staProtocol.isLoading()
////                        || !staProtocol.isInEnable()
//                        || (staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9991)
//                        || !staProtocol.isPakMk()) {
//                    return false;
//                }
//
//                // 提升机判断 -----------------------------------------------
//                liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getDockNo()));
//                liftProtocol = liftThread.getLiftProtocol();
//                if (null == liftProtocol) {
//                    return false;
//                }
//                DevpSlave.Sta inSta = devpThread.getSlave().queryInSta(staProtocol.getSiteId());
//                if (!(liftProtocol.getMode()
//                        || liftProtocol.getReady()
//                        || !liftProtocol.getRunning()
//                        || !liftProtocol.getLev().equals(Short.parseShort(motion.getTarget())))) {
//                    return false;
//                }
//
//                // 下发命令 -----------------------------------------------
//
//                // 1.驱动提升机电机
//                LiftCommand liftCommand = new LiftCommand();
//
//                LiftInteractiveModeType liftInteractiveModeType = null;
//                switch (Integer.parseInt(motion.getOrigin())) {
//                    case 2:
//                        liftInteractiveModeType = LiftInteractiveModeType.ENGINE_EMPTY_TURN;
//                        break;
//                    case 7:
//                        liftInteractiveModeType = LiftInteractiveModeType.ENGINE_EMPTY_TURN;
//                        break;
//                    case 9:
//                    case 10:
//                    case 11:
//                        liftInteractiveModeType = LiftInteractiveModeType.ENGINE_EMPTY_TURN;
//                        break;
//                    default:
//                        break;
//                }
//
//                if (liftInteractiveModeType == null) {
//                    return false;
//                }
//                liftCommand = liftThread.getLiftTurnCommand(liftInteractiveModeType.id);
//                liftCommand.setLiftNo(liftProtocol.getLiftNo());
//                liftCommand.setTaskNo(motion.getWrkNo().shortValue());
//                if (!liftThread.assignWork(liftCommand)) {
//                    return false;
//                }
//
//                try {
//                    Thread.sleep(1000);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//                // 2.下发输送线任务
//                clone = staProtocol.clone();
//                // 判断是否存在提升机代理站点
//                ConveyorProxyType conveyorProxyType = ConveyorProxyType.queryByLift(Integer.parseInt(motion.getDockNo()), true);
//                clone.setWorkNo(motion.getWrkNo().shortValue());
//                clone.setStaNo(conveyorProxyType.liftProxyStaNo.shortValue());
//                devpThread.setPakMk(staProtocol.getSiteId(), false);
//                return MessageQueue.offer(SlaveType.Devp, deviceNo, new Task(2, clone));
//
//            case CONVEYOR_OUTBOUND:
//                devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, deviceNo);
//
//                staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getOrigin()));
//                if (staProtocol == null) {
//                    return false;
//                }
//                if (!staProtocol.isAutoing()
//                        || !staProtocol.isLoading()
//                        || staProtocol.getWorkNo() != 0
//                        || !staProtocol.isPakMk()) {
//                    return false;
//                }
//
//                // 下发命令 -----------------------------------------------
//                clone = staProtocol.clone();
//                clone.setWorkNo(motion.getWrkNo().shortValue());
//                clone.setStaNo(Short.parseShort(motion.getTarget()));
//
//                devpThread.setPakMk(clone.getSiteId(), false);
//
//                return MessageQueue.offer(SlaveType.Devp, deviceNo, new Task(2, clone));
//
////            case CONVEYOR_OUTBOUND_FROM_LIFT:
////                Integer liftNo = Integer.parseInt(motion.getDockNo());
////
////                LiftNeighborType.query(liftNo, )
////
////                // 输送线 -----------------------------------------------
////                devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, deviceNo);
////
////                staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getTarget()));
////                if (staProtocol == null) {
////                    return false;
////                }
////                // 查询站点详细信息
////                staDetl = basDevpService.selectById(staProtocol.getSiteId());
////                if (staDetl == null || Cools.isEmpty(staDetl.getCanouting()) || !"Y".equals(staDetl.getCanouting())) {
////                    News.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", staProtocol.getSiteId());
////                    return false;
////                }
////                if (!staProtocol.isAutoing()
////                        || !staProtocol.isLoading()
////                        || !staProtocol.isInEnable()
////                        || !(staProtocol.getWorkNo() >= 9991 && staProtocol.getWorkNo() <= 9999)) {
////                    return false;
////                }
////                if (!staProtocol.getWorkNo().equals(motion.getWrkNo().shortValue())) {
////                    return false;
////                }
////
////                // 提升机判断 -----------------------------------------------
////                liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, liftNo);
////                liftProtocol = liftThread.getLiftProtocol();
////                if (null == liftProtocol) {
////                    return false;
////                }
////                DevpSlave.Sta inSta = devpThread.getSlave().queryOutSta(staProtocol.getSiteId());
////                if (liftProtocol.getMode() != 1
////                        || liftProtocol.getAlarm() != 2
////                        || liftProtocol.getLoadingByGoods() != 1
////                        || liftProtocol.getPos() != inSta.getLiftLev().shortValue()) {
////                    return false;
////                }
//
//
//            default:
//                break;
//        }
        Integer deviceNo = Integer.parseInt(motion.getDevice());
        DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, deviceNo);
        if (devpThread == null) {
            return false;
        }
        switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){
            // 输送线指令下发
            case CONVEYOR_INBOUND://输送线入库
                break;
            case CONVEYOR_INBOUND_TO_LIFT://输送线入库至提升机
                break;
            case CONVEYOR_OUTBOUND://输送线出库
                boolean result = devpThread.writeWorkSta(Integer.parseInt(motion.getOrigin()), motion.getTaskNo().shortValue(), Short.parseShort(motion.getTarget()));
                if (!result) {
                    return false;
                }
                break;
            default:
                break;
        }
        return Boolean.TRUE;
    }
    public Boolean finish(Motion motion) {
//        Integer deviceNo = Integer.parseInt(motion.getDevice());
//        SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, deviceNo);
//        StaProtocol staProtocol;
//        switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){
//            case CONVEYOR_INBOUND:
//                staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getTarget()));
//                if (staProtocol == null) {
//                    return false;
//                }
//                if (!staProtocol.isAutoing() || !staProtocol.isLoading() || !(staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9990)) {
//                    return false;
//                }
//                if (!staProtocol.getWorkNo().equals(motion.getWrkNo().shortValue())) {
//                    return false;
//                }
//                break;
//            case CONVEYOR_OUTBOUND:
//                // todo:luxiaotao 出库到目标站是否需要跟踪
////                staProtocol = devpThread.getStation().get(Integer.parseInt(motion.getTarget()));
////                if (staProtocol == null) {
////                    return false;
////                }
////                if (!staProtocol.isAutoing() || !staProtocol.isLoading() || !(staProtocol.getWorkNo() > 0 && staProtocol.getWorkNo() < 9990)) {
////                    return false;
////                }
////                if (!staProtocol.getWorkNo().equals(motion.getWrkNo().shortValue())) {
////                    return false;
////                }
//                break;
//            case CONVEYOR_INBOUND_TO_LIFT:
//                // 判断提升机状态
//                SiemensLiftThread liftThread = (SiemensLiftThread) SlaveConnection.get(SlaveType.Lift, Integer.parseInt(motion.getDockNo()));
//                LiftProtocol liftProtocol = liftThread.getLiftProtocol();
//                if (null == liftProtocol) {
//                    return false;
//                }
//
//                DevpSlave.Sta inSta = devpThread.getSlave().queryInSta(Integer.parseInt(motion.getOrigin()));
//                if (!(liftProtocol.getMode()
//                        || liftProtocol.getReady()
//                        || !liftProtocol.getRunning()
//                        || liftProtocol.getLev() != Short.parseShort(motion.getTarget()))) {
//                    return false;
//                }
//
//                //货物已经进入提升机
//                if (!(liftProtocol.getLineFrontHasStock() && liftProtocol.getLineEndHasStock())) {
//                    return false;
//                }
//
//                //清空提升机工作号
//                if (liftProtocol.getTaskNo().intValue() == motion.getWrkNo()) {
//                    liftThread.setTaskNo(0);
//                }
//
//                // 判断输送线状态
//                int originSta = Integer.parseInt(motion.getOrigin());
//                if (originSta == 6) {
//                    originSta = 7;
//                }
//                staProtocol = devpThread.getStation().get(originSta);
//
//                // 停止输送线电机
//                int times = 0;boolean staProtocolMotorRes = false;
//                while (times < 5) {
//                    if (staProtocol.getStaMotorType().equals(StaMotorType.STANDBY)) {
//                        staProtocolMotorRes = true;
//                        break;
//                    }
//                    if (!devpThread.controlMotor(originSta, StaMotorType.REQ_STOP)) {
//                        continue;
//                    }
//                    try {
//                        Thread.sleep(500);
//                    } catch (InterruptedException ignore) {}
//                    times++;
//                }
//                if (!staProtocolMotorRes) {
//                    return false;
//                }
//
//                break;
//            default:
//                break;
//        }
        Integer deviceNo = Integer.parseInt(motion.getDevice());
        DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Conveyor, deviceNo);
        if (devpThread == null) {
            return false;
        }
        switch (Objects.requireNonNull(MotionCtgType.get(motion.getMotionCtgEl()))){
            case CONVEYOR_INBOUND:
                break;
            case CONVEYOR_OUTBOUND:
                break;
            case CONVEYOR_INBOUND_TO_LIFT:
                break;
            default:
                break;
        }
        return true;
    }