Просмотр исходного кода

修改bug:多次点击废除会生成多条未上报数据

lvy 3 месяцев назад
Родитель
Сommit
9fb993f614

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

@@ -1211,18 +1211,7 @@ public R<String> batchDownloadFileToZip(String ids, HttpServletResponse response
 //                        wrapper.set(InformationQuery::getAuditUserIdAndName, null);
 
                         this.informationQueryService.update(wrapper.in(InformationQuery::getId, Arrays.asList(task.getFormDataId().split(","))));
-                        List<InformationQuery> informationQueries = this.informationQueryService.getBaseMapper().selectBatchIds(Arrays.asList(task.getFormDataId().split(",")));
-                        if (informationQueries != null && !informationQueries.isEmpty()) {
-                            for (InformationQuery informationQuery : informationQueries) {
-                                informationQuery.setStatus(0);
-                                informationQuery.setId(SnowFlakeUtil.getId());
-                                informationQuery.setEVisaPdfUrl(null);
-                                informationQuery.setReportNumber(null);
-                                informationQuery.setAuditUserIdAndName(null);
-                                informationQuery.setTaskId(null);
-                            }
-                            this.informationQueryService.saveBatch(informationQueries);
-                        }
+                        this.informationQueryService.createNewInformationQueriesByStatusForLock(Arrays.asList(task.getFormDataId().split(",")));
                     }
 
                     List<InformationQuery> queries = this.informationQueryService.getBaseMapper().selectBatchIds(Arrays.asList(task.getFormDataId().split(",")));
