yys 1 неделя назад
Родитель
Сommit
cafd0b7d37

+ 0 - 2
fs-admin/src/main/java/com/fs/admin/controller/TenantDictController.java

@@ -43,7 +43,6 @@ public class TenantDictController extends BaseController {
     @PreAuthorize("@ss.hasPermi('tenant:dict:list')")
     @GetMapping("/type/list")
     public TableDataInfo tenantTypeList(@RequestParam Long tenantId, SysDictType query) {
-        startPage();
         List<SysDictType> list = tenantDictManageService.selectDictTypeList(tenantId, query);
         return getDataTable(list);
     }
@@ -81,7 +80,6 @@ public class TenantDictController extends BaseController {
     @PreAuthorize("@ss.hasPermi('tenant:dict:list')")
     @GetMapping("/data/list")
     public TableDataInfo tenantDataList(@RequestParam Long tenantId, SysDictData query) {
-        startPage();
         List<SysDictData> list = tenantDictManageService.selectDictDataList(tenantId, query);
         return getDataTable(list);
     }

+ 41 - 8
fs-service/src/main/java/com/fs/tenant/dict/service/impl/TenantDictManageServiceImpl.java

@@ -1,5 +1,10 @@
 package com.fs.tenant.dict.service.impl;
 
+import com.fs.common.core.page.PageDomain;
+import com.fs.common.core.page.TableSupport;
+import com.fs.common.utils.StringUtils;
+import com.fs.common.utils.sql.SqlUtil;
+import com.github.pagehelper.PageHelper;
 import com.fs.common.constant.UserConstants;
 import com.fs.common.core.domain.entity.SysDictData;
 import com.fs.common.core.domain.entity.SysDictType;
@@ -31,7 +36,10 @@ public class TenantDictManageServiceImpl implements TenantDictManageService {
 
     @Override
     public List<SysDictType> selectDictTypeList(Long tenantId, SysDictType query) {
-        return contextHelper.executeInTenant(tenantId, () -> dictTypeService.selectDictTypeList(query));
+        return contextHelper.executeInTenant(tenantId, () -> {
+            startPage();
+            return dictTypeService.selectDictTypeList(query);
+        });
     }
 
     @Override
@@ -57,8 +65,8 @@ public class TenantDictManageServiceImpl implements TenantDictManageService {
             if (existing == null) {
                 throw new CustomException("字典类型不存在");
             }
-            if (isPlatformLocked(existing) && !TenantDictConstants.SOURCE_PLATFORM.equals(dict.getDictSource())) {
-                throw new CustomException("平台管控字典类型不可直接修改,请通过模板同步或先取消平台管控");
+            if (isPlatformLocked(existing)) {
+                throw new CustomException("平台管控字典类型不可直接修改,请通过模板同步更新");
             }
             if (UserConstants.NOT_UNIQUE.equals(dictTypeService.checkDictTypeUnique(dict))) {
                 throw new CustomException("字典类型已存在: " + dict.getDictType());
@@ -88,7 +96,10 @@ public class TenantDictManageServiceImpl implements TenantDictManageService {
 
     @Override
     public List<SysDictData> selectDictDataList(Long tenantId, SysDictData query) {
-        return contextHelper.executeInTenant(tenantId, () -> dictDataService.selectDictDataList(query));
+        return contextHelper.executeInTenant(tenantId, () -> {
+            startPage();
+            return dictDataService.selectDictDataList(query);
+        });
     }
 
     @Override
@@ -170,12 +181,34 @@ public class TenantDictManageServiceImpl implements TenantDictManageService {
     }
 
     private boolean isPlatformLocked(SysDictType type) {
-        return TenantDictConstants.SOURCE_PLATFORM.equals(type.getDictSource())
-                || (type.getIsPlatformManaged() != null && type.getIsPlatformManaged() == 1);
+        if (type == null) {
+            return false;
+        }
+        if (type.getIsPlatformManaged() != null) {
+            return type.getIsPlatformManaged() == 1;
+        }
+        return TenantDictConstants.SOURCE_PLATFORM.equals(type.getDictSource());
     }
 
     private boolean isPlatformLocked(SysDictData data) {
-        return TenantDictConstants.SOURCE_PLATFORM.equals(data.getDictSource())
-                || (data.getIsPlatformManaged() != null && data.getIsPlatformManaged() == 1);
+        if (data == null) {
+            return false;
+        }
+        if (data.getIsPlatformManaged() != null) {
+            return data.getIsPlatformManaged() == 1;
+        }
+        return TenantDictConstants.SOURCE_PLATFORM.equals(data.getDictSource());
+    }
+
+    /** 切库后再开启分页,避免 loadActiveTenant 查询消耗 PageHelper */
+    private void startPage() {
+        PageDomain pageDomain = TableSupport.buildPageRequest();
+        Integer pageNum = pageDomain.getPageNum();
+        Integer pageSize = pageDomain.getPageSize();
+        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
+            String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
+            Boolean reasonable = pageDomain.getReasonable();
+            PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
+        }
     }
 }

+ 4 - 4
fs-service/src/main/java/com/fs/tenant/dict/service/impl/TenantDictSyncServiceImpl.java

@@ -343,11 +343,11 @@ public class TenantDictSyncServiceImpl implements TenantDictSyncService {
     }
 
     private boolean canUpdateType(SysDictType existing, String mode) {
-        if (TenantDictConstants.SYNC_OVERWRITE.equals(mode)) {
-            return true;
+        if (TenantDictConstants.SYNC_APPEND.equals(mode)) {
+            return false;
         }
-        return TenantDictConstants.SOURCE_PLATFORM.equals(existing.getDictSource())
-                || (existing.getIsPlatformManaged() != null && existing.getIsPlatformManaged() == 1);
+        // MERGE / OVERWRITE:模板中的类型均写入平台溯源字段,便于租户侧锁定
+        return true;
     }
 
     private boolean canUpdateData(SysDictData existing, TenantDictTemplateData template, String mode) {

+ 2 - 2
fs-service/src/main/java/com/fs/tenant/dict/service/impl/TenantDictTemplateServiceImpl.java

@@ -228,7 +228,7 @@ public class TenantDictTemplateServiceImpl implements TenantDictTemplateService
         row.setDictType(source.getDictType());
         row.setStatus(source.getStatus());
         row.setRemark(source.getRemark());
-        row.setIsManaged(1);
+        row.setIsManaged(0);
         row.setSyncMode("MERGE");
         row.setCreateBy(operator);
         row.setUpdateBy(operator);
@@ -287,7 +287,7 @@ public class TenantDictTemplateServiceImpl implements TenantDictTemplateService
             row.setStatus(UserConstants.NORMAL);
         }
         if (row.getIsManaged() == null) {
-            row.setIsManaged(1);
+            row.setIsManaged(0);
         }
         if (row.getSyncMode() == null || row.getSyncMode().isEmpty()) {
             row.setSyncMode("MERGE");