| | |
| | | import com.zy.asrs.framework.common.DateUtils; |
| | | import com.zy.asrs.framework.common.SpringUtils; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | import com.zy.asrs.wcs.core.entity.BasShuttle; |
| | | import com.zy.asrs.wcs.core.entity.Loc; |
| | | import com.zy.asrs.wcs.core.model.NavigateNode; |
| | | import com.zy.asrs.wcs.core.model.command.ShuttleCommand; |
| | | import com.zy.asrs.wcs.core.model.enums.ShuttleCommandModeType; |
| | | import com.zy.asrs.wcs.core.model.enums.ShuttleRunDirection; |
| | | import com.zy.asrs.wcs.core.service.BasShuttleService; |
| | | import com.zy.asrs.wcs.core.service.LocService; |
| | | import com.zy.asrs.wcs.core.utils.NavigateUtils; |
| | | import com.zy.asrs.wcs.rcs.News; |
| | | import com.zy.asrs.wcs.rcs.cache.OutputQueue; |
| | | import com.zy.asrs.wcs.rcs.entity.DeviceDataLog; |
| | | import com.zy.asrs.wcs.rcs.model.enums.ShuttleProtocolStatusType; |
| | | import com.zy.asrs.wcs.rcs.model.enums.SlaveType; |
| | | import com.zy.asrs.wcs.rcs.model.protocol.ShuttleProtocol; |
| | | import com.zy.asrs.wcs.rcs.service.DeviceDataLogService; |
| | | import com.zy.asrs.wcs.rcs.thread.ShuttleThread; |
| | | import com.zy.asrs.wcs.core.utils.RedisUtil; |
| | | import com.zy.asrs.wcs.rcs.entity.Device; |
| | |
| | | //----------读取四向穿梭车状态----------- |
| | | //小车设备状态 |
| | | Integer deviceStatus = data.getInteger("deviceStatus"); |
| | | if (deviceStatus == 255) { |
| | | //离线 |
| | | shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.OFFLINE); |
| | | } |
| | | shuttleProtocol.setDeviceStatus(deviceStatus); |
| | | //当前二维码 |
| | | shuttleProtocol.setCurrentCode(data.getString("groundCode") == null ? "0" : data.getString("groundCode")); |
| | |
| | | //是否顶升 |
| | | shuttleProtocol.setHasLift(data.getInteger("palletStatus") == 1 ? true : false); |
| | | //是否有托盘 |
| | | shuttleProtocol.setHasPallet(data.getInteger("hasPallet") != 2 ? true : false); |
| | | shuttleProtocol.setHasPallet(data.getInteger("hasPallet") == null ? true : data.getInteger("hasPallet") != 2 ? true : false); |
| | | //行驶方向 |
| | | shuttleProtocol.setRunDirection(data.getString("direction") == null ? "none" : data.getString("direction")); |
| | | //是否为充电状态 |
| | | shuttleProtocol.setHasCharge((deviceStatus == 5 || deviceStatus == 13) ? true : false); |
| | | |
| | | //*********读取扩展字段********** |
| | | InnerSuhttleExtend extend = JSON.parseObject(JSON.toJSONString(shuttleProtocol.getExtend()), InnerSuhttleExtend.class); |
| | | InnerSuhttleExtend extend = (InnerSuhttleExtend) shuttleProtocol.getExtend(); |
| | | extend.setMapVersion(data.getString("version"));//地图版本 |
| | | extend.setStatusDescription(data.getString("statusDescription"));//状态描述 |
| | | shuttleProtocol.setExtend(extend);//扩展字段 |
| | |
| | | // shuttleProtocol.setProtocolStatusType(ShuttleProtocolStatusType.IDLE); |
| | | // } |
| | | |
| | | // if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) { |
| | | // //采集时间超过5s,保存一次数据记录 |
| | | // //保存数据记录 |
| | | // DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class); |
| | | // DeviceDataLog deviceDataLog = new DeviceDataLog(); |
| | | // deviceDataLog.setOriginData(Base64.getEncoder().encodeToString(result.Content)); |
| | | // deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol)); |
| | | // deviceDataLog.setType("shuttle"); |
| | | // deviceDataLog.setDeviceNo(shuttleProtocol.getShuttleNo().intValue()); |
| | | // deviceDataLog.setCreateTime(new Date()); |
| | | // deviceDataLogService.insert(deviceDataLog); |
| | | // |
| | | // //更新采集时间 |
| | | // shuttleProtocol.setDeviceDataLog(System.currentTimeMillis()); |
| | | // } |
| | | if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) { |
| | | //采集时间超过5s,保存一次数据记录 |
| | | //保存数据记录 |
| | | DeviceDataLogService deviceDataLogService = SpringUtils.getBean(DeviceDataLogService.class); |
| | | DeviceDataLog deviceDataLog = new DeviceDataLog(); |
| | | deviceDataLog.setOriginData(JSON.toJSONString(data)); |
| | | deviceDataLog.setWcsData(JSON.toJSONString(shuttleProtocol)); |
| | | deviceDataLog.setType(String.valueOf(SlaveType.Shuttle)); |
| | | deviceDataLog.setDeviceNo(String.valueOf(shuttleProtocol.getShuttleNo())); |
| | | deviceDataLog.setCreateTime(new Date()); |
| | | deviceDataLog.setHostId(device.getHostId()); |
| | | deviceDataLogService.save(deviceDataLog); |
| | | |
| | | //更新采集时间 |
| | | shuttleProtocol.setDeviceDataLog(System.currentTimeMillis()); |
| | | } |
| | | } else { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】{1}读取四向穿梭车状态信息失败", DateUtils.convert(new Date()), device.getDeviceNo())); |
| | | throw new CoolException(MessageFormat.format("读取四向穿梭车状态信息失败 ===>> [id:{0}] [ip:{1}] [port:{2}]", device.getDeviceNo(), device.getIp(), device.getPort())); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean isRequireCharge() { |
| | | if (this.shuttleProtocol.getIdle() == null |
| | | || this.shuttleProtocol.getPakMk() == null |
| | | || this.shuttleProtocol.getErrorCode() == null |
| | | || this.shuttleProtocol.getProtocolStatus() == null |
| | | ) { |
| | | return false; |
| | | } |
| | | |
| | | boolean res = this.shuttleProtocol.getIdle() |
| | | && this.shuttleProtocol.getPakMk() |
| | | && this.shuttleProtocol.getErrorCode().equals("0") |
| | | && this.shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.IDLE.id |
| | | ; |
| | | if (!res) { |
| | | return res; |
| | | } else { |
| | | // 电量小于阈值需要进行充电 |
| | | try { |
| | | BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); |
| | | if (shuttleService == null) { |
| | | return false; |
| | | } |
| | | BasShuttle basShuttle = shuttleService.getById(this.device.getDeviceNo()); |
| | | if (basShuttle == null) { |
| | | return false; |
| | | } |
| | | Integer chargeLine = basShuttle.getChargeLine(); |
| | | if (chargeLine == null) { |
| | | return false; |
| | | } |
| | | return Integer.valueOf(this.shuttleProtocol.getBatteryPower()) < chargeLine; |
| | | } catch (Exception e) { |
| | | News.error("fail", e); |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean isCharging() { |
| | | if (this.shuttleProtocol.getDeviceStatus() == null) { |
| | | return false; |
| | | } |
| | | |
| | | if (this.shuttleProtocol.getDeviceStatus() == 5 || this.shuttleProtocol.getDeviceStatus() == 13) { |
| | | //充电中和电池均衡 =》 充电 |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public boolean isChargingCompleted() { |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public ShuttleCommand getMoveCommand(Integer taskNo, String startCodeNum, String distCodeNum, Integer allDistance, Integer runDirection, Integer runSpeed) { |
| | | HashMap<String, Object> body = new HashMap<>(); |
| | | body.put("messageName", "runOrder"); |