Search in sources :

Example 26 with TopicDO

use of org.neusoft.neubbs.entity.TopicDO in project neubbs by nuitcoder.

the class TopicServiceImpl method listTopics.

@Override
public List<Map<String, Object>> listTopics(int limit, int page, String categoryNick, String username) {
    // if limit = 0, explain no input limit, use neubbs.properties default param
    if (limit == 0) {
        limit = neubbsConfig.getTopicsApiRequestParamLimitDefault();
    }
    this.confirmNoExceedTopicTotalNumber(limit, page);
    int categoryId = categoryNick == null ? 0 : this.getTopicCategoryNotNullByNick(categoryNick).getId();
    int userId = username == null ? 0 : this.getUserNotNullByName(username).getId();
    // get database query results
    List<TopicDO> dbQueryTopicList = this.getTopicList(limit, page, categoryId, userId);
    if (dbQueryTopicList.size() == 0) {
        throw new ServiceException(ApiMessage.NO_QUERY_TOPICS).log(LogWarnEnum.TS16);
    }
    List<Map<String, Object>> resultTopicList = new ArrayList<>(dbQueryTopicList.size());
    for (TopicDO topic : dbQueryTopicList) {
        Map<String, Object> topicInfoMap = this.getTopicInfoMap(topic);
        Map<String, Object> topicContentInfoMap = this.getTopicContentInfoMap(this.getTopicContent(topic.getId()));
        Map<String, Object> topicCategoryInfoMap = this.getTopicCategoryInfoMap(this.getTopicCategory(topic.getCategoryid()));
        Map<String, Object> authorUserMap = this.getTopicUserInfoMap(this.getUser(topic.getUserid()));
        Map<String, Object> lastReplyUserMap = this.getTopicUserInfoMap(this.getUser(topic.getLastreplyuserid()));
        // merge all information map
        topicInfoMap.putAll(topicContentInfoMap);
        topicInfoMap.put(ParamConst.CATEGORY, topicCategoryInfoMap);
        topicInfoMap.put(ParamConst.USER, authorUserMap);
        topicInfoMap.put(ParamConst.LAST_REPLY_USER, lastReplyUserMap);
        resultTopicList.add(topicInfoMap);
    }
    return resultTopicList;
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException) ArrayList(java.util.ArrayList) TopicDO(org.neusoft.neubbs.entity.TopicDO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 27 with TopicDO

use of org.neusoft.neubbs.entity.TopicDO in project neubbs by nuitcoder.

the class TopicServiceImpl method getTopicContentModelMap.

@Override
public Map<String, Object> getTopicContentModelMap(int topicId) {
    TopicDO topic = this.getTopicNotNull(topicId);
    TopicContentDO topicContent = this.getTopicContentNotNull(topicId);
    TopicCategoryDO topicCategory = this.getTopicCategoryNotNullById(topic.getCategoryid());
    UserDO topicAuthorUser = this.getUserNotNullById(topic.getUserid());
    Map<String, Object> topicInfoMap = this.getTopicInfoMap(topic);
    Map<String, Object> topicContentInfoMap = this.getTopicContentInfoMap(topicContent);
    Map<String, Object> topicCategoryInfoMap = this.getTopicCategoryInfoMap(topicCategory);
    Map<String, Object> authorUserInfoMap = this.getTopicUserInfoMap(topicAuthorUser);
    Map<String, Object> lastReplyUserInfoMap = this.getTopicUserInfoMap(this.getUserNotNullById(topic.getLastreplyuserid()));
    // get topic reply list, and add to map
    List<TopicReplyDO> listReply = topicReplyDAO.listTopicReplyByTopicId(topicId);
    List<Map<String, Object>> listReplyInfoMap = new ArrayList<>(listReply.size());
    for (TopicReplyDO reply : listReply) {
        Map<String, Object> replyInfoMap = this.getTopicReplyInfoMap(reply);
        replyInfoMap.put(ParamConst.USER, this.getTopicUserInfoMap(userDAO.getUserById(reply.getUserid())));
        listReplyInfoMap.add(replyInfoMap);
    }
    // merge all information map
    topicInfoMap.putAll(topicContentInfoMap);
    topicInfoMap.put(ParamConst.CATEGORY, topicCategoryInfoMap);
    topicInfoMap.put(ParamConst.USER, authorUserInfoMap);
    topicInfoMap.put(ParamConst.LAST_REPLY_USER, lastReplyUserInfoMap);
    topicInfoMap.put(ParamConst.REPLY_LIST, listReplyInfoMap);
    return topicInfoMap;
}
Also used : TopicContentDO(org.neusoft.neubbs.entity.TopicContentDO) UserDO(org.neusoft.neubbs.entity.UserDO) TopicReplyDO(org.neusoft.neubbs.entity.TopicReplyDO) ArrayList(java.util.ArrayList) TopicDO(org.neusoft.neubbs.entity.TopicDO) TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 28 with TopicDO

use of org.neusoft.neubbs.entity.TopicDO in project neubbs by nuitcoder.

the class TopicServiceImpl method listHotTopics.

@Override
public List<Map<String, Object>> listHotTopics() {
    List<TopicDO> topicList = topicDAO.listTopicOrderByCreatetimeDESCByRepliesDESCLimitTen();
    List<Map<String, Object>> hotTopicMapList = new ArrayList<>(topicList.size());
    for (TopicDO topic : topicList) {
        Map<String, Object> itemTopicMap = this.getTopicInfoMap(topic);
        itemTopicMap.put(ParamConst.CATEGORY, this.getTopicCategoryInfoMap(this.getTopicCategory(topic.getCategoryid())));
        itemTopicMap.put(ParamConst.USER, this.getTopicUserInfoMap(this.getUser(topic.getUserid())));
        itemTopicMap.put(ParamConst.LAST_REPLY_USER, this.getTopicUserInfoMap(this.getUser(topic.getLastreplyuserid())));
        // add to list
        hotTopicMapList.add(itemTopicMap);
    }
    return hotTopicMapList;
}
Also used : ArrayList(java.util.ArrayList) TopicDO(org.neusoft.neubbs.entity.TopicDO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

TopicDO (org.neusoft.neubbs.entity.TopicDO)28 Test (org.junit.Test)19 Transactional (javax.transaction.Transactional)18 Map (java.util.Map)5 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)4 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 TopicCategoryDO (org.neusoft.neubbs.entity.TopicCategoryDO)3 TopicActionDO (org.neusoft.neubbs.entity.TopicActionDO)2 ServiceException (org.neusoft.neubbs.exception.ServiceException)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 Date (java.util.Date)1 UserDO (org.neusoft.neubbs.entity.UserDO)1