在现代企业管理中,考勤管理是人力资源工作的重要环节。传统的人工考勤方式存在数据分散、统计效率低、易出错等问题,迫切需要数字化解决方案。本文将详细介绍一个企业级智能考勤管理平台的技术实现方案。
系统架构与技术栈
该平台采用经典的SSM(Spring + Spring MVC + MyBatis)三层架构,结合Maven进行项目依赖管理。前端使用JSP结合Bootstrap框架构建响应式界面,jQuery处理客户端交互逻辑。
核心依赖配置:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
</dependencies>
Spring框架作为IoC容器,管理业务对象的生命周期和依赖注入,通过声明式事务管理确保数据操作的一致性。Spring MVC负责Web请求的分发和处理,MyBatis作为持久层框架,提供灵活的SQL映射能力。
数据库设计亮点
考勤报表统计表设计
report_info表的设计体现了数据聚合和统计的优化思路:
CREATE TABLE `report_info` (
`REPORT_ID` int(11) NOT NULL AUTO_INCREMENT COMMENT '报表ID',
`create_date` date DEFAULT NULL COMMENT '创建时间',
`DEPARTMENT_ID` int(11) DEFAULT NULL COMMENT '部门ID',
`DEPARTMENT_NAME` varchar(255) DEFAULT NULL COMMENT '部门名称',
`DAY_LATE_COUNT` int(10) DEFAULT NULL COMMENT '部门当天迟到人次统计',
`DAY_EARLY_COUNT` int(10) DEFAULT NULL COMMENT '部门当天早退人次统计',
`MONTH_LATE_COUNT` int(10) DEFAULT NULL COMMENT '部门当月迟到人次统计',
`MONTH_EARLY_COUNT` int(10) DEFAULT NULL COMMENT '部门当月早退人次统计',
`YEAR_LATE_COUNT` int(10) DEFAULT NULL COMMENT '部门当年迟到人次统计',
`YEAR_EARLY_COUNT` int(10) DEFAULT NULL COMMENT '部门当年迟到人次统计',
PRIMARY KEY (`REPORT_ID`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT
设计亮点分析:
- 采用多时间维度统计(日、月、年),支持灵活的报表查询
- 使用BTREE索引优化查询性能
- 部门名称冗余存储,避免联表查询,提升统计效率
- 自增主键确保数据插入顺序和性能
请假记录表的事务完整性
leave_record表的设计重点考虑了业务流程的完整性:
CREATE TABLE `leave_record` (
`RECORD_ID` int(11) NOT NULL AUTO_INCREMENT COMMENT '记录编号',
`DEPARTMENT_ID` int(11) DEFAULT NULL COMMENT '部门编号',
`STAFF_ID` varchar(11) DEFAULT NULL COMMENT '员工编号',
`HANIN_TIME` datetime DEFAULT NULL COMMENT '申请时间',
`LEAVE_START_TIME` datetime DEFAULT NULL COMMENT '假期开始时间',
`LEAVE_END_TIME` datetime DEFAULT NULL COMMENT '假期结束时间',
`APPLICATION_STATE` varchar(255) DEFAULT NULL COMMENT '申请状态0.待审核1.通过2.不通过',
`REASON` varchar(255) DEFAULT NULL COMMENT '请假事由',
`REPLY` varchar(255) DEFAULT NULL COMMENT '审批片语',
`HANDLE_TIME` datetime DEFAULT NULL COMMENT '处理时间',
PRIMARY KEY (`RECORD_ID`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT
该表通过状态字段和审批时间戳完整记录了请假审批的全流程,确保数据可追溯。
核心功能实现
员工信息分页管理
系统采用标准的分页查询模式处理员工信息展示:
@Controller
@RequestMapping("/admin")
public class AdminController {
@Resource(name = "staffCustomServiceImpl")
private StaffCustomService staffCustomService;
@RequestMapping("/showStaff")
public String showStudent(Model model, Integer page) throws Exception {
List<StaffCustom> list = null;
//页码对象
PagingVO pagingVO = new PagingVO();
//设置总页数
pagingVO.setTotalCount(staffCustomService.getStaffCount());
if (page == null || page == 0) {
pagingVO.setToPageNo(1);
list = staffCustomService.findByPaging(1);
} else {
pagingVO.setToPageNo(page);
list = staffCustomService.findByPaging(page);
}
model.addAttribute("staffList", list);
model.addAttribute("pagingVO", pagingVO);
return "/admin/showStaff";
}
}
对应的MyBatis分页查询实现:
<select id="findByPaging" parameterType="Integer" resultMap="StaffResult">
SELECT * FROM staff
LIMIT #{pageSize} OFFSET #{offset}
</select>

考勤签到业务逻辑
员工签到功能包含完整的业务验证逻辑:
@Service
public class AttendanceServiceImpl implements AttendanceService {
@Override
public AttendanceRecord signIn(String staffId, Date signTime) {
// 检查今日是否已签到
AttendanceRecord todayRecord = attendanceMapper.selectTodayRecord(staffId);
if (todayRecord != null) {
throw new BusinessException("今日已签到,请勿重复操作");
}
// 计算是否迟到
boolean isLate = calculateIsLate(signTime);
AttendanceRecord record = new AttendanceRecord();
record.setStaffId(staffId);
record.setSignInTime(signTime);
record.setIsLate(isLate ? 1 : 0);
record.setCreateTime(new Date());
attendanceMapper.insert(record);
return record;
}
private boolean calculateIsLate(Date signTime) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(signTime);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
// 标准上班时间9:00
return hour > 9 || (hour == 9 && minute > 0);
}
}

请假审批工作流
请假审批采用状态机模式管理业务流程:
@Controller
@RequestMapping("/manager")
public class LeaveApprovalController {
@RequestMapping("/approveLeave")
@ResponseBody
public Map<String, Object> approveLeave(
@RequestParam Integer recordId,
@RequestParam Integer approveResult,
@RequestParam String reply) {
Map<String, Object> result = new HashMap<>();
try {
LeaveRecord record = leaveService.getRecordById(recordId);
if (record.getApplicationState().equals("0")) {
record.setApplicationState(approveResult == 1 ? "1" : "2");
record.setReply(reply);
record.setHandleTime(new Date());
leaveService.updateRecord(record);
// 发送通知
notificationService.sendLeaveResult(record.getStaffId(), approveResult);
result.put("success", true);
result.put("message", "审批操作成功");
} else {
result.put("success", false);
result.put("message", "该申请已被处理");
}
} catch (Exception e) {
result.put("success", false);
result.put("message", "审批操作失败");
}
return result;
}
}

统计报表生成
系统提供多维度考勤统计功能:
@Service
public class ReportServiceImpl implements ReportService {
@Override
public ReportInfo generateDepartmentReport(Integer departmentId, Date reportDate) {
ReportInfo report = new ReportInfo();
report.setCreateDate(new Date());
report.setDepartmentId(departmentId);
report.setDepartmentName(departmentService.getNameById(departmentId));
// 日统计
report.setDayLateCount(attendanceMapper.countLateByDepartment(departmentId, reportDate));
report.setDayEarlyCount(attendanceMapper.countEarlyByDepartment(departmentId, reportDate));
// 月统计
Date monthStart = getMonthStart(reportDate);
Date monthEnd = getMonthEnd(reportDate);
report.setMonthLateCount(attendanceMapper.countLateByDepartmentRange(
departmentId, monthStart, monthEnd));
report.setMonthEarlyCount(attendanceMapper.countEarlyByDepartmentRange(
departmentId, monthStart, monthEnd));
reportMapper.insert(report);
return report;
}
}

实体模型设计
系统采用面向对象的设计思想,核心实体模型如下:
public class StaffCustom extends Staff {
private String departmentName;
private String roleName;
// 省略getter/setter
}
public class PagingVO {
private Integer toPageNo = 1; // 当前页码
private Integer pageSize = 10; // 每页显示数量
private Integer totalCount; // 总记录数
private Integer totalPage; // 总页数
public Integer getTotalPage() {
return totalCount % pageSize == 0 ?
totalCount / pageSize : totalCount / pageSize + 1;
}
}
功能展望与优化
1. 引入Redis缓存优化
@Service
public class DepartmentServiceWithCache {
@Autowired
private RedisTemplate<String, Department> redisTemplate;
public Department getById(Integer id) {
String cacheKey = "department:" + id;
Department department = redisTemplate.opsForValue().get(cacheKey);
if (department == null) {
department = departmentMapper.selectById(id);
redisTemplate.opsForValue().set(cacheKey, department, 30, TimeUnit.MINUTES);
}
return department;
}
}
2. 微服务架构改造
将系统拆分为用户服务、考勤服务、审批服务等微服务,通过Spring Cloud实现服务治理和链路追踪。
3. 移动端适配
开发React Native或Flutter移动应用,支持移动端签到、请假申请等功能。
4. 实时消息推送
集成WebSocket实现实时消息推送,及时通知审批结果和系统公告。
5. 大数据分析集成
将考勤数据同步到数据仓库,使用ELK栈或ClickHouse进行深度数据分析和可视化。
总结
该企业级智能考勤管理平台通过SSM框架的合理运用,实现了稳定可靠的考勤管理功能。数据库设计考虑了业务扩展性和查询性能,代码结构清晰易于维护。系统支持多角色协同工作,提供了完整的考勤管理解决方案。未来通过引入缓存、微服务等现代技术栈,可以进一步提升系统性能和用户体验。