lxb 1 năm trước cách đây
mục cha
commit
18770b2101

+ 207 - 20
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/impl/ToolRobotNodeServiceImpl.java

@@ -3,6 +3,7 @@ package com.github.zuihou.business.productionResourceCenter.service.impl;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.github.zuihou.business.DemoLine.DemoLineConstant;
 import com.github.zuihou.business.DemoLine.DemoLineConstant;
+import com.github.zuihou.business.DemoLine.YunjianConstant;
 import com.github.zuihou.business.centralToolMagazine.entity.TaskNodeTool;
 import com.github.zuihou.business.centralToolMagazine.entity.TaskNodeTool;
 import com.github.zuihou.business.centralToolMagazine.entity.ToolStorge;
 import com.github.zuihou.business.centralToolMagazine.entity.ToolStorge;
 import com.github.zuihou.business.centralToolMagazine.entity.ToolTask;
 import com.github.zuihou.business.centralToolMagazine.entity.ToolTask;
@@ -19,6 +20,7 @@ import com.github.zuihou.business.operationManagementCenter.service.ToolTaskServ
 import com.github.zuihou.business.operationManagementCenter.service.ToolWorkpieceService;
 import com.github.zuihou.business.operationManagementCenter.service.ToolWorkpieceService;
 import com.github.zuihou.business.productionReadyCenter.dao.BBomMapper;
 import com.github.zuihou.business.productionReadyCenter.dao.BBomMapper;
 import com.github.zuihou.business.productionReadyCenter.entity.BBom;
 import com.github.zuihou.business.productionReadyCenter.entity.BBom;
+import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourcePositionMapper;
 import com.github.zuihou.business.productionResourceCenter.dao.ZZoneProductionresourceMapper;
 import com.github.zuihou.business.productionResourceCenter.dao.ZZoneProductionresourceMapper;
 import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
 import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
 import com.github.zuihou.business.productionResourceCenter.entity.Tool;
 import com.github.zuihou.business.productionResourceCenter.entity.Tool;
@@ -33,6 +35,7 @@ import com.github.zuihou.common.constant.DictionaryKey;
 import com.github.zuihou.common.constant.ParameterKey;
 import com.github.zuihou.common.constant.ParameterKey;
 import com.github.zuihou.common.util.StringUtil;
 import com.github.zuihou.common.util.StringUtil;
 import com.github.zuihou.database.mybatis.conditions.Wraps;
 import com.github.zuihou.database.mybatis.conditions.Wraps;
+import com.github.zuihou.database.mybatis.conditions.query.QueryWrap;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
@@ -40,6 +43,8 @@ import org.springframework.stereotype.Service;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 
 import static java.util.stream.Collectors.groupingBy;
 import static java.util.stream.Collectors.groupingBy;
 
 
