|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.lang.Snowflake;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import edu.travel.adapter.service.country.CountryAdapter;
|
|
|
import edu.travel.adapter.service.country.CurrencyAdapter;
|
|
@@ -20,6 +21,7 @@ import edu.travel.commodity.mapper.ShopProductSpecMapper;
|
|
|
import edu.travel.commodity.service.ShopAddressService;
|
|
|
import edu.travel.commodity.service.ShopProductService;
|
|
|
import edu.travel.commodity.service.ShopProductSkuService;
|
|
|
+import edu.travel.commodity.utils.TokenData;
|
|
|
import edu.travel.exception.BaseException;
|
|
|
import edu.travel.remote.dto.*;
|
|
|
import edu.travel.remote.vo.ShopSkuSpecValueVo;
|
|
@@ -84,8 +86,9 @@ public class ShopProductSkuServiceImpl extends ServiceImpl<ShopProductSkuMapper,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @GlobalTransactional
|
|
|
- public String shopProductSku(AddShopOrderDto params) {
|
|
|
+// @GlobalTransactional
|
|
|
+ public void shopProductSku(AddShopOrderDto params) {
|
|
|
+ String userId = TokenData.getUserId();
|
|
|
List<AddShopProductOrderDto> products = params.getProducts();
|
|
|
//商品ID
|
|
|
Set<String> product = products.stream().map(AddShopProductOrderDto::getProductId).collect(Collectors.toSet());
|
|
@@ -119,7 +122,6 @@ public class ShopProductSkuServiceImpl extends ServiceImpl<ShopProductSkuMapper,
|
|
|
}
|
|
|
RLock multiLock = redissonClient.getMultiLock(locks);
|
|
|
|
|
|
-
|
|
|
try {
|
|
|
if(multiLock.tryLock(20, TimeUnit.SECONDS)){
|
|
|
List<ShopProductSku> ls = shopProductSkuMapper.getByProductSkus(products);
|
|
@@ -153,12 +155,12 @@ public class ShopProductSkuServiceImpl extends ServiceImpl<ShopProductSkuMapper,
|
|
|
}
|
|
|
//修改数量
|
|
|
shopProductSku.setFreeze(shopProductSku.getFreeze()+dto.getQuantity());
|
|
|
- //库存数量
|
|
|
- shopProductSku.setInventory(shopProductSku.getInventory()-dto.getQuantity());
|
|
|
//商品价格
|
|
|
BigDecimal multiply = shopProductSku.getPrice().multiply(new BigDecimal(dto.getQuantity()));
|
|
|
//总价
|
|
|
all=all.add(multiply);
|
|
|
+ //快照信息
|
|
|
+ Map<String, ShopSnapshotVo> snapshot = this.getSnapshot(products);
|
|
|
|
|
|
AddOrderItemDto addOrderItemDto = new AddOrderItemDto();
|
|
|
addOrderItemDto.setProductId(shopProduct.getId().toString());
|
|
@@ -166,9 +168,12 @@ public class ShopProductSkuServiceImpl extends ServiceImpl<ShopProductSkuMapper,
|
|
|
addOrderItemDto.setPrice(shopProductSku.getPrice());
|
|
|
addOrderItemDto.setQuantity(dto.getQuantity());
|
|
|
addOrderItemDto.setOrderId(orderNum+"");
|
|
|
- //快照信息 ShopSnapshotVo
|
|
|
|
|
|
- //addOrderItemDto.setSnapshot();
|
|
|
+ ShopSnapshotVo shopSnapshotVo = snapshot.get(shopProductSku.getSkuId().toString());
|
|
|
+ shopSnapshotVo.setProductName(shopProduct.getProductName());
|
|
|
+ shopSnapshotVo.setDescription(shopProduct.getDescription());
|
|
|
+ shopSnapshotVo.setImageUrl(shopProductSku.getImageUrl());
|
|
|
+ addOrderItemDto.setSnapshot(JSONUtil.toJsonStr(shopSnapshotVo));
|
|
|
|
|
|
orderItems.add(addOrderItemDto);
|
|
|
}
|
|
@@ -181,10 +186,12 @@ public class ShopProductSkuServiceImpl extends ServiceImpl<ShopProductSkuMapper,
|
|
|
order.setAddressId(params.getAddressId());
|
|
|
order.setAddress(address.getDetailedAddress());
|
|
|
order.setGlobalCouponId(params.getGlobalCouponId());
|
|
|
- order.setGlobalCouponId(country.getServiceChargeValue().toString());
|
|
|
+ order.setServiceChargeValue(country.getServiceChargeValue());
|
|
|
order.setOrderNumber(orderNum+"");
|
|
|
order.setCurrency(currency.getCurrencySymbol());
|
|
|
order.setCurrencyId(currency.getId().toString());
|
|
|
+ order.setOrderRemark(params.getRemark());
|
|
|
+ order.setUserId(userId);
|
|
|
|
|
|
orderAdapter.addShopOrder(order);
|
|
|
orderItemAdapter.addShopOrderItem(orderItems);
|
|
@@ -195,24 +202,26 @@ public class ShopProductSkuServiceImpl extends ServiceImpl<ShopProductSkuMapper,
|
|
|
shopOrderLogAdapter.addOrderLog(addOrderLogDto);
|
|
|
}
|
|
|
} catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
throw new BaseException(e);
|
|
|
+ }finally {
|
|
|
+ multiLock.unlock();//解锁
|
|
|
}
|
|
|
- return "下单成功";
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//获取商品快照信息
|
|
|
- public Map<String,ShopSnapshotVo> getSnapshot(Set<String> skuId) {
|
|
|
- Map<String, List<ShopSkuSpecValueVo>> specs = shopProductSkuService.getSkuValuesById(skuId);
|
|
|
+ public Map<String,ShopSnapshotVo> getSnapshot(List<AddShopProductOrderDto> products) {
|
|
|
+ Set<String> collect = products.stream().map(AddShopProductOrderDto::getSkuId).collect(Collectors.toSet());
|
|
|
+ Map<String, List<ShopSkuSpecValueVo>> specs = shopProductSkuService.getSkuValuesById(collect);
|
|
|
HashMap<String, ShopSnapshotVo> map = new HashMap<>();
|
|
|
specs.forEach((k,v)->{
|
|
|
ShopSnapshotVo shopSnapshotVo = new ShopSnapshotVo();
|
|
|
+ shopSnapshotVo.setSkuId(k);
|
|
|
List<SpecValueVo> specValueVos = BeanUtil.copyToList(v, SpecValueVo.class);
|
|
|
shopSnapshotVo.setSnapshotSpec(specValueVos);
|
|
|
map.put(k,shopSnapshotVo);
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return map;
|
|
|
}
|
|
|
|