//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nc.impl.obm.ebank;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.bs.sec.esapi.NCESAPI;
import nc.bs.trade.business.HYPubBO;
import nc.itf.obm.IEbankbillinfoqueryMaintain;
import nc.itf.obm.IEbankdatadownloadMaintain;
import nc.itf.obm.IObmEvent;
import nc.itf.obm.PayStateVO;
import nc.itf.obm.ebank.IObmEbankNccService;
import nc.itf.obm.ebankecd.IEbankEcdService;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.SQLParameter;
import nc.jdbc.framework.processor.ArrayListProcessor;
import nc.md.persist.framework.IMDPersistenceQueryService;
import nc.md.persist.framework.MDPersistenceService;
import nc.vo.bd.currtype.CurrtypeVO;
import nc.vo.obm.ebankbillinfo.BillInfoQueryVO;
import nc.vo.obm.ebankbillinfoquery.AggEbankBillInfoQueryVO;
import nc.vo.obm.ebankbillinfoquery.EbankBillInfoQueryVO;
import nc.vo.obm.ebankdzd.DzdQueryInfoVO;
import nc.vo.obm.ebankdzd.EbankDzdVO;
import nc.vo.obm.ebankecd.EbankEcdVO;
import nc.vo.obm.log.ObmLog;
import nc.vo.obm.payroll.DfgzBVO;
import nc.vo.obm.payroll.DfgzBillVO;
import nc.vo.obm.payroll.DfgzHVO;
import nc.vo.obm.payroll.DfgzQueryCardInfoVO;
import nc.vo.obm.payroll.DfgzQueryInfoVO;
import nc.vo.obm.sql.StrWhereSqlUtils;
import nc.vo.org.OrgVO;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFDouble;
import nc.vo.tmpub.security.DefCommonClientSignForNCC;
import nc.vo.tmpub.security.SignAttributeNameVO;
import nc.vo.tmpub.util.SqlUtil;
import nccloud.commons.collections.CollectionUtils;
import nccloud.dto.obm.ebankbillinfo.vo.BillInfoDownloadVO;
import org.apache.commons.lang3.ArrayUtils;

public class ObmEbankNccServiceImpl implements IObmEbankNccService {
    private BaseDAO dao = null;

    public ObmEbankNccServiceImpl() {
    }

    public boolean executeSql(String strSql) throws BusinessException {
        if (this.dao == null) {
            this.dao = new BaseDAO();
        }

        this.dao.executeUpdate(strSql);
        return true;
    }

    public boolean executeSql(String strSql, String[] values) throws BusinessException {
        if (this.dao == null) {
            this.dao = new BaseDAO();
        }

        SQLParameter params = new SQLParameter();

        for(int i = 0; i < values.length; ++i) {
            params.addParam(values[i]);
        }

        this.dao.executeUpdate(strSql, params);
        return true;
    }

    public String[][] getData(String sqlStr) {
        String[][] dataAray = null;

        try {
            IUAPQueryBS query = (IUAPQueryBS)NCLocator.getInstance().lookup(IUAPQueryBS.class);
            new ArrayList();
            ArrayListProcessor processor = new ArrayListProcessor();
            List<Object[]> rsList = (List)query.executeQuery(sqlStr, processor);
            if (rsList.size() != 0) {
                int lenrow = rsList.size();
                Object[] firstrow = rsList.get(0);
                int lencol = firstrow.length;
                dataAray = new String[lenrow][lencol];

                for(int i = 0; i < lenrow; ++i) {
                    Object[] objs = rsList.get(i);

                    for(int j = 0; j < lencol; ++j) {
                        if (null != objs[j]) {
                            dataAray[i][j] = objs[j].toString();
                        }
                    }
                }
            }
        } catch (Exception var12) {
        }

        return dataAray;
    }

    public EbankDzdVO[] queryByPks(String[] pks) throws BusinessException {
        String var10000 = StrWhereSqlUtils.getInStr("pk_ebank_dzd", pks, new boolean[]{false});
        String strWhere = "isnull(dr,0)=0 and " + var10000;
        HYPubBO hy = new HYPubBO();
        EbankDzdVO[] dzdvos = (EbankDzdVO[])hy.queryByCondition(EbankDzdVO.class, strWhere);
        return dzdvos != null && dzdvos.length == 0 ? null : dzdvos;
    }