@@ -97,6 +102,9 @@ public class ToolRobotNodeServiceImpl implements ToolNodeOperationService {
 
 
     private static String URL = "http://192.168.0.0.1:8099/api/RobotAction";
     private static String URL = "http://192.168.0.0.1:8099/api/RobotAction";
 
 
+    @Autowired
+    private ProductionresourcePositionMapper productionresourcePositionMapper;
+
     @Override
     @Override
     public void initResource(ToolTaskNode taskNode, ToolTask task, Map dataMap) {
     public void initResource(ToolTaskNode taskNode, ToolTask task, Map dataMap) {
         String moduleName = dataMap.get("moduleName") == null ? "" : dataMap.get("moduleName").toString();
         String moduleName = dataMap.get("moduleName") == null ? "" : dataMap.get("moduleName").toString();
@@ -122,7 +130,6 @@ public class ToolRobotNodeServiceImpl implements ToolNodeOperationService {
 
 
     @Override
     @Override
     public Map checkCondition(ToolTaskExecute toolTaskExecute, Map<String, Object> dataMap) throws InterruptedException {
     public Map checkCondition(ToolTaskExecute toolTaskExecute, Map<String, Object> dataMap) throws InterruptedException {
-
         //更新状态
         //更新状态
         if(toolTaskExecute.getStatus() == 0){
         if(toolTaskExecute.getStatus() == 0){
             toolTaskExecute.setStatus(1);
             toolTaskExecute.setStatus(1);
@@ -147,26 +154,170 @@ public class ToolRobotNodeServiceImpl implements ToolNodeOperationService {
             toolTaskService.updateById(toolTask);
             toolTaskService.updateById(toolTask);
         }
         }
 
 
+        Map map = new HashMap();
 
 
+        //int count = Integer.parseInt(dataMap.get(toolTaskExecute.getId().toString() + "count") == null ? "0" : dataMap.get(toolTaskExecute.getId().toString() + "count").toString());
+        int count = 0; //移动取放不分开
         //判断command 指令
         //判断command 指令
         if ("1".equals(toolTaskExecute.getCommand()) || "2".equals(toolTaskExecute.getCommand())) {
         if ("1".equals(toolTaskExecute.getCommand()) || "2".equals(toolTaskExecute.getCommand())) {
-            //取放动作
-            JSONObject jsonObject = new JSONObject();
-            jsonObject.put("url", "192.168.10.101");
-            jsonObject.put("port", "102");
-            jsonObject.put("taskId", toolTaskExecute.getToolTaskId());
-            jsonObject.put("taskNodeId", toolTaskExecute.getId()); //为了和托盘保持一致,实际取的是执行表的ID
-            Map<String, Object> data = new HashMap<>();
-            data.put("location", toolTaskExecute.getStartPoint());
-            data.put("destLocation", toolTaskExecute.getEndPoint());
-            data.put("toolStorgeNo", toolTaskExecute.getToolStorgeNo()); // 刀位号
-            jsonObject.put("data",data);
+            //取动作
+            if(count == 0){ //移动
+                //第一步的时候设置缓存
+                Long robotResourceId = this.getAndLockRobot();
+                ToolStorge startStorge = (ToolStorge)msgUtil.redis_get(DemoLineConstant.TOOL_START_STORE + "_" + toolTaskExecute.getId());
+                ToolStorge targetStore = (ToolStorge)msgUtil.redis_get(DemoLineConstant.TOOL_TARGET_STORE + "_" + toolTaskExecute.getId());
+
+                JSONObject callBackParam = new JSONObject();
+                callBackParam.put("srcStorgeId",startStorge.getId());
+                callBackParam.put("targetStorgeId",targetStore.getId());
+                callBackParam.put(toolTaskExecute.getId() + "count",count);
+                callBackParam.put(DemoLineConstant.TOOL_TASK_TYPE + "_" + toolTaskExecute.getId(),DemoLineConstant.TOOL_TASK_TYPE_CARRY);
+
+                //回调参数
+                msgUtil.redis_set(YunjianConstant.TOOL_CALLBACK_PARAM + "_" + toolTaskExecute.getId(),callBackParam.toString(),10,TimeUnit.DAYS);
+
+                //获取机器人当前所在的位置
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("url", "192.168.10.101");
+                jsonObject.put("port", "102");
+                jsonObject.put("taskId", toolTaskExecute.getToolTaskId());
+                jsonObject.put("taskNodeId", toolTaskExecute.getId()); //为了和托盘保持一致,实际取的是执行表的ID
+
+                Map<String, Object> data = new HashMap<>();
+                data.put("taskType",DictionaryKey.TASK_TYPE.get("CARRY"));
+                data.put("carryType",DictionaryKey.CARRY_TYPE.get("TOOL"));
+                data.put("location", toolTaskExecute.getStartPoint());
+                data.put("destLocation", toolTaskExecute.getEndPoint());
+                jsonObject.put("data",data);
+
+                log.info("请求参数:{}",jsonObject.toString());
+
+                if("1".equals(toolTaskExecute.getCommand())){
+                    // 记录机器人移动到对应设备
+                    msgUtil.redis_set("JQR_RESOURCE",startStorge.getResourceId());
+                }else{
+                    // 记录机器人移动到对应设备
+                    msgUtil.redis_set("JQR_RESOURCE",targetStore.getResourceId());
+                }
 
 
-            log.info("请求参数:{}",jsonObject.toString());
+                //msgUtil.httpForPost(URL,jsonObject.toString());
+
+            }else if(count == 1){
+                //取
+                ToolStorge startStorge = (ToolStorge)msgUtil.redis_get(DemoLineConstant.TOOL_START_STORE + "_" + toolTaskExecute.getId());
+                ToolStorge jqrHandStorge = (ToolStorge)msgUtil.redis_get(YunjianConstant.YUNJIAN_TOOL_JXS + "_" + toolTaskExecute.getId());
+
+                JSONObject callBackParam = new JSONObject();
+                callBackParam.put("srcStorgeId",startStorge.getId());
+                callBackParam.put("targetStorgeId",jqrHandStorge.getId());
+                callBackParam.put(toolTaskExecute.getId() + "count",count);
+                callBackParam.put(DemoLineConstant.TOOL_TASK_TYPE + "_" + toolTaskExecute.getId(),DemoLineConstant.TOOL_TASK_TYPE_CARRY);
+                //回调参数
+                msgUtil.redis_set(YunjianConstant.TOOL_CALLBACK_PARAM + "_" + toolTaskExecute.getId(),callBackParam.toString(),10,TimeUnit.DAYS);
+
+                //获取机器人当前所在的位置
+                String robotPosition = msgUtil.redis_get("ROBOT_POSITION").toString();
+                JSONObject jsonObject = new JSONObject();
+
+                jsonObject.put("url", "192.168.10.101");
+                jsonObject.put("port", "102");
+                jsonObject.put("taskId", toolTaskExecute.getToolTaskId());
+                jsonObject.put("taskNodeId", toolTaskExecute.getId()); //为了和托盘保持一致,实际取的是执行表的ID
+
+
+                Map<String, Object> data = new HashMap<>();
+                data.put("location", robotPosition);
+                data.put("destLocation", jqrHandStorge.getPointId());
+                data.put("taskType",DictionaryKey.TASK_TYPE.get("CARRY"));
+                data.put("carryType",DictionaryKey.CARRY_TYPE.get("TOOL"));
+
+                jsonObject.put("data",data);
+
+                log.info("请求参数:{}",jsonObject.toString());
+
+                //msgUtil.httpForPost(URL,jsonObject.toString());
+            }else if(count == 2){
+                //读RFID
+                JSONObject callBackParam = new JSONObject();
+                callBackParam.put(DemoLineConstant.TOOL_TASK_TYPE + "_" + toolTaskExecute.getId(),DemoLineConstant.TOOL_TASK_TYPE_READ);
+                callBackParam.put(toolTaskExecute.getId() + "count",count);
+                //回调参数
+                msgUtil.redis_set(YunjianConstant.TOOL_CALLBACK_PARAM + "_" + toolTaskExecute.getId(),callBackParam.toString(),10,TimeUnit.DAYS);
+
+
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("url", "192.168.10.101");
+                jsonObject.put("port", "102");
+                jsonObject.put("taskId", toolTaskExecute.getToolTaskId());
+                jsonObject.put("taskNodeId", toolTaskExecute.getId()); //为了和托盘保持一致,实际取的是执行表的ID
+                Map<String, Object> data = new HashMap<>();
+                jsonObject.put("data",data);
+                data.put("taskType",DictionaryKey.TASK_TYPE.get("READ_WRITE"));
+
+                log.info("请求参数:{}",jsonObject.toString());
+
+                //msgUtil.httpForPost(URL,jsonObject.toString());
+            }else if(count == 3){
+                //写RFID
+                JSONObject callBackParam = new JSONObject();
+                callBackParam.put(DemoLineConstant.TOOL_TASK_TYPE + "_" + toolTaskExecute.getId(),DemoLineConstant.TOOL_TASK_TYPE_WRITE);
+                callBackParam.put(toolTaskExecute.getId() + "count",count);
+                //回调参数
+                msgUtil.redis_set(YunjianConstant.TOOL_CALLBACK_PARAM + "_" + toolTaskExecute.getId(),callBackParam.toString(),10,TimeUnit.DAYS);
+
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("url", "192.168.10.101");
+                jsonObject.put("port", "102");
+                jsonObject.put("taskId", toolTaskExecute.getToolTaskId());
+                jsonObject.put("taskNodeId", toolTaskExecute.getId()); //为了和托盘保持一致,实际取的是执行表的ID
+                jsonObject.put("taskType",DictionaryKey.TASK_TYPE.get("READ_WRITE"));
+                Map<String, Object> data = new HashMap<>();
+                jsonObject.put("data",data);
+
+                log.info("请求参数:{}",jsonObject.toString());
+
+                //msgUtil.httpForPost(URL,jsonObject.toString());
+            }else if(count == 4){
+                //放
+                ToolStorge jqrHandStorge = (ToolStorge)msgUtil.redis_get(YunjianConstant.YUNJIAN_TOOL_JXS + "_" + toolTaskExecute.getId());
+                ToolStorge targetStorge = (ToolStorge)msgUtil.redis_get(DemoLineConstant.TOOL_TARGET_STORE + "_" + toolTaskExecute.getId());
+
+                JSONObject callBackParam = new JSONObject();
+                callBackParam.put("srcStorgeId",jqrHandStorge.getId());
+                callBackParam.put("targetStorgeId",targetStorge.getId());
+                callBackParam.put(toolTaskExecute.getId() + "count",count);
+                callBackParam.put(DemoLineConstant.TOOL_TASK_TYPE + "_" + toolTaskExecute.getId(),DemoLineConstant.TOOL_TASK_TYPE_CARRY);
+                //回调参数
+                msgUtil.redis_set(YunjianConstant.TOOL_CALLBACK_PARAM + "_" + toolTaskExecute.getId(),callBackParam.toString(),10,TimeUnit.DAYS);
+
+
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("url", "192.168.10.101");
+                jsonObject.put("port", "102");
+                jsonObject.put("taskId", toolTaskExecute.getToolTaskId());
+                jsonObject.put("taskNodeId", toolTaskExecute.getId()); //为了和托盘保持一致,实际取的是执行表的ID
+                jsonObject.put("taskType",DictionaryKey.TASK_TYPE.get("CARRY"));
+                jsonObject.put("carryType",DictionaryKey.CARRY_TYPE.get("TOOL"));
+
+                Map<String, Object> data = new HashMap<>();
+                jsonObject.put("data",data);
+                data.put("location", jqrHandStorge.getPointId());
+                data.put("destLocation", targetStorge.getPointId());
+
+                jsonObject.put("data",data);
+
+                log.info("请求参数:{}",jsonObject.toString());
+
+                //msgUtil.httpForPost(URL,jsonObject.toString());
+            }
 
 
-            msgUtil.httpForPost(URL,jsonObject.toString());
         }else if("3".equals(toolTaskExecute.getCommand()) || "4".equals(toolTaskExecute.getCommand())){
         }else if("3".equals(toolTaskExecute.getCommand()) || "4".equals(toolTaskExecute.getCommand())){
             //程序上传/启动程序
             //程序上传/启动程序
+            JSONObject callBackParam = new JSONObject();
+            callBackParam.put(DemoLineConstant.TOOL_TASK_TYPE + "_" + toolTaskExecute.getId(),DemoLineConstant.TOOL_TASK_TYPE_PRO);
+            //回调参数
+            msgUtil.redis_set(YunjianConstant.TOOL_CALLBACK_PARAM + "_" + toolTaskExecute.getId(),callBackParam.toString(),10,TimeUnit.DAYS);
+
             JSONObject jsonObject = new JSONObject();
             JSONObject jsonObject = new JSONObject();
             jsonObject.put("url", "192.168.10.101");
             jsonObject.put("url", "192.168.10.101");
             jsonObject.put("port", "102");
             jsonObject.put("port", "102");
@@ -177,17 +328,19 @@ public class ToolRobotNodeServiceImpl implements ToolNodeOperationService {
             jsonObject.put("data",data);
             jsonObject.put("data",data);
             log.info("请求参数:{}",jsonObject.toString());
             log.info("请求参数:{}",jsonObject.toString());
             if("3".equals(toolTaskExecute.getCommand())){
             if("3".equals(toolTaskExecute.getCommand())){
-                msgUtil.httpForPost(URL,jsonObject.toString());
+               // msgUtil.httpForPost(URL,jsonObject.toString());
             }else{
             }else{
-                msgUtil.httpForPost(URL,jsonObject.toString());
+               // msgUtil.httpForPost(URL,jsonObject.toString());
             }
             }
 
 
-        }else if("5".equals(toolTaskExecute.getCommand())){
-            //读RFID
-        }else if("6".equals(toolTaskExecute.getCommand())){
-            //写RFID
         }else if("7".equals(toolTaskExecute.getCommand())){
         }else if("7".equals(toolTaskExecute.getCommand())){
             //换手抓
             //换手抓
+            JSONObject callBackParam = new JSONObject();
+            callBackParam.put(DemoLineConstant.TOOL_TASK_TYPE + "_" + toolTaskExecute.getId(),DemoLineConstant.TASK_TYPE_CHANGE);
+            callBackParam.put(toolTaskExecute.getId() + "HAND_TYPE",DictionaryKey.CARRY_TYPE.get("TOOL_HAND"));
+            //回调参数
+            msgUtil.redis_set(YunjianConstant.TOOL_CALLBACK_PARAM + "_" + toolTaskExecute.getId(),callBackParam.toString(),10,TimeUnit.DAYS);
+            this.changeToolRobotHand(toolTaskExecute);
         }
         }
 
 
         //更新当前任务状态
         //更新当前任务状态
@@ -197,6 +350,40 @@ public class ToolRobotNodeServiceImpl implements ToolNodeOperationService {
         return dataMap;
         return dataMap;
     }
     }
 
 
+    public void changeToolRobotHand(ToolTaskExecute toolTaskExecute){
+        JSONObject jsonObject = new JSONObject();
+
+        jsonObject.put("taskId", String.valueOf(toolTaskExecute.getToolTaskId()));
+        jsonObject.put("taskNodeId", String.valueOf(toolTaskExecute.getId()));
+
+        jsonObject.put("taskType", DictionaryKey.TASK_TYPE.get("CHANGE"));
+        jsonObject.put("carryType", DictionaryKey.CARRY_TYPE.get("TOOL_HAND"));
+        jsonObject.put("url", "");
+        jsonObject.put("port", "");
+        Map map = new HashMap();
+        map.put("location",DictionaryKey.HAND_PONIT.get("TOOL_HAND"));
+        map.put("destLocation",DictionaryKey.ROBOT_PONIT.get("CHANGE_HAND"));
+        jsonObject.put("data", map);
+
+        //msgUtil.httpForPost("http://192.168.10.150",jsonObject.toString());
+    }
+
+    //查询和锁定机器人
+    public Long getAndLockRobot() throws InterruptedException {
+        Long robotResourceId = null;
+        //查询机器人状态,锁定机器人*****
+        ProductionresourcePosition productionresourcePosition = productionresourcePositionMapper.selectOne(new QueryWrap<ProductionresourcePosition>().lambda().like(ProductionresourcePosition::getName, "FMS_机器人_手抓"));
+        if("0".equals(productionresourcePosition.getStatus())){
+            //未锁定
+            productionresourcePosition.setStatus("1"); //锁定机器人
+            productionresourcePositionMapper.updateById(productionresourcePosition);
+            robotResourceId = productionresourcePosition.getResourceId();
+        }else{
+            log.info("当前机器人已被锁定,不满足条件,重新回到队尾");
+            throw new InterruptedException("当前机器人已被锁定,不满足条件,重新回到队尾");
+        }
+        return robotResourceId;
+    }
     private Map<String, Object> commandHandle(Map<String, Object> dataMap) throws InterruptedException {
     private Map<String, Object> commandHandle(Map<String, Object> dataMap) throws InterruptedException {
         ToolTaskNode taskNode = (ToolTaskNode) dataMap.get("taskNode");
         ToolTaskNode taskNode = (ToolTaskNode) dataMap.get("taskNode");
         ToolTask task = (ToolTask) dataMap.get("task");
         ToolTask task = (ToolTask) dataMap.get("task");