Пример #1
0
 private void doDeleteVO(SuperVO vo) {
   try {
     CRUDHelper.getCRUDService().deleteVo(vo);
   } catch (LfwBusinessException e) {
     LfwLogger.error(e.getMessage(), e);
   }
 }
Пример #2
0
 @Override
 public PortalModule getPortalModuleById(String moduleid) {
   try {
     PtModuleVO[] vos =
         CRUDHelper.getCRUDService()
             .queryVOs(" moduleid = '" + moduleid + "'", PtModuleVO.class, null, null, null);
     if (vos != null && vos.length > 0) {
       PtModuleVO vo = vos[0];
       PortalModule module = new PortalModule();
       module.setModule(vo.getModuleid());
       module.setDepends(vo.getDependentid());
       return module;
     }
   } catch (LfwBusinessException e) {
     LfwLogger.error(e.getMessage());
   }
   return null;
 }
Пример #3
0
  /**
   * 字段关联处理
   *
   * @param ds
   * @param rels
   */
  public void dealFieldRelation(Dataset ds, FieldRelation[] rels) {
    if (rels != null && rels.length != 0) {
      for (int i = 0; i < rels.length; i++) {
        FieldRelation rel = rels[i];
        try {
          if (!needDoRel(ds, rel)) continue;
          String sql = aggregateSql(ds, rel);
          List<Object[]> result = null;
          if (sql != null) {
            result =
                (List<Object[]>) CRUDHelper.getCRUDService().query(sql, new ArrayListProcessor());
          } else {
            result = new ArrayList<Object[]>();
          }
          // 如果查出数据为空,则增加一行,使后面置空逻辑可继续运行
          if (result.size() == 0) result.add(null);
          Iterator<Object[]> it = result.iterator();

          WhereField whereField = rel.getWhereField();
          // 外键字段
          String key = ds.getFieldSet().getField(whereField.getValue()).getId();
          // 关联字段
          MatchField[] mfs = rel.getMatchFields();
          int[] mfIndices = new int[mfs.length];
          for (int j = 0; j < mfIndices.length; j++) {
            mfIndices[j] = ds.nameToIndex(mfs[j].getWriteField());
          }

          // 记录是否关联过的标识,以便于处理多选关联
          Row[] rows = ds.getCurrentRowData().getRows();
          boolean[][] notFirst = new boolean[rows.length][];
          for (int j = 0; j < notFirst.length; j++) {
            notFirst[j] = new boolean[mfIndices.length];
          }

          while (it.hasNext()) {

            Object[] values = it.next();
            int keyIndex = ds.nameToIndex(key);
            for (int j = 0; j < rows.length; j++) {
              if (rows[j] instanceof EmptyRow) continue;
              String keyValue = (String) rows[j].getValue(keyIndex);
              if (keyValue != null && values != null) {
                // 将主键值分隔
                String[] keyValues = keyValue.split(",");
                for (int m = 0; m < keyValues.length; m++) {
                  // 找出匹配的主键值,将对应的值字段写入
                  if (values[values.length - 1] != null
                      && values[values.length - 1].toString().trim().equals(keyValues[m].trim())) {
                    for (int k = 0; k < mfIndices.length; k++) {
                      Object value = values[k];
                      int mfIndex = mfIndices[k];
                      Object oldValue = rows[j].getValue(mfIndex);

                      // 原来的值不为空,有2种情况。一种是残留值,这种情况应该去掉。另一种是上一循环设置的,这种情况应该拼上 ","
                      if (oldValue != null) {
                        if (notFirst[j][k]) {
                          // SuperVO vo = (SuperVO) cavos[j].getCavo();
                          if (!mfs[k].getReadField().equals(whereField.getKey())) {
                            value = oldValue.toString() + "," + value;
                            rows[j].setValue(mfIndex, value);
                          }
                        } else {
                          notFirst[j][k] = true;
                          rows[j].setValue(mfIndex, value);
                        }
                      } else {
                        notFirst[j][k] = true;
                        rows[j].setValue(mfIndex, value);
                      }
                    }
                    break;
                  }
                }
              }
              // 将数据置空
              else {
                for (int k = 0; k < mfIndices.length; k++) {
                  Object value = null;
                  int mfIndex = mfIndices[k];
                  rows[j].setValue(mfIndex, value);
                }
              }
            }
          }
          if (rel.getChildRelationList() != null) {
            dealFieldRelation(ds, rel.getChildRelationList().toArray(new FieldRelation[0]));
          }
        } catch (Exception e) {
          Logger.error(e.getMessage(), e);
        }
      }
    }
  }
Пример #4
0
 protected ILfwCRUDService<SuperVO, AggregatedValueObject> getCrudService() {
   return CRUDHelper.getCRUDService();
 }