-- =============================================
-- MES 编码规则初始化脚本
-- 执行前请确保 mes_md_auto_code_rule 和 mes_md_auto_code_part 表已存在
-- =============================================

-- 清空现有数据（重新初始化时执行）
DELETE FROM mes_md_auto_code_part;
DELETE FROM mes_md_auto_code_rule;

-- =============================================
-- 1. 基础主数据编码规则
-- =============================================

-- 1.1 物料分类编码规则 (MD_ITEM_TYPE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (1, 'MD_ITEM_TYPE_CODE', '物料分类编码', '用于生成物料分类编码', 10, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (1, 1, 3, 3, 'ITC', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (1, 2, 4, 4, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 1.2 物料编码规则 (MD_ITEM_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (2, 'MD_ITEM_CODE', '物料编码', '用于生成物料编码', 20, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (2, 1, 3, 5, 'ITEM_', NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (2, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (2, 3, 4, 4, NULL, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 1.3 供应商编码规则 (MD_VENDOR_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (3, 'MD_VENDOR_CODE', '供应商编码', '用于生成供应商编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (3, 1, 3, 3, 'VDR', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (3, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 1.4 客户编码规则 (MD_CLIENT_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (4, 'MD_CLIENT_CODE', '客户编码', '用于生成客户编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (4, 1, 3, 3, 'CLT', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (4, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 1.5 工作站编码规则 (MD_WORKSTATION_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (5, 'MD_WORKSTATION_CODE', '工作站编码', '用于生成工作站编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (5, 1, 3, 3, 'WKS', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (5, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 1.6 车间编码规则 (MD_WORKSHOP_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (6, 'MD_WORKSHOP_CODE', '车间编码', '用于生成车间编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (6, 1, 3, 3, 'WSP', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (6, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 1.7 工具类型编码规则 (TM_TOOL_TYPE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (7, 'TM_TOOL_TYPE_CODE', '工具类型编码', '用于生成工具类型编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (7, 1, 3, 3, 'TTL', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (7, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- =============================================
-- 2. 仓库管理编码规则
-- =============================================

-- 2.1 仓库编码 (WM_WAREHOUSE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (8, 'WM_WAREHOUSE_CODE', '仓库编码', '用于生成仓库编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (8, 1, 3, 3, 'WHS', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (8, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 2.2 库区编码 (WM_LOCATION_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (9, 'WM_LOCATION_CODE', '库区编码', '用于生成库区编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (9, 1, 3, 3, 'LOC', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (9, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 2.3 库位编码 (WM_AREA_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (10, 'WM_AREA_CODE', '库位编码', '用于生成库位编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (10, 1, 3, 3, 'ARA', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (10, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 2.4 批次编码 (WM_BATCH_CODE) - 按天循环
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (11, 'WM_BATCH_CODE', '批次编码', '用于生成批次编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (11, 1, 3, 1, 'B', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (11, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (11, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.5 SN码 (WM_SN_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (12, 'WM_SN_CODE', 'SN码', '用于生成SN码', 20, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (12, 1, 3, 3, 'SN_', NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (12, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (12, 3, 4, 6, NULL, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 2.6 装箱单编码 (WM_PACKAGE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (13, 'WM_PACKAGE_CODE', '装箱单编码', '用于生成装箱单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, remark, creator, create_time, updater, update_time, deleted)
VALUES (13, 1, 3, 4, 'PKG_', NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, remark, creator, create_time, updater, update_time, deleted)
VALUES (13, 2, 2, 8, NULL, 'yyyyMMdd', '日期', '1', NOW(), '1', NOW(), b'0');

-- 2.7 到货通知单编码 (WM_ARRIVAL_NOTICE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (14, 'WM_ARRIVAL_NOTICE_CODE', '到货通知单编码', '用于生成到货通知单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (14, 1, 3, 3, 'AN_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (14, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (14, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.8 采购入库单编码 (WM_ITEM_RECEIPT_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (15, 'WM_ITEM_RECEIPT_CODE', '采购入库单编码', '用于生成采购入库单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (15, 1, 3, 3, 'IR_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (15, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (15, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.9 采购退货单编码 (WM_RETURN_VENDOR_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (16, 'WM_RETURN_VENDOR_CODE', '采购退货单编码', '用于生成采购退货单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (16, 1, 3, 3, 'RV_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (16, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (16, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.10 生产退料单编码 (WM_RETURN_ISSUE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (17, 'WM_RETURN_ISSUE_CODE', '生产退料单编码', '用于生成生产退料单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (17, 1, 3, 3, 'RI_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (17, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (17, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.11 销售出库单编码 (WM_PRODUCT_SALES_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (18, 'WM_PRODUCT_SALES_CODE', '销售出库单编码', '用于生成销售出库单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (18, 1, 3, 3, 'SO_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (18, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (18, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.12 发货通知单编码 (WM_SALES_NOTICE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (19, 'WM_SALES_NOTICE_CODE', '发货通知单编码', '用于生成发货通知单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (19, 1, 3, 3, 'SN_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (19, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (19, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.13 销售退货单编码 (WM_RETURN_SALES_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (20, 'WM_RETURN_SALES_CODE', '销售退货单编码', '用于生成销售退货单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (20, 1, 3, 3, 'RS_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (20, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (20, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.14 杂项入库单编码 (WM_MISC_RECEIPT_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (21, 'WM_MISC_RECEIPT_CODE', '杂项入库单编码', '用于生成杂项入库单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (21, 1, 3, 3, 'MR_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (21, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (21, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.15 杂项出库单编码 (WM_MISC_ISSUE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (22, 'WM_MISC_ISSUE_CODE', '杂项出库单编码', '用于生成杂项出库单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (22, 1, 3, 3, 'MI_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (22, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (22, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.16 盘点方案编码 (WM_STOCK_TAKING_PLAN_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (23, 'WM_STOCK_TAKING_PLAN_CODE', '盘点方案编码', '用于生成盘点方案编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (23, 1, 3, 3, 'SP_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (23, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (23, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.17 盘点任务编码 (WM_STOCK_TAKING_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (24, 'WM_STOCK_TAKING_CODE', '盘点任务编码', '用于生成盘点任务编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (24, 1, 3, 3, 'ST_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (24, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (24, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.18 转移调拨单编码 (TRANSFER_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (25, 'TRANSFER_CODE', '转移调拨单编码', '用于生成转移调拨单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (25, 1, 3, 3, 'TR_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (25, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (25, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.19 外协发料单编码 (WM_OUTSOURCE_ISSUE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (26, 'WM_OUTSOURCE_ISSUE_CODE', '外协发料单编码', '用于生成外协发料单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (26, 1, 3, 3, 'OI_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (26, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (26, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 2.20 外协入库单编码 (WM_OUTSOURCE_RECEIPT_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (27, 'WM_OUTSOURCE_RECEIPT_CODE', '外协入库单编码', '用于生成外协入库单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (27, 1, 3, 3, 'OR_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (27, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (27, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- =============================================
-- 3. 生产管理编码规则
-- =============================================

-- 3.1 生产工单编码 (PRO_WORK_ORDER_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (28, 'PRO_WORK_ORDER_CODE', '生产工单编码', '用于生成生产工单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (28, 1, 3, 3, 'WO_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (28, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (28, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 3.2 生产任务编码 (PRO_TASK_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (29, 'PRO_TASK_CODE', '生产任务编码', '用于生成生产任务编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (29, 1, 3, 3, 'TK_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (29, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (29, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 3.3 生产报工单编码 (PRO_FEEDBACK_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (30, 'PRO_FEEDBACK_CODE', '生产报工单编码', '用于生成生产报工单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (30, 1, 3, 3, 'FB_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (30, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (30, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 3.4 工艺路线编码 (PRO_ROUTE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (31, 'PRO_ROUTE_CODE', '工艺路线编码', '用于生成工艺路线编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (31, 1, 3, 3, 'RT_', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (31, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- =============================================
-- 4. 质量管理编码规则
-- =============================================

-- 4.1 来料检验单编码 (QC_IQC_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (32, 'QC_IQC_CODE', '来料检验单编码', '用于生成来料检验单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (32, 1, 3, 4, 'IQC_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (32, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (32, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 4.2 过程检验单编码 (QC_IPQC_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (33, 'QC_IPQC_CODE', '过程检验单编码', '用于生成过程检验单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (33, 1, 3, 5, 'IPQC_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (33, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (33, 3, 4, 3, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 4.3 出货检验单编码 (QC_OQC_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (34, 'QC_OQC_CODE', '出货检验单编码', '用于生成出货检验单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (34, 1, 3, 5, 'OQC_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (34, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (34, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 4.4 退货检验单编码 (QC_RQC_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (35, 'QC_RQC_CODE', '退货检验单编码', '用于生成退货检验单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (35, 1, 3, 4, 'RQC_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (35, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (35, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- 4.5 缺陷类型编码 (QC_DEFECT_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (36, 'QC_DEFECT_CODE', '缺陷类型编码', '用于生成缺陷类型编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (36, 1, 3, 3, 'DFC', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (36, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 4.6 样品检验结果编码 (QC_INDICATOR_RESULT_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (37, 'QC_INDICATOR_RESULT_CODE', '样品检验结果编码', '用于生成样品检验结果编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (37, 1, 3, 4, 'QIR_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (37, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (37, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- =============================================
-- 5. 设备管理编码规则
-- =============================================

-- 5.1 设备编码 (DV_MACHINERY_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (38, 'DV_MACHINERY_CODE', '设备编码', '用于生成设备编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (38, 1, 3, 3, 'MC_', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (38, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 5.2 设备类型编码 (DV_MACHINERY_TYPE_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (39, 'DV_MACHINERY_TYPE_CODE', '设备类型编码', '用于生成设备类型编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (39, 1, 3, 3, 'MCT', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (39, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 5.3 点检保养项目编码 (DV_SUBJECT_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (40, 'DV_SUBJECT_CODE', '点检保养项目编码', '用于生成点检保养项目编码', 12, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (40, 1, 3, 3, 'SBJ', NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, serial_start_no, serial_step, cycle_flag, remark, creator, create_time, updater, update_time, deleted)
VALUES (40, 2, 4, 6, NULL, 1, 1, b'0', '流水号', '1', NOW(), '1', NOW(), b'0');

-- 5.4 维修单编码 (DV_REPAIR_CODE)
INSERT INTO mes_md_auto_code_rule (id, code, name, description, max_length, padded, status, creator, create_time, updater, update_time, deleted)
VALUES (41, 'DV_REPAIR_CODE', '维修单编码', '用于生成维修单编码', 16, b'0', 0, '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (41, 1, 3, 3, 'RP_', NULL, NULL, NULL, NULL, NULL, '固定前缀', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (41, 2, 2, 8, NULL, 'yyyyMMdd', NULL, NULL, NULL, NULL, '日期', '1', NOW(), '1', NOW(), b'0');

INSERT INTO mes_md_auto_code_part (rule_id, sort, type, length, fix_character, date_format, serial_start_no, serial_step, cycle_flag, cycle_method, remark, creator, create_time, updater, update_time, deleted)
VALUES (41, 3, 4, 4, NULL, NULL, 1, 1, b'1', 3, '流水号-按天循环', '1', NOW(), '1', NOW(), b'0');

-- =============================================
-- 执行完成提示
-- =============================================
SELECT 'MES 编码规则初始化完成！' AS result;
SELECT COUNT(*) AS rule_count FROM mes_md_auto_code_rule WHERE deleted = 0;
SELECT COUNT(*) AS part_count FROM mes_md_auto_code_part WHERE deleted = 0;