Esempio n. 1
0
 /**
  * 为了避免由于权限配置不严格,导致未授权的Controller数据操作访问,父类提供protected基础实现,子类根据需要覆写public然后调用基类方法
  *
  * @return JSON操作提示
  */
 @MetaData(value = "删除")
 protected HttpHeaders doDelete() {
   Set<T> enableDeleteEntities = Sets.newHashSet();
   Collection<T> entities = this.getEntitiesByParameterIds();
   for (T entity : entities) {
     // 添加检查逻辑:当前对象是否允许被删除,如状态检查
     if (!isDisallowDelete(entity)) {
       enableDeleteEntities.add(entity);
     }
   }
   ExtRevisionListener.setOperationEvent(RevisionType.DEL.name());
   // 对于批量删除,循环每个对象调用Service接口删除,则各对象删除事务分离
   // 这样可以方便某些对象删除失败不影响其他对象删除
   // 如果业务逻辑需要确保批量对象删除在同一个事务则请子类覆写调用Service的批量删除接口
   for (T entity : enableDeleteEntities) {
     getEntityService().delete(entity);
   }
   int rejectSize = entities.size() - enableDeleteEntities.size();
   setModel(
       OperationResult.buildSuccessResult(
           "删除操作完成.删除:"
               + enableDeleteEntities.size()
               + "条"
               + (rejectSize > 0 ? ",拒绝:" + rejectSize + "条" : "")));
   return buildDefaultHttpHeaders();
 }
Esempio n. 2
0
 /**
  * 为了避免由于权限配置不严格,导致未授权的Controller数据操作访问,父类提供protected基础实现,子类根据需要覆写public然后调用基类方法
  *
  * @return JSON操作提示
  */
 @MetaData(value = "更新")
 protected HttpHeaders doUpdate() {
   ExtRevisionListener.setOperationEvent(RevisionType.MOD.name());
   getEntityService().save(bindingEntity);
   setModel(OperationResult.buildSuccessResult("更新操作成功", bindingEntity));
   return buildDefaultHttpHeaders();
 }
Esempio n. 3
0
  @MetaData(value = "保存")
  protected HttpHeaders doSave() {
    getEntityService().save(bindingEntity);

    // 附件关联处理,自动处理以attachment为前缀的参数
    if (bindingEntity instanceof AttachmentableEntity) {
      Enumeration<?> names = getRequest().getParameterNames();
      Set<String> attachmentNames = Sets.newHashSet();
      while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (name.startsWith("_attachment_")) {
          attachmentNames.add(name);
        }
      }
      if (attachmentNames.size() > 0) {
        AttachmentFileService attachmentFileService =
            SpringContextHolder.getBean(AttachmentFileService.class);
        for (String attachmentName : attachmentNames) {
          String[] attachments = getParameterIds(attachmentName);
          attachmentFileService.attachmentBind(
              attachments,
              bindingEntity,
              StringUtils.substringAfter(attachmentName, "_attachment_"));
        }
      }
    }
    setModel(OperationResult.buildSuccessResult("数据保存成功", bindingEntity));
    return buildDefaultHttpHeaders();
  }
Esempio n. 4
0
 /**
  * 为了避免由于权限配置不严格,导致未授权的Controller数据操作访问,父类提供protected基础实现,子类根据需要覆写public然后调用基类方法
  *
  * @return JSON操作提示
  */
 @MetaData(value = "创建")
 protected HttpHeaders doCreate() {
   // 检查提交的数据参数符合用户ACL权限,否则拒绝创建数据
   checkEntityAclPermission(bindingEntity);
   ExtRevisionListener.setOperationEvent(RevisionType.ADD.name());
   getEntityService().save(bindingEntity);
   setModel(OperationResult.buildSuccessResult("创建操作成功", bindingEntity));
   return buildDefaultHttpHeaders();
 }
Esempio n. 5
0
  public HttpHeaders doPasswd() {
    AuthUserDetails authUserDetails = AuthContextHolder.getAuthUserDetails();
    Assert.notNull(authUserDetails);
    HttpServletRequest request = ServletActionContext.getRequest();
    String oldpasswd = request.getParameter("oldpasswd");
    String newpasswd = request.getParameter("newpasswd");
    Assert.isTrue(StringUtils.isNotBlank(oldpasswd));
    Assert.isTrue(StringUtils.isNotBlank(newpasswd));

    User user = userService.findByUid(authUserDetails.getUid());
    String encodedPasswd = userService.encodeUserPasswd(user, oldpasswd);
    if (!encodedPasswd.equals(user.getPassword())) {
      setModel(OperationResult.buildFailureResult("原密码不正确,请重新输入"));
    } else {
      userService.save(user, newpasswd);
      setModel(OperationResult.buildSuccessResult("密码修改成功,请在下次登录使用新密码"));
    }
    return new DefaultHttpHeaders().disableCaching();
  }
