-- 20241022
-- 进口商新增字段
ALTER TABLE `importer_entity`
    ADD COLUMN `business_category` varchar(256) DEFAULT '' COMMENT '经营品类' AFTER `vat_no`;

ALTER TABLE `importer_entity`
    ADD COLUMN `trading_life` varchar(16) DEFAULT '' COMMENT '交易年限(M/Y)' AFTER `business_category`;

ALTER TABLE `importer_entity`
    ADD COLUMN `settlement_period` SMALLINT(6) DEFAULT 0 COMMENT '结算账期（天）' AFTER `trading_life`;

ALTER TABLE `importer_entity`
    ADD COLUMN `trading_amount_past_year` DECIMAL(17, 2) DEFAULT 0 COMMENT '过去一年双方交易额' AFTER `settlement_period`;

ALTER TABLE `importer_entity`
    ADD COLUMN `trading_amount_past_year_currency` varchar(3) DEFAULT '' COMMENT '过去一年双方交易额币种' AFTER `trading_amount_past_year`;

ALTER TABLE `importer_entity`
    ADD COLUMN `amount_to_be_applied` DECIMAL(17, 2) DEFAULT 0 COMMENT '拟申请额度金额' AFTER `amount_trading_past_year_currency`;

ALTER TABLE `importer_entity`
    ADD COLUMN `amount_to_be_applied_currency` varchar(3) DEFAULT '' COMMENT '拟申请额度金额币种' AFTER `amount_to_be_applied`;

ALTER TABLE `importer_entity`
    ADD COLUMN `period_to_be_applied` varchar(16) DEFAULT '' COMMENT '拟申请额度期限(M/Y)' AFTER `amount_to_be_applied_currency`;


-- 新建备案单证写入小图任务
DROP TABLE IF EXISTS `filing_doc_write_task`;
CREATE TABLE `filing_doc_write_task`
(
    `id`      bigint(20)  NOT NULL AUTO_INCREMENT COMMENT '主键id',
    `cert_no` varchar(50) NOT NULL COMMENT '企业证件号',
    `biz_no`  varchar(50) NOT NULL COMMENT '业务编号',
    `part`    tinyint(4)   DEFAULT 1 COMMENT '阶段',
    `status`  tinyint(4)   DEFAULT 0 COMMENT '状态',
    `remark`  varchar(128) DEFAULT '' COMMENT '备注',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4 COMMENT ='备案单证写入小图任务';


-- 报关单相关文件
DROP TABLE IF EXISTS `customs_declaration_file`;
CREATE TABLE `customs_declaration_file`
(
    `id`              bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `customs_no`      varchar(18) COLLATE utf8mb4_bin DEFAULT '' COMMENT '报关单海关编号',
    `customs_file_id` bigint(20)                      DEFAULT NULL COMMENT '报关单文件id',
    `entrust_no`      varchar(32) COLLATE utf8mb4_bin DEFAULT '' COMMENT '委托报关协议编号',
    `entrust_file_id` bigint(20)                      DEFAULT NULL COMMENT '委托报关协议文件id',
    `deleted`         tinyint(1)                      DEFAULT '0' COMMENT '删除标识',
    `gmt_create`      timestamp           NOT NULL    DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `gmt_modified`    timestamp           NOT NULL    DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin COMMENT ='报关单相关文件';


-- 销售订单物流新增字段
ALTER TABLE `sales_order_logistics`
    ADD COLUMN `lading_type` varchar(2) DEFAULT '' COMMENT '提运单类型' AFTER `dest_port`;
ALTER TABLE `sales_order_logistics`
    ADD COLUMN `lading_date` datetime DEFAULT NULL COMMENT '提运单日期' AFTER `lading_type`;


-- 国家表 新增制裁级标识
ALTER TABLE sys_country
    ADD COLUMN
        `sanctioned` TINYINT(1) DEFAULT 0 COMMENT '制裁标识' AFTER `level`;

update sys_country
set sanctioned = 1
where name in (
               '朝鲜', '苏丹', '厄立特里亚', '伊拉克', '利比亚', '刚果（金）', '也门', '南苏丹', '黎巴嫩',
               '马里', '索马里', '伊朗', '科特迪瓦', '叙利亚', '古巴', '俄罗斯', '委内瑞拉', '缅甸',
               '布隆迪', '津巴布韦', '白俄罗斯', '北苏丹');
