liyong
2026-07-10 80ddf4c9c0bcb0f6c31524e0d9f5599c8001e904
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cn.iocoder.yudao.module.hrm.service.attendance.listener;
 
import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent;
import cn.iocoder.yudao.module.hrm.dal.dataobject.attendance.HrmAttendanceExceptionDO;
import cn.iocoder.yudao.module.hrm.dal.mysql.attendance.HrmAttendanceExceptionMapper;
import cn.iocoder.yudao.module.hrm.enums.HrmAuditStatusEnum;
import cn.iocoder.yudao.module.hrm.enums.HrmAttendanceExceptionTypeEnum;
import cn.iocoder.yudao.module.hrm.service.attendance.HrmAttendanceExceptionService;
import cn.iocoder.yudao.module.hrm.service.attendance.HrmAttendanceRecordService;
import cn.iocoder.yudao.module.hrm.util.HrmAuditStatusUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
 
/**
 * 考勤异常申请审批的结果监听器实现类
 *
 * @author 芋道源码
 */
@Component
@Slf4j
public class HrmAttendanceExceptionStatusListener implements ApplicationListener<BpmProcessInstanceStatusEvent> {
 
    @Resource
    private HrmAttendanceExceptionService attendanceExceptionService;
    @Resource
    private HrmAttendanceExceptionMapper attendanceExceptionMapper;
    @Resource
    private HrmAttendanceRecordService attendanceRecordService;
 
    @Override
    public void onApplicationEvent(BpmProcessInstanceStatusEvent event) {
        // 通过 businessKey 查询考勤异常申请
        Long exceptionId;
        try {
            exceptionId = Long.parseLong(event.getBusinessKey());
        } catch (NumberFormatException e) {
            return;
        }
 
        HrmAttendanceExceptionDO exception = attendanceExceptionMapper.selectById(exceptionId);
        if (exception == null) {
            return;
        }
 
        // 只有审批中状态的考勤异常申请才处理
        if (!HrmAuditStatusEnum.PROCESS.getStatus().equals(exception.getStatus())) {
            log.warn("[onApplicationEvent] 考勤异常申请({}) 不处于审批中状态,当前状态: {}", exceptionId, exception.getStatus());
            return;
        }
 
        log.info("[onApplicationEvent] 考勤异常申请({}) 审批状态更新: {}", exceptionId, event.getStatus());
        // 转换审批状态
        Integer auditStatus = HrmAuditStatusUtils.convertBpmResultToAuditStatus(event.getStatus());
        // 更新审批状态
        attendanceExceptionService.updateAttendanceExceptionAuditStatus(exceptionId, auditStatus);
 
        // 补卡审批通过后,更新考勤记录
        if (HrmAttendanceExceptionTypeEnum.SUPPLEMENT.getType().equals(exception.getType())
                && HrmAuditStatusEnum.APPROVE.getStatus().equals(auditStatus)) {
            log.info("[onApplicationEvent] 补卡申请({}) 审批通过,开始更新考勤记录", exceptionId);
            attendanceRecordService.supplementClockIn(exception);
        }
    }
 
}