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.ContractCostInfo;
import com.yh.saas.plugin.yiliangyiyun.entity.NonContractExpenses;
import com.yh.saas.plugin.yiliangyiyun.service.IContractCostInfoService;
import com.yh.saas.plugin.yiliangyiyun.service.INonContractExpensesService;
import org.springframework.beans.factory.annotation.Autowired;

@WorkflowTaskListener(name = "合同管理", group = "合同外费用")
public class NonContractExpensesListener extends AbstractWorkflowTaskListener {

    private static final long serialVersionUID = 4103656734835351132L;

    @Autowired
    private INonContractExpensesService nonContractExpensesService;

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

    @Override
    public void handleRejectApplicationRepulsed(String workflowId, String businessKey, boolean needReapply) {
        NonContractExpenses nonContractExpenses = nonContractExpensesService.selectById(businessKey);
        if (nonContractExpenses == null) {
            return;
        }
        nonContractExpenses.setStatusFlag(StatusEnum.TASK_RETURN.getFlag());
        nonContractExpenses.setStatus(StatusEnum.TASK_RETURN.getName());
        nonContractExpenses.setApproveStatus(null);
        nonContractExpensesService.updateAllColumnById(nonContractExpenses);

    }

}