    public EbankDzdVO[] queryEbankDzdByCondition(DzdQueryInfoVO info) throws BusinessException {
        String var10000 = info.getBegdate();
        String strWhere = "isnull(dr,0)=0  and styleflag='A' and trans_date>='" + var10000 + "' and trans_date<='" + info.getEnddate() + "'";
        if (info.getCuracc() != null) {
            strWhere = strWhere + " and curacc in (select accnum from bd_bankaccsub where " + SqlUtil.buildSqlForIn("pk_bankaccsub", info.getCuracc()) + ") ";
        }

        if (!ArrayUtils.isEmpty(info.getOppacc())) {
            strWhere = strWhere + " and oppacc ='" + NCESAPI.sqlEncode(info.getOppacc()[0]) + "' ";
        }

        if (info.getC_ccynbr() != null) {
            strWhere = strWhere + " and c_ccynbr ='" + info.getC_ccynbr() + "' ";
        }

        if (info.getDbtrsamtlow() != null) {
            strWhere = strWhere + " and ((curacc=dbtacc and trsamt >='" + info.getDbtrsamtlow() + "') or (curacc=crtacc and trsamt >='" + info.getCrtrsamtlow() + "'))";
        }

        if (info.getDbtrsamtup() != null) {
            strWhere = strWhere + " and ((curacc=dbtacc and trsamt <='" + info.getDbtrsamtup() + "') or (curacc=crtacc and trsamt <='" + info.getCrtrsamtup() + "'))";
        }

        if (info.getTxseqid() != null) {
            strWhere = strWhere + " and txseqid ='" + info.getTxseqid() + "' ";
        }

        strWhere = strWhere + " and styleflag  ='A' ";
        HYPubBO hy = new HYPubBO();
        EbankDzdVO[] dzdvos = (EbankDzdVO[])hy.queryByCondition(EbankDzdVO.class, strWhere);
        return dzdvos != null && dzdvos.length == 0 ? null : dzdvos;
    }

    public DfgzBillVO[] queryEbankDfgzCardByCondition(DfgzQueryCardInfoVO info) throws BusinessException {
        String[] pks = new String[1];
        pks[0] = info.getPk();
        String sqlWhere = StrWhereSqlUtils.getInStr("pk_dfgz", pks, new boolean[]{false});
        Collection<?> result = ((IMDPersistenceQueryService)NCLocator.getInstance().lookup(IMDPersistenceQueryService.class)).queryBillOfVOByCond(DfgzBillVO.class, sqlWhere, true, false);
        DfgzBillVO[] vos = CollectionUtils.isEmpty(result) ? new DfgzBillVO[0] : (DfgzBillVO[])result.toArray(new DfgzBillVO[0]);
        return vos;
    }

    public DfgzHVO[] queryEbankDfgzCardByPks(String[] pks) throws BusinessException {
        String sqlWhere = StrWhereSqlUtils.getInStr("pk_dfgz", pks, new boolean[]{false});
        Collection<?> result = ((IMDPersistenceQueryService)NCLocator.getInstance().lookup(IMDPersistenceQueryService.class)).queryBillOfVOByCond(DfgzHVO.class, sqlWhere, true, false);
        DfgzBillVO[] billvos = CollectionUtils.isEmpty(result) ? new DfgzBillVO[0] : (DfgzBillVO[])result.toArray(new DfgzBillVO[0]);
        if (billvos != null && billvos.length != 0) {
            DfgzHVO[] vos = new DfgzHVO[billvos.length];

            for(int i = 0; i < billvos.length; ++i) {
                vos[i] = billvos[i].getParentVO();
            }

            return vos;
        } else {
            return null;
        }
    }

    public String getPkGroupByOrg(String pk_org) throws Exception {
        HYPubBO hy = new HYPubBO();
        OrgVO orgvo = (OrgVO)hy.queryByPrimaryKey(OrgVO.class, pk_org);
        String pk_group = orgvo.getPk_group();
        return pk_group;
    }

    public String getPkCurrtypeByOrg(String pk_org) throws Exception {
        HYPubBO hy = new HYPubBO();
        OrgVO orgvo = (OrgVO)hy.queryByPrimaryKey(OrgVO.class, pk_org);
        String pk_currtype = orgvo.getPk_currtype();
        return pk_currtype;
    }

