|
@@ -1,13 +1,10 @@
|
|
|
package com.github.zuihou.business.mq;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.github.zuihou.authority.service.common.ParameterService;
|
|
|
import com.github.zuihou.business.DemoLine.DemoCacheKey;
|
|
|
import com.github.zuihou.business.DemoLine.DemoLineConstant;
|
|
|
import com.github.zuihou.business.edgeLibrary.entity.Storge;
|
|
|
-import com.github.zuihou.business.edgeLibrary.service.StockInfoService;
|
|
|
import com.github.zuihou.business.edgeLibrary.service.StorgeService;
|
|
|
import com.github.zuihou.business.operationManagementCenter.dao.OrderMapper;
|
|
|
import com.github.zuihou.business.operationManagementCenter.dao.PlanMapper;
|
|
@@ -16,28 +13,15 @@ import com.github.zuihou.business.operationManagementCenter.dao.TaskNodeMapper;
|
|
|
import com.github.zuihou.business.operationManagementCenter.entity.TTask;
|
|
|
import com.github.zuihou.business.operationManagementCenter.entity.TaskNode;
|
|
|
import com.github.zuihou.business.operationManagementCenter.service.TaskNodeService;
|
|
|
-import com.github.zuihou.business.operationManagementCenter.service.TaskService;
|
|
|
-import com.github.zuihou.business.operationManagementCenter.service.WorkpieceService;
|
|
|
import com.github.zuihou.business.productionReadyCenter.dao.AutoNodeLogMapper;
|
|
|
-import com.github.zuihou.business.productionReadyCenter.dao.AutoNodeMapper;
|
|
|
-import com.github.zuihou.business.productionReadyCenter.dao.BomProcedureProgramGroupMapper;
|
|
|
-import com.github.zuihou.business.productionReadyCenter.dao.BomProcedureTrayMapper;
|
|
|
import com.github.zuihou.business.productionReadyCenter.entity.AAutoNodeLog;
|
|
|
-import com.github.zuihou.business.productionReadyCenter.entity.BomProcedure;
|
|
|
-import com.github.zuihou.business.productionReadyCenter.entity.BomProcedureProgramGroup;
|
|
|
-import com.github.zuihou.business.productionReadyCenter.service.AutoNodeService;
|
|
|
-import com.github.zuihou.business.productionReadyCenter.service.BomProcedureService;
|
|
|
-import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourcePositionMapper;
|
|
|
import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
|
|
|
-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.impl.AGVNodeServiceImpl;
|
|
|
import com.github.zuihou.business.productionResourceCenter.service.impl.MachineNodeServiceImpl;
|
|
|
import com.github.zuihou.business.productionResourceCenter.service.impl.RobotNodeServiceImpl;
|
|
|
import com.github.zuihou.business.util.MsgUtil;
|
|
|
-import com.github.zuihou.business.websocket.WebSocketServer;
|
|
|
import com.github.zuihou.common.constant.BizConstant;
|
|
|
import com.github.zuihou.common.constant.CacheKey;
|
|
|
import com.github.zuihou.common.constant.DictionaryKey;
|
|
@@ -59,37 +43,26 @@ import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
-import static java.util.stream.Collectors.groupingBy;
|
|
|
-
|
|
|
@Component
|
|
|
public class TaskWorkNode {
|
|
|
- @Autowired
|
|
|
- private BomProcedureService bomProcedureService;
|
|
|
- @Autowired
|
|
|
- private TaskService taskService;
|
|
|
- @Autowired
|
|
|
- private AutoNodeService autoNodeService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BomProcedureTrayMapper bomProcedureTrayMapper;
|
|
|
@Autowired
|
|
|
private OrderMapper orderMapper;
|
|
|
@Autowired
|
|
|
private PlanMapper planMapper;
|
|
|
@Autowired
|
|
|
- private AutoNodeMapper autoNodeMapper;
|
|
|
- @Autowired
|
|
|
private TTaskMapper taskMapper;
|
|
|
@Autowired
|
|
|
private AutoNodeLogMapper autoNodeLogMapper;
|
|
|
@Autowired
|
|
|
- private BomProcedureProgramGroupMapper bomProcedureProgramGroupMapper;
|
|
|
- @Autowired
|
|
|
- private ParameterService parameterService;
|
|
|
- @Autowired
|
|
|
private RestTemplate restTemplate;
|
|
|
@Autowired
|
|
|
private TaskNodeService taskNodeService;
|
|
@@ -100,27 +73,15 @@ public class TaskWorkNode {
|
|
|
@Autowired
|
|
|
private StorgeService storgeService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private StockInfoService stockInfoService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ProductionresourcePositionMapper productionresourcePositionMapper;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ProductionresourcePositionService productionresourcePositionService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private WorkpieceService workpieceService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ProductionresourceService productionresourceService;
|
|
|
|
|
|
@Autowired
|
|
|
private MsgUtil msgUtil;
|
|
|
|
|
|
- @Autowired
|
|
|
- private ZZoneProductionresourceService zZoneProductionresourceService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ModuleService moduleService;
|
|
|
|
|
@@ -172,7 +133,8 @@ public class TaskWorkNode {
|
|
|
for (TTask task : taskList) {
|
|
|
try {
|
|
|
//把本次待执行任务全部改成进行中
|
|
|
- if ("1".equals(task.getStatus())) {//下发的数据才更新状态
|
|
|
+ if ("1".equals(task.getStatus())) {
|
|
|
+ //下发的数据才更新状态
|
|
|
task.setStatus("2");
|
|
|
task.setStartTime(new Date());
|
|
|
taskMapper.updateById(task);
|
|
@@ -184,8 +146,6 @@ public class TaskWorkNode {
|
|
|
}
|
|
|
//获取每个节点对应的执行地址
|
|
|
String autoProgrameUrl = getInterfaceUrl(taskNode);
|
|
|
- //判断节点设备类型
|
|
|
- String[] category = getResourceCategory(taskNode.getResourceId().toString());
|
|
|
|
|
|
//把当前节点存放缓存
|
|
|
msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE + "_" + task.getResourceId(), taskNode.getAutoNode().getId());
|
|
@@ -225,22 +185,6 @@ public class TaskWorkNode {
|
|
|
queryMap.put(taskNode.getId() + "count", j.getString(taskNode.getId() + "count"));
|
|
|
}
|
|
|
|
|
|
- if ("1" == category[0]) {
|
|
|
- nodeOperationService = new MachineNodeServiceImpl();
|
|
|
- queryMap.put("zonId", category[1]);
|
|
|
- queryMap.put("categoryName", category[2]);
|
|
|
- nodeOperationService.initResource(taskNode, task, queryMap);
|
|
|
- } else if ("2" == category[0]) {
|
|
|
- queryMap.put("zonId", category[1]);
|
|
|
- nodeOperationService = new AGVNodeServiceImpl();
|
|
|
- nodeOperationService.initResource(taskNode, task, queryMap);
|
|
|
- } else if ("3" == category[0]) {
|
|
|
- queryMap.put("zonId", category[1]);
|
|
|
- nodeOperationService = new RobotNodeServiceImpl();
|
|
|
- nodeOperationService.initResource(taskNode, task, queryMap);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
//运行条件验证
|
|
|
Map conMap = checkCon(taskNode, task, queryMap);
|
|
|
//组装接口参数
|
|
@@ -295,11 +239,11 @@ public class TaskWorkNode {
|
|
|
return autoProgrameUrl;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private String[] getResourceCategory(String resourceId) {
|
|
|
Productionresource productionresource = productionresourceService.getOne(new QueryWrap<Productionresource>().eq("id", resourceId));
|
|
|
- ZZoneProductionresource zZoneProductionresource = zZoneProductionresourceService.getOne(new QueryWrap<ZZoneProductionresource>().eq("resource_id", productionresource.getId()));
|
|
|
Module module = moduleService.getById(new QueryWrap<Module>().eq("id", productionresource.getModuleId()));
|
|
|
- return new String[]{productionresource.getResourcesCategory(), zZoneProductionresource.getZoneId().toString(), module.getName()};
|
|
|
+ return new String[]{productionresource.getResourcesCategory(), module.getName()};
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -400,63 +344,29 @@ public class TaskWorkNode {
|
|
|
bizJsonObject.put(DemoLineConstant.DEMOLINE_XBK_TYPE, xbkType);
|
|
|
bizJsonObject.put(DemoLineConstant.DEMOLINE_XBK_CARRY_TYPE, carryType);
|
|
|
}
|
|
|
- } else if (DictionaryKey.INTERFACETYPE_PRO.equals(taskNode.getInterfaceType())) {
|
|
|
- jsonObject.put("url", task.getIp());
|
|
|
- jsonObject.put("port", task.getPort());
|
|
|
- jsonObject.put("IsCallBackFlag", "1");
|
|
|
- //搬运类型,拿-放
|
|
|
- String carryRequest = conMap.get(DemoLineConstant.DEMOLINE_BIZ_TYPE) == null ? "" : conMap.get(DemoLineConstant.DEMOLINE_BIZ_TYPE).toString();
|
|
|
- jsonObject.put("BusinessType", carryRequest);
|
|
|
-
|
|
|
- //执行程序标志
|
|
|
- String exePrograme = conMap.get(DemoLineConstant.DEMOLINE_EXEPRO_FLAG) == null ? "" : conMap.get(DemoLineConstant.DEMOLINE_EXEPRO_FLAG).toString();
|
|
|
- bizJsonObject.put(DemoLineConstant.DEMOLINE_EXEPRO_FLAG, exePrograme);
|
|
|
-
|
|
|
- String data = conMap.get("Data") == null ? "" : conMap.get("Data").toString();
|
|
|
- if (StringUtil.isNotEmpty(data)) {
|
|
|
- jsonObject.put("Data", data);
|
|
|
- }
|
|
|
+ }
|
|
|
+ else if (DictionaryKey.INTERFACETYPE_PRO.equals(taskNode.getInterfaceType())) {
|
|
|
+ //生产加工
|
|
|
+ nodeOperationService = new MachineNodeServiceImpl();
|
|
|
+ conMap.put("NO_WMS", true);
|
|
|
+ Map map = nodeOperationService.operation(jsonObject, bizJsonObject, conMap);
|
|
|
+ jsonObject = (JSONObject) map.get("jsonObject");
|
|
|
+ bizJsonObject = (JSONObject) map.get("bizJsonObject");
|
|
|
} else if (DictionaryKey.INTERFACETYPE_AGV.equals(taskNode.getInterfaceType())) {
|
|
|
- //AGV取料--接驳位A到B或C
|
|
|
- nodeOperationService.operation(conMap);
|
|
|
- } else if (DictionaryKey.INTERFACETYPE_WMS.equals(taskNode.getInterfaceType())) {
|
|
|
+ //AGV取料
|
|
|
+ nodeOperationService = new AGVNodeServiceImpl();
|
|
|
+ Map map = nodeOperationService.operation(jsonObject, bizJsonObject,conMap);
|
|
|
+ jsonObject = (JSONObject) map.get("jsonObject");
|
|
|
+ bizJsonObject = (JSONObject) map.get("bizJsonObject");
|
|
|
+ }
|
|
|
+ else if (DictionaryKey.INTERFACETYPE_WMS.equals(taskNode.getInterfaceType())) {
|
|
|
//WMS分出库和入库
|
|
|
//通过自动化程序的CODE区分是上料还是下料
|
|
|
- String wmsType = conMap.get(DemoLineConstant.DEMOLINE_WMS_TYPE) == null ? "" : conMap.get(DemoLineConstant.DEMOLINE_WMS_TYPE).toString();
|
|
|
- //物料类型0-毛坯1-成品
|
|
|
- String goodsType = conMap.get(DemoLineConstant.DEMOLINE_GOODS_TYPE) == null ? "" : conMap.get(DemoLineConstant.DEMOLINE_GOODS_TYPE).toString();
|
|
|
-
|
|
|
- String locationName = conMap.get("locationName") == null ? "" : conMap.get("locationName").toString();
|
|
|
-
|
|
|
- String boxes = conMap.get("boxes") == null ? "" : conMap.get("boxes").toString();
|
|
|
-
|
|
|
- if (DemoLineConstant.DEMOLINE_WMS_CHUKU.equals(wmsType)) {
|
|
|
- jsonObject.put("jobType", "wmsDown");
|
|
|
- } else {
|
|
|
- jsonObject.put("jobType", "wmsUp");
|
|
|
- //3-货物入库1-无物入库
|
|
|
- jsonObject.put("type", "3");
|
|
|
- }
|
|
|
- jsonObject.put("transferType", "wms");
|
|
|
-
|
|
|
- jsonObject.put("locationName", locationName);
|
|
|
-
|
|
|
- jsonObject.put("boxes", boxes);
|
|
|
- //WMS只能出一个
|
|
|
-// jsonObject.put("goodsQua", 1);
|
|
|
-
|
|
|
-
|
|
|
- if (DemoLineConstant.DEMOLINE_GOODS_TYPE_MAOPI.equals(goodsType)) {//毛坯
|
|
|
- jsonObject.put("goodsId", task.getMeterialId());
|
|
|
- } else {
|
|
|
- jsonObject.put("goodsId", task.getBomId());
|
|
|
- }
|
|
|
-
|
|
|
- Storge fstorge = (Storge) conMap.get("fromStorge");
|
|
|
- Storge tstorge = (Storge) conMap.get("toStorge");
|
|
|
- //此数据用来业务回传
|
|
|
- bizJsonObject.put("srcPosition", fstorge == null ? "" : fstorge.getId().toString());
|
|
|
- bizJsonObject.put("targetPostion", tstorge == null ? "" : tstorge.getId().toString());
|
|
|
+ conMap.put("NO_WMS", false);
|
|
|
+ nodeOperationService = new MachineNodeServiceImpl();
|
|
|
+ Map map = nodeOperationService.operation(jsonObject, bizJsonObject, conMap);
|
|
|
+ jsonObject = (JSONObject) map.get("jsonObject");
|
|
|
+ bizJsonObject = (JSONObject) map.get("bizJsonObject");
|
|
|
}
|
|
|
|
|
|
//业务回调数据,传给接口,接口再返回过来。
|
|
@@ -468,7 +378,6 @@ public class TaskWorkNode {
|
|
|
return jsonObject.toJSONString();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 轮询验证。
|
|
|
*
|
|
@@ -477,17 +386,43 @@ public class TaskWorkNode {
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public Map checkCon(TaskNode taskNode, TTask task, Map<String, Object> dataMap) throws Exception {
|
|
|
- Map map = getCheckCon(taskNode, task, dataMap);
|
|
|
- boolean b = (boolean) map.get("result");
|
|
|
- if (!b) {
|
|
|
- Thread.sleep(10000);
|
|
|
- return checkCon(taskNode, task, dataMap);
|
|
|
- } else {
|
|
|
+ public Map checkCon(TaskNode taskNode, TTask task, Map<String, Object> dataMap) throws Exception {
|
|
|
+// Map map = getCheckCon(taskNode, task, dataMap);
|
|
|
+// boolean b = (boolean) map.get("result");
|
|
|
+// if (!b) {
|
|
|
+// Thread.sleep(10000);
|
|
|
+// return checkCon(taskNode, task, dataMap);
|
|
|
+// } else {
|
|
|
+// return map;
|
|
|
+// }
|
|
|
+ logger.info("异步消息获取执行状态:");
|
|
|
+ ExecutorService pool = Executors.newCachedThreadPool();
|
|
|
+ CompletableFuture<Map> future = CompletableFuture.supplyAsync(()->{
|
|
|
+ Map map = Maps.newHashMap();
|
|
|
+ try {
|
|
|
+ TimeUnit.SECONDS.sleep(2);
|
|
|
+ map = getCheckCon(taskNode, task, dataMap);
|
|
|
+ }
|
|
|
+ catch(InterruptedException e){
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
return map;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ }, pool);
|
|
|
+ future.whenCompleteAsync((v, ex) ->{
|
|
|
+ if(ex == null){
|
|
|
+ Map map = future.join();
|
|
|
+ boolean bool = (boolean) map.get("result");
|
|
|
+ if(bool){
|
|
|
+ logger.info("条件判断成功,关闭线程池");
|
|
|
+ pool.shutdown();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException(ex);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ return future.join();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 具体验证
|
|
@@ -503,10 +438,22 @@ public class TaskWorkNode {
|
|
|
//具体的搬运类型
|
|
|
String carryType = dataMap.get("carryType") == null ? "" : dataMap.get("carryType").toString();
|
|
|
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
+ //判断节点设备类型
|
|
|
+ String[] category = getResourceCategory(taskNode.getResourceId().toString());
|
|
|
+ if ("1" == category[0]) {
|
|
|
+ nodeOperationService = new MachineNodeServiceImpl();
|
|
|
+ } else if ("2" == category[0]) {
|
|
|
+ nodeOperationService = new AGVNodeServiceImpl();
|
|
|
+ } else if ("3" == category[0]) {
|
|
|
+ nodeOperationService = new RobotNodeServiceImpl();
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
map.put("taskNode", taskNode);
|
|
|
map.put("task", task);
|
|
|
map.put("bizType", bizType);
|
|
|
+ map.put("categoryName", category[1]);
|
|
|
+
|
|
|
|
|
|
//线边库轮询两个机械手和接驳位资源。如果两个都有空则从线边库搬运到接驳位
|
|
|
if (BizConstant.MQ_TASK_NODE_TYPE_STORAGE_WAIT_ZLZX.equals(bizType)) {
|
|
@@ -705,6 +652,7 @@ public class TaskWorkNode {
|
|
|
}
|
|
|
else if (DemoLineConstant.DEMOLINE_OP01_07.equals(taskNode.getNodeNo())) {
|
|
|
//机器人取料(机器人从人工上料站取料放到机械手)
|
|
|
+ map.put("robotType", DemoLineConstant.JQR1);
|
|
|
map = nodeOperationService.checkCondition(taskNode,task,map);
|
|
|
}
|
|
|
else if (DemoLineConstant.DEMOLINE_OP01_08.equals(taskNode.getNodeNo())) {
|