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.SalesDeliveryReport;
import com.yh.saas.plugin.yiliangyiyun.service.IPurchaseReceiptReportService;
import com.yh.saas.plugin.yiliangyiyun.service.ISalesDeliveryReportService;
import com.yh.saas.plugin.yiliangyiyun.service.ISearchRecordsInfoService;
import org.springframework.beans.factory.annotation.Autowired;

@WorkflowTaskListener(name = "统计报表", group = "销售出库统计")
public class SaleOutReportListener extends AbstractWorkflowTaskListener {

    private static final long serialVersionUID = 4103656734835351132L;

    @Autowired
    private ISalesDeliveryReportService salesDeliveryReportService;

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

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

    }

}
