Ejemplo n.º 1
0
  private List<?> copyParamTo(Param copyParam, Param toParam) {
    Long copyParamId = copyParam.getId();
    List<?> params = paramDao.getChildrenById(copyParamId);
    Map<Long, Long> paramMapping = new HashMap<Long, Long>(); // 复制出来的新节点 与 被复制源节点 建立一一对应关系(ID 对 ID)
    for (int i = 0; i < params.size(); i++) {
      Param param = (Param) params.get(i);
      Long sourceParamId = param.getId();

      paramDao.evict(param);
      param.setId(null);
      if (sourceParamId.compareTo(copyParamId) == 0) {
        param.setParentId(toParam.getId());
        param.setSeqNo(paramDao.getNextSeqNo(toParam.getId()));
      } else {
        param.setParentId(paramMapping.get(param.getParentId()));
      }

      if (ParamConstants.TRUE.equals(toParam.getDisabled())) {
        param.setDisabled(toParam.getDisabled()); // 如果目标根节点是停用状态,则所有新复制出来的节点也一律为停用状态
      }

      judgeLegit(param, ParamConstants.EDIT_FLAG);

      paramDao.create(param);
      paramMapping.put(sourceParamId, param.getId());
    }
    return params;
  }
Ejemplo n.º 2
0
  private List<?> copyParamLocal(Param copyParam) {
    List<?> params = paramDao.getChildrenById(copyParam.getId());
    Map<Long, Long> paramMapping = new HashMap<Long, Long>(); // 复制出来的新节点 与 被复制源节点 建立一一对应关系(ID 对 ID)
    for (int i = 0; i < params.size(); i++) {
      Param param = (Param) params.get(i);
      Long sourceParamId = param.getId();

      paramDao.evict(param);
      param.setId(null);
      if (sourceParamId.compareTo(copyParam.getId()) == 0) { // 复制指定节点
        if (ParamConstants.GROUP_PARAM_TYPE.equals(copyParam.getType())) {
          param.setName(ParamConstants.COPY_PREFIX_NAME + copyParam.getName());
        } else if (ParamConstants.NORMAL_PARAM_TYPE.equals(copyParam.getType())) {
          param.setCode(ParamConstants.COPY_PREFIX_CODE + copyParam.getCode());
          param.setName(ParamConstants.COPY_PREFIX_NAME + copyParam.getName());
        } else {
          param.setText(ParamConstants.COPY_PREFIX_NAME + copyParam.getText());
        }
        param.setSeqNo(paramDao.getNextSeqNo(copyParam.getParentId()));
      }
      // 复制指定节点的儿孙节点
      else {
        param.setParentId(paramMapping.get(param.getParentId()));
      }

      paramDao.create(param);
      paramMapping.put(sourceParamId, param.getId());
    }
    return params;
  }
Ejemplo n.º 3
0
  public Param saveParam(Param param) {
    if (null == param.getId()) {
      param.setSeqNo(paramDao.getNextSeqNo(param.getParentId()));
      judgeLegit(param, ParamConstants.SAVE_FLAG);
      paramDao.create(param);
    } else {
      judgeLegit(param, ParamConstants.EDIT_FLAG);
      paramDao.update(param);
    }

    // 刷新参数缓存 ,如果保存的是缓存项,则需要手动的刷新其所属的参数节点
    ParamManager.remove(param.getCode());
    return param;
  }
Ejemplo n.º 4
0
  public void move(Long paramId, Long toParamId) {
    List<?> params = paramDao.getChildrenById(paramId);
    Param toParam = paramDao.getEntity(toParamId);
    for (int i = 0; i < params.size(); i++) {
      Param param = (Param) params.get(i);
      if (param.getId().equals(paramId)) { // 判断是否是移动节点(即被移动枝的根节点)
        param.setSeqNo(paramDao.getNextSeqNo(toParamId));
        param.setParentId(toParamId);
      }

      if (ParamConstants.TRUE.equals(toParam.getDisabled())) {
        param.setDisabled(ParamConstants.TRUE); // 如果目标根节点是停用状态,则所有新复制出来的节点也一律为停用状态
      }

      judgeLegit(param, ParamConstants.EDIT_FLAG);
      paramDao.update(param);
    }
  }