Merge branch 'master' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into feature/mall_product

# Conflicts:
#	sql/mysql/mall.sql
#	sql/mysql/ruoyi-vue-pro.sql
#	yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/recharge/AppPayWalletRechargeCreateReqVO.java
#	yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java
#	yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserService.java
This commit is contained in:
YunaiV 2023-11-04 20:48:27 +08:00
commit 787de1be94
194 changed files with 1637 additions and 2116 deletions

View File

@ -256,7 +256,7 @@ _前端基于 crmeb uniapp 经过授权重构,优化代码实现,接入芋
| 框架 | 说明 | 版本 | 学习指南 |
|---------------------------------------------------------------------------------------------|------------------|----------------|----------------------------------------------------------------|
| [Spring Boot](https://spring.io/projects/spring-boot) | 应用开发框架 | 2.7.16 | [文档](https://github.com/YunaiV/SpringBoot-Labs) |
| [Spring Boot](https://spring.io/projects/spring-boot) | 应用开发框架 | 2.7.17 | [文档](https://github.com/YunaiV/SpringBoot-Labs) |
| [MySQL](https://www.mysql.com/cn/) | 数据库服务器 | 5.7 / 8.0+ | |
| [Druid](https://github.com/alibaba/druid) | JDBC 连接池、监控组件 | 1.2.19 | [文档](http://www.iocoder.cn/Spring-Boot/datasource-pool/?yudao) |
| [MyBatis Plus](https://mp.baomidou.com/) | MyBatis 增强工具包 | 3.5.3.2 | [文档](http://www.iocoder.cn/Spring-Boot/MyBatis/?yudao) |

14
pom.xml
View File

@ -13,16 +13,16 @@
<!-- Server 主项目 -->
<module>yudao-server</module>
<!-- 各种 module 拓展 -->
<module>yudao-module-member</module>
<module>yudao-module-system</module>
<module>yudao-module-infra</module>
<!-- <module>yudao-module-bpm</module>-->
<!-- <module>yudao-module-member</module>-->
<!-- <module>yudao-module-bpm</module>-->
<!-- <module>yudao-module-report</module>-->
<!-- <module>yudao-module-mp</module>-->
<module>yudao-module-pay</module>
<module>yudao-module-mall</module>
<!-- <module>yudao-module-pay</module>-->
<!-- <module>yudao-module-mall</module>-->
<!-- 示例项目 -->
<module>yudao-example</module>
<!-- <module>yudao-example</module>-->
</modules>
<name>${project.artifactId}</name>
@ -30,7 +30,7 @@
<url>https://github.com/YunaiV/ruoyi-vue-pro</url>
<properties>
<revision>1.8.2-snapshot</revision>
<revision>1.8.3-snapshot</revision>
<!-- Maven 相关 -->
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
@ -40,7 +40,7 @@
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
<!-- 看看咋放到 bom 里 -->
<lombok.version>1.18.30</lombok.version>
<spring.boot.version>2.7.16</spring.boot.version>
<spring.boot.version>2.7.17</spring.boot.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

View File

@ -14,28 +14,30 @@
<url>https://github.com/YunaiV/ruoyi-vue-pro</url>
<properties>
<revision>1.8.2-snapshot</revision>
<revision>1.8.3-snapshot</revision>
<flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
<!-- 统一依赖管理 -->
<spring.boot.version>2.7.16</spring.boot.version>
<spring.boot.version>2.7.17</spring.boot.version>
<!-- Web 相关 -->
<springdoc.version>1.6.15</springdoc.version>
<knife4j.version>4.3.0</knife4j.version>
<servlet.versoin>2.5</servlet.versoin>
<!-- DB 相关 -->
<druid.version>1.2.19</druid.version>
<mybatis-plus.version>3.5.3.2</mybatis-plus.version>
<mybatis-plus-generator.version>3.5.3.2</mybatis-plus-generator.version>
<druid.version>1.2.20</druid.version>
<mybatis-plus.version>3.5.4</mybatis-plus.version>
<mybatis-plus-generator.version>3.5.4</mybatis-plus-generator.version>
<dynamic-datasource.version>3.6.1</dynamic-datasource.version>
<mybatis-plus-join.version>1.4.6</mybatis-plus-join.version>
<mybatis-plus-join.version>1.4.7</mybatis-plus-join.version>
<redisson.version>3.18.0</redisson.version>
<dm8.jdbc.version>8.1.2.141</dm8.jdbc.version>
<dm8.jdbc.version>8.1.3.62</dm8.jdbc.version>
<!-- 消息队列 -->
<rocketmq-spring.version>2.2.3</rocketmq-spring.version>
<!-- 服务保障相关 -->
<lock4j.version>2.2.3</lock4j.version>
<lock4j.version>2.2.5</lock4j.version>
<resilience4j.version>1.7.1</resilience4j.version>
<!-- 监控相关 -->
<skywalking.version>8.12.0</skywalking.version>
<spring-boot-admin.version>2.7.10</spring-boot-admin.version>
<spring-boot-admin.version>2.7.11</spring-boot-admin.version>
<opentracing.version>0.33.0</opentracing.version>
<!-- Test 测试相关 -->
<podam.version>7.2.11.RELEASE</podam.version>
@ -44,8 +46,8 @@
<!-- Bpm 工作流相关 -->
<flowable.version>6.8.0</flowable.version>
<!-- 工具类相关 -->
<captcha-plus.version>1.0.8</captcha-plus.version>
<jsoup.version>1.16.1</jsoup.version>
<captcha-plus.version>1.0.10</captcha-plus.version>
<jsoup.version>1.16.2</jsoup.version>
<lombok.version>1.18.30</lombok.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<hutool.version>5.8.22</hutool.version>
@ -53,10 +55,10 @@
<velocity.version>2.3</velocity.version>
<screw.version>1.0.5</screw.version>
<fastjson.version>1.2.83</fastjson.version>
<guava.version>32.1.2-jre</guava.version>
<guava.version>32.1.3-jre</guava.version>
<guice.version>5.1.0</guice.version>
<transmittable-thread-local.version>2.14.2</transmittable-thread-local.version>
<commons-net.version>3.9.0</commons-net.version>
<commons-net.version>3.10.0</commons-net.version>
<jsch.version>0.1.55</jsch.version>
<tika-core.version>2.7.0</tika-core.version>
<ip2region.version>2.7.0</ip2region.version>
@ -67,8 +69,8 @@
<minio.version>8.5.6</minio.version>
<aliyun-java-sdk-core.version>4.6.4</aliyun-java-sdk-core.version>
<aliyun-java-sdk-dysmsapi.version>2.2.1</aliyun-java-sdk-dysmsapi.version>
<tencentcloud-sdk-java.version>3.1.853</tencentcloud-sdk-java.version>
<justauth.version>1.0.5</justauth.version>
<tencentcloud-sdk-java.version>3.1.880</tencentcloud-sdk-java.version>
<justauth.version>1.0.7</justauth.version>
<jimureport.version>1.6.1</jimureport.version>
<xercesImpl.version>2.12.2</xercesImpl.version>
<weixin-java.version>4.5.0</weixin-java.version>
@ -96,11 +98,6 @@
<artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-trade</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-dict</artifactId>
@ -260,6 +257,12 @@
<version>${revision}</version>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>${rocketmq-spring.version}</version>
</dependency>
<!-- 服务保障相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>

View File

@ -21,7 +21,7 @@
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 统一依赖管理 -->
<spring.boot.version>2.7.16</spring.boot.version>
<spring.boot.version>2.7.17</spring.boot.version>
</properties>
<dependencyManagement>

View File

@ -21,7 +21,7 @@
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 统一依赖管理 -->
<spring.boot.version>2.7.16</spring.boot.version>
<spring.boot.version>2.7.17</spring.boot.version>
</properties>
<dependencyManagement>

View File

@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* Key Value 的键值对
*
@ -12,7 +14,7 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class KeyValue<K, V> {
public class KeyValue<K, V> implements Serializable {
private K key;
private V value;

View File

@ -8,6 +8,7 @@ import com.google.common.collect.ImmutableMap;
import java.util.*;
import java.util.function.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.util.Arrays.asList;
@ -271,4 +272,20 @@ public class CollectionUtils {
return deptId == null ? Collections.emptyList() : Collections.singleton(deptId);
}
public static <T, U> List<U> convertListByFlatMap(Collection<T> from,
Function<T, ? extends Stream<? extends U>> func) {
if (CollUtil.isEmpty(from)) {
return new ArrayList<>();
}
return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toList());
}
public static <T, U> Set<U> convertSetByFlatMap(Collection<T> from,
Function<T, ? extends Stream<? extends U>> func) {
if (CollUtil.isEmpty(from)) {
return new HashSet<>();
}
return from.stream().flatMap(func).filter(Objects::nonNull).collect(Collectors.toSet());
}
}

View File

@ -21,7 +21,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@ConditionalOnProperty(prefix = "yudao.error-code", value = "enable", matchIfMissing = true) // 允许使用 yudao.error-code.enable=false 禁用访问日志
@EnableConfigurationProperties(ErrorCodeProperties.class)
@EnableScheduling // 开启调度任务的功能因为 ErrorCodeRemoteLoader 通过定时刷新错误码
public class YudaoErrorCodeConfiguration {
public class YudaoErrorCodeAutoConfiguration {
@Bean
public ErrorCodeAutoGenerator errorCodeAutoGenerator(@Value("${spring.application.name}") String applicationName,

View File

@ -1 +1 @@
cn.iocoder.yudao.framework.errorcode.config.YudaoErrorCodeConfiguration
cn.iocoder.yudao.framework.errorcode.config.YudaoErrorCodeAutoConfiguration

View File

@ -48,6 +48,22 @@
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-mq</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<optional>true</optional>
</dependency>
<!-- Test 测试相关 -->

View File

@ -6,7 +6,9 @@ import cn.iocoder.yudao.framework.redis.config.YudaoCacheProperties;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnoreAspect;
import cn.iocoder.yudao.framework.tenant.core.db.TenantDatabaseInterceptor;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJobAspect;
import cn.iocoder.yudao.framework.tenant.core.mq.TenantRedisMessageInterceptor;
import cn.iocoder.yudao.framework.tenant.core.mq.rabbitmq.TenantRabbitMQInitializer;
import cn.iocoder.yudao.framework.tenant.core.mq.redis.TenantRedisMessageInterceptor;
import cn.iocoder.yudao.framework.tenant.core.mq.rocketmq.TenantRocketMQInitializer;
import cn.iocoder.yudao.framework.tenant.core.redis.TenantRedisCacheManager;
import cn.iocoder.yudao.framework.tenant.core.security.TenantSecurityWebFilter;
import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService;
@ -18,6 +20,7 @@ import cn.iocoder.yudao.module.system.api.tenant.TenantApi;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
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;
@ -92,6 +95,18 @@ public class YudaoTenantAutoConfiguration {
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();
}
// ========== Job ==========
@Bean

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.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 芋道源码
*/
@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 依赖
}
}
}

View File

@ -0,0 +1,47 @@
package cn.iocoder.yudao.framework.tenant.core.mq.kafka;
import cn.hutool.core.util.ReflectUtil;
import cn.iocoder.yudao.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 cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID;
/**
* Kafka 消息队列的多租户 {@link ProducerInterceptor} 实现类
*
* 1. Producer 发送消息时 {@link TenantContextHolder} 租户编号添加到消息的 Header
* 2. Consumer 消费消息时将消息的 Header 的租户编号添加到 {@link TenantContextHolder} 通过 {@link InvocableHandlerMethod} 实现
*
* @author 芋道源码
*/
public class TenantKafkaProducerInterceptor implements ProducerInterceptor<Object, Object> {
@Override
public ProducerRecord<Object, Object> onSend(ProducerRecord<Object, Object> 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<String, ?> configs) {
}
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.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 芋道源码
*/
public class TenantRabbitMQInitializer implements BeanPostProcessor {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof RabbitTemplate) {
RabbitTemplate rabbitTemplate = (RabbitTemplate) bean;
rabbitTemplate.addBeforePublishPostProcessors(new TenantRabbitMQMessagePostProcessor());
}
return bean;
}
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.yudao.framework.tenant.core.mq.rabbitmq;
import cn.iocoder.yudao.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 cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID;
/**
* RabbitMQ 消息队列的多租户 {@link ProducerInterceptor} 实现类
*
* 1. Producer 发送消息时 {@link TenantContextHolder} 租户编号添加到消息的 Header
* 2. Consumer 消费消息时将消息的 Header 的租户编号添加到 {@link TenantContextHolder} 通过 {@link InvocableHandlerMethod} 实现
*
* @author 芋道源码
*/
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;
}
}

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.framework.tenant.core.mq;
package cn.iocoder.yudao.framework.tenant.core.mq.redis;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.mq.core.interceptor.RedisMessageInterceptor;
import cn.iocoder.yudao.framework.mq.core.message.AbstractRedisMessage;
import cn.iocoder.yudao.framework.mq.redis.core.interceptor.RedisMessageInterceptor;
import cn.iocoder.yudao.framework.mq.redis.core.message.AbstractRedisMessage;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID;

View File

@ -0,0 +1,46 @@
package cn.iocoder.yudao.framework.tenant.core.mq.rocketmq;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.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 cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID;
/**
* RocketMQ 消息队列的多租户 {@link ConsumeMessageHook} 实现类
*
* Consumer 消费消息时将消息的 Header 的租户编号添加到 {@link TenantContextHolder} 通过 {@link InvocableHandlerMethod} 实现
*
* @author 芋道源码
*/
public class TenantRocketMQConsumeMessageHook implements ConsumeMessageHook {
@Override
public String hookName() {
return getClass().getSimpleName();
}
@Override
public void consumeMessageBefore(ConsumeMessageContext context) {
// 校验消息必须是单条不然设置租户可能不正确
List<MessageExt> 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();
}
}

View File

@ -0,0 +1,53 @@
package cn.iocoder.yudao.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 芋道源码
*/
public class TenantRocketMQInitializer implements BeanPostProcessor {
@Override
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());
}
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.framework.tenant.core.mq.rocketmq;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import org.apache.rocketmq.client.hook.SendMessageContext;
import org.apache.rocketmq.client.hook.SendMessageHook;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID;
/**
* RocketMQ 消息队列的多租户 {@link SendMessageHook} 实现类
*
* Producer 发送消息时 {@link TenantContextHolder} 租户编号添加到消息的 Header
*
* @author 芋道源码
*/
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) {
}
}

