*
1
1 天以前 7cefeee8ebf28abf429c3654a0520da2469207f1
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -107,6 +107,8 @@
    private BasArmService basArmService;
    @Autowired
    private BasArmMastService basArmMastService;
    @Autowired
    private ApiLogService apiLogService;
    @Value("${wms.url}")
    private String wmsUrl;
@@ -116,7 +118,7 @@
    @Value("${inventory.number}")
    private Integer inventoryNumber;
    public Integer wrkNo = 10000;
    public Integer wrkNo = 10001;
    public static final List<Integer> LEFT_POSITION = Arrays.asList(1018,2018);
    /**
     * 组托
@@ -214,6 +216,7 @@
                        && staProtocol.isInEnable()
                        && !staProtocol.isEmptyMk()
                        && staProtocol.isPakMk()
                        && staProtocol.getWorkNo() == 0
                ) {
                    if(Cools.isEmpty(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode)) {
//                        News.error(JSON.toJSONString(staProtocol));
@@ -3432,12 +3435,15 @@
                    News.error("" + mark + " - 1" + " - 2" + " - 入库 ===>>Rgv站点在数据库不存在, 站点编号={}", rgvStn.getStaNo());
                    continue;
                }
                if((staProtocol.getWorkNo()>9999 && staProtocol2.getWorkNo()>9999) || (staProtocol.getWorkNo()<10000 && staProtocol2.getWorkNo()<10000)){
                    //当连续取货站点为相同类型时才能连续取
                    wrkMastSta3 = wrkMastStaMapper.selectByWrkNo(staProtocol2.getWorkNo());
                }
                wrkMastSta3 = wrkMastStaMapper.selectByWrkNo(staProtocol2.getWorkNo());
            }
//            if(rgvProtocol.getTaskNo2() > 9999){
//                continue;
//            }
            if(rgvProtocol.getTaskNo2() > 9999 && staProtocol.getWorkNo() < 10000){
                continue;
            }
            if (staProtocol == null) {
                News.infoNoLog("" + mark + " - 1" + " - 1" + " - Rgv入库站信息(staProtocol!=null继续执行):staProtocol=" + staProtocol);
@@ -3468,7 +3474,8 @@
                case 2: route = RouteUtils.getRouteTwo();break;
            }
            basRgvMap.setNowRoute(rgvProtocol.getRgvPosI2()); //更新小车当前位置站点号
             WrkMastSta wrkMastSta = wrkMastStaMapper.selectNoInterfere(route, route, Long.valueOf(staProtocol.getWorkNo()));//根据站点工作号和小车工作范围检索任务档
            basRgvMapService.updateById(basRgvMap);
            WrkMastSta wrkMastSta = wrkMastStaMapper.selectNoInterfere(route, route, Long.valueOf(staProtocol.getWorkNo()));//根据站点工作号和小车工作范围检索任务档
            if( null == wrkMastSta ) {
                News.infoNoLog("" + mark + " - 1" + " - 4" + " - 查询无待入库数据--wrk_sts0, 工作号={}", staProtocol.getWorkNo());
                continue;
@@ -4044,7 +4051,7 @@
    /*
     * arm任务完成自动组托
     * */
    public synchronized void armMissionAccomplished() {
    public synchronized void  armMissionAccomplished() {
        try{
            for (DevpSlave devp : slaveProperties.getDevp()) {
                // 遍历拣料入库口
@@ -4058,17 +4065,16 @@
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    String barcode = staProtocol.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
                            log.error("机械臂抓取任务完成:"+JSON.toJSON(barcode)+"===》托盘条码异常");
                            continue;
                        }
                    } else {
                        log.error("机械臂抓取任务完成:===》托盘条码为空");
                        continue;
                    }
//                    String barcode = staProtocol.getBarcode();
//                    if(!Cools.isEmpty(barcode)) {
//                        if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
//                            armTaskAssignmentCallApiLogSave(staProtocol, "托盘条码为空", staProtocol.getSiteId()+"码垛位置,===》托盘条码为空", false);
//                            continue;
//                        }
//                    } else {
//                        armTaskAssignmentCallApiLogSave(staProtocol, "托盘条码为空", staProtocol.getSiteId()+"码垛位置,===》托盘条码为空", false);
//                        continue;
//                    }
                    List<BasArm> basArmList = basArmService.selectList(new EntityWrapper<BasArm>()
                            .eq("arm_no", armSta.getArmNo())
                            .eq("sta_no_sou", armSta.getStaNo())
@@ -4088,16 +4094,17 @@
                                continue;
                            }
                            CombParam combParam = new CombParam(basArmMastList);
                            combParam.setBarcode(barcode);
                            //arm任务完成自动组托
                            ReturnT<String> result = new PostMesDataUtils().postMesData("arm任务完成自动组托",wmsUrl, wmsComb, combParam);
                            if (result.getCode()==200){
                                basArmMastService.updateArmMastStatus(basArm.getArmNo(),basArm.getSortingLineSou(),3,4);
                            } else {
                                log.error("机械臂抓取任务完成:"+JSON.toJSON(basArmMastList)+"===》自动组托失败,等待重试");
                                armTaskAssignmentCallApiLogSave(staProtocol, "自动组托失败", staProtocol.getSiteId()+"码垛位置,===》自动组托失败,等待重试", false);
//                                log.error("机械臂抓取任务完成:"+JSON.toJSON(basArmMastList)+"===》自动组托失败,等待重试");
                            }
                        }  catch (Exception e){
                            log.error("arm编号:"+basArm.getArmNo()+"====》机械臂抓取任务完成"+e.getMessage());
                            armTaskAssignmentCallApiLogSave(staProtocol, "机械臂抓取任务完成异常", staProtocol.getSiteId()+"码垛位置,===》自动组托失败,等待重试", false);
//                            log.error("arm编号:"+basArm.getArmNo()+"====》机械臂抓取任务完成"+e.getMessage());
                        }
                        break;
                    }
