START TRANSACTION;

-- 1. 清理本次专项核查专用样本
DELETE FROM ccdi_bank_statement_tag_result
WHERE project_id = 51
  AND object_type = 'STAFF_ID_CARD'
  AND object_key IN (
    '330101199003010101',
    '330101199003010102',
    '330101199003010103',
    '330101199003010104',
    '330101199003010105',
    '330101199003010106'
  );

DELETE FROM ccdi_debts_info
WHERE person_id IN (
  '330101199003010101',
  '330101199003010102',
  '330101199003010103',
  '330101199003010104',
  '330101199003010105',
  '330101199003010106',
  '330101199104010101',
  '330101199104010102',
  '330101199104010103',
  '330101199104010104',
  '330101199104010105'
);

DELETE FROM ccdi_asset_info
WHERE family_id IN (
    '330101199003010101',
    '330101199003010102',
    '330101199003010103',
    '330101199003010104',
    '330101199003010105',
    '330101199003010106'
  )
   OR person_id IN (
    '330101199003010101',
    '330101199003010102',
    '330101199003010103',
    '330101199003010104',
    '330101199003010105',
    '330101199003010106',
    '330101199104010101',
    '330101199104010102',
    '330101199104010103',
    '330101199104010104',
    '330101199104010105'
  );

DELETE FROM ccdi_staff_fmy_relation
WHERE person_id IN (
    '330101199003010101',
    '330101199003010102',
    '330101199003010103',
    '330101199003010104',
    '330101199003010105'
  )
  AND relation_cert_no IN (
    '330101199104010101',
    '330101199104010102',
    '330101199104010103',
    '330101199104010104',
    '330101199104010105'
  );

DELETE FROM ccdi_base_staff
WHERE staff_id IN (1900001, 1900002, 1900003, 1900004, 1900005, 1900006)
   OR id_card IN (
    '330101199003010101',
    '330101199003010102',
    '330101199003010103',
    '330101199003010104',
    '330101199003010105',
    '330101199003010106'
  );

-- 2. 新增专项核查员工
INSERT INTO ccdi_base_staff (
  staff_id,
  name,
  dept_id,
  id_card,
  phone,
  annual_income,
  hire_date,
  status,
  create_by,
  create_time,
  update_by,
  update_time
) VALUES
  (1900001, '专项核查正常边界样本', 100, '330101199003010101', '13900000001', 200000.00, '2020-01-10', '0', 'admin', NOW(), 'admin', NOW()),
  (1900002, '专项核查风险边界样本', 100, '330101199003010102', '13900000002', 180000.00, '2020-01-10', '0', 'admin', NOW(), 'admin', NOW()),
  (1900003, '专项核查高风险样本', 100, '330101199003010103', '13900000003', 150000.00, '2020-01-10', '0', 'admin', NOW(), 'admin', NOW()),
  (1900004, '专项核查缺少负债样本', 100, '330101199003010104', '13900000004', 160000.00, '2020-01-10', '0', 'admin', NOW(), 'admin', NOW()),
  (1900005, '专项核查缺少资产样本', 100, '330101199003010105', '13900000005', 220000.00, '2020-01-10', '0', 'admin', NOW(), 'admin', NOW()),
  (1900006, '专项核查单身完整样本', 100, '330101199003010106', '13900000006', 180000.00, '2020-01-10', '0', 'admin', NOW(), 'admin', NOW());

