START TRANSACTION;

-- 清理本次异常账户规则验证样本
DELETE FROM ccdi_bank_statement_tag_result
WHERE project_id = 90331
  AND model_code = 'ABNORMAL_ACCOUNT';

DELETE FROM ccdi_bank_statement
WHERE project_id = 90331;

DELETE FROM ccdi_account_info
WHERE account_no IN (
    '6222000000000001',
    '6222000000000002',
    '6222000000000003',
    '6222000000000004'
);

DELETE FROM ccdi_base_staff
WHERE staff_id IN (9033101, 9033102, 9033103, 9033104);

DELETE FROM ccdi_project
WHERE project_id = 90331;

INSERT INTO ccdi_project (
    project_id, project_name, description, config_type, status, is_archived,
    target_count, high_risk_count, medium_risk_count, low_risk_count,
    del_flag, create_by, create_time, update_by, update_time, remark
) VALUES (
    90331, '异常账户规则测试项目', '用于验证异常账户模型两条规则的最小样本项目',
    'default', '0', 0,
    4, 0, 0, 0,
    '0', 'system', NOW(), 'system', NOW(), 'abnormal-account-rule-test'
);

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
    (9033101, '测试员工A', 90331, '330101199001010001', '13800000001', 180000.00, '2020-01-01', '0', 'system', NOW(), 'system', NOW()),
    (9033102, '测试员工B', 90331, '330101199001010002', '13800000002', 180000.00, '2020-01-01', '0', 'system', NOW(), 'system', NOW()),
    (9033103, '测试员工C', 90331, '330101199001010003', '13800000003', 180000.00, '2020-01-01', '0', 'system', NOW(), 'system', NOW()),
    (9033104, '测试员工D', 90331, '330101199001010004', '13800000004', 180000.00, '2020-01-01', '0', 'system', NOW(), 'system', NOW());

INSERT INTO ccdi_account_info (
    account_no, account_type, account_name, owner_type, owner_id, bank, bank_code, currency,
    is_self_account, monthly_avg_trans_count, monthly_avg_trans_amount, trans_freq_type,
    dr_max_single_amount, cr_max_single_amount, dr_max_daily_amount, cr_max_daily_amount,
    trans_risk_level, status, effective_date, invalid_date,
    create_by, create_time, update_by, update_time
) VALUES
    ('6222000000000001', 'DEBIT', '测试员工A工资卡', 'EMPLOYEE', '330101199001010001', '兰溪农商银行', 'LXNCSY', 'CNY',
     1, 3.00, 120000.00, 'LOW', 80000.00, 70000.00, 90000.00, 70000.00,
     'HIGH', 2, '2024-01-01', '2026-03-20', 'system', NOW(), 'system', NOW()),
    ('6222000000000002', 'DEBIT', '测试员工B工资卡', 'EMPLOYEE', '330101199001010002', '兰溪农商银行', 'LXNCSY', 'CNY',
     1, 2.00, 275000.00, 'LOW', 250000.00, 300000.00, 250000.00, 300000.00,
     'HIGH', 1, '2025-01-01', NULL, 'system', NOW(), 'system', NOW()),
    ('6222000000000003', 'DEBIT', '测试员工C工资卡', 'EMPLOYEE', '330101199001010003', '兰溪农商银行', 'LXNCSY', 'CNY',
     1, 1.00, 150000.00, 'LOW', 120000.00, 120000.00, 120000.00, 120000.00,
     'MEDIUM', 1, '2025-05-01', NULL, 'system', NOW(), 'system', NOW()),
    ('6222000000000004', 'DEBIT', '测试员工D工资卡', 'EMPLOYEE', '330101199001010004', '兰溪农商银行', 'LXNCSY', 'CNY',
     1, 1.00, 20000.00, 'LOW', 20000.00, 20000.00, 20000.00, 20000.00,
     'LOW', 2, '2024-06-01', '2026-03-20', 'system', NOW(), 'system', NOW());

-- 员工 A：命中 SUDDEN_ACCOUNT_CLOSURE
INSERT INTO ccdi_bank_statement (
    project_id, LE_ID, ACCOUNT_ID, LE_ACCOUNT_NAME, LE_ACCOUNT_NO, ACCOUNTING_DATE_ID,
    ACCOUNTING_DATE, TRX_DATE, CURRENCY, AMOUNT_DR, AMOUNT_CR, AMOUNT_BALANCE,
    CASH_TYPE, CUSTOMER_LE_ID, CUSTOMER_ACCOUNT_NAME, CUSTOMER_ACCOUNT_NO, customer_bank,
    customer_reference, USER_MEMO, BANK_COMMENTS, BANK_TRX_NUMBER, BANK, TRX_FLAG, TRX_TYPE,
    EXCEPTION_TYPE, internal_flag, batch_id, batch_sequence, CREATE_DATE, created_by,
    meta_json, no_balance, begin_balance, end_balance, group_id, override_bs_id, payment_method, cret_no
) VALUES
    (90331, 0, 90331011, '测试员工A', '6222000000000001', 20260305, '2026-03-05', '2026-03-05', 'CNY',
     0.00, 120000.00, 230000.00, '转账', -1, '交易对手A1', NULL, '兰溪农商银行', NULL,
     '异常账户测试A-1', NULL, 'A0001', 'LANXI', '0', 0, '', 0, 1, 1, NOW(), 1, NULL, 0, 0, 0, 90331, 0, NULL, '330101199001010001'),
    (90331, 0, 90331011, '测试员工A', '6222000000000001', 20260310, '2026-03-10', '2026-03-10', 'CNY',
     50000.00, 0.00, 130000.00, '转账', -1, '交易对手A2', NULL, '兰溪农商银行', NULL,
     '异常账户测试A-2', NULL, 'A0002', 'LANXI', '0', 0, '', 0, 1, 2, NOW(), 1, NULL, 0, 0, 0, 90331, 0, NULL, '330101199001010001'),
    (90331, 0, 90331011, '测试员工A', '6222000000000001', 20260318, '2026-03-18', '2026-03-18', 'CNY',
     0.00, 60000.00, 190000.00, '转账', -1, '交易对手A3', NULL, '兰溪农商银行', NULL,
     '异常账户测试A-3', NULL, 'A0003', 'LANXI', '0', 0, '', 0, 1, 3, NOW(), 1, NULL, 0, 0, 0, 90331, 0, NULL, '330101199001010001');

