From cd94420b21c42fa8e803cb6ecff38db71f4afb0b Mon Sep 17 00:00:00 2001 From: FCL Date: Tue, 13 Jan 2026 09:22:22 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=E7=99=BB=E9=99=86=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E9=83=A8=E9=97=A8=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0=E8=A7=92=E8=89=B2=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../permission/PermissionCommonApi.java | 7 +++++ .../core/context/DeptContextHolder.java | 21 ++++++++++++++ .../api/permission/PermissionApiImpl.java | 4 +++ .../service/permission/PermissionService.java | 1 + .../permission/PermissionServiceImpl.java | 28 +++++++++++++++++++ 5 files changed, 61 insertions(+) diff --git a/zt-framework/zt-common/src/main/java/com/zt/plat/framework/common/biz/system/permission/PermissionCommonApi.java b/zt-framework/zt-common/src/main/java/com/zt/plat/framework/common/biz/system/permission/PermissionCommonApi.java index 844593d0..f809b7ea 100644 --- a/zt-framework/zt-common/src/main/java/com/zt/plat/framework/common/biz/system/permission/PermissionCommonApi.java +++ b/zt-framework/zt-common/src/main/java/com/zt/plat/framework/common/biz/system/permission/PermissionCommonApi.java @@ -40,4 +40,11 @@ public interface PermissionCommonApi { @Parameter(name = "userId", description = "用户编号", example = "2", required = true) CommonResult getDeptDataPermission(@RequestParam("userId") Long userId); + @GetMapping(PREFIX + "/get-dept-data-permission-with-roleCodes") + @Operation(summary = "获得登陆用户的部门数据权限") + @Parameters({ + @Parameter(name = "userId", description = "用户编号", example = "2", required = true), + @Parameter(name = "roleCodes", description = "角色编码", example = "2", required = true) + }) + CommonResult getDeptDataPermissionWithRoleCodes(@RequestParam("userId") Long userId, @RequestParam("roleCodes") String roleCodes); } \ No newline at end of file diff --git a/zt-framework/zt-spring-boot-starter-biz-tenant/src/main/java/com/zt/plat/framework/tenant/core/context/DeptContextHolder.java b/zt-framework/zt-spring-boot-starter-biz-tenant/src/main/java/com/zt/plat/framework/tenant/core/context/DeptContextHolder.java index e463ae50..8652ebdb 100644 --- a/zt-framework/zt-spring-boot-starter-biz-tenant/src/main/java/com/zt/plat/framework/tenant/core/context/DeptContextHolder.java +++ b/zt-framework/zt-spring-boot-starter-biz-tenant/src/main/java/com/zt/plat/framework/tenant/core/context/DeptContextHolder.java @@ -2,6 +2,8 @@ package com.zt.plat.framework.tenant.core.context; import com.alibaba.ttl.TransmittableThreadLocal; +import java.util.List; + /** * 部门上下文 Holder,使用 {@link TransmittableThreadLocal} 支持在线程池/异步场景下的上下文传递。 * @@ -15,6 +17,8 @@ public class DeptContextHolder { private static final ThreadLocal COMPANY_ID = new TransmittableThreadLocal<>(); /** 是否忽略部门数据权限 */ private static final ThreadLocal IGNORE = new TransmittableThreadLocal<>(); + /** 角色编码列表 */ + private static final ThreadLocal> ROLE_CODE_LIST = new TransmittableThreadLocal<>(); public static Long getDeptId() { return DEPT_ID.get(); @@ -32,6 +36,12 @@ public class DeptContextHolder { COMPANY_ID.set(companyId); } + public static void setContext(Long deptId, Long companyId, List roleCodeList) { + DEPT_ID.set(deptId); + COMPANY_ID.set(companyId); + ROLE_CODE_LIST.set(roleCodeList); + } + public static void setDeptId(Long deptId) { DEPT_ID.set(deptId); } @@ -53,9 +63,20 @@ public class DeptContextHolder { return Boolean.TRUE.equals(IGNORE.get()); } + public static void setRoleCodeList(List roleCodeList) { + ROLE_CODE_LIST.set(roleCodeList); + } + public static List getRoleCodeList() { + return ROLE_CODE_LIST.get(); + } + public static void clearRoleCodeList(){ + ROLE_CODE_LIST.remove(); + } + public static void clear() { DEPT_ID.remove(); COMPANY_ID.remove(); IGNORE.remove(); + ROLE_CODE_LIST.remove(); } } diff --git a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/permission/PermissionApiImpl.java b/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/permission/PermissionApiImpl.java index 771f322b..c3899330 100644 --- a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/permission/PermissionApiImpl.java +++ b/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/permission/PermissionApiImpl.java @@ -86,4 +86,8 @@ public class PermissionApiImpl implements PermissionApi { return success(permissionService.getDeptDataPermission(userId)); } + @Override + public CommonResult getDeptDataPermissionWithRoleCodes(Long userId, String roleCodes) { + return success(permissionService.getDeptDataPermissionWithRoleCodes(userId, roleCodes)); + } } diff --git a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/service/permission/PermissionService.java b/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/service/permission/PermissionService.java index a1a88dd3..69a4857c 100644 --- a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/service/permission/PermissionService.java +++ b/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/service/permission/PermissionService.java @@ -143,6 +143,7 @@ public interface PermissionService { * @return 部门数据权限 */ DeptDataPermissionRespDTO getDeptDataPermission(Long userId); + DeptDataPermissionRespDTO getDeptDataPermissionWithRoleCodes(Long userId, String roleCodes); /** * 获得用户的数据权限级别 diff --git a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/service/permission/PermissionServiceImpl.java b/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/service/permission/PermissionServiceImpl.java index 6bb37d18..52265633 100644 --- a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/service/permission/PermissionServiceImpl.java +++ b/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/service/permission/PermissionServiceImpl.java @@ -3,6 +3,7 @@ package com.zt.plat.module.system.service.permission; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.google.common.annotations.VisibleForTesting; @@ -12,6 +13,7 @@ import com.zt.plat.framework.common.biz.system.permission.dto.DeptDataPermission import com.zt.plat.framework.common.enums.CommonStatusEnum; import com.zt.plat.framework.common.util.collection.CollectionUtils; import com.zt.plat.framework.datapermission.core.annotation.DataPermission; +import com.zt.plat.framework.tenant.core.context.DeptContextHolder; import com.zt.plat.module.system.dal.dataobject.permission.MenuDO; import com.zt.plat.module.system.dal.dataobject.permission.RoleDO; import com.zt.plat.module.system.dal.dataobject.permission.RoleMenuDO; @@ -347,6 +349,12 @@ public class PermissionServiceImpl implements PermissionService { // 获得用户的角色 List roles = getEnableUserRoleListByUserIdFromCache(userId); + //使用上下文角色编码过滤 + List contextRoleCodes = DeptContextHolder.getRoleCodeList(); + if(!CollectionUtil.isEmpty(contextRoleCodes)){ + roles = roles.stream().filter(role -> contextRoleCodes.contains(role.getCode())).collect(Collectors.toList()); + } + // 获得用户的部门编号的缓存,通过 Guava 的 Suppliers 惰性求值,即有且仅有第一次发起 DB 的查询 Supplier> userDeptIds = Suppliers.memoize(() -> { List validUserDeptListByUserId = userDeptService.getValidUserDeptListByUserIds(singleton(userId)); @@ -414,6 +422,26 @@ public class PermissionServiceImpl implements PermissionService { return result; } + @Override + public DeptDataPermissionRespDTO getDeptDataPermissionWithRoleCodes(Long userId, String roleCodes) { + // 获得用户的角色 + List roles = getEnableUserRoleListByUserIdFromCache(userId); + if(ObjectUtil.isEmpty(roleCodes)) + return getDeptDataPermission(userId); + List roleCodesList = Arrays.asList(roleCodes.split(",")); + if(CollectionUtil.isEmpty(roles)) + return getDeptDataPermission(userId); + DeptContextHolder.setRoleCodeList(roleCodesList); + try{ + return getDeptDataPermission(userId); + }catch (Exception e){ + log.error("getDeptDataPermission-- error ", e); + }finally { + DeptContextHolder.clearRoleCodeList(); + } + return getDeptDataPermission(userId); + } + @Override @DataPermission(enable = false) @TenantIgnore From 206bf9a3c5c76aa3f3e32a2aec1974db74c23c28 Mon Sep 17 00:00:00 2001 From: chenbowen Date: Tue, 13 Jan 2026 11:11:34 +0800 Subject: [PATCH 2/4] =?UTF-8?q?1.=20=E7=A7=BB=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=20java=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tabusDeptProviderApiImpl_BACKUP_71078.java | 224 ------------------ ...DatabusDeptProviderApiImpl_BASE_71078.java | 218 ----------------- ...atabusDeptProviderApiImpl_LOCAL_71078.java | 221 ----------------- ...tabusDeptProviderApiImpl_REMOTE_71078.java | 220 ----------------- 4 files changed, 883 deletions(-) delete mode 100644 zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_BACKUP_71078.java delete mode 100644 zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_BASE_71078.java delete mode 100644 zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_LOCAL_71078.java delete mode 100644 zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_REMOTE_71078.java diff --git a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_BACKUP_71078.java b/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_BACKUP_71078.java deleted file mode 100644 index 41d331bf..00000000 --- a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_BACKUP_71078.java +++ /dev/null @@ -1,224 +0,0 @@ -package com.zt.plat.module.system.api.databus; - -import cn.hutool.core.collection.CollUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.zt.plat.framework.common.pojo.CommonResult; -import com.zt.plat.module.databus.api.data.DatabusDeptData; -import com.zt.plat.module.databus.api.dto.CursorPageReqDTO; -import com.zt.plat.module.databus.api.dto.CursorPageResult; -import com.zt.plat.module.databus.api.provider.DatabusDeptProviderApi; -import com.zt.plat.module.system.dal.dataobject.dept.DeptDO; -import com.zt.plat.module.system.dal.dataobject.user.AdminUserDO; -import com.zt.plat.module.system.dal.mysql.dept.DeptMapper; -import com.zt.plat.module.system.dal.mysql.user.AdminUserMapper; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RestController; - -import java.util.*; -import java.util.stream.Collectors; - -import static com.zt.plat.framework.common.pojo.CommonResult.success; - -/** - * Databus 部门数据提供者 API 实现 - * - * @author ZT - */ -@Slf4j -@RestController -@Validated -public class DatabusDeptProviderApiImpl implements DatabusDeptProviderApi { - - @Resource - private DeptMapper deptMapper; - - @Resource - private AdminUserMapper userMapper; - - @Override - public CommonResult> getPageByCursor(CursorPageReqDTO reqDTO) { - // 构建游标查询条件 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(DeptDO::getDeptSource, 3); - // 游标条件:create_time > cursorTime OR (create_time = cursorTime AND id > cursorId) - if (!reqDTO.isFirstPage()) { - queryWrapper.and(w -> w - .gt(DeptDO::getCreateTime, reqDTO.getCursorTime()) - .or(o -> o - .eq(DeptDO::getCreateTime, reqDTO.getCursorTime()) - .gt(DeptDO::getId, reqDTO.getCursorId()) - ) - ); - } - - // 租户过滤(如果指定) - if (reqDTO.getTenantId() != null) { - queryWrapper.eq(DeptDO::getTenantId, reqDTO.getTenantId()); - } - - // 按 create_time, id 升序排列,确保顺序稳定 - queryWrapper.orderByAsc(DeptDO::getCreateTime) - .orderByAsc(DeptDO::getId); - - // 多查一条判断是否有更多数据 - int limit = reqDTO.getBatchSize() != null ? reqDTO.getBatchSize() : 100; - queryWrapper.last("LIMIT " + (limit + 1)); - - List deptList = deptMapper.selectList(queryWrapper); - - // 判断是否有更多 - boolean hasMore = deptList.size() > limit; - if (hasMore) { - deptList = deptList.subList(0, limit); - } - - if (CollUtil.isEmpty(deptList)) { - return success(CursorPageResult.empty()); - } - - // 收集负责人用户ID - Set leaderUserIds = deptList.stream() - .map(DeptDO::getLeaderUserId) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - - // 批量查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (CollUtil.isNotEmpty(leaderUserIds)) { - List users = userMapper.selectBatchIds(leaderUserIds); - userNameMap = users.stream() - .collect(Collectors.toMap(AdminUserDO::getId, AdminUserDO::getNickname, (v1, v2) -> v1)); - } - - // 转换为同步数据 - Map finalUserNameMap = userNameMap; - List dataList = deptList.stream() - .map(dept -> convertToDatabusDeptData(dept, finalUserNameMap)) - .collect(Collectors.toList()); - - // 获取最后一条数据的游标 - DeptDO lastDept = deptList.get(deptList.size() - 1); - - // 首次查询时返回总数 - Long total = null; - if (reqDTO.isFirstPage()) { - LambdaQueryWrapper countWrapper = new LambdaQueryWrapper<>(); - countWrapper.eq(DeptDO::getDeptSource, 3); - if (reqDTO.getTenantId() != null) { - countWrapper.eq(DeptDO::getTenantId, reqDTO.getTenantId()); - } - total = deptMapper.selectCount(countWrapper); - } - - return success(CursorPageResult.of( - dataList, - lastDept.getCreateTime(), - lastDept.getId(), - hasMore, - total - )); - } - - @Override - public CommonResult getById(Long id) { - DeptDO dept = deptMapper.selectById(id); - if (dept == null) { - return success(null); - } - - // 查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (dept.getLeaderUserId() != null) { - AdminUserDO user = userMapper.selectById(dept.getLeaderUserId()); - if (user != null) { - userNameMap.put(user.getId(), user.getNickname()); - } - } - - return success(convertToDatabusDeptData(dept, userNameMap)); - } - - @Override - public CommonResult> getListByIds(List ids) { - if (CollUtil.isEmpty(ids)) { - return success(Collections.emptyList()); - } - - List deptList = deptMapper.selectBatchIds(ids); - if (CollUtil.isEmpty(deptList)) { - return success(Collections.emptyList()); - } - - // 收集负责人用户ID - Set leaderUserIds = deptList.stream() - .map(DeptDO::getLeaderUserId) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - - // 批量查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (CollUtil.isNotEmpty(leaderUserIds)) { - List users = userMapper.selectBatchIds(leaderUserIds); - userNameMap = users.stream() - .collect(Collectors.toMap(AdminUserDO::getId, AdminUserDO::getNickname, (v1, v2) -> v1)); - } - - Map finalUserNameMap = userNameMap; - List dataList = deptList.stream() - .map(dept -> convertToDatabusDeptData(dept, finalUserNameMap)) - .collect(Collectors.toList()); - - return success(dataList); - } - - @Override - public CommonResult count(Long tenantId) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); -<<<<<<< HEAD - // ⚠️ 只统计 userSource = 3 的用户 -======= ->>>>>>> test - queryWrapper.eq(DeptDO::getDeptSource, 3); - if (tenantId != null) { - queryWrapper.eq(DeptDO::getTenantId, tenantId); - } - return success(deptMapper.selectCount(queryWrapper)); - } - - /** - * 将 DeptDO 转换为 DatabusDeptData - */ - private DatabusDeptData convertToDatabusDeptData(DeptDO dept, Map userNameMap) { - // 根据 isCompany 反推 deptType - Integer deptType = null; - if (Boolean.TRUE.equals(dept.getIsCompany())) { - deptType = 28; // 公司 - } else if (Boolean.FALSE.equals(dept.getIsCompany())) { - deptType = 26; // 部门 - } - - return DatabusDeptData.builder() - .id(dept.getId()) - .code(dept.getCode()) - .name(dept.getName()) - .shortName(dept.getShortName()) - .parentId(dept.getParentId()) - .sort(dept.getSort()) - .status(dept.getStatus()) - .deptType(deptType) - .isGroup(dept.getIsGroup()) - .isCompany(dept.getIsCompany()) - .deptSource(dept.getDeptSource()) - .leaderUserId(dept.getLeaderUserId()) - .leaderUserName(dept.getLeaderUserId() != null ? userNameMap.get(dept.getLeaderUserId()) : null) - .phone(dept.getPhone()) - .email(dept.getEmail()) - .tenantId(dept.getTenantId()) - .createTime(dept.getCreateTime()) - .updateTime(dept.getUpdateTime()) - .build(); - } - -} diff --git a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_BASE_71078.java b/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_BASE_71078.java deleted file mode 100644 index 909845dc..00000000 --- a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_BASE_71078.java +++ /dev/null @@ -1,218 +0,0 @@ -package com.zt.plat.module.system.api.databus; - -import cn.hutool.core.collection.CollUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.zt.plat.framework.common.pojo.CommonResult; -import com.zt.plat.module.databus.api.data.DatabusDeptData; -import com.zt.plat.module.databus.api.dto.CursorPageReqDTO; -import com.zt.plat.module.databus.api.dto.CursorPageResult; -import com.zt.plat.module.databus.api.provider.DatabusDeptProviderApi; -import com.zt.plat.module.system.dal.dataobject.dept.DeptDO; -import com.zt.plat.module.system.dal.dataobject.user.AdminUserDO; -import com.zt.plat.module.system.dal.mysql.dept.DeptMapper; -import com.zt.plat.module.system.dal.mysql.user.AdminUserMapper; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RestController; - -import java.util.*; -import java.util.stream.Collectors; - -import static com.zt.plat.framework.common.pojo.CommonResult.success; - -/** - * Databus 部门数据提供者 API 实现 - * - * @author ZT - */ -@Slf4j -@RestController -@Validated -public class DatabusDeptProviderApiImpl implements DatabusDeptProviderApi { - - @Resource - private DeptMapper deptMapper; - - @Resource - private AdminUserMapper userMapper; - - @Override - public CommonResult> getPageByCursor(CursorPageReqDTO reqDTO) { - // 构建游标查询条件 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - - // 游标条件:create_time > cursorTime OR (create_time = cursorTime AND id > cursorId) - if (!reqDTO.isFirstPage()) { - queryWrapper.and(w -> w - .gt(DeptDO::getCreateTime, reqDTO.getCursorTime()) - .or(o -> o - .eq(DeptDO::getCreateTime, reqDTO.getCursorTime()) - .gt(DeptDO::getId, reqDTO.getCursorId()) - ) - ); - } - - // 租户过滤(如果指定) - if (reqDTO.getTenantId() != null) { - queryWrapper.eq(DeptDO::getTenantId, reqDTO.getTenantId()); - } - - // 按 create_time, id 升序排列,确保顺序稳定 - queryWrapper.orderByAsc(DeptDO::getCreateTime) - .orderByAsc(DeptDO::getId); - - // 多查一条判断是否有更多数据 - int limit = reqDTO.getBatchSize() != null ? reqDTO.getBatchSize() : 100; - queryWrapper.last("LIMIT " + (limit + 1)); - - List deptList = deptMapper.selectList(queryWrapper); - - // 判断是否有更多 - boolean hasMore = deptList.size() > limit; - if (hasMore) { - deptList = deptList.subList(0, limit); - } - - if (CollUtil.isEmpty(deptList)) { - return success(CursorPageResult.empty()); - } - - // 收集负责人用户ID - Set leaderUserIds = deptList.stream() - .map(DeptDO::getLeaderUserId) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - - // 批量查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (CollUtil.isNotEmpty(leaderUserIds)) { - List users = userMapper.selectBatchIds(leaderUserIds); - userNameMap = users.stream() - .collect(Collectors.toMap(AdminUserDO::getId, AdminUserDO::getNickname, (v1, v2) -> v1)); - } - - // 转换为同步数据 - Map finalUserNameMap = userNameMap; - List dataList = deptList.stream() - .map(dept -> convertToDatabusDeptData(dept, finalUserNameMap)) - .collect(Collectors.toList()); - - // 获取最后一条数据的游标 - DeptDO lastDept = deptList.get(deptList.size() - 1); - - // 首次查询时返回总数 - Long total = null; - if (reqDTO.isFirstPage()) { - LambdaQueryWrapper countWrapper = new LambdaQueryWrapper<>(); - if (reqDTO.getTenantId() != null) { - countWrapper.eq(DeptDO::getTenantId, reqDTO.getTenantId()); - } - total = deptMapper.selectCount(countWrapper); - } - - return success(CursorPageResult.of( - dataList, - lastDept.getCreateTime(), - lastDept.getId(), - hasMore, - total - )); - } - - @Override - public CommonResult getById(Long id) { - DeptDO dept = deptMapper.selectById(id); - if (dept == null) { - return success(null); - } - - // 查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (dept.getLeaderUserId() != null) { - AdminUserDO user = userMapper.selectById(dept.getLeaderUserId()); - if (user != null) { - userNameMap.put(user.getId(), user.getNickname()); - } - } - - return success(convertToDatabusDeptData(dept, userNameMap)); - } - - @Override - public CommonResult> getListByIds(List ids) { - if (CollUtil.isEmpty(ids)) { - return success(Collections.emptyList()); - } - - List deptList = deptMapper.selectBatchIds(ids); - if (CollUtil.isEmpty(deptList)) { - return success(Collections.emptyList()); - } - - // 收集负责人用户ID - Set leaderUserIds = deptList.stream() - .map(DeptDO::getLeaderUserId) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - - // 批量查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (CollUtil.isNotEmpty(leaderUserIds)) { - List users = userMapper.selectBatchIds(leaderUserIds); - userNameMap = users.stream() - .collect(Collectors.toMap(AdminUserDO::getId, AdminUserDO::getNickname, (v1, v2) -> v1)); - } - - Map finalUserNameMap = userNameMap; - List dataList = deptList.stream() - .map(dept -> convertToDatabusDeptData(dept, finalUserNameMap)) - .collect(Collectors.toList()); - - return success(dataList); - } - - @Override - public CommonResult count(Long tenantId) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - if (tenantId != null) { - queryWrapper.eq(DeptDO::getTenantId, tenantId); - } - return success(deptMapper.selectCount(queryWrapper)); - } - - /** - * 将 DeptDO 转换为 DatabusDeptData - */ - private DatabusDeptData convertToDatabusDeptData(DeptDO dept, Map userNameMap) { - // 根据 isCompany 反推 deptType - Integer deptType = null; - if (Boolean.TRUE.equals(dept.getIsCompany())) { - deptType = 28; // 公司 - } else if (Boolean.FALSE.equals(dept.getIsCompany())) { - deptType = 26; // 部门 - } - - return DatabusDeptData.builder() - .id(dept.getId()) - .code(dept.getCode()) - .name(dept.getName()) - .shortName(dept.getShortName()) - .parentId(dept.getParentId()) - .sort(dept.getSort()) - .status(dept.getStatus()) - .deptType(deptType) - .isGroup(dept.getIsGroup()) - .isCompany(dept.getIsCompany()) - .deptSource(dept.getDeptSource()) - .leaderUserId(dept.getLeaderUserId()) - .leaderUserName(dept.getLeaderUserId() != null ? userNameMap.get(dept.getLeaderUserId()) : null) - .phone(dept.getPhone()) - .email(dept.getEmail()) - .tenantId(dept.getTenantId()) - .createTime(dept.getCreateTime()) - .updateTime(dept.getUpdateTime()) - .build(); - } - -} diff --git a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_LOCAL_71078.java b/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_LOCAL_71078.java deleted file mode 100644 index 326d1d3d..00000000 --- a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_LOCAL_71078.java +++ /dev/null @@ -1,221 +0,0 @@ -package com.zt.plat.module.system.api.databus; - -import cn.hutool.core.collection.CollUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.zt.plat.framework.common.pojo.CommonResult; -import com.zt.plat.module.databus.api.data.DatabusDeptData; -import com.zt.plat.module.databus.api.dto.CursorPageReqDTO; -import com.zt.plat.module.databus.api.dto.CursorPageResult; -import com.zt.plat.module.databus.api.provider.DatabusDeptProviderApi; -import com.zt.plat.module.system.dal.dataobject.dept.DeptDO; -import com.zt.plat.module.system.dal.dataobject.user.AdminUserDO; -import com.zt.plat.module.system.dal.mysql.dept.DeptMapper; -import com.zt.plat.module.system.dal.mysql.user.AdminUserMapper; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RestController; - -import java.util.*; -import java.util.stream.Collectors; - -import static com.zt.plat.framework.common.pojo.CommonResult.success; - -/** - * Databus 部门数据提供者 API 实现 - * - * @author ZT - */ -@Slf4j -@RestController -@Validated -public class DatabusDeptProviderApiImpl implements DatabusDeptProviderApi { - - @Resource - private DeptMapper deptMapper; - - @Resource - private AdminUserMapper userMapper; - - @Override - public CommonResult> getPageByCursor(CursorPageReqDTO reqDTO) { - // 构建游标查询条件 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(DeptDO::getDeptSource, 3); - // 游标条件:create_time > cursorTime OR (create_time = cursorTime AND id > cursorId) - if (!reqDTO.isFirstPage()) { - queryWrapper.and(w -> w - .gt(DeptDO::getCreateTime, reqDTO.getCursorTime()) - .or(o -> o - .eq(DeptDO::getCreateTime, reqDTO.getCursorTime()) - .gt(DeptDO::getId, reqDTO.getCursorId()) - ) - ); - } - - // 租户过滤(如果指定) - if (reqDTO.getTenantId() != null) { - queryWrapper.eq(DeptDO::getTenantId, reqDTO.getTenantId()); - } - - // 按 create_time, id 升序排列,确保顺序稳定 - queryWrapper.orderByAsc(DeptDO::getCreateTime) - .orderByAsc(DeptDO::getId); - - // 多查一条判断是否有更多数据 - int limit = reqDTO.getBatchSize() != null ? reqDTO.getBatchSize() : 100; - queryWrapper.last("LIMIT " + (limit + 1)); - - List deptList = deptMapper.selectList(queryWrapper); - - // 判断是否有更多 - boolean hasMore = deptList.size() > limit; - if (hasMore) { - deptList = deptList.subList(0, limit); - } - - if (CollUtil.isEmpty(deptList)) { - return success(CursorPageResult.empty()); - } - - // 收集负责人用户ID - Set leaderUserIds = deptList.stream() - .map(DeptDO::getLeaderUserId) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - - // 批量查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (CollUtil.isNotEmpty(leaderUserIds)) { - List users = userMapper.selectBatchIds(leaderUserIds); - userNameMap = users.stream() - .collect(Collectors.toMap(AdminUserDO::getId, AdminUserDO::getNickname, (v1, v2) -> v1)); - } - - // 转换为同步数据 - Map finalUserNameMap = userNameMap; - List dataList = deptList.stream() - .map(dept -> convertToDatabusDeptData(dept, finalUserNameMap)) - .collect(Collectors.toList()); - - // 获取最后一条数据的游标 - DeptDO lastDept = deptList.get(deptList.size() - 1); - - // 首次查询时返回总数 - Long total = null; - if (reqDTO.isFirstPage()) { - LambdaQueryWrapper countWrapper = new LambdaQueryWrapper<>(); - countWrapper.eq(DeptDO::getDeptSource, 3); - if (reqDTO.getTenantId() != null) { - countWrapper.eq(DeptDO::getTenantId, reqDTO.getTenantId()); - } - total = deptMapper.selectCount(countWrapper); - } - - return success(CursorPageResult.of( - dataList, - lastDept.getCreateTime(), - lastDept.getId(), - hasMore, - total - )); - } - - @Override - public CommonResult getById(Long id) { - DeptDO dept = deptMapper.selectById(id); - if (dept == null) { - return success(null); - } - - // 查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (dept.getLeaderUserId() != null) { - AdminUserDO user = userMapper.selectById(dept.getLeaderUserId()); - if (user != null) { - userNameMap.put(user.getId(), user.getNickname()); - } - } - - return success(convertToDatabusDeptData(dept, userNameMap)); - } - - @Override - public CommonResult> getListByIds(List ids) { - if (CollUtil.isEmpty(ids)) { - return success(Collections.emptyList()); - } - - List deptList = deptMapper.selectBatchIds(ids); - if (CollUtil.isEmpty(deptList)) { - return success(Collections.emptyList()); - } - - // 收集负责人用户ID - Set leaderUserIds = deptList.stream() - .map(DeptDO::getLeaderUserId) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - - // 批量查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (CollUtil.isNotEmpty(leaderUserIds)) { - List users = userMapper.selectBatchIds(leaderUserIds); - userNameMap = users.stream() - .collect(Collectors.toMap(AdminUserDO::getId, AdminUserDO::getNickname, (v1, v2) -> v1)); - } - - Map finalUserNameMap = userNameMap; - List dataList = deptList.stream() - .map(dept -> convertToDatabusDeptData(dept, finalUserNameMap)) - .collect(Collectors.toList()); - - return success(dataList); - } - - @Override - public CommonResult count(Long tenantId) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - // ⚠️ 只统计 userSource = 3 的用户 - queryWrapper.eq(DeptDO::getDeptSource, 3); - if (tenantId != null) { - queryWrapper.eq(DeptDO::getTenantId, tenantId); - } - return success(deptMapper.selectCount(queryWrapper)); - } - - /** - * 将 DeptDO 转换为 DatabusDeptData - */ - private DatabusDeptData convertToDatabusDeptData(DeptDO dept, Map userNameMap) { - // 根据 isCompany 反推 deptType - Integer deptType = null; - if (Boolean.TRUE.equals(dept.getIsCompany())) { - deptType = 28; // 公司 - } else if (Boolean.FALSE.equals(dept.getIsCompany())) { - deptType = 26; // 部门 - } - - return DatabusDeptData.builder() - .id(dept.getId()) - .code(dept.getCode()) - .name(dept.getName()) - .shortName(dept.getShortName()) - .parentId(dept.getParentId()) - .sort(dept.getSort()) - .status(dept.getStatus()) - .deptType(deptType) - .isGroup(dept.getIsGroup()) - .isCompany(dept.getIsCompany()) - .deptSource(dept.getDeptSource()) - .leaderUserId(dept.getLeaderUserId()) - .leaderUserName(dept.getLeaderUserId() != null ? userNameMap.get(dept.getLeaderUserId()) : null) - .phone(dept.getPhone()) - .email(dept.getEmail()) - .tenantId(dept.getTenantId()) - .createTime(dept.getCreateTime()) - .updateTime(dept.getUpdateTime()) - .build(); - } - -} diff --git a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_REMOTE_71078.java b/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_REMOTE_71078.java deleted file mode 100644 index 9c5e55b7..00000000 --- a/zt-module-system/zt-module-system-server/src/main/java/com/zt/plat/module/system/api/databus/DatabusDeptProviderApiImpl_REMOTE_71078.java +++ /dev/null @@ -1,220 +0,0 @@ -package com.zt.plat.module.system.api.databus; - -import cn.hutool.core.collection.CollUtil; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.zt.plat.framework.common.pojo.CommonResult; -import com.zt.plat.module.databus.api.data.DatabusDeptData; -import com.zt.plat.module.databus.api.dto.CursorPageReqDTO; -import com.zt.plat.module.databus.api.dto.CursorPageResult; -import com.zt.plat.module.databus.api.provider.DatabusDeptProviderApi; -import com.zt.plat.module.system.dal.dataobject.dept.DeptDO; -import com.zt.plat.module.system.dal.dataobject.user.AdminUserDO; -import com.zt.plat.module.system.dal.mysql.dept.DeptMapper; -import com.zt.plat.module.system.dal.mysql.user.AdminUserMapper; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RestController; - -import java.util.*; -import java.util.stream.Collectors; - -import static com.zt.plat.framework.common.pojo.CommonResult.success; - -/** - * Databus 部门数据提供者 API 实现 - * - * @author ZT - */ -@Slf4j -@RestController -@Validated -public class DatabusDeptProviderApiImpl implements DatabusDeptProviderApi { - - @Resource - private DeptMapper deptMapper; - - @Resource - private AdminUserMapper userMapper; - - @Override - public CommonResult> getPageByCursor(CursorPageReqDTO reqDTO) { - // 构建游标查询条件 - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(DeptDO::getDeptSource, 3); - // 游标条件:create_time > cursorTime OR (create_time = cursorTime AND id > cursorId) - if (!reqDTO.isFirstPage()) { - queryWrapper.and(w -> w - .gt(DeptDO::getCreateTime, reqDTO.getCursorTime()) - .or(o -> o - .eq(DeptDO::getCreateTime, reqDTO.getCursorTime()) - .gt(DeptDO::getId, reqDTO.getCursorId()) - ) - ); - } - - // 租户过滤(如果指定) - if (reqDTO.getTenantId() != null) { - queryWrapper.eq(DeptDO::getTenantId, reqDTO.getTenantId()); - } - - // 按 create_time, id 升序排列,确保顺序稳定 - queryWrapper.orderByAsc(DeptDO::getCreateTime) - .orderByAsc(DeptDO::getId); - - // 多查一条判断是否有更多数据 - int limit = reqDTO.getBatchSize() != null ? reqDTO.getBatchSize() : 100; - queryWrapper.last("LIMIT " + (limit + 1)); - - List deptList = deptMapper.selectList(queryWrapper); - - // 判断是否有更多 - boolean hasMore = deptList.size() > limit; - if (hasMore) { - deptList = deptList.subList(0, limit); - } - - if (CollUtil.isEmpty(deptList)) { - return success(CursorPageResult.empty()); - } - - // 收集负责人用户ID - Set leaderUserIds = deptList.stream() - .map(DeptDO::getLeaderUserId) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - - // 批量查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (CollUtil.isNotEmpty(leaderUserIds)) { - List users = userMapper.selectBatchIds(leaderUserIds); - userNameMap = users.stream() - .collect(Collectors.toMap(AdminUserDO::getId, AdminUserDO::getNickname, (v1, v2) -> v1)); - } - - // 转换为同步数据 - Map finalUserNameMap = userNameMap; - List dataList = deptList.stream() - .map(dept -> convertToDatabusDeptData(dept, finalUserNameMap)) - .collect(Collectors.toList()); - - // 获取最后一条数据的游标 - DeptDO lastDept = deptList.get(deptList.size() - 1); - - // 首次查询时返回总数 - Long total = null; - if (reqDTO.isFirstPage()) { - LambdaQueryWrapper countWrapper = new LambdaQueryWrapper<>(); - countWrapper.eq(DeptDO::getDeptSource, 3); - if (reqDTO.getTenantId() != null) { - countWrapper.eq(DeptDO::getTenantId, reqDTO.getTenantId()); - } - total = deptMapper.selectCount(countWrapper); - } - - return success(CursorPageResult.of( - dataList, - lastDept.getCreateTime(), - lastDept.getId(), - hasMore, - total - )); - } - - @Override - public CommonResult getById(Long id) { - DeptDO dept = deptMapper.selectById(id); - if (dept == null) { - return success(null); - } - - // 查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (dept.getLeaderUserId() != null) { - AdminUserDO user = userMapper.selectById(dept.getLeaderUserId()); - if (user != null) { - userNameMap.put(user.getId(), user.getNickname()); - } - } - - return success(convertToDatabusDeptData(dept, userNameMap)); - } - - @Override - public CommonResult> getListByIds(List ids) { - if (CollUtil.isEmpty(ids)) { - return success(Collections.emptyList()); - } - - List deptList = deptMapper.selectBatchIds(ids); - if (CollUtil.isEmpty(deptList)) { - return success(Collections.emptyList()); - } - - // 收集负责人用户ID - Set leaderUserIds = deptList.stream() - .map(DeptDO::getLeaderUserId) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); - - // 批量查询负责人用户名 - Map userNameMap = new HashMap<>(); - if (CollUtil.isNotEmpty(leaderUserIds)) { - List users = userMapper.selectBatchIds(leaderUserIds); - userNameMap = users.stream() - .collect(Collectors.toMap(AdminUserDO::getId, AdminUserDO::getNickname, (v1, v2) -> v1)); - } - - Map finalUserNameMap = userNameMap; - List dataList = deptList.stream() - .map(dept -> convertToDatabusDeptData(dept, finalUserNameMap)) - .collect(Collectors.toList()); - - return success(dataList); - } - - @Override - public CommonResult count(Long tenantId) { - LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(DeptDO::getDeptSource, 3); - if (tenantId != null) { - queryWrapper.eq(DeptDO::getTenantId, tenantId); - } - return success(deptMapper.selectCount(queryWrapper)); - } - - /** - * 将 DeptDO 转换为 DatabusDeptData - */ - private DatabusDeptData convertToDatabusDeptData(DeptDO dept, Map userNameMap) { - // 根据 isCompany 反推 deptType - Integer deptType = null; - if (Boolean.TRUE.equals(dept.getIsCompany())) { - deptType = 28; // 公司 - } else if (Boolean.FALSE.equals(dept.getIsCompany())) { - deptType = 26; // 部门 - } - - return DatabusDeptData.builder() - .id(dept.getId()) - .code(dept.getCode()) - .name(dept.getName()) - .shortName(dept.getShortName()) - .parentId(dept.getParentId()) - .sort(dept.getSort()) - .status(dept.getStatus()) - .deptType(deptType) - .isGroup(dept.getIsGroup()) - .isCompany(dept.getIsCompany()) - .deptSource(dept.getDeptSource()) - .leaderUserId(dept.getLeaderUserId()) - .leaderUserName(dept.getLeaderUserId() != null ? userNameMap.get(dept.getLeaderUserId()) : null) - .phone(dept.getPhone()) - .email(dept.getEmail()) - .tenantId(dept.getTenantId()) - .createTime(dept.getCreateTime()) - .updateTime(dept.getUpdateTime()) - .build(); - } - -} From 7a15fff979972234d5f3a79b114e11d4742f7edf Mon Sep 17 00:00:00 2001 From: qianshijiang <1965297290@qq.com> Date: Tue, 13 Jan 2026 15:14:09 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/asyncTask/AsyncLatchUtils.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/zt-framework/zt-common/src/main/java/com/zt/plat/framework/common/util/asyncTask/AsyncLatchUtils.java b/zt-framework/zt-common/src/main/java/com/zt/plat/framework/common/util/asyncTask/AsyncLatchUtils.java index 30837df7..25d4f235 100644 --- a/zt-framework/zt-common/src/main/java/com/zt/plat/framework/common/util/asyncTask/AsyncLatchUtils.java +++ b/zt-framework/zt-common/src/main/java/com/zt/plat/framework/common/util/asyncTask/AsyncLatchUtils.java @@ -9,7 +9,7 @@ import java.util.concurrent.*; * 多次提交,一次等待 */ public class AsyncLatchUtils { - private static final ThreadLocal> THREADLOCAL = ThreadLocal.withInitial(LinkedList::new); + private static final ThreadLocal> THREAD_LOCAL = ThreadLocal.withInitial(LinkedList::new); /** * 提交一个异步任务 @@ -17,7 +17,7 @@ public class AsyncLatchUtils { * @param runnable 需要异步执行的具体业务逻辑 */ public static void submitTask(Executor executor, Runnable runnable) { - THREADLOCAL.get().add(new TaskInfo(executor, runnable)); + THREAD_LOCAL.get().add(new TaskInfo(executor, runnable)); } /** @@ -25,8 +25,8 @@ public class AsyncLatchUtils { * @return */ private static List popTask() { - List taskInfos = THREADLOCAL.get(); - THREADLOCAL.remove(); + List taskInfos = THREAD_LOCAL.get(); + THREAD_LOCAL.remove(); return taskInfos; } @@ -39,7 +39,7 @@ public class AsyncLatchUtils { */ public static boolean waitFor(long timeout, TimeUnit timeUnit) { List taskInfos = popTask(); - if (taskInfos.isEmpty()) { + if (taskInfos.isEmpty()) { return true; } CountDownLatch latch = new CountDownLatch(taskInfos.size()); @@ -57,8 +57,11 @@ public class AsyncLatchUtils { boolean await = false; try { await = latch.await(timeout, timeUnit); - } catch (Exception ignored) {} - return await; + } catch (Exception ignored) { + // 恢复中断状态 + Thread.currentThread().interrupt(); + } + return await; } private static final class TaskInfo { From 3524f0fffb25e66c983c1df42f83a45b60d69f69 Mon Sep 17 00:00:00 2001 From: wuzongyong <13203449218@163.com> Date: Wed, 14 Jan 2026 18:11:02 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat(gateway):=20=E6=B7=BB=E5=8A=A0API?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=87=AD=E8=AF=81=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在ApiClientCredentialDO实体类中新增enableEncryption字段 - 在ApiClientCredentialRespVO响应对象中添加加密启用状态字段 - 在ApiClientCredentialSaveReqVO请求对象中添加加密启用状态字段 - 在GatewaySecurityFilter中实现加密启用状态检查逻辑 - 添加数据库表结构变更脚本支持加密字段 --- ...s_api_credential_enable_encryption_20260114.sql | 7 +++++++ .../vo/credential/ApiClientCredentialRespVO.java | 3 +++ .../credential/ApiClientCredentialSaveReqVO.java | 4 ++++ .../dataobject/gateway/ApiClientCredentialDO.java | 2 ++ .../gateway/security/GatewaySecurityFilter.java | 14 ++++++++++++++ 5 files changed, 30 insertions(+) create mode 100644 sql/dm/databus_api_credential_enable_encryption_20260114.sql diff --git a/sql/dm/databus_api_credential_enable_encryption_20260114.sql b/sql/dm/databus_api_credential_enable_encryption_20260114.sql new file mode 100644 index 00000000..c7e0da21 --- /dev/null +++ b/sql/dm/databus_api_credential_enable_encryption_20260114.sql @@ -0,0 +1,7 @@ +-- 为 API 客户端凭证表添加"是否启用加密"字段 +-- 2026-01-14 + +ALTER TABLE databus_api_client_credential + ADD enable_encryption BIT DEFAULT '1' NOT NULL; + +COMMENT ON COLUMN databus_api_client_credential.enable_encryption IS '是否启用加密传输'; diff --git a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/controller/admin/gateway/vo/credential/ApiClientCredentialRespVO.java b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/controller/admin/gateway/vo/credential/ApiClientCredentialRespVO.java index 33e2dbe7..a4cc7ec5 100644 --- a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/controller/admin/gateway/vo/credential/ApiClientCredentialRespVO.java +++ b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/controller/admin/gateway/vo/credential/ApiClientCredentialRespVO.java @@ -42,6 +42,9 @@ public class ApiClientCredentialRespVO { @Schema(description = "匿名访问固定用户昵称", example = "张三") private String anonymousUserNickname; + @Schema(description = "是否启用加密", example = "true") + private Boolean enableEncryption; + @Schema(description = "创建时间") private LocalDateTime createTime; diff --git a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/controller/admin/gateway/vo/credential/ApiClientCredentialSaveReqVO.java b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/controller/admin/gateway/vo/credential/ApiClientCredentialSaveReqVO.java index 11043ac5..796b1704 100644 --- a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/controller/admin/gateway/vo/credential/ApiClientCredentialSaveReqVO.java +++ b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/controller/admin/gateway/vo/credential/ApiClientCredentialSaveReqVO.java @@ -45,4 +45,8 @@ public class ApiClientCredentialSaveReqVO { @Schema(description = "匿名访问固定用户 ID", example = "1024") private Long anonymousUserId; + @Schema(description = "是否启用加密", example = "true") + @NotNull(message = "启用加密标识不能为空") + private Boolean enableEncryption; + } diff --git a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/dal/dataobject/gateway/ApiClientCredentialDO.java b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/dal/dataobject/gateway/ApiClientCredentialDO.java index 0bf5134f..7b44ecce 100644 --- a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/dal/dataobject/gateway/ApiClientCredentialDO.java +++ b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/dal/dataobject/gateway/ApiClientCredentialDO.java @@ -38,4 +38,6 @@ public class ApiClientCredentialDO extends BaseDO { private Long anonymousUserId; + private Boolean enableEncryption; + } diff --git a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/framework/integration/gateway/security/GatewaySecurityFilter.java b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/framework/integration/gateway/security/GatewaySecurityFilter.java index f9e5754d..b37dfb76 100644 --- a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/framework/integration/gateway/security/GatewaySecurityFilter.java +++ b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/framework/integration/gateway/security/GatewaySecurityFilter.java @@ -238,6 +238,11 @@ public class GatewaySecurityFilter extends OncePerRequestFilter { private byte[] decryptRequestBody(byte[] originalBody, ApiClientCredentialDO credential, ApiGatewayProperties.Security security) { + // 检查是否启用加密,如果未启用则直接返回原文 + if (credential != null && Boolean.FALSE.equals(credential.getEnableEncryption())) { + return originalBody != null ? originalBody : new byte[0]; + } + if (originalBody == null || originalBody.length == 0) { return new byte[0]; } @@ -390,6 +395,11 @@ public class GatewaySecurityFilter extends OncePerRequestFilter { private void encryptResponse(ContentCachingResponseWrapper responseWrapper, ApiClientCredentialDO credential, ApiGatewayProperties.Security security) throws IOException { + // 检查是否启用加密,如果未启用则直接返回,不加密响应 + if (credential != null && Boolean.FALSE.equals(credential.getEnableEncryption())) { + return; + } + if (!security.isEncryptResponse()) { return; } @@ -524,6 +534,10 @@ public class GatewaySecurityFilter extends OncePerRequestFilter { if (security == null || credential == null) { return false; } + // 检查是否启用加密,如果未启用则不加密错误响应 + if (Boolean.FALSE.equals(credential.getEnableEncryption())) { + return false; + } if (!security.isEncryptResponse()) { return false; }