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.PurchaseReceiptReport;
import com.yh.saas.plugin.yiliangyiyun.entity.TranSettlementReport;
import com.yh.saas.plugin.yiliangyiyun.service.IPurchaseReceiptReportService;
import com.yh.saas.plugin.yiliangyiyun.service.ITranSettlementReportService;
import org.springframework.beans.factory.annotation.Autowired;

@WorkflowTaskListener(name = "统计报表", group = "运输结算统计")
public class TranSettlementReportListener extends AbstractWorkflowTaskListener {

    private static final long serialVersionUID = 4103656734835351132L;

    @Autowired
    private ITranSettlementReportService tranSettlementReportService;

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

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

    }

}
