Пример #1
0
  public void confirm(ActionEvent event) {
    String name = nameField.getText();
    if (S.isEmpty(name)) {
      tipsLabel.setText("错误:工具名字不能为空!");
      nameField.requestFocus();
      return;
    }
    String command = commandText.getText();
    String order = orderField.getText();
    ToolsTray bandeja = (ToolsTray) parentCombo.getSelectionModel().getSelectedItem();
    Integer parentId = bandeja.getId();
    ToolType toolType = (ToolType) typeCombo.getSelectionModel().getSelectedItem();
    String type = toolType.getToolType();

    ToolsTray toolsTray = new ToolsTray();
    toolsTray.setTrayName(name);
    toolsTray.setCommand(command);
    toolsTray.setParentId(parentId);
    toolsTray.setToolOrder(order);
    toolsTray.setToolType(type);
    if (null == id) {
      dao.insert(toolsTray);
      id = toolsTray.getId();
      tipsLabel.setText("添加成功:" + name);
    } else {
      toolsTray.setId(id);
      dao.update(toolsTray);
      tipsLabel.setText("更新成功:" + name);
    }
    refresh(null);
  }
Пример #2
0
 @Aop("redis")
 public CResult add(Topic topic, int userId) {
   if (userId < 1) {
     return _fail("请先登录");
   }
   if (Strings.isBlank(topic.getTitle())
       || topic.getTitle().length() > 1024
       || topic.getTitle().length() < 5) {
     return _fail("标题长度不合法");
   }
   if (Strings.isBlank(topic.getContent())) {
     return _fail("内容不合法");
   }
   if (topic.getTags() != null && topic.getTags().size() > 10) {
     return _fail("最多只能有10个tag");
   }
   if (0 != dao.count(Topic.class, Cnd.where("title", "=", topic.getTitle().trim()))) {
     return _fail("相同标题已经发过了");
   }
   topic.setTitle(Strings.escapeHtml(topic.getTitle().trim()));
   topic.setUserId(userId);
   topic.setTop(false);
   topic.setTags(new HashSet<String>());
   if (topic.getType() == null) topic.setType(TopicType.ask);
   topic.setContent(Toolkit.filteContent(topic.getContent()));
   String oldContent = topic.getContent();
   topic.setContentId(bigContentService.put(topic.getContent()));
   topic.setContent(null);
   dao.insert(topic);
   try {
     topic.setContent(oldContent);
     topicSearchService.add(topic);
   } catch (Exception e) {
   }
   // 如果是ask类型,把帖子加入到 "未回复"列表
   Pipeline pipe = jedis().pipelined();
   if (TopicType.ask.equals(topic.getType())) {
     pipe.zadd(RKEY_TOPIC_NOREPLY, System.currentTimeMillis(), topic.getId());
   }
   pipe.zadd(RKEY_TOPIC_UPDATE + topic.getType(), System.currentTimeMillis(), topic.getId());
   if (topic.getType() != TopicType.shortit)
     pipe.zadd(RKEY_TOPIC_UPDATE_ALL, System.currentTimeMillis(), topic.getId());
   pipe.zincrby(RKEY_USER_SCORE, 100, "" + userId);
   pipe.sync();
   String replyAuthorName = dao.fetch(User.class, userId).getName();
   for (Integer watcherId : globalWatcherIds) {
     if (watcherId != userId)
       pushUser(
           watcherId,
           "新帖:" + topic.getTitle(),
           topic.getId(),
           replyAuthorName,
           topic.getTitle(),
           PushService.PUSH_TYPE_REPLY);
   }
   updateTopicTypeCount();
   return _ok(topic.getId());
 }
Пример #3
0
 public void init() {
   if (dao.count(ForumTip.class) < 1) {
     ForumTip forumTip = new ForumTip();
     forumTip.setUid(1);
     forumTip.setContent("第一条测试信息--论坛信息");
     forumTip.setCreateTime(System.currentTimeMillis());
     dao.insert(forumTip);
   }
 }
Пример #4
0
 @Override
 public Item insert(Item i) {
   if (!ItemDaoValidator.save(i)) {
     log.error("insert item failed:");
     log.error(i);
     throw new IllegalParameterException();
   }
   return dao.insert(i);
 }
