Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into develop-tmp

# Conflicts:
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponController.java
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/coupon/CouponMapper.java
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponService.java
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java
#	yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java
#	yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/calculator/TradeRewardActivityPriceCalculator.java
This commit is contained in:
YunaiV 2024-09-15 11:24:32 +08:00
commit 2876c7ce16
70 changed files with 674 additions and 893 deletions

View File

@ -15,12 +15,12 @@
<!-- 各种 module 拓展 --> <!-- 各种 module 拓展 -->
<module>yudao-module-system</module> <module>yudao-module-system</module>
<module>yudao-module-infra</module> <module>yudao-module-infra</module>
<module>yudao-module-member</module> <!-- <module>yudao-module-member</module>-->
<!-- <module>yudao-module-bpm</module>--> <!-- <module>yudao-module-bpm</module>-->
<!-- <module>yudao-module-report</module>--> <!-- <module>yudao-module-report</module>-->
<!-- <module>yudao-module-mp</module>--> <!-- <module>yudao-module-mp</module>-->
<module>yudao-module-pay</module> <!-- <module>yudao-module-pay</module>-->
<module>yudao-module-mall</module> <!-- <module>yudao-module-mall</module>-->
<!-- <module>yudao-module-crm</module>--> <!-- <module>yudao-module-crm</module>-->
<!-- <module>yudao-module-erp</module>--> <!-- <module>yudao-module-erp</module>-->
<!-- <module>yudao-module-ai</module>--> <!-- <module>yudao-module-ai</module>-->

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.tenant.core.job;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.exceptions.ExceptionUtil; import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService; import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService;
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
@ -44,7 +45,8 @@ public class TenantJobAspect {
// TODO 芋艿先通过 parallel 实现并行1多个租户是一条执行日志2异常的情况 // TODO 芋艿先通过 parallel 实现并行1多个租户是一条执行日志2异常的情况
TenantUtils.execute(tenantId, () -> { TenantUtils.execute(tenantId, () -> {
try { try {
joinPoint.proceed(); Object result = joinPoint.proceed();
results.put(tenantId, StrUtil.toStringOrNull(result));
} catch (Throwable e) { } catch (Throwable e) {
log.error("[execute][租户({}) 执行 Job 发生异常", tenantId, e); log.error("[execute][租户({}) 执行 Job 发生异常", tenantId, e);
results.put(tenantId, ExceptionUtil.getRootCauseMessage(e)); results.put(tenantId, ExceptionUtil.getRootCauseMessage(e));

View File

@ -11,7 +11,6 @@ import com.mzt.logapi.service.ILogRecordService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import java.util.List; import java.util.List;
@ -29,7 +28,6 @@ public class LogRecordServiceImpl implements ILogRecordService {
private OperateLogApi operateLogApi; private OperateLogApi operateLogApi;
@Override @Override
@Async
public void record(LogRecord logRecord) { public void record(LogRecord logRecord) {
OperateLogCreateReqDTO reqDTO = new OperateLogCreateReqDTO(); OperateLogCreateReqDTO reqDTO = new OperateLogCreateReqDTO();
try { try {
@ -42,7 +40,7 @@ public class LogRecordServiceImpl implements ILogRecordService {
fillRequestFields(reqDTO); fillRequestFields(reqDTO);
// 2. 异步记录日志 // 2. 异步记录日志
operateLogApi.createOperateLog(reqDTO); operateLogApi.createOperateLogAsync(reqDTO);
} catch (Throwable ex) { } catch (Throwable ex) {
// 由于 @Async 异步调用这里打印下日志更容易跟进 // 由于 @Async 异步调用这里打印下日志更容易跟进
log.error("[record][url({}) log({}) 发生异常]", reqDTO.getRequestUrl(), reqDTO, ex); log.error("[record][url({}) log({}) 发生异常]", reqDTO.getRequestUrl(), reqDTO, ex);

View File

@ -2,15 +2,10 @@ package cn.iocoder.yudao.framework.apilog.config;
import cn.iocoder.yudao.framework.apilog.core.filter.ApiAccessLogFilter; import cn.iocoder.yudao.framework.apilog.core.filter.ApiAccessLogFilter;
import cn.iocoder.yudao.framework.apilog.core.interceptor.ApiAccessLogInterceptor; import cn.iocoder.yudao.framework.apilog.core.interceptor.ApiAccessLogInterceptor;
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService;
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkServiceImpl;
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkServiceImpl;
import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
import cn.iocoder.yudao.framework.web.config.WebProperties; import cn.iocoder.yudao.framework.web.config.WebProperties;
import cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration; import cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration;
import cn.iocoder.yudao.module.infra.api.logger.ApiAccessLogApi; import cn.iocoder.yudao.module.infra.api.logger.ApiAccessLogApi;
import cn.iocoder.yudao.module.infra.api.logger.ApiErrorLogApi;
import jakarta.servlet.Filter; import jakarta.servlet.Filter;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
@ -23,18 +18,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@AutoConfiguration(after = YudaoWebAutoConfiguration.class) @AutoConfiguration(after = YudaoWebAutoConfiguration.class)
public class YudaoApiLogAutoConfiguration implements WebMvcConfigurer { public class YudaoApiLogAutoConfiguration implements WebMvcConfigurer {
@Bean
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public ApiAccessLogFrameworkService apiAccessLogFrameworkService(ApiAccessLogApi apiAccessLogApi) {
return new ApiAccessLogFrameworkServiceImpl(apiAccessLogApi);
}
@Bean
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public ApiErrorLogFrameworkService apiErrorLogFrameworkService(ApiErrorLogApi apiErrorLogApi) {
return new ApiErrorLogFrameworkServiceImpl(apiErrorLogApi);
}
/** /**
* 创建 ApiAccessLogFilter Bean记录 API 请求日志 * 创建 ApiAccessLogFilter Bean记录 API 请求日志
*/ */
@ -42,8 +25,8 @@ public class YudaoApiLogAutoConfiguration implements WebMvcConfigurer {
@ConditionalOnProperty(prefix = "yudao.access-log", value = "enable", matchIfMissing = true) // 允许使用 yudao.access-log.enable=false 禁用访问日志 @ConditionalOnProperty(prefix = "yudao.access-log", value = "enable", matchIfMissing = true) // 允许使用 yudao.access-log.enable=false 禁用访问日志
public FilterRegistrationBean<ApiAccessLogFilter> apiAccessLogFilter(WebProperties webProperties, public FilterRegistrationBean<ApiAccessLogFilter> apiAccessLogFilter(WebProperties webProperties,
@Value("${spring.application.name}") String applicationName, @Value("${spring.application.name}") String applicationName,
ApiAccessLogFrameworkService apiAccessLogFrameworkService) { ApiAccessLogApi apiAccessLogApi) {
ApiAccessLogFilter filter = new ApiAccessLogFilter(webProperties, applicationName, apiAccessLogFrameworkService); ApiAccessLogFilter filter = new ApiAccessLogFilter(webProperties, applicationName, apiAccessLogApi);
return createFilterBean(filter, WebFilterOrderEnum.API_ACCESS_LOG_FILTER); return createFilterBean(filter, WebFilterOrderEnum.API_ACCESS_LOG_FILTER);
} }

View File

@ -9,7 +9,6 @@ import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum; import cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum;
import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService;
import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants; import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
@ -18,6 +17,7 @@ import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import cn.iocoder.yudao.framework.web.config.WebProperties; import cn.iocoder.yudao.framework.web.config.WebProperties;
import cn.iocoder.yudao.framework.web.core.filter.ApiRequestFilter; import cn.iocoder.yudao.framework.web.core.filter.ApiRequestFilter;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.infra.api.logger.ApiAccessLogApi;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -36,7 +36,7 @@ import java.time.temporal.ChronoUnit;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import static cn.iocoder.yudao.framework.apilog.core.interceptor.ApiAccessLogInterceptor.*; import static cn.iocoder.yudao.framework.apilog.core.interceptor.ApiAccessLogInterceptor.ATTRIBUTE_HANDLER_METHOD;
import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString;
/** /**
@ -53,12 +53,12 @@ public class ApiAccessLogFilter extends ApiRequestFilter {
private final String applicationName; private final String applicationName;
private final ApiAccessLogFrameworkService apiAccessLogFrameworkService; private final ApiAccessLogApi apiAccessLogApi;
public ApiAccessLogFilter(WebProperties webProperties, String applicationName, ApiAccessLogFrameworkService apiAccessLogFrameworkService) { public ApiAccessLogFilter(WebProperties webProperties, String applicationName, ApiAccessLogApi apiAccessLogApi) {
super(webProperties); super(webProperties);
this.applicationName = applicationName; this.applicationName = applicationName;
this.apiAccessLogFrameworkService = apiAccessLogFrameworkService; this.apiAccessLogApi = apiAccessLogApi;
} }
@Override @Override
@ -91,7 +91,7 @@ public class ApiAccessLogFilter extends ApiRequestFilter {
if (!enable) { if (!enable) {
return; return;
} }
apiAccessLogFrameworkService.createApiAccessLog(accessLog); apiAccessLogApi.createApiAccessLogAsync(accessLog);
} catch (Throwable th) { } catch (Throwable th) {
log.error("[createApiAccessLog][url({}) log({}) 发生异常]", request.getRequestURI(), toJsonString(accessLog), th); log.error("[createApiAccessLog][url({}) log({}) 发生异常]", request.getRequestURI(), toJsonString(accessLog), th);
} }

View File

@ -1,19 +0,0 @@
package cn.iocoder.yudao.framework.apilog.core.service;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
/**
* API 访问日志 Framework Service 接口
*
* @author 芋道源码
*/
public interface ApiAccessLogFrameworkService {
/**
* 创建 API 访问日志
*
* @param reqDTO API 访问日志
*/
void createApiAccessLog(ApiAccessLogCreateReqDTO reqDTO);
}

View File

@ -1,33 +0,0 @@
package cn.iocoder.yudao.framework.apilog.core.service;
import cn.iocoder.yudao.module.infra.api.logger.ApiAccessLogApi;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
/**
* API 访问日志 Framework Service 实现类
*
* 基于 {@link ApiAccessLogApi} 服务记录访问日志
*
* @author 芋道源码
*/
@RequiredArgsConstructor
@Slf4j
public class ApiAccessLogFrameworkServiceImpl implements ApiAccessLogFrameworkService {
private final ApiAccessLogApi apiAccessLogApi;
@Override
@Async
public void createApiAccessLog(ApiAccessLogCreateReqDTO reqDTO) {
try {
apiAccessLogApi.createApiAccessLog(reqDTO);
} catch (Throwable ex) {
// 由于 @Async 异步调用这里打印下日志更容易跟进
log.error("[createApiAccessLog][url({}) log({}) 发生异常]", reqDTO.getRequestUrl(), reqDTO, ex);
}
}
}

View File

@ -1,19 +0,0 @@
package cn.iocoder.yudao.framework.apilog.core.service;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
/**
* API 错误日志 Framework Service 接口
*
* @author 芋道源码
*/
public interface ApiErrorLogFrameworkService {
/**
* 创建 API 错误日志
*
* @param reqDTO API 错误日志
*/
void createApiErrorLog(ApiErrorLogCreateReqDTO reqDTO);
}

View File

@ -1,33 +0,0 @@
package cn.iocoder.yudao.framework.apilog.core.service;
import cn.iocoder.yudao.module.infra.api.logger.ApiErrorLogApi;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
/**
* API 错误日志 Framework Service 实现类
*
* 基于 {@link ApiErrorLogApi} 服务记录错误日志
*
* @author 芋道源码
*/
@RequiredArgsConstructor
@Slf4j
public class ApiErrorLogFrameworkServiceImpl implements ApiErrorLogFrameworkService {
private final ApiErrorLogApi apiErrorLogApi;
@Override
@Async
public void createApiErrorLog(ApiErrorLogCreateReqDTO reqDTO) {
try {
apiErrorLogApi.createApiErrorLog(reqDTO);
} catch (Throwable ex) {
// 由于 @Async 异步调用这里打印下日志更容易跟进
log.error("[createApiErrorLog][url({}) log({}) 发生异常]", reqDTO.getRequestUrl(), reqDTO, ex);
}
}
}

View File

@ -1,12 +1,14 @@
package cn.iocoder.yudao.framework.web.config; package cn.iocoder.yudao.framework.web.config;
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
import cn.iocoder.yudao.framework.web.core.filter.CacheRequestBodyFilter; import cn.iocoder.yudao.framework.web.core.filter.CacheRequestBodyFilter;
import cn.iocoder.yudao.framework.web.core.filter.DemoFilter; import cn.iocoder.yudao.framework.web.core.filter.DemoFilter;
import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler; import cn.iocoder.yudao.framework.web.core.handler.GlobalExceptionHandler;
import cn.iocoder.yudao.framework.web.core.handler.GlobalResponseBodyHandler; import cn.iocoder.yudao.framework.web.core.handler.GlobalResponseBodyHandler;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.infra.api.logger.ApiErrorLogApi;
import jakarta.annotation.Resource;
import jakarta.servlet.Filter;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@ -25,9 +27,6 @@ import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import jakarta.annotation.Resource;
import jakarta.servlet.Filter;
@AutoConfiguration @AutoConfiguration
@EnableConfigurationProperties(WebProperties.class) @EnableConfigurationProperties(WebProperties.class)
public class YudaoWebAutoConfiguration implements WebMvcConfigurer { public class YudaoWebAutoConfiguration implements WebMvcConfigurer {
@ -59,8 +58,9 @@ public class YudaoWebAutoConfiguration implements WebMvcConfigurer {
} }
@Bean @Bean
public GlobalExceptionHandler globalExceptionHandler(ApiErrorLogFrameworkService apiErrorLogFrameworkService) { @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
return new GlobalExceptionHandler(applicationName, apiErrorLogFrameworkService); public GlobalExceptionHandler globalExceptionHandler(ApiErrorLogApi apiErrorLogApi) {
return new GlobalExceptionHandler(applicationName, apiErrorLogApi);
} }
@Bean @Bean

View File

@ -5,7 +5,6 @@ import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.JakartaServletUtil; import cn.hutool.extra.servlet.JakartaServletUtil;
import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.framework.common.exception.ServiceException;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
@ -14,6 +13,7 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.infra.api.logger.ApiErrorLogApi;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
import com.fasterxml.jackson.databind.exc.InvalidFormatException; import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
@ -40,12 +40,7 @@ import java.time.LocalDateTime;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.FORBIDDEN;
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.METHOD_NOT_ALLOWED;
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.NOT_FOUND;
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.NOT_IMPLEMENTED;
/** /**
* 全局异常处理器 Exception 翻译成 CommonResult + 对应的异常编号 * 全局异常处理器 Exception 翻译成 CommonResult + 对应的异常编号
@ -65,7 +60,7 @@ public class GlobalExceptionHandler {
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
private final String applicationName; private final String applicationName;
private final ApiErrorLogFrameworkService apiErrorLogFrameworkService; private final ApiErrorLogApi apiErrorLogApi;
/** /**
* 处理所有异常主要是提供给 Filter 使用 * 处理所有异常主要是提供给 Filter 使用
@ -288,7 +283,7 @@ public class GlobalExceptionHandler {
// 初始化 errorLog // 初始化 errorLog
buildExceptionLog(errorLog, req, e); buildExceptionLog(errorLog, req, e);
// 执行插入 errorLog // 执行插入 errorLog
apiErrorLogFrameworkService.createApiErrorLog(errorLog); apiErrorLogApi.createApiErrorLogAsync(errorLog);
} catch (Throwable th) { } catch (Throwable th) {
log.error("[createExceptionLog][url({}) log({}) 发生异常]", req.getRequestURI(), JsonUtils.toJsonString(errorLog), th); log.error("[createExceptionLog][url({}) log({}) 发生异常]", req.getRequestURI(), JsonUtils.toJsonString(errorLog), th);
} }

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mq.redis.core.RedisMQTemplate;
import cn.iocoder.yudao.framework.websocket.core.handler.JsonWebSocketMessageHandler; import cn.iocoder.yudao.framework.websocket.core.handler.JsonWebSocketMessageHandler;
import cn.iocoder.yudao.framework.websocket.core.listener.WebSocketMessageListener; import cn.iocoder.yudao.framework.websocket.core.listener.WebSocketMessageListener;
import cn.iocoder.yudao.framework.websocket.core.security.LoginUserHandshakeInterceptor; import cn.iocoder.yudao.framework.websocket.core.security.LoginUserHandshakeInterceptor;
import cn.iocoder.yudao.framework.websocket.core.security.WebSocketAuthorizeRequestsCustomizer;
import cn.iocoder.yudao.framework.websocket.core.sender.kafka.KafkaWebSocketMessageConsumer; import cn.iocoder.yudao.framework.websocket.core.sender.kafka.KafkaWebSocketMessageConsumer;
import cn.iocoder.yudao.framework.websocket.core.sender.kafka.KafkaWebSocketMessageSender; import cn.iocoder.yudao.framework.websocket.core.sender.kafka.KafkaWebSocketMessageSender;
import cn.iocoder.yudao.framework.websocket.core.sender.local.LocalWebSocketMessageSender; import cn.iocoder.yudao.framework.websocket.core.sender.local.LocalWebSocketMessageSender;
@ -76,6 +77,11 @@ public class YudaoWebSocketAutoConfiguration {
return new WebSocketSessionManagerImpl(); return new WebSocketSessionManagerImpl();
} }
@Bean
public WebSocketAuthorizeRequestsCustomizer webSocketAuthorizeRequestsCustomizer(WebSocketProperties webSocketProperties) {
return new WebSocketAuthorizeRequestsCustomizer(webSocketProperties);
}
// ==================== Sender 相关 ==================== // ==================== Sender 相关 ====================
@Configuration @Configuration

View File

@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModel
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO; import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO; import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
import cn.iocoder.yudao.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO; import cn.iocoder.yudao.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO;
import org.flowable.common.engine.impl.db.SuspensionState; import org.flowable.common.engine.impl.db.SuspensionState;
import org.flowable.engine.repository.Deployment; import org.flowable.engine.repository.Deployment;
@ -55,7 +56,7 @@ public interface BpmModelConvert {
BpmModelMetaInfoRespDTO metaInfo = buildMetaInfo(model); BpmModelMetaInfoRespDTO metaInfo = buildMetaInfo(model);
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null); BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null);
if (ArrayUtil.isNotEmpty(bpmnBytes)) { if (ArrayUtil.isNotEmpty(bpmnBytes)) {
modelVO.setBpmnXml(new String(bpmnBytes)); modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes));
} }
return modelVO; return modelVO;
} }

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.util;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants; import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnModelConstants;
import org.flowable.bpmn.converter.BpmnXMLConverter; import org.flowable.bpmn.converter.BpmnXMLConverter;
@ -108,7 +109,14 @@ public class BpmnModelUtils {
return null; return null;
} }
BpmnXMLConverter converter = new BpmnXMLConverter(); BpmnXMLConverter converter = new BpmnXMLConverter();
return new String(converter.convertToXML(model)); return StrUtil.utf8Str(converter.convertToXML(model));
}
public static String getBpmnXml(byte[] bpmnBytes) {
if (ArrayUtil.isEmpty(bpmnBytes)) {
return null;
}
return StrUtil.utf8Str(bpmnBytes);
} }
// ========== 遍历相关的方法 ========== // ========== 遍历相关的方法 ==========

View File

@ -92,7 +92,7 @@ public interface CrmReceivableMapper extends BaseMapperX<CrmReceivableDO> {
List<Map<String, Object>> result = selectMaps(new QueryWrapper<CrmReceivableDO>() List<Map<String, Object>> result = selectMaps(new QueryWrapper<CrmReceivableDO>()
.select("contract_id, SUM(price) AS total_price") .select("contract_id, SUM(price) AS total_price")
.in("audit_status", CrmAuditStatusEnum.DRAFT.getStatus(), // 草稿 + 审批中 + 审批通过 .in("audit_status", CrmAuditStatusEnum.DRAFT.getStatus(), // 草稿 + 审批中 + 审批通过
CrmAuditStatusEnum.PROCESS, CrmAuditStatusEnum.APPROVE.getStatus()) CrmAuditStatusEnum.PROCESS.getStatus(), CrmAuditStatusEnum.APPROVE.getStatus())
.groupBy("contract_id") .groupBy("contract_id")
.in("contract_id", contractIds)); .in("contract_id", contractIds));
// 获得金额 // 获得金额

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.infra.api.logger;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.scheduling.annotation.Async;
/** /**
* API 访问日志的 API 接口 * API 访问日志的 API 接口
@ -18,4 +19,14 @@ public interface ApiAccessLogApi {
*/ */
void createApiAccessLog(@Valid ApiAccessLogCreateReqDTO createDTO); void createApiAccessLog(@Valid ApiAccessLogCreateReqDTO createDTO);
/**
* 异步创建 API 访问日志
*
* @param createDTO 访问日志 DTO
*/
@Async
default void createApiAccessLogAsync(ApiAccessLogCreateReqDTO createDTO) {
createApiAccessLog(createDTO);
}
} }

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.infra.api.logger;
import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO; import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.scheduling.annotation.Async;
/** /**
* API 错误日志的 API 接口 * API 错误日志的 API 接口
@ -18,4 +19,14 @@ public interface ApiErrorLogApi {
*/ */
void createApiErrorLog(@Valid ApiErrorLogCreateReqDTO createDTO); void createApiErrorLog(@Valid ApiErrorLogCreateReqDTO createDTO);
/**
* 异步创建 API 异常日志
*
* @param createDTO 异常日志 DTO
*/
@Async
default void createApiErrorLogAsync(ApiErrorLogCreateReqDTO createDTO) {
createApiErrorLog(createDTO);
}
} }

View File

@ -22,7 +22,7 @@ public interface ErrorCodeConstants {
ErrorCode JOB_CHANGE_STATUS_EQUALS = new ErrorCode(1_001_001_003, "定时任务已经处于该状态,无需修改"); ErrorCode JOB_CHANGE_STATUS_EQUALS = new ErrorCode(1_001_001_003, "定时任务已经处于该状态,无需修改");
ErrorCode JOB_UPDATE_ONLY_NORMAL_STATUS = new ErrorCode(1_001_001_004, "只有开启状态的任务,才可以修改"); ErrorCode JOB_UPDATE_ONLY_NORMAL_STATUS = new ErrorCode(1_001_001_004, "只有开启状态的任务,才可以修改");
ErrorCode JOB_CRON_EXPRESSION_VALID = new ErrorCode(1_001_001_005, "CRON 表达式不正确"); ErrorCode JOB_CRON_EXPRESSION_VALID = new ErrorCode(1_001_001_005, "CRON 表达式不正确");
ErrorCode JOB_HANDLER_BEAN_NOT_EXISTS = new ErrorCode(1_001_001_006, "定时任务的处理器 Bean 不存在"); ErrorCode JOB_HANDLER_BEAN_NOT_EXISTS = new ErrorCode(1_001_001_006, "定时任务的处理器 Bean 不存在,注意 Bean 默认首字母小写");
ErrorCode JOB_HANDLER_BEAN_TYPE_ERROR = new ErrorCode(1_001_001_007, "定时任务的处理器 Bean 类型不正确,未实现 JobHandler 接口"); ErrorCode JOB_HANDLER_BEAN_TYPE_ERROR = new ErrorCode(1_001_001_007, "定时任务的处理器 Bean 类型不正确,未实现 JobHandler 接口");
// ========== API 错误日志 1-001-002-000 ========== // ========== API 错误日志 1-001-002-000 ==========

View File

@ -14,7 +14,6 @@ public enum CodegenFrontTypeEnum {
VUE2(10), // Vue2 Element UI 标准模版 VUE2(10), // Vue2 Element UI 标准模版
VUE3(20), // Vue3 Element Plus 标准模版 VUE3(20), // Vue3 Element Plus 标准模版
VUE3_SCHEMA(21), // Vue3 Element Plus Schema 模版
VUE3_VBEN(30), // Vue3 VBEN 模版 VUE3_VBEN(30), // Vue3 VBEN 模版
; ;

View File

@ -135,15 +135,6 @@ public class CodegenEngine {
vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}List.vue")) vue3FilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}List.vue"))
.put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("api/api.ts"), .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("api/api.ts"),
vue3FilePath("api/${table.moduleName}/${table.businessName}/index.ts")) vue3FilePath("api/${table.moduleName}/${table.businessName}/index.ts"))
// Vue3 Schema 模版
.put(CodegenFrontTypeEnum.VUE3_SCHEMA.getType(), vue3SchemaTemplatePath("views/data.ts"),
vue3FilePath("views/${table.moduleName}/${table.businessName}/${classNameVar}.data.ts"))
.put(CodegenFrontTypeEnum.VUE3_SCHEMA.getType(), vue3SchemaTemplatePath("views/index.vue"),
vue3FilePath("views/${table.moduleName}/${table.businessName}/index.vue"))
.put(CodegenFrontTypeEnum.VUE3_SCHEMA.getType(), vue3SchemaTemplatePath("views/form.vue"),
vue3FilePath("views/${table.moduleName}/${table.businessName}/${simpleClassName}Form.vue"))
.put(CodegenFrontTypeEnum.VUE3_SCHEMA.getType(), vue3SchemaTemplatePath("api/api.ts"),
vue3FilePath("api/${table.moduleName}/${table.businessName}/index.ts"))
// Vue3 vben 模版 // Vue3 vben 模版
.put(CodegenFrontTypeEnum.VUE3_VBEN.getType(), vue3VbenTemplatePath("views/data.ts"), .put(CodegenFrontTypeEnum.VUE3_VBEN.getType(), vue3VbenTemplatePath("views/data.ts"),
vue3FilePath("views/${table.moduleName}/${table.businessName}/${classNameVar}.data.ts")) vue3FilePath("views/${table.moduleName}/${table.businessName}/${classNameVar}.data.ts"))
@ -496,10 +487,6 @@ public class CodegenEngine {
"src/" + path; "src/" + path;
} }
private static String vue3SchemaTemplatePath(String path) {
return "codegen/vue3_schema/" + path + ".vm";
}
private static String vue3VbenTemplatePath(String path) { private static String vue3VbenTemplatePath(String path) {
return "codegen/vue3_vben/" + path + ".vm"; return "codegen/vue3_vben/" + path + ".vm";
} }

View File

@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.infra.enums.job.JobStatusEnum;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.quartz.SchedulerException; import org.quartz.SchedulerException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -91,13 +92,15 @@ public class JobServiceImpl implements JobService {
} }
private void validateJobHandlerExists(String handlerName) { private void validateJobHandlerExists(String handlerName) {
try {
Object handler = SpringUtil.getBean(handlerName); Object handler = SpringUtil.getBean(handlerName);
if (handler == null) { assert handler != null;
throw exception(JOB_HANDLER_BEAN_NOT_EXISTS);
}
if (!(handler instanceof JobHandler)) { if (!(handler instanceof JobHandler)) {
throw exception(JOB_HANDLER_BEAN_TYPE_ERROR); throw exception(JOB_HANDLER_BEAN_TYPE_ERROR);
} }
} catch (NoSuchBeanDefinitionException e) {
throw exception(JOB_HANDLER_BEAN_NOT_EXISTS);
}
} }
@Override @Override

View File

@ -1,46 +0,0 @@
import request from '@/config/axios'
#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}")
export interface ${simpleClassName}VO {
#foreach ($column in $columns)
#if ($column.createOperation || $column.updateOperation)
#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal")
${column.javaField}: number
#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime")
${column.javaField}: Date
#else
${column.javaField}: ${column.javaType.toLowerCase()}
#end
#end
#end
}
// 查询${table.classComment}列表
export const get${simpleClassName}Page = async (params) => {
return await request.get({ url: '${baseURL}/page', params })
}
// 查询${table.classComment}详情
export const get${simpleClassName} = async (id: number) => {
return await request.get({ url: '${baseURL}/get?id=' + id })
}
// 新增${table.classComment}
export const create${simpleClassName} = async (data: ${simpleClassName}VO) => {
return await request.post({ url: '${baseURL}/create', data })
}
// 修改${table.classComment}
export const update${simpleClassName} = async (data: ${simpleClassName}VO) => {
return await request.put({ url: '${baseURL}/update', data })
}
// 删除${table.classComment}
export const delete${simpleClassName} = async (id: number) => {
return await request.delete({ url: '${baseURL}/delete?id=' + id })
}
// 导出${table.classComment} Excel
export const export${simpleClassName}Api = async (params) => {
return await request.download({ url: '${baseURL}/export-excel', params })
}

View File

@ -1,124 +0,0 @@
import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'
// 表单校验
export const rules = reactive({
#foreach ($column in $columns)
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
#set($comment=$column.columnComment)
$column.javaField: [required],
#end
#end
})
// CrudSchema https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
#foreach($column in $columns)
#if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation)
#set ($dictType = $column.dictType)
#set ($javaField = $column.javaField)
#set ($javaType = $column.javaType)
{
label: '${column.columnComment}',
field: '${column.javaField}',
## ========= 字典部分 =========
#if ("" != $dictType)## 有数据字典
dictType: DICT_TYPE.$dictType.toUpperCase(),
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
dictClass: 'number',
#elseif ($javaType == "String")
dictClass: 'string',
#elseif ($javaType == "Boolean")
dictClass: 'boolean',
#end
#end
## ========= Table 表格部分 =========
#if (!$column.listOperationResult)
isTable: false,
#else
#if ($column.htmlType == "datetime")
formatter: dateFormatter,
#end
#end
## ========= Search 表格部分 =========
#if ($column.listOperation)
isSearch: true,
#if ($column.htmlType == "datetime")
search: {
component: 'DatePicker',
componentProps: {
valueFormat: 'YYYY-MM-DD HH:mm:ss',
type: 'daterange',
defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
}
},
#end
#end
## ========= Form 表单部分 =========
#if ((!$column.createOperation && !$column.updateOperation) || $column.primaryKey)
isForm: false,
#else
#if($column.htmlType == "imageUpload")## 图片上传
form: {
component: 'UploadImg'
},
#elseif($column.htmlType == "fileUpload")## 文件上传
form: {
component: 'UploadFile'
},
#elseif($column.htmlType == "editor")## 文本编辑器
form: {
component: 'Editor',
componentProps: {
valueHtml: '',
height: 200
}
},
#elseif($column.htmlType == "select")## 下拉框
form: {
component: 'SelectV2'
},
#elseif($column.htmlType == "checkbox")## 多选框
form: {
component: 'Checkbox'
},
#elseif($column.htmlType == "radio")## 单选框
form: {
component: 'Radio'
},
#elseif($column.htmlType == "datetime")## 时间框
form: {
component: 'DatePicker',
componentProps: {
type: 'datetime',
valueFormat: 'x'
}
},
#elseif($column.htmlType == "textarea")## 文本框
form: {
component: 'Input',
componentProps: {
type: 'textarea',
rows: 4
},
colProps: {
span: 24
}
},
#elseif(${javaType.toLowerCase()} == "long" || ${javaType.toLowerCase()} == "integer")## 文本框
form: {
component: 'InputNumber',
value: 0
},
#end
#end
},
#end
#end
{
label: '操作',
field: 'action',
isForm: false
}
])
export const { allSchemas } = useCrudSchemas(crudSchemas)

View File

@ -1,65 +0,0 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible">
<Form ref="formRef" :schema="allSchemas.formSchema" :rules="rules" v-loading="formLoading" />
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
<el-button @click="dialogVisible = false">取 消</el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
import { rules, allSchemas } from './${classNameVar}.data'
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中1修改时的数据加载2提交的按钮禁用
const formType = ref('') // 表单的类型create - 新增update - 修改
const formRef = ref() // 表单 Ref
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
// 修改时,设置数据
if (id) {
formLoading.value = true
try {
const data = await ${simpleClassName}Api.get${simpleClassName}(id)
formRef.value.setValues(data)
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
const submitForm = async () => {
// 校验表单
if (!formRef) return
const valid = await formRef.value.getElFormRef().validate()
if (!valid) return
// 提交请求
formLoading.value = true
try {
const data = formRef.value.formModel as ${simpleClassName}Api.${simpleClassName}VO
if (formType.value === 'create') {
await ${simpleClassName}Api.create${simpleClassName}(data)
message.success(t('common.createSuccess'))
} else {
await ${simpleClassName}Api.update${simpleClassName}(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
// 发送操作成功的事件
emit('success')
} finally {
formLoading.value = false
}
}
</script>

View File

@ -1,85 +0,0 @@
<template>
<!-- 搜索工作栏 -->
<ContentWrap>
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams">
<!-- 新增等操作按钮 -->
<template #actionMore>
<el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['${permissionPrefix}:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 新增
</el-button>
</template>
</Search>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<Table
:columns="allSchemas.tableColumns"
:data="tableObject.tableList"
:loading="tableObject.loading"
:pagination="{
total: tableObject.total
}"
v-model:pageSize="tableObject.pageSize"
v-model:currentPage="tableObject.currentPage"
>
<template #action="{ row }">
<el-button
link
type="primary"
@click="openForm('update', row.id)"
v-hasPermi="['${permissionPrefix}:update']"
>
编辑
</el-button>
<el-button
link
type="danger"
v-hasPermi="['${permissionPrefix}:delete']"
@click="handleDelete(row.id)"
>
删除
</el-button>
</template>
</Table>
</ContentWrap>
<!-- 表单弹窗:添加/修改 -->
<${simpleClassName}Form ref="formRef" @success="getList" />
</template>
<script setup lang="ts" name="${table.className}">
import { allSchemas } from './${classNameVar}.data'
import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'
import ${simpleClassName}Form from './${simpleClassName}Form.vue'
// tableObject表格的属性对象可获得分页大小、条数等属性
// tableMethods表格的操作对象可进行获得分页、删除记录等操作
// 详细可见https://doc.iocoder.cn/vue3/crud-schema/
const { tableObject, tableMethods } = useTable({
getListApi: ${simpleClassName}Api.get${simpleClassName}Page, // 分页接口
delListApi: ${simpleClassName}Api.delete${simpleClassName} // 删除接口
})
// 获得表格的各种操作
const { getList, setSearchParams } = tableMethods
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = (id: number) => {
tableMethods.delList(id, false)
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>

View File

@ -42,9 +42,17 @@ export const searchFormSchema: FormSchema[] = [
#foreach($column in $columns) #foreach($column in $columns)
#if ($column.listOperation) #if ($column.listOperation)
#set ($dictType=$column.dictType) #set ($dictType=$column.dictType)
#set ($javaType = $column.javaType)
#set ($javaField = $column.javaField) #set ($javaField = $column.javaField)
#set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#set ($comment=$column.columnComment) #set ($comment=$column.columnComment)
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
#set ($dictMethod = "number")
#elseif ($javaType == "String")
#set ($dictMethod = "string")
#elseif ($javaType == "Boolean")
#set ($dictMethod = "boolean")
#end
{ {
label: '${comment}', label: '${comment}',
field: '${javaField}', field: '${javaField}',
@ -54,16 +62,16 @@ export const searchFormSchema: FormSchema[] = [
component: 'Select', component: 'Select',
componentProps: { componentProps: {
#if ("" != $dictType)## 设置了 dictType 数据字典的情况 #if ("" != $dictType)## 设置了 dictType 数据字典的情况
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase()), options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
#else## 未设置 dictType 数据字典的情况 #else## 未设置 dictType 数据字典的情况
options: [], options: [],
#end #end
}, },
#elseif ($column.htmlType == "radio") #elseif ($column.htmlType == "radio")
component: 'Radio', component: 'RadioButtonGroup',
componentProps: { componentProps: {
#if ("" != $dictType)## 设置了 dictType 数据字典的情况 #if ("" != $dictType)## 设置了 dictType 数据字典的情况
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase()), options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
#else## 未设置 dictType 数据字典的情况 #else## 未设置 dictType 数据字典的情况
options: [], options: [],
#end #end
@ -87,9 +95,17 @@ export const createFormSchema: FormSchema[] = [
#foreach($column in $columns) #foreach($column in $columns)
#if ($column.createOperation) #if ($column.createOperation)
#set ($dictType = $column.dictType) #set ($dictType = $column.dictType)
#set ($javaType = $column.javaType)
#set ($javaField = $column.javaField) #set ($javaField = $column.javaField)
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#set ($comment = $column.columnComment) #set ($comment = $column.columnComment)
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
#set ($dictMethod = "number")
#elseif ($javaType == "String")
#set ($dictMethod = "string")
#elseif ($javaType == "Boolean")
#set ($dictMethod = "boolean")
#end
#if (!$column.primaryKey)## 忽略主键,不用在表单里 #if (!$column.primaryKey)## 忽略主键,不用在表单里
{ {
label: '${comment}', label: '${comment}',
@ -117,7 +133,7 @@ export const createFormSchema: FormSchema[] = [
component: 'Select', component: 'Select',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
#else##没数据字典 #else##没数据字典
options:[], options:[],
#end #end
@ -126,7 +142,7 @@ export const createFormSchema: FormSchema[] = [
component: 'Checkbox', component: 'Checkbox',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
#else##没数据字典 #else##没数据字典
options:[], options:[],
#end #end
@ -135,7 +151,7 @@ export const createFormSchema: FormSchema[] = [
component: 'RadioButtonGroup', component: 'RadioButtonGroup',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
#else##没数据字典 #else##没数据字典
options:[], options:[],
#end #end
@ -166,9 +182,17 @@ export const updateFormSchema: FormSchema[] = [
#foreach($column in $columns) #foreach($column in $columns)
#if ($column.updateOperation) #if ($column.updateOperation)
#set ($dictType = $column.dictType) #set ($dictType = $column.dictType)
#set ($javaType = $column.javaType)
#set ($javaField = $column.javaField) #set ($javaField = $column.javaField)
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#set ($comment = $column.columnComment) #set ($comment = $column.columnComment)
#if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short")
#set ($dictMethod = "number")
#elseif ($javaType == "String")
#set ($dictMethod = "string")
#elseif ($javaType == "Boolean")
#set ($dictMethod = "boolean")
#end
#if (!$column.primaryKey)## 忽略主键,不用在表单里 #if (!$column.primaryKey)## 忽略主键,不用在表单里
{ {
label: '${comment}', label: '${comment}',
@ -196,7 +220,7 @@ export const updateFormSchema: FormSchema[] = [
component: 'Select', component: 'Select',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
#else##没数据字典 #else##没数据字典
options:[], options:[],
#end #end
@ -205,7 +229,7 @@ export const updateFormSchema: FormSchema[] = [
component: 'Checkbox', component: 'Checkbox',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
#else##没数据字典 #else##没数据字典
options:[], options:[],
#end #end
@ -214,7 +238,7 @@ export const updateFormSchema: FormSchema[] = [
component: 'RadioButtonGroup', component: 'RadioButtonGroup',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number'), options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), '$dictMethod'),
#else##没数据字典 #else##没数据字典
options:[], options:[],
#end #end

View File

@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.promotion.api.combination;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
/** /**
@ -33,13 +33,13 @@ public interface CombinationRecordApi {
CombinationRecordCreateRespDTO createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); CombinationRecordCreateRespDTO createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
/** /**
* 查询拼团记录是否成功 * 基于订单编号查询拼团记录
* *
* @param userId 用户编号 * @param userId 用户编号
* @param orderId 订单编号 * @param orderId 订单编号
* @return 拼团是否成功 * @return 拼团记录
*/ */
boolean isCombinationRecordSuccess(Long userId, Long orderId); CombinationRecordRespDTO getCombinationRecordByOrderId(Long userId, Long orderId);
/** /**
* 下单前校验是否满足拼团活动条件 * 下单前校验是否满足拼团活动条件

View File

@ -0,0 +1,110 @@
package cn.iocoder.yudao.module.promotion.api.combination.dto;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 拼团记录 Response DTO
*
* @author 芋道源码
*/
@Data
public class CombinationRecordRespDTO {
/**
* 编号主键自增
*/
private Long id;
/**
* 拼团活动编号
*
* 关联 CombinationActivityDO id 字段
*/
private Long activityId;
/**
* 拼团商品单价
*
* 冗余 CombinationProductDO combinationPrice 字段
*/
private Integer combinationPrice;
/**
* SPU 编号
*/
private Long spuId;
/**
* 商品名字
*/
private String spuName;
/**
* 商品图片
*/
private String picUrl;
/**
* SKU 编号
*/
private Long skuId;
/**
* 购买的商品数量
*/
private Integer count;
/**
* 用户编号
*/
private Long userId;
/**
* 用户昵称
*/
private String nickname;
/**
* 用户头像
*/
private String avatar;
/**
* 团长编号
*/
private Long headId;
/**
* 开团状态
*
* 关联 {@link CombinationRecordStatusEnum}
*/
private Integer status;
/**
* 订单编号
*/
private Long orderId;
/**
* 开团需要人数
*
* 关联 CombinationActivityDO userSize 字段
*/
private Integer userSize;
/**
* 已加入拼团人数
*/
private Integer userCount;
/**
* 是否虚拟成团
*/
private Boolean virtualGroup;
/**
* 过期时间
*/
private LocalDateTime expireTime;
/**
* 开始时间 (订单付款后开始的时间)
*/
private LocalDateTime startTime;
/**
* 结束时间成团时间/失败时间
*/
private LocalDateTime endTime;
}

View File

@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.api.coupon;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import java.util.List; import java.util.List;
@ -15,6 +14,15 @@ import java.util.Map;
*/ */
public interface CouponApi { public interface CouponApi {
/**
* 获得用户的优惠劵列表
*
* @param userId 用户编号
* @param status 优惠劵状态
* @return 优惠劵列表
*/
List<CouponRespDTO> getCouponListByUserId(Long userId, Integer status);
/** /**
* 使用优惠劵 * 使用优惠劵
* *
@ -29,14 +37,6 @@ public interface CouponApi {
*/ */
void returnUsedCoupon(Long id); void returnUsedCoupon(Long id);
/**
* 校验优惠劵
*
* @param validReqDTO 校验请求
* @return 优惠劵
*/
CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO);
/** /**
* 管理员给指定用户批量发送优惠券 * 管理员给指定用户批量发送优惠券
* *

View File

@ -1,27 +0,0 @@
package cn.iocoder.yudao.module.promotion.api.coupon.dto;
import lombok.Data;
import jakarta.validation.constraints.NotNull;
/**
* 优惠劵使用 Request DTO
*
* @author 芋道源码
*/
@Data
public class CouponValidReqDTO {
/**
* 优惠劵编号
*/
@NotNull(message = "优惠劵编号不能为空")
private Long id;
/**
* 用户编号
*/
@NotNull(message = "用户编号不能为空")
private Long userId;
}

View File

@ -21,8 +21,6 @@ public interface ErrorCodeConstants {
ErrorCode BANNER_NOT_EXISTS = new ErrorCode(1_013_002_000, "Banner 不存在"); ErrorCode BANNER_NOT_EXISTS = new ErrorCode(1_013_002_000, "Banner 不存在");
// ========== Coupon 相关 1-013-003-000 ============ // ========== Coupon 相关 1-013-003-000 ============
ErrorCode COUPON_NO_MATCH_SPU = new ErrorCode(1_013_003_000, "优惠劵没有可使用的商品!");
ErrorCode COUPON_NO_MATCH_MIN_PRICE = new ErrorCode(1_013_003_001, "所结算的商品中未满足使用的金额");
// ========== 优惠劵模板 1-013-004-000 ========== // ========== 优惠劵模板 1-013-004-000 ==========
ErrorCode COUPON_TEMPLATE_NOT_EXISTS = new ErrorCode(1_013_004_000, "优惠劵模板不存在"); ErrorCode COUPON_TEMPLATE_NOT_EXISTS = new ErrorCode(1_013_004_000, "优惠劵模板不存在");

View File

@ -1,19 +1,17 @@
package cn.iocoder.yudao.module.promotion.api.combination; package cn.iocoder.yudao.module.promotion.api.combination;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO;
import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_RECORD_NOT_EXISTS;
/** /**
* 拼团活动 API 实现类 * 拼团活动 API 实现类
* *
@ -37,12 +35,9 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
} }
@Override @Override
public boolean isCombinationRecordSuccess(Long userId, Long orderId) { public CombinationRecordRespDTO getCombinationRecordByOrderId(Long userId, Long orderId) {
CombinationRecordDO record = combinationRecordService.getCombinationRecord(userId, orderId); CombinationRecordDO record = combinationRecordService.getCombinationRecord(userId, orderId);
if (record == null) { return BeanUtils.toBean(record, CombinationRecordRespDTO.class);
throw exception(COMBINATION_RECORD_NOT_EXISTS);
}
return CombinationRecordStatusEnum.isSuccess(record.getStatus());
} }
@Override @Override

View File

@ -1,11 +1,9 @@
package cn.iocoder.yudao.module.promotion.api.coupon; package cn.iocoder.yudao.module.promotion.api.coupon;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO;
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 cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -26,6 +24,11 @@ public class CouponApiImpl implements CouponApi {
@Resource @Resource
private CouponService couponService; private CouponService couponService;
@Override
public List<CouponRespDTO> getCouponListByUserId(Long userId, Integer status) {
return BeanUtils.toBean(couponService.getCouponList(userId, status), CouponRespDTO.class);
}
@Override @Override
public void useCoupon(CouponUseReqDTO useReqDTO) { public void useCoupon(CouponUseReqDTO useReqDTO) {
couponService.useCoupon(useReqDTO.getId(), useReqDTO.getUserId(), couponService.useCoupon(useReqDTO.getId(), useReqDTO.getUserId(),
@ -37,12 +40,6 @@ public class CouponApiImpl implements CouponApi {
couponService.returnUsedCoupon(id); couponService.returnUsedCoupon(id);
} }
@Override
public CouponRespDTO validateCoupon(CouponValidReqDTO validReqDTO) {
CouponDO coupon = couponService.validCoupon(validReqDTO.getId(), validReqDTO.getUserId());
return CouponConvert.INSTANCE.convert(coupon);
}
@Override @Override
public List<Long> takeCouponsByAdmin(Map<Long, Integer> giveCoupons, Long userId) { public List<Long> takeCouponsByAdmin(Map<Long, Integer> giveCoupons, Long userId) {
return couponService.takeCouponsByAdmin(giveCoupons, userId); return couponService.takeCouponsByAdmin(giveCoupons, userId);

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.promotion.controller.admin.combination; package cn.iocoder.yudao.module.promotion.controller.admin.combination;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
@ -16,18 +17,20 @@ import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordSe
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource; import java.util.Collections;
import jakarta.validation.Valid;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static cn.hutool.core.collection.CollectionUtil.newArrayList; import static cn.hutool.core.collection.CollectionUtil.newArrayList;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@Tag(name = "管理后台 - 拼团活动") @Tag(name = "管理后台 - 拼团活动")
@ -87,6 +90,23 @@ public class CombinationActivityController {
return success(CombinationActivityConvert.INSTANCE.convert(activity, products)); return success(CombinationActivityConvert.INSTANCE.convert(activity, products));
} }
@GetMapping("/list-by-ids")
@Operation(summary = "获得拼团活动列表,基于活动编号数组")
@Parameter(name = "ids", description = "活动编号数组", required = true, example = "[1024, 1025]")
public CommonResult<List<CombinationActivityRespVO>> getCombinationActivityListByIds(@RequestParam("ids") List<Long> ids) {
// 1. 获得开启的活动列表
List<CombinationActivityDO> activityList = combinationActivityService.getCombinationActivityListByIds(ids);
activityList.removeIf(activity -> CommonStatusEnum.isDisable(activity.getStatus()));
if (CollUtil.isEmpty(activityList)) {
return success(Collections.emptyList());
}
// 2. 拼接返回
List<CombinationProductDO> productList = combinationActivityService.getCombinationProductListByActivityIds(
convertList(activityList, CombinationActivityDO::getId));
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(convertList(activityList, CombinationActivityDO::getSpuId));
return success(CombinationActivityConvert.INSTANCE.convertList(activityList, productList, spuList));
}
@GetMapping("/page") @GetMapping("/page")
@Operation(summary = "获得拼团活动分页") @Operation(summary = "获得拼团活动分页")
@PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')") @PreAuthorize("@ss.hasPermission('promotion:combination-activity:query')")

View File

@ -27,4 +27,14 @@ public class CombinationActivityRespVO extends CombinationActivityBaseVO {
@Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "拼团商品", requiredMode = Schema.RequiredMode.REQUIRED)
private List<CombinationProductRespVO> products; private List<CombinationProductRespVO> products;
@Schema(description = "商品 SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "一个白菜")
private String spuName; // SPU name 读取
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "4096")
private String picUrl; // SPU picUrl 读取
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
private Integer marketPrice; // SPU marketPrice 读取
@Schema(description = "拼团金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer combinationPrice; // products 获取最小 price 读取
} }

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.promotion.controller.admin.seckill; package cn.iocoder.yudao.module.promotion.controller.admin.seckill;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi;
@ -13,15 +14,17 @@ import cn.iocoder.yudao.module.promotion.service.seckill.SeckillActivityService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource; import java.util.Collections;
import jakarta.validation.Valid;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@Tag(name = "管理后台 - 秒杀活动") @Tag(name = "管理后台 - 秒杀活动")
@ -89,11 +92,28 @@ public class SeckillActivityController {
} }
// 拼接数据 // 拼接数据
List<SeckillProductDO> products = seckillActivityService.getSeckillProductListByActivityId( List<SeckillProductDO> products = seckillActivityService.getSeckillProductListByActivityIds(
convertSet(pageResult.getList(), SeckillActivityDO::getId)); convertSet(pageResult.getList(), SeckillActivityDO::getId));
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList( List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(
convertSet(pageResult.getList(), SeckillActivityDO::getSpuId)); convertSet(pageResult.getList(), SeckillActivityDO::getSpuId));
return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, products, spuList)); return success(SeckillActivityConvert.INSTANCE.convertPage(pageResult, products, spuList));
} }
@GetMapping("/list-by-ids")
@Operation(summary = "获得秒杀活动列表,基于活动编号数组")
@Parameter(name = "ids", description = "活动编号数组", required = true, example = "[1024, 1025]")
public CommonResult<List<SeckillActivityRespVO>> getCombinationActivityListByIds(@RequestParam("ids") List<Long> ids) {
// 1. 获得开启的活动列表
List<SeckillActivityDO> activityList = seckillActivityService.getSeckillActivityListByIds(ids);
activityList.removeIf(activity -> CommonStatusEnum.isDisable(activity.getStatus()));
if (CollUtil.isEmpty(activityList)) {
return success(Collections.emptyList());
}
// 2. 拼接返回
List<SeckillProductDO> productList = seckillActivityService.getSeckillProductListByActivityIds(
convertList(activityList, SeckillActivityDO::getId));
List<ProductSpuRespDTO> spuList = productSpuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId));
return success(SeckillActivityConvert.INSTANCE.convertList(activityList, productList, spuList));
}
} }

View File

@ -54,4 +54,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO {
example = "50") example = "50")
private Integer marketPrice; private Integer marketPrice;
@Schema(description = "拼团金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer seckillPrice; // products 获取最小 price 读取
} }

View File

@ -14,24 +14,20 @@ import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivity
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO;
import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService; import cn.iocoder.yudao.module.promotion.service.combination.CombinationActivityService;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import jakarta.annotation.Resource;
import java.time.Duration;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
@Tag(name = "用户 APP - 拼团活动") @Tag(name = "用户 APP - 拼团活动")
@ -40,45 +36,12 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
@Validated @Validated
public class AppCombinationActivityController { public class AppCombinationActivityController {
/**
* {@link AppCombinationActivityRespVO} 缓存通过它异步刷新 {@link #getCombinationActivityList0(Integer)} 所要的首页数据
*/
private final LoadingCache<Integer, List<AppCombinationActivityRespVO>> combinationActivityListCache = buildAsyncReloadingCache(Duration.ofSeconds(10L),
new CacheLoader<Integer, List<AppCombinationActivityRespVO>>() {
@Override
public List<AppCombinationActivityRespVO> load(Integer count) {
return getCombinationActivityList0(count);
}
});
@Resource @Resource
private CombinationActivityService activityService; private CombinationActivityService activityService;
@Resource @Resource
private ProductSpuApi spuApi; private ProductSpuApi spuApi;
@GetMapping("/list")
@Operation(summary = "获得拼团活动列表", description = "用于小程序首页")
@Parameter(name = "count", description = "需要展示的数量", example = "6")
public CommonResult<List<AppCombinationActivityRespVO>> getCombinationActivityList(
@RequestParam(name = "count", defaultValue = "6") Integer count) {
return success(combinationActivityListCache.getUnchecked(count));
}
private List<AppCombinationActivityRespVO> getCombinationActivityList0(Integer count) {
List<CombinationActivityDO> activityList = activityService.getCombinationActivityListByCount(count);
if (CollUtil.isEmpty(activityList)) {
return Collections.emptyList();
}
// 拼接返回
List<CombinationProductDO> productList = activityService.getCombinationProductListByActivityIds(
convertList(activityList, CombinationActivityDO::getId));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, CombinationActivityDO::getSpuId));
return CombinationActivityConvert.INSTANCE.convertAppList(activityList, productList, spuList);
}
@GetMapping("/page") @GetMapping("/page")
@Operation(summary = "获得拼团活动分页") @Operation(summary = "获得拼团活动分页")
public CommonResult<PageResult<AppCombinationActivityRespVO>> getCombinationActivityPage(PageParam pageParam) { public CommonResult<PageResult<AppCombinationActivityRespVO>> getCombinationActivityPage(PageParam pageParam) {
@ -93,6 +56,23 @@ public class AppCombinationActivityController {
return success(CombinationActivityConvert.INSTANCE.convertAppPage(pageResult, productList, spuList)); return success(CombinationActivityConvert.INSTANCE.convertAppPage(pageResult, productList, spuList));
} }
@GetMapping("/list-by-ids")
@Operation(summary = "获得拼团活动列表,基于活动编号数组")
@Parameter(name = "ids", description = "活动编号数组", required = true, example = "[1024, 1025]")
public CommonResult<List<AppCombinationActivityRespVO>> getCombinationActivityListByIds(@RequestParam("ids") List<Long> ids) {
// 1. 获得开启的活动列表
List<CombinationActivityDO> activityList = activityService.getCombinationActivityListByIds(ids);
activityList.removeIf(activity -> CommonStatusEnum.isDisable(activity.getStatus()));
if (CollUtil.isEmpty(activityList)) {
return success(Collections.emptyList());
}
// 2. 拼接返回
List<CombinationProductDO> productList = activityService.getCombinationProductListByActivityIds(
convertList(activityList, CombinationActivityDO::getId));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, CombinationActivityDO::getSpuId));
return success(CombinationActivityConvert.INSTANCE.convertAppList(activityList, productList, spuList));
}
@GetMapping("/get-detail") @GetMapping("/get-detail")
@Operation(summary = "获得拼团活动明细") @Operation(summary = "获得拼团活动明细")
@Parameter(name = "id", description = "活动编号", required = true, example = "1024") @Parameter(name = "id", description = "活动编号", required = true, example = "1024")

View File

@ -19,15 +19,14 @@ public class AppCombinationActivityRespVO {
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long spuId; private Long spuId;
@Schema(description = "商品 SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "一个白菜")
private String spuName; // SPU name 读取
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "4096") @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "4096")
// SPU picUrl 读取 private String picUrl; // SPU picUrl 读取
private String picUrl;
@Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50") @Schema(description = "商品市场价,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
// SPU marketPrice 读取 private Integer marketPrice; // SPU marketPrice 读取
private Integer marketPrice;
@Schema(description = "拼团金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") @Schema(description = "拼团金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer combinationPrice; private Integer combinationPrice; // products 获取最小 price 读取
} }

View File

@ -5,7 +5,9 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.*; import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponTakeReqVO;
import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; 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.dal.dataobject.coupon.CouponDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO;
@ -15,13 +17,12 @@ import cn.iocoder.yudao.module.promotion.service.coupon.CouponTemplateService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -56,14 +57,6 @@ public class AppCouponController {
return success(canTakeAgain); return success(canTakeAgain);
} }
@GetMapping("/match-list")
@Operation(summary = "获得匹配指定商品的优惠劵列表", description = "用于下单页,展示优惠劵列表")
public CommonResult<List<AppCouponMatchRespVO>> getMatchCouponList(AppCouponMatchReqVO matchReqVO) {
// todo: 优化优惠金额倒序
List<AppCouponMatchRespVO> list = couponService.getMatchCouponList(getLoginUserId(), matchReqVO);
return success(list);
}
@GetMapping("/page") @GetMapping("/page")
@Operation(summary = "我的优惠劵列表") @Operation(summary = "我的优惠劵列表")
@PreAuthenticated @PreAuthenticated

View File

@ -1,30 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;
@Schema(description = "用户 App - 优惠劵的匹配 Request VO")
@Data
public class AppCouponMatchReqVO {
@Schema(description = "商品金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@NotNull(message = "商品金额不能为空")
private Integer price;
@Schema(description = "商品 SPU 编号的数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]")
@NotEmpty(message = "商品 SPU 编号不能为空")
private List<Long> spuIds;
@Schema(description = "商品 SKU 编号的数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]")
@NotEmpty(message = "商品 SKU 编号不能为空")
private List<Long> skuIds;
@Schema(description = "分类编号的数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "[10, 20]")
@NotEmpty(message = "分类编号不能为空")
private List<Long> categoryIds;
}

View File

@ -1,16 +0,0 @@
package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "用户 App - 优惠劵 Response VO")
@Data
public class AppCouponMatchRespVO extends AppCouponRespVO {
@Schema(description = "是否匹配", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean match;
@Schema(description = "匹配条件的提示", example = "所结算商品没有符合条件的商品")
private String description;
}

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import jakarta.validation.constraints.Min;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -42,7 +41,6 @@ public class AppCouponRespVO {
private Integer discountPercent; private Integer discountPercent;
@Schema(description = "优惠金额", example = "10") @Schema(description = "优惠金额", example = "10")
@Min(value = 0, message = "优惠金额需要大于等于 0")
private Integer discountPrice; private Integer discountPrice;
@Schema(description = "折扣上限", example = "100") // 单位仅在 discountType PERCENT 使用 @Schema(description = "折扣上限", example = "100") // 单位仅在 discountType PERCENT 使用

View File

@ -23,6 +23,7 @@ import com.google.common.cache.LoadingCache;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -30,11 +31,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import jakarta.annotation.Resource;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.Collections;
import java.util.List; import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@ -86,7 +87,7 @@ public class AppSeckillActivityController {
// 2.1 查询满足当前阶段的活动 // 2.1 查询满足当前阶段的活动
List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIdAndStatus(config.getId(), CommonStatusEnum.ENABLE.getStatus()); List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByConfigIdAndStatus(config.getId(), CommonStatusEnum.ENABLE.getStatus());
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityId( List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityIds(
convertList(activityList, SeckillActivityDO::getId)); convertList(activityList, SeckillActivityDO::getId));
// 2.2 获取 spu 信息 // 2.2 获取 spu 信息
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId)); List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId));
@ -101,7 +102,7 @@ public class AppSeckillActivityController {
if (CollUtil.isEmpty(pageResult.getList())) { if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty(pageResult.getTotal())); return success(PageResult.empty(pageResult.getTotal()));
} }
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityId( List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityIds(
convertList(pageResult.getList(), SeckillActivityDO::getId)); convertList(pageResult.getList(), SeckillActivityDO::getId));
// 2. 拼接数据 // 2. 拼接数据
@ -149,4 +150,21 @@ public class AppSeckillActivityController {
return success(SeckillActivityConvert.INSTANCE.convert3(activity, productList, startTime, endTime)); return success(SeckillActivityConvert.INSTANCE.convert3(activity, productList, startTime, endTime));
} }
@GetMapping("/list-by-ids")
@Operation(summary = "获得拼团活动列表,基于活动编号数组")
@Parameter(name = "ids", description = "活动编号数组", required = true, example = "[1024, 1025]")
public CommonResult<List<AppSeckillActivityRespVO>> getCombinationActivityListByIds(@RequestParam("ids") List<Long> ids) {
// 1. 获得开启的活动列表
List<SeckillActivityDO> activityList = activityService.getSeckillActivityListByIds(ids);
activityList.removeIf(activity -> CommonStatusEnum.isDisable(activity.getStatus()));
if (CollUtil.isEmpty(activityList)) {
return success(Collections.emptyList());
}
// 2. 拼接返回
List<SeckillProductDO> productList = activityService.getSeckillProductListByActivityIds(
convertList(activityList, SeckillActivityDO::getId));
List<ProductSpuRespDTO> spuList = spuApi.getSpuList(convertList(activityList, SeckillActivityDO::getSpuId));
return success(SeckillActivityConvert.INSTANCE.convertAppList(activityList, productList, spuList));
}
} }

View File

@ -16,6 +16,9 @@ public class AppSeckillActivityRespVO {
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048") @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long spuId; private Long spuId;
@Schema(description = "商品 SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "一个白菜")
private String spuName; // SPU name 读取
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // SPU picUrl 读取 @Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, // SPU picUrl 读取
example = "https://www.iocoder.cn/xx.png") example = "https://www.iocoder.cn/xx.png")
private String picUrl; private String picUrl;

View File

@ -4,6 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
@ -127,40 +128,42 @@ public interface CombinationActivityConvert {
.setSpuName(spu.getName()).setPicUrl(sku.getPicUrl()); .setSpuName(spu.getName()).setPicUrl(sku.getPicUrl());
} }
List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list); default List<CombinationActivityRespVO> convertList(List<CombinationActivityDO> list,
default List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list,
List<CombinationProductDO> productList, List<CombinationProductDO> productList,
List<ProductSpuRespDTO> spuList) { List<ProductSpuRespDTO> spuList) {
List<AppCombinationActivityRespVO> activityList = convertAppList(list); List<CombinationActivityRespVO> activityList = BeanUtils.toBean(list, CombinationActivityRespVO.class);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId); Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
Map<Long, List<CombinationProductDO>> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId); Map<Long, List<CombinationProductDO>> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId);
return CollectionUtils.convertList(activityList, item -> { return CollectionUtils.convertList(activityList, item -> {
// 设置 product 信息 // 设置 product 信息
item.setCombinationPrice(getMinValue(productMap.get(item.getId()), CombinationProductDO::getCombinationPrice)); item.setCombinationPrice(getMinValue(productMap.get(item.getId()), CombinationProductDO::getCombinationPrice));
// 设置 SPU 信息 // 设置 SPU 信息
findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice())); findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName())
.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
return item; return item;
}); });
} }
PageResult<AppCombinationActivityRespVO> convertAppPage(PageResult<CombinationActivityDO> result); default List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list,
List<CombinationProductDO> productList,
List<ProductSpuRespDTO> spuList) {
List<AppCombinationActivityRespVO> activityList = BeanUtils.toBean(list, AppCombinationActivityRespVO.class);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
Map<Long, List<CombinationProductDO>> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId);
return CollectionUtils.convertList(activityList, item -> {
// 设置 product 信息
item.setCombinationPrice(getMinValue(productMap.get(item.getId()), CombinationProductDO::getCombinationPrice));
// 设置 SPU 信息
findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName())
.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
return item;
});
}
default PageResult<AppCombinationActivityRespVO> convertAppPage(PageResult<CombinationActivityDO> result, default PageResult<AppCombinationActivityRespVO> convertAppPage(PageResult<CombinationActivityDO> result,
List<CombinationProductDO> productList, List<CombinationProductDO> productList,
List<ProductSpuRespDTO> spuList) { List<ProductSpuRespDTO> spuList) {
PageResult<AppCombinationActivityRespVO> appPage = convertAppPage(result); return new PageResult<>(convertAppList(result.getList(), productList, spuList), result.getTotal());
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
Map<Long, List<CombinationProductDO>> productMap = convertMultiMap(productList, CombinationProductDO::getActivityId);
List<AppCombinationActivityRespVO> list = CollectionUtils.convertList(appPage.getList(), item -> {
// 设置 product 信息
item.setCombinationPrice(getMinValue(productMap.get(item.getId()), CombinationProductDO::getCombinationPrice));
// 设置 SPU 信息
findAndThen(spuMap, item.getSpuId(), spu -> item.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
return item;
});
appPage.setList(list);
return appPage;
} }
AppCombinationActivityDetailRespVO convert2(CombinationActivityDO combinationActivity); AppCombinationActivityDetailRespVO convert2(CombinationActivityDO combinationActivity);

View File

@ -4,9 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageItemRespVO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageItemRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchRespVO;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponPageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
@ -16,7 +14,6 @@ import org.mapstruct.factory.Mappers;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection; import java.util.Collection;
import java.util.List;
/** /**
* 优惠劵 Convert * 优惠劵 Convert

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.convert.seckill;
import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO;
import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillValidateJoinRespDTO; import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillValidateJoinRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
@ -87,6 +88,38 @@ public interface SeckillActivityConvert {
return CollectionUtils.convertList(products, item -> convert(activity, item).setActivityStatus(activity.getStatus())); return CollectionUtils.convertList(products, item -> convert(activity, item).setActivityStatus(activity.getStatus()));
} }
default List<SeckillActivityRespVO> convertList(List<SeckillActivityDO> list,
List<SeckillProductDO> productList,
List<ProductSpuRespDTO> spuList) {
List<SeckillActivityRespVO> activityList = BeanUtils.toBean(list, SeckillActivityRespVO.class);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
Map<Long, List<SeckillProductDO>> productMap = convertMultiMap(productList, SeckillProductDO::getActivityId);
return CollectionUtils.convertList(activityList, item -> {
// 设置 product 信息
item.setSeckillPrice(getMinValue(productMap.get(item.getId()), SeckillProductDO::getSeckillPrice));
// 设置 SPU 信息
findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName())
.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
return item;
});
}
default List<AppSeckillActivityRespVO> convertAppList(List<SeckillActivityDO> list,
List<SeckillProductDO> productList,
List<ProductSpuRespDTO> spuList) {
List<AppSeckillActivityRespVO> activityList = BeanUtils.toBean(list, AppSeckillActivityRespVO.class);
Map<Long, ProductSpuRespDTO> spuMap = convertMap(spuList, ProductSpuRespDTO::getId);
Map<Long, List<SeckillProductDO>> productMap = convertMultiMap(productList, SeckillProductDO::getActivityId);
return CollectionUtils.convertList(activityList, item -> {
// 设置 product 信息
item.setSeckillPrice(getMinValue(productMap.get(item.getId()), SeckillProductDO::getSeckillPrice));
// 设置 SPU 信息
findAndThen(spuMap, item.getSpuId(), spu -> item.setSpuName(spu.getName())
.setPicUrl(spu.getPicUrl()).setMarketPrice(spu.getMarketPrice()));
return item;
});
}
List<SeckillProductRespVO> convertList2(List<SeckillProductDO> list); List<SeckillProductRespVO> convertList2(List<SeckillProductDO> list);
List<AppSeckillActivityRespVO> convertList3(List<SeckillActivityDO> activityList); List<AppSeckillActivityRespVO> convertList3(List<SeckillActivityDO> activityList);

View File

@ -1,13 +1,11 @@
package cn.iocoder.yudao.module.promotion.dal.mysql.coupon; package cn.iocoder.yudao.module.promotion.dal.mysql.coupon;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.yulichang.toolkit.MPJWrappers; import com.github.yulichang.toolkit.MPJWrappers;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -16,8 +14,6 @@ import java.time.LocalDateTime;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;

View File

@ -100,14 +100,6 @@ public interface CombinationActivityService {
*/ */
List<CombinationActivityDO> getCombinationActivityListByIds(Collection<Long> ids); List<CombinationActivityDO> getCombinationActivityListByIds(Collection<Long> ids);
/**
* 获取正在进行的活动分页数据
*
* @param count 需要的数量
* @return 拼团活动分页
*/
List<CombinationActivityDO> getCombinationActivityListByCount(Integer count);
/** /**
* 获取正在进行的活动分页数据 * 获取正在进行的活动分页数据
* *

View File

@ -225,11 +225,6 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic
return combinationActivityMapper.selectList(CombinationActivityDO::getId, ids); return combinationActivityMapper.selectList(CombinationActivityDO::getId, ids);
} }
@Override
public List<CombinationActivityDO> getCombinationActivityListByCount(Integer count) {
return combinationActivityMapper.selectListByStatus(CommonStatusEnum.ENABLE.getStatus(), count);
}
@Override @Override
public PageResult<CombinationActivityDO> getCombinationActivityPage(PageParam pageParam) { public PageResult<CombinationActivityDO> getCombinationActivityPage(PageParam pageParam) {
return combinationActivityMapper.selectPage(pageParam, CommonStatusEnum.ENABLE.getStatus()); return combinationActivityMapper.selectPage(pageParam, CommonStatusEnum.ENABLE.getStatus());

View File

@ -4,8 +4,6 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchRespVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum;
@ -19,26 +17,6 @@ import java.util.*;
*/ */
public interface CouponService { public interface CouponService {
/**
* 校验优惠劵包括状态有限期
* <p>
* 1. 如果校验通过则返回优惠劵信息
* 2. 如果校验不通过则直接抛出业务异常
*
* @param id 优惠劵编号
* @param userId 用户编号
* @return 优惠劵信息
*/
CouponDO validCoupon(Long id, Long userId);
/**
* 校验优惠劵包括状态有限期
*
* @param coupon 优惠劵
* @see #validCoupon(Long, Long) 逻辑相同只是入参不同
*/
void validCoupon(CouponDO coupon);
/** /**
* 使用优惠劵 * 使用优惠劵
* *
@ -172,15 +150,6 @@ public interface CouponService {
return MapUtil.getInt(map, templateId, 0); return MapUtil.getInt(map, templateId, 0);
} }
/**
* 获取用户匹配的优惠券列表
*
* @param userId 用户编号
* @param matchReqVO 匹配参数
* @return 优惠券列表
*/
List<AppCouponMatchRespVO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO);
/** /**
* 获取用户是否可以领取优惠券 * 获取用户是否可以领取优惠券
* *

View File

@ -12,13 +12,10 @@ import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.coupon.CouponPageReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchReqVO;
import cn.iocoder.yudao.module.promotion.controller.app.coupon.vo.coupon.AppCouponMatchRespVO;
import cn.iocoder.yudao.module.promotion.convert.coupon.CouponConvert; 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.dal.dataobject.coupon.CouponDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO;
import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper; import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponMapper;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTemplateValidityTypeEnum;
@ -58,18 +55,9 @@ public class CouponServiceImpl implements CouponService {
private MemberUserApi memberUserApi; private MemberUserApi memberUserApi;
@Override @Override
public CouponDO validCoupon(Long id, Long userId) { public void useCoupon(Long id, Long userId, Long orderId) {
CouponDO coupon = couponMapper.selectByIdAndUserId(id, userId);
if (coupon == null) {
throw exception(COUPON_NOT_EXISTS);
}
validCoupon(coupon);
return coupon;
}
@Override
public void validCoupon(CouponDO coupon) {
// 校验状态 // 校验状态
CouponDO coupon = couponMapper.selectByIdAndUserId(id, userId);
if (ObjectUtil.notEqual(coupon.getStatus(), CouponStatusEnum.UNUSED.getStatus())) { if (ObjectUtil.notEqual(coupon.getStatus(), CouponStatusEnum.UNUSED.getStatus())) {
throw exception(COUPON_STATUS_NOT_UNUSED); throw exception(COUPON_STATUS_NOT_UNUSED);
} }
@ -77,12 +65,6 @@ public class CouponServiceImpl implements CouponService {
if (!LocalDateTimeUtils.isBetween(coupon.getValidStartTime(), coupon.getValidEndTime())) { if (!LocalDateTimeUtils.isBetween(coupon.getValidStartTime(), coupon.getValidEndTime())) {
throw exception(COUPON_VALID_TIME_NOT_NOW); throw exception(COUPON_VALID_TIME_NOT_NOW);
} }
}
@Override
public void useCoupon(Long id, Long userId, Long orderId) {
// 校验优惠劵
validCoupon(id, userId);
// 更新状态 // 更新状态
int updateCount = couponMapper.updateByIdAndStatus(id, CouponStatusEnum.UNUSED.getStatus(), int updateCount = couponMapper.updateByIdAndStatus(id, CouponStatusEnum.UNUSED.getStatus(),
@ -286,10 +268,8 @@ public class CouponServiceImpl implements CouponService {
if (couponTemplate == null) { if (couponTemplate == null) {
throw exception(COUPON_TEMPLATE_NOT_EXISTS); throw exception(COUPON_TEMPLATE_NOT_EXISTS);
} }
// 校验剩余数量仅在 CouponTakeTypeEnum.USER 用户领取时 // 校验剩余数量
if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeCount()) if (couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) {
&& couponTemplate.getTotalCount() != null
&& couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) {
throw exception(COUPON_TEMPLATE_NOT_ENOUGH); throw exception(COUPON_TEMPLATE_NOT_ENOUGH);
} }
// 校验"固定日期"的有效期类型是否过期 // 校验"固定日期"的有效期类型是否过期
@ -299,7 +279,7 @@ public class CouponServiceImpl implements CouponService {
} }
} }
// 校验领取方式 // 校验领取方式
if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType.getType())) { if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType.getValue())) {
throw exception(COUPON_TEMPLATE_CANNOT_TAKE); throw exception(COUPON_TEMPLATE_CANNOT_TAKE);
} }
} }
@ -311,7 +291,7 @@ public class CouponServiceImpl implements CouponService {
* @param couponTemplate 优惠劵模版 * @param couponTemplate 优惠劵模版
*/ */
private void removeTakeLimitUser(Set<Long> userIds, CouponTemplateDO couponTemplate) { private void removeTakeLimitUser(Set<Long> userIds, CouponTemplateDO couponTemplate) {
if (couponTemplate.getTakeLimitCount() == null || couponTemplate.getTakeLimitCount() <= 0) { if (couponTemplate.getTakeLimitCount() <= 0) {
return; return;
} }
// 查询已领过券的用户 // 查询已领过券的用户
@ -358,48 +338,6 @@ public class CouponServiceImpl implements CouponService {
return couponMapper.selectCountByUserIdAndTemplateIdIn(userId, templateIds); return couponMapper.selectCountByUserIdAndTemplateIdIn(userId, templateIds);
} }
@Override
public List<AppCouponMatchRespVO> getMatchCouponList(Long userId, AppCouponMatchReqVO matchReqVO) {
List<AppCouponMatchRespVO> couponMatchist = new ArrayList<>();
List<CouponDO> list = couponMapper.selectListByUserIdAndStatusAndUsePriceLeAndProductScope(userId,
CouponStatusEnum.UNUSED.getStatus());
for (CouponDO couponDO : list) {
AppCouponMatchRespVO appCouponMatchRespVO = CouponConvert.INSTANCE.convert2(couponDO);
Integer productScope = appCouponMatchRespVO.getProductScope();
List<Long> productScopeValues = appCouponMatchRespVO.getProductScopeValues();
Integer usePrice = appCouponMatchRespVO.getUsePrice();
if(matchReqVO.getPrice() < usePrice){
// 价格小于等于满足价格使用条件
appCouponMatchRespVO.setMatch(false);
appCouponMatchRespVO.setDescription("未达到使用门槛");
}else if(!LocalDateTimeUtils.isBetween(appCouponMatchRespVO.getValidStartTime(), appCouponMatchRespVO.getValidEndTime())) {
//判断时间
appCouponMatchRespVO.setMatch(false);
appCouponMatchRespVO.setDescription("使用时间未到");
}else if (PromotionProductScopeEnum.ALL.getScope().equals(productScope)){
appCouponMatchRespVO.setMatch(true);
}else if (PromotionProductScopeEnum.SPU.getScope().equals(productScope)){
boolean spu = new HashSet<>(productScopeValues).containsAll(matchReqVO.getSpuIds());
if(spu){
appCouponMatchRespVO.setMatch(true);
}else {
appCouponMatchRespVO.setMatch(false);
appCouponMatchRespVO.setDescription("与商品不匹配");
}
}else if (PromotionProductScopeEnum.CATEGORY.getScope().equals(productScope)){
boolean category = new HashSet<>(productScopeValues).containsAll(matchReqVO.getCategoryIds());
if(category){
appCouponMatchRespVO.setMatch(true);
}else {
appCouponMatchRespVO.setMatch(false);
appCouponMatchRespVO.setDescription("与商品类型不匹配");
}
}
couponMatchist.add(appCouponMatchRespVO);
}
return couponMatchist;
}
@Override @Override
public Map<Long, Boolean> getUserCanCanTakeMap(Long userId, List<CouponTemplateDO> templates) { public Map<Long, Boolean> getUserCanCanTakeMap(Long userId, List<CouponTemplateDO> templates) {
// 1. 未登录时都显示可以领取 // 1. 未登录时都显示可以领取

View File

@ -8,8 +8,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.Se
import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppSeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppSeckillActivityPageReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -98,7 +98,7 @@ public interface SeckillActivityService {
* @param activityIds 活动编号 * @param activityIds 活动编号
* @return 活动商品列表 * @return 活动商品列表
*/ */
List<SeckillProductDO> getSeckillProductListByActivityId(Collection<Long> activityIds); List<SeckillProductDO> getSeckillProductListByActivityIds(Collection<Long> activityIds);
/** /**
* 通过活动时段编号获取指定 status 的秒杀活动 * 通过活动时段编号获取指定 status 的秒杀活动
@ -139,4 +139,12 @@ public interface SeckillActivityService {
*/ */
List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatusAndDateTimeLt(Collection<Long> spuIds, Integer status, LocalDateTime dateTime); List<SeckillActivityDO> getSeckillActivityBySpuIdsAndStatusAndDateTimeLt(Collection<Long> spuIds, Integer status, LocalDateTime dateTime);
/**
* 获得拼团活动列表
*
* @param ids 拼团活动编号数组
* @return 拼团活动的列表
*/
List<SeckillActivityDO> getSeckillActivityListByIds(Collection<Long> ids);
} }

View File

@ -51,6 +51,7 @@ public interface ErrorCodeConstants {
ErrorCode AFTER_SALE_REFUND_FAIL_STATUS_NOT_WAIT_REFUND = new ErrorCode(1_011_000_110, "退款失败,售后单状态不是【待退款】"); ErrorCode AFTER_SALE_REFUND_FAIL_STATUS_NOT_WAIT_REFUND = new ErrorCode(1_011_000_110, "退款失败,售后单状态不是【待退款】");
ErrorCode AFTER_SALE_CANCEL_FAIL_STATUS_NOT_APPLY_OR_AGREE_OR_BUYER_DELIVERY = ErrorCode AFTER_SALE_CANCEL_FAIL_STATUS_NOT_APPLY_OR_AGREE_OR_BUYER_DELIVERY =
new ErrorCode(1_011_000_111, "取消售后单失败,售后单状态不是【待审核】或【卖家同意】或【商家待收货】"); new ErrorCode(1_011_000_111, "取消售后单失败,售后单状态不是【待审核】或【卖家同意】或【商家待收货】");
ErrorCode AFTER_SALE_CREATE_FAIL_ORDER_STATUS_COMBINATION_IN_PROGRESS = new ErrorCode(1_011_000_112, "订单拼团中,无法申请售后");
// ========== Cart 模块 1-011-002-000 ========== // ========== Cart 模块 1-011-002-000 ==========
ErrorCode CARD_ITEM_NOT_FOUND = new ErrorCode(1_011_002_000, "购物车项不存在"); ErrorCode CARD_ITEM_NOT_FOUND = new ErrorCode(1_011_002_000, "购物车项不存在");
@ -61,7 +62,7 @@ public interface ErrorCodeConstants {
ErrorCode PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER = new ErrorCode(1_011_003_004, "参与秒杀、拼团、砍价的营销商品,无法使用优惠劵"); ErrorCode PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER = new ErrorCode(1_011_003_004, "参与秒杀、拼团、砍价的营销商品,无法使用优惠劵");
ErrorCode PRICE_CALCULATE_SECKILL_TOTAL_LIMIT_COUNT = new ErrorCode(1_011_003_005, "参与秒杀的商品,超过了秒杀总限购数量"); ErrorCode PRICE_CALCULATE_SECKILL_TOTAL_LIMIT_COUNT = new ErrorCode(1_011_003_005, "参与秒杀的商品,超过了秒杀总限购数量");
ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TYPE_ILLEGAL = new ErrorCode(1_011_003_006, "计算快递运费异常,配送方式不匹配"); ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TYPE_ILLEGAL = new ErrorCode(1_011_003_006, "计算快递运费异常,配送方式不匹配");
ErrorCode PRICE_CALCULATE_COUPON_PRICE_TOO_MUCH = new ErrorCode(1_011_003_007, "该优惠劵无法使用,原因:优惠金额超过订单金额"); ErrorCode PRICE_CALCULATE_COUPON_CAN_NOT_USE = new ErrorCode(1_011_003_007, "该优惠劵无法使用,原因:{}」");
// ========== 物流 Express 模块 1-011-004-000 ========== // ========== 物流 Express 模块 1-011-004-000 ==========
ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1_011_004_000, "快递公司不存在"); ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1_011_004_000, "快递公司不存在");

View File

@ -44,7 +44,7 @@ public class AppBrokerageWithdrawCreateReqVO {
private String name; private String name;
@Schema(description = "提现银行", example = "1") @Schema(description = "提现银行", example = "1")
@NotNull(message = "提现银行不能为空", groups = {Bank.class}) @NotNull(message = "提现银行不能为空", groups = {Bank.class})
private Integer bankName; private String bankName;
@Schema(description = "开户地址", example = "海淀支行") @Schema(description = "开户地址", example = "海淀支行")
private String bankAddress; private String bankAddress;

View File

@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.trade.controller.app.order.vo;
import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.trade.controller.app.base.property.AppProductPropertyValueDetailRespVO;
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@Schema(description = "用户 App - 交易订单结算信息 Response VO") @Schema(description = "用户 App - 交易订单结算信息 Response VO")
@ -20,6 +20,9 @@ public class AppTradeOrderSettlementRespVO {
@Schema(description = "购物项数组", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "购物项数组", requiredMode = Schema.RequiredMode.REQUIRED)
private List<Item> items; private List<Item> items;
@Schema(description = "优惠劵数组", requiredMode = Schema.RequiredMode.REQUIRED)
private List<Coupon> coupons; // 可用 + 不可用
@Schema(description = "费用", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "费用", requiredMode = Schema.RequiredMode.REQUIRED)
private Price price; private Price price;
@ -117,7 +120,6 @@ public class AppTradeOrderSettlementRespVO {
private String mobile; private String mobile;
@Schema(description = "地区编号", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "地区编号", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "地区编号不能为空")
private Long areaId; private Long areaId;
@Schema(description = "地区名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "上海上海市普陀区") @Schema(description = "地区名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "上海上海市普陀区")
private String areaName; private String areaName;
@ -130,4 +132,43 @@ public class AppTradeOrderSettlementRespVO {
} }
@Schema(description = "优惠劵信息")
@Data
public static class Coupon {
@Schema(description = "优惠劵编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "优惠劵名", requiredMode = Schema.RequiredMode.REQUIRED, example = "春节送送送")
private String name;
@Schema(description = "是否设置满多少金额可用", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") // 单位0 - 不限制
private Integer usePrice;
@Schema(description = "固定日期 - 生效开始时间")
private LocalDateTime validStartTime;
@Schema(description = "固定日期 - 生效结束时间")
private LocalDateTime validEndTime;
@Schema(description = "优惠类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer discountType;
@Schema(description = "折扣百分比", example = "80") // 例如说80% 80
private Integer discountPercent;
@Schema(description = "优惠金额", example = "10")
private Integer discountPrice;
@Schema(description = "折扣上限", example = "100") // 单位仅在 discountType PERCENT 使用
private Integer discountLimitPrice;
@Schema(description = "是否可用", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean match;
@Schema(description = "不可用原因", example = "优惠劵已过期")
private String mismatchReason;
}
} }

View File

@ -8,6 +8,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.pay.api.refund.PayRefundApi; import cn.iocoder.yudao.module.pay.api.refund.PayRefundApi;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO; import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleDisagreeReqVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleDisagreeReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSalePageReqVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSalePageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleRefuseReqVO; import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleRefuseReqVO;
@ -26,6 +29,7 @@ import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleTypeEnum;
import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleWayEnum; import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleWayEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderItemAfterSaleStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
import cn.iocoder.yudao.module.trade.framework.aftersale.core.annotations.AfterSaleLog; import cn.iocoder.yudao.module.trade.framework.aftersale.core.annotations.AfterSaleLog;
import cn.iocoder.yudao.module.trade.framework.aftersale.core.utils.AfterSaleLogUtils; import cn.iocoder.yudao.module.trade.framework.aftersale.core.utils.AfterSaleLogUtils;
import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties;
@ -71,6 +75,8 @@ public class AfterSaleServiceImpl implements AfterSaleService {
@Resource @Resource
private PayRefundApi payRefundApi; private PayRefundApi payRefundApi;
@Resource
private CombinationRecordApi combinationRecordApi;
@Resource @Resource
private TradeOrderProperties tradeOrderProperties; private TradeOrderProperties tradeOrderProperties;
@ -148,6 +154,14 @@ public class AfterSaleServiceImpl implements AfterSaleService {
&& !TradeOrderStatusEnum.haveDelivered(order.getStatus())) { && !TradeOrderStatusEnum.haveDelivered(order.getStatus())) {
throw exception(AFTER_SALE_CREATE_FAIL_ORDER_STATUS_NO_DELIVERED); throw exception(AFTER_SALE_CREATE_FAIL_ORDER_STATUS_NO_DELIVERED);
} }
// 如果是拼团订单则进行中不允许售后
if (TradeOrderTypeEnum.isCombination(order.getType())) {
CombinationRecordRespDTO combinationRecord = combinationRecordApi.getCombinationRecordByOrderId(
order.getUserId(), order.getId());
if (combinationRecord != null && CombinationRecordStatusEnum.isInProgress(combinationRecord.getStatus())) {
throw exception(AFTER_SALE_CREATE_FAIL_ORDER_STATUS_COMBINATION_IN_PROGRESS);
}
}
return orderItem; return orderItem;
} }

View File

@ -887,7 +887,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
.setAppKey(tradeOrderProperties.getPayAppKey()).setUserIp(getClientIP()) // 支付应用 .setAppKey(tradeOrderProperties.getPayAppKey()).setUserIp(getClientIP()) // 支付应用
.setMerchantOrderId(String.valueOf(order.getId())) // 支付单号 .setMerchantOrderId(String.valueOf(order.getId())) // 支付单号
.setMerchantRefundId(String.valueOf(order.getId())) .setMerchantRefundId(String.valueOf(order.getId()))
.setReason(TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getName()).setPrice(order.getPayPrice()));// 价格信息 .setReason(TradeOrderCancelTypeEnum.COMBINATION_CLOSE.getName()).setPrice(order.getPayPrice())); // 价格信息
} }
@Override @Override

View File

@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.trade.service.order.handler;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateRespDTO;
import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordRespDTO;
import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum;
import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
@ -84,7 +86,9 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler {
return; return;
} }
// 校验订单拼团是否成功 // 校验订单拼团是否成功
if (!combinationRecordApi.isCombinationRecordSuccess(order.getUserId(), order.getId())) { CombinationRecordRespDTO combinationRecord = combinationRecordApi.getCombinationRecordByOrderId(order.getUserId(), order.getId());
Assert.notNull(combinationRecord, "订单({})对应的拼团记录不存在", order.getId());
if (!CombinationRecordStatusEnum.isSuccess(combinationRecord.getStatus())) {
throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS);
} }
} }

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -45,9 +46,13 @@ public class TradePriceCalculateRespBO {
private List<Promotion> promotions; private List<Promotion> promotions;
/** /**
* 优惠劵编号 * 使用的优惠劵编号
*/ */
private Long couponId; private Long couponId;
/**
* 用户的优惠劵列表可用 + 不可用
*/
private List<Coupon> coupons;
/** /**
* 会员剩余积分 * 会员剩余积分
@ -340,4 +345,62 @@ public class TradePriceCalculateRespBO {
} }
/**
* 优惠劵信息
*/
@Data
public static class Coupon {
/**
* 优惠劵编号
*/
private Long id;
/**
* 优惠劵名
*/
private String name;
/**
* 是否设置满多少金额可用单位
*/
private Integer usePrice;
/**
* 生效开始时间
*/
private LocalDateTime validStartTime;
/**
* 生效结束时间
*/
private LocalDateTime validEndTime;
/**
* 优惠类型
*/
private Integer discountType;
/**
* 折扣百分比
*/
private Integer discountPercent;
/**
* 优惠金额单位
*/
private Integer discountPrice;
/**
* 折扣上限单位
*/
private Integer discountLimitPrice;
/**
* 是否匹配
*/
private Boolean match;
/**
* 不匹配的原因
*/
private String mismatchReason;
}
} }

View File

@ -1,31 +1,31 @@
package cn.iocoder.yudao.module.trade.service.price.calculator; package cn.iocoder.yudao.module.trade.service.price.calculator;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
import jakarta.annotation.Resource;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import jakarta.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_NO_MATCH_MIN_PRICE; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_COUPON_CAN_NOT_USE;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_NO_MATCH_SPU;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.PRICE_CALCULATE_COUPON_PRICE_TOO_MUCH;
/** /**
* 优惠劵的 {@link TradePriceCalculator} 实现类 * 优惠劵的 {@link TradePriceCalculator} 实现类
@ -41,34 +41,37 @@ public class TradeCouponPriceCalculator implements TradePriceCalculator {
@Override @Override
public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) { public void calculate(TradePriceCalculateReqBO param, TradePriceCalculateRespBO result) {
// 1.1 校验优惠劵 // 只有普通订单才允许使用优惠劵
if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) {
if (param.getCouponId() != null) {
throw exception(PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER);
}
return;
}
// 1.1 加载用户的优惠劵列表
List<CouponRespDTO> coupons = couponApi.getCouponListByUserId(param.getUserId(), CouponStatusEnum.UNUSED.getStatus());
coupons.removeIf(coupon -> LocalDateTimeUtils.beforeNow(coupon.getValidEndTime()));
// 1.2 计算优惠劵的使用条件
result.setCoupons(calculateCoupons(coupons, result));
// 2. 校验优惠劵是否可用
if (param.getCouponId() == null) { if (param.getCouponId() == null) {
return; return;
} }
CouponRespDTO coupon = couponApi.validateCoupon(new CouponValidReqDTO() TradePriceCalculateRespBO.Coupon couponBO = CollUtil.findOne(result.getCoupons(), item -> item.getId().equals(param.getCouponId()));
.setId(param.getCouponId()).setUserId(param.getUserId())); CouponRespDTO coupon = CollUtil.findOne(coupons, item -> item.getId().equals(param.getCouponId()));
Assert.notNull(coupon, "校验通过的优惠劵({}),不能为空", param.getCouponId()); if (couponBO == null || coupon == null) {
// 1.2 只有普通订单才允许使用优惠劵 throw exception(PRICE_CALCULATE_COUPON_CAN_NOT_USE, "优惠劵不存在");
if (ObjectUtil.notEqual(result.getType(), TradeOrderTypeEnum.NORMAL.getType())) {
throw exception(PRICE_CALCULATE_COUPON_NOT_MATCH_NORMAL_ORDER);
} }
if (Boolean.FALSE.equals(couponBO.getMatch())) {
// 2.1 获得匹配的商品 SKU 数组 throw exception(PRICE_CALCULATE_COUPON_CAN_NOT_USE, couponBO.getMismatchReason());
List<TradePriceCalculateRespBO.OrderItem> orderItems = filterMatchCouponOrderItems(result, coupon);
if (CollUtil.isEmpty(orderItems)) {
throw exception(COUPON_NO_MATCH_SPU);
}
// 2.2 计算是否满足优惠劵的使用金额
Integer totalPayPrice = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems);
if (totalPayPrice < coupon.getUsePrice()) {
throw exception(COUPON_NO_MATCH_MIN_PRICE);
} }
// 3.1 计算可以优惠的金额 // 3.1 计算可以优惠的金额
List<TradePriceCalculateRespBO.OrderItem> orderItems = filterMatchCouponOrderItems(result, coupon);
Integer totalPayPrice = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems);
Integer couponPrice = getCouponPrice(coupon, totalPayPrice); Integer couponPrice = getCouponPrice(coupon, totalPayPrice);
if (couponPrice <= totalPayPrice) {
throw exception(PRICE_CALCULATE_COUPON_PRICE_TOO_MUCH);
}
// 3.2 计算分摊的优惠金额 // 3.2 计算分摊的优惠金额
List<Integer> divideCouponPrices = TradePriceCalculatorHelper.dividePrice(orderItems, couponPrice); List<Integer> divideCouponPrices = TradePriceCalculatorHelper.dividePrice(orderItems, couponPrice);
@ -76,7 +79,7 @@ public class TradeCouponPriceCalculator implements TradePriceCalculator {
result.setCouponId(param.getCouponId()); result.setCouponId(param.getCouponId());
// 4.2 记录优惠明细 // 4.2 记录优惠明细
TradePriceCalculatorHelper.addPromotion(result, orderItems, TradePriceCalculatorHelper.addPromotion(result, orderItems,
param.getCouponId(), coupon.getName(), PromotionTypeEnum.COUPON.getType(), param.getCouponId(), couponBO.getName(), PromotionTypeEnum.COUPON.getType(),
StrUtil.format("优惠劵:省 {} 元", TradePriceCalculatorHelper.formatPrice(couponPrice)), StrUtil.format("优惠劵:省 {} 元", TradePriceCalculatorHelper.formatPrice(couponPrice)),
divideCouponPrices); divideCouponPrices);
// 4.3 更新 SKU 优惠金额 // 4.3 更新 SKU 优惠金额
@ -88,6 +91,43 @@ public class TradeCouponPriceCalculator implements TradePriceCalculator {
TradePriceCalculatorHelper.recountAllPrice(result); TradePriceCalculatorHelper.recountAllPrice(result);
} }
/**
* 计算用户的优惠劵列表可用 + 不可用
*
* @param coupons 优惠劵
* @param result 计算结果
* @return 优惠劵列表
*/
private List<TradePriceCalculateRespBO.Coupon> calculateCoupons(List<CouponRespDTO> coupons,
TradePriceCalculateRespBO result) {
return convertList(coupons, coupon -> {
TradePriceCalculateRespBO.Coupon matchCoupon = BeanUtils.toBean(coupon, TradePriceCalculateRespBO.Coupon.class);
// 1.1 优惠劵未到使用时间
if (LocalDateTimeUtils.afterNow(coupon.getValidStartTime())) {
return matchCoupon.setMatch(false).setMismatchReason("优惠劵未到使用时间");
}
// 1.2 优惠劵没有匹配的商品
List<TradePriceCalculateRespBO.OrderItem> orderItems = filterMatchCouponOrderItems(result, coupon);
if (CollUtil.isEmpty(orderItems)) {
return matchCoupon.setMatch(false).setMismatchReason("优惠劵没有匹配的商品");
}
// 1.3 %1$,.2f 元可用优惠劵
Integer totalPayPrice = TradePriceCalculatorHelper.calculateTotalPayPrice(orderItems);
if (totalPayPrice < coupon.getUsePrice()) {
return matchCoupon.setMatch(false)
.setMismatchReason(String.format("差 %1$,.2f 元可用优惠劵", (coupon.getUsePrice() - totalPayPrice) / 100D));
}
// 1.4 优惠金额超过订单金额
Integer couponPrice = getCouponPrice(coupon, totalPayPrice);
if (couponPrice >= totalPayPrice) {
return matchCoupon.setMatch(false).setMismatchReason("优惠金额超过订单金额");
}
// 2. 满足条件
return matchCoupon.setMatch(true);
});
}
private Integer getCouponPrice(CouponRespDTO coupon, Integer totalPayPrice) { private Integer getCouponPrice(CouponRespDTO coupon, Integer totalPayPrice) {
if (PromotionDiscountTypeEnum.PRICE.getType().equals(coupon.getDiscountType())) { // 减价 if (PromotionDiscountTypeEnum.PRICE.getType().equals(coupon.getDiscountType())) { // 减价
return coupon.getDiscountPrice(); return coupon.getDiscountPrice();

View File

@ -1,12 +1,13 @@
package cn.iocoder.yudao.module.trade.service.price.calculator; package cn.iocoder.yudao.module.trade.service.price.calculator;
import cn.hutool.core.collection.ListUtil;
import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest;
import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO; import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponRespDTO;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponValidReqDTO;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionDiscountTypeEnum;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionProductScopeEnum;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum; import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum;
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateReqBO;
import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
@ -14,8 +15,10 @@ import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -69,8 +72,10 @@ public class TradeCouponPriceCalculatorTest extends BaseMockitoUnitTest {
CouponRespDTO coupon = randomPojo(CouponRespDTO.class, o -> o.setId(1024L).setName("程序员节") CouponRespDTO coupon = randomPojo(CouponRespDTO.class, o -> o.setId(1024L).setName("程序员节")
.setProductScope(PromotionProductScopeEnum.SPU.getScope()).setProductScopeValues(asList(1L, 2L)) .setProductScope(PromotionProductScopeEnum.SPU.getScope()).setProductScopeValues(asList(1L, 2L))
.setUsePrice(350).setDiscountType(PromotionDiscountTypeEnum.PERCENT.getType()) .setUsePrice(350).setDiscountType(PromotionDiscountTypeEnum.PERCENT.getType())
.setDiscountPercent(50).setDiscountLimitPrice(70)); .setDiscountPercent(50).setDiscountLimitPrice(70))
when(couponApi.validateCoupon(eq(new CouponValidReqDTO().setId(1024L).setUserId(233L)))).thenReturn(coupon); .setValidStartTime(addTime(Duration.ofDays(1))).setValidEndTime(addTime(Duration.ofDays(2)));
when(couponApi.getCouponListByUserId(eq(233L), eq(CouponStatusEnum.UNUSED.getStatus())))
.thenReturn(ListUtil.toList(coupon));
// 调用 // 调用
tradeCouponPriceCalculator.calculate(param, result); tradeCouponPriceCalculator.calculate(param, result);

View File

@ -431,9 +431,7 @@ public class PayOrderServiceImpl implements PayOrderService {
return; return;
} }
// TODO 芋艿应该 new 出来更新 orderMapper.updateById(new PayOrderDO().setId(order.getId()).setPrice(payPrice));
order.setPrice(payPrice);
orderMapper.updateById(order);
} }
@Override @Override

View File

@ -266,7 +266,7 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
String errorCode = getErrorCode(e); String errorCode = getErrorCode(e);
String errorMessage = getErrorMessage(e); String errorMessage = getErrorMessage(e);
return PayRefundRespDTO.failureOf(errorCode, errorMessage, return PayRefundRespDTO.failureOf(errorCode, errorMessage,
reqDTO.getOutTradeNo(), e.getXmlString()); reqDTO.getOutRefundNo(), e.getXmlString());
} }
} }

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogPageReqDTO; import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogPageReqDTO;
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogRespDTO; import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogRespDTO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springframework.scheduling.annotation.Async;
/** /**
* 操作日志 API 接口 * 操作日志 API 接口
@ -20,6 +21,16 @@ public interface OperateLogApi {
*/ */
void createOperateLog(@Valid OperateLogCreateReqDTO createReqDTO); void createOperateLog(@Valid OperateLogCreateReqDTO createReqDTO);
/**
* 异步创建操作日志
*
* @param createReqDTO 请求
*/
@Async
default void createOperateLogAsync(OperateLogCreateReqDTO createReqDTO) {
createOperateLog(createReqDTO);
}
/** /**
* 获取指定模块的指定数据的操作日志分页 * 获取指定模块的指定数据的操作日志分页
* *

View File

@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
import cn.iocoder.yudao.module.system.service.logger.OperateLogService; import cn.iocoder.yudao.module.system.service.logger.OperateLogService;
import com.fhs.core.trans.anno.TransMethodResult; import com.fhs.core.trans.anno.TransMethodResult;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -26,7 +25,6 @@ public class OperateLogApiImpl implements OperateLogApi {
private OperateLogService operateLogService; private OperateLogService operateLogService;
@Override @Override
@Async
public void createOperateLog(OperateLogCreateReqDTO createReqDTO) { public void createOperateLog(OperateLogCreateReqDTO createReqDTO) {
operateLogService.createOperateLog(createReqDTO); operateLogService.createOperateLog(createReqDTO);
} }

View File

@ -144,7 +144,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest {
// 调用并断言 // 调用并断言
assertServiceException(() -> oauth2TokenService.refreshAccessToken(refreshToken, clientId), assertServiceException(() -> oauth2TokenService.refreshAccessToken(refreshToken, clientId),
new ErrorCode(401, "刷新令牌已过期")); new ErrorCode(401, "刷新令牌已过期"));
assertEquals(0, oauth2RefreshTokenMapper.selectCount()); assertEquals(0, oauth2AccessTokenMapper.selectCount());
} }
@Test @Test

View File

@ -33,11 +33,11 @@
</dependency> </dependency>
<!-- 会员中心。默认注释,保证编译速度 --> <!-- 会员中心。默认注释,保证编译速度 -->
<dependency> <!-- <dependency>-->
<groupId>cn.iocoder.boot</groupId> <!-- <groupId>cn.iocoder.boot</groupId>-->
<artifactId>yudao-module-member-biz</artifactId> <!-- <artifactId>yudao-module-member-biz</artifactId>-->
<version>${revision}</version> <!-- <version>${revision}</version>-->
</dependency> <!-- </dependency>-->
<!-- 数据报表。默认注释,保证编译速度 --> <!-- 数据报表。默认注释,保证编译速度 -->
<!-- <dependency>--> <!-- <dependency>-->
@ -52,11 +52,11 @@
<!-- <version>${revision}</version>--> <!-- <version>${revision}</version>-->
<!-- </dependency>--> <!-- </dependency>-->
<!-- 支付服务。默认注释,保证编译速度 --> <!-- 支付服务。默认注释,保证编译速度 -->
<dependency> <!-- <dependency>-->
<groupId>cn.iocoder.boot</groupId> <!-- <groupId>cn.iocoder.boot</groupId>-->
<artifactId>yudao-module-pay-biz</artifactId> <!-- <artifactId>yudao-module-pay-biz</artifactId>-->
<version>${revision}</version> <!-- <version>${revision}</version>-->
</dependency> <!-- </dependency>-->
<!-- 微信公众号模块。默认注释,保证编译速度 --> <!-- 微信公众号模块。默认注释,保证编译速度 -->
<!-- <dependency>--> <!-- <dependency>-->
@ -66,26 +66,26 @@
<!-- </dependency>--> <!-- </dependency>-->
<!-- 商城相关模块。默认注释,保证编译速度--> <!-- 商城相关模块。默认注释,保证编译速度-->
<dependency> <!-- <dependency>-->
<groupId>cn.iocoder.boot</groupId> <!-- <groupId>cn.iocoder.boot</groupId>-->
<artifactId>yudao-module-promotion-biz</artifactId> <!-- <artifactId>yudao-module-promotion-biz</artifactId>-->
<version>${revision}</version> <!-- <version>${revision}</version>-->
</dependency> <!-- </dependency>-->
<dependency> <!-- <dependency>-->
<groupId>cn.iocoder.boot</groupId> <!-- <groupId>cn.iocoder.boot</groupId>-->
<artifactId>yudao-module-product-biz</artifactId> <!-- <artifactId>yudao-module-product-biz</artifactId>-->
<version>${revision}</version> <!-- <version>${revision}</version>-->
</dependency> <!-- </dependency>-->
<dependency> <!-- <dependency>-->
<groupId>cn.iocoder.boot</groupId> <!-- <groupId>cn.iocoder.boot</groupId>-->
<artifactId>yudao-module-trade-biz</artifactId> <!-- <artifactId>yudao-module-trade-biz</artifactId>-->
<version>${revision}</version> <!-- <version>${revision}</version>-->
</dependency> <!-- </dependency>-->
<dependency> <!-- <dependency>-->
<groupId>cn.iocoder.boot</groupId> <!-- <groupId>cn.iocoder.boot</groupId>-->
<artifactId>yudao-module-statistics-biz</artifactId> <!-- <artifactId>yudao-module-statistics-biz</artifactId>-->
<version>${revision}</version> <!-- <version>${revision}</version>-->
</dependency> <!-- </dependency>-->
<!-- CRM 相关模块。默认注释,保证编译速度 --> <!-- CRM 相关模块。默认注释,保证编译速度 -->
<!-- <dependency>--> <!-- <dependency>-->

View File

@ -154,9 +154,9 @@ spring:
embedding: embedding:
transformer: transformer:
onnx: onnx:
model-uri: http://test.yudao.iocoder.cn/model.onnx model-uri: https://raw.gitcode.com/yudaocode/yudao-demo/raw/master/yudao-static/ai/model.onnx
tokenizer: tokenizer:
uri: http://test.yudao.iocoder.cn/tokenizer.json uri: https://raw.gitcode.com/yudaocode/yudao-demo/raw/master/yudao-static/ai/tokenizer.json
qianfan: # 文心一言 qianfan: # 文心一言
api-key: x0cuLZ7XsaTCU08vuJWO87Lg api-key: x0cuLZ7XsaTCU08vuJWO87Lg
secret-key: R9mYF9dl9KASgi5RUq0FQt3wRisSnOcK secret-key: R9mYF9dl9KASgi5RUq0FQt3wRisSnOcK
@ -245,7 +245,7 @@ yudao:
codegen: codegen:
base-package: ${yudao.info.base-package} base-package: ${yudao.info.base-package}
db-schemas: ${spring.datasource.dynamic.datasource.master.name} db-schemas: ${spring.datasource.dynamic.datasource.master.name}
front-type: 10 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类 front-type: 20 # 前端模版的类型,参见 CodegenFrontTypeEnum 枚举类
tenant: # 多租户相关配置项 tenant: # 多租户相关配置项
enable: true enable: true
ignore-urls: ignore-urls: