START TRANSACTION;

CREATE TABLE IF NOT EXISTS `ccdi_account_info` (
  `account_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `account_no` VARCHAR(240) NOT NULL COMMENT '账号',
  `account_type` VARCHAR(64) DEFAULT NULL COMMENT '账户类型',
  `account_name` VARCHAR(128) DEFAULT NULL COMMENT '账户名称',
  `owner_type` VARCHAR(32) NOT NULL COMMENT '归属人类型',
  `owner_id` VARCHAR(64) NOT NULL COMMENT '归属人标识',
  `bank` VARCHAR(128) DEFAULT NULL COMMENT '开户行',
  `bank_code` VARCHAR(64) DEFAULT NULL COMMENT '开户行编码',
  `currency` VARCHAR(32) DEFAULT NULL COMMENT '币种',
  `is_self_account` TINYINT DEFAULT 1 COMMENT '是否本人账户',
  `monthly_avg_trans_count` DECIMAL(18, 2) DEFAULT NULL COMMENT '月均交易笔数',
  `monthly_avg_trans_amount` DECIMAL(18, 2) DEFAULT NULL COMMENT '月均交易金额',
  `trans_freq_type` VARCHAR(32) DEFAULT NULL COMMENT '交易频率类型',
  `dr_max_single_amount` DECIMAL(18, 2) DEFAULT NULL COMMENT '最大单笔支出金额',
  `cr_max_single_amount` DECIMAL(18, 2) DEFAULT NULL COMMENT '最大单笔收入金额',
  `dr_max_daily_amount` DECIMAL(18, 2) DEFAULT NULL COMMENT '最大单日支出金额',
  `cr_max_daily_amount` DECIMAL(18, 2) DEFAULT NULL COMMENT '最大单日收入金额',
  `trans_risk_level` VARCHAR(32) DEFAULT NULL COMMENT '交易风险等级',
  `status` TINYINT NOT NULL DEFAULT 1 COMMENT '账户状态：1正常，2已销户',
  `effective_date` DATE DEFAULT NULL COMMENT '开户日期',
  `invalid_date` DATE DEFAULT NULL COMMENT '销户日期',
  `create_by` VARCHAR(64) DEFAULT NULL COMMENT '创建者',
  `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_by` VARCHAR(64) DEFAULT NULL COMMENT '更新者',
  `update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`account_id`),
  KEY `idx_ccdi_account_info_owner` (`owner_type`, `owner_id`),
  KEY `idx_ccdi_account_info_account_no` (`account_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='员工账户信息表';

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
('ABNORMAL_ACCOUNT', '异常账户', 'SUDDEN_ACCOUNT_CLOSURE', '突然销户', NULL, 'OBJECT', 'HIGH',
 '员工本人账户已销户，且销户日前30天内仍存在交易记录。', 1, 10, 'system',
 '真实规则：识别员工本人账户销户前30天内仍有交易的员工对象'),
('ABNORMAL_ACCOUNT', '异常账户', 'DORMANT_ACCOUNT_LARGE_ACTIVATION', '休眠账户大额启用', NULL, 'OBJECT', 'HIGH',
 '员工本人账户开户后长期未使用，首次启用后出现大额资金流动。', 1, 20, 'system',
 '真实规则：识别长期休眠后首次启用即出现大额资金流动的员工对象')
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',
    update_time = NOW(),
    remark = VALUES(remark);

COMMIT;