    public DfgzHVO[] queryEbankDfgzByCondition(DfgzQueryInfoVO info) throws BusinessException {
        String strWhere = "isnull(dr,0)=0 ";
        if (info.getPk_org() != null) {
            strWhere = strWhere + " and " + SqlUtil.buildSqlForIn("pk_org", info.getPk_org());
        }

        if (info.getPk_banktype() != null) {
            strWhere = strWhere + " and " + SqlUtil.buildSqlForIn("pk_banktype", info.getPk_banktype());
        }

        if (info.getDbtacc() != null) {
            strWhere = strWhere + " and dbtacc ='" + info.getDbtacc() + "' ";
        }

        if (info.getBegdate() != null) {
            strWhere = strWhere + " and billmakedate >='" + info.getBegdate() + "' ";
        }

        if (info.getEnddate() != null) {
            strWhere = strWhere + " and  billmakedate<='" + info.getEnddate() + "' ";
        }

        if (info.getPaytotalnumlow() != null) {
            strWhere = strWhere + " and paytotalnum  >='" + info.getPaytotalnumlow() + "' ";
        }

        if (info.getPaytotalnumup() != null) {
            strWhere = strWhere + " and paytotalnum  <='" + info.getPaytotalnumup() + "' ";
        }

        strWhere = strWhere + "  and logflag=0";
        HYPubBO hy = new HYPubBO();
        DfgzHVO[] dfgzvos = (DfgzHVO[])hy.queryByCondition(DfgzHVO.class, strWhere);
        return dfgzvos;
    }

    public void dfgzApproveSignWithClient(String pk_user, DfgzBillVO[] aggDfgzVOs) throws Exception {
        String constructClassName = "nc.vo.obm.payroll.DfgzBillEncryptVO";
        SignAttributeNameVO signAttributeNameVO = new SignAttributeNameVO();
        signAttributeNameVO.setParentAttributeName("encryptkey");
        DefCommonClientSignForNCC signner = new DefCommonClientSignForNCC(pk_user, constructClassName, signAttributeNameVO);
        if (aggDfgzVOs != null && aggDfgzVOs.length > 0) {
            for(int i = 0; i < aggDfgzVOs.length; ++i) {
                this.trimDfgzBVO(aggDfgzVOs[i]);
                signner.signWithClient(new AggregatedValueObject[]{aggDfgzVOs[i]});
            }
        }

    }

    private void trimDfgzBVO(DfgzBillVO dfgzBillVO) {
        DfgzBVO[] dfgzBVOs = (DfgzBVO[])dfgzBillVO.getChildrenVO();

        for(DfgzBVO dfgzBVO : dfgzBVOs) {
            if (dfgzBVO.getCrtidet() != null) {
                dfgzBVO.setCrtidet(dfgzBVO.getCrtidet().trim());
            }

            if (dfgzBVO.getPersonname() != null) {
                dfgzBVO.setPersonname(dfgzBVO.getPersonname().trim());
            }

            if (dfgzBVO.getIdentitynum() != null) {
                dfgzBVO.setIdentitynum(dfgzBVO.getIdentitynum().trim());
            }

            if (dfgzBVO.getCrtacc() != null) {
                dfgzBVO.setCrtacc(dfgzBVO.getCrtacc().trim());
            }

            if (dfgzBVO.getCrtaccname() != null) {
                dfgzBVO.setCrtaccname(dfgzBVO.getCrtaccname().trim());
            }

            if (dfgzBVO.getBusnar() != null) {
                dfgzBVO.setBusnar(dfgzBVO.getBusnar().trim());
            }

            if (dfgzBVO.getNusage() != null) {
                dfgzBVO.setNusage(dfgzBVO.getNusage().trim());
            }

            if (dfgzBVO.getCrtbankname() != null) {
                dfgzBVO.setCrtbankname(dfgzBVO.getCrtbankname().trim());
            }
        }

    }

    private IMDPersistenceQueryService getMDQueryService() {
        return MDPersistenceService.lookupPersistenceQueryService();
    }

