Search in sources :

Example 11 with TopicContentDO

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

the class TopicContentDAOTest method testUpdateReadById.

/**
 * 测试更新阅读数量(自动 +1)
 */
@Test
@Transactional
public void testUpdateReadById() {
    TopicContentDO topicContent = this.savaTestTopicContentDOToDatabase();
    int topicId = topicContent.getTopicid();
    int beforeRead = topicContent.getRead();
    Assert.assertEquals(1, topicContentDAO.updateReadAddOneByTopicId(topicId));
    int afterRead = topicContentDAO.getTopicContentByTopicId(topicId).getRead();
    Assert.assertEquals(beforeRead + 1, afterRead);
    System.out.println("update topicId=" + topicId + " topic content read+1 success!");
}
Also used : TopicContentDO(org.neusoft.neubbs.entity.TopicContentDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 12 with TopicContentDO

use of org.neusoft.neubbs.entity.TopicContentDO 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 TopicContentDO

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

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

the class TopicServiceImpl method alterTopicLikeByCommand.

@Override
public int alterTopicLikeByCommand(boolean isCurrentUserLikeTopic, int topicId, int userId, String command) {
    // judge current user whether repeat operation(no repeat input 'inc' or 'dec')
    boolean isIncOfCommand = command.equals(SetConst.COMMAND_INC);
    if (isCurrentUserLikeTopic && isIncOfCommand) {
        // like topic & command equals 'inc'
        throw new ServiceException(ApiMessage.NO_REPEAT_INC_TOPIC_LIKE).log(LogWarnEnum.TS19);
    } else if (!isCurrentUserLikeTopic && !isIncOfCommand) {
        // no like topic & command no equals 'inc'
        throw new ServiceException(ApiMessage.NO_REPEAT_DEC_TOPIC_LIKE).log(LogWarnEnum.TS20);
    }
    // update forum_topic_content 'like'
    TopicContentDO topicContent = this.getTopicContentNotNull(topicId);
    int effectRow = isIncOfCommand ? topicContentDAO.updateLikeAddOneByTopicId(topicId) : topicContentDAO.updateLikeCutOneByTopicId(topicId);
    if (effectRow == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS7);
    }
    // update forum_topic_action 'fta_like_fu_id_array'
    effectRow = !isCurrentUserLikeTopic ? topicActionDAO.updateLikeUserIdJsonArrayByOneUserIdToAppendEnd(topicId, userId) : topicActionDAO.updateLikeUserIdJsonArrayByIndexToRemoveOneUserId(topicId, JsonUtil.getIntElementIndex(topicActionDAO.getTopicActionLikeUserIdJsonArray(topicId), userId));
    if (effectRow == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS26);
    }
    return isIncOfCommand ? topicContent.getLike() + 1 : topicContent.getLike() - 1;
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException) TopicContentDO(org.neusoft.neubbs.entity.TopicContentDO)

Aggregations

TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)14 Test (org.junit.Test)10 Transactional (javax.transaction.Transactional)9 TopicDO (org.neusoft.neubbs.entity.TopicDO)4 TopicCategoryDO (org.neusoft.neubbs.entity.TopicCategoryDO)3 UserDO (org.neusoft.neubbs.entity.UserDO)2 ServiceException (org.neusoft.neubbs.exception.ServiceException)2 JSONArray (com.alibaba.fastjson.JSONArray)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Cookie (javax.servlet.http.Cookie)1 TopicActionDO (org.neusoft.neubbs.entity.TopicActionDO)1 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)1