Merge branch 'develop' of https://gitee.com/youlaitech/youlai-mall into develop

This commit is contained in:
Ray.Hao 2024-08-31 22:39:10 +08:00
commit a0801c0d4b
17 changed files with 52 additions and 43 deletions

View File

@ -42,6 +42,11 @@
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<!-- 配置中心 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>

View File

@ -10,6 +10,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
* 会员服务启动类
*
* @author ray
* @since 0.0.1
*/
@SpringBootApplication
@EnableDiscoveryClient()

View File

@ -30,13 +30,16 @@ import java.util.stream.Collectors;
* ---- hKey:value <--> skuId 商品1
* ---- hKey:value <--> 商品2
* ---- hKey:value <--> 商品3
*
* @author Ray
* @since 4.0.0
*/
@Service
@Slf4j
@RequiredArgsConstructor
@Slf4j
public class CartServiceImpl implements CartService {
private final RedisTemplate<String, CartItemDTO> redisTemplate;
private final RedisTemplate redisTemplate;
private final SkuFeignClient skuFeignClient;
private final CartConverter cartConverter;
@ -60,7 +63,6 @@ public class CartServiceImpl implements CartService {
List<Long> skuIds = cartItems.stream().map(CartItemDTO::getSkuId).toList();
List<SkuDTO> skuList = skuFeignClient.listSkusByIds(skuIds);
// 创建SKU ID到SkuInfoDto的映射以优化查找性能
Map<Long, SkuDTO> skuIdToSkuInfoMap = skuList.stream()
.collect(Collectors.toMap(SkuDTO::getId, Function.identity()));
@ -158,8 +160,6 @@ public class CartServiceImpl implements CartService {
}
}
/**
* 获取购物车的Hash操作对象
*

View File

@ -88,6 +88,10 @@
<artifactId>common-middleware-seata</artifactId>
</dependency>
<dependency>
<groupId>com.youlai</groupId>
<artifactId>common-middleware-rabbitmq</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -60,12 +60,12 @@
<dependency>
<groupId>com.youlai</groupId>
<artifactId>common-mybatis</artifactId>
<artifactId>common-web</artifactId>
</dependency>
<dependency>
<groupId>com.youlai</groupId>
<artifactId>common-web</artifactId>
<artifactId>common-mybatis</artifactId>
</dependency>
<dependency>

View File

@ -10,6 +10,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
* 营销服务启动类
*
* @author ray
* @since 0.0.1
*/
@SpringBootApplication
@EnableDiscoveryClient

View File

@ -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 = "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)))"),
})

View File

@ -26,7 +26,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.6</version>
<version>3.2.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
@ -36,8 +36,8 @@
<maven.compiler.target>17</maven.compiler.target>
<!-- spring cloud & alibaba -->
<spring-cloud.version>2023.0.0</spring-cloud.version>
<spring-cloud-alibaba.version>2023.0.1.0</spring-cloud-alibaba.version>
<spring-cloud.version>2023.0.3</spring-cloud.version>
<spring-cloud-alibaba.version>2023.0.1.2</spring-cloud-alibaba.version>
<!-- 数据库 & ORM -->
<mysql.version>8.0.28</mysql.version>

View File

@ -84,11 +84,6 @@
<artifactId>common-mybatis</artifactId>
</dependency>
<dependency>
<groupId>com.youlai</groupId>
<artifactId>common-middleware-redis</artifactId>
</dependency>
<dependency>
<groupId>com.youlai</groupId>
<artifactId>common-thirdparty-sms</artifactId>

View File

