#客户管理
背景
表结构
1. customer 客户信息
CREATE TABLE `customer` (
`customer_id` bigint NOT NULL AUTO_INCREMENT COMMENT '客户ID',
`customer_code` varchar(32) NOT NULL DEFAULT '' COMMENT '客户代码',
`customer_name` varchar(100) NOT NULL DEFAULT '' COMMENT '客户名称',
`customer_short_name` varchar(50) NOT NULL DEFAULT '' COMMENT '客户简称',
`customer_status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '客户状态:0待审核,1已通过审核,2未通过审核,3已停用',
`customer_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '客户类型:1普通',
`customer_address` varchar(150) NOT NULL DEFAULT '' COMMENT '公司地址',
`customer_domain` varchar(100) NOT NULL DEFAULT '' COMMENT '公司网址',
`customer_currency` char(8) NOT NULL DEFAULT 'CNY' COMMENT '结算币种',
`customer_contactor` varchar(32) NOT NULL DEFAULT '' COMMENT '联系人',
`customer_phone` varchar(32) NOT NULL DEFAULT '' COMMENT '联系电话',
`customer_email` varchar(32) NOT NULL DEFAULT '' COMMENT '联系邮箱',
`app_id` varchar(100) NOT NULL DEFAULT '' COMMENT 'appId',
`app_secret` varchar(100) NOT NULL DEFAULT '' COMMENT 'appSecret',
`create_user_id` bigint NOT NULL DEFAULT '0' COMMENT '创建人ID',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_user_id` bigint NOT NULL DEFAULT '0' COMMENT '更新人ID',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
`config_status` tinyint NOT NULL DEFAULT '1' COMMENT '0:禁用 1:启用',
`customer_level` tinyint NOT NULL DEFAULT '1' COMMENT '客户等级 1:C级 2:P级 3:S级',
`notify_email` varchar(128) DEFAULT '' COMMENT '通知邮箱',
`account_email` varchar(128) DEFAULT '' COMMENT '账单邮箱',
`contract_id` bigint DEFAULT NULL COMMENT '合同ID',
`contract_name` varchar(32) DEFAULT NULL COMMENT '合同名称',
`attached_id` bigint DEFAULT NULL COMMENT '附件ID',
`file_name` varchar(255) DEFAULT NULL COMMENT '文件名',
PRIMARY KEY (`customer_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='客户表';
2. customer 按规范添加字段与索引
-- 客户信息
-- 第一步先添加字段,存在create_time,create_user_id,update_time,update_user_id
ALTER TABLE customer
ADD COLUMN `remark` varchar(256) DEFAULT '' COMMENT '备注',
ADD COLUMN `over_flag` tinyint NOT NULL DEFAULT '0' COMMENT '完结标识 0-未完结,1-已完结',
ADD COLUMN `create_user` bigint DEFAULT NULL COMMENT '创建人',
ADD COLUMN `update_user` bigint DEFAULT NULL COMMENT '更新人';
-- 第二步历史数据初始化
update customer set
create_user = create_user_id,
update_user = update_user_id
where 1=1;
-- 第三步修改字段约束
ALTER TABLE customer
MODIFY COLUMN `create_user` bigint NOT NULL COMMENT '创建人',
MODIFY COLUMN `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';
-- 索引
ALTER TABLE customer
ADD UNIQUE INDEX `uniq_customer_code`(`customer_code`),
ADD INDEX `idx_create_time` (`create_time`),
ADD INDEX `idx_update_time` (`update_time`);
-- create_user_id,update_user_id待弃用
ALTER TABLE customer
MODIFY COLUMN `create_user_id` bigint NOT NULL DEFAULT '0' COMMENT '创建人ID(待弃用)',
MODIFY COLUMN `update_user_id` bigint NOT NULL DEFAULT '0' COMMENT '更新人ID(待弃用)';
3. real_customers_info 真实客户信息
CREATE TABLE `real_customers_info` (
`real_customers_id` bigint NOT NULL COMMENT '主键',
`real_customers_code` varchar(32) NOT NULL COMMENT '真实客户编码',
`real_customers_name` varchar(64) NOT NULL COMMENT '真实客户名称',
`remark` varchar(255) DEFAULT NULL COMMENT '备注',
`over_flag` tinyint NOT NULL DEFAULT '0' COMMENT '完结标识 0-未完结,1-已完结',
`create_user` bigint NOT NULL COMMENT '创建人',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_user` bigint DEFAULT NULL COMMENT '更新人',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`real_customers_id`),
UNIQUE KEY `uniq_real_customers_code` (`real_customers_code`),
KEY `idx_create_time` (`create_time`),
KEY `idx_update_time` (`update_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='真实客户信息表';
4. customer_cancel_key 客户取消密钥key
CREATE TABLE `customer_cancel_key` (
`aid` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`customer_id` bigint NOT NULL DEFAULT '0' COMMENT '客户ID',
`customer_code` varchar(32) NOT NULL COMMENT '客户代码',
`customer_status` tinyint NOT NULL DEFAULT '1' COMMENT '0:禁用 1:启用',
`app_key` varchar(100) NOT NULL COMMENT 'app_key',
`app_token` varchar(100) NOT NULL COMMENT 'app_token',
`create_user` bigint NOT NULL DEFAULT '0' COMMENT '创建人ID',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_user` bigint NOT NULL DEFAULT '0' COMMENT '更新人ID',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`aid`)
) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8mb3 COMMENT='客户取消订单密钥表';
5. customer_cancel_key 按规范添加字段与索引
-- customer_cancel_key
-- 第一步先添加字段,存在create_time,create_user,update_time,update_user
ALTER TABLE customer_cancel_key
ADD COLUMN `remark` varchar(256) DEFAULT '' COMMENT '备注',
ADD COLUMN `over_flag` tinyint NOT NULL DEFAULT '0' COMMENT '完结标识 0-未完结,1-已完结';
-- 第二步修改字段约束
ALTER TABLE customer_cancel_key
MODIFY COLUMN `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';
-- 索引,一个客户多个key
ALTER TABLE customer_cancel_key
ADD UNIQUE INDEX `uniq_customer_code_app_key`(`customer_code`,`app_key`),
ADD INDEX `idx_create_time` (`create_time`),
ADD INDEX `idx_update_time` (`update_time`);
6. customer_attached 客户附件表
CREATE TABLE `customer_attached` (
`attached_id` bigint NOT NULL AUTO_INCREMENT COMMENT '附件ID',
`file_name` varchar(255) NOT NULL COMMENT '文件名',
`file_path` varchar(255) NOT NULL COMMENT '文件路径',
`file_type` varchar(16) NOT NULL DEFAULT '' COMMENT '文件类型',
`customer_id` bigint NOT NULL COMMENT '客户ID',
`customer_code` varchar(32) NOT NULL COMMENT '客户代码',
`attached_status` tinyint(1) DEFAULT '0' COMMENT '状态:0废弃1正常',
`attached_type` tinyint(1) DEFAULT '0' COMMENT '附件类型:1合同文件',
`remark` varchar(255) DEFAULT NULL COMMENT '备注',
`create_user` bigint NOT NULL COMMENT '创建人',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_user` bigint NOT NULL COMMENT '更新人',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`attached_id`),
UNIQUE KEY `udx_customer_id` (`customer_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='客户附件表';
7. customer_attached 按规范添加字段与索引
-- customer_attached
-- 客户附件信息
-- 第一步先添加字段,存在create_time,create_user_id,update_time,update_user_id
ALTER TABLE customer_attached
ADD COLUMN `over_flag` tinyint NOT NULL DEFAULT '0' COMMENT '完结标识 0-未完结,1-已完结';
-- 索引
ALTER TABLE customer_attached
ADD INDEX `idx_create_time` (`create_time`),
ADD INDEX `idx_update_time` (`update_time`);
8. dms_business_log 业务日志
business_source通过类型区分不同业务日志,客户日志对应business_source==5
CREATE TABLE `dms_business_log` (
`log_id` bigint NOT NULL AUTO_INCREMENT COMMENT '日志ID',
`business_no` varchar(64) NOT NULL COMMENT '业务来源单号',
`business_source` tinyint NOT NULL COMMENT '业务来源 1-运输费用录入',
`operation_type` tinyint NOT NULL COMMENT '操作类型 1-创建 2-更新 3-删除',
`old_value` text COMMENT '旧值',
`new_value` text COMMENT '新值',
`change_fields` text COMMENT '变化字段',
`ip_address` varchar(45) DEFAULT NULL COMMENT '操作人IP地址',
`remark` varchar(255) DEFAULT NULL COMMENT '备注',
`over_flag` tinyint NOT NULL DEFAULT '0' COMMENT '完结标识 0-未完结,1-已完结',
`create_user` bigint NOT NULL COMMENT '创建人',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_user` bigint DEFAULT NULL COMMENT '更新人',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`log_id`),
KEY `idx_create_time` (`create_time`),
KEY `idx_update_time` (`update_time`),
KEY `idx_business_no` (`business_no`,`business_source`)
) ENGINE=InnoDB AUTO_INCREMENT=2011241839663370242 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='业务日志表';
功能流程图

作者:陆飞 创建时间:2026-01-13 17:18
最后编辑:高美燕 更新时间:2026-03-03 10:08
最后编辑:高美燕 更新时间:2026-03-03 10:08