|  |  |  | 
|---|
|  |  |  | package com.zy.core.model.protocol; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.SpringUtils; | 
|---|
|  |  |  | import com.zy.asrs.service.BasShuttleService; | 
|---|
|  |  |  | import com.zy.core.News; | 
|---|
|  |  |  | import com.zy.core.enums.LiftProtocolStatusType; | 
|---|
|  |  |  | import com.zy.core.enums.ShuttleErrorCodeType; | 
|---|
|  |  |  | import com.zy.core.enums.ShuttleProtocolStatusType; | 
|---|
|  |  |  | import com.zy.core.enums.ShuttleStatusType; | 
|---|
|  |  |  | import com.zy.core.model.command.LiftAssignCommand; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasLiftErr; | 
|---|
|  |  |  | import com.zy.asrs.service.BasLiftErrService; | 
|---|
|  |  |  | import com.zy.common.utils.RedisUtil; | 
|---|
|  |  |  | import com.zy.core.enums.*; | 
|---|
|  |  |  | import lombok.Data; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Data | 
|---|
|  |  |  | public class LiftProtocol { | 
|---|
|  |  |  | public class LiftProtocol implements Cloneable { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 提升机号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short liftNo; | 
|---|
|  |  |  | private Integer liftNo; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 模式0手动 1单机 2联机 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer model; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 任务号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short taskNo = 0; | 
|---|
|  |  |  | private Integer taskNo = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 四向穿梭车号 | 
|---|
|  |  |  | * PLC任务号 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short shuttleNo = 0; | 
|---|
|  |  |  | private Integer plcTaskNo; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 当前提升机状态(内部自我维护) | 
|---|
|  |  |  | * 任务状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer protocolStatus = 1; | 
|---|
|  |  |  | private Integer protocolStatus = LiftProtocolStatusType.IDLE.id; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 当前提升机状态枚举 | 
|---|
|  |  |  | * 任务状态枚举 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private LiftProtocolStatusType protocolStatusType = LiftProtocolStatusType.IDLE; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 层 | 
|---|
|  |  |  | * 设备状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short lev; | 
|---|
|  |  |  | private Integer deviceStatus = LiftDeviceStatusType.NONE.id; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 提升机锁定 | 
|---|
|  |  |  | * 设备状态枚举 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean liftLock; | 
|---|
|  |  |  | private LiftDeviceStatusType deviceStatusType = LiftDeviceStatusType.NONE; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 位置到达反馈 | 
|---|
|  |  |  | * 任务模式 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short positionArrivalFeedback; | 
|---|
|  |  |  | private Integer taskMode = LiftTaskModeType.NONE.id; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 准备就绪 | 
|---|
|  |  |  | * 就绪为1,未就绪为0 | 
|---|
|  |  |  | * 任务模式枚举 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean ready; | 
|---|
|  |  |  | private LiftTaskModeType modeType = LiftTaskModeType.NONE; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 运行中 | 
|---|
|  |  |  | * 运行中为1,未运行为0 | 
|---|
|  |  |  | * 取货数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean running; | 
|---|
|  |  |  | private Integer pick; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 联机/单机 | 
|---|
|  |  |  | * 联机为1,单机为0 | 
|---|
|  |  |  | * 放货数据 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean mode; | 
|---|
|  |  |  | private Integer put; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 输送线前端光电有货 | 
|---|
|  |  |  | * 有货为1,无货为0(前端指靠近货架侧) | 
|---|
|  |  |  | * 有托盘 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean lineFrontHasStock; | 
|---|
|  |  |  | private Boolean hasTray; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 输送线正转反馈 | 
|---|
|  |  |  | * 正转运行为1,否则为0 | 
|---|
|  |  |  | * 有小车 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean forwardRotationFeedback; | 
|---|
|  |  |  | private Boolean hasCar; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 输送线反转反馈 | 
|---|
|  |  |  | * 反转运行为1,否则为0 | 
|---|
|  |  |  | * 出入库模式 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean reverseFeedback; | 
|---|
|  |  |  | private Integer iOMode = LiftIoModeType.NONE.id; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 输送线电机过载 | 
|---|
|  |  |  | * 过载为0,正常为1 | 
|---|
|  |  |  | * 出入库模式枚举 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean motorOverload; | 
|---|
|  |  |  | private LiftIoModeType iOModeType = LiftIoModeType.NONE; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 输送线末端光电有货 | 
|---|
|  |  |  | * 有货为1,无货为0 | 
|---|
|  |  |  | * 故障码 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean lineEndHasStock; | 
|---|
|  |  |  | private Integer errorCode; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 进输送线卡托盘报警 | 
|---|
|  |  |  | * 报警为1,未报警为0 | 
|---|
|  |  |  | * 当前层 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean inConveyLineCardTrayAlarm; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 出输送线卡托盘报警 | 
|---|
|  |  |  | * 报警为1,未报警为0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean outConveyLineCardTrayAlarm; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 平台位置偏差报警 | 
|---|
|  |  |  | * 报警为1,未报警为0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean platPositionDeviationAlarm; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 平台扭矩偏差报警 | 
|---|
|  |  |  | * 报警为1,未报警为0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean platTorqueDeviationAlarm; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 平台四向车检测 | 
|---|
|  |  |  | * 有车为1,无车为0 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean platShuttleCheck; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 未就绪状态 | 
|---|
|  |  |  | * 1.   不在指定层 | 
|---|
|  |  |  | * 2.   四轴不同步 | 
|---|
|  |  |  | * 3.   平台前限光电被挡到(靠近货架) | 
|---|
|  |  |  | * 4.   平台后限光电被挡到(远离货架) | 
|---|
|  |  |  | * 5.   平台上限位报警 | 
|---|
|  |  |  | * 6.   平台下限位报警 | 
|---|
|  |  |  | * 7.   电柜急停报警 | 
|---|
|  |  |  | * 8.   输送线前限位被挡到(靠近货架) | 
|---|
|  |  |  | * 9.   输送线后限位被挡到(远离货架) | 
|---|
|  |  |  | * 10.   触摸屏紧急停止被按下 | 
|---|
|  |  |  | * 11.   四轴动力线断线 | 
|---|
|  |  |  | * 12.   单机模式 | 
|---|
|  |  |  | * 13.   四轴报警 | 
|---|
|  |  |  | * 14.   位置偏差过大 | 
|---|
|  |  |  | * 15.   扭矩偏差过大 | 
|---|
|  |  |  | * 16.   输送线过载 | 
|---|
|  |  |  | * 17.   进提升机卡托盘 | 
|---|
|  |  |  | * 18.   出提升机卡托盘 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short notReady; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 伺服1错误 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short servoError1; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 伺服2错误 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short servoError2; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 伺服3错误 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short servoError3; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 伺服4错误 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short servoError4; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 提升机实际速度反馈 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Short liftActualSpeed; | 
|---|
|  |  |  | private Integer lev; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 作业标记 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean pakMk = true; | 
|---|
|  |  |  | private Boolean pakMk = false; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 四向穿梭车调度提升机时,需要锁定此标记 | 
|---|
|  |  |  | * 指令下发时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean securityMk = false; | 
|---|
|  |  |  | private Long sendTime = 0L; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 任务命令 | 
|---|
|  |  |  | * 日志采集时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private LiftAssignCommand assignCommand; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Short getLiftLockShortValue() { | 
|---|
|  |  |  | return liftLock ? (short) 1 : (short) 0; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private Long deviceDataLog = System.currentTimeMillis(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设置提升机状态 | 
|---|
|  |  |  | * 扩展字段 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Object extend; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设置任务状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void setProtocolStatus(Integer status) { | 
|---|
|  |  |  | this.protocolStatus = status; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设置提升机状态 | 
|---|
|  |  |  | * 设置任务状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void setProtocolStatus(LiftProtocolStatusType status) { | 
|---|
|  |  |  | this.protocolStatus = status.id; | 
|---|
|  |  |  | this.protocolStatusType = status; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 是否处于空闲待命状态 | 
|---|
|  |  |  | public Boolean isIdle() { | 
|---|
|  |  |  | if(this.taskNo == null | 
|---|
|  |  |  | || this.liftLock == null | 
|---|
|  |  |  | || this.ready == null | 
|---|
|  |  |  | || this.running == null | 
|---|
|  |  |  | || this.mode == null | 
|---|
|  |  |  | || this.pakMk == null | 
|---|
|  |  |  | ){ | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设置任务模式 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void setTaskMode(Integer taskMode) { | 
|---|
|  |  |  | this.taskMode = taskMode; | 
|---|
|  |  |  | this.modeType = LiftTaskModeType.get(taskMode); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设置任务模式 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void setMode(LiftTaskModeType taskMode) { | 
|---|
|  |  |  | this.taskMode = taskMode.id; | 
|---|
|  |  |  | this.modeType = taskMode; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设置出入库模式 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void setIOMode(Integer ioMode) { | 
|---|
|  |  |  | this.iOMode = ioMode; | 
|---|
|  |  |  | this.iOModeType = LiftIoModeType.get(ioMode); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 设置出入库模式 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public void setIOMode(LiftIoModeType ioMode) { | 
|---|
|  |  |  | this.iOMode = ioMode.id; | 
|---|
|  |  |  | this.iOModeType = ioMode; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 错误码 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public String getErrCode$() { | 
|---|
|  |  |  | if (this.errorCode == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasLiftErrService basLiftErrService = SpringUtils.getBean(BasLiftErrService.class); | 
|---|
|  |  |  | BasLiftErr basLiftErr = basLiftErrService.selectById(this.errorCode); | 
|---|
|  |  |  | if (basLiftErr == null) { | 
|---|
|  |  |  | return String.valueOf(this.errorCode); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return basLiftErr.getErrName(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public Integer getTaskNo() { | 
|---|
|  |  |  | RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); | 
|---|
|  |  |  | if (null != redisUtil) { | 
|---|
|  |  |  | Object o = redisUtil.get(RedisKeyType.LIFT_FLAG.key + this.liftNo); | 
|---|
|  |  |  | if (!Cools.isEmpty(o)) { | 
|---|
|  |  |  | this.taskNo = Integer.parseInt(String.valueOf(o)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return this.taskNo == null ? 0 : this.taskNo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getModel$() { | 
|---|
|  |  |  | if (this.model == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | boolean res = this.taskNo == 0 | 
|---|
|  |  |  | && !this.liftLock | 
|---|
|  |  |  | && this.ready | 
|---|
|  |  |  | && !this.running | 
|---|
|  |  |  | && this.mode | 
|---|
|  |  |  | && this.pakMk.equals(true) | 
|---|
|  |  |  | && !this.securityMk | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | return res; | 
|---|
|  |  |  | String name = ""; | 
|---|
|  |  |  | if (this.model == 0) { | 
|---|
|  |  |  | name = "手动"; | 
|---|
|  |  |  | } else if (this.model == 1) { | 
|---|
|  |  |  | name = "单机"; | 
|---|
|  |  |  | }else if (this.model == 2) { | 
|---|
|  |  |  | name = "联机"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return name; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setPositionArrivalFeedback(Short position) { | 
|---|
|  |  |  | this.lev = position;//层高 | 
|---|
|  |  |  | this.positionArrivalFeedback = position;//位置到达反馈 | 
|---|
|  |  |  | public String getProtocolStatus$() { | 
|---|
|  |  |  | if (this.protocolStatus == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return LiftProtocolStatusType.get(this.protocolStatus).desc; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getDeviceStatus$() { | 
|---|
|  |  |  | if (this.deviceStatus == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return LiftDeviceStatusType.get(this.deviceStatus).desc; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getTaskMode$() { | 
|---|
|  |  |  | if (this.taskMode == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return LiftTaskModeType.get(this.taskMode).desc; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getIOMode$() { | 
|---|
|  |  |  | if (this.iOMode == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return LiftIoModeType.get(this.iOMode).desc; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public LiftProtocol clone() { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | return (LiftProtocol) super.clone(); | 
|---|
|  |  |  | } catch (CloneNotSupportedException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|