Example #1
0
  /**
   * 此处插入方法说明。 功能描述: 自动将部门的条件变成包含所有下级部门 逻辑: 满足条件: 1- ConditionVO中包含 "部门"或“部门档案”项,而且存在PK值 返回值: 处理后的VO
   * 异常处理: 日期: 2003-09-05 谢高兴 输入参数:
   *
   * @param condvo nc.vo.pub.query.ConditionVO[]
   * @param String[] saPk_corp 需查的所有公司 处理逻辑: 1.先返回所有需要处理的项 2.然后将每个项生成相应的需要替换的VO列表 3.最后替换原来对应的项
   *     <p>修改时间:2007-8-21 修改人:张成 修改内容:增加对销售组织树型结构的支持-自动将销售组织的条件变成包含所有下级销售组织
   */
  public nc.vo.pub.query.ConditionVO[] getTotalSubPkVO(
      nc.vo.pub.query.ConditionVO[] condvo, String[] saPk_corp) throws Exception {
    int lenold;
    int lennew;

    lenold = condvo.length;
    if (lenold <= 0) {
      return condvo;
    }

    // 是否有部门项
    String sCurPk = null;
    boolean flag = false;
    ArrayList rowdept = new ArrayList();
    Integer newint;
    for (int i = 0; i < lenold; i++) {
      if ((condvo[i].getFieldName() != null)
          && (condvo[i].getFieldName().equals("部门")
              || condvo[i].getFieldName().equals("部门档案")
              || condvo[i].getFieldName().equals("销售组织") // v5.02增加
              // by
              // zhangcheng
              || condvo[i].getFieldName().indexOf("地区分类") >= 0 // v5.02增加
          // by
          // zhangcheng
          )
          && (("=".equals(condvo[i].getOperaCode()))
              || ("like".equals(condvo[i].getOperaCode()))
              || ("LIKE".equals(condvo[i].getOperaCode())))) {
        sCurPk = condvo[i].getValue();
        if (sCurPk != null && sCurPk.length() > 0) {
          newint = new Integer(i);
          rowdept.add(newint);
          flag = true;
        }
      }
    }

    if (!flag) {
      return condvo;
    }

    String[] sRetPk;
    // 包含所有子项的List
    ArrayList arAll = new ArrayList();
    for (int j = 0; j < rowdept.size(); j++) {
      // 单个项的List
      ArrayList arPer = new ArrayList();
      // 取下级部门的ID
      int rowindex = ((Integer) rowdept.get(j)).intValue();
      // sCurPk = condvo[rowindex].getValue();
      // 加入判断 避免空指针异常
      if (null != condvo[rowindex].getRefResult())
        sCurPk = condvo[rowindex].getRefResult().getRefPK();
      else sCurPk = NCLangResOnserver.getInstance().getStrByID("scmpub", "UPPscmpub-000054") /*
					 * @res
					 * "无效的输入!"
					 */;

      String sCurName;
      if (condvo[rowindex].getRefResult() != null) // 加入判断,避免抛错 wj
      sCurName = condvo[rowindex].getRefResult().getRefName();
      else sCurName = NCLangResOnserver.getInstance().getStrByID("scmpub", "UPPscmpub-000054") /*
																									 * @res
																									 * "无效的输入!"
																									 */;
      String sRetName[] = null; // modify by zxj

      // v5.02修改,增加对销售组织条件的处理////////////////////
      try {
        ArrayList retArray = null;
        if (("部门档案".equals(condvo[rowindex].getFieldName()))
            || ("部门".equals(condvo[rowindex].getFieldName()))) {
          retArray = getTotalSubPkAndNames(DEPTDOC, sCurPk, sCurName, saPk_corp);
        } else if (("销售组织".equals(condvo[rowindex].getFieldName()))) {
          retArray = getTotalSubPkAndNames(SALESTRU, sCurPk, sCurName, saPk_corp);
        } else if (null != condvo[rowindex].getFieldName()
            && condvo[rowindex].getFieldName().indexOf("地区分类") >= 0) {
          retArray = getTotalSubPkAndNames(AREACL, sCurPk, sCurName, saPk_corp);
        }
        sRetPk = (String[]) retArray.get(0);
        sRetName = (String[]) retArray.get(1);
      } catch (Exception e) {
        nc.vo.scm.pub.SCMEnv.out(e);
        /** <needn't ??> */
        sRetPk = null;
      }
      // v5.02修改////////////////////////////////////////

      // 如果只有原来一个值,则不进行替换
      if (sRetPk == null || sRetPk.length <= 1) {
        arAll.add(null);
        continue;
      }
      nc.vo.pub.query.ConditionVO vo;
      for (int i = 0; i < sRetPk.length; i++) {
        vo = new nc.vo.pub.query.ConditionVO();
        vo.setDataType(condvo[rowindex].getDataType());
        vo.setDirty(condvo[rowindex].isDirty());
        vo.setFieldCode(condvo[rowindex].getFieldCode());
        vo.setFieldName(condvo[rowindex].getFieldName());
        vo.setOperaCode(condvo[rowindex].getOperaCode());
        vo.setOperaName(condvo[rowindex].getOperaName());
        vo.setTableCode(condvo[rowindex].getTableCodeForMultiTable());
        vo.setTableName(condvo[rowindex].getTableNameForMultiTable());
        vo.setValue(sRetPk[i]);
        // modify by zxj
        nc.vo.pub.query.RefResultVO refresultvo = new nc.vo.pub.query.RefResultVO();
        refresultvo.setRefPK(sRetPk[i]);
        refresultvo.setRefName(sRetName[i]);
        vo.setRefResult(refresultvo);
        //

        // 关系操作设置位or
        vo.setLogic(false);
        // 第一个设置左括号,最后一个设置右括号
        if (i == 0) {
          vo.setNoLeft(false);
          // 如果原来有左括号,则设置为and
          if (!condvo[rowindex].getNoLeft()) {
            vo.setLogic(true);
          } else {
            vo.setLogic(condvo[rowindex].getLogic());
          }
        } else if (i == sRetPk.length - 1) {
          vo.setNoRight(false);
        }
        arPer.add(vo);
      }
      // 如果原来有左括号
      if (!condvo[rowindex].getNoLeft()) {
        vo = new nc.vo.pub.query.ConditionVO();
        // vo.setDataType(condvo[rowindex].getDataType());
        // 都设置为整数,最后的条件合成为1=1 如果是字符串合成是1='1'可能在其他的数据库中为非法
        vo.setDataType(1);
        vo.setFieldCode("1");
        vo.setOperaCode("=");
        vo.setValue("1");
        vo.setLogic(condvo[rowindex].getLogic());
        vo.setNoLeft(false);
        arPer.add(0, vo);
      }
      // 如果原来有右括号
      if (!condvo[rowindex].getNoRight()) {
        vo = new nc.vo.pub.query.ConditionVO();
        // vo.setDataType(condvo[rowindex].getDataType());
        vo.setDataType(1);
        vo.setFieldCode("1");
        vo.setOperaCode("=");
        vo.setValue("1");
        vo.setLogic(true);
        vo.setNoRight(false);
        arPer.add(vo);
      }

      arAll.add(arPer);
    }

    // 合成最后的List
    ArrayList arRes = new ArrayList();

    // 先复制原来的数组到list
    for (int i = 0; i < lenold; i++) {
      arRes.add(condvo[i]);
    }
    // 从后往前复制
    for (int j = rowdept.size() - 1; j >= 0; j--) {
      int rowindex = ((Integer) rowdept.get(j)).intValue();
      ArrayList arPer = (ArrayList) arAll.get(j);
      if (arPer == null) {
        continue;
      }
      arRes.remove(rowindex);
      if (rowindex >= arRes.size()) {
        // 从最后顺序增加
        for (int k = 0; k < arPer.size(); k++) {
          arRes.add(arPer.get(k));
        }
      } else {
        // 反着从中间插入
        for (int k = arPer.size() - 1; k >= 0; k--) {
          arRes.add(rowindex, arPer.get(k));
        }
      }
    }

    int iSize = arRes.size();
    return (nc.vo.pub.query.ConditionVO[]) (arRes.toArray(new nc.vo.pub.query.ConditionVO[iSize]));
  }
  /**
   * @param cvos
   * @param pk_corp
   * @return 根据客户管理id和基本id分别构建两个sql,分别用于构建供应链和财务的sql
   * @throws SQLException
   * @throws BusinessException
   * @throws NamingException
   * @throws SystemException
   */
  private String[] getSql(ConditionVO[] cvos, String pk_corp)
      throws SQLException, BusinessException, SystemException, NamingException {
    HashSet<String> pk_cumandoc = new HashSet();
    HashSet<String> pk_cubasdoc = new HashSet();
    HashSet<String> cproductid = new HashSet();
    HashSet<String> cbiztypeid = new HashSet();

    HashSet<String> newValue;
    String querySql;
    for (ConditionVO cvo : cvos) {
      if (cvo.getFieldCode().equals("pk_cumandoc")
          || cvo.getFieldCode().equals("creditlevel")
          || cvo.getFieldCode().equals("pk_pricegroupcorp")
          || cvo.getFieldCode().equals("pk_areacl")
          || cvo.getFieldCode().equals("pk_salestru")) {
        if (cvo.getFieldCode().equals("pk_cumandoc")) {
          pk_cumandoc.add(cvo.getValue());
        } else {
          if (cvo.getFieldCode().equals("pk_areacl")) {
            querySql =
                "select pk_cumandoc from bd_cumandoc, bd_cubasdoc where bd_cumandoc.pk_cubasdoc=bd_cubasdoc.pk_cubasdoc "
                    + " and custflag in('0','2') and bd_cumandoc.pk_corp='"
                    + pk_corp
                    + "' and pk_areacl "; // 增加custflag 过滤
            if ("like".equals(cvo.getOperaCode())) {
              querySql +=
                  " in (select pk_areacl from bd_areacl where areaclcode like '"
                      + cvo.getRefResult().getRefCode()
                      + "%')";
            } else {
              querySql += "='" + cvo.getValue() + "'";
            }
          } else {
            querySql =
                "select pk_cumandoc from bd_cumandoc where "
                    + cvo.getFieldCode()
                    + "='"
                    + cvo.getValue()
                    + "'";
          }
          newValue = queryNewValue(querySql);
          if (newValue.isEmpty())
            throw new BusinessException(
                nc.bs.ml.NCLangResOnserver.getInstance()
                    .getStrByID(
                        "scmsocredit",
                        "UPPSCMSOCredit-000292",
                        null,
                        new String[] {cvo.getFieldName()}) /*
						 * @res
						 * "所选{0}中没有相匹配的客户!"
						 */);
          updateValue(pk_cumandoc, newValue);
        }
      } else if (cvo.getFieldCode().equals("cproductid")) {
        cproductid.add(cvo.getValue());
      } else if (cvo.getFieldCode().equals("cbiztypeid")) {
        cbiztypeid.add(cvo.getValue());
      }
    } // end for

    pk_cumandoc = findAllForwardCust(pk_cumandoc, pk_corp);
    fillPkCubas(pk_cumandoc, pk_cubasdoc);

    String[] results = new String[2];
    results[0] = buildSql(pk_cumandoc, cproductid, cbiztypeid, "temp_so_forminsql001");
    results[1] = buildSql(pk_cubasdoc, cproductid, cbiztypeid, "temp_so_forminsql002");

    return results;
  }