@@ -1252,6 +1241,9 @@ public R<String> batchDownloadFileToZip(String ids, HttpServletResponse response
                         }
 
                         for (InformationQuery query : queries) {
+                            if (query.getStatus() != 3) {
+                                this.informationQueryService.update(Wrappers.<InformationQuery>lambdaUpdate().in(InformationQuery::getId, query.getId()).set(InformationQuery::getStatus, 3));
+                            }
                             if (StringUtils.isNotEmpty(query.getFileUserIdAndName())) {
                                 String[] userArray = query.getFileUserIdAndName().split(",");
                                 for (String str : userArray) {
@@ -1427,16 +1419,15 @@ public R<Object> batchTask(@RequestBody StartTaskVO startTaskVO) {
             Map<String, InformationQuery> queryMap = new HashMap<>();
             List<InformationQuery> queryTempList = new ArrayList<>();
             Map<String, InformationQuery> queryTempMap = new HashMap<>();
-            List<InformationQuery> saveQueryList = new ArrayList<>();
             queryList.forEach(query -> {
                 if (query.getStatus() != 0) {
                     long count = this.informationQueryService.count(Wrappers.<InformationQuery>lambdaQuery().eq(InformationQuery::getWbsId, query.getWbsId()).eq(InformationQuery::getClassify, query.getClassify())
-                            .eq(InformationQuery::getContractId, query.getContractId()).in(InformationQuery::getStatus, 1, 2));
+                            .eq(InformationQuery::getContractId, query.getContractId()).in(InformationQuery::getStatus, 0,1, 2));
                     if (count == 0) {
                         if (query.getStatus() != null && query.getStatus() == 3) {
                             query.setId(SnowFlakeUtil.getId());
                             query.setStatus(0);
-                            saveQueryList.add(query);
+                            this.informationQueryService.save(query);
                         }
                     } else {
                         return;
@@ -1453,9 +1444,6 @@ public R<Object> batchTask(@RequestBody StartTaskVO startTaskVO) {
                 queryTempList.add(query);
                 queryMap.put(query.getId().toString(), query);
             });
-            if (!saveQueryList.isEmpty()) {
-                this.informationQueryService.saveOrUpdateBatch(saveQueryList);
-            }
             queryList = queryTempList;
             if (queryList.isEmpty()) {
                 return R.fail( "已上报,无需重复上报");

+ 2 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/IInformationQueryService.java

@@ -27,6 +27,7 @@ import org.springblade.manager.entity.TabBusstimeInfo;
 import org.springblade.manager.entity.WbsTreeContract;
 import org.springblade.manager.vo.WbsTreeContractTreeVOS;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -160,4 +161,5 @@ public interface IInformationQueryService extends BaseService<InformationQuery>
     //根据wbsTreeContract主键集合获取已经审批的资料
     List<Long> getInfoByNodeIds(List<Long> ids);
 
+    void createNewInformationQueriesByStatusForLock(Collection<String> ids);
 }

+ 46 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/InformationQueryServiceImpl.java

@@ -27,6 +27,7 @@ import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.secure.utils.SecureUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.*;
+import org.springblade.evisa.redissionUtil.DistributedRedisLock;
 import org.springblade.manager.entity.ContractInfo;
 import org.springblade.manager.entity.ContractRelationJlyz;
 import org.springblade.manager.entity.TabBusstimeInfo;
@@ -1053,4 +1054,49 @@ public class InformationQueryServiceImpl extends BaseServiceImpl<InformationQuer
         return baseMapper.getInfoByNodeIds(ids);
     }
 
+    @Override
+    public void createNewInformationQueriesByStatusForLock(Collection<String> ids) {
+        if (ids == null || ids.isEmpty()) {
+            return;
+        }
+        List<InformationQuery> informationQueries = this.getBaseMapper().selectBatchIds(ids);
+        if (informationQueries != null && !informationQueries.isEmpty()) {
+            for (InformationQuery informationQuery : informationQueries) {
+                if (DistributedRedisLock.acquire("informationQueryLock_" + informationQuery.getWbsId() + "_" + informationQuery.getContractId() + "_" + informationQuery.getClassify() + "_" + informationQuery.getType(),5)) {
+                    try {
+                        List<InformationQuery> queryList = this.list(Wrappers.<InformationQuery>lambdaQuery().select(InformationQuery::getId, InformationQuery::getStatus)
+                                .eq(InformationQuery::getWbsId, informationQuery.getWbsId())
+                                .eq(InformationQuery::getContractId, informationQuery.getContractId())
+                                .eq(InformationQuery::getClassify, informationQuery.getClassify()).eq(InformationQuery::getType, informationQuery.getType()).in(InformationQuery::getStatus, 0, 1, 2));
+                        InformationQuery temp = new InformationQuery();
+                        if (queryList != null && !queryList.isEmpty()) {
+                            queryList.forEach(query -> {
+                                if (query.getStatus() == 0 && temp.getId() == null) {
+                                    temp.setId(query.getId());
+                                } else {
+                                    query.setStatus(3);
+                                }
+                            });
+                            List<Long> collect = queryList.stream().map(InformationQuery::getId).filter(id -> !id.equals(temp.getId())).collect(Collectors.toList());
+                            if (!collect.isEmpty()) {
+                                this.update(Wrappers.<InformationQuery>lambdaUpdate().set(InformationQuery::getStatus, 3).in(InformationQuery::getId, collect));
+                            }
+                        }
+                        if (temp.getId() != null) {
+                            continue;
+                        }
+                        informationQuery.setStatus(0);
+                        informationQuery.setId(SnowFlakeUtil.getId());
+                        informationQuery.setEVisaPdfUrl(null);
+                        informationQuery.setReportNumber(null);
+                        informationQuery.setAuditUserIdAndName(null);
+                        informationQuery.setTaskId(null);
+                        this.save(informationQuery);
+                    } finally {
+                        DistributedRedisLock.release("informationQueryLock_" + informationQuery.getWbsId() + "_" + informationQuery.getContractId() + "_" + informationQuery.getClassify() + "_" + informationQuery.getType());
+                    }
+                }
+            }
+        }
+    }
 }

+ 1 - 12
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TaskServiceImpl.java

@@ -447,18 +447,7 @@ public class TaskServiceImpl extends BaseServiceImpl<TaskMapper, Task> implement
         //修改业务数据状态为未上报
         // this.updateBusinessDataByFormDataId(task, 0, null);
         this.updateBusinessDataByFormDataId(task, 3, null, -1L);
-        List<InformationQuery> informationQueries = this.informationQueryService.getBaseMapper().selectBatchIds(Arrays.asList(task.getFormDataId().split(",")));
-        if (informationQueries != null && !informationQueries.isEmpty()) {
-            for (InformationQuery informationQuery : informationQueries) {
-                informationQuery.setStatus(0);
-                informationQuery.setId(SnowFlakeUtil.getId());
-                informationQuery.setEVisaPdfUrl(null);
-                informationQuery.setReportNumber(null);
-                informationQuery.setAuditUserIdAndName(null);
-                informationQuery.setTaskId(null);
-            }
-            this.informationQueryService.saveBatch(informationQueries);
-        }
+        this.informationQueryService.createNewInformationQueriesByStatusForLock(Arrays.asList(task.getFormDataId().split(",")));
         return true;
     }