Sfoglia il codice sorgente

后台代码功能处理

oyq28 3 mesi fa
parent
commit
8c1a51cbc0

+ 2 - 0
imcs-admin-boot/imcs-authority-server/src/main/java/com/github/zuihou/AuthorityApplication.java

@@ -5,6 +5,7 @@ import com.github.zuihou.validator.annotation.EnableFormValidator;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.Configuration;
@@ -31,6 +32,7 @@ import java.net.UnknownHostException;
 @EnableFormValidator
 @EnableLoginArgResolver
 @EnableFeignClients("com.github.zuihou")
+@EnableCaching
 public class AuthorityApplication {
     public static void main(String[] args) throws UnknownHostException {
         ConfigurableApplicationContext application = SpringApplication.run(AuthorityApplication.class, args);

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

@@ -2,6 +2,7 @@ package com.github.zuihou.business.mq;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONObject;
@@ -59,6 +60,7 @@ import com.github.zuihou.tenant.entity.ModuleInstruction;
 import com.github.zuihou.tenant.service.ModuleInstructionService;
 import com.github.zuihou.tenant.service.ModuleService;
 import com.google.common.collect.Maps;
+import io.swagger.models.auth.In;
 import jdk.nashorn.internal.runtime.regexp.joni.exception.InternalException;
 import lombok.extern.slf4j.Slf4j;
 import net.sf.jsqlparser.statement.select.KSQLWindow;
@@ -175,9 +177,6 @@ public class TaskWorkNode {
     @Autowired
     private OrderTaskService orderTaskService;
 
-    @Value("${imcs-to-ccs.enabled:true}")
-    private Boolean imcsTOccsEnable;
-
     //总控端口
     private final String ZK_port = "120";
 
@@ -593,7 +592,6 @@ public class TaskWorkNode {
                                         String jsonParam = getRequestParam(conMap);
                                         //缓存执行当前节点传参
                                         msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonParam,3,TimeUnit.DAYS);
-                                        HttpEntity<String> formEntity = new HttpEntity<String>(jsonParam, headers);
 
                                         //动态调用接口和新增指令执行时间
                                         String instructionUrl = conMap.get("instructionUrl") + "/api/" + conMap.get("method").toString();
@@ -607,11 +605,7 @@ public class TaskWorkNode {
                                         }
                                         logger.info("instructionUrl={}" ,instructionUrl);
                                         logger.info("[ECS指令发送]节点传参={}" ,jsonParam);
-                                        if(imcsTOccsEnable){
-                                            returnData = restTemplate.postForObject(instructionUrl, formEntity, String.class);
-                                        }else {
-                                            returnData = "{\"result\": \"true\"}";
-                                        }
+                                        returnData = msgUtil.httpForPost(instructionUrl, jsonParam);
                                     }
                                 }
                             }
