基于架构的社区宠物疫苗接种管理系统设计实现
一、 项目背景与意义随着城市化进程加快和居民生活水平提高饲养宠物已成为许多家庭生活的重要组成部分。然而宠物数量的激增也带来了公共卫生管理上的新挑战其中宠物疫苗接种是预防狂犬病、犬瘟热等烈性传染病、保障社区公共卫生安全的关键环节。目前许多社区在宠物疫苗接种管理上仍依赖纸质登记、人工通知等传统方式存在信息记录分散、查询统计困难、接种提醒不及时、数据无法共享等问题。这不仅增加了基层工作人员的工作负担也导致宠物免疫覆盖率难以有效提升存在公共卫生安全隐患。因此设计并实现一套基于架构的社区宠物疫苗接种管理系统具有重要的现实意义提升管理效率实现宠物信息、疫苗库存、接种记录的数字化管理自动化生成统计报表。保障接种率通过系统自动发送接种提醒短信、小程序消息减少漏打、迟打情况。加强数据联动为城市级宠物管理平台、动物疫病防控中心提供数据接口实现信息共享与协同。服务社区居民为宠物主提供便捷的在线预约、接种记录查询、知识科普等服务提升社区治理现代化水平。二、 系统技术栈选型本系统采用前后端分离的微服务架构确保系统的高可用性、可扩展性和易维护性。2.1 后端技术栈核心框架Spring Boot 2.7.x安全框架Spring Security JWT数据持久层MyBatis-Plus数据库MySQL 8.0主业务数据Redis 7.x缓存与SessionAPI文档Knife4j (Swagger增强)消息队列RabbitMQ用于异步处理接种提醒、日志记录服务注册与发现Nacos配置中心Nacos ConfigAPI网关Spring Cloud Gateway服务调用OpenFeign分布式事务Seata2.2 前端技术栈管理后台Vue 3 Element Plus TypeScript Vite社区居民端微信小程序Uni-app框架2.3 运维与部署容器化Docker Docker Compose持续集成/持续部署Jenkins监控Spring Boot Admin, Prometheus Grafana三、 系统架构设计系统采用清晰的四层架构确保职责分离与模块化。3.1 整体架构图flowchart TD subgraph Client [客户端] A[微信小程序] B[管理后台Web] end subgraph Gateway [网关层] C[Spring Cloud Gateway] end subgraph Microservices [微服务层] D[用户服务] E[宠物档案服务] F[疫苗库存服务] G[接种预约服务] H[消息通知服务] end subgraph Infrastructure [基础设施层] I[(MySQL)] J[(Redis)] K[(Nacos)] L{{RabbitMQ}} end A B -- C C -- D E F G H D E F G H -- I J H -- L D E F G H -.- K/code/pre 3.2 核心模块划分 用户服务负责社区居民、社区工作人员、系统管理员的身份认证、权限管理。 宠物档案服务管理宠物基本信息品种、年龄、照片、主人信息及历史接种记录。 疫苗库存服务管理疫苗的入库、出库、库存预警、批次与有效期管理。 接种预约服务处理居民的在线预约、接种排期、接种记录生成与状态更新。 消息通知服务集成短信、小程序模板消息发送预约成功、接种提醒、库存预警等通知。 四、 核心功能与数据库设计 4.1 核心功能流程 宠物建档居民通过小程序提交宠物信息社区工作人员审核后生成电子档案。 疫苗预约居民查看可预约的疫苗种类与时间提交预约申请。 接种执行工作人员在管理后台确认预约扫描疫苗批次码系统自动扣减库存并生成接种记录。 提醒与反馈系统根据宠物年龄和上次接种时间自动计算并推送下次接种提醒。居民可对服务进行评价。 4.2 核心表结构部分 -- 宠物信息表 CREATE TABLE pet_info ( id bigint NOT NULL AUTO_INCREMENT COMMENT 主键, pet_name varchar(50) NOT NULL COMMENT 宠物名称, pet_type tinyint NOT NULL COMMENT 宠物类型 1:犬 2:猫, breed varchar(100) DEFAULT NULL COMMENT 品种, birth_date date DEFAULT NULL COMMENT 出生日期, owner_id bigint NOT NULL COMMENT 主人ID, avatar_url varchar(500) DEFAULT NULL COMMENT 头像URL, create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, update_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY idx_owner_id (owner_id) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COMMENT宠物信息表; -- 疫苗接种记录表 CREATE TABLE vaccination_record ( id bigint NOT NULL AUTO_INCREMENT COMMENT 主键, pet_id bigint NOT NULL COMMENT 宠物ID, vaccine_id bigint NOT NULL COMMENT 疫苗ID, batch_no varchar(100) NOT NULL COMMENT 疫苗批次号, inoculation_date date NOT NULL COMMENT 接种日期, next_due_date date DEFAULT NULL COMMENT 下次应接种日期, operator_id bigint DEFAULT NULL COMMENT 操作员ID, status tinyint NOT NULL DEFAULT 1 COMMENT 状态 1:有效 0:作废, create_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY idx_pet_id (pet_id), KEY idx_vaccine_id (vaccine_id) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4 COMMENT疫苗接种记录表; 五、 核心代码实现示例 5.1 接种预约服务核心逻辑Java package com.community.pet.vaccination.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.community.pet.vaccination.dto.AppointmentDTO; import com.community.pet.vaccination.entity.VaccineInventory; import com.community.pet.vaccination.entity.VaccinationAppointment; import com.community.pet.vaccination.exception.BusinessException; import com.community.pet.vaccination.mapper.VaccineInventoryMapper; import com.community.pet.vaccination.mapper.VaccinationAppointmentMapper; import com.community.pet.vaccination.service.AppointmentService; import com.community.pet.vaccination.service.MessageService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.time.LocalDateTime; /** 接种预约服务实现 */ Slf4j Service RequiredArgsConstructor public class AppointmentServiceImpl implements AppointmentService { private final VaccinationAppointmentMapper appointmentMapper; private final VaccineInventoryMapper inventoryMapper; private final MessageService messageService; Override Transactional(rollbackFor Exception.class) public Long createAppointment(AppointmentDTO dto) { // 1. 校验宠物是否存在且属于当前用户略 // 2. 校验疫苗库存是否充足 VaccineInventory inventory inventoryMapper.selectById(dto.getVaccineId()); if (inventory null || inventory.getAvailableStock() 1) { throw new BusinessException(所选疫苗库存不足); } if (inventory.getExpiryDate().isBefore(LocalDate.now().plusDays(7))) { throw new BusinessException(该批次疫苗即将过期暂不可预约); } // 3. 创建预约记录 VaccinationAppointment appointment new VaccinationAppointment(); appointment.setPetId(dto.getPetId()); appointment.setVaccineId(dto.getVaccineId()); appointment.setAppointmentDate(dto.getAppointmentDate()); appointment.setStatus(0); // 0:待确认 appointment.setCreateTime(LocalDateTime.now()); appointmentMapper.insert(appointment); // 4. 预扣库存乐观锁 int updateCount inventoryMapper.deductStock(dto.getVaccineId(), 1); if (updateCount 0) { throw new BusinessException(库存扣减失败请重试); } // 5. 异步发送预约成功通知 messageService.sendAppointmentSuccessMsg(appointment.getId(), dto.getUserId()); log.info(接种预约创建成功预约ID: {}, appointment.getId()); return appointment.getId(); } Override public void confirmAppointment(Long appointmentId, Long operatorId) { VaccinationAppointment appointment appointmentMapper.selectById(appointmentId); if (appointment null || appointment.getStatus() ! 0) { throw new BusinessException(预约记录无效或状态异常); } appointment.setStatus(1); // 1:已确认 appointment.setOperatorId(operatorId); appointment.setConfirmTime(LocalDateTime.now()); appointmentMapper.updateById(appointment); // 触发接种记录生成逻辑可放入消息队列异步处理 // ... } } 5.2 接种提醒定时任务Spring Scheduler package com.community.pet.vaccination.job; import com.community.pet.vaccination.entity.VaccinationRecord; import com.community.pet.vaccination.mapper.VaccinationRecordMapper; import com.community.pet.vaccination.service.MessageService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.time.LocalDate; import java.util.List; /** 疫苗接种提醒定时任务 */ Slf4j Component RequiredArgsConstructor public class VaccinationReminderJob { private final VaccinationRecordMapper recordMapper; private final MessageService messageService; /** 每天上午9点执行检查未来7天内需要接种的宠物 */ Scheduled(cron 0 0 9 * * ?) public void checkUpcomingVaccinations() { LocalDate checkDate LocalDate.now().plusDays(7); ListVaccinationRecord records recordMapper.selectDueRecords(checkDate); if (records.isEmpty()) { log.info(未找到未来7天内需接种的宠物记录); return; } for (VaccinationRecord record : records) { try { messageService.sendVaccinationReminder(record.getPetId(), record.getNextDueDate()); log.debug(已发送接种提醒宠物ID: {}, 应接种日期: {}, record.getPetId(), record.getNextDueDate()); } catch (Exception e) { log.error(发送接种提醒失败宠物ID: {}, record.getPetId(), e); } } log.info(接种提醒任务执行完毕共处理{}条记录, records.size()); } } 5.3 疫苗库存预警Vue 3 Element Plus 组件示例 template div classvaccine-inventory el-card header疫苗库存看板 el-table :datainventoryList stylewidth: 100% el-table-column propvaccineName label疫苗名称 width180 / el-table-column propbatchNo label批次号 width120 / el-table-column propexpiryDate label有效期至 width120 template #defaultscope span :class{ expiring-soon: isExpiringSoon(scope.row.expiryDate) } {{ formatDate(scope.row.expiryDate) }} /span /template /el-table-column el-table-column propavailableStock label可用库存 width100 template #defaultscope el-tag :typegetStockTagType(scope.row.availableStock) {{ scope.row.availableStock }} /el-tag /template /el-table-column el-table-column propaction label操作 width150 template #defaultscope el-button sizesmall clickhandleReplenish(scope.row)补货/el-button el-button sizesmall typewarning clickhandleDetail(scope.row)详情/el-button /template /el-table-column /el-table /el-card /div /template script setup langts import { ref, onMounted } from vue import { ElMessage } from element-plus import { getVaccineInventory } from /api/inventory import type { VaccineInventoryVO } from /types/inventory const inventoryList refVaccineInventoryVO[]([]) const loadInventoryData async () { try { const { data } await getVaccineInventory() inventoryList.value data } catch (error) { ElMessage.error(获取库存数据失败) } } const isExpiringSoon (expiryDate: string) { const date new Date(expiryDate) const now new Date() const diffDays Math.ceil((date.getTime() - now.getTime()) / (1000 * 3600 * 24)) return diffDays 30 // 30天内过期 } const getStockTagType (stock: number) { if (stock 10) return danger if (stock 30) return warning return success } const handleReplenish (row: VaccineInventoryVO) { // 打开补货对话框 console.log(补货, row) } const handleDetail (row: VaccineInventoryVO) { // 查看详情 console.log(详情, row) } onMounted(() { loadInventoryData() }) /script style scoped .expiring-soon { color: #e6a23c; font-weight: bold; } /style 六、 总结与展望 本文详细阐述了一个基于微服务架构的社区宠物疫苗接种管理系统的设计与实现。系统通过Spring Cloud技术栈实现了服务化拆分利用微信小程序与Vue管理后台覆盖了居民与工作人员两端并通过自动化提醒与库存预警机制提升了管理效率与接种覆盖率。 未来可扩展方向 大数据分析集成数据仓库对区域接种率、疫苗效力、宠物健康趋势进行分析与可视化。 物联网集成连接智能项圈、宠物芯片阅读器自动识别宠物并同步健康数据。 AI应用利用图像识别技术辅助宠物品种鉴定、健康状态初步评估。 跨平台扩展开发独立的移动App并考虑与政府“一网通办”平台对接。