Commit 7514867191af462132fef7fa0ef4211e6fe7ae07
1 parent
b995977e
update:效验购物车
Showing
6 changed files
with
85 additions
and
2 deletions
etrade-order/src/main/java/com/diligrp/etrade/order/dao/ShopCartMessageMapper.java
@@ -38,4 +38,7 @@ public interface ShopCartMessageMapper extends MybatisMapperSupport { | @@ -38,4 +38,7 @@ public interface ShopCartMessageMapper extends MybatisMapperSupport { | ||
38 | * @return | 38 | * @return |
39 | */ | 39 | */ |
40 | List<Long> findCartIdByMessageIds(ShopCartDto shopCartDto); | 40 | List<Long> findCartIdByMessageIds(ShopCartDto shopCartDto); |
41 | + | ||
42 | + /** 查询并锁定数据 */ | ||
43 | + List<ShopCartMessage> selectAndLockByIds(List<Long> messages); | ||
41 | } | 44 | } |
42 | \ No newline at end of file | 45 | \ No newline at end of file |
etrade-order/src/main/java/com/diligrp/etrade/order/domain/ProductDto.java
@@ -72,6 +72,9 @@ public class ProductDto { | @@ -72,6 +72,9 @@ public class ProductDto { | ||
72 | 72 | ||
73 | private String productUnit; | 73 | private String productUnit; |
74 | 74 | ||
75 | + /** 购物车商品Id */ | ||
76 | + private Long shopCertMessageId; | ||
77 | + | ||
75 | public String getCode() { | 78 | public String getCode() { |
76 | return code; | 79 | return code; |
77 | } | 80 | } |
@@ -231,4 +234,12 @@ public class ProductDto { | @@ -231,4 +234,12 @@ public class ProductDto { | ||
231 | public void setProductUnit(String productUnit) { | 234 | public void setProductUnit(String productUnit) { |
232 | this.productUnit = productUnit; | 235 | this.productUnit = productUnit; |
233 | } | 236 | } |
237 | + | ||
238 | + public Long getShopCertMessageId() { | ||
239 | + return shopCertMessageId; | ||
240 | + } | ||
241 | + | ||
242 | + public void setShopCertMessageId(Long shopCertMessageId) { | ||
243 | + this.shopCertMessageId = shopCertMessageId; | ||
244 | + } | ||
234 | } | 245 | } |
etrade-order/src/main/java/com/diligrp/etrade/order/service/IShopCartMessageService.java
@@ -31,4 +31,7 @@ public interface IShopCartMessageService { | @@ -31,4 +31,7 @@ public interface IShopCartMessageService { | ||
31 | * @return | 31 | * @return |
32 | */ | 32 | */ |
33 | List<Long> findCartIdByMessageIds(ShopCartDto shopCartDto); | 33 | List<Long> findCartIdByMessageIds(ShopCartDto shopCartDto); |
34 | + | ||
35 | + /** 查询并上锁 */ | ||
36 | + List<ShopCartMessage> selectByIds(List<Long> messages); | ||
34 | } | 37 | } |
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/OrderServiceImpl.java
@@ -62,6 +62,7 @@ import java.math.RoundingMode; | @@ -62,6 +62,7 @@ import java.math.RoundingMode; | ||
62 | import java.time.Duration; | 62 | import java.time.Duration; |
63 | import java.time.LocalDateTime; | 63 | import java.time.LocalDateTime; |
64 | import java.util.*; | 64 | import java.util.*; |
65 | +import java.util.stream.Collectors; | ||
65 | 66 | ||
66 | /** | 67 | /** |
67 | * 订单主单服务实现 | 68 | * 订单主单服务实现 |
@@ -123,6 +124,12 @@ public class OrderServiceImpl implements OrderService { | @@ -123,6 +124,12 @@ public class OrderServiceImpl implements OrderService { | ||
123 | @Resource | 124 | @Resource |
124 | private BasicDataConfigRpc basicDataConfigRpc; | 125 | private BasicDataConfigRpc basicDataConfigRpc; |
125 | 126 | ||
127 | + @Resource | ||
128 | + private IShopCartMessageService shopCartMessageService; | ||
129 | + | ||
130 | + @Resource | ||
131 | + private IShopCartService shopCartService; | ||
132 | + | ||
126 | @Transactional | 133 | @Transactional |
127 | @Override | 134 | @Override |
128 | public Order createOrder(OrderCreateDto orderCreateDto, Integer orderType,Boolean transportFeeFlag) { | 135 | public Order createOrder(OrderCreateDto orderCreateDto, Integer orderType,Boolean transportFeeFlag) { |
@@ -1385,7 +1392,18 @@ public class OrderServiceImpl implements OrderService { | @@ -1385,7 +1392,18 @@ public class OrderServiceImpl implements OrderService { | ||
1385 | @Transactional(rollbackFor = Exception.class) | 1392 | @Transactional(rollbackFor = Exception.class) |
1386 | public List<Order> createMultipleOrder(MultipleOrderDto multipleOrderDto, Integer codeInteger) { | 1393 | public List<Order> createMultipleOrder(MultipleOrderDto multipleOrderDto, Integer codeInteger) { |
1387 | List<Order> orders = new ArrayList<>(); | 1394 | List<Order> orders = new ArrayList<>(); |
1388 | - Map<Long,OrderCreateDto> orderCreateDtos = buildOrdersDto(multipleOrderDto); | 1395 | + //检测购物车是否存在数据 |
1396 | + List<Long> messages = multipleOrderDto.getProductDtoList().stream().map(ProductDto::getShopCertMessageId).toList(); | ||
1397 | + List<ShopCartMessage> shopCartMessagesIds = shopCartMessageService.selectByIds(messages); | ||
1398 | + if(shopCartMessagesIds != null){ | ||
1399 | + Integer size = shopCartMessagesIds.size(); | ||
1400 | + if(!size.equals(messages.size())){ | ||
1401 | + throw new OrderException(OrderErrorCode.PARAM_ERROR,"购物车数据已变更请刷新后重试"); | ||
1402 | + } | ||
1403 | + }else{ | ||
1404 | + throw new OrderException(OrderErrorCode.PARAM_ERROR,"购物车数据已变更请刷新后重试"); | ||
1405 | + } | ||
1406 | + Map<Long,OrderCreateDto> orderCreateDtos = buildOrdersDto(multipleOrderDto,shopCartMessagesIds); | ||
1389 | boolean first = true; | 1407 | boolean first = true; |
1390 | for(Long shopId :orderCreateDtos.keySet()){ | 1408 | for(Long shopId :orderCreateDtos.keySet()){ |
1391 | if(first){ | 1409 | if(first){ |
@@ -1398,6 +1416,9 @@ public class OrderServiceImpl implements OrderService { | @@ -1398,6 +1416,9 @@ public class OrderServiceImpl implements OrderService { | ||
1398 | orders.add(order); | 1416 | orders.add(order); |
1399 | } | 1417 | } |
1400 | } | 1418 | } |
1419 | + ShopCartDto shopCartDto = new ShopCartDto(); | ||
1420 | + shopCartDto.setIds(messages); | ||
1421 | + shopCartService.deleteShopCartMessageList(shopCartDto); | ||
1401 | return orders; | 1422 | return orders; |
1402 | } | 1423 | } |
1403 | 1424 | ||
@@ -1497,11 +1518,19 @@ public class OrderServiceImpl implements OrderService { | @@ -1497,11 +1518,19 @@ public class OrderServiceImpl implements OrderService { | ||
1497 | * @param multipleOrderDto | 1518 | * @param multipleOrderDto |
1498 | * @return | 1519 | * @return |
1499 | */ | 1520 | */ |
1500 | - private Map<Long,OrderCreateDto> buildOrdersDto(MultipleOrderDto multipleOrderDto) { | 1521 | + private Map<Long,OrderCreateDto> buildOrdersDto(MultipleOrderDto multipleOrderDto,List<ShopCartMessage> messages) { |
1501 | Map<Long,OrderCreateDto> orderCreateDtoMap = new HashMap<>(); | 1522 | Map<Long,OrderCreateDto> orderCreateDtoMap = new HashMap<>(); |
1502 | BigDecimal totleAmount = new BigDecimal(0).setScale(2, RoundingMode.HALF_UP); | 1523 | BigDecimal totleAmount = new BigDecimal(0).setScale(2, RoundingMode.HALF_UP); |
1503 | Long tempShopid = 0L; | 1524 | Long tempShopid = 0L; |
1504 | for (ProductDto productDto : multipleOrderDto.getProductDtoList()){ | 1525 | for (ProductDto productDto : multipleOrderDto.getProductDtoList()){ |
1526 | + for(ShopCartMessage shopCartMessage : messages){ | ||
1527 | + if(shopCartMessage.getId().equals(productDto.getShopCertMessageId())){ | ||
1528 | + Long wight= productDto.getProductWeight().multiply(NumberTransform.ONE_HUNDERD).longValue(); | ||
1529 | + if(wight.equals(shopCartMessage.getWeight())){ | ||
1530 | + throw new OrderException(OrderErrorCode.PARAM_ERROR,productDto.getProductName()+"的数量已发生变更,请刷新后重试"); | ||
1531 | + } | ||
1532 | + } | ||
1533 | + } | ||
1505 | OrderCreateDto orderCreateDto = orderCreateDtoMap.get(productDto.getShopId()); | 1534 | OrderCreateDto orderCreateDto = orderCreateDtoMap.get(productDto.getShopId()); |
1506 | if(orderCreateDto == null){ | 1535 | if(orderCreateDto == null){ |
1507 | orderCreateDto = new OrderCreateDto(); | 1536 | orderCreateDto = new OrderCreateDto(); |
@@ -1535,6 +1564,26 @@ public class OrderServiceImpl implements OrderService { | @@ -1535,6 +1564,26 @@ public class OrderServiceImpl implements OrderService { | ||
1535 | 1564 | ||
1536 | tempShopid = productDto.getShopId(); | 1565 | tempShopid = productDto.getShopId(); |
1537 | } | 1566 | } |
1567 | + //配送情况增加计算运费 | ||
1568 | + if(multipleOrderDto.getAchieveType().equals(OrderAchieveType.SELLER_DELIVERY.getCodeInteger())){ | ||
1569 | + ConfigQueryDto query = new ConfigQueryDto(); | ||
1570 | + query.setType("TransportFee"); | ||
1571 | + query.setMarketId(multipleOrderDto.getMarketId()); | ||
1572 | + BaseOutput<List<ConfigDto>> listBaseOutput = basicDataConfigRpc.queryAll(query); | ||
1573 | + Long transportFee = multipleOrderDto.getTransportFee().multiply(NumberTransform.ONE_HUNDERD).longValue(); | ||
1574 | + Long transportFeeConfig = 0L; | ||
1575 | + if("200".equals(listBaseOutput.getCode())){ | ||
1576 | + List<ConfigDto> configDtos = listBaseOutput.getData(); | ||
1577 | + if(configDtos!=null&&configDtos.size()>0) { | ||
1578 | + ConfigDto configDto = configDtos.get(0); | ||
1579 | + transportFeeConfig = Long.parseLong(configDto.getValue()); | ||
1580 | + } | ||
1581 | + } | ||
1582 | + if(!transportFee.equals(transportFeeConfig)){ | ||
1583 | + throw new OrderException(OrderErrorCode.PARAM_ERROR,"运费与设置不一致,请刷新后重试"); | ||
1584 | + } | ||
1585 | + totleAmount.add(multipleOrderDto.getTransportFee()); | ||
1586 | + } | ||
1538 | //订单总价,与订单总重效验 | 1587 | //订单总价,与订单总重效验 |
1539 | if(!(multipleOrderDto.getTotleAmount().compareTo(totleAmount)==0)){ | 1588 | if(!(multipleOrderDto.getTotleAmount().compareTo(totleAmount)==0)){ |
1540 | throw new OrderException(OrderErrorCode.PARAM_ERROR,"商品交易总价计算异常"); | 1589 | throw new OrderException(OrderErrorCode.PARAM_ERROR,"商品交易总价计算异常"); |
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/ShopCartMessageServiceImpl.java
@@ -201,4 +201,9 @@ public class ShopCartMessageServiceImpl implements IShopCartMessageService { | @@ -201,4 +201,9 @@ public class ShopCartMessageServiceImpl implements IShopCartMessageService { | ||
201 | public List<Long> findCartIdByMessageIds(ShopCartDto shopCartDto) { | 201 | public List<Long> findCartIdByMessageIds(ShopCartDto shopCartDto) { |
202 | return shopCartMessageMapper.findCartIdByMessageIds(shopCartDto); | 202 | return shopCartMessageMapper.findCartIdByMessageIds(shopCartDto); |
203 | } | 203 | } |
204 | + | ||
205 | + @Override | ||
206 | + public List<ShopCartMessage> selectByIds(List<Long> messages) { | ||
207 | + return shopCartMessageMapper.selectAndLockByIds(messages); | ||
208 | + } | ||
204 | } | 209 | } |
etrade-order/src/main/resources/com/diligrp/etrade/dao/mapper/shopCart/ShopCartMessageMapper.xml
@@ -104,6 +104,18 @@ | @@ -104,6 +104,18 @@ | ||
104 | </where> | 104 | </where> |
105 | group by shop_cart_id | 105 | group by shop_cart_id |
106 | </select> | 106 | </select> |
107 | + <select id="selectAndLockByIds" resultType="com.diligrp.etrade.order.model.ShopCartMessage"> | ||
108 | + select | ||
109 | + id,shop_cart_id,market_id,product_id,weight,`type`,product_name | ||
110 | + from shop_cart_message | ||
111 | + <where> | ||
112 | + id in | ||
113 | + <foreach collection="ids" item="item" open="(" separator="," close=")"> | ||
114 | + #{item} | ||
115 | + </foreach> | ||
116 | + </where> | ||
117 | + for update | ||
118 | + </select> | ||
107 | <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> | 119 | <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> |
108 | delete | 120 | delete |
109 | from shop_cart_message | 121 | from shop_cart_message |