Browse Source

机器手臂

laoyao 3 years ago
parent
commit
7dd1d6083d

+ 83 - 38
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/impl/RobotNodeServiceImpl.java

@@ -132,45 +132,90 @@ public class RobotNodeServiceImpl implements NodeOperationService {
             map.put(DemoLineConstant.DEMOLINE_RXJQR_FLAG, "1");
             map.put("zkIp", ZK_ip_rxx);
 
-//            if(count==0){//第一步的时候锁定资源
-//                //判断机器人是否为空
-//                String jrqarr[] = {resourceAutoCode.getResourceId().toString()};
-//                List<ProductionresourcePosition> jqrList = productionresourcePositionService.getFreeProductionresourcePositionByNos(jrqarr);
-//                Map<String,List<ProductionresourcePosition>> jqrMap = jqrList.stream().collect(groupingBy(ProductionresourcePosition::getPointId));
-//
-//                TaskNode nextTaskNode = taskNodeService.getNextNTaskNode(taskNode, 1);
-//                //机器人手抓没被锁定,并且有空闲未知
-//                if (CollectionUtil.isNotEmpty(jqrList)&&jqrList.size()>1&&jqrMap.containsKey(DemoLineConstant.DEMOLINE_RJQR_ZS)) {
-//                    //满足条件--机器人空闲,设备或线边库有一个空闲
-//                    Storge startStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
-//                    map.put("Data", startStore);
-//                    map.put(DemoLineConstant.DEMOLINE_BIZ_TYPE,"moveMaterial");
-//                }
-//                map.put("result", (CollectionUtil.isNotEmpty(jqrList) )&&jqrMap.containsKey(DemoLineConstant.DEMOLINE_RJQR_ZS));
-//            }else if(count == 1){
-//                map.put(DemoLineConstant.DEMOLINE_BIZ_TYPE,"fetchMaterial");
-//                Storge currentStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
-//                map.put("fromStorge", currentStore);
-//                map.put("Data", currentStore);
-//                //出入库类型
-//                map.put(DemoLineConstant.DEMOLINE_STOCK_TYPE,DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
-//                //目的地为机器人手臂
-//                map.put("toStorge", jqrStorge);
-//                map.put("result", true);
-//            }else if(count == 2){
-//                Storge currentStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
-//                map.put(DemoLineConstant.DEMOLINE_BIZ_TYPE,"putMaterial");
-//                map.put("fromStorge", currentStore);
-//                //出入库类型
-//                map.put(DemoLineConstant.DEMOLINE_STOCK_TYPE,DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
-//                //目的地为机器人手臂
-//                Storge hcwStorge = (Storge)redisTemplate.opsForValue().get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.DEMOLINE_RJQR_HCW + taskNode.getId());
-//                map.put("Data", hcwStorge);
-//                map.put("toStorge", hcwStorge);
-//                map.put("result", true);
-//            }
-//        }
+            if (count == 0) {//第一步的时候锁定资源
+                //判断机器人是否为空
+                String jrqarr[] = {resourceAutoCode.getResourceId().toString()};
+                List<ProductionresourcePosition> jqrList = productionresourcePositionService.getFreeProductionresourcePositionByNos(jrqarr);
+                Map<String, List<ProductionresourcePosition>> jqrMap = jqrList.stream().collect(groupingBy(ProductionresourcePosition::getPointId));
+
+                TaskNode nextTaskNode = taskNodeService.getNextNTaskNode(taskNode, 1);
+                //机器人手抓没被锁定,并且有空闲未知
+                if (CollectionUtil.isNotEmpty(jqrList) && jqrList.size() > 1 && jqrMap.containsKey(DemoLineConstant.DEMOLINE_RJQR_ZS)) {
+
+                    Storge jqrStorge = storgeService.getById(jqrMap.get(DemoLineConstant.DEMOLINE_RJQR_ZS).get(0).getStorgeId());
+                    jqrStorge.setCompleteBatchNo(task.getCompleteBatchNo());
+                    storgeService.lockStorge(jqrStorge, nextTaskNode.getId());
+//                                //去掉抓手
+//                                jqrMap.remove(DemoLineConstant.DEMOLINE_RJQR_ZS);
+                    //锁定一个缓存位
+                    List<ProductionresourcePosition> hcwList = jqrMap.get(jqrMap.keySet().stream().filter(p -> !DemoLineConstant.DEMOLINE_RJQR_ZS.equals(p)).findFirst().get());
+                    Storge hcwStorge = storgeService.getById(hcwList.get(0).getStorgeId());
+                    hcwStorge.setCompleteBatchNo(task.getCompleteBatchNo());
+                    storgeService.lockStorge(hcwStorge, nextTaskNode.getId());
 
+
+                    //抓手缓存
+                    msgUtil.redis_set(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.JQR3 + nextTaskNode.getId(), jqrStorge, 1, TimeUnit.DAYS);
+                    msgUtil.redis_set(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId(), jqrStorge, 1, TimeUnit.DAYS);
+                    //缓存位缓存
+                    msgUtil.redis_set(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.DEMOLINE_RJQR_HCW + nextTaskNode.getId(), hcwStorge, 1, TimeUnit.DAYS);
+                    msgUtil.redis_set(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.DEMOLINE_RJQR_HCW + taskNode.getId(), hcwStorge, 1, TimeUnit.DAYS);
+
+                    //满足条件--机器人空闲,设备或线边库有一个空闲
+                    Storge startStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
+                    map.put("Data", startStore);
+                    map.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "moveMaterial");
+                }
+                map.put("result", (CollectionUtil.isNotEmpty(jqrList)) && jqrMap.containsKey(DemoLineConstant.DEMOLINE_RJQR_ZS));
+            } else if (count == 1) {
+                Storge jqrStorge = (Storge) msgUtil.redis_get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId());
+                map.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "fetchMaterial");
+                Storge currentStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
+                map.put("fromStorge", currentStore);
+                map.put("Data", currentStore);
+                //出入库类型
+                map.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
+                //目的地为机器人手臂
+                map.put("toStorge", jqrStorge);
+                map.put("result", true);
+            } else if (count == 2) {
+                Storge currentStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
+                map.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "putMaterial");
+                map.put("fromStorge", currentStore);
+                //出入库类型
+                map.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
+                //目的地为机器人手臂
+                Storge hcwStorge = (Storge) msgUtil.redis_get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.DEMOLINE_RJQR_HCW + taskNode.getId());
+                map.put("Data", hcwStorge);
+                map.put("toStorge", hcwStorge);
+                map.put("result", true);
+            }
+
+        } else if ("放".equals(moduleName)) {
+            //判断目标位置是否空闲
+            String target[] = {resourceAutoCode.getTargetId().toString()};
+            List<ProductionresourcePosition> targetList = productionresourcePositionService.getFreeProductionresourcePositionByNos(target);
+            List<ProductionresourcePosition> xbkList = new ArrayList<>();
+
+            if (CollectionUtil.isNotEmpty(targetList)) {//设备空闲
+                Storge targetStorge = storgeService.getById(targetList.get(0).getStorgeId());
+                //锁定加工设备库位
+                targetStorge.setCompleteBatchNo(task.getCompleteBatchNo());
+                storgeService.lockStorge(targetStorge, taskNode.getId());
+
+            } else {//设备忙碌,放置到线边库
+                //TODO,哪里的线边库
+                String znscdyXBKarr[] = {DemoLineConstant.NODE_RESOURCE_ZNSCDY_XBK};
+                xbkList = productionresourcePositionService.getFreeProductionresourcePositionByNos(znscdyXBKarr);
+                if (xbkList != null && xbkList.size() > 0) {
+                    //锁定线边库
+                    Storge xbkStorge = storgeService.getById(xbkList.get(0).getStorgeId());
+
+                    xbkStorge.setCompleteBatchNo(task.getCompleteBatchNo());
+                    storgeService.lockStorge(xbkStorge, taskNode.getId());
+//                    redisTemplate.opsForValue().set(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.NODE_RESOURCE_ZNSCDY_XBK + nextTaskNode.getId(), xbkStorge, 1, TimeUnit.DAYS);
+                }
+            }
         }
         return map;
     }