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