姚云青 3 سال پیش
والد
کامیت
b6fabf57f1

+ 9 - 2
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/DemoLine/DemoLineConstant.java

@@ -36,10 +36,17 @@ public interface DemoLineConstant {
     //缓存位
     String DEMOLINE_RJQR_HCW = "DEMOLINE_RJQR_HCW";
     //柔性机器人的三个点位
-    String DEMOLINE_RJQR_ZS = "0";
-    String DEMOLINE_RJQR_KW1 = "124";
+    String DEMOLINE_RJQR_ZS = "124";
+    String DEMOLINE_RJQR_KW1 = "126";
     String DEMOLINE_RJQR_KW2 = "125";
 
+    //云箭目标库位
+    String YUNJIAN_TARGET_STORE = "YUNJIAN_TARGET_STORE";
+
+
+    //柔性机器人的三个点位
+    String YUJIAN_SFTJ_ = "371";
+
     //上下料站
     String SXLZ ="sxlz";
 

+ 2 - 1
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/edgeLibrary/service/StorgeService.java

@@ -10,6 +10,7 @@ import com.github.zuihou.business.edgeLibrary.entity.Storge;
 import com.github.zuihou.business.edgeLibrary.entity.StorgeType;
 import com.github.zuihou.business.operationManagementCenter.entity.TTask;
 import com.github.zuihou.business.productionResourceCenter.entity.Tool;
+import com.github.zuihou.business.productionResourceCenter.entity.ZZone;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
 
 import java.util.List;
@@ -83,7 +84,7 @@ public interface StorgeService extends SuperCacheService<Storge> {
 
     void setValidTray(Map map);
 
-    Map getPlateStorgeByNo(String noArr[],String completeBatchNo);
+    Map getPlateStorgeByNo(ZZone zZone);
 
     String getPointId(Storge storge, TTask task,String zoneType);
 

+ 17 - 65
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/edgeLibrary/service/impl/StorgeServiceImpl.java

@@ -25,8 +25,10 @@ import com.github.zuihou.business.productionReadyCenter.entity.Plate;
 import com.github.zuihou.business.productionReadyCenter.service.PlateService;
 import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourcePositionMapper;
 import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
+import com.github.zuihou.business.productionResourceCenter.entity.ZZone;
 import com.github.zuihou.business.productionResourceCenter.service.ProductionresourcePositionService;
 import com.github.zuihou.common.constant.BizConstant;
+import com.github.zuihou.common.constant.DictionaryKey;
 import com.github.zuihou.common.util.StringUtil;
 import com.github.zuihou.database.mybatis.auth.DataScope;
 import com.github.zuihou.database.mybatis.conditions.Wraps;
@@ -250,25 +252,11 @@ public class StorgeServiceImpl extends SuperCacheServiceImpl<StorgeMapper, Storg
 
     /**
      * 验证接驳位是否放置了托板
-     * @param noArr
+     * @param zZone
      * @return
      */
     @Override
-    public Map getPlateStorgeByNo(String noArr[],String completeBatchNo) {
-        //根据要处理的工件编号,查出其产线
-        String zoneNo = redisTemplate.opsForValue().get(DemoCacheKey.DEMOLINE_WORKOP_ZONE+completeBatchNo)==null?""
-                :redisTemplate.opsForValue().get(DemoCacheKey.DEMOLINE_WORKOP_ZONE+completeBatchNo).toString();
-        int stockNum = 0;
-
-        //根据产线编号,匹配出产线类型。
-        String zoneType = "";
-        if(DemoLineConstant.DEMOLINE_WORK_SPACE1.equals(zoneNo)){
-            zoneType = DemoLineConstant.DEMOLINE_ZONE_TYPE1;
-            stockNum = DemoLineConstant.DEMOLINE_ZONE_TYPE1_NUM;
-        }else if(DemoLineConstant.DEMOLINE_WORK_SPACE2.equals(zoneNo)){
-            zoneType = DemoLineConstant.DEMOLINE_ZONE_TYPE2;
-            stockNum = DemoLineConstant.DEMOLINE_ZONE_TYPE2_NUM;
-        }
+    public Map getPlateStorgeByNo(ZZone zZone) {
         //返回的map
         Map returnMap = new HashMap();
         Long relJBW = null;
@@ -279,12 +267,13 @@ public class StorgeServiceImpl extends SuperCacheServiceImpl<StorgeMapper, Storg
         String jbwCode = "";
         //查询接驳位库位的存放物品,验证是否放置了1个托板
         Map map = new HashMap();
-        map.put("codes",StringUtil.changeIdsArrToSubQueryStr(noArr));
+        String jbw = DictionaryKey.YJ_ZONE_JBW.get(zZone.getName());
+        map.put("codes",StringUtil.changeIdsArrToSubQueryStr(jbw));
         map.put("haveGoods","1");
         List<ProductionresourcePosition>jbwList = productionresourcePositionMapper.getPPList(map);
         if(jbwList!=null&&jbwList.size()>0){
             //查出当前工件属于产线的托板
-            Map<Long,Plate> plateMap = getPlate(zoneType);
+            Map<Long,Plate> plateMap = getPlate(zZone.getId().toString());
             //根据接驳位分组
             Map<String,List<ProductionresourcePosition>> jbwMap = jbwList.stream().collect(groupingBy(ProductionresourcePosition::getNo));
             List<ProductionresourcePosition>tbList = new ArrayList<>();
@@ -309,50 +298,13 @@ public class StorgeServiceImpl extends SuperCacheServiceImpl<StorgeMapper, Storg
                 //查询托板上的库位
                 List<ProductionresourcePosition>list = productionresourcePositionMapper.getPPList(querymap);
                 //查出有库位或被占用的数据
-                List<ProductionresourcePosition>fullList = list.stream().filter(p->"0".equals(p.getLockStatus())||StringUtil.isNotEmpty(p.getCompleteBatchNo())).collect(toList());
                 //查出所有空闲的
                 List<ProductionresourcePosition>emptyList = list.stream().filter(p->"1".equals(p.getLockStatus())&&StringUtil.isEmpty(p.getCompleteBatchNo())).collect(toList());
-                Map<String, List<ProductionresourcePosition>> fulltbMap = fullList.stream().collect(groupingBy(ProductionresourcePosition::getNo));
                 Map<String, List<ProductionresourcePosition>> emptytbMap = emptyList.stream().collect(groupingBy(ProductionresourcePosition::getNo));
 
-                if(fullList==null||fullList.size()==0){//如果接驳位的是空的
-                    //
-                    if(emptyList!=null&&emptyList.size()>0){
-                        ProductionresourcePosition position = emptyList.get(0);
-                        storge = baseMapper.selectById(position.getStorgeId());
-                    }
-                }else{
-                    for(String key:fulltbMap.keySet()){
-                        //托板库位
-                        List<ProductionresourcePosition> tbkwlist = fulltbMap.get(key);
-                        if(tbkwlist!=null&&tbkwlist.size()>0&&tbkwlist.size()<stockNum){//库位有了一些,但是没有满。
-
-                            ProductionresourcePosition p = tbkwlist.get(0);
-                            //判断库位里的原材料加工产线和即将要放入的原材料的加工产线是否一致
-                            String stockcompleteBatchNo = p.getCompleteBatchNo();
-                            String campCompleteBatchNo= p.getCampCompleteBatchNo();
-                            //有库存了或者被预占了
-                            if(StringUtil.isNotEmpty(stockcompleteBatchNo)||StringUtil.isNotEmpty(campCompleteBatchNo)){
-                                String stockZoneNo = "";
-                                if(StringUtil.isNotEmpty(stockcompleteBatchNo)){
-                                    stockZoneNo = redisTemplate.opsForValue().get(DemoCacheKey.DEMOLINE_WORKOP_ZONE+stockcompleteBatchNo)==null?""
-                                            :redisTemplate.opsForValue().get(DemoCacheKey.DEMOLINE_WORKOP_ZONE+stockcompleteBatchNo).toString();
-                                }
-
-                                if(StringUtil.isNotEmpty(campCompleteBatchNo)){
-                                    stockZoneNo = redisTemplate.opsForValue().get(DemoCacheKey.DEMOLINE_WORKOP_ZONE+campCompleteBatchNo)==null?""
-                                            :redisTemplate.opsForValue().get(DemoCacheKey.DEMOLINE_WORKOP_ZONE+campCompleteBatchNo).toString();
-                                }
-                                //选中了托板
-                                if(zoneNo.equals(stockZoneNo)){
-                                    List<ProductionresourcePosition> l = emptytbMap.get(key);
-                                    if(l!=null&&l.size()>0){
-                                        storge = baseMapper.selectById(l.get(0).getStorgeId());
-                                    }
-                                }
-                            }
-                        }
-                    }
+                if(emptyList!=null&&emptyList.size()>0){
+                    ProductionresourcePosition position = emptyList.get(0);
+                    storge = baseMapper.selectById(position.getStorgeId());
                 }
             }
             }
@@ -362,22 +314,22 @@ public class StorgeServiceImpl extends SuperCacheServiceImpl<StorgeMapper, Storg
                 storge.setResourceNo(jbwCode);
                 returnMap.put("jbwCode",jbwCode);
                 //把所属的接驳位放入map
-                if(relJBW!=null){
-                    Storge jbwStorge = this.getById(relJBW);
-                    jbwStorge.setResourceNo(jbwCode);
-                    returnMap.put("jbwStorge",jbwStorge);
-                }
+//                if(relJBW!=null){
+//                    Storge jbwStorge = this.getById(relJBW);
+//                    jbwStorge.setResourceNo(jbwCode);
+//                    returnMap.put("jbwStorge",jbwStorge);
+//                }
             }
             return returnMap;
         }
 
 
-        private Map<Long,Plate> getPlate(String zoneType){
+        private Map<Long,Plate> getPlate(String zoneId){
             Map<Long,Plate>plateMap = new HashMap<>();
             List<Plate>plateList = plateService.list();
             List<Plate>plist = new ArrayList<>();
             for(Plate plate:plateList){
-                if(zoneType.equals(plate.getZoneType())){
+                if(zoneId.equals(plate.getZoneId()==null?"":plate.getZoneId().toString())){
                     plist.add(plate);
                 }
             }

+ 3 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/ZZoneService.java

@@ -56,4 +56,7 @@ public interface ZZoneService extends SuperService<ZZone> {
     //示范线所有的生产资源
     Map demoLineAllResource();
 
+    String getRobotTypebyZone(String zoneName);
+
+
 }

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

@@ -16,10 +16,12 @@ import com.github.zuihou.business.operationManagementCenter.service.WorkpieceSer
 import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourcePositionMapper;
 import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
 import com.github.zuihou.business.productionResourceCenter.entity.ResourceAutoCode;
+import com.github.zuihou.business.productionResourceCenter.entity.ZZone;
 import com.github.zuihou.business.productionResourceCenter.entity.ZZoneProductionresource;
 import com.github.zuihou.business.productionResourceCenter.service.NodeOperationService;
 import com.github.zuihou.business.productionResourceCenter.service.ProductionresourcePositionService;
 import com.github.zuihou.business.productionResourceCenter.service.ZZoneProductionresourceService;
+import com.github.zuihou.business.productionResourceCenter.service.ZZoneService;
 import com.github.zuihou.business.util.MsgUtil;
 import com.github.zuihou.common.constant.BizConstant;
 import com.github.zuihou.common.constant.DictionaryKey;
@@ -28,6 +30,7 @@ import com.github.zuihou.database.mybatis.conditions.Wraps;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
 import com.github.zuihou.tenant.entity.Module;
 import com.github.zuihou.tenant.entity.Productionresource;
+import com.github.zuihou.tenant.entity.TenantResource;
 import com.github.zuihou.tenant.service.ModuleService;
 import com.github.zuihou.tenant.service.ProductionresourceService;
 import com.google.common.collect.Maps;
@@ -80,6 +83,9 @@ public class RobotNodeServiceImpl implements NodeOperationService {
     @Autowired
     private ZZoneProductionresourceService zZoneProductionresourceService;
 
+    @Autowired
+    private ZZoneService zoneService;
+
     private Map<String, Object> map = Maps.newHashMap();
 
     private String ZK_ip_zlzx = "192.168.170.61";
@@ -96,13 +102,19 @@ public class RobotNodeServiceImpl implements NodeOperationService {
 
     private String[] xbkArr;
 
-    private List<ProductionresourcePosition> deviceList;
+    private List<ProductionresourcePosition> robotList;
+
+    private List<ProductionresourcePosition> targetList;
 
     private List<ProductionresourcePosition> xbkList;
 
     private List<ProductionresourcePosition> jbwList;
 
-    private Long zone_id;
+    private Long zoneId;
+
+    private String zoneName;
+
+    private ZZone zZone;
 
     @Override
     public void initResource(TaskNode taskNode, TTask task, Map dataMap) {
@@ -110,29 +122,29 @@ public class RobotNodeServiceImpl implements NodeOperationService {
         //this.sxlzIdArr = new String[] {DemoLineConstant.JQR1};
         String moduleName = dataMap.get("moduleName") == null ? "" : dataMap.get("moduleName").toString();
         String robotType = dataMap.get("robotType") == null ? "" : dataMap.get("robotType").toString();
-        if(StringUtil.isNotEmpty(moduleName) && StringUtil.isNotEmpty(robotType)) {
+        if(StringUtil.isNotEmpty(moduleName)) {
             //List<Module> modules = moduleService.list(new QueryWrapper<Module>().like("name", moduleName));
-            Productionresource productionresource = productionresourceService.getOne(new QueryWrapper<Productionresource>().eq("name", robotType));
+            Productionresource productionresource = productionresourceService.getOne(new QueryWrapper<Productionresource>().eq("id", taskNode.getResourceId()));
             if(productionresource!=null){
                 deviceArr = new String[] {productionresource.getId().toString()};
-                deviceList = productionresourcePositionService.getFreeProductionresourcePositionByIds(deviceArr);
+                robotList = productionresourcePositionService.getFreeProductionresourcePositionByIds(deviceArr);
             }
         }
         //获取机器人操作线边库
-        xbkArr = dataMap.get("robotType")!=null? new String[]{
-                    DictionaryKey.YJ_ZONE_XBK.get(dataMap.get("robotType").toString())
-                }: new String[]{DemoLineConstant.NODE_RESOURCE_ZLZX_XBK};
+        xbkArr = new String[]{DictionaryKey.YJ_ZONE_XBK.get(zoneName)};
         xbkList = productionresourcePositionService.getFreeProductionresourcePositionByNos(xbkArr);
         //jbwArr = modules.stream().map(Module::getNo).toArray(String[]::new);
         // 获取机器人抓取、放可操作的接驳位(依据产线  待定)
-        List<Productionresource> dataList = productionresourceService.list(new QueryWrapper<Productionresource>().like("name", robotType));
-        if(dataList.size()>0) {
-            jbwArr = dataList.stream().map(Productionresource::getId).toArray(String[]::new);
-            jbwList = productionresourcePositionService.getFreeProductionresourcePositionByIds(jbwArr);
-        }
+//        List<Productionresource> dataList = productionresourceService.list(new QueryWrapper<Productionresource>().like("name", robotType));
+//        if(dataList.size()>0) {
+//            jbwArr = dataList.stream().map(Productionresource::getId).toArray(String[]::new);
+//            jbwList = productionresourcePositionService.getFreeProductionresourcePositionByIds(jbwArr);
+//        }
         //获取产线ID
         ZZoneProductionresource zZoneProductionresource = zZoneProductionresourceService.getOne(new LbqWrapper<ZZoneProductionresource>().eq(ZZoneProductionresource::getResourceId, taskNode.getResourceId()));
-        zone_id = zZoneProductionresource.getZoneId();
+        zoneId = zZoneProductionresource.getZoneId();
+        zZone = zoneService.getById(zoneId);
+        zoneName = zoneService.getById(zoneId).getName();
     }
 
     @Override
@@ -154,57 +166,57 @@ public class RobotNodeServiceImpl implements NodeOperationService {
         }
         String functionName = DictionaryKey.ROBOT_ACTION.get(resourceAutoCode.getCommand());
         //设备条件判断
-        ProductionresourcePosition productionresourcePosition = this.logical(deviceList, true);
-        boolean bool =  productionresourcePosition!=null ? true : false;
-        if(!bool){
-            map.put("result", false);
-            return map;
-        }
+        String count = dataMap.get(taskNode.getId().toString() + "count") == null ? "0" : dataMap.get(taskNode.getId().toString() + "count").toString();
+//        ProductionresourcePosition productionresourcePosition = this.logical(robotList, count);
+
+//        boolean bool =  productionresourcePosition!=null ? true : false;
+//        if(!bool){
+//            map.put("result", false);
+//            return map;
+//        }
         //开始库位
-        Storge startStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
+        Storge currStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
         //目的库位
-        Storge jqrStorge = storgeService.getById(deviceList.get(0).getStorgeId());
+        Storge jqrStorge = storgeService.getById(robotList.get(0).getStorgeId());
         //目标地址判断
-        if(map.containsKey("useXbk")){
-            //目标地址是线边库
-            map.put("result", false);
-            return map;
-        }
+//        if(map.containsKey("useXbk")){
+//            //目标地址是线边库
+//            map.put("result", false);
+//            return map;
+//        }
 
-        switch(robotType){
+        switch(zoneName){
             case "质量中心机器人":
                 //操作质量中心边库 具有取、移动、放三种指令
-                  //取放上下料站
-                  //取放三坐标
+                //取放上下料站
+                //取放三坐标
                 map.put("deviceUrl", ZK_ip_zlzx);
                 break;
             case "柔性线机器人":
                 //操作柔性线边库 具有取、移动、放三种指令
-                 //取放加工设备  设备存在缓存位
-                String count = dataMap.get(taskNode.getId().toString() + "count") == null ? "0" : dataMap.get(taskNode.getId().toString() + "count").toString();
-                map = this.commandHandle(map, startStore, jqrStorge, functionName, count);
+                //取放加工设备  设备存在缓存位
+                map = this.commandHandle(map, currStore, jqrStorge, functionName, count);
                 map.put("deviceUrl", ZK_ip_rxx);
                 break;
             case "智能单元机器人":
                 //操作智能单元线边库 具有取、移动、放三种指令
                 //取放加工设备 无缓存位处理
-                map = this.commandHandle(map, startStore, jqrStorge, functionName);
+                map = this.commandHandle(map, currStore, jqrStorge, functionName);
                 map.put("deviceUrl", ZK_ip_zndy);
                 break;
-            case "舱体线机器人":
+            case "舱体类加工单元":
                 //操作舱体线边库 具有取、移动、放三种指令
-                //本机存在缓存库位 (取->缓存库位->放->目标库位)
-
+                //取放加工设备
+                map = this.commandHandle(map, currStore, jqrStorge, functionName, count);
                 break;
-            case "伺服舵机":
+            case "智能生产保障系统":
                 //操作三个线边库 只具有取、放两种动作
-                //本机无缓存库位 (取->放->目标库位)
 
 
                 break;
-            case "框体线机器人":
+            case "框体类加工单元":
                 //操作框体线边库 具有取、移动、放三种指令
-                //本机存在缓存库位 (取->缓存库位->放->目标库位)
+                //取放加工设备
 
                 break;
         }
@@ -235,151 +247,218 @@ public class RobotNodeServiceImpl implements NodeOperationService {
     private Map<String, Object>  commandHandle(Map<String, Object> dataMap, Storge startStore, Storge jqrStorge, String... params){
         TaskNode taskNode = (TaskNode) dataMap.get("taskNode");
         TTask task = (TTask) dataMap.get("task");
-        //缓存位判断处理
-        if (params[1]!= null) {
-            //int count = dataMap.get(taskNode.getId().toString() + "count") == null ? 0 : Integer.parseInt(dataMap.get(taskNode.getId().toString() + "count").toString());
-             int count = Integer.parseInt(params[1]);
-            //执行到第几步
-            dataMap.put(taskNode.getId().toString() + "count", count);
-            dataMap.put(DemoLineConstant.DEMOLINE_RXJQR_FLAG, "1");
-            dataMap.put("zkIp", ZK_ip_rxx);
-
-            if (count == 0) {//第一步的时候锁定资源
-                //判断机器人是否为空
-                Map<String, List<ProductionresourcePosition>> jqrMap = deviceList.stream().collect(groupingBy(ProductionresourcePosition::getPointId));
+        int count = Integer.parseInt(params[1]);
 
+        //缓存位判断处理
+        if ("取".equals(params[0])) {
+            if(BizConstant.ROBOT_TYPE_CACHE.equals(zoneService.getRobotTypebyZone(zoneName))){
+                //执行到第几步
+                dataMap.put(taskNode.getId().toString() + "count", count);
+                dataMap.put(DemoLineConstant.DEMOLINE_RXJQR_FLAG, "1");
+                dataMap.put("zkIp", ZK_ip_rxx);
+
+                if (count == 0) {//第一步的时候锁定资源
+                    //判断机器人是否为空
+                    Map<String, List<ProductionresourcePosition>> jqrMap = robotList.stream().collect(groupingBy(ProductionresourcePosition::getPointId));
+
+                    TaskNode nextTaskNode = taskNodeService.getNextNTaskNode(taskNode, 1);
+                    //目标库位,可能是
+                    Map returnMap = getTargetStorge(nextTaskNode);
+
+                    //目标地址和类型
+                    Storge targetStorge = returnMap.get("store")==null?null:(Storge)returnMap.get("store");
+                    String type = returnMap.get("type")==null?null:(String)returnMap.get("store");
+
+                    //机器人手抓没被锁定,并且有空闲未知
+                    if (logical(robotList,targetStorge)!=null) {
+                        jqrStorge = storgeService.getById(jqrMap.get(DemoLineConstant.DEMOLINE_RJQR_ZS).get(0).getStorgeId());
+                        jqrStorge.setCompleteBatchNo(task.getCompleteBatchNo());
+                        storgeService.lockStorge(jqrStorge, nextTaskNode.getId());
+                        //锁定一个缓存位
+                        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());
+
+                        //锁定目标库位
+                        targetStorge.setCompleteBatchNo(task.getCompleteBatchNo());
+                        storgeService.lockStorge(targetStorge, 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);
+                        //目标缓存
+                        msgUtil.redis_set(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + nextTaskNode.getId(), targetStorge, 1, TimeUnit.DAYS);
+
+                        //满足条件--机器人空闲,设备或线边库有一个空闲
+                        dataMap.put("Data", startStore);
+                        dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "moveMaterial");
+                    }
+                    dataMap.put("result", logical(robotList,targetStorge));
+                } else if (count == 1) {
+                    jqrStorge = (Storge) msgUtil.redis_get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId());
+                    dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "fetchMaterial");
+                    Storge currentStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
+                    dataMap.put("fromStorge", currentStore);
+                    dataMap.put("Data", currentStore);
+                    //出入库类型
+                    dataMap.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
+                    //目的地为机器人手臂
+                    map.put("toStorge", jqrStorge);
+                    dataMap.put("result", true);
+                } else if (count == 2) {
+                    Storge currentStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
+                    dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "putMaterial");
+                    dataMap.put("fromStorge", currentStore);
+                    //出入库类型
+                    dataMap.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());
+                    dataMap.put("Data", hcwStorge);
+                    dataMap.put("toStorge", hcwStorge);
+                    dataMap.put("result", true);
+                }
+            }else if (BizConstant.ROBOT_TYPE_NOCACHE.equals(zoneService.getRobotTypebyZone(zoneName))) {
                 TaskNode nextTaskNode = taskNodeService.getNextNTaskNode(taskNode, 1);
-                //机器人手抓没被锁定,并且有空闲未知
-                if (CollectionUtil.isNotEmpty(deviceList) && deviceList.size() > 1 && jqrMap.containsKey(DemoLineConstant.DEMOLINE_RJQR_ZS)) {
+                Map returnMap = getTargetStorge(nextTaskNode);
 
-                    jqrStorge = storgeService.getById(jqrMap.get(DemoLineConstant.DEMOLINE_RJQR_ZS).get(0).getStorgeId());
+                //目标地址和类型
+                Storge targetStorge = returnMap.get("store")==null?null:(Storge)returnMap.get("store");
+                String type = returnMap.get("type")==null?null:(String)returnMap.get("store");
+
+                dataMap.put("zkIp", ZK_ip_zndy);
+                dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "fetchMaterial");
+                if (logical(robotList,targetStorge)!=null) {
+                    dataMap.put("fromStorge", startStore);
+                    dataMap.put("Data", startStore);
+                    //出入库类型
+                    dataMap.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
+                    //目的地为机器人手臂
+                    dataMap.put("toStorge", jqrStorge);
+                    //锁定机器人
                     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());
+
+                    //锁定目标库位
+                    targetStorge.setCompleteBatchNo(task.getCompleteBatchNo());
+                    storgeService.lockStorge(targetStorge, 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);
-
-                    //满足条件--机器人空闲,设备或线边库有一个空闲
-                    startStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
-                    dataMap.put("Data", startStore);
-                    dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "moveMaterial");
+                    //目标缓存
+                    msgUtil.redis_set(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + nextTaskNode.getId(), targetStorge, 1, TimeUnit.DAYS);
+                    map.put("result", true);
                 }
-                dataMap.put("result", (CollectionUtil.isNotEmpty(deviceList)) && jqrMap.containsKey(DemoLineConstant.DEMOLINE_RJQR_ZS));
-            } else if (count == 1) {
-                jqrStorge = (Storge) msgUtil.redis_get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId());
-                dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "fetchMaterial");
-                Storge currentStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
-                dataMap.put("fromStorge", currentStore);
-                dataMap.put("Data", currentStore);
-                //出入库类型
-                dataMap.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
-                //目的地为机器人手臂
-                map.put("toStorge", jqrStorge);
-                dataMap.put("result", true);
-            } else if (count == 2) {
-                Storge currentStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
-                dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "putMaterial");
-                dataMap.put("fromStorge", currentStore);
-                //出入库类型
-                dataMap.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());
-                dataMap.put("Data", hcwStorge);
-                dataMap.put("toStorge", hcwStorge);
-                dataMap.put("result", true);
             }
-
-        }
-        else if ("取".equals(params[0])) {
-            dataMap.put("zkIp", ZK_ip_zndy);
-            dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "fetchMaterial");
-            TaskNode nextTaskNode = taskNodeService.getNextNTaskNode(taskNode, 1);
-            //if (CollectionUtil.isNotEmpty(jqrList)) {
-            dataMap.put("fromStorge", startStore);
-            dataMap.put("Data", startStore);
-            //出入库类型
-            dataMap.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
-            //目的地为机器人手臂
-            dataMap.put("toStorge", jqrStorge);
-            //锁定机器人
-            jqrStorge.setCompleteBatchNo(task.getCompleteBatchNo());
-            storgeService.lockStorge(jqrStorge, nextTaskNode.getId());
-            //}
-            //
+        }else if ("放".equals(params[0])) {
+            Object targetStorge = msgUtil.redis_get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + taskNode.getId());
+            //执行到第几步
+            map.put(taskNode.getId().toString()+"count",count);
+            map.put(DemoLineConstant.DEMOLINE_RXJQR_FLAG, "1");
+            map.put("zkIp",ZK_ip_rxx);
+            if(BizConstant.ROBOT_TYPE_CACHE.equals(zoneService.getRobotTypebyZone(zoneName))){
+                if(count==0) {
+                    map.put("Data", targetStorge);
+                    map.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "moveMaterial");
+                }else if(count == 1){//从缓存位拿出来
+                    map.put(DemoLineConstant.DEMOLINE_BIZ_TYPE,"fetchMaterial");
+                    Storge hcwStorge = (Storge)msgUtil.redis_get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.DEMOLINE_RJQR_HCW + taskNode.getId());
+                    map.put("Data", hcwStorge);
+                    map.put("fromStorge", hcwStorge);
+                    Storge handStorge = (Storge)msgUtil.redis_get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId());
+                    map.put("toStorge", handStorge);
+                    //出入库类型
+                    map.put(DemoLineConstant.DEMOLINE_STOCK_TYPE,DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
+                }else if(count == 2){
+                    map.put(DemoLineConstant.DEMOLINE_BIZ_TYPE,"putMaterial");
+                    //出入库类型
+                    map.put(DemoLineConstant.DEMOLINE_STOCK_TYPE,DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
+                    map.put("Data", targetStorge);
+                    map.put("toStorge", targetStorge);
+
+                    Storge handStorge = (Storge)msgUtil.redis_get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId());
+                    map.put("fromStorge", handStorge);
+                }
+            }else if (BizConstant.ROBOT_TYPE_NOCACHE.equals(zoneService.getRobotTypebyZone(zoneName))) {
+                map.put("zkIp",ZK_ip_zndy);
+                map.put(DemoLineConstant.DEMOLINE_BIZ_TYPE,"putMaterial");
+                map.put("toStorge", targetStorge);
+                map.put("Data", targetStorge);
+            }
             map.put("result", true);
         }