@@ -4131,7 +4138,6 @@
                    } else {
                        staProtocol = staProtocol.clone();
                    }
//                    if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isPakMk()) {
//                        int workNo = commonService.getWorkNo(6);//待完善
//                        // 更新站点信息 且 下发plc命令
@@ -4163,6 +4169,56 @@
                    continue;
                }
                try{
                    // 获取站点信息
                    SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, basArm.getDevpId());
                    StaProtocol staProtocol = devpThread.getStation().get(basArm.getStaNoSou());
                    if (staProtocol == null || !staProtocol.isLoading()) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    String barcode = staProtocol.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
                            armTaskAssignmentCallApiLogSave(staProtocol, "托盘条码为空", staProtocol.getSiteId()+"码垛位置,===》托盘条码为空", false);
//                            log.error(staProtocol.getSiteId()+"码垛位置,===》托盘条码为空");
                            continue;
                        }
                    } else {
                        armTaskAssignmentCallApiLogSave(staProtocol, "托盘条码为空", staProtocol.getSiteId()+"码垛位置,===》托盘条码为空", false);
//                        log.error(staProtocol.getSiteId()+"码垛位置,===》托盘条码为空");
                        continue;
                    }
                    if(barcode.length()!=6){
                        armTaskAssignmentCallApiLogSave(staProtocol, "条码长度不是6位", staProtocol.getSiteId()+"码垛位置,条码长度不是6位===>>" + barcode, false);
//                        log.error(staProtocol.getSiteId()+"码垛位置,条码长度不是6位===>>" + barcode);
                        continue;
//                        throw new CoolException(staProtocol.getSiteId()+"码垛位置,条码长度不是6位===>>" + barcode);
                    }
                    int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",barcode));
                    int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",barcode));
                    int countwait = waitPakinMapper.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet",barcode));
                    if (countLoc > 0 || countWrk > 0 || countwait > 0) {
//                        throw new CoolException("组托档/工作档/库存条码数据已存在===>>" + barcode);
                        armTaskAssignmentCallApiLogSave(staProtocol, "条码数据已存在", staProtocol.getSiteId()+"码垛位置,组托档/工作档/库存条码数据已存在===>>" + barcode, false);
//                        log.error(staProtocol.getSiteId()+"码垛位置,组托档/工作档/库存条码数据已存在===>>" + barcode);
                        continue;
                    }
                    List<BasArmMast> basArmMastListRuningBarCode = basArmMastService.selectList(
                            new EntityWrapper<BasArmMast>()
                                    .eq("barcode", barcode)
                                    .eq("status", 3)
                    );
                    if (!basArmMastListRuningBarCode.isEmpty()){
                        armTaskAssignmentCallApiLogSave(staProtocol, "条码数据已存在,正在自动组托!!!", staProtocol.getSiteId()+"码垛位置,条码数据正在自动组托===>>" + barcode, false);
                        continue;
                    }
                    List<BasArmMast> basArmMastListError = basArmMastService.selectList(
                            new EntityWrapper<BasArmMast>()
                                    .eq("arm_no", basArm.getArmNo())
@@ -4170,7 +4226,9 @@
                                    .eq("status", 9)
                    );
                    if (!basArmMastListError.isEmpty()){
                        log.error(basArm.getArmNo()+"号机械臂存在异常数据需要维护!!!");
                        armTaskAssignmentCallApiLogSave(staProtocol, "存在异常机械臂任务", basArm.getArmNo()+"号机械臂存在异常数据需要维护!!!", false);
//                        log.error(basArm.getArmNo()+"号机械臂存在异常数据需要维护!!!");
                        continue;
                    }
                    List<BasArmMast> basArmMastListRuning = basArmMastService.selectList(
@@ -4196,7 +4254,9 @@
                            continue;
                        }
                        if (basArmMastList.size()>1){
                            log.error("arm编号:"+basArm.getArmNo()+"====》拆码垛任务异常禁止下发!!!任务待执行数量大于1!!!");
                            armTaskAssignmentCallApiLogSave(staProtocol, "任务待执行数量大于1", "arm编号:"+basArm.getArmNo()+"====》拆码垛任务异常禁止下发!!!任务待执行数量大于1!!!", false);
//                            log.error("arm编号:"+basArm.getArmNo()+"====》拆码垛任务异常禁止下发!!!任务待执行数量大于1!!!");
                            continue;
                        }
                        BasArmMast basArmMast = basArmMastList.get(0);
