#
Junjie
2024-10-17 cab87dcfaa7b1e2bc1298572b775026bb17ef38b
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java
@@ -10,9 +10,11 @@
import com.zy.asrs.framework.common.SpringUtils;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wcs.common.ExecuteSupport;
import com.zy.asrs.wcs.core.domain.dto.BasLiftStaDto;
import com.zy.asrs.wcs.core.entity.BasLift;
import com.zy.asrs.wcs.core.model.command.LiftCommand;
import com.zy.asrs.wcs.core.model.enums.LiftCommandModeType;
import com.zy.asrs.wcs.core.model.enums.MotionCtgType;
import com.zy.asrs.wcs.core.service.BasLiftService;
import com.zy.asrs.wcs.core.utils.RedisUtil;
import com.zy.asrs.wcs.core.utils.Utils;
@@ -39,7 +41,7 @@
    private LiftProtocol liftProtocol;
    private SiemensS7Net siemensS7Net;
    private List<LiftStaProtocol> liftStaProtocols = new ArrayList<>();
    private List<Sta> staList = new ArrayList<>();
    private List<BasLiftStaDto> staList = new ArrayList<>();
    public NyLiftThread(Device device, RedisUtil redisUtil) {
        this.device = device;
@@ -49,9 +51,9 @@
        BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class);
        BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>()
                .eq(BasLift::getDeviceId, device.getId()));
        List<Sta> staList = JSON.parseArray(basLift.getSta(), Sta.class);
        List<BasLiftStaDto> staList = JSON.parseArray(basLift.getSta(), BasLiftStaDto.class);
        this.staList = staList;
        for (Sta sta : staList) {
        for (BasLiftStaDto sta : staList) {
            LiftStaProtocol liftStaProtocol = new LiftStaProtocol();
            liftStaProtocol.setStaNo(sta.getStaNo());//站点号
            liftStaProtocol.setLev(sta.getLev());//站点楼层
@@ -80,9 +82,9 @@
        try {
            readStatus();
            //提升机处于运行状态,将标记置为false
            //提升机处于运行状态,将标记置为true
            if (liftProtocol.getRun()) {
                liftProtocol.setPakMk(false);
                liftProtocol.setPakMk(true);
            }
        } catch (Exception e) {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】读取提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort()));
@@ -140,7 +142,7 @@
                liftProtocol.setLev((int) lev);
                //************补充扩展字段*************
                InnerLiftExtend liftExtend = JSON.parseObject(JSON.toJSONString(liftProtocol.getExtend()), InnerLiftExtend.class);
                InnerLiftExtend liftExtend = (InnerLiftExtend) liftProtocol.getExtend();
                //任务号
                liftExtend.setLiftTaskNo(String.valueOf(siemensS7Net.getByteTransform().TransInt16(result1.Content, 2)));
                liftProtocol.setExtend(liftExtend);
@@ -207,6 +209,31 @@
                //更新采集时间
                liftProtocol.setDeviceDataLog(System.currentTimeMillis());
            }
            //将提升机状态保存至数据库
            BasLiftService basLiftService = SpringUtils.getBean(BasLiftService.class);
            BasLift basLift = basLiftService.getOne(new LambdaQueryWrapper<BasLift>()
                    .eq(BasLift::getLiftNo, device.getDeviceNo())
                    .eq(BasLift::getHostId, device.getHostId()));
            if (basLift == null) {
                basLift = new BasLift();
                //提升机号
                basLift.setLiftNo(Integer.valueOf(device.getDeviceNo()));
                basLift.setStatus(1);
                basLift.setDeleted(0);
                basLift.setHostId(device.getHostId());
                basLift.setDeviceId(device.getId());
                basLiftService.save(basLift);
            }
            //任务号
            basLift.setTaskNo(liftProtocol.getTaskNo().intValue());
            //修改时间
            basLift.setUpdateTime(new Date());
            //设备状态
            basLift.setProtocol(JSON.toJSONString(liftProtocol));
            if (basLiftService.updateById(basLift)) {
                OutputQueue.LIFT.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), device.getDeviceNo()));
            }
        } catch (Exception e) {
@@ -280,19 +307,40 @@
    }
    @Override
    public boolean isIdle(ExecuteSupport support) {
        if (null != support) {
            if (!support.judgement()) {
                return false;
            }
        }
    public boolean isIdle(MotionCtgType flag) {
        // 判断提升机是否自动、就绪、空闲
        if (this.liftProtocol.getModel()
                && !this.liftProtocol.getRun()
                && this.liftProtocol.getReady()
                && this.liftProtocol.getPakMk()
                && this.liftProtocol.getErrorCode().equals("0")
                && this.liftProtocol.getProtocolStatus().equals(LiftProtocolStatusType.IDLE)
                && (this.liftProtocol.getProtocolStatusType().equals(LiftProtocolStatusType.IDLE)
                || this.liftProtocol.getProtocolStatusType().equals(LiftProtocolStatusType.WAITING))
        ) {
            return true;
        }
        return false;
    }
    @Override
    public boolean isDeviceIdle() {
        return isDeviceIdle(null);
    }
    @Override
    public boolean isDeviceIdle(ExecuteSupport support) {
        if (null != support) {
            Boolean judgement = support.judgement();
            if (judgement != null && !judgement) {
                return true;
            }
        }
        // 判断提升机是否自动、就绪、空闲
        if (this.liftProtocol.getModel()
                && !this.liftProtocol.getRun()
                && this.liftProtocol.getReady()
                && this.liftProtocol.getErrorCode().equals("0")
        ) {
            return true;
        }
@@ -312,15 +360,28 @@
    }
    @Override
    public LiftCommand getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer mode) {
    public boolean isLock(ExecuteSupport support) {
        if (support != null) {
            return support.judgement();
        }
        return true;
    }
    @Override
    public int generateDeviceTaskNo(int taskNo, MotionCtgType motionCtgType) {
        return taskNo;
    }
    @Override
    public List<LiftCommand> getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode) {
        /**
         * 任务类型
         * 1=移托盘;升降机将源站台托盘移到目标站台
         * 2=移小车,升降机移到目标层,等待
         */
        short taskMode = 2;
        if (mode == null) {
            taskMode = mode.shortValue();
        if (mode.equals(LiftCommandModeType.PALLET_INOUT)) {
            taskMode = 1;
        }
        // 开始任务
@@ -340,29 +401,30 @@
        command.setMode(LiftCommandModeType.MOVE.id);
        command.setOriginLev(sourceLev);
        command.setTargetLev(targetLev);
        return command;
        ArrayList<LiftCommand> list = new ArrayList<>();
        list.add(command);
        return list;
    }
    @Override
    public LiftCommand getMoveWithShuttleCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer mode) {
        return getMoveCommand(taskNo, sourceLev, targetLev, 2);
    public List<LiftCommand> getMoveWithShuttleCommand(Integer taskNo, Integer sourceLev, Integer targetLev, LiftCommandModeType mode) {
        return getMoveCommand(taskNo, sourceLev, targetLev, mode);
    }
    @Override
    public LiftCommand getPalletInOutCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer originSta, Integer targetSta, Integer mode) {
        return getMoveCommand(taskNo, sourceLev, targetLev, 1);
    public List<LiftCommand> getPalletInOutCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer originSta, Integer targetSta, LiftCommandModeType mode) {
        return getMoveCommand(taskNo, sourceLev, targetLev, mode);
    }
    @Override
    public LiftCommand getLockCommand(Integer taskNo, Boolean lock) {
        LiftCommand command = new LiftCommand();
        return command;
    public List<LiftCommand> getLockCommand(Integer taskNo, Boolean lock) {
        return null;
    }
    @Override
    public LiftCommand getShuttleSignalCommand(Integer taskNo, Boolean signal) {
        LiftCommand command = new LiftCommand();
        return command;
    public List<LiftCommand> getShuttleSignalCommand(Integer taskNo, Boolean signal) {
        return null;
    }
    @Override
@@ -488,23 +550,6 @@
         * 提升机号
         */
        private Integer liftNo;
    }
    @Data
    public static class Sta {
        // 提升机站点号
        private Integer staNo;
        //输送站点排
        private Integer row;
        //输送站点列
        private Integer bay;
        // 层
        private Integer lev;
    }