3 天以前 b852254d90e7d1955db31db154193ec8ee84d8b3
yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/approval/listener/HrmResignationApplicationStatusListener.java
@@ -2,7 +2,9 @@
import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent;
import cn.iocoder.yudao.module.hrm.dal.dataobject.approval.HrmResignationApplicationDO;
import cn.iocoder.yudao.module.hrm.dal.dataobject.employee.HrmEmployeeDO;
import cn.iocoder.yudao.module.hrm.dal.mysql.approval.HrmResignationApplicationMapper;
import cn.iocoder.yudao.module.hrm.dal.mysql.employee.HrmEmployeeMapper;
import cn.iocoder.yudao.module.hrm.enums.HrmAuditStatusEnum;
import cn.iocoder.yudao.module.hrm.service.approval.HrmResignationApplicationService;
import cn.iocoder.yudao.module.hrm.util.HrmAuditStatusUtils;
@@ -14,16 +16,23 @@
/**
 * 离职申请审批的结果监听器实现类
 *
 * @author 芋道源码
 * @author 超级管理员
 */
@Component
@Slf4j
public class HrmResignationApplicationStatusListener implements ApplicationListener<BpmProcessInstanceStatusEvent> {
    /**
     * 员工状态:离职
     */
    private static final Integer EMPLOYEE_STATUS_RESIGNED = 3;
    @Resource
    private HrmResignationApplicationService resignationApplicationService;
    @Resource
    private HrmResignationApplicationMapper resignationApplicationMapper;
    @Resource
    private HrmEmployeeMapper employeeMapper;
    @Override
    public void onApplicationEvent(BpmProcessInstanceStatusEvent event) {
@@ -50,6 +59,25 @@
        // 更新审批状态
        Integer auditStatus = HrmAuditStatusUtils.convertBpmResultToAuditStatus(event.getStatus());
        resignationApplicationService.updateResignationApplicationAuditStatus(applicationId, auditStatus);
        // 审批通过:回写员工主档(状态=离职,离职日期 = 实际离职日期或预计离职日期)
        if (HrmAuditStatusEnum.APPROVE.getStatus().equals(auditStatus)) {
            writeBackEmployee(application);
        }
    }
    private void writeBackEmployee(HrmResignationApplicationDO application) {
        HrmEmployeeDO employee = employeeMapper.selectByUserId(application.getUserId());
        if (employee == null) {
            log.warn("[writeBackEmployee] 离职申请({}) 用户({}) 未找到员工档案,跳过回写", application.getId(), application.getUserId());
            return;
        }
        java.time.LocalDate leaveDate = application.getActualDate() != null
                ? application.getActualDate() : application.getExpectedDate();
        employeeMapper.updateById(HrmEmployeeDO.builder()
                .id(employee.getId())
                .employeeStatus(EMPLOYEE_STATUS_RESIGNED)
                .leaveDate(leaveDate)
                .build());
    }
}