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.WarehousingOrder;
import com.yh.saas.plugin.yiliangyiyun.service.IWarehousingOrderService;
import org.springframework.beans.factory.annotation.Autowired;

@WorkflowTaskListener(name = "仓库管理", group = "入库单盘损")
public class WarehousingDebitListener extends AbstractWorkflowTaskListener {

    private static final long serialVersionUID = 4103656734835351132L;

    @Autowired
    private IWarehousingOrderService warehousingOrderService;

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

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

    }

}
