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.PaymentManagement;
import com.yh.saas.plugin.yiliangyiyun.entity.PurchasePrice;
import com.yh.saas.plugin.yiliangyiyun.service.IPaymentManagementService;
import com.yh.saas.plugin.yiliangyiyun.service.IPurchasePriceService;
import org.springframework.beans.factory.annotation.Autowired;

@WorkflowTaskListener(name = "收购管理", group = "付款管理")
public class AcquisitionPayListener extends AbstractWorkflowTaskListener {

    private static final long serialVersionUID = 4103656734835351132L;

    @Autowired
    private IPaymentManagementService paymentManagementService;

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

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

    }

}
