Junjie
2023-04-14 f57741a11f0cce1f7ac0f2c8ab0627c046cb855b
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -68,6 +68,10 @@
    @Autowired
    private BasSteErrLogService basSteErrLogService;
    @Autowired
    private BasShuttleErrLogService basShuttleErrLogService;
    @Autowired
    private BasShuttleErrService basShuttleErrService;
    @Autowired
    private BasCrnErrorMapper basCrnErrorMapper;
    @Autowired
    private BasSteService basSteService;
@@ -793,6 +797,20 @@
                                //同一层直接取货无需经过提升机
                                //直接计算车到提升机取货再到库位路径指令
                                List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftLocNo, locNo);
                                if (wrkMast.getWrkSts() == 8) {
                                    //此时车在提升机内部,需要多下达一步指令让车移动到提升机口
                                    BasDevp basDevp = basDevpService.selectById(109);//获取提升机信息
                                    ShuttleCommand moveCommand = new ShuttleCommand();
                                    moveCommand.setCommandWord((short) 1);
                                    moveCommand.setStartCodeNum(Short.parseShort(basDevp.getQrCodeValue()));//提升机内部二维码
                                    moveCommand.setDistCodeNum(commands.get(0).getStartCodeNum());//提升机口二维码
                                    moveCommand.setStartToDistDistance(1300);
                                    moveCommand.setMiddleToDistDistance(0);
                                    moveCommand.setRunDirection(commands.get(0).getRunDirection());
                                    moveCommand.setRunSpeed((short) 1000);
                                    moveCommand.setCommandEnd((short) 1);
                                    commands.add(0, moveCommand);//将该指令添加到队头
                                }
                                assignCommand.setCommands(commands);
                                //分配目标库位
                                shuttleProtocol.setLocNo(wrkMast.getLocNo());
@@ -847,14 +865,22 @@
            ShuttleCommand command = new ShuttleCommand();
            command.setCommandWord((short) 1);
            command.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY()));
            command.setMiddleCodeNum((short) 0);
            command.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY()));
            //通过xy坐标小车二维码
            Short startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());
            command.setStartCodeNum(startCodeNum);
            command.setMiddleCodeNum((short) 1);
            //通过xy坐标小车二维码
            Short distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());
            command.setDistCodeNum(distCodeNum);
            command.setStartToDistDistance(allDistance);
            command.setMiddleToDistDistance(1000);
            command.setMiddleToDistDistance(0);
            command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
            command.setPalletLift((short) 1);
            command.setForceMoveDistance(1000);
            command.setForceMoveDistance(0);
            command.setChargeSwitch((short) 2);
            command.setIOControl((short) 0);
            command.setRunSpeed((short) 1000);
@@ -886,14 +912,22 @@
            ShuttleCommand command = new ShuttleCommand();
            command.setCommandWord((short) 1);
            command.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY()));
            command.setMiddleCodeNum((short) 0);
            command.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY()));
            //通过xy坐标小车二维码
            Short startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());
            command.setStartCodeNum(startCodeNum);
            command.setMiddleCodeNum((short) 1);
            //通过xy坐标小车二维码
            Short distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());
            command.setDistCodeNum(distCodeNum);
            command.setStartToDistDistance(allDistance);
            command.setMiddleToDistDistance(1000);
            command.setMiddleToDistDistance(0);
            command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
            command.setPalletLift((short) 1);
            command.setForceMoveDistance(1000);
            command.setForceMoveDistance(0);
            command.setChargeSwitch((short) 2);
            command.setIOControl((short) 0);
            command.setRunSpeed((short) 1000);
@@ -926,14 +960,22 @@
            command = new ShuttleCommand();
            command.setCommandWord((short) 1);
            command.setStartCodeNum(NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY()));
            command.setMiddleCodeNum((short) 0);
            command.setDistCodeNum(NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY()));
            //通过xy坐标小车二维码
            Short startCodeNum = NavigatePositionConvert.xyToPosition(startPath.getX(), startPath.getY(), startPath.getZ());
            command.setStartCodeNum(startCodeNum);
            command.setMiddleCodeNum((short) 1);
            //通过xy坐标小车二维码
            Short distCodeNum = NavigatePositionConvert.xyToPosition(endPath.getX(), endPath.getY(), endPath.getZ());
            command.setDistCodeNum(distCodeNum);
            command.setStartToDistDistance(allDistance);
            command.setMiddleToDistDistance(1000);
            command.setMiddleToDistDistance(0);
            command.setRunDirection(ShuttleRunDirection.get(startPath.getDirection()).id);
            command.setPalletLift((short) 1);
            command.setForceMoveDistance(1000);
            command.setForceMoveDistance(0);
            command.setChargeSwitch((short) 2);
            command.setIOControl((short) 0);
            command.setRunSpeed((short) 1000);
@@ -1052,6 +1094,19 @@
                        }
                    } else if (wrkMast.getWrkSts() == 25) {
                        List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, wrkMast.getSourceLocNo(), liftLocNo);
                        //此时车在提升机内部,需要多下达一步指令让车移动到提升机口
                        BasDevp basDevp = basDevpService.selectById(109);//获取提升机信息
                        ShuttleCommand moveCommand = new ShuttleCommand();
                        moveCommand.setCommandWord((short) 1);//小车移动指令字
                        moveCommand.setStartCodeNum(Short.parseShort(basDevp.getQrCodeValue()));//提升机二维码
                        moveCommand.setDistCodeNum(commands.get(0).getStartCodeNum());
                        moveCommand.setStartToDistDistance(1300);
                        moveCommand.setMiddleToDistDistance(0);
                        moveCommand.setRunDirection(commands.get(0).getRunDirection());
                        moveCommand.setRunSpeed((short) 1000);
                        moveCommand.setCommandEnd((short) 1);
                        commands.add(0, moveCommand);//将该指令添加到队头
                        //分配目标库位
                        shuttleProtocol.setLocNo(wrkMast.getSourceLocNo());
                        //目标库位
