-- MySQL 8.0.35 CREATE DATABASE IF NOT EXISTS `building_cdwms` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; USE `building_cdwms`; CREATE TABLE IF NOT EXISTS `wh_warehouse` ( `id` bigint NOT NULL COMMENT '主键', `warehouse_name` varchar(128) NOT NULL COMMENT '仓库名称', `warehouse_type_code` varchar(32) NOT NULL COMMENT '仓库类型编码(来源数据字典,例如:RAW=原料仓、FINISHED=成品仓、HAZ_TMP=危废暂存仓等)', `capacity` decimal(16,2) NOT NULL DEFAULT 0 COMMENT '最大容量', `capacity_unit_code` varchar(16) NOT NULL DEFAULT 'TON' COMMENT '容量单位编码(来源字典,例如:TON=吨、CBM=立方米)', `manager_id` bigint DEFAULT NULL COMMENT '责任人 Id; sys_user.id', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`), KEY `idx_wh_warehouse_type_code` (`warehouse_type_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='仓库信息'; -- 仓库存量(实时库存) -- 出入库单(入库单+出库单,且每笔订单只包含一种物料) CREATE TABLE IF NOT EXISTS `wh_stock_order` ( `id` bigint NOT NULL COMMENT '主键', `batch_no` varchar(64) DEFAULT NULL COMMENT '出入库编号', `order_id` bigint NOT NULL COMMENT '上游业务订单Id(如销售订单、采购订单等)', `order_type` varchar(16) NOT NULL COMMENT '单据类型(字典):IN=入库单、OUT=出库单', `warehouse_id` bigint NOT NULL COMMENT '仓库 Id; wh_warehouse.id', `order_no` varchar(32) DEFAULT NULL COMMENT '关联业务单号(可选,用于展示用单号)', `customer_id` bigint DEFAULT NULL COMMENT '客户 Id; tb_customer.id,仅出库单使用', `operate_time` datetime NOT NULL COMMENT '出入库时间(入库=到货/入库时间,出库=发货时间)', `locator` varchar(64) DEFAULT NULL COMMENT '仓内存放位置(货架/库位等,入库使用为主)', `material_id` bigint NOT NULL COMMENT '物料 Id; tb_material.id', `quantity` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '数量', `remark` varchar(255) DEFAULT NULL COMMENT '备注信息', `responsible_id` bigint DEFAULT NULL COMMENT '经办人/责任人 Id; sys_user.id', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`), UNIQUE KEY `uk_wh_stock_order_order_id_type` (`order_id`,`order_type`), KEY `idx_wh_stock_order_wh` (`warehouse_id`), KEY `idx_wh_stock_order_type` (`order_type`), KEY `idx_wh_stock_order_material` (`material_id`), KEY `idx_wh_stock_order_customer` (`customer_id`), CONSTRAINT `fk_wh_stock_order_wh` FOREIGN KEY (`warehouse_id`) REFERENCES `wh_warehouse` (`id`), CONSTRAINT `fk_wh_stock_order_material` FOREIGN KEY (`material_id`) REFERENCES `tb_material` (`id`), CONSTRAINT `fk_wh_stock_order_customer` FOREIGN KEY (`customer_id`) REFERENCES `tb_customer` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='出入库单(单物料)'; -- 库存预警记录 CREATE TABLE IF NOT EXISTS `wh_stock_alert` ( `id` bigint NOT NULL COMMENT '主键', `warehouse_id` bigint NOT NULL COMMENT '仓库 Id', `material_id` bigint NOT NULL COMMENT '物料 Id', `alert_type` varchar(16) NOT NULL COMMENT '预警类型(字典):LOW=低库存预警、HIGH=高库存预警', `current_quantity` decimal(16,3) NOT NULL COMMENT '触发时库存', `status` varchar(16) NOT NULL DEFAULT 'UNRESOLVED' COMMENT '处理状态(字典):UNRESOLVED=未处理、RESOLVED=已处理', `suggestion` varchar(255) DEFAULT NULL COMMENT '处理建议', `alert_time` datetime NOT NULL COMMENT '预警时间', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`), KEY `idx_wh_stock_alert_wh_material` (`warehouse_id`,`material_id`), CONSTRAINT `fk_wh_stock_alert_wh` FOREIGN KEY (`warehouse_id`) REFERENCES `wh_warehouse` (`id`), CONSTRAINT `fk_wh_stock_alert_material` FOREIGN KEY (`material_id`) REFERENCES `tb_material` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='库存预警记录'; -- 盘点任务 CREATE TABLE IF NOT EXISTS `wh_stocktaking_task` ( `id` bigint NOT NULL COMMENT '主键', `task_no` varchar(32) NOT NULL COMMENT '盘点编号', `warehouse_id` bigint NOT NULL COMMENT '盘点仓库 Id', `checker_id` bigint DEFAULT NULL COMMENT '盘点人 Id; sys_user.id', `reviewer_id` bigint DEFAULT NULL COMMENT '复核人 Id; sys_user.id', `task_time` datetime NOT NULL COMMENT '盘点时间', `item_count` int NOT NULL DEFAULT 0 COMMENT '盘点项数', `abnormal_count` int NOT NULL DEFAULT 0 COMMENT '差异项数', `remark` varchar(255) DEFAULT NULL COMMENT '备注', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`), UNIQUE KEY `uk_wh_stocktaking_task_no` (`task_no`), KEY `idx_wh_stocktaking_task_wh` (`warehouse_id`), CONSTRAINT `fk_wh_stocktaking_task_wh` FOREIGN KEY (`warehouse_id`) REFERENCES `wh_warehouse` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='库存盘点任务'; -- 盘点明细 CREATE TABLE IF NOT EXISTS `wh_stocktaking_item` ( `id` bigint NOT NULL COMMENT '主键', `task_id` bigint NOT NULL COMMENT '盘点任务 Id; wh_stocktaking_task.id', `material_id` bigint NOT NULL COMMENT '物料 Id', `system_quantity` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '系统库存', `actual_quantity` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '实际库存', `difference_quantity` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '差异数量', `status` varchar(16) NOT NULL DEFAULT 'NORMAL' COMMENT '盘点结果状态(字典):NORMAL=无差异、ABNORMAL=有差异', `suggestion` varchar(255) DEFAULT NULL COMMENT '处理建议', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`), KEY `idx_wh_stocktaking_item_task` (`task_id`), KEY `idx_wh_stocktaking_item_material` (`material_id`), CONSTRAINT `fk_wh_stocktaking_item_task` FOREIGN KEY (`task_id`) REFERENCES `wh_stocktaking_task` (`id`), CONSTRAINT `fk_wh_stocktaking_item_material` FOREIGN KEY (`material_id`) REFERENCES `tb_material` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='库存盘点明细'; CREATE TABLE `fin_money_account` ( `id` bigint NOT NULL COMMENT 'Id', `account_no` varchar(64) NOT NULL COMMENT '账户编号', `type` varchar(32) NOT NULL COMMENT '账户类型编码(来源数据字典,例如:COMPANY=企业账户、PERSONAL=个人账户)', `user_id` bigint DEFAULT NULL COMMENT '用户Id; 个人账户使用', `company_id` bigint DEFAULT NULL COMMENT '企业Id; 企业账户使用', `money` decimal(14,2) NOT NULL DEFAULT '0.00' COMMENT '余额', `revenue` decimal(14,2) NOT NULL DEFAULT '0.00' COMMENT '营收', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `uk_fin_money_account_no` (`account_no`), KEY `idx_fin_money_account_type` (`type`), KEY `idx_fin_money_account_user` (`user_id`), KEY `idx_fin_money_account_company` (`company_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='资金账户表'; CREATE TABLE `fin_money_detail` ( `id` bigint NOT NULL COMMENT 'Id', `order_id` bigint DEFAULT NULL COMMENT '订单 Id', `money_account_id` bigint NOT NULL COMMENT '资金账户 Id', `balance_before` decimal(14,2) NOT NULL COMMENT '变动前余额', `delta` decimal(14,2) NOT NULL COMMENT '变动金额; 有正负', `balance_after` decimal(14,2) NOT NULL COMMENT '变动后余额', `type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '变动类型(字典 money_change_category):recharge=充值、platform_pay=平台打款、order_adjust=订单调账、order_deduct=订单扣款、order_refund=订单退款', `memo` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='资金明细'; CREATE TABLE `fin_money_bill` ( `id` bigint NOT NULL COMMENT 'Id', `company_id` bigint NOT NULL COMMENT '企业 Id', `user_id` bigint NOT NULL COMMENT '个人 Id', `type` varchar(32) NOT NULL COMMENT '账户类型编码(company=企业账户、personal=个人账户)', `start_time` date NOT NULL COMMENT '账单开始时间', `end_time` date NOT NULL COMMENT '账单结束时间', `bill_period` date DEFAULT NULL COMMENT '账期', `goods_id` bigint NOT NULL COMMENT '产品id', `goods_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '产品名称', `order_count` int NOT NULL COMMENT '订单数', `total_weight` int DEFAULT '0' COMMENT '总质量; 单位:千克', `car_count` int DEFAULT '0' COMMENT '总车数', `discount_money` decimal(14,2) NOT NULL DEFAULT '0.00' COMMENT '优惠金额', `total_money` decimal(14,2) NOT NULL COMMENT '账单金额', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='对账单'; CREATE TABLE `fin_expense` ( `id` bigint NOT NULL COMMENT 'Id', `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '付费项名称', `price` decimal(14,2) DEFAULT '0.00' COMMENT '单价; 单位:元', `money_strategy` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '计费策略; 字典代码:money_strategy', `canuse` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否可用; 0-->否、1-->是', `scope` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '适用范围; all -->所有客户 customer_type-->指定客户类型 customer -->指定客户', `company_ids` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '公司ids', `goods_scope` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '产品范围;字典代码:goods_scope all -->所有产品 goods -->指定产品', `goods_ids` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '产品ids', `station_scope` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '站点范围;字典代码:station_scope all -->所有站点 stations -->指定站点', `station_ids` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '站点ids', `billing_type` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '计费类型 字典代码:billing_type', `basic_weight` decimal(14,2) DEFAULT '0.00' COMMENT '基础磅重', `basic_price` decimal(14,2) DEFAULT '0.00' COMMENT '基础单价; 单位:元', `every_weight` decimal(14,2) DEFAULT '0.00' COMMENT '每档磅重', `every_price` decimal(14,2) DEFAULT '0.00' COMMENT '每档单价; 单位:元', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='费用配置'; CREATE TABLE `fin_discount` ( `id` bigint NOT NULL COMMENT 'Id', `company_id` bigint DEFAULT NULL COMMENT '公司id', `fee_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '费用类型:goods 产品 service 服务费', `expense_id` bigint DEFAULT NULL COMMENT '服务费id', `goods_ids` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '产品ids', `type` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '优惠类型:discount 优惠 raise加价', `money` decimal(14,2) DEFAULT '0.00' COMMENT '变化金额', `start_time` datetime NOT NULL COMMENT '开始时间', `end_time` datetime NOT NULL COMMENT '结束时间', `remark` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '备注', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='优惠管理'; -- 生产计划(简化:单表存主信息,物料明细在子表) CREATE TABLE IF NOT EXISTS `prod_plan` ( `id` bigint NOT NULL COMMENT '主键', `plan_code` varchar(32) NOT NULL COMMENT '计划编号(如 PLAN-20230515-001)', `plan_name` varchar(128) NOT NULL COMMENT '计划名称', `plan_type_code` varchar(32) NOT NULL COMMENT '计划类型编码(字典,如建筑垃圾处理等)', `create_mode_code` varchar(16) NOT NULL COMMENT '创建方式(字典):AI=AI生成,MANUAL=手动创建', `status_code` varchar(16) NOT NULL DEFAULT 'PENDING' COMMENT '计划状态(字典):PENDING=待执行、RUNNING=执行中、DONE=已完成、CANCELLED=已取消', `start_date` date NOT NULL COMMENT '开始日期', `end_date` date NOT NULL COMMENT '结束日期', `raw_plan_total` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '原料计划量汇总(吨)', `finished_plan_total` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '成品计划量汇总(吨)', `remark` varchar(512) DEFAULT NULL COMMENT '备注说明', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `uk_prod_plan_code` (`plan_code`), KEY `idx_prod_plan_status` (`status_code`), KEY `idx_prod_plan_type` (`plan_type_code`), KEY `idx_prod_plan_date` (`start_date`,`end_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='生产计划'; -- 生产计划物料明细(原料/成品在同一表,用 material_kind 区分) CREATE TABLE IF NOT EXISTS `prod_plan_material` ( `id` bigint NOT NULL COMMENT '主键', `plan_id` bigint NOT NULL COMMENT '生产计划 Id; prod_plan.id', `material_kind` varchar(16) NOT NULL COMMENT '物料类型:RAW=原料、FINISHED=成品', `material_id` bigint NOT NULL COMMENT '物料 Id; tb_material.id', `material_name` varchar(128) NOT NULL COMMENT '物料名称/品类名称快照', `plan_quantity` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '计划量(吨)', `actual_quantity` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '实际量(吨)', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, KEY `idx_prod_plan_material_plan` (`plan_id`), KEY `idx_prod_plan_material_kind` (`material_kind`), CONSTRAINT `fk_prod_plan_material_plan` FOREIGN KEY (`plan_id`) REFERENCES `prod_plan` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='生产计划物料明细'; -- 生产计划报告(执行结果汇总与偏差分析) CREATE TABLE IF NOT EXISTS `prod_plan_report` ( `id` bigint NOT NULL COMMENT '主键', `report_code` varchar(32) NOT NULL COMMENT '报告编号(如 REP-20230508-001)', `plan_id` bigint NOT NULL COMMENT '关联计划 Id; prod_plan.id', `execute_date` date NOT NULL COMMENT '执行日期/生成日期', `raw_plan_total` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '原料计划量汇总(吨)', `raw_actual_total` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '原料实际量汇总(吨)', `finished_plan_total` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '成品计划量汇总(吨)', `finished_actual_total` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '成品实际量汇总(吨)', `completion_rate` decimal(5,2) NOT NULL DEFAULT 0 COMMENT '计划完成率(%)', `raw_deviation_rate` decimal(6,2) DEFAULT NULL COMMENT '原料偏差率(%)', `finished_deviation_rate` decimal(6,2) DEFAULT NULL COMMENT '成品偏差率(%)', `raw_deviation_reason` text DEFAULT NULL COMMENT '原料偏差原因', `finished_deviation_reason` text DEFAULT NULL COMMENT '成品偏差原因', `improvement_suggestion` text DEFAULT NULL COMMENT '改进建议', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `uk_prod_plan_report_code` (`report_code`), KEY `idx_prod_plan_report_plan` (`plan_id`), CONSTRAINT `fk_prod_plan_report_plan` FOREIGN KEY (`plan_id`) REFERENCES `prod_plan` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='生产计划报告'; -- AI勘料主表 CREATE TABLE IF NOT EXISTS `ai_material_inspection` ( `id` bigint NOT NULL COMMENT '主键', `order_id` bigint DEFAULT NULL COMMENT '关联订单 Id', `license_plate_no` varchar(32) NOT NULL COMMENT '车牌号', `entry_time` datetime NOT NULL COMMENT '进场时间', `exit_time` datetime DEFAULT NULL COMMENT '出场时间', `material_id` bigint NOT NULL COMMENT '物料 Id; tb_material.id', `material_name` varchar(128) NOT NULL COMMENT '物料名称/品名快照(如拆除垃圾)', `gross_weight` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '毛重(吨)', `tare_weight` decimal(16,3) DEFAULT NULL COMMENT '皮重(吨)', `net_weight` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '净重(吨)', `inspection_method_code` varchar(32) NOT NULL COMMENT '看料方式编码(字典):smart=智能看料、manual=人工', `inspection_result_code` varchar(32) NOT NULL COMMENT '看料结果编码(字典):qualified=合格、unqualified=不合格', `judgment_reason` text DEFAULT NULL COMMENT '判断原因/原因说明', `judgment_basis` text DEFAULT NULL COMMENT '判断依据', `status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT '状态(字典):pending=未看料、inspected=已看料', `preliminary_images` text DEFAULT NULL COMMENT '初步识别图片(JSON数组,存储图片URL)', `deep_images` text DEFAULT NULL COMMENT '深度识别图片(JSON数组,存储图片URL)', `inspection_result` text DEFAULT NULL COMMENT '看料结果(Json字符串)', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, KEY `idx_ai_material_inspection_order` (`order_id`), KEY `idx_ai_material_inspection_plate` (`license_plate_no`), KEY `idx_ai_material_inspection_entry_time` (`entry_time`), KEY `idx_ai_material_inspection_status` (`status`), KEY `idx_ai_material_inspection_result` (`inspection_result_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='AI勘料主表'; -- ==================== AI运营决策模块 ==================== -- 能耗决策报告主表 CREATE TABLE IF NOT EXISTS `ai_energy_decision_report` ( `id` bigint NOT NULL COMMENT '主键', `report_code` varchar(64) NOT NULL COMMENT '报告编号(如AED-20230512-001)', `generation_time` datetime NOT NULL COMMENT '生成时间', `analysis_condition_ids` text DEFAULT NULL COMMENT '分析条件ID列表(JSON数组字符串,如["code1","code2"])', `analysis_condition_count` int NOT NULL DEFAULT 0 COMMENT '分析条件数', `estimated_energy_saving` decimal(5,2) DEFAULT NULL COMMENT '预计节能(%)', `status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT '执行状态(字典):executed=已执行、expired=已过期、pending=待执行', `core_conclusion` text DEFAULT NULL COMMENT '核心结论', `energy_saving_forecast` text DEFAULT NULL COMMENT '节能预期说明', `best_operating_period` text DEFAULT NULL COMMENT '最佳运行时段说明', `optimization_strategy` text DEFAULT NULL COMMENT '能耗优化策略说明', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `uk_ai_energy_decision_report_code` (`report_code`), KEY `idx_ai_energy_decision_report_status` (`status`), KEY `idx_ai_energy_decision_report_time` (`generation_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='能耗决策报告主表'; -- 能耗决策设备建议表 CREATE TABLE IF NOT EXISTS `ai_energy_decision_equipment` ( `id` bigint NOT NULL COMMENT '主键', `report_id` bigint NOT NULL COMMENT '能耗决策报告 Id; ai_energy_decision_report.id', `equipment_name` varchar(128) NOT NULL COMMENT '设备名称', `suggested_time` varchar(128) DEFAULT NULL COMMENT '建议运行时间(如00:00-06:00)', `operating_status_code` varchar(32) NOT NULL COMMENT '运行状态编码(字典):priority=优先运行、peak_flat=平峰运行、linked=联动运行、intermittent=间歇运行', `suggestion_reason` text DEFAULT NULL COMMENT '建议理由', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, KEY `idx_ai_energy_decision_equipment_report` (`report_id`), CONSTRAINT `fk_ai_energy_decision_equipment_report` FOREIGN KEY (`report_id`) REFERENCES `ai_energy_decision_report` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='能耗决策设备建议表'; -- 生产决策计划主表 CREATE TABLE IF NOT EXISTS `ai_production_decision_plan` ( `id` bigint NOT NULL COMMENT '主键', `plan_code` varchar(64) NOT NULL COMMENT '计划编号(如APD-20230512-001)', `generation_time` datetime NOT NULL COMMENT '生成时间', `analysis_condition_ids` text DEFAULT NULL COMMENT '分析条件ID列表(JSON数组字符串,如["code1","code2"])', `plan_period_days` int NOT NULL DEFAULT 7 COMMENT '计划周期(天)', `start_date` date NOT NULL COMMENT '计划开始日期', `end_date` date NOT NULL COMMENT '计划结束日期', `estimated_output` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '预计产量(吨)', `estimated_raw_consumption` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '预计原料消耗(吨)', `estimated_finished_output` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '预计成品产出(吨)', `estimated_revenue` decimal(16,2) DEFAULT NULL COMMENT '预计生产收益(元)', `status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT '执行状态(字典):pending=待执行、executing=执行中、completed=已完成、cancelled=已取消', `production_strategy` text DEFAULT NULL COMMENT '生产策略说明', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `uk_ai_production_decision_plan_code` (`plan_code`), KEY `idx_ai_production_decision_plan_status` (`status`), KEY `idx_ai_production_decision_plan_time` (`generation_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='生产决策计划主表'; -- 生产决策物料计划表 CREATE TABLE IF NOT EXISTS `ai_production_decision_material` ( `id` bigint NOT NULL COMMENT '主键', `plan_id` bigint NOT NULL COMMENT '生产决策计划 Id; ai_production_decision_plan.id', `raw_material_type_code` varchar(32) NOT NULL COMMENT '原料类型编码(字典)', `raw_material_name` varchar(128) NOT NULL COMMENT '原料类型名称快照', `demand_quantity` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '需求数量(吨)', `estimated_output_quantity` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '预计产出成品数量(吨)', `finished_product_type_code` varchar(32) DEFAULT NULL COMMENT '成品类型编码(字典)', `finished_product_name` varchar(128) DEFAULT NULL COMMENT '成品类型名称快照', `estimated_market_price` decimal(16,2) DEFAULT NULL COMMENT '预计市场价格(元/吨)', `priority_code` varchar(32) NOT NULL COMMENT '优先级编码(字典):highest=最高、high=高、medium=中、low=低', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, KEY `idx_ai_production_decision_material_plan` (`plan_id`), CONSTRAINT `fk_ai_production_decision_material_plan` FOREIGN KEY (`plan_id`) REFERENCES `ai_production_decision_plan` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='生产决策物料计划表'; -- 生产决策每日安排表 CREATE TABLE IF NOT EXISTS `ai_production_decision_daily` ( `id` bigint NOT NULL COMMENT '主键', `plan_id` bigint NOT NULL COMMENT '生产决策计划 Id; ai_production_decision_plan.id', `schedule_date` date NOT NULL COMMENT '安排日期', `planned_quantity` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '计划产量(吨)', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, KEY `idx_ai_production_decision_daily_plan` (`plan_id`), KEY `idx_ai_production_decision_daily_date` (`schedule_date`), CONSTRAINT `fk_ai_production_decision_daily_plan` FOREIGN KEY (`plan_id`) REFERENCES `ai_production_decision_plan` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='生产决策每日安排表'; -- 智能决策扫描报告主表 CREATE TABLE IF NOT EXISTS `ai_intelligent_decision_scan` ( `id` bigint NOT NULL COMMENT '主键', `scan_month` varchar(7) NOT NULL COMMENT '扫描月份(格式:YYYY-MM)', `scan_time` datetime NOT NULL COMMENT '扫描时间', `data_coverage` varchar(64) DEFAULT NULL COMMENT '数据覆盖范围(如全平台)', `production_efficiency_rate` decimal(5,2) DEFAULT NULL COMMENT '生产效率达标率(%)', `energy_cost_control_rate` decimal(5,2) DEFAULT NULL COMMENT '能耗成本控制率(%)', `safety_disposal_rate` decimal(5,2) DEFAULT NULL COMMENT '安全隐患处置及时率(%)', `recycled_profit_margin` decimal(5,2) DEFAULT NULL COMMENT '再生品销售利润率(%)', `ai_inspection_accuracy_rate` decimal(5,2) DEFAULT NULL COMMENT 'AI勘料准确率(%)', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `uk_ai_intelligent_decision_scan_month` (`scan_month`), KEY `idx_ai_intelligent_decision_scan_time` (`scan_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='智能决策扫描报告主表'; -- 智能决策建议表 CREATE TABLE IF NOT EXISTS `ai_intelligent_decision_recommendation` ( `id` bigint NOT NULL COMMENT '主键', `scan_id` bigint DEFAULT NULL COMMENT '扫描报告 Id; ai_intelligent_decision_scan.id(可为空,支持历史建议)', `category_tags` varchar(255) DEFAULT NULL COMMENT '类别标签(多个用逗号分隔,如能耗中心,生产管理)', `title` varchar(255) NOT NULL COMMENT '建议标题', `details` text NOT NULL COMMENT '建议详情', `priority_code` varchar(32) NOT NULL COMMENT '优先级编码(字典):high=高优先级、medium=中优先级、low=低优先级', `data_basis` text DEFAULT NULL COMMENT '数据依据说明', `handle_deadline` varchar(64) DEFAULT NULL COMMENT '处理期限(如7天内处理、15天内处理、30天内处理、下月周期前)', `status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT '处理状态(字典):pending=待处理、assigned=已分配、processing=处理中、completed=已完成', `assigned_to` bigint DEFAULT NULL COMMENT '分配给(用户Id)', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, KEY `idx_ai_intelligent_decision_recommendation_scan` (`scan_id`), KEY `idx_ai_intelligent_decision_recommendation_priority` (`priority_code`), KEY `idx_ai_intelligent_decision_recommendation_status` (`status`), CONSTRAINT `fk_ai_intelligent_decision_recommendation_scan` FOREIGN KEY (`scan_id`) REFERENCES `ai_intelligent_decision_scan` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='智能决策建议表'; -- ==================== 采购管理模块 ==================== -- 采购计划主表 CREATE TABLE IF NOT EXISTS `proc_plan` ( `id` bigint NOT NULL COMMENT '主键', `plan_code` varchar(64) NOT NULL COMMENT '采购编号', `name` varchar(128) NOT NULL COMMENT '采购项名称(如颚式破碎机、铁矿石等)', `type_code` varchar(32) NOT NULL COMMENT '类型编码(字典):equipment=设备、raw_material=原料', `quantity` decimal(16,3) NOT NULL DEFAULT 0 COMMENT '数量', `unit` varchar(16) NOT NULL COMMENT '单位(如台、吨等)', `planned_purchase_time` date NOT NULL COMMENT '计划采购时间', `responsible_id` bigint DEFAULT NULL COMMENT '责任人 Id; sys_user.id', `progress_rate` decimal(5,2) NOT NULL DEFAULT 0 COMMENT '采购进度(%)', `company_id` bigint DEFAULT NULL COMMENT '企业id', `status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT '采购状态(字典):pending=未开始、in_progress=进行中、completed=已完成、cancelled=已取消', `remark` varchar(512) DEFAULT NULL COMMENT '备注', `creator_id` bigint NOT NULL COMMENT '创建人 Id; sys_user.id', `modifier_id` bigint NOT NULL COMMENT '修改人 Id; sys_user.id', `create_time` datetime NOT NULL COMMENT '创建时间', `modify_time` datetime NOT NULL COMMENT '修改时间', `deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除; 0-->未删除、1-->已删除', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `uk_proc_plan_code` (`plan_code`), KEY `idx_proc_plan_type` (`type_code`), KEY `idx_proc_plan_status` (`status`), KEY `idx_proc_plan_planned_purchase_time` (`planned_purchase_time`), KEY `idx_proc_plan_company` (`company_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='采购计划主表';