    public Collection<DfgzBillVO> queryEbankDfgzByCondtion(String whereSQLOnly) throws BusinessException {
        if (whereSQLOnly == null) {
            whereSQLOnly = "1=1";
        }

        Collection<DfgzBillVO> results = null;
        results = this.getMDQueryService().queryBillOfVOByCond(DfgzBillVO.class, whereSQLOnly, true, false);
        return results;
    }

    public EbankBillInfoQueryVO[] queryEbankBillInfoByPks(String[] pks) throws BusinessException {
        String strWhere = "isnull(dr,0)=0 and " + SqlUtil.buildSqlForIn("pk_ebankbillinfoquery", pks);
        HYPubBO hy = new HYPubBO();
        EbankBillInfoQueryVO[] billinfovos = (EbankBillInfoQueryVO[])hy.queryByCondition(EbankBillInfoQueryVO.class, strWhere);
        return billinfovos != null && billinfovos.length == 0 ? null : billinfovos;
    }

    public EbankBillInfoQueryVO[] queryEbankBillInfoByCondition(BillInfoQueryVO info) throws BusinessException {
        String strWhere = "isnull(dr,0)=0 ";
        if (info.getBegdate() != null) {
            strWhere = strWhere + " and tradedate>='" + info.getBegdate() + "'";
        }

        if (info.getEnddate() != null) {
            strWhere = strWhere + " and tradedate<='" + info.getEnddate() + "'";
        }

        if (info.getPk_org() != null) {
            strWhere = strWhere + " and  pk_org ='" + info.getPk_org() + "'";
        }

        if (info.getBanktype() != null) {
            strWhere = strWhere + " and  pk_banktype ='" + info.getBanktype() + "'";
        }

        if (info.getCuracc() != null) {
            strWhere = strWhere + " and (account in (select accnum from bd_bankaccsub where pk_bankaccsub='" + info.getCuracc() + "') or payorgbankaccount in (select accnum from bd_bankaccsub where pk_bankaccsub='" + info.getCuracc() + "') )";
        }

        HYPubBO hy = new HYPubBO();
        EbankBillInfoQueryVO[] billinfovos = (EbankBillInfoQueryVO[])hy.queryByCondition(EbankBillInfoQueryVO.class, strWhere);
        return billinfovos != null && billinfovos.length == 0 ? null : billinfovos;
    }

    public EbankBillInfoQueryVO[] downloadEbankBillInfo(BillInfoDownloadVO info) throws Exception {
        EbankEcdVO[] ecdvos = this.getEcdVOs(info);
        IEbankEcdService ecdinfo = (IEbankEcdService)NCLocator.getInstance().lookup(IEbankEcdService.class);
        EbankEcdVO[] recdvos = ecdinfo.queryEcdBillStatus(ecdvos);
        AggEbankBillInfoQueryVO[] resultvos = this.getEcdBillInfoVOs(recdvos, info);
        int len1 = 0;
        if (resultvos == null) {
            return null;
        } else {
            len1 = resultvos.length;
            IEbankdatadownloadMaintain ecdmaininfo = (IEbankdatadownloadMaintain)NCLocator.getInstance().lookup(IEbankdatadownloadMaintain.class);
            String strSql = "";
            String strWhere = "";
            String[] pks = new String[len1];

            for(int vos = 0; vos < len1; ++vos) {
                pks[vos] = resultvos[vos].getParentVO().getEbillnum();
            }

            strWhere = SqlUtil.buildSqlForIn("ebillnum", pks);
            strSql = "delete from ebank_billinfoquery where " + strWhere;
            ecdmaininfo.executeSql(strSql);
            if (resultvos != null && resultvos.length > 0) {
                IEbankbillinfoqueryMaintain billinfoquery = (IEbankbillinfoqueryMaintain)NCLocator.getInstance().lookup(IEbankbillinfoqueryMaintain.class);
                resultvos = billinfoquery.insert(resultvos, (AggEbankBillInfoQueryVO[])null);
            }

            len1 = resultvos.length;
            EbankBillInfoQueryVO[] vos = new EbankBillInfoQueryVO[len1];

            for(int i = 0; i < len1; ++i) {
                vos[i] = resultvos[i].getParentVO();
            }

            return vos;
        }
    }

