package nckd.jimin.jyyy.fi.plugin.form;

import kd.bos.algo.Algo;
import kd.bos.algo.DataSet;
import kd.bos.algo.DataType;
import kd.bos.algo.RowMeta;
import kd.bos.context.RequestContext;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.workflow.WorkflowServiceHelper;
import kd.bos.util.CollectionUtils;
import kd.bos.util.StringUtils;
import kd.bos.workflow.api.BizProcessStatus;
import nckd.jimin.jyyy.fi.common.util.CommonUtils;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

public class ReimWorkBenchesHelper {

    private static final Log logger = LogFactory.getLog(ReimWorkBenchesHelper.class);

    /**
     * 用车申请单、费用申请单、出差申请单、差旅借款单、借款单、预付单
     * @param filterList
     * @param quickFilter
     * @return
     */
    public DataSet queryDataApply(List<QFilter> filterList , String quickFilter){
        List<DataSet> dataSetList = new ArrayList<>();
        List<QFilter> commonFilterList = new ArrayList<>();
        commonFilterList.add(getProjectPersonFilter());
        if(CollectionUtils.isNotEmpty(filterList)){
            commonFilterList.addAll(filterList);
        }
        if(StringUtils.isNotEmpty(quickFilter)){
            commonFilterList.add(new QFilter("billno", QCP.like,"%"+ quickFilter +"%")
                    .or(new QFilter("description",QCP.like,"%"+ quickFilter +"%")));
        }

        // 显示暂存、已提交、审核中、审核未通过的申请类单据
        List<QFilter> applierFilter = new ArrayList<>();
        applierFilter.add(new QFilter("billstatus",QCP.in,new String[]{"A","B","C","D"}));
        applierFilter.addAll(commonFilterList);


        DataSet dailyVehHeadDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyvehiclebill",
                "id billid,bizdate applydate,'er_dailyvehiclebill' billtype,'er_dailyvehiclebill' pageid,billno billno,description description,null expenseamount," +
                        "null approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                applierFilter.toArray(new QFilter[0]), "");

        DataSet tripReqDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_tripreqbill",
                "id billid,bizdate applydate,'er_tripreqbill' billtype,'er_tripreqbill' pageid,billno billno,description description,null applyamount," +
                        "null approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                applierFilter.toArray(new QFilter[0]), "");

        DataSet dailyApplyDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyapplybill",
                "id billid,bizdate applydate,'er_dailyapplybill' billtype,'er_dailyapplybill' pageid,billno billno,description description,applyamount applyamount," +
                        "approveamount approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                applierFilter.toArray(new QFilter[0]), "");

        dataSetList.add(getTaskApproveData(dailyVehHeadDataSet));
        dataSetList.add(getTaskApproveData(tripReqDataSet));
        dataSetList.add(getTaskApproveData(dailyApplyDataSet));

        // 显示暂存、已提交、审核中、审核未通过、等待付款，或者审核通过（未付金额>0、借款余额=0）的借款预付类单据。
        List<QFilter> loanPayFilter = new ArrayList<>();
        QFilter auditStatusFilter = new QFilter("billstatus", QCP.equals, "E")
                .and(new QFilter("notpayamount", QCP.large_than, BigDecimal.ZERO))
                .and(new QFilter("balanceamount", QCP.equals, BigDecimal.ZERO));
        loanPayFilter.add(new QFilter("billstatus",QCP.in,new String[]{"A","B","C","D","F"}).or(auditStatusFilter));
        loanPayFilter.addAll(commonFilterList);

        DataSet dailyloanDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyloanbill",
                "id billid,bizdate applydate,'er_dailyloanbill' billtype,'er_dailyloanbill' pageid,billno billno,description description,loanamount applyamount," +
                        "approveamount approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                loanPayFilter.toArray(new QFilter[0]), "");

        DataSet prepayBillDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_prepaybill",
                "id billid,bizdate applydate,'er_prepaybill' billtype,case when nckd_pageid = 'nckd_er_srmperpaybill' then 'nckd_er_srmperpaybill' else 'nckd_er_dailyloanbill' end pageid," +
                        "billno billno,description description,loanamount applyamount," +
                        "approveamount approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                loanPayFilter.toArray(new QFilter[0]), "");


        dataSetList.add(getTaskApproveData(dailyloanDataSet));
        dataSetList.add(getTaskApproveData(prepayBillDataSet));

        return CommonUtils.joinDataSetList(dataSetList);
    }


