feat(商城): 1.4.0 版本发布,更新内容如下

1. 商城搜索栏,新增搜索建议,支持拼音搜索
2. 标签栏购物车新增商品数量为微标
3. 商城购物车新增商品失效处理
4. 购物车页面、订单详情页面样式优化
5. 标签栏切换bug修复
master
wayn 12 months ago
parent db7b14ff19
commit afd46d5e06

@ -15,7 +15,7 @@
</modules> </modules>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<artifactId>waynboot-mall</artifactId> <artifactId>waynboot-mall</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>waynboot</name> <name>waynboot</name>
<description>waynboot mall商城</description> <description>waynboot mall商城</description>

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>waynboot-mall</artifactId> <artifactId>waynboot-mall</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -48,7 +48,7 @@
<dependency> <dependency>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<artifactId>waynboot-common</artifactId> <artifactId>waynboot-common</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.elasticsearch</groupId> <groupId>org.elasticsearch</groupId>
@ -68,7 +68,7 @@
<dependency> <dependency>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<artifactId>waynboot-message-core</artifactId> <artifactId>waynboot-message-core</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -85,13 +85,6 @@
</exclusions> </exclusions>
</dependency> </dependency>
<!-- 滑块验证码 -->
<!--<dependency>
<groupId>com.anji-plus</groupId>
<artifactId>spring-boot-starter-captcha</artifactId>
<version>1.3.0</version>
</dependency>-->
<dependency> <dependency>
<groupId>com.hierynomus</groupId> <groupId>com.hierynomus</groupId>
<artifactId>sshj</artifactId> <artifactId>sshj</artifactId>

@ -5,11 +5,11 @@
<parent> <parent>
<artifactId>waynboot-mall</artifactId> <artifactId>waynboot-mall</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>waynboot-common</artifactId> <artifactId>waynboot-common</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
<dependencies> <dependencies>
<dependency> <dependency>
@ -148,13 +148,13 @@
<dependency> <dependency>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<artifactId>waynboot-data-redis</artifactId> <artifactId>waynboot-data-redis</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<artifactId>waynboot-data-elastic</artifactId> <artifactId>waynboot-data-elastic</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
</dependency> </dependency>
</dependencies> </dependencies>

@ -3,6 +3,8 @@ package com.wayn.common.core.service.shop;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.wayn.common.core.domain.shop.GoodsProduct; import com.wayn.common.core.domain.shop.GoodsProduct;
import java.util.List;
/** /**
* *
* *
@ -26,4 +28,6 @@ public interface IGoodsProductService extends IService<GoodsProduct> {
* @return boolean * @return boolean
*/ */
boolean addStock(Long productId, Integer number); boolean addStock(Long productId, Integer number);
List<GoodsProduct> selectProductByIds(List<Long> productIds);
} }