    private AggEbankBillInfoQueryVO[] getEcdBillInfoVOs(EbankEcdVO[] ecdvos, BillInfoDownloadVO info) throws Exception {
        CurrtypeVO[] currTypeVo = (CurrtypeVO[])(new HYPubBO()).queryByCondition(CurrtypeVO.class, " code='CNY'");
        String pk_currtype = "";
        if (currTypeVo != null) {
            pk_currtype = currTypeVo[0].getPk_currtype();
        } else {
            pk_currtype = "1002Z0100000000001K1";
        }

        String pk_org = info.getPk_org();
        String pk_banktype = info.getPk_banktype();
        String strSql = "select pk_group from org_orgs where pk_org = '" + pk_org + "'";
        String[][] dataArray = this.getData(strSql);
        String pk_group = dataArray[0][0];
        int len1 = ecdvos.length;
        List<AggEbankBillInfoQueryVO> aggvolist = new ArrayList();

        for(int i = 0; i < len1; ++i) {
            if (ecdvos[i].getTranflag().equals("1")) {
                EbankBillInfoQueryVO hvo = new EbankBillInfoQueryVO();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                hvo.setStatus(2);
                hvo.setPk_group(pk_group);
                hvo.setPk_org(pk_org);
                hvo.setSrcgroup(pk_group);
                hvo.setSrcorg(pk_org);
                hvo.setPk_banktype(pk_banktype);
                hvo.setEbillnum((String)ecdvos[i].getAttributeValue("bklistno1"));
                if (ecdvos[i].getAttributeValue("billamt") != null) {
                    hvo.setBillmoney(new UFDouble(ecdvos[i].getAttributeValue("billamt").toString()));
                } else if (ecdvos[i].getAttributeValue("bkamt3") != null) {
                    hvo.setBillmoney(new UFDouble(ecdvos[i].getAttributeValue("bkamt3").toString()));
                } else if (ecdvos[i].getAttributeValue("bkamt4") != null) {
                    hvo.setBillmoney(new UFDouble(ecdvos[i].getAttributeValue("bkamt4").toString()));
                }

                if (ecdvos[i].getAttributeValue("billopendate") != null) {
                    hvo.setTradedate(new UFDate(ecdvos[i].getAttributeValue("billopendate").toString()));
                } else if (ecdvos[i].getAttributeValue("bk8date3") != null) {
                    hvo.setTradedate(new UFDate(ecdvos[i].getAttributeValue("bk8date3").toString()));
                }

                String billState = "";
                if (ecdvos[i].getAttributeValue("billstate") != null) {
                    billState = ecdvos[i].getAttributeValue("billstate").toString();
                } else if (ecdvos[i].getAttributeValue("bkflag1") != null) {
                    billState = ecdvos[i].getAttributeValue("bkflag1").toString();
                }

                hvo.setBillstatus(billState);
                if (ecdvos[i].getAttributeValue("billtype") != null) {
                    hvo.setDef1(ecdvos[i].getAttributeValue("billtype").toString());
                }

                if (ecdvos[i].getAttributeValue("billopenacc") != null) {
                    hvo.setPayorgbankaccount((String)ecdvos[i].getAttributeValue("billopenacc"));
                }

                if (ecdvos[i].getAttributeValue("billopenname") != null) {
                    hvo.setPayorg((String)ecdvos[i].getAttributeValue("billopenname"));
                }

                if (ecdvos[i].getAttributeValue("billopenbank") != null) {
                    hvo.setPaybank((String)ecdvos[i].getAttributeValue("billopenbank"));
                }

                if (ecdvos[i].getAttributeValue("recaccname") != null) {
                    hvo.setGatheorg((String)ecdvos[i].getAttributeValue("recaccname"));
                }

                if (ecdvos[i].getAttributeValue("recbankname") != null) {
                    hvo.setGatherbank((String)ecdvos[i].getAttributeValue("recbankname"));
                }

                if (ecdvos[i].getAttributeValue("recbankno") != null) {
                    hvo.setGatherorgbank((String)ecdvos[i].getAttributeValue("recbankno"));
                }

                if (ecdvos[i].getAttributeValue("recaccno") != null) {
                    hvo.setAccount((String)ecdvos[i].getAttributeValue("recaccno"));
                }

                if (ecdvos[i].getAttributeValue("acceptaccno") != null) {
                    hvo.setDef3((String)ecdvos[i].getAttributeValue("acceptaccno"));
                }

                if (ecdvos[i].getAttributeValue("acceptaccname") != null) {
                    hvo.setDef4((String)ecdvos[i].getAttributeValue("acceptaccname"));
                }

                if (ecdvos[i].getAttributeValue("acceptbank") != null) {
                    hvo.setDef5((String)ecdvos[i].getAttributeValue("acceptbank"));
                }

                if (ecdvos[i].getAttributeValue("acceptdate") != null) {
                    hvo.setDef2(sdf.format(((UFDate)ecdvos[i].getAttributeValue("acceptdate")).toDate()));
                }

                if (ecdvos[i].getAttributeValue("endflag") != null) {
                    hvo.setDef5((String)ecdvos[i].getAttributeValue("endflag"));
                }

                if (ecdvos[i].getAttributeValue("billduedate") != null) {
                    hvo.setOutdate(new UFDate(sdf.parse(ecdvos[i].getAttributeValue("billduedate").toString())));
                } else if (ecdvos[i].getAttributeValue("bk8date2") != null) {
                    hvo.setOutdate(new UFDate(sdf.parse(ecdvos[i].getAttributeValue("bk8date2").toString())));
                }

                if (ecdvos[i].getAttributeValue("billholdname") != null) {
                    hvo.setOutbillorg(ecdvos[i].getAttributeValue("billholdname").toString());
                }

                if (ecdvos[i].getAttributeValue("contractno") != null) {
                    hvo.setTradecontractdate((String)ecdvos[i].getAttributeValue("contractno"));
                }

                if (ecdvos[i].getAttributeValue("acceptno") != null) {
                    hvo.setCdxynum((String)ecdvos[i].getAttributeValue("acceptno"));
                }

                if (ecdvos[i].getAttributeValue("billsystype") != null) {
                    hvo.setBillsystype((String)ecdvos[i].getAttributeValue("billsystype"));
                }

                if (ecdvos[i].getAttributeValue("ecdsstatus") != null) {
                    hvo.setEcdsstatus((String)ecdvos[i].getAttributeValue("ecdsstatus"));
                }

                if (ecdvos[i].getAttributeValue("billrangestart") != null) {
                    hvo.setBillrangestart((String)ecdvos[i].getAttributeValue("billrangestart"));
                }

                if (ecdvos[i].getAttributeValue("billrangeend") != null) {
                    hvo.setBillrangeend((String)ecdvos[i].getAttributeValue("billrangeend"));
                }

                if (ecdvos[i].getAttributeValue("billrange") != null) {
                    hvo.setBillrange((String)ecdvos[i].getAttributeValue("billrange"));
                }

                if (ecdvos[i].getAttributeValue("ifsepflow") != null && "CS02".equals(ecdvos[i].getAttributeValue("ifsepflow"))) {
                    hvo.setSubcontractcirculation(UFBoolean.TRUE);
                } else {
                    hvo.setSubcontractcirculation(UFBoolean.FALSE);
                }

                hvo.setAttributeValue("dr", 0);
                hvo.setPk_currtype(pk_currtype);
                hvo.setMaketime(new UFDateTime(new Date()));
                hvo.setCreationtime(new UFDateTime(new Date()));
                hvo.setApprovestatus(-1);
                hvo.setDef10((String)ecdvos[i].getAttributeValue("reqreserved10"));
                AggEbankBillInfoQueryVO aggvo = new AggEbankBillInfoQueryVO();
                aggvo.setParentVO(hvo);
                aggvolist.add(aggvo);
            }
        }

        if (aggvolist.size() > 0) {
            AggEbankBillInfoQueryVO[] aggvos = (AggEbankBillInfoQueryVO[])aggvolist.toArray(new AggEbankBillInfoQueryVO[0]);
            return aggvos;
        } else {
            String errmsg = "";
            if (ecdvos.length > 0) {
                errmsg = ecdvos[0].getErrmsg();
                throw new Exception(errmsg);
            } else {
                return null;
            }
        }
    }