-- 员工 B：命中 DORMANT_ACCOUNT_LARGE_ACTIVATION
INSERT INTO ccdi_bank_statement (
    project_id, LE_ID, ACCOUNT_ID, LE_ACCOUNT_NAME, LE_ACCOUNT_NO, ACCOUNTING_DATE_ID,
    ACCOUNTING_DATE, TRX_DATE, CURRENCY, AMOUNT_DR, AMOUNT_CR, AMOUNT_BALANCE,
    CASH_TYPE, CUSTOMER_LE_ID, CUSTOMER_ACCOUNT_NAME, CUSTOMER_ACCOUNT_NO, customer_bank,
    customer_reference, USER_MEMO, BANK_COMMENTS, BANK_TRX_NUMBER, BANK, TRX_FLAG, TRX_TYPE,
    EXCEPTION_TYPE, internal_flag, batch_id, batch_sequence, CREATE_DATE, created_by,
    meta_json, no_balance, begin_balance, end_balance, group_id, override_bs_id, payment_method, cret_no
) VALUES
    (90331, 0, 90331022, '测试员工B', '6222000000000002', 20250801, '2025-08-01', '2025-08-01', 'CNY',
     0.00, 300000.00, 300000.00, '转账', -1, '交易对手B1', NULL, '兰溪农商银行', NULL,
     '异常账户测试B-1', NULL, 'B0001', 'LANXI', '0', 0, '', 0, 1, 4, NOW(), 1, NULL, 0, 0, 0, 90331, 0, NULL, '330101199001010002'),
    (90331, 0, 90331022, '测试员工B', '6222000000000002', 20250820, '2025-08-20', '2025-08-20', 'CNY',
     250000.00, 0.00, 50000.00, '转账', -1, '交易对手B2', NULL, '兰溪农商银行', NULL,
     '异常账户测试B-2', NULL, 'B0002', 'LANXI', '0', 0, '', 0, 1, 5, NOW(), 1, NULL, 0, 0, 0, 90331, 0, NULL, '330101199001010002');

-- 员工 C：休眠不足 6 个月，不命中
INSERT INTO ccdi_bank_statement (
    project_id, LE_ID, ACCOUNT_ID, LE_ACCOUNT_NAME, LE_ACCOUNT_NO, ACCOUNTING_DATE_ID,
    ACCOUNTING_DATE, TRX_DATE, CURRENCY, AMOUNT_DR, AMOUNT_CR, AMOUNT_BALANCE,
    CASH_TYPE, CUSTOMER_LE_ID, CUSTOMER_ACCOUNT_NAME, CUSTOMER_ACCOUNT_NO, customer_bank,
    customer_reference, USER_MEMO, BANK_COMMENTS, BANK_TRX_NUMBER, BANK, TRX_FLAG, TRX_TYPE,
    EXCEPTION_TYPE, internal_flag, batch_id, batch_sequence, CREATE_DATE, created_by,
    meta_json, no_balance, begin_balance, end_balance, group_id, override_bs_id, payment_method, cret_no
) VALUES
    (90331, 0, 90331033, '测试员工C', '6222000000000003', 20250801, '2025-08-01', '2025-08-01', 'CNY',
     0.00, 120000.00, 120000.00, '转账', -1, '交易对手C1', NULL, '兰溪农商银行', NULL,
     '异常账户测试C-1', NULL, 'C0001', 'LANXI', '0', 0, '', 0, 1, 6, NOW(), 1, NULL, 0, 0, 0, 90331, 0, NULL, '330101199001010003');

-- 员工 D：销户前 30 天无流水，不命中
INSERT INTO ccdi_bank_statement (
    project_id, LE_ID, ACCOUNT_ID, LE_ACCOUNT_NAME, LE_ACCOUNT_NO, ACCOUNTING_DATE_ID,
    ACCOUNTING_DATE, TRX_DATE, CURRENCY, AMOUNT_DR, AMOUNT_CR, AMOUNT_BALANCE,
    CASH_TYPE, CUSTOMER_LE_ID, CUSTOMER_ACCOUNT_NAME, CUSTOMER_ACCOUNT_NO, customer_bank,
    customer_reference, USER_MEMO, BANK_COMMENTS, BANK_TRX_NUMBER, BANK, TRX_FLAG, TRX_TYPE,
    EXCEPTION_TYPE, internal_flag, batch_id, batch_sequence, CREATE_DATE, created_by,
    meta_json, no_balance, begin_balance, end_balance, group_id, override_bs_id, payment_method, cret_no
) VALUES
    (90331, 0, 90331044, '测试员工D', '6222000000000004', 20260115, '2026-01-15', '2026-01-15', 'CNY',
     0.00, 20000.00, 20000.00, '转账', -1, '交易对手D1', NULL, '兰溪农商银行', NULL,
     '异常账户测试D-1', NULL, 'D0001', 'LANXI', '0', 0, '', 0, 1, 7, NOW(), 1, NULL, 0, 0, 0, 90331, 0, NULL, '330101199001010004');

COMMIT;
