diff --git a/alert_function.sql b/alert_function.sql new file mode 100644 index 0000000..bdb018d --- /dev/null +++ b/alert_function.sql @@ -0,0 +1,61 @@ +-- ======================================= +-- 药品库存智能预警功能数据库脚本 +-- ======================================= + +-- 1. 为药品信息表添加最低库存阈值字段 +ALTER TABLE `yaopinxinxi` +ADD COLUMN `low_stock_threshold` INT(11) NULL DEFAULT 10 COMMENT '最低库存阈值' AFTER `beizhu`; + +-- 2. 创建库存预警记录表 +DROP TABLE IF EXISTS `stock_alert`; +CREATE TABLE `stock_alert` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', + `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `yaopin_id` bigint(20) NOT NULL COMMENT '药品ID', + `yaopinmingcheng` varchar(200) NOT NULL COMMENT '药品名称', + `current_stock` int(11) NOT NULL COMMENT '当前库存', + `low_stock_threshold` int(11) NOT NULL COMMENT '最低库存阈值', + `alert_level` int(11) DEFAULT 1 COMMENT '预警级别(1:低库存预警, 2:紧急预警)', + `status` int(11) DEFAULT 0 COMMENT '处理状态(0:未处理, 1:已处理)', + `handler_id` bigint(20) DEFAULT NULL COMMENT '处理人ID', + `handler_name` varchar(200) DEFAULT NULL COMMENT '处理人姓名', + `handle_time` timestamp NULL DEFAULT NULL COMMENT '处理时间', + `handle_note` varchar(500) DEFAULT NULL COMMENT '处理备注', + PRIMARY KEY (`id`), + KEY `idx_yaopin_id` (`yaopin_id`), + KEY `idx_status` (`status`), + KEY `idx_addtime` (`addtime`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='库存预警记录表'; + +-- 3. 创建药品采购建议表 +DROP TABLE IF EXISTS `purchase_suggestion`; +CREATE TABLE `purchase_suggestion` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', + `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `yaopin_id` bigint(20) NOT NULL COMMENT '药品ID', + `yaopinmingcheng` varchar(200) NOT NULL COMMENT '药品名称', + `guige` varchar(200) DEFAULT NULL COMMENT '规格', + `current_stock` int(11) NOT NULL COMMENT '当前库存', + `low_stock_threshold` int(11) NOT NULL COMMENT '最低库存阈值', + `suggested_quantity` int(11) NOT NULL COMMENT '建议采购数量', + `suggested_min_quantity` int(11) DEFAULT NULL COMMENT '建议最小采购量', + `suggested_max_quantity` int(11) DEFAULT NULL COMMENT '建议最大采购量', + `avg_monthly_usage` int(11) DEFAULT NULL COMMENT '月平均使用量', + `lead_time_days` int(11) DEFAULT NULL COMMENT '采购提前期(天)', + `urgency_level` int(11) DEFAULT 1 COMMENT '紧急程度(1:一般, 2:紧急, 3:非常紧急)', + `status` int(11) DEFAULT 0 COMMENT '状态(0:待审核, 1:已采纳, 2:已拒绝)', + `creator_id` bigint(20) DEFAULT NULL COMMENT '创建人ID', + `creator_name` varchar(200) DEFAULT NULL COMMENT '创建人姓名', + `remark` varchar(500) DEFAULT NULL COMMENT '备注', + PRIMARY KEY (`id`), + KEY `idx_yaopin_id` (`yaopin_id`), + KEY `idx_status` (`status`), + KEY `idx_urgency_level` (`urgency_level`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='药品采购建议表'; + +-- 4. 初始化现有药品的最低库存阈值为10 +UPDATE `yaopinxinxi` SET `low_stock_threshold` = 10 WHERE `low_stock_threshold` IS NULL; + +-- 5. 创建索引优化查询 +CREATE INDEX idx_yaopin_kucun ON yaopinxinxi(kucun); +CREATE INDEX idx_yaopin_threshold ON yaopinxinxi(low_stock_threshold); diff --git a/manage_code/src/views/yaopinxinxi/list.vue b/manage_code/src/views/yaopinxinxi/list.vue index 63ffcb5..2287c16 100644 --- a/manage_code/src/views/yaopinxinxi/list.vue +++ b/manage_code/src/views/yaopinxinxi/list.vue @@ -29,6 +29,14 @@ 药品库存统计 + + + + 库存预警检查 + + + + 生成采购建议 @@ -101,16 +109,29 @@ - + + + + - - 出库 - + + 出库 + + + + 设置阈值 + @@ -182,6 +207,77 @@ + + + + + {{thresholdForm.yaopinmingcheng}} + + + {{thresholdForm.kucun}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +