| | |
| | | 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; |
| | |
| | | //----------读取四向穿梭车状态----------- |
| | | //小车设备状态 |
| | | 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.setPakMk(true); |
| | | } |
| | | |
| | | // if (shuttleProtocol.getProtocolStatusType() == null && shuttleProtocol.getDeviceStatus().intValue() == ShuttleDeviceStatusType.IDLE.id) { |
| | | // //小车空闲状态、小车任务状态为未知,认定曾离线过,需要复位成空闲 |
| | | // shuttleProtocol.setProtocolStatusType(ShuttleProtocolStatusType.IDLE); |
| | | // } |
| | | if (shuttleProtocol.getProtocolStatusType() == null && shuttleProtocol.getDeviceStatus().intValue() == 3) { |
| | | //小车空闲状态、小车任务状态为未知,认定曾离线过,需要复位成空闲 |
| | | shuttleProtocol.setProtocolStatusType(ShuttleProtocolStatusType.IDLE); |
| | | } |
| | | |
| | | if (System.currentTimeMillis() - shuttleProtocol.getDeviceDataLog() > 1000 * 5) { |
| | | //采集时间超过5s,保存一次数据记录 |
| | |
| | | |
| | | //更新采集时间 |
| | | shuttleProtocol.setDeviceDataLog(System.currentTimeMillis()); |
| | | } |
| | | |
| | | //将四向穿梭车状态保存至数据库 |
| | | BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class); |
| | | BasShuttle basShuttle = shuttleService.getOne(new LambdaQueryWrapper<BasShuttle>() |
| | | .eq(BasShuttle::getShuttleNo, device.getDeviceNo()) |
| | | .eq(BasShuttle::getHostId, device.getHostId())); |
| | | if (basShuttle == null) { |
| | | basShuttle = new BasShuttle(); |
| | | //四向穿梭车号 |
| | | basShuttle.setShuttleNo(Integer.valueOf(device.getDeviceNo())); |
| | | basShuttle.setHostId(device.getHostId()); |
| | | shuttleService.save(basShuttle); |
| | | } |
| | | //任务号 |
| | | basShuttle.setTaskNo(shuttleProtocol.getTaskNo().intValue()); |
| | | //修改时间 |
| | | basShuttle.setUpdateTime(new Date()); |
| | | //设备状态 |
| | | basShuttle.setProtocol(JSON.toJSONString(shuttleProtocol)); |
| | | if (shuttleService.updateById(basShuttle)) { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】[id:{1}] <<<<< 实时数据更新成功",DateUtils.convert(new Date()), device.getDeviceNo())); |
| | | } |
| | | } else { |
| | | OutputQueue.SHUTTLE.offer(MessageFormat.format("【{0}】{1}读取四向穿梭车状态信息失败", DateUtils.convert(new Date()), device.getDeviceNo())); |
| | |
| | | } |
| | | |
| | | @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"); |