-- --------------------------------------------------------
-- 入库管理系统数据库表
-- 创建日期: 2025-11-03
-- --------------------------------------------------------

-- ----------------------------
-- 1. 入库单表
-- ----------------------------
DROP TABLE IF EXISTS `warehouse_receipt`;
CREATE TABLE `warehouse_receipt` (
  `receipt_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '入库单ID',
  `receipt_no` varchar(50) NOT NULL COMMENT '入库单号',
  `commission_no` varchar(100) DEFAULT NULL COMMENT '样品委托单号',
  `client_unit` varchar(200) DEFAULT NULL COMMENT '委托单位',
  `client_contact` varchar(100) DEFAULT NULL COMMENT '委托人',
  `receipt_date` date DEFAULT NULL COMMENT '收样日期',
  `source_location` varchar(200) DEFAULT NULL COMMENT '来源地',
  `delivery_person` varchar(100) DEFAULT NULL COMMENT '送样人',
  `receipt_method` varchar(50) DEFAULT NULL COMMENT '收样方式(专人/小运/快递/货拉拉/交本框)',
  `receipt_method_detail` varchar(200) DEFAULT NULL COMMENT '收样方式详情(单号等)',
  `receiver` varchar(100) DEFAULT NULL COMMENT '收样人',
  `recorder` varchar(100) DEFAULT NULL COMMENT '入库记录人',
  `purpose` varchar(50) DEFAULT NULL COMMENT '来样目的(标准化测试/开发验证/故障验证/实验)',
  `purpose_detail` varchar(500) DEFAULT NULL COMMENT '来样目的详情',
  `status` char(1) DEFAULT '0' COMMENT '状态(0正常 1已完成 2已取消)',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  `create_by` varchar(64) DEFAULT '' COMMENT '创建者',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_by` varchar(64) DEFAULT '' COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0代表存在 1代表删除)',
  PRIMARY KEY (`receipt_id`),
  UNIQUE KEY `idx_receipt_no` (`receipt_no`),
  KEY `idx_create_time` (`create_time`),
  KEY `idx_status` (`status`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='入库单表';

-- ----------------------------
-- 2. 样品表
-- ----------------------------
DROP TABLE IF EXISTS `warehouse_sample`;
CREATE TABLE `warehouse_sample` (
  `sample_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '样品ID',
  `receipt_id` bigint(20) NOT NULL COMMENT '入库单ID',
  `receipt_no` varchar(50) DEFAULT NULL COMMENT '入库单号(冗余字段便于查询)',
  `sample_model` varchar(100) DEFAULT NULL COMMENT '样品型号',
  `sample_sn` varchar(100) DEFAULT NULL COMMENT '样品SN号',
  `hardware_version` varchar(100) DEFAULT NULL COMMENT '样品硬件版本号',
  `external_status` varchar(50) DEFAULT NULL COMMENT '样品入库外测状态(PCBA/点板板/建板板)',
  `test_items` varchar(500) DEFAULT NULL COMMENT '计划测试项',
  `test_deadline` date DEFAULT NULL COMMENT '计划测试截止日期',
  `actual_test_items` varchar(500) DEFAULT NULL COMMENT '实际测试项',
  `delivery_date` date DEFAULT NULL COMMENT '出库交样日期',
  `delivery_method` varchar(50) DEFAULT NULL COMMENT '出库交样方式',
  `delivery_person` varchar(100) DEFAULT NULL COMMENT '出库交样人',
  `receive_person` varchar(100) DEFAULT NULL COMMENT '出库接样人',
  `delivery_recorder` varchar(100) DEFAULT NULL COMMENT '出库记录人',
  `status` char(1) DEFAULT '0' COMMENT '状态(0待测试 1测试中 2已完成 3已退回)',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  `create_by` varchar(64) DEFAULT '' COMMENT '创建者',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_by` varchar(64) DEFAULT '' COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0代表存在 1代表删除)',
  PRIMARY KEY (`sample_id`),
  KEY `idx_receipt_id` (`receipt_id`),
  KEY `idx_receipt_no` (`receipt_no`),
  KEY `idx_sample_sn` (`sample_sn`),
  KEY `idx_status` (`status`),
  CONSTRAINT `fk_sample_receipt` FOREIGN KEY (`receipt_id`) REFERENCES `warehouse_receipt` (`receipt_id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='样品表';

-- ----------------------------
-- 3. 入库单序号表(用于生成入库单号)
-- ----------------------------
DROP TABLE IF EXISTS `warehouse_receipt_sequence`;
CREATE TABLE `warehouse_receipt_sequence` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `year` int(4) NOT NULL COMMENT '年份',
  `type` varchar(10) NOT NULL COMMENT '类型标识(内检等)',
  `sequence` int(11) NOT NULL DEFAULT '0' COMMENT '当前序号',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_year_type` (`year`,`type`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='入库单序号表';

-- ----------------------------
-- 4. 初始化示例数据
-- ----------------------------
INSERT INTO `warehouse_receipt` VALUES 
(1, '202510001', NULL, '中海油', '王珺珍', '2025-10-10', '燕邵', '张子萎', '专人', NULL, '陈蔚', '梁广超', '标准化测试', NULL, '0', NULL, 'admin', '2025-11-03 00:00:00', 'admin', '2025-11-03 00:00:00', '0');

INSERT INTO `warehouse_sample` VALUES 
(1, 1, '202510001', 'DSM', '240212SG', 'DSM_V4.1.2', '点板板', '点板板入库测试', '2025-10-20', '点板板入库测试', NULL, NULL, NULL, NULL, NULL, '0', NULL, 'admin', '2025-11-03 00:00:00', 'admin', '2025-11-03 00:00:00', '0');

-- ----------------------------
-- 5. 菜单SQL
-- ----------------------------
-- 主菜单
INSERT INTO `sys_menu` VALUES (2000, '入库管理', 0, 5, 'warehouse', NULL, '', 1, 0, 'M', '0', '0', '', 'education', 'admin', '2025-11-03 00:00:00', '', NULL, '入库管理目录');

-- 入库单管理菜单
INSERT INTO `sys_menu` VALUES (2001, '入库单管理', 2000, 1, 'receipt', 'warehouse/receipt/index', '', 1, 0, 'C', '0', '0', 'warehouse:receipt:list', 'form', 'admin', '2025-11-03 00:00:00', '', NULL, '入库单管理菜单');
INSERT INTO `sys_menu` VALUES (2002, '入库单查询', 2001, 1, '', '', '', 1, 0, 'F', '0', '0', 'warehouse:receipt:query', '#', 'admin', '2025-11-03 00:00:00', '', NULL, '');
INSERT INTO `sys_menu` VALUES (2003, '入库单新增', 2001, 2, '', '', '', 1, 0, 'F', '0', '0', 'warehouse:receipt:add', '#', 'admin', '2025-11-03 00:00:00', '', NULL, '');
INSERT INTO `sys_menu` VALUES (2004, '入库单修改', 2001, 3, '', '', '', 1, 0, 'F', '0', '0', 'warehouse:receipt:edit', '#', 'admin', '2025-11-03 00:00:00', '', NULL, '');
INSERT INTO `sys_menu` VALUES (2005, '入库单删除', 2001, 4, '', '', '', 1, 0, 'F', '0', '0', 'warehouse:receipt:remove', '#', 'admin', '2025-11-03 00:00:00', '', NULL, '');
INSERT INTO `sys_menu` VALUES (2006, '入库单导出', 2001, 5, '', '', '', 1, 0, 'F', '0', '0', 'warehouse:receipt:export', '#', 'admin', '2025-11-03 00:00:00', '', NULL, '');

-- 样品管理菜单
INSERT INTO `sys_menu` VALUES (2011, '样品管理', 2000, 2, 'sample', 'warehouse/sample/index', '', 1, 0, 'C', '0', '0', 'warehouse:sample:list', 'list', 'admin', '2025-11-03 00:00:00', '', NULL, '样品管理菜单');
INSERT INTO `sys_menu` VALUES (2012, '样品查询', 2011, 1, '', '', '', 1, 0, 'F', '0', '0', 'warehouse:sample:query', '#', 'admin', '2025-11-03 00:00:00', '', NULL, '');
INSERT INTO `sys_menu` VALUES (2013, '样品新增', 2011, 2, '', '', '', 1, 0, 'F', '0', '0', 'warehouse:sample:add', '#', 'admin', '2025-11-03 00:00:00', '', NULL, '');
INSERT INTO `sys_menu` VALUES (2014, '样品修改', 2011, 3, '', '', '', 1, 0, 'F', '0', '0', 'warehouse:sample:edit', '#', 'admin', '2025-11-03 00:00:00', '', NULL, '');
INSERT INTO `sys_menu` VALUES (2015, '样品删除', 2011, 4, '', '', '', 1, 0, 'F', '0', '0', 'warehouse:sample:remove', '#', 'admin', '2025-11-03 00:00:00', '', NULL, '');
INSERT INTO `sys_menu` VALUES (2016, '样品导出', 2011, 5, '', '', '', 1, 0, 'F', '0', '0', 'warehouse:sample:export', '#', 'admin', '2025-11-03 00:00:00', '', NULL, '');






