考勤管理系统是现代企业数字化转型的基础设施之一。作为一名经历过多次考勤系统迭代开发的工程师,我深知传统纸质考勤的痛点:月底统计时人事部门加班核对表格、员工代打卡屡禁不止、请假调休记录混乱等。这套基于SpringBoot+Vue的解决方案,正是针对这些痛点设计的轻量级实现。
系统采用前后端分离架构,后端使用SpringBoot 2.7提供RESTful API,前端采用Vue 3组合式API开发管理界面,数据库选用MySQL 8.0。我在开发过程中特别注重三个核心体验:考勤打卡的响应速度控制在300ms内、管理端报表生成支持10万级数据秒开、移动端适配率达到100%。
SpringBoot框架的选择基于以下考量:
关键依赖配置示例:
xml复制<dependencies>
<!-- 持久层 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.3</version>
</dependency>
<!-- 安全控制 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- 接口文档 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
Vue 3的组合式API相比Options API更适合考勤系统这类表单密集型的应用:
性能优化措施:
通过H5 Geolocation API获取用户坐标后,后端使用JTS库进行多边形包含判断:
java复制// 围栏坐标校验逻辑
public boolean checkInRange(Point userPoint) {
GeometryFactory geometryFactory = new GeometryFactory();
Polygon fenceArea = geometryFactory.createPolygon(fenceCoordinates);
return fenceArea.contains(userPoint);
}
采用OpenCV的LBPH算法实现基础人脸比对:
请假审批采用状态机模式设计:
mermaid复制stateDiagram
[*] --> PENDING
PENDING --> APPROVED: 主管审批
PENDING --> REJECTED: 主管驳回
APPROVED --> COMPLETED: 考勤同步
考勤记录表按月分表,命名规则为attendance_[year][month]。使用MyBatis拦截器实现动态表名切换:
java复制@Intercepts({
@Signature(type= StatementHandler.class,
method="prepare",
args={Connection.class, Integer.class})
})
public class TableSplitInterceptor implements Interceptor {
// 解析SQL替换表名逻辑...
}
高频查询字段索引配置:
sql复制-- 员工考勤查询索引
CREATE INDEX idx_employee_attendance
ON attendance_202307(employee_id, attendance_date);
-- 部门统计索引
CREATE INDEX idx_department_stats
ON employee(department_code, hire_date);
采用Nginx+Keepalived实现负载均衡:
code复制upstream backend {
server 192.168.1.100:8080 weight=5;
server 192.168.1.101:8080 weight=5;
check interval=3000 rise=2 fall=3 timeout=1000;
}
Prometheus监控指标示例:
yaml复制- job_name: 'attendance_app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['localhost:8080']
可能原因及解决方案:
处理方案:
java复制// 使用游标分批处理
try (Cursor<Attendance> cursor = attendanceMapper.scan()) {
while (cursor.hasNext()) {
processRecord(cursor.next());
}
}
实际开发中发现,考勤时间计算要特别注意时区问题。建议在数据库存储UTC时间,前端按用户所在时区显示。我在处理跨国企业项目时,曾因时区配置错误导致全员考勤异常,这个教训值得分享。