Ejemplo n.º 1
0
  /**
   * 字段重复判断。 (区分参数组、参数、参数项的概念) 不同参数的code不可以相同,必须帮助每个参数 的code值对整个参数表中的“参数”唯一
   *
   * @param param
   */
  private void judgeLegit(Param param, int flag) {
    // 如果保存的是参数(区分参数组、参数、参数项的概念),则要保证code值对所有“参数”唯一
    Integer type = param.getType();
    if (ParamConstants.NORMAL_PARAM_TYPE.equals(type)) {
      String hql = "select p.id from Param p where p.type = ? and p.code = ?";
      List<?> list =
          paramDao.getEntities(
              hql, new Object[] {ParamConstants.NORMAL_PARAM_TYPE, param.getCode()});
      if (list.size() > flag) {
        throw new BusinessException("相同参数名称(指CODE)已经存在,请更改参数名称后再保存!");
      }
      return;
    }

    String hql = "select p.id from Param p where p.parentId=" + param.getParentId();
    if (ParamConstants.GROUP_PARAM_TYPE.equals(param.getType())) { // 参数组不能同名
      hql += " and p.name='" + param.getName() + "'";
    } else if (ParamConstants.NORMAL_PARAM_TYPE.equals(param.getType())) {
      if (EasyUtils.isNullOrEmpty(param.getName())) {
        param.setName(param.getCode());
      }
      hql += " and (p.name='" + param.getName() + "' or p.code='" + param.getCode() + "')";
    } else {
      if (EasyUtils.isNullOrEmpty(param.getText())) {
        param.setText(param.getValue());
      }
      Param parentParam = paramDao.getEntity(param.getParentId());
      param.setModality(parentParam.getModality());
      hql += " and (p.value='" + param.getValue() + "' or p.text='" + param.getText() + "')";
    }

    if (paramDao.getEntities(hql).size() > flag) {
      throw new BusinessException("字段重复! + " + hql);
    }
  }
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 void delete(Long id) {
    // 一并删除子节点
    List<?> params = paramDao.getChildrenById(id);
    for (Object entity : params) {
      Param param = (Param) entity;
      paramDao.delete(param);

      // 刷新参数缓存,如果删除的是缓存项,则需要手动的刷新其所属的参数节点
      ParamManager.remove(param.getCode());
    }
  }
Ejemplo n.º 4
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;
  }