Commit dbc97216 authored by wlx@33.cn's avatar wlx@33.cn

盲盒提测

parent 5d59b8e3
...@@ -5,6 +5,7 @@ import com.fzm.mall.server.front.goods.mapper.GoodSkuMapper; ...@@ -5,6 +5,7 @@ import com.fzm.mall.server.front.goods.mapper.GoodSkuMapper;
import com.fzm.mall.server.front.goods.model.vo.SkuVo; import com.fzm.mall.server.front.goods.model.vo.SkuVo;
import com.fzm.mall.server.front.order.service.IOrderBindBoxService; import com.fzm.mall.server.front.order.service.IOrderBindBoxService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -17,6 +18,7 @@ import java.util.concurrent.ThreadLocalRandom; ...@@ -17,6 +18,7 @@ import java.util.concurrent.ThreadLocalRandom;
* @author wulixian * @author wulixian
* @since 2022/2/23 * @since 2022/2/23
*/ */
@Slf4j
@Service @Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) @RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class IOrderBindBoxServiceImpl implements IOrderBindBoxService { public class IOrderBindBoxServiceImpl implements IOrderBindBoxService {
...@@ -30,8 +32,9 @@ public class IOrderBindBoxServiceImpl implements IOrderBindBoxService { ...@@ -30,8 +32,9 @@ public class IOrderBindBoxServiceImpl implements IOrderBindBoxService {
* 从数据库获取库存大于0的盲盒sku列表 * 从数据库获取库存大于0的盲盒sku列表
*/ */
List<SkuVo> skuList = goodSkuMapper.listAvailableSku(goodsId); List<SkuVo> skuList = goodSkuMapper.listAvailableSku(goodsId);
int difficulty = skuList.stream().map(SkuVo::getDifficulty).findFirst().get(); long wStart = System.currentTimeMillis();
while(!CollectionUtils.isEmpty(skuList)){ while(!CollectionUtils.isEmpty(skuList)){
int difficulty = skuList.stream().map(SkuVo::getDifficulty).findFirst().get();
result = genRandomSku(skuList, difficulty); result = genRandomSku(skuList, difficulty);
if (result == null) { if (result == null) {
throw new RuntimeException("库存不足!!!"); throw new RuntimeException("库存不足!!!");
...@@ -48,6 +51,8 @@ public class IOrderBindBoxServiceImpl implements IOrderBindBoxService { ...@@ -48,6 +51,8 @@ public class IOrderBindBoxServiceImpl implements IOrderBindBoxService {
break; break;
} }
} }
long wEnd = System.currentTimeMillis();
log.info("循环耗时:" +(wEnd-wStart));
if (result == null) { if (result == null) {
throw new RuntimeException("库存不足!!!"); throw new RuntimeException("库存不足!!!");
} }
......
...@@ -47,6 +47,7 @@ import com.fzm.mall.server.front.util.OrderUtil; ...@@ -47,6 +47,7 @@ import com.fzm.mall.server.front.util.OrderUtil;
import com.fzm.mall.server.front.util.TimeUtil; import com.fzm.mall.server.front.util.TimeUtil;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -68,6 +69,7 @@ import java.util.concurrent.TimeUnit; ...@@ -68,6 +69,7 @@ import java.util.concurrent.TimeUnit;
* @author fzm * @author fzm
* @since 2021-03-02 * @since 2021-03-02
*/ */
@Slf4j
@Service @Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) @RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService { public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
...@@ -1387,27 +1389,37 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements ...@@ -1387,27 +1389,37 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
/** /**
* 1.根据算法,获取本次下单的对应的盲盒sku信息(sku基本信息+快递模板id),生成订单详情order_detail * 1.根据算法,获取本次下单的对应的盲盒sku信息(sku基本信息+快递模板id),生成订单详情order_detail
*/ */
long rStart = System.currentTimeMillis();
SkuVo skuVo = orderBindBoxService.genRandomSku(orderVo.getGoodsId()); SkuVo skuVo = orderBindBoxService.genRandomSku(orderVo.getGoodsId());
long rEnd = System.currentTimeMillis();
log.info("计算库存耗时:" +(rEnd-rStart));
long odStart = System.currentTimeMillis();
String oid = OrderUtil.getOid(); String oid = OrderUtil.getOid();
OrderDetail orderDetail = saveOrderDetail(skuVo, oid); OrderDetail orderDetail = saveOrderDetail(skuVo, oid);
long odEnd = System.currentTimeMillis();
log.info("保存订单详情耗时:" +(odEnd-odStart));
/** /**
* 2.记录本次下单的sku的数量和规格信息,计算邮费 * 2.记录本次下单的sku的数量和规格信息,计算邮费(一幕沒有邮费)
*/ */
long teStart = System.currentTimeMillis();
BigDecimal postFee = BigDecimal.ZERO; BigDecimal postFee = BigDecimal.ZERO;
if (orderVo.getDelivery().equals(OrderBlindBoxVo.DELIVERY_IMMEDIATELY)) { // if (orderVo.getDelivery().equals(OrderBlindBoxVo.DELIVERY_IMMEDIATELY)) {
postFee = sumPostFee(skuVo, orderVo, orderDetail); // postFee = sumPostFee(skuVo, orderVo, orderDetail);
} // }
/** /**
* (一幕沒有优惠券和促销活动) * (一幕沒有优惠券和促销活动)
* 3.计算本次下单可享受的促销优惠:优惠券+促销活动(一幕沒有优惠券和促销活动) * 3.计算本次下单可享受的促销优惠:优惠券+促销活动(一幕沒有优惠券和促销活动)
*/ */
List<OrderSkuVo> orderSkuVoList = new ArrayList<>();
OrderSkuVo orderSkuVo = new OrderSkuVo();
orderSkuVo.setSkuId(skuVo.getSkuId());
orderSkuVo.setNum(orderDetail.getNumber());
BigDecimal promotionDiscountAmount = BigDecimal.ZERO; BigDecimal promotionDiscountAmount = BigDecimal.ZERO;
// List<OrderSkuVo> orderSkuVoList = new ArrayList<>();
// OrderSkuVo orderSkuVo = new OrderSkuVo();
// orderSkuVo.setSkuId(skuVo.getSkuId());
// orderSkuVo.setNum(orderDetail.getNumber());
// orderSkuVoList.add(orderSkuVo);
// BigDecimal promotionDiscountAmount = sumPromotionDiscount(skuVo, orderSkuVoList, type, oid); // BigDecimal promotionDiscountAmount = sumPromotionDiscount(skuVo, orderSkuVoList, type, oid);
/** /**
...@@ -1429,13 +1441,20 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements ...@@ -1429,13 +1441,20 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
payableAmount = payableAmount.compareTo(BigDecimal.ZERO) == CommonConst.BIEDICIMAL_LEFT_LESS ? BigDecimal.ZERO : payableAmount; payableAmount = payableAmount.compareTo(BigDecimal.ZERO) == CommonConst.BIEDICIMAL_LEFT_LESS ? BigDecimal.ZERO : payableAmount;
BigDecimal integralDeductionNum = BigDecimal.ZERO; BigDecimal integralDeductionNum = BigDecimal.ZERO;
// BigDecimal integralDeductionNum = saveIntegralRecord(payableAmount, orderVo, uid, payId); // BigDecimal integralDeductionNum = saveIntegralRecord(payableAmount, orderVo, uid, payId);
long teEnd = System.currentTimeMillis();
log.info("中间计算耗时:" +(teEnd-teStart));
/** /**
* 5.生成支付单order_pay和订单order_info * 5.生成支付单order_pay和订单order_info
*/ */
long oiStart = System.currentTimeMillis();
saveOrderInfo(payId, oid, uid, skuVo.getMerchantId(), skuAmount, discountAmount, postFee, integralDeductionNum, orderVo); saveOrderInfo(payId, oid, uid, skuVo.getMerchantId(), skuAmount, discountAmount, postFee, integralDeductionNum, orderVo);
long oiEnd = System.currentTimeMillis();
log.info("保存订单耗时:" +(oiEnd-oiStart));
long opStart = System.currentTimeMillis();
saveOrderPay(payId, oid, orderVo.getCoin(), integralDeductionNum, uid, payableAmount); saveOrderPay(payId, oid, orderVo.getCoin(), integralDeductionNum, uid, payableAmount);
long opEnd = System.currentTimeMillis();
log.info("保存支付单耗时:" +(opEnd-opStart));
return payId; return payId;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment