-- ============================================================================
-- S0-FULL-DEMO-COVERAGE-CLOSURE-1 · STEP 2A · QUALITY DOMAIN
--
-- 目标：为 UATTEST_CHL 补齐 14 张 qms_* 质量主数据，解锁质量建模 15 个页面。
--   覆盖率预期 19/58 → 34/58。
--
-- 口径（CTO 2026-08-28 拍板）：
--   PURE COPY        37 行（9 张配置表，无外部业务键）
--   COPY + FK CLOSED  7 行（qms_jygf，按 UAT A 现有物料闭合）
--   CONSTRUCT        15 行（4 张物料/供应商键控表，797 侧与 UAT A 零 FK 交集）
--   ─────────────────────────
--   INSERT 语句 14 条 · INSERT 行 59 · UPDATE 0 · DELETE 0 · DDL 0
--
-- 关键物理事实（详见 lwb/memory/modules/S0/CURRENT.md F-06）：
--   · 14 张表 id 均为 PRIMARY KEY；13 张**不是** auto_increment（仅 qms_quality_base_type 是）
--     → 本脚本对 13 张表使用**固定确定性 ID 区间**，见下方 ID BLOCK
--   · 14 张表**无任何业务唯一键**，DB 层不防重 → 幂等只能靠逻辑业务键 NOT EXISTS
--   · 无 company_ref_id / factory_ref_id / Domain 列；但存在改名的组织外键
--     FCREATEORGID / FUSEORGID，797 侧值为 AIDOP 根组织，必须改写为目标租户组织
--   · 域内 FK：qms_inspectionitems.FCHECKMETHOD → qms_inspection_method.id
--     → method 必须先插；映射经业务键 FNUMBER 回绑，**不用 id 算术猜映射**
--
-- 明确不碰（另批 S0-DEFAULT-TENANT-SEED-CONTAMINATION-CLEANUP-1 处理）：
--   · 默认租户 1300000000001 的 47 行 [AI测试] 质量数据
--   · qms_quality_base_type 的 TEST_CAT_1777008124562
--   · 797 侧 qms_gcjygf 的 3 行 [AI测试]（id 9250024001-9250024003）
--   本脚本对源租户与默认租户 WRITE = 0。
--
-- ⚠️ WIP：不占正式版本号，AutoVersionUpdate 不会自动应用。
-- ============================================================================

-- ---------------------------------------------------------------------------
-- ID BLOCK（固定确定性区间，已实测 13/13 表在该区间 collision = 0，仓内亦无同区间字面量）
--   base = 3000000000000000000
--   每表 = base + 表序号*1000 + 行序号
--   3000000000000014004 < bigint max 9223372036854775807，安全
-- ---------------------------------------------------------------------------

SET @src     := (SELECT t.Id FROM SysTenant t JOIN SysOrg o ON o.Id = t.OrgId
                 WHERE o.Code = 'AIDOP' AND t.Status = 1 LIMIT 1);
SET @dst     := (SELECT t.Id FROM SysTenant t JOIN SysOrg o ON o.Id = t.OrgId
                 WHERE o.Code = 'UATTEST_CHL' AND t.Status = 1 LIMIT 1);
SET @org_dst := (SELECT t.OrgId FROM SysTenant t WHERE t.Id = @dst LIMIT 1);

-- 任一变量为 NULL 时，下方每条语句的 guard 使全脚本降为空操作。


-- ===========================================================================
-- 01 · qms_inspection_method  PURE COPY 5   ★ 必须最先（qms_inspectionitems 依赖）
--      QM-001..005 → 3000000000000001001..1005
-- ===========================================================================
INSERT INTO qms_inspection_method
    (id, tenant_id, FNUMBER, FNAME, FCTRLSTRATEGY, FSTATUS, FENABLE, FCOMMENT, FCREATETIME, FMODIFYTIME)
SELECT CASE s.FNUMBER
           WHEN 'QM-001' THEN 3000000000000001001
           WHEN 'QM-002' THEN 3000000000000001002
           WHEN 'QM-003' THEN 3000000000000001003
           WHEN 'QM-004' THEN 3000000000000001004
           WHEN 'QM-005' THEN 3000000000000001005
       END,
       @dst, s.FNUMBER, s.FNAME, s.FCTRLSTRATEGY, s.FSTATUS, s.FENABLE, s.FCOMMENT, s.FCREATETIME, s.FMODIFYTIME