View File

@ -0,0 +1,269 @@
/*
* Copyright 2002-2021 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 cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.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 java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Arrays;
import static cn.iocoder.yudao.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).
* <p>Default is a {@link DefaultParameterNameDiscoverer}.
*/
public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDiscoverer) {
this.parameterNameDiscoverer = parameterNameDiscoverer;
}
/**
* Invoke the method after resolving its argument values in the context of the given message.
* <p>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.
* <p>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.
* <p>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.getMessage() : "Illegal argument");
throw new IllegalStateException(formatInvokeError(text, args), ex);
}
catch (InvocationTargetException ex) {
// Unwrap for HandlerExceptionResolvers ...
Throwable targetException = ex.getTargetException();
if (targetException instanceof RuntimeException) {
throw (RuntimeException) targetException;
}
else if (targetException instanceof Error) {
throw (Error) targetException;
}
else if (targetException instanceof Exception) {
throw (Exception) targetException;
}
else {
throw new IllegalStateException(formatInvokeError("Invocation failure", args), targetException);
}
}
}
MethodParameter getAsyncReturnValueType(@Nullable Object returnValue) {
return new AsyncResultMethodParameter(returnValue);
}
private class AsyncResultMethodParameter extends HandlerMethodParameter {
@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);
}
}
}

View File

@ -0,0 +1,2 @@
org.springframework.boot.env.EnvironmentPostProcessor=\
cn.iocoder.yudao.framework.tenant.core.mq.kafka.TenantKafkaEnvironmentPostProcessor

View File

@ -1,28 +0,0 @@
package cn.iocoder.yudao.framework.tenant.core.job;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@Component
public class TestJob implements JobHandler {
private final List<Long> tenantIds = new CopyOnWriteArrayList<>();
@Override
@TenantJob // 标记多租户
public String execute(String param) throws Exception {
tenantIds.add(TenantContextHolder.getTenantId());
return "success";
}
public List<Long> getTenantIds() {
CollUtil.sort(tenantIds, Long::compareTo);
return tenantIds;
}
}

View File

@ -12,7 +12,7 @@
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>消息队列,基于 Redis Pub/Sub 实现广播消费,基于 Stream 实现集群消费</description>
<description>消息队列,支持 Redis、RocketMQ、RabbitMQ、Kafka 四种</description>
<url>https://github.com/YunaiV/ruoyi-vue-pro</url>
<dependencies>
@ -21,6 +21,23 @@
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-redis</artifactId>
</dependency>
<!-- 消息队列相关 -->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
</project>

View File

@ -1,21 +0,0 @@
package cn.iocoder.yudao.framework.mq.core.pubsub;
import cn.iocoder.yudao.framework.mq.core.message.AbstractRedisMessage;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Redis Channel Message 抽象类
*
* @author 芋道源码
*/
public abstract class AbstractChannelMessage extends AbstractRedisMessage {
/**
* 获得 Redis Channel
*
* @return Channel
*/
@JsonIgnore // 避免序列化原因是Redis 发布 Channel 消息的时候已经会指定
public abstract String getChannel();
}

View File

@ -1,21 +0,0 @@
package cn.iocoder.yudao.framework.mq.core.stream;
import cn.iocoder.yudao.framework.mq.core.message.AbstractRedisMessage;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Redis Stream Message 抽象类
*
* @author 芋道源码
*/
public abstract class AbstractStreamMessage extends AbstractRedisMessage {
/**
* 获得 Redis Stream Key
*
* @return Channel
*/
@JsonIgnore // 避免序列化
public abstract String getStreamKey();
}

View File

@ -1,6 +1,4 @@
/**
* 消息队列基于 Redis 提供
* 1. 基于 Pub/Sub 实现广播消费
* 2. 基于 Stream 实现集群消费
* 消息队列支持 RedisRocketMQRabbitMQKafka 四种
*/
package cn.iocoder.yudao.framework.mq;

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.framework.mq.rabbitmq.config;
import cn.hutool.core.util.ReflectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.utils.SerializationUtils;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import java.lang.reflect.Field;
/**
* RabbitMQ 消息队列配置类
*
* @author 芋道源码
*/
@AutoConfiguration
@Slf4j
@ConditionalOnClass(name = "org.springframework.amqp.rabbit.core.RabbitTemplate")
public class YudaoRabbitMQAutoConfiguration {
static {
// 强制设置 SerializationUtils TRUST_ALL true避免 RabbitMQ Consumer 反序列化消息报错
// 为什么不通过设置 spring.amqp.deserialization.trust.all 因为可能在 SerializationUtils static 初始化后
Field trustAllField = ReflectUtil.getField(SerializationUtils.class, "TRUST_ALL");
ReflectUtil.removeFinalModify(trustAllField);
ReflectUtil.setFieldValue(SerializationUtils.class, trustAllField, true);
}
}

View File

@ -0,0 +1,4 @@
/**
* 占位符无特殊逻辑
*/
package cn.iocoder.yudao.framework.mq.rabbitmq.core;

View File

@ -0,0 +1,4 @@
/**
* 消息队列基于 RabbitMQ 提供
*/
package cn.iocoder.yudao.framework.mq.rabbitmq;

View File

