Browse Source

质检系统-资料查询-save-again-保存功能改成异步操作,记录id缓存

LHB 2 months ago
parent
commit
e5bcfdf340

+ 40 - 13
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TaskServiceImpl.java

@@ -3,6 +3,7 @@ package org.springblade.business.service.impl;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.AllArgsConstructor;
@@ -18,6 +19,7 @@ import org.springblade.business.entity.*;
 import org.springblade.business.mapper.TaskMapper;
 import org.springblade.business.mapper.TrialSelfInspectionRecordMapper;
 import org.springblade.business.service.*;
+import org.springblade.business.sync.TaskSync;
 import org.springblade.business.utils.FileUtils;
 import org.springblade.business.vo.*;
 import org.springblade.common.constant.CommonConstant;
@@ -26,6 +28,7 @@ import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.oss.model.BladeFile;
+import org.springblade.core.redis.cache.BladeRedis;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.secure.utils.SecureUtil;
 import org.springblade.core.tool.api.R;
@@ -61,6 +64,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.SingleColumnRowMapper;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -134,6 +138,13 @@ public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implement
 
     @Autowired
     StringRedisTemplate RedisTemplate;
+    @Autowired
+    private BladeRedis bladeRedis;
+    //异步类
+    @Autowired
+    private TaskSync taskSync;
+
+
 
     private final ITrialSelfInspectionRecordService iTrialSelfInspectionRecordService;
 
@@ -1969,19 +1980,35 @@ public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implement
         public R reSigningEVisaStatus0(List<reSigningEVisaStatus> dtos, String header) throws Exception {
          R result= new R();
          if(dtos.size()>0){
-            for (reSigningEVisaStatus dto : dtos) {
-                InformationQuery iq = informationQueryService.getById(dto.getId());
-                if(iq!=null){
-                    informationQueryService.update(new LambdaUpdateWrapper<InformationQuery>()
-                        .eq(InformationQuery::getId, dto.getId())
-                        .set(InformationQuery::getEVisaPdfUrl, null)
-                        .set(InformationQuery::getPdfUrl, null));
-                    result = this.saveNodePdf(iq.getClassify()+"", iq.getWbsId()+"", dto.getContractId()+"", dto.getProjectId()+"", header);
-                    if(result==null||(result!=null&&result.getCode()!=200)){
-                        return R.fail(iq.getName()+"重新保存PDF信息失败");
-                    }
-                }
-            }
+
+             //添加缓存
+             Set<Long> newIds = dtos.stream().map(reSigningEVisaStatus::getId).collect(Collectors.toSet());
+
+             //随机id
+             String s = "sign-reSigningEVisaStatus0:" + SnowFlakeUtil.getId();
+
+             //数据效验
+             Set<Long> oldIds = new HashSet<>();
+             Set<String> keys = bladeRedis.keys("sign-reSigningEVisaStatus0*");
+             for (String key : keys) {
+                 Set<Long> ids = bladeRedis.get(key);
+                 if(ids !=null ){
+                     oldIds.addAll(ids);
+                 }
+             }
+
+             if(CollectionUtils.isNotEmpty(oldIds)){
+                 //如果旧的id中存在新的id,则不允许添加
+                 long count = oldIds.stream().filter(f -> newIds.contains(f)).count();
+                 if(count > 0){
+                     return R.fail("当前提交数据中存在正在保存的数据,请勿重复提交");
+                 }
+             }
+             //10分钟过期
+             bladeRedis.setEx(s,newIds, 600L);
+
+             //执行异步
+             taskSync.reSigningEVisaStatusSync(dtos,header,s);
         }
          return R.success("操作成功");
     }

+ 58 - 0
blade-service/blade-business/src/main/java/org/springblade/business/sync/TaskSync.java

@@ -0,0 +1,58 @@
+package org.springblade.business.sync;
+
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import lombok.AllArgsConstructor;
+import org.springblade.business.dto.reSigningEVisaStatus;
+import org.springblade.business.entity.InformationQuery;
+import org.springblade.business.service.IInformationQueryFileService;
+import org.springblade.business.service.IInformationQueryService;
+import org.springblade.core.redis.cache.BladeRedis;
+import org.springblade.core.tool.api.R;
+import org.springblade.manager.feign.ExcelTabClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * @author LHB
+ */
+@Component
+@AllArgsConstructor
+public class TaskSync {
+
+    private final IInformationQueryService informationQueryService;
+
+    private final ExcelTabClient excelTabClient;
+    @Autowired
+    private BladeRedis bladeRedis;
+    @Async("taskExecutor1")
+    public void reSigningEVisaStatusSync(List<reSigningEVisaStatus> dtos, String header,String s) {
+        R result= null;
+        try {
+            for (reSigningEVisaStatus dto : dtos) {
+                InformationQuery iq = informationQueryService.getById(dto.getId());
+                if(iq!=null){
+                    informationQueryService.update(new LambdaUpdateWrapper<InformationQuery>()
+                            .eq(InformationQuery::getId, dto.getId())
+                            .set(InformationQuery::getEVisaPdfUrl, null)
+                            .set(InformationQuery::getPdfUrl, null));
+                    result = this.saveNodePdf(iq.getClassify()+"", iq.getWbsId()+"", dto.getContractId()+"", dto.getProjectId()+"", header);
+                    if(result==null||(result!=null&&result.getCode()!=200)){
+                        System.out.println(iq.getName()+"重新保存PDF信息失败");
+                    }
+                }
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }finally {
+            //删除缓f存
+            bladeRedis.del(s);
+        }
+    }
+
+    R saveNodePdf(String classify, String nodePKeyIds, String contractId, String projectId, String header) throws Exception {
+        return excelTabClient.synPDFInfo(contractId, nodePKeyIds, classify, projectId, header);
+    }
+}