FROM qms_inspection_method s
WHERE s.tenant_id = @src
  AND s.FNUMBER IN ('QM-001','QM-002','QM-003','QM-004','QM-005')
  AND @src IS NOT NULL AND @dst IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM qms_inspection_method x WHERE x.tenant_id = @dst AND x.FNUMBER = s.FNUMBER);


-- ===========================================================================
-- 02 · qms_inspectionitems  PURE COPY 5
--      QI-001..005 → 3000000000000002001..2005
--      FCHECKMETHOD 经 FNUMBER 回绑目标 method（禁止直接复制 source id、禁止 id offset）
--      预期映射：QI-001→QM-003 · QI-002→QM-001 · QI-003→QM-003 · QI-004→QM-005 · QI-005→QM-001
--      FCHECKBASIS：797 侧 5/5 为 NULL，原样带过，无需映射
-- ===========================================================================
INSERT INTO qms_inspectionitems
    (id, tenant_id, FNUMBER, FNAME, FCHECKMETHOD, FCHECKBASIS, FCHECKINSTRUCT,
     FRADIOGROUPFIELD, FRADIOGROUPFIELD1, zblx, FSTATUS, FENABLE, FCOMMENT, FCREATETIME, FMODIFYTIME)
SELECT CASE s.FNUMBER
           WHEN 'QI-001' THEN 3000000000000002001
           WHEN 'QI-002' THEN 3000000000000002002
           WHEN 'QI-003' THEN 3000000000000002003
           WHEN 'QI-004' THEN 3000000000000002004
           WHEN 'QI-005' THEN 3000000000000002005
       END,
       @dst, s.FNUMBER, s.FNAME,
       (SELECT t.id FROM qms_inspection_method t
         WHERE t.tenant_id = @dst AND t.FNUMBER = m.FNUMBER LIMIT 1),
       s.FCHECKBASIS, s.FCHECKINSTRUCT,
       s.FRADIOGROUPFIELD, s.FRADIOGROUPFIELD1, s.zblx,
       s.FSTATUS, s.FENABLE, s.FCOMMENT, s.FCREATETIME, s.FMODIFYTIME
FROM qms_inspectionitems s
LEFT JOIN qms_inspection_method m ON m.id = s.FCHECKMETHOD AND m.tenant_id = @src
WHERE s.tenant_id = @src
  AND s.FNUMBER IN ('QI-001','QI-002','QI-003','QI-004','QI-005')
  AND @src IS NOT NULL AND @dst IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM qms_inspectionitems x WHERE x.tenant_id = @dst AND x.FNUMBER = s.FNUMBER);


-- ===========================================================================
-- 03 · qms_inspectioninstru  PURE COPY 5    QG-001..005 → ...003001..3005
-- ===========================================================================
INSERT INTO qms_inspectioninstru
    (id, tenant_id, FNUMBER, FNAME, FMODEL, FSPECIFICATION, FMANUFACTURER,
     FSTATUS, FENABLE, FCOMMENT, FCREATETIME, FMODIFYTIME,
     gauge_category, calibration_cycle_days, next_calibration_date)
SELECT CASE s.FNUMBER
           WHEN 'QG-001' THEN 3000000000000003001
           WHEN 'QG-002' THEN 3000000000000003002
           WHEN 'QG-003' THEN 3000000000000003003
           WHEN 'QG-004' THEN 3000000000000003004
           WHEN 'QG-005' THEN 3000000000000003005
       END,
       @dst, s.FNUMBER, s.FNAME, s.FMODEL, s.FSPECIFICATION, s.FMANUFACTURER,
       s.FSTATUS, s.FENABLE, s.FCOMMENT, s.FCREATETIME, s.FMODIFYTIME,
       s.gauge_category, s.calibration_cycle_days, s.next_calibration_date
FROM qms_inspectioninstru s
WHERE s.tenant_id = @src
  AND s.FNUMBER IN ('QG-001','QG-002','QG-003','QG-004','QG-005')
  AND @src IS NOT NULL AND @dst IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM qms_inspectioninstru x WHERE x.tenant_id = @dst AND x.FNUMBER = s.FNUMBER);


