-- 进口商企业信息
DROP TABLE IF EXISTS `importer_entity`;
CREATE TABLE `importer_entity`
(
    `id`                      BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `customer_user_id`         BIGINT(20)  UNSIGNED NOT NULL COMMENT '用户id',
    `entity_no`            VARCHAR(16)        DEFAULT '' COMMENT '企业编号',
    `region`            VARCHAR(4)        DEFAULT '' COMMENT '地区 1中国香港 2中国澳门 3中国台湾 4中国境外',
    `country`            VARCHAR(4)        DEFAULT '' COMMENT '国家',
    `status`            TINYINT(3)        DEFAULT 0 COMMENT '状态 0待生效/1生效',
    `entity_name`            VARCHAR(64)        DEFAULT '' COMMENT '企业名称',
    `cert_type`            VARCHAR(32)        DEFAULT '' COMMENT '企业证件类型',
    `cert_no`            VARCHAR(32)        DEFAULT '' COMMENT '企业证件号',
    `business_province`  	VARCHAR(64)        DEFAULT '' COMMENT '经营地址（省 / 州 / 区）',
    `business_city`  	VARCHAR(64)        DEFAULT '' COMMENT '经营地址（市 / 区）',
    `business_address`  	VARCHAR(64)        DEFAULT '' COMMENT '经营地址',
    `business_post_code`  	VARCHAR(64)        DEFAULT '' COMMENT '经营地址邮政编码',
    `contact_direct_ind`  VARCHAR(1)        DEFAULT '' COMMENT '是否允许直接联系',
    `contact_name`  		VARCHAR(32)        DEFAULT '' COMMENT '企业联系人姓名',
    `contact_mobile`  	VARCHAR(18)        DEFAULT '' COMMENT '企业联系人手机号',
    `contact_email`  		VARCHAR(64)        DEFAULT '' COMMENT '企业联系人邮箱',
    `vat_no`  		VARCHAR(64)        DEFAULT '' COMMENT '税号',
    `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`),
    UNIQUE KEY uk_importer_entity_no (`entity_no`),
    INDEX idx_user_id(`customer_user_id`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='进口商企业信息';





-- 供应商企业信息
DROP TABLE IF EXISTS `vendor_entity`;
CREATE TABLE `vendor_entity`
(
    `id`                      BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `customer_user_id`         BIGINT(20)  UNSIGNED NOT NULL COMMENT '用户id',
    `entity_no`            VARCHAR(16)        DEFAULT '' COMMENT '企业编号',
    `entity_name`            VARCHAR(64)        DEFAULT '' COMMENT '企业名称',
    `contact_name`  		VARCHAR(32)        DEFAULT '' COMMENT '企业联系人姓名',
    `contact_cert_no`  		VARCHAR(32)        DEFAULT '' COMMENT '企业联系人证件号',
    `contact_mobile`  	VARCHAR(18)        DEFAULT '' COMMENT '企业联系人手机号',
    `contact_email`  		VARCHAR(64)        DEFAULT '' COMMENT '企业联系人邮箱',
    `acct_name`  		VARCHAR(64)        DEFAULT '' COMMENT '收款账户户名',
    `acct_no`  		VARCHAR(32)        DEFAULT '' COMMENT '收款银行卡号',
    `acct_open_bank`  		VARCHAR(64)        DEFAULT '' COMMENT '收款账户开户行',
    `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`),
    UNIQUE KEY uk_vendor_entity_no (`entity_no`),
    INDEX idx_user_id(`customer_user_id`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='供应商企业信息';






-- 销售订单
DROP TABLE IF EXISTS `sales_order`;
CREATE TABLE `sales_order`
(
    `id`                      BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `customer_user_id`         BIGINT(20)  UNSIGNED NOT NULL COMMENT '用户id',
    `order_no`            VARCHAR(32)        DEFAULT '' COMMENT '订单编号',
    `importer_id`            BIGINT(20)  UNSIGNED DEFAULT NULL COMMENT '进口商id',
    `sale_contract_id`       BIGINT(20)  UNSIGNED DEFAULT NULL COMMENT '销售合同id',
    `amount`            DECIMAL(17,2)        DEFAULT '0.00' COMMENT '订单金额',
    `status`            TINYINT(3)        DEFAULT 0 COMMENT '状态 0待生效/1待发货/2运输中/3交易完成',
    `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`),
    UNIQUE KEY uk_order_no (`order_no`),
    INDEX idx_user_id(`customer_user_id`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='销售订单表';





-- 销售订单-关联商品
DROP TABLE IF EXISTS `sales_order_goods`;
CREATE TABLE `sales_order_goods`
(
    `id`                      BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `sale_order_id`         BIGINT(20)  UNSIGNED NOT NULL COMMENT '销售订单id',
    `sales_commodity_id`         BIGINT(20)  UNSIGNED NOT NULL COMMENT '销售合同商品id',
    `vendor_entity_no`            VARCHAR(32)        DEFAULT '' COMMENT '供应商编号',
    `hs_code`            VARCHAR(32)  DEFAULT '' COMMENT 'HS CODE',
    `name`            VARCHAR(32)  DEFAULT '' COMMENT '商品名称',
    `unit`            VARCHAR(32)  DEFAULT '' COMMENT '计量单位',
    `packing_specifications`            VARCHAR(16)  DEFAULT '' COMMENT '包装规格',
    `price`            DECIMAL(17,2)   DEFAULT '0' COMMENT '销售单价',
    `tax_refund_rate`            DECIMAL(8,6)   DEFAULT '0' COMMENT '退税率',
    `count`            SMALLINT(6)   DEFAULT '0' COMMENT '商品数量',
    `price_total`            DECIMAL(17,2)   DEFAULT '0' COMMENT '商品总额',
    `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`),
    INDEX idx_sale_order_id (`sale_order_id`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='销售订单-关联商品';



-- 销售订单-物流信息
DROP TABLE IF EXISTS `sales_order_logistics`;
CREATE TABLE `sales_order_logistics`
(
    `id`                      BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `order_id`         BIGINT(20)  UNSIGNED NOT NULL COMMENT '销售订单id',
    `logistics_company`            VARCHAR(64)        DEFAULT '' COMMENT '物流公司',
    `deliver_time`            datetime        DEFAULT null COMMENT '发货时间',
    `from_port`            VARCHAR(64)        DEFAULT '' COMMENT '启运港',
    `dest_port`  	VARCHAR(64)        DEFAULT '' COMMENT '目的港',
    `lading_bill_no`  	VARCHAR(64)        DEFAULT '' COMMENT '提单号',
    `lading_bill_file_id`  	 BIGINT(20)  UNSIGNED DEFAULT null COMMENT '提单文件id',
    `estimated_arrival_time`  	datetime        DEFAULT null COMMENT '预计送达日期',
    `deliver_remark`  	VARCHAR(128)        DEFAULT '' COMMENT '发货备注',
    `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`),
    INDEX idx_order_id (`order_id`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='销售订单-物流信息';




-- 销售订单-发票信息
DROP TABLE IF EXISTS `sales_order_invoice`;
CREATE TABLE `sales_order_invoice`
(
    `id`                      BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `order_id`         BIGINT(20)  UNSIGNED NOT NULL COMMENT '销售订单id',
    `invoice_no`            VARCHAR(32)        DEFAULT '' COMMENT '发票号码',
    `amount`             DECIMAL(17,2)   DEFAULT '0' COMMENT '发票金额',
    `file_id`            BIGINT(20)  UNSIGNED NOT 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`),
    UNIQUE KEY uk_invoice_no (`invoice_no`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='销售订单-发票信息';




-- 销售订单-物流-集装箱信息
DROP TABLE IF EXISTS `sales_order_container`;
CREATE TABLE `sales_order_container`
(
    `id`                      BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `logistics_id`         BIGINT(20)  UNSIGNED NOT NULL COMMENT '订单物流id',
    `bill_no`            VARCHAR(32)        DEFAULT '' COMMENT '集装箱单号',
    `file_id`            BIGINT(20)  UNSIGNED NOT 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`),
    INDEX idx_logistics_id (`logistics_id`)
)ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='销售订单-集装箱信息';





-- 文件模板配置
DROP TABLE IF EXISTS `s_file_template`;
CREATE TABLE `s_file_template`
(
    `id`                      BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `template_code`         VARCHAR(32)        not null COMMENT '模板编号',
    `file_type`           VARCHAR(32)  	DEFAULT '' COMMENT '文件类型',
    `default_name`           VARCHAR(32)  	DEFAULT '' COMMENT '生成文件默认名称',
    `src_path`            VARCHAR(128)        DEFAULT '' COMMENT '模板绝对路径',
    `dest_dir`            VARCHAR(64)   DEFAULT '' COMMENT '生成文件存储目录',
    `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 CHARACTER SET utf8mb4 COLLATE utf8mb4_bin COMMENT='文件模板配置';

