@RequiresPermissions({"categoryWord-get"})
  @RequestMapping(
      method = RequestMethod.GET,
      value = "/getAll",
      headers = "Accept=application/json")
  public @ResponseBody Map<String, Object> getAll(HttpServletRequest req) {
    int pageNo = Integer.parseInt(req.getParameter("page"));
    int rowCount = Integer.parseInt(req.getParameter("rows"));
    String englishWord = req.getParameter("englishWord");
    String chineseWord = req.getParameter("chineseWord");
    String esglisgAb = req.getParameter("esglisgAb");
    String remark = req.getParameter("remark");

    List<SearchCondition> searchConds = new ArrayList<SearchCondition>();
    StringBuffer hql = new StringBuffer("select c from CategoryWord c where 1=1 ");
    if (null != englishWord && !"".equals(englishWord)) {
      hql.append(" and englishWord like ?");
      searchConds.add(new SearchCondition("englishWord", "%" + englishWord + "%"));
    }
    if (null != chineseWord && !"".equals(chineseWord)) {
      hql.append(" and chineseWord like ?");
      try {
        chineseWord = URLDecoder.decode(chineseWord, "utf-8");
      } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      searchConds.add(new SearchCondition("chineseWord", "%" + chineseWord + "%"));
    }
    if (null != esglisgAb && !"".equals(esglisgAb)) {
      hql.append(" and esglisgAb like ?");
      searchConds.add(new SearchCondition("esglisgAb", "%" + esglisgAb + "%"));
    }
    if (null != remark && !"".equals(remark)) {
      hql.append(" and remark like ?");
      try {
        remark = URLDecoder.decode(remark, "utf-8");
      } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      searchConds.add(new SearchCondition("remark", "%" + remark + "%"));
    }
    hql.append(" order by esglisgAb");
    //        Page page = categoryWordService.getAll(rowCount);
    Page page = new Page();
    if (searchConds.size() <= 0) {
      page = categoryWordService.getPageBy(hql.toString(), rowCount);
    } else {
      page = categoryWordService.getPageBy(hql.toString(), rowCount, searchConds);
    }

    page.setPage(pageNo);

    List<CategoryWord> list = categoryWordService.findBy(hql.toString(), page, searchConds);
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("total", page.getResultCount());
    map.put("rows", list);
    return map;
  }
