Bladeren bron

后台异常警报和回调重置功能处理

oyq28 4 dagen geleden
bovenliggende
commit
3f735b405e

+ 2 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/AAutoNodeLogService.java

@@ -35,4 +35,6 @@ public interface AAutoNodeLogService extends SuperService<AAutoNodeLog> {
     List<Map> getErrList(Map params);
 
     void synLineWarn(String ips);
+
+    AAutoNodeLog confirmCallback();
 }

+ 24 - 5
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/impl/AAutoNodeLogServiceImpl.java

@@ -28,6 +28,7 @@ import com.github.zuihou.business.util.DynamicRabbitMq;
 import com.github.zuihou.business.util.MsgUtil;
 import com.github.zuihou.common.constant.BizConstant;
 import com.github.zuihou.common.constant.ParameterKey;
+import com.github.zuihou.common.util.DateUtil;
 import com.github.zuihou.common.util.StringUtil;
 import com.github.zuihou.context.BaseContextHandler;
 import com.github.zuihou.database.mybatis.auth.DataScope;
@@ -44,10 +45,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -87,6 +85,8 @@ public class AAutoNodeLogServiceImpl extends SuperServiceImpl<AAutoNodeLogMapper
     @Resource
     private DynamicRabbitMq dynamicRabbitMq;
 
+    //延时阈值约为10分钟
+    private final int TIMEOUT_THRESHOLD_SEC = -600;
 
     @Override
     public IPage<AAutoNodeLog> pageList(IPage page, LbqWrapper<AAutoNodeLog> wrapper, String instructionName) {
@@ -301,4 +301,23 @@ public class AAutoNodeLogServiceImpl extends SuperServiceImpl<AAutoNodeLogMapper
         }
         //非空判断是否本地存储
     }
-}
+
+    @Override
+    public AAutoNodeLog confirmCallback() {
+        LbqWrapper<AAutoNodeLog> lbqWrapper = new LbqWrapper<AAutoNodeLog>();
+        lbqWrapper.eq(AAutoNodeLog::getExeStatus, "2").isNotNull(AAutoNodeLog::getTaskNodeId).isNotNull(AAutoNodeLog::getRequestParameter)
+                .lt(AAutoNodeLog::getStartTime, DateUtil.getAddSecondsTime(new Date(), TIMEOUT_THRESHOLD_SEC)).orderByDesc(AAutoNodeLog::getCreateTime);
+        List<AAutoNodeLog> robotLogList = aAutoNodeLogService.list(lbqWrapper);
+
+        Optional<AAutoNodeLog> aAutoNodeLog = robotLogList.stream().filter(item->{
+            //判断节点是否存在或超时过期
+            TaskNode taskNode = taskNodeService.getById(item.getTaskNodeId());
+            //限定判断时间为同一天
+            return taskNode!=null && !taskNode.getExeStatus().equals("3") && DateUtils.date2LocalDate(item.getStartTime()).equals(LocalDate.now());
+        }).findFirst();
+        if(aAutoNodeLog.isPresent()){
+            return aAutoNodeLog.get();
+        }
+        return null;
+    }
+}

+ 32 - 0
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/ProductionTasksController.java

@@ -20,6 +20,7 @@ import com.github.zuihou.base.request.PageParams;
 import com.github.zuihou.business.controller.operationManagementCenter.OrderController;
 import com.github.zuihou.business.controller.operationManagementCenter.PlanController;
 import com.github.zuihou.business.controller.operationManagementCenter.TaskController;
+import com.github.zuihou.business.controller.operationManagementCenter.ToolbarController;
 import com.github.zuihou.business.edgeLibrary.entity.Storge;
 import com.github.zuihou.business.edgeLibrary.service.StorgeService;
 import com.github.zuihou.business.externalApi.entity.MesNotice;
@@ -75,6 +76,8 @@ import java.util.stream.Stream;
 
 import  com.github.zuihou.business.externalApi.entity.R2;
 
+import javax.annotation.Resource;
+
 @Slf4j
 @Validated
 @RestController
