START TRANSACTION;

INSERT INTO ccdi_bank_tag_rule (
    model_code,
    model_name,
    rule_code,
    rule_name,
    indicator_code,
    result_type,
    risk_level,
    business_caliber,
    enabled,
    sort_order,
    create_by,
    remark
) VALUES
('LARGE_TRANSACTION', '大额交易', 'HOUSE_OR_CAR_EXPENSE', '房车消费支出交易', 'HOUSE_OR_CAR_EXPENSE', 'STATEMENT', 'HIGH', '识别房产、购车等大额消费支出流水', 1, 10, 'system', '初始化规则'),
('LARGE_TRANSACTION', '大额交易', 'TAX_EXPENSE', '税务支出交易', 'TAX_EXPENSE', 'STATEMENT', 'HIGH', '识别税务类大额支出流水', 1, 20, 'system', '初始化规则'),
('LARGE_TRANSACTION', '大额交易', 'SINGLE_LARGE_INCOME', '大额单笔收入', 'SINGLE_TRANSACTION_AMOUNT', 'STATEMENT', 'HIGH', '识别超过单笔阈值的收入流水', 1, 30, 'system', '初始化规则'),
('LARGE_TRANSACTION', '大额交易', 'CUMULATIVE_INCOME', '累计收入超限', 'CUMULATIVE_TRANSACTION_AMOUNT', 'OBJECT', 'HIGH', '识别累计收入超过阈值的对象', 1, 40, 'system', '初始化规则'),
('LARGE_TRANSACTION', '大额交易', 'ANNUAL_TURNOVER', '年流水交易额超限', 'ANNUAL_TURNOVER', 'OBJECT', 'HIGH', '识别年交易额超过阈值的对象', 1, 50, 'system', '初始化规则'),
('LARGE_TRANSACTION', '大额交易', 'LARGE_CASH_DEPOSIT', '大额存现交易', 'LARGE_CASH_DEPOSIT', 'STATEMENT', 'HIGH', '识别大额现金存入流水', 1, 60, 'system', '初始化规则'),
('LARGE_TRANSACTION', '大额交易', 'FREQUENT_CASH_DEPOSIT', '短时间多次存现', 'FREQUENT_CASH_DEPOSIT', 'OBJECT', 'HIGH', '识别短时间多次现金存入对象', 1, 70, 'system', '初始化规则'),
('LARGE_TRANSACTION', '大额交易', 'LARGE_TRANSFER', '大额转账交易', 'FREQUENT_TRANSFER', 'STATEMENT', 'HIGH', '识别大额转账流水', 1, 80, 'system', '初始化规则'),
('ABNORMAL_TRANSACTION', '异常交易', 'ABNORMAL_CUSTOMER_TRANSACTION', '与客户之间非正常资金往来', NULL, 'STATEMENT', 'HIGH', '员工及关系人与客户及关系人之间有超过1000元以上的资金往来；客户指信贷类客户包括贷款户、担保人，中介库人员，包括中介注册的主体及主体关系人。', 1, 10, 'system', '占位规则，待补充真实SQL'),
('ABNORMAL_TRANSACTION', '异常交易', 'LOW_INCOME_RELATIVE_LARGE_TRANSACTION', '低收入亲属大额交易', NULL, 'OBJECT', 'GENERAL', '关系人中没有收入或月收入低于3000元的人员，累计交易金额超过10万元。', 1, 20, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_GAMBLING', '疑似赌博', 'MULTI_PARTY_GAMBLING_TRANSFER', '疑似赌博交易', NULL, 'OBJECT', 'HIGH', '多人（2人及以上）、多次（2次以上）、相近时间（同一天）内，有转账、微信转账、支付宝转账发生，且额度在可疑区间。金额区间可在排查设置页面进行设置', 1, 10, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_GAMBLING', '疑似赌博', 'GAMBLING_SENSITIVE_KEYWORD', '疑似敏感交易', NULL, 'STATEMENT', 'HIGH', '备注或交易摘要、对手有“游戏、抖币、体彩、福彩”等字眼。', 1, 20, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_RELATION', '可疑关系', 'SPECIAL_AMOUNT_TRANSACTION', '特殊金额交易', NULL, 'STATEMENT', NULL, '除与配偶、子女外，发生特殊金额交易，如1314元、520元等具有特殊含义的金额。', 1, 10, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_PART_TIME', '可疑兼职', 'MONTHLY_FIXED_INCOME', '疑似兼职', 'MONTHLY_FIXED_INCOME', 'OBJECT', NULL, '除本行工资收入外，每月有固定收入，固定收入金额自行设置。', 1, 10, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_PART_TIME', '可疑兼职', 'FIXED_COUNTERPARTY_TRANSFER', '疑似兼职', 'FIXED_COUNTERPARTY_TRANSFER', 'OBJECT', NULL, '每季或每年从固定交易对手转入金额，金额可设区间值，如5000-10000。', 1, 20, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_PART_TIME', '可疑兼职', 'SUSPICIOUS_INCOME_KEYWORD', '疑似兼职', NULL, 'STATEMENT', 'HIGH', '转入资金摘要有“工资”、“分红”、“红利”、“利息（非银行结息）”等收入', 1, 30, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_PROPERTY', '可疑财产', 'HOUSE_REGISTRATION_MISMATCH', '购房交易与房产登记不匹配', NULL, 'STATEMENT', NULL, '员工及关系人有购房交易，但名下房产无新增登记；有新增登记购房，但无相关购房交易记录。', 1, 10, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_PROPERTY', '可疑财产', 'PROPERTY_FEE_REGISTRATION_MISMATCH', '物业缴费与房产登记不匹配', NULL, 'STATEMENT', NULL, '员工及关系人有物业缴费记录，但名下房产无新增登记。', 1, 20, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_PROPERTY', '可疑财产', 'TAX_ASSET_REGISTRATION_MISMATCH', '大额纳税与资产登记不匹配', NULL, 'STATEMENT', NULL, '员工及关系人有5000元以上的纳税记录，但名下无房产车产新增登记。', 1, 30, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_PROPERTY', '可疑财产', 'INCOME_ASSET_MISMATCH', '收入资产不符', NULL, 'STATEMENT', 'HIGH', '豪华房产价值超家庭年收入10倍', 1, 40, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_FOREIGN_EXCHANGE', '可疑外汇交易', 'FOREX_BUY_AMT', '可疑外汇交易', 'FOREX_BUY_AMT', 'STATEMENT', NULL, '单笔购汇金额超限', 1, 10, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_FOREIGN_EXCHANGE', '可疑外汇交易', 'FOREX_SELL_AMT', '可疑外汇交易', 'FOREX_SELL_AMT', 'STATEMENT', NULL, '单笔结汇金额超限', 1, 20, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_FOREIGN_EXCHANGE', '可疑外汇交易', 'CROSS_BORDER_AMT', '可疑外汇交易', 'CROSS_BORDER_AMT', 'STATEMENT', NULL, '单笔跨境汇款金额超限', 1, 30, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_INTEREST_PAYMENT', '可疑付息', 'INTEREST_PAYMENT_BY_OTHERS', '可疑付息', NULL, 'OBJECT', 'HIGH', '客户经理管户的客户在智柜、柜面连续代交利息，且代交人数超过2人。', 1, 10, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_PURCHASE', '可疑采购', 'LARGE_PURCHASE_TRANSACTION', '可疑采购', NULL, 'STATEMENT', NULL, '单笔采购金额超过10万元。', 1, 10, 'system', '占位规则，待补充真实SQL'),
('SUSPICIOUS_PURCHASE', '可疑采购', 'SUPPLIER_CONCENTRATION', '可疑采购', NULL, 'OBJECT', NULL, '单个供应商采购额占总采购额比例超过70%。', 1, 20, 'system', '占位规则，待补充真实SQL'),
('ABNORMAL_BEHAVIOR', '异常行为', 'STOCK_TFR_LARGE', '可疑银证大额转账', 'STOCK_TFR_LARGE', 'STATEMENT', NULL, '家庭老人/非关系人银证大额转账', 1, 10, 'system', '占位规则，待补充真实SQL'),
('ABNORMAL_BEHAVIOR', '异常行为', 'WITHDRAW_CNT', '微信支付宝频繁提现', 'WITHDRAW_CNT', 'OBJECT', NULL, '微信、支付宝单日提现次数超过设置次数', 1, 20, 'system', '占位规则，待补充真实SQL'),
('ABNORMAL_BEHAVIOR', '异常行为', 'WITHDRAW_AMT', '微信支付宝提现超额', 'WITHDRAW_AMT', 'OBJECT', NULL, '微信、支付宝单日累计提现金额超过限额', 1, 30, 'system', '占位规则，待补充真实SQL'),
('ABNORMAL_BEHAVIOR', '异常行为', 'SALARY_QUICK_TRANSFER', '工资快速转出', NULL, 'OBJECT', NULL, '工资发放后24小时内转出超过80%的资金', 1, 40, 'system', '占位规则，待补充真实SQL'),
('ABNORMAL_BEHAVIOR', '异常行为', 'SALARY_UNUSED', '工资无使用记录', NULL, 'OBJECT', NULL, '工资发放后除代扣项目外，连续30天犖奕魏蜗鸦蜃思锹肌', 1, 50, 'system', '占位规则，待补充真实SQL'),
('ABNORMAL_BEHAVIOR', '异常行为', 'LARGE_STOCK_TRADING', '大额炒股', NULL, 'STATEMENT', 'HIGH', '单次三方资管交易金额超过100万元。', 1, 60, 'system', '占位规则，待补充真实SQL'),
('ABNORMAL_BEHAVIOR', '异常行为', 'PROXY_ACCOUNT_OPERATION', '疑似代理他人账户', NULL, 'OBJECT', NULL, NULL, 1, 70, 'system', '占位规则，待补充真实SQL')
ON DUPLICATE KEY UPDATE
    model_code = VALUES(model_code),
    model_name = VALUES(model_name),
    rule_name = VALUES(rule_name),
    indicator_code = VALUES(indicator_code),
    result_type = VALUES(result_type),
    risk_level = VALUES(risk_level),
    business_caliber = VALUES(business_caliber),
    enabled = VALUES(enabled),
    sort_order = VALUES(sort_order),
    update_by = 'system',
    remark = VALUES(remark);

INSERT INTO ccdi_model_param (
    project_id,
    model_code,
    model_name,
    param_code,
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    update_by,
    update_time,
    remark
)
SELECT
    project_id,
    model_code,
    model_name,
    'ANNUAL_TURNOVER',
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    COALESCE(update_by, create_by),
    update_time,
    remark
FROM ccdi_model_param
WHERE model_code = 'LARGE_TRANSACTION'
  AND param_code = 'annual_turnover'
ON DUPLICATE KEY UPDATE
    model_name = VALUES(model_name),
    param_name = VALUES(param_name),
    param_desc = VALUES(param_desc),
    param_value = VALUES(param_value),
    param_unit = VALUES(param_unit),
    sort_order = VALUES(sort_order),
    update_by = 'system',
    update_time = NOW(),
    remark = VALUES(remark);

INSERT INTO ccdi_model_param (
    project_id,
    model_code,
    model_name,
    param_code,
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    update_by,
    update_time,
    remark
)
SELECT
    project_id,
    model_code,
    model_name,
    'STOCK_TFR_LARGE',
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    COALESCE(update_by, create_by),
    update_time,
    remark
FROM ccdi_model_param
WHERE model_code = 'ABNORMAL_BEHAVIOR'
  AND param_code = 'stock_tfr_large'
ON DUPLICATE KEY UPDATE
    model_name = VALUES(model_name),
    param_name = VALUES(param_name),
    param_desc = VALUES(param_desc),
    param_value = VALUES(param_value),
    param_unit = VALUES(param_unit),
    sort_order = VALUES(sort_order),
    update_by = 'system',
    update_time = NOW(),
    remark = VALUES(remark);

INSERT INTO ccdi_model_param (
    project_id,
    model_code,
    model_name,
    param_code,
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    update_by,
    update_time,
    remark
)
SELECT
    project_id,
    model_code,
    model_name,
    'WITHDRAW_CNT',
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    COALESCE(update_by, create_by),
    update_time,
    remark
FROM ccdi_model_param
WHERE model_code = 'ABNORMAL_BEHAVIOR'
  AND param_code = 'withdraw_cnt'
ON DUPLICATE KEY UPDATE
    model_name = VALUES(model_name),
    param_name = VALUES(param_name),
    param_desc = VALUES(param_desc),
    param_value = VALUES(param_value),
    param_unit = VALUES(param_unit),
    sort_order = VALUES(sort_order),
    update_by = 'system',
    update_time = NOW(),
    remark = VALUES(remark);

INSERT INTO ccdi_model_param (
    project_id,
    model_code,
    model_name,
    param_code,
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    update_by,
    update_time,
    remark
)
SELECT
    project_id,
    model_code,
    model_name,
    'WITHDRAW_AMT',
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    COALESCE(update_by, create_by),
    update_time,
    remark
FROM ccdi_model_param
WHERE model_code = 'ABNORMAL_BEHAVIOR'
  AND param_code = 'withdraw_amt'
ON DUPLICATE KEY UPDATE
    model_name = VALUES(model_name),
    param_name = VALUES(param_name),
    param_desc = VALUES(param_desc),
    param_value = VALUES(param_value),
    param_unit = VALUES(param_unit),
    sort_order = VALUES(sort_order),
    update_by = 'system',
    update_time = NOW(),
    remark = VALUES(remark);

INSERT INTO ccdi_model_param (
    project_id,
    model_code,
    model_name,
    param_code,
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    update_by,
    update_time,
    remark
)
SELECT
    project_id,
    model_code,
    model_name,
    'MULTI_PARTY_AMT_MIN',
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    COALESCE(update_by, create_by),
    update_time,
    remark
FROM ccdi_model_param
WHERE model_code = 'SUSPICIOUS_GAMBLING'
  AND param_code = 'multi_party_amt_min'
ON DUPLICATE KEY UPDATE
    model_name = VALUES(model_name),
    param_name = VALUES(param_name),
    param_desc = VALUES(param_desc),
    param_value = VALUES(param_value),
    param_unit = VALUES(param_unit),
    sort_order = VALUES(sort_order),
    update_by = 'system',
    update_time = NOW(),
    remark = VALUES(remark);

INSERT INTO ccdi_model_param (
    project_id,
    model_code,
    model_name,
    param_code,
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    update_by,
    update_time,
    remark
)
SELECT
    project_id,
    model_code,
    model_name,
    'MULTI_PARTY_AMT_MAX',
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    create_time,
    COALESCE(update_by, create_by),
    update_time,
    remark
FROM ccdi_model_param
WHERE model_code = 'SUSPICIOUS_GAMBLING'
  AND param_code = 'multi_party_amt_max'
ON DUPLICATE KEY UPDATE
    model_name = VALUES(model_name),
    param_name = VALUES(param_name),
    param_desc = VALUES(param_desc),
    param_value = VALUES(param_value),
    param_unit = VALUES(param_unit),
    sort_order = VALUES(sort_order),
    update_by = 'system',
    update_time = NOW(),
    remark = VALUES(remark);

DELETE FROM ccdi_model_param
WHERE param_code IN (
    'annual_turnover',
    'stock_tfr_large',
    'withdraw_cnt',
    'withdraw_amt',
    'multi_party_amt_min',
    'multi_party_amt_max'
);

INSERT INTO ccdi_model_param (
    project_id,
    model_code,
    model_name,
    param_code,
    param_name,
    param_desc,
    param_value,
    param_unit,
    sort_order,
    create_by,
    remark
) VALUES
(0, 'LARGE_TRANSACTION', '大额交易模型', 'SINGLE_TRANSACTION_AMOUNT', '单笔大额收入金额', '单笔收入超过该金额', '1111', '元', 1, 'admin', '系统默认参数'),
(0, 'LARGE_TRANSACTION', '大额交易模型', 'CUMULATIVE_TRANSACTION_AMOUNT', '累计大额收入金额', '年累计收入超过该金额', '50000001', '元', 2, 'admin', '系统默认参数'),
(0, 'LARGE_TRANSACTION', '大额交易模型', 'ANNUAL_TURNOVER', '年累计交易额', '年累计交易额超过该金额', '50000001', '元', 3, 'admin', '系统默认参数'),
(0, 'LARGE_TRANSACTION', '大额交易模型', 'LARGE_CASH_DEPOSIT', '单笔大额存现金额', '单笔存现金额超过', '2000001', '元', 4, 'admin', '系统默认参数'),
(0, 'LARGE_TRANSACTION', '大额交易模型', 'FREQUENT_CASH_DEPOSIT', '单日多次存现次数', '24小时内累计存现超过', '5', '次', 5, 'admin', '系统默认参数'),
(0, 'LARGE_TRANSACTION', '大额交易模型', 'FREQUENT_TRANSFER', '单笔大额转账金额', '单日转账次数超过', '100001', '次/日', 6, 'admin', '系统默认参数'),
(0, 'SUSPICIOUS_PART_TIME', '可疑兼职模型', 'MONTHLY_FIXED_INCOME', '月度非本行工资收入金额', '除本行工资外,每月固定收入超过', '5000', '元/月', 1, 'admin', '系统默认参数'),
(0, 'SUSPICIOUS_PART_TIME', '可疑兼职模型', 'FIXED_COUNTERPARTY_TRANSFER_MIN', '季度稳定收入金额下限', '每季从固定交易对手转入金额下限', '3000', '元/季', 2, 'admin', '系统默认参数'),
(0, 'SUSPICIOUS_PART_TIME', '可疑兼职模型', 'FIXED_COUNTERPARTY_TRANSFER_MAX', '季度稳定收入金额上限', '每季从固定交易对手转入金额上限', '15000', '元/季', 3, 'admin', '系统默认参数'),
(0, 'SUSPICIOUS_FOREIGN_EXCHANGE', '可疑外汇交易模型', 'SINGLE_PURCHASE_AMOUNT', '单笔购汇金额', '单笔购汇超过该金额', '50000', '美元/笔', 1, 'admin', '系统默认参数'),
(0, 'SUSPICIOUS_FOREIGN_EXCHANGE', '可疑外汇交易模型', 'SINGLE_SETTLEMENT_AMOUNT', '单笔结汇金额', '单笔结汇超过该金额', '50000', '美元/笔', 2, 'admin', '系统默认参数'),
(0, 'SUSPICIOUS_FOREIGN_EXCHANGE', '可疑外汇交易模型', 'CROSS_BORDER_REMITTANCE', '跨境汇款金额', '跨境汇款金额超过', '200000', '美元/笔', 3, 'admin', '系统默认参数'),
(0, 'ABNORMAL_BEHAVIOR', '异常行为模型', 'STOCK_TFR_LARGE', '银证转账大额金额', '', '1000000', '元', 1, 'admin', '系统默认参数'),
(0, 'ABNORMAL_BEHAVIOR', '异常行为模型', 'WITHDRAW_CNT', '微信、支付宝单日提现次数', '', '3', '次/日', 2, 'admin', '系统默认参数'),
(0, 'ABNORMAL_BEHAVIOR', '异常行为模型', 'WITHDRAW_AMT', '微信、支付宝单日提现金额', '', '50000', '元/日', 3, 'admin', '系统默认参数'),
(0, 'SUSPICIOUS_GAMBLING', '疑似赌博交易模型', 'MULTI_PARTY_AMT_MIN', '疑似赌博金额下限', '', '500', '元', 1, 'admin', '系统默认参数'),
(0, 'SUSPICIOUS_GAMBLING', '疑似赌博交易模型', 'MULTI_PARTY_AMT_MAX', '疑似赌博金额上限', '', '5000', '元', 2, 'admin', '系统默认参数')
ON DUPLICATE KEY UPDATE
    model_name = VALUES(model_name),
    param_name = VALUES(param_name),
    param_desc = VALUES(param_desc),
    param_value = VALUES(param_value),
    param_unit = VALUES(param_unit),
    sort_order = VALUES(sort_order),
    update_by = 'system',
    update_time = NOW(),
    remark = VALUES(remark);

COMMIT;