-- 3. 新增配偶关系
INSERT INTO ccdi_staff_fmy_relation (
  person_id,
  relation_type,
  relation_name,
  gender,
  birth_date,
  relation_cert_type,
  relation_cert_no,
  mobile_phone1,
  contact_address,
  relation_desc,
  status,
  effective_date,
  remark,
  data_source,
  is_emp_family,
  is_cust_family,
  created_by,
  updated_by,
  create_time,
  update_time,
  annual_income
) VALUES
  ('330101199003010101', '配偶', '边界配偶甲', 'F', '1991-04-01', '身份证', '330101199104010101', '13800000001', '专项核查测试地址1', '专项核查正常边界配偶', 1, NOW(), '专项核查测试数据', 'MANUAL', 1, 0, 'admin', 'admin', NOW(), NOW(), 100000.00),
  ('330101199003010102', '配偶', '边界配偶乙', 'F', '1991-04-01', '身份证', '330101199104010102', '13800000002', '专项核查测试地址2', '专项核查风险边界配偶', 1, NOW(), '专项核查测试数据', 'MANUAL', 1, 0, 'admin', 'admin', NOW(), NOW(), 120000.00),
  ('330101199003010103', '配偶', '高风险配偶', 'F', '1991-04-01', '身份证', '330101199104010103', '13800000003', '专项核查测试地址3', '专项核查高风险配偶', 1, NOW(), '专项核查测试数据', 'MANUAL', 1, 0, 'admin', 'admin', NOW(), NOW(), 90000.00),
  ('330101199003010104', '配偶', '负债缺失配偶', 'F', '1991-04-01', '身份证', '330101199104010104', '13800000004', '专项核查测试地址4', '专项核查缺少本人负债配偶', 1, NOW(), '专项核查测试数据', 'MANUAL', 1, 0, 'admin', 'admin', NOW(), NOW(), 140000.00),
  ('330101199003010105', '配偶', '资产缺失配偶', 'F', '1991-04-01', '身份证', '330101199104010105', '13800000005', '专项核查测试地址5', '专项核查缺少本人资产配偶', 1, NOW(), '专项核查测试数据', 'MANUAL', 1, 0, 'admin', 'admin', NOW(), NOW(), 130000.00);

-- 4. 新增资产明细
INSERT INTO ccdi_asset_info (
  family_id,
  person_id,
  asset_main_type,
  asset_sub_type,
  asset_name,
  ownership_ratio,
  purchase_eval_date,
  original_value,
  current_value,
  valuation_date,
  asset_status,
  remarks,
  create_by,
  update_by
) VALUES
  ('330101199003010101', '330101199003010101', '房产', '住宅', '专项核查正常边界样本-本人住宅', 100.00, '2024-01-01', 400000.00, 400000.00, '2026-03-20', '正常', '专项核查测试数据-正常边界', 'admin', 'admin'),
  ('330101199003010101', '330101199003010101', '金融资产', '理财', '专项核查正常边界样本-本人理财', 100.00, '2024-06-01', 200000.00, 200000.00, '2026-03-18', '正常', '专项核查测试数据-正常边界', 'admin', 'admin'),
  ('330101199003010101', '330101199104010101', '车辆', '家用汽车', '专项核查正常边界样本-配偶车辆', 100.00, '2024-02-01', 250000.00, 250000.00, '2026-03-17', '正常', '专项核查测试数据-正常边界', 'admin', 'admin'),
  ('330101199003010101', '330101199104010101', '金融资产', '基金', '专项核查正常边界样本-配偶基金', 100.00, '2024-07-01', 150000.00, 150000.00, '2026-03-16', '正常', '专项核查测试数据-正常边界', 'admin', 'admin'),

  ('330101199003010102', '330101199003010102', '房产', '公寓', '专项核查风险边界样本-本人公寓', 100.00, '2024-01-01', 200000.00, 200000.00, '2026-03-20', '正常', '专项核查测试数据-风险边界', 'admin', 'admin'),
  ('330101199003010102', '330101199104010102', '车辆', '新能源车', '专项核查风险边界样本-配偶车辆', 100.00, '2024-04-01', 300000.00, 300000.00, '2026-03-19', '正常', '专项核查测试数据-风险边界', 'admin', 'admin'),

  ('330101199003010103', '330101199003010103', '房产', '住宅', '专项核查高风险样本-本人住宅', 100.00, '2024-01-01', 200000.00, 200000.00, '2026-03-20', '正常', '专项核查测试数据-高风险', 'admin', 'admin'),
  ('330101199003010103', '330101199104010103', '金融资产', '股票', '专项核查高风险样本-配偶股票', 100.00, '2024-05-01', 300000.00, 300000.00, '2026-03-18', '正常', '专项核查测试数据-高风险', 'admin', 'admin'),

  ('330101199003010104', '330101199003010104', '房产', '住宅', '专项核查缺少负债样本-本人住宅', 100.00, '2024-01-01', 450000.00, 450000.00, '2026-03-20', '正常', '专项核查测试数据-缺少本人负债', 'admin', 'admin'),
  ('330101199003010104', '330101199104010104', '金融资产', '理财', '专项核查缺少负债样本-配偶理财', 100.00, '2024-06-01', 350000.00, 350000.00, '2026-03-18', '正常', '专项核查测试数据-缺少本人负债', 'admin', 'admin'),

  ('330101199003010105', '330101199104010105', '房产', '住宅', '专项核查缺少资产样本-配偶住宅', 100.00, '2024-01-01', 600000.00, 600000.00, '2026-03-20', '正常', '专项核查测试数据-缺少本人资产', 'admin', 'admin'),

  ('330101199003010106', '330101199003010106', '房产', '住宅', '专项核查单身完整样本-本人住宅', 100.00, '2024-01-01', 250000.00, 250000.00, '2026-03-20', '正常', '专项核查测试数据-单身完整', 'admin', 'admin'),
  ('330101199003010106', '330101199003010106', '金融资产', '存款', '专项核查单身完整样本-本人存款', 100.00, '2024-05-01', 150000.00, 150000.00, '2026-03-18', '正常', '专项核查测试数据-单身完整', 'admin', 'admin');