-- ===========================================================================
-- 04 · qms_inspectionfreq  PURE COPY 4      JYPC-001..004 → ...004001..4004
-- ===========================================================================
INSERT INTO qms_inspectionfreq
    (id, tenant_id, FNUMBER, FNAME, FREMARK, FSTATUS, FENABLE, FCREATETIME, FMODIFYTIME)
SELECT CASE s.FNUMBER
           WHEN 'JYPC-001' THEN 3000000000000004001
           WHEN 'JYPC-002' THEN 3000000000000004002
           WHEN 'JYPC-003' THEN 3000000000000004003
           WHEN 'JYPC-004' THEN 3000000000000004004
       END,
       @dst, s.FNUMBER, s.FNAME, s.FREMARK, s.FSTATUS, s.FENABLE, s.FCREATETIME, s.FMODIFYTIME
FROM qms_inspectionfreq s
WHERE s.tenant_id = @src
  AND s.FNUMBER IN ('JYPC-001','JYPC-002','JYPC-003','JYPC-004')
  AND @src IS NOT NULL AND @dst IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM qms_inspectionfreq x WHERE x.tenant_id = @dst AND x.FNUMBER = s.FNUMBER);


-- ===========================================================================
-- 05 · qms_sampscheme  PURE COPY 4          QS-001..004 → ...005001..5004
--      FINSPECTORGID / FINSPECTUSERID：797 侧全 NULL，原样带过
-- ===========================================================================
INSERT INTO qms_sampscheme
    (id, tenant_id, FNUMBER, FNAME, FSAMPLINGTYPE, FINSPECTIONLEVEL, FSTRICTNESS, FAQLVALUE,
     FINSPECTIONTYPE, FINSPECTORGID, FINSPECTUSERID, FSTATUS, FENABLE, FCOMMENT,
     FCREATETIME, FMODIFYTIME, FFIXEDRATE)
SELECT CASE s.FNUMBER
           WHEN 'QS-001' THEN 3000000000000005001
           WHEN 'QS-002' THEN 3000000000000005002
           WHEN 'QS-003' THEN 3000000000000005003
           WHEN 'QS-004' THEN 3000000000000005004
       END,
       @dst, s.FNUMBER, s.FNAME, s.FSAMPLINGTYPE, s.FINSPECTIONLEVEL, s.FSTRICTNESS, s.FAQLVALUE,
       s.FINSPECTIONTYPE, s.FINSPECTORGID, s.FINSPECTUSERID, s.FSTATUS, s.FENABLE, s.FCOMMENT,
       s.FCREATETIME, s.FMODIFYTIME, s.FFIXEDRATE
FROM qms_sampscheme s
WHERE s.tenant_id = @src
  AND s.FNUMBER IN ('QS-001','QS-002','QS-003','QS-004')
  AND @src IS NOT NULL AND @dst IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM qms_sampscheme x WHERE x.tenant_id = @dst AND x.FNUMBER = s.FNUMBER);


-- ===========================================================================
-- 06 · qms_quality_base_type  PURE COPY 4   ★ 唯一 auto_increment 表，不给 id
--      逻辑键 (tenant_id, type_category, type_code)
-- ===========================================================================
INSERT INTO qms_quality_base_type
    (tenant_id, type_category, type_code, short_name, full_name, is_active, remark, create_time, modify_time)
SELECT @dst, s.type_category, s.type_code, s.short_name, s.full_name, s.is_active, s.remark, s.create_time, s.modify_time
FROM qms_quality_base_type s
WHERE s.tenant_id = @src
  AND @src IS NOT NULL AND @dst IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM qms_quality_base_type x
                  WHERE x.tenant_id = @dst AND x.type_category = s.type_category AND x.type_code = s.type_code);


-- ===========================================================================
-- 07 · qms_inspectioncrit  PURE COPY 3      JYYJ-001..003 → ...007001..7003
--      ★ FCREATEORGID：797 根组织 → 目标租户组织
-- ===========================================================================
INSERT INTO qms_inspectioncrit
    (id, tenant_id, FNUMBER, FNAME, FCTRLSTRATEGY, FCREATEORGID, FUSEORG,
     FCOMMENT, FSTATUS, FENABLE, FCREATETIME, FMODIFYTIME)
