Search in sources :

Example 11 with TopicCategoryDO

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

the class TopicCategoryDAOTest method testGetTopicCategoryByNick.

/**
 * 测试(昵称)获取话题分类
 */
@Test
@Transactional
public void testGetTopicCategoryByNick() {
    TopicCategoryDO category = this.savaTestTopicCategoryDOToDatabase();
    String categoryNick = category.getNick();
    Assert.assertNotNull(topicCategoryDAO.getTopicCategoryByNick(categoryNick));
    System.out.println("get topic category information: " + topicCategoryDAO.getTopicCategoryByNick(categoryNick));
}
Also used : TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 12 with TopicCategoryDO

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

the class TopicServiceImpl method saveTopic.

@Override
public Map<String, Object> saveTopic(int userId, String categoryNick, String title, String topicContent) {
    // judge whether exist category(nick)
    TopicCategoryDO category = this.getTopicCategoryNotNullByNick(categoryNick);
    // build TopicDO, TopicContentDO, TopicActionDO
    TopicDO topic = new TopicDO();
    topic.setUserid(userId);
    topic.setCategoryid(category.getId());
    topic.setTitle(title);
    // insert forum_topic, get new topic id
    if (topicDAO.saveTopic(topic) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS1);
    }
    // insert forum_topic_content
    TopicContentDO topicContentDO = new TopicContentDO();
    topicContentDO.setTopicid(topic.getId());
    topicContentDO.setContent(topicContent);
    if (topicContentDAO.saveTopicContent(topicContentDO) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS2);
    }
    // insert forum_topic_action
    TopicActionDO topicAction = new TopicActionDO();
    topicAction.setTopicId(topic.getId());
    if (topicActionDAO.saveTopicAction(topicAction) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS24);
    }
    return MapFilterUtil.generateMap(ParamConst.TOPIC_ID, topic.getId());
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException) TopicContentDO(org.neusoft.neubbs.entity.TopicContentDO) TopicDO(org.neusoft.neubbs.entity.TopicDO) TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO) TopicActionDO(org.neusoft.neubbs.entity.TopicActionDO)

Example 13 with TopicCategoryDO

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

the class TopicServiceImpl method saveCategory.

@Override
public Map<String, Object> saveCategory(String categoryNick, String categoryName) {
    if (topicCategoryDAO.getTopicCategoryByNick(categoryNick) != null) {
        throw new ServiceException(ApiMessage.ALREADY_EXIST_CATEGORY_NICK).log(LogWarnEnum.TS14);
    }
    if (topicCategoryDAO.getTopicCategoryByName(categoryName) != null) {
        throw new ServiceException(ApiMessage.ALREADY_EXIST_CATEGORY_NAME).log(LogWarnEnum.TS15);
    }
    TopicCategoryDO category = new TopicCategoryDO();
    category.setNick(categoryNick);
    category.setName(categoryName);
    topicCategoryDAO.saveTopicCategory(category);
    return this.getTopicCategoryInfoMap(category);
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException) TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO)

Example 14 with TopicCategoryDO

use of org.neusoft.neubbs.entity.TopicCategoryDO 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 15 with TopicCategoryDO

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

the class TopicServiceImpl method listAllTopicCategories.

@Override
public List<Map<String, Object>> listAllTopicCategories() {
    List<TopicCategoryDO> dbQueryCategoryList = topicCategoryDAO.listAllTopicCategory();
    List<Map<String, Object>> resultCategoryList = new ArrayList<>(dbQueryCategoryList.size());
    for (TopicCategoryDO category : dbQueryCategoryList) {
        resultCategoryList.add(this.getTopicCategoryInfoMap(category));
    }
    return resultCategoryList;
}
Also used : ArrayList(java.util.ArrayList) TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

TopicCategoryDO (org.neusoft.neubbs.entity.TopicCategoryDO)15 Test (org.junit.Test)9 Transactional (javax.transaction.Transactional)8 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)3 TopicDO (org.neusoft.neubbs.entity.TopicDO)3 ServiceException (org.neusoft.neubbs.exception.ServiceException)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 TopicActionDO (org.neusoft.neubbs.entity.TopicActionDO)1 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)1 UserDO (org.neusoft.neubbs.entity.UserDO)1