214 lines
14 KiB
SQL
214 lines
14 KiB
SQL
-- =====================================================
|
|
-- ERP系统数据库设计 - 初始数据脚本
|
|
-- 版本: 1.0.0
|
|
-- 创建日期: 2026-01-25
|
|
-- 说明: 系统初始化数据,包含默认租户、字典、计量单位等
|
|
-- =====================================================
|
|
|
|
SET NAMES utf8mb4;
|
|
|
|
-- =====================================================
|
|
-- 1. 默认租户数据
|
|
-- 说明: 用户表(sys_user)和部门表(sys_dept)已在原项目数据库中定义,此处不再插入初始数据
|
|
-- =====================================================
|
|
|
|
INSERT INTO `sys_tenant` (`tenant_id`, `tenant_name`, `contact_name`, `contact_phone`, `status`, `del_flag`, `create_time`) VALUES
|
|
('000000', '默认租户', '管理员', '13800000000', '0', '0', NOW());
|
|
|
|
-- =====================================================
|
|
-- 2. 计量单位数据
|
|
-- =====================================================
|
|
|
|
INSERT INTO `erp_md_unit` (`tenant_id`, `unit_code`, `unit_name`, `unit_type`, `order_num`, `enable_flag`, `del_flag`, `create_time`) VALUES
|
|
-- 数量单位
|
|
('000000', 'PCS', '个', 'COUNT', 1, 'Y', '0', NOW()),
|
|
('000000', 'SET', '套', 'COUNT', 2, 'Y', '0', NOW()),
|
|
('000000', 'PAIR', '对', 'COUNT', 3, 'Y', '0', NOW()),
|
|
('000000', 'BATCH', '批', 'COUNT', 4, 'Y', '0', NOW()),
|
|
('000000', 'ROLL', '卷', 'COUNT', 5, 'Y', '0', NOW()),
|
|
('000000', 'SHEET', '张', 'COUNT', 6, 'Y', '0', NOW()),
|
|
('000000', 'BOX', '箱', 'COUNT', 7, 'Y', '0', NOW()),
|
|
('000000', 'BAG', '袋', 'COUNT', 8, 'Y', '0', NOW()),
|
|
('000000', 'BOTTLE', '瓶', 'COUNT', 9, 'Y', '0', NOW()),
|
|
('000000', 'CAN', '罐', 'COUNT', 10, 'Y', '0', NOW()),
|
|
-- 重量单位
|
|
('000000', 'KG', '千克', 'WEIGHT', 20, 'Y', '0', NOW()),
|
|
('000000', 'G', '克', 'WEIGHT', 21, 'Y', '0', NOW()),
|
|
('000000', 'T', '吨', 'WEIGHT', 22, 'Y', '0', NOW()),
|
|
('000000', 'MG', '毫克', 'WEIGHT', 23, 'Y', '0', NOW()),
|
|
-- 长度单位
|
|
('000000', 'M', '米', 'LENGTH', 30, 'Y', '0', NOW()),
|
|
('000000', 'CM', '厘米', 'LENGTH', 31, 'Y', '0', NOW()),
|
|
('000000', 'MM', '毫米', 'LENGTH', 32, 'Y', '0', NOW()),
|
|
('000000', 'KM', '千米', 'LENGTH', 33, 'Y', '0', NOW()),
|
|
-- 面积单位
|
|
('000000', 'M2', '平方米', 'AREA', 40, 'Y', '0', NOW()),
|
|
('000000', 'CM2', '平方厘米', 'AREA', 41, 'Y', '0', NOW()),
|
|
-- 体积单位
|
|
('000000', 'M3', '立方米', 'VOLUME', 50, 'Y', '0', NOW()),
|
|
('000000', 'L', '升', 'VOLUME', 51, 'Y', '0', NOW()),
|
|
('000000', 'ML', '毫升', 'VOLUME', 52, 'Y', '0', NOW());
|
|
|
|
-- =====================================================
|
|
-- 3. 物料分类数据
|
|
-- =====================================================
|
|
|
|
INSERT INTO `erp_md_item_type` (`tenant_id`, `item_type_code`, `item_type_name`, `parent_type_id`, `ancestors`, `order_num`, `enable_flag`, `del_flag`, `create_time`) VALUES
|
|
-- 一级分类
|
|
('000000', 'RAW', '原材料', NULL, NULL, 1, 'Y', '0', NOW()),
|
|
('000000', 'PARTS', '零部件', NULL, NULL, 2, 'Y', '0', NOW()),
|
|
('000000', 'SEMI', '半成品', NULL, NULL, 3, 'Y', '0', NOW()),
|
|
('000000', 'FINISHED', '成品', NULL, NULL, 4, 'Y', '0', NOW()),
|
|
('000000', 'PACKAGING', '包装物', NULL, NULL, 5, 'Y', '0', NOW()),
|
|
('000000', 'CONSUMABLE', '辅料', NULL, NULL, 6, 'Y', '0', NOW());
|
|
|
|
-- 原材料子分类
|
|
INSERT INTO `erp_md_item_type` (`tenant_id`, `item_type_code`, `item_type_name`, `parent_type_id`, `ancestors`, `order_num`, `enable_flag`, `del_flag`, `create_time`)
|
|
SELECT '000000', 'RAW_STEEL', '钢材', item_type_id, CONCAT(item_type_id), 1, 'Y', '0', NOW() FROM erp_md_item_type WHERE item_type_code = 'RAW' AND tenant_id = '000000';
|
|
|
|
INSERT INTO `erp_md_item_type` (`tenant_id`, `item_type_code`, `item_type_name`, `parent_type_id`, `ancestors`, `order_num`, `enable_flag`, `del_flag`, `create_time`)
|
|
SELECT '000000', 'RAW_ALUMINUM', '铝材', item_type_id, CONCAT(item_type_id), 2, 'Y', '0', NOW() FROM erp_md_item_type WHERE item_type_code = 'RAW' AND tenant_id = '000000';
|
|
|
|
INSERT INTO `erp_md_item_type` (`tenant_id`, `item_type_code`, `item_type_name`, `parent_type_id`, `ancestors`, `order_num`, `enable_flag`, `del_flag`, `create_time`)
|
|
SELECT '000000', 'RAW_PLASTIC', '塑料', item_type_id, CONCAT(item_type_id), 3, 'Y', '0', NOW() FROM erp_md_item_type WHERE item_type_code = 'RAW' AND tenant_id = '000000';
|
|
|
|
INSERT INTO `erp_md_item_type` (`tenant_id`, `item_type_code`, `item_type_name`, `parent_type_id`, `ancestors`, `order_num`, `enable_flag`, `del_flag`, `create_time`)
|
|
SELECT '000000', 'RAW_RUBBER', '橡胶', item_type_id, CONCAT(item_type_id), 4, 'Y', '0', NOW() FROM erp_md_item_type WHERE item_type_code = 'RAW' AND tenant_id = '000000';
|
|
|
|
-- 零部件子分类
|
|
INSERT INTO `erp_md_item_type` (`tenant_id`, `item_type_code`, `item_type_name`, `parent_type_id`, `ancestors`, `order_num`, `enable_flag`, `del_flag`, `create_time`)
|
|
SELECT '000000', 'PARTS_ELEC', '电子元器件', item_type_id, CONCAT(item_type_id), 1, 'Y', '0', NOW() FROM erp_md_item_type WHERE item_type_code = 'PARTS' AND tenant_id = '000000';
|
|
|
|
INSERT INTO `erp_md_item_type` (`tenant_id`, `item_type_code`, `item_type_name`, `parent_type_id`, `ancestors`, `order_num`, `enable_flag`, `del_flag`, `create_time`)
|
|
SELECT '000000', 'PARTS_MECH', '机械部件', item_type_id, CONCAT(item_type_id), 2, 'Y', '0', NOW() FROM erp_md_item_type WHERE item_type_code = 'PARTS' AND tenant_id = '000000';
|
|
|
|
INSERT INTO `erp_md_item_type` (`tenant_id`, `item_type_code`, `item_type_name`, `parent_type_id`, `ancestors`, `order_num`, `enable_flag`, `del_flag`, `create_time`)
|
|
SELECT '000000', 'PARTS_HARDWARE', '五金件', item_type_id, CONCAT(item_type_id), 3, 'Y', '0', NOW() FROM erp_md_item_type WHERE item_type_code = 'PARTS' AND tenant_id = '000000';
|
|
|
|
-- =====================================================
|
|
-- 4. 默认仓库数据
|
|
-- =====================================================
|
|
|
|
INSERT INTO `erp_wm_warehouse` (`tenant_id`, `warehouse_code`, `warehouse_name`, `warehouse_type`, `location`, `charge`, `enable_flag`, `del_flag`, `create_time`) VALUES
|
|
('000000', 'WH_RAW', '原材料仓', 'RAW', 'A区', '张三', 'Y', '0', NOW()),
|
|
('000000', 'WH_SEMI', '半成品仓', 'SEMI', 'B区', '李四', 'Y', '0', NOW()),
|
|
('000000', 'WH_FINISHED', '成品仓', 'FINISHED', 'C区', '王五', 'Y', '0', NOW()),
|
|
('000000', 'WH_DEFECT', '不良品仓', 'DEFECT', 'D区', '赵六', 'Y', '0', NOW());
|
|
|
|
-- =====================================================
|
|
-- 5. 系统字典类型表 (如需要)
|
|
-- =====================================================
|
|
|
|
-- 如果系统有字典表,可以在此添加字典数据
|
|
-- 以下为示例结构
|
|
|
|
/*
|
|
-- 字典类型表
|
|
CREATE TABLE IF NOT EXISTS `erp_sys_dict_type` (
|
|
`dict_id` bigint NOT NULL AUTO_INCREMENT,
|
|
`dict_name` varchar(100) NOT NULL COMMENT '字典名称',
|
|
`dict_type` varchar(100) NOT NULL COMMENT '字典类型',
|
|
`status` char(1) DEFAULT '0' COMMENT '状态',
|
|
`create_time` datetime DEFAULT NULL,
|
|
PRIMARY KEY (`dict_id`),
|
|
UNIQUE KEY `dict_type` (`dict_type`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='字典类型表';
|
|
|
|
-- 字典数据表
|
|
CREATE TABLE IF NOT EXISTS `erp_sys_dict_data` (
|
|
`dict_code` bigint NOT NULL AUTO_INCREMENT,
|
|
`dict_sort` int DEFAULT 0 COMMENT '排序',
|
|
`dict_label` varchar(100) NOT NULL COMMENT '字典标签',
|
|
`dict_value` varchar(100) NOT NULL COMMENT '字典值',
|
|
`dict_type` varchar(100) NOT NULL COMMENT '字典类型',
|
|
`css_class` varchar(100) DEFAULT NULL COMMENT '样式',
|
|
`list_class` varchar(100) DEFAULT NULL COMMENT '表格样式',
|
|
`is_default` char(1) DEFAULT 'N' COMMENT '默认',
|
|
`status` char(1) DEFAULT '0' COMMENT '状态',
|
|
`create_time` datetime DEFAULT NULL,
|
|
PRIMARY KEY (`dict_code`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='字典数据表';
|
|
|
|
-- 字典数据: 单据状态
|
|
INSERT INTO `erp_sys_dict_type` VALUES (1, '单据状态', 'doc_status', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (1, 1, '开立', 'DRAFT', 'doc_status', NULL, 'primary', 'Y', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (2, 2, '已提交', 'SUBMITTED', 'doc_status', NULL, 'warning', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (3, 3, '已审核', 'APPROVED', 'doc_status', NULL, 'success', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (4, 4, '已驳回', 'REJECTED', 'doc_status', NULL, 'danger', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (5, 5, '已关闭', 'CLOSED', 'doc_status', NULL, 'info', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (6, 6, '已取消', 'CANCELLED', 'doc_status', NULL, 'info', 'N', '0', NOW());
|
|
|
|
-- 字典数据: 业务状态
|
|
INSERT INTO `erp_sys_dict_type` VALUES (2, '业务状态', 'business_status', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (10, 1, '正常', 'NORMAL', 'business_status', NULL, 'success', 'Y', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (11, 2, '暂停', 'PAUSE', 'business_status', NULL, 'warning', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (12, 3, '取消', 'CANCEL', 'business_status', NULL, 'danger', 'N', '0', NOW());
|
|
|
|
-- 字典数据: 供应方式
|
|
INSERT INTO `erp_sys_dict_type` VALUES (3, '供应方式', 'supply_type', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (20, 1, '采购', 'PURCHASE', 'supply_type', NULL, 'primary', 'Y', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (21, 2, '自制', 'SELF_MADE', 'supply_type', NULL, 'success', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (22, 3, '委外', 'OUTSOURCE', 'supply_type', NULL, 'warning', 'N', '0', NOW());
|
|
|
|
-- 字典数据: 客户等级
|
|
INSERT INTO `erp_sys_dict_type` VALUES (4, '客户等级', 'client_level', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (30, 1, 'A级', 'A', 'client_level', NULL, 'danger', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (31, 2, 'B级', 'B', 'client_level', NULL, 'warning', 'Y', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (32, 3, 'C级', 'C', 'client_level', NULL, 'primary', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (33, 4, 'D级', 'D', 'client_level', NULL, 'info', 'N', '0', NOW());
|
|
|
|
-- 字典数据: 采购业务类型
|
|
INSERT INTO `erp_sys_dict_type` VALUES (5, '采购业务类型', 'po_business_type', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (40, 1, '原材料', 'RAW_MATERIAL', 'po_business_type', NULL, 'primary', 'Y', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (41, 2, '零部件', 'PARTS', 'po_business_type', NULL, 'success', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (42, 3, '装配件', 'ASSEMBLY', 'po_business_type', NULL, 'warning', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (43, 4, '成品', 'FINISHED', 'po_business_type', NULL, 'danger', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (44, 5, '五金件', 'HARDWARE', 'po_business_type', NULL, 'info', 'N', '0', NOW());
|
|
INSERT INTO `erp_sys_dict_data` VALUES (45, 6, '包装物', 'PACKAGING', 'po_business_type', NULL, 'info', 'N', '0', NOW());
|
|
*/
|
|
|
|
-- =====================================================
|
|
-- 6. 示例物料数据 (可选)
|
|
-- =====================================================
|
|
|
|
/*
|
|
-- 示例产品物料
|
|
INSERT INTO `erp_md_item` (`tenant_id`, `item_code`, `item_name`, `specification`, `unit_of_measure`, `item_type_code`, `item_type_name`, `item_or_product`, `enable_flag`, `del_flag`, `create_time`) VALUES
|
|
('000000', 'P001', '产品A', '100*100*50', '套', 'FINISHED', '成品', 'PRODUCT', 'Y', '0', NOW()),
|
|
('000000', 'P002', '产品B', '200*150*80', '套', 'FINISHED', '成品', 'PRODUCT', 'Y', '0', NOW());
|
|
|
|
-- 示例原材料
|
|
INSERT INTO `erp_md_item` (`tenant_id`, `item_code`, `item_name`, `specification`, `unit_of_measure`, `item_type_code`, `item_type_name`, `item_or_product`, `enable_flag`, `del_flag`, `create_time`) VALUES
|
|
('000000', 'M001', '钢板', '2mm厚', '张', 'RAW_STEEL', '钢材', 'ITEM', 'Y', '0', NOW()),
|
|
('000000', 'M002', '铝板', '3mm厚', '张', 'RAW_ALUMINUM', '铝材', 'ITEM', 'Y', '0', NOW()),
|
|
('000000', 'M003', '螺丝', 'M6*20', '个', 'PARTS_HARDWARE', '五金件', 'ITEM', 'Y', '0', NOW()),
|
|
('000000', 'M004', '螺母', 'M6', '个', 'PARTS_HARDWARE', '五金件', 'ITEM', 'Y', '0', NOW());
|
|
*/
|
|
|
|
-- =====================================================
|
|
-- 7. 示例客户数据 (可选)
|
|
-- =====================================================
|
|
|
|
/*
|
|
-- 客户数据已合并到 md_client 表,使用基础数据模块的客户管理功能
|
|
INSERT INTO `md_client` (`tenant_id`, `client_code`, `client_name`, `client_nick`, `client_level`, `address`, `tel`, `contact1`, `contact1_tel`, `enable_flag`, `del_flag`, `create_time`) VALUES
|
|
('000000', 'C001', '深圳科技有限公司', '深圳科技', 'A', '深圳市南山区科技园', '0755-12345678', '张经理', '13800001111', 'Y', '0', NOW()),
|
|
('000000', 'C002', '广州制造有限公司', '广州制造', 'B', '广州市天河区工业区', '020-87654321', '李总', '13900002222', 'Y', '0', NOW()),
|
|
('000000', 'C003', '东莞贸易有限公司', '东莞贸易', 'B', '东莞市虎门镇商业中心', '0769-55556666', '王总', '13700003333', 'Y', '0', NOW());
|
|
*/
|
|
|
|
-- =====================================================
|
|
-- 8. 示例供应商数据 (可选)
|
|
-- =====================================================
|
|
|
|
/*
|
|
INSERT INTO `erp_po_supplier` (`tenant_id`, `supplier_code`, `supplier_name`, `supplier_nick`, `supplier_level`, `address`, `tel`, `contact1`, `contact1_tel`, `enable_flag`, `del_flag`, `create_time`) VALUES
|
|
('000000', 'S001', '佛山钢材供应商', '佛山钢材', 'A', '佛山市顺德区钢材市场', '0757-11112222', '陈经理', '13600001111', 'Y', '0', NOW()),
|
|
('000000', 'S002', '中山五金供应商', '中山五金', 'B', '中山市小榄镇五金城', '0760-33334444', '林经理', '13500002222', 'Y', '0', NOW()),
|
|
('000000', 'S003', '惠州塑料供应商', '惠州塑料', 'B', '惠州市博罗县工业区', '0752-55556666', '黄经理', '13400003333', 'Y', '0', NOW());
|
|
*/
|
|
|
|
-- =====================================================
|
|
-- 完成
|
|
-- =====================================================
|