SELECT CASE s.FNUMBER
           WHEN 'JYYJ-001' THEN 3000000000000007001
           WHEN 'JYYJ-002' THEN 3000000000000007002
           WHEN 'JYYJ-003' THEN 3000000000000007003
       END,
       @dst, s.FNUMBER, s.FNAME, s.FCTRLSTRATEGY,
       CASE WHEN s.FCREATEORGID IS NULL THEN NULL ELSE @org_dst END,
       s.FUSEORG, s.FCOMMENT, s.FSTATUS, s.FENABLE, s.FCREATETIME, s.FMODIFYTIME
FROM qms_inspectioncrit s
WHERE s.tenant_id = @src
  AND s.FNUMBER IN ('JYYJ-001','JYYJ-002','JYYJ-003')
  AND @src IS NOT NULL AND @dst IS NOT NULL AND @org_dst IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM qms_inspectioncrit x WHERE x.tenant_id = @dst AND x.FNUMBER = s.FNUMBER);


-- ===========================================================================
-- 08 · qms_inspectionstd  PURE COPY 3       JYBZ-001..003 → ...008001..8003
--      ★ FCREATEORGID 改写
-- ===========================================================================
INSERT INTO qms_inspectionstd
    (id, tenant_id, FNUMBER, FNAME, FCOMMENT, FCTRLSTRATEGY, FCREATEORGID, FUSEORG, FSTATUS, FENABLE)
SELECT CASE s.FNUMBER
           WHEN 'JYBZ-001' THEN 3000000000000008001
           WHEN 'JYBZ-002' THEN 3000000000000008002
           WHEN 'JYBZ-003' THEN 3000000000000008003
       END,
       @dst, s.FNUMBER, s.FNAME, s.FCOMMENT, s.FCTRLSTRATEGY,
       CASE WHEN s.FCREATEORGID IS NULL THEN NULL ELSE @org_dst END,
       s.FUSEORG, s.FSTATUS, s.FENABLE
FROM qms_inspectionstd s
WHERE s.tenant_id = @src
  AND s.FNUMBER IN ('JYBZ-001','JYBZ-002','JYBZ-003')
  AND @src IS NOT NULL AND @dst IS NOT NULL AND @org_dst IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM qms_inspectionstd x WHERE x.tenant_id = @dst AND x.FNUMBER = s.FNUMBER);


-- ===========================================================================
-- 09 · qms_inspectpro  PURE COPY 4          PLAN-* → ...009001..9004
--      ★ FCREATEORGID + FUSEORGID 双改写
--      FBIZSTYPEID 是字符串码（IQC/PQC/FQC/OQC），不是 id，原样带过
-- ===========================================================================
INSERT INTO qms_inspectpro
    (id, tenant_id, FNUMBER, FNAME, FBIZSTYPEID, FCOMMENT, FCTRLSTRATEGY,
     FCREATEORGID, FUSEORGID, FSTATUS, FENABLE, FCREATETIME, FMODIFYTIME)
SELECT CASE s.FNUMBER
           WHEN 'PLAN-FQC-001' THEN 3000000000000009001
           WHEN 'PLAN-IQC-001' THEN 3000000000000009002
           WHEN 'PLAN-OQC-001' THEN 3000000000000009003
           WHEN 'PLAN-PQC-001' THEN 3000000000000009004
       END,
       @dst, s.FNUMBER, s.FNAME, s.FBIZSTYPEID, s.FCOMMENT, s.FCTRLSTRATEGY,
       CASE WHEN s.FCREATEORGID IS NULL THEN NULL ELSE @org_dst END,
       CASE WHEN s.FUSEORGID   IS NULL THEN NULL ELSE @org_dst END,
       s.FSTATUS, s.FENABLE, s.FCREATETIME, s.FMODIFYTIME
FROM qms_inspectpro s
WHERE s.tenant_id = @src
  AND s.FNUMBER IN ('PLAN-FQC-001','PLAN-IQC-001','PLAN-OQC-001','PLAN-PQC-001')
  AND @src IS NOT NULL AND @dst IS NOT NULL AND @org_dst IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM qms_inspectpro x WHERE x.tenant_id = @dst AND x.FNUMBER = s.FNUMBER);


