From 7f0059984deae80a109a457f41ef8732d52228ff Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sat, 26 Jul 2025 10:24:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E5=86=85?= =?UTF-8?q?=E9=83=A8=20API=20=E4=BE=9D=E8=B5=96=E6=A8=A1=E5=BC=8F=EF=BC=88?= =?UTF-8?q?=E9=99=8D=E4=BD=8E=E8=80=A6=E5=90=88=EF=BC=8C=E5=85=AC=E4=BC=97?= =?UTF-8?q?=E5=8F=B7=E6=8A=95=E7=A5=A8=E7=BB=93=E8=AE=BA=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E5=9C=A8=20common=20=E6=A8=A1=E5=9D=97=E6=96=B0=E5=A2=9E=20api?= =?UTF-8?q?=20=E5=8C=85=EF=BC=8C=E5=9C=A8=E5=AF=B9=E5=BA=94=20biz=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=A2=9E=E5=8A=A0=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/common/api/system/DictApi.java | 37 +++++++++++ .../system/DictItemApi.java} | 6 +- .../admin/common/api/system/MenuApi.java | 38 +++++++++++ .../admin/common/api/system/RoleApi.java | 41 ++++++++++++ .../admin/common/api/system/RoleMenuApi.java | 61 ++++++++++++++++++ .../system/UserApi.java} | 14 +++- .../common/api/tenant/PackageMenuApi.java | 36 +++++++++++ .../admin/common/api/tenant/TenantApi.java | 34 ++++++++++ .../common/api/tenant/TenantDataApi.java | 10 +-- .../config/excel/ExcelDictConverter.java | 6 +- .../common/context/UserContextHolder.java | 4 +- .../admin/common/model/dto/TenantDTO.java | 60 +++++++++++++++++ .../continew-plugin-generator/pom.xml | 8 --- .../controller/GeneratorController.java | 10 ++- .../continew-plugin-tenant/pom.xml | 8 --- .../admin/tenant/api/PackageMenuApiImpl.java | 42 ++++++++++++ .../admin/tenant/api/TenantApiImpl.java | 47 ++++++++++++++ .../tenant/controller/PackageController.java | 12 +--- .../tenant/controller/TenantController.java | 11 +--- .../service/impl/TenantServiceImpl.java | 44 ++++++------- .../admin/system/api/DictApiImpl.java | 45 +++++++++++++ .../admin/system/api/DictItemApiImpl.java | 43 +++++++++++++ .../admin/system/api/MenuApiImpl.java | 49 ++++++++++++++ .../admin/system/api/RoleApiImpl.java | 48 ++++++++++++++ .../admin/system/api/RoleMenuApiImpl.java | 64 +++++++++++++++++++ .../api/TenantDataApiForSystemImpl.java | 52 ++++++--------- .../admin/system/api/UserApiImpl.java | 54 ++++++++++++++++ .../admin/system/service/DictItemService.java | 12 +++- .../service/impl/RoleMenuServiceImpl.java | 2 - .../system/service/impl/UserServiceImpl.java | 11 +--- 30 files changed, 781 insertions(+), 128 deletions(-) create mode 100644 continew-common/src/main/java/top/continew/admin/common/api/system/DictApi.java rename continew-common/src/main/java/top/continew/admin/common/{service/CommonDictItemService.java => api/system/DictItemApi.java} (89%) create mode 100644 continew-common/src/main/java/top/continew/admin/common/api/system/MenuApi.java create mode 100644 continew-common/src/main/java/top/continew/admin/common/api/system/RoleApi.java create mode 100644 continew-common/src/main/java/top/continew/admin/common/api/system/RoleMenuApi.java rename continew-common/src/main/java/top/continew/admin/common/{service/CommonUserService.java => api/system/UserApi.java} (82%) create mode 100644 continew-common/src/main/java/top/continew/admin/common/api/tenant/PackageMenuApi.java create mode 100644 continew-common/src/main/java/top/continew/admin/common/api/tenant/TenantApi.java rename continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/handler/TenantDataHandler.java => continew-common/src/main/java/top/continew/admin/common/api/tenant/TenantDataApi.java (81%) create mode 100644 continew-common/src/main/java/top/continew/admin/common/model/dto/TenantDTO.java create mode 100644 continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/api/PackageMenuApiImpl.java create mode 100644 continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/api/TenantApiImpl.java create mode 100644 continew-system/src/main/java/top/continew/admin/system/api/DictApiImpl.java create mode 100644 continew-system/src/main/java/top/continew/admin/system/api/DictItemApiImpl.java create mode 100644 continew-system/src/main/java/top/continew/admin/system/api/MenuApiImpl.java create mode 100644 continew-system/src/main/java/top/continew/admin/system/api/RoleApiImpl.java create mode 100644 continew-system/src/main/java/top/continew/admin/system/api/RoleMenuApiImpl.java rename continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/handler/TenantDataHandlerForSystem.java => continew-system/src/main/java/top/continew/admin/system/api/TenantDataApiForSystemImpl.java (82%) create mode 100644 continew-system/src/main/java/top/continew/admin/system/api/UserApiImpl.java diff --git a/continew-common/src/main/java/top/continew/admin/common/api/system/DictApi.java b/continew-common/src/main/java/top/continew/admin/common/api/system/DictApi.java new file mode 100644 index 00000000..9930e76f --- /dev/null +++ b/continew-common/src/main/java/top/continew/admin/common/api/system/DictApi.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.common.api.system; + +import top.continew.starter.extension.crud.model.resp.LabelValueResp; + +import java.util.List; + +/** + * 字典业务 API + * + * @author Charles7c + * @since 2025/7/26 10:16 + */ +public interface DictApi { + + /** + * 查询字典列表 + * + * @return 字典列表(包含枚举字典列表) + */ + List listAll(); +} diff --git a/continew-common/src/main/java/top/continew/admin/common/service/CommonDictItemService.java b/continew-common/src/main/java/top/continew/admin/common/api/system/DictItemApi.java similarity index 89% rename from continew-common/src/main/java/top/continew/admin/common/service/CommonDictItemService.java rename to continew-common/src/main/java/top/continew/admin/common/api/system/DictItemApi.java index 8ea19412..3830e3e1 100644 --- a/continew-common/src/main/java/top/continew/admin/common/service/CommonDictItemService.java +++ b/continew-common/src/main/java/top/continew/admin/common/api/system/DictItemApi.java @@ -14,19 +14,19 @@ * limitations under the License. */ -package top.continew.admin.common.service; +package top.continew.admin.common.api.system; import top.continew.starter.extension.crud.model.resp.LabelValueResp; import java.util.List; /** - * 公共字典项业务接口 + * 字典项业务 API * * @author Charles7c * @since 2025/4/9 20:17 */ -public interface CommonDictItemService { +public interface DictItemApi { /** * 根据字典编码查询 diff --git a/continew-common/src/main/java/top/continew/admin/common/api/system/MenuApi.java b/continew-common/src/main/java/top/continew/admin/common/api/system/MenuApi.java new file mode 100644 index 00000000..e349f952 --- /dev/null +++ b/continew-common/src/main/java/top/continew/admin/common/api/system/MenuApi.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.common.api.system; + +import cn.hutool.core.lang.tree.Tree; + +import java.util.List; + +/** + * 菜单业务 API + * + * @author Charles7c + * @since 2025/7/26 9:53 + */ +public interface MenuApi { + + /** + * 查询树结构列表 + * + * @param excludeMenuIds 排除的菜单 ID 列表 + * @return 树结构列表 + */ + List> listTree(List excludeMenuIds); +} diff --git a/continew-common/src/main/java/top/continew/admin/common/api/system/RoleApi.java b/continew-common/src/main/java/top/continew/admin/common/api/system/RoleApi.java new file mode 100644 index 00000000..63250b73 --- /dev/null +++ b/continew-common/src/main/java/top/continew/admin/common/api/system/RoleApi.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.common.api.system; + +/** + * 角色业务 API + * + * @author Charles7c + * @since 2025/7/26 9:39 + */ +public interface RoleApi { + + /** + * 根据编码查询 ID + * + * @param code 编码 + * @return 角色 ID + */ + Long getIdByCode(String code); + + /** + * 更新用户上下文 + * + * @param roleId 角色 ID + */ + void updateUserContext(Long roleId); +} diff --git a/continew-common/src/main/java/top/continew/admin/common/api/system/RoleMenuApi.java b/continew-common/src/main/java/top/continew/admin/common/api/system/RoleMenuApi.java new file mode 100644 index 00000000..e802bcac --- /dev/null +++ b/continew-common/src/main/java/top/continew/admin/common/api/system/RoleMenuApi.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.common.api.system; + +import java.util.List; +import java.util.Set; + +/** + * 角色和菜单关联业务 API + * + * @author Charles7c + * @since 2025/7/26 9:39 + */ +public interface RoleMenuApi { + + /** + * 根据菜单 ID 列表查询角色 ID 列表 + * + * @param menuIds 菜单 ID 列表(Not In) + * @return 角色 ID 列表 + */ + Set listRoleIdByNotInMenuIds(List menuIds); + + /** + * 根据角色 ID 列表查询菜单 ID 列表 + * + * @param roleIds 角色 ID 列表 + * @return 菜单 ID 列表 + */ + List listMenuIdByRoleIds(List roleIds); + + /** + * 根据菜单 ID 列表删除 + * + * @param menuIds 菜单 ID 列表(Not In) + */ + void deleteByNotInMenuIds(List menuIds); + + /** + * 新增 + * + * @param menuIds 菜单 ID 列表 + * @param roleId 角色 ID + * @return 是否新增成功(true:成功;false:无变更/失败) + */ + boolean add(List menuIds, Long roleId); +} diff --git a/continew-common/src/main/java/top/continew/admin/common/service/CommonUserService.java b/continew-common/src/main/java/top/continew/admin/common/api/system/UserApi.java similarity index 82% rename from continew-common/src/main/java/top/continew/admin/common/service/CommonUserService.java rename to continew-common/src/main/java/top/continew/admin/common/api/system/UserApi.java index 66649a4e..502e745a 100644 --- a/continew-common/src/main/java/top/continew/admin/common/service/CommonUserService.java +++ b/continew-common/src/main/java/top/continew/admin/common/api/system/UserApi.java @@ -14,19 +14,19 @@ * limitations under the License. */ -package top.continew.admin.common.service; +package top.continew.admin.common.api.system; import cn.crane4j.annotation.ContainerMethod; import cn.crane4j.annotation.MappingType; import top.continew.admin.common.constant.ContainerConstants; /** - * 公共用户业务接口 + * 用户业务 API * * @author Charles7c * @since 2025/1/9 20:17 */ -public interface CommonUserService { +public interface UserApi { /** * 根据 ID 查询昵称 @@ -40,4 +40,12 @@ public interface CommonUserService { */ @ContainerMethod(namespace = ContainerConstants.USER_NICKNAME, type = MappingType.ORDER_OF_KEYS) String getNicknameById(Long id); + + /** + * 重置密码 + * + * @param newPassword 新密码 + * @param id ID + */ + void resetPassword(String newPassword, Long id); } diff --git a/continew-common/src/main/java/top/continew/admin/common/api/tenant/PackageMenuApi.java b/continew-common/src/main/java/top/continew/admin/common/api/tenant/PackageMenuApi.java new file mode 100644 index 00000000..79d895fc --- /dev/null +++ b/continew-common/src/main/java/top/continew/admin/common/api/tenant/PackageMenuApi.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.common.api.tenant; + +import java.util.List; + +/** + * 套餐和菜单关联业务 API + * + * @author Charles7c + * @since 2025/7/23 21:13 + */ +public interface PackageMenuApi { + + /** + * 根据套餐 ID 查询 + * + * @param packageId 套餐 ID + * @return 菜单 ID 列表 + */ + List listMenuIdsByPackageId(Long packageId); +} diff --git a/continew-common/src/main/java/top/continew/admin/common/api/tenant/TenantApi.java b/continew-common/src/main/java/top/continew/admin/common/api/tenant/TenantApi.java new file mode 100644 index 00000000..d70b8b53 --- /dev/null +++ b/continew-common/src/main/java/top/continew/admin/common/api/tenant/TenantApi.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.common.api.tenant; + +/** + * 租户业务 API + * + * @author Charles7c + * @since 2025/7/23 21:13 + */ +public interface TenantApi { + + /** + * 绑定租户管理员用户 + * + * @param tenantId 租户 ID + * @param userId 用户 ID + */ + void bindAdminUser(Long tenantId, Long userId); +} diff --git a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/handler/TenantDataHandler.java b/continew-common/src/main/java/top/continew/admin/common/api/tenant/TenantDataApi.java similarity index 81% rename from continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/handler/TenantDataHandler.java rename to continew-common/src/main/java/top/continew/admin/common/api/tenant/TenantDataApi.java index 6ffa5a62..c82986ae 100644 --- a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/handler/TenantDataHandler.java +++ b/continew-common/src/main/java/top/continew/admin/common/api/tenant/TenantDataApi.java @@ -14,25 +14,25 @@ * limitations under the License. */ -package top.continew.admin.tenant.handler; +package top.continew.admin.common.api.tenant; -import top.continew.admin.tenant.model.req.TenantReq; +import top.continew.admin.common.model.dto.TenantDTO; /** - * 租户数据处理器 + * 租户数据 API * * @author 小熊 * @author Charles7c * @since 2024/12/2 20:08 */ -public interface TenantDataHandler { +public interface TenantDataApi { /** * 初始化数据 * * @param tenant 租户信息 */ - void init(TenantReq tenant); + void init(TenantDTO tenant); /** * 清除数据 diff --git a/continew-common/src/main/java/top/continew/admin/common/config/excel/ExcelDictConverter.java b/continew-common/src/main/java/top/continew/admin/common/config/excel/ExcelDictConverter.java index f73d2a0a..4c1eee41 100644 --- a/continew-common/src/main/java/top/continew/admin/common/config/excel/ExcelDictConverter.java +++ b/continew-common/src/main/java/top/continew/admin/common/config/excel/ExcelDictConverter.java @@ -24,7 +24,7 @@ import cn.idev.excel.metadata.GlobalConfiguration; import cn.idev.excel.metadata.data.ReadCellData; import cn.idev.excel.metadata.data.WriteCellData; import cn.idev.excel.metadata.property.ExcelContentProperty; -import top.continew.admin.common.service.CommonDictItemService; +import top.continew.admin.common.api.system.DictItemApi; import top.continew.starter.core.constant.StringConstants; import top.continew.starter.extension.crud.model.resp.LabelValueResp; @@ -86,7 +86,7 @@ public class ExcelDictConverter implements Converter { if (dictExcelProperty == null) { throw new IllegalArgumentException("Excel 字典转换器异常:请为字段添加 @DictExcelProperty 注解"); } - CommonDictItemService dictItemService = SpringUtil.getBean(CommonDictItemService.class); - return dictItemService.listByDictCode(dictExcelProperty.value()); + DictItemApi dictItemApi = SpringUtil.getBean(DictItemApi.class); + return dictItemApi.listByDictCode(dictExcelProperty.value()); } } diff --git a/continew-common/src/main/java/top/continew/admin/common/context/UserContextHolder.java b/continew-common/src/main/java/top/continew/admin/common/context/UserContextHolder.java index ceaa46fc..48facc3f 100644 --- a/continew-common/src/main/java/top/continew/admin/common/context/UserContextHolder.java +++ b/continew-common/src/main/java/top/continew/admin/common/context/UserContextHolder.java @@ -20,7 +20,7 @@ import cn.dev33.satoken.session.SaSession; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.convert.Convert; import cn.hutool.extra.spring.SpringUtil; -import top.continew.admin.common.service.CommonUserService; +import top.continew.admin.common.api.system.UserApi; import top.continew.starter.core.util.ExceptionUtils; /** @@ -177,7 +177,7 @@ public class UserContextHolder { * @return 用户昵称 */ public static String getNickname(Long userId) { - return ExceptionUtils.exToNull(() -> SpringUtil.getBean(CommonUserService.class).getNicknameById(userId)); + return ExceptionUtils.exToNull(() -> SpringUtil.getBean(UserApi.class).getNicknameById(userId)); } /** diff --git a/continew-common/src/main/java/top/continew/admin/common/model/dto/TenantDTO.java b/continew-common/src/main/java/top/continew/admin/common/model/dto/TenantDTO.java new file mode 100644 index 00000000..b0ec8c5e --- /dev/null +++ b/continew-common/src/main/java/top/continew/admin/common/model/dto/TenantDTO.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.common.model.dto; + +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 租户信息 + * + * @author Charles7c + * @since 2025/7/23 21:05 + */ +@Data +public class TenantDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * ID + */ + private Long id; + + /** + * 名称 + */ + private String name; + + /** + * 管理员用户名 + */ + private String username; + + /** + * 管理员密码 + */ + private String password; + + /** + * 套餐 ID + */ + private Long packageId; +} diff --git a/continew-plugin/continew-plugin-generator/pom.xml b/continew-plugin/continew-plugin-generator/pom.xml index a6cacab5..5779f624 100644 --- a/continew-plugin/continew-plugin-generator/pom.xml +++ b/continew-plugin/continew-plugin-generator/pom.xml @@ -14,12 +14,4 @@ ${project.artifactId} 代码生成器插件 - - - - - top.continew.admin - continew-system - - \ No newline at end of file diff --git a/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/controller/GeneratorController.java b/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/controller/GeneratorController.java index 3086c613..23898d84 100644 --- a/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/controller/GeneratorController.java +++ b/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/controller/GeneratorController.java @@ -25,13 +25,13 @@ import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import top.continew.admin.common.api.system.DictApi; import top.continew.admin.generator.model.entity.FieldConfigDO; import top.continew.admin.generator.model.entity.GenConfigDO; import top.continew.admin.generator.model.query.GenConfigQuery; import top.continew.admin.generator.model.req.GenConfigReq; import top.continew.admin.generator.model.resp.GeneratePreviewResp; import top.continew.admin.generator.service.GeneratorService; -import top.continew.admin.system.service.DictService; import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.resp.LabelValueResp; import top.continew.starter.extension.crud.model.resp.PageResp; @@ -52,7 +52,7 @@ import java.util.List; public class GeneratorController { private final GeneratorService baseService; - private final DictService dictService; + private final DictApi dictApi; @Operation(summary = "分页查询生成配置", description = "分页查询生成配置列表") @SaCheckPermission("code:generator:list") @@ -111,12 +111,10 @@ public class GeneratorController { baseService.generateCode(tableNames); } - @Operation(summary = "查询字典", description = "查询字典列表") + @Operation(summary = "查询字典", description = "查询字典列表(包含枚举字典)") @SaCheckPermission("code:generator:config") @GetMapping("/dict") public List listDict() { - List dictList = dictService.listDict(null, null); - dictList.addAll(dictService.listEnumDict()); - return dictList; + return dictApi.listAll(); } } diff --git a/continew-plugin/continew-plugin-tenant/pom.xml b/continew-plugin/continew-plugin-tenant/pom.xml index e8c1d5e6..d670d194 100644 --- a/continew-plugin/continew-plugin-tenant/pom.xml +++ b/continew-plugin/continew-plugin-tenant/pom.xml @@ -14,12 +14,4 @@ ${project.artifactId} 租户插件 - - - - - top.continew.admin - continew-system - - \ No newline at end of file diff --git a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/api/PackageMenuApiImpl.java b/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/api/PackageMenuApiImpl.java new file mode 100644 index 00000000..9f4efd90 --- /dev/null +++ b/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/api/PackageMenuApiImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.tenant.api; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import top.continew.admin.common.api.tenant.PackageMenuApi; +import top.continew.admin.tenant.service.PackageMenuService; + +import java.util.List; + +/** + * 套餐和菜单关联业务 API 实现 + * + * @author Charles7c + * @since 2025/7/23 21:13 + */ +@Service +@RequiredArgsConstructor +public class PackageMenuApiImpl implements PackageMenuApi { + + private final PackageMenuService baseService; + + @Override + public List listMenuIdsByPackageId(Long packageId) { + return baseService.listMenuIdsByPackageId(packageId); + } +} diff --git a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/api/TenantApiImpl.java b/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/api/TenantApiImpl.java new file mode 100644 index 00000000..2a81573d --- /dev/null +++ b/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/api/TenantApiImpl.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.tenant.api; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import top.continew.admin.common.api.tenant.TenantApi; +import top.continew.admin.tenant.constant.TenantCacheConstants; +import top.continew.admin.tenant.mapper.TenantMapper; +import top.continew.admin.tenant.model.entity.TenantDO; +import top.continew.starter.cache.redisson.util.RedisUtils; +import top.continew.starter.extension.crud.model.entity.BaseIdDO; + +/** + * 租户业务 API 实现 + * + * @author Charles7c + * @since 2025/7/23 21:13 + */ +@Service +@RequiredArgsConstructor +public class TenantApiImpl implements TenantApi { + + private final TenantMapper baseMapper; + + @Override + public void bindAdminUser(Long tenantId, Long userId) { + baseMapper.lambdaUpdate().set(TenantDO::getAdminUser, userId).eq(BaseIdDO::getId, tenantId).update(); + // 更新租户缓存 + TenantDO entity = baseMapper.selectById(tenantId); + RedisUtils.set(TenantCacheConstants.TENANT_KEY_PREFIX + tenantId, entity); + } +} diff --git a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/controller/PackageController.java b/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/controller/PackageController.java index 6fa0fe9c..5b936316 100644 --- a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/controller/PackageController.java +++ b/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/controller/PackageController.java @@ -23,11 +23,9 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +import top.continew.admin.common.api.system.MenuApi; import top.continew.admin.common.base.controller.BaseController; import top.continew.admin.common.config.TenantExtensionProperties; -import top.continew.admin.common.enums.DisEnableStatusEnum; -import top.continew.admin.system.model.query.MenuQuery; -import top.continew.admin.system.service.MenuService; import top.continew.admin.tenant.model.query.PackageQuery; import top.continew.admin.tenant.model.req.PackageReq; import top.continew.admin.tenant.model.resp.PackageDetailResp; @@ -52,16 +50,12 @@ import java.util.List; public class PackageController extends BaseController { private final TenantExtensionProperties tenantExtensionProperties; - private final MenuService menuService; + private final MenuApi menuApi; @Operation(summary = "查询租户套餐菜单", description = "查询租户套餐菜单树列表") @SaCheckPermission("tenant:package:list") @GetMapping("/menu/tree") public List> listMenuTree() { - MenuQuery query = new MenuQuery(); - query.setStatus(DisEnableStatusEnum.ENABLE); - // 过滤掉租户不能使用的菜单 - query.setExcludeMenuIdList(tenantExtensionProperties.getIgnoreMenus()); - return menuService.tree(query, null, true); + return menuApi.listTree(tenantExtensionProperties.getIgnoreMenus()); } } \ No newline at end of file diff --git a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/controller/TenantController.java b/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/controller/TenantController.java index fe45cf5c..5bb8e55d 100644 --- a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/controller/TenantController.java +++ b/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/controller/TenantController.java @@ -25,11 +25,9 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; +import top.continew.admin.common.api.system.UserApi; import top.continew.admin.common.base.controller.BaseController; import top.continew.admin.common.util.SecureUtils; -import top.continew.admin.system.model.entity.user.UserDO; -import top.continew.admin.system.model.req.user.UserPasswordResetReq; -import top.continew.admin.system.service.UserService; import top.continew.admin.tenant.model.entity.TenantDO; import top.continew.admin.tenant.model.query.TenantQuery; import top.continew.admin.tenant.model.req.TenantAdminUserPwdUpdateReq; @@ -56,7 +54,7 @@ import top.continew.starter.extension.tenant.util.TenantUtils; @CrudRequestMapping(value = "/tenant/management", api = {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE}) public class TenantController extends BaseController { - private final UserService userService; + private final UserApi userApi; @Operation(summary = "修改租户管理员密码", description = "修改租户管理员密码") @SaCheckPermission("tenant:management:updateAdminUserPwd") @@ -65,12 +63,9 @@ public class TenantController extends BaseController { - UserDO user = userService.getById(tenant.getAdminUser()); String password = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(encryptPassword)); ValidationUtils.throwIfNull(password, "新密码解密失败"); - UserPasswordResetReq passwordResetReq = new UserPasswordResetReq(); - passwordResetReq.setNewPassword(password); - userService.resetPassword(passwordResetReq, user.getId()); + userApi.resetPassword(password, tenant.getAdminUser()); }); } } \ No newline at end of file diff --git a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/service/impl/TenantServiceImpl.java b/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/service/impl/TenantServiceImpl.java index 7511af69..af761df1 100644 --- a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/service/impl/TenantServiceImpl.java +++ b/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/service/impl/TenantServiceImpl.java @@ -16,24 +16,25 @@ package top.continew.admin.tenant.service.impl; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.extra.spring.SpringUtil; import com.alicp.jetcache.anno.Cached; import lombok.RequiredArgsConstructor; import me.ahoo.cosid.provider.IdGeneratorProvider; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import top.continew.admin.common.api.system.RoleApi; +import top.continew.admin.common.api.system.RoleMenuApi; +import top.continew.admin.common.api.tenant.TenantDataApi; import top.continew.admin.common.base.service.BaseServiceImpl; import top.continew.admin.common.config.TenantExtensionProperties; import top.continew.admin.common.constant.CacheConstants; import top.continew.admin.common.constant.SysConstants; import top.continew.admin.common.enums.DisEnableStatusEnum; -import top.continew.admin.system.model.entity.RoleDO; -import top.continew.admin.system.model.entity.RoleMenuDO; -import top.continew.admin.system.service.RoleMenuService; -import top.continew.admin.system.service.RoleService; +import top.continew.admin.common.model.dto.TenantDTO; import top.continew.admin.tenant.constant.TenantCacheConstants; import top.continew.admin.tenant.constant.TenantConstants; -import top.continew.admin.tenant.handler.TenantDataHandler; import top.continew.admin.tenant.mapper.TenantMapper; import top.continew.admin.tenant.model.entity.TenantDO; import top.continew.admin.tenant.model.query.TenantQuery; @@ -44,13 +45,13 @@ import top.continew.admin.tenant.service.PackageService; import top.continew.admin.tenant.service.TenantService; import top.continew.starter.cache.redisson.util.RedisUtils; import top.continew.starter.core.constant.StringConstants; -import top.continew.starter.core.util.CollUtils; import top.continew.starter.core.util.validation.CheckUtils; import top.continew.starter.extension.tenant.util.TenantUtils; import java.time.LocalDateTime; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -64,12 +65,12 @@ import java.util.Set; @RequiredArgsConstructor public class TenantServiceImpl extends BaseServiceImpl implements TenantService { + private final Map tenantDataApiMap = SpringUtil.getBeansOfType(TenantDataApi.class); private final TenantExtensionProperties tenantExtensionProperties; private final PackageService packageService; private final IdGeneratorProvider idGeneratorProvider; - private final TenantDataHandler tenantDataHandler; - private final RoleMenuService roleMenuService; - private final RoleService roleService; + private final RoleMenuApi roleMenuApi; + private final RoleApi roleApi; @Override public Long create(TenantReq req) { @@ -83,7 +84,7 @@ public class TenantServiceImpl extends BaseServiceImpl value.init(BeanUtil.copyProperties(req, TenantDTO.class))); return id; } @@ -107,7 +108,7 @@ public class TenantServiceImpl extends BaseServiceImpl ids) { // 在租户中执行数据清除 for (Long id : ids) { - TenantUtils.execute(id, tenantDataHandler::clear); + TenantUtils.execute(id, () -> tenantDataApiMap.forEach((key, value) -> value.clear())); } } @@ -162,27 +163,20 @@ public class TenantServiceImpl extends BaseServiceImpl TenantUtils.execute(tenantId, () -> { // 更新在线用户上下文 - List roleMenuList = roleMenuService.lambdaQuery() - .select(RoleMenuDO::getRoleId) - .notIn(RoleMenuDO::getMenuId, newMenuIds) - .list(); - Set roleIdSet = CollUtils.mapToSet(roleMenuList, RoleMenuDO::getRoleId); - roleIdSet.forEach(roleService::updateUserContext); + Set roleIdSet = roleMenuApi.listRoleIdByNotInMenuIds(newMenuIds); + roleIdSet.forEach(roleApi::updateUserContext); // 删除旧菜单 - roleMenuService.lambdaUpdate().notIn(RoleMenuDO::getMenuId, newMenuIds).remove(); + roleMenuApi.deleteByNotInMenuIds(newMenuIds); })); // 租户管理员:新增菜单 tenantIdList.forEach(tenantId -> TenantUtils.execute(tenantId, () -> { - RoleDO role = roleService.getByCode(SysConstants.TENANT_ADMIN_ROLE_CODE); - List oldMenuIdList = roleMenuService.listMenuIdByRoleIds(List.of(role.getId())); + Long roleId = roleApi.getIdByCode(SysConstants.TENANT_ADMIN_ROLE_CODE); + List oldMenuIdList = roleMenuApi.listMenuIdByRoleIds(List.of(roleId)); Collection addMenuIdList = CollUtil.disjunction(newMenuIds, oldMenuIdList); if (CollUtil.isNotEmpty(addMenuIdList)) { - List roleMenuList = addMenuIdList.stream() - .map(menuId -> new RoleMenuDO(role.getId(), menuId)) - .toList(); - roleMenuService.saveBatch(roleMenuList, roleMenuList.size()); + roleMenuApi.add(addMenuIdList.stream().toList(), roleId); // 更新在线用户上下文 - roleService.updateUserContext(role.getId()); + roleApi.updateUserContext(roleId); } })); // 删除缓存 diff --git a/continew-system/src/main/java/top/continew/admin/system/api/DictApiImpl.java b/continew-system/src/main/java/top/continew/admin/system/api/DictApiImpl.java new file mode 100644 index 00000000..1197f586 --- /dev/null +++ b/continew-system/src/main/java/top/continew/admin/system/api/DictApiImpl.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.system.api; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import top.continew.admin.common.api.system.DictApi; +import top.continew.admin.system.service.DictService; +import top.continew.starter.extension.crud.model.resp.LabelValueResp; + +import java.util.List; + +/** + * 字典业务 API 实现 + * + * @author Charles7c + * @since 2025/7/26 10:16 + */ +@Service +@RequiredArgsConstructor +public class DictApiImpl implements DictApi { + + private final DictService baseService; + + @Override + public List listAll() { + List list = baseService.listDict(null, null); + list.addAll(baseService.listEnumDict()); + return list; + } +} diff --git a/continew-system/src/main/java/top/continew/admin/system/api/DictItemApiImpl.java b/continew-system/src/main/java/top/continew/admin/system/api/DictItemApiImpl.java new file mode 100644 index 00000000..67374188 --- /dev/null +++ b/continew-system/src/main/java/top/continew/admin/system/api/DictItemApiImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.system.api; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import top.continew.admin.common.api.system.DictItemApi; +import top.continew.admin.system.service.DictItemService; +import top.continew.starter.extension.crud.model.resp.LabelValueResp; + +import java.util.List; + +/** + * 字典项业务 API 实现 + * + * @author Charles7c + * @since 2025/7/23 20:57 + */ +@Service +@RequiredArgsConstructor +public class DictItemApiImpl implements DictItemApi { + + private final DictItemService baseService; + + @Override + public List listByDictCode(String dictCode) { + return baseService.listByDictCode(dictCode); + } +} diff --git a/continew-system/src/main/java/top/continew/admin/system/api/MenuApiImpl.java b/continew-system/src/main/java/top/continew/admin/system/api/MenuApiImpl.java new file mode 100644 index 00000000..9cb47b47 --- /dev/null +++ b/continew-system/src/main/java/top/continew/admin/system/api/MenuApiImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.system.api; + +import cn.hutool.core.lang.tree.Tree; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import top.continew.admin.common.api.system.MenuApi; +import top.continew.admin.common.enums.DisEnableStatusEnum; +import top.continew.admin.system.model.query.MenuQuery; +import top.continew.admin.system.service.MenuService; + +import java.util.List; + +/** + * 菜单业务 API 实现 + * + * @author Charles7c + * @since 2025/7/26 9:53 + */ +@Service +@RequiredArgsConstructor +public class MenuApiImpl implements MenuApi { + + private final MenuService baseService; + + @Override + public List> listTree(List excludeMenuIds) { + MenuQuery query = new MenuQuery(); + query.setStatus(DisEnableStatusEnum.ENABLE); + // 过滤掉租户不能使用的菜单 + query.setExcludeMenuIdList(excludeMenuIds); + return baseService.tree(query, null, true); + } +} diff --git a/continew-system/src/main/java/top/continew/admin/system/api/RoleApiImpl.java b/continew-system/src/main/java/top/continew/admin/system/api/RoleApiImpl.java new file mode 100644 index 00000000..40e0146e --- /dev/null +++ b/continew-system/src/main/java/top/continew/admin/system/api/RoleApiImpl.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.system.api; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import top.continew.admin.common.api.system.RoleApi; +import top.continew.admin.system.model.entity.RoleDO; +import top.continew.admin.system.service.RoleService; + +import java.util.Optional; + +/** + * 角色业务 API 实现 + * + * @author Charles7c + * @since 2025/7/26 9:39 + */ +@Service +@RequiredArgsConstructor +public class RoleApiImpl implements RoleApi { + + private final RoleService baseService; + + @Override + public Long getIdByCode(String code) { + return Optional.ofNullable(baseService.getByCode(code)).map(RoleDO::getId).orElse(null); + } + + @Override + public void updateUserContext(Long roleId) { + baseService.updateUserContext(roleId); + } +} diff --git a/continew-system/src/main/java/top/continew/admin/system/api/RoleMenuApiImpl.java b/continew-system/src/main/java/top/continew/admin/system/api/RoleMenuApiImpl.java new file mode 100644 index 00000000..84608d98 --- /dev/null +++ b/continew-system/src/main/java/top/continew/admin/system/api/RoleMenuApiImpl.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.system.api; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import top.continew.admin.common.api.system.RoleMenuApi; +import top.continew.admin.system.model.entity.RoleMenuDO; +import top.continew.admin.system.service.RoleMenuService; +import top.continew.starter.core.util.CollUtils; + +import java.util.List; +import java.util.Set; + +/** + * 角色和菜单关联业务 API 实现 + * + * @author Charles7c + * @since 2025/7/26 9:39 + */ +@Service +@RequiredArgsConstructor +public class RoleMenuApiImpl implements RoleMenuApi { + + private final RoleMenuService baseService; + + @Override + public Set listRoleIdByNotInMenuIds(List menuIds) { + List roleMenuList = baseService.lambdaQuery() + .select(RoleMenuDO::getRoleId) + .notIn(RoleMenuDO::getMenuId, menuIds) + .list(); + return CollUtils.mapToSet(roleMenuList, RoleMenuDO::getRoleId); + } + + @Override + public List listMenuIdByRoleIds(List roleIds) { + return baseService.listMenuIdByRoleIds(roleIds); + } + + @Override + public void deleteByNotInMenuIds(List menuIds) { + baseService.lambdaUpdate().notIn(RoleMenuDO::getMenuId, menuIds).remove(); + } + + @Override + public boolean add(List menuIds, Long roleId) { + return baseService.add(menuIds, roleId); + } +} diff --git a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/handler/TenantDataHandlerForSystem.java b/continew-system/src/main/java/top/continew/admin/system/api/TenantDataApiForSystemImpl.java similarity index 82% rename from continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/handler/TenantDataHandlerForSystem.java rename to continew-system/src/main/java/top/continew/admin/system/api/TenantDataApiForSystemImpl.java index 6afffcde..017b0f93 100644 --- a/continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/handler/TenantDataHandlerForSystem.java +++ b/continew-system/src/main/java/top/continew/admin/system/api/TenantDataApiForSystemImpl.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.admin.tenant.handler; +package top.continew.admin.system.api; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.collection.ListUtil; @@ -24,11 +24,15 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import top.continew.admin.common.api.tenant.PackageMenuApi; +import top.continew.admin.common.api.tenant.TenantApi; +import top.continew.admin.common.api.tenant.TenantDataApi; import top.continew.admin.common.constant.RegexConstants; import top.continew.admin.common.constant.SysConstants; import top.continew.admin.common.enums.DataScopeEnum; import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.admin.common.enums.GenderEnum; +import top.continew.admin.common.model.dto.TenantDTO; import top.continew.admin.common.util.SecureUtils; import top.continew.admin.system.mapper.*; import top.continew.admin.system.mapper.user.UserMapper; @@ -41,23 +45,16 @@ import top.continew.admin.system.model.entity.user.UserDO; import top.continew.admin.system.service.FileService; import top.continew.admin.system.service.RoleMenuService; import top.continew.admin.system.service.RoleService; -import top.continew.admin.tenant.constant.TenantCacheConstants; -import top.continew.admin.tenant.mapper.TenantMapper; -import top.continew.admin.tenant.model.entity.TenantDO; -import top.continew.admin.tenant.model.req.TenantReq; -import top.continew.admin.tenant.service.PackageMenuService; -import top.continew.starter.cache.redisson.util.RedisUtils; import top.continew.starter.core.util.CollUtils; import top.continew.starter.core.util.ExceptionUtils; import top.continew.starter.core.util.validation.ValidationUtils; -import top.continew.starter.extension.crud.model.entity.BaseIdDO; import top.continew.starter.extension.tenant.util.TenantUtils; import java.time.LocalDateTime; import java.util.List; /** - * 租户数据处理器 + * 租户数据 API 实现 * * @author 小熊 * @author Charles7c @@ -65,16 +62,16 @@ import java.util.List; */ @Service @RequiredArgsConstructor -public class TenantDataHandlerForSystem implements TenantDataHandler { +public class TenantDataApiForSystemImpl implements TenantDataApi { - private final PackageMenuService packageMenuService; + private final PackageMenuApi packageMenuApi; + private final TenantApi tenantApi; + private final RoleService roleService; + private final FileService fileService; + private final RoleMenuService roleMenuService; private final DeptMapper deptMapper; private final RoleMapper roleMapper; - private final RoleMenuService roleMenuService; private final RoleMenuMapper roleMenuMapper; - private final RoleService roleService; - private final TenantMapper tenantMapper; - private final FileService fileService; private final LogMapper logMapper; private final MessageMapper messageMapper; private final MessageMapper messageUserMapper; @@ -87,7 +84,7 @@ public class TenantDataHandlerForSystem implements TenantDataHandler { @Override @Transactional(rollbackFor = Exception.class) - public void init(TenantReq tenant) { + public void init(TenantDTO tenant) { Long tenantId = tenant.getId(); TenantUtils.execute(tenantId, () -> { // 初始化部门 @@ -95,14 +92,14 @@ public class TenantDataHandlerForSystem implements TenantDataHandler { // 初始化角色 Long roleId = this.initRoleData(tenant); // 角色绑定菜单 - List menuIds = packageMenuService.listMenuIdsByPackageId(tenant.getPackageId()); + List menuIds = packageMenuApi.listMenuIdsByPackageId(tenant.getPackageId()); roleMenuService.add(menuIds, roleId); // 初始化管理用户 Long userId = this.initUserData(tenant, deptId); // 用户绑定角色 roleService.assignToUsers(roleId, ListUtil.of(userId)); // 租户绑定用户 - this.bindTenantUser(tenantId, userId); + tenantApi.bindAdminUser(tenantId, userId); }); } @@ -146,7 +143,7 @@ public class TenantDataHandlerForSystem implements TenantDataHandler { * @param tenant 租户信息 * @return 部门 ID */ - private Long initDeptData(TenantReq tenant) { + private Long initDeptData(TenantDTO tenant) { DeptDO dept = new DeptDO(); dept.setName(tenant.getName()); dept.setParentId(SysConstants.SUPER_PARENT_ID); @@ -164,7 +161,7 @@ public class TenantDataHandlerForSystem implements TenantDataHandler { * @param tenant 租户信息 * @return 角色 ID */ - private Long initRoleData(TenantReq tenant) { + private Long initRoleData(TenantDTO tenant) { RoleDO role = new RoleDO(); role.setName("系统管理员"); role.setCode(SysConstants.TENANT_ADMIN_ROLE_CODE); @@ -185,7 +182,7 @@ public class TenantDataHandlerForSystem implements TenantDataHandler { * @param deptId 部门 ID * @return 用户 ID */ - private Long initUserData(TenantReq tenant, Long deptId) { + private Long initUserData(TenantDTO tenant, Long deptId) { // 解密密码 String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(tenant.getPassword())); ValidationUtils.throwIfNull(rawPassword, "密码解密失败"); @@ -205,17 +202,4 @@ public class TenantDataHandlerForSystem implements TenantDataHandler { userMapper.insert(user); return user.getId(); } - - /** - * 绑定租户管理员用户 - * - * @param tenantId 租户 ID - * @param userId 用户 ID - */ - public void bindTenantUser(Long tenantId, Long userId) { - tenantMapper.lambdaUpdate().set(TenantDO::getAdminUser, userId).eq(BaseIdDO::getId, tenantId).update(); - // 更新租户缓存 - TenantDO entity = tenantMapper.selectById(tenantId); - RedisUtils.set(TenantCacheConstants.TENANT_KEY_PREFIX + tenantId, entity); - } } diff --git a/continew-system/src/main/java/top/continew/admin/system/api/UserApiImpl.java b/continew-system/src/main/java/top/continew/admin/system/api/UserApiImpl.java new file mode 100644 index 00000000..43f91179 --- /dev/null +++ b/continew-system/src/main/java/top/continew/admin/system/api/UserApiImpl.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package top.continew.admin.system.api; + +import com.alicp.jetcache.anno.CacheType; +import com.alicp.jetcache.anno.Cached; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import top.continew.admin.common.api.system.UserApi; +import top.continew.admin.common.constant.CacheConstants; +import top.continew.admin.system.mapper.user.UserMapper; +import top.continew.admin.system.model.req.user.UserPasswordResetReq; +import top.continew.admin.system.service.UserService; + +/** + * 用户业务 API 实现 + * + * @author Charles7c + * @since 2025/7/23 20:57 + */ +@Service +@RequiredArgsConstructor +public class UserApiImpl implements UserApi { + + private final UserService baseService; + private final UserMapper baseMapper; + + @Override + @Cached(key = "#id", name = CacheConstants.USER_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true) + public String getNicknameById(Long id) { + return baseMapper.selectNicknameById(id); + } + + @Override + public void resetPassword(String newPassword, Long id) { + UserPasswordResetReq req = new UserPasswordResetReq(); + req.setNewPassword(newPassword); + baseService.resetPassword(req, id); + } +} diff --git a/continew-system/src/main/java/top/continew/admin/system/service/DictItemService.java b/continew-system/src/main/java/top/continew/admin/system/service/DictItemService.java index 0aae0def..c08ac442 100644 --- a/continew-system/src/main/java/top/continew/admin/system/service/DictItemService.java +++ b/continew-system/src/main/java/top/continew/admin/system/service/DictItemService.java @@ -17,12 +17,12 @@ package top.continew.admin.system.service; import top.continew.admin.common.base.service.BaseService; -import top.continew.admin.common.service.CommonDictItemService; import top.continew.admin.system.model.entity.DictItemDO; import top.continew.admin.system.model.query.DictItemQuery; import top.continew.admin.system.model.req.DictItemReq; import top.continew.admin.system.model.resp.DictItemResp; import top.continew.starter.data.service.IService; +import top.continew.starter.extension.crud.model.resp.LabelValueResp; import java.util.List; @@ -32,7 +32,15 @@ import java.util.List; * @author Charles7c * @since 2023/9/11 21:29 */ -public interface DictItemService extends BaseService, IService, CommonDictItemService { +public interface DictItemService extends BaseService, IService { + + /** + * 根据字典编码查询字典项列表 + * + * @param dictCode 字典编码 + * @return 字典项列表 + */ + List listByDictCode(String dictCode); /** * 根据字典 ID 列表删除 diff --git a/continew-system/src/main/java/top/continew/admin/system/service/impl/RoleMenuServiceImpl.java b/continew-system/src/main/java/top/continew/admin/system/service/impl/RoleMenuServiceImpl.java index cd117900..df053b84 100644 --- a/continew-system/src/main/java/top/continew/admin/system/service/impl/RoleMenuServiceImpl.java +++ b/continew-system/src/main/java/top/continew/admin/system/service/impl/RoleMenuServiceImpl.java @@ -40,8 +40,6 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class RoleMenuServiceImpl extends ServiceImpl implements RoleMenuService { - private final RoleMenuMapper baseMapper; - @Override @Transactional(rollbackFor = Exception.class) public boolean add(List menuIds, Long roleId) { diff --git a/continew-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java b/continew-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java index 2fcb4fb8..1eeac289 100644 --- a/continew-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java +++ b/continew-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java @@ -32,9 +32,7 @@ import cn.hutool.http.ContentType; import cn.hutool.json.JSONUtil; import cn.idev.excel.EasyExcel; import com.alicp.jetcache.anno.CacheInvalidate; -import com.alicp.jetcache.anno.CacheType; import com.alicp.jetcache.anno.CacheUpdate; -import com.alicp.jetcache.anno.Cached; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -62,7 +60,6 @@ import top.continew.admin.common.context.UserContext; import top.continew.admin.common.context.UserContextHolder; import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.admin.common.enums.GenderEnum; -import top.continew.admin.common.service.CommonUserService; import top.continew.admin.system.enums.OptionCategoryEnum; import top.continew.admin.system.mapper.user.UserMapper; import top.continew.admin.system.model.entity.DeptDO; @@ -106,7 +103,7 @@ import static top.continew.admin.system.enums.PasswordPolicyEnum.*; @Slf4j @Service @RequiredArgsConstructor -public class UserServiceImpl extends BaseServiceImpl implements UserService, CommonUserService { +public class UserServiceImpl extends BaseServiceImpl implements UserService { private final PasswordEncoder passwordEncoder; private final UserPasswordHistoryService userPasswordHistoryService; @@ -221,12 +218,6 @@ public class UserServiceImpl extends BaseServiceImpl