ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

SpringBoot+Vue轻量级实习生管理系统设计与实践

SpringBoot+Vue轻量级实习生管理系统设计与实践 1. 项目概述最近在帮一家中型互联网公司搭建实习生管理系统发现市面上很多现成方案要么功能臃肿要么扩展性差。于是基于SpringBootVue技术栈重新设计了一套轻量级解决方案目前已在生产环境稳定运行半年多。这个系统最核心的价值在于用最精简的代码实现了实习生全生命周期管理从入职到离职的所有关键环节都能高效处理。系统采用经典的三层架构设计前端Vue 3 Element Plus构建响应式界面后端Spring Boot 2.7 MyBatis Plus实现业务逻辑数据库MySQL 8.0提供数据存储特别在权限控制方面做了深度优化RBAC模型结合JWT认证确保不同角色HR、部门主管、实习生只能访问对应功能模块。系统日均处理300考勤记录性能测试QPS达到1200完全能满足200人规模企业的管理需求。2. 核心功能设计2.1 多维度实习生档案实习生信息表设计时特别考虑了扩展性CREATE TABLE trainee ( id varchar(20) NOT NULL COMMENT 学号入职年份生成, name varchar(50) NOT NULL, gender char(1) DEFAULT NULL, id_card varchar(18) DEFAULT NULL COMMENT 加密存储, school varchar(100) NOT NULL, major varchar(50) NOT NULL, education tinyint NOT NULL COMMENT 1本科 2硕士 3博士, mentor_id int DEFAULT NULL COMMENT 导师员工ID, department_id int NOT NULL, entry_date date NOT NULL, status tinyint NOT NULL DEFAULT 1 COMMENT 0离职 1在职, PRIMARY KEY (id), KEY idx_department (department_id) ) ENGINEInnoDB DEFAULT CHARSETutf8mb4关键设计点主键采用学校学号入职年份组合生成如ZJU_20231234_2023避免单纯自增ID的业务耦合身份证号等敏感信息使用AES加密存储建立部门索引加速查询实测数据量10万时查询速度提升8倍2.2 智能考勤模块考勤表设计支持多种打卡方式public class Attendance { private Long id; private String traineeId; private LocalDateTime checkIn; // 支持自动定位打卡 private LocalDateTime checkOut; private Integer lateMinutes; // 自动计算迟到分钟 private Integer earlyMinutes; // 早退分钟 private Integer status; // 0正常 1迟到 2早退 3缺勤 private String location; // GPS坐标/WiFi定位 private String deviceId; // 防代打卡 }实现细节采用Redis GEO处理位置校验误差范围50米内视为有效考勤异常自动触发邮件通知使用Spring Mail支持批量导入导出ExcelEasyExcel实现3. 技术实现关键点3.1 前后端分离架构后端API设计遵循RESTful规范RestController RequestMapping(/api/attendance) public class AttendanceController { GetMapping(/{id}) public ResultAttendanceVO getDetail(PathVariable String id) { // 参数校验逻辑 } PostMapping public ResultString create(Valid RequestBody AttendanceDTO dto) { // 业务处理 } GetMapping(/stats) public ResultAttendanceStatsVO getStats( RequestParam String department, RequestParam DateTimeFormat(patternyyyy-MM) String month) { // 统计逻辑 } }前端采用Axios封装请求const api axios.create({ baseURL: import.meta.env.VITE_API_URL, timeout: 10000, headers: { Authorization: Bearer ${getToken()} } }) // 请求拦截器 api.interceptors.request.use(config { if (!config.headers[Authorization]) { config.headers[Authorization] Bearer ${getToken()} } return config })3.2 性能优化实践缓存策略Cacheable(value trainee, key #id) public Trainee getById(String id) { return traineeMapper.selectById(id); } CacheEvict(value trainee, key #trainee.id) public void updateTrainee(Trainee trainee) { traineeMapper.updateById(trainee); }数据库查询优化select idselectWithDepartment resultMapTraineeResultMap SELECT t.*, d.name as department_name FROM trainee t LEFT JOIN department d ON t.department_id d.id WHERE t.status 1 if testdepartmentId ! null AND t.department_id #{departmentId} /if ORDER BY t.entry_date DESC LIMIT #{pageSize} OFFSET #{offset} /select4. 部署与运维方案4.1 生产环境配置Nginx反向代理配置示例upstream backend { server 127.0.0.1:8080; keepalive 32; } server { listen 80; server_name hr.example.com; location /api { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Connection ; } location / { root /var/www/frontend; try_files $uri $uri/ /index.html; } }4.2 监控方案Spring Boot Actuator配置management: endpoints: web: exposure: include: health,info,metrics endpoint: health: show-details: always metrics: enabled: truePrometheus监控指标采集Bean MeterRegistryCustomizerMeterRegistry metricsCommonTags() { return registry - registry.config().commonTags( application, intern-system ); }5. 踩坑经验总结跨域问题解决方案Configuration public class CorsConfig implements WebMvcConfigurer { Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping(/**) .allowedOrigins(*) .allowedMethods(*) .maxAge(3600); } }MyBatis批量插入优化Transactional public void batchInsert(ListTrainee list) { SqlSession session sqlSessionTemplate.getSqlSessionFactory() .openSession(ExecutorType.BATCH, false); try { TraineeMapper mapper session.getMapper(TraineeMapper.class); for (Trainee trainee : list) { mapper.insert(trainee); } session.commit(); } finally { session.close(); } }前端性能优化技巧// 使用虚拟滚动处理大数据列表 el-table :datatableData stylewidth: 100% height500 row-keyid :row-height60 :virtual-scrolltrue !-- 列定义 -- /el-table这套系统从设计到上线共迭代了3个版本最大的体会是合理的领域建模比技术选型更重要。比如最初将考勤和绩效强耦合导致后期扩展困难重构为独立模块后才实现灵活配置。建议在开发初期就做好领域划分避免后期大规模返工。
返回列表