SET NAMES utf8mb4;
SET collation_connection = utf8mb4_general_ci;
SET @project_id := 90624001;
SET @staff_id_card := '330100199001010011';
SET @family_id_card := '330100199201010022';
SET @intermediary_id_card := '330100198801010033';
SET @customer_id_card := '330100198901010044';

DELETE FROM ccdi_bank_statement_tag_result WHERE project_id = @project_id;
DELETE FROM ccdi_bank_statement WHERE project_id = @project_id;
DELETE FROM ccdi_project_overview_employee_result WHERE project_id = @project_id;
DELETE FROM ccdi_staff_fmy_relation WHERE person_id = @staff_id_card OR relation_cert_no = @family_id_card;
DELETE FROM ccdi_base_staff WHERE id_card = @staff_id_card;
DELETE FROM ccdi_biz_intermediary WHERE person_id = @intermediary_id_card;
DELETE FROM ccdi_credit_customer_base WHERE person_id = @customer_id_card;
DELETE FROM ccdi_project WHERE project_id = @project_id;

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 (
    @project_id, '外部人员预警联调项目', '用于验证中介、客户等外部人员流水进入结果总览',
    'default', '0', 0, 1, 1, 0, 0, '0', 'admin', NOW(), 'admin', NOW(), '外部人员预警测试数据'
);

INSERT INTO ccdi_base_staff (
    staff_id, name, dept_id, id_card, phone, annual_income, hire_date,
    is_party_member, status, create_by, create_time, update_by, update_time
) VALUES (
    9062401, '测试员工张三', 100, @staff_id_card, '13800000001', 180000.00,
    '2020-01-01', 1, '0', 'admin', NOW(), 'admin', NOW()
);

INSERT INTO ccdi_staff_fmy_relation (
    person_id, relation_type, relation_name, gender, birth_date,
    relation_cert_type, relation_cert_no, mobile_phone1, annual_income,
    contact_address, relation_desc, status, effective_date, remark,
    data_source, is_emp_family, is_cust_family, created_by, updated_by, create_time, update_time
) VALUES (
    @staff_id_card, '配偶', '测试亲属李四', 'F', '1992-01-01',
    '身份证', @family_id_card, '13800000002', 120000.00,
    '杭州市测试地址', '测试员工配偶', 1, NOW(), '外部人员预警测试数据',
    'MANUAL', 1, 0, 'admin', 'admin', NOW(), NOW()
);

INSERT INTO ccdi_biz_intermediary (
    biz_id, person_type, person_sub_type, name, gender, id_type, person_id,
    mobile, company, data_source, remark, created_by, updated_by, create_time, update_time
) VALUES (
    'EXTWARN-MID-001', '个人', '本人', '测试中介王某', 'M', '身份证', @intermediary_id_card,
    '13800000003', '测试中介服务部', 'MANUAL', '外部人员预警测试数据', 'admin', 'admin', NOW(), NOW()
);

INSERT INTO ccdi_credit_customer_base (
    person_id, name, cinocsno, idno_type, source_type, create_by, create_time, update_by, update_time
) VALUES (
    @customer_id_card, '测试客户赵某', 'CUST-EXTWARN-001', '个人', 'MANUAL', 'admin', NOW(), 'admin', NOW()
);

INSERT INTO ccdi_bank_statement (
    bank_statement_id, 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, customer_cert_no, customer_social_credit_code,
    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
(
    9062400101, @project_id, 0, 0, '测试中介王某', '6222000000000033',
    20260601, '2026-06-01', '2026-06-01 09:30:00', 'CNY', 180000.00, 0.00,
    820000.00, '转账', -1, '测试亲属李四', '6222000000000022',
    '杭州银行', '', @family_id_card, NULL,
    '咨询服务费', '转账汇款', 'EXTWARN001', 'HZB', '0', 0, '',
    0, 90624001, 1, NOW(), 1, NULL, 0,
    0, 0, 0, 0, '网银', @intermediary_id_card
),
(
    9062400102, @project_id, 0, 0, '测试中介王某', '6222000000000033',
    20260603, '2026-06-03', '2026-06-03 22:18:00', 'CNY', 0.00, 52000.00,
    872000.00, '转账', -1, '测试员工张三', '6222000000000011',
    '杭州银行', '', @staff_id_card, NULL,
    '夜间转账', '转账汇款', 'EXTWARN002', 'HZB', '0', 0, '',
    0, 90624001, 2, NOW(), 1, NULL, 0,
    0, 0, 0, 0, '网银', @intermediary_id_card
),
(
    9062400103, @project_id, 0, 0, '测试客户赵某', '6222000000000044',
    20260604, '2026-06-04', '2026-06-04 21:40:00', 'CNY', 0.00, 8800.00,
    108800.00, '转账', -1, '测试中介王某', '6222000000000033',
    '杭州银行', '', @intermediary_id_card, NULL,
    '牌局结算', '转账汇款', 'EXTWARN003', 'HZB', '0', 0, '',
    0, 90624001, 3, NOW(), 1, NULL, 0,
    0, 0, 0, 0, '网银', @customer_id_card
);

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, create_time, update_by, update_time, remark
) VALUES
(
    @project_id, 'EXTERNAL_LARGE_TRANSACTION', '外部人员大额交易',
    'EXTERNAL_SINGLE_LARGE_AMOUNT', '外部人员单笔大额交易', 'EXTERNAL_SINGLE_AMOUNT',
    'STATEMENT', 'HIGH', 9062400101, 'EXTERNAL_CERT_NO', @intermediary_id_card,
    0, 90624001, '测试中介王某单笔转出180000元至员工亲属', '外部人员流水命中大额交易', '180000',
    'admin', NOW(), 'admin', NOW(), '外部人员预警测试数据'
),
(
    @project_id, 'EXTERNAL_SUSPICIOUS_RELATION', '外部人员可疑关系',
    'EXTERNAL_TO_STAFF_FAMILY_TRANSACTION', '外部人员与员工亲属交易', 'EXTERNAL_RELATION',
    'STATEMENT', 'HIGH', 9062400101, 'EXTERNAL_CERT_NO', @intermediary_id_card,
    0, 90624001, '测试中介王某与测试员工张三配偶发生资金往来', '外部人员与员工亲属交易', '配偶',
    'admin', NOW(), 'admin', NOW(), '外部人员预警测试数据'
),
(
    @project_id, 'EXTERNAL_ABNORMAL_TRANSACTION', '外部人员异常交易',
    'EXTERNAL_NIGHT_TRANSACTION', '外部人员夜间集中交易', 'EXTERNAL_NIGHT_TIME',
    'STATEMENT', 'MEDIUM', 9062400102, 'EXTERNAL_CERT_NO', @intermediary_id_card,
    0, 90624001, '测试中介王某夜间与员工发生资金往来', '外部人员夜间异常交易', '22:18',
    'admin', NOW(), 'admin', NOW(), '外部人员预警测试数据'
),
(
    @project_id, 'EXTERNAL_SUSPICIOUS_GAMBLING', '外部人员可疑赌博',
    'EXTERNAL_GAMBLING_MEMO', '外部人员疑似赌博摘要', 'EXTERNAL_MEMO',
    'STATEMENT', 'MEDIUM', 9062400103, 'EXTERNAL_CERT_NO', @customer_id_card,
    0, 90624001, '测试客户赵某交易摘要含牌局结算', '外部人员可疑赌博交易', '牌局结算',
    'admin', NOW(), 'admin', NOW(), '外部人员预警测试数据'
);