Пример #5
0
 @At
 @Ok("json")
 @AdaptBy(type = JsonAdaptor.class)
 public Object save(
     @Param("..") Store store, @Attr(scope = Scope.SESSION, value = "account") Account acc) {
   if (store.getId() == 0) {
     store.setAccountid(acc.accountid);
     store.setManagerid(acc.managerid);
     store = dao.insert(store);
   }
   return store;
 }
Пример #6
0
 @At("/passwd/reset")
 public void resetPassword(String email, HttpServletRequest req) {
   if (Strings.isBlank(email)) return;
   User user = dao.fetch(User.class, Cnd.where("email", "=", email));
   if (user == null) return;
   dao.clear(PasswordReset.class, Cnd.where("uid", "=", user.getId()));
   String token = R.UU64() + R.UU64();
   PasswordReset reset = new PasswordReset();
   reset.setUid(dao.fetch(User.class, Cnd.where("email", "=", email)).getId());
   reset.setToken(token);
   dao.insert(reset);
   String url = req.getRequestURL() + "/callback?token=" + token;
   mailService.add2Queue(email, "推爸 密码重置请求", "Reset URL --> " + url);
 }
Пример #7
0
  @Aop("redis")
  public CResult addReply(final String topicId, final TopicReply reply, final int userId) {
    if (userId < 1) return _fail("请先登录");
    if (reply == null || reply.getContent() == null || reply.getContent().trim().isEmpty()) {
      return _fail("内容不能为空");
    }
    final String cnt = reply.getContent().trim();
    final Topic topic = dao.fetch(Topic.class, topicId); // TODO 改成只fetch出type属性
    if (topic == null) {
      return _fail("主题不存在");
    }
    if (topic.isLock()) {
      return _fail("该帖子已经锁定,不能回复");
    }
    reply.setTopicId(topicId);
    reply.setUserId(userId);
    reply.setContent(Toolkit.filteContent(reply.getContent()));
    reply.setContentId(bigContentService.put(reply.getContent()));
    reply.setContent(null);
    dao.insert(reply);
    // 更新索引
    topicSearchService.add(topic);
    // 更新topic的时间戳
    Pipeline pipe = jedis().pipelined();
    if (topic.isTop()) {
      pipe.zadd(RKEY_TOPIC_TOP, reply.getCreateTime().getTime(), topicId);
    } else {
      pipe.zadd(RKEY_TOPIC_UPDATE + topic.getType(), reply.getCreateTime().getTime(), topicId);
      pipe.zadd(RKEY_TOPIC_UPDATE_ALL, reply.getCreateTime().getTime(), topicId);
    }
    pipe.zrem(RKEY_TOPIC_NOREPLY, topicId);
    if (topic.getTags() != null) {
      for (String tag : topic.getTags()) {
        pipe.zadd(
            RKEY_TOPIC_TAG + tag.toLowerCase().trim(), reply.getCreateTime().getTime(), topicId);
      }
    }
    pipe.hset(RKEY_REPLY_LAST, topicId, reply.getId());
    pipe.zincrby(RKEY_REPLY_COUNT, 1, topicId);
    pipe.zincrby(RKEY_USER_SCORE, 10, "" + userId);
    pipe.sync();

    notifyUsers(topic, reply, cnt, userId);

    return _ok(reply.getId());
  }
Пример #8
0
 @At
 public Object reg(@Param("email") String email) {
   if (Strings.isBlank(email) || !Strings.isEmail(email)) {
     return Ajax.fail().setMsg("email is blank or invaild!");
   } else {
     if (0 != dao.count(User.class, Cnd.where("email", "=", email))) {
       return Ajax.fail().setMsg("email is exist!");
     } else {
       final User me = new User();
       me.setEmail(email);
       String passwd = R.sg(12).next();
       me.setPasswd(xMD5(passwd));
       me.setNickName("_" + me.getNickName());
       dao.insert(me);
       if (mailService.add2Queue(email, "推爸注册确认邮件", "Your password : "******"Fail to send comfig email!!");
       }
     }
   }
 }