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.service.IContractCostInfoService;
import org.springframework.beans.factory.annotation.Autowired;

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

    private static final long serialVersionUID = 4103656734835351132L;

    @Autowired
    private IContractCostInfoService contractCostInfoService;

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

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

    }

}