@ -139,7 +139,7 @@ public class CaptchaAuthenticationProvider implements AuthenticationProvider {
.registeredClient(registeredClient)
.principal(usernamePasswordAuthentication) // 身份验证成功的认证信息(用户名权限等信息)
.authorizationServerContext(AuthorizationServerContextHolder.getContext())
.authorizedScopes(authorizedScopes)
.authorizedScopes(requestedScopes)
.authorizationGrantType(CaptchaAuthenticationToken.CAPTCHA) // 授权方式
.authorizationGrant(passwordAuthenticationToken) // 授权具体对象
;

View File

@ -6,7 +6,6 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
/**
* Redis 配置
*

View File

@ -39,23 +39,27 @@ import java.time.LocalDateTime;
public class MinioOssService implements OssService {
/**
* 服务Endpoint(http://localhost:9000)
* 服务Endpoint
*/
private String endpoint;
/**
* 访问凭据
*/
private String accessKey;
/**
* 凭据密钥
*/
private String secretKey;
/**
* 存储桶名称
*/
private String bucketName;
/**
* 自定义域名(https://oss.youlai.tech)
* 自定义域名
*/
private String customDomain;
@ -75,7 +79,7 @@ public class MinioOssService implements OssService {
* 上传文件
*
* @param file 表单文件对象
* @return
* @return 文件信息
*/
@Override
public FileInfo uploadFile(MultipartFile file) {
@ -97,7 +101,8 @@ public class MinioOssService implements OssService {
// 返回文件路径
String fileUrl;
if (StrUtil.isBlank(customDomain)) { // 未配置自定义域名
// 未配置自定义域名
if (StrUtil.isBlank(customDomain)) {
GetPresignedObjectUrlArgs getPresignedObjectUrlArgs = GetPresignedObjectUrlArgs.builder()
.bucket(bucketName).object(fileName)
.method(Method.GET)
@ -105,7 +110,8 @@ public class MinioOssService implements OssService {
fileUrl = minioClient.getPresignedObjectUrl(getPresignedObjectUrlArgs);
fileUrl = fileUrl.substring(0, fileUrl.indexOf("?"));
} else { // 配置自定义文件路径域名
} else {
// 配置自定义文件路径域名
fileUrl = customDomain + '/' + bucketName + "/" + fileName;
}
@ -122,9 +128,7 @@ public class MinioOssService implements OssService {
/**
* 删除文件
*
* @param filePath 文件路径
* https://oss.youlai.tech/default/20221120/test.jpg
* @return
* @param filePath 文件路径 https://oss.youlai.tech/default/20221120/test.jpg
*/
@Override
public boolean deleteFile(String filePath) {
@ -161,7 +165,7 @@ public class MinioOssService implements OssService {
* Resource: 指定存储桶
* Action: 操作行为
*
* @param bucketName
* @param bucketName 存储桶名称
* @return
*/
private static String publicBucketPolicy(String bucketName) {

View File

@ -18,6 +18,11 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
@ -28,12 +33,6 @@
<artifactId>feign-httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>

View File

@ -28,8 +28,8 @@ import java.util.concurrent.TimeUnit;
*/
@Aspect
@Component
@Slf4j
@RequiredArgsConstructor
@Slf4j
public class PreventRepeatSubmit {
private final RedissonClient redissonClient;
@ -41,10 +41,9 @@ public class PreventRepeatSubmit {
*/
@Pointcut("@annotation(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 {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
@ -52,11 +51,14 @@ public class PreventRepeatSubmit {
String jti = SecurityUtils.getJti();
if (StrUtil.isNotBlank(jti)) {
String resubmitLockKey = RESUBMIT_LOCK_PREFIX + jti + ":" + request.getMethod() + "-" + request.getRequestURI();
int expire = preventDuplicateResubmit.expire(); // 防重提交锁过期时间
// 防重提交锁过期时间
int expire = preventDuplicateResubmit.expire();
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) {
throw new BusinessException(ResultCode.REPEAT_SUBMIT_ERROR); // 抛出重复提交提示信息
// 抛出重复提交提示信息
throw new BusinessException(ResultCode.REPEAT_SUBMIT_ERROR);
}
}
return pjp.proceed();

View File

@ -3,7 +3,6 @@ package com.youlai.system.api;
import com.youlai.common.web.config.FeignDecoderConfig;
import com.youlai.system.api.fallback.UserFeignFallbackClient;
import com.youlai.system.dto.UserAuthInfo;
import com.youlai.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

View File

@ -88,7 +88,7 @@
<dependency>
<groupId>com.youlai</groupId>
<artifactId>common-middleware-redis</artifactId>
<artifactId>common-web</artifactId>
</dependency>
<dependency>

View File

@ -1,6 +1,6 @@
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.degrade.DegradeException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
@ -23,7 +23,7 @@ import jakarta.servlet.http.HttpServletResponse;
public class DefaultBlockExceptionHandler implements BlockExceptionHandler {
@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.setCharacterEncoding("UTF-8");
response.setContentType("application/json;charset=utf-8");