产品id绑定改为code绑定

This commit is contained in:
luojiaquan
2026-09-22 11:20:51 +08:00
parent e0df965d89
commit 91e9a0c9b7
8 changed files with 91 additions and 64 deletions
@@ -107,9 +107,9 @@ public class BmsCustomer extends BaseEntity
@Excel(name = "信用额度", readConverterExp = "元=")
private BigDecimal creditEd;
/** 绑定产品ID(多个产品ID用逗号分隔,支持批量操作) */
@Excel(name = "绑定产品ID", readConverterExp = "多=个产品ID用逗号分隔,支持批量操作")
private String productIds;
/** 绑定产品代码(多个产品代码用逗号分隔;旧库导入产品ID不稳定,统一用代码对接) */
@Excel(name = "绑定产品代码")
private String productCodes;
/** 附件列表(子表 bms_customer_attachment) */
private List<BmsCustomerAttachment> attachmentList;
@@ -27,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="weightThreshold" column="weight_threshold" />
<result property="throwRatio" column="throw_ratio" />
<result property="creditEd" column="credit_ed" />
<result property="productIds" column="product_ids" />
<result property="productCodes" column="product_codes" />
<result property="remark" column="remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
@@ -51,7 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
(select coalesce(sum(ca.total_credit+ca.extra_credit-ca.used_credit), 0) from customer_account ca
where ca.customer_id = c.customer_id and ca.del_flag = '0') as credit_ed,
c.product_ids, c.remark,
c.product_codes, c.remark,
c.create_by, c.create_time, c.update_by, c.update_time, c.del_flag
from bms_customer c
<!-- 数据权限:销售(仅本人 c.sales_user_id)/销售经理(本部门 su.dept_id);
@@ -82,7 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="weightThreshold != null "> and c.weight_threshold = #{weightThreshold}</if>
<if test="throwRatio != null "> and c.throw_ratio = #{throwRatio}</if>
<if test="creditEd != null "> and c.credit_ed = #{creditEd}</if>
<if test="productIds != null and productIds != ''"> and c.product_ids = #{productIds}</if>
<if test="productCodes != null and productCodes != ''"> and c.product_codes = #{productCodes}</if>
<!-- 数据权限过滤(@DataScope 生成:仅本人= c.sales_user_id=当前用户;本部门= su.dept_id=当前用户部门) -->
${params.dataScope}
</where>
@@ -253,7 +253,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="weightThreshold != null">weight_threshold,</if>
<if test="throwRatio != null">throw_ratio,</if>
<if test="creditEd != null">credit_ed,</if>
<if test="productIds != null">product_ids,</if>
<if test="productCodes != null">product_codes,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
@@ -283,7 +283,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="weightThreshold != null">#{weightThreshold},</if>
<if test="throwRatio != null">#{throwRatio},</if>
<if test="creditEd != null">#{creditEd},</if>
<if test="productIds != null">#{productIds},</if>
<if test="productCodes != null">#{productCodes},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
@@ -315,7 +315,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="foreignCurrencyBalance != null">foreign_currency_balance = #{foreignCurrencyBalance},</if>
<if test="weightThreshold != null">weight_threshold = #{weightThreshold},</if>
<if test="throwRatio != null">throw_ratio = #{throwRatio},</if>
<if test="productIds != null">product_ids = #{productIds},</if>
<if test="productCodes != null">product_codes = #{productCodes},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
+1 -1
View File
@@ -29,7 +29,7 @@ CREATE TABLE `bms_customer` (
`weight_threshold` decimal(15,2) DEFAULT 0.00 COMMENT '重量阈值(kg)',
`throw_ratio` decimal(15,2) DEFAULT 0.00 COMMENT '抛比(%)',
`credit_ed` decimal(15,2) DEFAULT 0.00 COMMENT '信用额度(元)',
`product_ids` varchar(1000) DEFAULT NULL COMMENT '绑定产品ID(多个产品ID用逗号分隔,支持批量操作)',
`product_codes` varchar(1000) DEFAULT NULL COMMENT '绑定产品代码(多个产品代码用逗号分隔,对接旧库产品编码)',
-- ========== 附件字段(新增) ==========
`logo_oss_id` bigint(20) DEFAULT NULL COMMENT '客户Logo(图片,关联sys_oss.oss_id)',
@@ -0,0 +1,23 @@
-- =====================================================================
-- 客户绑定产品:存储口径由「产品ID逗号串」改为「产品代码逗号串」
-- 背景:后续产品数据从旧数据库迁移导入,新旧库产品ID不一致,
-- 产品代码(product_code)在两库间稳定,故客户绑定关系改用代码。
-- 日期:2026-09-22
-- =====================================================================
-- 1. 列改名(保留原数据,CHANGE 仅改列名/注释)
ALTER TABLE bms_customer
CHANGE COLUMN product_ids product_codes varchar(1000) DEFAULT NULL
COMMENT '绑定产品代码(多个产品代码用逗号分隔,对接旧库产品编码)';
-- 2. 旧值(产品ID逗号串)按 bms_product 映射为产品代码逗号串
-- FIND_IN_SET 逐个匹配逗号串中的ID,GROUP_CONCAT 重新拼为代码串;
-- 匹配不到产品的ID会被置为NULL(脏数据,可在客户编辑页重新绑定)
UPDATE bms_customer c
SET c.product_codes = (
SELECT GROUP_CONCAT(p.product_code)
FROM bms_product p
WHERE FIND_IN_SET(p.product_id, c.product_codes)
)
WHERE c.product_codes IS NOT NULL
AND c.product_codes <> '';