1. 项目概述:老年一站式服务平台的技术架构设计
这个基于Java SpringBoot+Vue3+MyBatis的全栈项目,是一个专门为老年人群体设计的综合性服务平台。我在实际开发这类系统时发现,老年服务类应用与传统管理系统有着显著差异——它需要更简单的交互逻辑、更直观的视觉呈现,同时又要保证后台业务处理的严谨性。这正是我们选择前后端分离架构的核心原因。
技术栈选型上,SpringBoot 2.7.x作为后端框架提供了完善的依赖管理和自动配置,Vue3的组合式API让前端组件开发更加灵活,MyBatis-Plus 3.5.x则简化了数据库操作。特别值得注意的是,我们在这个项目中采用了MySQL 8.0作为数据库,利用其JSON字段类型来存储老年人健康档案中的非结构化数据,这种设计在实际运行中表现非常出色。
需要模型API调用? 免费领10W Token,多模型网关一键接入 Claude、DeepSeek 等主流模型。
2. 环境搭建与工程初始化
2.1 后端工程配置
使用Spring Initializr创建项目时,我推荐勾选以下关键依赖:
- Spring Web (用于RESTful接口)
- MyBatis Framework (数据库持久层)
- MySQL Driver (数据库连接)
- Lombok (简化实体类代码)
bash复制# 通过命令行快速创建项目
curl https://start.spring.io/starter.zip \
-d dependencies=web,mybatis,mysql,lombok \
-d javaVersion=17 \
-d packaging=jar \
-d artifactId=elderly-service \
-o elderly-service-backend.zip
在application.yml中需要特别注意的配置项:
yaml复制spring:
datasource:
url: jdbc:mysql://localhost:3306/elderly_db?useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: yourpassword
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
mapper-locations: classpath:mapper/*.xml
configuration:
map-underscore-to-camel-case: true
2.2 前端工程搭建
Vue3项目的创建建议使用Vite作为构建工具,它能显著提升开发体验:
bash复制npm create vite@latest elderly-frontend --template vue-ts
cd elderly-frontend
npm install axios vue-router@4 pinia element-plus
对于老年用户界面的特殊处理,我们需要在main.ts中全局配置大字号和对比色:
typescript复制import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
const app = createApp(App)
app.use(ElementPlus, {
size: 'large',
zIndex: 3000
})
3. 核心功能模块实现
3.1 老年人健康档案管理
这是系统的核心模块,我们采用DDD领域驱动设计来组织代码结构。在MySQL中设计的health_record表包含以下关键字段:
sql复制CREATE TABLE `health_record` (
`id` bigint NOT NULL AUTO_INCREMENT,
`elderly_id` bigint NOT NULL COMMENT '老人ID',
`basic_info` json DEFAULT NULL COMMENT '基本信息JSON',
`medical_history` json DEFAULT NULL COMMENT '病史记录',
`medication` json DEFAULT NULL COMMENT '用药情况',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_elderly` (`elderly_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
对应的MyBatis动态SQL实现:
xml复制<update id="updateHealthRecord">
UPDATE health_record
<set>
<if test="basicInfo != null">basic_info = #{basicInfo},</if>
<if test="medicalHistory != null">medical_history = #{medicalHistory},</if>
<if test="medication != null">medication = #{medication}</if>
</set>
WHERE elderly_id = #{elderlyId}
</update>
3.2 服务预约系统
考虑到老年人操作习惯,我们设计了极简的预约流程。后端采用Spring的@Scheduled实现自动取消超时预约:
java复制@Scheduled(cron = "0 0/30 * * * ?")
public void cancelTimeoutReservations() {
LocalDateTime deadline = LocalDateTime.now().minusMinutes(30);
List<Reservation> timeoutList = reservationMapper.selectTimeoutReservations(deadline);
timeoutList.forEach(reservation -> {
reservation.setStatus(ReservationStatus.CANCELLED);
reservationMapper.updateById(reservation);
// 发送通知
notificationService.sendCancelNotice(reservation);
});
}
4. 前后端交互关键实现
4.1 跨域与安全配置
在后端SecurityConfig中需要特别为老年人常用的低版本浏览器做兼容配置:
java复制@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOriginPattern("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("GET");
config.addAllowedMethod("POST");
config.setMaxAge(3600L);
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
4.2 大文件上传优化
针对老年人可能上传的体检报告等大文件,我们采用分片上传策略:
vue复制<template>
<el-upload
:action="uploadUrl"
:before-upload="handleBeforeUpload"
:on-success="handleSuccess"
:data="uploadData"
:multiple="false"
:limit="1"
:file-list="fileList">
<el-button size="large" type="primary">点击上传</el-button>
</el-upload>
</template>
<script setup>
const chunkSize = 5 * 1024 * 1024 // 5MB
const handleBeforeUpload = (file) => {
if (file.size > chunkSize) {
return uploadChunks(file)
}
return true
}
</script>
5. 性能优化与特殊处理
5.1 老年人界面适配方案
我们在全局CSS中设置了老年人友好的默认样式:
css复制:root {
--elderly-font-size: 18px;
--elderly-line-height: 1.8;
}
body {
font-size: var(--elderly-font-size);
line-height: var(--elderly-line-height);
color: #333;
background-color: #f5f5f5;
}
button, input, select {
font-size: calc(var(--elderly-font-size) + 2px);
padding: 12px 24px;
}
5.2 数据库查询优化
针对老年人常用的历史记录查询,我们添加了以下索引并使用了MyBatis二级缓存:
java复制@CacheNamespace(implementation = MybatisRedisCache.class, eviction = MybatisRedisCache.class)
public interface HealthRecordMapper {
@Select("SELECT * FROM health_record WHERE elderly_id = #{elderlyId} ORDER BY create_time DESC")
@Options(useCache = true, flushCache = Options.FlushCachePolicy.FALSE)
List<HealthRecord> selectByElderlyId(@Param("elderlyId") Long elderlyId);
}
6. 部署与运维实践
6.1 生产环境配置
在application-prod.yml中我们采用了连接池优化配置:
yaml复制spring:
datasource:
hikari:
maximum-pool-size: 20
minimum-idle: 5
idle-timeout: 30000
max-lifetime: 1800000
connection-timeout: 30000
connection-test-query: SELECT 1
6.2 日志收集与分析
针对老年人操作行为分析,我们特别设计了操作日志埋点:
java复制@Aspect
@Component
public class OperationLogAspect {
@AfterReturning(pointcut = "@annotation(operationLog)", returning = "result")
public void afterReturning(JoinPoint joinPoint, OperationLog operationLog, Object result) {
HttpServletRequest request = ((ServletRequestAttributes)
RequestContextHolder.getRequestAttributes()).getRequest();
String ip = request.getRemoteAddr();
String method = request.getMethod();
String uri = request.getRequestURI();
// 记录老年人操作特征
OperationLogEntity log = new OperationLogEntity();
log.setOperationTime(LocalDateTime.now());
log.setOperationType(operationLog.value());
log.setUserAgent(request.getHeader("User-Agent"));
log.setOperationIp(ip);
logMapper.insert(log);
}
}
在实际部署时,我们发现老年用户多在早晨和傍晚活跃,因此设置了弹性扩缩容策略,在7-9点和18-20点自动增加服务器实例。这个项目让我深刻体会到,为特殊群体设计系统不仅需要技术能力,更需要对人性的理解和对细节的关注。比如我们在按钮设计上采用了高对比色彩,所有操作都提供明确的语音反馈,这些看似简单的改进却大幅提升了老年用户的使用体验。
