Browse Source

翻面初步

laoyao 2 years ago
parent
commit
3912e949ee

+ 1 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/DemoLine/YunjianConstant.java

@@ -280,6 +280,7 @@ public interface YunjianConstant {
     String YUNJIAN_PRODUCTION_STATUS_2="离线";
     String YUNJIAN_PRODUCTION_STATUS_3="空闲";
     String YUNJIAN_PRODUCTION_STATUS_4="报警";
+    String YUNJIAN_FANMIAN = "YUNJIAN_FANMIAN";
 
 
 

+ 6 - 2
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/mq/TaskWorkNode.java

@@ -288,7 +288,7 @@ public class TaskWorkNode {
                     taskNodeMapper.updateAllById(taskNode);
                 }
 
-                if ("04".equals(taskNode.getInterfaceType())) {
+                if ("04".equals(taskNode.getInterfaceType())&&!"3".equals(bizType)) {
                     //人工上下料或质检
                     //不用调接口,直接返回成功
                     conMap.put("result",true);
@@ -296,6 +296,10 @@ public class TaskWorkNode {
                 } else {
                     Map queryMap = Maps.newHashMap();
                     queryMap.put("bizType", bizType);
+                    if("3".equals(bizType)){
+                        String functionName = jsonObject.getString("functionName");
+                        queryMap.put("functionName",functionName);
+                    }
                     queryMap.put("carryType", carryType);
                     queryMap.put("handMode", handMode);
                     if (jsonObject.containsKey(taskNode.getId() + "count")) {
@@ -372,7 +376,7 @@ public class TaskWorkNode {
                                 }
                             }
                         } else {
-                            if (!"04".equals(taskNode.getInterfaceType())) {
+                            if (!"04".equals(taskNode.getInterfaceType())||"3".equals(bizType)) {
                                 // 判断当前工序是三坐标或者前一工序是三坐标,分别将三坐标的放和三坐标下一工序的取不调用ccs接口
                                 String method = conMap.get("method")==null?null:conMap.get("method").toString();
                                 ResourceBusiness resourceBusiness = resourceBusinessService.getById(tTask.getResourceBusinessId());

+ 2 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/TaskNodeService.java

@@ -163,4 +163,6 @@ public interface TaskNodeService extends SuperService<TaskNode> {
 
     void freeLock(String completeBatchNo);
 
+    R callRobot(Map<String, Object> map);
+
 }

+ 51 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/impl/TaskNodeServiceImpl.java

@@ -2324,4 +2324,55 @@ public class TaskNodeServiceImpl extends SuperServiceImpl<TaskNodeMapper, TaskNo
             storgeService.unlockStorgeList(storgeList);
         }
     }
+
+    @Override
+    public R callRobot(Map<String, Object> map) {
+        String taskNodeId = map.get("taskNodeId").toString();
+
+        TaskNode hisTask = this.getById(taskNodeId);
+
+        List<BomProcedureTray>trayList = procedureTrayService.list(Wraps.<BomProcedureTray>lbQ().in(BomProcedureTray::getProcedureId, hisTask.getProcedureId()));
+        List<Long>trayIdList = trayList.stream().map(t->t.getTrayId()).collect(Collectors.toList());
+
+
+        List<TaskNode> taskNodeList = baseMapper.selectList(Wraps.<TaskNode>lbQ().eq(TaskNode::getCompleteBatchNo, hisTask.getCompleteBatchNo()).orderByAsc(TaskNode::getCompleteBatchSort));
+        TaskNode firstTaskNode = taskNodeList.get(0);
+        List<BomProcedureTray>firsttrayList = procedureTrayService.list(Wraps.<BomProcedureTray>lbQ().in(BomProcedureTray::getProcedureId, firstTaskNode.getProcedureId()));
+        List<Long>firsttrayIdList = firsttrayList.stream().map(t->t.getTrayId()).collect(Collectors.toList());
+
+        //判断翻面得托盘工装和翻面前得是否一致
+        if(containAll(trayIdList,firsttrayIdList)){
+            return R.fail("无需呼叫");
+        }
+
+        //验证是否已经呼叫过
+        if(msgUtil.redis_get(taskNodeId+YunjianConstant.YUNJIAN_FANMIAN)!=null){
+            return R.fail("呼叫机器人尚未完成");
+        }
+        msgUtil.redis_set(YunjianConstant.YUNJIAN_FANMIAN+taskNodeId,YunjianConstant.YUNJIAN_FANMIAN+taskNodeId);
+
+        //获取机器人
+        Long resourceId = getResourceIdByAutoCode("2");
+        //呼叫
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("taskNodeId",taskNodeId);
+        jsonObject.put("taskNodeId"+"count", "0");
+        jsonObject.put("bizType", BizConstant.MQ_TASK_NODE_TYPE_VIRTUALLY);
+        jsonObject.put("functionName", "取");
+        jsonObject.put("resourceId",resourceId);
+        dynamicRabbitMq.sendMsg(resourceId.toString(),jsonObject.toString());
+        return R.success("");
+    }
+
+
+    private  Boolean containAll(List<Long> A, List<Long> B) {
+        List<Long> collect = A.stream().filter(item -> B.contains(item)).collect(Collectors.toList());
+        if (null != collect && collect.size() > 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+
 }

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

@@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.IdUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.github.zuihou.authority.entity.auth.RoleOrg;
+import com.github.zuihou.authority.entity.common.DictionaryItem;
 import com.github.zuihou.authority.entity.core.Org;
 import com.github.zuihou.base.R;
 import com.github.zuihou.business.DemoLine.DemoCacheKey;
@@ -62,6 +63,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Collectors.toList;
 
 @Slf4j
 @Service
@@ -281,7 +283,15 @@ public class RobotNodeServiceImpl implements NodeOperationService {
             dataMap.put("msg", DictionaryKey.NodeException.RUNNING_FALSE);
             return dataMap;
         }
-        String functionName = DictionaryKey.ROBOT_ACTION.get(resourceAutoCode.getCommand());
+
+        String bizType = dataMap.get("bizType")==null?"":dataMap.get("bizType").toString();
+        String functionName = "";
+        if("3".equals(bizType)){
+            functionName = dataMap.get("functionName")==null?"":dataMap.get("functionName").toString();
+        }else{
+            functionName = DictionaryKey.ROBOT_ACTION.get(resourceAutoCode.getCommand());
+        }
+
         //设备条件判断
         //当需要锁定agv开始、结束的接驳位库位
         Storge agvStartStationStorge = null;
@@ -549,7 +559,13 @@ public class RobotNodeServiceImpl implements NodeOperationService {
 
                         dataMap.put("result", false);
                     }else{
-                        Map returnMap = getTargetStorge(nextTaskNode,taskNode.getFindAgvFlag(),bomProcedure.getType());
+                        Map returnMap = null;
+                        String bizType = dataMap.get("bizType")==null?"":dataMap.get("bizType").toString();
+                        if("3".equals(bizType)){
+                            returnMap = getFanmianTargetStorge(taskNode,dataMap);
+                        }else {
+                            returnMap = getTargetStorge(nextTaskNode,taskNode.getFindAgvFlag(),bomProcedure.getType());
+                        }
 
                         //目标地址和类型
                         Storge targetStorge = returnMap.get("store")==null?null:(Storge)returnMap.get("store");
@@ -818,6 +834,49 @@ public class RobotNodeServiceImpl implements NodeOperationService {
     }
 
 
+    /**
+     * 翻面都是根据执行步骤写死的目标路径
+     * @param taskNode
+     * @param dataMap
+     * @return
+     */
+    public Map getFanmianTargetStorge(TaskNode taskNode,Map<String, Object> dataMap){
+        Map returnMap = new HashMap();
+        Storge targetStorge = null;
+        int count = Integer.parseInt(dataMap.get(taskNode.getId().toString() + "count") == null ? "0" : dataMap.get(taskNode.getId().toString() + "count").toString());
+        Long resourceId = null;
+        if(count==0){//先
+            //获取机器人操作线边库
+            String xbkKey = zoneName+"-"+bomzZone.getNo();
+            xbkArr = DictionaryKey.YJ_ZONE_XBK.get(xbkKey).split(",");
+            xbkList = productionresourcePositionService.getFreeProductionresourcePositionByNos(xbkArr);
+            if(CollectionUtil.isNotEmpty(xbkList)){
+                ProductionresourcePosition position = xbkList.get(0);
+                targetStorge = storgeService.getById(position.getStorgeId());
+                returnMap.put("storeResourceId",position.getResourceId());
+                returnMap.put("store",targetStorge);
+            }
+        }else if(count==2){//到线边库
+            //获取翻面工序的托盘夹具
+            ProductionresourcePosition position = getProductionresourcePosition(taskNode);
+            targetStorge = storgeService.getById(position.getStorgeId());
+            returnMap.put("storeResourceId",position.getResourceId());
+            returnMap.put("store",targetStorge);
+
+        }else if(count==4){//到线边库
+            //获取翻面工序的托盘夹具
+            resourceId = taskNode.getTargetResourceId();
+            targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[] {resourceId.toString()});
+            if(CollectionUtil.isNotEmpty(targetList)){
+                targetStorge = storgeService.getById(targetList.get(0).getStorgeId());
+                returnMap.put("storeResourceId",targetList.get(0).getResourceId());
+                returnMap.put("store",targetStorge);
+                returnMap.put("targetxbk","0");
+            }
+
+        }
+        return returnMap;
+    }
 
     public Map getTargetStorge(TaskNode taskNode,String findAgvFlag,String bomProcedureType){
         Map returnMap = new HashMap();
@@ -1166,4 +1225,36 @@ public class RobotNodeServiceImpl implements NodeOperationService {
         }
     }
 
+
+    private ProductionresourcePosition getProductionresourcePosition(TaskNode taskNode){
+        ProductionresourcePosition position = new ProductionresourcePosition();
+        List<BomProcedureTray>trayList = procedureTrayService.list(Wraps.<BomProcedureTray>lbQ().in(BomProcedureTray::getProcedureId, taskNode.getProcedureId()));
+        List<Long>trayIdList = trayList.stream().map(t->t.getTrayId()).collect(Collectors.toList());
+        List<ProductionresourcePosition> list = productionresourcePositionService.getFullProductionresourcePositionByNos(xbkArr);
+        if(CollectionUtil.isNotEmpty(list)){
+            Map<Long,List<ProductionresourcePosition>>map = list.stream().collect(groupingBy(ProductionresourcePosition::getStorgeId, LinkedHashMap::new, toList()));
+            for(Long l:map.keySet()){
+                List<ProductionresourcePosition>subList = map.get(l);
+                if(CollectionUtil.isNotEmpty(subList)&&subList.size()==2){
+                    List<Long>goodIdList = subList.stream().map(t->t.getGoodsId()).collect(Collectors.toList());
+                    if(containAll(trayIdList,goodIdList)){
+                        position = subList.get(0);
+                    }
+                }
+
+            }
+        }
+        return position;
+    }
+
+
+    private  Boolean containAll(List<Long> A, List<Long> B) {
+        List<Long> collect = A.stream().filter(item -> B.contains(item)).collect(Collectors.toList());
+        if (null != collect && collect.size() > 0) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
 }

+ 19 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/util/MsgUtil.java

@@ -527,6 +527,25 @@ public class MsgUtil implements ApplicationContextAware {
                         jsonObject.put("bizType", BizConstant.MQ_TASK_NODE_TYPE_COMMON);
                         dynamicRabbitMq.sendMsg(nextTaskNode.getResourceId().toString(),jsonObject.toString());
                     }
+            }else if(callBackJson.containsKey(BizConstant.MQ_TASK_NODE_TYPE_VIRTUALLY)){//翻面
+                int count =  callBackJson.getString(taskNode.getId().toString()+"count")==null?-1:Integer.parseInt(callBackJson.getString(taskNode.getId().toString()+"count"));
+                int limit =5;
+                if(count<limit){//
+                    count = ++count;
+                    //把当前节点推送到mq
+                    jsonObject.put("taskNodeId",taskNode.getId().toString());
+                    jsonObject.put(taskNode.getId().toString()+"count",count);
+                    jsonObject.put("bizType",BizConstant.MQ_TASK_NODE_TYPE_VIRTUALLY);
+                    dynamicRabbitMq.sendMsg(taskNode.getResourceId().toString(),jsonObject.toString());
+                    return;
+                }else{
+                    // 删除缓存位优先执行的节点标志
+                    redis_del(YunjianConstant.YUNJIAN_FANMIAN + taskNode.getId());
+
+                    jsonObject.put("taskNodeId",taskNode.getId().toString());
+                    jsonObject.put("bizType", BizConstant.MQ_TASK_NODE_TYPE_COMMON);
+                    dynamicRabbitMq.sendMsg(taskNode.getResourceId().toString(),jsonObject.toString());
+                }
             }else{
                 jsonObject.put("bizType", BizConstant.MQ_TASK_NODE_TYPE_COMMON);
                 if(callBackJson.containsKey(YunjianConstant.YUNJIAN_ROBORT_CACHE_FLAG)){//带缓存位机器人的多步骤执行

+ 6 - 0
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/operationManagementCenter/TaskNodeController.java

@@ -159,4 +159,10 @@ public class TaskNodeController extends SuperController<TaskNodeService, Long, T
         return baseService.taskNodeCallback(bean);
     }
 
+    @ApiOperation(value = "翻面呼叫机器人", notes = "翻面呼叫机器人")
+    @PostMapping("/callRobot")
+    public R callRobot(@RequestBody Map<String,Object> map) {
+        log.info("翻面呼叫机器人,请求参数{}",map);
+        return baseService.callRobot(map);
+    }
 }

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

@@ -167,6 +167,9 @@ public interface BizConstant {
     //普通的节点类型(bizType)
     String MQ_TASK_NODE_TYPE_XBK = "2";
 
+    //虚拟的,写死的节点
+    String MQ_TASK_NODE_TYPE_VIRTUALLY = "3";
+
 
     //强制的节点类型(bizType)
     String MQ_TASK_NODE_TYPE_FORCE_OFFLINE = "3";