-- ===========================================================================
-- 10 · qms_jygf  COPY + FK CLOSED 7         → ...010001..10007
--      仅取 wlbm ∈ UAT A 现有 56 物料的行（797 共 4704 行，禁止整表迁移）
--      ★ 逻辑键必须含版本 bb：Y101-1-11 存在 A.1 与 X.1 两版，两者都要保留
-- ===========================================================================
INSERT INTO qms_jygf
    (id, tenant_id, wjbh, bb, th, yclmc, wlbm, sxrq, tzbb, czclph, xm, fj, filename, title, isEnable)
SELECT CASE CONCAT(s.wjbh, '|', s.bb)
           WHEN 'F03-1-21|A.0'  THEN 3000000000000010001
           WHEN 'F101-1-39|A.0' THEN 3000000000000010002
           WHEN 'M05-1-19|A.4'  THEN 3000000000000010003
           WHEN 'U01-1-63|A.1'  THEN 3000000000000010004
           WHEN 'Y101-1-11|A.1' THEN 3000000000000010005
           WHEN 'Y101-1-11|X.1' THEN 3000000000000010006
           WHEN 'Y101-1-36|X.1' THEN 3000000000000010007
       END,
       @dst, s.wjbh, s.bb, s.th, s.yclmc, s.wlbm, s.sxrq, s.tzbb, s.czclph, s.xm,
       s.fj, s.filename, s.title, s.isEnable
FROM qms_jygf s
WHERE s.tenant_id = @src
  AND @src IS NOT NULL AND @dst IS NOT NULL
  AND EXISTS (SELECT 1 FROM ItemMaster i WHERE i.tenant_id = @dst AND i.ItemNum = s.wlbm)
  AND NOT EXISTS (SELECT 1 FROM qms_jygf x
                  WHERE x.tenant_id = @dst AND x.wjbh = s.wjbh AND x.bb <=> s.bb);


-- ===========================================================================
-- 11 · qms_gcjygf  CONSTRUCT 5              UATD-GC-001..005 → ...011001..11005
--      797 侧 263 行与 UAT A 物料零交集（且含 3 行 [AI测试]）→ 不复制，按 UAT A 自有制造件构造
--      provenance：业务键前缀 UATD-（展示字段不带前缀）
-- ===========================================================================
INSERT INTO qms_gcjygf (id, tenant_id, syxh, wjbh, bb, sxrj, fj, wlbm, fj2, version)
SELECT c.new_id, @dst, c.syxh, c.wjbh, 'A.0', CURDATE(), NULL, c.wlbm, NULL, 1
FROM (
          SELECT 3000000000000011001 AS new_id, 'UATD-GC-001' AS wjbh, '91HC0497' AS wlbm, '集控备机'        AS syxh
    UNION ALL SELECT 3000000000000011002, 'UATD-GC-002', '3124C0015', 'IFT45PULB'
    UNION ALL SELECT 3000000000000011003, 'UATD-GC-003', '3221C0031', '压（FBE6035B）'
    UNION ALL SELECT 3000000000000011004, 'UATD-GC-004', '3121C0035', '上底（45PUL）'
    UNION ALL SELECT 3000000000000011005, 'UATD-GC-005', '322AD001',  '上底（6035B）'
) c
WHERE @dst IS NOT NULL
  AND EXISTS (SELECT 1 FROM ItemMaster i WHERE i.tenant_id = @dst AND i.ItemNum = c.wlbm)
  AND NOT EXISTS (SELECT 1 FROM qms_gcjygf x WHERE x.tenant_id = @dst AND x.wjbh = c.wjbh);


