package com.yh.saas.plugin.yiliangyiyun.workflow;

import com.yh.saas.common.support.workflow.AbstractWorkflowTaskListener;
import com.yh.saas.common.support.workflow.annotation.WorkflowTaskListener;
import com.yh.saas.plugin.yiliangyiyun.constant.StatusEnum;
import com.yh.saas.plugin.yiliangyiyun.entity.ClockInfo;
import com.yh.saas.plugin.yiliangyiyun.service.IClockInfoService;
import org.springframework.beans.factory.annotation.Autowired;

@WorkflowTaskListener(name = "考勤管理", group = "补卡管理")
public class BukaListener extends AbstractWorkflowTaskListener {

    private static final long serialVersionUID = 4103656734835351132L;

    @Autowired
    private IClockInfoService clockInfoService;

    @Override
    public void handleStatusChanged(String businessKey, String status, String statusEn, boolean processIsEnd) {
        ClockInfo clockInfo = clockInfoService.selectById(businessKey);
        if (clockInfo == null) {
            return;
        }
        if (processIsEnd) {
            clockInfo.setStatusFlag(StatusEnum.SUPP_SUCCESS.getFlag());
            clockInfo.setStatus(StatusEnum.SUPP_SUCCESS.getName());
            clockInfo.setWorkflowId(null);
            clockInfo.setApproveStatus(null);
        } else {
            clockInfo.setApproveStatus(status);
        }
        clockInfoService.updateAllColumnById(clockInfo);
    }

    @Override
    public void handleRejectApplicationRepulsed(String workflowId, String businessKey, boolean needReapply) {
        ClockInfo clockInfo = clockInfoService.selectById(businessKey);
        if (clockInfo == null) {
            return;
        }
        clockInfo.setStatusFlag(StatusEnum.SUPP_FAIL.getFlag());
        clockInfo.setStatus(StatusEnum.SUPP_FAIL.getName());
        clockInfo.setApproveStatus(null);
        clockInfoService.updateAllColumnById(clockInfo);

    }

}
