zyx
2024-01-31 ca8f5a8f133e7f5b00b9d35ff6d15720804569af
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -96,20 +96,20 @@
        try {
        // 根据输送线plc遍历
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历入库口
            for (DevpSlave.Sta inSta : devp.getInSta()) {
                // 获取入库站信息
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
                if (staProtocol == null) {
                    continue;
                } else {
                    staProtocol = staProtocol.clone();
                }
                Short workNo = staProtocol.getWorkNo();
                Short stano = staProtocol.getStaNo();
            // 根据输送线plc遍历
            for (DevpSlave devp : slaveProperties.getDevp()) {
                // 遍历入库口
                for (DevpSlave.Sta inSta : devp.getInSta()) {
                    // 获取入库站信息
                    DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    Short workNo = staProtocol.getWorkNo();
                    Short stano = staProtocol.getStaNo();
@@ -167,59 +167,59 @@
                        }
                        continue;
                    }
                // 判断是否满足入库条件
                if (staProtocol.isAutoing() && staProtocol.isLoading()
                        && staProtocol.isInEnable()
                        && !staProtocol.isEmptyMk() && (workNo >= 0)
                        && staProtocol.isPakMk()) {
                    // 获取条码扫描仪信息
                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
                    if (barcodeThread == null) {
                        continue;
                    }
                    String barcode = barcodeThread.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        // 请求wms接口,获取工作号和目标库位
                        ToWmsDTO toWmsDTO = new ToWmsDTO(barcode,staProtocol.getSiteId());
                        String response;
                        response = new HttpHandler.Builder()
                                .setHeaders(null)
                                .setUri(wmsUrl)
                                .setPath(inboundTaskApplyPath)
                                .setJson(JSON.toJSONString(toWmsDTO))
                                .build()
                                .doPost();
                        JSONObject jsonObject = JSON.parseObject(response);
                        apiLogService.save("wms请求入库货位接口"
                                ,wmsUrl+inboundTaskApplyPath
                                ,null
                                ,"127.0.0.1"
                                ,JSON.toJSONString(toWmsDTO)
                                ,response
                                ,true
                        );
                        if (jsonObject.getInteger("code").equals(200) && !Cools.isEmpty(jsonObject.get("data").toString())) {
                            GetWmsDto getWmsDto = JSON.parseObject(jsonObject.get("data").toString(), GetWmsDto.class);
                            // 创新一个入库工作档
                            TaskWrk taskWrk = taskWrkService.selectByTaskNo(getWmsDto.getTaskNo());
                            if(Cools.isEmpty(taskWrk)) {
                                taskWrk = createTask(getWmsDto,staProtocol.getStaNo().intValue());
                                if (Cools.isEmpty(taskWrk)){
                                    log.error("库位异常,库位号:{}", getWmsDto.getTargetLocationCode());
                                }else {
                                    taskWrkService.insert(taskWrk);
                                    StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>()
                                            .eq("crn_no", taskWrk.getCrnNo()).eq("type_no",1).eq("stn_no",staProtocol.getStaNo().intValue()));
                                    staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue());
                                    staProtocol.setStaNo(staDesc.getCrnStn().shortValue());
                                    MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                                }
                            }
                        }else {
                    // 判断是否满足入库条件
                    if (staProtocol.isAutoing() && staProtocol.isLoading()
                            && staProtocol.isInEnable()
                            && !staProtocol.isEmptyMk() && (workNo >= 0)
                            && staProtocol.isPakMk()) {
                        // 获取条码扫描仪信息
                        BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
                        if (barcodeThread == null) {
                            continue;
                        }
                        String barcode = barcodeThread.getBarcode();
                        if(!Cools.isEmpty(barcode)) {
                            // 请求wms接口,获取工作号和目标库位
                            ToWmsDTO toWmsDTO = new ToWmsDTO(barcode,staProtocol.getSiteId());
                            String response;
                            response = new HttpHandler.Builder()
                                    .setHeaders(null)
                                    .setUri(wmsUrl)
                                    .setPath(inboundTaskApplyPath)
                                    .setJson(JSON.toJSONString(toWmsDTO))
                                    .build()
                                    .doPost();
                            JSONObject jsonObject = JSON.parseObject(response);
                            apiLogService.save("wms请求入库货位接口"
                                    ,wmsUrl+inboundTaskApplyPath
                                    ,null
                                    ,"127.0.0.1"
                                    ,JSON.toJSONString(toWmsDTO)
                                    ,response
                                    ,true
                            );
                            if (jsonObject.getInteger("code").equals(200) && !Cools.isEmpty(jsonObject.get("data").toString())) {
                                GetWmsDto getWmsDto = JSON.parseObject(jsonObject.get("data").toString(), GetWmsDto.class);
                                // 创新一个入库工作档
                                TaskWrk taskWrk = taskWrkService.selectByTaskNo(getWmsDto.getTaskNo());
                                if(Cools.isEmpty(taskWrk)) {
                                    taskWrk = createTask(getWmsDto,staProtocol.getStaNo().intValue());
                                    if (Cools.isEmpty(taskWrk)){
                                        log.error("库位异常,库位号:{}", getWmsDto.getTargetLocationCode());
                                    }else {
                                        taskWrkService.insert(taskWrk);
                                        StaDesc staDesc = staDescService.selectOne(new EntityWrapper<StaDesc>()
                                                .eq("crn_no", taskWrk.getCrnNo()).eq("type_no",1).eq("stn_no",staProtocol.getStaNo().intValue()));
                                        staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue());
                                        staProtocol.setStaNo(staDesc.getCrnStn().shortValue());
                                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                                    }
                                }
                            }else {
                                continue;
                            }
//                        StaDescService staDescService = SpringUtils.getBean(StaDescService.class);
//
@@ -294,12 +294,12 @@
//                            }
//                        }
                        }
                    }
                }
            }
        }
        } catch (Exception e) {
            log.error("generateStoreWrkFile e", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -522,7 +522,7 @@
                }
            }
           // return;
            // return;
        }
    }
@@ -935,7 +935,7 @@
                            }
                        }
                    }
                // 无任务
                    // 无任务
                } else {
                    BasErrLog latest = basErrLogService.findLatest(crn.getId());
                    // 有异常
@@ -971,7 +971,7 @@
                                log.error("堆垛机plc异常记录失败 ===>> [id:{}] [error:{}]", crn.getId(), errName);
                            }
                        }
                    // 无异常
                        // 无异常
                    } else {
                        // 异常修复
                        if (latest != null && latest.getStatus() == 1) {