Ver Fonte

更新wbs节点状态使用线程池

wangming há 1 mês atrás
pai
commit
b69164b52f

+ 2 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ProjectWbsNodeServiceImpl.java

@@ -6,12 +6,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.rongwei.bscommon.sys.service.ZhcxItpProjectNodeStateService;
+import com.rongwei.bscommon.sys.utils.ZhcxCommon;
 import com.rongwei.bsentity.domain.ProjectWbsNodeDo;
 import com.rongwei.bscommon.sys.dao.ProjectWbsNodeDao;
 import com.rongwei.bscommon.sys.service.ProjectWbsNodeService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.rongwei.bsentity.domain.ZhcxItpProjectNodeStateDo;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 import java.util.HashMap;

+ 13 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/utils/ZhcxCommon.java

@@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.json.JSONUtil;
 import com.aspose.words.Document;
 import com.rongwei.bscommon.sys.feign.SysNotifyFeginService;
+import com.rongwei.bscommon.sys.service.ProjectWbsNodeService;
 import com.rongwei.bsentity.dto.NotifyDto;
 import com.rongwei.commonservice.service.RedisService;
 import com.rongwei.rwadmincommon.system.domain.PagePartDo;
@@ -47,6 +48,9 @@ public class ZhcxCommon {
     @Autowired
     private SysGeneralCRUDService sysGeneralCRUDService;
 
+    @Autowired
+    private ProjectWbsNodeService projectWbsNodeService;
+
     public SysUserVo getCurrentUser() {
         // 获取当前登录人信息
         SysUserVo currUser = null;
@@ -87,6 +91,15 @@ public class ZhcxCommon {
 
     }
 
+    /**
+     * 开启线程处理任务节点状态
+     *
+     */
+    @Async("updateWbsNodeStatusTaskExecutor")
+    public void updateWbsNode() {
+        projectWbsNodeService.updateWbsNode();
+    }
+
     /**
      * aspose 解析
      *

+ 18 - 0
business-server/src/main/java/com/rongwei/bsserver/config/AsyncConfig.java

@@ -39,4 +39,22 @@ public class AsyncConfig {
         executor.initialize();
         return executor;
     }
+
+    /**
+     *  取消邮件
+     *
+     * @return
+     */
+    @Bean(name = "updateWbsNodeStatusTaskExecutor")
+    public Executor updateWbsNodeStatus() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(4); // 核心线程数
+        executor.setMaxPoolSize(8); // 最大线程数
+        executor.setQueueCapacity(100); // 队列大小
+        executor.setKeepAliveSeconds(60); // 线程空闲时间
+        executor.setThreadNamePrefix("wbs-node-status-udpate-thread-"); // 线程名前缀
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // 拒绝策略
+        executor.initialize();
+        return executor;
+    }
 }

+ 6 - 1
business-server/src/main/java/com/rongwei/bsserver/controller/ProjectWbsNodeController.java

@@ -2,7 +2,9 @@ package com.rongwei.bsserver.controller;
 
 
 import com.rongwei.bscommon.sys.service.ProjectWbsNodeService;
+import com.rongwei.bscommon.sys.utils.ZhcxCommon;
 import com.rongwei.rwcommon.base.R;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -21,6 +23,9 @@ public class ProjectWbsNodeController {
     @Autowired
     private ProjectWbsNodeService service;
 
+    @Autowired
+    private ZhcxCommon zhcxCommon;
+
     /**
      * 更新节点
      *
@@ -29,7 +34,7 @@ public class ProjectWbsNodeController {
     @PostMapping("/updateWbsNode")
     @ResponseBody
     public R updateWbsNode() {
-        service.updateWbsNode();
+        zhcxCommon.updateWbsNode();
         return R.ok();
     }
 }