/**
  * 功能:得到与某个clbh相关联的单据oid 作者:宋涛 创建时间:(2001-11-14 13:13:45) 参数:<|>o 返回值: 算法: 异常描述:
  *
  * @return java.lang.String[]
  * @param sClbh java.lang.String
  */
 public String[] getOids(QueryStructVO voQryStruct, String sClbh) throws BusinessException {
   String[] sResults = new String[0];
   try {
     ICreateSql createTools = getSqlCreater();
     if (voQryStruct.isWanglaiDetail()) {
       createTools = new CreateSql_WL();
     }
     createTools.initParam(voQryStruct);
     String strSQL = createTools.getOidSql();
     NewListQueryDAO dmo = new NewListQueryDAO();
     sResults = dmo.getVouchid(strSQL, sClbh);
   } catch (Exception e) {
     Log.getInstance(this.getClass()).error(e.getMessage());
     throw new BusinessShowException(
         "NewListQueryBO::getOids(QueryStructVO voQryStruct, String sClbh) Exception!", e);
   }
   return sResults;
 }
  /**
   * 通过查询对象、条件和显示字段构造查询语句,返回符合条件的查询结果。
   *
   * <p>创建日期:(2001-5-15)
   *
   * @return StatValueObject[] 查到的VO对象数组
   * @param QueryStructVO voQryStruct 查询结构
   * @exception BusinessException 异常说明。
   */
  public RSTransferVO getQueryResult(QueryStructVO voQryStruct) throws BusinessException {
    try {

      RSTransferVO voResult = new RSTransferVO();
      MemoryResultSet[] mrsResults = null;

      // add by wdg(2007-10-18)
      // 期初暂估冲回数据
      MemoryResultSet[] tempEstimateInitMrsResults = null;
      // 暂估发生数据
      MemoryResultSet[] tempEstimateOccurMrsResults = null;
      for (int i = 0; i < voQryStruct.getVetQryObj().size(); i++) {
        if (nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
            .getStrByID("2006", "UPTcommon-0100172") /*@res "客商"*/
            .equals(voQryStruct.getVetQryObj().get(i).getM_strDisplayName())) {
          voQryStruct.getVetQryObj().get(i).setPk_bdinfo("00010000000000000073");
        }
      }
      if (voQryStruct.getSecsrc() != null) {
        InvocationInfoProxy.getInstance().setUserDataSource(voQryStruct.getSecsrc());
      }
      if (true) {
        ListQueryMetadata queryMetadata =
            new ListQueryMetadata(QueryMetadataUtil.convertQryStruct2Metadata(voQryStruct));
        DateRange dateRange = new DateRange();
        dateRange.setStartDate(voQryStruct.getSumDate()[0]);
        dateRange.setEndDate(voQryStruct.getSumDate()[1]);
        queryMetadata.getConfig().setSumDateRange(dateRange);
        queryMetadata.getConfig().setMonthQuery(voQryStruct.isQuerybyPeriod());
        if (voQryStruct.getSecsrc() == null) {
          BalQryObjLogUtil.log(
              queryMetadata.getQueryObjects(),
              queryMetadata.getConfig().getSystem() == SysEnum.YS ? "20060504" : "20080504");
        }

        voResult = new ListQueryBO().query(queryMetadata);
        mrsResults = voResult.getResultset();
      } else {

        /** 插入单据信息,这是明细查询中的必查项目 */
        Vector<QryObjVO> vetDisplay = voQryStruct.getVetDisplay();
        vetDisplay = insertDjxx(vetDisplay);
        voQryStruct.setVetDisplay(vetDisplay);
        Vector vetObj = voQryStruct.getVetQryObj();
        vetObj = PubMethodVO.mergeVector(vetObj, voQryStruct.getVetGroupBy());
        voQryStruct.setVetQryObj(vetObj);
        voQryStruct.setVetGroupBy(new Vector());
        ICreateSql createTools = getSqlCreater();
        if (voQryStruct.isWanglaiDetail()) {
          createTools = new CreateSql_WL();
        }
        /*设置需要的查询语句*/
        int[] iPos;
        boolean[] bSum;
        if (!voQryStruct.isQuerybyPeriod()) {
          /*日期模式*/
          iPos =
              new int[] {
                0, 1, 2, 3, /*4, 5, 6, 7, 8, 9, 10*/
              };
          bSum =
              new boolean[] {
                false, false, false, false, /* false, false, false, false, false, false, false */
              };
        } else {
          /*期间模式*/
          iPos =
              new int[] {
                0, 1, 2, 3, /* 4, 5, 6, 7, 8, 9, 10, */ 2, 3, /*4, 5, 6, 7, 8, 9, 10*/
              };
          bSum =
              new boolean[] {
                false,
                false,
                false,
                false,
                /*
                false,
                false,
                false,
                false,
                false,
                false,
                false,*/
                true,
                true,
                /*true,
                true,
                true,
                true,
                true,
                true,
                true */ };
        }
        /*-----设置完毕----*/

        NewListQueryDAO dmo = new NewListQueryDAO();
        //        Debug.println("调用dmo类,进行查询");

        // zhongyue_begin for  多单位权限控制 begin
        nc.bs.arap.pub.CreatJoinSQLTool jointool = new nc.bs.arap.pub.CreatJoinSQLTool();
        if (voQryStruct.getSecsrc() != null) {
          InvocationInfoProxy.getInstance().setUserDataSource(voQryStruct.getSecsrc());
        }
        if (jointool.checkLegal(voQryStruct.getCorp())) {
          createTools.setQueryIdx(iPos, bSum);
          createTools.setDateType(voQryStruct);
          createTools.initParam(voQryStruct);
          String[] strSqls = createTools.getSQL();
          mrsResults = dmo.getQueryResult(strSqls);
        } else {
          String[] sPk_corps = voQryStruct.getCorp();
          if (sPk_corps != null) {
            for (int i = 0; i < sPk_corps.length; i++) {
              String[] tables = new PowerCtrlVO(sPk_corps[i]).getTables();
              if (voQryStruct.getPowerCtrlVO() != null) {
                voQryStruct.getPowerCtrlVO().setTables(tables);
              }
              voQryStruct.setCorp(new String[] {sPk_corps[i]});
              if (voQryStruct.getPowerCtrlVO() != null) {
                voQryStruct.getPowerCtrlVO().setPk_corp(new String[] {sPk_corps[i]});
              }
              createTools = getSqlCreater();
              if (voQryStruct.isWanglaiDetail()) {
                createTools = new CreateSql_WL();
              }
              createTools.setQueryIdx(iPos, bSum);
              createTools.setDateType(voQryStruct);
              createTools.initParam(voQryStruct);

              String[] strSqls = createTools.getSQL();
              mrsResults = mergeMultiCorps(mrsResults, dmo.getQueryResult(strSqls));
            }
          }
        }
      }
      String[] sPk_corps = voQryStruct.getCorp();
      if (sPk_corps != null) {
        for (int i = 0; i < sPk_corps.length; i++) {
          // 期初冲回数据要考虑数据权限,否则查出的无权限数据加入原期初结果集会造成数据增多
          if (!voQryStruct.isBlnClearEstimateDataShow()) {
            tempEstimateInitMrsResults =
                mergeMultiCorps(
                    tempEstimateInitMrsResults, getInitTempEstimateOffsetData(voQryStruct));
            tempEstimateOccurMrsResults =
                mergeMultiCorps(tempEstimateOccurMrsResults, getTempEstimateData(voQryStruct));
          }
        }
      }

      // end
      if (voQryStruct.isVouchshow()) {
        PubMethodVO.insertVouchidCol(mrsResults);
      }
      VOCompress.objectReference(mrsResults);
      voResult.setResultset(mrsResults);

      /*删除控制数据权限建立的临时表*/
      // new PubDMO().onDropTemTab(createTools.getPowerHashtable());

      // 如果查询条件为“已两清的暂估单据不显示”(add by wdg:2007-10-11)
      if (!voQryStruct.isBlnClearEstimateDataShow()) {
        mergeTempEstimateData(
            voQryStruct, voResult, tempEstimateInitMrsResults, tempEstimateOccurMrsResults);
      }

      if (!voQryStruct.isRecheck()
          && !(voQryStruct
                  .getStrBillType()
                  .equals(
                      NCLangRes4VoTransl.getNCLangRes()
                          .getStrByID("20060504", "UPP20060504-000228"))
              || voQryStruct
                  .getStrBillType()
                  .equals(
                      NCLangRes4VoTransl.getNCLangRes()
                          .getStrByID("20060504", "UPP20060504-000230")))) {
        Iterator<QryObjVO> iterator = voQryStruct.getVetQryObj().iterator();
        while (iterator.hasNext()) {
          QryObjVO qryObjVO = iterator.next();
          if ("bzbm".equals(qryObjVO.getQryfld())) {
            iterator.remove();
          }
        }
      }

      voResult.setObjs(getJoinTools().getQryObjs(voQryStruct.getVetQryObj()));
      voResult.setDisplays(getJoinTools().getQryObjs(voQryStruct.getVetDisplay()));
      MemoryResultSet sumRs = null;
      MemoryResultSet[] mrs = voResult.getResultset();
      if (isLastPageIndex(voQryStruct, voResult)) {
        sumRs = voResult.getResultset()[voResult.getResultset().length - 1];
        mrs =
            (MemoryResultSet[])
                ArrayUtils.subarray(voResult.getResultset(), 0, voResult.getResultset().length - 1);
      }
      MemoryResultSet[] mrsSource =
          prepareData(
              mrs,
              voQryStruct,
              voQryStruct.isQuerybyPeriod(),
              voResult.getObjs(),
              voResult.getDisplays());
      if (mrsSource != null) {
        int total = 0;
        for (MemoryResultSet ms : mrsSource) {
          if (ms != null && ms.getResultArrayList() != null)
            total += ms.getResultArrayList().size();
        }
        if (total > 20000) {
          throw new BusinessException("记录超过两万条,请分页查或缩小查询范围");
        }
      }
      voResult.setResultset(mrsSource);
      if (sumRs != null) {
        voResult.setResultset((MemoryResultSet[]) ArrayUtils.add(mrsSource, sumRs));
      }
      PubMethodVO.createCodeAndName(voResult.getObjs());
      PubMethodVO.insertCodeAndNameColumns(voResult.getResultset(), voResult.getObjs());
      return voResult;
    } catch (Exception e) {
      Log.getInstance(this.getClass()).error(e.getMessage());
      throw new BusinessShowException(e.getMessage());
    }
  }