USE jiaheng_erp;

SET NAMES utf8mb4;

-- 已建库后补充字段注释脚本
-- 执行前请先在测试库验证

ALTER TABLE sys_department
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN dept_code VARCHAR(50) NOT NULL COMMENT '部门编码',
  MODIFY COLUMN dept_name VARCHAR(100) NOT NULL COMMENT '部门名称',
  MODIFY COLUMN parent_id BIGINT NULL COMMENT '上级ID',
  MODIFY COLUMN dept_type VARCHAR(32) NOT NULL COMMENT '部门类型：ADMIN/SALES/PURCHASE/WAREHOUSE/PRODUCTION/FINANCE/EQUIPMENT',
  MODIFY COLUMN manager_name VARCHAR(100) NULL COMMENT '负责人姓名',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN sort_no INT NOT NULL DEFAULT 0 COMMENT '排序号',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE hr_employee
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN employee_code VARCHAR(50) NOT NULL COMMENT '员工编码',
  MODIFY COLUMN employee_name VARCHAR(100) NOT NULL COMMENT '员工姓名',
  MODIFY COLUMN dept_id BIGINT NOT NULL COMMENT '部门ID',
  MODIFY COLUMN mobile VARCHAR(30) NULL COMMENT '手机号',
  MODIFY COLUMN gender VARCHAR(16) NULL COMMENT '性别',
  MODIFY COLUMN hire_date DATE NULL COMMENT '入职日期',
  MODIFY COLUMN job_title VARCHAR(100) NULL COMMENT '岗位名称',
  MODIFY COLUMN shift_code VARCHAR(32) NULL COMMENT '班次编码',
  MODIFY COLUMN manager_employee_id BIGINT NULL COMMENT '上级员工ID',
  MODIFY COLUMN is_operator TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否操作工',
  MODIFY COLUMN is_workshop_staff TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否车间人员',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE sys_role
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN role_code VARCHAR(50) NOT NULL COMMENT '角色编码',
  MODIFY COLUMN role_name VARCHAR(100) NOT NULL COMMENT '角色名称',
  MODIFY COLUMN role_scope VARCHAR(32) NOT NULL DEFAULT 'SYSTEM' COMMENT '角色范围',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE sys_permission
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN permission_code VARCHAR(100) NOT NULL COMMENT '权限编码',
  MODIFY COLUMN permission_name VARCHAR(100) NOT NULL COMMENT '权限名称',
  MODIFY COLUMN module_code VARCHAR(50) NOT NULL COMMENT '模块编码',
  MODIFY COLUMN action_code VARCHAR(50) NOT NULL COMMENT '操作编码',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE sys_role_permission
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN role_id BIGINT NOT NULL COMMENT '角色ID',
  MODIFY COLUMN permission_id BIGINT NOT NULL COMMENT '权限ID',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间';

ALTER TABLE sys_user
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN username VARCHAR(50) NOT NULL COMMENT '登录账号',
  MODIFY COLUMN password_hash VARCHAR(255) NOT NULL COMMENT '密码哈希',
  MODIFY COLUMN employee_id BIGINT NOT NULL COMMENT '员工ID',
  MODIFY COLUMN dept_id BIGINT NOT NULL COMMENT '部门ID',
  MODIFY COLUMN nickname VARCHAR(100) NULL COMMENT '昵称',
  MODIFY COLUMN email VARCHAR(100) NULL COMMENT '邮箱',
  MODIFY COLUMN is_super_admin TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否超级管理员',
  MODIFY COLUMN last_login_at DATETIME NULL COMMENT '最后登录时间',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE sys_user_role
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN user_id BIGINT NOT NULL COMMENT '用户ID',
  MODIFY COLUMN role_id BIGINT NOT NULL COMMENT '角色ID',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间';

