Merge remote-tracking branch 'origin/master'

master
waynaqua 12 months ago
commit 9969a1683f

@ -0,0 +1,57 @@
# Elasticsearch plugin descriptor file
# This file must exist as 'plugin-descriptor.properties' at
# the root directory of all plugins.
#
# A plugin can be 'site', 'jvm', or both.
#
### example site plugin for "foo":
#
# foo.zip <-- zip file for the plugin, with this structure:
# _site/ <-- the contents that will be served
# plugin-descriptor.properties <-- example contents below:
#
# site=true
# description=My cool plugin
# version=1.0
#
### example jvm plugin for "foo"
#
# foo.zip <-- zip file for the plugin, with this structure:
# <arbitrary name1>.jar <-- classes, resources, dependencies
# <arbitrary nameN>.jar <-- any number of jars
# plugin-descriptor.properties <-- example contents below:
#
# jvm=true
# classname=foo.bar.BazPlugin
# description=My cool plugin
# version=2.0.0-rc1
# elasticsearch.version=2.0
# java.version=1.7
#
### mandatory elements for all plugins:
#
# 'description': simple summary of the plugin
description=Pinyin Analysis for Elasticsearch
#
# 'version': plugin's version
version=7.14.0
#
# 'name': the plugin name
name=analysis-pinyin
#
# 'classname': the name of the class to load, fully-qualified.
classname=org.elasticsearch.plugin.analysis.pinyin.AnalysisPinyinPlugin
#
# 'java.version' version of java the code is built against
# use the system property java.specification.version
# version string must be a sequence of nonnegative decimal integers
# separated by "."'s and may have leading zeros
java.version=1.8
#
# 'elasticsearch.version' version of elasticsearch compiled against
# You will have to release a new version of the plugin for each new
# elasticsearch release. This version is checked when the plugin
# is loaded so Elasticsearch will refuse to start in the presence of
# plugins with the incorrect elasticsearch.version.
elasticsearch.version=7.14.0

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

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

@ -96,6 +96,7 @@ public class GoodsController extends BaseController {
elasticEntity.setId(goods.getId().toString());
map.put("id", goods.getId());
map.put("name", goods.getName());
map.put("pyname", goods.getName());
map.put("sales", goods.getActualSales() + goods.getVirtualSales());
map.put("isHot", goods.getIsHot());
map.put("isNew", goods.getIsNew());

@ -7,12 +7,20 @@
"type": "text",
"analyzer": "ik_max_word",
"fields": {
"suggest": {
"kw": {
"type": "completion",
"analyzer": "ik_max_word"
"analyzer": "keyword"
},
"py": {
"type": "completion",
"analyzer": "pinyin"
}
}
},
"pyname": {
"type": "text",
"analyzer": "pinyin"
},
"sales": {
"type": "integer"
},

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

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

@ -1,5 +1,7 @@
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.wayn.common.core.domain.shop.GoodsProduct;
import com.wayn.common.core.mapper.shop.GoodsProductMapper;
@ -7,6 +9,8 @@ import com.wayn.common.core.service.shop.IGoodsProductService;
import lombok.AllArgsConstructor;
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);
}
@Override
public List<GoodsProduct> selectProductByIds(List<Long> productIds) {
LambdaQueryWrapper<GoodsProduct> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.in(GoodsProduct::getId, productIds);
return list(queryWrapper);
}
@Override
public boolean reduceStock(Long productId, Integer number) {
return goodsProductMapper.reduceStock(productId, number);

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

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

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

@ -5,7 +5,7 @@
<parent>
<artifactId>waynboot-data</artifactId>
<groupId>com.wayn</groupId>
<version>1.3.0</version>
<version>1.4.0</version>
</parent>
<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),
ORDER_CONSUMER_MAP(CacheConstants.CACHE_PREFIX + "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;

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

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

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

@ -22,7 +22,7 @@ public class MobileApiImpl implements MobileApi {
@Resource
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
public void submitOrder(String body) throws Exception {
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
public void unpaidOrder(String body) throws Exception {
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
public void sendEmail(String body) throws Exception {
JSONObject msgObject = JSONObject.parseObject(body);

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

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

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

@ -65,7 +65,7 @@ public class SearchController extends BaseController {
@GetMapping("sugguest")
public R sugguest(SearchVO searchVO) throws IOException {
String keyword = searchVO.getKeyword();
String suggestField = "name.suggest";
String suggestField = "name.py";
String suggestName = "my-suggest";
SuggestionBuilder<CompletionSuggestionBuilder> termSuggestionBuilder = SuggestBuilders.completionSuggestion(suggestField)
.prefix(keyword)
@ -89,20 +89,19 @@ public class SearchController extends BaseController {
Boolean isPrice = searchVO.getIsPrice();
Boolean isSales = searchVO.getIsSales();
String orderBy = searchVO.getOrderBy();
SearchHistory searchHistory = new SearchHistory();
if (memberId != null && StringUtils.isNotEmpty(keyword)) {
searchHistory.setCreateTime(LocalDateTime.now());
searchHistory.setUserId(memberId);
searchHistory.setKeyword(keyword);
}
Page<SearchVO> page = getPage();
// 查询包含关键字、已上架商品
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
MatchQueryBuilder matchFiler = QueryBuilders.matchQuery("isOnSale", true);
MatchQueryBuilder matchQuery = QueryBuilders.matchQuery("name", keyword);
MatchQueryBuilder pymatchQuery = QueryBuilders.matchQuery("pyname", keyword);
MatchPhraseQueryBuilder matchPhraseQueryBuilder = QueryBuilders.matchPhraseQuery("keyword", keyword);
boolQueryBuilder.filter(matchFiler).should(matchQuery).should(matchPhraseQueryBuilder).minimumShouldMatch(1);
boolQueryBuilder.filter(matchFiler).should(matchQuery)
.should(pymatchQuery)
.should(matchPhraseQueryBuilder)
.minimumShouldMatch(1);
searchSourceBuilder.timeout(new TimeValue(10, TimeUnit.SECONDS));
// 按是否新品排序
if (isNew) {
@ -153,9 +152,15 @@ public class SearchController extends BaseController {
AsyncManager.me().execute(new TimerTask() {
@Override
public void run() {
SearchHistory searchHistory = new SearchHistory();
if (memberId != null && StringUtils.isNotEmpty(keyword)) {
searchHistory.setCreateTime(LocalDateTime.now());
searchHistory.setUserId(memberId);
searchHistory.setKeyword(keyword);
searchHistory.setHasGoods(true);
iSearchHistoryService.save(searchHistory);
}
}
});
}
return R.success().add("goods", returnGoodsList);

@ -1,26 +1,45 @@
package com.wayn.mobile.api.controller.callback;
import com.alibaba.fastjson.JSON;
import com.wayn.common.exception.BusinessException;
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.mobile.api.service.IMobileOrderService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.UnsupportedEncodingException;
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("callback/order")
public class SubmitOrderController {
private IMobileOrderService iMobileOrderService;
private RedisCache redisCache;
@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);
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
* @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
* @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.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import java.beans.IntrospectionException;
@ -52,7 +53,7 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements IC
private IGoodsProductService iGoodsProductService;
private CartMapper cartMapper;
private ThreadPoolTaskExecutor commonThreadPoolTaskExecutor;
@Override
public Cart checkExistsGoods(Long userId, Long goodsId, Long productId) {
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) {
IPage<Cart> goodsIPage = cartMapper.selectCartPageList(page, userId);
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();
if (CollectionUtils.isEmpty(goodsIdList)) {
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) {
JSONObject jsonObject = new JSONObject();
try {
MyBeanUtil.copyProperties2Map(cart, jsonObject);
Goods goods = goodsIdMap.get(cart.getGoodsId());
if (goods.getIsNew()) {
jsonObject.put("tag", "新品");
}
if (goods.getIsHot()) {
jsonObject.put("tag", "热品");
GoodsProduct product = productIdMap.get(cart.getProductId());
Integer number = cart.getNumber();
Integer maxNumber = product.getNumber();
if (maxNumber < number) {
commonThreadPoolTaskExecutor.execute(() -> {
this.lambdaUpdate()
.set(Cart::getChecked, false)
.eq(Cart::getId, cart.getId())
.update();
});
}
MyBeanUtil.copyProperties2Map(cart, jsonObject);
jsonObject.put("maxNum", maxNumber);
} catch (IntrospectionException | InvocationTargetException | IllegalAccessException e) {
log.error(e.getMessage(), e);
}
@ -159,16 +169,12 @@ public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements IC
}
@Override
public R changeNum(Long cartId, Integer number) {
Cart cart = getById(cartId);
Long productId = cart.getProductId();
GoodsProduct goodsProduct = iGoodsProductService.getById(productId);
Integer productNumber = goodsProduct.getNumber();
if (number > productNumber) {
throw new BusinessException(String.format("库存不足,该商品只剩%d件了", productNumber));
}
boolean update = lambdaUpdate().setSql("number = " + number).eq(Cart::getId, cartId).update();
return R.result(update);
public Boolean changeNum(Long cartId, Integer number) {
// todo 并发问题,后续可以通过 mq 实现
commonThreadPoolTaskExecutor.execute(() -> {
lambdaUpdate().setSql("number = " + number).eq(Cart::getId, cartId).update();
});
return true;
}
@Override

@ -23,6 +23,7 @@ import com.wayn.common.exception.BusinessException;
import com.wayn.common.util.IdUtil;
import com.wayn.common.util.R;
import com.wayn.common.util.bean.MyBeanUtil;
import com.wayn.data.redis.constant.RedisKeyEnum;
import com.wayn.data.redis.manager.RedisCache;
import com.wayn.message.core.constant.MQConstants;
import com.wayn.message.core.dto.OrderDTO;
@ -236,14 +237,15 @@ public class MobileOrderServiceImpl extends ServiceImpl<OrderMapper, Order> impl
@Override
@Transactional(rollbackFor = Exception.class)
public R submit(OrderDTO orderDTO) throws UnsupportedEncodingException {
public void submit(OrderDTO orderDTO) throws UnsupportedEncodingException {
Long userId = orderDTO.getUserId();
String orderSn = orderDTO.getOrderSn();
// 获取用户地址
Long addressId = orderDTO.getAddressId();
Address checkedAddress;
if (Objects.isNull(addressId)) {
throw new BusinessException("收获地址为空,请求参数" + JSON.toJSONString(orderDTO));
throw new BusinessException(ReturnCodeEnum.ORDER_ERROR_ADDRESS_ERROR);
}
checkedAddress = iAddressService.getById(addressId);
@ -257,6 +259,8 @@ public class MobileOrderServiceImpl extends ServiceImpl<OrderMapper, Order> impl
}
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);
}
@ -274,10 +278,11 @@ public class MobileOrderServiceImpl extends ServiceImpl<OrderMapper, Order> impl
Goods goods = iGoodsService.getById(goodsId);
String goodsName = goods.getName();
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())) {
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.setCreateTime(new Date());
if (!save(order)) {
throw new BusinessException("订单创建失败" + JSON.toJSONString(order));
throw new BusinessException(ReturnCodeEnum.ORDER_SUBMIT_ERROR);
}
Long orderId = order.getId();
@ -341,7 +346,7 @@ public class MobileOrderServiceImpl extends ServiceImpl<OrderMapper, Order> impl
orderGoodsList.add(orderGoods);
}
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));
return messagePostProcessor;
});
return R.success().add("orderId", order.getId());
}
@Override
public R searchResult(String orderSn) {
Order order = getOne(new QueryWrapper<Order>().eq("order_sn", orderSn));
if (order == null) {
return R.error(ReturnCodeEnum.ORDER_NOT_EXISTS_ERROR);
String value = redisCache.getCacheObject(RedisKeyEnum.ORDER_RESULT_KEY.getKey(orderSn));
if (value == null) {
return R.error(ReturnCodeEnum.ORDER_SUBMIT_ERROR);
}
// 检查这个订单是否已经处理过
if (!OrderUtil.isCreateStatus(order)) {
return R.error(ReturnCodeEnum.ORDER_HAS_CREATED_ERROR);
if (!"success".equals(value)) {
return R.error(ReturnCodeEnum.ORDER_SUBMIT_ERROR.getCode(), value);
}
return R.success();
}

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

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

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

Loading…
Cancel
Save