Commit 976a80c8 by 林永健

feat(strategy): 添加套餐商品类型支持并完善商品状态查询

- 在MarketingPackageQueryMapper中新增findPackageByCode方法查询套餐信息
- 在MarketingActivityService中注入MarketingPackageQueryMapper依赖
- 使用switch语句重构商品类型处理逻辑,支持PACKAGE和GOODS类型
- 为套餐类型添加套餐编号验证和套餐存在性检查
- 为商品类型添加商品状态验证,确保商品已上架
- 在ORM映射文件中添加商品状态字段查询
- 在GoodsTypeInfoDTO中添加goodsStatus字段
- 优化itemName拼接逻辑,在车系名称后添加空格分隔符
1 parent 6cd60d44
......@@ -32,6 +32,10 @@ public class GoodsTypeInfoDTO implements Serializable {
@ApiModelProperty(notes = "商品类型名称")
private String goodsTypeName;
/** 商品状态 */
@ApiModelProperty(notes = "商品状态")
private Integer goodsStatus;
/** 现售价 */
@ApiModelProperty(notes = "现售价")
private BigDecimal currentPrice;
......
......@@ -27,4 +27,6 @@ public interface MarketingPackageQueryMapper {
@Param("merchantIds") List<Integer> merchantIds);
List<PackageItemRespDTO> findPackageItems(@Param("packageCode") String packageCode);
PackageRespDTO findPackageByCode(@Param("packageCode") String packageCode);
}
......@@ -54,6 +54,7 @@ public class MarketingActivityService {
private final MarketingActivityProductItemMapper marketingActivityProductItemMapper;
private final MarketingActivityOperationLogMapper marketingActivityOperationLogMapper;
private final MarketingGoodsQueryMapper marketingGoodsQueryMapper;
private final MarketingPackageQueryMapper marketingPackageQueryMapper;
private final MerchantRemote merchantRemote;
......@@ -735,36 +736,50 @@ public class MarketingActivityService {
p.setGoodsCode(req.getGoodsCode());
p.setPackageCode(req.getPackageCode());
if (!StringUtils.hasLength(req.getGoodsCode())) {
if (Objects.equals(req.getProductType(), ProductTypeEnum.GOODS.getValue())) {
log.warn("商品编号为空,productType=GOODS,但goodsCode为空,tabName={}", req.getTabName());
}
RpcAssert.assertIsTrue(!Objects.equals(req.getProductType(), ProductTypeEnum.GOODS.getValue()),
DefaultErrorEnum.SERVER_ERROR, "商品编号为空");
p.setCurrentPrice(req.getCurrentPrice());
p.setMinimumPrice(req.getMinimumPrice());
} else {
String itemName = StringUtils.hasText(req.getCarSeriesName()) ? req.getCarSeriesName() : "";
itemName += StringUtils.hasText(req.getProductName()) ? req.getProductName() : req.getTabName();
// 查询 goods_type/goods_type_name/现售价/最低限价(实时)
GoodsTypeInfoDTO goodsTypeInfo = lookupGoodsTypeInfo(itemName, req.getGoodsCode());
p.setGoodsType(goodsTypeInfo.getGoodsType());
p.setGoodsTypeName(goodsTypeInfo.getGoodsTypeName());
p.setCurrentPrice(goodsTypeInfo.getCurrentPrice());
p.setMinimumPrice(goodsTypeInfo.getMinimumPrice());
// 价格一致性校验:前端传入的现售价/最低限价必须与实时查询一致
if (req.getCurrentPrice().compareTo(p.getCurrentPrice()) != 0) {
log.warn("商品价格变更,现售价不一致,goodsCode={}, reqCurrentPrice={}, dbCurrentPrice={}",
req.getGoodsCode(), req.getCurrentPrice(), p.getCurrentPrice());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemName + "的产品信息存在变更,请重新选择");
}
if (req.getMinimumPrice().compareTo(p.getMinimumPrice()) != 0) {
log.warn("商品价格变更,最低限价不一致,goodsCode={}, reqMinPrice={}, dbMinPrice={}",
req.getGoodsCode(), req.getMinimumPrice(), p.getMinimumPrice());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemName + "的产品信息存在变更,请重新选择");
}
String itemName = StringUtils.hasText(req.getCarSeriesName()) ? req.getCarSeriesName() + " " : "";
itemName += StringUtils.hasText(req.getProductName()) ? req.getProductName() : req.getTabName();
ProductTypeEnum productTypeEnum = ProductTypeEnum.fromValue(req.getProductType());
RpcAssert.assertNotNull(productTypeEnum, DefaultErrorEnum.SERVER_ERROR, "商品类型错误");
switch (productTypeEnum) {
case PACKAGE:
RpcAssert.assertNotNull(req.getPackageCode(), DefaultErrorEnum.SERVER_ERROR, "套餐编号为空");
PackageRespDTO packageDTO = marketingPackageQueryMapper.findPackageByCode(req.getPackageCode());
if (Objects.isNull(packageDTO)) {
log.error("套餐不存在已上架记录,code:{}", req.getPackageCode());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemName + "的产品信息存在变更,请重新选择");
}
p.setCurrentPrice(req.getCurrentPrice());
p.setMinimumPrice(req.getMinimumPrice());
break;
case GOODS:
RpcAssert.assertNotNull(req.getGoodsCode(), DefaultErrorEnum.SERVER_ERROR, "商品编号为空");
// 查询 goods_type/goods_type_name/现售价/最低限价(实时)
GoodsTypeInfoDTO goodsTypeInfo = lookupGoodsTypeInfo(itemName, req.getGoodsCode());
if (!Objects.equals(goodsTypeInfo.getGoodsStatus(), 1)) {
log.error("商品未上架,goods:{}", goodsTypeInfo);
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemName + "的产品信息存在变更,请重新选择");
}
p.setGoodsType(goodsTypeInfo.getGoodsType());
p.setGoodsTypeName(goodsTypeInfo.getGoodsTypeName());
p.setCurrentPrice(goodsTypeInfo.getCurrentPrice());
p.setMinimumPrice(goodsTypeInfo.getMinimumPrice());
// 价格一致性校验:前端传入的现售价/最低限价必须与实时查询一致
if (req.getCurrentPrice().compareTo(p.getCurrentPrice()) != 0) {
log.warn("商品价格变更,现售价不一致,goodsCode={}, reqCurrentPrice={}, dbCurrentPrice={}",
req.getGoodsCode(), req.getCurrentPrice(), p.getCurrentPrice());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemName + "的产品信息存在变更,请重新选择");
}
if (req.getMinimumPrice().compareTo(p.getMinimumPrice()) != 0) {
log.warn("商品价格变更,最低限价不一致,goodsCode={}, reqMinPrice={}, dbMinPrice={}",
req.getGoodsCode(), req.getMinimumPrice(), p.getMinimumPrice());
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, itemName + "的产品信息存在变更,请重新选择");
}
break;
default:
log.error("异常类型无匹配");
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "商品类型错误");
}
p.setProductName(req.getProductName());
......@@ -813,7 +828,7 @@ public class MarketingActivityService {
if (CollectionUtils.isEmpty(items)) return;
List<MarketingActivityProductItem> list = items.stream().map(req -> {
String itemLabel = StringUtils.hasText(productReq.getCarSeriesName()) ? productReq.getCarSeriesName() : "";
String itemLabel = StringUtils.hasText(productReq.getCarSeriesName()) ? productReq.getCarSeriesName() + " " : "";
itemLabel += StringUtils.hasText(req.getGoodsName()) ? req.getGoodsName() : req.getGoodsCode();
MarketingActivityProductItem item = new MarketingActivityProductItem();
......
......@@ -76,6 +76,7 @@
mgi.goods_alias AS goodsAlias,
gi.goods_type AS goodsType,
gi.goods_type_name AS goodsTypeName,
mgi.status AS goodsStatus,
COALESCE(mgi.sell_price, 0) AS currentPrice,
COALESCE(mgi.min_sell_price, 0) AS minimumPrice
FROM dj_car_life_merchant_goods_info mgi
......
......@@ -90,4 +90,17 @@
ORDER BY mgi.id ASC
</select>
<select id="findPackageByCode" resultType="cn.com.glsx.dj.strategy.dto.PackageRespDTO">
SELECT
p.package_code AS packageId,
p.package_name AS packageName,
p.scene_type AS scene,
p.base_scene_code AS baseSceneCode
FROM dj_car_life_merchant_package_goods_info p
WHERE p.deleted_flag = 'N'
AND p.status = 1
AND p.package_code = #{packageCode}
limit 1
</select>
</mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!