ALTER TABLE md_unit
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN unit_code VARCHAR(50) NOT NULL COMMENT '单位编码',
  MODIFY COLUMN unit_name VARCHAR(50) NOT NULL COMMENT '单位名称',
  MODIFY COLUMN precision_digits INT NOT NULL DEFAULT 3 COMMENT '小数精度位数',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_customer
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN customer_code VARCHAR(50) NOT NULL COMMENT '客户编码',
  MODIFY COLUMN customer_name VARCHAR(200) NOT NULL COMMENT '客户名称',
  MODIFY COLUMN short_name VARCHAR(100) NULL COMMENT '简称',
  MODIFY COLUMN contact_name VARCHAR(100) NULL COMMENT '联系人',
  MODIFY COLUMN contact_phone VARCHAR(50) NULL COMMENT '联系电话',
  MODIFY COLUMN address VARCHAR(255) NULL COMMENT '地址',
  MODIFY COLUMN tax_no VARCHAR(100) NULL COMMENT '税号',
  MODIFY COLUMN credit_days INT NOT NULL DEFAULT 0 COMMENT '账期天数',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_supplier
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN supplier_code VARCHAR(50) NOT NULL COMMENT '供应商编码',
  MODIFY COLUMN supplier_name VARCHAR(200) NOT NULL COMMENT '供应商名称',
  MODIFY COLUMN short_name VARCHAR(100) NULL COMMENT '简称',
  MODIFY COLUMN contact_name VARCHAR(100) NULL COMMENT '联系人',
  MODIFY COLUMN contact_phone VARCHAR(50) NULL COMMENT '联系电话',
  MODIFY COLUMN address VARCHAR(255) NULL COMMENT '地址',
  MODIFY COLUMN lead_time_days INT NOT NULL DEFAULT 0 COMMENT '采购提前期天数',
  MODIFY COLUMN default_tax_rate DECIMAL(8,4) NOT NULL DEFAULT 0 COMMENT '默认税率',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_item_category
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN category_code VARCHAR(50) NOT NULL COMMENT '分类编码',
  MODIFY COLUMN category_name VARCHAR(100) NOT NULL COMMENT '分类名称',
  MODIFY COLUMN parent_id BIGINT NULL COMMENT '上级ID',
  MODIFY COLUMN item_type VARCHAR(32) NOT NULL COMMENT '物料类型',
  MODIFY COLUMN sort_no INT NOT NULL DEFAULT 0 COMMENT '排序号',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_item
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN item_code VARCHAR(50) NOT NULL COMMENT '物料编码',
  MODIFY COLUMN item_name VARCHAR(200) NOT NULL COMMENT '物料名称',
  MODIFY COLUMN item_type VARCHAR(32) NOT NULL COMMENT '物料类型：RAW_MATERIAL/FINISHED_GOOD/SEMI_FINISHED/SCRAP/SPARE_PART',
  MODIFY COLUMN category_id BIGINT NULL COMMENT '分类ID',
  MODIFY COLUMN specification VARCHAR(200) NULL COMMENT '规格',
  MODIFY COLUMN model_no VARCHAR(100) NULL COMMENT '型号',
  MODIFY COLUMN material_type VARCHAR(100) NULL COMMENT '材料类型',
  MODIFY COLUMN material_grade VARCHAR(100) NULL COMMENT '材质牌号',
  MODIFY COLUMN length_mm DECIMAL(18,3) NOT NULL DEFAULT 0 COMMENT '长度(mm)',
  MODIFY COLUMN width_mm DECIMAL(18,3) NOT NULL DEFAULT 0 COMMENT '宽度(mm)',
  MODIFY COLUMN thickness_mm DECIMAL(18,3) NOT NULL DEFAULT 0 COMMENT '厚度(mm)',
  MODIFY COLUMN density_kg_m3 DECIMAL(18,3) NOT NULL DEFAULT 0 COMMENT '密度(kg/m3)',
  MODIFY COLUMN theoretical_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '理论重量(kg)',
  MODIFY COLUMN unit_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '实际管理用单件或单批重量',
  MODIFY COLUMN sales_unit_id BIGINT NULL COMMENT '销售单位ID',
  MODIFY COLUMN stock_unit_id BIGINT NULL COMMENT '库存单位ID',
  MODIFY COLUMN purchase_unit_id BIGINT NULL COMMENT '采购单位ID',
  MODIFY COLUMN safety_stock_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '安全库存数量',
  MODIFY COLUMN safety_stock_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '安全库存重量(kg)',
  MODIFY COLUMN scrap_sale_price DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '废料销售单价',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_material
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN item_id BIGINT NOT NULL COMMENT '物料ID',
  MODIFY COLUMN default_supplier_id BIGINT NULL COMMENT '默认供应商ID',
  MODIFY COLUMN purchase_calc_mode VARCHAR(32) NOT NULL DEFAULT 'BY_WEIGHT' COMMENT '采购计算方式',
  MODIFY COLUMN min_purchase_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '最小采购数量',
  MODIFY COLUMN purchase_multiple_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '采购倍数数量',
  MODIFY COLUMN purchase_multiple_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '采购倍数重量(kg)',
  MODIFY COLUMN lead_time_days INT NOT NULL DEFAULT 0 COMMENT '采购提前期天数',
  MODIFY COLUMN quality_rule VARCHAR(255) NULL COMMENT '质检规则',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_product
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN item_id BIGINT NOT NULL COMMENT '物料ID',
  MODIFY COLUMN drawing_no VARCHAR(100) NULL COMMENT '图号',
  MODIFY COLUMN product_family VARCHAR(100) NULL COMMENT '产品系列',
  MODIFY COLUMN version_no VARCHAR(50) NOT NULL DEFAULT 'V1.0' COMMENT '版本号',
  MODIFY COLUMN standard_output_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '标准产出数量',
  MODIFY COLUMN allowed_scrap_rate DECIMAL(8,4) NOT NULL DEFAULT 0 COMMENT '允许报废率',
  MODIFY COLUMN quality_standard VARCHAR(255) NULL COMMENT '质量标准',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_process
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN process_code VARCHAR(50) NOT NULL COMMENT '工序编码',
  MODIFY COLUMN process_name VARCHAR(100) NOT NULL COMMENT '工序名称',
  MODIFY COLUMN process_type VARCHAR(50) NOT NULL COMMENT '工序类型',
  MODIFY COLUMN is_report_required TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否必须报工',
  MODIFY COLUMN is_quality_gate TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否质量关卡',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_work_center
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN center_code VARCHAR(50) NOT NULL COMMENT '工作中心编码',
  MODIFY COLUMN center_name VARCHAR(100) NOT NULL COMMENT '工作中心名称',
  MODIFY COLUMN dept_id BIGINT NOT NULL COMMENT '部门ID',
  MODIFY COLUMN center_type VARCHAR(50) NOT NULL COMMENT '工作中心类型',
  MODIFY COLUMN shift_pattern VARCHAR(50) NULL COMMENT '班制',
  MODIFY COLUMN capacity_hours_per_day DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '日产能工时',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_process_route
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN route_code VARCHAR(50) NOT NULL COMMENT '工艺路线编码',
  MODIFY COLUMN route_name VARCHAR(100) NOT NULL COMMENT '工艺路线名称',
  MODIFY COLUMN product_item_id BIGINT NOT NULL COMMENT '产品物料ID',
  MODIFY COLUMN version_no VARCHAR(50) NOT NULL DEFAULT 'V1.0' COMMENT '版本号',
  MODIFY COLUMN is_default TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否默认',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN effective_date DATE NULL COMMENT '生效日期',
  MODIFY COLUMN expire_date DATE NULL COMMENT '失效日期',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_process_route_operation
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN route_id BIGINT NOT NULL COMMENT '工艺路线ID',
  MODIFY COLUMN seq_no INT NOT NULL COMMENT '序号',
  MODIFY COLUMN process_id BIGINT NOT NULL COMMENT '工序ID',
  MODIFY COLUMN work_center_id BIGINT NOT NULL COMMENT '工作中心ID',
  MODIFY COLUMN operation_name VARCHAR(100) NOT NULL COMMENT '工序名称',
  MODIFY COLUMN std_setup_minutes DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '标准准备时长(分钟)',
  MODIFY COLUMN std_cycle_seconds DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '标准节拍(秒/件)',
  MODIFY COLUMN std_labor_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '标准人工成本',
  MODIFY COLUMN std_machine_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '标准设备成本',
  MODIFY COLUMN std_outsource_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '标准委外成本',
  MODIFY COLUMN allowed_scrap_rate DECIMAL(8,4) NOT NULL DEFAULT 0 COMMENT '允许报废率',
  MODIFY COLUMN report_required TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否要求报工',
  MODIFY COLUMN is_key_operation TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否关键工序',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_bom
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN bom_code VARCHAR(50) NOT NULL COMMENT 'BOM编码',
  MODIFY COLUMN product_item_id BIGINT NOT NULL COMMENT '产品物料ID',
  MODIFY COLUMN version_no VARCHAR(50) NOT NULL DEFAULT 'V1.0' COMMENT '版本号',
  MODIFY COLUMN is_default TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否默认',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN effective_date DATE NULL COMMENT '生效日期',
  MODIFY COLUMN expire_date DATE NULL COMMENT '失效日期',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE md_bom_item
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN bom_id BIGINT NOT NULL COMMENT 'BOM ID',
  MODIFY COLUMN seq_no INT NOT NULL COMMENT '序号',
  MODIFY COLUMN material_item_id BIGINT NOT NULL COMMENT '原材料物料ID',
  MODIFY COLUMN usage_type VARCHAR(32) NOT NULL DEFAULT 'WEIGHT' COMMENT '用量类型：WEIGHT/FIXED_QTY',
  MODIFY COLUMN qty_per_piece DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '单件用量',
  MODIFY COLUMN net_weight_per_piece_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '单件净重(kg)',
  MODIFY COLUMN gross_weight_per_piece_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '单件毛重(kg)',
  MODIFY COLUMN loss_rate DECIMAL(8,4) NOT NULL DEFAULT 0 COMMENT '损耗率',
  MODIFY COLUMN issue_over_tolerance_rate DECIMAL(8,4) NOT NULL DEFAULT 0 COMMENT '领料超发容差率',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE em_equipment
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN equipment_code VARCHAR(50) NOT NULL COMMENT '设备编码',
  MODIFY COLUMN equipment_name VARCHAR(100) NOT NULL COMMENT '设备名称',
  MODIFY COLUMN category_name VARCHAR(100) NULL COMMENT '分类名称',
  MODIFY COLUMN work_center_id BIGINT NOT NULL COMMENT '工作中心ID',
  MODIFY COLUMN manufacturer VARCHAR(100) NULL COMMENT '制造商',
  MODIFY COLUMN model_no VARCHAR(100) NULL COMMENT '型号',
  MODIFY COLUMN install_date DATE NULL COMMENT '安装日期',
  MODIFY COLUMN rated_power_kw DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '额定功率(kW)',
  MODIFY COLUMN occupied_area_sqm DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '占用场地面积(平方米)',
  MODIFY COLUMN maintenance_cycle_hours DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '保养周期(小时)',
  MODIFY COLUMN last_maintenance_at DATETIME NULL COMMENT '上次保养时间',
  MODIFY COLUMN next_maintenance_at DATETIME NULL COMMENT '下次保养时间',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'IDLE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE em_maintenance_plan
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN plan_code VARCHAR(50) NOT NULL COMMENT '计划编码',
  MODIFY COLUMN equipment_id BIGINT NOT NULL COMMENT '设备ID',
  MODIFY COLUMN plan_name VARCHAR(100) NOT NULL COMMENT '计划名称',
  MODIFY COLUMN maintenance_type VARCHAR(32) NOT NULL COMMENT '保养类型',
  MODIFY COLUMN cycle_hours DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '周期小时数',
  MODIFY COLUMN cycle_days INT NOT NULL DEFAULT 0 COMMENT '周期天数',
  MODIFY COLUMN last_execute_at DATETIME NULL COMMENT '上次执行时间',
  MODIFY COLUMN next_execute_at DATETIME NULL COMMENT '下次执行时间',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE em_maintenance_order
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN order_no VARCHAR(50) NOT NULL COMMENT '单据号',
  MODIFY COLUMN equipment_id BIGINT NOT NULL COMMENT '设备ID',
  MODIFY COLUMN plan_id BIGINT NULL COMMENT '计划ID',
  MODIFY COLUMN maintenance_type VARCHAR(32) NOT NULL COMMENT '保养类型',
  MODIFY COLUMN start_time DATETIME NULL COMMENT '开始时间',
  MODIFY COLUMN end_time DATETIME NULL COMMENT '结束时间',
  MODIFY COLUMN downtime_minutes DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '停机时长(分钟)',
  MODIFY COLUMN owner_employee_id BIGINT NULL COMMENT '负责人员工ID',
  MODIFY COLUMN result_summary VARCHAR(255) NULL COMMENT '结果摘要',
  MODIFY COLUMN cost_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '成本金额',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'CREATED' COMMENT '状态',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE so_sales_order
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN order_no VARCHAR(50) NOT NULL COMMENT '单据号',
  MODIFY COLUMN customer_id BIGINT NOT NULL COMMENT '客户ID',
  MODIFY COLUMN order_date DATE NOT NULL COMMENT '订单日期',
  MODIFY COLUMN promised_date DATE NULL COMMENT '承诺交期',
  MODIFY COLUMN sales_employee_id BIGINT NULL COMMENT '销售员员工ID',
  MODIFY COLUMN delivery_address VARCHAR(255) NULL COMMENT '送货地址',
  MODIFY COLUMN tax_rate DECIMAL(8,4) NOT NULL DEFAULT 0 COMMENT '税率',
  MODIFY COLUMN total_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '总金额',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'DRAFT' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE so_sales_order_item
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN sales_order_id BIGINT NOT NULL COMMENT '订单ID',
  MODIFY COLUMN line_no INT NOT NULL COMMENT '行号',
  MODIFY COLUMN product_item_id BIGINT NOT NULL COMMENT '产品物料ID',
  MODIFY COLUMN customer_part_no VARCHAR(100) NULL COMMENT '客户料号',
  MODIFY COLUMN order_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '订单数量',
  MODIFY COLUMN delivered_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已发货数量',
  MODIFY COLUMN unit_price DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '单价',
  MODIFY COLUMN line_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '行金额',
  MODIFY COLUMN promised_date DATE NULL COMMENT '承诺交期',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'OPEN' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE mrp_material_demand
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN demand_no VARCHAR(50) NOT NULL COMMENT '需求单号',
  MODIFY COLUMN sales_order_item_id BIGINT NOT NULL COMMENT '订单明细ID',
  MODIFY COLUMN product_item_id BIGINT NOT NULL COMMENT '产品物料ID',
  MODIFY COLUMN material_item_id BIGINT NOT NULL COMMENT '原材料物料ID',
  MODIFY COLUMN bom_item_id BIGINT NOT NULL COMMENT 'BOM明细ID',
  MODIFY COLUMN order_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '订单数量',
  MODIFY COLUMN theoretical_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '理论重量(kg)',
  MODIFY COLUMN planned_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '计划重量(kg)',
  MODIFY COLUMN available_stock_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '可用库存重量(kg)',
  MODIFY COLUMN shortage_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '缺口重量(kg)',
  MODIFY COLUMN suggested_purchase_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '建议采购数量',
  MODIFY COLUMN suggested_purchase_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '建议采购重量(kg)',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'NEW' COMMENT '状态',
  MODIFY COLUMN generated_at DATETIME NULL COMMENT '生成时间',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE po_purchase_order
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN po_no VARCHAR(50) NOT NULL COMMENT '采购订单号',
  MODIFY COLUMN supplier_id BIGINT NOT NULL COMMENT 'SupplierID',
  MODIFY COLUMN order_date DATE NOT NULL COMMENT '订单日期',
  MODIFY COLUMN expected_date DATE NULL COMMENT '预计到货日期',
  MODIFY COLUMN purchaser_employee_id BIGINT NULL COMMENT '采购员员工ID',
  MODIFY COLUMN target_warehouse_type VARCHAR(32) NOT NULL DEFAULT 'RAW' COMMENT '目标仓库类型：RAW原材料库/AUX辅料库',
  MODIFY COLUMN tax_rate DECIMAL(8,4) NOT NULL DEFAULT 0 COMMENT '税率',
  MODIFY COLUMN total_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '总金额',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'DRAFT' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE po_purchase_order_item
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN purchase_order_id BIGINT NOT NULL COMMENT '采购订单ID',
  MODIFY COLUMN line_no INT NOT NULL COMMENT '行号',
  MODIFY COLUMN material_item_id BIGINT NOT NULL COMMENT '原材料物料ID',
  MODIFY COLUMN source_demand_id BIGINT NULL COMMENT '来源需求ID',
  MODIFY COLUMN order_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '订单数量',
  MODIFY COLUMN order_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '订单重量(kg)',
  MODIFY COLUMN received_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已收货数量',
  MODIFY COLUMN received_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已收货重量(kg)',
  MODIFY COLUMN unit_price DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '单价',
  MODIFY COLUMN line_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '行金额',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'OPEN' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE wh_warehouse
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN warehouse_code VARCHAR(50) NOT NULL COMMENT '仓库编码',
  MODIFY COLUMN warehouse_name VARCHAR(100) NOT NULL COMMENT '仓库名称',
  MODIFY COLUMN warehouse_type VARCHAR(32) NOT NULL COMMENT '仓库类型：RAW/SEMI/FINISHED/AUX/RETURN/SCRAP',
  MODIFY COLUMN manager_employee_id BIGINT NULL COMMENT '上级员工ID',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE wh_location
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN warehouse_id BIGINT NOT NULL COMMENT '仓库ID',
  MODIFY COLUMN location_code VARCHAR(50) NOT NULL COMMENT '库位编码',
  MODIFY COLUMN location_name VARCHAR(100) NOT NULL COMMENT '库位名称',
  MODIFY COLUMN zone_name VARCHAR(100) NULL COMMENT '库区名称',
  MODIFY COLUMN is_default TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否默认',
  MODIFY COLUMN is_locked TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否锁定',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE po_receipt
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN receipt_no VARCHAR(50) NOT NULL COMMENT '入库单号',
  MODIFY COLUMN purchase_order_id BIGINT NOT NULL COMMENT '采购订单ID',
  MODIFY COLUMN warehouse_id BIGINT NOT NULL COMMENT '仓库ID',
  MODIFY COLUMN receipt_date DATETIME NOT NULL COMMENT '收货日期',
  MODIFY COLUMN receiver_employee_id BIGINT NULL COMMENT '接收人员工ID',
  MODIFY COLUMN supplier_delivery_no VARCHAR(100) NULL COMMENT '供应商送货单号',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'DRAFT' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE po_receipt_item
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN receipt_id BIGINT NOT NULL COMMENT '单据ID',
  MODIFY COLUMN line_no INT NOT NULL COMMENT '行号',
  MODIFY COLUMN purchase_order_item_id BIGINT NOT NULL COMMENT '采购订单明细ID',
  MODIFY COLUMN material_item_id BIGINT NOT NULL COMMENT '原材料物料ID',
  MODIFY COLUMN location_id BIGINT NULL COMMENT '库位ID',
  MODIFY COLUMN lot_no VARCHAR(50) NOT NULL COMMENT '批次号',
  MODIFY COLUMN received_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已收货数量',
  MODIFY COLUMN received_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已收货重量(kg)',
  MODIFY COLUMN accepted_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '合格数量',
  MODIFY COLUMN accepted_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '合格重量(kg)',
  MODIFY COLUMN unit_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '单位成本',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'PENDING_QC' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE wh_stock_lot
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN lot_no VARCHAR(50) NOT NULL COMMENT '批次号',
  MODIFY COLUMN item_id BIGINT NOT NULL COMMENT '物料ID',
  MODIFY COLUMN warehouse_id BIGINT NOT NULL COMMENT '仓库ID',
  MODIFY COLUMN location_id BIGINT NULL COMMENT '库位ID',
  MODIFY COLUMN source_doc_type VARCHAR(32) NOT NULL COMMENT '来源单据类型',
  MODIFY COLUMN source_doc_id BIGINT NOT NULL COMMENT '来源单据ID',
  MODIFY COLUMN source_line_id BIGINT NULL COMMENT '来源单据行ID',
  MODIFY COLUMN inbound_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '入库数量',
  MODIFY COLUMN inbound_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '入库重量(kg)',
  MODIFY COLUMN remaining_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '剩余数量',
  MODIFY COLUMN remaining_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '剩余重量(kg)',
  MODIFY COLUMN locked_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '锁定数量',
  MODIFY COLUMN locked_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '锁定重量(kg)',
  MODIFY COLUMN unit_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '单位成本',
  MODIFY COLUMN production_date DATE NULL COMMENT '生产日期',
  MODIFY COLUMN expire_date DATE NULL COMMENT '失效日期',
  MODIFY COLUMN quality_status VARCHAR(32) NOT NULL DEFAULT 'PASS' COMMENT '质量状态',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'AVAILABLE' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE wh_stock_balance
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN item_id BIGINT NOT NULL COMMENT '物料ID',
  MODIFY COLUMN warehouse_id BIGINT NOT NULL COMMENT '仓库ID',
  MODIFY COLUMN location_id BIGINT NULL COMMENT '库位ID',
  MODIFY COLUMN qty_on_hand DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '现存数量',
  MODIFY COLUMN weight_on_hand_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '现存重量(kg)',
  MODIFY COLUMN qty_available DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '可用数量',
  MODIFY COLUMN weight_available_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '可用重量(kg)',
  MODIFY COLUMN qty_allocated DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已分配数量',
  MODIFY COLUMN weight_allocated_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已分配重量(kg)',
  MODIFY COLUMN avg_unit_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '平均单位成本',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE wh_inventory_txn
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN txn_no VARCHAR(50) NOT NULL COMMENT '流水号',
  MODIFY COLUMN txn_type VARCHAR(32) NOT NULL COMMENT '流水类型：PURCHASE_IN/MATERIAL_ISSUE/FG_IN/SALES_OUT/RETURN_IN/RETURN_OUT/SCRAP_OUT/PRODUCTION_SCRAP_IN/OUTSOURCING_SCRAP_IN/SCRAP_SALE_OUT/ADJUST',
  MODIFY COLUMN item_id BIGINT NOT NULL COMMENT '物料ID',
  MODIFY COLUMN warehouse_id BIGINT NOT NULL COMMENT '仓库ID',
  MODIFY COLUMN location_id BIGINT NULL COMMENT '库位ID',
  MODIFY COLUMN lot_id BIGINT NULL COMMENT '批次ID',
  MODIFY COLUMN qty_change DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '数量变动',
  MODIFY COLUMN weight_change_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '重量变动(kg)',
  MODIFY COLUMN unit_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '单位成本',
  MODIFY COLUMN amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '金额',
  MODIFY COLUMN source_doc_type VARCHAR(32) NOT NULL COMMENT '来源单据类型',
  MODIFY COLUMN source_doc_id BIGINT NOT NULL COMMENT '来源单据ID',
  MODIFY COLUMN source_line_id BIGINT NULL COMMENT '来源单据行ID',
  MODIFY COLUMN biz_time DATETIME NOT NULL COMMENT '业务时间',
  MODIFY COLUMN operator_user_id BIGINT NULL COMMENT '操作人用户ID',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE pp_work_order
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN work_order_no VARCHAR(50) NOT NULL COMMENT '工单号',
  MODIFY COLUMN work_order_type VARCHAR(32) NOT NULL DEFAULT 'NORMAL' COMMENT '工单类型：NORMAL/REWORK',
  MODIFY COLUMN source_sales_order_item_id BIGINT NULL COMMENT '来源订单明细ID',
  MODIFY COLUMN product_item_id BIGINT NOT NULL COMMENT '产品物料ID',
  MODIFY COLUMN route_id BIGINT NOT NULL COMMENT '工艺路线ID',
  MODIFY COLUMN bom_id BIGINT NOT NULL COMMENT 'BOM ID',
  MODIFY COLUMN planned_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '计划数量',
  MODIFY COLUMN released_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '下达数量',
  MODIFY COLUMN finished_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '完工数量',
  MODIFY COLUMN scrap_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '报废数量',
  MODIFY COLUMN planned_start_time DATETIME NULL COMMENT '计划开始时间',
  MODIFY COLUMN planned_end_time DATETIME NULL COMMENT '计划结束时间',
  MODIFY COLUMN actual_start_time DATETIME NULL COMMENT '实际开始时间',
  MODIFY COLUMN actual_end_time DATETIME NULL COMMENT '实际结束时间',
  MODIFY COLUMN priority_level INT NOT NULL DEFAULT 3 COMMENT '优先级',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'CREATED' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE pp_work_order_material
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN work_order_id BIGINT NOT NULL COMMENT '工单ID',
  MODIFY COLUMN bom_item_id BIGINT NOT NULL COMMENT 'BOM明细ID',
  MODIFY COLUMN material_item_id BIGINT NOT NULL COMMENT '原材料物料ID',
  MODIFY COLUMN required_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '需求数量',
  MODIFY COLUMN required_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '需求重量(kg)',
  MODIFY COLUMN issued_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已领料数量',
  MODIFY COLUMN issued_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已领料重量(kg)',
  MODIFY COLUMN returned_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已退料数量',
  MODIFY COLUMN returned_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '已退料重量(kg)',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'OPEN' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE pp_work_order_operation
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN work_order_id BIGINT NOT NULL COMMENT '工单ID',
  MODIFY COLUMN route_operation_id BIGINT NOT NULL COMMENT '工艺路线工序ID',
  MODIFY COLUMN seq_no INT NOT NULL COMMENT '序号',
  MODIFY COLUMN operation_name VARCHAR(100) NOT NULL COMMENT '工序名称',
  MODIFY COLUMN work_center_id BIGINT NOT NULL COMMENT '工作中心ID',
  MODIFY COLUMN planned_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '计划数量',
  MODIFY COLUMN report_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '报工数量',
  MODIFY COLUMN good_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '合格数量',
  MODIFY COLUMN scrap_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '报废数量',
  MODIFY COLUMN rework_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '返工数量',
  MODIFY COLUMN std_labor_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '标准人工成本',
  MODIFY COLUMN std_machine_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '标准设备成本',
  MODIFY COLUMN std_outsource_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '标准委外成本',
  MODIFY COLUMN allowed_scrap_rate DECIMAL(8,4) NOT NULL DEFAULT 0 COMMENT '允许报废率',
  MODIFY COLUMN is_abnormal TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否异常',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'PENDING' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE pp_material_issue
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN issue_no VARCHAR(50) NOT NULL COMMENT '领料单号',
  MODIFY COLUMN work_order_id BIGINT NOT NULL COMMENT '工单ID',
  MODIFY COLUMN warehouse_id BIGINT NOT NULL COMMENT '仓库ID',
  MODIFY COLUMN issue_time DATETIME NOT NULL COMMENT '领料时间',
  MODIFY COLUMN issuer_employee_id BIGINT NULL COMMENT '发料人员工ID',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'CREATED' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE pp_material_issue_item
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN material_issue_id BIGINT NOT NULL COMMENT '领料单ID',
  MODIFY COLUMN work_order_material_id BIGINT NOT NULL COMMENT '工单用料ID',
  MODIFY COLUMN material_item_id BIGINT NOT NULL COMMENT '原材料物料ID',
  MODIFY COLUMN lot_id BIGINT NOT NULL COMMENT '批次ID',
  MODIFY COLUMN location_id BIGINT NULL COMMENT '库位ID',
  MODIFY COLUMN issue_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT 'Issue数量',
  MODIFY COLUMN issue_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT 'issue_weight_kg',
  MODIFY COLUMN unit_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '单位成本',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'POSTED' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE pp_operation_report
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN report_no VARCHAR(50) NOT NULL COMMENT '报工单号',
  MODIFY COLUMN work_order_id BIGINT NOT NULL COMMENT '工单ID',
  MODIFY COLUMN work_order_operation_id BIGINT NOT NULL COMMENT '工单工序ID',
  MODIFY COLUMN employee_id BIGINT NOT NULL COMMENT '员工ID',
  MODIFY COLUMN equipment_id BIGINT NULL COMMENT '设备ID',
  MODIFY COLUMN report_source VARCHAR(32) NOT NULL DEFAULT 'MANUAL' COMMENT '报工来源：MANUAL/MINI_APP/IMPORT',
  MODIFY COLUMN shift_code VARCHAR(32) NULL COMMENT '班次编码',
  MODIFY COLUMN start_time DATETIME NOT NULL COMMENT '开始时间',
  MODIFY COLUMN end_time DATETIME NOT NULL COMMENT '结束时间',
  MODIFY COLUMN report_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '报工数量',
  MODIFY COLUMN good_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '合格数量',
  MODIFY COLUMN scrap_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '报废数量',
  MODIFY COLUMN rework_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '返工数量',
  MODIFY COLUMN scrap_reason VARCHAR(255) NULL COMMENT '报废原因',
  MODIFY COLUMN downtime_minutes DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '停机时长(分钟)',
  MODIFY COLUMN extra_cost_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '额外成本金额',
  MODIFY COLUMN is_abnormal TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否异常',
  MODIFY COLUMN approved_by BIGINT NULL COMMENT '审批人用户ID',
  MODIFY COLUMN approved_at DATETIME NULL COMMENT '审批时间',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE pp_scrap_record
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN scrap_no VARCHAR(50) NOT NULL COMMENT '报废单号',
  MODIFY COLUMN report_id BIGINT NOT NULL COMMENT '报工记录ID',
  MODIFY COLUMN work_order_id BIGINT NOT NULL COMMENT '工单ID',
  MODIFY COLUMN work_order_operation_id BIGINT NOT NULL COMMENT '工单工序ID',
  MODIFY COLUMN item_id BIGINT NOT NULL COMMENT '物料ID',
  MODIFY COLUMN scrap_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '报废数量',
  MODIFY COLUMN scrap_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '报废重量(kg)',
  MODIFY COLUMN scrap_reason VARCHAR(255) NULL COMMENT '报废原因',
  MODIFY COLUMN disposal_type VARCHAR(32) NOT NULL DEFAULT 'SCRAP' COMMENT '处置类型：SCRAP/REWORK',
  MODIFY COLUMN saleable_scrap_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '可售废料重量(kg)',
  MODIFY COLUMN scrap_cost_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '报废成本金额',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'CONFIRMED' COMMENT '状态',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE pp_completion_receipt
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN receipt_no VARCHAR(50) NOT NULL COMMENT '入库单号',
  MODIFY COLUMN work_order_id BIGINT NOT NULL COMMENT '工单ID',
  MODIFY COLUMN warehouse_id BIGINT NOT NULL COMMENT '仓库ID',
  MODIFY COLUMN receipt_time DATETIME NOT NULL COMMENT '入库时间',
  MODIFY COLUMN receiver_employee_id BIGINT NULL COMMENT '接收人员工ID',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'CREATED' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE pp_completion_receipt_item
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN completion_receipt_id BIGINT NOT NULL COMMENT '完工入库单ID',
  MODIFY COLUMN line_no INT NOT NULL COMMENT '行号',
  MODIFY COLUMN product_item_id BIGINT NOT NULL COMMENT '产品物料ID',
  MODIFY COLUMN location_id BIGINT NULL COMMENT '库位ID',
  MODIFY COLUMN lot_no VARCHAR(50) NOT NULL COMMENT '批次号',
  MODIFY COLUMN receipt_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT 'Receipt数量',
  MODIFY COLUMN receipt_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT 'receipt_weight_kg',
  MODIFY COLUMN unit_cost DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '单位成本',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'POSTED' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE so_delivery
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN delivery_no VARCHAR(50) NOT NULL COMMENT '发货单号',
  MODIFY COLUMN sales_order_id BIGINT NOT NULL COMMENT '订单ID',
  MODIFY COLUMN warehouse_id BIGINT NOT NULL COMMENT '仓库ID',
  MODIFY COLUMN delivery_date DATETIME NOT NULL COMMENT '发货时间',
  MODIFY COLUMN shipper_employee_id BIGINT NULL COMMENT '发货人员工ID',
  MODIFY COLUMN consignee_name VARCHAR(100) NULL COMMENT '收货人姓名',
  MODIFY COLUMN consignee_phone VARCHAR(50) NULL COMMENT '收货人电话',
  MODIFY COLUMN delivery_address VARCHAR(255) NULL COMMENT '送货地址',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'CREATED' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE so_delivery_item
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN delivery_id BIGINT NOT NULL COMMENT '发货单ID',
  MODIFY COLUMN line_no INT NOT NULL COMMENT '行号',
  MODIFY COLUMN sales_order_item_id BIGINT NOT NULL COMMENT '订单明细ID',
  MODIFY COLUMN product_item_id BIGINT NOT NULL COMMENT '产品物料ID',
  MODIFY COLUMN lot_id BIGINT NULL COMMENT '批次ID',
  MODIFY COLUMN delivery_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '发货数量',
  MODIFY COLUMN delivery_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '发货重量(kg)',
  MODIFY COLUMN unit_price DECIMAL(18,4) NOT NULL DEFAULT 0 COMMENT '单价',
  MODIFY COLUMN line_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '行金额',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'POSTED' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE rt_return_order
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN return_no VARCHAR(50) NOT NULL COMMENT '退货单号',
  MODIFY COLUMN customer_id BIGINT NOT NULL COMMENT '客户ID',
  MODIFY COLUMN sales_order_id BIGINT NULL COMMENT '订单ID',
  MODIFY COLUMN delivery_id BIGINT NULL COMMENT '发货单ID',
  MODIFY COLUMN return_date DATETIME NOT NULL COMMENT '退货时间',
  MODIFY COLUMN return_reason VARCHAR(255) NULL COMMENT '退货原因',
  MODIFY COLUMN handler_employee_id BIGINT NULL COMMENT '处理人员工ID',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'CREATED' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE rt_return_item
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN return_order_id BIGINT NOT NULL COMMENT '退货单ID',
  MODIFY COLUMN line_no INT NOT NULL COMMENT '行号',
  MODIFY COLUMN sales_order_item_id BIGINT NULL COMMENT '订单明细ID',
  MODIFY COLUMN product_item_id BIGINT NOT NULL COMMENT '产品物料ID',
  MODIFY COLUMN source_lot_id BIGINT NULL COMMENT '来源批次ID',
  MODIFY COLUMN return_qty DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '退货数量',
  MODIFY COLUMN return_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '退货重量(kg)',
  MODIFY COLUMN disposition_status VARCHAR(32) NOT NULL DEFAULT 'PENDING' COMMENT '处置状态',
  MODIFY COLUMN responsibility_type VARCHAR(32) NULL COMMENT '责任类型',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE rt_return_disposition
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN disposition_no VARCHAR(50) NOT NULL COMMENT '处置单号',
  MODIFY COLUMN return_item_id BIGINT NOT NULL COMMENT '退货明细ID',
  MODIFY COLUMN disposition_type VARCHAR(32) NOT NULL COMMENT '处置方式：REWORK/SCRAP',
  MODIFY COLUMN rework_work_order_id BIGINT NULL COMMENT '返工工单ID',
  MODIFY COLUMN scrap_weight_kg DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '报废重量(kg)',
  MODIFY COLUMN extra_cost_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '额外成本金额',
  MODIFY COLUMN scrap_sale_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '废料销售金额',
  MODIFY COLUMN closed_at DATETIME NULL COMMENT '关闭时间',
  MODIFY COLUMN status VARCHAR(32) NOT NULL DEFAULT 'OPEN' COMMENT '状态',
  MODIFY COLUMN remark VARCHAR(255) NULL COMMENT '备注',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE fi_accounting_period
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN period_code VARCHAR(20) NOT NULL COMMENT '期间编码',
  MODIFY COLUMN year_no INT NOT NULL COMMENT '年度',
  MODIFY COLUMN month_no INT NOT NULL COMMENT '月份',
  MODIFY COLUMN start_date DATE NOT NULL COMMENT '开始日期',
  MODIFY COLUMN end_date DATE NOT NULL COMMENT '结束日期',
  MODIFY COLUMN close_status VARCHAR(32) NOT NULL DEFAULT 'OPEN' COMMENT '关账状态',
  MODIFY COLUMN closed_at DATETIME NULL COMMENT '关闭时间',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE fi_overhead_entry
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN period_id BIGINT NOT NULL COMMENT '期间ID',
  MODIFY COLUMN overhead_type VARCHAR(32) NOT NULL COMMENT '制造费用类型：RENT/UTILITY/LOGISTICS/ADMIN/DEPRECIATION/OTHER',
  MODIFY COLUMN dept_id BIGINT NULL COMMENT '部门ID',
  MODIFY COLUMN amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '金额',
  MODIFY COLUMN allocation_basis VARCHAR(32) NOT NULL DEFAULT 'WORK_HOURS' COMMENT '分摊依据：WORK_HOURS/MACHINE_HOURS/QTY/OCCUPIED_AREA',
  MODIFY COLUMN description VARCHAR(255) NULL COMMENT '说明',
  MODIFY COLUMN created_by BIGINT NULL COMMENT '创建人用户ID',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE fi_cost_allocation
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN period_id BIGINT NOT NULL COMMENT '期间ID',
  MODIFY COLUMN work_order_id BIGINT NOT NULL COMMENT '工单ID',
  MODIFY COLUMN product_item_id BIGINT NOT NULL COMMENT '产品物料ID',
  MODIFY COLUMN allocation_basis_value DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '分摊依据值',
  MODIFY COLUMN overhead_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '制造费用金额',
  MODIFY COLUMN material_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '材料金额',
  MODIFY COLUMN labor_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '人工金额',
  MODIFY COLUMN machine_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '设备金额',
  MODIFY COLUMN abnormal_loss_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '异常损失金额',
  MODIFY COLUMN total_cost_amount DECIMAL(18,2) NOT NULL DEFAULT 0 COMMENT '总成本金额',
  MODIFY COLUMN unit_cost DECIMAL(18,6) NOT NULL DEFAULT 0 COMMENT '单位成本',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

ALTER TABLE fi_statement_snapshot
  MODIFY COLUMN id BIGINT NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  MODIFY COLUMN snapshot_no VARCHAR(50) NOT NULL COMMENT '快照编号',
  MODIFY COLUMN period_id BIGINT NOT NULL COMMENT '期间ID',
  MODIFY COLUMN statement_type VARCHAR(32) NOT NULL COMMENT '报表类型：WEEKLY/MONTHLY/INVENTORY/COSTING',
  MODIFY COLUMN report_date DATE NOT NULL COMMENT '报表日期',
  MODIFY COLUMN summary_json JSON NOT NULL COMMENT '汇总数据(JSON)',
  MODIFY COLUMN created_by BIGINT NULL COMMENT '创建人用户ID',
  MODIFY COLUMN created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  MODIFY COLUMN updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';
