王佳豪
2021-06-19 0ae7027b39b0954fd462af601fdc2b5ed0f5832f
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -86,30 +86,35 @@
                }
                // 小车入库搬运命令 ----------------------------------------------------
                if (!Cools.isEmpty(param.getAgvSite())) {
                    BasAgv idleAgv = basAgvService.selectIdleAgv();
                    AgvCommand command = new AgvCommand();
                    command.setAgvId(idleAgv.getAgvId());
                    command.setInterCode(basAgvService.getAgvWorkNo());
                    command.setBeginLoc(String.valueOf(param.getAgvSite()));
                    command.setEndLoc("1088");
                    log.info(JSON.toJSONString(command));
                    String result;
                    try {
                        result = new HttpHandler.Builder()
                                .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                                .setJson(JSON.toJSONString(command))
                                .build()
                                .doPost();
                    } catch (IOException e) {
                        e.printStackTrace();
                        throw new CoolException("访问AGV接口失败");
                    // 判断是否有空闲小车
                    if (basAgvService.haveIdleAgv()) {
                        AgvCommand command = new AgvCommand();
                        command.setAgvId(0);
                        command.setInterCode(basAgvService.getAgvWorkNo());
                        command.setBeginLoc(String.valueOf(param.getAgvSite()));
                        command.setEndLoc("1088");
                        log.info(JSON.toJSONString(command));
                        String result;
                        try {
                            result = new HttpHandler.Builder()
                                    .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                                    .setJson(JSON.toJSONString(command))
                                    .build()
                                    .doPost();
                        } catch (IOException e) {
                            e.printStackTrace();
                            throw new CoolException("访问AGV接口失败");
                        }
                        AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
                        log.info(JSON.toJSONString(agvResult));
                        if (!agvResult.getResult()) {
                            log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                            throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
                        }
                    } else {
                        throw new CoolException("没有空闲小车");
                    }
                    AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
                    log.info(JSON.toJSONString(agvResult));
                    if (!agvResult.getResult()) {
                        log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                        throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
                    }
                }
            } else {
@@ -196,30 +201,35 @@
            // 小车入库搬运命令 ----------------------------------------------------
            if (!Cools.isEmpty(param.getCombMats()) && !Cools.isEmpty(param.getAgvSite())) {
                BasAgv idleAgv = basAgvService.selectIdleAgv();
                AgvCommand command = new AgvCommand();
                command.setAgvId(idleAgv.getAgvId());
                command.setInterCode(basAgvService.getAgvWorkNo());
                command.setBeginLoc(String.valueOf(param.getAgvSite()));
                command.setEndLoc("1088");
                log.info(JSON.toJSONString(command));
                String result;
                try {
                    result = new HttpHandler.Builder()
                            .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                            .setJson(JSON.toJSONString(command))
                            .build()
                            .doPost();
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new CoolException("访问AGV接口失败");
                // 判断是否有空闲小车
                if (basAgvService.haveIdleAgv()) {
                    AgvCommand command = new AgvCommand();
                    command.setAgvId(0);
                    command.setInterCode(basAgvService.getAgvWorkNo());
                    command.setBeginLoc(String.valueOf(param.getAgvSite()));
                    command.setEndLoc("1088");
                    log.info(JSON.toJSONString(command));
                    String result;
                    try {
                        result = new HttpHandler.Builder()
                                .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                                .setJson(JSON.toJSONString(command))
                                .build()
                                .doPost();
                    } catch (IOException e) {
                        e.printStackTrace();
                        throw new CoolException("访问AGV接口失败");
                    }
                    AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
                    log.info(JSON.toJSONString(agvResult));
                    if (!agvResult.getResult()) {
                        log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                        throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
                    }
                } else {
                    throw new CoolException("没有空闲小车");
                }
                AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
                log.info(JSON.toJSONString(agvResult));
                if (!agvResult.getResult()) {
                    log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                    throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
                }
            }
        }
@@ -301,30 +311,35 @@
        }
        // 小车入库搬运命令 ----------------------------------------------------
        if (!Cools.isEmpty(param.getCombMats()) && !Cools.isEmpty(param.getAgvSite())) {
            BasAgv idleAgv = basAgvService.selectIdleAgv();
            AgvCommand command = new AgvCommand();
            command.setAgvId(idleAgv.getAgvId());
            command.setInterCode(basAgvService.getAgvWorkNo());
            command.setBeginLoc(String.valueOf(param.getAgvSite()));
            command.setEndLoc("1088");
            log.info(JSON.toJSONString(command));
            String result;
            try {
                result = new HttpHandler.Builder()
                        .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                        .setJson(JSON.toJSONString(command))
                        .build()
                        .doPost();
            } catch (IOException e) {
                e.printStackTrace();
                throw new CoolException("访问AGV接口失败");
            // 判断是否有空闲小车
            if (basAgvService.haveIdleAgv()) {
                AgvCommand command = new AgvCommand();
                command.setAgvId(0);
                command.setInterCode(basAgvService.getAgvWorkNo());
                command.setBeginLoc(String.valueOf(param.getAgvSite()));
                command.setEndLoc("1088");
                log.info(JSON.toJSONString(command));
                String result;
                try {
                    result = new HttpHandler.Builder()
                            .setUri(agvUrl + "/api/interfaceTask/SendTaskByThirdParty")
                            .setJson(JSON.toJSONString(command))
                            .build()
                            .doPost();
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new CoolException("访问AGV接口失败");
                }
                AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
                log.info(JSON.toJSONString(agvResult));
                if (!agvResult.getResult()) {
                    log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                    throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
                }
            } else {
                throw new CoolException("没有空闲小车");
            }
            AgvResult agvResult = JSON.parseObject(result, AgvResult.class);
            log.info(JSON.toJSONString(agvResult));
            if (!agvResult.getResult()) {
                log.error("agv命令发送失败[agvId={}],错误信息={}", command.getAgvId(), agvResult.getExplain());
                throw new CoolException("agv命令发送失败[agvId=" + command.getAgvId() + "],错误信息=" + agvResult.getExplain());
            }
        }