Exemplo n.º 2
0
  @RequestMapping(value = "setPermission", method = RequestMethod.POST)
  public String permission(
      @Valid @ModelAttribute("role") Role role, RedirectAttributes redirectAttributes) {
    List<String> list = role.getPermissionList();
    String nowPermissionString = role.getPermissions();
    StringBuffer sb = new StringBuffer("");
    boolean permissionOne = false;
    boolean permissionTwo = false;
    boolean permissionThree = false;
    boolean permissionFour = false;
    for (String temp : list) {
      if (temp.indexOf("artery") != -1
          || temp.indexOf("cerebral") != -1
          || temp.indexOf("bloodvessel") != -1) {
        if (permissionOne) {
          continue;
        }
        sb.append(",mind:view");
        permissionOne = true;
        continue;
      }
      if (temp.indexOf("aorta") != -1
          || temp.indexOf("kidney") != -1
          || temp.indexOf("arms") != -1) {
        if (permissionTwo) {
          continue;
        }
        sb.append(",cube:view");
        permissionTwo = true;
        continue;
      }
      if (temp.indexOf("cancer") != -1
          || temp.indexOf("icterus") != -1
          || temp.indexOf("alimentary") != -1) {
        if (permissionThree) {
          continue;
        }
        sb.append(",all:view");
        permissionThree = true;
        continue;
      }
      if (temp.indexOf("user") != -1 || temp.indexOf("team") != -1 || temp.indexOf("role") != -1) {
        if (permissionFour) {
          continue;
        }
        sb.append(",system:view");
        permissionFour = true;
        continue;
      }
    }

    nowPermissionString = nowPermissionString + sb.toString();
    role.setPermissions(nowPermissionString);

    roleService.saveRole(role);
    redirectAttributes.addFlashAttribute("message", "Great.. 修改权限值成功!");
    return "redirect:/role";
  }
  // 新建Tweet
  @RequestMapping(value = "/tweet", method = RequestMethod.POST)
  public Tweet add(
      @RequestParam("prompt") String prompt,
      @RequestParam("originTid") long originTid,
      @RequestParam("tweet") MultipartFile tweetFile,
      @RequestParam("image") MultipartFile[] images)
      throws IOException {

    // 保持userTweet
    String tweetJSON = new String(tweetFile.getBytes());
    Tweet tweet = new Gson().fromJson(URLDecoder.decode(tweetJSON, "UTF8"), Tweet.class);
    long uid = tweet.getUid();
    User user = userRepo.findOne(uid);

    if (user.getUserType() == User.UserType.SPECIAL && originTid > 0) { // 超级用户
      Tweet t = tweetRepo.findOne(originTid);
      tweet = new Tweet();
      tweet.setUid(uid);
      tweet.setName(user.getName());
      tweet.setIcon(user.getAvatar());
      tweet.setTweetType(Tweet.TweetType.SPECIAL);
      tweet.setTweetContentType(tweet.getTweetContentType());
      tweet.setTitle(t.getTitle());
      tweet.setSummary(t.getSummary());
      tweet.setImages(t.getImages());
      tweet.setContent(t.getContent());
      tweet.setLat(t.getLat());
      tweet.setLon(t.getLon());
      tweet.setLocation(t.location);
      tweet.setTime(Utils.getTime());
      tweet.setDate(System.currentTimeMillis());
      originTid = 0;
      prompt = null;

    } else {
      String content = tweet.getContent();
      tweet.setSummary(content);
      content = content.replace(" ", "&nbsp;").replace("\n", "<br>");
      Pattern pattern = Pattern.compile("@[^\\p{P}|\\p{S}|\\p{Z}|\\p{M}]*");
      String mContent = content;
      Matcher matcher = pattern.matcher(mContent);
      while (matcher.find()) {
        int start = matcher.start();
        int end = matcher.end();
        String p = mContent.substring(start, end);
        content =
            content.replace(
                p, Constants.TWEET_ADD_PROMPT_HTML.replace(Constants.TWEET_HTML_PROMPT_TAG, p));
      }

      List<String> imageUrls = new ArrayList<>();
      StringBuffer imageContent = new StringBuffer();
      if (images != null) {
        for (MultipartFile image : images) {
          String imageUrl = Utils.image(image);
          if (!StringUtils.isEmpty(imageUrl)) {
            imageUrls.add(imageUrl);
            imageContent.append(
                Constants.TWEET_ADD_IMAGE_HTML.replace(Constants.TWEET_HTML_IMAGE_TAG, imageUrl));
          }
        }
        tweet.setImages(String.join(";", imageUrls));
      }
      tweet.setContent(
          Utils.content(
              Constants.TWEET_ADD_HTML
                  .replace(Constants.TWEET_HTML_CONTENT_TAG, content)
                  .replace(Constants.TWEET_HTML_IMAGES_TAG, imageContent)));
      tweet.setTime(Utils.getTime());
      tweet.setDate(System.currentTimeMillis());
    }

    tweet = tweetRepo.saveAndFlush(tweet);

    UserTweet userTweet = new UserTweet();
    userTweet.setUid(uid);
    userTweet.setTid(tweet.getId());
    userTweet.setUserTweetType(UserTweet.UserTweetType.ADD);
    userTweetRepo.saveAndFlush(userTweet);

    // 保存@ 并且发送message
    if (!StringUtils.isEmpty(prompt)) {
      String[] uids = prompt.split(";");
      for (String id : uids) {
        // 保存@
        UserTweet ut = new UserTweet();
        ut.setUid(Long.valueOf(id));
        ut.setTid(tweet.getId());
        ut.setUserTweetType(UserTweet.UserTweetType.PROMPT);
        userTweetRepo.saveAndFlush(ut);

        // 保存@ message
        Message message = new Message();
        message.setUid(uid);
        message.setUid2(Long.valueOf(id));
        message.setTid(tweet.getId());
        message.setMessageType(Message.MessageType.PROMPT);
        message.setTitle(user.getName());
        message.setContent(user.getName());
        message.setIcon(user.getAvatar());
        message.setTime(Utils.getTime());
        message.setDate(System.currentTimeMillis());
        Utils.message(messageRepo.saveAndFlush(message));
      }
    }

    // 查找转发的tweet
    if (originTid > 0) {
      Tweet originTweet = tweetRepo.findOne(originTid);
      tweet.setOriginTweet(originTweet);
      TweetTweet tweetTweet = new TweetTweet();
      tweetTweet.setTid(tweet.getId());
      tweetTweet.setTid2(originTid);
      tweetTweet.setTweetTweetType(TweetTweet.TweetTweetType.REPEAT);
      tweetTweetRepo.saveAndFlush(tweetTweet);

      originTweet.setRepeatCount(originTweet.getRepeatCount() + 1);
      tweetRepo.saveAndFlush(originTweet);
    }

    return tweet;
  }