-- ===========================================================================
-- 12 · qms_fqcjygf  CONSTRUCT 3             UATD-FQC-001..003 → ...012001..12003
--      797 侧 3 行物料 1AB6753/91HC0857/1AB6755 均不在 UAT A → 不复制
-- ===========================================================================
INSERT INTO qms_fqcjygf (id, tenant_id, syxh, wjbh, bb, sxrj, fj, wlbm, fj2, version)
SELECT c.new_id, @dst, c.syxh, c.wjbh, 'A.0', CURDATE(), NULL, c.wlbm, NULL, 1
FROM (
          SELECT 3000000000000012001 AS new_id, 'UATD-FQC-001' AS wjbh, '91HC0497' AS wlbm, '集控备机'      AS syxh
    UNION ALL SELECT 3000000000000012002, 'UATD-FQC-002', '3124C0015', 'IFT45PULB'
    UNION ALL SELECT 3000000000000012003, 'UATD-FQC-003', '3221C0031', '压（FBE6035B）'
) c
WHERE @dst IS NOT NULL
  AND EXISTS (SELECT 1 FROM ItemMaster i WHERE i.tenant_id = @dst AND i.ItemNum = c.wlbm)
  AND NOT EXISTS (SELECT 1 FROM qms_fqcjygf x WHERE x.tenant_id = @dst AND x.wjbh = c.wjbh);


-- ===========================================================================
-- 13 · qms_oqcjygf  CONSTRUCT 3             UATD-OQC-001..003 → ...013001..13003
-- ===========================================================================
INSERT INTO qms_oqcjygf (id, tenant_id, syxh, wjbh, bb, sxrj, fj, wlbm, fj2, version)
SELECT c.new_id, @dst, c.syxh, c.wjbh, 'A.0', CURDATE(), NULL, c.wlbm, NULL, 1
FROM (
          SELECT 3000000000000013001 AS new_id, 'UATD-OQC-001' AS wjbh, '91HC0497' AS wlbm, '集控备机'      AS syxh
    UNION ALL SELECT 3000000000000013002, 'UATD-OQC-002', '3124C0015', 'IFT45PULB'
    UNION ALL SELECT 3000000000000013003, 'UATD-OQC-003', '3221C0031', '压（FBE6035B）'
) c
WHERE @dst IS NOT NULL
  AND EXISTS (SELECT 1 FROM ItemMaster i WHERE i.tenant_id = @dst AND i.ItemNum = c.wlbm)
  AND NOT EXISTS (SELECT 1 FROM qms_oqcjygf x WHERE x.tenant_id = @dst AND x.wjbh = c.wjbh);


-- ===========================================================================
-- 14 · qms_lymjbmd  CONSTRUCT 4             → ...014001..14004
--      797 侧 4 行的供应商 10000000/10000001/10000002 与物料 91CC0136/1A03G87
--      均不在 UAT A → 不复制；改用 UAT A 自有真实供应商与物料组合白名单。
--      本表无任何 provenance 字段，且 gysbm/wlbm 必须是真实编码 → 不写 UATD 标记，
--      provenance 由本注释、S0 Memory 与执行回执承载（CTO 2026-08-28 批准）。
-- ===========================================================================
INSERT INTO qms_lymjbmd (id, tenant_id, gysbm, gysmc, wlbm, wlmc, dim_type)
SELECT c.new_id, @dst, c.gysbm, c.gysmc, c.wlbm, c.wlmc, c.dim_type
FROM (
          SELECT 3000000000000014001 AS new_id, '10003232' AS gysbm, '珩睿'   AS gysmc, NULL       AS wlbm, NULL                AS wlmc, 'supplier'          AS dim_type
    UNION ALL SELECT 3000000000000014002, '10000015', '怡祥',   NULL,       NULL,                 'supplier'
    UNION ALL SELECT 3000000000000014003, NULL,       NULL,     '91C0D2C',  '管组件-新EE2305H',   'material'
    UNION ALL SELECT 3000000000000014004, '10001597', '奥博特', '91HC0497', '集控备机',           'material_supplier'
) c
WHERE @dst IS NOT NULL
  AND (c.gysbm IS NULL OR EXISTS (SELECT 1 FROM SuppMaster s WHERE s.tenant_id = @dst AND s.Supp = c.gysbm))
  AND (c.wlbm  IS NULL OR EXISTS (SELECT 1 FROM ItemMaster i WHERE i.tenant_id = @dst AND i.ItemNum = c.wlbm))
  AND NOT EXISTS (SELECT 1 FROM qms_lymjbmd x
                  WHERE x.tenant_id = @dst AND x.dim_type = c.dim_type
                    AND IFNULL(x.gysbm,'') = IFNULL(c.gysbm,'')
                    AND IFNULL(x.wlbm,'')  = IFNULL(c.wlbm,''));
