| | |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.dispatcher.ShuttleDispatchUtils; |
| | | import com.zy.core.enums.*; |
| | | import com.zy.core.model.*; |
| | | import com.zy.core.model.command.*; |
| | | import com.zy.core.model.protocol.*; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.*; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | |
| | | @Service("mainService") |
| | | public class MainServiceImpl { |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private WrkMastService wrkMastService; |
| | | @Autowired |
| | |
| | | private NotifyUtils notifyUtils; |
| | | @Autowired |
| | | private BasShuttleChargeService basShuttleChargeService; |
| | | @Autowired |
| | | private DeviceConfigService deviceConfigService; |
| | | |
| | | /** |
| | | * 初始化实时地图 |
| | |
| | | */ |
| | | public synchronized void shuttleFinished() { |
| | | try { |
| | | for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { |
| | | List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Shuttle))); |
| | | for (DeviceConfig device : shuttleList) { |
| | | //获取四向穿梭车信息 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo()); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | continue; |
| | |
| | | } |
| | | |
| | | //获取提升机命令 |
| | | List<ForkLiftCommand> liftCommands = forkLiftThread.getPickAndPutCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), liftSta.getLev()); |
| | | ForkLiftCommand liftCommand = forkLiftThread.getPickAndPutCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), liftSta.getLev()); |
| | | ArrayList<ForkLiftCommand> commands = new ArrayList<>(); |
| | | commands.addAll(liftCommands); |
| | | commands.add(liftCommand); |
| | | |
| | | //提交到线程去工作 |
| | | LiftAssignCommand assignCommand = new LiftAssignCommand(); |
| | |
| | | } |
| | | |
| | | //获取提升机命令 |
| | | List<ForkLiftCommand> liftCommands = forkLiftThread.getPickAndPutCommand(wrkMast.getWrkNo(), liftSta.getLev(), wrkMast.getStaNo()); |
| | | ForkLiftCommand liftCommand = forkLiftThread.getPickAndPutCommand(wrkMast.getWrkNo(), liftSta.getLev(), wrkMast.getStaNo()); |
| | | ArrayList<ForkLiftCommand> commands = new ArrayList<>(); |
| | | commands.addAll(liftCommands); |
| | | commands.add(liftCommand); |
| | | |
| | | //提交到线程去工作 |
| | | LiftAssignCommand assignCommand = new LiftAssignCommand(); |
| | |
| | | */ |
| | | public synchronized void forkLiftFinished() { |
| | | try { |
| | | for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) { |
| | | List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.ForkLift))); |
| | | for (DeviceConfig device : forkliftList) { |
| | | //获取提升机信息 |
| | | ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, forkLiftSlave.getId()); |
| | | ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo()); |
| | | if(forkLiftThread == null) { |
| | | continue; |
| | | } |
| | | ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus(); |
| | | if (forkLiftProtocol == null) { |
| | | continue; |
| | |
| | | */ |
| | | private void recShuttleErr() { |
| | | Date now = new Date(); |
| | | for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) { |
| | | List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Shuttle))); |
| | | for (DeviceConfig device : shuttleList) { |
| | | // 获取四向穿梭车信息 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId()); |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo()); |
| | | if (shuttleThread == null) { |
| | | continue; |
| | | } |
| | |
| | | |
| | | if (shuttleProtocol.getTaskNo() != 0) { |
| | | //有任务 |
| | | BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(shuttleSlave.getId(), shuttleProtocol.getTaskNo()); |
| | | BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(device.getDeviceNo(), shuttleProtocol.getTaskNo()); |
| | | // 有异常 |
| | | if (latest == null) { |
| | | if (shuttleProtocol.getErrorCode() != null && Integer.parseInt(shuttleProtocol.getErrorCode()) != 0) { |
| | |
| | | null, // 结束时间 |
| | | wrkMast.getWrkSts(), // 工作状态 |
| | | wrkMast.getIoType(), // 入出库类型 |
| | | shuttleSlave.getId(), // 四向穿梭车 |
| | | device.getDeviceNo(), // 四向穿梭车 |
| | | null, // plc |
| | | wrkMast.getLocNo(), // 目标库位 |
| | | wrkMast.getStaNo(), // 目标站 |
| | |
| | | JSON.toJSONString(shuttleProtocol) // 系统状态数据 |
| | | ); |
| | | if (!basShuttleErrLogService.insert(basShuttleErrLog)) { |
| | | News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName); |
| | | News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", device.getDeviceNo(), errName); |
| | | } |
| | | } |
| | | } else { |
| | |
| | | latest.setUpdateTime(now); |
| | | latest.setStatus(2); |
| | | if (!basShuttleErrLogService.updateById(latest)) { |
| | | News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId()); |
| | | News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", device.getDeviceNo(), latest.getId()); |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | private void recLiftErr() { |
| | | Date now = new Date(); |
| | | for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) { |
| | | List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.ForkLift))); |
| | | for (DeviceConfig device : forkliftList) { |
| | | // 获取提升机信息 |
| | | ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, forkLiftSlave.getId()); |
| | | ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo()); |
| | | if (forkLiftThread == null) { |
| | | continue; |
| | | } |
| | |
| | | |
| | | if (forkLiftProtocol.getTaskNo() != 0) { |
| | | //有任务 |
| | | BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(forkLiftSlave.getId(), forkLiftProtocol.getTaskNo()); |
| | | BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(device.getDeviceNo(), forkLiftProtocol.getTaskNo()); |
| | | // 有异常 |
| | | if (latest == null) { |
| | | if (forkLiftProtocol.getErrorCode() != null && forkLiftProtocol.getErrorCode() != 0) { |
| | |
| | | null, // 结束时间 |
| | | wrkMast.getWrkSts(), // 工作状态 |
| | | wrkMast.getIoType(), // 入出库类型 |
| | | forkLiftSlave.getId(), // 提升机 |
| | | device.getDeviceNo(), // 提升机 |
| | | null, // plc |
| | | wrkMast.getLocNo(), // 目标库位 |
| | | wrkMast.getStaNo(), // 目标站 |
| | |
| | | JSON.toJSONString(forkLiftProtocol) // 系统状态数据 |
| | | ); |
| | | if (!basLiftErrLogService.insert(basLiftErrLog)) { |
| | | News.error("提升机plc异常记录失败 ===>> [id:{}] [error:{}]", forkLiftSlave.getId(), errName); |
| | | News.error("提升机plc异常记录失败 ===>> [id:{}] [error:{}]", device.getDeviceNo(), errName); |
| | | } |
| | | } |
| | | } else { |
| | |
| | | latest.setUpdateTime(now); |
| | | latest.setStatus(2); |
| | | if (!basLiftErrLogService.updateById(latest)) { |
| | | News.error("提升机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", forkLiftSlave.getId(), latest.getId()); |
| | | News.error("提升机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", device.getDeviceNo(), latest.getId()); |
| | | } |
| | | } |
| | | } |
| | |
| | | return;//无充电桩 |
| | | } |
| | | |
| | | for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { |
| | | List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Shuttle))); |
| | | for (DeviceConfig device : shuttleList) { |
| | | //获取四向穿梭车线程 |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); |
| | | ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo()); |
| | | ShuttleProtocol shuttleProtocol = shuttleThread.getStatus(); |
| | | if (shuttleProtocol == null) { |
| | | continue; |
| | |
| | | wrkMast.setIoType(WrkIoType.SHUTTLE_CHARGE.id);//300.充电 |
| | | wrkMast.setIoPri((double) 999); |
| | | wrkMast.setLocNo(chargeLocNo); |
| | | wrkMast.setShuttleNo(shuttle.getId()); |
| | | wrkMast.setShuttleNo(device.getDeviceNo()); |
| | | wrkMast.setMemo("charge"); |
| | | wrkMast.setAppeTime(new Date()); |
| | | if (!wrkMastService.insert(wrkMast)) { |
| | | News.error("保存{}号四向穿梭车充电任务失败!!!", shuttle.getId()); |
| | | News.error("保存{}号四向穿梭车充电任务失败!!!", device.getDeviceNo()); |
| | | continue; |
| | | } |
| | | |
| | | News.info("保存{}号四向穿梭车充电任务成功!!!", shuttle.getId()); |
| | | News.info("保存{}号四向穿梭车充电任务成功!!!", device.getDeviceNo()); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | public synchronized void executeShuttleCharge() { |
| | | try { |
| | | //查询小车充电任务 |
| | | for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { |
| | | WrkMast wrkMast = wrkMastService.selectChargeWorking(shuttle.getId()); |
| | | List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | .eq("device_type", String.valueOf(SlaveType.Shuttle))); |
| | | for (DeviceConfig device : shuttleList) { |
| | | WrkMast wrkMast = wrkMastService.selectChargeWorking(device.getDeviceNo()); |
| | | if(wrkMast == null) { |
| | | continue; |
| | | } |
| | |
| | | } |
| | | |
| | | //获取提升机命令 |
| | | List<ForkLiftCommand> liftCommands = forkLiftThread.getShuttleSwitchCommand(wrkMast.getWrkNo(), sourceLiftSta.getLev(), liftSta.getLev()); |
| | | ForkLiftCommand liftCommand = forkLiftThread.getShuttleSwitchCommand(wrkMast.getWrkNo(), sourceLiftSta.getLev(), liftSta.getLev()); |
| | | ArrayList<ForkLiftCommand> commands = new ArrayList<>(); |
| | | commands.addAll(liftCommands); |
| | | commands.add(liftCommand); |
| | | |
| | | //提交到线程去工作 |
| | | LiftAssignCommand assignCommand = new LiftAssignCommand(); |
| | |
| | | |
| | | //自动切换出入库模式 |
| | | public void autoSwitchForkLiftIOMode() { |
| | | for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) { |
| | | Integer liftNo = forkLiftSlave.getId(); |
| | | ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo); |
| | | if (forkLiftThread == null) { |
| | | continue; |
| | | } |
| | | ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus(); |
| | | if (forkLiftProtocol == null) { |
| | | continue; |
| | | } |
| | | |
| | | List<Integer> liftAllStaNo = ForkLiftUtils.getLiftAllStaNo(liftNo); |
| | | if (liftAllStaNo.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | List<Integer> conveyorBindLiftAllStaNo = ForkLiftUtils.getConveyorBindLiftAllStaNo(liftNo); |
| | | if (conveyorBindLiftAllStaNo.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | //获取入库任务 |
| | | List<WrkMast> inWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() |
| | | .in("sta_no", liftAllStaNo) |
| | | .in("wrk_sts" |
| | | , WrkStsType.NEW_INBOUND.sts |
| | | , WrkStsType.INBOUND_DEVICE_RUN.sts |
| | | , WrkStsType.INBOUND_LIFT_RUN.sts |
| | | , WrkStsType.INBOUND_LIFT_RUN_COMPLETE.sts |
| | | , WrkStsType.INBOUND_SHUTTLE_RUN.sts |
| | | , WrkStsType.INBOUND_SHUTTLE_RUN_COMPLETE.sts |
| | | )); |
| | | |
| | | //获取出库任务 |
| | | List<WrkMast> outWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() |
| | | .in("sta_no", conveyorBindLiftAllStaNo) |
| | | .in("wrk_sts" |
| | | , WrkStsType.NEW_OUTBOUND.sts |
| | | , WrkStsType.OUTBOUND_SHUTTLE_RUN.sts |
| | | , WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts |
| | | , WrkStsType.OUTBOUND_LIFT_RUN.sts |
| | | , WrkStsType.OUTBOUND_LIFT_RUN_COMPLETE.sts |
| | | )); |
| | | |
| | | if (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.NONE)) { |
| | | //未知模式 |
| | | if (!inWrkMasts.isEmpty()) { |
| | | forkLiftThread.switchIOMode(ForkLiftIoModeType.IN); |
| | | } else if (!outWrkMasts.isEmpty()) { |
| | | forkLiftThread.switchIOMode(ForkLiftIoModeType.OUT); |
| | | }else { |
| | | forkLiftThread.switchIOMode(ForkLiftIoModeType.IN); |
| | | } |
| | | } else if (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.IN)) { |
| | | //入库模式 |
| | | if (inWrkMasts.isEmpty() && !outWrkMasts.isEmpty()) { |
| | | forkLiftThread.switchIOMode(ForkLiftIoModeType.OUT); |
| | | } |
| | | } else if (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.OUT)) { |
| | | //出库模式 |
| | | if (outWrkMasts.isEmpty() && !inWrkMasts.isEmpty()) { |
| | | forkLiftThread.switchIOMode(ForkLiftIoModeType.IN); |
| | | } |
| | | } |
| | | } |
| | | // List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>() |
| | | // .eq("device_type", String.valueOf(SlaveType.ForkLift))); |
| | | // for (DeviceConfig device : forkliftList) { |
| | | // Integer liftNo = device.getDeviceNo(); |
| | | // ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo); |
| | | // if (forkLiftThread == null) { |
| | | // continue; |
| | | // } |
| | | // ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus(); |
| | | // if (forkLiftProtocol == null) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // List<Integer> liftAllStaNo = ForkLiftUtils.getLiftAllStaNo(liftNo); |
| | | // if (liftAllStaNo.isEmpty()) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // List<Integer> conveyorBindLiftAllStaNo = ForkLiftUtils.getConveyorBindLiftAllStaNo(liftNo); |
| | | // if (conveyorBindLiftAllStaNo.isEmpty()) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // //获取入库任务 |
| | | // List<WrkMast> inWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() |
| | | // .in("sta_no", liftAllStaNo) |
| | | // .in("wrk_sts" |
| | | // , WrkStsType.NEW_INBOUND.sts |
| | | // , WrkStsType.INBOUND_DEVICE_RUN.sts |
| | | // , WrkStsType.INBOUND_LIFT_RUN.sts |
| | | // , WrkStsType.INBOUND_LIFT_RUN_COMPLETE.sts |
| | | // , WrkStsType.INBOUND_SHUTTLE_RUN.sts |
| | | // , WrkStsType.INBOUND_SHUTTLE_RUN_COMPLETE.sts |
| | | // )); |
| | | // |
| | | // //获取出库任务 |
| | | // List<WrkMast> outWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() |
| | | // .in("sta_no", conveyorBindLiftAllStaNo) |
| | | // .in("wrk_sts" |
| | | // , WrkStsType.NEW_OUTBOUND.sts |
| | | // , WrkStsType.OUTBOUND_SHUTTLE_RUN.sts |
| | | // , WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts |
| | | // , WrkStsType.OUTBOUND_LIFT_RUN.sts |
| | | // , WrkStsType.OUTBOUND_LIFT_RUN_COMPLETE.sts |
| | | // )); |
| | | // |
| | | // if (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.NONE)) { |
| | | // //未知模式 |
| | | // if (!inWrkMasts.isEmpty()) { |
| | | // forkLiftThread.switchIOMode(ForkLiftIoModeType.IN); |
| | | // } else if (!outWrkMasts.isEmpty()) { |
| | | // forkLiftThread.switchIOMode(ForkLiftIoModeType.OUT); |
| | | // }else { |
| | | // forkLiftThread.switchIOMode(ForkLiftIoModeType.IN); |
| | | // } |
| | | // } else if (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.IN)) { |
| | | // //入库模式 |
| | | // if (inWrkMasts.isEmpty() && !outWrkMasts.isEmpty()) { |
| | | // forkLiftThread.switchIOMode(ForkLiftIoModeType.OUT); |
| | | // } |
| | | // } else if (forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.OUT)) { |
| | | // //出库模式 |
| | | // if (outWrkMasts.isEmpty() && !inWrkMasts.isEmpty()) { |
| | | // forkLiftThread.switchIOMode(ForkLiftIoModeType.IN); |
| | | // } |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | //出库任务预调度提升机 |
| | |
| | | int workNo = commonService.getWorkNo(WrkIoType.FORKLIFT_MOVE.id);//获取任务号 |
| | | |
| | | //获取提升机命令 |
| | | List<ForkLiftCommand> liftCommand = forkLiftThread.getMoveCommand(workNo, forkLiftProtocol.getLev(), Utils.getLev(wrkMast.getSourceLocNo())); |
| | | ForkLiftCommand liftCommand = forkLiftThread.getMoveCommand(workNo, forkLiftProtocol.getLev(), Utils.getLev(wrkMast.getSourceLocNo())); |
| | | ArrayList<ForkLiftCommand> commands = new ArrayList<>(); |
| | | commands.addAll(liftCommand); |
| | | commands.add(liftCommand); |
| | | |
| | | //提交到线程去工作 |
| | | LiftAssignCommand assignCommand = new LiftAssignCommand(); |