Beispiel #1
0
  @At
  @Ok("json")
  public JDataGrid list_grid(
      @Attr(scope = Scope.SESSION, value = "account") Account acc,
      @Param("::columns") List<?> columns,
      @Param("::search") Map<?, ?> search,
      int draw,
      int start,
      int length) {
    start = start / length;
    Pager pager = new Pager();
    pager.setPageNumber(start + 1);
    pager.setPageSize(length);

    Cnd cnd = Cnd.where("accountid", "=", acc.accountid);

    if (!Lang.isEmpty(search.get("value")) && !search.get("value").toString().equals("")) {
      cnd.and("name", "like", search.get("value"));
    }

    List<?> aaData = dao.query(Store.class, cnd);
    pager.setRecordCount(dao.count(Store.class, cnd));

    JDataGrid ret = new JDataGrid();
    ret.draw = draw;
    ret.data = aaData;
    ret.recordsTotal = pager.getRecordCount();
    ret.recordsFiltered = pager.getRecordCount();
    return ret;
  }
 @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());
 }
Beispiel #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);
   }
 }
  /**
   * 分页查找 resource
   *
   * @param categoryId 分类id好好
   * @param order
   * @param pager
   * @return
   */
  public List<Resource> search(Integer categoryId, Integer tagId, String order, Pager pager) {
    List<Resource> query = null;

    if (categoryId != null) {
      query = dao.query(Resource.class, Cnd.where("categoryId", "=", categoryId).desc("id"), pager);
      if (pager != null) {
        pager.setRecordCount(dao.count(Resource.class, Cnd.where("categoryId", "=", categoryId)));
      }

    } else {
      query = dao.query(Resource.class, Cnd.orderBy().desc("id"), pager);
      if (pager != null) {
        pager.setRecordCount(dao.count(Resource.class));
      }
    }
    for (Resource resource : query) {
      resourceRelationFull(resource);
    }
    return query;
  }
  public List<Topic> getRecentTopics(int userId, Pager pager) {
    List<Topic> recent_topics =
        dao.query(Topic.class, Cnd.where("userId", "=", userId).desc("createTime"), pager);

    Map<Integer, UserProfile> authors = new HashMap<Integer, UserProfile>();
    if (!recent_topics.isEmpty()) {
      for (Topic topic : recent_topics) {
        fillTopic(topic, authors);
      }
    }
    pager.setRecordCount(dao.count(Topic.class, Cnd.where("userId", "=", userId)));
    return recent_topics;
  }
 @Aop("redis")
 public CResult replyUp(String replyId, int userId) {
   if (userId < 1) return _fail("你还没登录呢");
   if (1 != dao.count(TopicReply.class, Cnd.where("id", "=", replyId))) {
     return _fail("没这条评论");
   }
   String key = RKEY_REPLY_LIKE + replyId;
   Double t = jedis().zscore(key, "" + userId);
   if (t != null) {
     jedis().zrem(key, userId + "");
     return _ok("down");
   } else {
     jedis().zadd(key, System.currentTimeMillis(), userId + "");
     return _ok("up");
   }
 }
  /**
   * 分页查找 resource
   *
   * @param categoryId 分类id好好
   * @param order
   * @param pager
   * @return
   */
  public List<Resource> search(Integer categoryId, String order, Pager pager, Integer userId) {
    List<Resource> query = null;

    Cnd cnd = Cnd.NEW();
    if (userId != null) {
      cnd = cnd.and("author", "=", userId);
    }

    if (categoryId != null && categoryId != 0) {
      cnd = cnd.and("categoryId", "=", categoryId);
    }

    if (pager != null) {
      pager.setRecordCount(dao.count(Resource.class, cnd));
    }
    query = dao.query(Resource.class, cnd.desc("id"), pager);

    for (Resource resource : query) {
      resourceRelationFull(resource);
    }
    return query;
  }
Beispiel #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!!");
       }
     }
   }
 }
Beispiel #9
0
 /**
  * 填充记录总数
  *
  * @param pager 分页对象,如果为null就不进行任何操作
  * @param dao Dao实例
  * @param tableName 表名
  * @param cnd 查询条件
  * @return 传入的Pager参数
  */
 public static Pager updatePagerCount(Pager pager, Dao dao, String tableName, Condition cnd) {
   if (null != pager) {
     pager.setRecordCount(dao.count(tableName, cnd));
   }
   return pager;
 }
Beispiel #10
0
 /**
  * 填充记录总数
  *
  * @param pager 分页对象,如果为null就不进行任何操作
  * @param dao Dao实例
  * @param entityType 实体类,可以通过dao.getEntity获取
  * @param cnd 查询条件
  * @return 传入的Pager参数
  */
 public static Pager updatePagerCount(Pager pager, Dao dao, Class<?> entityType, Condition cnd) {
   if (null != pager) {
     pager.setRecordCount(dao.count(entityType, cnd));
   }
   return pager;
 }
Beispiel #11
0
 public void setRecordCount(Pager pager, Dao dao, Sql newSql) {
   pager.setRecordCount(dao.count("(" + newSql.toString() + ") _table_"));
 }