Browse Source

删除机构/ 切换机构类型 时 删除机构扩展 和GA38 的数据; 添加机构缓存时新增锁机制 保证机构缓存不会添加重复

zhulu 1 year ago
parent
commit
0a4fcf4333

+ 10 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysDeptServiceImpl.java

@@ -396,7 +396,16 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
         List<SysOrgVO> cacheList = null;
         Boolean isOk = RedisUtils.hasKey(CacheConstants.ORG_CACHE_LIST_KEY);
         if (!isOk) {
-            cacheList = orgService.loadingOrgCache();
+            synchronized (SysDeptServiceImpl.class){
+                Boolean isOk2 = RedisUtils.hasKey(CacheConstants.ORG_CACHE_LIST_KEY);
+                if(!isOk2){
+                    cacheList = orgService.loadingOrgCache();
+                }
+                else {
+                    cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
+                }
+            }
+
         } else {
             cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
         }

+ 19 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysOrgServiceImpl.java

@@ -28,11 +28,13 @@ import com.xunmei.common.security.utils.DictUtils;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.system.api.domain.SysDictData;
 import com.xunmei.system.api.domain.SysOrg;
+import com.xunmei.system.api.domain.SysOrgExtend;
 import com.xunmei.system.api.vo.FindOrgTypes;
 import com.xunmei.system.api.vo.SysOrgVO;
 import com.xunmei.system.domain.SysPhysicalDefenseConstruction;
 import com.xunmei.system.dto.SysOrgDto;
 import com.xunmei.system.dto.SysPhysicalDefenseConstructionDTO;
+import com.xunmei.system.mapper.SysOrgExtendMapper;
 import com.xunmei.system.mapper.SysOrgMapper;
 import com.xunmei.system.mapper.SysPhysicalDefenseConstructionMapper;
 import com.xunmei.system.mapper.SysUserMapper;
@@ -70,6 +72,9 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
     @Autowired
     private SysPhysicalDefenseConstructionMapper sysPhysicalDefenseConstructionMapper;
 
+    @Autowired
+    private SysOrgExtendMapper sysOrgExtendMapper;
+
     private static List<SysOrg> handleTree(Map<Long, List<SysOrg>> map, Long parentId) {
         List<SysOrg> orgList = map.get(parentId);
         if (ObjectUtil.isNotEmpty(orgList)) {
@@ -827,6 +832,15 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
                 org.setAffiliatedArea(hsAndDqOrgNames.get(1));
             }
 
+            // 机构类型 变化后 需删除 机构扩展新和 GA38 达标信息
+            if(!ObjectUtil.equal(originalOrg.getType(),org.getType()))
+            {
+                // 删除GA38 信息
+                sysPhysicalDefenseConstructionMapper.delete(new LambdaQueryWrapper<SysPhysicalDefenseConstruction>().eq(SysPhysicalDefenseConstruction::getOrgId,org.getId()));
+                // 删除机构扩展信息
+                sysOrgExtendMapper.delete(new LambdaQueryWrapper<SysOrgExtend>().eq(SysOrgExtend::getOrgId,org.getId()));
+            }
+
             isOk = this.updateById(org);
 
         } else {
@@ -891,8 +905,13 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public boolean removeOrg(Long orgId) {
         boolean rel = this.removeById(orgId);
+        // 删除机构扩展信息,GA38 信息
+        sysPhysicalDefenseConstructionMapper.delete(new LambdaQueryWrapper<SysPhysicalDefenseConstruction>().eq(SysPhysicalDefenseConstruction::getOrgId,orgId));
+        sysOrgExtendMapper.delete(new LambdaQueryWrapper<SysOrgExtend>().eq(SysOrgExtend::getOrgId,orgId));
+
         /*
          * 重置缓存
          */