-        else if ("放".equals(params[0])) {
-            //判断目标位置是否空闲
-            String actionTarget = taskNode.getAutoNode().getTargetId().toString();
-            //1是本设备 2是接驳位
-            List<ProductionresourcePosition> targetList = "1".equals(actionTarget)? productionresourcePositionService.getFreeProductionresourcePositionByNos(new String[]{taskNode.getNodeNo()}) : jbwList;
-            ProductionresourcePosition productionresourcePosition = this.logical(targetList, true);
-            boolean bool =  productionresourcePosition!=null ? true : false;
-            if(!bool){
-                dataMap.put("result", false);
-                return dataMap;
+        return map;
+    }
+
+
+    /**
+     * 判断机器人是否可用
+     * @return
+     */
+    public boolean checkRobot(){
+        if(BizConstant.ROBOT_TYPE_NOCACHE.equals(zoneService.getRobotTypebyZone(zoneName))){
+            return CollectionUtil.isNotEmpty(robotList) && robotList.size() == 1;
+        }else if(BizConstant.ROBOT_TYPE_CACHE.equals(zoneService.getRobotTypebyZone(zoneName))){//手抓必须空闲。
+            Map<String, List<ProductionresourcePosition>> jqrMap = robotList.stream().collect(groupingBy(ProductionresourcePosition::getPointId));
+            return CollectionUtil.isNotEmpty(robotList) && robotList.size() >1&&jqrMap.containsKey(DemoLineConstant.DEMOLINE_RJQR_ZS);
+        }
+        return true;
+    }
+
+
+    public Map getTargetStorge(TaskNode taskNode){
+        Map returnMap = new HashMap();
+        Storge targetStorge = null;
+        Long resourceId = taskNode.getResourceId();
+        //目标设备
+        if(resourceId!=null){
+            targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[] {resourceId.toString()});
+            if(CollectionUtil.isNotEmpty(targetList)){
+                targetStorge = storgeService.getById(targetList.get(0).getStorgeId());
+                returnMap.put("store",targetStorge);
+                returnMap.put("type","resource");
+
             }
-            boolean isXbk = dataMap.containsKey("useXbk");
-            Storge targetStorge = storgeService.getById(productionresourcePosition.getStorgeId());
-            targetStorge.setCompleteBatchNo(task.getCompleteBatchNo());
-            if(isXbk){
-                dataMap.put("result", false);
-            }else{
-                //锁定设备
-                storgeService.lockStorge(targetStorge, taskNode.getId());
-                dataMap.put("result", true);
+        }else{//放到线边库
+            Map map = storgeService.getPlateStorgeByNo(zZone);
+            targetStorge = map.get("storge") ==null?null:(Storge)map.get("storge");
+            if(targetStorge!=null){
+                returnMap.put("store",targetStorge);
+                returnMap.put("type","xbk");
             }
         }
-        return map;
+        return returnMap;
     }
 
     /**
      *  设备动态逻辑判断处理
      *
-     * @param deviceList
-     * @param useXbk
+     * @param robotList
      * @return
      */
-    private ProductionresourcePosition logical(List<ProductionresourcePosition> deviceList, boolean useXbk){
+    private ProductionresourcePosition logical(List<ProductionresourcePosition> robotList,Storge targetStorge){
         //设备不存在
-        if(deviceList == null || deviceList.size() == 0){
+        if(checkRobot()){
             map.put("msg", DictionaryKey.NodeException.NO_RESOURCE);
             return null;
         }
         //资源临界判断
-        int current_running_num = storgeService.getstorgeByZone(zone_id.toString());
+        int current_running_num = storgeService.getstorgeByZone(zoneId.toString());
         if(current_running_num == DictionaryKey.RESOURCE_MAX_NUM){
             map.put("msg", DictionaryKey.NodeException.NO_RESOURCE);
             return null;
         }
-        deviceList = deviceList.stream().filter(position->position.getStatus()=="1" && position.getLockStatus()=="1").collect(Collectors.toList());
-        //设备被锁定
-        if(deviceList.size() == 0) {
-            if(useXbk){
-                if(xbkList.size() == 0){
-                    map.put("msg", DictionaryKey.NodeException.RESOURCE_LOCK);
-                    return null;
-                }
-                map.put("useXbk", true);
-                return xbkList.get(0);
-            }
-            map.put("msg", DictionaryKey.NodeException.RESOURCE_LOCK);
+
+        if(targetStorge==null){
+            map.put("msg", DictionaryKey.NodeException.NO_RESOURCE);
             return null;
         }
-        //设备托盘、夹具条件不满足  待定
 
-        return deviceList.get(0);
+        return robotList.get(0);
     }
 
 }

+ 12 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/impl/ZZoneServiceImpl.java

@@ -17,6 +17,7 @@ import com.github.zuihou.business.productionResourceCenter.service.ZZoneProducti
 import com.github.zuihou.business.productionResourceCenter.service.ZZoneService;
 import com.github.zuihou.base.service.SuperServiceImpl;
 
+import com.github.zuihou.common.constant.BizConstant;
 import com.github.zuihou.common.constant.CacheKey;
 import com.github.zuihou.common.constant.CodeRuleModule;
 import com.github.zuihou.common.constant.DictionaryType;
@@ -512,4 +513,15 @@ public class ZZoneServiceImpl extends SuperServiceImpl<ZZoneMapper, ZZone> imple
         returnMap.put("list",returnList);
             return returnMap;
         }
+
+
+    @Override
+    public String getRobotTypebyZone(String zoneName) {
+        if(zoneName.indexOf("舱体")>0||zoneName.indexOf("框体")>0){
+            return BizConstant.ROBOT_TYPE_CACHE;
+        }else if(zoneName.indexOf("保障")>0){
+            return BizConstant.ROBOT_TYPE_NOCACHE;
+        }
+        return "";
+    }
 }

+ 7 - 0
imcs-admin-boot/imcs-common/src/main/java/com/github/zuihou/common/constant/BizConstant.java

@@ -188,4 +188,11 @@ public interface BizConstant {
     String STOCK_GOODS_TYPE_5 = "5";
 
 
+    //机器人是否带缓存位
+    String ROBOT_TYPE_CACHE = "CACHE";
+
+    String ROBOT_TYPE_NOCACHE = "NOCACHE";
+
+
+
 }

+ 15 - 6
imcs-admin-boot/imcs-common/src/main/java/com/github/zuihou/common/constant/DictionaryKey.java

@@ -121,12 +121,21 @@ public interface DictionaryKey {
     //设备关联线边库
     Map<String, String> YJ_ZONE_XBK = new HashMap<String, String>(){
         {
-            put("舱体线机器人", "CTxianbianku");
-            put("框体线机器人", "KTxianbianku");
-            put("伺服舵机", "BZZXxianbianku");
-            put("质量中心机器人", "Qxianbianku");
-            put("智能单元机器人", "Zxianbianku");
-            put("柔性线机器人","Rxianbianku");
+            put("智能生产保障系统", "CT_01,CT_02,CT_03");
+            put("框体类加工单元", "KT_01,KT_02,KT_03");
+            put("舱体类加工单元", "BZ_01,BZ_02,BZ_03");
+//            put("质量中心机器人", "Qxianbianku");
+//            put("智能单元机器人", "Zxianbianku");
+//            put("柔性线机器人","Rxianbianku");
+        }
+    };
+
+
+    Map<String, String> YJ_ZONE_JBW = new HashMap<String, String>(){
+        {
+            put("智能生产保障系统", "BZ_361,BZ_361,BZ_361");
+            put("框体类加工单元", "KT_121,KT_121");
+            put("舱体类加工单元", "CT_121,CT_122");
         }
     };