    private EbankEcdVO[] getEcdVOs(BillInfoDownloadVO qvo) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        EbankEcdVO[] ecdvos = new EbankEcdVO[1];

        try {
            String pk_banktype = qvo.getPk_banktype();
            String pk_org = qvo.getPk_org();
            String strSql = "select pk_group from org_orgs where pk_org = '" + pk_org + "'";
            String[][] dataArray = this.getData(strSql);
            String pk_group = dataArray[0][0];
            String startdate = sdf.format(qvo.getBegindate().toDate());
            String enddate = sdf.format(qvo.getEnddate().toDate());
            String accno = qvo.getCuracc();
            strSql = "select accnum from bd_bankaccsub  where pk_bankaccsub ='" + accno + "'";
            dataArray = this.getData(strSql);
            accno = dataArray[0][0];
            EbankEcdVO ecdvo = new EbankEcdVO();
            ecdvo.setPk_banktype(pk_banktype);
            ecdvo.setPk_group(pk_group);
            ecdvo.setPk_org(pk_org);
            ecdvo.setAccNo(accno);
            ecdvo.setBk8Date1(startdate);
            ecdvo.setBk8Date2(enddate);
            ecdvo.setBeginDate(startdate);
            ecdvo.setEndDate(enddate);
            ecdvo.setDateType("1");
            ecdvo.setPk_srcbill("");
            ecdvo.setPk_srcbilltype("");
            ecdvo.setVsrcbillno("");
            if (qvo.getBilltype() != null && !qvo.getBilltype().equals("")) {
                ecdvo.setBillType(qvo.getBilltype());
            }

            if (qvo.getSendertype() != null && !qvo.getSendertype().equals("")) {
                ecdvo.setSendertype(qvo.getSendertype());
            }

            ecdvos[0] = ecdvo;
        } catch (Exception ex) {
            ObmLog.error(ex.getMessage(), ex, this.getClass(), "getEcdVOs");
        }

