private static HashMap queryRetailMeas(String[] invids, String pk_corp) throws BusinessException {

    String currency = new SysInitBO().getPkValue(pk_corp, "BD301");
    StringBuffer sql =
        new StringBuffer("select distinct cinvbasdocid as cinvbasid ,cmeasdocid as pk_measdoc  ");
    sql.append(" from prm_tariffcurlist prm ,  bd_invmandoc man ");
    // sql.append(" left outer join bd_convert con on
    // bas.pk_invbasdoc=con.pk_invbasdoc ");
    sql.append(
        " where prm.cinventoryid=man.pk_invmandoc and man.pk_corp='"
            + pk_corp
            + "' and prm.ccurrencyid='"
            + currency
            + "'"
            + SQLUtil.formInSQL("man.pk_invbasdoc", invids));

    HashMap hmData = new HashMap();
    ArrayList alinv = null;
    try {
      InvVO[] voInvs = (InvVO[]) new SmartDMO().selectBySql(sql.toString(), InvVO.class);

      if (voInvs != null && voInvs.length > 0) {
        for (int i = 0; i < voInvs.length; i++) {

          if (!hmData.containsKey(voInvs[i].getCinvbasid())) {

            hmData.put(voInvs[i].getCinvbasid(), voInvs[i].getPk_measdoc());
          }
        }
      }
    } catch (Exception e) {
      throw new BusinessException();
    }
    return hmData;
  }
  private static HashMap queryInvVos(String[] invids) throws BusinessException {
    StringBuffer sql =
        new StringBuffer(
            "select bas.pk_invbasdoc as cinvbasid, bas.invcode ,bas.pk_measdoc as pk_measdoc,assistunit,con.pk_measdoc as cassistunitid ,con.mainmeasrate  ");
    sql.append(" from bd_invbasdoc bas ");
    sql.append("  left outer join bd_convert con on bas.pk_invbasdoc=con.pk_invbasdoc ");
    sql.append(" where 1=1 " + SQLUtil.formInSQL("bas.pk_invbasdoc", invids));

    HashMap hmData = new HashMap();
    ArrayList alinv = null;
    try {
      InvVO[] voInvs = (InvVO[]) new SmartDMO().selectBySql(sql.toString(), InvVO.class);

      if (voInvs != null && voInvs.length > 0) {
        for (int i = 0; i < voInvs.length; i++) {
          if (hmData.containsKey(voInvs[i].getCinvbasid())) {
            alinv = (ArrayList) hmData.get(voInvs[i].getCinvbasid());
          } else {
            alinv = new ArrayList();
            hmData.put(voInvs[i].getCinvbasid(), alinv);
          }

          alinv.add(voInvs[i]);
        }
      }
    } catch (Exception e) {
      throw new BusinessException();
    }
    return hmData;
  }
  public static void convertFreeValue(String pk_corp, IFreeField[] voItems)
      throws BusinessException {

    if (voItems == null || voItems.length == 0) return;

    HashMap<String, String> hmInv = new HashMap<String, String>();
    for (int i = 0; i < voItems.length; i++) {
      String invid = voItems[i].getInvBasID();
      hmInv.put(invid, invid);
    }

    String[] invids = new String[hmInv.size()];
    hmInv.keySet().toArray(invids);

    String sql =
        " select pk_invbasdoc,bas.free1,bas.free2,bas.free3,bas.free4,bas.free5 from bd_invbasdoc bas where  coalesce(bas.free1,bas.free2,bas.free3,bas.free4,bas.free5,'ZZ') !='ZZ' ";
    sql = sql + SQLUtil.formInSQL("pk_invbasdoc", invids);

    Object[] values = null;
    try {
      values = new SmartDMO().selectBy2(sql);
    } catch (Exception e) {
      SCMEnv.out(e);
      throw new BusinessException(e.getMessage());
    }

    FreeVO voFree = null;
    HashMap<String, FreeVO> hmFree = new HashMap<String, FreeVO>();
    if (values != null) {
      for (int i = 0; i < values.length; i++) {
        Object[] itemValues = (Object[]) values[i];

        voFree = new FreeVO();
        voFree.setPk_invbasdoc((String) itemValues[0]);
        voFree.setVfreeid1((String) itemValues[1]);
        voFree.setVfreeid2((String) itemValues[2]);
        voFree.setVfreeid3((String) itemValues[3]);
        voFree.setVfreeid4((String) itemValues[4]);
        voFree.setVfreeid5((String) itemValues[5]);

        hmFree.put(voFree.getPk_invbasdoc(), voFree);
      }
    }

    HashMap hmPara = getParaFreeAndPosMap(pk_corp);

    for (int i = 0; i < voItems.length; i++) {
      String invid = voItems[i].getInvBasID();
      Object[] ncvalues = new Object[5];
      Object[] retailvalues = voItems[i].getRetailFreeValue();

      if (hmFree.containsKey(invid)) {
        voFree = (FreeVO) hmFree.get(invid);

        int count = 0;
        for (int j = 0; j < 5; j++) {
          String key = (String) voFree.getAttributeValue("vfreeid" + String.valueOf(j + 1));
          if (key != null) count = count + 1;
          if (hmPara.containsKey(key)) {
            ncvalues[j] = retailvalues[((Integer) hmPara.get(key)).intValue() - 1];
          } else ncvalues[j] = null;
          if (ncvalues[j] != null) count = count - 1;
        }

        voItems[i].setNCFreeValue(ncvalues);

        if (count != 0) throw new BusinessException("请检查自由项值的正确性!");

      } else voItems[i].setNCFreeValue(null);
    }
  }