@ -1,21 +1,20 @@
package cn.iocoder.yudao.framework.mq.config;
package cn.iocoder.yudao.framework.mq.redis.config;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.system.SystemUtil;
import cn.iocoder.yudao.framework.common.enums.DocumentEnum;
import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate;
import cn.iocoder.yudao.framework.mq.core.interceptor.RedisMessageInterceptor;
import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessageListener;
import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener;
import cn.iocoder.yudao.framework.mq.job.RedisPendingMessageResendJob;
import cn.iocoder.yudao.framework.mq.redis.core.RedisMQTemplate;
import cn.iocoder.yudao.framework.mq.redis.core.interceptor.RedisMessageInterceptor;
import cn.iocoder.yudao.framework.mq.redis.core.job.RedisPendingMessageResendJob;
import cn.iocoder.yudao.framework.mq.redis.core.pubsub.AbstractRedisChannelMessageListener;
import cn.iocoder.yudao.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
import cn.iocoder.yudao.framework.redis.config.YudaoRedisAutoConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisServerCommands;
import org.springframework.data.redis.connection.stream.Consumer;
@ -27,7 +26,6 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.stream.DefaultStreamMessageListenerContainerX;
import org.springframework.data.redis.stream.StreamMessageListenerContainer;
import org.springframework.scheduling.annotation.EnableScheduling;
@ -42,7 +40,7 @@ import java.util.Properties;
@Slf4j
@EnableScheduling // 启用定时任务用于 RedisPendingMessageResendJob 重发消息
@AutoConfiguration(after = YudaoRedisAutoConfiguration.class)
public class YudaoMQAutoConfiguration {
public class YudaoRedisMQAutoConfiguration {
@Bean
public RedisMQTemplate redisMQTemplate(StringRedisTemplate redisTemplate,
@ -59,10 +57,9 @@ public class YudaoMQAutoConfiguration {
* 创建 Redis Pub/Sub 广播消费的容器
*/
@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnBean(AbstractChannelMessageListener.class) // 只有 AbstractChannelMessageListener 存在的时候才需要注册 Redis pubsub 监听
@ConditionalOnProperty(prefix = "yudao.mq.redis.pubsub", value = "enable", matchIfMissing = true) // 允许使用 yudao.mq.redis.pubsub.enable=false 禁用多租户
@ConditionalOnBean(AbstractRedisChannelMessageListener.class) // 只有 AbstractChannelMessageListener 存在的时候才需要注册 Redis pubsub 监听
public RedisMessageListenerContainer redisMessageListenerContainer(
RedisMQTemplate redisMQTemplate, List<AbstractChannelMessageListener<?>> listeners) {
RedisMQTemplate redisMQTemplate, List<AbstractRedisChannelMessageListener<?>> listeners) {
// 创建 RedisMessageListenerContainer 对象
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
// 设置 RedisConnection 工厂
@ -81,9 +78,8 @@ public class YudaoMQAutoConfiguration {
* 创建 Redis Stream 重新消费的任务
*/
@Bean
@ConditionalOnBean(AbstractStreamMessageListener.class) // 只有 AbstractStreamMessageListener 存在的时候才需要注册 Redis pubsub 监听
@ConditionalOnProperty(prefix = "yudao.mq.redis.stream", value = "enable", matchIfMissing = true) // 允许使用 yudao.mq.redis.stream.enable=false 禁用多租户
public RedisPendingMessageResendJob redisPendingMessageResendJob(List<AbstractStreamMessageListener<?>> listeners,
@ConditionalOnBean(AbstractRedisStreamMessageListener.class) // 只有 AbstractStreamMessageListener 存在的时候才需要注册 Redis pubsub 监听
public RedisPendingMessageResendJob redisPendingMessageResendJob(List<AbstractRedisStreamMessageListener<?>> listeners,
RedisMQTemplate redisTemplate,
@Value("${spring.application.name}") String groupName,
RedissonClient redissonClient) {
@ -92,14 +88,13 @@ public class YudaoMQAutoConfiguration {
/**
* 创建 Redis Stream 集群消费的容器
* <p>
* Redis Stream xreadgroup 命令https://www.geek-book.com/src/docs/redis/redis/redis.io/commands/xreadgroup.html
*
* 基础知识<a href="https://www.geek-book.com/src/docs/redis/redis/redis.io/commands/xreadgroup.html">Redis Stream xreadgroup 命令</a>
*/
@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnBean(AbstractStreamMessageListener.class) // 只有 AbstractStreamMessageListener 存在的时候才需要注册 Redis pubsub 监听
@ConditionalOnProperty(prefix = "yudao.mq.redis.stream", value = "enable", matchIfMissing = true) // 允许使用 yudao.mq.redis.stream.enable=false 禁用多租户
@ConditionalOnBean(AbstractRedisStreamMessageListener.class) // 只有 AbstractStreamMessageListener 存在的时候才需要注册 Redis pubsub 监听
public StreamMessageListenerContainer<String, ObjectRecord<String, String>> redisStreamMessageListenerContainer(
RedisMQTemplate redisMQTemplate, List<AbstractStreamMessageListener<?>> listeners) {
RedisMQTemplate redisMQTemplate, List<AbstractRedisStreamMessageListener<?>> listeners) {
RedisTemplate<String, ?> redisTemplate = redisMQTemplate.getRedisTemplate();
checkRedisVersion(redisTemplate);
// 第一步创建 StreamMessageListenerContainer 容器
@ -111,8 +106,7 @@ public class YudaoMQAutoConfiguration {
.build();
// 创建 container 对象
StreamMessageListenerContainer<String, ObjectRecord<String, String>> container =
// StreamMessageListenerContainer.create(redisTemplate.getRequiredConnectionFactory(), containerOptions);
DefaultStreamMessageListenerContainerX.create(redisMQTemplate.getRedisTemplate().getRequiredConnectionFactory(), containerOptions);
StreamMessageListenerContainer.create(redisMQTemplate.getRedisTemplate().getRequiredConnectionFactory(), containerOptions);
// 第二步注册监听器消费对应的 Stream 主题
String consumerName = buildConsumerName();

View File

@ -1,10 +1,10 @@
package cn.iocoder.yudao.framework.mq.core;
package cn.iocoder.yudao.framework.mq.redis.core;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.mq.core.interceptor.RedisMessageInterceptor;
import cn.iocoder.yudao.framework.mq.core.message.AbstractRedisMessage;
import cn.iocoder.yudao.framework.mq.core.pubsub.AbstractChannelMessage;
import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessage;
import cn.iocoder.yudao.framework.mq.redis.core.interceptor.RedisMessageInterceptor;
import cn.iocoder.yudao.framework.mq.redis.core.message.AbstractRedisMessage;
import cn.iocoder.yudao.framework.mq.redis.core.pubsub.AbstractRedisChannelMessage;
import cn.iocoder.yudao.framework.mq.redis.core.stream.AbstractRedisStreamMessage;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.data.redis.connection.stream.RecordId;
@ -35,7 +35,7 @@ public class RedisMQTemplate {
*
* @param message 消息
*/
public <T extends AbstractChannelMessage> void send(T message) {
public <T extends AbstractRedisChannelMessage> void send(T message) {
try {
sendMessageBefore(message);
// 发送消息
@ -51,7 +51,7 @@ public class RedisMQTemplate {
* @param message 消息
* @return 消息记录的编号对象
*/
public <T extends AbstractStreamMessage> RecordId send(T message) {
public <T extends AbstractRedisStreamMessage> RecordId send(T message) {
try {
sendMessageBefore(message);
// 发送消息

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.framework.mq.core.interceptor;
package cn.iocoder.yudao.framework.mq.redis.core.interceptor;
import cn.iocoder.yudao.framework.mq.core.message.AbstractRedisMessage;
import cn.iocoder.yudao.framework.mq.redis.core.message.AbstractRedisMessage;
/**
* {@link AbstractRedisMessage} 消息拦截器

View File

@ -1,8 +1,8 @@
package cn.iocoder.yudao.framework.mq.job;
package cn.iocoder.yudao.framework.mq.redis.core.job;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate;
import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener;
import cn.iocoder.yudao.framework.mq.redis.core.RedisMQTemplate;
import cn.iocoder.yudao.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
@ -33,7 +33,7 @@ public class RedisPendingMessageResendJob {
*/
private static final int EXPIRE_TIME = 5 * 60;
private final List<AbstractStreamMessageListener<?>> listeners;
private final List<AbstractRedisStreamMessageListener<?>> listeners;
private final RedisMQTemplate redisTemplate;
private final String groupName;
private final RedissonClient redissonClient;

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.framework.mq.redis.core.pubsub;
import cn.iocoder.yudao.framework.mq.redis.core.message.AbstractRedisMessage;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Redis Channel Message 抽象类
*
* @author 芋道源码
*/
public abstract class AbstractRedisChannelMessage extends AbstractRedisMessage {
/**
* 获得 Redis Channel默认使用类名
*
* @return Channel
*/
@JsonIgnore // 避免序列化原因是Redis 发布 Channel 消息的时候已经会指定
public String getChannel() {
return getClass().getSimpleName();
}
}

View File

@ -1,10 +1,10 @@
package cn.iocoder.yudao.framework.mq.core.pubsub;
package cn.iocoder.yudao.framework.mq.redis.core.pubsub;
import cn.hutool.core.util.TypeUtil;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate;
import cn.iocoder.yudao.framework.mq.core.interceptor.RedisMessageInterceptor;
import cn.iocoder.yudao.framework.mq.core.message.AbstractRedisMessage;
import cn.iocoder.yudao.framework.mq.redis.core.RedisMQTemplate;
import cn.iocoder.yudao.framework.mq.redis.core.interceptor.RedisMessageInterceptor;
import cn.iocoder.yudao.framework.mq.redis.core.message.AbstractRedisMessage;
import lombok.Setter;
import lombok.SneakyThrows;
import org.springframework.data.redis.connection.Message;
@ -20,7 +20,7 @@ import java.util.List;
*
* @author 芋道源码
*/
public abstract class AbstractChannelMessageListener<T extends AbstractChannelMessage> implements MessageListener {
public abstract class AbstractRedisChannelMessageListener<T extends AbstractRedisChannelMessage> implements MessageListener {
/**
* 消息类型
@ -37,7 +37,7 @@ public abstract class AbstractChannelMessageListener<T extends AbstractChannelMe
private RedisMQTemplate redisMQTemplate;
@SneakyThrows
protected AbstractChannelMessageListener() {
protected AbstractRedisChannelMessageListener() {
this.messageType = getMessageClass();
this.channel = messageType.getDeclaredConstructor().newInstance().getChannel();
}

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.framework.mq.redis.core.stream;
import cn.iocoder.yudao.framework.mq.redis.core.message.AbstractRedisMessage;
import com.fasterxml.jackson.annotation.JsonIgnore;
/**
* Redis Stream Message 抽象类
*
* @author 芋道源码
*/
public abstract class AbstractRedisStreamMessage extends AbstractRedisMessage {
/**
* 获得 Redis Stream Key默认使用类名
*
* @return Channel
*/
@JsonIgnore // 避免序列化
public String getStreamKey() {
return getClass().getSimpleName();
}
}

View File

@ -1,10 +1,10 @@
package cn.iocoder.yudao.framework.mq.core.stream;
package cn.iocoder.yudao.framework.mq.redis.core.stream;
import cn.hutool.core.util.TypeUtil;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate;
import cn.iocoder.yudao.framework.mq.core.interceptor.RedisMessageInterceptor;
import cn.iocoder.yudao.framework.mq.core.message.AbstractRedisMessage;
import cn.iocoder.yudao.framework.mq.redis.core.RedisMQTemplate;
import cn.iocoder.yudao.framework.mq.redis.core.interceptor.RedisMessageInterceptor;
import cn.iocoder.yudao.framework.mq.redis.core.message.AbstractRedisMessage;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
@ -22,7 +22,7 @@ import java.util.List;
*
* @author 芋道源码
*/
public abstract class AbstractStreamMessageListener<T extends AbstractStreamMessage>
public abstract class AbstractRedisStreamMessageListener<T extends AbstractRedisStreamMessage>
implements StreamListener<String, ObjectRecord<String, String>> {
/**
@ -48,7 +48,7 @@ public abstract class AbstractStreamMessageListener<T extends AbstractStreamMess
private RedisMQTemplate redisMQTemplate;
@SneakyThrows
protected AbstractStreamMessageListener() {
protected AbstractRedisStreamMessageListener() {
this.messageType = getMessageClass();
this.streamKey = messageType.getDeclaredConstructor().newInstance().getStreamKey();
}

View File

@ -0,0 +1,6 @@
/**
* 消息队列基于 Redis 提供
* 1. 基于 Pub/Sub 实现广播消费
* 2. 基于 Stream 实现集群消费
*/
package cn.iocoder.yudao.framework.mq.redis;

View File

@ -1,62 +0,0 @@
package org.springframework.data.redis.stream;
import cn.hutool.core.util.ReflectUtil;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.stream.ByteRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.Record;
import org.springframework.util.Assert;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
/**
* 拓展 DefaultStreamMessageListenerContainer 实现解决 Spring Data Redis + Redisson 结合使用时Redisson Stream 获得不到数据时返回 null 而不是空 List导致 NPE 异常
* 对应 issuehttps://github.com/spring-projects/spring-data-redis/issues/2147 https://github.com/redisson/redisson/issues/4006
* 目前看下来 Spring Data Redis 不肯加 null 判断Redisson 暂时也没改返回 null 到空 List 的打算所以暂时只能自己改哽咽
*
* @author 芋道源码
*/
public class DefaultStreamMessageListenerContainerX<K, V extends Record<K, ?>> extends DefaultStreamMessageListenerContainer<K, V> {
/**
* 参考 {@link StreamMessageListenerContainer#create(RedisConnectionFactory, StreamMessageListenerContainerOptions)} 的实现
*/
public static <K, V extends Record<K, ?>> StreamMessageListenerContainer<K, V> create(RedisConnectionFactory connectionFactory, StreamMessageListenerContainer.StreamMessageListenerContainerOptions<K, V> options) {
Assert.notNull(connectionFactory, "RedisConnectionFactory must not be null!");
Assert.notNull(options, "StreamMessageListenerContainerOptions must not be null!");
return new DefaultStreamMessageListenerContainerX<>(connectionFactory, options);
}
public DefaultStreamMessageListenerContainerX(RedisConnectionFactory connectionFactory, StreamMessageListenerContainerOptions<K, V> containerOptions) {
super(connectionFactory, containerOptions);
}
/**
* 参考 {@link DefaultStreamMessageListenerContainer#register(StreamReadRequest, StreamListener)} 的实现
*/
@Override
public Subscription register(StreamReadRequest<K> streamRequest, StreamListener<K, V> listener) {
return this.doRegisterX(getReadTaskX(streamRequest, listener));
}
@SuppressWarnings("unchecked")
private StreamPollTask<K, V> getReadTaskX(StreamReadRequest<K> streamRequest, StreamListener<K, V> listener) {
StreamPollTask<K, V> task = ReflectUtil.invoke(this, "getReadTask", streamRequest, listener);
// 修改 readFunction 方法
Function<ReadOffset, List<ByteRecord>> readFunction = (Function<ReadOffset, List<ByteRecord>>) ReflectUtil.getFieldValue(task, "readFunction");
ReflectUtil.setFieldValue(task, "readFunction", (Function<ReadOffset, List<ByteRecord>>) readOffset -> {
List<ByteRecord> records = readFunction.apply(readOffset);
//重点保证 records 不是空避免 NPE 的问题
return records != null ? records : Collections.emptyList();
});
return task;
}
private Subscription doRegisterX(Task task) {
return ReflectUtil.invoke(this, "doRegister", task);
}
}

View File

@ -1 +1,2 @@
cn.iocoder.yudao.framework.mq.config.YudaoMQAutoConfiguration
cn.iocoder.yudao.framework.mq.redis.config.YudaoRedisMQAutoConfiguration
cn.iocoder.yudao.framework.mq.rabbitmq.config.YudaoRabbitMQAutoConfiguration

View File

@ -0,0 +1 @@
<http://www.iocoder.cn/Spring-Boot/RocketMQ/?yudao>

View File

@ -0,0 +1 @@
<http://www.iocoder.cn/Spring-Boot/Kafka/?yudao>

View File

@ -0,0 +1 @@
<http://www.iocoder.cn/Spring-Boot/RabbitMQ/?yudao>

View File

@ -0,0 +1 @@
<http://www.iocoder.cn/Spring-Boot/RocketMQ/?yudao>

View File

@ -5,7 +5,6 @@ import lombok.Data;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
// TODO @小吉祥搞个 job清理 14 天外的访问日志
/**
* API 访问日志
*

View File

@ -5,7 +5,6 @@ import lombok.Data;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
// TODO @小吉祥搞个 job清理 14 天外的异常日志
/**
* API 错误日志
*

View File

@ -20,16 +20,16 @@ public enum BpmCommentTypeEnum {
;
/**
* 结果
* 操作类型
*/
private final Integer type;
/**
* 描述
* 操作名字
*/
private final String desc;
private final String name;
/**
* 模板信息
* 操作描述
*/
private final String templateComment;
private final String comment;
}

View File

@ -30,13 +30,13 @@ public enum BpmProcessInstanceResultEnum {
* 相当于是 通过 APPROVE 的特殊状态
* 例如A审批 A 后加签了 B并且审批通过了任务但是 B 还未审批则当前任务状态为待后加签任务完成
*/
ADD_SIGN_AFTER(7, "待后加签任务完成"),
SIGN_AFTER(7, "待后加签任务完成"),
/**
* 加签源任务未审批但是向前加签了所以源任务状态变为待前加签任务完成
* 相当于是 处理中 PROCESS 的特殊状态
* 例如A 审批 A 前加签了 BB 还未审核
*/
ADD_SIGN_BEFORE(8, "待前加签任务完成"),
SIGN_BEFORE(8, "待前加签任务完成"),
/**
* 加签后加签任务被创建时的初始状态
* 相当于是 处理中 PROCESS 的特殊状态
@ -71,7 +71,7 @@ public enum BpmProcessInstanceResultEnum {
public static boolean isEndResult(Integer result) {
return ObjectUtils.equalsAny(result, APPROVE.getResult(), REJECT.getResult(),
CANCEL.getResult(), BACK.getResult(),
ADD_SIGN_AFTER.getResult());
SIGN_AFTER.getResult());
}
}

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.bpm.enums.task;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 流程任务 -- 加签类型枚举类型
*/

View File

@ -74,7 +74,7 @@ public class BpmTaskController {
return success(true);
}
@GetMapping("/get-return-list")
@GetMapping("/return-list")
@Operation(summary = "获取所有可回退的节点", description = "用于【流程详情】的【回退】按钮")
@Parameter(name = "taskId", description = "当前任务ID", required = true)
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
@ -98,27 +98,28 @@ public class BpmTaskController {
return success(true);
}
@PutMapping("/add-sign")
@PutMapping("/create-sign")
@Operation(summary = "加签", description = "before 前加签after 后加签")
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
public CommonResult<Boolean> addSignTask(@Valid @RequestBody BpmTaskAddSignReqVO reqVO) {
taskService.addSignTask(getLoginUserId(), reqVO);
public CommonResult<Boolean> createSignTask(@Valid @RequestBody BpmTaskAddSignReqVO reqVO) {
taskService.createSignTask(getLoginUserId(), reqVO);
return success(true);
}
@PutMapping("/sub-sign")
@DeleteMapping("/delete-sign")
@Operation(summary = "减签")
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
public CommonResult<Boolean> subSignTask(@Valid @RequestBody BpmTaskSubSignReqVO reqVO) {
taskService.subSignTask(getLoginUserId(), reqVO);
public CommonResult<Boolean> deleteSignTask(@Valid @RequestBody BpmTaskSubSignReqVO reqVO) {
taskService.deleteSignTask(getLoginUserId(), reqVO);
return success(true);
}
@GetMapping("/get-children-task-list")
@GetMapping("children-list")
@Operation(summary = "获取能被减签的任务")
@Parameter(name = "parentId", description = "父级任务 ID", required = true)
@PreAuthorize("@ss.hasPermission('bpm:task:update')")
public CommonResult<List<BpmTaskSubSignRespVO>> getChildrenTaskList(@RequestParam("taskId") String taskId) {
return success(taskService.getChildrenTaskList(taskId));
public CommonResult<List<BpmTaskSubSignRespVO>> getChildrenTaskList(@RequestParam("parentId") String parentId) {
return success(taskService.getChildrenTaskList(parentId));
}
}

View File

@ -6,6 +6,7 @@ import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.Set;
// TODO @海洋类名应该是 create
@Schema(description = "管理后台 - 加签流程任务的 Request VO")
@Data
public class BpmTaskAddSignReqVO {
@ -26,4 +27,4 @@ public class BpmTaskAddSignReqVO {
@NotEmpty(message = "加签原因不能为空")
private String reason;
}
}

View File

@ -5,6 +5,7 @@ import lombok.Data;
import javax.validation.constraints.NotEmpty;
// TODO @海洋类名应该是 delete
@Schema(description = "管理后台 - 减签流程任务的 Request VO")
@Data
public class BpmTaskSubSignReqVO {

View File

@ -1,9 +1,10 @@
package cn.iocoder.yudao.module.bpm.convert.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
@ -25,6 +26,9 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
/**
* Bpm 任务 Convert
*
@ -167,32 +171,31 @@ public interface BpmTaskConvert {
default List<BpmTaskSubSignRespVO> convertList(List<BpmTaskExtDO> bpmTaskExtDOList,
Map<Long, AdminUserRespDTO> userMap,
Map<String, Task> idTaskMap){
return CollectionUtils.convertList(bpmTaskExtDOList, task->{
BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO();
bpmTaskSubSignRespVO.setName(task.getName());
bpmTaskSubSignRespVO.setId(task.getTaskId());
Task sourceTask = idTaskMap.get(task.getTaskId());
return CollectionUtils.convertList(bpmTaskExtDOList, task -> {
BpmTaskSubSignRespVO bpmTaskSubSignRespVO = new BpmTaskSubSignRespVO()
.setId(task.getTaskId()).setName(task.getName());
// 后加签任务不会直接设置 assignee ,所以不存在 assignee 的情况则去取 owner
String assignee = StrUtil.isNotEmpty(sourceTask.getAssignee()) ? sourceTask.getAssignee() : sourceTask.getOwner();
AdminUserRespDTO assignUser = userMap.get(NumberUtils.parseLong(assignee));
if (assignUser != null) {
bpmTaskSubSignRespVO.setAssigneeUser(convert3(assignUser));
}
Task sourceTask = idTaskMap.get(task.getTaskId());
String assignee = ObjectUtil.defaultIfBlank(sourceTask.getOwner(),sourceTask.getAssignee());
MapUtils.findAndThen(userMap,NumberUtils.parseLong(assignee),
assignUser-> bpmTaskSubSignRespVO.setAssigneeUser(convert3(assignUser)));
return bpmTaskSubSignRespVO;
});
}
/**
* 转换任务为父子级
*
* @param sourceList 原始数据
* @return 转换后的父子级数组
*/
default List<BpmTaskRespVO> convertChildrenList(List<BpmTaskRespVO> sourceList){
List<BpmTaskRespVO> childrenTaskList = CollectionUtils.filterList(sourceList, r -> StrUtil.isNotEmpty(r.getParentTaskId()));
Map<String, List<BpmTaskRespVO>> parentChildrenTaskListMap = CollectionUtils.convertMultiMap(childrenTaskList, BpmTaskRespVO::getParentTaskId);
default List<BpmTaskRespVO> convertChildrenList(List<BpmTaskRespVO> sourceList) {
List<BpmTaskRespVO> childrenTaskList = filterList(sourceList, r -> StrUtil.isNotEmpty(r.getParentTaskId()));
Map<String, List<BpmTaskRespVO>> parentChildrenTaskListMap = convertMultiMap(childrenTaskList, BpmTaskRespVO::getParentTaskId);
for (BpmTaskRespVO bpmTaskRespVO : sourceList) {
bpmTaskRespVO.setChildren(parentChildrenTaskListMap.get(bpmTaskRespVO.getId()));
}
return CollectionUtils.filterList(sourceList, r -> StrUtil.isEmpty(r.getParentTaskId()));
return filterList(sourceList, r -> StrUtil.isEmpty(r.getParentTaskId()));
}
}

View File

@ -21,13 +21,13 @@ public interface BpmTaskExtMapper extends BaseMapperX<BpmTaskExtDO> {
return selectList(BpmTaskExtDO::getTaskId, taskIds);
}
// TODO @海BpmProcessInstanceResultEnum.CAN_SUB_SIGN_STATUS_LIST) 应该作为条件mapper 不要有业务
default List<BpmTaskExtDO> selectProcessListByTaskIds(Collection<String> taskIds) {
return selectList(new LambdaQueryWrapperX<BpmTaskExtDO>()
.in(BpmTaskExtDO::getTaskId, taskIds)
.in(BpmTaskExtDO::getResult, BpmProcessInstanceResultEnum.CAN_SUB_SIGN_STATUS_LIST));
}
default BpmTaskExtDO selectByTaskId(String taskId) {
return selectOne(BpmTaskExtDO::getTaskId, taskId);
}

View File

@ -1,28 +0,0 @@
package cn.iocoder.yudao.module.bpm.framework.bpm.config;
import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
/**
* @author kemengkai
* @create 2022-05-07 08:15
*/
@Configuration("bpmSecurityConfiguration")
public class BpmSecurityConfiguration {
@Bean("bpmAuthorizeRequestsCustomizer")
public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {
return new AuthorizeRequestsCustomizer() {
@Override
public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) {
// 任务回退接口
registry.antMatchers(buildAdminApi("/bpm/task/back")).permitAll();
}
};
}
}

View File

@ -12,6 +12,7 @@ import javax.validation.Valid;
* @author yunlongn
*/
public interface BpmModelService {
/**
* 获得流程模型分页
*

View File

@ -288,5 +288,4 @@ public class BpmModelServiceImpl implements BpmModelService {
processDefinitionService.updateProcessDefinitionState(oldDefinition.getId(), SuspensionState.SUSPENDED.getStateCode());
}
}

View File

@ -163,7 +163,7 @@ public interface BpmTaskService {
* @param userId 被加签的用户和任务 ID加签类型
* @param reqVO 当前用户 ID
*/
void addSignTask(Long userId, BpmTaskAddSignReqVO reqVO);
void createSignTask(Long userId, BpmTaskAddSignReqVO reqVO);
/**
* 任务减签名
@ -171,14 +171,14 @@ public interface BpmTaskService {
* @param userId 当前用户ID
* @param reqVO 被减签的任务 ID理由
*/
void subSignTask(Long userId, BpmTaskSubSignReqVO reqVO);
void deleteSignTask(Long userId, BpmTaskSubSignReqVO reqVO);
/**
* 获取指定任务的子任务和审批人信息
*
* @param taskId 指定任务ID
* @param parentId 指定任务ID
* @return 子任务列表
*/
List<BpmTaskSubSignRespVO> getChildrenTaskList(String taskId);
List<BpmTaskSubSignRespVO> getChildrenTaskList(String parentId);
}

View File

@ -53,7 +53,6 @@ import javax.annotation.Resource;
import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -240,10 +239,11 @@ public class BpmTaskServiceImpl implements BpmTaskService {
handleParentTask(task);
}
/**
* 审批通过存在后加签的任务
* <p>
* 注意该任务不能马上完成需要一个中间状态ADD_SIGN_AFTER并激活剩余所有子任务PROCESS为可审批处理
* 注意该任务不能马上完成需要一个中间状态SIGN_AFTER并激活剩余所有子任务PROCESS为可审批处理
*
* @param task 当前任务
* @param reqVO 前端请求参数
@ -251,7 +251,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
private void approveAfterSignTask(Task task, BpmTaskApproveReqVO reqVO) {
// 1. 有向后加签则该任务状态临时设置为 ADD_SIGN_AFTER 状态
taskExtMapper.updateByTaskId(
new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.ADD_SIGN_AFTER.getResult())
new BpmTaskExtDO().setTaskId(task.getId()).setResult(BpmProcessInstanceResultEnum.SIGN_AFTER.getResult())
.setReason(reqVO.getReason()).setEndTime(LocalDateTime.now()));
// 2. 激活子任务
@ -265,7 +265,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
}
/**
* 处理当前任务的父任务
* 处理当前任务的父任务主要处理加签的情况
*
* @param task 当前任务
*/
@ -274,76 +274,79 @@ public class BpmTaskServiceImpl implements BpmTaskService {
if (StrUtil.isBlank(parentTaskId)) {
return;
}
if (StrUtil.isNotBlank(parentTaskId)) {
// 1. 判断当前任务的父任务是否还有子任务
Long childrenTaskCount = getChildrenTaskCount(parentTaskId);
if (childrenTaskCount > 0) {
return;
}
// 2. 获取父任务
Task parentTask = validateTaskExist(parentTaskId);
// 3. 情况一处理向前加签
String scopeType = parentTask.getScopeType();
if (BpmTaskAddSignTypeEnum.BEFORE.getType().equals(scopeType)) {
// 3.1 如果是向前加签的任务则调用 resolveTask 指派父任务 owner 重新赋值给父任务的 assignee
taskService.resolveTask(parentTaskId);
// 3.2 更新任务拓展表为处理中
taskExtMapper.updateByTaskId(
new BpmTaskExtDO().setTaskId(parentTask.getId()).setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()));
} else if (BpmTaskAddSignTypeEnum.AFTER.getType().equals(scopeType)) {
// 3. 情况二处理向后加签
handleAfterSign(parentTask);
}
// 4. 子任务已处理完成清空 scopeType 字段修改 parentTask 信息方便后续可以继续向前后向后加签
// 再查询一次的原因是避免报错Task was updated by another transaction concurrently
// 因为前面处理后可能会导致 parentTask rev 字段被修改需要重新获取最新的
parentTask = getTask(parentTaskId);
if (parentTask == null) {
// 为空的情况是已经通过 handleAfterSign 方法将任务完成了所以 ru_task 表会查不到数据
return;
}
clearTaskScopeTypeAndSave(parentTask);
// 1. 判断当前任务的父任务是否还有子任务
Long childrenTaskCount = getChildrenTaskCount(parentTaskId);
if (childrenTaskCount > 0) {
return;
}
// 2. 获取父任务
Task parentTask = validateTaskExist(parentTaskId);
// 3. 处理加签情况
String scopeType = parentTask.getScopeType();
if(!validateSignType(scopeType)){
return;
}
// 3.1 情况一处理向前加签
if (BpmTaskAddSignTypeEnum.BEFORE.getType().equals(scopeType)) {
// 3.1.1 如果是向前加签的任务则调用 resolveTask 指派父任务 owner 重新赋值给父任务的 assignee这样它就可以被审批
taskService.resolveTask(parentTaskId);
// 3.1.2 更新任务拓展表为处理中
taskExtMapper.updateByTaskId(
new BpmTaskExtDO().setTaskId(parentTask.getId()).setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()));
} else if (BpmTaskAddSignTypeEnum.AFTER.getType().equals(scopeType)) {
// 3.2 情况二处理向后加签
handleParentTaskForAfterSign(parentTask);
}
// 4. 子任务已处理完成清空 scopeType 字段修改 parentTask 信息方便后续可以继续向前后向后加签
// 再查询一次的原因是避免报错Task was updated by another transaction concurrently
// 因为前面处理后可能会导致 parentTask rev 字段被修改需要重新获取最新的
parentTask = getTask(parentTaskId);
if (parentTask == null) {
// 为空的情况是已经通过 handleAfterSign 方法将任务完成了所以 ru_task 表会查不到数据
return;
}
clearTaskScopeTypeAndSave(parentTask);
}
/**
* 处理后加签任务
*
* @param parentTask 当前审批任务的父任务
*/
private void handleAfterSign(Task parentTask) {
// TODO @海这个逻辑怎么感觉可以是 parentTask parent再去调用 handleParentTask 方法可以微信聊下
private void handleParentTaskForAfterSign(Task parentTask) {
String parentTaskId = parentTask.getId();
//1. 更新 parentTask 的任务拓展表为通过并调用 complete 完成自己
// 1. 更新 parentTask 的任务拓展表为通过并调用 complete 完成自己
BpmTaskExtDO currentTaskExt = taskExtMapper.selectByTaskId(parentTask.getId());
BpmTaskExtDO currentTaskUpdateEntity = new BpmTaskExtDO().setTaskId(parentTask.getId())
BpmTaskExtDO currentTaskExtUpdateObj = new BpmTaskExtDO().setTaskId(parentTask.getId())
.setResult(BpmProcessInstanceResultEnum.APPROVE.getResult());
if (currentTaskExt.getEndTime() == null) {
// 1.1 有这个判断是因为,以前没设置过结束时间才去设置
currentTaskUpdateEntity.setEndTime(LocalDateTime.now());
currentTaskExtUpdateObj.setEndTime(LocalDateTime.now());
}
// 1.2 完成自己
taskExtMapper.updateByTaskId(currentTaskUpdateEntity);
taskExtMapper.updateByTaskId(currentTaskExtUpdateObj);
// 1.2 完成自己因为它已经没有子任务所以也可以完成
taskService.complete(parentTaskId);
// 2. 如果有父级递归查询上级任务是否都已经完成
if (StrUtil.isEmpty(parentTask.getParentTaskId())) {
return;
}
// TODO @海这块待讨论脑子略乱感觉 handleAfterSign 的后半段 handleParentTask 有点重叠
// 2.1 判断整条链路的任务是否完成
// 例如从 A 任务加签了一个 B 任务B 任务又加签了一个 C 任务C 任务加签了 D 任务
// 此时D 任务完成要一直往上找到祖先任务 A调用 complete 方法完成 A 任务
boolean allChildrenTaskFinish = true;
while (StrUtil.isNotBlank(parentTask.getParentTaskId())) {
parentTask = validateTaskExist(parentTask.getParentTaskId());
BpmTaskExtDO bpmTaskExtDO = taskExtMapper.selectByTaskId(parentTask.getId());
if (bpmTaskExtDO == null) {
BpmTaskExtDO parentTaskExt = taskExtMapper.selectByTaskId(parentTask.getId());
if (parentTaskExt == null) {
break;
}
boolean currentTaskFinish = BpmProcessInstanceResultEnum.isEndResult(bpmTaskExtDO.getResult());
// 2.2 如果 allChildrenTaskFinish 已经被赋值为 false ,则不会再赋值为 true因为整个链路没有完成
boolean currentTaskFinish = BpmProcessInstanceResultEnum.isEndResult(parentTaskExt.getResult());
// 2.2 如果 allChildrenTaskFinish 已经被赋值为 false则不会再赋值为 true因为整个链路没有完成
if (allChildrenTaskFinish) {
allChildrenTaskFinish = currentTaskFinish;
}
@ -354,19 +357,19 @@ public class BpmTaskServiceImpl implements BpmTaskService {
// 3 处理非完成状态的任务
// 3.1 判断当前任务的父任务是否还有子任务
Long childrenTaskCount = getChildrenTaskCount(bpmTaskExtDO.getTaskId());
Long childrenTaskCount = getChildrenTaskCount(parentTaskExt.getTaskId());
if (childrenTaskCount > 0) {
continue;
}
// 3.2 没有子任务判断当前任务状态是否为 ADD_SIGN_BEFORE 待前加签任务完成
if (BpmProcessInstanceResultEnum.ADD_SIGN_BEFORE.getResult().equals(bpmTaskExtDO.getResult())) {
if (BpmProcessInstanceResultEnum.SIGN_BEFORE.getResult().equals(parentTaskExt.getResult())) {
// 3.3 需要修改该任务状态为处理中
taskService.resolveTask(bpmTaskExtDO.getTaskId());
bpmTaskExtDO.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
taskExtMapper.updateByTaskId(bpmTaskExtDO);
taskService.resolveTask(parentTaskExt.getTaskId());
parentTaskExt.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
taskExtMapper.updateByTaskId(parentTaskExt);
}
// 3.4 清空 scopeType 字段用于任务没有子任务时使用该方法方便任务可以再次被不同的方式加签
parentTask = validateTaskExist(bpmTaskExtDO.getTaskId());
parentTask = validateTaskExist(parentTaskExt.getTaskId());
clearTaskScopeTypeAndSave(parentTask);
}
@ -387,7 +390,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
taskService.saveTask(task);
}
/**
* 获取子任务个数
*
@ -709,7 +711,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
@Override
@Transactional(rollbackFor = Exception.class)
public void addSignTask(Long userId, BpmTaskAddSignReqVO reqVO) {
public void createSignTask(Long userId, BpmTaskAddSignReqVO reqVO) {
// 1. 获取和校验任务
TaskEntityImpl taskEntity = validateAddSign(userId, reqVO);
List<AdminUserRespDTO> userList = adminUserApi.getUserList(reqVO.getUserIdList());
@ -728,7 +730,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
// 2.3 更新扩展表状态
taskExtMapper.updateByTaskId(
new BpmTaskExtDO().setTaskId(taskEntity.getId())
.setResult(BpmProcessInstanceResultEnum.ADD_SIGN_BEFORE.getResult())
.setResult(BpmProcessInstanceResultEnum.SIGN_BEFORE.getResult())
.setReason(reqVO.getReason()));
}
// 2.4 记录加签方式完成任务时需要用到判断
@ -737,12 +739,12 @@ public class BpmTaskServiceImpl implements BpmTaskService {
taskService.saveTask(taskEntity);
// 3. 创建加签任务
createAddSignChildrenTasks(convertList(reqVO.getUserIdList(), String::valueOf), taskEntity);
createSignTask(convertList(reqVO.getUserIdList(), String::valueOf), taskEntity);
// 4. 记录加签 comment拼接结果为 [当前用户]向前加签/向后加签给了[多个用户]理由为reason
AdminUserRespDTO currentUser = adminUserApi.getUser(userId);
String comment = StrUtil.format(BpmCommentTypeEnum.ADD_SIGN.getTemplateComment(), currentUser.getNickname(), BpmTaskAddSignTypeEnum.formatDesc(reqVO.getType()),
String.join(",", convertList(userList, AdminUserRespDTO::getNickname)), reqVO.getReason());
String comment = StrUtil.format(BpmCommentTypeEnum.ADD_SIGN.getComment(), currentUser.getNickname(),
BpmTaskAddSignTypeEnum.formatDesc(reqVO.getType()), String.join(",", convertList(userList, AdminUserRespDTO::getNickname)), reqVO.getReason());
taskService.addComment(reqVO.getId(), taskEntity.getProcessInstanceId(),
BpmCommentTypeEnum.ADD_SIGN.getType().toString(), comment);
}
@ -786,7 +788,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
* @param addSingUserIdList 被加签的用户 ID
* @param taskEntity 被加签的任务
*/
private void createAddSignChildrenTasks(List<String> addSingUserIdList, TaskEntityImpl taskEntity) {
private void createSignTask(List<String> addSingUserIdList, TaskEntityImpl taskEntity) {
if (CollUtil.isEmpty(addSingUserIdList)) {
return;
}
@ -795,23 +797,22 @@ public class BpmTaskServiceImpl implements BpmTaskService {
if (StrUtil.isBlank(addSignId)) {
continue;
}
createChildrenTask(taskEntity, addSignId);
createSignTask(taskEntity, addSignId);
}
}
/**
* 创建子任务
* 创建加签子任务
*
* @param parentTask 父任务
* @param assignee 子任务的执行人
* @return
*/
private void createChildrenTask(TaskEntityImpl parentTask, String assignee) {
private void createSignTask(TaskEntityImpl parentTask, String assignee) {
// 1. 生成子任务
TaskEntityImpl task = (TaskEntityImpl) taskService.newTask(IdUtil.fastSimpleUUID());
task = BpmTaskConvert.INSTANCE.convert(task, parentTask);
if (BpmTaskAddSignTypeEnum.BEFORE.getType().equals(parentTask.getScopeType())) {
// 2.1 前加签设置审批人否则设置 owner
// 2.1 前加签设置审批人
task.setAssignee(assignee);
} else {
// 2.2.1 设置 owner 不设置 assignee 是因为不能同时审批需要等父任务完成
@ -825,9 +826,10 @@ public class BpmTaskServiceImpl implements BpmTaskService {
@Override
@Transactional(rollbackFor = Exception.class)
public void subSignTask(Long userId, BpmTaskSubSignReqVO reqVO) {
public void deleteSignTask(Long userId, BpmTaskSubSignReqVO reqVO) {
// 1.1 校验 task 可以被减签
Task task = validateSubSign(reqVO.getId());
AdminUserRespDTO user = adminUserApi.getUser(userId);
// 1.2 校验取消人存在
AdminUserRespDTO cancelUser = null;
if (StrUtil.isNotBlank(task.getAssignee())) {
cancelUser = adminUserApi.getUser(NumberUtils.parseLong(task.getAssignee()));
@ -836,20 +838,24 @@ public class BpmTaskServiceImpl implements BpmTaskService {
cancelUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner()));
}
Assert.notNull(cancelUser, "任务中没有所有者和审批人,数据错误");
//1. 获取所有需要删除的任务 ID 包含当前任务和所有子任务
// 2. 删除任务和对应子任务
// 2.1 获取所有需要删除的任务 ID 包含当前任务和所有子任务
List<String> allTaskIdList = getAllChildTaskIds(task.getId());
//2. 删除任务和所有子任务
// 2.2 删除任务和所有子任务
taskService.deleteTasks(allTaskIdList);
//3. 修改扩展表状态为取消
// 2.3 修改扩展表状态为取消
AdminUserRespDTO user = adminUserApi.getUser(userId);
taskExtMapper.updateBatchByTaskIdList(allTaskIdList, new BpmTaskExtDO().setResult(BpmProcessInstanceResultEnum.CANCEL.getResult())
.setReason(StrUtil.format("由于{}操作[减签],任务被取消", user.getNickname())));
//4.记录日志到父任务中 先记录日志是因为通过 handleParentTask 方法之后任务可能被完成了并且不存在了会报异常所以先记录
String comment = StrUtil.format(BpmCommentTypeEnum.SUB_SIGN.getTemplateComment(), user.getNickname(), cancelUser.getNickname());
// 3. 记录日志到父任务中先记录日志是因为通过 handleParentTask 方法之后任务可能被完成了并且不存在了会报异常所以先记录
String comment = StrUtil.format(BpmCommentTypeEnum.SUB_SIGN.getComment(), user.getNickname(), cancelUser.getNickname());
taskService.addComment(task.getParentTaskId(), task.getProcessInstanceId(),
BpmCommentTypeEnum.SUB_SIGN.getType().toString(), comment);
//5. 处理当前任务的父任务
this.handleParentTask(task);
// 4. 处理当前任务的父任务
handleParentTask(task);
}
/**
@ -860,13 +866,28 @@ public class BpmTaskServiceImpl implements BpmTaskService {
*/
private Task validateSubSign(String id) {
Task task = validateTaskExist(id);
//必须有parentId
if (StrUtil.isEmpty(task.getParentTaskId())) {
// 必须有 scopeType
String scopeType = task.getScopeType();
if (StrUtil.isEmpty(scopeType)) {
throw exception(TASK_SUB_SIGN_NO_PARENT);
}
// 并且值为 向前和向后加签
if (!validateSignType(scopeType)) {
throw exception(TASK_SUB_SIGN_NO_PARENT);
}
return task;
}
/**
* 判断当前类型是否为加签
* @param scopeType 任务的 scopeType
* @return 当前 scopeType 为加签则返回 true
*/
private boolean validateSignType(String scopeType){
return StrUtil.equalsAny(scopeType,BpmTaskAddSignTypeEnum.BEFORE.getType(),scopeType, BpmTaskAddSignTypeEnum.AFTER.getType());
}
/**
* 获取所有要被取消的删除的任务 ID 集合
*
@ -875,25 +896,30 @@ public class BpmTaskServiceImpl implements BpmTaskService {
*/
public List<String> getAllChildTaskIds(String parentTaskId) {
List<String> allChildTaskIds = new ArrayList<>();
//1. 先将自己放入
allChildTaskIds.add(parentTaskId);
//2. 递归获取子级
recursiveGetChildTaskIds(parentTaskId, allChildTaskIds);
return allChildTaskIds;
}
/**
* 递归处理子级任务
*
* @param taskId 当前任务ID
* @param taskIds 结果
*/
private void recursiveGetChildTaskIds(String taskId, List<String> taskIds) {
List<String> childrenTaskIdList = getChildrenTaskIdList(taskId);
for (String childTaskId : childrenTaskIdList) {
taskIds.add(childTaskId); // 将子任务的ID添加到集合中
recursiveGetChildTaskIds(childTaskId, taskIds); // 递归获取子任务的子任务
// 1. 递归获取子级
Stack<String> stack = new Stack<>();
// 1.1 将根任务ID入栈
stack.push(parentTaskId);
//控制遍历的次数不超过 Byte.MAX_VALUE避免脏数据造成死循环
int count = 0;
// TODO @海< 的前后空格要注意哈
while (!stack.isEmpty() && count<Byte.MAX_VALUE) {
// 1.2 弹出栈顶任务ID
String taskId = stack.pop();
// 1.3 将任务ID添加到结果集合中
allChildTaskIds.add(taskId);
// 1.4 获取该任务的子任务列表
// TODO @海有个更高效的写法一次性去 in 一层不然每个节点都去查询一次 db 太浪费了每次 in最终就是 O(h) 查询而不是 O(n) 查询
List<String> childrenTaskIdList = getChildrenTaskIdList(taskId);
if (CollUtil.isNotEmpty(childrenTaskIdList)) {
for (String childTaskId : childrenTaskIdList) {
// 1.5 将子任务ID入栈以便后续处理
stack.push(childTaskId);
}
}
count++;
}
return allChildTaskIds;
}
/**
@ -903,32 +929,41 @@ public class BpmTaskServiceImpl implements BpmTaskService {
* @return 所有子任务的 ID 集合
*/
private List<String> getChildrenTaskIdList(String parentTaskId) {
String tableName = managementService.getTableName(TaskEntity.class);
String sql = "select ID_ from " + tableName + " where PARENT_TASK_ID_=#{parentTaskId}";
List<Task> childrenTaskList = taskService.createNativeTaskQuery().sql(sql).parameter("parentTaskId", parentTaskId).list();
return convertList(childrenTaskList, Task::getId);
return convertList(getChildrenTaskList0(parentTaskId), Task::getId);
}
/**
* 获取指定父级任务的所有子任务 ID 集合
*
* @param parentTaskId 父任务 ID
* @return 所有子任务的 ID 集合
*/
private List<Task> getChildrenTaskList0(String parentTaskId) {
String tableName = managementService.getTableName(TaskEntity.class);
// taskService.createTaskQuery() 没有 parentId 参数所以写 sql 查询
String sql = "select ID_,OWNER_,ASSIGNEE_ from " + tableName + " where PARENT_TASK_ID_=#{parentTaskId}";
return taskService.createNativeTaskQuery().sql(sql).parameter("parentTaskId", parentTaskId).list();
}
@Override
public List<BpmTaskSubSignRespVO> getChildrenTaskList(String taskId) {
List<String> childrenTaskIdList = getChildrenTaskIdList(taskId);
if (CollUtil.isEmpty(childrenTaskIdList)) {
public List<BpmTaskSubSignRespVO> getChildrenTaskList(String parentId) {
// 1. 只查询进行中的任务 后加签的任务可能不存在 assignee所以还需要查询 owner
List<Task> taskList = getChildrenTaskList0(parentId);
if (CollUtil.isEmpty(taskList)) {
return Collections.emptyList();
}
//1. 只查询进行中的任务
List<BpmTaskExtDO> bpmTaskExtDOList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList);
//2. 后加签的任务可能不存在 assignee,所以还需要查询 owner
List<Task> taskList = taskService.createTaskQuery().taskIds(childrenTaskIdList).list();
Map<String, Task> idTaskMap = convertMap(taskList, TaskInfo::getId);
//3. owner assignee 统一到一个集合中
List<Long> userIds = taskList.stream()
.flatMap(control ->
Stream.of(control.getAssignee(), control.getOwner())
.filter(Objects::nonNull))
.distinct()
.map(NumberUtils::parseLong)
.collect(Collectors.toList());
List<String> childrenTaskIdList = convertList(taskList, Task::getId);
// 2.1 owner assignee 统一到一个集合中
List<Long> userIds = convertListByFlatMap(taskList, control ->
Stream.of(NumberUtils.parseLong(control.getAssignee()), NumberUtils.parseLong(control.getOwner()))
.filter(Objects::nonNull));
// 2.2 组装数据
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
return BpmTaskConvert.INSTANCE.convertList(bpmTaskExtDOList, userMap, idTaskMap);
List<BpmTaskExtDO> taskExtList = taskExtMapper.selectProcessListByTaskIds(childrenTaskIdList);
Map<String, Task> idTaskMap = convertMap(taskList, TaskInfo::getId);
return BpmTaskConvert.INSTANCE.convertList(taskExtList, userMap, idTaskMap);
}
}

View File

@ -147,7 +147,7 @@ public class DatabaseDocController {
*/
private static ProcessConfig buildProcessConfig() {
return ProcessConfig.builder()
.ignoreTablePrefix(Arrays.asList("QRTZ_", "ACT_")) // 忽略表前缀
.ignoreTablePrefix(Arrays.asList("QRTZ_", "ACT_", "FLW_")) // 忽略表前缀
.build();
}

View File

@ -29,8 +29,6 @@ public class SecurityConfiguration {
.antMatchers("/swagger-resources/**").anonymous()
.antMatchers("/webjars/**").anonymous()
.antMatchers("/*/api-docs").anonymous();
// 积木报表
registry.antMatchers("/jmreport/**").permitAll();
// Spring Boot Actuator 的安全配置
registry.antMatchers("/actuator").anonymous()
.antMatchers("/actuator/**").anonymous();

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.infra.job.logger;
package cn.iocoder.yudao.module.infra.job.job;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
@ -33,7 +33,7 @@ public class JobLogCleanJob implements JobHandler {
@TenantIgnore
public String execute(String param) {
Integer count = jobLogService.cleanJobLog(JOB_CLEAN_RETAIN_DAY, DELETE_LIMIT);
log.info("[count][定时执行清理定时任务日志数量 ({}) 个]", count);
log.info("[execute][定时执行清理定时任务日志数量 ({}) 个]", count);
return String.format("定时执行清理定时任务日志数量 %s 个", count);
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.infra.job.job;
package cn.iocoder.yudao.module.infra.job.logger;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
@ -34,7 +34,7 @@ public class AccessLogCleanJob implements JobHandler {
@TenantIgnore
public String execute(String param) {
Integer count = apiAccessLogService.cleanAccessLog(JOB_CLEAN_RETAIN_DAY, DELETE_LIMIT);
log.info("[count][定时执行清理访问日志数量 ({}) 个]", count);
log.info("[execute][定时执行清理访问日志数量 ({}) 个]", count);
return String.format("定时执行清理错误日志数量 %s 个", count);
}

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.module.infra.job.job;
package cn.iocoder.yudao.module.infra.job.logger;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
@ -34,7 +34,7 @@ public class ErrorLogCleanJob implements JobHandler {
@TenantIgnore
public String execute(String param) {
Integer count = apiErrorLogService.cleanErrorLog(JOB_CLEAN_RETAIN_DAY,DELETE_LIMIT);
log.info("[count][定时执行清理错误日志数量 ({}) 个]", count);
log.info("[execute][定时执行清理错误日志数量 ({}) 个]", count);
return String.format("定时执行清理错误日志数量 %s 个", count);
}

View File

@ -58,9 +58,9 @@ public class FileConfigServiceImpl implements FileConfigService {
FileConfigDO config = Objects.equals(CACHE_MASTER_ID, id) ?
fileConfigMapper.selectByMaster() : fileConfigMapper.selectById(id);
if (config != null) {
fileClientFactory.createOrUpdateFileClient(id, config.getStorage(), config.getConfig());
fileClientFactory.createOrUpdateFileClient(config.getId(), config.getStorage(), config.getConfig());
}
return fileClientFactory.getFileClient(id);
return fileClientFactory.getFileClient(null == config ? id : config.getId());
}
});

View File

@ -28,5 +28,5 @@ export function delete${simpleClassName}(id: number) {
// 导出${table.classComment} Excel
export function export${simpleClassName}(params) {
return defHttp.download({ url: '${baseURL}/export-excel', params }, '${table.classComment}.xls')
return defHttp.download({ url: '${baseURL}/export-excel', params }, '${table.classComment}.xls')
}

View File

@ -1,6 +1,6 @@
import type { BasicColumn, FormSchema } from '@/components/Table'
import { useRender } from '@/components/Table'
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import type {BasicColumn, FormSchema} from '@/components/Table'
import {useRender} from '@/components/Table'
import {DICT_TYPE, getDictOptions} from '@/utils/dict'
export const columns: BasicColumn[] = [
#foreach($column in $columns)
@ -50,7 +50,7 @@ export const searchFormSchema: FormSchema[] = [
field: '${javaField}',
#if ($column.htmlType == "input")
component: 'Input',
#elseif ($column.htmlType == "select" || $column.htmlType == "radio")
#elseif ($column.htmlType == "select")
component: 'Select',
componentProps: {
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
@ -59,6 +59,15 @@ export const searchFormSchema: FormSchema[] = [
options: [],
#end
},
#elseif ($column.htmlType == "radio")
component: 'Radio',
componentProps: {
#if ("" != $dictType)## 设置了 dictType 数据字典的情况
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase()),
#else## 未设置 dictType 数据字典的情况
options: [],
#end
},
#elseif($column.htmlType == "datetime")
component: 'RangePicker',
#end
@ -181,7 +190,8 @@ export const updateFormSchema: FormSchema[] = [
fileType: 'file',
maxCount: 1,
},
#elseif($column.htmlType == "editor")## 文本编辑器component: 'Editor',
#elseif($column.htmlType == "editor")## 文本编辑器
component: 'Editor',
#elseif($column.htmlType == "select")## 下拉框
component: 'Select',
componentProps: {

View File

@ -1,12 +1,11 @@
<script lang="ts" setup>
import ${ simpleClassName }Modal from './${simpleClassName}Modal.vue'
import ${simpleClassName}Modal from './${simpleClassName}Modal.vue'
import { columns, searchFormSchema } from './${classNameVar}.data'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useModal } from '@/components/Modal'
import { IconEnum } from '@/enums/appEnum'
import { BasicTable, useTable, TableAction } from '@/components/Table'
import { delete${ simpleClassName }, export${ simpleClassName }, get${ simpleClassName } Page } from '@/api/${table.moduleName}/${classNameVar}'
import { useTable } from '@/components/Table'
import { delete${simpleClassName}, export${simpleClassName}, get${simpleClassName}Page } from '@/api/${table.moduleName}/${classNameVar}'
defineOptions({ name: '${table.className}' })
@ -16,7 +15,7 @@ const [registerModal, { openModal }] = useModal()
const [registerTable, { getForm, reload }] = useTable({
title: '${table.classComment}列表',
api: get${ simpleClassName }Page,
api: get${simpleClassName}Page,
columns,
formConfig: { labelWidth: 120, schemas: searchFormSchema },
useSearchForm: true,
@ -43,14 +42,14 @@ async function handleExport() {
iconType: 'warning',
content: t('common.exportMessage'),
async onOk() {
await export${ simpleClassName } (getForm().getFieldsValue())
await export${simpleClassName}(getForm().getFieldsValue())
createMessage.success(t('common.exportSuccessText'))
},
})
}
async function handleDelete(record: Recordable) {
await delete${ simpleClassName } (record.id)
await delete${simpleClassName}(record.id)
createMessage.success(t('common.delSuccessText'))
reload()
}
@ -62,7 +61,7 @@ async function handleDelete(record: Recordable) {
<a-button type="primary" v-auth="['${permissionPrefix}:create']" :preIcon="IconEnum.ADD" @click="handleCreate">
{{ t('action.create') }}
</a-button>
<a-button type="warning" v-auth="['${permissionPrefix}:export']" :preIcon="IconEnum.EXPORT" @click="handleExport">
<a-button v-auth="['${permissionPrefix}:export']" :preIcon="IconEnum.EXPORT" @click="handleExport">
{{ t('action.export') }}
</a-button>
</template>

View File

@ -258,12 +258,12 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest {
Long id = fileConfig.getId();
// mock 获得 Client
FileClient fileClient = new LocalFileClient(id, new LocalFileClientConfig());
when(fileClientFactory.getFileClient(eq(0L))).thenReturn(fileClient);
when(fileClientFactory.getFileClient(eq(fileConfig.getId()))).thenReturn(fileClient);
// 调用并断言
assertSame(fileClient, fileConfigService.getMasterFileClient());
// 断言缓存
verify(fileClientFactory).createOrUpdateFileClient(eq(0L), eq(fileConfig.getStorage()),
verify(fileClientFactory).createOrUpdateFileClient(eq(fileConfig.getId()), eq(fileConfig.getStorage()),
eq(fileConfig.getConfig()));
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.product.api.comment.dto;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
@ -15,6 +16,7 @@ public class ProductCommentCreateReqDTO {
/**
* 商品 SKU 编号
*/
@NotNull(message = "商品 SKU 编号不能为空")
private Long skuId;
/**
* 订单编号
@ -25,21 +27,20 @@ public class ProductCommentCreateReqDTO {
*/
private Long orderItemId;
/**
* 评分星级 1-5
*/
private Integer scores;
/**
* 描述星级 1-5
*/
@NotNull(message = "描述星级不能为空")
private Integer descriptionScores;
/**
* 服务星级 1-5
*/
@NotNull(message = "服务星级不能为空")
private Integer benefitScores;
/**
* 评论内容
*/
@NotNull(message = "评论内容不能为空")
private String content;
/**
* 评论图片地址数组以逗号分隔最多上传 9
@ -49,11 +50,12 @@ public class ProductCommentCreateReqDTO {
/**
* 是否匿名
*/
@NotNull(message = "是否匿名不能为空")
private Boolean anonymous;
/**
* 评价人
*/
@NotNull(message = "评价人不能为空")
private Long userId;
}

View File

@ -1,23 +0,0 @@
package cn.iocoder.yudao.module.product.api.property;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import java.util.Collection;
import java.util.List;
/**
* 商品属性值 API 接口
*
* @author 芋道源码
*/
public interface ProductPropertyValueApi {
/**
* 根据编号数组获得属性值列表
*
* @param ids 编号数组
* @return 属性值明细列表
*/
List<ProductPropertyValueDetailRespDTO> getPropertyValueDetailList(Collection<Long> ids);
}

View File

@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.product.api.spu.dto;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import lombok.Data;
import java.util.List;
// TODO @LeeYan9: ProductSpuRespDTO
/**
* 商品 SPU 信息 Response DTO
@ -26,55 +24,22 @@ public class ProductSpuRespDTO {
* 商品名称
*/
private String name;
/**
* 关键字
*/
private String keyword;
/**
* 单位
*
* 对应 product_unit 数据字典
*/
private Integer unit;
/**
* 商品简介
*/
private String introduction;
/**
* 商品详情
*/
private String description;
// TODO @芋艿是不是要删除
/**
* 商品条码一维码
*/
private String barCode;
/**
* 商品分类编号
*/
private Long categoryId;
/**
* 商品品牌编号
*/
private Long brandId;
/**
* 商品封面图
*/
private String picUrl;
/**
* 商品轮播图
*/
private List<String> sliderPicUrls;
/**
* 商品视频
*/
private String videoUrl;
/**
* 排序字段
*/
private Integer sort;
/**
* 商品状态
* <p>
@ -124,22 +89,6 @@ public class ProductSpuRespDTO {
*/
private Integer giveIntegral;
// ========== 统计相关字段 =========
/**
* 商品销量
*/
private Integer salesCount;
/**
* 虚拟销量
*/
private Integer virtualSalesCount;
/**
* 商品点击量
*/
private Integer clickCount;
// ========== 分销相关字段 =========
/**

View File

@ -1,38 +0,0 @@
package cn.iocoder.yudao.module.product.enums.group;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* 商品分组的样式枚举
*
* @author 芋道源码
*/
@Getter
@AllArgsConstructor
public enum ProductGroupStyleEnum implements IntArrayValuable {
ONE(1, "每列一个"),
TWO(2, "每列两个"),
THREE(2, "每列三个"),;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ProductGroupStyleEnum::getStyle).toArray();
/**
* 列表样式
*/
private final Integer style;
/**
* 状态名
*/
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -1,31 +0,0 @@
package cn.iocoder.yudao.module.product.api.property;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyValueService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
/**
* 商品属性值 API 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class ProductPropertyValueApiImpl implements ProductPropertyValueApi {
@Resource
private ProductPropertyValueService productPropertyValueService;
@Override
public List<ProductPropertyValueDetailRespDTO> getPropertyValueDetailList(Collection<Long> ids) {
return ProductPropertyValueConvert.INSTANCE.convertList02(
productPropertyValueService.getPropertyValueDetailList(ids));
}
}

View File

@ -1,6 +1,5 @@
package cn.iocoder.yudao.module.product.api.sku;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
@ -11,7 +10,6 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
@ -35,18 +33,12 @@ public class ProductSkuApiImpl implements ProductSkuApi {
@Override
public List<ProductSkuRespDTO> getSkuList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
List<ProductSkuDO> skus = productSkuService.getSkuList(ids);
return ProductSkuConvert.INSTANCE.convertList04(skus);
}
@Override
public List<ProductSkuRespDTO> getSkuListBySpuId(Collection<Long> spuIds) {
if (CollUtil.isEmpty(spuIds)) {
return Collections.emptyList();
}
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spuIds);
return ProductSkuConvert.INSTANCE.convertList04(skus);
}

View File

@ -27,9 +27,6 @@ public class ProductSpuApiImpl implements ProductSpuApi {
@Override
public List<ProductSpuRespDTO> getSpuList(Collection<Long> ids) {
if (CollectionUtil.isEmpty(ids)) {
return Collections.emptyList();
}
return ProductSpuConvert.INSTANCE.convertList2(spuService.getSpuList(ids));
}

View File

@ -1,22 +1,14 @@
package cn.iocoder.yudao.module.product.convert.property;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueRespVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* 属性值 Convert
@ -38,18 +30,4 @@ public interface ProductPropertyValueConvert {
PageResult<ProductPropertyValueRespVO> convertPage(PageResult<ProductPropertyValueDO> page);
default List<ProductPropertyValueDetailRespBO> convertList(List<ProductPropertyValueDO> values, List<ProductPropertyDO> keys) {
Map<Long, ProductPropertyDO> keyMap = convertMap(keys, ProductPropertyDO::getId);
return CollectionUtils.convertList(values, value -> {
ProductPropertyValueDetailRespBO valueDetail = new ProductPropertyValueDetailRespBO()
.setValueId(value.getId()).setValueName(value.getName());
// 设置属性项
MapUtils.findAndThen(keyMap, value.getPropertyId(),
key -> valueDetail.setPropertyId(key.getId()).setPropertyName(key.getName()));
return valueDetail;
});
}
List<ProductPropertyValueDetailRespDTO> convertList02(List<ProductPropertyValueDetailRespBO> list);
}

View File

@ -5,7 +5,6 @@ import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.Produc
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
import java.util.Collection;
import java.util.List;
@ -56,14 +55,6 @@ public interface ProductPropertyValueService {
*/
List<ProductPropertyValueDO> getPropertyValueListByPropertyId(Collection<Long> propertyIds);
/**
* 根据编号数组获得属性值列表
*
* @param ids 编号数组
* @return 属性值明细列表
*/
List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids);
/**
* 根据属性项编号活的属性值数量
*

View File

@ -1,15 +1,12 @@
package cn.iocoder.yudao.module.product.service.property;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueCreateReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValuePageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.property.vo.value.ProductPropertyValueUpdateReqVO;
import cn.iocoder.yudao.module.product.convert.property.ProductPropertyValueConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyDO;
import cn.iocoder.yudao.module.product.dal.dataobject.property.ProductPropertyValueDO;
import cn.iocoder.yudao.module.product.dal.mysql.property.ProductPropertyValueMapper;
import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -17,11 +14,9 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_EXISTS;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.PROPERTY_VALUE_NOT_EXISTS;
@ -99,23 +94,6 @@ public class ProductPropertyValueServiceImpl implements ProductPropertyValueServ
return productPropertyValueMapper.selectListByPropertyId(propertyIds);
}
@Override
public List<ProductPropertyValueDetailRespBO> getPropertyValueDetailList(Collection<Long> ids) {
// 获得属性值列表
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
List<ProductPropertyValueDO> values = productPropertyValueMapper.selectBatchIds(ids);
if (CollUtil.isEmpty(values)) {
return Collections.emptyList();
}
// 获得属性项列表
List<ProductPropertyDO> keys = productPropertyService.getPropertyList(
convertSet(values, ProductPropertyValueDO::getPropertyId));
// 组装明细
return ProductPropertyValueConvert.INSTANCE.convertList(values, keys);
}
@Override
public Integer getPropertyValueCountByPropertyId(Long propertyId) {
return productPropertyValueMapper.selectCountByPropertyId(propertyId);

View File

@ -1,33 +0,0 @@
package cn.iocoder.yudao.module.product.service.property.bo;
import lombok.Data;
/**
* 商品属性项的明细 Response BO
*
* @author 芋道源码
*/
@Data
public class ProductPropertyValueDetailRespBO {
/**
* 属性的编号
*/
private Long propertyId;
/**
* 属性的名称
*/
private String propertyName;
/**
* 属性值的编号
*/
private Long valueId;
/**
* 属性值的名称
*/
private String valueName;
}

View File

@ -153,6 +153,9 @@ public class ProductSkuServiceImpl implements ProductSkuService {
@Override
public List<ProductSkuDO> getSkuListBySpuId(Collection<Long> spuIds) {
if (CollUtil.isEmpty(spuIds)) {
return Collections.emptyList();
}
return productSkuMapper.selectListBySpuId(spuIds);
}

View File

@ -188,6 +188,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
@Override
public List<ProductSpuDO> getSpuList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyList();
}
return productSpuMapper.selectBatchIds(ids);
}

View File

@ -13,7 +13,7 @@
<name>${project.artifactId}</name>
<description>
market 模块 API暴露给其它模块调用
promotion 模块 API暴露给其它模块调用
</description>
<dependencies>

View File

@ -1,10 +0,0 @@
package cn.iocoder.yudao.module.promotion.api.combination;
/**
* 拼团活动 Api 接口
*
* @author HUIHUI
*/
public interface CombinationActivityApi {
}

View File

@ -41,14 +41,6 @@ public interface CombinationRecordApi {
*/
boolean isCombinationRecordSuccess(Long userId, Long orderId);
/**
* 更新拼团状态为失败
*
* @param userId 用户编号
* @param orderId 订单编号
*/
void updateRecordStatusToFailed(Long userId, Long orderId);
/**
* 下单前校验是否满足拼团活动条件
*

View File

@ -1,21 +0,0 @@
package cn.iocoder.yudao.module.promotion.api.price;
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO;
/**
* 价格 API 接口
*
* @author 芋道源码
*/
public interface PriceApi {
/**
* 计算商品的价格
*
* @param calculateReqDTO 价格请求
* @return 价格相应
*/
PriceCalculateRespDTO calculatePrice(PriceCalculateReqDTO calculateReqDTO);
}

View File

@ -1,35 +0,0 @@
package cn.iocoder.yudao.module.promotion.api.price.dto;
import lombok.Data;
/**
* 优惠劵的匹配信息 Response DTO
*
* why 放在 price 包下主要获取的时候需要涉及到较多的价格计算逻辑放在 price 可以更好的复用逻辑
*
* @author 芋道源码
*/
@Data
public class CouponMeetRespDTO {
/**
* 优惠劵编号
*/
private Long id;
// ========== 非优惠劵的基本信息字段 ==========
/**
* 是否匹配
*/
private Boolean meet;
/**
* 不匹配的提示 {@link #meet} = true 才有值
*
* 例如说
* 1. 所结算商品没有符合条件的商品
* 2. XXX 元可用优惠劵
* 3. 优惠劵未到使用时间
*/
private String meetTip;
}

View File

@ -1,62 +0,0 @@
package cn.iocoder.yudao.module.promotion.api.price.dto;
import lombok.Data;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* 价格计算 Request DTO
*
* @author 芋道源码
*/
@Data
@Deprecated
public class PriceCalculateReqDTO {
/**
* 用户编号
*
* 对应 MemberUserDO id 编号
*/
private Long userId;
/**
* 优惠劵编号
*/
private Long couponId;
/**
* 收货地址编号
*/
private Long addressId;
/**
* 商品 SKU 数组
*/
@NotNull(message = "商品数组不能为空")
private List<Item> items;
/**
* 商品 SKU
*/
@Data
public static class Item {
/**
* SKU 编号
*/
@NotNull(message = "商品 SKU 编号不能为空")
private Long skuId;
/**
* SKU 数量
*/
@NotNull(message = "商品 SKU 数量不能为空")
@Min(value = 0L, message = "商品 SKU 数量必须大于等于 0") // 可传递 0 数量用于购物车未选中的情况
private Integer count;
}
}

View File

@ -1,252 +0,0 @@
package cn.iocoder.yudao.module.promotion.api.price.dto;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
import lombok.Data;
import java.util.List;
/**
* 价格计算 Response DTO
*
* 整体设计参考 taobao 的技术文档
* 1. <a href="https://developer.alibaba.com/docs/doc.htm?treeId=1&articleId=1029&docType=1">订单管理</a>
* 2. <a href="https://open.taobao.com/docV3.htm?docId=108471&docType=1">常用订单金额说明</a>
*
* 举个例子<a href="https://img.alicdn.com/top/i1/LB1mALAi4HI8KJjy1zbXXaxdpXa">订单图</a>
* 输入
* 1. 订单实付 trade.payment = 198.00订单邮费5
* 2. 商品级优惠 圣诞价: 29.00 圣诞价: 150.00 订单级优惠圣诞 2: 5.00
* 分摊
* 1. 商品 1原价 108 优惠 29 子订单实付 79 分摊主订单优惠 1.99
* 2. 商品 2原价 269 优惠 150 子订单实付 119 分摊主订单优惠 3.01
*
* @author 芋道源码
*/
@Data
@Deprecated
public class PriceCalculateRespDTO {
/**
* 订单
*/
private Order order;
/**
* 营销活动数组
*
* 只对应 {@link Order#items} 商品匹配的活动
*/
private List<Promotion> promotions;
// TODO @芋艿需要改造下主要是价格字段
/**
* 订单
*/
@Data
public static class Order {
/**
* 商品原价单位
*
* 基于 {@link OrderItem#getOriginalPrice()} 求和
*
* 对应 taobao trade.total_fee 字段
*/
private Integer totalPrice;
/**
* 订单优惠单位
*
* 订单级优惠对主订单的优惠常见如订单满 200 元减 10 订单满 80 包邮
*
* 对应 taobao order.discount_fee 字段
*/
private Integer discountPrice;
/**
* 优惠劵减免金额单位
*
* 对应 taobao trade.coupon_fee 字段
*/
private Integer couponPrice;
/**
* 积分减免金额单位
*
* 对应 taobao trade.point_fee 字段
*/
private Integer pointPrice;
/**
* 运费金额单位
*/
private Integer deliveryPrice;
/**
* 最终购买金额单位
*
* = {@link OrderItem#getPayPrice()} 求和
* - {@link #couponPrice}
* - {@link #pointPrice}
* + {@link #deliveryPrice}
* - {@link #discountPrice}
*/
private Integer payPrice;
/**
* 商品 SKU 数组
*/
private List<OrderItem> items;
// ========== 营销基本信息 ==========
/**
* 优惠劵编号
*/
private Long couponId;
}
/**
* 订单商品 SKU
*/
@Data
public static class OrderItem {
/**
* SPU 编号
*/
private Long spuId;
/**
* SKU 编号
*/
private Long skuId;
/**
* 购买数量
*/
private Integer count;
/**
* 商品原价单位
*
* = {@link #originalUnitPrice} * {@link #getCount()}
*/
private Integer originalPrice;
/**
* 商品原价单位
*
* 对应 ProductSkuDO price 字段
* 对应 taobao order.price 字段
*/
private Integer originalUnitPrice;
/**
* 商品优惠单位
*
* 商品级优惠对单个商品的常见如商品原价的 8 商品原价的减 50
*
* 对应 taobao order.discount_fee 字段
*/
private Integer discountPrice;
/**
* 子订单实付金额不算主订单分摊金额单位
*
* = {@link #originalPrice}
* - {@link #discountPrice}
*
* 对应 taobao order.payment 字段
*/
private Integer payPrice;
/**
* 子订单分摊金额单位
* 需要分摊 {@link Order#discountPrice}{@link Order#couponPrice}{@link Order#pointPrice}
*
* 对应 taobao order.part_mjz_discount 字段
* 淘宝说明子订单分摊优惠基础逻辑一般正常优惠券和满减优惠按照子订单的金额进行分摊特殊情况如果优惠券是指定商品使用的只会分摊到对应商品子订单上不分摊
*/
private Integer orderPartPrice;
/**
* 分摊后子订单实付金额单位
*
* = {@link #payPrice}
* - {@link #orderPartPrice}
*
* 对应 taobao divide_order_fee 字段
*/
private Integer orderDividePrice;
}
/**
* 营销明细
*/
@Data
@Deprecated
public static class Promotion {
/**
* 营销编号
*
* 例如说营销活动的编号优惠劵的编号
*/
private Long id;
/**
* 营销名字
*/
private String name;
/**
* 营销类型
*
* 枚举 {@link PromotionTypeEnum}
*/
private Integer type;
/**
* 营销级别
*
* 枚举 @link PromotionLevelEnum} TODO PromotionLevelEnum 没有这个枚举类
*/
private Integer level;
/**
* 计算时的原价单位
*/
private Integer totalPrice;
/**
* 计算时的优惠单位
*/
private Integer discountPrice;
/**
* 匹配的商品 SKU 数组
*/
private List<PromotionItem> items;
// ========== 匹配情况 ==========
/**
* 是否满足优惠条件
*/
private Boolean match;
/**
* 满足条件的提示
*
* 如果 {@link #match} = true 满足则提示圣诞价: 150.00
* 如果 {@link #match} = false 不满足则提示购满 85 可减 40
*/
private String description;
}
/**
* 营销匹配的商品 SKU
*/
@Data
public static class PromotionItem {
/**
* 商品 SKU 编号
*/
private Long skuId;
/**
* 计算时的原价单位
*/
private Integer originalPrice;
/**
* 计算时的优惠单位
*/
private Integer discountPrice;
}
}

View File

@ -14,8 +14,8 @@
<name>${project.artifactId}</name>
<description>
market模块,主要实现营销相关功能
例如营销活动、banner广告、优惠券、优惠码等功能。
promotion 模块,主要实现营销相关功能
例如营销活动、banner 广告、优惠券、优惠码等功能。
</description>
<dependencies>
@ -49,10 +49,6 @@
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-tenant</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-weixin</artifactId>
</dependency>
<!-- Web 相关 -->
<dependency>

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.api.bargain;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainActivityService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
@ -11,6 +12,7 @@ import javax.annotation.Resource;
* @author HUIHUI
*/
@Service
@Validated
public class BargainActivityApiImpl implements BargainActivityApi {
@Resource

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.api.bargain;
import cn.iocoder.yudao.module.promotion.api.bargain.dto.BargainValidateJoinRespDTO;
import cn.iocoder.yudao.module.promotion.service.bargain.BargainRecordService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
@ -12,6 +13,7 @@ import javax.annotation.Resource;
* @author HUIHUI
*/
@Service
@Validated
public class BargainRecordApiImpl implements BargainRecordApi {
@Resource

View File

@ -1,13 +0,0 @@
package cn.iocoder.yudao.module.promotion.api.combination;
import org.springframework.stereotype.Service;
/**
* 拼团活动 Api 接口实现类
*
* @author HUIHUI
*/
@Service
public class CombinationActivityApiImpl implements CombinationActivityApi {
}

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
@ -20,6 +21,7 @@ import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINA
* @author HUIHUI
*/
@Service
@Validated
public class CombinationRecordApiImpl implements CombinationRecordApi {
@Resource
@ -44,11 +46,6 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
return CombinationRecordStatusEnum.isSuccess(record.getStatus());
}
@Override
public void updateRecordStatusToFailed(Long userId, Long orderId) {
recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.FAILED.getStatus(), userId, orderId);
}
@Override
public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) {
return recordService.validateJoinCombination(userId, activityId, headId, skuId, count);

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
@ -17,6 +18,7 @@ import javax.annotation.Resource;
* @author 芋道源码
*/
@Service
@Validated
public class CouponApiImpl implements CouponApi {
@Resource

View File

@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.promotion.api.discount.dto.DiscountProductRespDTO
import cn.iocoder.yudao.module.promotion.convert.discount.DiscountActivityConvert;
import cn.iocoder.yudao.module.promotion.service.discount.DiscountActivityService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
@ -15,6 +16,7 @@ import java.util.List;
* @author 芋道源码
*/
@Service
@Validated
public class DiscountActivityApiImpl implements DiscountActivityApi {
@Resource

View File

@ -1,28 +0,0 @@
package cn.iocoder.yudao.module.promotion.api.price;
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateReqDTO;
import cn.iocoder.yudao.module.promotion.api.price.dto.PriceCalculateRespDTO;
import cn.iocoder.yudao.module.promotion.service.price.PriceService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* 价格 API 实现类
*
* @author 芋道源码
*/
@Service
public class PriceApiImpl implements PriceApi {
@Resource
private PriceService priceService;
@Override
public PriceCalculateRespDTO calculatePrice(PriceCalculateReqDTO calculateReqDTO) {
//return priceService.calculatePrice(calculateReqDTO); TODO 没有 calculatePrice 这个方法
return null;
}
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.api.reward;
import cn.iocoder.yudao.module.promotion.api.reward.dto.RewardActivityMatchRespDTO;
import cn.iocoder.yudao.module.promotion.service.reward.RewardActivityService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.Collection;
@ -14,6 +15,7 @@ import java.util.List;
* @author 芋道源码
*/
@Service
@Validated
public class RewardActivityApiImpl implements RewardActivityApi {
@Resource

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.api.seckill;
import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillValidateJoinRespDTO;
import cn.iocoder.yudao.module.promotion.service.seckill.SeckillActivityService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
@ -12,6 +13,7 @@ import javax.annotation.Resource;
* @author HUIHUI
*/
@Service
@Validated
public class SeckillActivityApiImpl implements SeckillActivityApi {
@Resource

Some files were not shown because too many files have changed in this diff Show More