CREATE TABLE `rolling_plan` (
  `plan_id` bigint NOT NULL AUTO_INCREMENT COMMENT '序号',
  `plan_number` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '滚动计划号',
  `machine_code` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '整机编码',
  `plan_year` int NOT NULL COMMENT '年度',
  `version_week` varchar(10) COLLATE utf8mb4_general_ci NOT NULL COMMENT '版本周次',
  `production_mode` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '生产方式',
  `status` char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '状态（0草稿 1确认 2关闭）',
  `sales_area_code` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '销售区域编码',
  `country_code` char(2) COLLATE utf8mb4_general_ci NOT NULL COMMENT '国家编码',
  `sales_coordinator` varchar(64) COLLATE utf8mb4_general_ci NOT NULL COMMENT '销售协调',
  `customer_name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '客户名称',
  `production_version` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '生产版本',
  `brand_code` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '品牌编码',
  `sales_model` varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '销售型号',
  `production_base` varchar(64) COLLATE utf8mb4_general_ci NOT NULL COMMENT '生产地',
  `is_zero_execution` char(1) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '是否执行0号（0否 1是）',
  `schedule_time` datetime DEFAULT NULL COMMENT '排定时间',
  `last_adjust_time` datetime DEFAULT NULL COMMENT '上版意向调整时间',
  `adjust_time` datetime NOT NULL COMMENT '意向调整时间',
  `last_week_qty` int DEFAULT '0' COMMENT '上周数量',
  `current_week_qty` int NOT NULL COMMENT '本周数量',
  `qty_difference` int DEFAULT '0' COMMENT '差异',
  `order_stage` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '订单阶段',
  `order_type` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '订单类别',
  `packing_method` varchar(64) COLLATE utf8mb4_general_ci NOT NULL COMMENT '出口包装方式',
  `plan_sequence` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '计划序号',
  `is_first_order` char(1) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '是否首单（0否 1是）',
  `is_direct_delivery` char(1) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '是否直发（0否 1是）',
  `screen_requirement` varchar(200) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '屏要求',
  `panel_manufacturer` varchar(64) COLLATE utf8mb4_general_ci NOT NULL COMMENT '面板厂家',
  `panel_requirement` varchar(200) COLLATE utf8mb4_general_ci NOT NULL COMMENT '面板要求',
  `core_requirement` varchar(200) COLLATE utf8mb4_general_ci NOT NULL COMMENT '机芯要求',
  `product_category` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '产品类别',
  `product_size` varchar(32) COLLATE utf8mb4_general_ci NOT NULL COMMENT '尺寸',
  `remark` varchar(500) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注',
  `lock_week` varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '锁定周次',
  `create_by` varchar(64) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '创建者',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_by` varchar(64) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`plan_id`),
  UNIQUE KEY `uk_plan_number` (`plan_number`),
  KEY `idx_machine_code` (`machine_code`),
  KEY `idx_sales_area` (`sales_area_code`),
  KEY `idx_country` (`country_code`),
  KEY `idx_customer` (`customer_name`),
  KEY `idx_brand` (`brand_code`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='滚动计划表';

-------------------------------
-- 菜单 SQL
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('滚动计划管理', '1', '1', 'rollingPlan', 'system/rollingPlan/index', 1, 0, 'C', '0', '0', 'system:rollingPlan:list', 'time', 'admin', sysdate(), '', null, '滚动计划管理菜单');

-- 按钮父菜单ID
SELECT @parentId := LAST_INSERT_ID();

-- 按钮 SQL
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('滚动计划查询', @parentId, '1',  '#', '', 1, 0, 'F', '0', '0', 'system:rollingPlan:query',        '#', 'admin', sysdate(), '', null, '');

insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('滚动计划新增', @parentId, '2',  '#', '', 1, 0, 'F', '0', '0', 'system:rollingPlan:add',          '#', 'admin', sysdate(), '', null, '');

insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('滚动计划修改', @parentId, '3',  '#', '', 1, 0, 'F', '0', '0', 'system:rollingPlan:edit',         '#', 'admin', sysdate(), '', null, '');

insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('滚动计划删除', @parentId, '4',  '#', '', 1, 0, 'F', '0', '0', 'system:rollingPlan:remove',       '#', 'admin', sysdate(), '', null, '');

insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('滚动计划导出', @parentId, '5',  '#', '', 1, 0, 'F', '0', '0', 'system:rollingPlan:export',       '#', 'admin', sysdate(), '', null, '');

-- 修改菜单权限标识
UPDATE sys_menu 
SET perms = REPLACE(perms, 'system:rollingPlan:', 'system:rolling-plan:') 
WHERE perms LIKE 'system:rollingPlan:%';