package com.jeeplus.finance.invoice.thread;


import com.jeeplus.finance.invoice.service.OMS.OMSDisposeService;
import com.jeeplus.finance.invoice.service.dto.CwFinanceInvoiceDTO;
import com.jeeplus.finance.invoice.util.OMS.SpringContextHolderFinance;
import com.jeeplus.utils.StringUtils;


import java.util.HashMap;
import java.util.Map;

/**
 * @author: 徐滕
 * @create: 2021-12-07 16:36
 **/
public class ApprovalThread extends Thread {

    private OMSDisposeService omsDisposeService = SpringContextHolderFinance.getBean(OMSDisposeService.class);
    private CwFinanceInvoiceDTO workInvoice;
    private String informType;


    public ApprovalThread(CwFinanceInvoiceDTO workInvoice, String informType)
    {
        this.workInvoice = workInvoice;
        this.informType = informType;
    }

    public void run(){
        String disposeResult = "";
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            //进行签章调用
            //根据项目id查询是否已经提交过了审定单签章
            if(null == workInvoice){
                disposeResult = "查询不到该开票信息";
                omsDisposeService.handleInvoiceRetryAllFail("","",disposeResult, informType);
                return;
            }
            if(StringUtils.isNotBlank( workInvoice.getOmsOfdUrl())){
                disposeResult = "该发票已经开过票";
                omsDisposeService.handleInvoiceRetryAllFail("",workInvoice.getId(),disposeResult, informType);
                return;
            }
            omsDisposeService.doInvoiceBusiness(map,workInvoice.getId(), informType);

        }catch (Exception e){
            disposeResult = e.getMessage();
            omsDisposeService.handleInvoiceRetryAllFail("",workInvoice.getId(),disposeResult, informType);
        }finally {

        }

    }
}
