Ver Fonte

增加robot AGV接驳位找到后更新tasknode表的目标接驳位信息,agv任务下发

yejian há 3 anos atrás
pai
commit
e89be59826

+ 4 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/externalApi/service/AgvHikOrderInfoService.java

@@ -1,11 +1,14 @@
 package com.github.zuihou.business.externalApi.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.zuihou.base.R;
 import com.github.zuihou.base.service.SuperCacheService;
 import com.github.zuihou.business.externalApi.entity.AgvHikOrderInfo;
 import com.github.zuihou.business.externalApi.entity.AgvOrderInfo;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
 
+import java.util.Map;
+
 /**
  * <p>
  * 业务接口
@@ -33,4 +36,5 @@ public interface AgvHikOrderInfoService extends SuperCacheService<AgvHikOrderInf
      */
     AgvHikOrderInfo updateAgvOrderInfo(AgvHikOrderInfo agvHikOrderInfo);
 
+    R addHikTask(Map<String, String> data);
 }

+ 116 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/externalApi/service/impl/AgvHikOrderInfoServiceImpl.java

@@ -1,21 +1,45 @@
 package com.github.zuihou.business.externalApi.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.zuihou.authority.service.common.ParameterService;
+import com.github.zuihou.base.R;
 import com.github.zuihou.base.service.SuperCacheServiceImpl;
 import com.github.zuihou.business.externalApi.dao.AgvHikOrderInfoMapper;
 import com.github.zuihou.business.externalApi.dao.AgvOrderInfoMapper;
+import com.github.zuihou.business.externalApi.entity.AgvHikOrderDetailInfo;
 import com.github.zuihou.business.externalApi.entity.AgvHikOrderInfo;
+import com.github.zuihou.business.externalApi.entity.AgvOrderDetailInfo;
 import com.github.zuihou.business.externalApi.entity.AgvOrderInfo;
+import com.github.zuihou.business.externalApi.service.AgvHikOrderDetailInfoService;
 import com.github.zuihou.business.externalApi.service.AgvHikOrderInfoService;
 import com.github.zuihou.business.externalApi.service.AgvOrderInfoService;
+import com.github.zuihou.common.constant.BizConstant;
 import com.github.zuihou.common.constant.CacheKey;
+import com.github.zuihou.common.constant.ParameterKey;
+import com.github.zuihou.common.util.UniqueKeyGenerator;
+import com.github.zuihou.context.BaseContextHandler;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
 import com.github.zuihou.injection.annonation.InjectionResult;
 import com.github.zuihou.utils.BeanPlusUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.Calendar;
