新增按套餐版本查询销售附加费关联,优化产品附加费展示逻辑

This commit is contained in:
wuweihua
2026-11-20 14:48:08 +08:00
parent a98c8a6c42
commit 8c3e7f8616
6 changed files with 131 additions and 34 deletions
@@ -16,6 +16,9 @@ public interface PrcSurchargeRelMapper
*/
public List<PrcSurchargeRel> selectPrcSurchargeRelList(PrcSurchargeRel rel);
/** 按套餐版本查销售附加费关联(产品或明细) */
public List<PrcSurchargeRel> selectSalesRelsByPsvId(@Param("psvId") Long psvId);
public List<PrcSurchargeRel> selectByDetailIdsAndPriceType(
@Param("detailIds") List<Long> detailIds,
@Param("priceType") String priceType);
@@ -84,8 +84,8 @@ public interface IPrcPriceSetService
public List<PrcPriceSetDetail> selectDetailListByVersion(Long psvId);
/**
* 版本明细搜索下拉选项:按版本去重后的 产品/国家/分区 列表。
* 返回 { products: [{code,name}], countries: [{code,name}], zones: [{code,name}] }
* 版本明细搜索下拉选项:按版本去重后的 产品/国家/分区。
* products 项含 surcharges(轻量,供查看详情产品列表)。
*/
public Map<String, Object> selectDetailOptions(Long psvId);
@@ -994,13 +994,87 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
zones.putIfAbsent(zoneCode != null ? zoneCode : zoneName, item);
}
}
// 补全套餐产品表(无明细时也能展示)
PrcPriceSetProduct pq = new PrcPriceSetProduct();
pq.setPsvId(psvId);
List<PrcPriceSetProduct> setProducts = setProductMapper.selectPrcPriceSetProductList(pq);
if (setProducts != null)
{
for (PrcPriceSetProduct sp : setProducts)
{
if (sp == null || StringUtils.isBlank(sp.getProductCode()))
{
continue;
}
Map<String, String> item = new LinkedHashMap<String, String>();
item.put("code", sp.getProductCode());
item.put("name", StringUtils.isNotBlank(sp.getProductName()) ? sp.getProductName() : sp.getProductCode());
products.putIfAbsent(sp.getProductCode(), item);
}
}
// 产品列表轻量挂附加费,避免查看详情拉整版明细
Map<String, List<PrcSurchargeRel>> scByProduct = loadSalesSurchargesByProduct(psvId);
List<Map<String, Object>> productRows = new ArrayList<Map<String, Object>>();
for (Map<String, String> p : products.values())
{
Map<String, Object> row = new LinkedHashMap<String, Object>();
row.put("code", p.get("code"));
row.put("name", p.get("name"));
String code = p.get("code");
List<PrcSurchargeRel> sc = code == null ? null : scByProduct.get(code);
row.put("surcharges", sc != null ? sc : new ArrayList<PrcSurchargeRel>());
productRows.add(row);
}
Map<String, Object> result = new HashMap<String, Object>();
result.put("products", new ArrayList<Map<String, String>>(products.values()));
result.put("products", productRows);
result.put("countries", new ArrayList<Map<String, String>>(countries.values()));
result.put("zones", new ArrayList<Map<String, String>>(zones.values()));
return result;
}
/** 按产品代码汇总版本销售附加费(scId 去重) */
private Map<String, List<PrcSurchargeRel>> loadSalesSurchargesByProduct(Long psvId)
{
Map<String, List<PrcSurchargeRel>> out = new LinkedHashMap<String, List<PrcSurchargeRel>>();
if (psvId == null)
{
return out;
}
List<PrcSurchargeRel> rels = surchargeRelMapper.selectSalesRelsByPsvId(psvId);
if (rels == null || rels.isEmpty())
{
return out;
}
Map<String, Map<Long, PrcSurchargeRel>> dedupe = new LinkedHashMap<String, Map<Long, PrcSurchargeRel>>();
for (PrcSurchargeRel rel : rels)
{
if (rel == null || rel.getScId() == null)
{
continue;
}
String code = StringUtils.trim(rel.getProductCode());
if (StringUtils.isEmpty(code))
{
continue;
}
Map<Long, PrcSurchargeRel> bySc = dedupe.get(code);
if (bySc == null)
{
bySc = new LinkedHashMap<Long, PrcSurchargeRel>();
dedupe.put(code, bySc);
}
if (!bySc.containsKey(rel.getScId()))
{
bySc.put(rel.getScId(), rel);
}
}
for (Map.Entry<String, Map<Long, PrcSurchargeRel>> e : dedupe.entrySet())
{
out.put(e.getKey(), new ArrayList<PrcSurchargeRel>(e.getValue().values()));
}
return out;
}
/** 为一页明细挂载 SALES 附加费关联(detail_id=psd_id)。 */
private void fillDetailSurcharges(List<PrcPriceSetDetail> details)
{
@@ -3670,6 +3744,7 @@ public class PrcPriceSetServiceImpl implements IPrcPriceSetService
version.setProducts(products == null ? new ArrayList<PrcPriceSetProduct>() : products);
// 明细 + SALES 附加费关联按需加载(编辑价格/明细抽屉)
version.setDetails(new ArrayList<PrcPriceSetDetail>());
version.setDetailCount(Integer.valueOf(detailMapper.countByPsvId(version.getPsvId())));
}
private PrcPriceSetVersion pickCurrentVersion(List<PrcPriceSetVersion> versions)
@@ -71,19 +71,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
bp.fv_registration_fee as base_registration_fee,
d.discount_value, d.round_mode, d.pr_id, d.effective_date, d.expire_date, d.is_del, d.create_time, d.update_time
from prc_price_set_detail d
left join prc_price_set_detail bp
on bp.price_type = 'PRODUCT'
and bp.product_code = d.product_code
and ifnull(bp.country_code,'') = ifnull(d.country_code,'')
and ifnull(bp.zone_code,'') = ifnull(d.zone_code,'')
and ifnull(bp.weight_min,-1) = ifnull(d.weight_min,-1)
and ifnull(bp.weight_max,-1) = ifnull(d.weight_max,-1)
and ifnull(bp.is_del, '0') = '0'
and bp.psv_id = (
select v.psv_id from prc_price_set_version v
where v.price_type = 'PRODUCT' and v.price_set_id is null and v.status = '1'
order by v.version_seq desc limit 1
)
left join (
select bp0.psd_id, bp0.product_code, bp0.country_code, bp0.zone_code,
bp0.weight_min, bp0.weight_max, bp0.fv_value, bp0.fv_registration_fee
from prc_price_set_detail bp0
where bp0.price_type = 'PRODUCT'
and ifnull(bp0.is_del, '0') = '0'
and bp0.psv_id = (
select v.psv_id from prc_price_set_version v
where v.price_type = 'PRODUCT' and v.price_set_id is null and v.status = '1'
order by v.version_seq desc limit 1
)
) bp
on bp.product_code = d.product_code
and bp.country_code &lt;=&gt; d.country_code
and bp.zone_code &lt;=&gt; d.zone_code
and bp.weight_min &lt;=&gt; d.weight_min
and bp.weight_max &lt;=&gt; d.weight_max
<where>
and ifnull(d.is_del, '0') = '0'
@@ -80,6 +80,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by r.detail_id is not null, r.rel_id asc
</select>
<!-- 按套餐版本轻量查销售附加费(产品/明细关联),供查看详情产品列表 -->
<select id="selectSalesRelsByPsvId" resultMap="PrcSurchargeRelResult">
select r.rel_id, r.sc_id, r.product_id,
coalesce(nullif(trim(r.product_code), ''), p.product_code, d.product_code) as product_code,
r.detail_id, r.price_type, r.country_code, r.is_del,
r.created_by, r.create_time, r.updated_by, r.update_time,
s.sc_name, s.fee_type, s.charge_type, s.charge_value, s.currency,
s.round_mode, s.ss_code, s.sc_note,
s.postcode_text, s.length_cm, s.width_cm, s.height_cm, s.size_type, s.volume_m3,
s.over_weight_kg, s.extra_weight_kg, s.block_title,
null as country_name, null as weight_min, null as weight_max
from prc_surcharge_rel r
join prc_surcharge s on s.sc_id = r.sc_id and ifnull(s.is_del, '0') = '0'
left join prc_price_set_product p on p.psp_id = r.product_id and p.psv_id = #{psvId}
left join prc_price_set_detail d on d.psd_id = r.detail_id and d.psv_id = #{psvId} and ifnull(d.is_del, '0') = '0'
where ifnull(r.is_del, '0') = '0'
and r.price_type = 'SALES'
and (p.psp_id is not null or d.psd_id is not null)
order by r.rel_id asc
</select>
<select id="selectByDetailIdsAndPriceType" resultMap="PrcSurchargeRelResult">
<include refid="selectPrcSurchargeRelVo"/>
where ifnull(r.is_del, '0') = '0'