فهرست منبع

公式相关:

yangyj 1 سال پیش
والد
کامیت
5f5dda5309

+ 1 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/TreeCodeUpdate.java

@@ -12,4 +12,5 @@ import java.lang.annotation.Target;
 @Target(ElementType.METHOD)
 @Retention(RetentionPolicy.RUNTIME)
 public @interface TreeCodeUpdate {
+    String name() default "";
 }

+ 32 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/TreeCodeUpdateAspect.java

@@ -1,12 +1,20 @@
 package org.springblade.business.entity;
 
 
+import lombok.RequiredArgsConstructor;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Pointcut;
+import org.springblade.core.tool.utils.BeanUtil;
+import org.springblade.core.tool.utils.Func;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Component;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author yangyj
  * @Date 2023/10/27 10:39
@@ -14,7 +22,10 @@ import org.springframework.stereotype.Component;
  */
 @Aspect
 @Component
+@RequiredArgsConstructor
 public class TreeCodeUpdateAspect {
+    private final StringRedisTemplate redisTemplate;
+    private final JdbcTemplate  jdbcTemplate;
 
     @Pointcut("@annotation(org.springblade.business.entity.TreeCodeUpdate)")
     public void p(){};
@@ -24,6 +35,25 @@ public class TreeCodeUpdateAspect {
         Object result = null;
         try {
             Object[] args = joinPoint.getArgs();
+             Map<String,Object> paramsMap=  BeanUtil.toMap(args[0]);
+            String  tcu= this.redisTemplate.opsForValue().get("tcu");
+            if(paramsMap.containsKey("contractId")){
+                  if(Func.isNotBlank(tcu)){
+                      tcu=tcu+","+paramsMap.get("contractId");
+                  }
+             }else if(paramsMap.containsKey("needCopyPrimaryKeyId")){
+                List<Map<String,Object>> listMap=  jdbcTemplate.queryForList("select contract_id contractId from m_wbs_tree_contract where p_key_id ="+paramsMap.get("needCopyPrimaryKeyId"));
+                if(listMap.size()>0){
+                    if(Func.isNotBlank(tcu)){
+                        tcu=tcu+","+listMap.get(0).get("contractId");
+                    }else{
+                        tcu=listMap.get(0).get("contractId").toString();
+                    }
+                }
+             }
+            if(tcu!=null) {
+                this.redisTemplate.opsForValue().set("tcu", tcu);
+            }
             result= joinPoint.proceed();
         }catch (Exception e){
             e.printStackTrace();
@@ -32,4 +62,6 @@ public class TreeCodeUpdateAspect {
         return result;
     }
 
+
+
 }

+ 2 - 2
blade-service/blade-business/src/main/java/org/springblade/business/controller/InformationWriteQueryController.java

@@ -1370,7 +1370,7 @@ public class InformationWriteQueryController extends BladeController {
     @PostMapping("/copyContractTreeNode")
     @ApiOperationSupport(order = 15)
     @ApiOperation(value = "复制节点(新)")
-    @TreeCodeUpdate
+    @TreeCodeUpdate(name = "pkeyId_${vo.primaryKeyId}")
     public R<Boolean> copyContractTreeNode(@RequestBody CopyContractTreeNodeVO vo) {
         //表单所属方
         String tabOwner = "";
@@ -2954,7 +2954,7 @@ public class InformationWriteQueryController extends BladeController {
     @PostMapping("/saveContractTreeNode")
     @ApiOperationSupport(order = 10)
     @ApiOperation(value = "新增节点及其子节点")
-    @TreeCodeUpdate
+    @TreeCodeUpdate(name="contractId_${vo.contractId}")
     public R<Boolean> saveContractTreeNode(@RequestBody AddContractTreeNodeVO vo) {
         //先获取当前节点的信息
         WbsTreeContract treeContract = this.wbsTreeContractClient.getContractWbsTreeByPrimaryKeyId(Long.parseLong(vo.getCurrentNodePrimaryKeyId()));

+ 14 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsParamController.java

@@ -591,7 +591,7 @@ public class WbsParamController {
             return this.service.treeCodeUpdateProjectAllForJob();
     }
 
-
+/*每天固定时间刷新treeCode*/
     @Scheduled(cron = " 0 0 3,13 * * ?")
     public  void job(){
         System.out.println("treeCode刷新任务开始"+ LocalDateTime.now());
@@ -600,6 +600,19 @@ public class WbsParamController {
         }
     }
 
+    @Scheduled(fixedDelay = 30000)
+    public  void monitor(){
+        System.out.println("treeCode刷新检测"+ LocalDateTime.now());
+       String tcu= this.redisTemplate.opsForValue().get("tcu");
+       if(Func.isNotBlank(tcu)){
+           assert tcu != null;
+           Arrays.stream(tcu.split(",")).filter(StringUtils::isNumber).distinct().forEach(id->{
+               this.service.treeCode(Long.parseLong(id),null);
+           });
+           this.redisTemplate.delete("tcu");
+       }
+    }
+
 
 
 

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IWbsParamService.java

@@ -48,6 +48,6 @@ public interface IWbsParamService extends BaseService<WbsParam> {
      void treeCodeUpdate(Set<Long> contractIds);
     /**全部项目刷新*/
      R<Object> treeCodeUpdateProjectAllForJob();
-    /**指定合同段或者项目*/
+    /**指定合同段或者项目 ,合同段id,projectId项目id , R<Object> 返回信息*/
      R<Object> treeCode(Long contractId,Long projectId);
 }