        return ecdvos;
    }

    public DfgzHVO[] queryEbankDfgzByConditionString(String strWhere) throws BusinessException {
        if (strWhere == null) {
            strWhere = "1=1";
        }

        HYPubBO hy = new HYPubBO();
        DfgzHVO[] dfgzvos = (DfgzHVO[])hy.queryByCondition(DfgzHVO.class, strWhere);
        return dfgzvos;
    }

    public String getInParameter(AggEbankBillInfoQueryVO[] resultvos, String parameter) {
        StringBuffer sb = new StringBuffer();
        String returnString = "";
        if (resultvos.length == 0 || null == resultvos) {
            returnString = sb.append(parameter).append("=''").toString();
        }

        sb.append(parameter);

        for(int i = 0; i < resultvos.length; ++i) {
            sb.append("'");
            sb.append(resultvos[i].getParentVO().getEbillnum());
            sb.append("'");
            if (i >= 900 && i < resultvos.length - 1) {
                if (i % 900 == 0) {
                    sb.append(") or ");
                    sb.append(parameter);
                } else {
                    sb.append(",");
                }
            } else if (i < resultvos.length - 1) {
                sb.append(",");
            }

            if (i == resultvos.length - 1) {
                sb.append(")");
            }
        }

        returnString = sb.toString();
        return returnString;
    }

    public void dfgzFireEvent(String yurref) throws Exception {
        HYPubBO hy = new HYPubBO();
        String strWhere = " isNull(dr,0)=0 and logflag='1' and yurref='" + yurref + "' ";
        DfgzHVO[] dfgzbillvos = (DfgzHVO[])hy.queryByCondition(DfgzHVO.class, strWhere);
        PayStateVO[] sourcevos = new PayStateVO[dfgzbillvos.length];
        String eventType = "paystate_syn";
        String action = "download";
        String fireposition = "after_cx";

        for(int i = 0; i < sourcevos.length; ++i) {
            sourcevos[i] = new PayStateVO();
            sourcevos[i].setAction(action);
            sourcevos[i].setFireposition(fireposition);
            sourcevos[i].setYurref(dfgzbillvos[i].getYurref());
            sourcevos[i].setPayState(dfgzbillvos[i].getBillpaystate() == null ? -1 : dfgzbillvos[i].getBillpaystate());
            sourcevos[i].setMsg(dfgzbillvos[i].getPaymsg());
            sourcevos[i].setPk_user(dfgzbillvos[i].getModifier());
        }

        IObmEvent event = (IObmEvent)NCLocator.getInstance().lookup(IObmEvent.class);
        event.fireEvent("dfgz", eventType, sourcevos);
    }
}