+import java.util.Map;
 
 /**
  * <p>
@@ -30,6 +54,14 @@ import org.springframework.transaction.annotation.Transactional;
 @Service
 
 public class AgvHikOrderInfoServiceImpl extends SuperCacheServiceImpl<AgvHikOrderInfoMapper, AgvHikOrderInfo> implements AgvHikOrderInfoService {
+    @Autowired
+    private RedisTemplate<String,Object> redisTemplate;
+    @Autowired
+    private ParameterService parameterService;
+    @Autowired
+    private RestTemplate restTemplate;
+    @Autowired
+    private AgvHikOrderDetailInfoService agvHikOrderDetailInfoService;
 
     @Override
     protected String getRegion() {
@@ -58,4 +90,88 @@ public class AgvHikOrderInfoServiceImpl extends SuperCacheServiceImpl<AgvHikOrde
 
         return agvHikOrderInfo;
     }
+
+    @Override
+    public R addHikTask(Map<String, String> data){
+        BaseContextHandler.setTenant(BizConstant.TENANT);
+        R ret = null;
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+
+        String addAgvTaskUrl = "";
+        if(null==redisTemplate.opsForValue().get(ParameterKey.ADDTASK)){
+            addAgvTaskUrl = parameterService.getValue(ParameterKey.ADDTASK, null);
+            if(StringUtils.isEmpty(addAgvTaskUrl)){
+                ret = R.fail("agv任务创建地址未配置");
+            }else{
+                redisTemplate.opsForValue().set(ParameterKey.ADDTASK,addAgvTaskUrl);
+            }
+        }else{
+            addAgvTaskUrl = (String)redisTemplate.opsForValue().get(ParameterKey.ADDTASK);
+        }
+        log.info("addAgvTaskUrl{}",addAgvTaskUrl);
+        String start = data.get("start");
+        String goal = data.get("goal");
+        String taskCode = UniqueKeyGenerator.getUniqueKeyStartWithTimestamp(64);
+        String reqTime = DateUtil.format(Calendar.getInstance().getTime(), DatePattern.NORM_DATETIME_MS_PATTERN);
+        String taskId = data.get("taskId");
+        String taskNodeId = data.get("taskNodeId");
+        // 组装创建AGV任务数据入库
+        AgvHikOrderInfo agvOrderInfo = new AgvHikOrderInfo();
+        agvOrderInfo.setStart(start);
+        agvOrderInfo.setStartAction("00");
+        agvOrderInfo.setGoal(goal);
+        agvOrderInfo.setGoalAction("00");
+        agvOrderInfo.setTaskId(taskId);
+        agvOrderInfo.setTaskNodeId(taskNodeId);
+        agvOrderInfo.setTaskCode(taskCode);
+        agvOrderInfo.setReqTime(reqTime);
+        baseMapper.insert(agvOrderInfo);
+
+        // 组装出入库申请详情数据入库,方便后续回调时数据记录及比对
+        String reqCode = UniqueKeyGenerator.getUniqueKeyStartWithTimestamp(32);
+        JSONObject jsonObject = new JSONObject();
+        JSONArray positionCodePath = new JSONArray();
+        JSONObject begin = new JSONObject();
+        begin.put("positionCode",start);
+        begin.put("type","00");
+        JSONObject end = new JSONObject();
+        end.put("positionCode", goal);
+        end.put("type","00");
+        positionCodePath.add(0,begin);
+        positionCodePath.add(1,end);
+        jsonObject.put("reqCode",reqCode);
+        jsonObject.put("taskTyp","F01");
+        jsonObject.put("positionCodePath",positionCodePath.toJSONString());
+        jsonObject.put("taskCode",taskCode);
+        HttpEntity<String> addAgvTaskRequest = new HttpEntity<String>(jsonObject.toJSONString(), headers);
+
+        ResponseEntity<String> addAgvTaskEntity = restTemplate.postForEntity(addAgvTaskUrl, addAgvTaskRequest, String.class);
+
+        String retData = addAgvTaskEntity.getBody();
+
+        JSONObject returnData = JSONObject.parseObject(retData);
+
+        log.info("请求创建AGV运输任务返回{},请求参数{}",returnData,jsonObject.toString());
+
+        // 组装请求回调内容
+        AgvHikOrderDetailInfo agvOrderDetailInfo = new AgvHikOrderDetailInfo();
+        agvOrderDetailInfo.setReqCode(reqCode);
+        agvOrderDetailInfo.setTaskCode(taskCode);
+        agvOrderDetailInfo.setRequestTime(reqTime);
+
+        if("0".equals(returnData.getString("code"))){
+            // 解析返回的AGV任务号
+            String agvTaskId = String.valueOf(returnData.getJSONArray("data").get(0));
+            redisTemplate.opsForValue().set(agvTaskId,taskId+"-"+taskNodeId);
+            agvOrderInfo.setResponseCode(returnData.getString("code"));
+            agvOrderInfo.setResponseTime(DateUtil.format(Calendar.getInstance().getTime(), DatePattern.NORM_DATETIME_MS_PATTERN));
+            baseMapper.updateAllById(agvOrderInfo);
+            ret = R.success("AGV创建任务申请成功");
+        }else{
+            ret = R.fail(999999,"AGV创建任务申请失败");
+        }
+        agvHikOrderDetailInfoService.save(agvOrderDetailInfo);
+        return R.success();
+    }
 }

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

@@ -11,6 +11,7 @@ import com.github.zuihou.business.edgeLibrary.dao.StockInfoMapper;
 import com.github.zuihou.business.edgeLibrary.entity.StockInfo;
 import com.github.zuihou.business.edgeLibrary.entity.Storge;
 import com.github.zuihou.business.edgeLibrary.service.StorgeService;
+import com.github.zuihou.business.externalApi.service.AgvHikOrderInfoService;
 import com.github.zuihou.business.operationManagementCenter.dao.OrderMapper;
 import com.github.zuihou.business.operationManagementCenter.dao.PlanMapper;
 import com.github.zuihou.business.operationManagementCenter.dao.TTaskMapper;
@@ -128,6 +129,8 @@ public class TaskWorkNode {
 
     @Autowired
     private ZZoneService zoneService;
+    @Autowired
+    private AgvHikOrderInfoService agvHikOrderInfoService;
 
 
     //总控端口
@@ -154,6 +157,7 @@ public class TaskWorkNode {
         BaseContextHandler.setTenant("0000");
 
         TaskNode taskNode = taskNodeService.getById(taskNodeId);
+        TaskNode beforTaskNode = taskNodeService.getNextNTaskNode(taskNode,-1);
         if (taskNode == null || taskNode.getTaskId()== null) {
             throw new InterruptedException("当前任务节点为空");
         }
@@ -221,14 +225,25 @@ public class TaskWorkNode {
                 queryMap.put("zone",zZone);
                 //运行条件验证
                 Map conMap = checkCon(taskNode, tTask, queryMap);
-                //组装接口参数
-                HttpHeaders headers = new HttpHeaders();
-                headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
-                String jsonParam = getRequestParam(conMap);
-                HttpEntity<String> formEntity = new HttpEntity<String>(jsonParam, headers);
-                //动态调用接口
-                String instructionUrl = DictionaryKey.INSTRUCTION_URL +"/api/"+ conMap.get("method").toString() ;
-                returnData = restTemplate.postForObject(instructionUrl, formEntity, String.class);
+
+                if(null == taskNode.getResourceId()){
+                    // agv搬运
+                    Map agvData = new HashMap();
+                    agvData.put("start",beforTaskNode.getTargetResourceId());
+                    agvData.put("goal", taskNode.getTargetResourceId());
+                    agvData.put("taskId",tTask.getId());
+                    agvData.put("taskNodeId",taskNode.getId());
+                    agvHikOrderInfoService.addHikTask(agvData);
+                }else{
+                    //组装接口参数
+                    HttpHeaders headers = new HttpHeaders();
+                    headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
+                    String jsonParam = getRequestParam(conMap);
+                    HttpEntity<String> formEntity = new HttpEntity<String>(jsonParam, headers);
+                    //动态调用接口
+                    String instructionUrl = DictionaryKey.INSTRUCTION_URL +"/api/"+ conMap.get("method").toString() ;
+                    returnData = restTemplate.postForObject(instructionUrl, formEntity, String.class);
+                }
             }
         } catch (Exception e) {
             e.printStackTrace();

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

@@ -224,7 +224,8 @@ public class RobotNodeServiceImpl implements NodeOperationService {
             queryParams.put("zoneId",zZoneProductionresource.getZoneId());
             queryParams.put("resourceName","接驳");
             List<Productionresource> agvStartStationsResources = productionresourceBizMapper.selectResouces(queryParams);
-
+            Productionresource startAgvStation = null;
+            Productionresource endAgvStation = null;
             // 遍历开始接驳位判断是否有可用的接驳位
             for(Productionresource agvStation : agvStartStationsResources){
                 startProductionresourcePosition = productionresourcePositionMapper.selectOne(Wraps.<ProductionresourcePosition>lbQ().eq(ProductionresourcePosition::getResourceId, agvStation.getId()));
@@ -233,6 +234,7 @@ public class RobotNodeServiceImpl implements NodeOperationService {
                 agvStartStationStorge = storgeService.getById(startProductionresourcePosition.getStorgeId());
                 // 有托板但是没有托盘认为可放
                 if(meterails.contains("5") &&  !meterails.contains("2") && agvStartStationStorge.getStatus().equals("1")){
+                    startAgvStation = agvStation;
                     break;
                 }
             }
@@ -249,6 +251,7 @@ public class RobotNodeServiceImpl implements NodeOperationService {
                 agvEndStationStorge = storgeService.getById(endProductionresourcePosition.getStorgeId());
                 // 有托板但是没有托盘认为可放
                 if(meterails.contains("5") && !meterails.contains("2") && agvEndStationStorge.getStatus().equals("1")){
+                    endAgvStation = agvStation;
                     break;
                 }
             }
@@ -256,8 +259,22 @@ public class RobotNodeServiceImpl implements NodeOperationService {
             if (null != agvStartStationStorge && null != agvEndStationStorge){
                 storgeService.lockStorge(agvStartStationStorge, nextTaskNode.getId());
                 storgeService.lockStorge(agvEndStationStorge, lastOperationTaskNode.getId());
+                // 将agv相关的节点的目标节点地址更新进tasknode表
+                nextTaskNode.setTargetResourceId(startAgvStation.getId());
+                lastOperationTaskNode.setTargetResourceId(endAgvStation.getId());
+                taskNodeService.updateById(nextTaskNode);
+                taskNodeService.updateById(lastOperationTaskNode);
+                map.put("bizType","agv");
             }else{
-
+                // 获取机器人操作线边库
+                xbkArr = new String[]{DictionaryKey.YJ_ZONE_XBK.get(zoneName)};
+                xbkList = productionresourcePositionService.getFreeProductionresourcePositionByNos(xbkArr);
+                if(CollectionUtil.isNotEmpty(xbkList)){
+                    ProductionresourcePosition position = xbkList.get(0);
+                    // TODO 应该需要合并到getTargetStorge 方法中
+//                    targetStorge = storgeService.getById(position.getStorgeId());
+                    map.put("bizType","xbk");
+                }
             }
         }
 

+ 9 - 7
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/util/ManualTaskOperatorUtil.java

@@ -19,24 +19,26 @@ public class ManualTaskOperatorUtil {
      * 上位机系统地址
      */
 //    private static String hostSyetemUrl = "http://192.168.170.240:8090";
