
1. 医药配药管理系统项目概述医药配药管理系统是基于SpringBoot框架开发的毕业设计项目旨在解决医疗机构中药房配药环节的效率与准确性问题。这个系统将传统的人工配药流程数字化通过信息化手段管理药品库存、处方审核和配药记录显著降低人工配药错误率行业统计显示数字化配药可将错误率从5%降至0.1%以下。我在开发这个系统时重点考虑了三个核心需求首先是处方审核的严谨性系统需要内置药品配伍禁忌检查功能其次是库存管理的实时性要确保药品存量预警准确最后是配药流程的可追溯性所有操作必须记录完整日志。这些需求直接决定了技术栈的选择——SpringBoot提供了快速开发能力MySQL保证了数据可靠性而Thymeleaf模板引擎则实现了简洁的前后端交互。2. 技术架构设计2.1 SpringBoot框架选型选择SpringBoot 2.7.3版本当前LTS版本作为基础框架主要考虑其三大优势自动配置通过spring-boot-starter-web等starter简化了SSM框架的整合内嵌容器默认集成Tomcat可直接打包成可执行JAR生产就绪自带健康检查、指标监控等生产级特性关键POM依赖配置示例dependencies !-- Web基础 -- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-web/artifactId /dependency !-- 数据持久化 -- dependency groupIdorg.mybatis.spring.boot/groupId artifactIdmybatis-spring-boot-starter/artifactId version2.2.2/version /dependency dependency groupIdmysql/groupId artifactIdmysql-connector-java/artifactId scoperuntime/scope /dependency !-- 模板引擎 -- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-thymeleaf/artifactId /dependency /dependencies2.2 数据库设计采用MySQL 8.0作为主数据库设计时特别注意了医药行业的特殊需求药品表(medicine)CREATE TABLE medicine ( id int NOT NULL AUTO_INCREMENT COMMENT 药品ID, code varchar(20) NOT NULL COMMENT 药品编码, name varchar(50) NOT NULL COMMENT 通用名称, spec varchar(30) NOT NULL COMMENT 规格, unit varchar(10) NOT NULL COMMENT 单位, price decimal(10,2) NOT NULL COMMENT 单价, stock int NOT NULL DEFAULT 0 COMMENT 库存量, warning_value int DEFAULT NULL COMMENT 库存预警值, status tinyint NOT NULL DEFAULT 1 COMMENT 状态(1可用 0停用), PRIMARY KEY (id), UNIQUE KEY idx_code (code) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_0900_ai_ci;处方表(prescription)CREATE TABLE prescription ( id int NOT NULL AUTO_INCREMENT, patient_id varchar(20) NOT NULL COMMENT 患者ID, doctor_id int NOT NULL COMMENT 开方医生ID, create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, status tinyint NOT NULL DEFAULT 0 COMMENT 状态(0待审核 1已审核 2已配药), PRIMARY KEY (id) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_0900_ai_ci;处方明细表(prescription_detail)CREATE TABLE prescription_detail ( id int NOT NULL AUTO_INCREMENT, prescription_id int NOT NULL, medicine_id int NOT NULL, dosage varchar(20) NOT NULL COMMENT 用量, frequency varchar(20) NOT NULL COMMENT 频次, quantity int NOT NULL COMMENT 数量, notes varchar(100) DEFAULT NULL COMMENT 备注, PRIMARY KEY (id), KEY idx_prescription (prescription_id) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COLLATEutf8mb4_0900_ai_ci;3. 核心功能实现3.1 药品配伍禁忌检查在处方审核环节系统会自动检查药品间的配伍禁忌。我们建立了药品相互作用知识库表CREATE TABLE medicine_interaction ( medicine_id1 int NOT NULL, medicine_id2 int NOT NULL, interaction_type tinyint NOT NULL COMMENT 1禁忌 2慎用, description text NOT NULL COMMENT 相互作用说明, PRIMARY KEY (medicine_id1,medicine_id2) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4;对应的Java检查逻辑public class PrescriptionService { Autowired private MedicineInteractionMapper interactionMapper; public ListInteractionCheckResult checkInteractions(ListInteger medicineIds) { ListInteractionCheckResult results new ArrayList(); // 检查所有两两组合 for(int i0; imedicineIds.size(); i) { for(int ji1; jmedicineIds.size(); j) { MedicineInteraction interaction interactionMapper.selectByMedicines( medicineIds.get(i), medicineIds.get(j)); if(interaction ! null) { results.add(new InteractionCheckResult( medicineIds.get(i), medicineIds.get(j), interaction.getInteractionType(), interaction.getDescription() )); } } } return results; } }3.2 库存实时管理采用乐观锁解决并发库存更新问题Transactional public boolean deductStock(int medicineId, int quantity) { // 先查询当前库存和版本号 Medicine medicine medicineMapper.selectForUpdate(medicineId); if(medicine.getStock() quantity) { throw new BusinessException(库存不足); } // 更新库存带版本号校验 int affected medicineMapper.updateStock( medicineId, medicine.getStock() - quantity, medicine.getVersion()); if(affected 0) { throw new ConcurrentUpdateException(库存并发修改冲突); } // 记录库存变更日志 StockLog log new StockLog(); log.setMedicineId(medicineId); log.setChangeType(StockLog.CHANGE_TYPE_OUT); log.setQuantity(quantity); log.setRemarks(处方出库); stockLogMapper.insert(log); return true; }4. 系统特色功能4.1 智能配药提醒基于药品库存和处方频次分析系统会生成智能提醒public ListMedicineWarning generateWarnings() { ListMedicineWarning warnings new ArrayList(); // 检查库存预警 ListMedicine lowStockMedicines medicineMapper.selectLowStock(); lowStockMedicines.forEach(med - { warnings.add(new MedicineWarning( med.getId(), MedicineWarning.TYPE_LOW_STOCK, 药品库存不足当前剩余 med.getStock() )); }); // 检查近效期药品6个月内到期 ListMedicine expiringMedicines medicineMapper.selectExpiring(180); expiringMedicines.forEach(med - { warnings.add(new MedicineWarning( med.getId(), MedicineWarning.TYPE_EXPIRING, 药品即将过期到期日 med.getExpireDate() )); }); return warnings; }4.2 配药流程可视化使用Thymeleaf实现配药进度看板div classprogress-board div th:eachstep : ${steps} classprogress-step div classstep-header th:classappend${prescription.status step.status} ? completed : span th:text${step.name}/span span th:if${prescription.status step.status} classcurrent-indicator(当前)/span /div div th:if${step.actions} classstep-actions button th:eachaction : ${step.actions} th:text${action.name} th:onclick${action.script}/button /div /div /div5. 部署与调试5.1 多环境配置使用Spring Profile管理不同环境配置# application-dev.yml spring: datasource: url: jdbc:mysql://localhost:3306/pharmacy_dev username: devuser password: dev123 # application-prod.yml spring: datasource: url: jdbc:mysql://prod-db:3306/pharmacy_prod username: produser password: ${DB_PASSWORD}启动时指定profilejava -jar pharmacy.jar --spring.profiles.activeprod5.2 常见问题解决问题1MyBatis映射文件未加载症状报错Invalid bound statement (not found) 解决方案检查application.yml配置mybatis: mapper-locations: classpath:mapper/*.xml确保Mapper接口有Mapper注解或在启动类添加MapperScan问题2Thymeleaf模板缓存开发阶段建议关闭缓存spring: thymeleaf: cache: false问题3事务不生效确保启动类添加EnableTransactionManagement使用Transactional注解方法访问权限为public异常类型正确抛出默认只回滚RuntimeException6. 项目扩展建议移动端对接增加微信小程序接口支持患者查看处方进度RestController RequestMapping(/api/miniapp) public class MiniAppController { GetMapping(/prescription/{id}) public PrescriptionVO getPrescriptionStatus(PathVariable int id) { // 返回简化版的处方信息 } }智能推荐基于历史处方数据实现药品智能推荐public ListMedicine recommendMedicines(int doctorId, String diagnosis) { // 1. 提取诊断关键词 ListString keywords diagnosisAnalyzer.extractKeywords(diagnosis); // 2. 查询同类诊断的常用药品 return prescriptionMapper.selectCommonMedicines( doctorId, keywords); }报表分析集成EasyExcel实现数据导出GetMapping(/export) public void exportStockReport(HttpServletResponse response) { ListStockVO data stockService.generateReport(); response.setContentType(application/vnd.ms-excel); response.setHeader(Content-Disposition, attachment;filenamestock.xlsx); EasyExcel.write(response.getOutputStream(), StockVO.class) .sheet(库存报表) .doWrite(data); }在开发这个医药配药管理系统的过程中我特别体会到业务知识的重要性。比如最初设计药品库存表时没有考虑药品批号和效期管理后来通过请教药房工作人员才补充了这些关键字段。建议开发行业应用时一定要先深入了解业务场景而不是直接开始编码。