-- 5. 新增负债明细
INSERT INTO ccdi_debts_info (
  person_id,
  person_name,
  query_date,
  debt_main_type,
  debt_sub_type,
  creditor_type,
  debt_name,
  principal_balance,
  debt_total_amount,
  debt_status,
  create_by,
  update_by
) VALUES
  ('330101199003010101', '专项核查正常边界样本', '2026-03-24', '贷款', '房贷', '银行', '专项核查正常边界样本-本人房贷', 700000.00, 730000.00, '正常', 'admin', 'admin'),
  ('330101199104010101', '边界配偶甲', '2026-03-24', '贷款', '消费贷', '银行', '专项核查正常边界样本-配偶消费贷', 500000.00, 520000.00, '正常', 'admin', 'admin'),

  ('330101199003010102', '专项核查风险边界样本', '2026-03-24', '贷款', '经营贷', '银行', '专项核查风险边界样本-本人经营贷', 600000.00, 620000.00, '正常', 'admin', 'admin'),
  ('330101199003010102', '专项核查风险边界样本', '2026-03-23', '信用卡', '分期', '银行', '专项核查风险边界样本-本人信用卡分期', 100000.00, 102000.00, '正常', 'admin', 'admin'),
  ('330101199104010102', '边界配偶乙', '2026-03-24', '贷款', '房贷', '银行', '专项核查风险边界样本-配偶房贷', 500000.00, 530000.00, '正常', 'admin', 'admin'),

  ('330101199003010103', '专项核查高风险样本', '2026-03-24', '贷款', '房贷', '银行', '专项核查高风险样本-本人房贷', 900000.00, 930000.00, '正常', 'admin', 'admin'),
  ('330101199104010103', '高风险配偶', '2026-03-24', '贷款', '网贷', '消费金融', '专项核查高风险样本-配偶网贷', 500100.00, 510000.00, '正常', 'admin', 'admin'),

  ('330101199104010104', '负债缺失配偶', '2026-03-24', '贷款', '消费贷', '银行', '专项核查缺少负债样本-配偶消费贷', 200000.00, 205000.00, '正常', 'admin', 'admin'),

  ('330101199003010105', '专项核查缺少资产样本', '2026-03-24', '贷款', '信用贷', '银行', '专项核查缺少资产样本-本人信用贷', 250000.00, 255000.00, '正常', 'admin', 'admin'),
  ('330101199104010105', '资产缺失配偶', '2026-03-24', '贷款', '消费贷', '银行', '专项核查缺少资产样本-配偶消费贷', 150000.00, 152000.00, '正常', 'admin', 'admin'),

  ('330101199003010106', '专项核查单身完整样本', '2026-03-24', '贷款', '信用贷', '银行', '专项核查单身完整样本-本人信用贷', 180000.00, 182000.00, '正常', 'admin', 'admin'),
  ('330101199003010106', '专项核查单身完整样本', '2026-03-23', '信用卡', '分期', '银行', '专项核查单身完整样本-本人信用卡分期', 120000.00, 121500.00, '正常', 'admin', 'admin');

-- 6. 新增项目命中对象，使样本进入专项核查范围
INSERT INTO ccdi_bank_statement_tag_result (
  project_id,
  model_code,
  model_name,
  rule_code,
  rule_name,
  indicator_code,
  result_type,
  risk_level,
  bank_statement_id,
  object_type,
  object_key,
  group_id,
  log_id,
  reason_detail,
  business_caliber_snapshot,
  hit_value_snapshot,
  create_by,
  update_by,
  remark
) VALUES
  (51, 'ABNORMAL_TRANSACTION', '异常交易', 'LOW_INCOME_RELATIVE_LARGE_TRANSACTION', '低收入亲属大额交易', NULL, 'OBJECT', 'GENERAL', NULL, 'STAFF_ID_CARD', '330101199003010101', NULL, NULL, '专项核查测试数据-正常边界样本入围', '专项核查测试数据', '专项核查正常边界样本', 'admin', 'admin', '专项核查测试数据'),
  (51, 'ABNORMAL_TRANSACTION', '异常交易', 'LOW_INCOME_RELATIVE_LARGE_TRANSACTION', '低收入亲属大额交易', NULL, 'OBJECT', 'GENERAL', NULL, 'STAFF_ID_CARD', '330101199003010102', NULL, NULL, '专项核查测试数据-风险边界样本入围', '专项核查测试数据', '专项核查风险边界样本', 'admin', 'admin', '专项核查测试数据'),
  (51, 'ABNORMAL_TRANSACTION', '异常交易', 'LOW_INCOME_RELATIVE_LARGE_TRANSACTION', '低收入亲属大额交易', NULL, 'OBJECT', 'GENERAL', NULL, 'STAFF_ID_CARD', '330101199003010103', NULL, NULL, '专项核查测试数据-高风险样本入围', '专项核查测试数据', '专项核查高风险样本', 'admin', 'admin', '专项核查测试数据'),
  (51, 'ABNORMAL_TRANSACTION', '异常交易', 'LOW_INCOME_RELATIVE_LARGE_TRANSACTION', '低收入亲属大额交易', NULL, 'OBJECT', 'GENERAL', NULL, 'STAFF_ID_CARD', '330101199003010104', NULL, NULL, '专项核查测试数据-缺少负债样本入围', '专项核查测试数据', '专项核查缺少负债样本', 'admin', 'admin', '专项核查测试数据'),
  (51, 'ABNORMAL_TRANSACTION', '异常交易', 'LOW_INCOME_RELATIVE_LARGE_TRANSACTION', '低收入亲属大额交易', NULL, 'OBJECT', 'GENERAL', NULL, 'STAFF_ID_CARD', '330101199003010105', NULL, NULL, '专项核查测试数据-缺少资产样本入围', '专项核查测试数据', '专项核查缺少资产样本', 'admin', 'admin', '专项核查测试数据'),
  (51, 'ABNORMAL_TRANSACTION', '异常交易', 'LOW_INCOME_RELATIVE_LARGE_TRANSACTION', '低收入亲属大额交易', NULL, 'OBJECT', 'GENERAL', NULL, 'STAFF_ID_CARD', '330101199003010106', NULL, NULL, '专项核查测试数据-单身完整样本入围', '专项核查测试数据', '专项核查单身完整样本', 'admin', 'admin', '专项核查测试数据');

COMMIT;
