调整框架及订单模块
This commit is contained in:
@@ -3,8 +3,6 @@ CREATE TABLE `tz_trade_order`
|
|||||||
(
|
(
|
||||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '订单编号,主键自增',
|
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '订单编号,主键自增',
|
||||||
`order_num` varchar(64) NOT NULL COMMENT '订单流水号',
|
`order_num` varchar(64) NOT NULL COMMENT '订单流水号',
|
||||||
`order_category_id` bigint NOT NULL COMMENT '订单类目id',
|
|
||||||
`order_category_name` varchar(64) NOT NULL COMMENT '订单类目名称',
|
|
||||||
`order_type` tinyint NOT NULL COMMENT '订单类型 (枚举 TradeOrderTypeEnum)',
|
`order_type` tinyint NOT NULL COMMENT '订单类型 (枚举 TradeOrderTypeEnum)',
|
||||||
`order_terminal` tinyint NOT NULL COMMENT '订单来源 (枚举 TerminalEnum)',
|
`order_terminal` tinyint NOT NULL COMMENT '订单来源 (枚举 TerminalEnum)',
|
||||||
`order_status` tinyint NOT NULL COMMENT '订单状态 (枚举 TradeOrderStatusEnum)',
|
`order_status` tinyint NOT NULL COMMENT '订单状态 (枚举 TradeOrderStatusEnum)',
|
||||||
@@ -17,19 +15,18 @@ CREATE TABLE `tz_trade_order`
|
|||||||
`cancel_time` datetime DEFAULT NULL COMMENT '订单取消时间',
|
`cancel_time` datetime DEFAULT NULL COMMENT '订单取消时间',
|
||||||
`cancel_type` tinyint DEFAULT NULL COMMENT '取消类型 (枚举 TradeOrderCancelTypeEnum)',
|
`cancel_type` tinyint DEFAULT NULL COMMENT '取消类型 (枚举 TradeOrderCancelTypeEnum)',
|
||||||
`cancel_reason` varchar(128) DEFAULT NULL COMMENT '取消原因',
|
`cancel_reason` varchar(128) DEFAULT NULL COMMENT '取消原因',
|
||||||
|
`cancel_remark` varchar(255) DEFAULT NULL COMMENT '取消原因备注',
|
||||||
`merchant_id` bigint DEFAULT NULL COMMENT '商家编号',
|
`merchant_id` bigint DEFAULT NULL COMMENT '商家编号',
|
||||||
`merchant_name` varchar(64) DEFAULT NULL COMMENT '商家名称',
|
`merchant_name` varchar(64) DEFAULT NULL COMMENT '商家名称',
|
||||||
`merchant_remark` varchar(512) DEFAULT NULL COMMENT '商家备注',
|
`merchant_remark` varchar(512) DEFAULT NULL COMMENT '商家备注',
|
||||||
`comment_status` tinyint(1) DEFAULT NULL COMMENT '是否评价 (true-已评价, false-未评价)',
|
`comment_status` tinyint(1) DEFAULT NULL COMMENT '是否评价 (true-已评价, false-未评价)',
|
||||||
`sub_type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '预约类型(1预约 2 加急)',
|
`expense_price` int DEFAULT NULL COMMENT '商品成本(单),单位:分',
|
||||||
`sub_time` datetime NOT NULL COMMENT '预约时间',
|
`price` int DEFAULT NULL COMMENT '商品原价(单),单位:分',
|
||||||
`expense_price` int(11) DEFAULT NULL COMMENT '商品成本(单),单位:分',
|
`discount_price` int DEFAULT NULL COMMENT '优惠金额(总),单位:分',
|
||||||
`price` int(11) DEFAULT NULL COMMENT '商品原价(单),单位:分',
|
`delivery_price` int DEFAULT NULL COMMENT '运费金额(总),单位:分',
|
||||||
`discount_price` int(11) DEFAULT NULL COMMENT '优惠金额(总),单位:分',
|
`adjust_price` int DEFAULT NULL COMMENT '订单调价(总),单位:分',
|
||||||
`delivery_price` int(11) DEFAULT NULL COMMENT '运费金额(总),单位:分',
|
`pay_price` int DEFAULT NULL COMMENT '应付金额(总),单位:分',
|
||||||
`adjust_price` int(11) DEFAULT NULL COMMENT '订单调价(总),单位:分',
|
`live_price` int DEFAULT NULL COMMENT '实收金额(总),单位:分',
|
||||||
`pay_price` int(11) DEFAULT NULL COMMENT '应付金额(总),单位:分',
|
|
||||||
`live_price` int(11) DEFAULT NULL COMMENT '实收金额(总),单位:分',
|
|
||||||
`pay_order_id` bigint DEFAULT NULL COMMENT '支付订单编号',
|
`pay_order_id` bigint DEFAULT NULL COMMENT '支付订单编号',
|
||||||
`pay_status` tinyint(1) DEFAULT NULL COMMENT '是否已支付 (true-已支付, false-未支付)',
|
`pay_status` tinyint(1) DEFAULT NULL COMMENT '是否已支付 (true-已支付, false-未支付)',
|
||||||
`pay_type` tinyint DEFAULT NULL COMMENT '支付方式(PayTypeEnum)',
|
`pay_type` tinyint DEFAULT NULL COMMENT '支付方式(PayTypeEnum)',
|
||||||
@@ -53,6 +50,7 @@ CREATE TABLE `tz_trade_order`
|
|||||||
`after_sale_status` tinyint DEFAULT NULL COMMENT '售后状态 (枚举 TradeOrderItemAfterSaleStatusEnum)',
|
`after_sale_status` tinyint DEFAULT NULL COMMENT '售后状态 (枚举 TradeOrderItemAfterSaleStatusEnum)',
|
||||||
`finance_id` bigint DEFAULT NULL COMMENT '财务单编号',
|
`finance_id` bigint DEFAULT NULL COMMENT '财务单编号',
|
||||||
`finance_status` tinyint DEFAULT NULL COMMENT '财务状态 (枚举 TradeOrderItemFinanceEnum)',
|
`finance_status` tinyint DEFAULT NULL COMMENT '财务状态 (枚举 TradeOrderItemFinanceEnum)',
|
||||||
|
`tenant_id` bigint NOT NULL DEFAULT '1' COMMENT '租户编号',
|
||||||
`version` int NOT NULL DEFAULT '0' COMMENT '版本号(乐观锁)',
|
`version` int NOT NULL DEFAULT '0' COMMENT '版本号(乐观锁)',
|
||||||
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||||
`update_time` datetime DEFAULT NULL COMMENT '最后更新时间',
|
`update_time` datetime DEFAULT NULL COMMENT '最后更新时间',
|
||||||
@@ -310,14 +308,14 @@ CREATE TABLE `tz_trade_delivery_pick_up_store`
|
|||||||
-- 订单预约时间修改记录表 (tz_trade_sub_log)
|
-- 订单预约时间修改记录表 (tz_trade_sub_log)
|
||||||
CREATE TABLE `tz_trade_sub_log`
|
CREATE TABLE `tz_trade_sub_log`
|
||||||
(
|
(
|
||||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
|
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '编号',
|
||||||
`user_id` bigint(20) NOT NULL COMMENT '用户编号',
|
`user_id` bigint(20) NOT NULL COMMENT '用户编号',
|
||||||
`order_id` bigint(20) NOT NULL COMMENT '订单号',
|
`order_id` bigint(20) NOT NULL COMMENT '订单号',
|
||||||
`sub_time` datetime NOT NULL COMMENT '预约时间',
|
`sub_time` datetime NOT NULL COMMENT '预约时间',
|
||||||
`create_time` datetime NOT NULL COMMENT '创建时间',
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
`creator` varchar(64) NOT NULL COMMENT '创建者',
|
`creator` varchar(64) NOT NULL COMMENT '创建者',
|
||||||
`updater` varchar(64) NOT NULL COMMENT '更新者',
|
`updater` varchar(64) NOT NULL COMMENT '更新者',
|
||||||
`deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
|
`deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `idx_order_id` (`order_id`),
|
KEY `idx_order_id` (`order_id`),
|
||||||
KEY `idx_user_id` (`user_id`)
|
KEY `idx_user_id` (`user_id`)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.tashow.cloud.redis.config.TashowCacheProperties;
|
|||||||
import com.tashow.cloud.systemapi.api.tenant.TenantApi;
|
import com.tashow.cloud.systemapi.api.tenant.TenantApi;
|
||||||
import com.tashow.cloud.tenant.core.aop.TenantIgnoreAspect;
|
import com.tashow.cloud.tenant.core.aop.TenantIgnoreAspect;
|
||||||
import com.tashow.cloud.tenant.core.db.TenantDatabaseInterceptor;
|
import com.tashow.cloud.tenant.core.db.TenantDatabaseInterceptor;
|
||||||
import com.tashow.cloud.tenant.core.job.TenantJobAspect;
|
|
||||||
import com.tashow.cloud.tenant.core.mq.rabbitmq.TenantRabbitMQInitializer;
|
import com.tashow.cloud.tenant.core.mq.rabbitmq.TenantRabbitMQInitializer;
|
||||||
import com.tashow.cloud.tenant.core.redis.TenantRedisCacheManager;
|
import com.tashow.cloud.tenant.core.redis.TenantRedisCacheManager;
|
||||||
import com.tashow.cloud.tenant.core.security.TenantSecurityWebFilter;
|
import com.tashow.cloud.tenant.core.security.TenantSecurityWebFilter;
|
||||||
@@ -86,14 +85,6 @@ public class TenantAutoConfiguration {
|
|||||||
return registrationBean;
|
return registrationBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== Job ==========
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnClass(name = "com.xxl.job.core.handler.annotation.XxlJob")
|
|
||||||
public TenantJobAspect tenantJobAspect(TenantFrameworkService tenantFrameworkService) {
|
|
||||||
return new TenantJobAspect(tenantFrameworkService);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnClass(name = "org.springframework.amqp.rabbit.core.RabbitTemplate")
|
@ConditionalOnClass(name = "org.springframework.amqp.rabbit.core.RabbitTemplate")
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ package com.tashow.cloud.tenant.config;
|
|||||||
|
|
||||||
import com.tashow.cloud.systemapi.api.tenant.TenantApi;
|
import com.tashow.cloud.systemapi.api.tenant.TenantApi;
|
||||||
import com.tashow.cloud.tenant.core.rpc.TenantRequestInterceptor;
|
import com.tashow.cloud.tenant.core.rpc.TenantRequestInterceptor;
|
||||||
import com.tashow.cloud.tenant.core.rpc.TenantRequestInterceptor;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
@AutoConfiguration
|
@AutoConfiguration
|
||||||
@ConditionalOnProperty(prefix = "tashow.tenant", value = "enable", matchIfMissing = true) // 允许使用 yudao.tenant.enable=false 禁用多租户
|
@ConditionalOnProperty(prefix = "tashow.tenant", value = "enable", matchIfMissing = true)
|
||||||
@EnableFeignClients(clients = TenantApi.class) // 主要是引入相关的 API 服务
|
@EnableFeignClients(clients = TenantApi.class) // 主要是引入相关的 API 服务
|
||||||
public class TenantRpcAutoConfiguration {
|
public class TenantRpcAutoConfiguration {
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package com.tashow.cloud.tenant.core.job;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 多租户 Job 注解
|
|
||||||
*/
|
|
||||||
@Target({ElementType.METHOD})
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface TenantJob {
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
package com.tashow.cloud.tenant.core.job;
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.tashow.cloud.common.util.json.JsonUtils;
|
|
||||||
import com.tashow.cloud.tenant.core.service.TenantFrameworkService;
|
|
||||||
import com.tashow.cloud.tenant.core.util.TenantUtils;
|
|
||||||
import com.xxl.job.core.context.XxlJobContext;
|
|
||||||
import com.xxl.job.core.context.XxlJobHelper;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.Around;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 多租户 JobHandler AOP
|
|
||||||
* 任务执行时,会按照租户逐个执行 Job 的逻辑
|
|
||||||
*
|
|
||||||
* 注意,需要保证 JobHandler 的幂等性。因为 Job 因为某个租户执行失败重试时,之前执行成功的租户也会再次执行。
|
|
||||||
*
|
|
||||||
* @author 芋道源码
|
|
||||||
*/
|
|
||||||
@Aspect
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Slf4j
|
|
||||||
public class TenantJobAspect {
|
|
||||||
|
|
||||||
private final TenantFrameworkService tenantFrameworkService;
|
|
||||||
|
|
||||||
@Around("@annotation(tenantJob)")
|
|
||||||
public void around(ProceedingJoinPoint joinPoint, TenantJob tenantJob) {
|
|
||||||
// 获得租户列表
|
|
||||||
List<Long> tenantIds = tenantFrameworkService.getTenantIds();
|
|
||||||
if (CollUtil.isEmpty(tenantIds)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 逐个租户,执行 Job
|
|
||||||
Map<Long, String> results = new ConcurrentHashMap<>();
|
|
||||||
AtomicBoolean success = new AtomicBoolean(true); // 标记,是否存在失败的情况
|
|
||||||
XxlJobContext xxlJobContext = XxlJobContext.getXxlJobContext(); // XXL-Job 上下文
|
|
||||||
tenantIds.parallelStream().forEach(tenantId -> {
|
|
||||||
// TODO 芋艿:先通过 parallel 实现并行;1)多个租户,是一条执行日志;2)异常的情况
|
|
||||||
TenantUtils.execute(tenantId, () -> {
|
|
||||||
try {
|
|
||||||
XxlJobContext.setXxlJobContext(xxlJobContext);
|
|
||||||
// 执行 Job
|
|
||||||
Object result = joinPoint.proceed();
|
|
||||||
results.put(tenantId, StrUtil.toStringOrEmpty(result));
|
|
||||||
} catch (Throwable e) {
|
|
||||||
results.put(tenantId, ExceptionUtil.getRootCauseMessage(e));
|
|
||||||
success.set(false);
|
|
||||||
// 打印异常
|
|
||||||
XxlJobHelper.log(StrUtil.format("[多租户({}) 执行任务({}),发生异常:{}]",
|
|
||||||
tenantId, joinPoint.getSignature(), ExceptionUtils.getStackTrace(e)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
// 记录执行结果
|
|
||||||
if (success.get()) {
|
|
||||||
XxlJobHelper.handleSuccess(JsonUtils.toJsonString(results));
|
|
||||||
} else {
|
|
||||||
XxlJobHelper.handleFail(JsonUtils.toJsonString(results));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -41,6 +41,11 @@
|
|||||||
<artifactId>tashow-framework-env</artifactId>
|
<artifactId>tashow-framework-env</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.tashow.cloud</groupId>
|
||||||
|
<artifactId>tashow-framework-tenant</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 依赖服务 -->
|
<!-- 依赖服务 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.tashow.cloud</groupId>
|
<groupId>com.tashow.cloud</groupId>
|
||||||
|
|||||||
@@ -9,4 +9,5 @@ spring:
|
|||||||
import:
|
import:
|
||||||
- optional:classpath:application-${spring.profiles.active}.yaml # 加载【本地】配置
|
- optional:classpath:application-${spring.profiles.active}.yaml # 加载【本地】配置
|
||||||
- optional:nacos:application.yaml # 加载【本地】配置
|
- optional:nacos:application.yaml # 加载【本地】配置
|
||||||
|
- optional:nacos:tenant.yaml # 加载【本地】配置
|
||||||
- optional:nacos:${spring.application.name}-${spring.profiles.active}.yaml # 加载【Nacos】的配置
|
- optional:nacos:${spring.application.name}-${spring.profiles.active}.yaml # 加载【Nacos】的配置
|
||||||
@@ -16,3 +16,4 @@ spring:
|
|||||||
- optional:classpath:application-${spring.profiles.active}.yaml # 加载【本地】配置
|
- optional:classpath:application-${spring.profiles.active}.yaml # 加载【本地】配置
|
||||||
- optional:nacos:${spring.application.name}-${spring.profiles.active}.yaml # 加载【Nacos】的配置
|
- optional:nacos:${spring.application.name}-${spring.profiles.active}.yaml # 加载【Nacos】的配置
|
||||||
- optional:nacos:application.yaml # 加载【Nacos】的配置
|
- optional:nacos:application.yaml # 加载【Nacos】的配置
|
||||||
|
- optional:nacos:tenant.yaml # 加载【Nacos】的配置
|
||||||
|
|||||||
Reference in New Issue
Block a user