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

资料填报保存时加锁,tableFile先删后新增

lvy 2 месяцев назад
Родитель
Сommit
e99188cfcb

+ 16 - 8
blade-service-api/blade-e-visa-api/src/main/java/org/springblade/evisa/redissionUtil/DistributedRedisLock.java

@@ -14,8 +14,7 @@ import java.util.concurrent.TimeUnit;
 public class DistributedRedisLock {
 
     private static final Logger _log = Logger.getLogger(DistributedRedisLock.class);
-
-    private static final Config config = new Config();
+    private static volatile Redisson redisson;
 
     private static final String LOCK_TITLE = "redisLock_";
 
@@ -104,13 +103,22 @@ public class DistributedRedisLock {
     }
 
     private static Redisson getRedisson() {
-        config.useSingleServer()
-                .setAddress("redis://" + RedissonManager.SPRING_REDIS_HOST + ":" + RedissonManager.SPRING_REDIS_PORT)
-                .setConnectionPoolSize(500);
-        if (StringUtil.isNotEmpty(RedissonManager.SPRING_REDIS_PASSWORD)) {
-            config.useSingleServer().setPassword(RedissonManager.SPRING_REDIS_PASSWORD);
+        if (redisson == null) {
+            synchronized (DistributedRedisLock.class) {
+                if (redisson == null) {
+                    Config config = new Config();
+                    config.useSingleServer()
+                            .setAddress("redis://" + RedissonManager.SPRING_REDIS_HOST + ":" + RedissonManager.SPRING_REDIS_PORT)
+                            .setConnectionPoolSize(500);
+                    if (StringUtil.isNotEmpty(RedissonManager.SPRING_REDIS_PASSWORD)) {
+                        config.useSingleServer().setPassword(RedissonManager.SPRING_REDIS_PASSWORD);
+                    }
+                    redisson = (Redisson) Redisson.create(config);
+                    _log.info("Redisson instance created.");
+                }
+            }
         }
-        return (Redisson) Redisson.create(config);
+        return redisson;
     }
 
 }

+ 65 - 60
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/InformationQueryServiceImpl.java

@@ -387,71 +387,76 @@ public class InformationQueryServiceImpl extends BaseServiceImpl<InformationQuer
         } else {
             //首先根据wbsId获取合同段ID和项目ID
             WbsTreeContract contractTree = this.wbsTreeContractClient.getContractWbsTreeByPrimaryKeyId(Long.parseLong(primaryKeyId));
+            int type = (contractTree.getIsExpernode() == null || contractTree.getIsExpernode() <= 0) ? 1 : 2;
+            if (DistributedRedisLock.acquire("saveOrUpdateInformationQueryData:" + primaryKeyId + ":" + contractTree.getContractId() + ":" + classify + ":" + type,5)) {
+                try {
+                    //判断当前填报节点下是否已经存在相应数据
+                    InformationQuery oldData = this.baseMapper.getInformationQueryByWbsId(contractTree.getPKeyId(), classify,contractTree.getContractId());
 
-            //判断当前填报节点下是否已经存在相应数据
-            InformationQuery oldData = this.baseMapper.getInformationQueryByWbsId(contractTree.getPKeyId(), classify,contractTree.getContractId());
-
-            if (oldData != null) {
-                //存在记录,修改
-                if (StringUtils.isNotEmpty(fileName)) {
-                    oldData.setName(fileName);
-                }
-
-                //拼接填报人信息
-                String fileUser = userId + "-" + userNmae;
-                if (StringUtils.isNotEmpty(oldData.getFileUserIdAndName())) {
-                    if (!oldData.getFileUserIdAndName().contains(userId.toString())) {
-                        //不包含,拼接
-                        oldData.setFileUserIdAndName(oldData.getFileUserIdAndName() + "," + fileUser);
-                    }
-                } else {
-                    oldData.setFileUserIdAndName(fileUser);
-                }
-
-                oldData.setUpdateTime(new Date());
-                oldData.setUpdateUser(userId);
+                    if (oldData != null) {
+                        //存在记录,修改
+                        if (StringUtils.isNotEmpty(fileName)) {
+                            oldData.setName(fileName);
+                        }
 
-                List<String> linkIds = linkDataList.stream().map(json -> json.getString("id")).distinct().collect(Collectors.toList());
-                if (linkIds.size() > 0) {
-                    oldData.setSjRecordIds(StringUtils.join(linkIds, ","));
-                }
+                        //拼接填报人信息
+                        String fileUser = userId + "-" + userNmae;
+                        if (StringUtils.isNotEmpty(oldData.getFileUserIdAndName())) {
+                            if (!oldData.getFileUserIdAndName().contains(userId.toString())) {
+                                //不包含,拼接
+                                oldData.setFileUserIdAndName(oldData.getFileUserIdAndName() + "," + fileUser);
+                            }
+                        } else {
+                            oldData.setFileUserIdAndName(fileUser);
+                        }
 
-                //修改数据
-                this.baseMapper.updateById(oldData);
-            } else {
-                //新增基础数据
-                InformationQuery newData = new InformationQuery();
-                //设置文件题名
-                newData.setName(fileName);
-                //设置文件类型
-                newData.setCategory(contractTree.getNodeType());
-                //项目ID
-                newData.setProjectId(Long.parseLong(contractTree.getProjectId()));
-                //合同段ID
-                newData.setContractId(Long.parseLong(contractTree.getContractId()));
-                //施工资料还是质检资料
-                newData.setClassify(classify);
-                //节点ID
-                newData.setWbsId(contractTree.getPKeyId());
-
-                //1资料填报,2试验,3首件
-                newData.setType((contractTree.getIsExpernode() == null || contractTree.getIsExpernode() <= 0) ? 1 : 2);
-
-                //流程状态,默认未上报
-                newData.setStatus(0);
-                //填报人ID及姓名
-                newData.setFileUserIdAndName(userId + "-" + userNmae);
-                //数据源类型
-                newData.setSourceType(sourceType);
-                newData.setCreateUser(userId);
-                newData.setCreateTime(new Date());
+                        oldData.setUpdateTime(new Date());
+                        oldData.setUpdateUser(userId);
 
-                List<String> linkIds = linkDataList.stream().map(json -> json.getString("id")).distinct().collect(Collectors.toList());
-                if (linkIds.size() > 0) {
-                    newData.setSjRecordIds(StringUtils.join(linkIds, ","));
+                        List<String> linkIds = linkDataList.stream().map(json -> json.getString("id")).distinct().collect(Collectors.toList());
+                        if (linkIds.size() > 0) {
+                            oldData.setSjRecordIds(StringUtils.join(linkIds, ","));
+                        }
+                        //修改数据
+                        this.baseMapper.updateById(oldData);
+                    } else {
+                        //新增基础数据
+                        InformationQuery newData = new InformationQuery();
+                        //设置文件题名
+                        newData.setName(fileName);
+                        //设置文件类型
+                        newData.setCategory(contractTree.getNodeType());
+                        //项目ID
+                        newData.setProjectId(Long.parseLong(contractTree.getProjectId()));
+                        //合同段ID
+                        newData.setContractId(Long.parseLong(contractTree.getContractId()));
+                        //施工资料还是质检资料
+                        newData.setClassify(classify);
+                        //节点ID
+                        newData.setWbsId(contractTree.getPKeyId());
+
+                        //1资料填报,2试验,3首件
+                        newData.setType(type);
+
+                        //流程状态,默认未上报
+                        newData.setStatus(0);
+                        //填报人ID及姓名
+                        newData.setFileUserIdAndName(userId + "-" + userNmae);
+                        //数据源类型
+                        newData.setSourceType(sourceType);
+                        newData.setCreateUser(userId);
+                        newData.setCreateTime(new Date());
+
+                        List<String> linkIds = linkDataList.stream().map(json -> json.getString("id")).distinct().collect(Collectors.toList());
+                        if (linkIds.size() > 0) {
+                            newData.setSjRecordIds(StringUtils.join(linkIds, ","));
+                        }
+                        //保存数据
+                        this.baseMapper.insert(newData);
+                    }
+                } finally {
+                    DistributedRedisLock.release("saveOrUpdateInformationQueryData:" + primaryKeyId + ":" + contractTree.getContractId() + ":" + classify + ":" + type);
                 }
-                //保存数据
-                this.baseMapper.insert(newData);
             }
         }
         return null;

+ 8 - 6
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -2361,10 +2361,11 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         }
 
         //附件
-        TableFile tableFile1 = tableFileService.getBaseMapper().selectList(Wrappers.<TableFile>query().lambda().eq(TableFile::getTabId, pkeyId + "").eq(TableFile::getType, 1)).stream().findAny().orElse(null);
-        if (tableFile1 != null) {
-            tableFileService.update(Wrappers.<TableFile>lambdaUpdate().set(TableFile::getDomainPdfUrl, bladeFile.getLink()).eq(TableFile::getId, tableFile1.getId()));
-        } else {
+//        TableFile tableFile1 = tableFileService.getBaseMapper().selectList(Wrappers.<TableFile>query().lambda().eq(TableFile::getTabId, pkeyId + "").eq(TableFile::getType, 1)).stream().findAny().orElse(null);
+//        if (tableFile1 != null) {
+//            tableFileService.update(Wrappers.<TableFile>lambdaUpdate().set(TableFile::getDomainPdfUrl, bladeFile.getLink()).eq(TableFile::getId, tableFile1.getId()));
+//        } else
+        {
             TableFile tableFile = new TableFile();
             String fileExtension = FileUtil.getFileExtension(wbsTreeContract.getFullName() + ".pdf");
             tableFile.setTabId(pkeyId + "");
@@ -2374,7 +2375,8 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             tableFile.setIsDeleted(0);
             tableFile.setExtension(fileExtension);
             tableFile.setDomainPdfUrl(bladeFile.getLink());
-            tableFileService.saveOrUpdate(tableFile);
+            tableFileService.remove(Wrappers.<TableFile>query().lambda().eq(TableFile::getTabId, pkeyId + "").eq(TableFile::getType, 1));
+            tableFileService.save(tableFile);
         }
 
         List<TableFile> tableFileList = tableFileService.getBaseMapper().selectList(Wrappers.<TableFile>query().lambda().eq(TableFile::getTabId, pkeyId + "").eq(TableFile::getIsDeleted, 0));
@@ -2440,7 +2442,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             }
         }
 
-        String listPdf = file_path + "/pdf/" + nodeId + ".pdf";
+        String listPdf = file_path + "/pdf/" + nodeId + "_" + classify + ".pdf";
         File tabpdf2 = ResourceUtil.getFile(listPdf);
         if (tabpdf2.exists()) {
             tabpdf2.delete();