Commit c29ee971 by chenxi

feat(inventory): 推导套餐商品库存管控模式

- 新增接口根据商户商品编码和库存维度查询同门店同维度非套餐已上架商品库存管控记录
- 实现库存管控模式推导逻辑,支持按商品类型或升级商品ID匹配
- 修改XML映射文件,添加对应SQL查询以支持推导功能
- 库存服务中套餐商品库存管控模式获取方法新增兜底逻辑
- 配置文件支持库存维度的动态设置,日志记录推导过程和结果
- 异常情况下默认返回实物库存模式,确保系统稳定运行
1 parent 66d3c42c
...@@ -73,4 +73,20 @@ public interface MerchantGoodsInventoryTypeRefMapper extends OreMapper<MerchantG ...@@ -73,4 +73,20 @@ public interface MerchantGoodsInventoryTypeRefMapper extends OreMapper<MerchantG
*/ */
List<MerchantGoodsInventoryTypeRef> findByPackageCode( List<MerchantGoodsInventoryTypeRef> findByPackageCode(
@Param("packageCode") String packageCode); @Param("packageCode") String packageCode);
/**
* 套餐商品库存管控模式推导:根据 merchantGoodsCode 查同门店同维度非套餐已上架商品的库存管控记录
* <p>
* 当维度为 type 时,按照升级商品 type 字段匹配;当维度为 upgrade_goods_id 时,按升级商品ID匹配。
* 查询结果排除套餐商品,取第一条。
*
* @param merchantId 商户ID
* @param merchantGoodsCode 商户商品编码(套餐子商品)
* @param inventoryTypeDimension 库存维度("type" 或 "upgrade_goods_id")
* @return 第一条匹配的非套餐已上架商品库存管控记录,无则返回 null
*/
MerchantGoodsInventoryTypeRef findNonPackageOnShelfByMerchantGoodsCode(
@Param("merchantId") Integer merchantId,
@Param("merchantGoodsCode") String merchantGoodsCode,
@Param("inventoryTypeDimension") String inventoryTypeDimension);
} }
...@@ -289,12 +289,50 @@ public class MerchantGoodsInventoryTypeRefService { ...@@ -289,12 +289,50 @@ public class MerchantGoodsInventoryTypeRefService {
if (ref != null && ref.getInventoryType() != null) { if (ref != null && ref.getInventoryType() != null) {
return ref.getInventoryType(); return ref.getInventoryType();
} }
// 套餐商品兜底: ref 为空或 inventoryType 为空,且该商品属于套餐子商品(package_code 非空)
// 则按相同门店、相同维度查询非套餐已上架商品的库存管控模式,取第一条
if (ref != null && StringUtils.isNotBlank(ref.getPackageCode())) {
String dimension = env.getProperty(INVENTORY_TYPE_DIMENSION_KEY, DIMENSION_TYPE);
log.info("套餐子商品出库库存管控模式推导, merchantId={}, merchantGoodsCode={}, dimension={}",
merchantId, merchantGoodsCode, dimension);
MerchantGoodsInventoryTypeRef fallback =
mapper.findNonPackageOnShelfByMerchantGoodsCode(merchantId, merchantGoodsCode, dimension);
if (fallback != null && fallback.getInventoryType() != null) {
log.info("套餐子商品推导到库存管控模式: {}", fallback.getInventoryType());
return fallback.getInventoryType();
}
}
} catch (Exception e) { } catch (Exception e) {
log.warn("getInventoryTypeByMerchantGoodsCode 查询失败,merchantId={}, merchantGoodsCode={}", merchantId, merchantGoodsCode, e); log.warn("getInventoryTypeByMerchantGoodsCode 查询失败,merchantId={}, merchantGoodsCode={}", merchantId, merchantGoodsCode, e);
} }
return INVENTORY_TYPE_PHYSICAL; return INVENTORY_TYPE_PHYSICAL;
} }
/**
* 根据 merchantId + merchantGoodsCode 查询库存管控模式。
* <p>
* 若记录不存在或 inventoryType 为 null,则返回默认实物库存模式 (2)。
*
* @param merchantId 商户ID
* @param merchantGoodsCode 商户商品编码
* @return 库存管控模式(InventoryTypeEnum.VIRTUAL.getValue() 或 InventoryTypeEnum.PHYSICAL.getValue())
*/
/* public Byte getInventoryTypeByMerchantGoodsCode(Integer merchantId, String merchantGoodsCode) {
if (merchantId == null || StringUtils.isBlank(merchantGoodsCode)) {
return INVENTORY_TYPE_PHYSICAL;
}
try {
MerchantGoodsInventoryTypeRef ref =
mapper.findByMerchantIdAndMerchantGoodsCode(merchantId, merchantGoodsCode);
if (ref != null && ref.getInventoryType() != null) {
return ref.getInventoryType();
}
} catch (Exception e) {
log.warn("getInventoryTypeByMerchantGoodsCode 查询失败,merchantId={}, merchantGoodsCode={}", merchantId, merchantGoodsCode, e);
}
return INVENTORY_TYPE_PHYSICAL;
}*/
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// 同步/继承核心逻辑(由 MerchantGoodsInfoService.updateBatchWaitAudit 调用) // 同步/继承核心逻辑(由 MerchantGoodsInfoService.updateBatchWaitAudit 调用)
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
......
...@@ -111,4 +111,43 @@ ...@@ -111,4 +111,43 @@
AND ir.deleted_flag = 'N' AND ir.deleted_flag = 'N'
</select> </select>
<!--
套餐商品库存管控模式推导:
根据 merchantGoodsCode 找到当前套餐子商品的 upgradeGoodsId 和 type,
再按相同门店、相同维度查询同维度非套餐已上架商品的库存管控模式,取第一条。
-->
<select id="findNonPackageOnShelfByMerchantGoodsCode" resultMap="BaseResultMap">
SELECT ir.id, ir.merchant_goods_id, ir.package_code, ir.inventory_type, ir.merchant_id,
ir.created_by, ir.created_date, ir.updated_by, ir.updated_date, ir.deleted_flag
FROM dj_car_life_merchant_goods_inventory_type_ref ir
INNER JOIN dj_car_life_merchant_goods_info mgi ON mgi.id = ir.merchant_goods_id
INNER JOIN dj_car_life_upgrade_goods ug ON ug.id = mgi.upgrade_goods_id
WHERE ir.merchant_id = #{merchantId}
AND ir.deleted_flag = 'N'
AND mgi.deleted_flag = 'N'
AND mgi.status = 1
AND (mgi.package_code IS NULL OR mgi.package_code = '')
AND ug.deleted_flag = 'N'
<if test="inventoryTypeDimension == 'type'">
AND ug.type = (
SELECT ug2.type
FROM dj_car_life_merchant_goods_info mgi2
INNER JOIN dj_car_life_upgrade_goods ug2 ON ug2.id = mgi2.upgrade_goods_id
WHERE mgi2.merchant_goods_code = #{merchantGoodsCode}
AND mgi2.deleted_flag = 'N'
LIMIT 1
)
</if>
<if test="inventoryTypeDimension == 'upgrade_goods_id'">
AND mgi.upgrade_goods_id = (
SELECT mgi2.upgrade_goods_id
FROM dj_car_life_merchant_goods_info mgi2
WHERE mgi2.merchant_goods_code = #{merchantGoodsCode}
AND mgi2.deleted_flag = 'N'
LIMIT 1
)
</if>
LIMIT 1
</select>
</mapper> </mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!