@@ -146,6 +149,12 @@ public class ProductionTasksController {
     @Autowired
     private ProductLinePerformanceService productLinePerformanceService;
 
+    @Autowired
+    private AAutoNodeLogService autoNodeLogService;
+
+    @Resource
+    private ToolbarController toolbarController;
+
 
     //MES->产线
     @ApiOperation(value = "任务下发通知接口", notes = "任务下发通知接口")
@@ -699,6 +708,7 @@ public class ProductionTasksController {
         return R2.success(returnData);
     }
 
+    @PostMapping("/deviceStatusLog/collectDeviceRate")
     @Scheduled(cron="0 0 0 * * ?")
     public R2 collectDeviceRate(){
          BaseContextHandler.setTenant("0000");
@@ -744,4 +754,26 @@ public class ProductionTasksController {
          int rateVal = Math.round(avgActualTime * performanceRate);
         return String.valueOf(rateVal);
      }
+
+    @Scheduled(cron="0 0/3 * * * ?")
+    public R2 syncLineWarn(){
+        BaseContextHandler.setTenant("0000");
+        //判断产线警报信息是否同步
+        String ccsWarnSync = parameterService.getValue(ParameterKey.CCSWARNSYNC, "0");
+        if(ccsWarnSync.equals("1")) {
+            aAutoNodeLogService.synLineWarn("");
+        }
+        String imcsCallbackReset = parameterService.getValue(ParameterKey.IMCSCALLBACKRESET, "0");
+        if(imcsCallbackReset.equals("1")){
+            AAutoNodeLog aAutoNodeLog = aAutoNodeLogService.confirmCallback();
+            if(aAutoNodeLog!=null){
+                Map map = Maps.newHashMap();
+                map.put("taskNodeId", aAutoNodeLog.getTaskNodeId());
+                map.put("taskId", aAutoNodeLog.getTaskId());
+                toolbarController.resend(map);
+                msgUtil.createWarnLog(aAutoNodeLog.getTaskNodeId()+"节点执行错误或重复超时已重置", "DataException");
+            }
+        }
+        return R2.success(true);
+    }
 }

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

@@ -24,6 +24,7 @@ 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;
+import com.github.zuihou.business.externalApi.entity.R2;
 import com.github.zuihou.business.externalApi.service.AgvHikOrderDetailInfoService;
 import com.github.zuihou.business.externalApi.service.AgvHikOrderInfoService;
 import com.github.zuihou.business.operationManagementCenter.dto.OrderUpdateDTO;
@@ -63,6 +64,7 @@ import org.apache.commons.lang.time.DateUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -148,6 +150,9 @@ public class ToolbarController {
     @Autowired
     private AAutoNodeLogService  aAutoNodeLogService;
 
+    @Value("${imcs-to-ccs.enabled:true}")
+    private Boolean imcsTOccsEnable;
+
     @ApiOperation(value = "更新库位位置", notes = "更新库位位置")
     @PostMapping("/updateStorge")
     public R updateStorge(@RequestBody Map<String, String> data) {
@@ -322,32 +327,51 @@ public class ToolbarController {
     @ApiOperation(value = "复位重发指令", notes = "复位重发指令")
     @PostMapping("/resend")
     public R resend(@RequestBody Map<String, String> data) {
-        R result = this.taskNodeHandle("/api/GetCallbackList", data);
-        if (result.getIsError()) return fail("指令不存在");
+        JSONObject jsonObject = null;
         String taskNodeId = data.get("taskNodeId").toString();
         String taskId = data.get("taskId").toString();
-        TTask task = taskService.getById(taskId);
         TaskNode taskNode = taskNodeService.getById(taskNodeId);
-        TaskNode nextNode = taskNodeService.getNextNTaskNode(taskNode, 1);
-        if (task.getStatus().equals("3") || nextNode.getExeStatus().equals("3"))
-            return fail("节点任务已经完成无须重发指令");
-        JSONArray resultData = JSONArray.parseArray(result.getData().toString());
-
-        if (resultData.size() == 0) return fail("回调数据不存在");
-        JSONObject jsonObject = (JSONObject) resultData.get(resultData.size() - 1);
-        if (jsonObject.containsKey("state") && jsonObject.getString("state").equals("true")) {
-            return fail("没有需复位解决的回调数据");
-        }
-        if (jsonObject.containsKey("state") && jsonObject.getString("state").equals("false")) {
-            //更改回调状态和更新cache缓存
-            String hostSystemUrl = (null == msgUtil.redis_get(ParameterKey.PARAMETERS) ? "" : ((Map<String, String>) msgUtil.redis_get(ParameterKey.PARAMETERS)).get(ParameterKey.HOSTSYSTEMURL).toString());
-            String updateReCallState = hostSystemUrl + "/api/UpdateReCallState";
-            JSONObject params = new JSONObject();
-            params.put("TaskNodeId", taskNodeId);
-            params.put("TaskId", taskId);
-            params.put("State", "0");
-            msgUtil.httpForPost(updateReCallState, params.toJSONString());
+        if(StringUtils.isEmpty(taskNodeId) || StringUtils.isEmpty(taskId) || taskNode==null) return R2.fail("传参数据不允许为空");
+
+        if(imcsTOccsEnable){
+            R result = this.taskNodeHandle("/api/GetCallbackList", data);
+            if (result.getIsError()) return fail("指令不存在");
+
+            TTask task = taskService.getById(taskId);
+
+            TaskNode nextNode = taskNodeService.getNextNTaskNode(taskNode, 1);
+            if (task.getStatus().equals("3") || (nextNode!=null && nextNode.getExeStatus().equals("3")))
+                return fail("节点任务已经完成无须重发指令");
+            JSONArray resultData = JSONArray.parseArray(result.getData().toString());
+            if (resultData.size() == 0) return fail("回调数据不存在");
+            jsonObject = (JSONObject) resultData.get(resultData.size() - 1);
+            if (jsonObject.containsKey("state") && jsonObject.getString("state").equals("true")) {
+                return fail("没有需复位解决的回调数据");
+            }
+            if (jsonObject.containsKey("state") && jsonObject.getString("state").equals("false")) {
+                //更改回调状态和更新cache缓存
+                String hostSystemUrl = (null == msgUtil.redis_get(ParameterKey.PARAMETERS) ? "" : ((Map<String, String>) msgUtil.redis_get(ParameterKey.PARAMETERS)).get(ParameterKey.HOSTSYSTEMURL).toString());
+                String updateReCallState = hostSystemUrl + "/api/UpdateReCallState";
+                JSONObject params = new JSONObject();
+                params.put("TaskNodeId", taskNodeId);
+                params.put("TaskId", taskId);
+                params.put("State", "0");
+                msgUtil.httpForPost(updateReCallState, params.toJSONString());
+            }
         }
+            //重发更新节点日志
+
+            //后台缓存处理
+            List object = msgUtil.redis_get_list(YunjianConstant.YUNJIAN_SCHEDULE_LIST);
+            List scheduleList = (object!=null)?msgUtil.redis_get_list(YunjianConstant.YUNJIAN_SCHEDULE_LIST): org.apache.commons.compress.utils.Lists.newArrayList();
+            if(scheduleList.contains(taskNodeId)){
+                String repeatKey = taskNode.getId().toString() + taskNode.getTaskId().toString();
+                String cacheUid = msgUtil.redis_get(repeatKey) == null ? "" : msgUtil.redis_get(repeatKey).toString();
+                if(StringUtils.isNotEmpty(cacheUid)){
+                    msgUtil.redis_del(cacheUid);
+                }
+                msgUtil.redis_fuzzy_del(YunjianConstant.YUNJIAN_SCHEDULE_LIST, taskNodeId);
+            }
         return success();
     }
 
@@ -446,6 +470,7 @@ public class ToolbarController {
         if (StringUtils.isEmpty(taskNodeId) || StringUtils.isEmpty(taskId)) return fail("数据传参为空");
         TaskNode taskNode = taskNodeService.getById(taskNodeId);
         if (null == taskNode) return fail("节点数据不存在");
+        msgUtil.createWarnLog(taskNodeId+"节点手动释放库位锁定", "RunningLockException");
         taskNodeService.freeLock(taskNode.getCompleteBatchNo());
         return success();
     }

+ 8 - 5
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/productionReadyCenter/WarnLogController.java

@@ -81,10 +81,13 @@ public class WarnLogController extends SuperSimpleController<AAutoNodeLogService
         return R.success(baseService.updateStatus(ids));
     }
 
-    @ApiOperation(value = "获取产线报警", notes = "获取产线报警")
-    @PostMapping("/synLineWarn")
-    public R<Boolean> synLineWarn(@RequestParam(value="ips", required = false) String ips) {
-        baseService.synLineWarn(ips);
-        return R.success();
+    @ApiOperation(value = "获取产线报警信息", notes = "获取产线报警信息")
+    @PostMapping("/getLineWarn")
+    public R<List<AAutoNodeLog>> getLineWarn() {
+        LbqWrapper<AAutoNodeLog> warnWrapper = new LbqWrapper<AAutoNodeLog>();
+        warnWrapper.eq(AAutoNodeLog::getExeResult, "0").eq(AAutoNodeLog::getStatus, "0").eq(AAutoNodeLog::getManual, "1")
+                .orderByDesc(AAutoNodeLog::getCreateTime).last("LIMIT 3");
+        List<AAutoNodeLog> dataList = baseService.list(warnWrapper);
+        return R.success(dataList);
     }
 }

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

@@ -89,4 +89,8 @@ public interface ParameterKey {
     //Mes采集数据推送
     String MESDATAPUSH = "mes_data_push";
 
+    String CCSWARNSYNC = "ccs_warn_sync";
+
+    String IMCSCALLBACKRESET = "imcs_callback_reset";
+
 }