From 75928525ca13f0b8c211954c9dd4a64dad3c398a Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 24 Feb 2022 00:53:28 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=A2=9E=E5=8A=A0=E3=80=90=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E3=80=91=E7=9A=84=E7=B3=BB=E7=BB=9F=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E6=A6=82=E5=BF=B5=EF=BC=8C=E7=A6=81=E6=AD=A2=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=8E=E5=88=A0=E9=99=A4=E7=AD=89=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=202.=20=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=9C=A8=E5=88=B7=E6=96=B0=E6=9C=AC=E5=9C=B0=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=BC=9A=E8=BF=87=E6=BB=A4=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=203.=20=E8=B0=83=E6=95=B4=E7=9F=AD?= =?UTF-8?q?=E4=BF=A1=E7=9A=84=E5=9B=9E=E8=B0=83=E5=9C=B0=E5=9D=80=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E8=BF=9B=E8=A1=8C=E7=A7=9F=E6=88=B7=E7=9A=84=E7=99=BD?= =?UTF-8?q?=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../merchant/PayChannelServiceImpl.java | 7 ++++- .../system/enums/ErrorCodeConstants.java | 1 + .../admin/sms/SmsCallbackController.java | 5 ++-- .../admin/tenant/TenantPackageController.java | 10 ------- .../dal/dataobject/tenant/TenantDO.java | 6 +++++ .../permission/PermissionServiceImpl.java | 7 ++++- .../service/permission/RoleServiceImpl.java | 7 ++++- .../service/tenant/TenantPackageService.java | 9 ------- .../tenant/TenantPackageServiceImpl.java | 6 ----- .../service/tenant/TenantServiceImpl.java | 27 +++++++++++++++---- .../src/main/resources/application.yaml | 27 +++++++++++++++++-- .../src/views/system/tenant/index.vue | 3 ++- 更新日志.md | 2 +- 13 files changed, 77 insertions(+), 40 deletions(-) diff --git a/yudao-module-pay/yudao-module-pay-impl/src/main/java/cn/iocoder/yudao/module/pay/service/merchant/PayChannelServiceImpl.java b/yudao-module-pay/yudao-module-pay-impl/src/main/java/cn/iocoder/yudao/module/pay/service/merchant/PayChannelServiceImpl.java index d3410a2cb..1c58cf1e1 100644 --- a/yudao-module-pay/yudao-module-pay-impl/src/main/java/cn/iocoder/yudao/module/pay/service/merchant/PayChannelServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-impl/src/main/java/cn/iocoder/yudao/module/pay/service/merchant/PayChannelServiceImpl.java @@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayChannelDO; import cn.iocoder.yudao.module.pay.dal.mysql.merchant.PayChannelMapper; import cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -65,6 +66,10 @@ public class PayChannelServiceImpl implements PayChannelService { @Resource private Validator validator; + @Resource + @Lazy // 注入自己,所以延迟加载 + private PayChannelService self; + @Override @PostConstruct @TenantIgnore // 忽略自动化租户,全局初始化本地缓存 @@ -86,7 +91,7 @@ public class PayChannelServiceImpl implements PayChannelService { @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) public void schedulePeriodicRefresh() { - initPayClients(); + self.initPayClients(); } /** diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 0ffecd5f2..142354270 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -108,6 +108,7 @@ public interface ErrorCodeConstants { ErrorCode TENANT_NOT_EXISTS = new ErrorCode(1002014000, "租户不存在"); ErrorCode TENANT_DISABLE = new ErrorCode(1002014001, "名字为【{}】的租户已被禁用"); ErrorCode TENANT_EXPIRE = new ErrorCode(1002014002, "名字为【{}】的租户已过期"); + ErrorCode TENANT_CAN_NOT_UPDATE_SYSTEM = new ErrorCode(1002014003, "系统租户不能进行修改、删除等操作!"); // ========== 租户套餐 1002015000 ========== ErrorCode TENANT_PACKAGE_NOT_EXISTS = new ErrorCode(1002015000, "租户套餐不存在"); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsCallbackController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsCallbackController.java index def88c14c..c7dd1aad9 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsCallbackController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsCallbackController.java @@ -19,7 +19,6 @@ import javax.servlet.http.HttpServletRequest; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -// TODO 芋艿:这块的接口命名,在纠结下 @Api(tags = "管理后台 - 短信回调") @RestController @RequestMapping("/system/sms/callback") @@ -28,7 +27,7 @@ public class SmsCallbackController { @Resource private SmsSendService smsSendService; - @PostMapping("/sms/yunpian") + @PostMapping("/yunpian") @ApiOperation(value = "云片短信的回调", notes = "参见 https://www.yunpian.com/official/document/sms/zh_cn/domestic_push_report 文档") @ApiImplicitParam(name = "sms_status", value = "发送状态", required = true, example = "[{具体内容}]", dataTypeClass = String.class) @OperateLog(enable = false) @@ -38,7 +37,7 @@ public class SmsCallbackController { return "SUCCESS"; // 约定返回 SUCCESS 为成功 } - @PostMapping("/sms/aliyun") + @PostMapping("/aliyun") @ApiOperation(value = "阿里云短信的回调", notes = "参见 https://help.aliyun.com/document_detail/120998.html 文档") @OperateLog(enable = false) public CommonResult receiveAliyunSmsStatus(HttpServletRequest request) throws Throwable { diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantPackageController.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantPackageController.java index 7959e887f..b69b0dca5 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantPackageController.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenant/TenantPackageController.java @@ -16,7 +16,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -63,15 +62,6 @@ public class TenantPackageController { return success(TenantPackageConvert.INSTANCE.convert(tenantPackage)); } - @GetMapping("/list") - @ApiOperation("获得租户套餐列表") - @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class) - @PreAuthorize("@ss.hasPermission('system:tenant-package:query')") - public CommonResult> getTenantPackageList(@RequestParam("ids") Collection ids) { - List list = tenantPackageService.getTenantPackageList(ids); - return success(TenantPackageConvert.INSTANCE.convertList(list)); - } - @GetMapping("/page") @ApiOperation("获得租户套餐分页") @PreAuthorize("@ss.hasPermission('system:tenant-package:query')") diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/tenant/TenantDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/tenant/TenantDO.java index 069f1d502..40b7f85aa 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/tenant/TenantDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/tenant/TenantDO.java @@ -22,6 +22,11 @@ import java.util.Date; @NoArgsConstructor public class TenantDO extends BaseDO { + /** + * 套餐编号 - 系统 + */ + public static final Long PACKAGE_ID_SYSTEM = 0L; + /** * 租户编号,自增 */ @@ -60,6 +65,7 @@ public class TenantDO extends BaseDO { * 租户套餐编号 * * 关联 {@link TenantPackageDO#getId()} + * 特殊逻辑:系统内置租户,不使用套餐,暂时使用 {@link #PACKAGE_ID_SYSTEM} 标识 */ private Long packageId; /** diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java index 9033fe935..f47e83b02 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java @@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -90,6 +91,10 @@ public class PermissionServiceImpl implements PermissionService { @Resource private PermissionProducer permissionProducer; + @Resource + @Lazy // 注入自己,所以延迟加载 + private PermissionService self; + /** * 初始化 {@link #roleMenuCache} 和 {@link #menuRoleCache} 缓存 */ @@ -118,7 +123,7 @@ public class PermissionServiceImpl implements PermissionService { @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) public void schedulePeriodicRefresh() { - initLocalCache(); + self.initLocalCache(); } /** diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java index c915f4d72..eefa1ec52 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java @@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.system.enums.permission.RoleTypeEnum; import cn.iocoder.yudao.module.system.mq.producer.permission.RoleProducer; import com.google.common.annotations.VisibleForTesting; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Lazy; import org.springframework.lang.Nullable; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @@ -72,6 +73,10 @@ public class RoleServiceImpl implements RoleService { @Resource private RoleProducer roleProducer; + @Resource + @Lazy // 注入自己,所以延迟加载 + private RoleService self; + /** * 初始化 {@link #roleCache} 缓存 */ @@ -93,7 +98,7 @@ public class RoleServiceImpl implements RoleService { @Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD) public void schedulePeriodicRefresh() { - initLocalCache(); + self.initLocalCache(); } /** diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageService.java index 9c5b0e576..c58426a2b 100755 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageService.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageService.java @@ -7,7 +7,6 @@ import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.packages.Tenant import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; import javax.validation.Valid; -import java.util.Collection; import java.util.List; /** @@ -47,14 +46,6 @@ public interface TenantPackageService { */ TenantPackageDO getTenantPackage(Long id); - /** - * 获得租户套餐列表 - * - * @param ids 编号 - * @return 租户套餐列表 - */ - List getTenantPackageList(Collection ids); - /** * 获得租户套餐分页 * diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java index 969d4c03e..2528cb905 100755 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java @@ -16,7 +16,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -91,11 +90,6 @@ public class TenantPackageServiceImpl implements TenantPackageService { return tenantPackageMapper.selectById(id); } - @Override - public List getTenantPackageList(Collection ids) { - return tenantPackageMapper.selectBatchIds(ids); - } - @Override public PageResult getTenantPackagePage(TenantPackagePageReqVO pageReqVO) { return tenantPackageMapper.selectPage(pageReqVO); diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java index 9bc010bd4..c4b52eaa8 100755 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java @@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantEx import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; import cn.iocoder.yudao.module.system.controller.admin.tenant.vo.tenant.TenantUpdateReqVO; import cn.iocoder.yudao.module.system.convert.tenant.TenantConvert; +import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO; import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantPackageDO; @@ -23,6 +24,7 @@ import cn.iocoder.yudao.module.system.dal.mysql.tenant.TenantMapper; import cn.iocoder.yudao.module.system.enums.permission.RoleCodeEnum; import cn.iocoder.yudao.module.system.enums.permission.RoleTypeEnum; import cn.iocoder.yudao.module.system.mq.producer.tenant.TenantProducer; +import cn.iocoder.yudao.module.system.service.permission.MenuService; import cn.iocoder.yudao.module.system.service.permission.PermissionService; import cn.iocoder.yudao.module.system.service.permission.RoleService; import cn.iocoder.yudao.module.system.service.tenant.handler.TenantInfoHandler; @@ -86,6 +88,8 @@ public class TenantServiceImpl implements TenantService { @Resource private RoleService roleService; @Resource + private MenuService menuService; + @Resource private PermissionService permissionService; @Resource @@ -205,7 +209,7 @@ public class TenantServiceImpl implements TenantService { @Transactional(rollbackFor = Exception.class) public void updateTenant(TenantUpdateReqVO updateReqVO) { // 校验存在 - TenantDO tenant = validateTenantExists(updateReqVO.getId()); + TenantDO tenant = checkUpdateTenant(updateReqVO.getId()); // 校验套餐被禁用 TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId()); @@ -253,16 +257,20 @@ public class TenantServiceImpl implements TenantService { @Override public void deleteTenant(Long id) { // 校验存在 - validateTenantExists(id); + checkUpdateTenant(id); // 删除 tenantMapper.deleteById(id); } - private TenantDO validateTenantExists(Long id) { + private TenantDO checkUpdateTenant(Long id) { TenantDO tenant = tenantMapper.selectById(id); if (tenant == null) { throw exception(TENANT_NOT_EXISTS); } + // 内置租户,不允许删除 + if (isSystemTenant(tenant)) { + throw exception(TENANT_CAN_NOT_UPDATE_SYSTEM); + } return tenant; } @@ -321,9 +329,18 @@ public class TenantServiceImpl implements TenantService { } // 获得租户,然后获得菜单 TenantDO tenant = getTenant(TenantContextHolder.getRequiredTenantId()); - TenantPackageDO tenantPackage = tenantPackageService.getTenantPackage(tenant.getPackageId()); + Set menuIds; + if (isSystemTenant(tenant)) { // 系统租户,菜单是全量的 + menuIds = CollectionUtils.convertSet(menuService.getMenus(), MenuDO::getId); + } else { + menuIds = tenantPackageService.getTenantPackage(tenant.getPackageId()).getMenuIds(); + } // 执行处理器 - handler.handle(tenantPackage.getMenuIds()); + handler.handle(menuIds); + } + + private static boolean isSystemTenant(TenantDO tenant) { + return Objects.equals(tenant.getPackageId(), TenantDO.PACKAGE_ID_SYSTEM); } } diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 3e7e51bbc..67c06c7f4 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -79,8 +79,31 @@ yudao: - cn.iocoder.yudao.module.tool.enums.ErrorCodeConstants tenant: # 多租户相关配置项 enable: true - ignore-urls: /admin-api/system/tenant/get-id-by-name, /admin-api/system/captcha/get-image, /admin-api/infra/file/get/* - ignore-tables: infra_config, infra_file, infra_job, infra_job_log, infra_job_log, system_tenant, system_tenant_package, system_dict_data, system_dict_type, system_error_code, system_menu, system_sms_channel, system_sms_template, tool_codegen_column, tool_codegen_table, tool_test_demo, tables, columns + ignore-urls: + - /admin-api/system/tenant/get-id-by-name + - /admin-api/system/captcha/get-image + - /admin-api/infra/file/get/* + - /admin-api/system/sms/callback/* + ignore-tables: + - infra_config + - infra_file + - infra_job + - infra_job_log + - infra_job_log + - system_tenant + - system_tenant_package + - system_dict_data + - system_dict_type + - system_error_code + - system_menu + - system_sms_channel + - system_sms_template + - system_sms_log + - tool_codegen_column + - tool_codegen_table + - tool_test_demo + - tables + - columns sms-code: # 短信验证码相关的配置项 expire-times: 10m send-frequency: 1m diff --git a/yudao-ui-admin/src/views/system/tenant/index.vue b/yudao-ui-admin/src/views/system/tenant/index.vue index 748976516..71c8492d7 100755 --- a/yudao-ui-admin/src/views/system/tenant/index.vue +++ b/yudao-ui-admin/src/views/system/tenant/index.vue @@ -43,7 +43,8 @@ diff --git a/更新日志.md b/更新日志.md index 06291594b..080dc74a6 100644 --- a/更新日志.md +++ b/更新日志.md @@ -35,7 +35,7 @@ TODO ### 🐞 Bug Fixes -TODO +* 【修复】修复不支持根部门的问题 [commmit](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/fa62ace6af5ecc2f3030fa86d2ce222a1392f1a6) ### 🔨 Dependency Upgrades