@@ -2918,10 +2973,129 @@
     */
    public void recErr() {
        try {
            this.recShuttleErr();
            this.recCrnErr();
            this.recSteErr();
        } catch (Exception e) {
            News.error("recErr fail", e);
        }
    }
    /**
     * 四向穿梭车异常信息记录
     */
    private void recShuttleErr() {
        Date now = new Date();
        for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) {
            // 获取堆垛机信息
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId());
            if (shuttleThread == null) {
                continue;
            }
            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                continue;
            }
            if (shuttleProtocol.getTaskNo() != 0) {
                //有任务
                BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(shuttleSlave.getId(), shuttleProtocol.getTaskNo().intValue());
                // 有异常
                if (latest == null) {
                    if (shuttleProtocol.getStatusErrorCode() != null && shuttleProtocol.getStatusErrorCode() > 0) {
                        WrkMast wrkMast = wrkMastMapper.selectById(shuttleProtocol.getTaskNo());
                        if (wrkMast == null) {
                            continue;
                        }
                        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getStatusErrorCode().intValue());
                        String errName = basShuttleErr==null? "未知异常":basShuttleErr.getErrName();
                        BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog(
                                null,    // 编号
                                wrkMast.getWrkNo(),    // 工作号
                                now,    // 发生时间
                                null,    // 结束时间
                                wrkMast.getWrkSts(),    // 工作状态
                                wrkMast.getIoType(),    // 入出库类型
                                shuttleSlave.getId(),    // 四向穿梭车
                                null,    // plc
                                wrkMast.getLocNo(),    // 目标库位
                                wrkMast.getStaNo(),    // 目标站
                                wrkMast.getSourceStaNo(),    // 源站
                                wrkMast.getSourceLocNo(),    // 源库位
                                wrkMast.getBarcode(),    // 条码
                                (int) shuttleProtocol.getStatusErrorCode(),    // 异常码
                                errName,    // 异常
                                1,    // 异常情况
                                now,    // 添加时间
                                null,    // 添加人员
                                now,    // 修改时间
                                null,    // 修改人员
                                "任务中异常"    // 备注
                        );
                        if (!basShuttleErrLogService.insert(basShuttleErrLog)) {
                            News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName);
                        }
                    }
                } else {
                    // 异常修复
                    if (shuttleProtocol.getStatusErrorCode() == null || shuttleProtocol.getStatusErrorCode() == 0) {
                        latest.setEndTime(now);
                        latest.setUpdateTime(now);
                        latest.setStatus(2);
                        if (!basShuttleErrLogService.updateById(latest)) {
                            News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId());
                        }
                    }
                }
            }else {
                //无任务
                BasShuttleErrLog latest = basShuttleErrLogService.findLatest(shuttleSlave.getId());
                // 有异常
                if (shuttleProtocol.getStatusErrorCode() != null && shuttleProtocol.getStatusErrorCode() > 0) {
                    // 记录新异常
                    if (latest == null || (latest.getErrCode() != shuttleProtocol.getStatusErrorCode().intValue())) {
                        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getStatusErrorCode().intValue());
                        String errName = basShuttleErr==null? "未知异常":basShuttleErr.getErrName();
                        BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog(
                                null,    // 编号
                                null,    // 工作号
                                now,    // 发生时间
                                null,    // 结束时间
                                null,    // 工作状态
                                null,    // 入出库类型
                                shuttleSlave.getId(),    // 四向穿梭车
                                null,    // plc
                                null,    // 目标库位
                                null,    // 目标站
                                null,    // 源站
                                null,    // 源库位
                                null,    // 条码
                                (int)shuttleProtocol.getStatusErrorCode(),    // 异常码
                                errName,    // 异常
                                1,    // 异常情况
                                now,    // 添加时间
                                null,    // 添加人员
                                now,    // 修改时间
                                null,    // 修改人员
                                "无任务异常"    // 备注
                        );
                        if (!basShuttleErrLogService.insert(basShuttleErrLog)) {
                            News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName);
                        }
                    }
                    // 无异常
                } else {
                    // 异常修复
                    if (latest != null && latest.getStatus() == 1) {
                        latest.setEndTime(now);
                        latest.setUpdateTime(now);
                        latest.setStatus(2);
                        if (!basShuttleErrLogService.updateById(latest)) {
                            News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId());
                        }
                    }
                }
            }
        }
    }
@@ -3643,8 +3817,8 @@
        } else if (wrkCharge.getWrkSts() == 56) {
            //充电中
            //判断小车是否充满电量
            if (shuttleProtocol.getBatteryPower() == 1000) {
            //判断小车是否充满电量,满电1000或电压54V以上
            if (shuttleProtocol.getBatteryPower() >= 1000 || shuttleProtocol.getCurrentVoltage() >= 540) {
                //充满,断开充电
                List<ShuttleCommand> commands = new ArrayList<>();
                ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();