SpringBoot+Vue疫情打卡系统开发实战

📅 2026/8/9 13:50:15
SpringBoot+Vue疫情打卡系统开发实战
1. 项目背景与核心价值疫情打卡健康评测系统是近年来高校计算机专业毕业设计的热门选题方向。这个基于SpringBootVue的全栈项目完美契合了后疫情时代的校园管理需求既具备实际应用价值又能全面考察学生的技术综合运用能力。我在指导毕业设计和企业级项目开发时发现这类系统有三个典型痛点一是前后端数据交互复杂二是健康状态算法设计缺乏专业依据三是权限控制粒度不足。本项目源码通过清晰的模块划分和详尽的接口文档为初学者提供了绝佳的学习范本。2. 技术架构解析2.1 后端技术栈SpringBoot 2.7.x作为后端框架其自动配置特性大幅简化了项目初始化工作。核心配置类SpringBootApplication中特别设置了时区参数SpringBootApplication public class HealthApplication { public static void main(String[] args) { TimeZone.setDefault(TimeZone.getTimeZone(Asia/Shanghai)); SpringApplication.run(HealthApplication.class, args); } }MyBatis-Plus 3.5.x作为ORM框架其强大的CRUD接口和条件构造器显著提升了开发效率。例如用户打卡记录的Mapper接口public interface CheckInMapper extends BaseMapperCheckIn { Select(SELECT * FROM check_in WHERE user_id #{userId} AND create_time BETWEEN #{start} AND #{end}) ListCheckIn selectByDateRange(Param(userId) Long userId, Param(start) LocalDateTime start, Param(end) LocalDateTime end); }2.2 前端技术栈Vue 3.x组合式API带来更好的代码组织方式。体温填报组件采用script setup语法script setup import { ref } from vue const temp ref(36.5) const submitTemp async () { await axios.post(/api/health/temp, { temperature: temp.value }) } /scriptElement Plus作为UI框架其表单验证功能在健康申报场景中尤为重要el-form :modelhealthForm :rulesrules el-form-item proptemperature label体温(℃) el-input v-model.numberhealthForm.temperature/el-input /el-form-item /el-form3. 数据库设计精要3.1 核心表结构用户表sys_user采用RBAC权限模型设计CREATE TABLE sys_user ( user_id bigint NOT NULL AUTO_INCREMENT, username varchar(50) NOT NULL COMMENT 学号/工号, password varchar(100) NOT NULL, real_name varchar(50) DEFAULT NULL, college varchar(50) DEFAULT NULL COMMENT 学院, class_name varchar(50) DEFAULT NULL COMMENT 班级, user_type tinyint DEFAULT 0 COMMENT 0学生 1教师 2管理员, PRIMARY KEY (user_id), UNIQUE KEY username (username) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4;健康打卡记录表health_check包含关键防疫指标CREATE TABLE health_check ( check_id bigint NOT NULL AUTO_INCREMENT, user_id bigint NOT NULL, temperature decimal(3,1) NOT NULL COMMENT 体温, symptom varchar(255) DEFAULT NULL COMMENT 症状JSON数组, location varchar(100) DEFAULT NULL COMMENT GPS位置, risk_area tinyint DEFAULT 0 COMMENT 是否去过风险地区, create_time datetime DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (check_id), KEY idx_user_time (user_id,create_time) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4;3.2 查询优化实践每日健康统计视图使用物化查询提升性能CREATE MATERIALIZED VIEW daily_health_stats REFRESH COMPLETE ON DEMAND AS SELECT DATE(create_time) as check_date, COUNT(*) as total, SUM(CASE WHEN temperature 37.3 THEN 1 ELSE 0 END) as fever_count, SUM(risk_area) as risk_count FROM health_check GROUP BY DATE(create_time);4. 核心业务实现4.1 健康状态评估算法采用加权评分模型计算健康指数public HealthEvaluation evaluateHealth(CheckInRecord record) { double score 100; // 体温权重40% if(record.getTemperature() 37.3) { score - (record.getTemperature() - 37.3) * 10; } // 症状权重30% if(!CollectionUtils.isEmpty(record.getSymptoms())) { score - record.getSymptoms().size() * 5; } // 风险地区权重30% if(record.isRiskAreaContact()) { score - 30; } return new HealthEvaluation( score, score 80 ? 健康 : score 60 ? 观察 : 危险 ); }4.2 定时任务设计使用Spring Scheduler实现未打卡提醒Scheduled(cron 0 0 20 * * ?) // 每晚8点执行 public void checkMissingReports() { LocalDate today LocalDate.now(); ListLong missingUsers userMapper.selectMissingReportUsers(today); missingUsers.forEach(userId - { String openid wechatMapper.selectOpenId(userId); wechatService.sendTemplateMsg(openid, 今日未健康打卡); }); }5. 接口文档规范采用Swagger UI实现API文档自动化关键配置Configuration EnableSwagger2 public class SwaggerConfig { Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage(com.health.web)) .paths(PathSelectors.any()) .build() .apiInfo(apiInfo()); } }健康打卡接口示例ApiOperation(提交健康信息) PostMapping(/checkin) public Result checkIn(RequestBody Valid HealthCheckForm form) { return healthService.processCheckIn(SecurityUtils.getUserId(), form); }6. 部署与运维要点6.1 多环境配置通过profile实现环境隔离# application-dev.yml server: port: 8080 datasource: url: jdbc:mysql://localhost:3306/health_dev username: devuser password: dev123 # application-prod.yml server: port: 80 datasource: url: jdbc:mysql://prod-db:3306/health_prod username: ${DB_USER} password: ${DB_PWD}6.2 前端打包优化配置vue.config.js实现生产环境优化module.exports { chainWebpack: config { config.optimization.minimize(true); config.optimization.splitChunks({ chunks: all, maxSize: 244 * 1024 // 拆分包大小 }); }, productionSourceMap: false }7. 常见问题排查7.1 跨域问题解决方案后端配置CORS过滤器Bean public CorsFilter corsFilter() { UrlBasedCorsConfigurationSource source new UrlBasedCorsConfigurationSource(); CorsConfiguration config new CorsConfiguration(); config.addAllowedOriginPattern(*); config.addAllowedHeader(*); config.addAllowedMethod(*); config.setAllowCredentials(true); source.registerCorsConfiguration(/**, config); return new CorsFilter(source); }7.2 日期时间处理统一使用Java 8时间API并配置全局格式化Configuration public class WebMvcConfig implements WebMvcConfigurer { Override public void addFormatters(FormatterRegistry registry) { DateTimeFormatterRegistrar registrar new DateTimeFormatterRegistrar(); registrar.setUseIsoFormat(true); registrar.registerFormatters(registry); } }8. 项目扩展方向8.1 微信小程序集成通过uni-app实现多端兼容// 封装打卡接口 export function submitHealth(data) { return uni.request({ url: /api/miniapp/checkin, method: POST, header: { Content-Type: application/json, Authorization: uni.getStorageSync(token) }, data }); }8.2 大数据分析模块使用Elasticsearch存储海量打卡记录Repository public interface HealthCheckRepository extends ElasticsearchRepositoryHealthCheckEs, Long { ListHealthCheckEs findByUserIdAndCheckTimeBetween(Long userId, Date start, Date end); Query({\bool\:{\must\:[{\range\:{\temperature\:{\gt\:37.3}}}]}}) PageHealthCheckEs findFeverRecords(Pageable pageable); }在项目开发过程中特别要注意前后端数据格式的严格约定。建议采用统一的响应体结构public class ResultT implements Serializable { private int code; private String msg; private T data; public static T ResultT success(T data) { return new Result(200, 成功, data); } }对于高频访问的健康状态查询接口建议采用Redis缓存策略Cacheable(value healthStatus, key #userId_#date.format(dateFormatter)) public HealthStatus getDailyStatus(Long userId, LocalDate date) { // 数据库查询逻辑 }