Esempio n. 6
0
 @MetaData(value = "更新角色关联")
 public HttpHeaders doUpdateRelatedRoleR2s() {
   reportDefService.updateRelatedRoleR2s(getId(), getParameterIds("r2ids"));
   setModel(OperationResult.buildSuccessResult("角色关联操作完成"));
   return buildDefaultHttpHeaders();
 }
Esempio n. 7
0
  @MetaData(title = "移动/复制")
  public HttpHeaders doDrag() {
    Set<Menu> operationEntities = Sets.newHashSet();
    Menu target = null;
    String targetId = this.getParameter("targetId");
    if (StringUtils.isNotBlank(targetId)) {
      target = getEntityService().findOne(targetId);
    }

    Collection<Menu> entities = this.getEntitiesByParameterIds();
    String moveType = this.getParameter("moveType");
    String copy = this.getParameter("copy", "false");
    if (BooleanUtils.toBoolean(copy)) {
      Collection<Menu> copyEntities = Lists.newArrayList();
      for (Menu menu : entities) {
        copyEntities.add(cloneNewEntity(menu, "children", "parent"));
      }
      entities = copyEntities;
    }
    if (TreeNodeConstant.TreeNodeDragType.prev.name().equals(moveType)
        || TreeNodeConstant.TreeNodeDragType.next.name().equals(moveType)) {
      int max = 0;
      for (Menu menu : entities) {
        if (menu.getOrderRank() > max) {
          max = menu.getOrderRank();
        }
      }
      Iterable<Menu> children = null;
      Menu targetParent = target.getParent();
      if (targetParent == null) {
        children = menuService.findRoots();
      } else {
        children = target.getParent().getChildren();
      }
      if (TreeNodeConstant.TreeNodeDragType.prev.name().equals(moveType)) {
        List<Menu> childrenPrev = Lists.newArrayList();
        for (Menu menu : children) {
          if (menu.getOrderRank() >= target.getOrderRank()) {
            menu.setOrderRank(menu.getOrderRank() + max);
            operationEntities.add(menu);
          } else {
            childrenPrev.add(menu);
          }
        }
        int maxPrev = 0;
        for (Menu menu : childrenPrev) {
          if (menu.getOrderRank() > maxPrev) {
            maxPrev = menu.getOrderRank();
          }
        }
        for (Menu menu : entities) {
          menu.setOrderRank(menu.getOrderRank() + maxPrev);
          operationEntities.add(menu);
        }
      } else if (TreeNodeConstant.TreeNodeDragType.next.name().equals(moveType)) {
        for (Menu menu : children) {
          if (menu.getOrderRank() > target.getOrderRank()) {
            menu.setOrderRank(menu.getOrderRank() + max);
            operationEntities.add(menu);
          }
        }
        for (Menu menu : entities) {
          menu.setOrderRank(menu.getOrderRank() + target.getOrderRank());
          operationEntities.add(menu);
        }
      }
    } else if (TreeNodeConstant.TreeNodeDragType.inner.name().equals(moveType)) {
      Iterable<Menu> children = null;
      if (target == null) {
        children = menuService.findRoots();
      } else {
        children = target.getChildren();
      }
      int max = 0;
      for (Menu menu : children) {
        if (menu.getOrderRank() > max) {
          max = menu.getOrderRank();
        }
      }
      for (Menu menu : entities) {
        menu.setOrderRank(menu.getOrderRank() + max);
        menu.setParent(target);
        operationEntities.add(menu);
      }
    } else {
      throw new IllegalArgumentException("moveType=" + moveType);
    }
    getEntityService().save(operationEntities);
    setModel(OperationResult.buildSuccessResult("更新菜单所属上级节点操作完成"));
    return buildDefaultHttpHeaders();
  }
Esempio n. 8
0
 @MetaData(value = "批量添加")
 public HttpHeaders doCreateBatch() {
   dataDictService.save(batchDataDicts);
   setModel(OperationResult.buildSuccessResult("批量添加完成"));
   return buildDefaultHttpHeaders();
 }