+    /**
+     * 黄哥模拟接口地址,模式调试时改成38
+      */
     private static String hostSyetemUrl = "http://192.168.170.248:8081/";
-
     /**
      * agv运输
      */
     private static String agvURL = "http://localhost:9099/api/authority/mock/mockWms";
-    //质量中心
+    // 保障平台
     private static String ZK_ip_zlzx = "192.168.170.130";
-    //柔性
+    //框体
     private static String ZK_ip_rxx = "192.168.170.170";
-    //智能单元(舱体
+    //舱体
     private static String ZK_ip_zndy = "192.168.170.150";
 
-    // 质量中心PLC端口
+    // 障平台PLC端口
     private static String ZK_ip_zlzx_port = "102";
-    // 柔性线端口
+    // 框体端口
     private  static String ZK_ip_rxx_port = "102";
-    // 智能单元端口
+    // 舱体端口
     private static String ZK_ip_zndy_port = "102";
 
     /**

+ 8 - 3
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/HikAgvControl.java

@@ -6,6 +6,8 @@ import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.github.zuihou.authority.service.common.ParameterService;
 import com.github.zuihou.base.R;
+import com.github.zuihou.base.controller.SuperController;
+import com.github.zuihou.business.externalApi.dto.*;
 import com.github.zuihou.business.externalApi.entity.AgvHikOrderDetailInfo;
 import com.github.zuihou.business.externalApi.entity.AgvHikOrderInfo;
 import com.github.zuihou.business.externalApi.entity.AgvOrderDetailInfo;
@@ -53,7 +55,7 @@ import java.util.Map;
 @RequestMapping("/agv/agvCallbackService")
 @Api(value = "AgvInfo", tags = "agv交互")
 @SysLog(enabled = true)
-public class HikAgvControl {
+public class HikAgvControl extends SuperController<AgvHikOrderInfoService, Long, AgvHikOrderInfo, AgvHikOrderInfoPageDTO, AgvHikOrderInfoSaveDTO, AgvHikOrderInfoUpdateDTO> {
     @Autowired
     private RedisTemplate<String,Object> redisTemplate;
     @Resource
@@ -64,8 +66,6 @@ public class HikAgvControl {
     private AgvHikOrderDetailInfoService agvHikOrderDetailInfoService;
     @Autowired
     private AgvHikOrderInfoService agvHikOrderInfoService;
-    @Autowired
-    private ExternalApiService externalApiService;
 
     @ApiOperation(value = "agv任务完成回调", notes = "agv任务完成回调")
     @PostMapping("/agvCallback")
@@ -218,4 +218,9 @@ public class HikAgvControl {
         }
         return flag;
     }
+
+    @PostMapping("/addHikTask")
+    public R addHikTask(@RequestBody Map<String, String> data) {
+        return baseService.addHikTask(data);
+    }
 }

+ 2 - 2
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/externalApi/entity/AgvHikOrderInfo.java

@@ -55,14 +55,14 @@ public class AgvHikOrderInfo extends Entity<Long> {
      */
     @ApiModelProperty(value = "起点动作")
     @TableField("start_action")
-    private int startAction;
+    private String startAction;
 
     /**
      *  终点动作
      */
     @ApiModelProperty(value = "终点动作")
     @TableField("goal_action")
-    private int goalAction;
+    private String goalAction;
 
     /**
      *  下单请求时间