|
@@ -67,6 +67,7 @@ import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.locks.ReentrantLock;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
@@ -153,6 +154,8 @@ public class TaskWorkNode {
|
|
|
|
|
|
private final String fileName = "";
|
|
|
|
|
|
+ private static ReentrantLock lock = new ReentrantLock();
|
|
|
+
|
|
|
public void updateTaskStatusJob(String data, String consumerQueue) throws InterruptedException {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
System.out.println("返回请求数据: " + data);
|
|
@@ -240,107 +243,52 @@ public class TaskWorkNode {
|
|
|
String returnData = "";
|
|
|
boolean specialCallBackMyselfFlag = false;
|
|
|
Map conMap = new HashMap();
|
|
|
+ boolean lockFlag = false;
|
|
|
try {
|
|
|
- if ("04".equals(taskNode.getInterfaceType())) {
|
|
|
- //人工上下料或质检
|
|
|
- //不用调接口,直接返回成功
|
|
|
- conMap.put("result",true);
|
|
|
- msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_STATUS + "_" + taskNode.getId(), "0");
|
|
|
- } else {
|
|
|
- Map queryMap = Maps.newHashMap();
|
|
|
- queryMap.put("bizType", bizType);
|
|
|
- queryMap.put("carryType", carryType);
|
|
|
- queryMap.put("handMode", handMode);
|
|
|
- if (jsonObject.containsKey(taskNode.getId() + "count")) {
|
|
|
- queryMap.put(taskNode.getId() + "count", jsonObject.getString(taskNode.getId() + "count"));
|
|
|
- }
|
|
|
+ lockFlag = lock.tryLock(10,TimeUnit.SECONDS);
|
|
|
+ if(lockFlag){
|
|
|
+ if ("04".equals(taskNode.getInterfaceType())) {
|
|
|
+ //人工上下料或质检
|
|
|
+ //不用调接口,直接返回成功
|
|
|
+ conMap.put("result",true);
|
|
|
+ msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_STATUS + "_" + taskNode.getId(), "0");
|
|
|
+ } else {
|
|
|
+ Map queryMap = Maps.newHashMap();
|
|
|
+ queryMap.put("bizType", bizType);
|
|
|
+ queryMap.put("carryType", carryType);
|
|
|
+ queryMap.put("handMode", handMode);
|
|
|
+ if (jsonObject.containsKey(taskNode.getId() + "count")) {
|
|
|
+ queryMap.put(taskNode.getId() + "count", jsonObject.getString(taskNode.getId() + "count"));
|
|
|
+ }
|
|
|
|
|
|
- //把产线放进去,避免多次查询节点业务参数
|
|
|
- ZZoneProductionresource zoneProductionresource = zZoneProductionresourceMapper.selectOne(Wraps.<ZZoneProductionresource>lbQ().eq(ZZoneProductionresource::getResourceId, taskNode.getResourceId()));
|
|
|
- ZZone zZone = zoneService.getById(zoneProductionresource.getZoneId());
|
|
|
- queryMap.put("zone", zZone);
|
|
|
+ //把产线放进去,避免多次查询节点业务参数
|
|
|
+ ZZoneProductionresource zoneProductionresource = zZoneProductionresourceMapper.selectOne(Wraps.<ZZoneProductionresource>lbQ().eq(ZZoneProductionresource::getResourceId, taskNode.getResourceId()));
|
|
|
+ ZZone zZone = zoneService.getById(zoneProductionresource.getZoneId());
|
|
|
+ queryMap.put("zone", zZone);
|
|
|
|
|
|
|
|
|
- BBom bom = bBomMapper.selectById(tTask.getBomId());
|
|
|
- ZZone bomzZone = zoneService.getById(bom.getId());
|
|
|
- queryMap.put("bomzZone", bomzZone);
|
|
|
+ BBom bom = bBomMapper.selectById(tTask.getBomId());
|
|
|
+ ZZone bomzZone = zoneService.getById(bom.getId());
|
|
|
+ queryMap.put("bomzZone", bomzZone);
|
|
|
|
|
|
- //设置workpiece表当前执行的工序
|
|
|
- List<TWorkpiece>list = workpieceMapper.selectList(Wraps.<TWorkpiece>lbQ().eq(TWorkpiece::getCompleteBatchNo,taskNode.getCompleteBatchNo()));
|
|
|
- if(CollectionUtil.isNotEmpty(list)){
|
|
|
- TWorkpiece workpiece = list.get(0);
|
|
|
- workpiece.setProcedureId(tTask.getProcedureId());
|
|
|
- workpiece.setTaskNodeId(Long.parseLong(taskNodeId));
|
|
|
- workpieceMapper.updateById(workpiece);
|
|
|
- }
|
|
|
+ //设置workpiece表当前执行的工序
|
|
|
+ List<TWorkpiece>list = workpieceMapper.selectList(Wraps.<TWorkpiece>lbQ().eq(TWorkpiece::getCompleteBatchNo,taskNode.getCompleteBatchNo()));
|
|
|
+ if(CollectionUtil.isNotEmpty(list)){
|
|
|
+ TWorkpiece workpiece = list.get(0);
|
|
|
+ workpiece.setProcedureId(tTask.getProcedureId());
|
|
|
+ workpiece.setTaskNodeId(Long.parseLong(taskNodeId));
|
|
|
+ workpieceMapper.updateById(workpiece);
|
|
|
+ }
|
|
|
|
|
|
- //运行条件验证
|
|
|
- conMap = checkCon(taskNode, tTask, queryMap);
|
|
|
- msgUtil.redis_set_map(CacheKey.TASK_CURRENT_NODE_CONDITION + "_" + taskNode.getId(), conMap);
|
|
|
- if((boolean)conMap.get("result")){
|
|
|
- if ("03".equals(taskNode.getInterfaceType())) {
|
|
|
- // 执行线边库操作
|
|
|
- if("1".equals(conMap.get("targetxbk"))){
|
|
|
- //组装接口参数
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
|
|
|
- String jsonParam = getRequestParam(conMap);
|
|
|
- //缓存执行当前节点传参
|
|
|
- msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonParam);
|
|
|
- HttpEntity<String> formEntity = new HttpEntity<String>(jsonParam, headers);
|
|
|
-
|
|
|
- //动态调用接口和新增指令执行时间
|
|
|
- log.setZoneId(zZone.getId()).setMethod(conMap.get("method").toString()).setExecuteTime(new Date());
|
|
|
- String instructionUrl = conMap.get("instructionUrl") + "/api/" + conMap.get("method").toString();
|
|
|
- logger.info("instructionUrl=" + instructionUrl);
|
|
|
- logger.info("jsonParam=" + jsonParam);
|
|
|
- returnData = restTemplate.postForObject(instructionUrl, formEntity, String.class);
|
|
|
-
|
|
|
- logger.info("returnData=", returnData);
|
|
|
- }else{
|
|
|
- TaskNode beforTaskNode = taskNodeService.getNextNTaskNode(taskNode, -1);
|
|
|
- // agv搬运
|
|
|
- Map agvData = new HashMap();
|
|
|
- agvData.put("start", conMap.get("start"));
|
|
|
- agvData.put("goal", conMap.get("goal"));
|
|
|
- agvData.put("taskId", tTask.getId().toString());
|
|
|
- agvData.put("taskNodeId", taskNode.getId().toString());
|
|
|
- String jsonParam = getRequestParam(conMap);
|
|
|
- //缓存执行当前节点传参
|
|
|
- msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonParam);
|
|
|
- agvHikOrderInfoService.addHikTask(agvData);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (!"04".equals(taskNode.getInterfaceType())) {
|
|
|
- // 判断当前工序是三坐标或者前一工序是三坐标,分别将三坐标的放和三坐标下一工序的取不调用ccs接口
|
|
|
- String method = conMap.get("method").toString();
|
|
|
- ResourceBusiness resourceBusiness = resourceBusinessService.getById(tTask.getResourceBusinessId());
|
|
|
- TaskNode beforTaskNode = null;
|
|
|
- TTask beforTask = null;
|
|
|
- ResourceBusiness beforResourceBusiness = null;
|
|
|
- if(taskNode.getCompleteBatchSort() != 1){
|
|
|
- beforTaskNode = taskNodeService.getNextNTaskNode(taskNode,-1);
|
|
|
- beforTask = taskMapper.selectById(beforTaskNode.getTaskId());
|
|
|
- beforResourceBusiness = resourceBusinessService.getById(beforTask.getResourceBusinessId());
|
|
|
- }
|
|
|
|
|
|
- if("打标业务".equals(resourceBusiness.getName()) && "SendServoStacker".equals(method)){
|
|
|
- specialCallBackMyselfFlag = true;
|
|
|
- String jsonParam = getRequestParam(conMap);
|
|
|
- //缓存执行当前节点传参
|
|
|
- msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonParam);
|
|
|
- JSONObject ret = new JSONObject();
|
|
|
- ret.put("result","true");
|
|
|
- returnData = ret.toJSONString();
|
|
|
- }else if(resourceBusiness.getName().contains("下料业务") && "GetServoStacker".equals(method) && "打标业务".equals(beforResourceBusiness.getName())){
|
|
|
- specialCallBackMyselfFlag = true;
|
|
|
- String jsonParam = getRequestParam(conMap);
|
|
|
- //缓存执行当前节点传参
|
|
|
- msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonParam);
|
|
|
- JSONObject ret = new JSONObject();
|
|
|
- ret.put("result","true");
|
|
|
- returnData = ret.toJSONString();
|
|
|
- }else{
|
|
|
+
|
|
|
+ //运行条件验证
|
|
|
+ conMap = checkCon(taskNode, tTask, queryMap);
|
|
|
+ msgUtil.redis_set_map(CacheKey.TASK_CURRENT_NODE_CONDITION + "_" + taskNode.getId(), conMap);
|
|
|
+ if((boolean)conMap.get("result")){
|
|
|
+ if ("03".equals(taskNode.getInterfaceType())) {
|
|
|
+ // 执行线边库操作
|
|
|
+ if("1".equals(conMap.get("targetxbk"))){
|
|
|
//组装接口参数
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
|
|
@@ -350,15 +298,78 @@ public class TaskWorkNode {
|
|
|
HttpEntity<String> formEntity = new HttpEntity<String>(jsonParam, headers);
|
|
|
|
|
|
//动态调用接口和新增指令执行时间
|
|
|
- log.setZoneId(zZone.getId()).setMethod(method).setExecuteTime(new Date());
|
|
|
+ log.setZoneId(zZone.getId()).setMethod(conMap.get("method").toString()).setExecuteTime(new Date());
|
|
|
String instructionUrl = conMap.get("instructionUrl") + "/api/" + conMap.get("method").toString();
|
|
|
logger.info("instructionUrl=" + instructionUrl);
|
|
|
logger.info("jsonParam=" + jsonParam);
|
|
|
returnData = restTemplate.postForObject(instructionUrl, formEntity, String.class);
|
|
|
+
|
|
|
+ logger.info("returnData=", returnData);
|
|
|
+ }else{
|
|
|
+ TaskNode beforTaskNode = taskNodeService.getNextNTaskNode(taskNode, -1);
|
|
|
+ // agv搬运
|
|
|
+ Map agvData = new HashMap();
|
|
|
+ agvData.put("start", conMap.get("start"));
|
|
|
+ agvData.put("goal", conMap.get("goal"));
|
|
|
+ agvData.put("taskId", tTask.getId().toString());
|
|
|
+ agvData.put("taskNodeId", taskNode.getId().toString());
|
|
|
+ String jsonParam = getRequestParam(conMap);
|
|
|
+ //缓存执行当前节点传参
|
|
|
+ msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonParam);
|
|
|
+ agvHikOrderInfoService.addHikTask(agvData);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!"04".equals(taskNode.getInterfaceType())) {
|
|
|
+ // 判断当前工序是三坐标或者前一工序是三坐标,分别将三坐标的放和三坐标下一工序的取不调用ccs接口
|
|
|
+ String method = conMap.get("method").toString();
|
|
|
+ ResourceBusiness resourceBusiness = resourceBusinessService.getById(tTask.getResourceBusinessId());
|
|
|
+ TaskNode beforTaskNode = null;
|
|
|
+ TTask beforTask = null;
|
|
|
+ ResourceBusiness beforResourceBusiness = null;
|
|
|
+ if(taskNode.getCompleteBatchSort() != 1){
|
|
|
+ beforTaskNode = taskNodeService.getNextNTaskNode(taskNode,-1);
|
|
|
+ beforTask = taskMapper.selectById(beforTaskNode.getTaskId());
|
|
|
+ beforResourceBusiness = resourceBusinessService.getById(beforTask.getResourceBusinessId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if("打标业务".equals(resourceBusiness.getName()) && "SendServoStacker".equals(method)){
|
|
|
+ specialCallBackMyselfFlag = true;
|
|
|
+ String jsonParam = getRequestParam(conMap);
|
|
|
+ //缓存执行当前节点传参
|
|
|
+ msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonParam);
|
|
|
+ JSONObject ret = new JSONObject();
|
|
|
+ ret.put("result","true");
|
|
|
+ returnData = ret.toJSONString();
|
|
|
+ }else if(resourceBusiness.getName().contains("下料业务") && "GetServoStacker".equals(method) && "打标业务".equals(beforResourceBusiness.getName())){
|
|
|
+ specialCallBackMyselfFlag = true;
|
|
|
+ String jsonParam = getRequestParam(conMap);
|
|
|
+ //缓存执行当前节点传参
|
|
|
+ msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonParam);
|
|
|
+ JSONObject ret = new JSONObject();
|
|
|
+ ret.put("result","true");
|
|
|
+ returnData = ret.toJSONString();
|
|
|
+ }else{
|
|
|
+ //组装接口参数
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
|
|
|
+ String jsonParam = getRequestParam(conMap);
|
|
|
+ //缓存执行当前节点传参
|
|
|
+ msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonParam);
|
|
|
+ HttpEntity<String> formEntity = new HttpEntity<String>(jsonParam, headers);
|
|
|
+
|
|
|
+ //动态调用接口和新增指令执行时间
|
|
|
+ log.setZoneId(zZone.getId()).setMethod(method).setExecuteTime(new Date());
|
|
|
+ String instructionUrl = conMap.get("instructionUrl") + "/api/" + conMap.get("method").toString();
|
|
|
+ logger.info("instructionUrl=" + instructionUrl);
|
|
|
+ logger.info("jsonParam=" + jsonParam);
|
|
|
+ returnData = restTemplate.postForObject(instructionUrl, formEntity, String.class);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }else{
|
|
|
+ conMap.put("result",false);
|
|
|
}
|
|
|
} catch (BizException e) {
|
|
|
e.printStackTrace();
|
|
@@ -367,6 +378,8 @@ public class TaskWorkNode {
|
|
|
errJsonObject.put("msg", e.getMessage());
|
|
|
returnData = errJsonObject.toJSONString();
|
|
|
logger.error("调用接口发生异常" + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
} finally {
|
|
|
logger.info("最终检查结果conMap=" + conMap);
|
|
|
logger.info("===============================接口返回" + returnData);
|
|
@@ -382,13 +395,29 @@ public class TaskWorkNode {
|
|
|
msgUtil.redis_del(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId());
|
|
|
} else if (code.equals("false")) {
|
|
|
//需要人工处理解决警报异常
|
|
|
- log.setExeResult("0").setManual("1").setFeedback(retJson.getString("msg"));
|
|
|
+// log.setExeResult("0").setManual("1").setFeedback(retJson.getString("msg"));
|
|
|
+ // begin modify by yejian on 20220520 for 解决资源抢占时机器人是空闲状态但是实际上面有料不能操作的时候请求指令接口返回失败后进入死循环问题
|
|
|
+ log.setExeResult("0").setManual("0").setFeedback("设备资源不通过");
|
|
|
+ // 释放之前占用的资源
|
|
|
+ String occupyResources = conMap.get("occupyResources")==null?"":(String)conMap.get("occupyResources");
|
|
|
+ String[] occupyResourcesArray = occupyResources.split(",");
|
|
|
+ for (String occupyResource : occupyResourcesArray){
|
|
|
+ Storge storge = storgeService.getById(Long.valueOf(occupyResource));
|
|
|
+ if("0".equals(storge.getLockStatus())){
|
|
|
+ storge.setLockStatus("1");
|
|
|
+ storgeService.updateById(storge);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ conMap.put("result",false);
|
|
|
+ // end modify by yejian on 20220520 for 解决资源抢占时机器人是空闲状态但是实际上面有料不能操作的时候请求指令接口返回失败后进入死循环问题
|
|
|
+
|
|
|
} else if (code.equals("exception")) {
|
|
|
//执行异常处理(无须人工处理和警报提示)
|
|
|
log.setExeResult("0").setManual("0").setFeedback(retJson.getString("msg"));
|
|
|
}
|
|
|
}else{
|
|
|
// 非人工序
|
|
|
+ logger.info("节点{}名称{}类型{}",taskNode.getId(),taskNode.getNodeName(),taskNode.getInterfaceType());
|
|
|
if (!"04".equals(taskNode.getInterfaceType())) {
|
|
|
if((boolean)conMap.get("result")){
|
|
|
log.setExeResult("0").setManual("0").setFeedback("接口响应超时");
|
|
@@ -396,13 +425,13 @@ public class TaskWorkNode {
|
|
|
log.setExeResult("0").setManual("0").setFeedback("设备资源不通过");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
if (log.getId() == null) {
|
|
|
autoNodeLogService.save(log);
|
|
|
} else {
|
|
|
autoNodeLogService.updateAllById(log);
|
|
|
}
|
|
|
+ logger.info("specialCallBackMyselfFlag={}",specialCallBackMyselfFlag);
|
|
|
if(specialCallBackMyselfFlag){
|
|
|
// 打标机特殊处理
|
|
|
JSONObject callBackData = new JSONObject();
|
|
@@ -417,9 +446,14 @@ public class TaskWorkNode {
|
|
|
HttpEntity<String> formEntity = new HttpEntity<String>(callBackData.toJSONString(), headers);
|
|
|
restTemplate.postForObject(taskNodeCallbackUrl, formEntity, String.class);
|
|
|
}
|
|
|
+ if(lockFlag){
|
|
|
+ lock.unlock();
|
|
|
+ logger.info("节点{}名称{}释放锁",taskNode.getId(),taskNode.getNodeName());
|
|
|
+ }
|
|
|
if(!(boolean)conMap.get("result")){
|
|
|
throw new InterruptedException("设备资源不通过,消息重新进入队尾");
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -821,6 +855,14 @@ public class TaskWorkNode {
|
|
|
|
|
|
dataMap.put("method", "MoveRobotPosition");
|
|
|
dataMap.put("result", true);
|
|
|
+
|
|
|
+ // begin modify by yejian on 20220520 for 解决资源抢占时机器人是空闲状态但是实际上面有料不能操作的时候请求指令接口返回失败后进入死循环问题
|
|
|
+ // TODO 后续可改成信号对接判断,先如果返回失败释放资源进去队列重新轮训
|
|
|
+ // 返回内容中记录当前任务占用资源
|
|
|
+ String occupyResources = jqrStorge.getId() + "," + hcwStorge.getId() + "," + targetStorge.getId();
|
|
|
+ dataMap.put("occupyResources",occupyResources);
|
|
|
+ // end modify by yejian on 20220520 for 解决资源抢占时机器人是空闲状态但是实际上面有料不能操作的时候请求指令接口返回失败后进入死循环问题
|
|
|
+
|
|
|
}else{
|
|
|
dataMap.put("result", false);
|
|
|
}
|
|
@@ -940,6 +982,13 @@ public class TaskWorkNode {
|
|
|
//目标缓存
|
|
|
msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + taskNode.getId(), targetStorge, 1, TimeUnit.DAYS);
|
|
|
dataMap.put("result", true);
|
|
|
+
|
|
|
+ // begin modify by yejian on 20220520 for 解决资源抢占时机器人是空闲状态但是实际上面有料不能操作的时候请求指令接口返回失败后进入死循环问题
|
|
|
+ // TODO 后续可改成信号对接判断,先如果返回失败释放资源进去队列重新轮训
|
|
|
+ // 返回内容中记录当前任务占用资源
|
|
|
+ String occupyResources = jqrStorge.getId() + "," + targetStorge.getId();
|
|
|
+ dataMap.put("occupyResources",occupyResources);
|
|
|
+ // end modify by yejian on 20220520 for 解决资源抢占时机器人是空闲状态但是实际上面有料不能操作的时候请求指令接口返回失败后进入死循环问题
|
|
|
}else{
|
|
|
dataMap.put("result", false);
|
|
|
}
|