Пример #1
0
  @Override
  protected Condition getCondition(String value) {
    if (value == null || value.length() == 0) return null;

    AndCondition c = new AndCondition();

    // 车辆状态条件
    Condition statuesCondition =
        ConditionUtils.toConditionByComma4IntegerValue(this.status, "o.status_");
    if (statuesCondition != null) c.add(statuesCondition);

    // 排序条件
    c.add(new OrderCondition("o.status_", Direction.Asc).add("o.number_", Direction.Desc));

    // 左右like的自动判断处理
    if (value.startsWith("%")) {
      if (!value.endsWith("%")) {
        c.add(new LikeRightCondition("o.number_", value)); // like右边
        return c;
      }
    } else if (value.endsWith("%")) {
      c.add(new LikeLeftCondition("o.number_", value)); // like左边
      return c;
    }
    c.add(new LikeCondition("o.number_", value)); // 左右都like

    return c;
  }
Пример #2
0
  @Override
  protected Condition getGridSpecalCondition() {
    OrCondition orCondition = new OrCondition();
    AndCondition operateFoldersCondition = new AndCondition();
    AndCondition publicFoldersCondition = new AndCondition();
    // 状态条件
    Condition statusCondition = null;
    Condition typeCondition = null;
    // Condition userCondition = null;
    Condition authorityCondition = null;
    Condition eliminateCondition = null;
    // Condition tierCondition = null;

    // 状态
    if (status != null && status.length() > 0) {
      String[] ss = status.split(",");
      if (ss.length == 1) {
        statusCondition = new EqualsCondition("f.status_", new Integer(ss[0]));
      } else {
        statusCondition = new InCondition("f.status_", StringUtils.stringArray2IntegerArray(ss));
      }
    }
    // 文件夹类型
    typeCondition = new EqualsCondition("f.type_", NetdiskFile.TYPE_FOLDER);
    // 当前用户只能查看自己上传的文件
    SystemContext context = (SystemContext) this.getContext();
    // userCondition = new EqualsCondition("f.author_id", context
    // .getUserHistory().getId());

    // 文件夹不能隶属于自己
    if (folderId != null) {
      eliminateCondition = new NotEqualsCondition("f.id", folderId);
    }
    // 父级文件夹不能隶属子级
    // 当前用户有权限查看的文件
    Serializable[] ids = this.netdiskFileService.getUserSharFileId2All(context.getUser().getId());
    // 查找当前文件的父级
    // 可以操作的文件夹id
    List<Object> operateId = new ArrayList<Object>();
    if (folderId != null) {
      Serializable[] myselfAndChildId = this.netdiskFileService.getMyselfAndChildFileId(folderId);
      // 排除自己与子文件id后来的数组
      List<Object> eliminateId = new ArrayList<Object>();
      if (ids != null) {
        for (Serializable id : ids) {
          boolean isIn = false;
          for (Serializable pid : myselfAndChildId) {
            if (id.equals(pid)) {
              isIn = true;
              break;
            }
          }
          if (!isIn) {
            eliminateId.add(id);
          }
        }
        // 找出可操作的id
        if (!eliminateId.isEmpty()) {
          for (int i = 0; i < eliminateId.size(); i++) {
            // 查看当前文件是否设置访问权限,如果有就根据当前的权限来判断
            NetdiskShare myNetdiskShare =
                this.netdiskFileService.getNetdiskShare(
                    context.getUser().getId(), Long.valueOf(eliminateId.get(i).toString()));
            // 如果是自己的建的文件夹也操作
            NetdiskFile netdiskFile =
                this.netdiskFileService.load(Long.valueOf(eliminateId.get(i).toString()));
            if (netdiskFile.getAuthor().getId().equals(context.getUserHistory().getId())) {
              operateId.add(eliminateId.get(i));
            } else if (myNetdiskShare != null) {
              if (haveAuthority(myNetdiskShare.getRole(), 0)) {
                // 如果有权限就添加
                operateId.add(eliminateId.get(i));
              }
            } else {
              // 获取当前的文件和父级文件
              Serializable[] ParentIds =
                  this.netdiskFileService.getMyselfAndParentsFileId(
                      Long.valueOf(eliminateId.get(i).toString()));
              // 判断当前文件或父级文件夹该用户是否拥有编辑权限
              for (Serializable pid : ParentIds) {
                boolean isOwer = false;
                NetdiskFile nf = this.netdiskFileService.load(pid);
                Set<NetdiskShare> netdiskShare = nf.getFileVisitors();
                if (!netdiskShare.isEmpty()) {
                  Iterator<NetdiskShare> n = netdiskShare.iterator();
                  while (n.hasNext()) {
                    NetdiskShare ns = n.next();
                    if (ns.getAid().equals(context.getUser().getId())) {
                      if (haveAuthority(ns.getRole(), 0)) {
                        // 如果有权限就添加
                        operateId.add(eliminateId.get(i));
                        isOwer = true;
                        break;
                      }
                    }
                  }
                  if (isOwer) {
                    break;
                  }
                }
              }
            }
          }
        }
      }

      // 组装条件
      String qlStr4File = "";
      if (operateId.size() != 0) {
        for (int i = 0; i < operateId.size(); i++) {
          if (i + 1 != operateId.size()) {
            qlStr4File += "?,";
          } else {
            qlStr4File += "?";
          }
        }
      }
      authorityCondition =
          orCondition
              .add(
                  (operateId.size() != 0
                      ? new QlCondition("f.id in (" + qlStr4File + ")", operateId)
                      : null))
              .setAddBracket(true);
    }
    // 如果是公共硬盘管理员可以选择公共硬盘的文件夹
    Condition publicCondition = null;
    if (this.isPublicHardDiskManagement()) {
      publicCondition = new EqualsCondition("f.folder_type", NetdiskFile.FOLDER_TYPE_PUBLIC);
    }

    // 可以操作的文件夹不为空和有权限的
    if (operateId.size() != 0 && publicCondition != null) {
      return ConditionUtils.mix2OrCondition(
          operateFoldersCondition
              .add(statusCondition, typeCondition, eliminateCondition, authorityCondition)
              .setAddBracket(true),
          publicFoldersCondition
              .add(statusCondition, publicCondition, typeCondition)
              .setAddBracket(true));
      // 没有公共硬盘管理权限的
    } else if (operateId.size() != 0 && publicCondition == null) {
      return operateFoldersCondition.add(
          statusCondition, typeCondition, eliminateCondition, authorityCondition);
      // 没有可以操作的文件但有公共权限的
    } else if (operateId.size() == 0 && publicCondition != null) {
      return publicFoldersCondition.add(statusCondition, publicCondition, typeCondition);
    } else {
      return null;
    }
  }