mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-04 01:52:21 +08:00
Merge branch 'develop' of https://gitee.com/youlaitech/youlai-mall into develop
This commit is contained in:
commit
a0801c0d4b
@ -42,6 +42,11 @@
|
|||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 配置中心 -->
|
<!-- 配置中心 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
@ -10,6 +10,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||||||
* 会员服务启动类
|
* 会员服务启动类
|
||||||
*
|
*
|
||||||
* @author ray
|
* @author ray
|
||||||
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableDiscoveryClient()
|
@EnableDiscoveryClient()
|
||||||
|
@ -30,13 +30,16 @@ import java.util.stream.Collectors;
|
|||||||
* ---- hKey:value <--> skuId 商品1
|
* ---- hKey:value <--> skuId 商品1
|
||||||
* ---- hKey:value <--> 商品2
|
* ---- hKey:value <--> 商品2
|
||||||
* ---- hKey:value <--> 商品3
|
* ---- hKey:value <--> 商品3
|
||||||
|
*
|
||||||
|
* @author Ray
|
||||||
|
* @since 4.0.0
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class CartServiceImpl implements CartService {
|
public class CartServiceImpl implements CartService {
|
||||||
|
|
||||||
private final RedisTemplate<String, CartItemDTO> redisTemplate;
|
private final RedisTemplate redisTemplate;
|
||||||
private final SkuFeignClient skuFeignClient;
|
private final SkuFeignClient skuFeignClient;
|
||||||
private final CartConverter cartConverter;
|
private final CartConverter cartConverter;
|
||||||
|
|
||||||
@ -60,7 +63,6 @@ public class CartServiceImpl implements CartService {
|
|||||||
List<Long> skuIds = cartItems.stream().map(CartItemDTO::getSkuId).toList();
|
List<Long> skuIds = cartItems.stream().map(CartItemDTO::getSkuId).toList();
|
||||||
List<SkuDTO> skuList = skuFeignClient.listSkusByIds(skuIds);
|
List<SkuDTO> skuList = skuFeignClient.listSkusByIds(skuIds);
|
||||||
|
|
||||||
|
|
||||||
// 创建SKU ID到SkuInfoDto的映射,以优化查找性能
|
// 创建SKU ID到SkuInfoDto的映射,以优化查找性能
|
||||||
Map<Long, SkuDTO> skuIdToSkuInfoMap = skuList.stream()
|
Map<Long, SkuDTO> skuIdToSkuInfoMap = skuList.stream()
|
||||||
.collect(Collectors.toMap(SkuDTO::getId, Function.identity()));
|
.collect(Collectors.toMap(SkuDTO::getId, Function.identity()));
|
||||||
@ -158,8 +160,6 @@ public class CartServiceImpl implements CartService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取购物车的Hash操作对象
|
* 获取购物车的Hash操作对象
|
||||||
*
|
*
|
||||||
|
@ -88,6 +88,10 @@
|
|||||||
<artifactId>common-middleware-seata</artifactId>
|
<artifactId>common-middleware-seata</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.youlai</groupId>
|
||||||
|
<artifactId>common-middleware-rabbitmq</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -60,12 +60,12 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youlai</groupId>
|
<groupId>com.youlai</groupId>
|
||||||
<artifactId>common-mybatis</artifactId>
|
<artifactId>common-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youlai</groupId>
|
<groupId>com.youlai</groupId>
|
||||||
<artifactId>common-web</artifactId>
|
<artifactId>common-mybatis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -10,6 +10,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
* 营销服务启动类
|
* 营销服务启动类
|
||||||
*
|
*
|
||||||
* @author ray
|
* @author ray
|
||||||
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
|
@ -25,7 +25,7 @@ public interface CouponConverter {
|
|||||||
@Mapping(target = "faceValueLabel", expression = "java(com.youlai.mall.sms.util.CouponUtils.getFaceValue(entity.getType(),entity.getFaceValue(),entity.getDiscount()))"),
|
@Mapping(target = "faceValueLabel", expression = "java(com.youlai.mall.sms.util.CouponUtils.getFaceValue(entity.getType(),entity.getFaceValue(),entity.getDiscount()))"),
|
||||||
@Mapping(
|
@Mapping(
|
||||||
target = "validityPeriodLabel",
|
target = "validityPeriodLabel",
|
||||||
expression = "java(com.youlai.mall.sms.util.CouponUtils.getValidityPeriod(entity.getValidityPeriodType(),entity.getValidityDays(),entity.getValidityBeginTime(),entity.getValidityBeginTime()))"
|
expression = "java(com.youlai.mall.sms.util.CouponUtils.getValidityPeriod(entity.getValidityPeriodType(),entity.getValidityDays(),entity.getValidityStartTime(),entity.getValidityEndTime()))"
|
||||||
),
|
),
|
||||||
@Mapping(target = "minPointLabel", expression = "java(cn.hutool.core.util.NumberUtil.toStr(cn.hutool.core.util.NumberUtil.div(entity.getMinPoint(),new java.math.BigDecimal(100)).setScale(2)))"),
|
@Mapping(target = "minPointLabel", expression = "java(cn.hutool.core.util.NumberUtil.toStr(cn.hutool.core.util.NumberUtil.div(entity.getMinPoint(),new java.math.BigDecimal(100)).setScale(2)))"),
|
||||||
})
|
})
|
||||||
|
6
pom.xml
6
pom.xml
@ -26,7 +26,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.2.6</version>
|
<version>3.2.8</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -36,8 +36,8 @@
|
|||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
|
||||||
<!-- spring cloud & alibaba -->
|
<!-- spring cloud & alibaba -->
|
||||||
<spring-cloud.version>2023.0.0</spring-cloud.version>
|
<spring-cloud.version>2023.0.3</spring-cloud.version>
|
||||||
<spring-cloud-alibaba.version>2023.0.1.0</spring-cloud-alibaba.version>
|
<spring-cloud-alibaba.version>2023.0.1.2</spring-cloud-alibaba.version>
|
||||||
|
|
||||||
<!-- 数据库 & ORM -->
|
<!-- 数据库 & ORM -->
|
||||||
<mysql.version>8.0.28</mysql.version>
|
<mysql.version>8.0.28</mysql.version>
|
||||||
|
@ -84,11 +84,6 @@
|
|||||||
<artifactId>common-mybatis</artifactId>
|
<artifactId>common-mybatis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.youlai</groupId>
|
|
||||||
<artifactId>common-middleware-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youlai</groupId>
|
<groupId>com.youlai</groupId>
|
||||||
<artifactId>common-thirdparty-sms</artifactId>
|
<artifactId>common-thirdparty-sms</artifactId>
|
||||||
|
@ -139,7 +139,7 @@ public class CaptchaAuthenticationProvider implements AuthenticationProvider {
|
|||||||
.registeredClient(registeredClient)
|
.registeredClient(registeredClient)
|
||||||
.principal(usernamePasswordAuthentication) // 身份验证成功的认证信息(用户名、权限等信息)
|
.principal(usernamePasswordAuthentication) // 身份验证成功的认证信息(用户名、权限等信息)
|
||||||
.authorizationServerContext(AuthorizationServerContextHolder.getContext())
|
.authorizationServerContext(AuthorizationServerContextHolder.getContext())
|
||||||
.authorizedScopes(authorizedScopes)
|
.authorizedScopes(requestedScopes)
|
||||||
.authorizationGrantType(CaptchaAuthenticationToken.CAPTCHA) // 授权方式
|
.authorizationGrantType(CaptchaAuthenticationToken.CAPTCHA) // 授权方式
|
||||||
.authorizationGrant(passwordAuthenticationToken) // 授权具体对象
|
.authorizationGrant(passwordAuthenticationToken) // 授权具体对象
|
||||||
;
|
;
|
||||||
|
@ -6,7 +6,6 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redis 配置
|
* Redis 配置
|
||||||
*
|
*
|
||||||
|
@ -39,23 +39,27 @@ import java.time.LocalDateTime;
|
|||||||
public class MinioOssService implements OssService {
|
public class MinioOssService implements OssService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务Endpoint(http://localhost:9000)
|
* 服务Endpoint
|
||||||
*/
|
*/
|
||||||
private String endpoint;
|
private String endpoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 访问凭据
|
* 访问凭据
|
||||||
*/
|
*/
|
||||||
private String accessKey;
|
private String accessKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 凭据密钥
|
* 凭据密钥
|
||||||
*/
|
*/
|
||||||
private String secretKey;
|
private String secretKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储桶名称
|
* 存储桶名称
|
||||||
*/
|
*/
|
||||||
private String bucketName;
|
private String bucketName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义域名(https://oss.youlai.tech)
|
* 自定义域名
|
||||||
*/
|
*/
|
||||||
private String customDomain;
|
private String customDomain;
|
||||||
|
|
||||||
@ -75,7 +79,7 @@ public class MinioOssService implements OssService {
|
|||||||
* 上传文件
|
* 上传文件
|
||||||
*
|
*
|
||||||
* @param file 表单文件对象
|
* @param file 表单文件对象
|
||||||
* @return
|
* @return 文件信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public FileInfo uploadFile(MultipartFile file) {
|
public FileInfo uploadFile(MultipartFile file) {
|
||||||
@ -97,7 +101,8 @@ public class MinioOssService implements OssService {
|
|||||||
|
|
||||||
// 返回文件路径
|
// 返回文件路径
|
||||||
String fileUrl;
|
String fileUrl;
|
||||||
if (StrUtil.isBlank(customDomain)) { // 未配置自定义域名
|
// 未配置自定义域名
|
||||||
|
if (StrUtil.isBlank(customDomain)) {
|
||||||
GetPresignedObjectUrlArgs getPresignedObjectUrlArgs = GetPresignedObjectUrlArgs.builder()
|
GetPresignedObjectUrlArgs getPresignedObjectUrlArgs = GetPresignedObjectUrlArgs.builder()
|
||||||
.bucket(bucketName).object(fileName)
|
.bucket(bucketName).object(fileName)
|
||||||
.method(Method.GET)
|
.method(Method.GET)
|
||||||
@ -105,7 +110,8 @@ public class MinioOssService implements OssService {
|
|||||||
|
|
||||||
fileUrl = minioClient.getPresignedObjectUrl(getPresignedObjectUrlArgs);
|
fileUrl = minioClient.getPresignedObjectUrl(getPresignedObjectUrlArgs);
|
||||||
fileUrl = fileUrl.substring(0, fileUrl.indexOf("?"));
|
fileUrl = fileUrl.substring(0, fileUrl.indexOf("?"));
|
||||||
} else { // 配置自定义文件路径域名
|
} else {
|
||||||
|
// 配置自定义文件路径域名
|
||||||
fileUrl = customDomain + '/' + bucketName + "/" + fileName;
|
fileUrl = customDomain + '/' + bucketName + "/" + fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,9 +128,7 @@ public class MinioOssService implements OssService {
|
|||||||
/**
|
/**
|
||||||
* 删除文件
|
* 删除文件
|
||||||
*
|
*
|
||||||
* @param filePath 文件路径
|
* @param filePath 文件路径 https://oss.youlai.tech/default/20221120/test.jpg
|
||||||
* https://oss.youlai.tech/default/20221120/test.jpg
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteFile(String filePath) {
|
public boolean deleteFile(String filePath) {
|
||||||
@ -161,7 +165,7 @@ public class MinioOssService implements OssService {
|
|||||||
* Resource: 指定存储桶
|
* Resource: 指定存储桶
|
||||||
* Action: 操作行为
|
* Action: 操作行为
|
||||||
*
|
*
|
||||||
* @param bucketName
|
* @param bucketName 存储桶名称
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static String publicBucketPolicy(String bucketName) {
|
private static String publicBucketPolicy(String bucketName) {
|
||||||
|
@ -18,6 +18,11 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-aop</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.openfeign</groupId>
|
<groupId>io.github.openfeign</groupId>
|
||||||
<artifactId>feign-core</artifactId>
|
<artifactId>feign-core</artifactId>
|
||||||
@ -28,12 +33,6 @@
|
|||||||
<artifactId>feign-httpclient</artifactId>
|
<artifactId>feign-httpclient</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-aop</artifactId>
|
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mapstruct</groupId>
|
<groupId>org.mapstruct</groupId>
|
||||||
<artifactId>mapstruct</artifactId>
|
<artifactId>mapstruct</artifactId>
|
||||||
|
@ -28,8 +28,8 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class PreventRepeatSubmit {
|
public class PreventRepeatSubmit {
|
||||||
|
|
||||||
private final RedissonClient redissonClient;
|
private final RedissonClient redissonClient;
|
||||||
@ -41,10 +41,9 @@ public class PreventRepeatSubmit {
|
|||||||
*/
|
*/
|
||||||
@Pointcut("@annotation(preventDuplicateResubmit)")
|
@Pointcut("@annotation(preventDuplicateResubmit)")
|
||||||
public void preventDuplicateSubmitPointCut(PreventDuplicateResubmit preventDuplicateResubmit) {
|
public void preventDuplicateSubmitPointCut(PreventDuplicateResubmit preventDuplicateResubmit) {
|
||||||
log.info("定义防重复提交切点");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Around("preventDuplicateSubmitPointCut(preventDuplicateResubmit)")
|
@Around(value = "preventDuplicateSubmitPointCut(preventDuplicateResubmit)", argNames = "pjp,preventDuplicateResubmit")
|
||||||
public Object doAround(ProceedingJoinPoint pjp, PreventDuplicateResubmit preventDuplicateResubmit) throws Throwable {
|
public Object doAround(ProceedingJoinPoint pjp, PreventDuplicateResubmit preventDuplicateResubmit) throws Throwable {
|
||||||
|
|
||||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
@ -52,11 +51,14 @@ public class PreventRepeatSubmit {
|
|||||||
String jti = SecurityUtils.getJti();
|
String jti = SecurityUtils.getJti();
|
||||||
if (StrUtil.isNotBlank(jti)) {
|
if (StrUtil.isNotBlank(jti)) {
|
||||||
String resubmitLockKey = RESUBMIT_LOCK_PREFIX + jti + ":" + request.getMethod() + "-" + request.getRequestURI();
|
String resubmitLockKey = RESUBMIT_LOCK_PREFIX + jti + ":" + request.getMethod() + "-" + request.getRequestURI();
|
||||||
int expire = preventDuplicateResubmit.expire(); // 防重提交锁过期时间
|
// 防重提交锁过期时间
|
||||||
|
int expire = preventDuplicateResubmit.expire();
|
||||||
RLock lock = redissonClient.getLock(resubmitLockKey);
|
RLock lock = redissonClient.getLock(resubmitLockKey);
|
||||||
boolean lockResult = lock.tryLock(0, expire, TimeUnit.SECONDS); // 获取锁失败,直接返回 false
|
// 获取锁失败,直接返回 false
|
||||||
|
boolean lockResult = lock.tryLock(0, expire, TimeUnit.SECONDS);
|
||||||
if (!lockResult) {
|
if (!lockResult) {
|
||||||
throw new BusinessException(ResultCode.REPEAT_SUBMIT_ERROR); // 抛出重复提交提示信息
|
// 抛出重复提交提示信息
|
||||||
|
throw new BusinessException(ResultCode.REPEAT_SUBMIT_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pjp.proceed();
|
return pjp.proceed();
|
||||||
|
@ -3,7 +3,6 @@ package com.youlai.system.api;
|
|||||||
import com.youlai.common.web.config.FeignDecoderConfig;
|
import com.youlai.common.web.config.FeignDecoderConfig;
|
||||||
import com.youlai.system.api.fallback.UserFeignFallbackClient;
|
import com.youlai.system.api.fallback.UserFeignFallbackClient;
|
||||||
import com.youlai.system.dto.UserAuthInfo;
|
import com.youlai.system.dto.UserAuthInfo;
|
||||||
import com.youlai.common.result.Result;
|
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.youlai</groupId>
|
<groupId>com.youlai</groupId>
|
||||||
<artifactId>common-middleware-redis</artifactId>
|
<artifactId>common-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.youlai.system.handler;
|
package com.youlai.system.handler;
|
||||||
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
import com.alibaba.csp.sentinel.adapter.spring.webmvc_v6x.callback.BlockExceptionHandler;
|
||||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
|
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
|
||||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
|
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
|
||||||
@ -23,7 +23,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
public class DefaultBlockExceptionHandler implements BlockExceptionHandler {
|
public class DefaultBlockExceptionHandler implements BlockExceptionHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception {
|
public void handle(HttpServletRequest request, HttpServletResponse response, String s, BlockException e) throws Exception {
|
||||||
response.setStatus(HttpStatus.OK.value());
|
response.setStatus(HttpStatus.OK.value());
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
response.setContentType("application/json;charset=utf-8");
|
response.setContentType("application/json;charset=utf-8");
|
||||||
|
Loading…
Reference in New Issue
Block a user