    /**
     * 用车申请单、费用申请单、出差申请单、差旅借款单、借款单、预付单。
     * @param filterList
     * @param quickFilterStr
     * @return
     */
    public DataSet queryDataWaitReim(List<QFilter> filterList  , String quickFilterStr){

        List<DataSet> dataSetList = new ArrayList<>();

        QFilter projectPersonFilter = getProjectPersonFilter();

        QFilter quickFilter = null;
        if(StringUtils.isNotEmpty(quickFilterStr)){
            quickFilter = new QFilter("billno",QCP.like,"%"+ quickFilterStr +"%")
                    .or(new QFilter("description",QCP.like,"%"+ quickFilterStr +"%"));
        }

        // 显示审核通过（可用余额>0）的申请类单据
        QFilter applyStatusFilter = new QFilter("billstatus", QCP.equals, "E");
        // 确认可用余额的取值逻辑
        DataSet dailyVehDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyvehiclebill",
                "id billid,bizdate applydate,'er_dailyvehiclebill' billtype,'er_dailyvehiclebill' pageid,billno billno,description description,null applyamount," +
                        "null approveamount,null balanceamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,applyStatusFilter), "");

        DataSet tripReqDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_tripreqbill",
                "id billid,bizdate applydate,'er_tripreqbill' billtype,'er_tripreqbill' pageid,billno billno,description description,null applyamount," +
                        "null approveamount,null balanceamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,applyStatusFilter), "");

        DataSet dailyApplyDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyapplybill",
                "id billid,bizdate applydate,'er_dailyapplybill' billtype,'er_dailyapplybill' pageid,billno billno,description description,applyamount applyamount," +
                        "approveamount approveamount,balanceamount balanceamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,applyStatusFilter
                        ,new QFilter("balanceamount", QCP.large_than, BigDecimal.ZERO)
                        //增加手工隐藏标记的过滤
                        ,new QFilter("nckd_handhide", QCP.equals, "0")), "");
        dataSetList.add(dailyVehDataSet);
        dataSetList.add(tripReqDataSet);
        dataSetList.add(dailyApplyDataSet);

        // 显示审核通过（借款余额>0）、已付款（借款余额>0）的借款预付类单据
        QFilter loanPayFilter = new QFilter("billstatus",QCP.in,new String[]{"E","G"})
                .and(new QFilter("balanceamount", QCP.large_than, BigDecimal.ZERO));

        QFilter waitPayLoanPayFilter = new QFilter("billstatus",QCP.equals,"F")
                .and(new QFilter("notpayamount", QCP.large_than, BigDecimal.ZERO).and(new QFilter("balanceamount", QCP.large_than, BigDecimal.ZERO)));


        DataSet dailyloanDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyloanbill",
                "id billid,bizdate applydate,'er_dailyloanbill' billtype,'er_dailyloanbill' pageid,billno billno,description description,loanamount applyamount," +
                        "approveamount approveamount,balanceamount balanceamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,loanPayFilter.or(waitPayLoanPayFilter)), "");

        DataSet prepayBillDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_prepaybill",
                "id billid,bizdate applydate,'er_prepaybill' billtype,case when nckd_pageid = 'nckd_er_srmperpaybill' then 'nckd_er_srmperpaybill' else 'nckd_er_dailyloanbill' end pageid,billno billno,description description,loanamount applyamount," +
                        "approveamount approveamount,balanceamount balanceamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,loanPayFilter.or(waitPayLoanPayFilter)), "");

        dataSetList.add(dailyloanDataSet);
        dataSetList.add(prepayBillDataSet);

        return CommonUtils.joinDataSetList(dataSetList);
    }

    /**
     * 费用报销单、差旅费报销单、对公费用报销单、商旅付款申请单
     * @param filterList
     * @param quickFilterStr
     * @return
     */
    public DataSet queryDataReiming(List<QFilter> filterList , String quickFilterStr){
        long currUserId = RequestContext.get().getCurrUserId();
        List<DataSet> dataSetList = new ArrayList<>();
        QFilter projectPersonFilter = getProjectPersonFilter();
        QFilter quickFilter = null;
        if(StringUtils.isNotEmpty(quickFilterStr)){
            quickFilter = new QFilter("billno",QCP.like,"%"+ quickFilterStr +"%")
                    .or(new QFilter("description",QCP.like,"%"+ quickFilterStr +"%"));
        }

        QFilter statusFilter = new QFilter("billstatus",QCP.in,new String[]{"A","B","C","D","F"});
        // 或者审核通过且付现金额不等于0

        DataSet dailyReimBurseDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyreimbursebill",
                "id billid,bizdate applydate,'er_dailyreimbursebill' billtype,'er_dailyreimbursebill' pageid,billno billno,description description,reimburseamount applyamount," +
                        "approveamount approveamount,payamount payamount,notpayamount notpayamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,statusFilter.copy()
                        .or(new QFilter("billstatus", QCP.equals, "E").and(new QFilter("payamount", QCP.large_than, BigDecimal.ZERO)))), "");

        //显示暂存、已提交、审核中、审核未通过、审核通过、等待付款的报销类单据。
        DataSet tripReimBillDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_tripreimbursebill",
                "id billid,bizdate applydate,'er_tripreimbursebill' billtype,'er_tripreimbursebill' pageid,billno billno,description description,amount applyamount," +
                        "approveamount approveamount,encashamount payamount,notpayamount notpayamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,statusFilter.copy()
                        .or(new QFilter("billstatus", QCP.equals, "E").and(new QFilter("encashamount", QCP.large_than, BigDecimal.ZERO)))), "");

        // 付现金额、未付金额逻辑待确认
        DataSet publicReimBillDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_publicreimbursebill",
                "id billid,bizdate applydate,'er_publicreimbursebill' billtype,case when trim(nckd_pageid) != '' then nckd_pageid else 'nckd_dailyreimbursebill' end pageid," +
                        "billno billno,description description,reimburseamount applyamount," +
                        "approveamount approveamount,payamount payamount,notpayamount notpayamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,statusFilter.copy()
                        .or(new QFilter("billstatus", QCP.equals, "E").and(new QFilter("payamount", QCP.large_than, BigDecimal.ZERO)))), "");

        QFilter checkFilter = null;
        if(StringUtils.isNotEmpty(quickFilterStr)){
            checkFilter = new QFilter("billno",QCP.like,"%"+ quickFilterStr +"%").or(new QFilter("applyexplain",QCP.like,"%"+ quickFilterStr +"%"));
        }
        DataSet checkingPayBillDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_checkingpaybill",
                "id billid,bizdate applydate,'er_checkingpaybill' billtype,'er_checkingpaybill' pageid,billno billno,applyexplain description,totalamount_head applyamount," +
                        "totalamount_head approveamount,payamount payamount,totalamount_head-payamount notpayamount,billstatus billstatus,company.id company,applier.id applier",
                getFilterArr(new QFilter("applier", QCP.equals,currUserId), checkFilter, statusFilter.copy()
                        .or(new QFilter("billstatus", QCP.equals, "E").and(new QFilter("payamount", QCP.large_than, BigDecimal.ZERO)))), "");

        dataSetList.add(getTaskApproveData(tripReimBillDataSet));
        dataSetList.add(getTaskApproveData(publicReimBillDataSet));
        dataSetList.add(getTaskApproveData(dailyReimBurseDataSet));
        dataSetList.add(getTaskApproveData(checkingPayBillDataSet));
        return CommonUtils.joinDataSetList(dataSetList);
    }

    /**
     * 用车申请单、费用申请单、出差申请单、差旅借款单、借款单、预付单、费用报销单、差旅费报销单、对公费用报销单、商旅付款申请单
     * @param filterList
     * @param quickFilterStr
     * @return
     */
    public DataSet queryDataComplete(List<QFilter> filterList , String quickFilterStr){
        long currUserId = RequestContext.get().getCurrUserId();
        List<DataSet> dataSetList = new ArrayList<>();

        QFilter projectPersonFilter = getProjectPersonFilter();
        QFilter quickFilter = null;
        if(StringUtils.isNotEmpty(quickFilterStr)){
            quickFilter = new QFilter("billno",QCP.like,"%"+ quickFilterStr +"%")
                    .or(new QFilter("description",QCP.like,"%"+ quickFilterStr +"%"));
        }

        // 显示已废弃、已关闭、审核未通过、审核通过（可用余额=0）的申请类单据。
//        QFilter applyBillStatusFilter = new QFilter("billstatus", QCP.in, new String[]{"H", "I","E"});
        QFilter applyBillStatusFilter = new QFilter("billstatus", QCP.in, new String[]{"H", "I"})
                .or(new QFilter("billstatus", QCP.in, new String[]{"E"}).and(new QFilter("balanceamount", QCP.equals, BigDecimal.ZERO)));


        DataSet dailyVehDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyvehiclebill",
                "id billid,bizdate applydate,'er_dailyvehiclebill' billtype,'er_dailyvehiclebill' pageid,billno billno,description description,null applyamount," +
                        "null approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,new QFilter("billstatus", QCP.equals, "I")), "");

        DataSet tripReqDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_tripreqbill",
                "id billid,bizdate applydate,'er_tripreqbill' billtype,'er_tripreqbill' pageid,billno billno,description description,null applyamount," +
                        "null approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,new QFilter("billstatus", QCP.in, new String[]{"H", "I"})), "");

        DataSet dailyApplyDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyapplybill",
                "id billid,bizdate applydate,'er_dailyapplybill' billtype,'er_dailyapplybill' pageid,billno billno,description description,applyamount applyamount," +
                        "approveamount approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,applyBillStatusFilter
                        //增加手工隐藏标记的过滤
                    , new QFilter("nckd_handhide", QCP.equals, "0")), "");
        dataSetList.add(dailyVehDataSet);
        dataSetList.add(tripReqDataSet);
        dataSetList.add(dailyApplyDataSet);

        //已废弃、已关闭、审核未通过、审核通过（借款余额=0）、已付款（借款余额=0）的借款预付类单据。
        QFilter prepayBillStatusFilter = new QFilter("billstatus", QCP.in, new String[]{"H", "I"})
                .or(new QFilter("billstatus", QCP.equals, "G").and(new QFilter("balanceamount", QCP.equals, BigDecimal.ZERO)));

        DataSet dailyloanDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyloanbill",
                "id billid,bizdate applydate,'er_dailyloanbill' billtype,'er_dailyloanbill' pageid, billno billno,description description,loanamount applyamount," +
                        "approveamount approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,prepayBillStatusFilter), "");

        DataSet prepayBillDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_prepaybill",
                "id billid,bizdate applydate,'er_prepaybill' billtype,case when nckd_pageid = 'nckd_er_srmperpaybill' then 'nckd_er_srmperpaybill' else 'nckd_er_dailyloanbill' end pageid," +
                        "billno billno,description description,loanamount applyamount," +
                        "approveamount approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,prepayBillStatusFilter), "");
        dataSetList.add(dailyloanDataSet);
        dataSetList.add(prepayBillDataSet);
        // 显示已废弃、已关闭、审核未通过、已付款的报销类单据。
        QFilter reimBillStatusFilter = new QFilter("billstatus", QCP.in, new String[]{"H", "I","G"});

        // 或者审核通过且付现金额为0
        DataSet tripReimBillDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_tripreimbursebill",
                "id billid,bizdate applydate,'er_tripreimbursebill' billtype,'er_tripreimbursebill' pageid,billno billno,description description,amount applyamount," +
                        "approveamount approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,reimBillStatusFilter.copy()
                        .or(new QFilter("billstatus", QCP.equals, "E").and(new QFilter("encashamount", QCP.equals, BigDecimal.ZERO)))), "");

        DataSet publicReimBillDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_publicreimbursebill",
                "id billid,bizdate applydate,'er_publicreimbursebill' billtype,case when trim(nckd_pageid) != '' then nckd_pageid else 'nckd_dailyreimbursebill' end pageid," +
                        "billno billno,description description,reimburseamount applyamount," +
                        "approveamount approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,reimBillStatusFilter.copy()
                        .or(new QFilter("billstatus", QCP.equals, "E").and(new QFilter("payamount", QCP.equals, BigDecimal.ZERO)))), "");

        DataSet dailyReimBurseDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_dailyreimbursebill",
                "id billid,bizdate applydate,'er_dailyreimbursebill' billtype,'er_dailyreimbursebill' pageid,billno billno,description description,reimburseamount applyamount," +
                        "approveamount approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                getFilterArr(projectPersonFilter,quickFilter,reimBillStatusFilter.copy()
                        .or(new QFilter("billstatus", QCP.equals, "E").and(new QFilter("payamount", QCP.equals, BigDecimal.ZERO)))), "");


        QFilter checkFilter = null;
        if(StringUtils.isNotEmpty(quickFilterStr)){
            checkFilter = new QFilter("billno",QCP.like,"%"+ quickFilterStr +"%").or(new QFilter("applyexplain",QCP.like,"%"+ quickFilterStr +"%"));
        }
        DataSet checkingPayBillDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_checkingpaybill",
                "id billid,bizdate applydate,'er_checkingpaybill' billtype,'er_checkingpaybill' pageid,billno billno,applyexplain description,payamount applyamount," +
                        "payamount approveamount,billstatus billstatus,company.id company,applier.id applier",
                getFilterArr(new QFilter("applier", QCP.equals,currUserId), checkFilter, reimBillStatusFilter.copy()
                        .or(new QFilter("billstatus", QCP.equals, "E").and(new QFilter("payamount", QCP.equals, BigDecimal.ZERO)))), "");

        dataSetList.add(tripReimBillDataSet);
        dataSetList.add(publicReimBillDataSet);
        dataSetList.add(dailyReimBurseDataSet);
        dataSetList.add(checkingPayBillDataSet);

        return CommonUtils.joinDataSetList(dataSetList);
    }

    public DataSet queryDataRepay(List<QFilter> filterList , String quickFilter){
        List<QFilter> commonFilterList = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(filterList)){
            commonFilterList.addAll(filterList);
        }
        if(StringUtils.isNotEmpty(quickFilter)){
            commonFilterList.add(new QFilter("billno",QCP.like,"%"+ quickFilter +"%")
                    .or(new QFilter("description",QCP.like,"%"+ quickFilter +"%")));
        }
        long currUserId = RequestContext.get().getCurrUserId();
        commonFilterList.add(new QFilter("applier",QCP.equals,currUserId));

        List<QFilter> repayFilter = new ArrayList<>();
        repayFilter.add(new QFilter("billstatus",QCP.in,new String[]{"A","B","C","D","E","G"}));
        repayFilter.addAll(commonFilterList);

        DataSet repaymentBillDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), "er_repaymentbill",
                "id billid,repaymentdate applydate,'er_repaymentbill' billtype,case when trim(nckd_pageid) != '' then nckd_pageid else 'nckd_repaymentbill' end pageid," +
                        "billno billno,description description,amount applyamount," +
                        "approveamount approveamount,billstatus billstatus,costcompany.id company,applier.id applier",
                repayFilter.toArray(new QFilter[0]), "");
        return getTaskApproveData(repaymentBillDataSet);
    }
    protected DataSet getPrePayBillLoanData(DataSet dt , String entity){
        Set billIdSet = CommonUtils.getFiledFromDataSet(dt, "billid");

        DataSet sumAmountDataSet = QueryServiceHelper.queryDataSet(this.getClass().getName(), entity,
                        "id billid,accountentry.accbalamount accbalamount",
                        new QFilter("id",QCP.in,billIdSet).toArray(), "")
                .groupBy(new String[]{"billid"})
                .sum("accbalamount").finish();
        return dt.leftJoin(sumAmountDataSet).on("billid","billid")
                .select(dt.getRowMeta().getFieldNames() , new String[]{"accbalamount"}).finish();
    }




    protected DataSet getTaskApproveData(DataSet dt){
        Set<Object> billIdSet = CommonUtils.getFiledFromDataSet(dt, "billid");

        Map<String,String> approveStep = getApproveStep(billIdSet.stream().map(r -> r.toString()).collect(Collectors.toSet()));
        Map<String, DataType> fieldMap = new LinkedHashMap<>();
        fieldMap.put("billid",DataType.LongType);
        fieldMap.put("curapprovenode",DataType.StringType);
        //值域行，字段标识和类型与fieldMap一一对应
        List<Object[]> rowData = new ArrayList<>();
        approveStep.forEach((key,value) ->{
            rowData.add(new Object[]{Long.valueOf(key), value});
        });

        // 构建dataSet
        DataSet dataSet= Algo.create(this.getClass().getName())
                .createDataSet(rowData, new RowMeta(fieldMap.keySet().toArray(new String[0]), fieldMap.values().toArray(new DataType[0])));


        return dt.leftJoin(dataSet).on("billid","billid")
                .select(dt.getRowMeta().getFieldNames(),new String[]{"curapprovenode"}).finish();
    }

    public Map<String , String> getApproveStep(Set<String> billIdSet){
        Map<String , String> approveStepMap = new HashMap<>();

        Map<String, List<BizProcessStatus>> allProcessMap = WorkflowServiceHelper.getBizProcessStatus(billIdSet.toArray(new String[0]));
        for(Map.Entry<String, List<BizProcessStatus>> dataRow : allProcessMap.entrySet()){
            List<BizProcessStatus> node = dataRow.getValue();
            int count = 0;
            String nodeName = "";
            StringBuilder participantName = new StringBuilder();
            StringBuilder msg = new StringBuilder();
            try {
                for (BizProcessStatus e : node) {
                    nodeName = e.getCurrentNodeName();
                    String auditor = e.getParticipantName();
                    e.getProcessStatus();
                    if (auditor != null && !"".equals(auditor.trim())) {
                        participantName.append(",");
                        participantName.append(auditor);
                        if (++count == 3) {
                            participantName.append("...");
                            break;
                        }
                        continue;
                    }
                }
                if (!org.apache.commons.lang3.StringUtils.isBlank(nodeName)) {
                    msg.append(nodeName);
                    if (!org.apache.commons.lang3.StringUtils.isBlank(participantName)) {
                        msg.append('/');
                        msg.append(participantName.toString().replaceFirst(",", ""));
                    }
                }
                approveStepMap.put(dataRow.getKey(),msg.toString());
            }
            catch (Exception e2) {
                logger.info("ErWorkFlowFlexListForOtherPlugin>>>获取审批人出现异常: " + e2.getMessage());
            }
        }
        return approveStepMap;
    }

    public QFilter getProjectPersonFilter(){
        long currUserId = RequestContext.get().getCurrUserId();
        return new QFilter("projectower.fbasedataid", QCP.equals,currUserId);
    }

    public QFilter[] getFilterArr(QFilter... filters){
        List<QFilter> filterList = new ArrayList<>(filters.length);
        for(QFilter filter : filters){
            if(filter != null){
                filterList.add(filter);
            }
        }
        return filterList.toArray(new QFilter[0]);
    }
}
