#
Junjie
2024-06-18 838ed38fc421cb9efc90c6eecdefb497ad183160
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyLiftThread.java
@@ -10,6 +10,7 @@
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;
@@ -21,7 +22,6 @@
import com.zy.asrs.wcs.rcs.entity.Device;
import com.zy.asrs.wcs.rcs.entity.DeviceDataLog;
import com.zy.asrs.wcs.rcs.model.enums.LiftProtocolStatusType;
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
import com.zy.asrs.wcs.rcs.model.protocol.LiftProtocol;
import com.zy.asrs.wcs.rcs.service.DeviceDataLogService;
import com.zy.asrs.wcs.rcs.thread.LiftThread;
@@ -29,7 +29,6 @@
import lombok.extern.slf4j.Slf4j;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.*;
@Slf4j
@@ -41,7 +40,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;
@@ -51,9 +50,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());//站点楼层
@@ -211,6 +210,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) {
            OutputQueue.LIFT.offer(MessageFormat.format("【{0}】读取提升机状态信息失败 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), device.getId(), device.getIp(), device.getPort()));
        }
@@ -302,15 +326,35 @@
    }
    @Override
    public LiftCommand getMoveCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer mode) {
    public synchronized boolean setProtocolStatus(LiftProtocolStatusType status) {
        this.liftProtocol.setProtocolStatus(status);
        return true;
    }
    @Override
    public synchronized boolean setSyncTaskNo(Integer taskNo) {
        this.liftProtocol.setTaskNo(taskNo);
        return true;
    }
    @Override
    public boolean isLock(ExecuteSupport support) {
        if (support != null) {
            return support.judgement();
        }
        return true;
    }
    @Override
    public 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;
        }
        // 开始任务
@@ -334,25 +378,23 @@
    }
    @Override
    public LiftCommand getMoveWithShuttleCommand(Integer taskNo, Integer sourceLev, Integer targetLev, Integer mode) {
        return getMoveCommand(taskNo, sourceLev, targetLev, 2);
    public 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 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;
        return null;
    }
    @Override
    public LiftCommand getShuttleSignalCommand(Integer taskNo, Boolean signal) {
        LiftCommand command = new LiftCommand();
        return command;
        return null;
    }
    @Override
@@ -478,23 +520,6 @@
         * 提升机号
         */
        private Integer liftNo;
    }
    @Data
    public static class Sta {
        // 提升机站点号
        private Integer staNo;
        //输送站点排
        private Integer row;
        //输送站点列
        private Integer bay;
        // 层
        private Integer lev;
    }