@ -1,5 +1,7 @@
package com.wayn.common.core.service.shop.impl; package com.wayn.common.core.service.shop.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wayn.common.core.domain.shop.GoodsProduct; import com.wayn.common.core.domain.shop.GoodsProduct;
import com.wayn.common.core.mapper.shop.GoodsProductMapper; import com.wayn.common.core.mapper.shop.GoodsProductMapper;
@ -7,6 +9,8 @@ import com.wayn.common.core.service.shop.IGoodsProductService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* *
* *
@ -24,6 +28,13 @@ public class GoodsProductServiceImpl extends ServiceImpl<GoodsProductMapper, Goo
return goodsProductMapper.addStock(productId, number); return goodsProductMapper.addStock(productId, number);
} }
@Override
public List<GoodsProduct> selectProductByIds(List<Long> productIds) {
LambdaQueryWrapper<GoodsProduct> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.in(GoodsProduct::getId, productIds);
return list(queryWrapper);
}
@Override @Override
public boolean reduceStock(Long productId, Integer number) { public boolean reduceStock(Long productId, Integer number) {
return goodsProductMapper.reduceStock(productId, number); return goodsProductMapper.reduceStock(productId, number);

@ -44,6 +44,7 @@ public enum ReturnCodeEnum {
ORDER_ERROR_CART_EMPTY_ERROR(5013, "下单失败,当前购物车无数据"), ORDER_ERROR_CART_EMPTY_ERROR(5013, "下单失败,当前购物车无数据"),
ORDER_ERROR_ADDRESS_ERROR(50143, "下单失败,当前地址错误"), ORDER_ERROR_ADDRESS_ERROR(50143, "下单失败,当前地址错误"),
ORDER_REFUND_ERROR(50144, "退款失败"), ORDER_REFUND_ERROR(50144, "退款失败"),
ORDER_ERROR_STOCK_NOT_ENOUGH(50145, "%s,%s 库存不足,请重新选择商品"),
// 用户错误 // 用户错误
USER_NOT_EXISTS_ERROR(5101, "用户不存在"), USER_NOT_EXISTS_ERROR(5101, "用户不存在"),

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>waynboot-mall</artifactId> <artifactId>waynboot-mall</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>waynboot-data</artifactId> <artifactId>waynboot-data</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>waynboot-data</artifactId> <artifactId>waynboot-data</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

@ -1,23 +0,0 @@
package com.wayn.data.redis.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class LettuceConfig implements InitializingBean {
@Autowired
private RedisConnectionFactory redisConnectionFactory;
@Override
public void afterPropertiesSet() {
if (redisConnectionFactory instanceof LettuceConnectionFactory c) {
c.setValidateConnection(true);
}
}
}

@ -16,6 +16,7 @@ public enum RedisKeyEnum {
EMAIL_CONSUMER_MAP(CacheConstants.CACHE_PREFIX + "email_consumer_map", 60), EMAIL_CONSUMER_MAP(CacheConstants.CACHE_PREFIX + "email_consumer_map", 60),
ORDER_CONSUMER_MAP(CacheConstants.CACHE_PREFIX + "order_consumer_map", 60), ORDER_CONSUMER_MAP(CacheConstants.CACHE_PREFIX + "order_consumer_map", 60),
UNPAID_ORDER_CONSUMER_MAP(CacheConstants.CACHE_PREFIX + "unpaid_order_consumer_map", 60), UNPAID_ORDER_CONSUMER_MAP(CacheConstants.CACHE_PREFIX + "unpaid_order_consumer_map", 60),
ORDER_RESULT_KEY(CacheConstants.CACHE_PREFIX + "order_result_key:", 60),
; ;
private String key; private String key;

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>waynboot-mall</artifactId> <artifactId>waynboot-mall</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>waynboot-job</artifactId> <artifactId>waynboot-job</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -23,7 +23,7 @@
<dependency> <dependency>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<artifactId>waynboot-common</artifactId> <artifactId>waynboot-common</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.elasticsearch</groupId> <groupId>org.elasticsearch</groupId>

@ -5,11 +5,11 @@
<parent> <parent>
<artifactId>waynboot-mall</artifactId> <artifactId>waynboot-mall</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>waynboot-message-consumer</artifactId> <artifactId>waynboot-message-consumer</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
<properties> <properties>
<main-class>com.wayn.MessageApplication</main-class> <main-class>com.wayn.MessageApplication</main-class>
@ -19,12 +19,12 @@
<dependency> <dependency>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<artifactId>waynboot-message-core</artifactId> <artifactId>waynboot-message-core</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<artifactId>waynboot-data-redis</artifactId> <artifactId>waynboot-data-redis</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
</dependency> </dependency>
<dependency> <dependency>

@ -22,7 +22,7 @@ public class MobileApiImpl implements MobileApi {
@Resource @Resource
private RestTemplate restTemplate; private RestTemplate restTemplate;
@Retryable(value = Exception.class, maxAttempts = 3, backoff = @Backoff(delay = 2000L, multiplier = 1.5)) @Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000L, multiplier = 1.5))
@Override @Override
public void submitOrder(String body) throws Exception { public void submitOrder(String body) throws Exception {
JSONObject msgObject = JSONObject.parseObject(body); JSONObject msgObject = JSONObject.parseObject(body);
@ -45,7 +45,7 @@ public class MobileApiImpl implements MobileApi {
} }
} }
@Retryable(value = Exception.class, maxAttempts = 3, backoff = @Backoff(delay = 2000L, multiplier = 1.5)) @Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000L, multiplier = 1.5))
@Override @Override
public void unpaidOrder(String body) throws Exception { public void unpaidOrder(String body) throws Exception {
JSONObject msgObject = JSONObject.parseObject(body); JSONObject msgObject = JSONObject.parseObject(body);
@ -69,7 +69,7 @@ public class MobileApiImpl implements MobileApi {
} }
} }
@Retryable(value = Exception.class, maxAttempts = 3, backoff = @Backoff(delay = 2000L, multiplier = 1.5)) @Retryable(maxAttempts = 3, backoff = @Backoff(delay = 2000L, multiplier = 1.5))
@Override @Override
public void sendEmail(String body) throws Exception { public void sendEmail(String body) throws Exception {
JSONObject msgObject = JSONObject.parseObject(body); JSONObject msgObject = JSONObject.parseObject(body);

@ -5,11 +5,11 @@
<parent> <parent>
<artifactId>waynboot-mall</artifactId> <artifactId>waynboot-mall</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>waynboot-message-core</artifactId> <artifactId>waynboot-message-core</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
<dependencies> <dependencies>
<dependency> <dependency>

@ -5,11 +5,11 @@
<parent> <parent>
<artifactId>waynboot-mall</artifactId> <artifactId>waynboot-mall</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>waynboot-mobile-api</artifactId> <artifactId>waynboot-mobile-api</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
<properties> <properties>
<aliyun-docker-namespace>wayn111</aliyun-docker-namespace> <aliyun-docker-namespace>wayn111</aliyun-docker-namespace>
@ -26,13 +26,13 @@
<dependency> <dependency>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<artifactId>waynboot-common</artifactId> <artifactId>waynboot-common</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<artifactId>waynboot-message-core</artifactId> <artifactId>waynboot-message-core</artifactId>
<version>1.3.0</version> <version>1.4.0</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

@ -38,7 +38,6 @@ public class CartController extends BaseController {
Long userId = MobileSecurityUtils.getUserId(); Long userId = MobileSecurityUtils.getUserId();
Page<Cart> page = getPage(); Page<Cart> page = getPage();
R list = iCartService.list(page, userId); R list = iCartService.list(page, userId);
log.info("cart list:{}", JSON.toJSON(list));
return list; return list;
} }
@ -59,7 +58,7 @@ public class CartController extends BaseController {
@PostMapping("changeNum/{cartId}/{number}") @PostMapping("changeNum/{cartId}/{number}")
public R changeNum(@PathVariable Long cartId, @PathVariable Integer number) { public R changeNum(@PathVariable Long cartId, @PathVariable Integer number) {
return iCartService.changeNum(cartId, number); return R.result(iCartService.changeNum(cartId, number));
} }
@DeleteMapping("{cartId}") @DeleteMapping("{cartId}")

@ -1,26 +1,45 @@
package com.wayn.mobile.api.controller.callback; package com.wayn.mobile.api.controller.callback;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.wayn.common.exception.BusinessException;
import com.wayn.common.util.R; import com.wayn.common.util.R;
import com.wayn.data.redis.constant.RedisKeyEnum;
import com.wayn.data.redis.manager.RedisCache;
import com.wayn.message.core.dto.OrderDTO; import com.wayn.message.core.dto.OrderDTO;
import com.wayn.mobile.api.service.IMobileOrderService; import com.wayn.mobile.api.service.IMobileOrderService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.io.UnsupportedEncodingException; @Slf4j
@RestController @RestController
@AllArgsConstructor @AllArgsConstructor
@RequestMapping("callback/order") @RequestMapping("callback/order")
public class SubmitOrderController { public class SubmitOrderController {
private IMobileOrderService iMobileOrderService; private IMobileOrderService iMobileOrderService;
private RedisCache redisCache;
@PostMapping("submit") @PostMapping("submit")
public R submit(String order) throws UnsupportedEncodingException { public R submit(String order) {
log.info("callback order request is {}", order);
OrderDTO orderDTO = JSON.parseObject(order, OrderDTO.class); OrderDTO orderDTO = JSON.parseObject(order, OrderDTO.class);
return iMobileOrderService.submit(orderDTO); try {
iMobileOrderService.submit(orderDTO);
redisCache.setCacheObject(RedisKeyEnum.ORDER_RESULT_KEY.getKey(orderDTO.getOrderSn()),
"success", RedisKeyEnum.ORDER_RESULT_KEY.getExpireSecond());
return R.success();
} catch (Exception e) {
String errorMsg = "error";
if (e instanceof BusinessException businessException) {
errorMsg = businessException.getMsg();
}
redisCache.setCacheObject(RedisKeyEnum.ORDER_RESULT_KEY.getKey(orderDTO.getOrderSn()),
errorMsg, RedisKeyEnum.ORDER_RESULT_KEY.getExpireSecond());
log.error(e.getMessage(), e);
return R.error();
}
} }
} }

@ -56,7 +56,7 @@ public interface ICartService extends IService<Cart> {
* @param number * @param number
* @return r * @return r
*/ */
R changeNum(Long cartId, Integer number); Boolean changeNum(Long cartId, Integer number);
/** /**
* *

@ -24,7 +24,7 @@ public interface IMobileOrderService extends IService<Order> {
* @param orderDTO DTO * @param orderDTO DTO
* @return R * @return R
*/ */
R submit(OrderDTO orderDTO) throws UnsupportedEncodingException; void submit(OrderDTO orderDTO) throws UnsupportedEncodingException;
/** /**

@ -25,6 +25,7 @@ import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
@ -52,7 +53,7 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements IC
private IGoodsProductService iGoodsProductService; private IGoodsProductService iGoodsProductService;
private CartMapper cartMapper; private CartMapper cartMapper;
private ThreadPoolTaskExecutor commonThreadPoolTaskExecutor;
@Override @Override
public Cart checkExistsGoods(Long userId, Long goodsId, Long productId) { public Cart checkExistsGoods(Long userId, Long goodsId, Long productId) {
return getOne(new QueryWrapper<Cart>() return getOne(new QueryWrapper<Cart>()
@ -131,25 +132,34 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements IC
public R list(Page<Cart> page, Long userId) { public R list(Page<Cart> page, Long userId) {
IPage<Cart> goodsIPage = cartMapper.selectCartPageList(page, userId); IPage<Cart> goodsIPage = cartMapper.selectCartPageList(page, userId);
List<Cart> cartList = goodsIPage.getRecords(); List<Cart> cartList = goodsIPage.getRecords();
List<Long> goodsIdList = cartList.stream().map(Cart::getGoodsId).collect(Collectors.toList()); List<Long> goodsIdList = cartList.stream().map(Cart::getGoodsId).toList();
List<Long> productIdList = cartList.stream().map(Cart::getProductId).toList();
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
if (CollectionUtils.isEmpty(goodsIdList)) { if (CollectionUtils.isEmpty(goodsIdList)) {
return R.success().add("data", array); return R.success().add("data", array);
} }
Map<Long, Goods> goodsIdMap = iGoodsService.selectGoodsByIds(goodsIdList).stream().collect(Collectors.toMap(Goods::getId, goods -> goods)); // Map<Long, Goods> goodsIdMap = iGoodsService.selectGoodsByIds(goodsIdList).stream()
// .collect(Collectors.toMap(Goods::getId, goods -> goods));
Map<Long, GoodsProduct> productIdMap = iGoodsProductService.selectProductByIds(productIdList).stream()
.collect(Collectors.toMap(GoodsProduct::getId, product -> product));
for (Cart cart : cartList) { for (Cart cart : cartList) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
try { try {
MyBeanUtil.copyProperties2Map(cart, jsonObject); GoodsProduct product = productIdMap.get(cart.getProductId());
Goods goods = goodsIdMap.get(cart.getGoodsId()); Integer number = cart.getNumber();
if (goods.getIsNew()) { Integer maxNumber = product.getNumber();
jsonObject.put("tag", "新品"); if (maxNumber < number) {
} commonThreadPoolTaskExecutor.execute(() -> {
if (goods.getIsHot()) { this.lambdaUpdate()
jsonObject.put("tag", "热品"); .set(Cart::getChecked, false)
.eq(Cart::getId, cart.getId())
.update();
});
} }
MyBeanUtil.copyProperties2Map(cart, jsonObject);
jsonObject.put("maxNum", maxNumber);
} catch (IntrospectionException | InvocationTargetException | IllegalAccessException e) { } catch (IntrospectionException | InvocationTargetException | IllegalAccessException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
@ -159,16 +169,12 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements IC
} }
@Override @Override
public R changeNum(Long cartId, Integer number) { public Boolean changeNum(Long cartId, Integer number) {
Cart cart = getById(cartId); // todo 并发问题,后续可以通过 mq 实现
Long productId = cart.getProductId(); commonThreadPoolTaskExecutor.execute(() -> {
GoodsProduct goodsProduct = iGoodsProductService.getById(productId); lambdaUpdate().setSql("number = " + number).eq(Cart::getId, cartId).update();
Integer productNumber = goodsProduct.getNumber(); });
if (number > productNumber) { return true;
throw new BusinessException(String.format("库存不足,该商品只剩%d件了", productNumber));
}
boolean update = lambdaUpdate().setSql("number = " + number).eq(Cart::getId, cartId).update();
return R.result(update);
} }
@Override @Override

@ -23,6 +23,7 @@ import com.wayn.common.exception.BusinessException;
import com.wayn.common.util.IdUtil; import com.wayn.common.util.IdUtil;
import com.wayn.common.util.R; import com.wayn.common.util.R;
import com.wayn.common.util.bean.MyBeanUtil; import com.wayn.common.util.bean.MyBeanUtil;
import com.wayn.data.redis.constant.RedisKeyEnum;
import com.wayn.data.redis.manager.RedisCache; import com.wayn.data.redis.manager.RedisCache;
import com.wayn.message.core.constant.MQConstants; import com.wayn.message.core.constant.MQConstants;
import com.wayn.message.core.dto.OrderDTO; import com.wayn.message.core.dto.OrderDTO;
@ -236,14 +237,15 @@ public class MobileOrderServiceImpl extends ServiceImpl<OrderMapper, Order> impl
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public R submit(OrderDTO orderDTO) throws UnsupportedEncodingException { public void submit(OrderDTO orderDTO) throws UnsupportedEncodingException {
Long userId = orderDTO.getUserId(); Long userId = orderDTO.getUserId();
String orderSn = orderDTO.getOrderSn();
// 获取用户地址 // 获取用户地址
Long addressId = orderDTO.getAddressId(); Long addressId = orderDTO.getAddressId();
Address checkedAddress; Address checkedAddress;
if (Objects.isNull(addressId)) { if (Objects.isNull(addressId)) {
throw new BusinessException("收获地址为空,请求参数" + JSON.toJSONString(orderDTO)); throw new BusinessException(ReturnCodeEnum.ORDER_ERROR_ADDRESS_ERROR);
} }
checkedAddress = iAddressService.getById(addressId); checkedAddress = iAddressService.getById(addressId);
@ -257,6 +259,8 @@ public class MobileOrderServiceImpl extends ServiceImpl<OrderMapper, Order> impl
} }
if (checkedGoodsList.isEmpty()) { if (checkedGoodsList.isEmpty()) {
redisCache.setCacheObject(RedisKeyEnum.ORDER_RESULT_KEY.getKey(orderSn), "收获地址为空",
RedisKeyEnum.ORDER_RESULT_KEY.getExpireSecond());
throw new BusinessException(ReturnCodeEnum.ORDER_ERROR_CART_EMPTY_ERROR); throw new BusinessException(ReturnCodeEnum.ORDER_ERROR_CART_EMPTY_ERROR);
} }
@ -274,10 +278,11 @@ public class MobileOrderServiceImpl extends ServiceImpl<OrderMapper, Order> impl
Goods goods = iGoodsService.getById(goodsId); Goods goods = iGoodsService.getById(goodsId);
String goodsName = goods.getName(); String goodsName = goods.getName();
String[] specifications = product.getSpecifications(); String[] specifications = product.getSpecifications();
throw new BusinessException(String.format("%s,%s 库存不足", goodsName, StringUtils.join(specifications, " "))); throw new BusinessException(String.format(ReturnCodeEnum.ORDER_ERROR_STOCK_NOT_ENOUGH.getMsg(),
goodsName, StringUtils.join(specifications, " ")));
} }
if (!iGoodsProductService.reduceStock(productId, checkGoods.getNumber())) { if (!iGoodsProductService.reduceStock(productId, checkGoods.getNumber())) {
throw new BusinessException("商品货品库存减少失败"); throw new BusinessException(ReturnCodeEnum.ORDER_SUBMIT_ERROR);
} }
} }
@ -319,7 +324,7 @@ public class MobileOrderServiceImpl extends ServiceImpl<OrderMapper, Order> impl
order.setActualPrice(actualPrice); order.setActualPrice(actualPrice);
order.setCreateTime(new Date()); order.setCreateTime(new Date());
if (!save(order)) { if (!save(order)) {
throw new BusinessException("订单创建失败" + JSON.toJSONString(order)); throw new BusinessException(ReturnCodeEnum.ORDER_SUBMIT_ERROR);
} }
Long orderId = order.getId(); Long orderId = order.getId();
@ -341,7 +346,7 @@ public class MobileOrderServiceImpl extends ServiceImpl<OrderMapper, Order> impl
orderGoodsList.add(orderGoods); orderGoodsList.add(orderGoods);
} }
if (!iOrderGoodsService.saveBatch(orderGoodsList)) { if (!iOrderGoodsService.saveBatch(orderGoodsList)) {
throw new BusinessException("添加订单商品表项失败" + JSON.toJSONString(orderGoodsList)); throw new BusinessException(ReturnCodeEnum.ORDER_SUBMIT_ERROR);
} }
// 删除购物车里面的商品信息 // 删除购物车里面的商品信息
@ -365,18 +370,16 @@ public class MobileOrderServiceImpl extends ServiceImpl<OrderMapper, Order> impl
messagePostProcessor.getMessageProperties().setDelay(Math.toIntExact(delayTime)); messagePostProcessor.getMessageProperties().setDelay(Math.toIntExact(delayTime));
return messagePostProcessor; return messagePostProcessor;
}); });
return R.success().add("orderId", order.getId());
} }
@Override @Override
public R searchResult(String orderSn) { public R searchResult(String orderSn) {
Order order = getOne(new QueryWrapper<Order>().eq("order_sn", orderSn)); String value = redisCache.getCacheObject(RedisKeyEnum.ORDER_RESULT_KEY.getKey(orderSn));
if (order == null) { if (value == null) {
return R.error(ReturnCodeEnum.ORDER_NOT_EXISTS_ERROR); return R.error(ReturnCodeEnum.ORDER_SUBMIT_ERROR);
} }
// 检查这个订单是否已经处理过 if (!"success".equals(value)) {
if (!OrderUtil.isCreateStatus(order)) { return R.error(ReturnCodeEnum.ORDER_SUBMIT_ERROR.getCode(), value);
return R.error(ReturnCodeEnum.ORDER_HAS_CREATED_ERROR);
} }
return R.success(); return R.success();
} }

@ -52,8 +52,8 @@ public class SecurityConfig {
.authorizeHttpRequests( .authorizeHttpRequests(
registry -> registry registry -> registry
.requestMatchers("favicon.ico", "/actuator/**", "/login", "/registry", .requestMatchers("favicon.ico", "/actuator/**", "/login", "/registry",
"/search/**", "/sendEmailCode", "/test/**", "/seckill/**", "/captcha").anonymous() "/sendEmailCode", "/test/**", "/seckill/**", "/captcha").anonymous()
.requestMatchers("/home/**", "/category/**", "/comment/**", .requestMatchers("/home/**", "/category/**", "/comment/**", "/search/**",
"/goods/detail/**", "/cart/goodsCount", "/diamond/**").permitAll() "/goods/detail/**", "/cart/goodsCount", "/diamond/**").permitAll()
.requestMatchers("/upload/**").anonymous() .requestMatchers("/upload/**").anonymous()
.requestMatchers("/common/download**").anonymous() .requestMatchers("/common/download**").anonymous()

@ -29,8 +29,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
private TokenService tokenService; private TokenService tokenService;
@Override @Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) {
throws ServletException, IOException {
try { try {
// 入口传入请求ID // 入口传入请求ID
ThreadMdcUtil.setTraceIdIfAbsent(); ThreadMdcUtil.setTraceIdIfAbsent();
@ -43,6 +42,8 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
SecurityContextHolder.getContext().setAuthentication(authenticationToken); SecurityContextHolder.getContext().setAuthentication(authenticationToken);
} }
chain.doFilter(request, response); chain.doFilter(request, response);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally { } finally {
// 出口移除请求ID // 出口移除请求ID
ThreadMdcUtil.removeTraceId(); ThreadMdcUtil.removeTraceId();

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>waynboot-mall</artifactId> <artifactId>waynboot-mall</artifactId>
<groupId>com.wayn</groupId> <groupId>com.wayn</groupId>
<version>1.3.0</version> <version>1.4.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

Loading…
Cancel
Save