@@ -4219,13 +4279,17 @@
//                                订单下发(SKU+订单)
                                ReturnT<String> result = new PostMesDataUtils().postMesData("机械臂抓取订单(SKU)下发:",ArmConstant.getArmUrl(basArmMast.getArmNo()), ArmConstant.ARM_ADAPTOR, armOrderAssignmentParam);
                                if (result.getCode()==200){
                                    basArmMast.setStatus(1);
                                    basArmMastService.updateById(basArmMast);
//                                    basArmMast.setStatus(1);
//                                    basArmMast.setBarcode(barcode);
//                                    basArmMastService.updateById(basArmMast);
                                } else {
                                    log.error("机械臂抓取订单(SKU)下发:"+JSON.toJSON(basArmMast)+"===》订单信息下发失败");
                                    armTaskAssignmentCallApiLogSave(staProtocol, "机械臂抓取订单(SKU)下发", "arm编号:"+basArm.getArmNo()+"订单下发订单信息下发失败!!!", false);
//                                    log.error("arm编号:"+basArm.getArmNo()+"机械臂抓取订单(SKU)下发:"+JSON.toJSON(basArmMast)+"===》订单信息下发失败");
                                }
                            } catch (Exception e){
                                log.error("机械臂抓取订单(SKU)下发:"+JSON.toJSON(basArmMast)+"===》订单下发订单信息下发失败");
                                armTaskAssignmentCallApiLogSave(staProtocol, "机械臂抓取订单(SKU)下发", "arm编号:"+basArm.getArmNo()+"订单下发订单信息下发失败!!!", false);
//                                log.error("arm编号:"+basArm.getArmNo()+"机械臂抓取订单(SKU)下发:"+JSON.toJSON(basArmMast)+"===》订单下发订单信息下发失败");
                                continue;
                            }
                        }
@@ -4234,9 +4298,11 @@
                        ReturnT<String> result = new PostMesDataUtils().postMesData("机械臂抓取任务下发:通知工作空间已就绪",ArmConstant.getArmUrl(basArmMast.getArmNo()), ArmConstant.ARM_WORKSPACE, armTaskAssignmentParam);
                        if (result.getCode()==200){
                            basArmMast.setStatus(1);
                            basArmMast.setBarcode(barcode);
                            basArmMastService.updateById(basArmMast);
                        } else {
                            log.error("机械臂抓取任务:"+JSON.toJSON(basArmMast)+"===》任务信息下发失败");
                            armTaskAssignmentCallApiLogSave(staProtocol, "机械臂抓取任务信息下发失败", "arm编号:"+basArm.getArmNo()+"任务信息下发失败!!!", false);
//                            log.error("机械臂抓取任务:"+JSON.toJSON(basArmMast)+"===》任务信息下发失败");
                        }
                    }
                }  catch (Exception e){
@@ -4248,4 +4314,26 @@
        }
    }
    public void armTaskAssignmentCallApiLogSave(StaProtocol staProtocol ,String tableName, String response, Boolean bool) {
        ApiLog apiLog = apiLogService.selectOne(new EntityWrapper<ApiLog>()
                .eq("namespace", "机械臂任务相关")
                .eq("request", "站点号:" + staProtocol.getSiteId())
                .eq("response", response)
                .eq("url", tableName)
                .eq("client_ip", staProtocol.getBarcode())
                .eq("result", 0)
                .orderBy("create_time", false)
        );
        if (!Cools.isEmpty(apiLog)){
            long parseLong = Long.parseLong(apiLog.getTimestamp());
            if (new Date().getTime()-parseLong<5*1000*60){
                return;
            }
        }
        apiLogService.save("机械臂任务相关", tableName, "null", staProtocol.getBarcode(),
                "站点号:" + staProtocol.getSiteId() ,
                response, bool);
    }
}