Ver Fonte

合同段节点树缓存问题

liuyc há 1 ano atrás
pai
commit
03dd383b6d

+ 36 - 10
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/WbsTreeContractController.java

@@ -202,28 +202,54 @@ public class WbsTreeContractController extends BladeController {
             @ApiImplicitParam(name = "tableOwner", value = "所属方节点权限,施工=1,监理=2,区分节点的数量、颜色")
     })
     public R<List<WbsTreeContractLazyVO>> lazyQueryContractWbsTree(@RequestParam String primaryKeyId, @RequestParam String parentId, @RequestParam String contractId, @RequestParam String contractIdRelation, @RequestParam String classifyType, @RequestParam String tableOwner) {
+        //这里是对应的监理合同段下,加载树时primaryKeyId=parentId;与前端对接时没沟通好入参,就不单独处理了,直接重新映射赋值一下
         if (StringUtils.isNotEmpty(primaryKeyId)) {
             parentId = primaryKeyId;
         }
+
+        //结果集
         List<WbsTreeContractLazyVO> vos;
-        String dataInfoId;
+
+        //构造Redis缓存Key
+        String dataInfoId = "";
         if (("1").equals(classifyType)) {
             dataInfoId = contractId + "_" + parentId + "_" + classifyType + "_" + tableOwner;
-        } else {
-            /*// TODO 监理合同段先不加缓存,存在问题
-            dataInfoId = contractIdRelation + "_" + parentId + "_" + classifyType + "_" + tableOwner;*/
+        } else if (("2").equals(classifyType)) {
+            //监理合同段下,classifyType=1,直接查询对应的施工树缓存
+            dataInfoId = contractIdRelation + "_" + parentId + "_" + "1" + "_" + tableOwner;
+        }
 
-            //定义一个错误id,暂时不加载缓存
-            dataInfoId = "illegalID";
+        //获取Redis缓存信息
+        Object data = null;
+        if (ObjectUtil.isNotEmpty(dataInfoId)) {
+            if (("2").equals(classifyType) && ObjectUtil.isNotEmpty(contractIdRelation)) {
+                //监理根据contractIdRelation关联合同段id来判断获取缓存
+                data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + dataInfoId);
+            } else if (("1").equals(classifyType)) {
+                //施工直接获取缓存
+                data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + dataInfoId);
+            }
         }
-        Object data = redisTemplate.opsForValue().get("blade-manager::contract:wbstree:" + dataInfoId);
+
         if (data != null) {
+            //返回缓存
             vos = JSON.parseArray(data.toString(), WbsTreeContractLazyVO.class);
+
         } else {
+            //响应结果集
             vos = iWbsTreeContractService.lazyQueryContractWbsTree(parentId, contractId, contractIdRelation, tableOwner);
-            if (vos != null && !dataInfoId.equals("illegalID")) { //监理不缓存
-                JSONArray array = JSONArray.parseArray(JSON.toJSONString(vos));
-                redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + dataInfoId, JSON.toJSON(array).toString());
+
+            //存储缓存
+            if (vos != null && ObjectUtil.isNotEmpty(dataInfoId)) {
+                //监理根据contractIdRelation关联合同段id来判断存储缓存
+                if (("2").equals(classifyType) && ObjectUtil.isNotEmpty(contractIdRelation)) {
+                    JSONArray array = JSONArray.parseArray(JSON.toJSONString(vos));
+                    redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + dataInfoId, JSON.toJSON(array).toString());
+                } else if (("1").equals(classifyType)) {
+                    //施工直接存储缓存
+                    JSONArray array = JSONArray.parseArray(JSON.toJSONString(vos));
+                    redisTemplate.opsForValue().set("blade-manager::contract:wbstree:" + dataInfoId, JSON.toJSON(array).toString());
+                }
             }
         }
         return R.data(vos);

+ 16 - 11
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ContractInfoServiceImpl.java

@@ -837,9 +837,10 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
             if (contractInfos.size() > 0) {
                 throw new ServiceException("合同段名称已存在当前项目下,请重新输入");
             }
+
             ContractInfo contractInfo1 = baseMapper.selectById(contractInfo.getId());
             try {
-                int integer = archiveTreeContractMapper.updateByNodeName(contractInfo1.getContractName(), contractInfo.getContractName(), contractInfo.getId());
+                archiveTreeContractMapper.updateByNodeName(contractInfo1.getContractName(), contractInfo.getContractName(), contractInfo.getId());
             } catch (Exception e) {
                 e.printStackTrace();
             }
@@ -847,23 +848,27 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
 
             //监理、总监办编辑
             if (contractInfo.getContractType().equals(2) || contractInfo.getContractType().equals(3)) {
-                //获取当前项目所有施工合同段信息
-                List<Long> contractInfosSGAll = baseMapper.selectList(Wrappers.<ContractInfo>lambdaQuery().eq(ContractInfo::getPId, contractInfo.getPId()).eq(ContractInfo::getContractType, 1).eq(ContractInfo::getStatus, 1)).stream().map(ContractInfo::getId).collect(Collectors.toList());
+                //获取当前项目所有施工合同段ids
+                List<Long> contractInfosSGAll = baseMapper.selectList(Wrappers.<ContractInfo>lambdaQuery()
+                        .eq(ContractInfo::getPId, contractInfo.getPId())
+                        .eq(ContractInfo::getContractType, 1).eq(ContractInfo::getStatus, 1))
+                        .stream().map(ContractInfo::getId).collect(Collectors.toList());
+
+                //更新当下项目所有施工合同段Redis树缓存
+                for (Long id : contractInfosSGAll) {
+                    informationQueryClient.delAsyncWbsTree(id + "");
+                }
+
+                //更新当前监理合同段Redis树缓存
+                informationQueryClient.delAsyncWbsTree(contractInfo.getId() + "");
 
+                //删除记录信息
                 List<String> updateId_SG = contractInfo.getIdList().stream().map(WbsTreeContractVO3::getContractId).collect(Collectors.toList());
-                //删除新增记录信息
                 baseMapper.deleteContractRelationJLYZ(contractInfo.getId());
                 for (String id : updateId_SG) {
                     baseMapper.insertContractRelationJLYZ(SnowFlakeUtil.getId(), contractInfo.getId(), id);
                 }
 
-                //更新redis树缓存
-                for (Long id : contractInfosSGAll) {
-                    informationQueryClient.delAsyncWbsTree(id + "");
-                }
-                //当前合同段树缓存
-                informationQueryClient.delAsyncWbsTree(contractInfo.getId() + "");
-
                 //当前关联的施工合同段ids
                 String sql = "select * from m_contract_relation_jlyz where contract_id_jlyz = " + contractInfo.getId();
                 List<String> record_SG = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ContractRelationJlyz.class)).stream().map(ContractRelationJlyz::getContractIdSg).collect(Collectors.toList()).stream().map(String::valueOf).collect(Collectors.toList());