@Test public void testCalcProductPrice() { PriceProductCalcReqDTO calcReqDTO = new PriceProductCalcReqDTO(); PriceProductCalcReqDTO.Item item01 = new PriceProductCalcReqDTO.Item(33, 2, true); PriceProductCalcReqDTO.Item item02 = new PriceProductCalcReqDTO.Item(34, 2, true); calcReqDTO.setItems(Arrays.asList(item01, item02)); PriceProductCalcRespDTO calcRespDTO = priceManager.calcProductPrice(calcReqDTO); System.out.println(calcRespDTO); }
public PriceProductCalcRespDTO calcProductPrice(PriceProductCalcReqDTO calcReqDTO) { Map<Integer, PriceProductCalcReqDTO.Item> calcProductItemDTOMap = CollectionUtils.convertMap( calcReqDTO.getItems(), PriceProductCalcReqDTO.Item::getSkuId); CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuRpc.listProductSkus( new ProductSkuListQueryReqDTO().setProductSkuIds(calcProductItemDTOMap.keySet())); listProductSkusResult.checkError(); if (calcReqDTO.getItems().size() != listProductSkusResult.getData().size()) { throw ServiceExceptionUtil.exception(PRICE_PRODUCT_SKU_NOT_EXISTS); } List<PromotionActivityRespDTO> activityRespDTOs = promotionActivityService.listPromotionActivitiesBySpuIds( CollectionUtils.convertSet(listProductSkusResult.getData(), ProductSkuRespDTO::getSpuId), Collections.singleton(PromotionActivityStatusEnum.RUN.getValue())); PriceProductCalcRespDTO calcRespDTO = new PriceProductCalcRespDTO(); List<PriceProductCalcRespDTO.Item> calcItemRespDTOs = this.initCalcOrderPriceItems( listProductSkusResult.getData(), calcProductItemDTOMap); this.modifyPriceByTimeLimitDiscount(calcItemRespDTOs, activityRespDTOs); List<PriceProductCalcRespDTO.ItemGroup> itemGroups = this.groupByFullPrivilege(calcItemRespDTOs, activityRespDTOs); calcRespDTO.setItemGroups(itemGroups); if (calcReqDTO.getCouponCardId() != null) { Integer result = this.modifyPriceByCouponCard(calcReqDTO.getUserId(), calcReqDTO.getCouponCardId(), itemGroups); calcRespDTO.setCouponCardDiscountTotal(result); } int buyTotal = 0; int discountTotal = 0; int presentTotal = 0; for (PriceProductCalcRespDTO.ItemGroup itemGroup : calcRespDTO.getItemGroups()) { buyTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getBuyTotal() : 0).sum(); discountTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getDiscountTotal() : 0).sum(); presentTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getPresentTotal() : 0).sum(); } Assert.isTrue(buyTotal - discountTotal == presentTotal, String.format("价格合计( %d - %d == %d )不正确", buyTotal, discountTotal, presentTotal)); calcRespDTO.setFee(new PriceProductCalcRespDTO.Fee(buyTotal, discountTotal, 0, presentTotal)); return calcRespDTO; }
PriceManager { public PriceProductCalcRespDTO calcProductPrice(PriceProductCalcReqDTO calcReqDTO) { Map<Integer, PriceProductCalcReqDTO.Item> calcProductItemDTOMap = CollectionUtils.convertMap( calcReqDTO.getItems(), PriceProductCalcReqDTO.Item::getSkuId); CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuRpc.listProductSkus( new ProductSkuListQueryReqDTO().setProductSkuIds(calcProductItemDTOMap.keySet())); listProductSkusResult.checkError(); if (calcReqDTO.getItems().size() != listProductSkusResult.getData().size()) { throw ServiceExceptionUtil.exception(PRICE_PRODUCT_SKU_NOT_EXISTS); } List<PromotionActivityRespDTO> activityRespDTOs = promotionActivityService.listPromotionActivitiesBySpuIds( CollectionUtils.convertSet(listProductSkusResult.getData(), ProductSkuRespDTO::getSpuId), Collections.singleton(PromotionActivityStatusEnum.RUN.getValue())); PriceProductCalcRespDTO calcRespDTO = new PriceProductCalcRespDTO(); List<PriceProductCalcRespDTO.Item> calcItemRespDTOs = this.initCalcOrderPriceItems( listProductSkusResult.getData(), calcProductItemDTOMap); this.modifyPriceByTimeLimitDiscount(calcItemRespDTOs, activityRespDTOs); List<PriceProductCalcRespDTO.ItemGroup> itemGroups = this.groupByFullPrivilege(calcItemRespDTOs, activityRespDTOs); calcRespDTO.setItemGroups(itemGroups); if (calcReqDTO.getCouponCardId() != null) { Integer result = this.modifyPriceByCouponCard(calcReqDTO.getUserId(), calcReqDTO.getCouponCardId(), itemGroups); calcRespDTO.setCouponCardDiscountTotal(result); } int buyTotal = 0; int discountTotal = 0; int presentTotal = 0; for (PriceProductCalcRespDTO.ItemGroup itemGroup : calcRespDTO.getItemGroups()) { buyTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getBuyTotal() : 0).sum(); discountTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getDiscountTotal() : 0).sum(); presentTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getPresentTotal() : 0).sum(); } Assert.isTrue(buyTotal - discountTotal == presentTotal, String.format("价格合计( %d - %d == %d )不正确", buyTotal, discountTotal, presentTotal)); calcRespDTO.setFee(new PriceProductCalcRespDTO.Fee(buyTotal, discountTotal, 0, presentTotal)); return calcRespDTO; } }
PriceManager { public PriceProductCalcRespDTO calcProductPrice(PriceProductCalcReqDTO calcReqDTO) { Map<Integer, PriceProductCalcReqDTO.Item> calcProductItemDTOMap = CollectionUtils.convertMap( calcReqDTO.getItems(), PriceProductCalcReqDTO.Item::getSkuId); CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuRpc.listProductSkus( new ProductSkuListQueryReqDTO().setProductSkuIds(calcProductItemDTOMap.keySet())); listProductSkusResult.checkError(); if (calcReqDTO.getItems().size() != listProductSkusResult.getData().size()) { throw ServiceExceptionUtil.exception(PRICE_PRODUCT_SKU_NOT_EXISTS); } List<PromotionActivityRespDTO> activityRespDTOs = promotionActivityService.listPromotionActivitiesBySpuIds( CollectionUtils.convertSet(listProductSkusResult.getData(), ProductSkuRespDTO::getSpuId), Collections.singleton(PromotionActivityStatusEnum.RUN.getValue())); PriceProductCalcRespDTO calcRespDTO = new PriceProductCalcRespDTO(); List<PriceProductCalcRespDTO.Item> calcItemRespDTOs = this.initCalcOrderPriceItems( listProductSkusResult.getData(), calcProductItemDTOMap); this.modifyPriceByTimeLimitDiscount(calcItemRespDTOs, activityRespDTOs); List<PriceProductCalcRespDTO.ItemGroup> itemGroups = this.groupByFullPrivilege(calcItemRespDTOs, activityRespDTOs); calcRespDTO.setItemGroups(itemGroups); if (calcReqDTO.getCouponCardId() != null) { Integer result = this.modifyPriceByCouponCard(calcReqDTO.getUserId(), calcReqDTO.getCouponCardId(), itemGroups); calcRespDTO.setCouponCardDiscountTotal(result); } int buyTotal = 0; int discountTotal = 0; int presentTotal = 0; for (PriceProductCalcRespDTO.ItemGroup itemGroup : calcRespDTO.getItemGroups()) { buyTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getBuyTotal() : 0).sum(); discountTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getDiscountTotal() : 0).sum(); presentTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getPresentTotal() : 0).sum(); } Assert.isTrue(buyTotal - discountTotal == presentTotal, String.format("价格合计( %d - %d == %d )不正确", buyTotal, discountTotal, presentTotal)); calcRespDTO.setFee(new PriceProductCalcRespDTO.Fee(buyTotal, discountTotal, 0, presentTotal)); return calcRespDTO; }  }
PriceManager { public PriceProductCalcRespDTO calcProductPrice(PriceProductCalcReqDTO calcReqDTO) { Map<Integer, PriceProductCalcReqDTO.Item> calcProductItemDTOMap = CollectionUtils.convertMap( calcReqDTO.getItems(), PriceProductCalcReqDTO.Item::getSkuId); CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuRpc.listProductSkus( new ProductSkuListQueryReqDTO().setProductSkuIds(calcProductItemDTOMap.keySet())); listProductSkusResult.checkError(); if (calcReqDTO.getItems().size() != listProductSkusResult.getData().size()) { throw ServiceExceptionUtil.exception(PRICE_PRODUCT_SKU_NOT_EXISTS); } List<PromotionActivityRespDTO> activityRespDTOs = promotionActivityService.listPromotionActivitiesBySpuIds( CollectionUtils.convertSet(listProductSkusResult.getData(), ProductSkuRespDTO::getSpuId), Collections.singleton(PromotionActivityStatusEnum.RUN.getValue())); PriceProductCalcRespDTO calcRespDTO = new PriceProductCalcRespDTO(); List<PriceProductCalcRespDTO.Item> calcItemRespDTOs = this.initCalcOrderPriceItems( listProductSkusResult.getData(), calcProductItemDTOMap); this.modifyPriceByTimeLimitDiscount(calcItemRespDTOs, activityRespDTOs); List<PriceProductCalcRespDTO.ItemGroup> itemGroups = this.groupByFullPrivilege(calcItemRespDTOs, activityRespDTOs); calcRespDTO.setItemGroups(itemGroups); if (calcReqDTO.getCouponCardId() != null) { Integer result = this.modifyPriceByCouponCard(calcReqDTO.getUserId(), calcReqDTO.getCouponCardId(), itemGroups); calcRespDTO.setCouponCardDiscountTotal(result); } int buyTotal = 0; int discountTotal = 0; int presentTotal = 0; for (PriceProductCalcRespDTO.ItemGroup itemGroup : calcRespDTO.getItemGroups()) { buyTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getBuyTotal() : 0).sum(); discountTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getDiscountTotal() : 0).sum(); presentTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getPresentTotal() : 0).sum(); } Assert.isTrue(buyTotal - discountTotal == presentTotal, String.format("价格合计( %d - %d == %d )不正确", buyTotal, discountTotal, presentTotal)); calcRespDTO.setFee(new PriceProductCalcRespDTO.Fee(buyTotal, discountTotal, 0, presentTotal)); return calcRespDTO; }  PriceProductCalcRespDTO calcProductPrice(PriceProductCalcReqDTO calcReqDTO); }
PriceManager { public PriceProductCalcRespDTO calcProductPrice(PriceProductCalcReqDTO calcReqDTO) { Map<Integer, PriceProductCalcReqDTO.Item> calcProductItemDTOMap = CollectionUtils.convertMap( calcReqDTO.getItems(), PriceProductCalcReqDTO.Item::getSkuId); CommonResult<List<ProductSkuRespDTO>> listProductSkusResult = productSkuRpc.listProductSkus( new ProductSkuListQueryReqDTO().setProductSkuIds(calcProductItemDTOMap.keySet())); listProductSkusResult.checkError(); if (calcReqDTO.getItems().size() != listProductSkusResult.getData().size()) { throw ServiceExceptionUtil.exception(PRICE_PRODUCT_SKU_NOT_EXISTS); } List<PromotionActivityRespDTO> activityRespDTOs = promotionActivityService.listPromotionActivitiesBySpuIds( CollectionUtils.convertSet(listProductSkusResult.getData(), ProductSkuRespDTO::getSpuId), Collections.singleton(PromotionActivityStatusEnum.RUN.getValue())); PriceProductCalcRespDTO calcRespDTO = new PriceProductCalcRespDTO(); List<PriceProductCalcRespDTO.Item> calcItemRespDTOs = this.initCalcOrderPriceItems( listProductSkusResult.getData(), calcProductItemDTOMap); this.modifyPriceByTimeLimitDiscount(calcItemRespDTOs, activityRespDTOs); List<PriceProductCalcRespDTO.ItemGroup> itemGroups = this.groupByFullPrivilege(calcItemRespDTOs, activityRespDTOs); calcRespDTO.setItemGroups(itemGroups); if (calcReqDTO.getCouponCardId() != null) { Integer result = this.modifyPriceByCouponCard(calcReqDTO.getUserId(), calcReqDTO.getCouponCardId(), itemGroups); calcRespDTO.setCouponCardDiscountTotal(result); } int buyTotal = 0; int discountTotal = 0; int presentTotal = 0; for (PriceProductCalcRespDTO.ItemGroup itemGroup : calcRespDTO.getItemGroups()) { buyTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getBuyTotal() : 0).sum(); discountTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getDiscountTotal() : 0).sum(); presentTotal += itemGroup.getItems().stream().mapToInt(item -> item.getSelected() ? item.getPresentTotal() : 0).sum(); } Assert.isTrue(buyTotal - discountTotal == presentTotal, String.format("价格合计( %d - %d == %d )不正确", buyTotal, discountTotal, presentTotal)); calcRespDTO.setFee(new PriceProductCalcRespDTO.Fee(buyTotal, discountTotal, 0, presentTotal)); return calcRespDTO; }  PriceProductCalcRespDTO calcProductPrice(PriceProductCalcReqDTO calcReqDTO);  }