Kaynağa Gözat

机器人动作节点增加agv调度的逻辑及锁库逻辑

yejian 3 yıl önce
ebeveyn
işleme
590d247293

+ 1 - 1
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/impl/WorkpieceServiceImpl.java

@@ -702,7 +702,7 @@ public class WorkpieceServiceImpl extends SuperServiceImpl<WorkpieceMapper, TWor
             if(null == lastActionTaskNode.getResourceId()){
                 // agv动作,动态查询agv接驳位
                 // 查询当前设备所在产线的接驳位
-                Map queryParams = new HashedMap();
+                Map queryParams = new HashMap();
                 queryParams.put("zoneId",zZoneProductionresource.getZoneId());
                 queryParams.put("resourceName","接驳");
                 List<Productionresource> productionresources = productionresourceBizMapper.selectResouces(queryParams);

+ 44 - 26
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/impl/AGVNodeServiceImpl.java

@@ -8,6 +8,7 @@ import com.github.zuihou.business.DemoLine.DemoLineConstant;
 import com.github.zuihou.business.edgeLibrary.entity.Storge;
 import com.github.zuihou.business.edgeLibrary.service.StorgeService;
 import com.github.zuihou.business.operationManagementCenter.entity.TTask;
+import com.github.zuihou.business.operationManagementCenter.entity.TWorkpiece;
 import com.github.zuihou.business.operationManagementCenter.entity.TaskNode;
 import com.github.zuihou.business.operationManagementCenter.service.TaskNodeService;
 import com.github.zuihou.business.operationManagementCenter.service.WorkpieceService;
@@ -89,36 +90,53 @@ public class AGVNodeServiceImpl implements NodeOperationService {
         map.put("task", task);
         map.put("bizType", bizType);
 
-        //AGV设备操作关联接驳位(起点和终点都是接驳位库位),接驳位占用暂存在线边库
-
-        String moduleName = dataMap.get("moduleName").toString();
-        //List<ModuleInstruction> instructions = dataMap.get("instructions") == null ? Lists.newArrayList() : (List<ModuleInstruction>)dataMap.get("instructions");
-        ResourceAutoCode resourceAutoCode = taskNode.getAutoNode();
-        String functionName = resourceAutoCode.getCommand();
-
-
-        //目标位置
-        Long targetId = resourceAutoCode.getTargetId();
-        Storge targetStore = storgeService.getById(targetId);
+        // 在机器人这边已经预暂库位了,agv搬运直接组装数据封装调用海康创建搬运任务
+        TaskNode beforTaskNode = taskNodeService.getNextNTaskNode(taskNode,-1);
+        JSONObject jsonObject = new JSONObject();
+        JSONObject bizJsonObject = new JSONObject();
+        Storge fstorge = storgeService.getOne(Wraps.<Storge>lbQ().eq(Storge::getCampId,beforTaskNode.getId()));
+        Storge tstorge = storgeService.getOne(Wraps.<Storge>lbQ().eq(Storge::getCampId,taskNode.getId()));
+        jsonObject.put("start", fstorge.getPointId());
+        jsonObject.put("goal", tstorge.getPointId());
+        jsonObject.put("transferType", "agv");
+        //此数据用来业务回传
+        bizJsonObject.put("srcPosition", fstorge.getId().toString());
+        bizJsonObject.put("targetPostion", tstorge.getId().toString());
 
-        //开始位置
-        Storge startStore = workpieceService.getWorkPieceStock(taskNode.getId(),true);
+        map.put("jsonObject", jsonObject);
+        map.put("bizJsonObject", bizJsonObject);
 
-        jbwarr = new String[] {targetStore.getNo()};
-        List<ProductionresourcePosition> jbwList = productionresourcePositionService.getFreeProductionresourcePositionByNos(jbwarr);
 
-        //TODO还需要验证,开始接驳位是否被其他锁定。并且尚未放置上去。
-        if (CollectionUtil.isNotEmpty(jbwList)) {
-            //3、把起始终点库位存放到map,用于接口
-            map.put("fromStorge", startStore);
-            map.put("toStorge", targetStore);
-            //这个节点没有需要验证的内容,都在前一个节点验证并且锁定了
-            map.put("result", true);
+        //AGV设备操作关联接驳位(起点和终点都是接驳位库位),接驳位占用暂存在线边库
 
-            storgeService.lockStorge(targetStore, taskNode.getId());
-            //出入库类型-原料出入库
-            map.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_METERIAL_CRK);
-        }
+//        String moduleName = dataMap.get("moduleName").toString();
+//        //List<ModuleInstruction> instructions = dataMap.get("instructions") == null ? Lists.newArrayList() : (List<ModuleInstruction>)dataMap.get("instructions");
+//        ResourceAutoCode resourceAutoCode = taskNode.getAutoNode();
+//        String functionName = resourceAutoCode.getCommand();
+//
+//
+//        //目标位置
+//        Long targetId = resourceAutoCode.getTargetId();
+//        Storge targetStore = storgeService.getById(targetId);
+//
+//        //开始位置
+//        Storge startStore = workpieceService.getWorkPieceStock(taskNode.getId(),true);
+//
+//        jbwarr = new String[] {targetStore.getNo()};
+//        List<ProductionresourcePosition> jbwList = productionresourcePositionService.getFreeProductionresourcePositionByNos(jbwarr);
+
+//        //TODO还需要验证,开始接驳位是否被其他锁定。并且尚未放置上去。
+//        if (CollectionUtil.isNotEmpty(jbwList)) {
+//            //3、把起始终点库位存放到map,用于接口
+//            map.put("fromStorge", startStore);
+//            map.put("toStorge", targetStore);
+//            //这个节点没有需要验证的内容,都在前一个节点验证并且锁定了
+//            map.put("result", true);
+//
+//            storgeService.lockStorge(targetStore, taskNode.getId());
+//            //出入库类型-原料出入库
+//            map.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_METERIAL_CRK);
+//        }
 
 //        if (BizConstant.MQ_TASK_NODE_TYPE_COMMON.equals(bizType)) {
 //            if (DemoLineConstant.DEMOLINE_OP01_02.equals(taskNode.getNodeNo())) {

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

@@ -17,21 +17,15 @@ import com.github.zuihou.business.operationManagementCenter.entity.TWorkpiece;
 import com.github.zuihou.business.operationManagementCenter.entity.TaskNode;
 import com.github.zuihou.business.operationManagementCenter.service.TaskNodeService;
 import com.github.zuihou.business.operationManagementCenter.service.WorkpieceService;
+import com.github.zuihou.business.productionReadyCenter.dao.BBomMapper;
 import com.github.zuihou.business.productionReadyCenter.dao.BomProcedureMapper;
 import com.github.zuihou.business.productionReadyCenter.dao.BomProcedureTrayMapper;
 import com.github.zuihou.business.productionReadyCenter.entity.BBom;
 import com.github.zuihou.business.productionReadyCenter.entity.BomProcedure;
 import com.github.zuihou.business.productionReadyCenter.entity.BomProcedureTray;
-import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourcePositionMapper;
-import com.github.zuihou.business.productionResourceCenter.dao.ZZoneProductionresourceMapper;
-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.productionResourceCenter.dao.*;
+import com.github.zuihou.business.productionResourceCenter.entity.*;
+import com.github.zuihou.business.productionResourceCenter.service.*;
 import com.github.zuihou.business.util.MsgUtil;
 import com.github.zuihou.common.constant.BizConstant;
 import com.github.zuihou.common.constant.DictionaryKey;
@@ -46,6 +40,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 import static java.util.stream.Collectors.groupingBy;
 
@@ -84,6 +79,14 @@ public class RobotNodeServiceImpl implements NodeOperationService {
     private StockInfoMapper stockInfoMapper;
     @Autowired
     private StorgeMapper storgeMapper;
+    @Autowired
+    private ProductionresourceBizMapper productionresourceBizMapper;
+    @Autowired
+    private ResourceAutoCodeMapper resourceAutoCodeMapper;
+    @Autowired
+    private ZZoneMapper zZoneMapper;
+    @Autowired
+    private BBomMapper bBomMapper;
 
     @Autowired
     private ZZoneService zoneService;
@@ -118,6 +121,8 @@ public class RobotNodeServiceImpl implements NodeOperationService {
 
     private ZZone zZone;
 
+    private Long bomZzoneId;
+
     @Override
     public void initResource(TaskNode taskNode, TTask task, Map dataMap) {
         //productionresourcePosition = getResourcePosition(taskNode);
@@ -143,6 +148,9 @@ public class RobotNodeServiceImpl implements NodeOperationService {
         zoneId = zoneProductionresource.getZoneId();
         zZone = zoneService.getById(zoneId);
         zoneName = zoneService.getById(zoneId).getName();
+        BBom bom = bBomMapper.selectById(task.getBomId());
+        bomZzoneId = bom.getZoneId();
+        task.getBomId();
     }
 
     @Override
@@ -198,6 +206,62 @@ public class RobotNodeServiceImpl implements NodeOperationService {
             currStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
         }
 
+        // 先判断上一指令是否为是否为设备指令,在判断工序最后一个指令是agv动作时锁定锁定agv接驳位
+        TaskNode beforTaskNode = taskNodeService.getNextNTaskNode(taskNode,-1);
+        TaskNode nextTaskNode = taskNodeService.getNextNTaskNode(taskNode,1);
+        TaskNode lastOperationTaskNode = taskNodeService.getOne(Wraps.<TaskNode>lbQ().eq(TaskNode::getTaskId,taskNode.getTaskId()).orderByDesc(TaskNode::getCompleteBatchSort).last("limit 1"));
+
+        Productionresource productionresource =  productionresourceBizMapper.selectById(beforTaskNode.getResourceId());
+        beforTaskNode.setAutoNode(resourceAutoCodeMapper.selectById(beforTaskNode.getAutoNode().getId()));
+        //前序是设备序并且最后一个节点是agv搬运,锁定agv相关库位信息
+        if(beforTaskNode.getTaskId().equals(taskNode.getTaskId()) && "1".equals(beforTaskNode.getAutoNode().getCategory()) && null == lastOperationTaskNode.getResourceId()){
+            ProductionresourcePosition startProductionresourcePosition = null;
+            ProductionresourcePosition endProductionresourcePosition = null;
+            Storge agvStartStationStorge = null;
+            Storge agvEndStationStorge = null;
+            // 判断agv接驳位是可用
+            ZZoneProductionresource zZoneProductionresource = zZoneProductionresourceMapper.selectOne(Wraps.<ZZoneProductionresource>lbQ().eq(ZZoneProductionresource::getResourceId,taskNode.getResourceId()));
+            Map queryParams = new HashMap();
+            queryParams.put("zoneId",zZoneProductionresource.getZoneId());
+            queryParams.put("resourceName","接驳");
+            List<Productionresource> agvStartStationsResources = productionresourceBizMapper.selectResouces(queryParams);
+
+            // 遍历开始接驳位判断是否有可用的接驳位
+            for(Productionresource agvStation : agvStartStationsResources){
+                startProductionresourcePosition = productionresourcePositionMapper.selectOne(Wraps.<ProductionresourcePosition>lbQ().eq(ProductionresourcePosition::getResourceId, agvStation.getId()));
+                List<StockInfo> agvStationMeterails = stockInfoMapper.selectList(Wraps.<StockInfo>lbQ().eq(StockInfo::getStorgeId,endProductionresourcePosition.getStorgeId()));
+                List<String> meterails = agvStationMeterails.stream().map(p -> p.getGoodsType()).collect(Collectors.toList());
+                agvStartStationStorge = storgeService.getById(startProductionresourcePosition.getStorgeId());
+                // 有托板但是没有托盘认为可放
+                if(meterails.contains("5") &&  !meterails.contains("2") && agvStartStationStorge.getStatus().equals("1")){
+                    break;
+                }
+            }
+            queryParams.clear();
+            queryParams.put("zoneId",bomZzoneId);
+            queryParams.put("resourceName","接驳");
+            List<Productionresource> agvEndStationsResources = productionresourceBizMapper.selectResouces(queryParams);
+
+            // 遍历开始接驳位判断是否有可用的接驳位
+            for(Productionresource agvStation : agvEndStationsResources){
+                endProductionresourcePosition = productionresourcePositionMapper.selectOne(Wraps.<ProductionresourcePosition>lbQ().eq(ProductionresourcePosition::getResourceId, agvStation.getId()));
+                List<StockInfo> agvStationMeterails = stockInfoMapper.selectList(Wraps.<StockInfo>lbQ().eq(StockInfo::getStorgeId,endProductionresourcePosition.getStorgeId()));
+                List<String> meterails = agvStationMeterails.stream().map(p -> p.getGoodsType()).collect(Collectors.toList());
+                agvEndStationStorge = storgeService.getById(endProductionresourcePosition.getStorgeId());
+                // 有托板但是没有托盘认为可放
+                if(meterails.contains("5") && !meterails.contains("2") && agvEndStationStorge.getStatus().equals("1")){
+                    break;
+                }
+            }
+
+            if (null != agvStartStationStorge && null != agvEndStationStorge){
+                storgeService.lockStorge(agvStartStationStorge, nextTaskNode.getId());
+                storgeService.lockStorge(agvEndStationStorge, lastOperationTaskNode.getId());
+            }else{
+
+            }
+        }
+
         //目的库位
         Storge jqrStorge = storgeService.getById(robotList.get(0).getStorgeId());
         //目标地址判断