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.CollectionWarehousingRecord;
import com.yh.saas.plugin.yiliangyiyun.entity.ContractManagementInfo;
import com.yh.saas.plugin.yiliangyiyun.service.ICollectionWarehousingRecordService;
import com.yh.saas.plugin.yiliangyiyun.service.IContractManagementInfoService;
import org.springframework.beans.factory.annotation.Autowired;

@WorkflowTaskListener(name = "合同管理", group = "代收合同记录")
public class DsContractListListener extends AbstractWorkflowTaskListener {

    private static final long serialVersionUID = 4103656734835351132L;

    @Autowired
    private ICollectionWarehousingRecordService collectionWarehousingRecordService;

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

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

    }

}
