Search in sources :

Example 16 with TopicReplyDO

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

the class TopicReplyDAOTest method testRemoveTopicReplyById.

/**
 * 测试删除回复
 */
@Test
@Transactional
public void testRemoveTopicReplyById() {
    TopicReplyDO reply = this.saveTestReplyToDatabase();
    int replyId = reply.getId();
    Assert.assertEquals(1, topicReplyDAO.removeTopicReplyById(replyId));
    Assert.assertNull(topicReplyDAO.getTopicReplyById(replyId));
    System.out.println("delete replyId=" + reply.getId() + " reply");
}
Also used : TopicReplyDO(org.neusoft.neubbs.entity.TopicReplyDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 17 with TopicReplyDO

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

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

the class TopicServiceImpl method saveReply.

@Override
public Map<String, Object> saveReply(int userId, int topicId, String replyContent) {
    this.getTopicNotNull(topicId);
    // save topic reply
    TopicReplyDO topicReply = new TopicReplyDO();
    topicReply.setUserid(userId);
    topicReply.setTopicid(topicId);
    topicReply.setContent(replyContent);
    if (topicReplyDAO.saveTopicReply(topicReply) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS3);
    }
    // update forum_topic 'replies', 'lastReplyUserId', 'lastReplyTime'
    Date topicLastReplyTime = topicReplyDAO.getTopicReplyById(topicReply.getId()).getCreatetime();
    if (topicDAO.updateRepliesAddOneById(topicId) == 0 || topicDAO.updateLastReplyUserIdById(topicId, userId) == 0 || topicDAO.updateLastReplyTimeById(topicId, topicLastReplyTime) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS3);
    }
    return MapFilterUtil.generateMap(ParamConst.REPLY_ID, topicReply.getId());
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException) TopicReplyDO(org.neusoft.neubbs.entity.TopicReplyDO) Date(java.util.Date)

Aggregations

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