diff --git a/msgpush-dependencies/pom.xml b/msgpush-dependencies/pom.xml index bbd3ce4..c37070f 100644 --- a/msgpush-dependencies/pom.xml +++ b/msgpush-dependencies/pom.xml @@ -129,11 +129,6 @@ - - com.njcn - msgpush-spring-boot-starter-biz-tenant - ${revision} - com.njcn msgpush-spring-boot-starter-biz-ip diff --git a/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/biz/system/oauth2/dto/OAuth2AccessTokenCheckRespDTO.java b/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/biz/system/oauth2/dto/OAuth2AccessTokenCheckRespDTO.java index 43b1217..2a2ff7f 100644 --- a/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/biz/system/oauth2/dto/OAuth2AccessTokenCheckRespDTO.java +++ b/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/biz/system/oauth2/dto/OAuth2AccessTokenCheckRespDTO.java @@ -21,9 +21,6 @@ public class OAuth2AccessTokenCheckRespDTO implements Serializable { @Schema(description = "用户信息", example = "{\"nickname\": \"灿能\"}") private Map userInfo; - @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long tenantId; - @Schema(description = "授权范围的数组", example = "user_info") private List scopes; diff --git a/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/biz/system/tenant/TenantCommonApi.java b/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/biz/system/tenant/TenantCommonApi.java deleted file mode 100644 index b0379db..0000000 --- a/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/biz/system/tenant/TenantCommonApi.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.njcn.msgpush.framework.common.biz.system.tenant; - -import com.njcn.msgpush.framework.common.enums.RpcConstants; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Operation; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import java.util.List; - -@FeignClient(name = RpcConstants.SYSTEM_NAME) // TODO 芋艿:fallbackFactory = -@Tag(name = "RPC 服务 - 多租户") -public interface TenantCommonApi { - - String PREFIX = RpcConstants.SYSTEM_PREFIX + "/tenant"; - - @GetMapping(PREFIX + "/id-list") - @Operation(summary = "获得所有租户编号") - CommonResult> getTenantIdList(); - - @GetMapping(PREFIX + "/valid") - @Operation(summary = "校验租户是否合法") - @Parameter(name = "id", description = "租户编号", required = true, example = "1024") - CommonResult validTenant(@RequestParam("id") Long id); - -} diff --git a/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/enums/DocumentEnum.java b/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/enums/DocumentEnum.java index f721ad0..c0cf985 100644 --- a/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/enums/DocumentEnum.java +++ b/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/enums/DocumentEnum.java @@ -12,8 +12,7 @@ import lombok.Getter; @AllArgsConstructor public enum DocumentEnum { - REDIS_INSTALL("https://gitee.com/zhijiantianya/ruoyi-vue-pro/issues/I4VCSJ", "Redis 安装文档"), - TENANT("https://doc.iocoder.cn", "SaaS 多租户文档"); + REDIS_INSTALL("https://gitee.com/zhijiantianya/ruoyi-vue-pro/issues/I4VCSJ", "Redis 安装文档"); private final String url; private final String memo; diff --git a/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/enums/WebFilterOrderEnum.java b/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/enums/WebFilterOrderEnum.java index 668d378..a330eed 100644 --- a/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/enums/WebFilterOrderEnum.java +++ b/msgpush-framework/msgpush-common/src/main/java/com/njcn/msgpush/framework/common/enums/WebFilterOrderEnum.java @@ -21,16 +21,12 @@ public interface WebFilterOrderEnum { // OrderedRequestContextFilter 默认为 -105,用于国际化上下文等等 - int TENANT_CONTEXT_FILTER = - 104; // 需要保证在 ApiAccessLogFilter 前面 - int API_ACCESS_LOG_FILTER = -103; // 需要保证在 RequestBodyCacheFilter 后面 int XSS_FILTER = -102; // 需要保证在 RequestBodyCacheFilter 后面 // Spring Security Filter 默认为 -100,可见 org.springframework.boot.autoconfigure.security.SecurityProperties 配置属性类 - int TENANT_SECURITY_FILTER = -99; // 需要保证在 Spring Security 过滤器后面 - int FLOWABLE_FILTER = -98; // 需要保证在 Spring Security 过滤后面 int DEMO_FILTER = Integer.MAX_VALUE; diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/pom.xml b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/pom.xml deleted file mode 100644 index 73596f6..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - msgpush-framework - com.njcn - ${revision} - - 4.0.0 - msgpush-spring-boot-starter-biz-tenant - jar - - ${project.artifactId} - 多租户 - - - - - com.njcn - msgpush-common - - - - - com.njcn - msgpush-spring-boot-starter-security - - - - - com.njcn - msgpush-spring-boot-starter-mybatis - - - - com.njcn - msgpush-spring-boot-starter-redis - - - - - com.njcn - msgpush-spring-boot-starter-rpc - true - - - - - com.njcn - msgpush-spring-boot-starter-mq - true - - - org.springframework.kafka - spring-kafka - true - - - org.springframework.amqp - spring-rabbit - true - - - org.apache.rocketmq - rocketmq-spring-boot-starter - true - - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - com.google.guava - guava - - - - - diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/config/MsgpushTenantAutoConfiguration.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/config/MsgpushTenantAutoConfiguration.java deleted file mode 100644 index e48b8a7..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/config/MsgpushTenantAutoConfiguration.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.njcn.msgpush.framework.tenant.config; - -import cn.hutool.extra.spring.SpringUtil; -import com.njcn.msgpush.framework.common.biz.system.tenant.TenantCommonApi; -import com.njcn.msgpush.framework.common.enums.WebFilterOrderEnum; -import com.njcn.msgpush.framework.mybatis.core.util.MyBatisUtils; -import com.njcn.msgpush.framework.redis.config.MsgpushCacheProperties; -import com.njcn.msgpush.framework.security.core.service.SecurityFrameworkService; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnoreAspect; -import com.njcn.msgpush.framework.tenant.core.db.TenantDatabaseInterceptor; -import com.njcn.msgpush.framework.tenant.core.mq.rabbitmq.TenantRabbitMQInitializer; -import com.njcn.msgpush.framework.tenant.core.mq.redis.TenantRedisMessageInterceptor; -import com.njcn.msgpush.framework.tenant.core.mq.rocketmq.TenantRocketMQInitializer; -import com.njcn.msgpush.framework.tenant.core.redis.TenantRedisCacheManager; -import com.njcn.msgpush.framework.tenant.core.security.TenantSecurityWebFilter; -import com.njcn.msgpush.framework.tenant.core.service.TenantFrameworkService; -import com.njcn.msgpush.framework.tenant.core.service.TenantFrameworkServiceImpl; -import com.njcn.msgpush.framework.tenant.core.web.TenantContextWebFilter; -import com.njcn.msgpush.framework.tenant.core.web.TenantVisitContextInterceptor; -import com.njcn.msgpush.framework.web.config.WebProperties; -import com.njcn.msgpush.framework.web.core.handler.GlobalExceptionHandler; -import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; -import jakarta.annotation.Resource; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.data.redis.cache.BatchStrategies; -import org.springframework.data.redis.cache.RedisCacheConfiguration; -import org.springframework.data.redis.cache.RedisCacheManager; -import org.springframework.data.redis.cache.RedisCacheWriter; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.method.HandlerMethod; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.mvc.method.RequestMappingInfo; -import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; -import org.springframework.web.util.pattern.PathPattern; - -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - -import static com.njcn.msgpush.framework.common.util.collection.CollectionUtils.convertList; - -@AutoConfiguration -@ConditionalOnProperty(prefix = "msgpush.tenant", value = "enable", matchIfMissing = true) // 允许使用 msgpush.tenant.enable=false 禁用多租户 -@EnableConfigurationProperties(TenantProperties.class) -public class MsgpushTenantAutoConfiguration { - - @Resource - private ApplicationContext applicationContext; - - @Bean - public TenantFrameworkService tenantFrameworkService(TenantCommonApi tenantApi) { - try { - TenantCommonApi tenantApiImpl = SpringUtil.getBean("tenantApiImpl", TenantCommonApi.class); - if (tenantApiImpl != null) { - tenantApi = tenantApiImpl; - } - } catch (Exception ignored) {} - return new TenantFrameworkServiceImpl(tenantApi); - } - - // ========== AOP ========== - - @Bean - public TenantIgnoreAspect tenantIgnoreAspect() { - return new TenantIgnoreAspect(); - } - - // ========== DB ========== - - @Bean - public TenantLineInnerInterceptor tenantLineInnerInterceptor(TenantProperties properties, - MybatisPlusInterceptor interceptor) { - TenantLineInnerInterceptor inner = new TenantLineInnerInterceptor(new TenantDatabaseInterceptor(properties)); - // 添加到 interceptor 中 - // 需要加在首个,主要是为了在分页插件前面。这个是 MyBatis Plus 的规定 - MyBatisUtils.addInterceptor(interceptor, inner, 0); - return inner; - } - - // ========== WEB ========== - - @Bean - public FilterRegistrationBean tenantContextWebFilter() { - FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); - registrationBean.setFilter(new TenantContextWebFilter()); - registrationBean.setOrder(WebFilterOrderEnum.TENANT_CONTEXT_FILTER); - return registrationBean; - } - - @Bean - public TenantVisitContextInterceptor tenantVisitContextInterceptor(TenantProperties tenantProperties, - SecurityFrameworkService securityFrameworkService) { - return new TenantVisitContextInterceptor(tenantProperties, securityFrameworkService); - } - - @Bean - public WebMvcConfigurer tenantWebMvcConfigurer(TenantProperties tenantProperties, - TenantVisitContextInterceptor tenantVisitContextInterceptor) { - return new WebMvcConfigurer() { - - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(tenantVisitContextInterceptor) - .excludePathPatterns(tenantProperties.getIgnoreVisitUrls().toArray(new String[0])); - } - }; - } - - // ========== Security ========== - - @Bean - public FilterRegistrationBean tenantSecurityWebFilter(TenantProperties tenantProperties, - WebProperties webProperties, - GlobalExceptionHandler globalExceptionHandler, - TenantFrameworkService tenantFrameworkService) { - FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); - registrationBean.setFilter(new TenantSecurityWebFilter(webProperties, tenantProperties, getTenantIgnoreUrls(), - globalExceptionHandler, tenantFrameworkService)); - registrationBean.setOrder(WebFilterOrderEnum.TENANT_SECURITY_FILTER); - return registrationBean; - } - - /** - * 如果 Controller 接口上,有 {@link TenantIgnore} 注解,则添加到忽略租户的 URL 集合中 - * - * @return 忽略租户的 URL 集合 - */ - private Set getTenantIgnoreUrls() { - Set ignoreUrls = new HashSet<>(); - // 获得接口对应的 HandlerMethod 集合 - RequestMappingHandlerMapping requestMappingHandlerMapping = (RequestMappingHandlerMapping) - applicationContext.getBean("requestMappingHandlerMapping"); - Map handlerMethodMap = requestMappingHandlerMapping.getHandlerMethods(); - // 获得有 @TenantIgnore 注解的接口 - for (Map.Entry entry : handlerMethodMap.entrySet()) { - HandlerMethod handlerMethod = entry.getValue(); - if (!handlerMethod.hasMethodAnnotation(TenantIgnore.class) // 方法级 - && !handlerMethod.getBeanType().isAnnotationPresent(TenantIgnore.class)) { // 接口级 - continue; - } - // 添加到忽略的 URL 中 - if (entry.getKey().getPatternsCondition() != null) { - ignoreUrls.addAll(entry.getKey().getPatternsCondition().getPatterns()); - } - if (entry.getKey().getPathPatternsCondition() != null) { - ignoreUrls.addAll( - convertList(entry.getKey().getPathPatternsCondition().getPatterns(), PathPattern::getPatternString)); - } - } - return ignoreUrls; - } - - // ========== MQ ========== - - /** - * 多租户 Redis 消息队列的配置类 - * - * 为什么要单独一个配置类呢?如果直接把 TenantRedisMessageInterceptor Bean 的初始化放外面,会报 RedisMessageInterceptor 类不存在的错误 - */ - @Configuration - @ConditionalOnClass(name = "com.njcn.msgpush.framework.mq.redis.core.RedisMQTemplate") - public static class TenantRedisMQAutoConfiguration { - - @Bean - public TenantRedisMessageInterceptor tenantRedisMessageInterceptor() { - return new TenantRedisMessageInterceptor(); - } - - } - - @Bean - @ConditionalOnClass(name = "org.springframework.amqp.rabbit.core.RabbitTemplate") - public TenantRabbitMQInitializer tenantRabbitMQInitializer() { - return new TenantRabbitMQInitializer(); - } - - @Bean - @ConditionalOnClass(name = "org.apache.rocketmq.spring.core.RocketMQTemplate") - public TenantRocketMQInitializer tenantRocketMQInitializer() { - return new TenantRocketMQInitializer(); - } - - // ========== Redis ========== - - @Bean - @Primary // 引入租户时,tenantRedisCacheManager 为主 Bean - public RedisCacheManager tenantRedisCacheManager(RedisTemplate redisTemplate, - RedisCacheConfiguration redisCacheConfiguration, - MsgpushCacheProperties msgpushCacheProperties, - TenantProperties tenantProperties) { - // 创建 RedisCacheWriter 对象 - RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory()); - RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory, - BatchStrategies.scan(msgpushCacheProperties.getRedisScanBatchSize())); - // 创建 TenantRedisCacheManager 对象 - return new TenantRedisCacheManager(cacheWriter, redisCacheConfiguration, tenantProperties.getIgnoreCaches()); - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/config/MsgpushTenantRpcAutoConfiguration.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/config/MsgpushTenantRpcAutoConfiguration.java deleted file mode 100644 index 476e56a..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/config/MsgpushTenantRpcAutoConfiguration.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.njcn.msgpush.framework.tenant.config; - -import com.njcn.msgpush.framework.tenant.core.rpc.TenantRequestInterceptor; -import com.njcn.msgpush.framework.common.biz.system.tenant.TenantCommonApi; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.cloud.openfeign.EnableFeignClients; -import org.springframework.context.annotation.Bean; - -@AutoConfiguration -@ConditionalOnProperty(prefix = "msgpush.tenant", value = "enable", matchIfMissing = true) // 允许使用 msgpush.tenant.enable=false 禁用多租户 -@EnableFeignClients(clients = TenantCommonApi.class) // 主要是引入相关的 API 服务 -public class MsgpushTenantRpcAutoConfiguration { - - @Bean - public TenantRequestInterceptor tenantRequestInterceptor() { - return new TenantRequestInterceptor(); - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/config/TenantProperties.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/config/TenantProperties.java deleted file mode 100644 index 0ab6418..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/config/TenantProperties.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.njcn.msgpush.framework.tenant.config; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * 多租户配置 - * - * @author hongawen - */ -@ConfigurationProperties(prefix = "msgpush.tenant") -@Data -public class TenantProperties { - - /** - * 租户是否开启 - */ - private static final Boolean ENABLE_DEFAULT = true; - - /** - * 是否开启 - */ - private Boolean enable = ENABLE_DEFAULT; - - /** - * 需要忽略多租户的请求 - * - * 默认情况下,每个请求需要带上 tenant-id 的请求头。但是,部分请求是无需带上的,例如说短信回调、支付回调等 Open API! - */ - private Set ignoreUrls = new HashSet<>(); - - /** - * 需要忽略跨(切换)租户访问的请求 - * - * 原因是:某些接口,访问的是个人信息,在跨租户是获取不到的! - */ - private Set ignoreVisitUrls = Collections.emptySet(); - - /** - * 需要忽略多租户的表 - * - * 即默认所有表都开启多租户的功能,所以记得添加对应的 tenant_id 字段哟 - */ - private Set ignoreTables = Collections.emptySet(); - - /** - * 需要忽略多租户的 Spring Cache 缓存 - * - * 即默认所有缓存都开启多租户的功能,所以记得添加对应的 tenant_id 字段哟 - */ - private Set ignoreCaches = Collections.emptySet(); - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/aop/TenantIgnore.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/aop/TenantIgnore.java deleted file mode 100644 index 73936dc..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/aop/TenantIgnore.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.aop; - -import com.njcn.msgpush.framework.tenant.config.TenantProperties; - -import java.lang.annotation.*; - -/** - * 忽略租户,标记指定方法不进行租户的自动过滤 - * - * 注意,只有 DB 的场景会过滤,其它场景暂时不过滤: - * 1、Redis 场景:因为是基于 Key 实现多租户的能力,所以忽略没有意义,不像 DB 是一个 column 实现的 - * 2、MQ 场景:有点难以抉择,目前可以通过 Consumer 手动在消费的方法上,添加 @TenantIgnore 进行忽略 - * - * 特殊: - * 1、如果添加到 Controller 类上,则该 URL 自动添加到 {@link TenantProperties#getIgnoreUrls()} 中 - * 2、如果添加到 DO 实体类上,则它对应的表名“相当于”自动添加到 {@link TenantProperties#getIgnoreTables()} 中 - * - * @author hongawen - */ -@Target({ElementType.METHOD, ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Inherited -public @interface TenantIgnore { - - /** - * 是否开启忽略租户,默认为 true 开启 - * - * 支持 Spring EL 表达式,如果返回 true 则满足条件,进行租户的忽略 - */ - String enable() default "true"; - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/aop/TenantIgnoreAspect.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/aop/TenantIgnoreAspect.java deleted file mode 100644 index 1064c11..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/aop/TenantIgnoreAspect.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.aop; - -import com.njcn.msgpush.framework.common.util.spring.SpringExpressionUtils; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.tenant.core.util.TenantUtils; -import lombok.extern.slf4j.Slf4j; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; - -/** - * 忽略多租户的 Aspect,基于 {@link TenantIgnore} 注解实现,用于一些全局的逻辑。 - * 例如说,一个定时任务,读取所有数据,进行处理。 - * 又例如说,读取所有数据,进行缓存。 - * - * 整体逻辑的实现,和 {@link TenantUtils#executeIgnore(Runnable)} 需要保持一致 - * - * @author hongawen - */ -@Aspect -@Slf4j -public class TenantIgnoreAspect { - - @Around("@annotation(tenantIgnore)") - public Object around(ProceedingJoinPoint joinPoint, TenantIgnore tenantIgnore) throws Throwable { - Boolean oldIgnore = TenantContextHolder.isIgnore(); - try { - // 计算条件,满足的情况下,才进行忽略 - Object enable = SpringExpressionUtils.parseExpression(tenantIgnore.enable()); - if (Boolean.TRUE.equals(enable)) { - TenantContextHolder.setIgnore(true); - } - - // 执行逻辑 - return joinPoint.proceed(); - } finally { - TenantContextHolder.setIgnore(oldIgnore); - } - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/context/TenantContextHolder.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/context/TenantContextHolder.java deleted file mode 100644 index c575aaf..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/context/TenantContextHolder.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.context; - -import cn.hutool.core.util.StrUtil; -import com.njcn.msgpush.framework.common.enums.DocumentEnum; -import com.alibaba.ttl.TransmittableThreadLocal; - -/** - * 多租户上下文 Holder - * - * @author hongawen - */ -public class TenantContextHolder { - - /** - * 当前租户编号 - */ - private static final ThreadLocal TENANT_ID = new TransmittableThreadLocal<>(); - - /** - * 是否忽略租户 - */ - private static final ThreadLocal IGNORE = new TransmittableThreadLocal<>(); - - /** - * 获得租户编号 - * - * @return 租户编号 - */ - public static Long getTenantId() { - return TENANT_ID.get(); - } - - /** - * 获得租户编号。如果不存在,则抛出 NullPointerException 异常 - * - * @return 租户编号 - */ - public static Long getRequiredTenantId() { - Long tenantId = getTenantId(); - if (tenantId == null) { - throw new NullPointerException("TenantContextHolder 不存在租户编号!可参考文档:" - + DocumentEnum.TENANT.getUrl()); - } - return tenantId; - } - - public static void setTenantId(Long tenantId) { - TENANT_ID.set(tenantId); - } - - public static void setIgnore(Boolean ignore) { - IGNORE.set(ignore); - } - - /** - * 当前是否忽略租户 - * - * @return 是否忽略 - */ - public static boolean isIgnore() { - return Boolean.TRUE.equals(IGNORE.get()); - } - - public static void clear() { - TENANT_ID.remove(); - IGNORE.remove(); - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/db/TenantBaseDO.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/db/TenantBaseDO.java deleted file mode 100644 index 553b562..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/db/TenantBaseDO.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.db; - -import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import lombok.Data; -import lombok.EqualsAndHashCode; - -/** - * 拓展多租户的 BaseDO 基类 - * - * @author hongawen - */ -@Data -@EqualsAndHashCode(callSuper = true) -public abstract class TenantBaseDO extends BaseDO { - - /** - * 多租户编号 - */ - private Long tenantId; - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/db/TenantDatabaseInterceptor.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/db/TenantDatabaseInterceptor.java deleted file mode 100644 index 3e6afa3..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/db/TenantDatabaseInterceptor.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.db; - -import com.njcn.msgpush.framework.tenant.config.TenantProperties; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.baomidou.mybatisplus.core.metadata.TableInfo; -import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; -import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; -import com.baomidou.mybatisplus.extension.toolkit.SqlParserUtils; -import net.sf.jsqlparser.expression.Expression; -import net.sf.jsqlparser.expression.LongValue; - -import java.util.HashMap; -import java.util.Map; - -/** - * 基于 MyBatis Plus 多租户的功能,实现 DB 层面的多租户的功能 - * - * @author hongawen - */ -public class TenantDatabaseInterceptor implements TenantLineHandler { - - /** - * 忽略的表 - * - * KEY:表名 - * VALUE:是否忽略 - */ - private final Map ignoreTables = new HashMap<>(); - - public TenantDatabaseInterceptor(TenantProperties properties) { - // 不同 DB 下,大小写的习惯不同,所以需要都添加进去 - properties.getIgnoreTables().forEach(table -> { - addIgnoreTable(table, true); - }); - // 在 OracleKeyGenerator 中,生成主键时,会查询这个表,查询这个表后,会自动拼接 TENANT_ID 导致报错 - addIgnoreTable("DUAL", true); - } - - @Override - public Expression getTenantId() { - return new LongValue(TenantContextHolder.getRequiredTenantId()); - } - - @Override - public boolean ignoreTable(String tableName) { - // 情况一,全局忽略多租户 - if (TenantContextHolder.isIgnore()) { - return true; - } - // 情况二,忽略多租户的表 - tableName = SqlParserUtils.removeWrapperSymbol(tableName); - Boolean ignore = ignoreTables.get(tableName.toLowerCase()); - if (ignore == null) { - ignore = computeIgnoreTable(tableName); - synchronized (ignoreTables) { - addIgnoreTable(tableName, ignore); - } - } - return ignore; - } - - private void addIgnoreTable(String tableName, boolean ignore) { - ignoreTables.put(tableName.toLowerCase(), ignore); - ignoreTables.put(tableName.toUpperCase(), ignore); - } - - private boolean computeIgnoreTable(String tableName) { - // 找不到的表,说明不是 msgpush 项目里的,不进行拦截(忽略租户) - TableInfo tableInfo = TableInfoHelper.getTableInfo(tableName); - if (tableInfo == null) { - return true; - } - // 如果继承了 TenantBaseDO 基类,显然不忽略租户 - if (TenantBaseDO.class.isAssignableFrom(tableInfo.getEntityType())) { - return false; - } - // 如果添加了 @TenantIgnore 注解,则忽略租户 - TenantIgnore tenantIgnore = tableInfo.getEntityType().getAnnotation(TenantIgnore.class); - return tenantIgnore != null; - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/kafka/TenantKafkaEnvironmentPostProcessor.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/kafka/TenantKafkaEnvironmentPostProcessor.java deleted file mode 100644 index ecc6f8f..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/kafka/TenantKafkaEnvironmentPostProcessor.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.mq.kafka; - -import cn.hutool.core.util.StrUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.env.EnvironmentPostProcessor; -import org.springframework.core.env.ConfigurableEnvironment; - -/** - * 多租户的 Kafka 的 {@link EnvironmentPostProcessor} 实现类 - * - * Kafka Producer 发送消息时,增加 {@link TenantKafkaProducerInterceptor} 拦截器 - * - * @author hongawen - */ -@Slf4j -public class TenantKafkaEnvironmentPostProcessor implements EnvironmentPostProcessor { - - private static final String PROPERTY_KEY_INTERCEPTOR_CLASSES = "spring.kafka.producer.properties.interceptor.classes"; - - @Override - public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { - // 添加 TenantKafkaProducerInterceptor 拦截器 - try { - String value = environment.getProperty(PROPERTY_KEY_INTERCEPTOR_CLASSES); - if (StrUtil.isEmpty(value)) { - value = TenantKafkaProducerInterceptor.class.getName(); - } else { - value += "," + TenantKafkaProducerInterceptor.class.getName(); - } - environment.getSystemProperties().put(PROPERTY_KEY_INTERCEPTOR_CLASSES, value); - } catch (NoClassDefFoundError ignore) { - // 如果触发 NoClassDefFoundError 异常,说明 TenantKafkaProducerInterceptor 类不存在,即没引入 kafka-spring 依赖 - } - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/kafka/TenantKafkaProducerInterceptor.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/kafka/TenantKafkaProducerInterceptor.java deleted file mode 100644 index c9319a8..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/kafka/TenantKafkaProducerInterceptor.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.mq.kafka; - -import cn.hutool.core.util.ReflectUtil; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import org.apache.kafka.clients.producer.ProducerInterceptor; -import org.apache.kafka.clients.producer.ProducerRecord; -import org.apache.kafka.clients.producer.RecordMetadata; -import org.apache.kafka.common.header.Headers; -import org.springframework.messaging.handler.invocation.InvocableHandlerMethod; - -import java.util.Map; - -import static com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; - -/** - * Kafka 消息队列的多租户 {@link ProducerInterceptor} 实现类 - * - * 1. Producer 发送消息时,将 {@link TenantContextHolder} 租户编号,添加到消息的 Header 中 - * 2. Consumer 消费消息时,将消息的 Header 的租户编号,添加到 {@link TenantContextHolder} 中,通过 {@link InvocableHandlerMethod} 实现 - * - * @author hongawen - */ -public class TenantKafkaProducerInterceptor implements ProducerInterceptor { - - @Override - public ProducerRecord onSend(ProducerRecord record) { - Long tenantId = TenantContextHolder.getTenantId(); - if (tenantId != null) { - Headers headers = (Headers) ReflectUtil.getFieldValue(record, "headers"); // private 属性,没有 get 方法,智能反射 - headers.add(HEADER_TENANT_ID, tenantId.toString().getBytes()); - } - return record; - } - - @Override - public void onAcknowledgement(RecordMetadata metadata, Exception exception) { - } - - @Override - public void close() { - } - - @Override - public void configure(Map configs) { - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rabbitmq/TenantRabbitMQInitializer.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rabbitmq/TenantRabbitMQInitializer.java deleted file mode 100644 index acf3989..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rabbitmq/TenantRabbitMQInitializer.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.mq.rabbitmq; - -import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; - -/** - * 多租户的 RabbitMQ 初始化器 - * - * @author hongawen - */ -public class TenantRabbitMQInitializer implements BeanPostProcessor { - - @Override - @SuppressWarnings("PatternVariableCanBeUsed") - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof RabbitTemplate) { - RabbitTemplate rabbitTemplate = (RabbitTemplate) bean; - rabbitTemplate.addBeforePublishPostProcessors(new TenantRabbitMQMessagePostProcessor()); - } - return bean; - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rabbitmq/TenantRabbitMQMessagePostProcessor.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rabbitmq/TenantRabbitMQMessagePostProcessor.java deleted file mode 100644 index 390225d..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rabbitmq/TenantRabbitMQMessagePostProcessor.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.mq.rabbitmq; - -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import org.apache.kafka.clients.producer.ProducerInterceptor; -import org.springframework.amqp.AmqpException; -import org.springframework.amqp.core.Message; -import org.springframework.amqp.core.MessagePostProcessor; -import org.springframework.messaging.handler.invocation.InvocableHandlerMethod; - -import static com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; - -/** - * RabbitMQ 消息队列的多租户 {@link ProducerInterceptor} 实现类 - * - * 1. Producer 发送消息时,将 {@link TenantContextHolder} 租户编号,添加到消息的 Header 中 - * 2. Consumer 消费消息时,将消息的 Header 的租户编号,添加到 {@link TenantContextHolder} 中,通过 {@link InvocableHandlerMethod} 实现 - * - * @author hongawen - */ -public class TenantRabbitMQMessagePostProcessor implements MessagePostProcessor { - - @Override - public Message postProcessMessage(Message message) throws AmqpException { - Long tenantId = TenantContextHolder.getTenantId(); - if (tenantId != null) { - message.getMessageProperties().getHeaders().put(HEADER_TENANT_ID, tenantId); - } - return message; - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/redis/TenantRedisMessageInterceptor.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/redis/TenantRedisMessageInterceptor.java deleted file mode 100644 index 9cdbebe..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/redis/TenantRedisMessageInterceptor.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.mq.redis; - -import cn.hutool.core.util.StrUtil; -import com.njcn.msgpush.framework.mq.redis.core.interceptor.RedisMessageInterceptor; -import com.njcn.msgpush.framework.mq.redis.core.message.AbstractRedisMessage; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; - -import static com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; - -/** - * 多租户 {@link AbstractRedisMessage} 拦截器 - * - * 1. Producer 发送消息时,将 {@link TenantContextHolder} 租户编号,添加到消息的 Header 中 - * 2. Consumer 消费消息时,将消息的 Header 的租户编号,添加到 {@link TenantContextHolder} 中 - * - * @author hongawen - */ -public class TenantRedisMessageInterceptor implements RedisMessageInterceptor { - - @Override - public void sendMessageBefore(AbstractRedisMessage message) { - Long tenantId = TenantContextHolder.getTenantId(); - if (tenantId != null) { - message.addHeader(HEADER_TENANT_ID, tenantId.toString()); - } - } - - @Override - public void consumeMessageBefore(AbstractRedisMessage message) { - String tenantIdStr = message.getHeader(HEADER_TENANT_ID); - if (StrUtil.isNotEmpty(tenantIdStr)) { - TenantContextHolder.setTenantId(Long.valueOf(tenantIdStr)); - } - } - - @Override - public void consumeMessageAfter(AbstractRedisMessage message) { - // 注意,Consumer 是一个逻辑的入口,所以不考虑原本上下文就存在租户编号的情况 - TenantContextHolder.clear(); - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rocketmq/TenantRocketMQConsumeMessageHook.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rocketmq/TenantRocketMQConsumeMessageHook.java deleted file mode 100644 index 6ec45da..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rocketmq/TenantRocketMQConsumeMessageHook.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.mq.rocketmq; - -import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.StrUtil; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import org.apache.rocketmq.client.hook.ConsumeMessageContext; -import org.apache.rocketmq.client.hook.ConsumeMessageHook; -import org.apache.rocketmq.common.message.MessageExt; -import org.springframework.messaging.handler.invocation.InvocableHandlerMethod; - -import java.util.List; - -import static com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; - -/** - * RocketMQ 消息队列的多租户 {@link ConsumeMessageHook} 实现类 - * - * Consumer 消费消息时,将消息的 Header 的租户编号,添加到 {@link TenantContextHolder} 中,通过 {@link InvocableHandlerMethod} 实现 - * - * @author hongawen - */ -public class TenantRocketMQConsumeMessageHook implements ConsumeMessageHook { - - @Override - public String hookName() { - return getClass().getSimpleName(); - } - - @Override - public void consumeMessageBefore(ConsumeMessageContext context) { - // 校验,消息必须是单条,不然设置租户可能不正确 - List messages = context.getMsgList(); - Assert.isTrue(messages.size() == 1, "消息条数({})不正确", messages.size()); - // 设置租户编号 - String tenantId = messages.get(0).getUserProperty(HEADER_TENANT_ID); - if (StrUtil.isNotEmpty(tenantId)) { - TenantContextHolder.setTenantId(Long.parseLong(tenantId)); - } - } - - @Override - public void consumeMessageAfter(ConsumeMessageContext context) { - TenantContextHolder.clear(); - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rocketmq/TenantRocketMQInitializer.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rocketmq/TenantRocketMQInitializer.java deleted file mode 100644 index 9f79c7e..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rocketmq/TenantRocketMQInitializer.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.mq.rocketmq; - -import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; -import org.apache.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl; -import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl; -import org.apache.rocketmq.client.producer.DefaultMQProducer; -import org.apache.rocketmq.spring.core.RocketMQTemplate; -import org.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; - -/** - * 多租户的 RocketMQ 初始化器 - * - * @author hongawen - */ -public class TenantRocketMQInitializer implements BeanPostProcessor { - - @Override - @SuppressWarnings("PatternVariableCanBeUsed") - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof DefaultRocketMQListenerContainer) { - DefaultRocketMQListenerContainer container = (DefaultRocketMQListenerContainer) bean; - initTenantConsumer(container.getConsumer()); - } else if (bean instanceof RocketMQTemplate) { - RocketMQTemplate template = (RocketMQTemplate) bean; - initTenantProducer(template.getProducer()); - } - return bean; - } - - private void initTenantProducer(DefaultMQProducer producer) { - if (producer == null) { - return; - } - DefaultMQProducerImpl producerImpl = producer.getDefaultMQProducerImpl(); - if (producerImpl == null) { - return; - } - producerImpl.registerSendMessageHook(new TenantRocketMQSendMessageHook()); - } - - private void initTenantConsumer(DefaultMQPushConsumer consumer) { - if (consumer == null) { - return; - } - DefaultMQPushConsumerImpl consumerImpl = consumer.getDefaultMQPushConsumerImpl(); - if (consumerImpl == null) { - return; - } - consumerImpl.registerConsumeMessageHook(new TenantRocketMQConsumeMessageHook()); - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rocketmq/TenantRocketMQSendMessageHook.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rocketmq/TenantRocketMQSendMessageHook.java deleted file mode 100644 index bb4c71b..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/mq/rocketmq/TenantRocketMQSendMessageHook.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.mq.rocketmq; - -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import org.apache.rocketmq.client.hook.SendMessageContext; -import org.apache.rocketmq.client.hook.SendMessageHook; - -import static com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; - -/** - * RocketMQ 消息队列的多租户 {@link SendMessageHook} 实现类 - * - * Producer 发送消息时,将 {@link TenantContextHolder} 租户编号,添加到消息的 Header 中 - * - * @author hongawen - */ -public class TenantRocketMQSendMessageHook implements SendMessageHook { - - @Override - public String hookName() { - return getClass().getSimpleName(); - } - - @Override - public void sendMessageBefore(SendMessageContext sendMessageContext) { - Long tenantId = TenantContextHolder.getTenantId(); - if (tenantId == null) { - return; - } - sendMessageContext.getMessage().putUserProperty(HEADER_TENANT_ID, tenantId.toString()); - } - - @Override - public void sendMessageAfter(SendMessageContext sendMessageContext) { - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/redis/TenantRedisCacheManager.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/redis/TenantRedisCacheManager.java deleted file mode 100644 index a114313..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/redis/TenantRedisCacheManager.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.redis; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.StrUtil; -import com.njcn.msgpush.framework.redis.core.TimeoutRedisCacheManager; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import lombok.extern.slf4j.Slf4j; -import org.springframework.cache.Cache; -import org.springframework.data.redis.cache.RedisCacheConfiguration; -import org.springframework.data.redis.cache.RedisCacheManager; -import org.springframework.data.redis.cache.RedisCacheWriter; - -import java.util.Set; - -/** - * 多租户的 {@link RedisCacheManager} 实现类 - * - * 操作指定 name 的 {@link Cache} 时,自动拼接租户后缀,格式为 name + ":" + tenantId + 后缀 - * - * @author airhead - */ -@Slf4j -public class TenantRedisCacheManager extends TimeoutRedisCacheManager { - - private static final String SPLIT = "#"; - - private final Set ignoreCaches; - - public TenantRedisCacheManager(RedisCacheWriter cacheWriter, - RedisCacheConfiguration defaultCacheConfiguration, - Set ignoreCaches) { - super(cacheWriter, defaultCacheConfiguration); - this.ignoreCaches = ignoreCaches; - } - - @Override - public Cache getCache(String name) { - String[] names = StrUtil.splitToArray(name, SPLIT); - // 如果开启多租户,则 name 拼接租户后缀 - if (!TenantContextHolder.isIgnore() - && TenantContextHolder.getTenantId() != null - && !CollUtil.contains(ignoreCaches, names[0])) { - name = name + ":" + TenantContextHolder.getTenantId(); - } - - // 继续基于父方法 - return super.getCache(name); - } - -} \ No newline at end of file diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/rpc/TenantRequestInterceptor.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/rpc/TenantRequestInterceptor.java deleted file mode 100644 index d94b52d..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/rpc/TenantRequestInterceptor.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.rpc; - -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils; -import feign.RequestInterceptor; -import feign.RequestTemplate; - -import static com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; - -/** - * Tenant 的 RequestInterceptor 实现类:Feign 请求时,将 {@link TenantContextHolder} 设置到 header 中,继续透传给被调用的服务 - * - * @author hongawen - */ -public class TenantRequestInterceptor implements RequestInterceptor { - - @Override - public void apply(RequestTemplate requestTemplate) { - Long tenantId = TenantContextHolder.getTenantId(); - if (tenantId != null) { - requestTemplate.header(HEADER_TENANT_ID, String.valueOf(tenantId)); - } - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/security/TenantSecurityWebFilter.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/security/TenantSecurityWebFilter.java deleted file mode 100644 index effef5c..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/security/TenantSecurityWebFilter.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.security; - -import cn.hutool.core.collection.CollUtil; -import com.njcn.msgpush.framework.common.exception.enums.GlobalErrorCodeConstants; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.common.util.servlet.ServletUtils; -import com.njcn.msgpush.framework.security.core.LoginUser; -import com.njcn.msgpush.framework.security.core.util.SecurityFrameworkUtils; -import com.njcn.msgpush.framework.tenant.config.TenantProperties; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.tenant.core.service.TenantFrameworkService; -import com.njcn.msgpush.framework.web.config.WebProperties; -import com.njcn.msgpush.framework.web.core.filter.ApiRequestFilter; -import com.njcn.msgpush.framework.web.core.handler.GlobalExceptionHandler; -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import lombok.extern.slf4j.Slf4j; -import org.springframework.util.AntPathMatcher; - -import java.io.IOException; -import java.util.Objects; -import java.util.Set; - -/** - * 多租户 Security Web 过滤器 - * 1. 如果是登陆的用户,校验是否有权限访问该租户,避免越权问题。 - * 2. 如果请求未带租户的编号,检查是否是忽略的 URL,否则也不允许访问。 - * 3. 校验租户是合法,例如说被禁用、到期 - * - * @author hongawen - */ -@Slf4j -public class TenantSecurityWebFilter extends ApiRequestFilter { - - private final TenantProperties tenantProperties; - - /** - * 允许忽略租户的 URL 列表 - * - * 目的:解决 修改配置会导致 @TenantIgnore Controller 接口过滤失效 - */ - private final Set ignoreUrls; - - private final AntPathMatcher pathMatcher; - - private final GlobalExceptionHandler globalExceptionHandler; - private final TenantFrameworkService tenantFrameworkService; - - public TenantSecurityWebFilter(WebProperties webProperties, - TenantProperties tenantProperties, - Set ignoreUrls, - GlobalExceptionHandler globalExceptionHandler, - TenantFrameworkService tenantFrameworkService) { - super(webProperties); - this.tenantProperties = tenantProperties; - this.ignoreUrls = ignoreUrls; - this.pathMatcher = new AntPathMatcher(); - this.globalExceptionHandler = globalExceptionHandler; - this.tenantFrameworkService = tenantFrameworkService; - } - - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) - throws ServletException, IOException { - Long tenantId = TenantContextHolder.getTenantId(); - // 1. 登陆的用户,校验是否有权限访问该租户,避免越权问题。 - LoginUser user = SecurityFrameworkUtils.getLoginUser(); - if (user != null) { - // 如果获取不到租户编号,则尝试使用登陆用户的租户编号 - if (tenantId == null) { - tenantId = user.getTenantId(); - TenantContextHolder.setTenantId(tenantId); - // 如果传递了租户编号,则进行比对租户编号,避免越权问题 - } else if (!Objects.equals(user.getTenantId(), TenantContextHolder.getTenantId())) { - log.error("[doFilterInternal][租户({}) User({}/{}) 越权访问租户({}) URL({}/{})]", - user.getTenantId(), user.getId(), user.getUserType(), - TenantContextHolder.getTenantId(), request.getRequestURI(), request.getMethod()); - ServletUtils.writeJSON(response, CommonResult.error(GlobalErrorCodeConstants.FORBIDDEN.getCode(), - "您无权访问该租户的数据")); - return; - } - } - - // 如果非允许忽略租户的 URL,则校验租户是否合法 - if (!isIgnoreUrl(request)) { - // 2. 如果请求未带租户的编号,不允许访问。 - if (tenantId == null) { - log.error("[doFilterInternal][URL({}/{}) 未传递租户编号]", request.getRequestURI(), request.getMethod()); - ServletUtils.writeJSON(response, CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST.getCode(), - "请求的租户标识未传递,请进行排查")); - return; - } - // 3. 校验租户是合法,例如说被禁用、到期 - try { - tenantFrameworkService.validTenant(tenantId); - } catch (Throwable ex) { - CommonResult result = globalExceptionHandler.allExceptionHandler(request, ex); - ServletUtils.writeJSON(response, result); - return; - } - } else { // 如果是允许忽略租户的 URL,若未传递租户编号,则默认忽略租户编号,避免报错 - if (tenantId == null) { - TenantContextHolder.setIgnore(true); - } - } - - // 继续过滤 - chain.doFilter(request, response); - } - - private boolean isIgnoreUrl(HttpServletRequest request) { - String apiUri = request.getRequestURI().substring(request.getContextPath().length()); - // 快速匹配,保证性能 - if (CollUtil.contains(tenantProperties.getIgnoreUrls(), apiUri) - || CollUtil.contains(ignoreUrls, apiUri)) { - return true; - } - // 逐个 Ant 路径匹配 - for (String url : tenantProperties.getIgnoreUrls()) { - if (pathMatcher.match(url, apiUri)) { - return true; - } - } - for (String url : ignoreUrls) { - if (pathMatcher.match(url, apiUri)) { - return true; - } - } - return false; - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/service/TenantFrameworkService.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/service/TenantFrameworkService.java deleted file mode 100644 index b02709e..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/service/TenantFrameworkService.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.service; - -import java.util.List; - -/** - * Tenant 框架 Service 接口,定义获取租户信息 - * - * @author hongawen - */ -public interface TenantFrameworkService { - - /** - * 获得所有租户 - * - * @return 租户编号数组 - */ - List getTenantIds(); - - /** - * 校验租户是否合法 - * - * @param id 租户编号 - */ - void validTenant(Long id); - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/service/TenantFrameworkServiceImpl.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/service/TenantFrameworkServiceImpl.java deleted file mode 100644 index bbd44b1..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/service/TenantFrameworkServiceImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.service; - -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.common.biz.system.tenant.TenantCommonApi; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; - -import java.time.Duration; -import java.util.List; - -import static com.njcn.msgpush.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache; - -/** - * Tenant 框架 Service 实现类 - * - * @author hongawen - */ -@RequiredArgsConstructor -public class TenantFrameworkServiceImpl implements TenantFrameworkService { - - private final TenantCommonApi tenantApi; - - /** - * 针对 {@link #getTenantIds()} 的缓存 - */ - private final LoadingCache> getTenantIdsCache = buildAsyncReloadingCache( - Duration.ofMinutes(1L), // 过期时间 1 分钟 - new CacheLoader>() { - - @Override - public List load(Object key) { - return tenantApi.getTenantIdList().getCheckedData(); - } - - }); - - /** - * 针对 {@link #validTenant(Long)} 的缓存 - */ - private final LoadingCache> validTenantCache = buildAsyncReloadingCache( - Duration.ofMinutes(1L), // 过期时间 1 分钟 - new CacheLoader>() { - - @Override - public CommonResult load(Long id) { - return tenantApi.validTenant(id); - } - - }); - - @Override - @SneakyThrows - public List getTenantIds() { - return getTenantIdsCache.get(Boolean.TRUE); - } - - @Override - @SneakyThrows - public void validTenant(Long id) { - validTenantCache.get(id).checkError(); - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/util/TenantUtils.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/util/TenantUtils.java deleted file mode 100644 index c86d161..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/util/TenantUtils.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.util; - -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; - -import java.util.Map; -import java.util.concurrent.Callable; - -import static com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; - -/** - * 多租户 Util - * - * @author hongawen - */ -public class TenantUtils { - - /** - * 使用指定租户,执行对应的逻辑 - * - * 注意,如果当前是忽略租户的情况下,会被强制设置成不忽略租户 - * 当然,执行完成后,还是会恢复回去 - * - * @param tenantId 租户编号 - * @param runnable 逻辑 - */ - public static void execute(Long tenantId, Runnable runnable) { - Long oldTenantId = TenantContextHolder.getTenantId(); - Boolean oldIgnore = TenantContextHolder.isIgnore(); - try { - TenantContextHolder.setTenantId(tenantId); - TenantContextHolder.setIgnore(false); - // 执行逻辑 - runnable.run(); - } finally { - TenantContextHolder.setTenantId(oldTenantId); - TenantContextHolder.setIgnore(oldIgnore); - } - } - - /** - * 使用指定租户,执行对应的逻辑 - * - * 注意,如果当前是忽略租户的情况下,会被强制设置成不忽略租户 - * 当然,执行完成后,还是会恢复回去 - * - * @param tenantId 租户编号 - * @param callable 逻辑 - * @return 结果 - */ - public static V execute(Long tenantId, Callable callable) { - Long oldTenantId = TenantContextHolder.getTenantId(); - Boolean oldIgnore = TenantContextHolder.isIgnore(); - try { - TenantContextHolder.setTenantId(tenantId); - TenantContextHolder.setIgnore(false); - // 执行逻辑 - return callable.call(); - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - TenantContextHolder.setTenantId(oldTenantId); - TenantContextHolder.setIgnore(oldIgnore); - } - } - - /** - * 忽略租户,执行对应的逻辑 - * - * @param runnable 逻辑 - */ - public static void executeIgnore(Runnable runnable) { - Boolean oldIgnore = TenantContextHolder.isIgnore(); - try { - TenantContextHolder.setIgnore(true); - // 执行逻辑 - runnable.run(); - } finally { - TenantContextHolder.setIgnore(oldIgnore); - } - } - - /** - * 忽略租户,执行对应的逻辑 - * - * @param callable 逻辑 - * @return 结果 - */ - public static V executeIgnore(Callable callable) { - Boolean oldIgnore = TenantContextHolder.isIgnore(); - try { - TenantContextHolder.setIgnore(true); - // 执行逻辑 - return callable.call(); - } catch (Exception e) { - throw new RuntimeException(e); - } finally { - TenantContextHolder.setIgnore(oldIgnore); - } - } - - /** - * 将多租户编号,添加到 header 中 - * - * @param headers HTTP 请求 headers - * @param tenantId 租户编号 - */ - public static void addTenantHeader(Map headers, Long tenantId) { - if (tenantId != null) { - headers.put(HEADER_TENANT_ID, tenantId.toString()); - } - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/web/TenantContextWebFilter.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/web/TenantContextWebFilter.java deleted file mode 100644 index d50329b..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/web/TenantContextWebFilter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.web; - -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils; -import org.springframework.web.filter.OncePerRequestFilter; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; - -/** - * 多租户 Context Web 过滤器 - * 将请求 Header 中的 tenant-id 解析出来,添加到 {@link TenantContextHolder} 中,这样后续的 DB 等操作,可以获得到租户编号。 - * - * @author hongawen - */ -public class TenantContextWebFilter extends OncePerRequestFilter { - - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) - throws ServletException, IOException { - // 设置 - Long tenantId = WebFrameworkUtils.getTenantId(request); - if (tenantId != null) { - TenantContextHolder.setTenantId(tenantId); - } - try { - chain.doFilter(request, response); - } finally { - // 清理 - TenantContextHolder.clear(); - } - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/web/TenantVisitContextInterceptor.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/web/TenantVisitContextInterceptor.java deleted file mode 100644 index 59dac4f..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/core/web/TenantVisitContextInterceptor.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.njcn.msgpush.framework.tenant.core.web; - -import cn.hutool.core.util.ObjUtil; -import com.njcn.msgpush.framework.common.exception.enums.GlobalErrorCodeConstants; -import com.njcn.msgpush.framework.security.core.LoginUser; -import com.njcn.msgpush.framework.security.core.service.SecurityFrameworkService; -import com.njcn.msgpush.framework.security.core.util.SecurityFrameworkUtils; -import com.njcn.msgpush.framework.tenant.config.TenantProperties; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.servlet.HandlerInterceptor; - -import static com.njcn.msgpush.framework.common.exception.util.ServiceExceptionUtil.exception0; - -@RequiredArgsConstructor -@Slf4j -public class TenantVisitContextInterceptor implements HandlerInterceptor { - - private static final String PERMISSION = "system:tenant:visit"; - - private final TenantProperties tenantProperties; - - private final SecurityFrameworkService securityFrameworkService; - - @Override - public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { - // 如果和当前租户编号一致,则直接跳过 - Long visitTenantId = WebFrameworkUtils.getVisitTenantId(request); - if (visitTenantId == null) { - return true; - } - if (ObjUtil.equal(visitTenantId, TenantContextHolder.getTenantId())) { - return true; - } - // 必须是登录用户 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); - if (loginUser == null) { - return true; - } - - // 校验用户是否可切换租户 - if (!securityFrameworkService.hasAnyPermissions(PERMISSION)) { - throw exception0(GlobalErrorCodeConstants.FORBIDDEN.getCode(), "您无权切换租户"); - } - - // 【重点】切换租户编号 - loginUser.setVisitTenantId(visitTenantId); - TenantContextHolder.setTenantId(visitTenantId); - return true; - } - - @Override - public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { - // 【重点】清理切换,换回原租户编号 - LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); - if (loginUser != null && loginUser.getTenantId() != null) { - TenantContextHolder.setTenantId(loginUser.getTenantId()); - } - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/package-info.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/package-info.java deleted file mode 100644 index 1cccd52..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/com/njcn/msgpush/framework/tenant/package-info.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * 多租户,支持如下层面: - * 1. DB:基于 MyBatis Plus 多租户的功能实现。 - * 2. Redis:通过在 Redis Key 上拼接租户编号的方式,进行隔离。 - * 3. Web:请求 HTTP API 时,解析 Header 的 tenant-id 租户编号,添加到租户上下文。 - * 4. Security:校验当前登陆的用户,是否越权访问其它租户的数据。 - * 5. Job:在 JobHandler 执行任务时,会按照每个租户,都独立并行执行一次。 - * 6. MQ:在 Producer 发送消息时,Header 带上 tenant-id 租户编号;在 Consumer 消费消息时,将 Header 的 tenant-id 租户编号,添加到租户上下文。 - * 7. Async:异步需要保证 ThreadLocal 的传递性,通过使用阿里开源的 TransmittableThreadLocal 实现。相关的改造点,可见: - * 1)Spring Async: - * {@link com.njcn.msgpush.framework.quartz.config.MsgpushAsyncAutoConfiguration#threadPoolTaskExecutorBeanPostProcessor()} - * 2)Spring Security: - * TransmittableThreadLocalSecurityContextHolderStrategy - * 和 MsgpushSecurityAutoConfiguration#securityContextHolderMethodInvokingFactoryBean() 方法 - * - */ -package com.njcn.msgpush.framework.tenant; diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java deleted file mode 100644 index 2456f3c..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethod.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright 2002-2023 the original author or authors. - * - * 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 - * - * https://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 org.springframework.messaging.handler.invocation; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Type; -import java.util.Arrays; - -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.tenant.core.util.TenantUtils; -import org.springframework.core.DefaultParameterNameDiscoverer; -import org.springframework.core.MethodParameter; -import org.springframework.core.ParameterNameDiscoverer; -import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; -import org.springframework.messaging.Message; -import org.springframework.messaging.handler.HandlerMethod; -import org.springframework.util.ObjectUtils; - -import static com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; - -/** - * Extension of {@link HandlerMethod} that invokes the underlying method with - * argument values resolved from the current HTTP request through a list of - * {@link HandlerMethodArgumentResolver}. - * - * 针对 rabbitmq-spring 和 kafka-spring,不存在合适的拓展点,可以实现 Consumer 消费前,读取 Header 中的 tenant-id 设置到 {@link TenantContextHolder} 中 - * TODO 芋艿:持续跟进,看看有没新的拓展点 - * - * @author Rossen Stoyanchev - * @author Juergen Hoeller - * @since 4.0 - */ -public class InvocableHandlerMethod extends HandlerMethod { - - private static final Object[] EMPTY_ARGS = new Object[0]; - - - private HandlerMethodArgumentResolverComposite resolvers = new HandlerMethodArgumentResolverComposite(); - - private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); - - - /** - * Create an instance from a {@code HandlerMethod}. - */ - public InvocableHandlerMethod(HandlerMethod handlerMethod) { - super(handlerMethod); - } - - /** - * Create an instance from a bean instance and a method. - */ - public InvocableHandlerMethod(Object bean, Method method) { - super(bean, method); - } - - /** - * Construct a new handler method with the given bean instance, method name and parameters. - * @param bean the object bean - * @param methodName the method name - * @param parameterTypes the method parameter types - * @throws NoSuchMethodException when the method cannot be found - */ - public InvocableHandlerMethod(Object bean, String methodName, Class... parameterTypes) - throws NoSuchMethodException { - - super(bean, methodName, parameterTypes); - } - - - /** - * Set {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers} to use for resolving method argument values. - */ - public void setMessageMethodArgumentResolvers(HandlerMethodArgumentResolverComposite argumentResolvers) { - this.resolvers = argumentResolvers; - } - - /** - * Set the ParameterNameDiscoverer for resolving parameter names when needed - * (e.g. default request attribute name). - *

Default is a {@link org.springframework.core.DefaultParameterNameDiscoverer}. - */ - public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer) { - this.parameterNameDiscoverer = parameterNameDiscoverer; - } - - - /** - * Invoke the method after resolving its argument values in the context of the given message. - *

Argument values are commonly resolved through - * {@link HandlerMethodArgumentResolver HandlerMethodArgumentResolvers}. - * The {@code providedArgs} parameter however may supply argument values to be used directly, - * i.e. without argument resolution. - *

Delegates to {@link #getMethodArgumentValues} and calls {@link #doInvoke} with the - * resolved arguments. - * @param message the current message being processed - * @param providedArgs "given" arguments matched by type, not resolved - * @return the raw value returned by the invoked method - * @throws Exception raised if no suitable argument resolver can be found, - * or if the method raised an exception - * @see #getMethodArgumentValues - * @see #doInvoke - */ - @Nullable - public Object invoke(Message message, Object... providedArgs) throws Exception { - Object[] args = getMethodArgumentValues(message, providedArgs); - if (logger.isTraceEnabled()) { - logger.trace("Arguments: " + Arrays.toString(args)); - } - // 注意:如下是本类的改动点!!! - // 情况一:无租户编号的情况 - Long tenantId= parseTenantId(message); - if (tenantId == null) { - return doInvoke(args); - } - // 情况二:有租户的情况下 - return TenantUtils.execute(tenantId, () -> doInvoke(args)); - } - - private Long parseTenantId(Message message) { - Object tenantId = message.getHeaders().get(HEADER_TENANT_ID); - if (tenantId == null) { - return null; - } - if (tenantId instanceof Long) { - return (Long) tenantId; - } - if (tenantId instanceof Number) { - return ((Number) tenantId).longValue(); - } - if (tenantId instanceof String) { - return Long.parseLong((String) tenantId); - } - if (tenantId instanceof byte[]) { - return Long.parseLong(new String((byte[]) tenantId)); - } - throw new IllegalArgumentException("未知的数据类型:" + tenantId); - } - - /** - * Get the method argument values for the current message, checking the provided - * argument values and falling back to the configured argument resolvers. - *

The resulting array will be passed into {@link #doInvoke}. - * @since 5.1.2 - */ - protected Object[] getMethodArgumentValues(Message message, Object... providedArgs) throws Exception { - MethodParameter[] parameters = getMethodParameters(); - if (ObjectUtils.isEmpty(parameters)) { - return EMPTY_ARGS; - } - - Object[] args = new Object[parameters.length]; - for (int i = 0; i < parameters.length; i++) { - MethodParameter parameter = parameters[i]; - parameter.initParameterNameDiscovery(this.parameterNameDiscoverer); - args[i] = findProvidedArgument(parameter, providedArgs); - if (args[i] != null) { - continue; - } - if (!this.resolvers.supportsParameter(parameter)) { - throw new MethodArgumentResolutionException( - message, parameter, formatArgumentError(parameter, "No suitable resolver")); - } - try { - args[i] = this.resolvers.resolveArgument(parameter, message); - } - catch (Exception ex) { - // Leave stack trace for later, exception may actually be resolved and handled... - if (logger.isDebugEnabled()) { - String exMsg = ex.getMessage(); - if (exMsg != null && !exMsg.contains(parameter.getExecutable().toGenericString())) { - logger.debug(formatArgumentError(parameter, exMsg)); - } - } - throw ex; - } - } - return args; - } - - /** - * Invoke the handler method with the given argument values. - */ - @Nullable - protected Object doInvoke(Object... args) throws Exception { - try { - return getBridgedMethod().invoke(getBean(), args); - } - catch (IllegalArgumentException ex) { - assertTargetBean(getBridgedMethod(), getBean(), args); - String text = (ex.getMessage() == null || ex.getCause() instanceof NullPointerException) ? - "Illegal argument": ex.getMessage(); - throw new IllegalStateException(formatInvokeError(text, args), ex); - } - catch (InvocationTargetException ex) { - // Unwrap for HandlerExceptionResolvers ... - Throwable targetException = ex.getTargetException(); - if (targetException instanceof RuntimeException runtimeException) { - throw runtimeException; - } - else if (targetException instanceof Error error) { - throw error; - } - else if (targetException instanceof Exception exception) { - throw exception; - } - else { - throw new IllegalStateException(formatInvokeError("Invocation failure", args), targetException); - } - } - } - - MethodParameter getAsyncReturnValueType(@Nullable Object returnValue) { - return new AsyncResultMethodParameter(returnValue); - } - - - private class AsyncResultMethodParameter extends AnnotatedMethodParameter { - - @Nullable - private final Object returnValue; - - private final ResolvableType returnType; - - public AsyncResultMethodParameter(@Nullable Object returnValue) { - super(-1); - this.returnValue = returnValue; - this.returnType = ResolvableType.forType(super.getGenericParameterType()).getGeneric(); - } - - protected AsyncResultMethodParameter(AsyncResultMethodParameter original) { - super(original); - this.returnValue = original.returnValue; - this.returnType = original.returnType; - } - - @Override - public Class getParameterType() { - if (this.returnValue != null) { - return this.returnValue.getClass(); - } - if (!ResolvableType.NONE.equals(this.returnType)) { - return this.returnType.toClass(); - } - return super.getParameterType(); - } - - @Override - public Type getGenericParameterType() { - return this.returnType.getType(); - } - - @Override - public AsyncResultMethodParameter clone() { - return new AsyncResultMethodParameter(this); - } - } - -} diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/resources/META-INF/spring.factories b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 3c05e4c..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.env.EnvironmentPostProcessor=\ - com.njcn.msgpush.framework.tenant.core.mq.kafka.TenantKafkaEnvironmentPostProcessor diff --git a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 71362d0..0000000 --- a/msgpush-framework/msgpush-spring-boot-starter-biz-tenant/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1,2 +0,0 @@ -com.njcn.msgpush.framework.tenant.config.MsgpushTenantRpcAutoConfiguration -com.njcn.msgpush.framework.tenant.config.MsgpushTenantAutoConfiguration diff --git a/msgpush-framework/msgpush-spring-boot-starter-redis/src/main/java/com/njcn/msgpush/framework/redis/config/MsgpushCacheAutoConfiguration.java b/msgpush-framework/msgpush-spring-boot-starter-redis/src/main/java/com/njcn/msgpush/framework/redis/config/MsgpushCacheAutoConfiguration.java index 2d83adb..40bc027 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-redis/src/main/java/com/njcn/msgpush/framework/redis/config/MsgpushCacheAutoConfiguration.java +++ b/msgpush-framework/msgpush-spring-boot-starter-redis/src/main/java/com/njcn/msgpush/framework/redis/config/MsgpushCacheAutoConfiguration.java @@ -75,7 +75,7 @@ public class MsgpushCacheAutoConfiguration { RedisConnectionFactory connectionFactory = Objects.requireNonNull(redisTemplate.getConnectionFactory()); RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory, BatchStrategies.scan(msgpushCacheProperties.getRedisScanBatchSize())); - // 创建 TenantRedisCacheManager 对象 + // 创建 RedisCacheManager 对象 return new TimeoutRedisCacheManager(cacheWriter, redisCacheConfiguration); } diff --git a/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/LoginUser.java b/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/LoginUser.java index 870f8a8..e71e2e5 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/LoginUser.java +++ b/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/LoginUser.java @@ -35,10 +35,7 @@ public class LoginUser { * 额外的用户信息 */ private Map info; - /** - * 租户编号 - */ - private Long tenantId; + /** * 授权范围 */ @@ -56,10 +53,6 @@ public class LoginUser { */ @JsonIgnore private Map context; - /** - * 访问的租户编号 - */ - private Long visitTenantId; public void setContext(String key, Object value) { if (context == null) { diff --git a/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/filter/TokenAuthenticationFilter.java b/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/filter/TokenAuthenticationFilter.java index 8eb642e..63d511b 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/filter/TokenAuthenticationFilter.java +++ b/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/filter/TokenAuthenticationFilter.java @@ -96,7 +96,6 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter { // 构建登录用户 return new LoginUser().setId(accessToken.getUserId()).setUserType(accessToken.getUserType()) .setInfo(accessToken.getUserInfo()) // 额外的用户信息 - .setTenantId(accessToken.getTenantId()).setScopes(accessToken.getScopes()) .setExpiresTime(accessToken.getExpiresTime()); } catch (ServiceException serviceException) { // 校验 Token 不通过时,考虑到一些接口是无需登录的,所以直接返回 null 即可 @@ -124,8 +123,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter { } // 构建模拟用户 Long userId = Long.valueOf(token.substring(securityProperties.getMockSecret().length())); - return new LoginUser().setId(userId).setUserType(userType) - .setTenantId(WebFrameworkUtils.getTenantId(request)); + return new LoginUser().setId(userId).setUserType(userType); } private LoginUser buildLoginUserByHeader(HttpServletRequest request) { diff --git a/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/service/SecurityFrameworkServiceImpl.java b/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/service/SecurityFrameworkServiceImpl.java index 7595616..4eaf931 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/service/SecurityFrameworkServiceImpl.java +++ b/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/service/SecurityFrameworkServiceImpl.java @@ -16,7 +16,6 @@ import java.util.List; import static com.njcn.msgpush.framework.common.util.cache.CacheUtils.buildCache; import static com.njcn.msgpush.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; -import static com.njcn.msgpush.framework.security.core.util.SecurityFrameworkUtils.skipPermissionCheck; /** * 默认的 {@link SecurityFrameworkService} 实现类 @@ -64,11 +63,6 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService { @Override @SneakyThrows public boolean hasAnyPermissions(String... permissions) { - // 特殊:跨租户访问 - if (skipPermissionCheck()) { - return true; - } - // 权限校验 Long userId = getLoginUserId(); if (userId == null) { @@ -85,11 +79,6 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService { @Override @SneakyThrows public boolean hasAnyRoles(String... roles) { - // 特殊:跨租户访问 - if (skipPermissionCheck()) { - return true; - } - // 权限校验 Long userId = getLoginUserId(); if (userId == null) { @@ -105,11 +94,6 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService { @Override public boolean hasAnyScopes(String... scope) { - // 特殊:跨租户访问 - if (skipPermissionCheck()) { - return true; - } - // 权限校验 LoginUser user = SecurityFrameworkUtils.getLoginUser(); if (user == null) { diff --git a/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/util/SecurityFrameworkUtils.java b/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/util/SecurityFrameworkUtils.java index edf8d57..a9f04d7 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/util/SecurityFrameworkUtils.java +++ b/msgpush-framework/msgpush-spring-boot-starter-security/src/main/java/com/njcn/msgpush/framework/security/core/util/SecurityFrameworkUtils.java @@ -142,21 +142,5 @@ public class SecurityFrameworkUtils { return authenticationToken; } - /** - * 是否条件跳过权限校验,包括数据权限、功能权限 - * - * @return 是否跳过 - */ - public static boolean skipPermissionCheck() { - LoginUser loginUser = getLoginUser(); - if (loginUser == null) { - return false; - } - if (loginUser.getVisitTenantId() == null) { - return false; - } - // 重点:跨租户访问时,无法进行权限校验 - return ObjUtil.notEqual(loginUser.getVisitTenantId(), loginUser.getTenantId()); - } } diff --git a/msgpush-framework/msgpush-spring-boot-starter-web/src/main/java/com/njcn/msgpush/framework/swagger/config/MsgpushSwaggerAutoConfiguration.java b/msgpush-framework/msgpush-spring-boot-starter-web/src/main/java/com/njcn/msgpush/framework/swagger/config/MsgpushSwaggerAutoConfiguration.java index b2b4440..84a3447 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-web/src/main/java/com/njcn/msgpush/framework/swagger/config/MsgpushSwaggerAutoConfiguration.java +++ b/msgpush-framework/msgpush-spring-boot-starter-web/src/main/java/com/njcn/msgpush/framework/swagger/config/MsgpushSwaggerAutoConfiguration.java @@ -34,7 +34,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import static com.njcn.msgpush.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; /** * Swagger 自动配置类,基于 OpenAPI + Springdoc 实现。 @@ -127,24 +126,12 @@ public class MsgpushSwaggerAutoConfiguration { .group(group) .pathsToMatch("/admin-api/" + path + "/**", "/app-api/" + path + "/**") .addOperationCustomizer((operation, handlerMethod) -> operation - .addParametersItem(buildTenantHeaderParameter()) .addParametersItem(buildSecurityHeaderParameter())) .addOperationCustomizer(buildOperationIdCustomizer()) .build(); } - /** - * 构建 Tenant 租户编号请求头参数 - * - * @return 多租户参数 - */ - private static Parameter buildTenantHeaderParameter() { - return new Parameter() - .name(HEADER_TENANT_ID) // header 名 - .description("租户编号") // 描述 - .in(String.valueOf(SecurityScheme.In.HEADER)) // 请求 header - .schema(new IntegerSchema()._default(1L).name(HEADER_TENANT_ID).description("租户编号")); // 默认:使用租户编号为 1 - } + /** * 构建 Authorization 认证请求头参数 @@ -158,7 +145,7 @@ public class MsgpushSwaggerAutoConfiguration { .name(HttpHeaders.AUTHORIZATION) // header 名 .description("认证 Token") // 描述 .in(String.valueOf(SecurityScheme.In.HEADER)) // 请求 header - .schema(new StringSchema()._default("Bearer test1").name(HEADER_TENANT_ID).description("认证 Token")); // 默认:使用用户编号为 1 + .schema(new StringSchema()._default("Bearer test1").description("认证 Token")); // 默认:使用用户编号为 1 } /** diff --git a/msgpush-framework/msgpush-spring-boot-starter-web/src/main/java/com/njcn/msgpush/framework/web/core/util/WebFrameworkUtils.java b/msgpush-framework/msgpush-spring-boot-starter-web/src/main/java/com/njcn/msgpush/framework/web/core/util/WebFrameworkUtils.java index fff3d6f..7b5fefd 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-web/src/main/java/com/njcn/msgpush/framework/web/core/util/WebFrameworkUtils.java +++ b/msgpush-framework/msgpush-spring-boot-starter-web/src/main/java/com/njcn/msgpush/framework/web/core/util/WebFrameworkUtils.java @@ -27,9 +27,6 @@ public class WebFrameworkUtils { private static final String REQUEST_ATTRIBUTE_COMMON_RESULT = "common_result"; - public static final String HEADER_TENANT_ID = "tenant-id"; - public static final String HEADER_VISIT_TENANT_ID = "visit-tenant-id"; - /** * 终端的 Header * @@ -43,29 +40,8 @@ public class WebFrameworkUtils { WebFrameworkUtils.properties = webProperties; } - /** - * 获得租户编号,从 header 中 - * 考虑到其它 framework 组件也会使用到租户编号,所以不得不放在 WebFrameworkUtils 统一提供 - * - * @param request 请求 - * @return 租户编号 - */ - public static Long getTenantId(HttpServletRequest request) { - String tenantId = request.getHeader(HEADER_TENANT_ID); - return NumberUtil.isNumber(tenantId) ? Long.valueOf(tenantId) : null; - } - /** - * 获得访问的租户编号,从 header 中 - * 考虑到其它 framework 组件也会使用到租户编号,所以不得不放在 WebFrameworkUtils 统一提供 - * - * @param request 请求 - * @return 租户编号 - */ - public static Long getVisitTenantId(HttpServletRequest request) { - String tenantId = request.getHeader(HEADER_VISIT_TENANT_ID); - return NumberUtil.isNumber(tenantId)? Long.valueOf(tenantId) : null; - } + public static void setLoginUserId(ServletRequest request, Long userId) { request.setAttribute(REQUEST_ATTRIBUTE_LOGIN_USER_ID, userId); diff --git a/msgpush-framework/msgpush-spring-boot-starter-websocket/pom.xml b/msgpush-framework/msgpush-spring-boot-starter-websocket/pom.xml index d0e1197..02046c8 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-websocket/pom.xml +++ b/msgpush-framework/msgpush-spring-boot-starter-websocket/pom.xml @@ -58,16 +58,6 @@ rocketmq-spring-boot-starter true - - - - - com.njcn - msgpush-spring-boot-starter-biz-tenant - provided - \ No newline at end of file diff --git a/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/handler/JsonWebSocketMessageHandler.java b/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/handler/JsonWebSocketMessageHandler.java index 25c2e25..ee70ebb 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/handler/JsonWebSocketMessageHandler.java +++ b/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/handler/JsonWebSocketMessageHandler.java @@ -3,7 +3,6 @@ package com.njcn.msgpush.framework.websocket.core.handler; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.TypeUtil; import com.njcn.msgpush.framework.common.util.json.JsonUtils; -import com.njcn.msgpush.framework.tenant.core.util.TenantUtils; import com.njcn.msgpush.framework.websocket.core.listener.WebSocketMessageListener; import com.njcn.msgpush.framework.websocket.core.message.JsonWebSocketMessage; import com.njcn.msgpush.framework.websocket.core.util.WebSocketFrameworkUtils; @@ -73,8 +72,7 @@ public class JsonWebSocketMessageHandler extends TextWebSocketHandler { // 2.3 处理消息 Type type = TypeUtil.getTypeArgument(messageListener.getClass(), 0); Object messageObj = JsonUtils.parseObject(jsonMessage.getContent(), type); - Long tenantId = WebSocketFrameworkUtils.getTenantId(session); - TenantUtils.execute(tenantId, () -> messageListener.onMessage(session, messageObj)); + messageListener.onMessage(session, messageObj); } catch (Throwable ex) { log.error("[handleTextMessage][session({}) message({}) 处理异常]", session.getId(), message.getPayload()); } diff --git a/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/session/WebSocketSessionManagerImpl.java b/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/session/WebSocketSessionManagerImpl.java index 0c2e3e1..ef7774f 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/session/WebSocketSessionManagerImpl.java +++ b/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/session/WebSocketSessionManagerImpl.java @@ -2,7 +2,6 @@ package com.njcn.msgpush.framework.websocket.core.session; import cn.hutool.core.collection.CollUtil; import com.njcn.msgpush.framework.security.core.LoginUser; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; import com.njcn.msgpush.framework.websocket.core.util.WebSocketFrameworkUtils; import org.springframework.web.socket.WebSocketSession; @@ -95,18 +94,10 @@ public class WebSocketSessionManagerImpl implements WebSocketSessionManager { return new ArrayList<>(); } LinkedList result = new LinkedList<>(); // 避免扩容 - Long contextTenantId = TenantContextHolder.getTenantId(); for (List sessions : userSessionsMap.values()) { if (CollUtil.isEmpty(sessions)) { continue; } - // 特殊:如果租户不匹配,则直接排除 - if (contextTenantId != null) { - Long userTenantId = WebSocketFrameworkUtils.getTenantId(sessions.get(0)); - if (!contextTenantId.equals(userTenantId)) { - continue; - } - } result.addAll(sessions); } return result; diff --git a/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/util/WebSocketFrameworkUtils.java b/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/util/WebSocketFrameworkUtils.java index b365be1..33837db 100644 --- a/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/util/WebSocketFrameworkUtils.java +++ b/msgpush-framework/msgpush-spring-boot-starter-websocket/src/main/java/com/njcn/msgpush/framework/websocket/core/util/WebSocketFrameworkUtils.java @@ -53,15 +53,5 @@ public class WebSocketFrameworkUtils { return loginUser != null ? loginUser.getUserType() : null; } - /** - * 获得当前用户的租户编号 - * - * @param session Session - * @return 租户编号 - */ - public static Long getTenantId(WebSocketSession session) { - LoginUser loginUser = getLoginUser(session); - return loginUser != null ? loginUser.getTenantId() : null; - } } diff --git a/msgpush-framework/pom.xml b/msgpush-framework/pom.xml index 5ed90a7..899a056 100644 --- a/msgpush-framework/pom.xml +++ b/msgpush-framework/pom.xml @@ -22,7 +22,6 @@ msgpush-spring-boot-starter-rpc msgpush-spring-boot-starter-excel msgpush-spring-boot-starter-test - msgpush-spring-boot-starter-biz-tenant msgpush-spring-boot-starter-biz-ip diff --git a/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/filter/security/LoginUser.java b/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/filter/security/LoginUser.java index 8d98b98..5a0a848 100644 --- a/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/filter/security/LoginUser.java +++ b/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/filter/security/LoginUser.java @@ -28,10 +28,7 @@ public class LoginUser { * 额外的用户信息 */ private Map info; - /** - * 租户编号 - */ - private Long tenantId; + /** * 授权范围 */ diff --git a/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/filter/security/TokenAuthenticationFilter.java b/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/filter/security/TokenAuthenticationFilter.java index 21a6d73..9c815a5 100644 --- a/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/filter/security/TokenAuthenticationFilter.java +++ b/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/filter/security/TokenAuthenticationFilter.java @@ -30,7 +30,7 @@ import static com.njcn.msgpush.framework.common.util.cache.CacheUtils.buildAsync /** * Token 过滤器,验证 token 的有效性 - * 1. 验证通过时,将 userId、userType、tenantId 通过 Header 转发给服务 + * 1. 验证通过时,将 userId、userType通过 Header 转发给服务 * 2. 验证不通过,还是会转发给服务。因为,接口是否需要登录的校验,还是交给服务自身处理 * * @author hongawen @@ -42,11 +42,12 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered { * CommonResult 对应的 TypeReference 结果,用于解析 checkToken 的结果 */ private static final TypeReference> CHECK_RESULT_TYPE_REFERENCE - = new TypeReference>() {}; + = new TypeReference>() { + }; /** * 空的 LoginUser 的结果 - * + *

* 用于解决如下问题: * 1. {@link #getLoginUser(ServerWebExchange, String)} 返回 Mono.empty() 时,会导致后续的 flatMap 无法进行处理的问题。 * 2. {@link #buildUser(String)} 时,如果 Token 已经过期,返回 LOGIN_USER_EMPTY 对象,避免缓存无法刷新 @@ -57,25 +58,21 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered { /** * 登录用户的本地缓存 - * - * key1:多租户的编号 + *

* key2:访问令牌 */ - private final LoadingCache, LoginUser> loginUserCache = buildAsyncReloadingCache(Duration.ofMinutes(1), - new CacheLoader, LoginUser>() { - + private final LoadingCache loginUserCache = buildAsyncReloadingCache(Duration.ofMinutes(1), + new CacheLoader() { @Override - public LoginUser load(KeyValue token) { - String body = checkAccessToken(token.getKey(), token.getValue()).block(); + public LoginUser load(String token) { + String body = checkAccessToken(token).block(); return buildUser(body); } - }); public TokenAuthenticationFilter(ReactorLoadBalancerExchangeFilterFunction lbFunction) { // Q:为什么不使用 OAuth2TokenApi 进行调用? // A1:Spring Cloud OpenFeign 官方未内置 Reactive 的支持 https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html/#reactive-support - // A2:校验 Token 的 API 需要使用到 header[tenant-id] 传递租户编号,暂时不想编写 RequestInterceptor 实现 // 因此,这里采用 WebClient,通过 lbFunction 实现负载均衡 this.webClient = WebClient.builder().filter(lbFunction).build(); } @@ -91,7 +88,7 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered { return chain.filter(exchange); } - // 情况二,如果有 Token 令牌,则解析对应 userId、userType、tenantId 等字段,并通过 通过 Header 转发给服务 + // 情况二,如果有 Token 令牌,则解析对应 userId、userType等字段,并通过 通过 Header 转发给服务 // 重要说明:defaultIfEmpty 作用,保证 Mono.empty() 情况,可以继续执行 `flatMap 的 chain.filter(exchange)` 逻辑,避免返回给前端空的 Response!! ServerWebExchange finalExchange = exchange; return getLoginUser(exchange, token).defaultIfEmpty(LOGIN_USER_EMPTY).flatMap(user -> { @@ -111,30 +108,26 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered { } private Mono getLoginUser(ServerWebExchange exchange, String token) { - // 从缓存中,获取 LoginUser - Long tenantId = WebFrameworkUtils.getTenantId(exchange); - KeyValue cacheKey = new KeyValue().setKey(tenantId).setValue(token); - LoginUser localUser = loginUserCache.getIfPresent(cacheKey); + LoginUser localUser = loginUserCache.getIfPresent(token); if (localUser != null) { return Mono.just(localUser); } // 缓存不存在,则请求远程服务 - return checkAccessToken(tenantId, token).flatMap((Function>) body -> { + return checkAccessToken(token).flatMap((Function>) body -> { LoginUser remoteUser = buildUser(body); if (remoteUser != null) { // 非空,则进行缓存 - loginUserCache.put(cacheKey, remoteUser); + loginUserCache.put(token, remoteUser); return Mono.just(remoteUser); } return Mono.empty(); }); } - private Mono checkAccessToken(Long tenantId, String token) { + private Mono checkAccessToken(String token) { return webClient.get() .uri(OAuth2TokenCommonApi.URL_CHECK, uriBuilder -> uriBuilder.queryParam("accessToken", token).build()) - .headers(httpHeaders -> WebFrameworkUtils.setTenantIdHeader(tenantId, httpHeaders)) // 设置租户的 Header .retrieve().bodyToMono(String.class); } @@ -156,7 +149,6 @@ public class TokenAuthenticationFilter implements GlobalFilter, Ordered { OAuth2AccessTokenCheckRespDTO tokenInfo = result.getData(); return new LoginUser().setId(tokenInfo.getUserId()).setUserType(tokenInfo.getUserType()) .setInfo(tokenInfo.getUserInfo()) // 额外的用户信息 - .setTenantId(tokenInfo.getTenantId()).setScopes(tokenInfo.getScopes()) .setExpiresTime(tokenInfo.getExpiresTime()); } diff --git a/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/util/WebFrameworkUtils.java b/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/util/WebFrameworkUtils.java index 6a447c7..2b9b19c 100644 --- a/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/util/WebFrameworkUtils.java +++ b/msgpush-gateway/src/main/java/com/njcn/msgpush/gateway/util/WebFrameworkUtils.java @@ -26,27 +26,9 @@ import reactor.core.publisher.Mono; @Slf4j public class WebFrameworkUtils { - private static final String HEADER_TENANT_ID = "tenant-id"; private WebFrameworkUtils() {} - /** - * 将 Gateway 请求中的 header,设置到 HttpHeaders 中 - * - * @param tenantId 租户编号 - * @param httpHeaders WebClient 的请求 - */ - public static void setTenantIdHeader(Long tenantId, HttpHeaders httpHeaders) { - if (tenantId == null) { - return; - } - httpHeaders.set(HEADER_TENANT_ID, String.valueOf(tenantId)); - } - - public static Long getTenantId(ServerWebExchange exchange) { - String tenantId = exchange.getRequest().getHeaders().getFirst(HEADER_TENANT_ID); - return NumberUtil.isNumber(tenantId) ? Long.valueOf(tenantId) : null; - } /** * 返回 JSON 字符串 diff --git a/msgpush-module-infra/msgpush-module-infra-api/src/main/java/com/njcn/msgpush/module/infra/enums/ErrorCodeConstants.java b/msgpush-module-infra/msgpush-module-infra-api/src/main/java/com/njcn/msgpush/module/infra/enums/ErrorCodeConstants.java index 9fd4786..7e25826 100644 --- a/msgpush-module-infra/msgpush-module-infra-api/src/main/java/com/njcn/msgpush/module/infra/enums/ErrorCodeConstants.java +++ b/msgpush-module-infra/msgpush-module-infra-api/src/main/java/com/njcn/msgpush/module/infra/enums/ErrorCodeConstants.java @@ -15,15 +15,6 @@ public interface ErrorCodeConstants { ErrorCode CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE = new ErrorCode(1_001_000_003, "不能删除类型为系统内置的参数配置"); ErrorCode CONFIG_GET_VALUE_ERROR_IF_VISIBLE = new ErrorCode(1_001_000_004, "获取参数配置失败,原因:不允许获取不可见配置"); - // ========== 定时任务 1-001-001-000 ========== - ErrorCode JOB_NOT_EXISTS = new ErrorCode(1_001_001_000, "定时任务不存在"); - ErrorCode JOB_HANDLER_EXISTS = new ErrorCode(1_001_001_001, "定时任务的处理器已经存在"); - ErrorCode JOB_CHANGE_STATUS_INVALID = new ErrorCode(1_001_001_002, "只允许修改为开启或者关闭状态"); - ErrorCode JOB_CHANGE_STATUS_EQUALS = new ErrorCode(1_001_001_003, "定时任务已经处于该状态,无需修改"); - ErrorCode JOB_UPDATE_ONLY_NORMAL_STATUS = new ErrorCode(1_001_001_004, "只有开启状态的任务,才可以修改"); - ErrorCode JOB_CRON_EXPRESSION_VALID = new ErrorCode(1_001_001_005, "CRON 表达式不正确"); - ErrorCode JOB_HANDLER_BEAN_NOT_EXISTS = new ErrorCode(1_001_001_006, "定时任务的处理器 Bean 不存在,注意 Bean 默认首字母小写"); - ErrorCode JOB_HANDLER_BEAN_TYPE_ERROR = new ErrorCode(1_001_001_007, "定时任务的处理器 Bean 类型不正确,未实现 JobHandler 接口"); // ========== API 错误日志 1-001-002-000 ========== ErrorCode API_ERROR_LOG_NOT_FOUND = new ErrorCode(1_001_002_000, "API 错误日志不存在"); @@ -56,17 +47,6 @@ public interface ErrorCodeConstants { ErrorCode DATA_SOURCE_CONFIG_NOT_EXISTS = new ErrorCode(1_001_007_000, "数据源配置不存在"); ErrorCode DATA_SOURCE_CONFIG_NOT_OK = new ErrorCode(1_001_007_001, "数据源配置不正确,无法进行连接"); - // ========== 学生 1-001-201-000 ========== - ErrorCode DEMO01_CONTACT_NOT_EXISTS = new ErrorCode(1_001_201_000, "示例联系人不存在"); - ErrorCode DEMO02_CATEGORY_NOT_EXISTS = new ErrorCode(1_001_201_001, "示例分类不存在"); - ErrorCode DEMO02_CATEGORY_EXITS_CHILDREN = new ErrorCode(1_001_201_002, "存在存在子示例分类,无法删除"); - ErrorCode DEMO02_CATEGORY_PARENT_NOT_EXITS = new ErrorCode(1_001_201_003,"父级示例分类不存在"); - ErrorCode DEMO02_CATEGORY_PARENT_ERROR = new ErrorCode(1_001_201_004, "不能设置自己为父示例分类"); - ErrorCode DEMO02_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_001_201_005, "已经存在该名字的示例分类"); - ErrorCode DEMO02_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_001_201_006, "不能设置自己的子示例分类为父示例分类"); - ErrorCode DEMO03_STUDENT_NOT_EXISTS = new ErrorCode(1_001_201_007, "学生不存在"); - ErrorCode DEMO03_COURSE_NOT_EXISTS = new ErrorCode(1_001_201_008, "学生课程不存在"); - ErrorCode DEMO03_GRADE_NOT_EXISTS = new ErrorCode(1_001_201_009, "学生班级不存在"); - ErrorCode DEMO03_GRADE_EXISTS = new ErrorCode(1_001_201_010, "学生班级已存在"); + } diff --git a/msgpush-module-infra/msgpush-module-infra-server/pom.xml b/msgpush-module-infra/msgpush-module-infra-server/pom.xml index 3ad7d1d..2bb7f00 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/pom.xml +++ b/msgpush-module-infra/msgpush-module-infra-server/pom.xml @@ -32,11 +32,6 @@ ${revision} - - - com.njcn - msgpush-spring-boot-starter-biz-tenant - diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/Demo01ContactController.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/Demo01ContactController.java deleted file mode 100644 index dc8723b..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/Demo01ContactController.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo01; - -import com.njcn.msgpush.framework.apilog.core.annotation.ApiAccessLog; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.common.pojo.PageParam; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.framework.excel.core.util.ExcelUtils; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo.Demo01ContactRespVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; -import com.njcn.msgpush.module.infra.service.demo.demo01.Demo01ContactService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.io.IOException; -import java.util.List; - -import static com.njcn.msgpush.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static com.njcn.msgpush.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - 示例联系人") -@RestController -@RequestMapping("/infra/demo01-contact") -@Validated -public class Demo01ContactController { - - @Resource - private Demo01ContactService demo01ContactService; - - @PostMapping("/create") - @Operation(summary = "创建示例联系人") - @PreAuthorize("@ss.hasPermission('infra:demo01-contact:create')") - public CommonResult createDemo01Contact(@Valid @RequestBody Demo01ContactSaveReqVO createReqVO) { - return success(demo01ContactService.createDemo01Contact(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新示例联系人") - @PreAuthorize("@ss.hasPermission('infra:demo01-contact:update')") - public CommonResult updateDemo01Contact(@Valid @RequestBody Demo01ContactSaveReqVO updateReqVO) { - demo01ContactService.updateDemo01Contact(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除示例联系人") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('infra:demo01-contact:delete')") - public CommonResult deleteDemo01Contact(@RequestParam("id") Long id) { - demo01ContactService.deleteDemo01Contact(id); - return success(true); - } - - @DeleteMapping("/delete-list") - @Parameter(name = "ids", description = "编号", required = true) - @Operation(summary = "批量删除示例联系人") - @PreAuthorize("@ss.hasPermission('infra:demo01-contact:delete')") - public CommonResult deleteDemo0iContactList(@RequestParam("ids") List ids) { - demo01ContactService.deleteDemo0iContactList(ids); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得示例联系人") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('infra:demo01-contact:query')") - public CommonResult getDemo01Contact(@RequestParam("id") Long id) { - Demo01ContactDO demo01Contact = demo01ContactService.getDemo01Contact(id); - return success(BeanUtils.toBean(demo01Contact, Demo01ContactRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得示例联系人分页") - @PreAuthorize("@ss.hasPermission('infra:demo01-contact:query')") - public CommonResult> getDemo01ContactPage(@Valid Demo01ContactPageReqVO pageReqVO) { - PageResult pageResult = demo01ContactService.getDemo01ContactPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, Demo01ContactRespVO.class)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出示例联系人 Excel") - @PreAuthorize("@ss.hasPermission('infra:demo01-contact:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportDemo01ContactExcel(@Valid Demo01ContactPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { - pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = demo01ContactService.getDemo01ContactPage(pageReqVO).getList(); - // 导出 Excel - ExcelUtils.write(response, "示例联系人.xls", "数据", Demo01ContactRespVO.class, - BeanUtils.toBean(list, Demo01ContactRespVO.class)); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/vo/Demo01ContactPageReqVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/vo/Demo01ContactPageReqVO.java deleted file mode 100644 index 0d96ad6..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/vo/Demo01ContactPageReqVO.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo; - -import com.njcn.msgpush.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static com.njcn.msgpush.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 示例联系人分页 Request VO") -@Data -public class Demo01ContactPageReqVO extends PageParam { - - @Schema(description = "名字", example = "张三") - private String name; - - @Schema(description = "性别", example = "1") - private Integer sex; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/vo/Demo01ContactRespVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/vo/Demo01ContactRespVO.java deleted file mode 100644 index 698777d..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/vo/Demo01ContactRespVO.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo; - -import com.njcn.msgpush.framework.excel.core.annotations.DictFormat; -import com.njcn.msgpush.framework.excel.core.convert.DictConvert; -import cn.idev.excel.annotation.ExcelIgnoreUnannotated; -import cn.idev.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 示例联系人 Response VO") -@Data -@ExcelIgnoreUnannotated -public class Demo01ContactRespVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21555") - @ExcelProperty("编号") - private Long id; - - @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") - @ExcelProperty("名字") - private String name; - - @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @ExcelProperty(value = "性别", converter = DictConvert.class) - @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private Integer sex; - - @Schema(description = "出生年", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("出生年") - private LocalDateTime birthday; - - @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "你说的对") - @ExcelProperty("简介") - private String description; - - @Schema(description = "头像") - @ExcelProperty("头像") - private String avatar; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/vo/Demo01ContactSaveReqVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/vo/Demo01ContactSaveReqVO.java deleted file mode 100644 index 1365dbb..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo01/vo/Demo01ContactSaveReqVO.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 示例联系人新增/修改 Request VO") -@Data -public class Demo01ContactSaveReqVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "21555") - private Long id; - - @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") - @NotEmpty(message = "名字不能为空") - private String name; - - @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "性别不能为空") - private Integer sex; - - @Schema(description = "出生年", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "出生年不能为空") - private LocalDateTime birthday; - - @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "你说的对") - @NotEmpty(message = "简介不能为空") - private String description; - - @Schema(description = "头像") - private String avatar; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/Demo02CategoryController.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/Demo02CategoryController.java deleted file mode 100644 index 5c4f666..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/Demo02CategoryController.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo02; - -import com.njcn.msgpush.framework.apilog.core.annotation.ApiAccessLog; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.framework.excel.core.util.ExcelUtils; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryRespVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO; -import com.njcn.msgpush.module.infra.service.demo.demo02.Demo02CategoryService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.io.IOException; -import java.util.List; - -import static com.njcn.msgpush.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static com.njcn.msgpush.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - 示例分类") -@RestController -@RequestMapping("/infra/demo02-category") -@Validated -public class Demo02CategoryController { - - @Resource - private Demo02CategoryService demo02CategoryService; - - @PostMapping("/create") - @Operation(summary = "创建示例分类") - @PreAuthorize("@ss.hasPermission('infra:demo02-category:create')") - public CommonResult createDemo02Category(@Valid @RequestBody Demo02CategorySaveReqVO createReqVO) { - return success(demo02CategoryService.createDemo02Category(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新示例分类") - @PreAuthorize("@ss.hasPermission('infra:demo02-category:update')") - public CommonResult updateDemo02Category(@Valid @RequestBody Demo02CategorySaveReqVO updateReqVO) { - demo02CategoryService.updateDemo02Category(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除示例分类") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('infra:demo02-category:delete')") - public CommonResult deleteDemo02Category(@RequestParam("id") Long id) { - demo02CategoryService.deleteDemo02Category(id); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得示例分类") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('infra:demo02-category:query')") - public CommonResult getDemo02Category(@RequestParam("id") Long id) { - Demo02CategoryDO demo02Category = demo02CategoryService.getDemo02Category(id); - return success(BeanUtils.toBean(demo02Category, Demo02CategoryRespVO.class)); - } - - @GetMapping("/list") - @Operation(summary = "获得示例分类列表") - @PreAuthorize("@ss.hasPermission('infra:demo02-category:query')") - public CommonResult> getDemo02CategoryList(@Valid Demo02CategoryListReqVO listReqVO) { - List list = demo02CategoryService.getDemo02CategoryList(listReqVO); - return success(BeanUtils.toBean(list, Demo02CategoryRespVO.class)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出示例分类 Excel") - @PreAuthorize("@ss.hasPermission('infra:demo02-category:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportDemo02CategoryExcel(@Valid Demo02CategoryListReqVO listReqVO, - HttpServletResponse response) throws IOException { - List list = demo02CategoryService.getDemo02CategoryList(listReqVO); - // 导出 Excel - ExcelUtils.write(response, "示例分类.xls", "数据", Demo02CategoryRespVO.class, - BeanUtils.toBean(list, Demo02CategoryRespVO.class)); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/vo/Demo02CategoryListReqVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/vo/Demo02CategoryListReqVO.java deleted file mode 100644 index 03abfa2..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/vo/Demo02CategoryListReqVO.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static com.njcn.msgpush.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 示例分类列表 Request VO") -@Data -public class Demo02CategoryListReqVO { - - @Schema(description = "名字", example = "芋艿") - private String name; - - @Schema(description = "父级编号", example = "6080") - private Long parentId; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/vo/Demo02CategoryRespVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/vo/Demo02CategoryRespVO.java deleted file mode 100644 index 4d4267f..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/vo/Demo02CategoryRespVO.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo; - -import cn.idev.excel.annotation.ExcelIgnoreUnannotated; -import cn.idev.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 示例分类 Response VO") -@Data -@ExcelIgnoreUnannotated -public class Demo02CategoryRespVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10304") - @ExcelProperty("编号") - private Long id; - - @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @ExcelProperty("名字") - private String name; - - @Schema(description = "父级编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "6080") - @ExcelProperty("父级编号") - private Long parentId; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/vo/Demo02CategorySaveReqVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/vo/Demo02CategorySaveReqVO.java deleted file mode 100644 index 86adecb..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo02/vo/Demo02CategorySaveReqVO.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -@Schema(description = "管理后台 - 示例分类新增/修改 Request VO") -@Data -public class Demo02CategorySaveReqVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10304") - private Long id; - - @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @NotEmpty(message = "名字不能为空") - private String name; - - @Schema(description = "父级编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "6080") - @NotNull(message = "父级编号不能为空") - private Long parentId; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/Demo03StudentErpController.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/Demo03StudentErpController.java deleted file mode 100644 index 8ba4559..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/Demo03StudentErpController.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp; - -import com.njcn.msgpush.framework.apilog.core.annotation.ApiAccessLog; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.common.pojo.PageParam; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.framework.excel.core.util.ExcelUtils; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpRespVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import com.njcn.msgpush.module.infra.service.demo.demo03.erp.Demo03StudentErpService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.io.IOException; -import java.util.List; - -import static com.njcn.msgpush.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static com.njcn.msgpush.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - 学生") -@RestController -@RequestMapping("/infra/demo03-student-erp") -@Validated -public class Demo03StudentErpController { - - @Resource - private Demo03StudentErpService demo03StudentErpService; - - @PostMapping("/create") - @Operation(summary = "创建学生") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") - public CommonResult createDemo03Student(@Valid @RequestBody Demo03StudentErpSaveReqVO createReqVO) { - return success(demo03StudentErpService.createDemo03Student(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新学生") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") - public CommonResult updateDemo03Student(@Valid @RequestBody Demo03StudentErpSaveReqVO updateReqVO) { - demo03StudentErpService.updateDemo03Student(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除学生") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") - public CommonResult deleteDemo03Student(@RequestParam("id") Long id) { - demo03StudentErpService.deleteDemo03Student(id); - return success(true); - } - - @DeleteMapping("/delete-list") - @Parameter(name = "ids", description = "编号", required = true) - @Operation(summary = "批量删除学生") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") - public CommonResult deleteDemo03StudentList(@RequestParam("ids") List ids) { - demo03StudentErpService.deleteDemo03StudentList(ids); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得学生") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult getDemo03Student(@RequestParam("id") Long id) { - Demo03StudentDO demo03Student = demo03StudentErpService.getDemo03Student(id); - return success(BeanUtils.toBean(demo03Student, Demo03StudentErpRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得学生分页") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult> getDemo03StudentPage(@Valid Demo03StudentErpPageReqVO pageReqVO) { - PageResult pageResult = demo03StudentErpService.getDemo03StudentPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, Demo03StudentErpRespVO.class)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出学生 Excel") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportDemo03StudentExcel(@Valid Demo03StudentErpPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { - pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = demo03StudentErpService.getDemo03StudentPage(pageReqVO).getList(); - // 导出 Excel - ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentErpRespVO.class, - BeanUtils.toBean(list, Demo03StudentErpRespVO.class)); - } - - // ==================== 子表(学生课程) ==================== - - @GetMapping("/demo03-course/page") - @Operation(summary = "获得学生课程分页") - @Parameter(name = "studentId", description = "学生编号") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult> getDemo03CoursePage(PageParam pageReqVO, - @RequestParam("studentId") Long studentId) { - return success(demo03StudentErpService.getDemo03CoursePage(pageReqVO, studentId)); - } - - @PostMapping("/demo03-course/create") - @Operation(summary = "创建学生课程") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") - public CommonResult createDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) { - return success(demo03StudentErpService.createDemo03Course(demo03Course)); - } - - @PutMapping("/demo03-course/update") - @Operation(summary = "更新学生课程") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") - public CommonResult updateDemo03Course(@Valid @RequestBody Demo03CourseDO demo03Course) { - demo03StudentErpService.updateDemo03Course(demo03Course); - return success(true); - } - - @DeleteMapping("/demo03-course/delete") - @Parameter(name = "id", description = "编号", required = true) - @Operation(summary = "删除学生课程") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") - public CommonResult deleteDemo03Course(@RequestParam("id") Long id) { - demo03StudentErpService.deleteDemo03Course(id); - return success(true); - } - - @DeleteMapping("/demo03-course/delete-list") - @Parameter(name = "ids", description = "编号", required = true) - @Operation(summary = "批量删除学生课程") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") - public CommonResult deleteDemo03CourseList(@RequestParam("ids") List ids) { - demo03StudentErpService.deleteDemo03CourseList(ids); - return success(true); - } - - @GetMapping("/demo03-course/get") - @Operation(summary = "获得学生课程") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult getDemo03Course(@RequestParam("id") Long id) { - return success(demo03StudentErpService.getDemo03Course(id)); - } - - // ==================== 子表(学生班级) ==================== - - @GetMapping("/demo03-grade/page") - @Operation(summary = "获得学生班级分页") - @Parameter(name = "studentId", description = "学生编号") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult> getDemo03GradePage(PageParam pageReqVO, - @RequestParam("studentId") Long studentId) { - return success(demo03StudentErpService.getDemo03GradePage(pageReqVO, studentId)); - } - - @PostMapping("/demo03-grade/create") - @Operation(summary = "创建学生班级") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") - public CommonResult createDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) { - return success(demo03StudentErpService.createDemo03Grade(demo03Grade)); - } - - @PutMapping("/demo03-grade/update") - @Operation(summary = "更新学生班级") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") - public CommonResult updateDemo03Grade(@Valid @RequestBody Demo03GradeDO demo03Grade) { - demo03StudentErpService.updateDemo03Grade(demo03Grade); - return success(true); - } - - @DeleteMapping("/demo03-grade/delete") - @Parameter(name = "id", description = "编号", required = true) - @Operation(summary = "删除学生班级") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") - public CommonResult deleteDemo03Grade(@RequestParam("id") Long id) { - demo03StudentErpService.deleteDemo03Grade(id); - return success(true); - } - - @DeleteMapping("/demo03-grade/delete-list") - @Parameter(name = "ids", description = "编号", required = true) - @Operation(summary = "批量删除学生班级") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") - public CommonResult deleteDemo03GradeList(@RequestParam("ids") List ids) { - demo03StudentErpService.deleteDemo03GradeList(ids); - return success(true); - } - - @GetMapping("/demo03-grade/get") - @Operation(summary = "获得学生班级") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult getDemo03Grade(@RequestParam("id") Long id) { - return success(demo03StudentErpService.getDemo03Grade(id)); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpPageReqVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpPageReqVO.java deleted file mode 100644 index f06ef4b..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpPageReqVO.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo; - -import com.njcn.msgpush.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static com.njcn.msgpush.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 学生分页 Request VO") -@Data -public class Demo03StudentErpPageReqVO extends PageParam { - - @Schema(description = "名字", example = "芋艿") - private String name; - - @Schema(description = "性别") - private Integer sex; - - @Schema(description = "简介", example = "随便") - private String description; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpRespVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpRespVO.java deleted file mode 100644 index cc0faf5..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpRespVO.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo; - -import com.njcn.msgpush.framework.excel.core.annotations.DictFormat; -import com.njcn.msgpush.framework.excel.core.convert.DictConvert; -import cn.idev.excel.annotation.ExcelIgnoreUnannotated; -import cn.idev.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 学生 Response VO") -@Data -@ExcelIgnoreUnannotated -public class Demo03StudentErpRespVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") - @ExcelProperty("编号") - private Long id; - - @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @ExcelProperty("名字") - private String name; - - @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty(value = "性别", converter = DictConvert.class) - @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private Integer sex; - - @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("出生日期") - private LocalDateTime birthday; - - @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") - @ExcelProperty("简介") - private String description; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpSaveReqVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpSaveReqVO.java deleted file mode 100644 index 750e934..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/erp/vo/Demo03StudentErpSaveReqVO.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 学生新增/修改 Request VO") -@Data -public class Demo03StudentErpSaveReqVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") - private Long id; - - @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @NotEmpty(message = "名字不能为空") - private String name; - - @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "性别不能为空") - private Integer sex; - - @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "出生日期不能为空") - private LocalDateTime birthday; - - @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") - @NotEmpty(message = "简介不能为空") - private String description; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/Demo03StudentInnerController.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/Demo03StudentInnerController.java deleted file mode 100644 index 7322b80..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/Demo03StudentInnerController.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner; - -import com.njcn.msgpush.framework.apilog.core.annotation.ApiAccessLog; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.common.pojo.PageParam; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.framework.excel.core.util.ExcelUtils; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerRespVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import com.njcn.msgpush.module.infra.service.demo.demo03.inner.Demo03StudentInnerService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.io.IOException; -import java.util.List; - -import static com.njcn.msgpush.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static com.njcn.msgpush.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - 学生") -@RestController -@RequestMapping("/infra/demo03-student-inner") -@Validated -public class Demo03StudentInnerController { - - @Resource - private Demo03StudentInnerService demo03StudentInnerService; - - @PostMapping("/create") - @Operation(summary = "创建学生") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") - public CommonResult createDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO createReqVO) { - return success(demo03StudentInnerService.createDemo03Student(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新学生") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") - public CommonResult updateDemo03Student(@Valid @RequestBody Demo03StudentInnerSaveReqVO updateReqVO) { - demo03StudentInnerService.updateDemo03Student(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除学生") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") - public CommonResult deleteDemo03Student(@RequestParam("id") Long id) { - demo03StudentInnerService.deleteDemo03Student(id); - return success(true); - } - - @DeleteMapping("/delete-list") - @Parameter(name = "ids", description = "编号", required = true) - @Operation(summary = "批量删除学生") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") - public CommonResult deleteDemo03StudentList(@RequestParam("ids") List ids) { - demo03StudentInnerService.deleteDemo03StudentList(ids); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得学生") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult getDemo03Student(@RequestParam("id") Long id) { - Demo03StudentDO demo03Student = demo03StudentInnerService.getDemo03Student(id); - return success(BeanUtils.toBean(demo03Student, Demo03StudentInnerRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得学生分页") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult> getDemo03StudentPage(@Valid Demo03StudentInnerPageReqVO pageReqVO) { - PageResult pageResult = demo03StudentInnerService.getDemo03StudentPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, Demo03StudentInnerRespVO.class)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出学生 Excel") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportDemo03StudentExcel(@Valid Demo03StudentInnerPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { - pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = demo03StudentInnerService.getDemo03StudentPage(pageReqVO).getList(); - // 导出 Excel - ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentInnerRespVO.class, - BeanUtils.toBean(list, Demo03StudentInnerRespVO.class)); - } - - // ==================== 子表(学生课程) ==================== - - @GetMapping("/demo03-course/list-by-student-id") - @Operation(summary = "获得学生课程列表") - @Parameter(name = "studentId", description = "学生编号") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) { - return success(demo03StudentInnerService.getDemo03CourseListByStudentId(studentId)); - } - - // ==================== 子表(学生班级) ==================== - - @GetMapping("/demo03-grade/get-by-student-id") - @Operation(summary = "获得学生班级") - @Parameter(name = "studentId", description = "学生编号") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) { - return success(demo03StudentInnerService.getDemo03GradeByStudentId(studentId)); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerPageReqVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerPageReqVO.java deleted file mode 100644 index 6976042..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerPageReqVO.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo; - -import com.njcn.msgpush.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static com.njcn.msgpush.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 学生分页 Request VO") -@Data -public class Demo03StudentInnerPageReqVO extends PageParam { - - @Schema(description = "名字", example = "芋艿") - private String name; - - @Schema(description = "性别") - private Integer sex; - - @Schema(description = "简介", example = "随便") - private String description; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerRespVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerRespVO.java deleted file mode 100644 index 4de8b9d..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerRespVO.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo; - -import com.njcn.msgpush.framework.excel.core.annotations.DictFormat; -import com.njcn.msgpush.framework.excel.core.convert.DictConvert; -import cn.idev.excel.annotation.ExcelIgnoreUnannotated; -import cn.idev.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 学生 Response VO") -@Data -@ExcelIgnoreUnannotated -public class Demo03StudentInnerRespVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") - @ExcelProperty("编号") - private Long id; - - @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @ExcelProperty("名字") - private String name; - - @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty(value = "性别", converter = DictConvert.class) - @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private Integer sex; - - @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("出生日期") - private LocalDateTime birthday; - - @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") - @ExcelProperty("简介") - private String description; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerSaveReqVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerSaveReqVO.java deleted file mode 100644 index 2444082..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/inner/vo/Demo03StudentInnerSaveReqVO.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo; - -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.List; - -@Schema(description = "管理后台 - 学生新增/修改 Request VO") -@Data -public class Demo03StudentInnerSaveReqVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") - private Long id; - - @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @NotEmpty(message = "名字不能为空") - private String name; - - @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "性别不能为空") - private Integer sex; - - @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "出生日期不能为空") - private LocalDateTime birthday; - - @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") - @NotEmpty(message = "简介不能为空") - private String description; - - @Schema(description = "学生课程列表") - private List demo03Courses; - - @Schema(description = "学生班级") - private Demo03GradeDO demo03Grade; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/Demo03StudentNormalController.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/Demo03StudentNormalController.java deleted file mode 100644 index 59858c1..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/Demo03StudentNormalController.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal; - -import com.njcn.msgpush.framework.apilog.core.annotation.ApiAccessLog; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.common.pojo.PageParam; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.framework.excel.core.util.ExcelUtils; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalRespVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import com.njcn.msgpush.module.infra.service.demo.demo03.normal.Demo03StudentNormalService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.io.IOException; -import java.util.List; - -import static com.njcn.msgpush.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static com.njcn.msgpush.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - 学生") -@RestController -@RequestMapping("/infra/demo03-student-normal") -@Validated -public class Demo03StudentNormalController { - - @Resource - private Demo03StudentNormalService demo03StudentNormalService; - - @PostMapping("/create") - @Operation(summary = "创建学生") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:create')") - public CommonResult createDemo03Student(@Valid @RequestBody Demo03StudentNormalSaveReqVO createReqVO) { - return success(demo03StudentNormalService.createDemo03Student(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新学生") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:update')") - public CommonResult updateDemo03Student(@Valid @RequestBody Demo03StudentNormalSaveReqVO updateReqVO) { - demo03StudentNormalService.updateDemo03Student(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除学生") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") - public CommonResult deleteDemo03Student(@RequestParam("id") Long id) { - demo03StudentNormalService.deleteDemo03Student(id); - return success(true); - } - - @DeleteMapping("/delete-list") - @Parameter(name = "ids", description = "编号", required = true) - @Operation(summary = "批量删除学生") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:delete')") - public CommonResult deleteDemo03StudentList(@RequestParam("ids") List ids) { - demo03StudentNormalService.deleteDemo03StudentList(ids); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得学生") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult getDemo03Student(@RequestParam("id") Long id) { - Demo03StudentDO demo03Student = demo03StudentNormalService.getDemo03Student(id); - return success(BeanUtils.toBean(demo03Student, Demo03StudentNormalRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得学生分页") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult> getDemo03StudentPage(@Valid Demo03StudentNormalPageReqVO pageReqVO) { - PageResult pageResult = demo03StudentNormalService.getDemo03StudentPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, Demo03StudentNormalRespVO.class)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出学生 Excel") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportDemo03StudentExcel(@Valid Demo03StudentNormalPageReqVO pageReqVO, - HttpServletResponse response) throws IOException { - pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = demo03StudentNormalService.getDemo03StudentPage(pageReqVO).getList(); - // 导出 Excel - ExcelUtils.write(response, "学生.xls", "数据", Demo03StudentNormalRespVO.class, - BeanUtils.toBean(list, Demo03StudentNormalRespVO.class)); - } - - // ==================== 子表(学生课程) ==================== - - @GetMapping("/demo03-course/list-by-student-id") - @Operation(summary = "获得学生课程列表") - @Parameter(name = "studentId", description = "学生编号") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult> getDemo03CourseListByStudentId(@RequestParam("studentId") Long studentId) { - return success(demo03StudentNormalService.getDemo03CourseListByStudentId(studentId)); - } - - // ==================== 子表(学生班级) ==================== - - @GetMapping("/demo03-grade/get-by-student-id") - @Operation(summary = "获得学生班级") - @Parameter(name = "studentId", description = "学生编号") - @PreAuthorize("@ss.hasPermission('infra:demo03-student:query')") - public CommonResult getDemo03GradeByStudentId(@RequestParam("studentId") Long studentId) { - return success(demo03StudentNormalService.getDemo03GradeByStudentId(studentId)); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalPageReqVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalPageReqVO.java deleted file mode 100644 index 413c277..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalPageReqVO.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo; - -import com.njcn.msgpush.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static com.njcn.msgpush.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 学生分页 Request VO") -@Data -public class Demo03StudentNormalPageReqVO extends PageParam { - - @Schema(description = "名字", example = "芋艿") - private String name; - - @Schema(description = "性别") - private Integer sex; - - @Schema(description = "简介", example = "随便") - private String description; - - @Schema(description = "创建时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private LocalDateTime[] createTime; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalRespVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalRespVO.java deleted file mode 100644 index 90bbd5d..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalRespVO.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo; - -import com.njcn.msgpush.framework.excel.core.annotations.DictFormat; -import com.njcn.msgpush.framework.excel.core.convert.DictConvert; -import cn.idev.excel.annotation.ExcelIgnoreUnannotated; -import cn.idev.excel.annotation.ExcelProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; - -@Schema(description = "管理后台 - 学生 Response VO") -@Data -@ExcelIgnoreUnannotated -public class Demo03StudentNormalRespVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") - @ExcelProperty("编号") - private Long id; - - @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @ExcelProperty("名字") - private String name; - - @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty(value = "性别", converter = DictConvert.class) - @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 - private Integer sex; - - @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("出生日期") - private LocalDateTime birthday; - - @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") - @ExcelProperty("简介") - private String description; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalSaveReqVO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalSaveReqVO.java deleted file mode 100644 index 90d7179..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/demo03/normal/vo/Demo03StudentNormalSaveReqVO.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo; - -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.List; - -@Schema(description = "管理后台 - 学生新增/修改 Request VO") -@Data -public class Demo03StudentNormalSaveReqVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8525") - private Long id; - - @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @NotEmpty(message = "名字不能为空") - private String name; - - @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "性别不能为空") - private Integer sex; - - @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "出生日期不能为空") - private LocalDateTime birthday; - - @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "随便") - @NotEmpty(message = "简介不能为空") - private String description; - - @Schema(description = "学生课程列表") - private List demo03Courses; - - @Schema(description = "学生班级") - private Demo03GradeDO demo03Grade; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/package-info.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/package-info.java deleted file mode 100644 index 26f51e4..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/demo/package-info.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * 代码生成示例 - * - * 1. demo01:单表(增删改查) - * 2. demo02:单表(树形结构) - * 3. demo03:主子表(标准模式)+ 主子表(ERP 模式)+ 主子表(内嵌模式) - */ -package com.njcn.msgpush.module.infra.controller.admin.demo; \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/file/FileConfigController.http b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/file/FileConfigController.http deleted file mode 100644 index 04c570a..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/file/FileConfigController.http +++ /dev/null @@ -1,45 +0,0 @@ -### 请求 /infra/file-config/create 接口 => 成功 -POST {{baseUrl}}/infra/file-config/create -Content-Type: application/json -tenant-id: {{adminTenantId}} -Authorization: Bearer {{token}} - -{ - "name": "S3 - 七牛云", - "remark": "", - "storage": 20, - "config": { - "accessKey": "b7yvuhBSAGjmtPhMFcn9iMOxUOY_I06cA_p0ZUx8", - "accessSecret": "kXM1l5ia1RvSX3QaOEcwI3RLz3Y2rmNszWonKZtP", - "bucket": "ruoyi-vue-pro", - "endpoint": "s3-cn-south-1.qiniucs.com", - "domain": "http://test.msgpush.iocoder.cn", - "region": "oss-cn-beijing" - } -} - -### 请求 /infra/file-config/update 接口 => 成功 -PUT {{baseUrl}}/infra/file-config/update -Content-Type: application/json -tenant-id: {{adminTenantId}} -Authorization: Bearer {{token}} - -{ - "id": 2, - "name": "S3 - 七牛云", - "remark": "", - "config": { - "accessKey": "b7yvuhBSAGjmtPhMFcn9iMOxUOY_I06cA_p0ZUx8", - "accessSecret": "kXM1l5ia1RvSX3QaOEcwI3RLz3Y2rmNszWonKZtP", - "bucket": "ruoyi-vue-pro", - "endpoint": "s3-cn-south-1.qiniucs.com", - "domain": "http://test.msgpush.iocoder.cn", - "region": "oss-cn-beijing" - } -} - -### 请求 /infra/file-config/test 接口 => 成功 -GET {{baseUrl}}/infra/file-config/test?id=2 -Content-Type: application/json -tenant-id: {{adminTenantId}} -Authorization: Bearer {{token}} diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/file/FileController.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/file/FileController.java index af1a5cb..0650d36 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/file/FileController.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/file/FileController.java @@ -6,7 +6,7 @@ import cn.hutool.core.util.URLUtil; import com.njcn.msgpush.framework.common.pojo.CommonResult; import com.njcn.msgpush.framework.common.pojo.PageResult; import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.infra.controller.admin.file.vo.file.*; import com.njcn.msgpush.module.infra.dal.dataobject.file.FileDO; import com.njcn.msgpush.module.infra.service.file.FileService; @@ -100,7 +100,6 @@ public class FileController { @GetMapping("/{configId}/get/**") @PermitAll - @TenantIgnore @Operation(summary = "下载文件") @Parameter(name = "configId", description = "配置编号", required = true) public void getFileContent(HttpServletRequest request, diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/redis/RedisController.http b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/redis/RedisController.http deleted file mode 100644 index 68b5487..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/controller/admin/redis/RedisController.http +++ /dev/null @@ -1,4 +0,0 @@ -### 请求 /infra/redis/get-monitor-info 接口 => 成功 -GET {{baseUrl}}/infra/redis/get-monitor-info -Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/codegen/CodegenColumnDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/codegen/CodegenColumnDO.java index c75b832..ae33931 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/codegen/CodegenColumnDO.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/codegen/CodegenColumnDO.java @@ -1,7 +1,7 @@ package com.njcn.msgpush.module.infra.dal.dataobject.codegen; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.infra.enums.codegen.CodegenColumnHtmlTypeEnum; import com.njcn.msgpush.module.infra.enums.codegen.CodegenColumnListConditionEnum; import com.baomidou.mybatisplus.annotation.KeySequence; @@ -18,7 +18,6 @@ import lombok.Data; @TableName(value = "infra_codegen_column", autoResultMap = true) @KeySequence("infra_codegen_column_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data -@TenantIgnore public class CodegenColumnDO extends BaseDO { /** diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/codegen/CodegenTableDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/codegen/CodegenTableDO.java index 8c4bffa..81babfc 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/codegen/CodegenTableDO.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/codegen/CodegenTableDO.java @@ -1,7 +1,7 @@ package com.njcn.msgpush.module.infra.dal.dataobject.codegen; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.infra.dal.dataobject.db.DataSourceConfigDO; import com.njcn.msgpush.module.infra.enums.codegen.CodegenFrontTypeEnum; import com.njcn.msgpush.module.infra.enums.codegen.CodegenSceneEnum; @@ -20,7 +20,6 @@ import lombok.Data; @TableName(value = "infra_codegen_table", autoResultMap = true) @KeySequence("infra_codegen_table_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data -@TenantIgnore public class CodegenTableDO extends BaseDO { /** diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/config/ConfigDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/config/ConfigDO.java index 08cc4d4..1ecf1e9 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/config/ConfigDO.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/config/ConfigDO.java @@ -1,7 +1,7 @@ package com.njcn.msgpush.module.infra.dal.dataobject.config; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.infra.enums.config.ConfigTypeEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; @@ -20,7 +20,6 @@ import lombok.ToString; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -@TenantIgnore public class ConfigDO extends BaseDO { /** diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/db/DataSourceConfigDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/db/DataSourceConfigDO.java index 894b3ee..68b74c2 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/db/DataSourceConfigDO.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/db/DataSourceConfigDO.java @@ -2,7 +2,7 @@ package com.njcn.msgpush.module.infra.dal.dataobject.db; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; import com.njcn.msgpush.framework.mybatis.core.type.EncryptTypeHandler; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; @@ -16,7 +16,6 @@ import lombok.Data; @TableName(value = "infra_data_source_config", autoResultMap = true) @KeySequence("infra_data_source_config_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data -@TenantIgnore public class DataSourceConfigDO extends BaseDO { /** diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo01/Demo01ContactDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo01/Demo01ContactDO.java deleted file mode 100644 index 61899da..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo01/Demo01ContactDO.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.dataobject.demo.demo01; - -import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -import java.time.LocalDateTime; - -/** - * 示例联系人 DO - * - * @author hongawen - */ -@TableName("msgpush_demo01_contact") -@KeySequence("msgpush_demo01_contact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class Demo01ContactDO extends BaseDO { - - /** - * 编号 - */ - @TableId - private Long id; - /** - * 名字 - */ - private String name; - /** - * 性别 - * - * 枚举 {@link TODO system_user_sex 对应的类} - */ - private Integer sex; - /** - * 出生年 - */ - private LocalDateTime birthday; - /** - * 简介 - */ - private String description; - /** - * 头像 - */ - private String avatar; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo02/Demo02CategoryDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo02/Demo02CategoryDO.java deleted file mode 100644 index 22a797a..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo02/Demo02CategoryDO.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.dataobject.demo.demo02; - -import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -/** - * 示例分类 DO - * - * @author hongawen - */ -@TableName("msgpush_demo02_category") -@KeySequence("msgpush_demo02_category_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class Demo02CategoryDO extends BaseDO { - - public static final Long PARENT_ID_ROOT = 0L; - - /** - * 编号 - */ - @TableId - private Long id; - /** - * 名字 - */ - private String name; - /** - * 父级编号 - */ - private Long parentId; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo03/Demo03CourseDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo03/Demo03CourseDO.java deleted file mode 100644 index eb47aaf..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo03/Demo03CourseDO.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03; - -import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -/** - * 学生课程 DO - * - * @author hongawen - */ -@TableName("msgpush_demo03_course") -@KeySequence("msgpush_demo03_course_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class Demo03CourseDO extends BaseDO { - - /** - * 编号 - */ - @TableId - private Long id; - /** - * 学生编号 - */ - private Long studentId; - /** - * 名字 - */ - private String name; - /** - * 分数 - */ - private Integer score; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo03/Demo03GradeDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo03/Demo03GradeDO.java deleted file mode 100644 index b801874..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo03/Demo03GradeDO.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03; - -import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -/** - * 学生班级 DO - * - * @author hongawen - */ -@TableName("msgpush_demo03_grade") -@KeySequence("msgpush_demo03_grade_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class Demo03GradeDO extends BaseDO { - - /** - * 编号 - */ - @TableId - private Long id; - /** - * 学生编号 - */ - private Long studentId; - /** - * 名字 - */ - private String name; - /** - * 班主任 - */ - private String teacher; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo03/Demo03StudentDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo03/Demo03StudentDO.java deleted file mode 100644 index 13f04c1..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/demo/demo03/Demo03StudentDO.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03; - -import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -import java.time.LocalDateTime; - -/** - * 学生 DO - * - * @author hongawen - */ -@TableName("msgpush_demo03_student") -@KeySequence("msgpush_demo03_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class Demo03StudentDO extends BaseDO { - - /** - * 编号 - */ - @TableId - private Long id; - /** - * 名字 - */ - private String name; - /** - * 性别 - * - * 枚举 {@link TODO system_user_sex 对应的类} - */ - private Integer sex; - /** - * 出生日期 - */ - private LocalDateTime birthday; - /** - * 简介 - */ - private String description; - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileConfigDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileConfigDO.java index a0631f7..3645982 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileConfigDO.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileConfigDO.java @@ -3,7 +3,7 @@ package com.njcn.msgpush.module.infra.dal.dataobject.file; import cn.hutool.core.util.StrUtil; import com.njcn.msgpush.framework.common.util.json.JsonUtils; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.infra.framework.file.core.client.FileClientConfig; import com.njcn.msgpush.module.infra.framework.file.core.client.db.DBFileClientConfig; import com.njcn.msgpush.module.infra.framework.file.core.client.ftp.FtpFileClientConfig; @@ -33,7 +33,6 @@ import java.lang.reflect.Field; @Builder @NoArgsConstructor @AllArgsConstructor -@TenantIgnore public class FileConfigDO extends BaseDO { /** diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileContentDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileContentDO.java index 61d048a..553e85e 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileContentDO.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileContentDO.java @@ -1,7 +1,7 @@ package com.njcn.msgpush.module.infra.dal.dataobject.file; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.infra.framework.file.core.client.db.DBFileClient; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; @@ -23,7 +23,6 @@ import lombok.*; @Builder @NoArgsConstructor @AllArgsConstructor -@TenantIgnore public class FileContentDO extends BaseDO { /** diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileDO.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileDO.java index 2c77195..2006d27 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileDO.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/dataobject/file/FileDO.java @@ -1,7 +1,7 @@ package com.njcn.msgpush.module.infra.dal.dataobject.file; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; @@ -20,7 +20,6 @@ import lombok.*; @Builder @NoArgsConstructor @AllArgsConstructor -@TenantIgnore public class FileDO extends BaseDO { /** diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo01/Demo01ContactMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo01/Demo01ContactMapper.java deleted file mode 100644 index 4aae675..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo01/Demo01ContactMapper.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo01; - -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; -import org.apache.ibatis.annotations.Mapper; - -/** - * 示例联系人 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo01ContactMapper extends BaseMapperX { - - default PageResult selectPage(Demo01ContactPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(Demo01ContactDO::getName, reqVO.getName()) - .eqIfPresent(Demo01ContactDO::getSex, reqVO.getSex()) - .betweenIfPresent(Demo01ContactDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(Demo01ContactDO::getId)); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo02/Demo02CategoryMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo02/Demo02CategoryMapper.java deleted file mode 100644 index 488daf2..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo02/Demo02CategoryMapper.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo02; - -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * 示例分类 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo02CategoryMapper extends BaseMapperX { - - default List selectList(Demo02CategoryListReqVO reqVO) { - return selectList(new LambdaQueryWrapperX() - .likeIfPresent(Demo02CategoryDO::getName, reqVO.getName()) - .eqIfPresent(Demo02CategoryDO::getParentId, reqVO.getParentId()) - .betweenIfPresent(Demo02CategoryDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(Demo02CategoryDO::getId)); - } - - default Demo02CategoryDO selectByParentIdAndName(Long parentId, String name) { - return selectOne(Demo02CategoryDO::getParentId, parentId, Demo02CategoryDO::getName, name); - } - - default Long selectCountByParentId(Long parentId) { - return selectCount(Demo02CategoryDO::getParentId, parentId); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseErpMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseErpMapper.java deleted file mode 100644 index 3bca22b..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/erp/Demo03CourseErpMapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.erp; - -import com.njcn.msgpush.framework.common.pojo.PageParam; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * 学生课程 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo03CourseErpMapper extends BaseMapperX { - - default PageResult selectPage(PageParam reqVO, Long studentId) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eq(Demo03CourseDO::getStudentId, studentId) - .orderByDesc(Demo03CourseDO::getId)); - } - - default int deleteByStudentId(Long studentId) { - return delete(Demo03CourseDO::getStudentId, studentId); - } - - default int deleteByStudentIds(List studentIds) { - return deleteBatch(Demo03CourseDO::getStudentId, studentIds); - } - -} diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeErpMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeErpMapper.java deleted file mode 100644 index 0160d35..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/erp/Demo03GradeErpMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.erp; - -import com.njcn.msgpush.framework.common.pojo.PageParam; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * 学生班级 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo03GradeErpMapper extends BaseMapperX { - - default PageResult selectPage(PageParam reqVO, Long studentId) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eq(Demo03GradeDO::getStudentId, studentId) - .orderByDesc(Demo03GradeDO::getId)); - } - - default Demo03GradeDO selectByStudentId(Long studentId) { - return selectOne(Demo03GradeDO::getStudentId, studentId); - } - - default int deleteByStudentId(Long studentId) { - return delete(Demo03GradeDO::getStudentId, studentId); - } - - default int deleteByStudentIds(List studentIds) { - return deleteBatch(Demo03GradeDO::getStudentId, studentIds); - } - -} diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentErpMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentErpMapper.java deleted file mode 100644 index 0790a7d..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/erp/Demo03StudentErpMapper.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.erp; - -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import org.apache.ibatis.annotations.Mapper; - -/** - * 学生 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo03StudentErpMapper extends BaseMapperX { - - default PageResult selectPage(Demo03StudentErpPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) - .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) - .eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription()) - .betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(Demo03StudentDO::getId)); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/inner/Demo03CourseInnerMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/inner/Demo03CourseInnerMapper.java deleted file mode 100644 index d3cd4fe..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/inner/Demo03CourseInnerMapper.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.inner; - -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * 学生课程 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo03CourseInnerMapper extends BaseMapperX { - - default List selectListByStudentId(Long studentId) { - return selectList(Demo03CourseDO::getStudentId, studentId); - } - - default int deleteByStudentId(Long studentId) { - return delete(Demo03CourseDO::getStudentId, studentId); - } - - default int deleteByStudentIds(List studentIds) { - return deleteBatch(Demo03CourseDO::getStudentId, studentIds); - } - -} diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/inner/Demo03GradeInnerMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/inner/Demo03GradeInnerMapper.java deleted file mode 100644 index a6ae02b..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/inner/Demo03GradeInnerMapper.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.inner; - -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * 学生班级 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo03GradeInnerMapper extends BaseMapperX { - - default Demo03GradeDO selectByStudentId(Long studentId) { - return selectOne(Demo03GradeDO::getStudentId, studentId); - } - - default int deleteByStudentId(Long studentId) { - return delete(Demo03GradeDO::getStudentId, studentId); - } - - default int deleteByStudentIds(List studentIds) { - return deleteBatch(Demo03GradeDO::getStudentId, studentIds); - } - -} diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/inner/Demo03StudentInnerMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/inner/Demo03StudentInnerMapper.java deleted file mode 100644 index f3090e2..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/inner/Demo03StudentInnerMapper.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.inner; - -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import org.apache.ibatis.annotations.Mapper; - -/** - * 学生 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo03StudentInnerMapper extends BaseMapperX { - - default PageResult selectPage(Demo03StudentInnerPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) - .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) - .eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription()) - .betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(Demo03StudentDO::getId)); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/normal/Demo03CourseNormalMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/normal/Demo03CourseNormalMapper.java deleted file mode 100644 index eeeb95d..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/normal/Demo03CourseNormalMapper.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.normal; - -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * 学生课程 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo03CourseNormalMapper extends BaseMapperX { - - default List selectListByStudentId(Long studentId) { - return selectList(Demo03CourseDO::getStudentId, studentId); - } - - default int deleteByStudentId(Long studentId) { - return delete(Demo03CourseDO::getStudentId, studentId); - } - - default int deleteByStudentIds(List studentIds) { - return deleteBatch(Demo03CourseDO::getStudentId, studentIds); - } - -} diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/normal/Demo03GradeNormalMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/normal/Demo03GradeNormalMapper.java deleted file mode 100644 index 850e314..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/normal/Demo03GradeNormalMapper.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.normal; - -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -/** - * 学生班级 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo03GradeNormalMapper extends BaseMapperX { - - default Demo03GradeDO selectByStudentId(Long studentId) { - return selectOne(Demo03GradeDO::getStudentId, studentId); - } - - default int deleteByStudentId(Long studentId) { - return delete(Demo03GradeDO::getStudentId, studentId); - } - - default int deleteByStudentIds(List studentIds) { - return deleteBatch(Demo03GradeDO::getStudentId, studentIds); - } - -} diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/normal/Demo03StudentNormalMapper.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/normal/Demo03StudentNormalMapper.java deleted file mode 100644 index dfa260e..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/dal/mysql/demo/demo03/normal/Demo03StudentNormalMapper.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.normal; - -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import org.apache.ibatis.annotations.Mapper; - -/** - * 学生 Mapper - * - * @author hongawen - */ -@Mapper -public interface Demo03StudentNormalMapper extends BaseMapperX { - - default PageResult selectPage(Demo03StudentNormalPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(Demo03StudentDO::getName, reqVO.getName()) - .eqIfPresent(Demo03StudentDO::getSex, reqVO.getSex()) - .eqIfPresent(Demo03StudentDO::getDescription, reqVO.getDescription()) - .betweenIfPresent(Demo03StudentDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(Demo03StudentDO::getId)); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/codegen/inner/CodegenBuilder.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/codegen/inner/CodegenBuilder.java index 1adc13f..9f655b7 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/codegen/inner/CodegenBuilder.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/codegen/inner/CodegenBuilder.java @@ -59,10 +59,7 @@ public class CodegenBuilder { .put("date", CodegenColumnHtmlTypeEnum.DATETIME) .build(); - /** - * 多租户编号的字段名 - */ - public static final String TENANT_ID_FIELD = "tenantId"; + /** * {@link com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO} 的字段 */ @@ -86,7 +83,6 @@ public class CodegenBuilder { static { Arrays.stream(ReflectUtil.getFields(BaseDO.class)).forEach(field -> BASE_DO_FIELDS.add(field.getName())); - BASE_DO_FIELDS.add(TENANT_ID_FIELD); // 处理 OPERATION 相关的字段 CREATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); UPDATE_OPERATION_EXCLUDE_COLUMN.addAll(BASE_DO_FIELDS); diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo01/Demo01ContactService.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo01/Demo01ContactService.java deleted file mode 100644 index 5a3d5d1..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo01/Demo01ContactService.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.njcn.msgpush.module.infra.service.demo.demo01; - -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; -import jakarta.validation.Valid; - -import java.util.List; - -/** - * 示例联系人 Service 接口 - * - * @author hongawen - */ -public interface Demo01ContactService { - - /** - * 创建示例联系人 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createDemo01Contact(@Valid Demo01ContactSaveReqVO createReqVO); - - /** - * 更新示例联系人 - * - * @param updateReqVO 更新信息 - */ - void updateDemo01Contact(@Valid Demo01ContactSaveReqVO updateReqVO); - - /** - * 删除示例联系人 - * - * @param id 编号 - */ - void deleteDemo01Contact(Long id); - - /** - * 批量删除示例联系人 - * - * @param ids 编号 - */ - void deleteDemo0iContactList(List ids); - - /** - * 获得示例联系人 - * - * @param id 编号 - * @return 示例联系人 - */ - Demo01ContactDO getDemo01Contact(Long id); - - /** - * 获得示例联系人分页 - * - * @param pageReqVO 分页查询 - * @return 示例联系人分页 - */ - PageResult getDemo01ContactPage(Demo01ContactPageReqVO pageReqVO); - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo01/Demo01ContactServiceImpl.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo01/Demo01ContactServiceImpl.java deleted file mode 100644 index aa36882..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo01/Demo01ContactServiceImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.njcn.msgpush.module.infra.service.demo.demo01; - -import cn.hutool.core.collection.CollUtil; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo.Demo01ContactPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo01.vo.Demo01ContactSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo01.Demo01ContactDO; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo01.Demo01ContactMapper; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.util.List; - -import static com.njcn.msgpush.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.njcn.msgpush.module.infra.enums.ErrorCodeConstants.DEMO01_CONTACT_NOT_EXISTS; - -/** - * 示例联系人 Service 实现类 - * - * @author hongawen - */ -@Service -@Validated -public class Demo01ContactServiceImpl implements Demo01ContactService { - - @Resource - private Demo01ContactMapper demo01ContactMapper; - - @Override - public Long createDemo01Contact(Demo01ContactSaveReqVO createReqVO) { - // 插入 - Demo01ContactDO demo01Contact = BeanUtils.toBean(createReqVO, Demo01ContactDO.class); - demo01ContactMapper.insert(demo01Contact); - // 返回 - return demo01Contact.getId(); - } - - @Override - public void updateDemo01Contact(Demo01ContactSaveReqVO updateReqVO) { - // 校验存在 - validateDemo01ContactExists(updateReqVO.getId()); - // 更新 - Demo01ContactDO updateObj = BeanUtils.toBean(updateReqVO, Demo01ContactDO.class); - demo01ContactMapper.updateById(updateObj); - } - - @Override - public void deleteDemo01Contact(Long id) { - // 校验存在 - validateDemo01ContactExists(id); - // 删除 - demo01ContactMapper.deleteById(id); - } - - @Override - public void deleteDemo0iContactList(List ids) { - // 校验存在 - validateDemo01ContactExists(ids); - // 删除 - demo01ContactMapper.deleteByIds(ids); - } - - private void validateDemo01ContactExists(List ids) { - List list = demo01ContactMapper.selectByIds(ids); - if (CollUtil.isEmpty(list) || list.size() != ids.size()) { - throw exception(DEMO01_CONTACT_NOT_EXISTS); - } - } - - private void validateDemo01ContactExists(Long id) { - if (demo01ContactMapper.selectById(id) == null) { - throw exception(DEMO01_CONTACT_NOT_EXISTS); - } - } - - @Override - public Demo01ContactDO getDemo01Contact(Long id) { - return demo01ContactMapper.selectById(id); - } - - @Override - public PageResult getDemo01ContactPage(Demo01ContactPageReqVO pageReqVO) { - return demo01ContactMapper.selectPage(pageReqVO); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo02/Demo02CategoryService.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo02/Demo02CategoryService.java deleted file mode 100644 index 23c771c..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo02/Demo02CategoryService.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.njcn.msgpush.module.infra.service.demo.demo02; - -import com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO; -import jakarta.validation.Valid; - -import java.util.List; - -/** - * 示例分类 Service 接口 - * - * @author hongawen - */ -public interface Demo02CategoryService { - - /** - * 创建示例分类 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createDemo02Category(@Valid Demo02CategorySaveReqVO createReqVO); - - /** - * 更新示例分类 - * - * @param updateReqVO 更新信息 - */ - void updateDemo02Category(@Valid Demo02CategorySaveReqVO updateReqVO); - - /** - * 删除示例分类 - * - * @param id 编号 - */ - void deleteDemo02Category(Long id); - - /** - * 获得示例分类 - * - * @param id 编号 - * @return 示例分类 - */ - Demo02CategoryDO getDemo02Category(Long id); - - /** - * 获得示例分类列表 - * - * @param listReqVO 查询条件 - * @return 示例分类列表 - */ - List getDemo02CategoryList(Demo02CategoryListReqVO listReqVO); - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo02/Demo02CategoryServiceImpl.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo02/Demo02CategoryServiceImpl.java deleted file mode 100644 index 53f4e3d..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo02/Demo02CategoryServiceImpl.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.njcn.msgpush.module.infra.service.demo.demo02; - -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo.Demo02CategoryListReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo02.vo.Demo02CategorySaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo02.Demo02CategoryDO; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo02.Demo02CategoryMapper; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.util.List; -import java.util.Objects; - -import static com.njcn.msgpush.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.njcn.msgpush.module.infra.enums.ErrorCodeConstants.*; - -/** - * 示例分类 Service 实现类 - * - * @author hongawen - */ -@Service -@Validated -public class Demo02CategoryServiceImpl implements Demo02CategoryService { - - @Resource - private Demo02CategoryMapper demo02CategoryMapper; - - @Override - public Long createDemo02Category(Demo02CategorySaveReqVO createReqVO) { - // 校验父级编号的有效性 - validateParentDemo02Category(null, createReqVO.getParentId()); - // 校验名字的唯一性 - validateDemo02CategoryNameUnique(null, createReqVO.getParentId(), createReqVO.getName()); - - // 插入 - Demo02CategoryDO demo02Category = BeanUtils.toBean(createReqVO, Demo02CategoryDO.class); - demo02CategoryMapper.insert(demo02Category); - // 返回 - return demo02Category.getId(); - } - - @Override - public void updateDemo02Category(Demo02CategorySaveReqVO updateReqVO) { - // 校验存在 - validateDemo02CategoryExists(updateReqVO.getId()); - // 校验父级编号的有效性 - validateParentDemo02Category(updateReqVO.getId(), updateReqVO.getParentId()); - // 校验名字的唯一性 - validateDemo02CategoryNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName()); - - // 更新 - Demo02CategoryDO updateObj = BeanUtils.toBean(updateReqVO, Demo02CategoryDO.class); - demo02CategoryMapper.updateById(updateObj); - } - - @Override - public void deleteDemo02Category(Long id) { - // 校验存在 - validateDemo02CategoryExists(id); - // 校验是否有子示例分类 - if (demo02CategoryMapper.selectCountByParentId(id) > 0) { - throw exception(DEMO02_CATEGORY_EXITS_CHILDREN); - } - // 删除 - demo02CategoryMapper.deleteById(id); - } - - private void validateDemo02CategoryExists(Long id) { - if (demo02CategoryMapper.selectById(id) == null) { - throw exception(DEMO02_CATEGORY_NOT_EXISTS); - } - } - - private void validateParentDemo02Category(Long id, Long parentId) { - if (parentId == null || Demo02CategoryDO.PARENT_ID_ROOT.equals(parentId)) { - return; - } - // 1. 不能设置自己为父示例分类 - if (Objects.equals(id, parentId)) { - throw exception(DEMO02_CATEGORY_PARENT_ERROR); - } - // 2. 父示例分类不存在 - Demo02CategoryDO parentDemo02Category = demo02CategoryMapper.selectById(parentId); - if (parentDemo02Category == null) { - throw exception(DEMO02_CATEGORY_PARENT_NOT_EXITS); - } - // 3. 递归校验父示例分类,如果父示例分类是自己的子示例分类,则报错,避免形成环路 - if (id == null) { // id 为空,说明新增,不需要考虑环路 - return; - } - for (int i = 0; i < Short.MAX_VALUE; i++) { - // 3.1 校验环路 - parentId = parentDemo02Category.getParentId(); - if (Objects.equals(id, parentId)) { - throw exception(DEMO02_CATEGORY_PARENT_IS_CHILD); - } - // 3.2 继续递归下一级父示例分类 - if (parentId == null || Demo02CategoryDO.PARENT_ID_ROOT.equals(parentId)) { - break; - } - parentDemo02Category = demo02CategoryMapper.selectById(parentId); - if (parentDemo02Category == null) { - break; - } - } - } - - private void validateDemo02CategoryNameUnique(Long id, Long parentId, String name) { - Demo02CategoryDO demo02Category = demo02CategoryMapper.selectByParentIdAndName(parentId, name); - if (demo02Category == null) { - return; - } - // 如果 id 为空,说明不用比较是否为相同 id 的示例分类 - if (id == null) { - throw exception(DEMO02_CATEGORY_NAME_DUPLICATE); - } - if (!Objects.equals(demo02Category.getId(), id)) { - throw exception(DEMO02_CATEGORY_NAME_DUPLICATE); - } - } - - @Override - public Demo02CategoryDO getDemo02Category(Long id) { - return demo02CategoryMapper.selectById(id); - } - - @Override - public List getDemo02CategoryList(Demo02CategoryListReqVO listReqVO) { - return demo02CategoryMapper.selectList(listReqVO); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/erp/Demo03StudentErpService.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/erp/Demo03StudentErpService.java deleted file mode 100644 index 38130a1..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/erp/Demo03StudentErpService.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.njcn.msgpush.module.infra.service.demo.demo03.erp; - -import com.njcn.msgpush.framework.common.pojo.PageParam; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import jakarta.validation.Valid; - -import java.util.List; - -/** - * 学生 Service 接口 - * - * @author hongawen - */ -public interface Demo03StudentErpService { - - /** - * 创建学生 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createDemo03Student(@Valid Demo03StudentErpSaveReqVO createReqVO); - - /** - * 更新学生 - * - * @param updateReqVO 更新信息 - */ - void updateDemo03Student(@Valid Demo03StudentErpSaveReqVO updateReqVO); - - /** - * 删除学生 - * - * @param id 编号 - */ - void deleteDemo03Student(Long id); - - /** - * 批量删除学生 - * - * @param ids 编号 - */ - void deleteDemo03StudentList(List ids); - - /** - * 获得学生 - * - * @param id 编号 - * @return 学生 - */ - Demo03StudentDO getDemo03Student(Long id); - - /** - * 获得学生分页 - * - * @param pageReqVO 分页查询 - * @return 学生分页 - */ - PageResult getDemo03StudentPage(Demo03StudentErpPageReqVO pageReqVO); - - // ==================== 子表(学生课程) ==================== - - /** - * 获得学生课程分页 - * - * @param pageReqVO 分页查询 - * @param studentId 学生编号 - * @return 学生课程分页 - */ - PageResult getDemo03CoursePage(PageParam pageReqVO, Long studentId); - - /** - * 创建学生课程 - * - * @param demo03Course 创建信息 - * @return 编号 - */ - Long createDemo03Course(@Valid Demo03CourseDO demo03Course); - - /** - * 更新学生课程 - * - * @param demo03Course 更新信息 - */ - void updateDemo03Course(@Valid Demo03CourseDO demo03Course); - - /** - * 删除学生课程 - * - * @param id 编号 - */ - void deleteDemo03Course(Long id); - - /** - * 批量删除学生课程 - * - * @param ids 编号 - */ - void deleteDemo03CourseList(List ids); - - /** - * 获得学生课程 - * - * @param id 编号 - * @return 学生课程 - */ - Demo03CourseDO getDemo03Course(Long id); - - // ==================== 子表(学生班级) ==================== - - /** - * 获得学生班级分页 - * - * @param pageReqVO 分页查询 - * @param studentId 学生编号 - * @return 学生班级分页 - */ - PageResult getDemo03GradePage(PageParam pageReqVO, Long studentId); - - /** - * 创建学生班级 - * - * @param demo03Grade 创建信息 - * @return 编号 - */ - Long createDemo03Grade(@Valid Demo03GradeDO demo03Grade); - - /** - * 更新学生班级 - * - * @param demo03Grade 更新信息 - */ - void updateDemo03Grade(@Valid Demo03GradeDO demo03Grade); - - /** - * 删除学生班级 - * - * @param id 编号 - */ - void deleteDemo03Grade(Long id); - - /** - * 批量删除学生班级 - * - * @param ids 编号 - */ - void deleteDemo03GradeList(List ids); - - /** - * 获得学生班级 - * - * @param id 编号 - * @return 学生班级 - */ - Demo03GradeDO getDemo03Grade(Long id); - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/erp/Demo03StudentErpServiceImpl.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/erp/Demo03StudentErpServiceImpl.java deleted file mode 100644 index da26055..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/erp/Demo03StudentErpServiceImpl.java +++ /dev/null @@ -1,219 +0,0 @@ -package com.njcn.msgpush.module.infra.service.demo.demo03.erp; - -import cn.hutool.core.collection.CollUtil; -import com.njcn.msgpush.framework.common.pojo.PageParam; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.erp.vo.Demo03StudentErpSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.erp.Demo03CourseErpMapper; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.erp.Demo03GradeErpMapper; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.erp.Demo03StudentErpMapper; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import java.util.List; - -import static com.njcn.msgpush.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.njcn.msgpush.module.infra.enums.ErrorCodeConstants.*; - -/** - * 学生 Service 实现类 - * - * @author hongawen - */ -@Service -@Validated -public class Demo03StudentErpServiceImpl implements Demo03StudentErpService { - - @Resource - private Demo03StudentErpMapper demo03StudentErpMapper; - @Resource - private Demo03CourseErpMapper demo03CourseErpMapper; - @Resource - private Demo03GradeErpMapper demo03GradeErpMapper; - - @Override - public Long createDemo03Student(Demo03StudentErpSaveReqVO createReqVO) { - // 插入 - Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); - demo03StudentErpMapper.insert(demo03Student); - // 返回 - return demo03Student.getId(); - } - - @Override - public void updateDemo03Student(Demo03StudentErpSaveReqVO updateReqVO) { - // 校验存在 - validateDemo03StudentExists(updateReqVO.getId()); - // 更新 - Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); - demo03StudentErpMapper.updateById(updateObj); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteDemo03Student(Long id) { - // 校验存在 - validateDemo03StudentExists(id); - // 删除 - demo03StudentErpMapper.deleteById(id); - - // 删除子表 - deleteDemo03CourseByStudentId(id); - deleteDemo03GradeByStudentId(id); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteDemo03StudentList(List ids) { - // 校验存在 - validateDemo03StudentExists(ids); - // 删除 - demo03StudentErpMapper.deleteByIds(ids); - - // 删除子表 - deleteDemo03CourseByStudentIds(ids); - deleteDemo03GradeByStudentIds(ids); - } - - private void validateDemo03StudentExists(List ids) { - List list = demo03StudentErpMapper.selectByIds(ids); - if (CollUtil.isEmpty(list) || list.size() != ids.size()) { - throw exception(DEMO03_STUDENT_NOT_EXISTS); - } - } - - private void validateDemo03StudentExists(Long id) { - if (demo03StudentErpMapper.selectById(id) == null) { - throw exception(DEMO03_STUDENT_NOT_EXISTS); - } - } - - @Override - public Demo03StudentDO getDemo03Student(Long id) { - return demo03StudentErpMapper.selectById(id); - } - - @Override - public PageResult getDemo03StudentPage(Demo03StudentErpPageReqVO pageReqVO) { - return demo03StudentErpMapper.selectPage(pageReqVO); - } - - // ==================== 子表(学生课程) ==================== - - @Override - public PageResult getDemo03CoursePage(PageParam pageReqVO, Long studentId) { - return demo03CourseErpMapper.selectPage(pageReqVO, studentId); - } - - @Override - public Long createDemo03Course(Demo03CourseDO demo03Course) { - demo03CourseErpMapper.insert(demo03Course); - return demo03Course.getId(); - } - - @Override - public void updateDemo03Course(Demo03CourseDO demo03Course) { - // 校验存在 - validateDemo03CourseExists(demo03Course.getId()); - // 更新 - demo03Course.clean(); - demo03CourseErpMapper.updateById(demo03Course); - } - - @Override - public void deleteDemo03Course(Long id) { - // 删除 - demo03CourseErpMapper.deleteById(id); - } - - @Override - public void deleteDemo03CourseList(List ids) { - // 删除 - demo03CourseErpMapper.deleteByIds(ids); - } - - @Override - public Demo03CourseDO getDemo03Course(Long id) { - return demo03CourseErpMapper.selectById(id); - } - - private void validateDemo03CourseExists(Long id) { - if (demo03CourseErpMapper.selectById(id) == null) { - throw exception(DEMO03_COURSE_NOT_EXISTS); - } - } - - private void deleteDemo03CourseByStudentId(Long studentId) { - demo03CourseErpMapper.deleteByStudentId(studentId); - } - - private void deleteDemo03CourseByStudentIds(List studentIds) { - demo03CourseErpMapper.deleteByStudentIds(studentIds); - } - - // ==================== 子表(学生班级) ==================== - - @Override - public PageResult getDemo03GradePage(PageParam pageReqVO, Long studentId) { - return demo03GradeErpMapper.selectPage(pageReqVO, studentId); - } - - @Override - public Long createDemo03Grade(Demo03GradeDO demo03Grade) { - // 校验是否已经存在 - if (demo03GradeErpMapper.selectByStudentId(demo03Grade.getStudentId()) != null) { - throw exception(DEMO03_GRADE_EXISTS); - } - // 插入 - demo03GradeErpMapper.insert(demo03Grade); - return demo03Grade.getId(); - } - - @Override - public void updateDemo03Grade(Demo03GradeDO demo03Grade) { - // 校验存在 - validateDemo03GradeExists(demo03Grade.getId()); - // 更新 - demo03Grade.clean(); - demo03GradeErpMapper.updateById(demo03Grade); - } - - @Override - public void deleteDemo03Grade(Long id) { - // 删除 - demo03GradeErpMapper.deleteById(id); - } - - @Override - public void deleteDemo03GradeList(List ids) { - // 删除 - demo03GradeErpMapper.deleteByIds(ids); - } - - @Override - public Demo03GradeDO getDemo03Grade(Long id) { - return demo03GradeErpMapper.selectById(id); - } - - private void validateDemo03GradeExists(Long id) { - if (demo03GradeErpMapper.selectById(id) == null) { - throw exception(DEMO03_GRADE_NOT_EXISTS); - } - } - - private void deleteDemo03GradeByStudentId(Long studentId) { - demo03GradeErpMapper.deleteByStudentId(studentId); - } - - private void deleteDemo03GradeByStudentIds(List studentIds) { - demo03GradeErpMapper.deleteByStudentIds(studentIds); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/inner/Demo03StudentInnerService.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/inner/Demo03StudentInnerService.java deleted file mode 100644 index cc5c469..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/inner/Demo03StudentInnerService.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.njcn.msgpush.module.infra.service.demo.demo03.inner; - -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import jakarta.validation.Valid; - -import java.util.List; - -/** - * 学生 Service 接口 - * - * @author hongawen - */ -public interface Demo03StudentInnerService { - - /** - * 创建学生 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createDemo03Student(@Valid Demo03StudentInnerSaveReqVO createReqVO); - - /** - * 更新学生 - * - * @param updateReqVO 更新信息 - */ - void updateDemo03Student(@Valid Demo03StudentInnerSaveReqVO updateReqVO); - - /** - * 删除学生 - * - * @param id 编号 - */ - void deleteDemo03Student(Long id); - - /** - * 批量删除学生 - * - * @param ids 编号 - */ - void deleteDemo03StudentList(List ids); - - /** - * 获得学生 - * - * @param id 编号 - * @return 学生 - */ - Demo03StudentDO getDemo03Student(Long id); - - /** - * 获得学生分页 - * - * @param pageReqVO 分页查询 - * @return 学生分页 - */ - PageResult getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO); - - // ==================== 子表(学生课程) ==================== - - /** - * 获得学生课程列表 - * - * @param studentId 学生编号 - * @return 学生课程列表 - */ - List getDemo03CourseListByStudentId(Long studentId); - - // ==================== 子表(学生班级) ==================== - - /** - * 获得学生班级 - * - * @param studentId 学生编号 - * @return 学生班级 - */ - Demo03GradeDO getDemo03GradeByStudentId(Long studentId); - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/inner/Demo03StudentInnerServiceImpl.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/inner/Demo03StudentInnerServiceImpl.java deleted file mode 100644 index 49a4a53..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/inner/Demo03StudentInnerServiceImpl.java +++ /dev/null @@ -1,194 +0,0 @@ -package com.njcn.msgpush.module.infra.service.demo.demo03.inner; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ObjectUtil; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.inner.vo.Demo03StudentInnerSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.inner.Demo03CourseInnerMapper; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.inner.Demo03GradeInnerMapper; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.inner.Demo03StudentInnerMapper; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import java.util.List; - -import static com.njcn.msgpush.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.njcn.msgpush.framework.common.util.collection.CollectionUtils.convertList; -import static com.njcn.msgpush.framework.common.util.collection.CollectionUtils.diffList; -import static com.njcn.msgpush.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS; - -/** - * 学生 Service 实现类 - * - * @author hongawen - */ -@Service -@Validated -public class Demo03StudentInnerServiceImpl implements Demo03StudentInnerService { - - @Resource - private Demo03StudentInnerMapper demo03StudentInnerMapper; - @Resource - private Demo03CourseInnerMapper demo03CourseInnerMapper; - @Resource - private Demo03GradeInnerMapper demo03GradeInnerMapper; - - @Override - @Transactional(rollbackFor = Exception.class) - public Long createDemo03Student(Demo03StudentInnerSaveReqVO createReqVO) { - // 插入 - Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); - demo03StudentInnerMapper.insert(demo03Student); - - // 插入子表 - createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); - createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); - // 返回 - return demo03Student.getId(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateDemo03Student(Demo03StudentInnerSaveReqVO updateReqVO) { - // 校验存在 - validateDemo03StudentExists(updateReqVO.getId()); - // 更新 - Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); - demo03StudentInnerMapper.updateById(updateObj); - - // 更新子表 - updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); - updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteDemo03Student(Long id) { - // 校验存在 - validateDemo03StudentExists(id); - // 删除 - demo03StudentInnerMapper.deleteById(id); - - // 删除子表 - deleteDemo03CourseByStudentId(id); - deleteDemo03GradeByStudentId(id); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteDemo03StudentList(List ids) { - // 校验存在 - validateDemo03StudentExists(ids); - // 删除 - demo03StudentInnerMapper.deleteByIds(ids); - - // 删除子表 - deleteDemo03CourseByStudentIds(ids); - deleteDemo03GradeByStudentIds(ids); - } - - private void validateDemo03StudentExists(List ids) { - List list = demo03StudentInnerMapper.selectByIds(ids); - if (CollUtil.isEmpty(list) || list.size() != ids.size()) { - throw exception(DEMO03_STUDENT_NOT_EXISTS); - } - } - - private void validateDemo03StudentExists(Long id) { - if (demo03StudentInnerMapper.selectById(id) == null) { - throw exception(DEMO03_STUDENT_NOT_EXISTS); - } - } - - @Override - public Demo03StudentDO getDemo03Student(Long id) { - return demo03StudentInnerMapper.selectById(id); - } - - @Override - public PageResult getDemo03StudentPage(Demo03StudentInnerPageReqVO pageReqVO) { - return demo03StudentInnerMapper.selectPage(pageReqVO); - } - - // ==================== 子表(学生课程) ==================== - - @Override - public List getDemo03CourseListByStudentId(Long studentId) { - return demo03CourseInnerMapper.selectListByStudentId(studentId); - } - - private void createDemo03CourseList(Long studentId, List list) { - list.forEach(o -> o.setStudentId(studentId).clean()); - demo03CourseInnerMapper.insertBatch(list); - } - - private void updateDemo03CourseList(Long studentId, List list) { - list.forEach(o -> o.setStudentId(studentId).clean()); - List oldList = demo03CourseInnerMapper.selectListByStudentId(studentId); - List> diffList = diffList(oldList, list, (oldVal, newVal) -> { - boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId()); - if (same) { - newVal.setId(oldVal.getId()); - } - return same; - }); - - // 第二步,批量添加、修改、删除 - if (CollUtil.isNotEmpty(diffList.get(0))) { - demo03CourseInnerMapper.insertBatch(diffList.get(0)); - } - if (CollUtil.isNotEmpty(diffList.get(1))) { - demo03CourseInnerMapper.updateBatch(diffList.get(1)); - } - if (CollUtil.isNotEmpty(diffList.get(2))) { - demo03CourseInnerMapper.deleteByIds(convertList(diffList.get(2), Demo03CourseDO::getId)); - } - } - - private void deleteDemo03CourseByStudentId(Long studentId) { - demo03CourseInnerMapper.deleteByStudentId(studentId); - } - - private void deleteDemo03CourseByStudentIds(List studentIds) { - demo03CourseInnerMapper.deleteByStudentIds(studentIds); - } - - // ==================== 子表(学生班级) ==================== - - @Override - public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { - return demo03GradeInnerMapper.selectByStudentId(studentId); - } - - private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { - if (demo03Grade == null) { - return; - } - demo03Grade.setStudentId(studentId); - demo03GradeInnerMapper.insert(demo03Grade); - } - - private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { - if (demo03Grade == null) { - return; - } - demo03Grade.setStudentId(studentId).clean(); - demo03GradeInnerMapper.insertOrUpdate(demo03Grade); - } - - private void deleteDemo03GradeByStudentId(Long studentId) { - demo03GradeInnerMapper.deleteByStudentId(studentId); - } - - private void deleteDemo03GradeByStudentIds(List studentIds) { - demo03GradeInnerMapper.deleteByStudentIds(studentIds); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/normal/Demo03StudentNormalService.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/normal/Demo03StudentNormalService.java deleted file mode 100644 index 2b61f02..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/normal/Demo03StudentNormalService.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.njcn.msgpush.module.infra.service.demo.demo03.normal; - -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import jakarta.validation.Valid; - -import java.util.List; - -/** - * 学生 Service 接口 - * - * @author hongawen - */ -public interface Demo03StudentNormalService { - - /** - * 创建学生 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createDemo03Student(@Valid Demo03StudentNormalSaveReqVO createReqVO); - - /** - * 更新学生 - * - * @param updateReqVO 更新信息 - */ - void updateDemo03Student(@Valid Demo03StudentNormalSaveReqVO updateReqVO); - - /** - * 删除学生 - * - * @param id 编号 - */ - void deleteDemo03Student(Long id); - - /** - * 批量删除学生 - * - * @param ids 编号 - */ - void deleteDemo03StudentList(List ids); - - /** - * 获得学生 - * - * @param id 编号 - * @return 学生 - */ - Demo03StudentDO getDemo03Student(Long id); - - /** - * 获得学生分页 - * - * @param pageReqVO 分页查询 - * @return 学生分页 - */ - PageResult getDemo03StudentPage(Demo03StudentNormalPageReqVO pageReqVO); - - // ==================== 子表(学生课程) ==================== - - /** - * 获得学生课程列表 - * - * @param studentId 学生编号 - * @return 学生课程列表 - */ - List getDemo03CourseListByStudentId(Long studentId); - - // ==================== 子表(学生班级) ==================== - - /** - * 获得学生班级 - * - * @param studentId 学生编号 - * @return 学生班级 - */ - Demo03GradeDO getDemo03GradeByStudentId(Long studentId); - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/normal/Demo03StudentNormalServiceImpl.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/normal/Demo03StudentNormalServiceImpl.java deleted file mode 100644 index 39c02d4..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/demo/demo03/normal/Demo03StudentNormalServiceImpl.java +++ /dev/null @@ -1,194 +0,0 @@ -package com.njcn.msgpush.module.infra.service.demo.demo03.normal; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.ObjectUtil; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalPageReqVO; -import com.njcn.msgpush.module.infra.controller.admin.demo.demo03.normal.vo.Demo03StudentNormalSaveReqVO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03CourseDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03GradeDO; -import com.njcn.msgpush.module.infra.dal.dataobject.demo.demo03.Demo03StudentDO; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.normal.Demo03CourseNormalMapper; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.normal.Demo03GradeNormalMapper; -import com.njcn.msgpush.module.infra.dal.mysql.demo.demo03.normal.Demo03StudentNormalMapper; -import jakarta.annotation.Resource; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.validation.annotation.Validated; - -import java.util.List; - -import static com.njcn.msgpush.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.njcn.msgpush.framework.common.util.collection.CollectionUtils.convertList; -import static com.njcn.msgpush.framework.common.util.collection.CollectionUtils.diffList; -import static com.njcn.msgpush.module.infra.enums.ErrorCodeConstants.DEMO03_STUDENT_NOT_EXISTS; - -/** - * 学生 Service 实现类 - * - * @author hongawen - */ -@Service -@Validated -public class Demo03StudentNormalServiceImpl implements Demo03StudentNormalService { - - @Resource - private Demo03StudentNormalMapper demo03StudentNormalMapper; - @Resource - private Demo03CourseNormalMapper demo03CourseNormalMapper; - @Resource - private Demo03GradeNormalMapper demo03GradeNormalMapper; - - @Override - @Transactional(rollbackFor = Exception.class) - public Long createDemo03Student(Demo03StudentNormalSaveReqVO createReqVO) { - // 插入 - Demo03StudentDO demo03Student = BeanUtils.toBean(createReqVO, Demo03StudentDO.class); - demo03StudentNormalMapper.insert(demo03Student); - - // 插入子表 - createDemo03CourseList(demo03Student.getId(), createReqVO.getDemo03Courses()); - createDemo03Grade(demo03Student.getId(), createReqVO.getDemo03Grade()); - // 返回 - return demo03Student.getId(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateDemo03Student(Demo03StudentNormalSaveReqVO updateReqVO) { - // 校验存在 - validateDemo03StudentExists(updateReqVO.getId()); - // 更新 - Demo03StudentDO updateObj = BeanUtils.toBean(updateReqVO, Demo03StudentDO.class); - demo03StudentNormalMapper.updateById(updateObj); - - // 更新子表 - updateDemo03CourseList(updateReqVO.getId(), updateReqVO.getDemo03Courses()); - updateDemo03Grade(updateReqVO.getId(), updateReqVO.getDemo03Grade()); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteDemo03Student(Long id) { - // 校验存在 - validateDemo03StudentExists(id); - // 删除 - demo03StudentNormalMapper.deleteById(id); - - // 删除子表 - deleteDemo03CourseByStudentId(id); - deleteDemo03GradeByStudentId(id); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteDemo03StudentList(List ids) { - // 校验存在 - validateDemo03StudentExists(ids); - // 删除 - demo03StudentNormalMapper.deleteByIds(ids); - - // 删除子表 - deleteDemo03CourseByStudentIds(ids); - deleteDemo03GradeByStudentIds(ids); - } - - private void validateDemo03StudentExists(List ids) { - List list = demo03StudentNormalMapper.selectByIds(ids); - if (CollUtil.isEmpty(list) || list.size() != ids.size()) { - throw exception(DEMO03_STUDENT_NOT_EXISTS); - } - } - - private void validateDemo03StudentExists(Long id) { - if (demo03StudentNormalMapper.selectById(id) == null) { - throw exception(DEMO03_STUDENT_NOT_EXISTS); - } - } - - @Override - public Demo03StudentDO getDemo03Student(Long id) { - return demo03StudentNormalMapper.selectById(id); - } - - @Override - public PageResult getDemo03StudentPage(Demo03StudentNormalPageReqVO pageReqVO) { - return demo03StudentNormalMapper.selectPage(pageReqVO); - } - - // ==================== 子表(学生课程) ==================== - - @Override - public List getDemo03CourseListByStudentId(Long studentId) { - return demo03CourseNormalMapper.selectListByStudentId(studentId); - } - - private void createDemo03CourseList(Long studentId, List list) { - list.forEach(o -> o.setStudentId(studentId).clean()); - demo03CourseNormalMapper.insertBatch(list); - } - - private void updateDemo03CourseList(Long studentId, List list) { - list.forEach(o -> o.setStudentId(studentId).clean()); - List oldList = demo03CourseNormalMapper.selectListByStudentId(studentId); - List> diffList = diffList(oldList, list, (oldVal, newVal) -> { - boolean same = ObjectUtil.equal(oldVal.getId(), newVal.getId()); - if (same) { - newVal.setId(oldVal.getId()); - } - return same; - }); - - // 第二步,批量添加、修改、删除 - if (CollUtil.isNotEmpty(diffList.get(0))) { - demo03CourseNormalMapper.insertBatch(diffList.get(0)); - } - if (CollUtil.isNotEmpty(diffList.get(1))) { - demo03CourseNormalMapper.updateBatch(diffList.get(1)); - } - if (CollUtil.isNotEmpty(diffList.get(2))) { - demo03CourseNormalMapper.deleteByIds(convertList(diffList.get(2), Demo03CourseDO::getId)); - } - } - - private void deleteDemo03CourseByStudentId(Long studentId) { - demo03CourseNormalMapper.deleteByStudentId(studentId); - } - - private void deleteDemo03CourseByStudentIds(List studentIds) { - demo03CourseNormalMapper.deleteByStudentIds(studentIds); - } - - // ==================== 子表(学生班级) ==================== - - @Override - public Demo03GradeDO getDemo03GradeByStudentId(Long studentId) { - return demo03GradeNormalMapper.selectByStudentId(studentId); - } - - private void createDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { - if (demo03Grade == null) { - return; - } - demo03Grade.setStudentId(studentId); - demo03GradeNormalMapper.insert(demo03Grade); - } - - private void updateDemo03Grade(Long studentId, Demo03GradeDO demo03Grade) { - if (demo03Grade == null) { - return; - } - demo03Grade.setStudentId(studentId).clean(); - demo03GradeNormalMapper.insertOrUpdate(demo03Grade); - } - - private void deleteDemo03GradeByStudentId(Long studentId) { - demo03GradeNormalMapper.deleteByStudentId(studentId); - } - - private void deleteDemo03GradeByStudentIds(List studentIds) { - demo03GradeNormalMapper.deleteByStudentIds(studentIds); - } - -} \ No newline at end of file diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/logger/ApiAccessLogServiceImpl.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/logger/ApiAccessLogServiceImpl.java index 686b6df..21bfeb4 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/logger/ApiAccessLogServiceImpl.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/logger/ApiAccessLogServiceImpl.java @@ -4,8 +4,6 @@ import com.njcn.msgpush.framework.common.biz.infra.logger.dto.ApiAccessLogCreate import com.njcn.msgpush.framework.common.pojo.PageResult; import com.njcn.msgpush.framework.common.util.object.BeanUtils; import com.njcn.msgpush.framework.common.util.string.StrUtils; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.tenant.core.util.TenantUtils; import com.njcn.msgpush.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO; import com.njcn.msgpush.module.infra.dal.dataobject.logger.ApiAccessLogDO; import com.njcn.msgpush.module.infra.dal.mysql.logger.ApiAccessLogMapper; @@ -37,12 +35,7 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService { ApiAccessLogDO apiAccessLog = BeanUtils.toBean(createDTO, ApiAccessLogDO.class); apiAccessLog.setRequestParams(StrUtils.maxLength(apiAccessLog.getRequestParams(), REQUEST_PARAMS_MAX_LENGTH)); apiAccessLog.setResultMsg(StrUtils.maxLength(apiAccessLog.getResultMsg(), RESULT_MSG_MAX_LENGTH)); - if (TenantContextHolder.getTenantId() != null) { - apiAccessLogMapper.insert(apiAccessLog); - } else { - // 极端情况下,上下文中没有租户时,此时忽略租户上下文,避免插入失败! - TenantUtils.executeIgnore(() -> apiAccessLogMapper.insert(apiAccessLog)); - } + apiAccessLogMapper.insert(apiAccessLog); } @Override diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/logger/ApiErrorLogServiceImpl.java b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/logger/ApiErrorLogServiceImpl.java index 09b65d3..8b4f54d 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/logger/ApiErrorLogServiceImpl.java +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/java/com/njcn/msgpush/module/infra/service/logger/ApiErrorLogServiceImpl.java @@ -4,8 +4,6 @@ import com.njcn.msgpush.framework.common.biz.infra.logger.dto.ApiErrorLogCreateR import com.njcn.msgpush.framework.common.pojo.PageResult; import com.njcn.msgpush.framework.common.util.object.BeanUtils; import com.njcn.msgpush.framework.common.util.string.StrUtils; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.tenant.core.util.TenantUtils; import com.njcn.msgpush.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO; import com.njcn.msgpush.module.infra.dal.dataobject.logger.ApiErrorLogDO; import com.njcn.msgpush.module.infra.dal.mysql.logger.ApiErrorLogMapper; @@ -41,12 +39,7 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService { .setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus()); apiErrorLog.setRequestParams(StrUtils.maxLength(apiErrorLog.getRequestParams(), REQUEST_PARAMS_MAX_LENGTH)); try { - if (TenantContextHolder.getTenantId() != null) { - apiErrorLogMapper.insert(apiErrorLog); - } else { - // 极端情况下,上下文中没有租户时,此时忽略租户上下文,避免插入失败! - TenantUtils.executeIgnore(() -> apiErrorLogMapper.insert(apiErrorLog)); - } + apiErrorLogMapper.insert(apiErrorLog); } catch (Exception ex) { // 兜底处理,目前只有 msgpush-cloud 会发生:https://gitee.com/msgpushcode/msgpush-cloud-mini/issues/IC1O0A log.error("[createApiErrorLog][记录时({}) 发生异常]", createDTO, ex); diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/resources/application.yaml b/msgpush-module-infra/msgpush-module-infra-server/src/main/resources/application.yaml index 5b2e988..f799958 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/resources/application.yaml +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/resources/application.yaml @@ -107,9 +107,5 @@ msgpush: vo-type: 10 # VO 的类型,参见 CodegenVOTypeEnum 枚举类 delete-batch-enable: true # 是否生成批量删除接口 unit-test-enable: false # 是否生成单元测试 - tenant: # 多租户相关配置项 - enable: true - ignore-urls: - ignore-tables: debug: false diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/main/resources/codegen/sql/h2.vm b/msgpush-module-infra/msgpush-module-infra-server/src/main/resources/codegen/sql/h2.vm index 58d563e..0e9fea4 100644 --- a/msgpush-module-infra/msgpush-module-infra-server/src/main/resources/codegen/sql/h2.vm +++ b/msgpush-module-infra/msgpush-module-infra-server/src/main/resources/codegen/sql/h2.vm @@ -23,8 +23,6 @@ CREATE TABLE IF NOT EXISTS "${table.tableName.toLowerCase()}" ( "${column.columnName}" ${dataType} DEFAULT '', #elseif (${column.columnName} == 'deleted') "deleted" bit NOT NULL DEFAULT FALSE, - #elseif (${column.columnName} == 'tenant_id') - "tenant_id" bigint NOT NULL DEFAULT 0, #else "${column.columnName.toLowerCase()}" ${dataType}#if (${column.nullable} == false) NOT NULL#end, #end diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/test/resources/sql/clean.sql b/msgpush-module-infra/msgpush-module-infra-server/src/test/resources/sql/clean.sql deleted file mode 100644 index 58345ed..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/test/resources/sql/clean.sql +++ /dev/null @@ -1,11 +0,0 @@ -DELETE FROM "infra_config"; -DELETE FROM "infra_file_config"; -DELETE FROM "infra_file"; -DELETE FROM "infra_job"; -DELETE FROM "infra_job_log"; -DELETE FROM "infra_api_access_log"; -DELETE FROM "infra_api_error_log"; -DELETE FROM "infra_file_config"; -DELETE FROM "infra_data_source_config"; -DELETE FROM "infra_codegen_table"; -DELETE FROM "infra_codegen_column"; diff --git a/msgpush-module-infra/msgpush-module-infra-server/src/test/resources/sql/create_tables.sql b/msgpush-module-infra/msgpush-module-infra-server/src/test/resources/sql/create_tables.sql deleted file mode 100644 index d4b19c9..0000000 --- a/msgpush-module-infra/msgpush-module-infra-server/src/test/resources/sql/create_tables.sql +++ /dev/null @@ -1,216 +0,0 @@ - -CREATE TABLE IF NOT EXISTS "infra_config" ( - "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '编号', - "category" varchar(50) NOT NULL, - "type" tinyint NOT NULL, - "name" varchar(100) NOT NULL DEFAULT '' COMMENT '名字', - "config_key" varchar(100) NOT NULL DEFAULT '', - "value" varchar(500) NOT NULL DEFAULT '', - "visible" bit NOT NULL, - "remark" varchar(500) DEFAULT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '参数配置表'; - -CREATE TABLE IF NOT EXISTS "infra_file_config" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(63) NOT NULL, - "storage" tinyint NOT NULL, - "remark" varchar(255), - "master" bit(1) NOT NULL, - "config" varchar(4096) NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '文件配置表'; - -CREATE TABLE IF NOT EXISTS "infra_file" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "config_id" bigint NOT NULL, - "name" varchar(256), - "path" varchar(512), - "url" varchar(1024), - "type" varchar(63) DEFAULT NULL, - "size" bigint NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT '文件表'; - -CREATE TABLE IF NOT EXISTS "infra_job" ( - "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '任务编号', - "name" varchar(32) NOT NULL COMMENT '任务名称', - "status" tinyint(4) NOT NULL COMMENT '任务状态', - "handler_name" varchar(64) NOT NULL COMMENT '处理器的名字', - "handler_param" varchar(255) DEFAULT NULL COMMENT '处理器的参数', - "cron_expression" varchar(32) NOT NULL COMMENT 'CRON 表达式', - "retry_count" int(11) NOT NULL DEFAULT '0' COMMENT '重试次数', - "retry_interval" int(11) NOT NULL DEFAULT '0' COMMENT '重试间隔', - "monitor_timeout" int(11) NOT NULL DEFAULT '0' COMMENT '监控超时时间', - "creator" varchar(64) DEFAULT '' COMMENT '创建者', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - "updater" varchar(64) DEFAULT '' COMMENT '更新者', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - "deleted" bit NOT NULL DEFAULT FALSE COMMENT '是否删除', - PRIMARY KEY ("id") -) COMMENT='定时任务表'; - -CREATE TABLE IF NOT EXISTS "infra_job_log" ( - "id" bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY COMMENT '日志编号', - "job_id" bigint(20) NOT NULL COMMENT '任务编号', - "handler_name" varchar(64) NOT NULL COMMENT '处理器的名字', - "handler_param" varchar(255) DEFAULT NULL COMMENT '处理器的参数', - "execute_index" tinyint(4) NOT NULL DEFAULT '1' COMMENT '第几次执行', - "begin_time" datetime NOT NULL COMMENT '开始执行时间', - "end_time" datetime DEFAULT NULL COMMENT '结束执行时间', - "duration" int(11) DEFAULT NULL COMMENT '执行时长', - "status" tinyint(4) NOT NULL COMMENT '任务状态', - "result" varchar(4000) DEFAULT '' COMMENT '结果数据', - "creator" varchar(64) DEFAULT '' COMMENT '创建者', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - "updater" varchar(64) DEFAULT '' COMMENT '更新者', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - "deleted" bit(1) NOT NULL DEFAULT FALSE COMMENT '是否删除', - PRIMARY KEY ("id") -)COMMENT='定时任务日志表'; - -CREATE TABLE IF NOT EXISTS "infra_api_access_log" ( - "id" bigint not null GENERATED BY DEFAULT AS IDENTITY, - "trace_id" varchar(64) not null default '', - "user_id" bigint not null default '0', - "user_type" tinyint not null default '0', - "application_name" varchar(50) not null, - "request_method" varchar(16) not null default '', - "request_url" varchar(255) not null default '', - "request_params" varchar(8000) not null default '', - "response_body" varchar(8000) not null default '', - "user_ip" varchar(50) not null, - "user_agent" varchar(512) not null, - `operate_module` varchar(50) NOT NULL, - `operate_name` varchar(50) NOT NULL, - `operate_type` bigint(4) NOT NULL DEFAULT '0', - "begin_time" timestamp not null, - "end_time" timestamp not null, - "duration" integer not null, - "result_code" integer not null default '0', - "result_msg" varchar(512) default '', - "creator" varchar(64) default '', - "create_time" timestamp not null default current_timestamp, - "updater" varchar(64) default '', - "update_time" timestamp not null default current_timestamp, - "deleted" bit not null default false, - "tenant_id" bigint not null default '0', - primary key ("id") -) COMMENT 'API 访问日志表'; - -CREATE TABLE IF NOT EXISTS "infra_api_error_log" ( - "id" bigint not null GENERATED BY DEFAULT AS IDENTITY, - "trace_id" varchar(64) not null, - "user_id" bigint not null default '0', - "user_type" tinyint not null default '0', - "application_name" varchar(50) not null, - "request_method" varchar(16) not null, - "request_url" varchar(255) not null, - "request_params" varchar(8000) not null, - "user_ip" varchar(50) not null, - "user_agent" varchar(512) not null, - "exception_time" timestamp not null, - "exception_name" varchar(128) not null default '', - "exception_message" clob not null, - "exception_root_cause_message" clob not null, - "exception_stack_trace" clob not null, - "exception_class_name" varchar(512) not null, - "exception_file_name" varchar(512) not null, - "exception_method_name" varchar(512) not null, - "exception_line_number" integer not null, - "process_status" tinyint not null, - "process_time" timestamp default null, - "process_user_id" bigint default '0', - "creator" varchar(64) default '', - "create_time" timestamp not null default current_timestamp, - "updater" varchar(64) default '', - "update_time" timestamp not null default current_timestamp, - "deleted" bit not null default false, - "tenant_id" bigint not null default '0', - primary key ("id") -) COMMENT '系统异常日志'; - -CREATE TABLE IF NOT EXISTS "infra_data_source_config" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(100) NOT NULL, - "url" varchar(1024) NOT NULL, - "username" varchar(255) NOT NULL, - "password" varchar(255) NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '数据源配置表'; - -CREATE TABLE IF NOT EXISTS "infra_codegen_table" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "data_source_config_id" bigint not null, - "scene" tinyint not null DEFAULT 1, - "table_name" varchar(200) NOT NULL, - "table_comment" varchar(500) NOT NULL, - "remark" varchar(500) NOT NULL, - "module_name" varchar(30) NOT NULL, - "business_name" varchar(30) NOT NULL, - "class_name" varchar(100) NOT NULL, - "class_comment" varchar(50) NOT NULL, - "author" varchar(50) NOT NULL, - "template_type" tinyint not null DEFAULT 1, - "front_type" tinyint not null, - "parent_menu_id" bigint not null, - "master_table_id" bigint not null, - "sub_join_column_id" bigint not null, - "sub_join_many" bit not null, - "tree_parent_column_id" bigint not null, - "tree_name_column_id" bigint not null, - "creator" varchar(64) DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '代码生成表定义表'; - -CREATE TABLE IF NOT EXISTS "infra_codegen_column" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "table_id" bigint not null, - "column_name" varchar(200) NOT NULL, - "data_type" varchar(100) NOT NULL, - "column_comment" varchar(500) NOT NULL, - "nullable" tinyint not null, - "primary_key" tinyint not null, - "ordinal_position" int not null, - "java_type" varchar(32) NOT NULL, - "java_field" varchar(64) NOT NULL, - "dict_type" varchar(200) NOT NULL, - "example" varchar(64) NOT NULL, - "create_operation" bit not null, - "update_operation" bit not null, - "list_operation" bit not null, - "list_operation_condition" varchar(32) not null, - "list_operation_result" bit not null, - "html_type" varchar(32) NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '代码生成表字段定义表'; \ No newline at end of file diff --git a/msgpush-module-push/msgpush-module-push-server/pom.xml b/msgpush-module-push/msgpush-module-push-server/pom.xml index dbb0f7c..ced7551 100644 --- a/msgpush-module-push/msgpush-module-push-server/pom.xml +++ b/msgpush-module-push/msgpush-module-push-server/pom.xml @@ -40,11 +40,7 @@ ${revision} - - - com.njcn - msgpush-spring-boot-starter-biz-tenant - + com.njcn msgpush-spring-boot-starter-biz-ip diff --git a/msgpush-module-system/msgpush-module-system-api/src/main/java/com/njcn/msgpush/module/system/enums/ErrorCodeConstants.java b/msgpush-module-system/msgpush-module-system-api/src/main/java/com/njcn/msgpush/module/system/enums/ErrorCodeConstants.java index 1c3eb8d..88528c6 100644 --- a/msgpush-module-system/msgpush-module-system-api/src/main/java/com/njcn/msgpush/module/system/enums/ErrorCodeConstants.java +++ b/msgpush-module-system/msgpush-module-system-api/src/main/java/com/njcn/msgpush/module/system/enums/ErrorCodeConstants.java @@ -13,8 +13,6 @@ public interface ErrorCodeConstants { ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1_002_000_000, "登录失败,账号密码不正确"); ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1_002_000_001, "登录失败,账号被禁用"); ErrorCode AUTH_LOGIN_CAPTCHA_CODE_ERROR = new ErrorCode(1_002_000_004, "验证码不正确,原因:{}"); - ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1_002_000_005, "未绑定账号,需要进行绑定"); - ErrorCode AUTH_MOBILE_NOT_EXISTS = new ErrorCode(1_002_000_007, "手机号不存在"); ErrorCode AUTH_REGISTER_CAPTCHA_CODE_ERROR = new ErrorCode(1_002_000_008, "验证码不正确,原因:{}"); // ========== 菜单模块 1-002-001-000 ========== @@ -44,7 +42,6 @@ public interface ErrorCodeConstants { ErrorCode USER_IS_DISABLE = new ErrorCode(1_002_003_006, "名字为【{}】的用户已被禁用"); ErrorCode USER_COUNT_MAX = new ErrorCode(1_002_003_008, "创建用户失败,原因:超过租户最大租户配额({})!"); ErrorCode USER_IMPORT_INIT_PASSWORD = new ErrorCode(1_002_003_009, "初始密码不能为空"); - ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1_002_003_010, "该手机号尚未注册"); ErrorCode USER_REGISTER_DISABLED = new ErrorCode(1_002_003_011, "注册功能已关闭"); // ========== 部门模块 1-002-004-000 ========== @@ -77,57 +74,6 @@ public interface ErrorCodeConstants { // ========== 通知公告 1-002-008-000 ========== ErrorCode NOTICE_NOT_FOUND = new ErrorCode(1_002_008_001, "当前通知公告不存在"); - // ========== 短信渠道 1-002-011-000 ========== - ErrorCode SMS_CHANNEL_NOT_EXISTS = new ErrorCode(1_002_011_000, "短信渠道不存在"); - ErrorCode SMS_CHANNEL_DISABLE = new ErrorCode(1_002_011_001, "短信渠道不处于开启状态,不允许选择"); - ErrorCode SMS_CHANNEL_HAS_CHILDREN = new ErrorCode(1_002_011_002, "无法删除,该短信渠道还有短信模板"); - - // ========== 短信模板 1-002-012-000 ========== - ErrorCode SMS_TEMPLATE_NOT_EXISTS = new ErrorCode(1_002_012_000, "短信模板不存在"); - ErrorCode SMS_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1_002_012_001, "已经存在编码为【{}】的短信模板"); - ErrorCode SMS_TEMPLATE_API_ERROR = new ErrorCode(1_002_012_002, "短信 API 模板调用失败,原因是:{}"); - ErrorCode SMS_TEMPLATE_API_AUDIT_CHECKING = new ErrorCode(1_002_012_003, "短信 API 模版无法使用,原因:审批中"); - ErrorCode SMS_TEMPLATE_API_AUDIT_FAIL = new ErrorCode(1_002_012_004, "短信 API 模版无法使用,原因:审批不通过,{}"); - ErrorCode SMS_TEMPLATE_API_NOT_FOUND = new ErrorCode(1_002_012_005, "短信 API 模版无法使用,原因:模版不存在"); - - // ========== 短信发送 1-002-013-000 ========== - ErrorCode SMS_SEND_MOBILE_NOT_EXISTS = new ErrorCode(1_002_013_000, "手机号不存在"); - ErrorCode SMS_SEND_MOBILE_TEMPLATE_PARAM_MISS = new ErrorCode(1_002_013_001, "模板参数({})缺失"); - ErrorCode SMS_SEND_TEMPLATE_NOT_EXISTS = new ErrorCode(1_002_013_002, "短信模板不存在"); - - // ========== 短信验证码 1-002-014-000 ========== - ErrorCode SMS_CODE_NOT_FOUND = new ErrorCode(1_002_014_000, "验证码不存在"); - ErrorCode SMS_CODE_EXPIRED = new ErrorCode(1_002_014_001, "验证码已过期"); - ErrorCode SMS_CODE_USED = new ErrorCode(1_002_014_002, "验证码已使用"); - ErrorCode SMS_CODE_EXCEED_SEND_MAXIMUM_QUANTITY_PER_DAY = new ErrorCode(1_002_014_004, "超过每日短信发送数量"); - ErrorCode SMS_CODE_SEND_TOO_FAST = new ErrorCode(1_002_014_005, "短信发送过于频繁"); - - // ========== 租户信息 1-002-015-000 ========== - ErrorCode TENANT_NOT_EXISTS = new ErrorCode(1_002_015_000, "租户不存在"); - ErrorCode TENANT_DISABLE = new ErrorCode(1_002_015_001, "名字为【{}】的租户已被禁用"); - ErrorCode TENANT_EXPIRE = new ErrorCode(1_002_015_002, "名字为【{}】的租户已过期"); - ErrorCode TENANT_CAN_NOT_UPDATE_SYSTEM = new ErrorCode(1_002_015_003, "系统租户不能进行修改、删除等操作!"); - ErrorCode TENANT_NAME_DUPLICATE = new ErrorCode(1_002_015_004, "名字为【{}】的租户已存在"); - ErrorCode TENANT_WEBSITE_DUPLICATE = new ErrorCode(1_002_015_005, "域名为【{}】的租户已存在"); - - // ========== 租户套餐 1-002-016-000 ========== - ErrorCode TENANT_PACKAGE_NOT_EXISTS = new ErrorCode(1_002_016_000, "租户套餐不存在"); - ErrorCode TENANT_PACKAGE_USED = new ErrorCode(1_002_016_001, "租户正在使用该套餐,请给租户重新设置套餐后再尝试删除"); - ErrorCode TENANT_PACKAGE_DISABLE = new ErrorCode(1_002_016_002, "名字为【{}】的租户套餐已被禁用"); - ErrorCode TENANT_PACKAGE_NAME_DUPLICATE = new ErrorCode(1_002_016_003, "已经存在该名字的租户套餐"); - - // ========== 社交用户 1-002-018-000 ========== - ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1_002_018_000, "社交授权失败,原因是:{}"); - ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_001, "社交授权失败,找不到对应的用户"); - - ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_PHONE_CODE_ERROR = new ErrorCode(1_002_018_200, "获得手机号失败"); - ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_QRCODE_ERROR = new ErrorCode(1_002_018_201, "获得小程序码失败"); - ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_TEMPLATE_ERROR = new ErrorCode(1_002_018_202, "获得小程序订阅消息模版失败"); - ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_SUBSCRIBE_MESSAGE_ERROR = new ErrorCode(1_002_018_203, "发送小程序订阅消息失败"); - ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_ORDER_UPLOAD_SHIPPING_INFO_ERROR = new ErrorCode(1_002_018_204, "上传微信小程序发货信息失败"); - ErrorCode SOCIAL_CLIENT_WEIXIN_MINI_APP_ORDER_NOTIFY_CONFIRM_RECEIVE_ERROR = new ErrorCode(1_002_018_205, "上传微信小程序订单收货信息失败"); - ErrorCode SOCIAL_CLIENT_NOT_EXISTS = new ErrorCode(1_002_018_210, "社交客户端不存在"); - ErrorCode SOCIAL_CLIENT_UNIQUE = new ErrorCode(1_002_018_211, "社交客户端已存在配置"); // ========== OAuth2 客户端 1-002-020-000 ========= ErrorCode OAUTH2_CLIENT_NOT_EXISTS = new ErrorCode(1_002_020_000, "OAuth2 客户端不存在"); @@ -147,18 +93,6 @@ public interface ErrorCodeConstants { ErrorCode OAUTH2_CODE_NOT_EXISTS = new ErrorCode(1_002_022_000, "code 不存在"); ErrorCode OAUTH2_CODE_EXPIRE = new ErrorCode(1_002_022_001, "code 已过期"); - // ========== 邮箱账号 1-002-023-000 ========== - ErrorCode MAIL_ACCOUNT_NOT_EXISTS = new ErrorCode(1_002_023_000, "邮箱账号不存在"); - ErrorCode MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS = new ErrorCode(1_002_023_001, "无法删除,该邮箱账号还有邮件模板"); - - // ========== 邮件模版 1-002-024-000 ========== - ErrorCode MAIL_TEMPLATE_NOT_EXISTS = new ErrorCode(1_002_024_000, "邮件模版不存在"); - ErrorCode MAIL_TEMPLATE_CODE_EXISTS = new ErrorCode(1_002_024_001, "邮件模版 code({}) 已存在"); - - // ========== 邮件发送 1-002-025-000 ========== - ErrorCode MAIL_SEND_TEMPLATE_PARAM_MISS = new ErrorCode(1_002_025_000, "模板参数({})缺失"); - ErrorCode MAIL_SEND_MAIL_NOT_EXISTS = new ErrorCode(1_002_025_001, "邮箱不存在"); - // ========== 站内信模版 1-002-026-000 ========== ErrorCode NOTIFY_TEMPLATE_NOT_EXISTS = new ErrorCode(1_002_026_000, "站内信模版不存在"); ErrorCode NOTIFY_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1_002_026_001, "已经存在编码为【{}】的站内信模板"); diff --git a/msgpush-module-system/msgpush-module-system-api/src/main/java/com/njcn/msgpush/module/system/enums/permission/RoleCodeEnum.java b/msgpush-module-system/msgpush-module-system-api/src/main/java/com/njcn/msgpush/module/system/enums/permission/RoleCodeEnum.java index bd40e70..2375691 100644 --- a/msgpush-module-system/msgpush-module-system-api/src/main/java/com/njcn/msgpush/module/system/enums/permission/RoleCodeEnum.java +++ b/msgpush-module-system/msgpush-module-system-api/src/main/java/com/njcn/msgpush/module/system/enums/permission/RoleCodeEnum.java @@ -11,9 +11,7 @@ import lombok.Getter; @AllArgsConstructor public enum RoleCodeEnum { - SUPER_ADMIN("super_admin", "超级管理员"), - TENANT_ADMIN("tenant_admin", "租户管理员"), - CRM_ADMIN("crm_admin", "CRM 管理员"); // CRM 系统专用 + SUPER_ADMIN("super_admin", "超级管理员"); // CRM 系统专用 ; /** diff --git a/msgpush-module-system/msgpush-module-system-server/pom.xml b/msgpush-module-system/msgpush-module-system-server/pom.xml index 7713dce..58f43b5 100644 --- a/msgpush-module-system/msgpush-module-system-server/pom.xml +++ b/msgpush-module-system/msgpush-module-system-server/pom.xml @@ -37,10 +37,6 @@ - - com.njcn - msgpush-spring-boot-starter-biz-tenant - com.njcn msgpush-spring-boot-starter-biz-ip diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/api/oauth2/OAuth2TokenApiImpl.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/api/oauth2/OAuth2TokenApiImpl.java index 68fd143..d2971c3 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/api/oauth2/OAuth2TokenApiImpl.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/api/oauth2/OAuth2TokenApiImpl.java @@ -3,7 +3,6 @@ package com.njcn.msgpush.module.system.api.oauth2; import com.njcn.msgpush.framework.common.biz.system.oauth2.OAuth2TokenCommonApi; import com.njcn.msgpush.framework.common.pojo.CommonResult; import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; import com.njcn.msgpush.framework.common.biz.system.oauth2.dto.OAuth2AccessTokenCheckRespDTO; import com.njcn.msgpush.framework.common.biz.system.oauth2.dto.OAuth2AccessTokenCreateReqDTO; import com.njcn.msgpush.framework.common.biz.system.oauth2.dto.OAuth2AccessTokenRespDTO; @@ -30,7 +29,6 @@ public class OAuth2TokenApiImpl implements OAuth2TokenCommonApi { } @Override - @TenantIgnore // 访问令牌校验时,无需传递租户编号;主要解决上传文件的场景,前端不会传递 tenant-id public CommonResult checkAccessToken(String accessToken) { OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.checkAccessToken(accessToken); return success(BeanUtils.toBean(accessTokenDO, OAuth2AccessTokenCheckRespDTO.class)); diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/api/tenant/TenantApiImpl.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/api/tenant/TenantApiImpl.java deleted file mode 100644 index f48b010..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/api/tenant/TenantApiImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.njcn.msgpush.module.system.api.tenant; - -import com.njcn.msgpush.framework.common.biz.system.tenant.TenantCommonApi; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; -import com.njcn.msgpush.module.system.service.tenant.TenantService; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RestController; - -import jakarta.annotation.Resource; -import java.util.List; - -import static com.njcn.msgpush.framework.common.pojo.CommonResult.success; - -@RestController // 提供 RESTful API 接口,给 Feign 调用 -@Validated -public class TenantApiImpl implements TenantCommonApi { - - @Resource - private TenantService tenantService; - - @Override - @TenantIgnore // 防止递归。避免调用 /rpc-api/system/tenant/valid 接口时,又去触发 /rpc-api/system/tenant/valid 去校验 - public CommonResult> getTenantIdList() { - return success(tenantService.getTenantIdList()); - } - - @Override - @TenantIgnore // 获得租户列表的时候,无需传递租户编号 - public CommonResult validTenant(Long id) { - tenantService.validTenant(id); - return success(true); - } - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/auth/AuthController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/auth/AuthController.http index 52a724b..fc3aabe 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/auth/AuthController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/auth/AuthController.http @@ -1,7 +1,7 @@ ### 请求 /login 接口 => 成功 POST {{baseUrl}}/system/auth/login Content-Type: application/json -tenant-id: {{adminTenantId}} + tag: Yunai.local { @@ -14,7 +14,7 @@ tag: Yunai.local ### 请求 /login 接口【加密 AES】 => 成功 POST {{baseUrl}}/system/auth/login Content-Type: application/json -tenant-id: {{adminTenantId}} + tag: Yunai.local X-API-ENCRYPT: true @@ -23,7 +23,7 @@ WvSX9MOrenyGfBhEM0g1/hHgq8ocktMZ9OwAJ6MOG5FUrzYF/rG5JF1eMptQM1wT73VgDS05l/37WeRt ### 请求 /login 接口【加密 RSA】 => 成功 POST {{baseUrl}}/system/auth/login Content-Type: application/json -tenant-id: {{adminTenantId}} + tag: Yunai.local X-API-ENCRYPT: true @@ -32,7 +32,7 @@ e7QZTork9ZV5CmgZvSd+cHZk3xdUxKtowLM02kOha+gxHK2H/daU8nVBYS3+bwuDRy5abf+Pz1QJJGVA ### 请求 /login 接口 => 成功(无验证码) POST {{baseUrl}}/system/auth/login Content-Type: application/json -tenant-id: {{adminTenantId}} + { "username": "admin", @@ -42,10 +42,10 @@ tenant-id: {{adminTenantId}} ### 请求 /get-permission-info 接口 => 成功 GET {{baseUrl}}/system/auth/get-permission-info Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + ### 请求 /list-menus 接口 => 成功 GET {{baseUrl}}/system/list-menus Authorization: Bearer {{token}} #Authorization: Bearer a6aa7714a2e44c95aaa8a2c5adc2a67a -tenant-id: {{adminTenantId}} + diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/captcha/CaptchaController.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/captcha/CaptchaController.java index 9fee5dc..54dd382 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/captcha/CaptchaController.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/captcha/CaptchaController.java @@ -2,7 +2,7 @@ package com.njcn.msgpush.module.system.controller.admin.captcha; import cn.hutool.core.util.StrUtil; import com.njcn.msgpush.framework.common.util.servlet.ServletUtils; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.anji.captcha.model.common.ResponseModel; import com.anji.captcha.model.vo.CaptchaVO; import com.anji.captcha.service.CaptchaService; @@ -27,7 +27,6 @@ public class CaptchaController { @PostMapping({"/get"}) @Operation(summary = "获得验证码") @PermitAll - @TenantIgnore public ResponseModel get(@RequestBody CaptchaVO data, HttpServletRequest request) { assert request.getRemoteHost() != null; data.setBrowserInfo(getRemoteId(request)); @@ -37,7 +36,6 @@ public class CaptchaController { @PostMapping("/check") @Operation(summary = "校验验证码") @PermitAll - @TenantIgnore public ResponseModel check(@RequestBody CaptchaVO data, HttpServletRequest request) { data.setBrowserInfo(getRemoteId(request)); return captchaService.check(data); diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/dict/DictDataController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/dict/DictDataController.http index 5a7ce8e..9a6d22f 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/dict/DictDataController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/dict/DictDataController.http @@ -1,4 +1,4 @@ ### 请求 /menu/list 接口 => 成功 GET {{baseUrl}}/system/dict-data/list-all-simple Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/ip/AreaController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/ip/AreaController.http index 1416561..86af08f 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/ip/AreaController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/ip/AreaController.http @@ -1,5 +1,5 @@ ### 获得地区树 GET {{baseUrl}}/system/area/tree Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/logger/OperateLogController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/logger/OperateLogController.http index be3102e..8e5f7bd 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/logger/OperateLogController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/logger/OperateLogController.http @@ -1,4 +1,4 @@ ### 请求 /system/operate-log/page 接口 => 成功 GET {{baseUrl}}/system/operate-log/page Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2ClientController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2ClientController.http index 7830fa2..e1a3202 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2ClientController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2ClientController.http @@ -2,7 +2,7 @@ POST {{baseUrl}}/system/oauth2-client/create Content-Type: application/json Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + { "id": "1", diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2OpenController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2OpenController.http index cdcebbf..7aed4d1 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2OpenController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2OpenController.http @@ -1,13 +1,13 @@ ### 请求 /system/oauth2/authorize 接口 => 成功 GET {{baseUrl}}/system/oauth2/authorize?clientId=default Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + ### 请求 /system/oauth2/authorize + token 接口 => 成功 POST {{baseUrl}}/system/oauth2/authorize Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + response_type=token&client_id=default&scope={"user.read": true}&redirect_uri=https://www.iocoder.cn&auto_approve=true @@ -15,7 +15,7 @@ response_type=token&client_id=default&scope={"user.read": true}&redirect_uri=htt POST {{baseUrl}}/system/oauth2/authorize Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + response_type=code&client_id=default&scope={"user.read": true}&redirect_uri=https://www.iocoder.cn&auto_approve=false @@ -23,7 +23,7 @@ response_type=code&client_id=default&scope={"user.read": true}&redirect_uri=http POST {{baseUrl}}/system/oauth2/token Content-Type: application/x-www-form-urlencoded Authorization: Basic ZGVmYXVsdDphZG1pbjEyMw== -tenant-id: {{adminTenantId}} + grant_type=authorization_code&redirect_uri=https://www.iocoder.cn&code=189956c07a174588a97157eabef2f93a @@ -31,7 +31,7 @@ grant_type=authorization_code&redirect_uri=https://www.iocoder.cn&code=189956c07 POST {{baseUrl}}/system/oauth2/token Content-Type: application/x-www-form-urlencoded Authorization: Basic ZGVmYXVsdDphZG1pbjEyMw== -tenant-id: {{adminTenantId}} + grant_type=password&username=admin&password=admin123&scope=user.read @@ -39,7 +39,7 @@ grant_type=password&username=admin&password=admin123&scope=user.read POST {{baseUrl}}/system/oauth2/token Content-Type: application/x-www-form-urlencoded Authorization: Basic ZGVmYXVsdDphZG1pbjEyMw== -tenant-id: {{adminTenantId}} + grant_type=client_credentials&scope=user.read @@ -47,16 +47,16 @@ grant_type=client_credentials&scope=user.read POST {{baseUrl}}/system/oauth2/token Content-Type: application/x-www-form-urlencoded Authorization: Basic ZGVmYXVsdDphZG1pbjEyMw== -tenant-id: {{adminTenantId}} + grant_type=refresh_token&refresh_token=00895465d6994f72a9d926ceeed0f588 ### 请求 /system/oauth2/token + DELETE 接口 => 成功 DELETE {{baseUrl}}/system/oauth2/token?token=ca8a188f464441d6949c51493a2b7596 Authorization: Basic ZGVmYXVsdDphZG1pbjEyMw== -tenant-id: {{adminTenantId}} + ### 请求 /system/oauth2/check-token 接口 => 成功 POST {{baseUrl}}/system/oauth2/check-token?token=620d307c5b4148df8a98dd6c6c547106 Authorization: Basic ZGVmYXVsdDphZG1pbjEyMw== -tenant-id: {{adminTenantId}} + diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2UserController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2UserController.http index 4450ea9..6ecbcac 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2UserController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/OAuth2UserController.http @@ -1,13 +1,13 @@ ### 请求 /system/oauth2/user/get 接口 => 成功 GET {{baseUrl}}/system/oauth2/user/get Authorization: Bearer 47f9c74ec11041f193b777ebb95c3b0d -tenant-id: {{adminTenantId}} + ### 请求 /system/oauth2/user/update 接口 => 成功 PUT {{baseUrl}}/system/oauth2/user/update Content-Type: application/json Authorization: Bearer 47f9c74ec11041f193b777ebb95c3b0d -tenant-id: {{adminTenantId}} + { "nickname": "灿能源码" diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/vo/open/OAuth2OpenCheckTokenRespVO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/vo/open/OAuth2OpenCheckTokenRespVO.java index 157fa7d..17028aa 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/vo/open/OAuth2OpenCheckTokenRespVO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/oauth2/vo/open/OAuth2OpenCheckTokenRespVO.java @@ -20,9 +20,6 @@ public class OAuth2OpenCheckTokenRespVO { @Schema(description = "用户类型,参见 UserTypeEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") @JsonProperty("user_type") private Integer userType; - @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @JsonProperty("tenant_id") - private Long tenantId; @Schema(description = "客户端编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "car") @JsonProperty("client_id") diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/MenuController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/MenuController.http index fbaff1e..60b40b0 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/MenuController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/MenuController.http @@ -1,4 +1,4 @@ ### 请求 /menu/list 接口 => 成功 GET {{baseUrl}}/system/menu/list Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/MenuController.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/MenuController.java index e02822c..ee180f9 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/MenuController.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/MenuController.java @@ -75,17 +75,6 @@ public class MenuController { return success(BeanUtils.toBean(list, MenuRespVO.class)); } - @GetMapping({"/list-all-simple", "simple-list"}) - @Operation(summary = "获取菜单精简信息列表", - description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。在多租户的场景下,会只返回租户所在套餐有的菜单") - public CommonResult> getSimpleMenuList() { - List list = menuService.getMenuListByTenant( - new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); - list = menuService.filterDisableMenus(list); - list.sort(Comparator.comparing(MenuDO::getSort)); - return success(BeanUtils.toBean(list, MenuSimpleRespVO.class)); - } - @GetMapping("/get") @Operation(summary = "获取菜单信息") @PreAuthorize("@ss.hasPermission('system:menu:query')") diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/PermissionController.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/PermissionController.java index cc0f96c..9a11e88 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/PermissionController.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/PermissionController.java @@ -6,7 +6,6 @@ import com.njcn.msgpush.module.system.controller.admin.permission.vo.permission. import com.njcn.msgpush.module.system.controller.admin.permission.vo.permission.PermissionAssignRoleMenuReqVO; import com.njcn.msgpush.module.system.controller.admin.permission.vo.permission.PermissionAssignUserRoleReqVO; import com.njcn.msgpush.module.system.service.permission.PermissionService; -import com.njcn.msgpush.module.system.service.tenant.TenantService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -32,8 +31,6 @@ public class PermissionController { @Resource private PermissionService permissionService; - @Resource - private TenantService tenantService; @Operation(summary = "获得角色拥有的菜单编号") @Parameter(name = "roleId", description = "角色编号", required = true) @@ -47,9 +44,6 @@ public class PermissionController { @Operation(summary = "赋予角色菜单") @PreAuthorize("@ss.hasPermission('system:permission:assign-role-menu')") public CommonResult assignRoleMenu(@Validated @RequestBody PermissionAssignRoleMenuReqVO reqVO) { - // 开启多租户的情况下,需要过滤掉未开通的菜单 - tenantService.handleTenantMenu(menuIds -> reqVO.getMenuIds().removeIf(menuId -> !CollUtil.contains(menuIds, menuId))); - // 执行菜单的分配 permissionService.assignRoleMenu(reqVO.getRoleId(), reqVO.getMenuIds()); return success(true); diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/RoleController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/RoleController.http index 375180a..d256b69 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/RoleController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/permission/RoleController.http @@ -2,7 +2,7 @@ POST {{baseUrl}}/system/role/create Authorization: Bearer {{token}} Content-Type: application/json -tenant-id: {{adminTenantId}} + { "name": "测试角色", @@ -14,7 +14,7 @@ tenant-id: {{adminTenantId}} POST {{baseUrl}}/system/role/update Authorization: Bearer {{token}} Content-Type: application/json -tenant-id: {{adminTenantId}} + { "id": 100, @@ -26,7 +26,7 @@ tenant-id: {{adminTenantId}} POST {{baseUrl}}/system/role/delete Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + roleId=14 @@ -34,9 +34,9 @@ roleId=14 GET {{baseUrl}}/system/role/get?id=100 Content-Type: application/x-www-form-urlencoded Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + ### /role/page 成功 GET {{baseUrl}}/system/role/page?pageNo=1&pageSize=10 Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/TenantController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/TenantController.http deleted file mode 100644 index 510b63a..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/TenantController.http +++ /dev/null @@ -1,21 +0,0 @@ -### 获取租户编号 /admin-api/system/get-id-by-name -GET {{baseUrl}}/system/tenant/get-id-by-name?name=灿能源码 - -### 创建租户 /admin-api/system/tenant/create -POST {{baseUrl}}/system/tenant/create -Content-Type: application/json -Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} - -{ - "name": "灿能", - "contactName": "芋艿", - "contactMobile": "15601691300", - "status": 0, - "domain": "https://www.iocoder.cn", - "packageId": 110, - "expireTime": 1699545600000, - "accountCount": 20, - "username": "admin", - "password": "123321" -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/TenantController.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/TenantController.java deleted file mode 100644 index 0b2dc6f..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/TenantController.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.njcn.msgpush.module.system.controller.admin.tenant; - -import com.njcn.msgpush.framework.apilog.core.annotation.ApiAccessLog; -import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.common.pojo.PageParam; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.framework.excel.core.util.ExcelUtils; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant.TenantRespVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantDO; -import com.njcn.msgpush.module.system.service.tenant.TenantService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.annotation.security.PermitAll; -import jakarta.servlet.http.HttpServletResponse; -import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import java.io.IOException; -import java.util.List; - -import static com.njcn.msgpush.framework.apilog.core.enums.OperateTypeEnum.EXPORT; -import static com.njcn.msgpush.framework.common.pojo.CommonResult.success; -import static com.njcn.msgpush.framework.common.util.collection.CollectionUtils.convertList; - -@Tag(name = "管理后台 - 租户") -@RestController -@RequestMapping("/system/tenant") -public class TenantController { - - @Resource - private TenantService tenantService; - - @GetMapping("/get-id-by-name") - @PermitAll - @TenantIgnore - @Operation(summary = "使用租户名,获得租户编号", description = "登录界面,根据用户的租户名,获得租户编号") - @Parameter(name = "name", description = "租户名", required = true, example = "1024") - public CommonResult getTenantIdByName(@RequestParam("name") String name) { - TenantDO tenant = tenantService.getTenantByName(name); - return success(tenant != null ? tenant.getId() : null); - } - - @GetMapping({ "simple-list" }) - @PermitAll - @TenantIgnore - @Operation(summary = "获取租户精简信息列表", description = "只包含被开启的租户,用于【首页】功能的选择租户选项") - public CommonResult> getTenantSimpleList() { - List list = tenantService.getTenantListByStatus(CommonStatusEnum.ENABLE.getStatus()); - return success(convertList(list, tenantDO -> - new TenantRespVO().setId(tenantDO.getId()).setName(tenantDO.getName()))); - } - - @GetMapping("/get-by-website") - @PermitAll - @TenantIgnore - @Operation(summary = "使用域名,获得租户信息", description = "登录界面,根据用户的域名,获得租户信息") - @Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn") - public CommonResult getTenantByWebsite(@RequestParam("website") String website) { - TenantDO tenant = tenantService.getTenantByWebsite(website); - if (tenant == null || CommonStatusEnum.isDisable(tenant.getStatus())) { - return success(null); - } - return success(new TenantRespVO().setId(tenant.getId()).setName(tenant.getName())); - } - - @PostMapping("/create") - @Operation(summary = "创建租户") - @PreAuthorize("@ss.hasPermission('system:tenant:create')") - public CommonResult createTenant(@Valid @RequestBody TenantSaveReqVO createReqVO) { - return success(tenantService.createTenant(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新租户") - @PreAuthorize("@ss.hasPermission('system:tenant:update')") - public CommonResult updateTenant(@Valid @RequestBody TenantSaveReqVO updateReqVO) { - tenantService.updateTenant(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除租户") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('system:tenant:delete')") - public CommonResult deleteTenant(@RequestParam("id") Long id) { - tenantService.deleteTenant(id); - return success(true); - } - - @DeleteMapping("/delete-list") - @Parameter(name = "ids", description = "编号列表", required = true) - @Operation(summary = "批量删除租户") - @PreAuthorize("@ss.hasPermission('system:tenant:delete')") - public CommonResult deleteTenantList(@RequestParam("ids") List ids) { - tenantService.deleteTenantList(ids); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得租户") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('system:tenant:query')") - public CommonResult getTenant(@RequestParam("id") Long id) { - TenantDO tenant = tenantService.getTenant(id); - return success(BeanUtils.toBean(tenant, TenantRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得租户分页") - @PreAuthorize("@ss.hasPermission('system:tenant:query')") - public CommonResult> getTenantPage(@Valid TenantPageReqVO pageVO) { - PageResult pageResult = tenantService.getTenantPage(pageVO); - return success(BeanUtils.toBean(pageResult, TenantRespVO.class)); - } - - @GetMapping("/export-excel") - @Operation(summary = "导出租户 Excel") - @PreAuthorize("@ss.hasPermission('system:tenant:export')") - @ApiAccessLog(operateType = EXPORT) - public void exportTenantExcel(@Valid TenantPageReqVO exportReqVO, HttpServletResponse response) throws IOException { - exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = tenantService.getTenantPage(exportReqVO).getList(); - // 导出 Excel - ExcelUtils.write(response, "租户.xls", "数据", TenantRespVO.class, - BeanUtils.toBean(list, TenantRespVO.class)); - } - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/TenantPackageController.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/TenantPackageController.java deleted file mode 100644 index fed9b76..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/TenantPackageController.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.njcn.msgpush.module.system.controller.admin.tenant; - -import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackageRespVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackageSimpleRespVO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantPackageDO; -import com.njcn.msgpush.module.system.service.tenant.TenantPackageService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.validation.Valid; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -import static com.njcn.msgpush.framework.common.pojo.CommonResult.success; - -@Tag(name = "管理后台 - 租户套餐") -@RestController -@RequestMapping("/system/tenant-package") -@Validated -public class TenantPackageController { - - @Resource - private TenantPackageService tenantPackageService; - - @PostMapping("/create") - @Operation(summary = "创建租户套餐") - @PreAuthorize("@ss.hasPermission('system:tenant-package:create')") - public CommonResult createTenantPackage(@Valid @RequestBody TenantPackageSaveReqVO createReqVO) { - return success(tenantPackageService.createTenantPackage(createReqVO)); - } - - @PutMapping("/update") - @Operation(summary = "更新租户套餐") - @PreAuthorize("@ss.hasPermission('system:tenant-package:update')") - public CommonResult updateTenantPackage(@Valid @RequestBody TenantPackageSaveReqVO updateReqVO) { - tenantPackageService.updateTenantPackage(updateReqVO); - return success(true); - } - - @DeleteMapping("/delete") - @Operation(summary = "删除租户套餐") - @Parameter(name = "id", description = "编号", required = true) - @PreAuthorize("@ss.hasPermission('system:tenant-package:delete')") - public CommonResult deleteTenantPackage(@RequestParam("id") Long id) { - tenantPackageService.deleteTenantPackage(id); - return success(true); - } - - @DeleteMapping("/delete-list") - @Parameter(name = "ids", description = "编号列表", required = true) - @Operation(summary = "批量删除租户套餐") - @PreAuthorize("@ss.hasPermission('system:tenant-package:delete')") - public CommonResult deleteTenantPackageList(@RequestParam("ids") List ids) { - tenantPackageService.deleteTenantPackageList(ids); - return success(true); - } - - @GetMapping("/get") - @Operation(summary = "获得租户套餐") - @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('system:tenant-package:query')") - public CommonResult getTenantPackage(@RequestParam("id") Long id) { - TenantPackageDO tenantPackage = tenantPackageService.getTenantPackage(id); - return success(BeanUtils.toBean(tenantPackage, TenantPackageRespVO.class)); - } - - @GetMapping("/page") - @Operation(summary = "获得租户套餐分页") - @PreAuthorize("@ss.hasPermission('system:tenant-package:query')") - public CommonResult> getTenantPackagePage(@Valid TenantPackagePageReqVO pageVO) { - PageResult pageResult = tenantPackageService.getTenantPackagePage(pageVO); - return success(BeanUtils.toBean(pageResult, TenantPackageRespVO.class)); - } - - @GetMapping({"/get-simple-list", "simple-list"}) - @Operation(summary = "获取租户套餐精简信息列表", description = "只包含被开启的租户套餐,主要用于前端的下拉选项") - public CommonResult> getTenantPackageList() { - List list = tenantPackageService.getTenantPackageListByStatus(CommonStatusEnum.ENABLE.getStatus()); - return success(BeanUtils.toBean(list, TenantPackageSimpleRespVO.class)); - } - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackagePageReqVO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackagePageReqVO.java deleted file mode 100644 index fa6a76e..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackagePageReqVO.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages; - -import com.njcn.msgpush.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static com.njcn.msgpush.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 租户套餐分页 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class TenantPackagePageReqVO extends PageParam { - - @Schema(description = "套餐名", example = "VIP") - private String name; - - @Schema(description = "状态", example = "1") - private Integer status; - - @Schema(description = "备注", example = "好") - private String remark; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "创建时间") - private LocalDateTime[] createTime; -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackageRespVO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackageRespVO.java deleted file mode 100644 index 96fbcbe..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackageRespVO.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.Set; - -@Schema(description = "管理后台 - 租户套餐 Response VO") -@Data -public class TenantPackageRespVO { - - @Schema(description = "套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long id; - - @Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "VIP") - private String name; - - @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer status; - - @Schema(description = "备注", example = "好") - private String remark; - - @Schema(description = "关联的菜单编号", requiredMode = Schema.RequiredMode.REQUIRED) - private Set menuIds; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime createTime; - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackageSaveReqVO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackageSaveReqVO.java deleted file mode 100644 index 43ae7bd..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackageSaveReqVO.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages; - -import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.common.validation.InEnum; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import java.util.Set; - -@Schema(description = "管理后台 - 租户套餐创建/修改 Request VO") -@Data -public class TenantPackageSaveReqVO { - - @Schema(description = "套餐编号", example = "1024") - private Long id; - - @Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "VIP") - @NotEmpty(message = "套餐名不能为空") - private String name; - - @Schema(description = "状态,参见 CommonStatusEnum 枚举", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "状态不能为空") - @InEnum(value = CommonStatusEnum.class, message = "状态必须是 {value}") - private Integer status; - - @Schema(description = "备注", example = "好") - private String remark; - - @Schema(description = "关联的菜单编号", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "关联的菜单编号不能为空") - private Set menuIds; - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackageSimpleRespVO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackageSimpleRespVO.java deleted file mode 100644 index 69a5bf1..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/packages/TenantPackageSimpleRespVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import jakarta.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 租户套餐精简 Response VO") -@Data -public class TenantPackageSimpleRespVO { - - @Schema(description = "套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "套餐编号不能为空") - private Long id; - - @Schema(description = "套餐名", requiredMode = Schema.RequiredMode.REQUIRED, example = "VIP") - @NotNull(message = "套餐名不能为空") - private String name; - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/tenant/TenantPageReqVO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/tenant/TenantPageReqVO.java deleted file mode 100644 index a41df1a..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/tenant/TenantPageReqVO.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant; - -import com.njcn.msgpush.framework.common.pojo.PageParam; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; -import org.springframework.format.annotation.DateTimeFormat; - -import java.time.LocalDateTime; - -import static com.njcn.msgpush.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -@Schema(description = "管理后台 - 租户分页 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class TenantPageReqVO extends PageParam { - - @Schema(description = "租户名", example = "灿能") - private String name; - - @Schema(description = "联系人", example = "芋艿") - private String contactName; - - @Schema(description = "联系手机", example = "15601691300") - private String contactMobile; - - @Schema(description = "租户状态(0正常 1停用)", example = "1") - private Integer status; - - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - @Schema(description = "创建时间") - private LocalDateTime[] createTime; - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/tenant/TenantRespVO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/tenant/TenantRespVO.java deleted file mode 100644 index 024b771..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/tenant/TenantRespVO.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant; - -import cn.idev.excel.annotation.ExcelIgnoreUnannotated; -import cn.idev.excel.annotation.ExcelProperty; -import com.njcn.msgpush.framework.excel.core.annotations.DictFormat; -import com.njcn.msgpush.framework.excel.core.convert.DictConvert; -import com.njcn.msgpush.module.system.enums.DictTypeConstants; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.time.LocalDateTime; -import java.util.List; - -@Schema(description = "管理后台 - 租户 Response VO") -@Data -@ExcelIgnoreUnannotated -public class TenantRespVO { - - @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @ExcelProperty("租户编号") - private Long id; - - @Schema(description = "租户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "灿能") - @ExcelProperty("租户名") - private String name; - - @Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @ExcelProperty("联系人") - private String contactName; - - @Schema(description = "联系手机", example = "15601691300") - @ExcelProperty("联系手机") - private String contactMobile; - - @Schema(description = "租户状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @ExcelProperty(value = "状态", converter = DictConvert.class) - @DictFormat(DictTypeConstants.COMMON_STATUS) - private Integer status; - - @Schema(description = "绑定域名数组", example = "https://www.iocoder.cn") - private List websites; - - @Schema(description = "租户套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long packageId; - - @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED) - private LocalDateTime expireTime; - - @Schema(description = "账号数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer accountCount; - - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/tenant/TenantSaveReqVO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/tenant/TenantSaveReqVO.java deleted file mode 100644 index a2393fd..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/tenant/vo/tenant/TenantSaveReqVO.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant; - -import cn.hutool.core.util.ObjectUtil; -import com.fasterxml.jackson.annotation.JsonIgnore; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.AssertTrue; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Pattern; -import jakarta.validation.constraints.Size; -import lombok.Data; -import org.hibernate.validator.constraints.Length; - -import java.time.LocalDateTime; -import java.util.List; - -@Schema(description = "管理后台 - 租户创建/修改 Request VO") -@Data -public class TenantSaveReqVO { - - @Schema(description = "租户编号", example = "1024") - private Long id; - - @Schema(description = "租户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "灿能") - @NotNull(message = "租户名不能为空") - private String name; - - @Schema(description = "联系人", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿") - @NotNull(message = "联系人不能为空") - private String contactName; - - @Schema(description = "联系手机", example = "15601691300") - private String contactMobile; - - @Schema(description = "租户状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - @NotNull(message = "租户状态") - private Integer status; - - @Schema(description = "绑定域名数组", example = "https://www.iocoder.cn") - private List websites; - - @Schema(description = "租户套餐编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "租户套餐编号不能为空") - private Long packageId; - - @Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "过期时间不能为空") - private LocalDateTime expireTime; - - @Schema(description = "账号数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - @NotNull(message = "账号数量不能为空") - private Integer accountCount; - - // ========== 仅【创建】时,需要传递的字段 ========== - - @Schema(description = "用户账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "msgpush") - @Pattern(regexp = "^[a-zA-Z0-9]{4,30}$", message = "用户账号由 数字、字母 组成") - @Size(min = 4, max = 30, message = "用户账号长度为 4-30 个字符") - private String username; - - @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456") - @Length(min = 4, max = 16, message = "密码长度为 4-16 位") - private String password; - - @AssertTrue(message = "用户账号、密码不能为空") - @JsonIgnore - public boolean isUsernameValid() { - return id != null // 修改时,不需要传递 - || (ObjectUtil.isAllNotEmpty(username, password)); // 新增时,必须都传递 username、password - } - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/user/UserController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/user/UserController.http index 0ca6915..d63fe0e 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/user/UserController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/user/UserController.http @@ -2,10 +2,9 @@ GET {{baseUrl}}/system/user/page?pageNo=1&pageSize=10 Authorization: Bearer {{token}} #Authorization: Bearer test100 -tenant-id: {{adminTenantId}} + ### 请求 /system/user/page 接口(测试访问别的租户) GET {{baseUrl}}/system/user/page?pageNo=1&pageSize=10 Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} -visit-tenant-id: 122 \ No newline at end of file + diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/user/UserProfileController.http b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/user/UserProfileController.http index c94c2ad..4001b83 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/user/UserProfileController.http +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/admin/user/UserProfileController.http @@ -1,4 +1,4 @@ ### 请求 /system/user/profile/get 接口 => 没有权限 GET {{baseUrl}}/system/user/profile/get Authorization: Bearer {{token}} -tenant-id: {{adminTenantId}} + diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/app/tenant/AppTenantController.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/app/tenant/AppTenantController.java deleted file mode 100644 index 540c7ba..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/app/tenant/AppTenantController.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.njcn.msgpush.module.system.controller.app.tenant; - -import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.common.pojo.CommonResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; -import com.njcn.msgpush.module.system.controller.app.tenant.vo.AppTenantRespVO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantDO; -import com.njcn.msgpush.module.system.service.tenant.TenantService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.annotation.Resource; -import jakarta.annotation.security.PermitAll; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import static com.njcn.msgpush.framework.common.pojo.CommonResult.success; - -@Tag(name = "用户 App - 租户") -@RestController -@RequestMapping("/system/tenant") -public class AppTenantController { - - @Resource - private TenantService tenantService; - - @GetMapping("/get-by-website") - @PermitAll - @TenantIgnore - @Operation(summary = "使用域名,获得租户信息", description = "根据用户的域名,获得租户信息") - @Parameter(name = "website", description = "域名", required = true, example = "www.iocoder.cn") - public CommonResult getTenantByWebsite(@RequestParam("website") String website) { - TenantDO tenant = tenantService.getTenantByWebsite(website); - if (tenant == null || CommonStatusEnum.isDisable(tenant.getStatus())) { - return success(null); - } - return success(BeanUtils.toBean(tenant, AppTenantRespVO.class)); - } - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/app/tenant/vo/AppTenantRespVO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/app/tenant/vo/AppTenantRespVO.java deleted file mode 100644 index 0ed5bdd..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/controller/app/tenant/vo/AppTenantRespVO.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.njcn.msgpush.module.system.controller.app.tenant.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -@Schema(description = "用户 App - 租户 Response VO") -@Data -public class AppTenantRespVO { - - @Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Long id; - - @Schema(description = "租户名", requiredMode = Schema.RequiredMode.REQUIRED, example = "灿能") - private String name; - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/convert/tenant/TenantConvert.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/convert/tenant/TenantConvert.java deleted file mode 100644 index 1b2b611..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/convert/tenant/TenantConvert.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.njcn.msgpush.module.system.convert.tenant; - -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; -import com.njcn.msgpush.module.system.controller.admin.user.vo.user.UserSaveReqVO; -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -/** - * 租户 Convert - * - * @author hongawen - */ -@Mapper -public interface TenantConvert { - - TenantConvert INSTANCE = Mappers.getMapper(TenantConvert.class); - - default UserSaveReqVO convert02(TenantSaveReqVO bean) { - UserSaveReqVO reqVO = new UserSaveReqVO(); - reqVO.setUsername(bean.getUsername()); - reqVO.setPassword(bean.getPassword()); - reqVO.setNickname(bean.getContactName()).setMobile(bean.getContactMobile()); - return reqVO; - } - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dept/DeptDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dept/DeptDO.java index c996b37..e4928ce 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dept/DeptDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dept/DeptDO.java @@ -1,7 +1,7 @@ package com.njcn.msgpush.module.system.dal.dataobject.dept; import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.tenant.core.db.TenantBaseDO; +import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; import com.njcn.msgpush.module.system.dal.dataobject.user.AdminUserDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; @@ -19,7 +19,7 @@ import lombok.EqualsAndHashCode; @KeySequence("system_dept_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) -public class DeptDO extends TenantBaseDO { +public class DeptDO extends BaseDO { public static final Long PARENT_ID_ROOT = 0L; diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dict/DictDataDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dict/DictDataDO.java index 19fbe8d..baf8ab3 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dict/DictDataDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dict/DictDataDO.java @@ -2,7 +2,6 @@ package com.njcn.msgpush.module.system.dal.dataobject.dict; import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import lombok.EqualsAndHashCode; @@ -16,7 +15,6 @@ import lombok.EqualsAndHashCode; @KeySequence("system_dict_data_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) -@TenantIgnore public class DictDataDO extends BaseDO { /** diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dict/DictTypeDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dict/DictTypeDO.java index 0827c12..b6280a7 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dict/DictTypeDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/dict/DictTypeDO.java @@ -2,7 +2,6 @@ package com.njcn.msgpush.module.system.dal.dataobject.dict; import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -23,7 +22,6 @@ import java.time.LocalDateTime; @Builder @NoArgsConstructor @AllArgsConstructor -@TenantIgnore public class DictTypeDO extends BaseDO { /** diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailAccountDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailAccountDO.java index 094b7e9..c9280bb 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailAccountDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailAccountDO.java @@ -1,7 +1,7 @@ package com.njcn.msgpush.module.system.dal.dataobject.mail; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -20,7 +20,6 @@ import lombok.EqualsAndHashCode; @KeySequence("system_mail_account_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) -@TenantIgnore public class MailAccountDO extends BaseDO { /** diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailLogDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailLogDO.java index af6a124..db1a338 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailLogDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailLogDO.java @@ -3,7 +3,7 @@ package com.njcn.msgpush.module.system.dal.dataobject.mail; import com.njcn.msgpush.framework.common.enums.UserTypeEnum; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; import com.njcn.msgpush.framework.mybatis.core.type.StringListTypeHandler; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.system.enums.mail.MailSendStatusEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; @@ -31,7 +31,6 @@ import java.util.Map; @Builder @AllArgsConstructor @NoArgsConstructor -@TenantIgnore public class MailLogDO extends BaseDO implements Serializable { /** diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailTemplateDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailTemplateDO.java index 42469d9..a324408 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailTemplateDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/mail/MailTemplateDO.java @@ -2,7 +2,7 @@ package com.njcn.msgpush.module.system.dal.dataobject.mail; import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; @@ -22,7 +22,6 @@ import java.util.List; @KeySequence("system_mail_template_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) -@TenantIgnore public class MailTemplateDO extends BaseDO { /** diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/notify/NotifyTemplateDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/notify/NotifyTemplateDO.java index badaaac..d057a5b 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/notify/NotifyTemplateDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/notify/NotifyTemplateDO.java @@ -2,7 +2,7 @@ package com.njcn.msgpush.module.system.dal.dataobject.notify; import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; @@ -25,7 +25,6 @@ import java.util.List; @Builder @NoArgsConstructor @AllArgsConstructor -@TenantIgnore public class NotifyTemplateDO extends BaseDO { /** diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2AccessTokenDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2AccessTokenDO.java index 1f1338b..6f3874c 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2AccessTokenDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2AccessTokenDO.java @@ -1,12 +1,12 @@ package com.njcn.msgpush.module.system.dal.dataobject.oauth2; import com.njcn.msgpush.framework.common.enums.UserTypeEnum; -import com.njcn.msgpush.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; import lombok.Data; import lombok.EqualsAndHashCode; @@ -26,7 +26,7 @@ import java.util.Map; @KeySequence("system_oauth2_access_token_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) -public class OAuth2AccessTokenDO extends TenantBaseDO { +public class OAuth2AccessTokenDO extends BaseDO { /** * 编号,数据库递增 diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2ClientDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2ClientDO.java index 037453f..77a8f9e 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2ClientDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2ClientDO.java @@ -2,7 +2,7 @@ package com.njcn.msgpush.module.system.dal.dataobject.oauth2; import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.system.enums.oauth2.OAuth2GrantTypeEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; @@ -23,7 +23,6 @@ import java.util.List; @KeySequence("system_oauth2_client_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) -@TenantIgnore public class OAuth2ClientDO extends BaseDO { /** diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2RefreshTokenDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2RefreshTokenDO.java index f3230e9..8be1dd2 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2RefreshTokenDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/oauth2/OAuth2RefreshTokenDO.java @@ -1,11 +1,11 @@ package com.njcn.msgpush.module.system.dal.dataobject.oauth2; import com.njcn.msgpush.framework.common.enums.UserTypeEnum; -import com.njcn.msgpush.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; +import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; import lombok.Data; import java.time.LocalDateTime; @@ -20,7 +20,7 @@ import java.util.List; // 由于 Oracle 的 SEQ 的名字长度有限制,所以就先用 system_oauth2_access_token_seq 吧,反正也没啥问题 @KeySequence("system_oauth2_access_token_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data -public class OAuth2RefreshTokenDO extends TenantBaseDO { +public class OAuth2RefreshTokenDO extends BaseDO { /** * 编号,数据库字典 diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/MenuDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/MenuDO.java index 11577a7..bfd8f6f 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/MenuDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/MenuDO.java @@ -2,7 +2,7 @@ package com.njcn.msgpush.module.system.dal.dataobject.permission; import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.system.enums.permission.MenuTypeEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; @@ -19,7 +19,6 @@ import lombok.EqualsAndHashCode; @KeySequence("system_menu_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) -@TenantIgnore public class MenuDO extends BaseDO { /** diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/RoleDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/RoleDO.java index 7e60178..0636a8d 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/RoleDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/RoleDO.java @@ -1,7 +1,7 @@ package com.njcn.msgpush.module.system.dal.dataobject.permission; import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.tenant.core.db.TenantBaseDO; +import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; import com.njcn.msgpush.module.system.enums.permission.DataScopeEnum; import com.njcn.msgpush.module.system.enums.permission.RoleTypeEnum; import com.baomidou.mybatisplus.annotation.KeySequence; @@ -23,7 +23,7 @@ import java.util.Set; @KeySequence("system_role_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) -public class RoleDO extends TenantBaseDO { +public class RoleDO extends BaseDO { /** * 角色ID diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/RoleMenuDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/RoleMenuDO.java index ad676ac..db202fb 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/RoleMenuDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/permission/RoleMenuDO.java @@ -1,9 +1,9 @@ package com.njcn.msgpush.module.system.dal.dataobject.permission; -import com.njcn.msgpush.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; import lombok.Data; import lombok.EqualsAndHashCode; @@ -16,7 +16,7 @@ import lombok.EqualsAndHashCode; @KeySequence("system_role_menu_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) -public class RoleMenuDO extends TenantBaseDO { +public class RoleMenuDO extends BaseDO { /** * 自增主键 diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/tenant/TenantDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/tenant/TenantDO.java deleted file mode 100644 index 43fc049..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/tenant/TenantDO.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.njcn.msgpush.module.system.dal.dataobject.tenant; - -import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.mybatis.core.type.StringListTypeHandler; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; -import com.njcn.msgpush.module.system.dal.dataobject.user.AdminUserDO; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.*; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * 租户 DO - * - * @author hongawen - */ -@TableName(value = "system_tenant", autoResultMap = true) -@KeySequence("system_tenant_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@AllArgsConstructor -@NoArgsConstructor -@TenantIgnore -public class TenantDO extends BaseDO { - - /** - * 套餐编号 - 系统 - */ - public static final Long PACKAGE_ID_SYSTEM = 0L; - - /** - * 租户编号,自增 - */ - private Long id; - /** - * 租户名,唯一 - */ - private String name; - /** - * 联系人的用户编号 - * - * 关联 {@link AdminUserDO#getId()} - */ - private Long contactUserId; - /** - * 联系人 - */ - private String contactName; - /** - * 联系手机 - */ - private String contactMobile; - /** - * 租户状态 - * - * 枚举 {@link CommonStatusEnum} - */ - private Integer status; - /** - * 绑定域名列表 - * - * 1. 考虑到对微信小程序的兼容,也允许传递 appid - * 2. 为什么是数组,考虑到管理后台、会员前台都有独立的域名,又或者多个管理后台 - */ - @TableField(typeHandler = StringListTypeHandler.class) - private List websites; - /** - * 租户套餐编号 - * - * 关联 {@link TenantPackageDO#getId()} - * 特殊逻辑:系统内置租户,不使用套餐,暂时使用 {@link #PACKAGE_ID_SYSTEM} 标识 - */ - private Long packageId; - /** - * 过期时间 - */ - private LocalDateTime expireTime; - /** - * 账号数量 - */ - private Integer accountCount; - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/tenant/TenantPackageDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/tenant/TenantPackageDO.java deleted file mode 100644 index df8f586..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/tenant/TenantPackageDO.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.njcn.msgpush.module.system.dal.dataobject.tenant; - -import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; -import com.baomidou.mybatisplus.annotation.KeySequence; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; -import lombok.*; - -import java.util.Set; - -/** - * 租户套餐 DO - * - * @author hongawen - */ -@TableName(value = "system_tenant_package", autoResultMap = true) -@KeySequence("system_tenant_package_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -@Builder -@AllArgsConstructor -@NoArgsConstructor -@TenantIgnore -public class TenantPackageDO extends BaseDO { - - /** - * 套餐编号,自增 - */ - private Long id; - /** - * 套餐名,唯一 - */ - private String name; - /** - * 租户套餐状态 - * - * 枚举 {@link CommonStatusEnum} - */ - private Integer status; - /** - * 备注 - */ - private String remark; - /** - * 关联的菜单编号 - */ - @TableField(typeHandler = JacksonTypeHandler.class) - private Set menuIds; - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/user/AdminUserDO.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/user/AdminUserDO.java index 2ffdfe2..53b20a2 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/user/AdminUserDO.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/dataobject/user/AdminUserDO.java @@ -1,7 +1,7 @@ package com.njcn.msgpush.module.system.dal.dataobject.user; import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.tenant.core.db.TenantBaseDO; +import com.njcn.msgpush.framework.mybatis.core.dataobject.BaseDO; import com.njcn.msgpush.module.system.enums.common.SexEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; @@ -26,7 +26,7 @@ import java.util.Set; @Builder @NoArgsConstructor @AllArgsConstructor -public class AdminUserDO extends TenantBaseDO { +public class AdminUserDO extends BaseDO { /** * 用户ID diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/oauth2/OAuth2AccessTokenMapper.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/oauth2/OAuth2AccessTokenMapper.java index 2d724c6..aaaa701 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/oauth2/OAuth2AccessTokenMapper.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/oauth2/OAuth2AccessTokenMapper.java @@ -3,7 +3,7 @@ package com.njcn.msgpush.module.system.dal.mysql.oauth2; import com.njcn.msgpush.framework.common.pojo.PageResult; import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenPageReqVO; import com.njcn.msgpush.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; import org.apache.ibatis.annotations.Mapper; @@ -14,7 +14,6 @@ import java.util.List; @Mapper public interface OAuth2AccessTokenMapper extends BaseMapperX { - @TenantIgnore // 获取 token 的时候,需要忽略租户编号。原因是:一些场景下,可能不会传递 tenant-id 请求头,例如说文件上传、积木报表等等 default OAuth2AccessTokenDO selectByAccessToken(String accessToken) { return selectOne(OAuth2AccessTokenDO::getAccessToken, accessToken); } diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/oauth2/OAuth2RefreshTokenMapper.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/oauth2/OAuth2RefreshTokenMapper.java index 8c72f43..ba5103d 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/oauth2/OAuth2RefreshTokenMapper.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/oauth2/OAuth2RefreshTokenMapper.java @@ -2,7 +2,7 @@ package com.njcn.msgpush.module.system.dal.mysql.oauth2; import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.njcn.msgpush.framework.tenant.core.aop.TenantIgnore; + import com.njcn.msgpush.module.system.dal.dataobject.oauth2.OAuth2RefreshTokenDO; import org.apache.ibatis.annotations.Mapper; @@ -14,7 +14,6 @@ public interface OAuth2RefreshTokenMapper extends BaseMapperX { - - default PageResult selectPage(TenantPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(TenantDO::getName, reqVO.getName()) - .likeIfPresent(TenantDO::getContactName, reqVO.getContactName()) - .likeIfPresent(TenantDO::getContactMobile, reqVO.getContactMobile()) - .eqIfPresent(TenantDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(TenantDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(TenantDO::getId)); - } - - default TenantDO selectByName(String name) { - return selectOne(TenantDO::getName, name); - } - - default List selectListByWebsite(String website) { - return selectList(new LambdaQueryWrapperX() - .apply(MyBatisUtils.findInSet("websites", website))); - } - - default Long selectCountByPackageId(Long packageId) { - return selectCount(TenantDO::getPackageId, packageId); - } - - default List selectListByPackageId(Long packageId) { - return selectList(TenantDO::getPackageId, packageId); - } - - default List selectListByStatus(Integer status) { - return selectList(TenantDO::getStatus, status); - } - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/tenant/TenantPackageMapper.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/tenant/TenantPackageMapper.java deleted file mode 100644 index b450901..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/dal/mysql/tenant/TenantPackageMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.njcn.msgpush.module.system.dal.mysql.tenant; - -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.mybatis.core.mapper.BaseMapperX; -import com.njcn.msgpush.framework.mybatis.core.query.LambdaQueryWrapperX; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantPackageDO; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; - -@Mapper -public interface TenantPackageMapper extends BaseMapperX { - - default PageResult selectPage(TenantPackagePageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .likeIfPresent(TenantPackageDO::getName, reqVO.getName()) - .eqIfPresent(TenantPackageDO::getStatus, reqVO.getStatus()) - .likeIfPresent(TenantPackageDO::getRemark, reqVO.getRemark()) - .betweenIfPresent(TenantPackageDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(TenantPackageDO::getId)); - } - - default List selectListByStatus(Integer status) { - return selectList(TenantPackageDO::getStatus, status); - } - - default TenantPackageDO selectByName(String name) { - return selectOne(TenantPackageDO::getName, name); - } -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/oauth2/OAuth2TokenServiceImpl.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/oauth2/OAuth2TokenServiceImpl.java index 2908a76..cd5635e 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/oauth2/OAuth2TokenServiceImpl.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/oauth2/OAuth2TokenServiceImpl.java @@ -11,8 +11,6 @@ import com.njcn.msgpush.framework.common.pojo.PageResult; import com.njcn.msgpush.framework.common.util.date.DateUtils; import com.njcn.msgpush.framework.common.util.object.BeanUtils; import com.njcn.msgpush.framework.security.core.LoginUser; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.tenant.core.util.TenantUtils; import com.njcn.msgpush.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenPageReqVO; import com.njcn.msgpush.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; import com.njcn.msgpush.module.system.dal.dataobject.oauth2.OAuth2ClientDO; @@ -180,13 +178,6 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { .setClientId(clientDO.getClientId()).setScopes(refreshTokenDO.getScopes()) .setRefreshToken(refreshTokenDO.getRefreshToken()) .setExpiresTime(LocalDateTime.now().plusSeconds(clientDO.getAccessTokenValiditySeconds())); - // 优先从 refreshToken 获取租户编号,避免 ThreadLocal 被污染时导致 tenantId 为 null - // 可能关联的 issue:https://t.zsxq.com/JIi5G - Long tenantId = refreshTokenDO.getTenantId(); - if (tenantId == null) { - tenantId = TenantContextHolder.getTenantId(); - } - accessTokenDO.setTenantId(tenantId); oauth2AccessTokenMapper.insert(accessTokenDO); // 记录到 Redis 中 oauth2AccessTokenRedisDAO.set(accessTokenDO); @@ -205,8 +196,7 @@ public class OAuth2TokenServiceImpl implements OAuth2TokenService { private OAuth2AccessTokenDO convertToAccessToken(OAuth2RefreshTokenDO refreshTokenDO) { OAuth2AccessTokenDO accessTokenDO = BeanUtils.toBean(refreshTokenDO, OAuth2AccessTokenDO.class) .setAccessToken(refreshTokenDO.getRefreshToken()); - TenantUtils.execute(refreshTokenDO.getTenantId(), - () -> accessTokenDO.setUserInfo(buildUserInfo(refreshTokenDO.getUserId(), refreshTokenDO.getUserType()))); + accessTokenDO.setUserInfo(buildUserInfo(refreshTokenDO.getUserId(), refreshTokenDO.getUserType())); return accessTokenDO; } diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/permission/MenuService.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/permission/MenuService.java index 1b8afb1..8c3b7ed 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/permission/MenuService.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/permission/MenuService.java @@ -50,14 +50,6 @@ public interface MenuService { */ List getMenuList(); - /** - * 基于租户,筛选菜单列表 - * 注意,如果是系统租户,返回的还是全菜单 - * - * @param reqVO 筛选条件请求 VO - * @return 菜单列表 - */ - List getMenuListByTenant(MenuListReqVO reqVO); /** * 过滤掉关闭的菜单及其子菜单 diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/permission/MenuServiceImpl.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/permission/MenuServiceImpl.java index 215c972..30d6d78 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/permission/MenuServiceImpl.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/permission/MenuServiceImpl.java @@ -11,7 +11,6 @@ import com.njcn.msgpush.module.system.dal.dataobject.permission.MenuDO; import com.njcn.msgpush.module.system.dal.mysql.permission.MenuMapper; import com.njcn.msgpush.module.system.dal.redis.RedisKeyConstants; import com.njcn.msgpush.module.system.enums.permission.MenuTypeEnum; -import com.njcn.msgpush.module.system.service.tenant.TenantService; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; import jakarta.annotation.Resource; @@ -43,9 +42,6 @@ public class MenuServiceImpl implements MenuService { private MenuMapper menuMapper; @Resource private PermissionService permissionService; - @Resource - @Lazy // 延迟,避免循环依赖报错 - private TenantService tenantService; @Override @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, key = "#createReqVO.permission", @@ -127,15 +123,6 @@ public class MenuServiceImpl implements MenuService { return menuMapper.selectList(); } - @Override - public List getMenuListByTenant(MenuListReqVO reqVO) { - // 查询所有菜单,并过滤掉关闭的节点 - List menus = getMenuList(reqVO); - // 开启多租户的情况下,需要过滤掉未开通的菜单 - tenantService.handleTenantMenu(menuIds -> menus.removeIf(menu -> !CollUtil.contains(menuIds, menu.getId()))); - return menus; - } - @Override public List filterDisableMenus(List menuList) { if (CollUtil.isEmpty(menuList)){ diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantPackageService.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantPackageService.java deleted file mode 100644 index 3816fbc..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantPackageService.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.njcn.msgpush.module.system.service.tenant; - -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantPackageDO; -import jakarta.validation.Valid; - -import java.util.List; - -/** - * 租户套餐 Service 接口 - * - * @author hongawen - */ -public interface TenantPackageService { - - /** - * 创建租户套餐 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createTenantPackage(@Valid TenantPackageSaveReqVO createReqVO); - - /** - * 更新租户套餐 - * - * @param updateReqVO 更新信息 - */ - void updateTenantPackage(@Valid TenantPackageSaveReqVO updateReqVO); - - /** - * 删除租户套餐 - * - * @param id 编号 - */ - void deleteTenantPackage(Long id); - - /** - * 批量删除租户套餐 - * - * @param ids 编号数组 - */ - void deleteTenantPackageList(List ids); - - /** - * 获得租户套餐 - * - * @param id 编号 - * @return 租户套餐 - */ - TenantPackageDO getTenantPackage(Long id); - - /** - * 获得租户套餐分页 - * - * @param pageReqVO 分页查询 - * @return 租户套餐分页 - */ - PageResult getTenantPackagePage(TenantPackagePageReqVO pageReqVO); - - /** - * 校验租户套餐 - * - * @param id 编号 - * @return 租户套餐 - */ - TenantPackageDO validTenantPackage(Long id); - - /** - * 获得指定状态的租户套餐列表 - * - * @param status 状态 - * @return 租户套餐 - */ - List getTenantPackageListByStatus(Integer status); - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantPackageServiceImpl.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantPackageServiceImpl.java deleted file mode 100644 index 7b2c6d8..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantPackageServiceImpl.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.njcn.msgpush.module.system.service.tenant; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.StrUtil; -import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantDO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantPackageDO; -import com.njcn.msgpush.module.system.dal.mysql.tenant.TenantPackageMapper; -import com.baomidou.dynamic.datasource.annotation.DSTransactional; -import com.google.common.annotations.VisibleForTesting; -import jakarta.annotation.Resource; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.util.List; - -import static com.njcn.msgpush.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.njcn.msgpush.module.system.enums.ErrorCodeConstants.*; - -/** - * 租户套餐 Service 实现类 - * - * @author hongawen - */ -@Service -@Validated -public class TenantPackageServiceImpl implements TenantPackageService { - - @Resource - private TenantPackageMapper tenantPackageMapper; - - @Resource - @Lazy // 避免循环依赖的报错 - private TenantService tenantService; - - @Override - public Long createTenantPackage(TenantPackageSaveReqVO createReqVO) { - // 校验套餐名是否重复 - validateTenantPackageNameUnique(null, createReqVO.getName()); - // 插入 - TenantPackageDO tenantPackage = BeanUtils.toBean(createReqVO, TenantPackageDO.class); - tenantPackageMapper.insert(tenantPackage); - // 返回 - return tenantPackage.getId(); - } - - @Override - @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 - public void updateTenantPackage(TenantPackageSaveReqVO updateReqVO) { - // 校验存在 - TenantPackageDO tenantPackage = validateTenantPackageExists(updateReqVO.getId()); - // 校验套餐名是否重复 - validateTenantPackageNameUnique(updateReqVO.getId(), updateReqVO.getName()); - // 更新 - TenantPackageDO updateObj = BeanUtils.toBean(updateReqVO, TenantPackageDO.class); - tenantPackageMapper.updateById(updateObj); - // 如果菜单发生变化,则修改每个租户的菜单 - if (!CollUtil.isEqualList(tenantPackage.getMenuIds(), updateReqVO.getMenuIds())) { - List tenants = tenantService.getTenantListByPackageId(tenantPackage.getId()); - tenants.forEach(tenant -> tenantService.updateTenantRoleMenu(tenant.getId(), updateReqVO.getMenuIds())); - } - } - - @Override - public void deleteTenantPackage(Long id) { - // 校验存在 - validateTenantPackageExists(id); - // 校验正在使用 - validateTenantUsed(id); - // 删除 - tenantPackageMapper.deleteById(id); - } - - @Override - public void deleteTenantPackageList(List ids) { - // 1. 校验是否有租户正在使用该套餐 - for (Long id : ids) { - if (tenantService.getTenantCountByPackageId(id) > 0) { - throw exception(TENANT_PACKAGE_USED); - } - } - - // 2. 批量删除 - tenantPackageMapper.deleteByIds(ids); - } - - private TenantPackageDO validateTenantPackageExists(Long id) { - TenantPackageDO tenantPackage = tenantPackageMapper.selectById(id); - if (tenantPackage == null) { - throw exception(TENANT_PACKAGE_NOT_EXISTS); - } - return tenantPackage; - } - - private void validateTenantUsed(Long id) { - if (tenantService.getTenantCountByPackageId(id) > 0) { - throw exception(TENANT_PACKAGE_USED); - } - } - - @Override - public TenantPackageDO getTenantPackage(Long id) { - return tenantPackageMapper.selectById(id); - } - - @Override - public PageResult getTenantPackagePage(TenantPackagePageReqVO pageReqVO) { - return tenantPackageMapper.selectPage(pageReqVO); - } - - @Override - public TenantPackageDO validTenantPackage(Long id) { - TenantPackageDO tenantPackage = tenantPackageMapper.selectById(id); - if (tenantPackage == null) { - throw exception(TENANT_PACKAGE_NOT_EXISTS); - } - if (tenantPackage.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) { - throw exception(TENANT_PACKAGE_DISABLE, tenantPackage.getName()); - } - return tenantPackage; - } - - @Override - public List getTenantPackageListByStatus(Integer status) { - return tenantPackageMapper.selectListByStatus(status); - } - - - @VisibleForTesting - void validateTenantPackageNameUnique(Long id, String name) { - if (StrUtil.isBlank(name)) { - return; - } - TenantPackageDO tenantPackage = tenantPackageMapper.selectByName(name); - if (tenantPackage == null) { - return; - } - // 如果 id 为空,说明不用比较是否为相同 id 的用户 - if (id == null) { - throw exception(TENANT_PACKAGE_NAME_DUPLICATE); - } - if (!tenantPackage.getId().equals(id)) { - throw exception(TENANT_PACKAGE_NAME_DUPLICATE); - } - } - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantService.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantService.java deleted file mode 100644 index 32ce1d0..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantService.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.njcn.msgpush.module.system.service.tenant; - -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantDO; -import com.njcn.msgpush.module.system.service.tenant.handler.TenantInfoHandler; -import com.njcn.msgpush.module.system.service.tenant.handler.TenantMenuHandler; -import jakarta.validation.Valid; - -import java.util.List; -import java.util.Set; - -/** - * 租户 Service 接口 - * - * @author hongawen - */ -public interface TenantService { - - /** - * 创建租户 - * - * @param createReqVO 创建信息 - * @return 编号 - */ - Long createTenant(@Valid TenantSaveReqVO createReqVO); - - /** - * 更新租户 - * - * @param updateReqVO 更新信息 - */ - void updateTenant(@Valid TenantSaveReqVO updateReqVO); - - /** - * 更新租户的角色菜单 - * - * @param tenantId 租户编号 - * @param menuIds 菜单编号数组 - */ - void updateTenantRoleMenu(Long tenantId, Set menuIds); - - /** - * 删除租户 - * - * @param id 编号 - */ - void deleteTenant(Long id); - - /** - * 批量删除租户 - * - * @param ids 编号数组 - */ - void deleteTenantList(List ids); - - /** - * 获得租户 - * - * @param id 编号 - * @return 租户 - */ - TenantDO getTenant(Long id); - - /** - * 获得租户分页 - * - * @param pageReqVO 分页查询 - * @return 租户分页 - */ - PageResult getTenantPage(TenantPageReqVO pageReqVO); - - /** - * 获得名字对应的租户 - * - * @param name 租户名 - * @return 租户 - */ - TenantDO getTenantByName(String name); - - /** - * 获得域名对应的租户 - * - * @param website 域名 - * @return 租户 - */ - TenantDO getTenantByWebsite(String website); - - /** - * 获得使用指定套餐的租户数量 - * - * @param packageId 租户套餐编号 - * @return 租户数量 - */ - Long getTenantCountByPackageId(Long packageId); - - /** - * 获得使用指定套餐的租户数组 - * - * @param packageId 租户套餐编号 - * @return 租户数组 - */ - List getTenantListByPackageId(Long packageId); - - /** - * 获得指定状态的租户列表 - * - * @param status 状态 - * @return 租户列表 - */ - List getTenantListByStatus(Integer status); - - /** - * 进行租户的信息处理逻辑 - * 其中,租户编号从 {@link TenantContextHolder} 上下文中获取 - * - * @param handler 处理器 - */ - void handleTenantInfo(TenantInfoHandler handler); - - /** - * 进行租户的菜单处理逻辑 - * 其中,租户编号从 {@link TenantContextHolder} 上下文中获取 - * - * @param handler 处理器 - */ - void handleTenantMenu(TenantMenuHandler handler); - - /** - * 获得所有租户 - * - * @return 租户编号数组 - */ - List getTenantIdList(); - - /** - * 校验租户是否合法 - * - * @param id 租户编号 - */ - void validTenant(Long id); - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantServiceImpl.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantServiceImpl.java deleted file mode 100644 index 5ca5f93..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/TenantServiceImpl.java +++ /dev/null @@ -1,318 +0,0 @@ -package com.njcn.msgpush.module.system.service.tenant; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.lang.Assert; -import cn.hutool.core.util.ObjectUtil; -import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.common.util.collection.CollectionUtils; -import com.njcn.msgpush.framework.common.util.date.DateUtils; -import com.njcn.msgpush.framework.common.util.object.BeanUtils; -import com.njcn.msgpush.framework.tenant.config.TenantProperties; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.tenant.core.util.TenantUtils; -import com.njcn.msgpush.module.system.controller.admin.permission.vo.role.RoleSaveReqVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; -import com.njcn.msgpush.module.system.convert.tenant.TenantConvert; -import com.njcn.msgpush.module.system.dal.dataobject.permission.MenuDO; -import com.njcn.msgpush.module.system.dal.dataobject.permission.RoleDO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantDO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantPackageDO; -import com.njcn.msgpush.module.system.dal.mysql.tenant.TenantMapper; -import com.njcn.msgpush.module.system.enums.permission.RoleCodeEnum; -import com.njcn.msgpush.module.system.enums.permission.RoleTypeEnum; -import com.njcn.msgpush.module.system.service.permission.MenuService; -import com.njcn.msgpush.module.system.service.permission.PermissionService; -import com.njcn.msgpush.module.system.service.permission.RoleService; -import com.njcn.msgpush.module.system.service.tenant.handler.TenantInfoHandler; -import com.njcn.msgpush.module.system.service.tenant.handler.TenantMenuHandler; -import com.njcn.msgpush.module.system.service.user.AdminUserService; -import com.baomidou.dynamic.datasource.annotation.DSTransactional; -import jakarta.annotation.Resource; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import static com.njcn.msgpush.framework.common.exception.util.ServiceExceptionUtil.exception; -import static com.njcn.msgpush.module.system.enums.ErrorCodeConstants.*; -import static java.util.Collections.singleton; - -/** - * 租户 Service 实现类 - * - * @author hongawen - */ -@Service -@Validated -@Slf4j -public class TenantServiceImpl implements TenantService { - - @SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") - @Autowired(required = false) // 由于 msgpush.tenant.enable 配置项,可以关闭多租户的功能,所以这里只能不强制注入 - private TenantProperties tenantProperties; - - @Resource - private TenantMapper tenantMapper; - - @Resource - private TenantPackageService tenantPackageService; - @Resource - @Lazy // 延迟,避免循环依赖报错 - private AdminUserService userService; - @Resource - private RoleService roleService; - @Resource - private MenuService menuService; - @Resource - private PermissionService permissionService; - - @Override - public List getTenantIdList() { - List tenants = tenantMapper.selectList(); - return CollectionUtils.convertList(tenants, TenantDO::getId); - } - - @Override - public void validTenant(Long id) { - TenantDO tenant = getTenant(id); - if (tenant == null) { - throw exception(TENANT_NOT_EXISTS); - } - if (tenant.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) { - throw exception(TENANT_DISABLE, tenant.getName()); - } - if (DateUtils.isExpired(tenant.getExpireTime())) { - throw exception(TENANT_EXPIRE, tenant.getName()); - } - } - - @Override - @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 - public Long createTenant(TenantSaveReqVO createReqVO) { - // 校验租户名称是否重复 - validTenantNameDuplicate(createReqVO.getName(), null); - // 校验租户域名是否重复 - validTenantWebsiteDuplicate(createReqVO.getWebsites(), null); - // 校验套餐被禁用 - TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(createReqVO.getPackageId()); - - // 创建租户 - TenantDO tenant = BeanUtils.toBean(createReqVO, TenantDO.class); - tenantMapper.insert(tenant); - // 创建租户的管理员 - TenantUtils.execute(tenant.getId(), () -> { - // 创建角色 - Long roleId = createRole(tenantPackage); - // 创建用户,并分配角色 - Long userId = createUser(roleId, createReqVO); - // 修改租户的管理员 - tenantMapper.updateById(new TenantDO().setId(tenant.getId()).setContactUserId(userId)); - }); - return tenant.getId(); - } - - private Long createUser(Long roleId, TenantSaveReqVO createReqVO) { - // 创建用户 - Long userId = userService.createUser(TenantConvert.INSTANCE.convert02(createReqVO)); - // 分配角色 - permissionService.assignUserRole(userId, singleton(roleId)); - return userId; - } - - private Long createRole(TenantPackageDO tenantPackage) { - // 创建角色 - RoleSaveReqVO reqVO = new RoleSaveReqVO(); - reqVO.setName(RoleCodeEnum.TENANT_ADMIN.getName()).setCode(RoleCodeEnum.TENANT_ADMIN.getCode()) - .setSort(0).setRemark("系统自动生成"); - Long roleId = roleService.createRole(reqVO, RoleTypeEnum.SYSTEM.getType()); - // 分配权限 - permissionService.assignRoleMenu(roleId, tenantPackage.getMenuIds()); - return roleId; - } - - @Override - @DSTransactional // 多数据源,使用 @DSTransactional 保证本地事务,以及数据源的切换 - public void updateTenant(TenantSaveReqVO updateReqVO) { - // 校验存在 - TenantDO tenant = validateUpdateTenant(updateReqVO.getId()); - // 校验租户名称是否重复 - validTenantNameDuplicate(updateReqVO.getName(), updateReqVO.getId()); - // 校验租户域名是否重复 - validTenantWebsiteDuplicate(updateReqVO.getWebsites(), updateReqVO.getId()); - // 校验套餐被禁用 - TenantPackageDO tenantPackage = tenantPackageService.validTenantPackage(updateReqVO.getPackageId()); - - // 更新租户 - TenantDO updateObj = BeanUtils.toBean(updateReqVO, TenantDO.class); - tenantMapper.updateById(updateObj); - // 如果套餐发生变化,则修改其角色的权限 - if (ObjectUtil.notEqual(tenant.getPackageId(), updateReqVO.getPackageId())) { - updateTenantRoleMenu(tenant.getId(), tenantPackage.getMenuIds()); - } - } - - private void validTenantNameDuplicate(String name, Long id) { - TenantDO tenant = tenantMapper.selectByName(name); - if (tenant == null) { - return; - } - // 如果 id 为空,说明不用比较是否为相同名字的租户 - if (id == null) { - throw exception(TENANT_NAME_DUPLICATE, name); - } - if (!tenant.getId().equals(id)) { - throw exception(TENANT_NAME_DUPLICATE, name); - } - } - - private void validTenantWebsiteDuplicate(List websites, Long excludeId) { - if (CollUtil.isEmpty(websites)) { - return; - } - websites.forEach(website -> { - List tenants = tenantMapper.selectListByWebsite(website); - if (excludeId != null) { - tenants.removeIf(tenant -> tenant.getId().equals(excludeId)); - } - if (CollUtil.isNotEmpty(tenants)) { - throw exception(TENANT_WEBSITE_DUPLICATE, website); - } - }); - } - - @Override - @DSTransactional - public void updateTenantRoleMenu(Long tenantId, Set menuIds) { - TenantUtils.execute(tenantId, () -> { - // 获得所有角色 - List roles = roleService.getRoleList(); - roles.forEach(role -> Assert.isTrue(tenantId.equals(role.getTenantId()), "角色({}/{}) 租户不匹配", - role.getId(), role.getTenantId(), tenantId)); // 兜底校验 - // 重新分配每个角色的权限 - roles.forEach(role -> { - // 如果是租户管理员,重新分配其权限为租户套餐的权限 - if (Objects.equals(role.getCode(), RoleCodeEnum.TENANT_ADMIN.getCode())) { - permissionService.assignRoleMenu(role.getId(), menuIds); - log.info("[updateTenantRoleMenu][租户管理员({}/{}) 的权限修改为({})]", role.getId(), role.getTenantId(), menuIds); - return; - } - // 如果是其他角色,则去掉超过套餐的权限 - Set roleMenuIds = permissionService.getRoleMenuListByRoleId(role.getId()); - roleMenuIds = CollUtil.intersectionDistinct(roleMenuIds, menuIds); - permissionService.assignRoleMenu(role.getId(), roleMenuIds); - log.info("[updateTenantRoleMenu][角色({}/{}) 的权限修改为({})]", role.getId(), role.getTenantId(), roleMenuIds); - }); - }); - } - - @Override - public void deleteTenant(Long id) { - // 校验存在 - validateUpdateTenant(id); - // 删除 - tenantMapper.deleteById(id); - } - - @Override - public void deleteTenantList(List ids) { - // 1. 校验存在 - ids.forEach(this::validateUpdateTenant); - - // 2. 批量删除 - tenantMapper.deleteByIds(ids); - } - - private TenantDO validateUpdateTenant(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; - } - - @Override - public TenantDO getTenant(Long id) { - return tenantMapper.selectById(id); - } - - @Override - public PageResult getTenantPage(TenantPageReqVO pageReqVO) { - return tenantMapper.selectPage(pageReqVO); - } - - @Override - public TenantDO getTenantByName(String name) { - return tenantMapper.selectByName(name); - } - - @Override - public TenantDO getTenantByWebsite(String website) { - List tenants = tenantMapper.selectListByWebsite(website); - return CollUtil.getFirst(tenants); - } - - @Override - public Long getTenantCountByPackageId(Long packageId) { - return tenantMapper.selectCountByPackageId(packageId); - } - - @Override - public List getTenantListByPackageId(Long packageId) { - return tenantMapper.selectListByPackageId(packageId); - } - - @Override - public List getTenantListByStatus(Integer status) { - return tenantMapper.selectListByStatus(status); - } - - @Override - public void handleTenantInfo(TenantInfoHandler handler) { - // 如果禁用,则不执行逻辑 - if (isTenantDisable()) { - return; - } - // 获得租户 - TenantDO tenant = getTenant(TenantContextHolder.getRequiredTenantId()); - // 执行处理器 - handler.handle(tenant); - } - - @Override - public void handleTenantMenu(TenantMenuHandler handler) { - // 如果禁用,则不执行逻辑 - if (isTenantDisable()) { - return; - } - // 获得租户,然后获得菜单 - TenantDO tenant = getTenant(TenantContextHolder.getRequiredTenantId()); - Set menuIds; - if (isSystemTenant(tenant)) { // 系统租户,菜单是全量的 - menuIds = CollectionUtils.convertSet(menuService.getMenuList(), MenuDO::getId); - } else { - menuIds = tenantPackageService.getTenantPackage(tenant.getPackageId()).getMenuIds(); - } - // 执行处理器 - handler.handle(menuIds); - } - - private static boolean isSystemTenant(TenantDO tenant) { - return Objects.equals(tenant.getPackageId(), TenantDO.PACKAGE_ID_SYSTEM); - } - - private boolean isTenantDisable() { - return tenantProperties == null || Boolean.FALSE.equals(tenantProperties.getEnable()); - } - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/handler/TenantInfoHandler.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/handler/TenantInfoHandler.java deleted file mode 100644 index 370c789..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/handler/TenantInfoHandler.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.njcn.msgpush.module.system.service.tenant.handler; - -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantDO; - -/** - * 租户信息处理 - * 目的:尽量减少租户逻辑耦合到系统中 - * - * @author hongawen - */ -public interface TenantInfoHandler { - - /** - * 基于传入的租户信息,进行相关逻辑的执行 - * 例如说,创建用户时,超过最大账户配额 - * - * @param tenant 租户信息 - */ - void handle(TenantDO tenant); - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/handler/TenantMenuHandler.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/handler/TenantMenuHandler.java deleted file mode 100644 index 3d52f7b..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/tenant/handler/TenantMenuHandler.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.njcn.msgpush.module.system.service.tenant.handler; - -import java.util.Set; - -/** - * 租户菜单处理 - * 目的:尽量减少租户逻辑耦合到系统中 - * - * @author hongawen - */ -public interface TenantMenuHandler { - - /** - * 基于传入的租户菜单【全】列表,进行相关逻辑的执行 - * 例如说,返回可分配菜单的时候,可以移除多余的 - * - * @param menuIds 菜单列表 - */ - void handle(Set menuIds); - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/user/AdminUserServiceImpl.java b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/user/AdminUserServiceImpl.java index e37a535..d626eb2 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/user/AdminUserServiceImpl.java +++ b/msgpush-module-system/msgpush-module-system-server/src/main/java/com/njcn/msgpush/module/system/service/user/AdminUserServiceImpl.java @@ -28,7 +28,6 @@ import com.njcn.msgpush.module.system.service.dept.DeptService; import com.njcn.msgpush.module.system.service.dept.PostService; import com.njcn.msgpush.module.system.service.oauth2.OAuth2TokenService; import com.njcn.msgpush.module.system.service.permission.PermissionService; -import com.njcn.msgpush.module.system.service.tenant.TenantService; import com.google.common.annotations.VisibleForTesting; import com.mzt.logapi.context.LogRecordContext; import com.mzt.logapi.service.impl.DiffParseFunction; @@ -74,9 +73,6 @@ public class AdminUserServiceImpl implements AdminUserService { @Resource private PasswordEncoder passwordEncoder; @Resource - @Lazy // 延迟,避免循环依赖报错 - private TenantService tenantService; - @Resource @Lazy // 懒加载,避免循环依赖 private OAuth2TokenService oauth2TokenService; @@ -91,14 +87,7 @@ public class AdminUserServiceImpl implements AdminUserService { @LogRecord(type = SYSTEM_USER_TYPE, subType = SYSTEM_USER_CREATE_SUB_TYPE, bizNo = "{{#user.id}}", success = SYSTEM_USER_CREATE_SUCCESS) public Long createUser(UserSaveReqVO createReqVO) { - // 1.1 校验账户配合 - tenantService.handleTenantInfo(tenant -> { - long count = userMapper.selectCount(); - if (count >= tenant.getAccountCount()) { - throw exception(USER_COUNT_MAX, tenant.getAccountCount()); - } - }); - // 1.2 校验正确性 + // 1.1 校验正确性 validateUserForCreateOrUpdate(null, createReqVO.getUsername(), createReqVO.getMobile(), createReqVO.getEmail(), createReqVO.getDeptId(), createReqVO.getPostIds()); // 2.1 插入用户 @@ -123,14 +112,7 @@ public class AdminUserServiceImpl implements AdminUserService { if (ObjUtil.notEqual(configApi.getConfigValueByKey(USER_REGISTER_ENABLED_KEY).getCheckedData(), "true")) { throw exception(USER_REGISTER_DISABLED); } - // 1.2 校验账户配合 - tenantService.handleTenantInfo(tenant -> { - long count = userMapper.selectCount(); - if (count >= tenant.getAccountCount()) { - throw exception(USER_COUNT_MAX, tenant.getAccountCount()); - } - }); - // 1.3 校验正确性 + // 1.2 校验正确性 validateUserForCreateOrUpdate(null, registerReqVO.getUsername(), null, null, null, null); // 2. 插入用户 diff --git a/msgpush-module-system/msgpush-module-system-server/src/main/resources/application.yaml b/msgpush-module-system/msgpush-module-system-server/src/main/resources/application.yaml index 28760b4..06de94d 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/main/resources/application.yaml +++ b/msgpush-module-system/msgpush-module-system-server/src/main/resources/application.yaml @@ -126,20 +126,6 @@ msgpush: title: 管理后台 description: 提供管理员管理的所有功能 version: ${msgpush.info.version} - tenant: - enable: true - ignore-urls: - ignore-visit-urls: - - /admin-api/system/user/profile/** - - /admin-api/system/auth/** - ignore-tables: - ignore-caches: - - user_role_ids - - permission_menu_ids - - oauth_client - - notify_template - - mail_account - - mail_template - - sms_template + debug: false diff --git a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/oauth2/OAuth2TokenServiceImplTest.java b/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/oauth2/OAuth2TokenServiceImplTest.java index f8889e5..970fb80 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/oauth2/OAuth2TokenServiceImplTest.java +++ b/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/oauth2/OAuth2TokenServiceImplTest.java @@ -5,7 +5,6 @@ import com.njcn.msgpush.framework.common.enums.UserTypeEnum; import com.njcn.msgpush.framework.common.exception.ErrorCode; import com.njcn.msgpush.framework.common.pojo.PageResult; import com.njcn.msgpush.framework.common.util.date.DateUtils; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; import com.njcn.msgpush.framework.test.core.ut.BaseDbAndRedisUnitTest; import com.njcn.msgpush.module.system.controller.admin.oauth2.vo.token.OAuth2AccessTokenPageReqVO; import com.njcn.msgpush.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO; @@ -59,7 +58,6 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { @Test public void testCreateAccessToken() { - TenantContextHolder.setTenantId(0L); // 准备参数 Long userId = randomLongId(); Integer userType = UserTypeEnum.ADMIN.getValue(); @@ -149,7 +147,6 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { @Test public void testRefreshAccessToken_success() { - TenantContextHolder.setTenantId(0L); // 准备参数 String refreshToken = randomString(); String clientId = randomString(); @@ -161,8 +158,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { OAuth2RefreshTokenDO refreshTokenDO = randomPojo(OAuth2RefreshTokenDO.class, o -> o.setRefreshToken(refreshToken).setClientId(clientId) .setExpiresTime(LocalDateTime.now().plusDays(1)) - .setUserType(UserTypeEnum.ADMIN.getValue()) - .setTenantId(TenantContextHolder.getTenantId())); + .setUserType(UserTypeEnum.ADMIN.getValue())); oauth2RefreshTokenMapper.insert(refreshTokenDO); // mock 数据(访问令牌) OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class).setRefreshToken(refreshToken) diff --git a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/permission/MenuServiceImplTest.java b/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/permission/MenuServiceImplTest.java index 7957fea..ff2bc99 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/permission/MenuServiceImplTest.java +++ b/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/permission/MenuServiceImplTest.java @@ -7,7 +7,6 @@ import com.njcn.msgpush.module.system.controller.admin.permission.vo.menu.MenuSa import com.njcn.msgpush.module.system.dal.dataobject.permission.MenuDO; import com.njcn.msgpush.module.system.dal.mysql.permission.MenuMapper; import com.njcn.msgpush.module.system.enums.permission.MenuTypeEnum; -import com.njcn.msgpush.module.system.service.tenant.TenantService; import jakarta.annotation.Resource; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Import; @@ -42,8 +41,6 @@ public class MenuServiceImplTest extends BaseDbUnitTest { @MockitoBean private PermissionService permissionService; - @MockitoBean - private TenantService tenantService; @Test public void testCreateMenu_success() { @@ -162,30 +159,6 @@ public class MenuServiceImplTest extends BaseDbUnitTest { assertPojoEquals(menuDO, result.get(0)); } - @Test - public void testGetMenuListByTenant() { - // mock 数据 - MenuDO menu100 = randomPojo(MenuDO.class, o -> o.setId(100L).setStatus(CommonStatusEnum.ENABLE.getStatus())); - menuMapper.insert(menu100); - MenuDO menu101 = randomPojo(MenuDO.class, o -> o.setId(101L).setStatus(CommonStatusEnum.DISABLE.getStatus())); - menuMapper.insert(menu101); - MenuDO menu102 = randomPojo(MenuDO.class, o -> o.setId(102L).setStatus(CommonStatusEnum.ENABLE.getStatus())); - menuMapper.insert(menu102); - // mock 过滤菜单 - Set menuIds = asSet(100L, 101L); - doNothing().when(tenantService).handleTenantMenu(argThat(handler -> { - handler.handle(menuIds); - return true; - })); - // 准备参数 - MenuListReqVO reqVO = new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()); - - // 调用 - List result = menuService.getMenuListByTenant(reqVO); - // 断言 - assertEquals(1, result.size()); - assertPojoEquals(menu100, result.get(0)); - } @Test public void testGetMenuIdListByPermissionFromCache() { diff --git a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/permission/RoleServiceImplTest.java b/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/permission/RoleServiceImplTest.java index bc4cba6..31c2e6d 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/permission/RoleServiceImplTest.java +++ b/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/permission/RoleServiceImplTest.java @@ -320,23 +320,6 @@ public class RoleServiceImplTest extends BaseDbUnitTest { } } - @Test - public void testHasAnySuperAdmin_false() { - try (MockedStatic springUtilMockedStatic = mockStatic(SpringUtil.class)) { - springUtilMockedStatic.when(() -> SpringUtil.getBean(eq(RoleServiceImpl.class))) - .thenReturn(roleService); - - // mock 数据 - RoleDO dbRole = randomPojo(RoleDO.class).setCode("tenant_admin"); - roleMapper.insert(dbRole); - // 准备参数 - Long id = dbRole.getId(); - - // 调用,并调用 - assertFalse(roleService.hasAnySuperAdmin(singletonList(id))); - } - } - @Test public void testValidateRoleList_success() { // mock 数据 diff --git a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/tenant/TenantPackageServiceImplTest.java b/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/tenant/TenantPackageServiceImplTest.java deleted file mode 100644 index b2ad453..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/tenant/TenantPackageServiceImplTest.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.njcn.msgpush.module.system.service.tenant; - -import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.test.core.ut.BaseDbUnitTest; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackagePageReqVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.packages.TenantPackageSaveReqVO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantDO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantPackageDO; -import com.njcn.msgpush.module.system.dal.mysql.tenant.TenantPackageMapper; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.Import; - -import jakarta.annotation.Resource; -import org.springframework.test.context.bean.override.mockito.MockitoBean; - -import java.util.List; - -import static com.njcn.msgpush.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; -import static com.njcn.msgpush.framework.common.util.date.LocalDateTimeUtils.buildTime; -import static com.njcn.msgpush.framework.common.util.object.ObjectUtils.cloneIgnoreId; -import static com.njcn.msgpush.framework.test.core.util.AssertUtils.assertPojoEquals; -import static com.njcn.msgpush.framework.test.core.util.AssertUtils.assertServiceException; -import static com.njcn.msgpush.framework.test.core.util.RandomUtils.*; -import static com.njcn.msgpush.module.system.enums.ErrorCodeConstants.*; -import static java.util.Arrays.asList; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** -* {@link TenantPackageServiceImpl} 的单元测试类 -* -* @author hongawen -*/ -@Import(TenantPackageServiceImpl.class) -public class TenantPackageServiceImplTest extends BaseDbUnitTest { - - @Resource - private TenantPackageServiceImpl tenantPackageService; - - @Resource - private TenantPackageMapper tenantPackageMapper; - - @MockitoBean - private TenantService tenantService; - - @Test - public void testCreateTenantPackage_success() { - // 准备参数 - TenantPackageSaveReqVO reqVO = randomPojo(TenantPackageSaveReqVO.class, - o -> o.setStatus(randomCommonStatus())) - .setId(null); // 防止 id 被赋值 - - // 调用 - Long tenantPackageId = tenantPackageService.createTenantPackage(reqVO); - // 断言 - assertNotNull(tenantPackageId); - // 校验记录的属性是否正确 - TenantPackageDO tenantPackage = tenantPackageMapper.selectById(tenantPackageId); - assertPojoEquals(reqVO, tenantPackage, "id"); - } - - @Test - public void testUpdateTenantPackage_success() { - // mock 数据 - TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class, - o -> o.setStatus(randomCommonStatus())); - tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据 - // 准备参数 - TenantPackageSaveReqVO reqVO = randomPojo(TenantPackageSaveReqVO.class, o -> { - o.setId(dbTenantPackage.getId()); // 设置更新的 ID - o.setStatus(randomCommonStatus()); - }); - // mock 方法 - Long tenantId01 = randomLongId(); - Long tenantId02 = randomLongId(); - when(tenantService.getTenantListByPackageId(eq(reqVO.getId()))).thenReturn( - asList(randomPojo(TenantDO.class, o -> o.setId(tenantId01)), - randomPojo(TenantDO.class, o -> o.setId(tenantId02)))); - - // 调用 - tenantPackageService.updateTenantPackage(reqVO); - // 校验是否更新正确 - TenantPackageDO tenantPackage = tenantPackageMapper.selectById(reqVO.getId()); // 获取最新的 - assertPojoEquals(reqVO, tenantPackage); - // 校验调用租户的菜单 - verify(tenantService).updateTenantRoleMenu(eq(tenantId01), eq(reqVO.getMenuIds())); - verify(tenantService).updateTenantRoleMenu(eq(tenantId02), eq(reqVO.getMenuIds())); - } - - @Test - public void testUpdateTenantPackage_notExists() { - // 准备参数 - TenantPackageSaveReqVO reqVO = randomPojo(TenantPackageSaveReqVO.class); - - // 调用, 并断言异常 - assertServiceException(() -> tenantPackageService.updateTenantPackage(reqVO), TENANT_PACKAGE_NOT_EXISTS); - } - - @Test - public void testDeleteTenantPackage_success() { - // mock 数据 - TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class); - tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbTenantPackage.getId(); - // mock 租户未使用该套餐 - when(tenantService.getTenantCountByPackageId(eq(id))).thenReturn(0L); - - // 调用 - tenantPackageService.deleteTenantPackage(id); - // 校验数据不存在了 - assertNull(tenantPackageMapper.selectById(id)); - } - - @Test - public void testDeleteTenantPackage_notExists() { - // 准备参数 - Long id = randomLongId(); - - // 调用, 并断言异常 - assertServiceException(() -> tenantPackageService.deleteTenantPackage(id), TENANT_PACKAGE_NOT_EXISTS); - } - - @Test - public void testDeleteTenantPackage_used() { - // mock 数据 - TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class); - tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbTenantPackage.getId(); - // mock 租户在使用该套餐 - when(tenantService.getTenantCountByPackageId(eq(id))).thenReturn(1L); - - // 调用, 并断言异常 - assertServiceException(() -> tenantPackageService.deleteTenantPackage(id), TENANT_PACKAGE_USED); - } - - @Test - public void testGetTenantPackagePage() { - // mock 数据 - TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class, o -> { // 等会查询到 - o.setName("灿能源码"); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setRemark("源码解析"); - o.setCreateTime(buildTime(2022, 10, 10)); - }); - tenantPackageMapper.insert(dbTenantPackage); - // 测试 name 不匹配 - tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setName("源码"))); - // 测试 status 不匹配 - tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); - // 测试 remark 不匹配 - tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setRemark("解析"))); - // 测试 createTime 不匹配 - tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, o -> o.setCreateTime(buildTime(2022, 11, 11)))); - // 准备参数 - TenantPackagePageReqVO reqVO = new TenantPackagePageReqVO(); - reqVO.setName("灿能"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setRemark("源码"); - reqVO.setCreateTime(buildBetweenTime(2022, 10, 9, 2022, 10, 11)); - - // 调用 - PageResult pageResult = tenantPackageService.getTenantPackagePage(reqVO); - // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbTenantPackage, pageResult.getList().get(0)); - } - - @Test - public void testValidTenantPackage_success() { - // mock 数据 - TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class, - o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); - tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据 - - // 调用 - TenantPackageDO result = tenantPackageService.validTenantPackage(dbTenantPackage.getId()); - // 断言 - assertPojoEquals(dbTenantPackage, result); - } - - @Test - public void testValidTenantPackage_notExists() { - // 准备参数 - Long id = randomLongId(); - - // 调用, 并断言异常 - assertServiceException(() -> tenantPackageService.validTenantPackage(id), TENANT_PACKAGE_NOT_EXISTS); - } - - @Test - public void testValidTenantPackage_disable() { - // mock 数据 - TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class, - o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())); - tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据 - - // 调用, 并断言异常 - assertServiceException(() -> tenantPackageService.validTenantPackage(dbTenantPackage.getId()), - TENANT_PACKAGE_DISABLE, dbTenantPackage.getName()); - } - - @Test - public void testGetTenantPackage() { - // mock 数据 - TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class); - tenantPackageMapper.insert(dbTenantPackage);// @Sql: 先插入出一条存在的数据 - - // 调用 - TenantPackageDO result = tenantPackageService.getTenantPackage(dbTenantPackage.getId()); - // 断言 - assertPojoEquals(result, dbTenantPackage); - } - - @Test - public void testGetTenantPackageListByStatus() { - // mock 数据 - TenantPackageDO dbTenantPackage = randomPojo(TenantPackageDO.class, - o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus())); - tenantPackageMapper.insert(dbTenantPackage); - // 测试 status 不匹配 - tenantPackageMapper.insert(cloneIgnoreId(dbTenantPackage, - o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); - - // 调用 - List list = tenantPackageService.getTenantPackageListByStatus( - CommonStatusEnum.ENABLE.getStatus()); - assertEquals(1, list.size()); - assertPojoEquals(dbTenantPackage, list.get(0)); - } - -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/tenant/TenantServiceImplTest.java b/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/tenant/TenantServiceImplTest.java deleted file mode 100644 index 2fbbf92..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/tenant/TenantServiceImplTest.java +++ /dev/null @@ -1,461 +0,0 @@ -package com.njcn.msgpush.module.system.service.tenant; - -import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; -import com.njcn.msgpush.framework.common.pojo.PageResult; -import com.njcn.msgpush.framework.tenant.config.TenantProperties; -import com.njcn.msgpush.framework.tenant.core.context.TenantContextHolder; -import com.njcn.msgpush.framework.test.core.ut.BaseDbUnitTest; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO; -import com.njcn.msgpush.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO; -import com.njcn.msgpush.module.system.dal.dataobject.permission.MenuDO; -import com.njcn.msgpush.module.system.dal.dataobject.permission.RoleDO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantDO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantPackageDO; -import com.njcn.msgpush.module.system.dal.mysql.tenant.TenantMapper; -import com.njcn.msgpush.module.system.enums.permission.RoleCodeEnum; -import com.njcn.msgpush.module.system.enums.permission.RoleTypeEnum; -import com.njcn.msgpush.module.system.service.permission.MenuService; -import com.njcn.msgpush.module.system.service.permission.PermissionService; -import com.njcn.msgpush.module.system.service.permission.RoleService; -import com.njcn.msgpush.module.system.service.tenant.handler.TenantInfoHandler; -import com.njcn.msgpush.module.system.service.tenant.handler.TenantMenuHandler; -import com.njcn.msgpush.module.system.service.user.AdminUserService; -import jakarta.annotation.Resource; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.bean.override.mockito.MockitoBean; - -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static com.njcn.msgpush.framework.common.util.collection.SetUtils.asSet; -import static com.njcn.msgpush.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime; -import static com.njcn.msgpush.framework.common.util.date.LocalDateTimeUtils.buildTime; -import static com.njcn.msgpush.framework.common.util.object.ObjectUtils.cloneIgnoreId; -import static com.njcn.msgpush.framework.test.core.util.AssertUtils.assertPojoEquals; -import static com.njcn.msgpush.framework.test.core.util.AssertUtils.assertServiceException; -import static com.njcn.msgpush.framework.test.core.util.RandomUtils.*; -import static com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantDO.PACKAGE_ID_SYSTEM; -import static com.njcn.msgpush.module.system.enums.ErrorCodeConstants.*; -import static java.util.Arrays.asList; -import static java.util.Collections.singleton; -import static java.util.Collections.singletonList; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - -/** - * {@link TenantServiceImpl} 的单元测试类 - * - * @author hongawen - */ -@Import(TenantServiceImpl.class) -public class TenantServiceImplTest extends BaseDbUnitTest { - - @Resource - private TenantServiceImpl tenantService; - - @Resource - private TenantMapper tenantMapper; - - @MockitoBean - private TenantProperties tenantProperties; - @MockitoBean - private TenantPackageService tenantPackageService; - @MockitoBean - private AdminUserService userService; - @MockitoBean - private RoleService roleService; - @MockitoBean - private MenuService menuService; - @MockitoBean - private PermissionService permissionService; - - @BeforeEach - public void setUp() { - // 清理租户上下文 - TenantContextHolder.clear(); - } - - @Test - public void testGetTenantIdList() { - // mock 数据 - TenantDO tenant = randomPojo(TenantDO.class, o -> o.setId(1L)); - tenantMapper.insert(tenant); - - // 调用,并断言业务异常 - List result = tenantService.getTenantIdList(); - assertEquals(Collections.singletonList(1L), result); - } - - @Test - public void testValidTenant_notExists() { - assertServiceException(() -> tenantService.validTenant(randomLongId()), TENANT_NOT_EXISTS); - } - - @Test - public void testValidTenant_disable() { - // mock 数据 - TenantDO tenant = randomPojo(TenantDO.class, o -> o.setId(1L).setStatus(CommonStatusEnum.DISABLE.getStatus())); - tenantMapper.insert(tenant); - - // 调用,并断言业务异常 - assertServiceException(() -> tenantService.validTenant(1L), TENANT_DISABLE, tenant.getName()); - } - - @Test - public void testValidTenant_expired() { - // mock 数据 - TenantDO tenant = randomPojo(TenantDO.class, o -> o.setId(1L).setStatus(CommonStatusEnum.ENABLE.getStatus()) - .setExpireTime(buildTime(2020, 2, 2))); - tenantMapper.insert(tenant); - - // 调用,并断言业务异常 - assertServiceException(() -> tenantService.validTenant(1L), TENANT_EXPIRE, tenant.getName()); - } - - @Test - public void testValidTenant_success() { - // mock 数据 - TenantDO tenant = randomPojo(TenantDO.class, o -> o.setId(1L).setStatus(CommonStatusEnum.ENABLE.getStatus()) - .setExpireTime(LocalDateTime.now().plusDays(1))); - tenantMapper.insert(tenant); - - // 调用,并断言业务异常 - tenantService.validTenant(1L); - } - - @Test - public void testCreateTenant() { - // mock 套餐 100L - TenantPackageDO tenantPackage = randomPojo(TenantPackageDO.class, o -> o.setId(100L)); - when(tenantPackageService.validTenantPackage(eq(100L))).thenReturn(tenantPackage); - // mock 角色 200L - when(roleService.createRole(argThat(role -> { - assertEquals(RoleCodeEnum.TENANT_ADMIN.getName(), role.getName()); - assertEquals(RoleCodeEnum.TENANT_ADMIN.getCode(), role.getCode()); - assertEquals(0, role.getSort()); - assertEquals("系统自动生成", role.getRemark()); - return true; - }), eq(RoleTypeEnum.SYSTEM.getType()))).thenReturn(200L); - // mock 用户 300L - when(userService.createUser(argThat(user -> { - assertEquals("yunai", user.getUsername()); - assertEquals("yuanma", user.getPassword()); - assertEquals("灿能", user.getNickname()); - assertEquals("15601691300", user.getMobile()); - return true; - }))).thenReturn(300L); - - // 准备参数 - TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class, o -> { - o.setContactName("灿能"); - o.setContactMobile("15601691300"); - o.setPackageId(100L); - o.setStatus(randomCommonStatus()); - o.setWebsites(singletonList("https://www.iocoder.cn")); - o.setUsername("yunai"); - o.setPassword("yuanma"); - }).setId(null); // 设置为 null,方便后面校验 - - // 调用 - Long tenantId = tenantService.createTenant(reqVO); - // 断言 - assertNotNull(tenantId); - // 校验记录的属性是否正确 - TenantDO tenant = tenantMapper.selectById(tenantId); - assertPojoEquals(reqVO, tenant, "id"); - assertEquals(300L, tenant.getContactUserId()); - // verify 分配权限 - verify(permissionService).assignRoleMenu(eq(200L), same(tenantPackage.getMenuIds())); - // verify 分配角色 - verify(permissionService).assignUserRole(eq(300L), eq(singleton(200L))); - } - - @Test - public void testUpdateTenant_success() { - // mock 数据 - TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setStatus(randomCommonStatus())); - tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 - // 准备参数 - TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class, o -> { - o.setId(dbTenant.getId()); // 设置更新的 ID - o.setStatus(randomCommonStatus()); - o.setWebsites(singletonList(randomString())); - }); - - // mock 套餐 - TenantPackageDO tenantPackage = randomPojo(TenantPackageDO.class, - o -> o.setMenuIds(asSet(200L, 201L))); - when(tenantPackageService.validTenantPackage(eq(reqVO.getPackageId()))).thenReturn(tenantPackage); - // mock 所有角色 - RoleDO role100 = randomPojo(RoleDO.class, o -> o.setId(100L).setCode(RoleCodeEnum.TENANT_ADMIN.getCode())); - role100.setTenantId(dbTenant.getId()); - RoleDO role101 = randomPojo(RoleDO.class, o -> o.setId(101L)); - role101.setTenantId(dbTenant.getId()); - when(roleService.getRoleList()).thenReturn(asList(role100, role101)); - // mock 每个角色的权限 - when(permissionService.getRoleMenuListByRoleId(eq(101L))).thenReturn(asSet(201L, 202L)); - - // 调用 - tenantService.updateTenant(reqVO); - // 校验是否更新正确 - TenantDO tenant = tenantMapper.selectById(reqVO.getId()); // 获取最新的 - assertPojoEquals(reqVO, tenant); - // verify 设置角色权限 - verify(permissionService).assignRoleMenu(eq(100L), eq(asSet(200L, 201L))); - verify(permissionService).assignRoleMenu(eq(101L), eq(asSet(201L))); - } - - @Test - public void testUpdateTenant_notExists() { - // 准备参数 - TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class); - - // 调用, 并断言异常 - assertServiceException(() -> tenantService.updateTenant(reqVO), TENANT_NOT_EXISTS); - } - - @Test - public void testUpdateTenant_system() { - // mock 数据 - TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setPackageId(PACKAGE_ID_SYSTEM)); - tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 - // 准备参数 - TenantSaveReqVO reqVO = randomPojo(TenantSaveReqVO.class, o -> { - o.setId(dbTenant.getId()); // 设置更新的 ID - }); - - // 调用,校验业务异常 - assertServiceException(() -> tenantService.updateTenant(reqVO), TENANT_CAN_NOT_UPDATE_SYSTEM); - } - - @Test - public void testDeleteTenant_success() { - // mock 数据 - TenantDO dbTenant = randomPojo(TenantDO.class, - o -> o.setStatus(randomCommonStatus())); - tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbTenant.getId(); - - // 调用 - tenantService.deleteTenant(id); - // 校验数据不存在了 - assertNull(tenantMapper.selectById(id)); - } - - @Test - public void testDeleteTenant_notExists() { - // 准备参数 - Long id = randomLongId(); - - // 调用, 并断言异常 - assertServiceException(() -> tenantService.deleteTenant(id), TENANT_NOT_EXISTS); - } - - @Test - public void testDeleteTenant_system() { - // mock 数据 - TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setPackageId(PACKAGE_ID_SYSTEM)); - tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbTenant.getId(); - - // 调用, 并断言异常 - assertServiceException(() -> tenantService.deleteTenant(id), TENANT_CAN_NOT_UPDATE_SYSTEM); - } - - @Test - public void testGetTenant() { - // mock 数据 - TenantDO dbTenant = randomPojo(TenantDO.class); - tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 - // 准备参数 - Long id = dbTenant.getId(); - - // 调用 - TenantDO result = tenantService.getTenant(id); - // 校验存在 - assertPojoEquals(result, dbTenant); - } - - @Test - public void testGetTenantPage() { - // mock 数据 - TenantDO dbTenant = randomPojo(TenantDO.class, o -> { // 等会查询到 - o.setName("灿能源码"); - o.setContactName("芋艿"); - o.setContactMobile("15601691300"); - o.setStatus(CommonStatusEnum.ENABLE.getStatus()); - o.setCreateTime(buildTime(2020, 12, 12)); - }); - tenantMapper.insert(dbTenant); - // 测试 name 不匹配 - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setName(randomString()))); - // 测试 contactName 不匹配 - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setContactName(randomString()))); - // 测试 contactMobile 不匹配 - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setContactMobile(randomString()))); - // 测试 status 不匹配 - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()))); - // 测试 createTime 不匹配 - tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setCreateTime(buildTime(2021, 12, 12)))); - // 准备参数 - TenantPageReqVO reqVO = new TenantPageReqVO(); - reqVO.setName("灿能"); - reqVO.setContactName("艿"); - reqVO.setContactMobile("1560"); - reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); - reqVO.setCreateTime(buildBetweenTime(2020, 12, 1, 2020, 12, 24)); - - // 调用 - PageResult pageResult = tenantService.getTenantPage(reqVO); - // 断言 - assertEquals(1, pageResult.getTotal()); - assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbTenant, pageResult.getList().get(0)); - } - - @Test - public void testGetTenantByName() { - // mock 数据 - TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setName("灿能")); - tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 - - // 调用 - TenantDO result = tenantService.getTenantByName("灿能"); - // 校验存在 - assertPojoEquals(result, dbTenant); - } - - @Test - @Disabled // H2 不支持 find_in_set 函数 - public void testGetTenantByWebsite() { - // mock 数据 - TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setWebsites(singletonList("https://www.iocoder.cn"))); - tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 - - // 调用 - TenantDO result = tenantService.getTenantByWebsite("https://www.iocoder.cn"); - // 校验存在 - assertPojoEquals(result, dbTenant); - } - - @Test - public void testGetTenantListByPackageId() { - // mock 数据 - TenantDO dbTenant1 = randomPojo(TenantDO.class, o -> o.setPackageId(1L)); - tenantMapper.insert(dbTenant1);// @Sql: 先插入出一条存在的数据 - TenantDO dbTenant2 = randomPojo(TenantDO.class, o -> o.setPackageId(2L)); - tenantMapper.insert(dbTenant2);// @Sql: 先插入出一条存在的数据 - - // 调用 - List result = tenantService.getTenantListByPackageId(1L); - assertEquals(1, result.size()); - assertPojoEquals(dbTenant1, result.get(0)); - } - - @Test - public void testGetTenantCountByPackageId() { - // mock 数据 - TenantDO dbTenant1 = randomPojo(TenantDO.class, o -> o.setPackageId(1L)); - tenantMapper.insert(dbTenant1);// @Sql: 先插入出一条存在的数据 - TenantDO dbTenant2 = randomPojo(TenantDO.class, o -> o.setPackageId(2L)); - tenantMapper.insert(dbTenant2);// @Sql: 先插入出一条存在的数据 - - // 调用 - Long count = tenantService.getTenantCountByPackageId(1L); - assertEquals(1, count); - } - - @Test - public void testHandleTenantInfo_disable() { - // 准备参数 - TenantInfoHandler handler = mock(TenantInfoHandler.class); - // mock 禁用 - when(tenantProperties.getEnable()).thenReturn(false); - - // 调用 - tenantService.handleTenantInfo(handler); - // 断言 - verify(handler, never()).handle(any()); - } - - @Test - public void testHandleTenantInfo_success() { - // 准备参数 - TenantInfoHandler handler = mock(TenantInfoHandler.class); - // mock 未禁用 - when(tenantProperties.getEnable()).thenReturn(true); - // mock 租户 - TenantDO dbTenant = randomPojo(TenantDO.class); - tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 - TenantContextHolder.setTenantId(dbTenant.getId()); - - // 调用 - tenantService.handleTenantInfo(handler); - // 断言 - verify(handler).handle(argThat(argument -> { - assertPojoEquals(dbTenant, argument); - return true; - })); - } - - @Test - public void testHandleTenantMenu_disable() { - // 准备参数 - TenantMenuHandler handler = mock(TenantMenuHandler.class); - // mock 禁用 - when(tenantProperties.getEnable()).thenReturn(false); - - // 调用 - tenantService.handleTenantMenu(handler); - // 断言 - verify(handler, never()).handle(any()); - } - - @Test // 系统租户的情况 - public void testHandleTenantMenu_system() { - // 准备参数 - TenantMenuHandler handler = mock(TenantMenuHandler.class); - // mock 未禁用 - when(tenantProperties.getEnable()).thenReturn(true); - // mock 租户 - TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setPackageId(PACKAGE_ID_SYSTEM)); - tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 - TenantContextHolder.setTenantId(dbTenant.getId()); - // mock 菜单 - when(menuService.getMenuList()).thenReturn(Arrays.asList(randomPojo(MenuDO.class, o -> o.setId(100L)), - randomPojo(MenuDO.class, o -> o.setId(101L)))); - - // 调用 - tenantService.handleTenantMenu(handler); - // 断言 - verify(handler).handle(asSet(100L, 101L)); - } - - @Test // 普通租户的情况 - public void testHandleTenantMenu_normal() { - // 准备参数 - TenantMenuHandler handler = mock(TenantMenuHandler.class); - // mock 未禁用 - when(tenantProperties.getEnable()).thenReturn(true); - // mock 租户 - TenantDO dbTenant = randomPojo(TenantDO.class, o -> o.setPackageId(200L)); - tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据 - TenantContextHolder.setTenantId(dbTenant.getId()); - // mock 菜单 - when(tenantPackageService.getTenantPackage(eq(200L))).thenReturn(randomPojo(TenantPackageDO.class, - o -> o.setMenuIds(asSet(100L, 101L)))); - - // 调用 - tenantService.handleTenantMenu(handler); - // 断言 - verify(handler).handle(asSet(100L, 101L)); - } -} diff --git a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/user/AdminUserServiceImplTest.java b/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/user/AdminUserServiceImplTest.java index a9ebcd9..1e96cc2 100644 --- a/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/user/AdminUserServiceImplTest.java +++ b/msgpush-module-system/msgpush-module-system-server/src/test/java/com/njcn/msgpush/module/system/service/user/AdminUserServiceImplTest.java @@ -3,7 +3,6 @@ package com.njcn.msgpush.module.system.service.user; import cn.hutool.core.util.RandomUtil; import com.njcn.msgpush.framework.common.enums.CommonStatusEnum; import com.njcn.msgpush.framework.common.exception.ServiceException; -import com.njcn.msgpush.framework.common.pojo.CommonResult; import com.njcn.msgpush.framework.common.pojo.PageResult; import com.njcn.msgpush.framework.common.util.collection.ArrayUtils; import com.njcn.msgpush.framework.common.util.collection.CollectionUtils; @@ -19,7 +18,6 @@ import com.njcn.msgpush.module.system.controller.admin.user.vo.user.UserSaveReqV import com.njcn.msgpush.module.system.dal.dataobject.dept.DeptDO; import com.njcn.msgpush.module.system.dal.dataobject.dept.PostDO; import com.njcn.msgpush.module.system.dal.dataobject.dept.UserPostDO; -import com.njcn.msgpush.module.system.dal.dataobject.tenant.TenantDO; import com.njcn.msgpush.module.system.dal.dataobject.user.AdminUserDO; import com.njcn.msgpush.module.system.dal.mysql.dept.UserPostMapper; import com.njcn.msgpush.module.system.dal.mysql.user.AdminUserMapper; @@ -28,7 +26,6 @@ import com.njcn.msgpush.module.system.service.dept.DeptService; import com.njcn.msgpush.module.system.service.dept.PostService; import com.njcn.msgpush.module.system.service.oauth2.OAuth2TokenService; import com.njcn.msgpush.module.system.service.permission.PermissionService; -import com.njcn.msgpush.module.system.service.tenant.TenantService; import jakarta.annotation.Resource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -80,8 +77,6 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { @MockitoBean private PasswordEncoder passwordEncoder; @MockitoBean - private TenantService tenantService; - @MockitoBean private FileApi fileApi; @MockitoBean private ConfigApi configApi; @@ -102,12 +97,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { o.setMobile(randomString()); o.setPostIds(asSet(1L, 2L)); }).setId(null); // 避免 id 被赋值 - // mock 账户额度充足 - TenantDO tenant = randomPojo(TenantDO.class, o -> o.setAccountCount(1)); - doNothing().when(tenantService).handleTenantInfo(argThat(handler -> { - handler.handle(tenant); - return true; - })); + // mock deptService 的方法 DeptDO dept = randomPojo(DeptDO.class, o -> { o.setId(reqVO.getDeptId()); @@ -137,20 +127,6 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest { assertEquals(2L, userPosts.get(1).getPostId()); } - @Test - public void testCreatUser_max() { - // 准备参数 - UserSaveReqVO reqVO = randomPojo(UserSaveReqVO.class); - // mock 账户额度不足 - TenantDO tenant = randomPojo(TenantDO.class, o -> o.setAccountCount(-1)); - doNothing().when(tenantService).handleTenantInfo(argThat(handler -> { - handler.handle(tenant); - return true; - })); - - // 调用,并断言异常 - assertServiceException(() -> userService.createUser(reqVO), USER_COUNT_MAX, -1); - } @Test public void testUpdateUser_success() { diff --git a/msgpush-module-system/msgpush-module-system-server/src/test/resources/sql/clean.sql b/msgpush-module-system/msgpush-module-system-server/src/test/resources/sql/clean.sql deleted file mode 100644 index e7946a1..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/test/resources/sql/clean.sql +++ /dev/null @@ -1,33 +0,0 @@ -DELETE FROM "system_dept"; -DELETE FROM "system_dict_data"; -DELETE FROM "system_role"; -DELETE FROM "system_role_menu"; -DELETE FROM "system_menu"; -DELETE FROM "system_user_role"; -DELETE FROM "system_dict_type"; -DELETE FROM "system_user_session"; -DELETE FROM "system_post"; -DELETE FROM "system_user_post"; -DELETE FROM "system_notice"; -DELETE FROM "system_login_log"; -DELETE FROM "system_operate_log"; -DELETE FROM "system_users"; -DELETE FROM "system_sms_channel"; -DELETE FROM "system_sms_template"; -DELETE FROM "system_sms_log"; -DELETE FROM "system_sms_code"; -DELETE FROM "system_social_client"; -DELETE FROM "system_social_user"; -DELETE FROM "system_social_user_bind"; -DELETE FROM "system_tenant"; -DELETE FROM "system_tenant_package"; -DELETE FROM "system_oauth2_client"; -DELETE FROM "system_oauth2_approve"; -DELETE FROM "system_oauth2_access_token"; -DELETE FROM "system_oauth2_refresh_token"; -DELETE FROM "system_oauth2_code"; -DELETE FROM "system_mail_account"; -DELETE FROM "system_mail_template"; -DELETE FROM "system_mail_log"; -DELETE FROM "system_notify_template"; -DELETE FROM "system_notify_message"; diff --git a/msgpush-module-system/msgpush-module-system-server/src/test/resources/sql/create_tables.sql b/msgpush-module-system/msgpush-module-system-server/src/test/resources/sql/create_tables.sql deleted file mode 100644 index 9970065..0000000 --- a/msgpush-module-system/msgpush-module-system-server/src/test/resources/sql/create_tables.sql +++ /dev/null @@ -1,617 +0,0 @@ -CREATE TABLE IF NOT EXISTS "system_dept" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(30) NOT NULL DEFAULT '', - "parent_id" bigint NOT NULL DEFAULT '0', - "sort" int NOT NULL DEFAULT '0', - "leader_user_id" bigint DEFAULT NULL, - "phone" varchar(11) DEFAULT NULL, - "email" varchar(50) DEFAULT NULL, - "status" tinyint NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT '部门表'; - -CREATE TABLE IF NOT EXISTS "system_dict_data" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "sort" int NOT NULL DEFAULT '0', - "label" varchar(100) NOT NULL DEFAULT '', - "value" varchar(100) NOT NULL DEFAULT '', - "dict_type" varchar(100) NOT NULL DEFAULT '', - "status" tinyint NOT NULL DEFAULT '0', - "color_type" varchar(100) NOT NULL DEFAULT '', - "css_class" varchar(100) NOT NULL DEFAULT '', - "remark" varchar(500) DEFAULT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '字典数据表'; - -CREATE TABLE IF NOT EXISTS "system_role" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(30) NOT NULL, - "code" varchar(100) NOT NULL, - "sort" int NOT NULL, - "data_scope" tinyint NOT NULL DEFAULT '1', - "data_scope_dept_ids" varchar(500) NOT NULL DEFAULT '', - "status" tinyint NOT NULL, - "type" tinyint NOT NULL, - "remark" varchar(500) DEFAULT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT '角色信息表'; - -CREATE TABLE IF NOT EXISTS "system_role_menu" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "role_id" bigint NOT NULL, - "menu_id" bigint NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT '角色和菜单关联表'; - -CREATE TABLE IF NOT EXISTS "system_menu" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(50) NOT NULL, - "permission" varchar(100) NOT NULL DEFAULT '', - "type" tinyint NOT NULL, - "sort" int NOT NULL DEFAULT '0', - "parent_id" bigint NOT NULL DEFAULT '0', - "path" varchar(200) DEFAULT '', - "icon" varchar(100) DEFAULT '#', - "component" varchar(255) DEFAULT NULL, - "component_name" varchar(255) DEFAULT NULL, - "status" tinyint NOT NULL DEFAULT '0', - "visible" bit NOT NULL DEFAULT TRUE, - "keep_alive" bit NOT NULL DEFAULT TRUE, - "always_show" bit NOT NULL DEFAULT TRUE, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '菜单权限表'; - -CREATE TABLE IF NOT EXISTS "system_user_role" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint NOT NULL, - "role_id" bigint NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp DEFAULT NULL, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp DEFAULT NULL, - "deleted" bit DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT '用户和角色关联表'; - -CREATE TABLE IF NOT EXISTS "system_dict_type" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(100) NOT NULL DEFAULT '', - "type" varchar(100) NOT NULL DEFAULT '', - "status" tinyint NOT NULL DEFAULT '0', - "remark" varchar(500) DEFAULT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "deleted_time" timestamp NOT NULL, - PRIMARY KEY ("id") -) COMMENT '字典类型表'; - -CREATE TABLE IF NOT EXISTS `system_user_session` ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - `token` varchar(32) NOT NULL, - `user_id` bigint DEFAULT NULL, - "user_type" tinyint NOT NULL, - `username` varchar(50) NOT NULL DEFAULT '', - `user_ip` varchar(50) DEFAULT NULL, - `user_agent` varchar(512) DEFAULT NULL, - `session_timeout` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updater` varchar(64) DEFAULT '' , - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY (`id`) -) COMMENT '用户在线 Session'; - -CREATE TABLE IF NOT EXISTS "system_post" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "code" varchar(64) NOT NULL, - "name" varchar(50) NOT NULL, - "sort" integer NOT NULL, - "status" tinyint NOT NULL, - "remark" varchar(500) DEFAULT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT '岗位信息表'; - -CREATE TABLE IF NOT EXISTS `system_user_post`( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint DEFAULT NULL, - "post_id" bigint DEFAULT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY (`id`) -) COMMENT ='用户岗位表'; - -CREATE TABLE IF NOT EXISTS "system_notice" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "title" varchar(50) NOT NULL COMMENT '公告标题', - "content" text NOT NULL COMMENT '公告内容', - "type" tinyint NOT NULL COMMENT '公告类型(1通知 2公告)', - "status" tinyint NOT NULL DEFAULT '0' COMMENT '公告状态(0正常 1关闭)', - "creator" varchar(64) DEFAULT '' COMMENT '创建者', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - "updater" varchar(64) DEFAULT '' COMMENT '更新者', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - "deleted" bit NOT NULL DEFAULT 0 COMMENT '是否删除', - "tenant_id" bigint not null default '0', - PRIMARY KEY("id") -) COMMENT '通知公告表'; - -CREATE TABLE IF NOT EXISTS `system_login_log` ( - `id` bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, - `log_type` bigint(4) NOT NULL, - "user_id" bigint not null default '0', - "user_type" tinyint NOT NULL, - `trace_id` varchar(64) NOT NULL DEFAULT '', - `username` varchar(50) NOT NULL DEFAULT '', - `result` tinyint(4) NOT NULL, - `user_ip` varchar(50) NOT NULL, - `user_agent` varchar(512) NOT NULL, - `creator` varchar(64) DEFAULT '', - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updater` varchar(64) DEFAULT '', - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `deleted` bit(1) NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) COMMENT ='系统访问记录'; - -CREATE TABLE IF NOT EXISTS `system_operate_log` ( - `id` bigint(20) NOT NULL GENERATED BY DEFAULT AS IDENTITY, - `trace_id` varchar(64) NOT NULL DEFAULT '', - `user_id` bigint(20) NOT NULL, - "user_type" tinyint not null default '0', - `type` varchar(50) NOT NULL, - `sub_type` varchar(50) NOT NULL, - `biz_id` bigint(20) NOT NULL, - `action` varchar(2000) NOT NULL DEFAULT '', - `extra` varchar(512) NOT NULL DEFAULT '', - `request_method` varchar(16) DEFAULT '', - `request_url` varchar(255) DEFAULT '', - `user_ip` varchar(50) DEFAULT NULL, - `user_agent` varchar(200) DEFAULT NULL, - `creator` varchar(64) DEFAULT '', - `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updater` varchar(64) DEFAULT '', - `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `deleted` bit(1) NOT NULL DEFAULT '0', - "tenant_id" bigint not null default '0', - PRIMARY KEY (`id`) -) COMMENT ='操作日志记录'; - -CREATE TABLE IF NOT EXISTS "system_users" ( - "id" bigint not null GENERATED BY DEFAULT AS IDENTITY, - "username" varchar(30) not null, - "password" varchar(100) not null default '', - "nickname" varchar(30) not null, - "remark" varchar(500) default null, - "dept_id" bigint default null, - "post_ids" varchar(255) default null, - "email" varchar(50) default '', - "mobile" varchar(11) default '', - "sex" tinyint default '0', - "avatar" varchar(100) default '', - "status" tinyint not null default '0', - "login_ip" varchar(50) default '', - "login_date" timestamp default null, - "creator" varchar(64) default '', - "create_time" timestamp not null default current_timestamp, - "updater" varchar(64) default '', - "update_time" timestamp not null default current_timestamp, - "deleted" bit not null default false, - "tenant_id" bigint not null default '0', - primary key ("id") -) comment '用户信息表'; - -CREATE TABLE IF NOT EXISTS "system_sms_channel" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "signature" varchar(10) NOT NULL, - "code" varchar(63) NOT NULL, - "status" tinyint NOT NULL, - "remark" varchar(255) DEFAULT NULL, - "api_key" varchar(63) NOT NULL, - "api_secret" varchar(63) DEFAULT NULL, - "callback_url" varchar(255) DEFAULT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '短信渠道'; - -CREATE TABLE IF NOT EXISTS "system_sms_template" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "type" tinyint NOT NULL, - "status" tinyint NOT NULL, - "code" varchar(63) NOT NULL, - "name" varchar(63) NOT NULL, - "content" varchar(255) NOT NULL, - "params" varchar(255) NOT NULL, - "remark" varchar(255) DEFAULT NULL, - "api_template_id" varchar(63) NOT NULL, - "channel_id" bigint NOT NULL, - "channel_code" varchar(63) NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '短信模板'; - -CREATE TABLE IF NOT EXISTS "system_sms_log" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "channel_id" bigint NOT NULL, - "channel_code" varchar(63) NOT NULL, - "template_id" bigint NOT NULL, - "template_code" varchar(63) NOT NULL, - "template_type" tinyint NOT NULL, - "template_content" varchar(255) NOT NULL, - "template_params" varchar(255) NOT NULL, - "api_template_id" varchar(63) NOT NULL, - "mobile" varchar(11) NOT NULL, - "user_id" bigint DEFAULT '0', - "user_type" tinyint DEFAULT '0', - "send_status" tinyint NOT NULL DEFAULT '0', - "send_time" timestamp DEFAULT NULL, - "send_code" int DEFAULT NULL, - "send_msg" varchar(255) DEFAULT NULL, - "api_send_code" varchar(63) DEFAULT NULL, - "api_send_msg" varchar(255) DEFAULT NULL, - "api_request_id" varchar(255) DEFAULT NULL, - "api_serial_no" varchar(255) DEFAULT NULL, - "receive_status" tinyint NOT NULL DEFAULT '0', - "receive_time" timestamp DEFAULT NULL, - "api_receive_code" varchar(63) DEFAULT NULL, - "api_receive_msg" varchar(255) DEFAULT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '短信日志'; - -CREATE TABLE IF NOT EXISTS "system_sms_code" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "mobile" varchar(11) NOT NULL, - "code" varchar(11) NOT NULL, - "scene" bigint NOT NULL, - "create_ip" varchar NOT NULL, - "today_index" int NOT NULL, - "used" bit NOT NULL DEFAULT FALSE, - "used_time" timestamp DEFAULT NULL, - "used_ip" varchar NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '短信日志'; - -CREATE TABLE IF NOT EXISTS "system_social_client" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(255) NOT NULL, - "social_type" int NOT NULL, - "user_type" int NOT NULL, - "client_id" varchar(255) NOT NULL, - "client_secret" varchar(255) NOT NULL, - "public_key" varchar(2048) NOT NULL, - "agent_id" varchar(255) NOT NULL, - "status" int NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT '社交客户端表'; - -CREATE TABLE IF NOT EXISTS "system_social_user" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "type" tinyint NOT NULL, - "openid" varchar(64) NOT NULL, - "token" varchar(256) DEFAULT NULL, - "raw_token_info" varchar(1024) NOT NULL, - "nickname" varchar(32) NOT NULL, - "avatar" varchar(255) DEFAULT NULL, - "raw_user_info" varchar(1024) NOT NULL, - "code" varchar(64) NOT NULL, - "state" varchar(64), - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '社交用户'; - -CREATE TABLE IF NOT EXISTS "system_social_user_bind" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint NOT NULL, - "user_type" tinyint NOT NULL, - "social_type" tinyint NOT NULL, - "social_user_id" number NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '社交用户的绑定'; - -CREATE TABLE IF NOT EXISTS "system_tenant" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(63) NOT NULL, - "contact_user_id" bigint NOT NULL DEFAULT '0', - "contact_name" varchar(255) NOT NULL, - "contact_mobile" varchar(255), - "status" tinyint NOT NULL, - "websites" varchar(1024) DEFAULT '', - "package_id" bigint NOT NULL, - "expire_time" timestamp NOT NULL, - "account_count" int NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '租户'; - -CREATE TABLE IF NOT EXISTS "system_tenant_package" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar(30) NOT NULL, - "status" tinyint NOT NULL, - "remark" varchar(256), - "menu_ids" varchar(2048) NOT NULL, - "creator" varchar(64) DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar(64) DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '租户套餐表'; - -CREATE TABLE IF NOT EXISTS "system_oauth2_client" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "client_id" varchar NOT NULL, - "secret" varchar NOT NULL, - "name" varchar NOT NULL, - "logo" varchar NOT NULL, - "description" varchar, - "status" int NOT NULL, - "access_token_validity_seconds" int NOT NULL, - "refresh_token_validity_seconds" int NOT NULL, - "redirect_uris" varchar NOT NULL, - "authorized_grant_types" varchar NOT NULL, - "scopes" varchar NOT NULL DEFAULT '', - "auto_approve_scopes" varchar NOT NULL DEFAULT '', - "authorities" varchar NOT NULL DEFAULT '', - "resource_ids" varchar NOT NULL DEFAULT '', - "additional_information" varchar NOT NULL DEFAULT '', - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT 'OAuth2 客户端表'; - -CREATE TABLE IF NOT EXISTS "system_oauth2_approve" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint NOT NULL, - "user_type" tinyint NOT NULL, - "client_id" varchar NOT NULL, - "scope" varchar NOT NULL, - "approved" bit NOT NULL DEFAULT FALSE, - "expires_time" datetime NOT NULL, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT 'OAuth2 批准表'; - -CREATE TABLE IF NOT EXISTS "system_oauth2_access_token" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint NOT NULL, - "user_type" tinyint NOT NULL, - "user_info" varchar NOT NULL, - "access_token" varchar NOT NULL, - "refresh_token" varchar NOT NULL, - "client_id" varchar NOT NULL, - "scopes" varchar NOT NULL, - "approved" bit NOT NULL DEFAULT FALSE, - "expires_time" datetime NOT NULL, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null, - PRIMARY KEY ("id") -) COMMENT 'OAuth2 访问令牌'; - -CREATE TABLE IF NOT EXISTS "system_oauth2_refresh_token" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint NOT NULL, - "user_type" tinyint NOT NULL, - "refresh_token" varchar NOT NULL, - "client_id" varchar NOT NULL, - "scopes" varchar NOT NULL, - "approved" bit NOT NULL DEFAULT FALSE, - "expires_time" datetime NOT NULL, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT 'OAuth2 刷新令牌'; - -CREATE TABLE IF NOT EXISTS "system_oauth2_code" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint NOT NULL, - "user_type" tinyint NOT NULL, - "code" varchar NOT NULL, - "client_id" varchar NOT NULL, - "scopes" varchar NOT NULL, - "expires_time" datetime NOT NULL, - "redirect_uri" varchar NOT NULL, - "state" varchar NOT NULL, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT 'OAuth2 刷新令牌'; - -CREATE TABLE IF NOT EXISTS "system_mail_account" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "mail" varchar NOT NULL, - "username" varchar NOT NULL, - "password" varchar NOT NULL, - "host" varchar NOT NULL, - "port" int NOT NULL, - "ssl_enable" bit NOT NULL, - "starttls_enable" bit NOT NULL, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '邮箱账号表'; - -CREATE TABLE IF NOT EXISTS "system_mail_template" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar NOT NULL, - "code" varchar NOT NULL, - "account_id" bigint NOT NULL, - "nickname" varchar, - "title" varchar NOT NULL, - "content" varchar NOT NULL, - "params" varchar NOT NULL, - "status" varchar NOT NULL, - "remark" varchar, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '邮件模版表'; - -CREATE TABLE IF NOT EXISTS "system_mail_log" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint, - "user_type" varchar, - "to_mails" varchar NOT NULL, - "cc_mails" varchar, - "bcc_mails" varchar, - "account_id" bigint NOT NULL, - "from_mail" varchar NOT NULL, - "template_id" bigint NOT NULL, - "template_code" varchar NOT NULL, - "template_nickname" varchar, - "template_title" varchar NOT NULL, - "template_content" varchar NOT NULL, - "template_params" varchar NOT NULL, - "send_status" varchar NOT NULL, - "send_time" datetime, - "send_message_id" varchar, - "send_exception" varchar, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '邮件日志表'; - -CREATE TABLE IF NOT EXISTS "system_notify_template" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "name" varchar NOT NULL, - "code" varchar NOT NULL, - "nickname" varchar NOT NULL, - "content" varchar NOT NULL, - "type" varchar NOT NULL, - "params" varchar, - "status" varchar NOT NULL, - "remark" varchar, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - PRIMARY KEY ("id") -) COMMENT '站内信模板表'; - -CREATE TABLE IF NOT EXISTS "system_notify_message" ( - "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint NOT NULL, - "user_type" varchar NOT NULL, - "template_id" bigint NOT NULL, - "template_code" varchar NOT NULL, - "template_nickname" varchar NOT NULL, - "template_content" varchar NOT NULL, - "template_type" int NOT NULL, - "template_params" varchar NOT NULL, - "read_status" bit NOT NULL, - "read_time" varchar, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT '站内信消息表'; diff --git a/msgpush-server/src/main/resources/application.yaml b/msgpush-server/src/main/resources/application.yaml index 7d65f0c..5ea17aa 100644 --- a/msgpush-server/src/main/resources/application.yaml +++ b/msgpush-server/src/main/resources/application.yaml @@ -144,23 +144,5 @@ msgpush: vo-type: 10 # VO 的类型,参见 CodegenVOTypeEnum 枚举类 delete-batch-enable: true # 是否生成批量删除接口 unit-test-enable: false # 是否生成单元测试 - tenant: # 多租户相关配置项 - enable: true - ignore-urls: - - /jmreport/* # 积木报表,无法携带租户编号 - ignore-visit-urls: - - /admin-api/system/user/profile/** - - /admin-api/system/auth/** - ignore-tables: - ignore-caches: - - user_role_ids - - permission_menu_ids - - oauth_client - - notify_template - - mail_account - - mail_template - - sms_template - - iot:device - - iot:thing_model_list debug: false \ No newline at end of file