|  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.core.common.SpringUtils; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasShuttle; | 
|---|
|  |  |  | import com.zy.asrs.entity.BasShuttleErr; | 
|---|
|  |  |  | import com.zy.asrs.service.BasShuttleErrService; | 
|---|
|  |  |  | import com.zy.asrs.service.BasShuttleService; | 
|---|
|  |  |  | import com.zy.asrs.utils.Utils; | 
|---|
|  |  |  | import com.zy.common.utils.NavigatePositionConvert; | 
|---|
|  |  |  | import com.zy.core.News; | 
|---|
|  |  |  | import com.zy.core.enums.ShuttleErrorCodeType; | 
|---|
|  |  |  | import com.zy.core.enums.ShuttleProtocolStatusType; | 
|---|
|  |  |  | import com.zy.core.enums.ShuttleStatusType; | 
|---|
|  |  |  | import com.zy.core.model.command.ShuttleAssignCommand; | 
|---|
|  |  |  | import lombok.Data; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 牛眼四向穿梭车 | 
|---|
|  |  |  | 
|---|
|  |  |  | private NyShuttlePointClass coord; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * WCS库位xyz | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private NyShuttlePointClass wcsPoint; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 任务目的库位xyztaskId(正在动作的任务ID)lastTaskId(最后一个完成的任务ID)recentTaskId(收到的最后一个任务ID) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private TaskClass task; | 
|---|
|  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 故障码 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private List<Integer> errCode; | 
|---|
|  |  |  | private Integer errCode; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * mileage总里程数(米),liftNumber顶升总数dropNumber下降总数reversingX换X总数reversingY换Y总数 | 
|---|
|  |  |  | 
|---|
|  |  |  | * 非自动状态时间计时(S) | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer errTime; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 独占令牌 | 
|---|
|  |  |  | * 未被任务占据,令牌为0 | 
|---|
|  |  |  | * 被任务占据,将任务号赋值给令牌 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer token = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跑库状态 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Boolean moveLoc = false; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跑库类型,0:跑轨道,1:跑库位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer moveType = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跑库X起点 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer xStart = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跑库X终点 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer xTarget = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跑库X当前点位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer xCurrent = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跑库Y起点 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer yStart = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跑库Y终点 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer yTarget = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 跑库Y当前点位 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Integer yCurrent = 0; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 指令下发时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Long sendTime = 0L; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 日志采集时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Long deviceDataLog = System.currentTimeMillis(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 最近一次在线时间 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private Long lastOnlineTime = System.currentTimeMillis(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //总里程数 | 
|---|
|  |  |  | @Data | 
|---|
|  |  |  | 
|---|
|  |  |  | if (this.getFree() == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return this.getFree() == 1 ? "空闲" : "运行中"; | 
|---|
|  |  |  | return this.getFree() == 0 ? "运行中" : "空闲"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getWorkingMode$() { | 
|---|
|  |  |  | if (this.getWorkingMode() == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return this.getWorkingMode() == 0 ? "手动" : "自动"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getLoadState$() { | 
|---|
|  |  |  | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | switch (this.getRunDir()) { | 
|---|
|  |  |  | switch (this.getLiftPosition()) { | 
|---|
|  |  |  | case 0: | 
|---|
|  |  |  | return "未知"; | 
|---|
|  |  |  | case 1: | 
|---|
|  |  |  | 
|---|
|  |  |  | return NavigatePositionConvert.nyXyzToLocNo(this.getPoint().getX(), this.getPoint().getY(), this.getPoint().getZ()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getPoint$$() { | 
|---|
|  |  |  | if (this.getPoint() == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return JSON.toJSONString(this.getPoint()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getCoord$() { | 
|---|
|  |  |  | if (this.getCoord() == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | 
|---|
|  |  |  | return JSON.toJSONString(this.getCoord()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public String getErrCode$() { | 
|---|
|  |  |  | if (this.getErrCode() == null) { | 
|---|
|  |  |  | return ""; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | BasShuttleErrService basShuttleErrService = SpringUtils.getBean(BasShuttleErrService.class); | 
|---|
|  |  |  | BasShuttleErr basShuttleErr = basShuttleErrService.selectById(this.getErrCode()); | 
|---|
|  |  |  | if (basShuttleErr == null) { | 
|---|
|  |  |  | return this.getErrCode().toString(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return basShuttleErr.getErrName(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setPoint(NyShuttlePointClass point) { | 
|---|
|  |  |  | String locNo = NavigatePositionConvert.nyXyzToLocNo(point.getX(), point.getY(), point.getZ()); | 
|---|
|  |  |  | this.point = point; | 
|---|
|  |  |  | this.currentLocNo = locNo; | 
|---|
|  |  |  | NyShuttlePointClass wcsPoint = new NyShuttlePointClass(); | 
|---|
|  |  |  | wcsPoint.setX(Utils.getRow(locNo)); | 
|---|
|  |  |  | wcsPoint.setY(Utils.getBay(locNo)); | 
|---|
|  |  |  | wcsPoint.setZ(Utils.getLev(locNo)); | 
|---|
|  |  |  | this.wcsPoint = wcsPoint; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 是否处于空闲待命状态 | 
|---|
|  |  |  | public Boolean isIdle() { | 
|---|
|  |  |  | boolean res = this.free == ShuttleStatusType.IDLE.id | 
|---|
|  |  |  | && this.pakMk.equals(true) | 
|---|
|  |  |  | && !this.pakMk | 
|---|
|  |  |  | && this.errState == 0 | 
|---|
|  |  |  | && this.taskNo == 0 | 
|---|
|  |  |  | && this.protocolStatus == ShuttleProtocolStatusType.IDLE.id | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | if (!res) { | 
|---|
|  |  |  | return res; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 电量 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Integer chargeLine = SpringUtils.getBean(BasShuttleService.class).selectById(this.shuttleNo).getChargeLine(); | 
|---|
|  |  |  | if (chargeLine == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return this.getPowerPercent() >= chargeLine; | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | News.error("fail", e); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return res; | 
|---|
|  |  |  | //        if (!res) { | 
|---|
|  |  |  | //            return res; | 
|---|
|  |  |  | //        } else { | 
|---|
|  |  |  | //            // 电量 | 
|---|
|  |  |  | //            try { | 
|---|
|  |  |  | //                Integer chargeLine = SpringUtils.getBean(BasShuttleService.class).selectById(this.shuttleNo).getChargeLine(); | 
|---|
|  |  |  | //                if (chargeLine == null) { | 
|---|
|  |  |  | //                    return false; | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                return this.getPowerPercent() >= chargeLine; | 
|---|
|  |  |  | //            } catch (Exception e) { | 
|---|
|  |  |  | //                News.error("fail", e); | 
|---|
|  |  |  | //                return false; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 是否处于空闲待命状态,传入的taskNo和当前taskNo相同时允许放行 | 
|---|
|  |  |  | public Boolean isIdle(int taskNo) { | 
|---|
|  |  |  | boolean res = this.free == ShuttleStatusType.IDLE.id | 
|---|
|  |  |  | && this.pakMk.equals(true) | 
|---|
|  |  |  | && !this.pakMk | 
|---|
|  |  |  | && this.errState == 0 | 
|---|
|  |  |  | && (this.taskNo == 0 || this.taskNo == taskNo) | 
|---|
|  |  |  | && this.protocolStatus.intValue() == ShuttleProtocolStatusType.IDLE.id | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | if (!res) { | 
|---|
|  |  |  | return res; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 电量 | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Integer chargeLine = SpringUtils.getBean(BasShuttleService.class).selectById(this.shuttleNo).getChargeLine(); | 
|---|
|  |  |  | return this.getPowerPercent() > chargeLine; | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | News.error("fail", e); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return res; | 
|---|
|  |  |  | //        if (!res) { | 
|---|
|  |  |  | //            return res; | 
|---|
|  |  |  | //        } else { | 
|---|
|  |  |  | //            // 电量 | 
|---|
|  |  |  | //            try { | 
|---|
|  |  |  | //                Integer chargeLine = SpringUtils.getBean(BasShuttleService.class).selectById(this.shuttleNo).getChargeLine(); | 
|---|
|  |  |  | //                return this.getPowerPercent() > chargeLine; | 
|---|
|  |  |  | //            } catch (Exception e) { | 
|---|
|  |  |  | //                News.error("fail", e); | 
|---|
|  |  |  | //                return false; | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 是否处于空闲待命状态 | 
|---|
|  |  |  | public Boolean isIdleNoCharge() { | 
|---|
|  |  |  | boolean res = this.free == ShuttleStatusType.IDLE.id | 
|---|
|  |  |  | && this.pakMk.equals(true) | 
|---|
|  |  |  | && !this.pakMk | 
|---|
|  |  |  | && this.errState == 0 | 
|---|
|  |  |  | && this.taskNo == 0 | 
|---|
|  |  |  | && this.protocolStatus == ShuttleProtocolStatusType.IDLE.id | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | return res; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 是否处于空闲待命状态 | 
|---|
|  |  |  | public Boolean isIdleNoCharge(int taskNo) { | 
|---|
|  |  |  | boolean res = this.free == ShuttleStatusType.IDLE.id | 
|---|
|  |  |  | && !this.pakMk | 
|---|
|  |  |  | && this.errState == 0 | 
|---|
|  |  |  | && (this.taskNo == 0 || this.taskNo == taskNo) | 
|---|
|  |  |  | && this.protocolStatus == ShuttleProtocolStatusType.IDLE.id | 
|---|
|  |  |  | ; | 
|---|
|  |  |  | return res; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | boolean res = this.free == ShuttleStatusType.IDLE.id | 
|---|
|  |  |  | && this.pakMk | 
|---|
|  |  |  | && !this.pakMk | 
|---|
|  |  |  | && this.errState == 0 | 
|---|
|  |  |  | && this.taskNo == 0 | 
|---|
|  |  |  | && this.protocolStatusType.id == ShuttleProtocolStatusType.IDLE.id | 
|---|
|  |  |  | 
|---|
|  |  |  | if (chargeLine == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return this.getPowerPercent() < chargeLine || this.minCellVoltage < 2900; | 
|---|
|  |  |  | return this.getPowerPercent() < chargeLine; | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | News.error("fail", e); | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void setShuttleNo(Short shuttleNo) { | 
|---|
|  |  |  | if (shuttleNo != 0) { | 
|---|
|  |  |  | this.shuttleNo = shuttleNo; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|