Commit 6cd60d44 by 林永健

fix(marketing): 修复营销活动商品价格校验和数据传递问题

- 在构建商品时设置车系名称到商品请求对象
- 修改批量插入套餐子商品方法参数结构
- 优化商品价格一致性校验逻辑,直接与数据库记录比较
- 更新查询商品信息方法,增加错误处理和空值保护
- 添加车系名称字段用于错误提示信息拼接
- 修复套餐子商品价格校验中的实体属性引用错误
1 parent 4b1bc8b9
package cn.com.glsx.dj.strategy.dto; package cn.com.glsx.dj.strategy.dto;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.persistence.Transient;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
...@@ -88,6 +90,10 @@ public class MarketingActivityProductReqDTO implements Serializable { ...@@ -88,6 +90,10 @@ public class MarketingActivityProductReqDTO implements Serializable {
@ApiModelProperty(notes = "内容详图URL") @ApiModelProperty(notes = "内容详图URL")
private String detailImageUrl; private String detailImageUrl;
@JsonIgnore
@Transient
private String carSeriesName;
/** 套餐子商品(productType=PACKAGE时) */ /** 套餐子商品(productType=PACKAGE时) */
@ApiModelProperty(notes = "套餐子商品列表(productType=PACKAGE时必填)") @ApiModelProperty(notes = "套餐子商品列表(productType=PACKAGE时必填)")
private List<MarketingActivityProductItemReqDTO> packageItems; private List<MarketingActivityProductItemReqDTO> packageItems;
......
...@@ -687,6 +687,7 @@ public class MarketingActivityService { ...@@ -687,6 +687,7 @@ public class MarketingActivityService {
// 构建当前车系下的商品/套餐 // 构建当前车系下的商品/套餐
if (!CollectionUtils.isEmpty(csReq.getProducts())) { if (!CollectionUtils.isEmpty(csReq.getProducts())) {
for (MarketingActivityProductReqDTO prodReq : csReq.getProducts()) { for (MarketingActivityProductReqDTO prodReq : csReq.getProducts()) {
prodReq.setCarSeriesName(csReq.getCarSeriesName());
MarketingActivityProduct product = buildProduct(activityId, targetCarSeriesId, prodReq, createdBy); MarketingActivityProduct product = buildProduct(activityId, targetCarSeriesId, prodReq, createdBy);
allProductList.add(product); allProductList.add(product);
allProductReqList.add(prodReq); allProductReqList.add(prodReq);
...@@ -704,7 +705,7 @@ public class MarketingActivityService { ...@@ -704,7 +705,7 @@ public class MarketingActivityService {
MarketingActivityProductReqDTO req = allProductReqList.get(i); MarketingActivityProductReqDTO req = allProductReqList.get(i);
if (ProductTypeEnum.PACKAGE.getValue().equals(req.getProductType()) if (ProductTypeEnum.PACKAGE.getValue().equals(req.getProductType())
&& !CollectionUtils.isEmpty(req.getPackageItems())) { && !CollectionUtils.isEmpty(req.getPackageItems())) {
batchInsertItems(p.getId(), req.getPackageCode(), req.getPackageItems(), createdBy); batchInsertItems(p.getId(), req, createdBy);
} }
} }
} }
...@@ -743,25 +744,25 @@ public class MarketingActivityService { ...@@ -743,25 +744,25 @@ public class MarketingActivityService {
p.setCurrentPrice(req.getCurrentPrice()); p.setCurrentPrice(req.getCurrentPrice());
p.setMinimumPrice(req.getMinimumPrice()); p.setMinimumPrice(req.getMinimumPrice());
} else { } else {
String itemName = StringUtils.hasText(req.getCarSeriesName()) ? req.getCarSeriesName() : "";
itemName += StringUtils.hasText(req.getProductName()) ? req.getProductName() : req.getTabName();
// 查询 goods_type/goods_type_name/现售价/最低限价(实时) // 查询 goods_type/goods_type_name/现售价/最低限价(实时)
GoodsTypeInfoDTO goodsTypeInfo = lookupGoodsTypeInfo(req.getGoodsCode()); GoodsTypeInfoDTO goodsTypeInfo = lookupGoodsTypeInfo(itemName, req.getGoodsCode());
p.setGoodsType(goodsTypeInfo.getGoodsType()); p.setGoodsType(goodsTypeInfo.getGoodsType());
p.setGoodsTypeName(goodsTypeInfo.getGoodsTypeName()); p.setGoodsTypeName(goodsTypeInfo.getGoodsTypeName());
p.setCurrentPrice(goodsTypeInfo.getCurrentPrice()); p.setCurrentPrice(goodsTypeInfo.getCurrentPrice());
p.setMinimumPrice(goodsTypeInfo.getMinimumPrice()); p.setMinimumPrice(goodsTypeInfo.getMinimumPrice());
// 价格一致性校验:前端传入的现售价/最低限价必须与实时查询一致 // 价格一致性校验:前端传入的现售价/最低限价必须与实时查询一致
String itemName = StringUtils.hasText(req.getProductName()) ? req.getProductName() : req.getTabName(); if (req.getCurrentPrice().compareTo(p.getCurrentPrice()) != 0) {
if (req.getCurrentPrice() != null && goodsTypeInfo.getCurrentPrice() != null
&& req.getCurrentPrice().compareTo(goodsTypeInfo.getCurrentPrice()) != 0) {
log.warn("商品价格变更,现售价不一致,goodsCode={}, reqCurrentPrice={}, dbCurrentPrice={}", log.warn("商品价格变更,现售价不一致,goodsCode={}, reqCurrentPrice={}, dbCurrentPrice={}",
req.getGoodsCode(), req.getCurrentPrice(), goodsTypeInfo.getCurrentPrice()); req.getGoodsCode(), req.getCurrentPrice(), p.getCurrentPrice());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemName + "的产品信息存在变更,请重新选择"); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemName + "的产品信息存在变更,请重新选择");
} }
if (req.getMinimumPrice() != null && goodsTypeInfo.getMinimumPrice() != null if (req.getMinimumPrice().compareTo(p.getMinimumPrice()) != 0) {
&& req.getMinimumPrice().compareTo(goodsTypeInfo.getMinimumPrice()) != 0) {
log.warn("商品价格变更,最低限价不一致,goodsCode={}, reqMinPrice={}, dbMinPrice={}", log.warn("商品价格变更,最低限价不一致,goodsCode={}, reqMinPrice={}, dbMinPrice={}",
req.getGoodsCode(), req.getMinimumPrice(), goodsTypeInfo.getMinimumPrice()); req.getGoodsCode(), req.getMinimumPrice(), p.getMinimumPrice());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemName + "的产品信息存在变更,请重新选择"); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemName + "的产品信息存在变更,请重新选择");
} }
} }
...@@ -806,9 +807,15 @@ public class MarketingActivityService { ...@@ -806,9 +807,15 @@ public class MarketingActivityService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private void batchInsertItems(Integer activityProductId, String packageCode, List<MarketingActivityProductItemReqDTO> items, String createdBy) { private void batchInsertItems(Integer activityProductId, MarketingActivityProductReqDTO productReq, String createdBy) {
String packageCode = productReq.getPackageCode();
List<MarketingActivityProductItemReqDTO> items = productReq.getPackageItems();
if (CollectionUtils.isEmpty(items)) return; if (CollectionUtils.isEmpty(items)) return;
List<MarketingActivityProductItem> list = items.stream().map(req -> { List<MarketingActivityProductItem> list = items.stream().map(req -> {
String itemLabel = StringUtils.hasText(productReq.getCarSeriesName()) ? productReq.getCarSeriesName() : "";
itemLabel += StringUtils.hasText(req.getGoodsName()) ? req.getGoodsName() : req.getGoodsCode();
MarketingActivityProductItem item = new MarketingActivityProductItem(); MarketingActivityProductItem item = new MarketingActivityProductItem();
item.setActivityProductId(activityProductId); item.setActivityProductId(activityProductId);
item.setPackageCode(packageCode); item.setPackageCode(packageCode);
...@@ -817,19 +824,16 @@ public class MarketingActivityService { ...@@ -817,19 +824,16 @@ public class MarketingActivityService {
item.setUpgradeProductId(req.getUpgradeProductId()); item.setUpgradeProductId(req.getUpgradeProductId());
item.setGoodsAlias(req.getGoodsAlias()); item.setGoodsAlias(req.getGoodsAlias());
// 查询 goods_type/goods_type_name/最低限价(实时) // 查询 goods_type/goods_type_name/最低限价(实时)
GoodsTypeInfoDTO gti = lookupGoodsTypeInfo(req.getGoodsCode()); GoodsTypeInfoDTO gti = lookupGoodsTypeInfo(itemLabel, req.getGoodsCode());
item.setGoodsType(gti.getGoodsType()); item.setGoodsType(gti.getGoodsType());
item.setGoodsTypeName(gti.getGoodsTypeName()); item.setGoodsTypeName(gti.getGoodsTypeName());
item.setMinimumPrice(gti.getMinimumPrice()); item.setMinimumPrice(gti.getMinimumPrice());
// 价格一致性校验:前端传入的最低限价必须与实时查询一致 // 价格一致性校验:前端传入的最低限价必须与实时查询一致
String itemLabel = StringUtils.hasText(req.getGoodsName()) ? req.getGoodsName() : req.getGoodsCode(); if (req.getMinimumPrice().compareTo(item.getMinimumPrice()) != 0) {
if (req.getMinimumPrice() != null && gti.getMinimumPrice() != null
&& req.getMinimumPrice().compareTo(gti.getMinimumPrice()) != 0) {
log.warn("套餐子商品价格变更,最低限价不一致,goodsCode={}, reqMinPrice={}, dbMinPrice={}", log.warn("套餐子商品价格变更,最低限价不一致,goodsCode={}, reqMinPrice={}, dbMinPrice={}",
req.getGoodsCode(), req.getMinimumPrice(), gti.getMinimumPrice()); req.getGoodsCode(), req.getMinimumPrice(), item.getMinimumPrice());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemLabel + "的产品信息存在变更,请重新选择");
itemLabel + "的产品信息存在变更,请重新选择");
} }
item.setCurrentPrice(req.getCurrentPrice()); item.setCurrentPrice(req.getCurrentPrice());
...@@ -846,14 +850,19 @@ public class MarketingActivityService { ...@@ -846,14 +850,19 @@ public class MarketingActivityService {
/** /**
* 根据 goodsCode 查询 goods_type/现售价/最低限价 * 根据 goodsCode 查询 goods_type/现售价/最低限价
*/ */
private GoodsTypeInfoDTO lookupGoodsTypeInfo(String goodsCode) { private GoodsTypeInfoDTO lookupGoodsTypeInfo(String errMsg, String goodsCode) {
if (StringUtils.hasLength(goodsCode)) { if (!StringUtils.hasLength(goodsCode)) {
GoodsTypeInfoDTO result = marketingGoodsQueryMapper.findGoodsTypeInfo(goodsCode); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "商品编码不能为空");
if (result != null) { }
return result; GoodsTypeInfoDTO result = marketingGoodsQueryMapper.findGoodsTypeInfo(goodsCode);
} if (result == null) {
} log.error("查询商品信息异常, goodsCode:{}", goodsCode);
return new GoodsTypeInfoDTO(); throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, errMsg + "的产品信息存在变更,请重新选择");
}
// 置0,方便比对值
result.setCurrentPrice(Objects.isNull(result.getCurrentPrice()) ? BigDecimal.ZERO : result.getCurrentPrice());
result.setMinimumPrice(Objects.isNull(result.getMinimumPrice()) ? BigDecimal.ZERO : result.getMinimumPrice());
return result;
} }
private void saveOperationLog(Integer activityId, ActivityEventTypeEnum eventType, String operatorId, String operatorName) { private void saveOperationLog(Integer activityId, ActivityEventTypeEnum eventType, String operatorId, String operatorName) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!