自动化立体仓库 - WCS系统
#
Junjie
2025-04-10 1d624dfdb040825ffecba6c792c480be662b2dbc
src/main/java/com/zy/core/model/protocol/ShuttleProtocol.java
@@ -1,25 +1,46 @@
package com.zy.core.model.protocol;
import com.zy.core.enums.ShuttleStatusType;
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasShuttleErr;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.service.BasShuttleErrService;
import com.zy.asrs.service.LocMastService;
import com.zy.common.utils.RedisUtil;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.ShuttleProtocolStatusType;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.util.HashMap;
/**
 * 四向穿梭车
 */
@Slf4j
@Data
public class ShuttleProtocol {
public class ShuttleProtocol implements Cloneable {
    //**********************必须存在属性**********************
    /**
     * 四向穿梭车号
     */
    private Short shuttleNo;
    private Integer shuttleNo;
    /**
     * 任务号
     */
    private Short taskNo = 0;
    private Integer taskNo;
    /**
     * 当前小车状态(内部自我维护)
     */
    private Integer protocolStatus;
    /**
     * 当前小车作业状态枚举
     */
    private ShuttleProtocolStatusType protocolStatusType;
    /**
     * 源库位
@@ -32,207 +53,311 @@
    private String locNo;
    /**
     * 排
     * 小车设备状态0:忙碌 1:空闲
     */
    private Short row;
    private Integer deviceStatus;
    /**
     * 列
     * 小车模式,0:手动 1:自动
     */
    private Short bay;
    /**
     * 层
     */
    private Short lev;
    /**
     * 小车忙状态位
     * 1: 忙
     * 0: 空闲
     */
    private Short busyStatus;
    /**
     * 小车忙状态位枚举
     */
    private ShuttleStatusType busyStatusType;
    private Integer mode;
    /**
     * 当前二维码
     * 0为空
     */
    private Short currentCode;
    private String currentCode;
    /**
     * 电池电量百分比
     * 电池电量
     */
    private Short batteryPower;
    /**
     * 电池温度
     */
    private Short batteryTemp;
    private String batteryPower;
    /**
     * 错误编号
     */
    private Short errorCode;
    private String errorCode;
    //**********************非必须属性,实际使用中可能存在空值**********************
    /**
     * Plc输出状态IO
     * 电池温度
     */
    private Short plcOutputStatusIO;
    private String batteryTemp;
    /**
     * 错误信息码
     * 是否顶升
     */
    private Short statusErrorCode;
    private Boolean hasLift;
    /**
     * PLC输入状态
     * 是否有托盘
     */
    private Short plcInputStatus;
    private Boolean hasPallet;
    /**
     * 当前或者之前读到的二维码值
     * 行驶方向
     */
    private Short currentOrBeforeCode;
    private String runDirection;
    /**
     * 读到的二维码X方向偏移量
     * 是否为充电状态
     */
    private Short codeOffsetX;
    private Boolean hasCharge;
    /**
     * 读到的二维码Y方向偏移量
     * 电池电压
     */
    private Short codeOffsetY;
    private Integer batteryVoltage;
    /**
     * 当前的电压值
     * 运行速度
     */
    private Short currentVoltage;
    private Integer speed;
    /**
     * 当前的模拟量值
     */
    private Short currentAnalogValue;
    //**********************系统自身所需属性**********************
    /**
     * 当前的升降伺服速度
     */
    private Short currentLiftServoSpeed;
    /**
     * 当前的行走伺服速度
     */
    private Short currentMoveServoSpeed;
    /**
     * 当前的升降伺服负载率
     */
    private Short currentLiftServoLoad;
    /**
     * 当前的行走伺服负载率
     */
    private Short currentMoveServoLoad;
    /**
     * 作业标记
     * 作业标记 false表示正在作业
     */
    private Boolean pakMk = true;
    // 任务信息 ---------------------------------------------------------
    /**
     * 96.入库任务中
     * 跑库状态
     */
    private boolean pakInTask;
    private Boolean moveLoc = false;
    /**
     * 97. 出库任务中
     * 跑库类型,0:跑轨道,1:跑库位
     */
    private boolean pakOutTask;
    private Integer moveType = 0;
    /**
     * 98. 移库任务中
     * 跑库X起点
     */
    private boolean pakMoveTask;
    private Integer xStart = 0;
    /**
     * 99. 回原点任务中
     * 跑库X终点
     */
    private boolean goHpTask;
    private Integer xTarget = 0;
    /**
     * 100. 去反原点任务中
     * 跑库X当前点位
     */
    private boolean goOHpTask;
    private Integer xCurrent = 0;
    /**
     * 101. 去原点避让位
     * 跑库Y起点
     */
    private boolean goHpAvoid;
    private Integer yStart = 0;
    /**
     * 102. 去反原点避让位
     * 跑库Y终点
     */
    private boolean goOHpAvoid;
    private Integer yTarget = 0;
    /**
     * 104. 入库取空结束
     * 跑库Y当前点位
     */
    private boolean pakInEmpty;
    private Integer yCurrent = 0;
    /**
     * 105. 入库正常结束
     * 演示模式
     */
    private boolean pakInFinish;
    private Boolean demo = false;
    /**
     * 106. 出库取空结束
     * 日志采集时间
     */
    private boolean pakOutEmpty;
    private Long deviceDataLog = System.currentTimeMillis();
    /**
     * 107. 出库正常结束
     * 指令下发时间
     */
    private boolean pakOutFinish;
    private Long sendTime = 0L;
    /**
     * 108. 去原点避让完成
     * 最近一次在线时间
     */
    private boolean goHpAvoidFinish;
    private Long lastOnlineTime = System.currentTimeMillis();
    /**
     * 109. 去反原点避让完成
     * 扩展字段
     */
    private boolean goOHpAvoidFinish;
    private Object extend;
    /**
     * 110. 去原点避让完成
     * 系统消息
     */
    private boolean goHpAvoidErr;
    private String systemMsg;
    /**
     * 111. 去反原点避让完成
     */
    private boolean goOHpAvoidErr;
    public void setBusyStatus(Short status) {
        this.busyStatus = status;
        this.busyStatusType = ShuttleStatusType.get(status);
    public String getProtocolStatus$() {
        if (this.protocolStatusType == null) {
            return "";
        }
        return this.protocolStatusType.desc;
    }
    public void setBusyStatus(ShuttleStatusType type) {
        this.busyStatus = type.id.shortValue();
        this.busyStatusType = type;
    /**
     * 设置小车状态
     */
    public void setProtocolStatus(Integer status) {
        this.protocolStatus = status;
        this.protocolStatusType = ShuttleProtocolStatusType.get(status);
    }
    //获取电池电量
    public Short getBatteryPower() {
        return (short) (this.batteryPower * 0.1);
    /**
     * 设置小车状态
     */
    public void setProtocolStatus(ShuttleProtocolStatusType status) {
        this.protocolStatus = status.id;
        this.protocolStatusType = status;
    }
    public Integer getTaskNo() {
        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
        if (null != redisUtil) {
            Object o = redisUtil.get(RedisKeyType.SHUTTLE_FLAG.key + this.shuttleNo);
            if (!Cools.isEmpty(o)) {
                this.taskNo = Integer.parseInt(String.valueOf(o));
            }
        }
        return this.taskNo == null ? 0 : this.taskNo;
    }
    public synchronized void setSyncTaskNo(Integer taskNo) {
        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
        if (null != redisUtil) {
            redisUtil.set(RedisKeyType.SHUTTLE_FLAG.key + this.shuttleNo, taskNo);
            this.taskNo = taskNo;
        }
    }
    @Override
    public ShuttleProtocol clone() {
        try {
            return (ShuttleProtocol) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }
    //通过当前二维码获取当前库位号
    public String getCurrentLocNo() {
        LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
        if (locMastService == null) {
            return null;
        }
        //源库位(小车当前位置)
        LocMast currentLocMast = locMastService.queryByQrCode(this.currentCode);
        if (currentLocMast == null) {
            return null;
        }
        return currentLocMast.getLocNo();
    }
    public String getStatusErrorCode$() {
        BasShuttleErrService basShuttleErrService = SpringUtils.getBean(BasShuttleErrService.class);
        if (this.errorCode == null) {
            return "";
        }
        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(Integer.valueOf(this.errorCode));
        if (basShuttleErr == null) {
            return this.errorCode;
        }
        return basShuttleErr.getErrName();
    }
    public String getMode$() {
        if (this.mode == null) {
            return "";
        }
        if (this.mode == 0) {
            return "手动";
        } else if (this.mode == 1) {
            return "自动";
        }
        return "";
    }
    public String getDeviceStatus$() {
        if (this.deviceStatus == null) {
            return "";
        }
        if (this.deviceStatus == 0) {
            return "忙碌";
        } else if (this.deviceStatus == 1) {
            return "空闲";
        }
        return "";
    }
    public String getHasLift$() {
        if (this.hasLift == null) {
            return "";
        }
        return this.hasLift ? "Y" : "N";
    }
    public String getHasCharge$() {
        if (this.hasCharge == null) {
            return "";
        }
        return this.hasCharge ? "Y" : "N";
    }
    public String getHasPallet$() {
        if (this.hasPallet == null) {
            return "";
        }
        return this.hasPallet ? "Y" : "N";
    }
    public String getPakMk$() {
        if (this.pakMk == null) {
            return "";
        }
        return this.pakMk ? "Y" : "N";
    }
    public String getDemo$() {
        if (this.demo == null) {
            return "";
        }
        return this.demo ? "Y" : "N";
    }
    public HashMap<String, Object> getPoint() {
        HashMap<String, Object> map = new HashMap<>();
        if (this.currentCode == null) {
            return map;
        }
        LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
        if (locMastService == null) {
            return map;
        }
        //源库位(小车当前位置)
        LocMast currentLocMast = locMastService.queryByQrCode(this.currentCode);
        if (currentLocMast == null) {
            return map;
        }
        map.put("x", currentLocMast.getRow1());
        map.put("y", currentLocMast.getBay1());
        map.put("z", currentLocMast.getLev1());
        return map;
    }
}