Commit 8cb0244b by yu.sun

Merge branch 'feature/20201217_四个非常搭套餐需求_yu.sun'

# Conflicts:
#	shopping-cart-application-service/src/main/java/cn/freemud/adapter/ShoppingCartMccafeAdapter.java
#	shopping-cart-application-service/src/main/java/cn/freemud/service/impl/mcoffee/calculation/CalculationServiceImpl.java
#	shopping-cart-application-service/src/main/java/cn/freemud/service/impl/mcoffee/calculation/SetMealCalculation.java
parents edbcb7ab 180ae5f7
......@@ -733,7 +733,7 @@ public class ShoppingCartConvertAdapter {
comboxGoods.setTaxId(isComboxGoods ? (StringUtils.isNotEmpty(productComboType.getTaxId()) ? productComboType.getTaxId() : "") :
(StringUtils.isNotEmpty(groupDetailType.getTaxId()) ? groupDetailType.getTaxId() : ""));
// TODO: 2020/10/22 套餐内可选商品加料,暂无
//2020/10/22 套餐内可选商品加料,暂无
if(CollectionUtils.isNotEmpty(comboxGoods.getProductMaterialList())){
List<com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods> productMaterialList = new ArrayList<>();
com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods materialGoods = new com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods();
......@@ -742,6 +742,87 @@ public class ShoppingCartConvertAdapter {
}
}
/**
* 更新套餐可选商品加料信息
*/
private void updateComboxGoodsInfoForMCoffeeProductGroup(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.ComboxGoods comboxGoods, ProductTypeBeanDTO parentProductBean,
Map<String,ProductTypeBeanDTO> subProductTypeMap,
boolean isComboxGoods) {
if("0".equals(comboxGoods.getGoodsId())){
return;
}
ProductTypeBeanDTO.ProductComboType productComboType = new ProductTypeBeanDTO.ProductComboType();
ProductTypeBeanDTO.ProductGroupType.GroupDetailType groupDetailType = new ProductTypeBeanDTO.ProductGroupType.GroupDetailType();
if (isComboxGoods) {
productComboType = parentProductBean.getProductComboList().stream().filter(p -> ObjectUtils.equals(comboxGoods.getGoodsId(), p.getProductId())).findFirst().orElse(new ProductTypeBeanDTO.ProductComboType());
} else {
Map<String, ProductTypeBeanDTO.ProductGroupType.GroupDetailType> map = new HashMap<>();
parentProductBean.getProductGroupList().stream().map(t -> t.getGroupDetail()).forEach(group -> group.forEach(detailType -> map.put(detailType.getProductId(), detailType)));
groupDetailType = map.get(comboxGoods.getGoodsId());
}
// 若是固定商品则取商品详情的FinalPrice,若是可选商品则取MarkUpPrice
Long finalPrice = isComboxGoods ? (null != productComboType.getFinalPrice() ? productComboType.getFinalPrice().longValue() : 0L)
: (null != groupDetailType.getMarkUpPrice() ? groupDetailType.getMarkUpPrice().longValue() : 0L);
// 设置商品详情
Map<String, String> attributes = getAttributesNew(comboxGoods.getExtra());
comboxGoods.setSpuId(comboxGoods.getSpuId());
comboxGoods.setName(isComboxGoods ? productComboType.getProductName() : groupDetailType.getProductName());
comboxGoods.setSpuName(comboxGoods.getName());
comboxGoods.setSpecProductId(attributes.get(ATTRIBUTEID));
comboxGoods.setSubName(attributes.get(ATTRIBUTENAME));
comboxGoods.setPic(isComboxGoods ? productComboType.getPicture() : groupDetailType.getPicture());
comboxGoods.setOriginalPrice(isComboxGoods ? (null != productComboType.getFinalPrice() ? productComboType.getFinalPrice().longValue() : 0L)
: (null != groupDetailType.getProductFinalPrice() ? groupDetailType.getProductFinalPrice().longValue() : 0L));
comboxGoods.setOriginalAmount(comboxGoods.getOriginalPrice() * comboxGoods.getQty());
comboxGoods.setAmount(finalPrice * comboxGoods.getQty());
comboxGoods.setCustomerCode(isComboxGoods ? (StringUtils.isNotEmpty(productComboType.getCustomerCode()) ? productComboType.getCustomerCode() : "")
: (StringUtils.isNotEmpty(groupDetailType.getCustomerCode()) ? groupDetailType.getCustomerCode() : ""));
comboxGoods.setFinalPrice(finalPrice);
comboxGoods.setWeightType(isComboxGoods ? CommonsConstant.WEIGHT_PRODUCT.equals(productComboType.getWeightType()) : CommonsConstant.WEIGHT_PRODUCT.equals(groupDetailType.getWeightType()));
comboxGoods.setUnit(isComboxGoods ? (StringUtils.isNotEmpty(productComboType.getUnit()) ? productComboType.getUnit() :"") :
(StringUtils.isNotEmpty(groupDetailType.getUnit()) ? groupDetailType.getUnit() : ""));
comboxGoods.setWeight(isComboxGoods ? (null == productComboType.getWeight() ? 0 : productComboType.getWeight()) :
(null == groupDetailType.getWeight() ? 0:groupDetailType.getWeight()));
comboxGoods.setTax(isComboxGoods ? (null == productComboType.getTax() ? 0 : productComboType.getTax())
: (null == groupDetailType.getTax() ? 0 : groupDetailType.getTax()));
comboxGoods.setTaxId(isComboxGoods ? (StringUtils.isNotEmpty(productComboType.getTaxId()) ? productComboType.getTaxId() : "") :
(StringUtils.isNotEmpty(groupDetailType.getTaxId()) ? groupDetailType.getTaxId() : ""));
//2020/10/22 套餐内可选商品加料,暂无
if(CollectionUtils.isNotEmpty(comboxGoods.getProductMaterialList())){
Map<String, ProductTypeBeanDTO.ProductGroupType.GroupDetailType> materialMap = new HashMap<>();
subProductTypeMap.get(comboxGoods.getSkuId()).getAdditionalGroupList().stream().map(t->t.getGroupDetail()).forEach(group->group.forEach(detailType-> materialMap.put(detailType.getProductId(),detailType)));
List<ProductTypeBeanDTO.ProductGroupType.GroupDetailType> materialList = new ArrayList<>();
comboxGoods.getProductMaterialList().stream().forEach(materialGood -> materialList.add(materialMap.get(materialGood.getSpuId())));
List<com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods> productMaterialList = new ArrayList<>();
Long materialAmount = 0L;
if (CollectionUtils.isNotEmpty(materialList)){
for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods productMaterial :comboxGoods.getProductMaterialList()) {
for (ProductTypeBeanDTO.ProductGroupType.GroupDetailType detailType : materialList) {
// productMaterial.setCustomerCode(StringUtils.isNotEmpty(detailType.getCustomerCode()) ? detailType.getCustomerCode() : "");
if (detailType.getProductId().equals(productMaterial.getSpuId())) {
productMaterial.setAmount(null != detailType.getMarkUpPrice() ? detailType.getMarkUpPrice().longValue() : 0);
productMaterial.setFinalPrice(null != detailType.getProductFinalPrice() ? detailType.getProductFinalPrice().longValue() : 0);
productMaterial.setSpuName(StringUtils.isNotEmpty(detailType.getProductName()) ? detailType.getProductName() : "");
productMaterial.setSpuId(StringUtils.isNotEmpty(detailType.getProductId()) ? detailType.getProductId() : "");
productMaterial.setOriginalPrice(null != detailType.getProductFinalPrice() ? detailType.getProductFinalPrice().longValue() : 0);
productMaterial.setOriginalAmount(null != detailType.getProductFinalPrice() ? detailType.getProductFinalPrice().longValue() * comboxGoods.getQty() : 0);
productMaterialList.add(productMaterial);
materialAmount += detailType.getProductFinalPrice().longValue() * comboxGoods.getQty();
}
}
}
}
comboxGoods.setMaterialAmount(materialAmount);
comboxGoods.setProductMaterialList(productMaterialList);
}
}
private Map<String, String> getAttributesNew(List<com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.CartGoodsExtra> extra) {
if (CollectionUtils.isEmpty(extra)) {
return new HashMap<>();
......@@ -756,7 +837,9 @@ public class ShoppingCartConvertAdapter {
private void checkMaterialProductForMCoffee(com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods cartGoods, ProductTypeBeanDTO spuProduct) {
if (CollectionUtils.isEmpty(cartGoods.getProductMaterialList())) return;
if (CollectionUtils.isEmpty(cartGoods.getProductMaterialList())) {
return;
}
//加料信息为空
if (CollectionUtils.isEmpty(spuProduct.getAdditionalGroupList())) {
checkSkuMaterialProductForMccafe(cartGoods,spuProduct);
......@@ -785,7 +868,9 @@ public class ShoppingCartConvertAdapter {
String materialSubName = cartGoods.getSubName();
for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods materialGoods : cartGoods.getProductMaterialList()) {
ProductTypeBeanDTO.ProductGroupType.GroupDetailType detail = materialHash.get(materialGoods.getSpuId());
if (detail == null) continue;
if (detail == null) {
continue;
}
com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods material = new com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.MaterialGoods();
material.setSpuName(detail.getProductName());
material.setSpuId(detail.getProductId());
......@@ -871,10 +956,18 @@ public class ShoppingCartConvertAdapter {
}
}else {
for (com.freemud.sdk.api.assortment.shoppingcart.domain.CartGoods.ComboxGoods productGroup : cartGoods.getProductGroupList()) {
updateComboxGoodsInfoForMCoffee(productGroup, spuProduct, false);
// updateComboxGoodsInfoForMCoffee(productGroup, spuProduct, false);
updateComboxGoodsInfoForMCoffeeProductGroup(productGroup,spuProduct,subProductTypeMap
,false);
}
}
}
//可选商品组加料价格加到购物车行记录上
Long materialAmount =
cartGoods.getProductGroupList().stream().mapToLong(group -> (null != group.getMaterialAmount() ? group.getMaterialAmount() : 0)).sum();
cartGoods.setOriginalMaterialAmount(materialAmount);
cartGoods.setMaterialAmount(materialAmount);
cartGoods.setOriginalAmount(cartGoods.getOriginalPrice()*cartGoods.getQty() + materialAmount);
}
}
//更新当前商品行价格
......@@ -902,12 +995,16 @@ public class ShoppingCartConvertAdapter {
cartGoods.setWeight(isSkuProduct ? skuProduct.getWeight() : spuProduct.getWeight());
cartGoods.setUnit(isSkuProduct ? skuProduct.getUnit() : spuProduct.getUnit());
cartGoods.setWeightType(CommonsConstant.WEIGHT_PRODUCT.equals(spuProduct.getWeightType()));
cartGoods.setMaterialAmount(0L);
cartGoods.setOriginalMaterialAmount(0L);
if (null == cartGoods.getMaterialAmount()) {
cartGoods.setMaterialAmount(0L);
}
if (null == cartGoods.getOriginalMaterialAmount()) {
cartGoods.setOriginalMaterialAmount(0L);
}
// todo 设置加料
this.checkMaterialProductForMCoffee(cartGoods, spuProduct);
} catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
ErrorLog.infoConvertJson(this.getClass(), "updateCartGoodsInfoForMCoffee_Error", ex);
cartGoods.setCartGoodsUid(null);
}
......@@ -1045,7 +1142,7 @@ public class ShoppingCartConvertAdapter {
;
materialSubName = materialSubName + "/" + detail.getProductName();
}
//设置购物车行记录
//设置购物车行加料列表
cartGoods.setProductMaterialList(materialGoodsList);
//加料行记录现价总价
cartGoods.setMaterialAmount(materialAmount);
......@@ -1062,4 +1159,4 @@ public class ShoppingCartConvertAdapter {
}
}
}
\ No newline at end of file
}
......@@ -425,6 +425,9 @@ public class CartGoods {
if (CollectionUtils.isNotEmpty(productGroupList)) {
for (ComboxGoods goods : productGroupList) {
originalString.append(goods.toString());
if (CollectionUtils.isNotEmpty(goods.getProductMaterialList())) {
goods.getProductMaterialList().stream().sorted(Comparator.comparing(MaterialGoods::getSpuId)).forEach(e -> originalString.append(e.getSpuId()));
}
}
}
if (CollectionUtils.isNotEmpty(productMaterialList)) {
......
......@@ -1489,6 +1489,7 @@ public class ShoppingCartMCoffeeServiceImpl {
CartGoods.MaterialGoods materialGoods = new CartGoods.MaterialGoods();
materialGoods.setSpuId(materialRequestVo.getSpuId());
materialGoods.setGroupId(materialRequestVo.getGroupId());
materialGoods.setCustomerCode(materialRequestVo.getCustomerCode());
comboxMaterialGoodsList.add(materialGoods);
}
productCombox.setProductMaterialList(comboxMaterialGoodsList);
......
......@@ -82,12 +82,8 @@ public class CalculationServiceImpl {
@Autowired
private MaterialCalculation materialCalculation;
// @Autowired
// private ShoppingCartConvertAdapter shoppingCartConvertAdapter;
@Autowired
private ShoppingCartMccafeAdapter shoppingCartMccafeAdapter;
// @Autowired
// private ItemServiceImpl itemService;
/**
* 更新购物车行优惠信息
......@@ -414,13 +410,26 @@ public class CalculationServiceImpl {
if("0".equals(materialGoods.getGoodsId())){
continue;
}
ActivityCalculationDiscountRequestDto.CalculationDiscountGoods.Material material = new ActivityCalculationDiscountRequestDto.CalculationDiscountGoods.Material();
material.setType(2);
material.setGoodsId(materialGoods.getGoodsId());
material.setGoodsQuantity(materialGoods.getQty());
material.setOriginalPrice(null != materialGoods.getFinalPrice() ?
ActivityCalculationDiscountRequestDto.CalculationDiscountGoods.Material productGroup =
new ActivityCalculationDiscountRequestDto.CalculationDiscountGoods.Material();
productGroup.setType(2);
productGroup.setGoodsId(materialGoods.getGoodsId());
productGroup.setGoodsQuantity(materialGoods.getQty());
productGroup.setOriginalPrice(null != materialGoods.getFinalPrice() ?
materialGoods.getFinalPrice() : 0);
materials.add(material);
materials.add(productGroup);
if (CollectionUtils.isNotEmpty(materialGoods.getProductMaterialList())){
for (CartGoods.MaterialGoods goods : materialGoods.getProductMaterialList()) {
ActivityCalculationDiscountRequestDto.CalculationDiscountGoods.Material material = new ActivityCalculationDiscountRequestDto.CalculationDiscountGoods.Material();
material.setType(1);
material.setGoodsId(goods.getSpuId());
material.setGoodsQuantity(1);
material.setOriginalPrice(null != goods.getFinalPrice() ?
goods.getFinalPrice() : 0);
materials.add(material);
}
}
}
}
......@@ -508,7 +517,7 @@ public class CalculationServiceImpl {
//单品、多规格加料
if(CollectionUtils.isNotEmpty(cartGoods.getProductMaterialList())){
for (CartGoods.MaterialGoods materialGoods : cartGoods.getProductMaterialList()){
materialPrice+= materialGoods.getFinalPrice() * cartGoods.getQty();
materialPrice+= (null != materialGoods.getFinalPrice() ? materialGoods.getFinalPrice() : 0) * (null != cartGoods.getQty() ? cartGoods.getQty() : 0);
}
}
return materialPrice;
......
......@@ -98,6 +98,21 @@ public class SetMealCalculation {
productGroupTotalAmount + productComboTotalAmount + materialPrice;
cartGoods.setAmount(amount);
}
//套餐可选商品加料
if(CollectionUtils.isNotEmpty(cartGoods.getProductGroupList())){
for (CartGoods.ComboxGoods comboxGoods : cartGoods.getProductGroupList()){
Long productGroupmaterialPrice = 0L;
if(CollectionUtils.isNotEmpty(comboxGoods.getProductMaterialList())){
for (CartGoods.MaterialGoods materialGoods : comboxGoods.getProductMaterialList()){
productGroupmaterialPrice+= null != materialGoods.getFinalPrice() ? materialGoods.getFinalPrice() * cartGoods.getQty() : 0;
}
}
comboxGoods.setAmount((null == comboxGoods.getAmount() ? 0 :
comboxGoods.getAmount())+productGroupmaterialPrice);
materialPrice = materialPrice + productGroupmaterialPrice;
}
}
Long comboOriginalPriceAmount = null != cartGoods.getOriginalAmount() ? cartGoods.getOriginalAmount() :
productComboTotalAmount;
cartGoods.setOriginalAmount(productGroupTotalAmount + comboOriginalPriceAmount + materialPrice);
......
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