|  |  | 
 |  |  | package com.zy.core.model.protocol; | 
 |  |  |  | 
 |  |  | import com.core.common.Cools; | 
 |  |  | import com.core.common.SpringUtils; | 
 |  |  | import com.zy.asrs.entity.BasLiftErr; | 
 |  |  | import com.zy.asrs.service.BasLiftErrService; | 
 |  |  | import com.zy.common.utils.RedisUtil; | 
 |  |  | import com.zy.core.enums.LiftProtocolStatusType; | 
 |  |  | import com.zy.core.model.command.LiftAssignCommand; | 
 |  |  | import com.zy.core.enums.RedisKeyType; | 
 |  |  | import lombok.Data; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  |  | 
 |  |  | import java.util.Date; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 提升机 | 
 |  |  |  */ | 
 |  |  | @Slf4j | 
 |  |  | @Data | 
 |  |  | public class LiftProtocol { | 
 |  |  | public class LiftProtocol implements Cloneable { | 
 |  |  |  | 
 |  |  |     //**********************必须存在属性********************** | 
 |  |  |     /** | 
 |  |  |      * 提升机号 | 
 |  |  |      */ | 
 |  |  |     private Short liftNo; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 提升机内部二维码 | 
 |  |  |      */ | 
 |  |  |     private Short barcode = 1699; | 
 |  |  |     private Integer liftNo; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 任务号 | 
 |  |  |      */ | 
 |  |  |     private Short taskNo = 0; | 
 |  |  |     private Integer taskNo; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 四向穿梭车号 | 
 |  |  |      */ | 
 |  |  |     private Short shuttleNo = 0; | 
 |  |  |     private Integer shuttleNo = 0; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 当前提升机状态(内部自我维护) | 
 |  |  |      */ | 
 |  |  |     private Integer protocolStatus = 1; | 
 |  |  |     private Integer protocolStatus = -1; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 当前提升机状态枚举 | 
 |  |  |      */ | 
 |  |  |     private LiftProtocolStatusType protocolStatusType = LiftProtocolStatusType.IDLE; | 
 |  |  |     private LiftProtocolStatusType protocolStatusType = LiftProtocolStatusType.NONE; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 层 | 
 |  |  |      * 模式 => 自动/手动 | 
 |  |  |      */ | 
 |  |  |     private Short lev; | 
 |  |  |     private Boolean model; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 提升机锁定 | 
 |  |  |      * 运行状态 | 
 |  |  |      */ | 
 |  |  |     private Boolean liftLock; | 
 |  |  |     private Boolean run; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 位置到达反馈 | 
 |  |  |      */ | 
 |  |  |     private Short positionArrivalFeedback; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 准备就绪 | 
 |  |  |      * 就绪为1,未就绪为0 | 
 |  |  |      * 就绪状态 | 
 |  |  |      */ | 
 |  |  |     private Boolean ready; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 运行中 | 
 |  |  |      * 运行中为1,未运行为0 | 
 |  |  |      * 前超限 | 
 |  |  |      */ | 
 |  |  |     private Boolean running; | 
 |  |  |     private Boolean frontOverrun; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 联机/单机 | 
 |  |  |      * 联机为1,单机为0 | 
 |  |  |      * 后超限 | 
 |  |  |      */ | 
 |  |  |     private Boolean mode; | 
 |  |  |     private Boolean backOverrun; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 输送线前端光电有货 | 
 |  |  |      * 有货为1,无货为0(前端指靠近货架侧) | 
 |  |  |      * 左超限 | 
 |  |  |      */ | 
 |  |  |     private Boolean lineFrontHasStock; | 
 |  |  |     private Boolean leftOverrun; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 输送线正转反馈 | 
 |  |  |      * 正转运行为1,否则为0 | 
 |  |  |      * 右超限 | 
 |  |  |      */ | 
 |  |  |     private Boolean forwardRotationFeedback; | 
 |  |  |     private Boolean rightOverrun; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 输送线反转反馈 | 
 |  |  |      * 反转运行为1,否则为0 | 
 |  |  |      * 超高 | 
 |  |  |      */ | 
 |  |  |     private Boolean reverseFeedback; | 
 |  |  |     private Boolean overHeight; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 输送线电机过载 | 
 |  |  |      * 过载为0,正常为1 | 
 |  |  |      * 超重 | 
 |  |  |      */ | 
 |  |  |     private Boolean motorOverload; | 
 |  |  |     private Boolean overWeight; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 输送线末端光电有货 | 
 |  |  |      * 有货为1,无货为0 | 
 |  |  |      * 有托盘 | 
 |  |  |      */ | 
 |  |  |     private Boolean lineEndHasStock; | 
 |  |  |     private Boolean hasTray; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 进输送线卡托盘报警 | 
 |  |  |      * 报警为1,未报警为0 | 
 |  |  |      * 有小车 | 
 |  |  |      */ | 
 |  |  |     private Boolean inConveyLineCardTrayAlarm; | 
 |  |  |     private Boolean hasCar; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 出输送线卡托盘报警 | 
 |  |  |      * 报警为1,未报警为0 | 
 |  |  |      * 故障 | 
 |  |  |      */ | 
 |  |  |     private Boolean outConveyLineCardTrayAlarm; | 
 |  |  |     private Boolean error; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 平台位置偏差报警 | 
 |  |  |      * 报警为1,未报警为0 | 
 |  |  |      * 故障码 | 
 |  |  |      */ | 
 |  |  |     private Boolean platPositionDeviationAlarm; | 
 |  |  |     private String errorCode; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 平台扭矩偏差报警 | 
 |  |  |      * 报警为1,未报警为0 | 
 |  |  |      * 任务地址 | 
 |  |  |      */ | 
 |  |  |     private Boolean platTorqueDeviationAlarm; | 
 |  |  |     private Short taskAddress; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 平台四向车检测 | 
 |  |  |      * 有车为1,无车为0 | 
 |  |  |      * 目的地址 | 
 |  |  |      */ | 
 |  |  |     private Boolean platShuttleCheck; | 
 |  |  |     private Short distAddress; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 未就绪状态 | 
 |  |  |      * 1.   不在指定层 | 
 |  |  |      * 2.   四轴不同步 | 
 |  |  |      * 3.   平台前限光电被挡到(靠近货架) | 
 |  |  |      * 4.   平台后限光电被挡到(远离货架) | 
 |  |  |      * 5.   平台上限位报警 | 
 |  |  |      * 6.   平台下限位报警 | 
 |  |  |      * 7.   电柜急停报警 | 
 |  |  |      * 8.   输送线前限位被挡到(靠近货架) | 
 |  |  |      * 9.   输送线后限位被挡到(远离货架) | 
 |  |  |      * 10.   触摸屏紧急停止被按下 | 
 |  |  |      * 11.   四轴动力线断线 | 
 |  |  |      * 12.   单机模式 | 
 |  |  |      * 13.   四轴报警 | 
 |  |  |      * 14.   位置偏差过大 | 
 |  |  |      * 15.   扭矩偏差过大 | 
 |  |  |      * 16.   输送线过载 | 
 |  |  |      * 17.   进提升机卡托盘 | 
 |  |  |      * 18.   出提升机卡托盘 | 
 |  |  |      * 已完成的任务号 | 
 |  |  |      */ | 
 |  |  |     private Short notReady; | 
 |  |  |     private String completeTaskNo; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 伺服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 securityMk = false; | 
 |  |  |     private Long sendTime = 0L; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 任务命令 | 
 |  |  |      * 日志采集时间 | 
 |  |  |      */ | 
 |  |  |     private LiftAssignCommand assignCommand; | 
 |  |  |     private Long deviceDataLog = System.currentTimeMillis(); | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 出入库模式,1:入库,2:出库 | 
 |  |  |      * 扩展字段 | 
 |  |  |      */ | 
 |  |  |     private Integer outInModel; | 
 |  |  |     private Object extend; | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 出入库模式起始站点 | 
 |  |  |      */ | 
 |  |  |     private Integer startSta; | 
 |  |  |     public String getRun$() { | 
 |  |  |         if (this.run == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 出入库模式目标站点 | 
 |  |  |      */ | 
 |  |  |     private Integer distSta; | 
 |  |  |         return this.run ? "运行中" : "空闲"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 出入库模式步数 | 
 |  |  |      */ | 
 |  |  |     private Integer outInModelStep; | 
 |  |  |     public String getReady$() { | 
 |  |  |         if (this.ready == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 工作时间 | 
 |  |  |      */ | 
 |  |  |     private Date wrkTime; | 
 |  |  |         return this.ready ? "就绪" : "未就绪"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public Short getLiftLockShortValue() { | 
 |  |  |         return liftLock ? (short) 1 : (short) 0; | 
 |  |  |     public String getModel$() { | 
 |  |  |         if (this.model == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return this.model ? "自动" : "手动"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public String getHasTray$() { | 
 |  |  |         if (this.hasTray == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return this.hasTray ? "Y" : "N"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public String getHasCar$() { | 
 |  |  |         if (this.hasCar == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return this.hasCar ? "Y" : "N"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public String getFrontOverrun$() { | 
 |  |  |         if (this.frontOverrun == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return this.frontOverrun ? "Y" : "N"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public String getBackOverrun$() { | 
 |  |  |         if (this.backOverrun == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return this.backOverrun ? "Y" : "N"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public String getLeftOverrun$() { | 
 |  |  |         if (this.leftOverrun == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return this.leftOverrun ? "Y" : "N"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public String getRightOverrun$() { | 
 |  |  |         if (this.rightOverrun == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return this.rightOverrun ? "Y" : "N"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public String getOverHeight$() { | 
 |  |  |         if (this.overHeight == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return this.overHeight ? "Y" : "N"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public String getOverWeight$() { | 
 |  |  |         if (this.overWeight == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return this.overWeight ? "Y" : "N"; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public String getProtocolStatus$() { | 
 |  |  |         if (this.protocolStatusType == null) { | 
 |  |  |             return "未知"; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return this.protocolStatusType.desc; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  | 
 |  |  |         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 synchronized void setTaskNo(Integer taskNo) { | 
 |  |  |         RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); | 
 |  |  |         if (null != redisUtil) { | 
 |  |  |             redisUtil.set(RedisKeyType.LIFT_FLAG.key + this.liftNo, taskNo); | 
 |  |  |             this.taskNo = taskNo; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         boolean res = this.taskNo == 0 | 
 |  |  |                 && !this.liftLock | 
 |  |  | //                && this.ready | 
 |  |  |                 && !this.running | 
 |  |  |                 && this.mode | 
 |  |  |                 && this.pakMk.equals(true) | 
 |  |  |                 && !this.securityMk | 
 |  |  |                 ; | 
 |  |  |         return res; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 是否处于空闲待命状态,不判断任务号 | 
 |  |  |     public Boolean isIdleNoTask() { | 
 |  |  |         if(this.taskNo == null | 
 |  |  |                 || this.liftLock == null | 
 |  |  |                 || this.ready == null | 
 |  |  |                 || this.running == null | 
 |  |  |                 || this.mode == null | 
 |  |  |                 || this.pakMk == null | 
 |  |  |         ){ | 
 |  |  |             return false; | 
 |  |  |     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.valueOf(String.valueOf(o)); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         boolean res = !this.liftLock | 
 |  |  | //                && this.ready | 
 |  |  |                 && !this.running | 
 |  |  |                 && this.mode | 
 |  |  |                 && this.pakMk | 
 |  |  |                 && !this.securityMk | 
 |  |  |                 ; | 
 |  |  |         return res; | 
 |  |  |         return this.taskNo == null ? 0 : this.taskNo; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void setPositionArrivalFeedback(Short position) { | 
 |  |  |         Short lev = null; | 
 |  |  |         switch (position) { | 
 |  |  |             case 1: | 
 |  |  |                 lev = 1; | 
 |  |  |                 break; | 
 |  |  |             case 4: | 
 |  |  |                 lev = 2; | 
 |  |  |                 break; | 
 |  |  |             case 8: | 
 |  |  |                 lev = 3; | 
 |  |  |                 break; | 
 |  |  |             case 16: | 
 |  |  |                 lev = 4; | 
 |  |  |                 break; | 
 |  |  |     /** | 
 |  |  |      * 错误码 | 
 |  |  |      */ | 
 |  |  |     public String getErrCode$() { | 
 |  |  |         if (this.errorCode == null) { | 
 |  |  |             return ""; | 
 |  |  |         } | 
 |  |  |         this.lev = lev;//层高 | 
 |  |  |         this.positionArrivalFeedback = position;//位置到达反馈 | 
 |  |  |         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 getPositionArrivalFeedback$() { | 
 |  |  |         if (this.positionArrivalFeedback == null) { | 
 |  |  |             return null; | 
 |  |  |     @Override | 
 |  |  |     public LiftProtocol clone() { | 
 |  |  |         try { | 
 |  |  |             return (LiftProtocol) super.clone(); | 
 |  |  |         } catch (CloneNotSupportedException e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         switch (this.positionArrivalFeedback) { | 
 |  |  |             case 1: | 
 |  |  |                 return 1; | 
 |  |  |             case 2: | 
 |  |  |                 return 2; | 
 |  |  |             case 4: | 
 |  |  |                 return 3; | 
 |  |  |             case 8: | 
 |  |  |                 return 4; | 
 |  |  |             case 16: | 
 |  |  |                 return 5; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return null; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | } |