diff --git a/es/plugins/pinyin/elasticsearch-analysis-pinyin-7.14.0.jar b/es/plugins/pinyin/elasticsearch-analysis-pinyin-7.14.0.jar new file mode 100644 index 0000000..0ee1575 Binary files /dev/null and b/es/plugins/pinyin/elasticsearch-analysis-pinyin-7.14.0.jar differ diff --git a/es/plugins/pinyin/nlp-lang-1.7.jar b/es/plugins/pinyin/nlp-lang-1.7.jar new file mode 100644 index 0000000..b6d8f0a Binary files /dev/null and b/es/plugins/pinyin/nlp-lang-1.7.jar differ diff --git a/es/plugins/pinyin/plugin-descriptor.properties b/es/plugins/pinyin/plugin-descriptor.properties new file mode 100644 index 0000000..449feb0 --- /dev/null +++ b/es/plugins/pinyin/plugin-descriptor.properties @@ -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: +# .jar <-- classes, resources, dependencies +# .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 diff --git a/pom.xml b/pom.xml index 60ea384..bb44cd9 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ com.wayn waynboot-mall - 1.3.0 + 1.4.0 pom waynboot waynboot mall商城 diff --git a/waynboot-admin-api/pom.xml b/waynboot-admin-api/pom.xml index a50e57b..ba06fe8 100644 --- a/waynboot-admin-api/pom.xml +++ b/waynboot-admin-api/pom.xml @@ -5,7 +5,7 @@ waynboot-mall com.wayn - 1.3.0 + 1.4.0 4.0.0 @@ -48,7 +48,7 @@ com.wayn waynboot-common - 1.3.0 + 1.4.0 org.elasticsearch @@ -68,7 +68,7 @@ com.wayn waynboot-message-core - 1.3.0 + 1.4.0 org.springframework.boot @@ -85,13 +85,6 @@ - - - com.hierynomus sshj diff --git a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java index 6b46fe3..13aff12 100644 --- a/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java +++ b/waynboot-admin-api/src/main/java/com/wayn/admin/api/controller/shop/GoodsController.java @@ -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()); diff --git a/waynboot-admin-api/src/main/resources/es/index/goods.json b/waynboot-admin-api/src/main/resources/es/index/goods.json index e2a1ec0..4466417 100644 --- a/waynboot-admin-api/src/main/resources/es/index/goods.json +++ b/waynboot-admin-api/src/main/resources/es/index/goods.json @@ -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" }, diff --git a/waynboot-common/pom.xml b/waynboot-common/pom.xml index 4d07afc..112e8da 100644 --- a/waynboot-common/pom.xml +++ b/waynboot-common/pom.xml @@ -5,11 +5,11 @@ waynboot-mall com.wayn - 1.3.0 + 1.4.0 4.0.0 waynboot-common - 1.3.0 + 1.4.0 @@ -148,13 +148,13 @@ com.wayn waynboot-data-redis - 1.3.0 + 1.4.0 com.wayn waynboot-data-elastic - 1.3.0 + 1.4.0 diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsProductService.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsProductService.java index aee8d35..fa11e01 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsProductService.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/IGoodsProductService.java @@ -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 { * @return boolean */ boolean addStock(Long productId, Integer number); + + List selectProductByIds(List productIds); } diff --git a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsProductServiceImpl.java b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsProductServiceImpl.java index 9dc9500..9ba8d60 100644 --- a/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsProductServiceImpl.java +++ b/waynboot-common/src/main/java/com/wayn/common/core/service/shop/impl/GoodsProductServiceImpl.java @@ -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 selectProductByIds(List productIds) { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.in(GoodsProduct::getId, productIds); + return list(queryWrapper); + } + @Override public boolean reduceStock(Long productId, Integer number) { return goodsProductMapper.reduceStock(productId, number); diff --git a/waynboot-common/src/main/java/com/wayn/common/enums/ReturnCodeEnum.java b/waynboot-common/src/main/java/com/wayn/common/enums/ReturnCodeEnum.java index 158864a..2ed85c7 100644 --- a/waynboot-common/src/main/java/com/wayn/common/enums/ReturnCodeEnum.java +++ b/waynboot-common/src/main/java/com/wayn/common/enums/ReturnCodeEnum.java @@ -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, "用户不存在"), diff --git a/waynboot-data/pom.xml b/waynboot-data/pom.xml index 485258a..750d6e0 100644 --- a/waynboot-data/pom.xml +++ b/waynboot-data/pom.xml @@ -5,7 +5,7 @@ waynboot-mall com.wayn - 1.3.0 + 1.4.0 4.0.0 diff --git a/waynboot-data/waynboot-data-elastic/pom.xml b/waynboot-data/waynboot-data-elastic/pom.xml index 1d18a78..8157c8b 100644 --- a/waynboot-data/waynboot-data-elastic/pom.xml +++ b/waynboot-data/waynboot-data-elastic/pom.xml @@ -5,7 +5,7 @@ waynboot-data com.wayn - 1.3.0 + 1.4.0 4.0.0 diff --git a/waynboot-data/waynboot-data-redis/pom.xml b/waynboot-data/waynboot-data-redis/pom.xml index 423d952..062e505 100644 --- a/waynboot-data/waynboot-data-redis/pom.xml +++ b/waynboot-data/waynboot-data-redis/pom.xml @@ -5,7 +5,7 @@ waynboot-data com.wayn - 1.3.0 + 1.4.0 4.0.0 diff --git a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/LettuceConfig.java b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/LettuceConfig.java deleted file mode 100644 index cb534ea..0000000 --- a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/config/LettuceConfig.java +++ /dev/null @@ -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); - } - } -} diff --git a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/constant/RedisKeyEnum.java b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/constant/RedisKeyEnum.java index 5fba188..7f94aaf 100644 --- a/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/constant/RedisKeyEnum.java +++ b/waynboot-data/waynboot-data-redis/src/main/java/com/wayn/data/redis/constant/RedisKeyEnum.java @@ -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; diff --git a/waynboot-job/pom.xml b/waynboot-job/pom.xml index 25c527b..eeb8ed7 100644 --- a/waynboot-job/pom.xml +++ b/waynboot-job/pom.xml @@ -5,7 +5,7 @@ waynboot-mall com.wayn - 1.3.0 + 1.4.0 4.0.0 diff --git a/waynboot-job/waynboot-job-xxl-job/pom.xml b/waynboot-job/waynboot-job-xxl-job/pom.xml index dc6a734..a160c6f 100644 --- a/waynboot-job/waynboot-job-xxl-job/pom.xml +++ b/waynboot-job/waynboot-job-xxl-job/pom.xml @@ -5,7 +5,7 @@ waynboot-job com.wayn - 1.3.0 + 1.4.0 4.0.0 @@ -23,7 +23,7 @@ com.wayn waynboot-common - 1.3.0 + 1.4.0 org.elasticsearch diff --git a/waynboot-message-consumer/pom.xml b/waynboot-message-consumer/pom.xml index de1ef9a..cb63618 100644 --- a/waynboot-message-consumer/pom.xml +++ b/waynboot-message-consumer/pom.xml @@ -5,11 +5,11 @@ waynboot-mall com.wayn - 1.3.0 + 1.4.0 4.0.0 waynboot-message-consumer - 1.3.0 + 1.4.0 com.wayn.MessageApplication @@ -19,12 +19,12 @@ com.wayn waynboot-message-core - 1.3.0 + 1.4.0 com.wayn waynboot-data-redis - 1.3.0 + 1.4.0 diff --git a/waynboot-message-consumer/src/main/java/com/wayn/message/api/impl/MobileApiImpl.java b/waynboot-message-consumer/src/main/java/com/wayn/message/api/impl/MobileApiImpl.java index d2f0e1d..f570589 100644 --- a/waynboot-message-consumer/src/main/java/com/wayn/message/api/impl/MobileApiImpl.java +++ b/waynboot-message-consumer/src/main/java/com/wayn/message/api/impl/MobileApiImpl.java @@ -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); diff --git a/waynboot-message-core/pom.xml b/waynboot-message-core/pom.xml index 308480c..341a779 100644 --- a/waynboot-message-core/pom.xml +++ b/waynboot-message-core/pom.xml @@ -5,11 +5,11 @@ waynboot-mall com.wayn - 1.3.0 + 1.4.0 4.0.0 waynboot-message-core - 1.3.0 + 1.4.0 diff --git a/waynboot-mobile-api/pom.xml b/waynboot-mobile-api/pom.xml index b23b069..95fd2ea 100644 --- a/waynboot-mobile-api/pom.xml +++ b/waynboot-mobile-api/pom.xml @@ -5,11 +5,11 @@ waynboot-mall com.wayn - 1.3.0 + 1.4.0 4.0.0 waynboot-mobile-api - 1.3.0 + 1.4.0 wayn111 @@ -26,13 +26,13 @@ com.wayn waynboot-common - 1.3.0 + 1.4.0 com.wayn waynboot-message-core - 1.3.0 + 1.4.0 org.springframework.boot diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java index 0f690ef..cbd4564 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/CartController.java @@ -38,7 +38,6 @@ public class CartController extends BaseController { Long userId = MobileSecurityUtils.getUserId(); Page 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}") diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/SearchController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/SearchController.java index 6d16357..593571f 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/SearchController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/SearchController.java @@ -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 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 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,8 +152,14 @@ public class SearchController extends BaseController { AsyncManager.me().execute(new TimerTask() { @Override public void run() { - searchHistory.setHasGoods(true); - iSearchHistoryService.save(searchHistory); + 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); + } } }); } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/callback/SubmitOrderController.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/callback/SubmitOrderController.java index ca7d0e8..edf8306 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/callback/SubmitOrderController.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/controller/callback/SubmitOrderController.java @@ -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(); + } } } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java index 4c6a1d2..ce96092 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/ICartService.java @@ -56,7 +56,7 @@ public interface ICartService extends IService { * @param number 商品数量 * @return r */ - R changeNum(Long cartId, Integer number); + Boolean changeNum(Long cartId, Integer number); /** * 添加商品的默认选中货品至购物车 diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IMobileOrderService.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IMobileOrderService.java index 0c1d377..46d0fe6 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IMobileOrderService.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/IMobileOrderService.java @@ -24,7 +24,7 @@ public interface IMobileOrderService extends IService { * @param orderDTO 订单DTO * @return R */ - R submit(OrderDTO orderDTO) throws UnsupportedEncodingException; + void submit(OrderDTO orderDTO) throws UnsupportedEncodingException; /** diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/CartServiceImpl.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/CartServiceImpl.java index 1383bde..b2e879d 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/CartServiceImpl.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/CartServiceImpl.java @@ -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 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() @@ -131,25 +132,34 @@ public class CartServiceImpl extends ServiceImpl implements IC public R list(Page page, Long userId) { IPage goodsIPage = cartMapper.selectCartPageList(page, userId); List cartList = goodsIPage.getRecords(); - List goodsIdList = cartList.stream().map(Cart::getGoodsId).collect(Collectors.toList()); + List goodsIdList = cartList.stream().map(Cart::getGoodsId).toList(); + List productIdList = cartList.stream().map(Cart::getProductId).toList(); JSONArray array = new JSONArray(); if (CollectionUtils.isEmpty(goodsIdList)) { return R.success().add("data", array); } - Map goodsIdMap = iGoodsService.selectGoodsByIds(goodsIdList).stream().collect(Collectors.toMap(Goods::getId, goods -> goods)); + // Map goodsIdMap = iGoodsService.selectGoodsByIds(goodsIdList).stream() + // .collect(Collectors.toMap(Goods::getId, goods -> goods)); + Map 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 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 diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/MobileOrderServiceImpl.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/MobileOrderServiceImpl.java index 644cce4..915b3f5 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/MobileOrderServiceImpl.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/api/service/impl/MobileOrderServiceImpl.java @@ -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 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 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 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 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 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 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().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(); } diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/SecurityConfig.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/SecurityConfig.java index 33cce74..7eedb98 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/SecurityConfig.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/config/SecurityConfig.java @@ -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() diff --git a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/security/filter/JwtAuthenticationTokenFilter.java b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/security/filter/JwtAuthenticationTokenFilter.java index d4077be..4de22d5 100644 --- a/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/security/filter/JwtAuthenticationTokenFilter.java +++ b/waynboot-mobile-api/src/main/java/com/wayn/mobile/framework/security/filter/JwtAuthenticationTokenFilter.java @@ -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(); diff --git a/waynboot-monitor/pom.xml b/waynboot-monitor/pom.xml index 4cfeb3a..7179025 100644 --- a/waynboot-monitor/pom.xml +++ b/waynboot-monitor/pom.xml @@ -5,7 +5,7 @@ waynboot-mall com.wayn - 1.3.0 + 1.4.0 4.0.0