@@ -645,10 +639,9 @@ public class TaskWorkNode {
             if (retJson != null) {
                 String code = retJson.getString("result").trim();
                 String concurrency = retJson.containsKey("concurrency")? retJson.getString("concurrency").trim() : "false";
+                String isUpload = retJson.containsKey("isUpload")? retJson.getString("isUpload").trim() : "false";
                 if (code.equals("true")) {
                     //回调处理
-//                    taskNode.setExeStatus("3").setEndTime(new Date()).setExeResult("1");
-//                    taskNodeService.updateAllById(taskNode);
                     log.setExeStatus("2").setEndTime(new Date()).setSendStatus("1").setExeResult("").setFeedback("");
 //                    msgUtil.redis_del(CacheKey.TASK_CURRENT_NODE_CONDITION + "_" + taskNode.getId());
 //                    msgUtil.redis_del(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId());
@@ -657,7 +650,24 @@ public class TaskWorkNode {
 //                    log.setExeResult("0").setManual("1").setFeedback(retJson.getString("msg"));
                     // 释放之前占用的资源 并发延迟带来的异常不释放锁定资源
                     if(concurrency.equals("false")) {
-                        // begin modify by yejian on 20220520 for 解决资源抢占时机器人是空闲状态但是实际上面有料不能操作的时候请求指令接口返回失败后进入死循环问题
+                        //机床程序上传连续失败处理
+                        if(isUpload.equals("true")){
+                             int uploadFailCount = (Integer) msgUtil.redis_get(CacheKey.TASK_UPLOAD_FAIL_COUNT+"_"+taskNode.getId());
+                             if(ObjectUtil.isEmpty(uploadFailCount)){
+                                 msgUtil.redis_set(CacheKey.TASK_UPLOAD_FAIL_COUNT+"_"+taskNode.getId(),0, 7, TimeUnit.DAYS);
+                             }else{
+                                 if(uploadFailCount < 5){
+                                     msgUtil.redis_set(CacheKey.TASK_UPLOAD_FAIL_COUNT+"_"+taskNode.getId(),uploadFailCount++, 7, TimeUnit.DAYS);
+                                 }else{
+                                     //执行失败超过5次 直接改成暂存状态
+                                     taskNode.setExeStatus("4");
+                                     taskNodeService.updateById(taskNode);
+                                     msgUtil.redis_del(CacheKey.TASK_UPLOAD_FAIL_COUNT+"_"+taskNode.getId());
+                                     msgUtil.createWarnLog("上传程序连续失败节点"+taskNode.getId()+"进入暂停状态", "FileUploadException");
+                                 }
+                             }
+                        }
+
                         log.setExeResult("0").setManual("0").setFeedback("设备资源和条件判断不通过");
                         taskNodeService.freeLock(taskNode.getCompleteBatchNo());
                         logger.warn("{}设备资源不通过释放节点", taskNode.getCompleteBatchNo());

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

@@ -94,6 +94,8 @@ public class MsgUtil implements ApplicationContextAware {
     private String filePath;
     @Value("${zuihou.file.storage-path}")
     private String uploadFolder;
+    @Value("${imcs-to-ccs.enabled:true}")
+    private Boolean imcsTOccsEnable;
 
     //@Resource
     @Autowired
@@ -950,7 +952,11 @@ public class MsgUtil implements ApplicationContextAware {
         HttpEntity<String> formEntity = new HttpEntity<String>(params, headers);
         String returnData = null;
         try{
-            returnData = restTemplate.postForObject(url, formEntity, String.class);
+            if(imcsTOccsEnable){
+                returnData = restTemplate.postForObject(url, formEntity, String.class);
+            }else {
+                returnData = "{\"result\": \"true\", \"imcsTOccsEnable\": \"true\"}";
+            }
         }catch(BizException ex){
             logger.error("接口{}数据远程调用失败,参数:{}", url,params);
         }

+ 2 - 7
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/SynProductionStatus.java

@@ -146,15 +146,10 @@ public class SynProductionStatus {
                 LbqWrapper<AAutoNodeLog> lbqWrapper = new LbqWrapper<AAutoNodeLog>();
 
                 lbqWrapper.eq(AAutoNodeLog::getMethod, "GlobalException")
-                        .eq(AAutoNodeLog::getFeedback, "["+ productionresource.getName() +"] "+content).orderByDesc(AAutoNodeLog::getExecuteTime).last("limit 1");
+                        .eq(AAutoNodeLog::getFeedback, "["+ productionresource.getName() +"] "+content).geHeader(AAutoNodeLog::getCreateTime, LocalDateTime.now()).orderByDesc(AAutoNodeLog::getExecuteTime).last("limit 1");
 
                 AAutoNodeLog historyLog = autoNodeLogService.getOne(lbqWrapper);
-                if(null!=historyLog){
-                    //更新节点 更新时间状态
-                    UpdateWrapper<AAutoNodeLog> updateWrapper = new UpdateWrapper<AAutoNodeLog>();
-                    updateWrapper.lambda().eq(AAutoNodeLog::getId, historyLog.getId()).set(AAutoNodeLog::getStatus, "0").set(AAutoNodeLog::getStartTime, new Date()).set(AAutoNodeLog::getEndTime, null).set(AAutoNodeLog::getExecuteTime, new Date());
-                    autoNodeLogService.update(null, updateWrapper);
-                }else{
+                if(null==historyLog){
                     autoNodeLogService.save(autoNodeLog);
                 }
             }

+ 2 - 1
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/operationManagementCenter/ToolQueryController.java

@@ -132,7 +132,7 @@ public class ToolQueryController {
         JSONObject jsonParam = new JSONObject();
         jsonParam.put("state", "1");
         String callbackTaskList = msgUtil.httpForPost(hostSystemUrl + instructionUrl, jsonParam.toJSONString());
-        if (null == callbackTaskList) return R.fail("CCS数据调用失败");
+        if (null == callbackTaskList || callbackTaskList.contains("imcsTOccsEnable")) return R.fail("CCS数据调用失败");
 
         JSONArray jsonArray = JSON.parseArray(callbackTaskList);
         List<Map> mapList = JSONObject.parseArray(jsonArray.toJSONString(), Map.class);
@@ -264,6 +264,7 @@ public class ToolQueryController {
         Date date = DateUtils.addMinutes(new Date(), -20);
         Map map = new HashMap();
         R result = this.getCacheCallbackList(map);
+        if(result.getIsError()) return;
         Map datas = (Map)result.getData();
         List<Map> mapList = (List<Map>)datas.get("data");
         List<Map> resultList = mapList.stream().filter(item->{

+ 25 - 0
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/operationManagementCenter/ToolbarController.java

@@ -20,6 +20,7 @@ import com.github.zuihou.business.edgeLibrary.entity.StockInfo;
 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.externalApi.dao.AgvHikOrderInfoMapper;
 import com.github.zuihou.business.externalApi.dto.ManualInfo;
 import com.github.zuihou.business.externalApi.entity.AgvHikOrderDetailInfo;
 import com.github.zuihou.business.externalApi.entity.AgvHikOrderInfo;
@@ -140,6 +141,8 @@ public class ToolbarController {
     private PlanService planService;
     @Autowired
     private TrayService trayService;
+    @Autowired
+    private AgvHikOrderInfoMapper agvHikOrderInfoMapper;
 
     @ApiOperation(value = "更新库位位置", notes = "更新库位位置")
     @PostMapping("/updateStorge")
@@ -279,6 +282,28 @@ public class ToolbarController {
         String start = data.containsKey("start")? data.get("start").toString() : null;
         String goal = data.containsKey("goal")? data.get("goal").toString() : null;
         if(StringUtils.isEmpty(start) || StringUtils.isEmpty(goal)) return R.fail("数据传参为空");
+
+        String[] startNameCondition = start.split("_");
+        String[] goalNameCondition = goal.split("_");
+        if(startNameCondition.length != 2 || goalNameCondition.length != 2) return R.fail("数据格式传输有误");
+
+        Storge startStorge = storgeService.getOne(new LbqWrapper<Storge>().eq(Storge::getLockStatus,"0").likeRight(Storge::getName, startNameCondition[0]).likeLeft(Storge::getName, startNameCondition[1]).eq(Storge::getPointId, startNameCondition[1]));
+        if(null == startStorge) return R.fail("起始接驳位不可用");
+        Storge goalStorge = storgeService.getOne(new LbqWrapper<Storge>().eq(Storge::getLockStatus,"0").likeRight(Storge::getName, goalNameCondition[0]).likeLeft(Storge::getName, goalNameCondition[1]).eq(Storge::getPointId, goalNameCondition[1]));
+        if(null == goalStorge) return R.fail("目的接驳位不可用");
+
+        //判断是否已被节点目标设备预先锁定
+        Productionresource startDevice = productionresourceBizMapper.selectOne(new LbqWrapper<Productionresource>().eq(Productionresource::getCode, start).last("limit 1"));
+        if(null == startDevice) return R.fail("起始接驳位设备不存在");
+        Productionresource endDevice = productionresourceBizMapper.selectOne(new LbqWrapper<Productionresource>().eq(Productionresource::getCode, goal).last("limit 1"));
+        if(null == endDevice) return R.fail("起始接驳位设备不存在");
+
+        List<Map> agvDataList = agvHikOrderInfoMapper.queryAgvCheck();
+        if(agvDataList.size() > 0){
+           List<Map> dataList = agvDataList.stream().filter(entry->entry.get("target_resource_id").toString() != startDevice.getId().toString() && entry.get("target_resource_id").toString() != endDevice.getId().toString()).collect(Collectors.toList());
+           if(dataList.size() > 0) return R.fail("接驳位已被任务节点锁定");
+        }
+
         Map agvData = new HashMap();
         agvData.put("start", start);
         agvData.put("goal", goal);

+ 0 - 1
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/productionReadyCenter/CuttingToolController.java

@@ -2,7 +2,6 @@ package com.github.zuihou.business.controller.productionReadyCenter;
 
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.github.zuihou.authority.dto.auth.UserPageDTO;
 import com.github.zuihou.authority.entity.core.Org;
 import com.github.zuihou.base.controller.SuperCacheController;

+ 5 - 0
imcs-admin-boot/imcs-common/src/main/java/com/github/zuihou/common/constant/CacheKey.java

@@ -278,6 +278,11 @@ public interface CacheKey {
      */
     String MQ_ROBOT_INTERCEPT = "MQ_ROBOT_INTERCEPT";
 
+    /**
+     * 机床上传程序失败次数
+     */
+    String TASK_UPLOAD_FAIL_COUNT = "TASK_UPLOAD_FAIL_COUNT";
+
 
     /**
      * 构建key