Search in sources :

Example 11 with ServiceException

use of org.neusoft.neubbs.exception.ServiceException 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 12 with ServiceException

use of org.neusoft.neubbs.exception.ServiceException in project neubbs by nuitcoder.

the class TopicServiceImpl method countTopicTotalPages.

@Override
public Map<String, Object> countTopicTotalPages(int limit, String categoryNick, String username) {
    if (limit == 0) {
        limit = neubbsConfig.getTopicsApiRequestParamLimitDefault();
    }
    // get categoryId, userId
    int categoryId = categoryNick == null ? 0 : this.getTopicCategoryNotNullByNick(categoryNick).getId();
    int userId = username == null ? 0 : this.getUserNotNullByName(username).getId();
    int topicNumber = this.countTopicCount(categoryId, userId);
    if (topicNumber == 0) {
        throw new ServiceException(ApiMessage.NO_QUERY_TOPICS).log(LogWarnEnum.TS17);
    }
    // count totalPages by limit by topicNumber
    int totalPages = topicNumber % limit == 0 ? (topicNumber / limit) : (topicNumber / limit + 1);
    return MapFilterUtil.generateMap(ParamConst.TOTAL_PAGES, totalPages);
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException)

Example 13 with ServiceException

use of org.neusoft.neubbs.exception.ServiceException in project neubbs by nuitcoder.

the class TopicServiceImpl method confirmNoExceedTopicTotalNumber.

/*
     * ***********************************************
     * confirm method
     * ***********************************************
     */
/**
 * 确认不会超过话题数量
 *
 * @param limit 每页显示限制
 * @param page 跳转指定页数
 */
private void confirmNoExceedTopicTotalNumber(int limit, int page) {
    int allTopicTotals = topicDAO.countTopic();
    int maxPage = allTopicTotals % limit == 0 ? allTopicTotals / limit : allTopicTotals / limit + 1;
    if (limit > allTopicTotals || page > maxPage) {
        throw new ServiceException(ApiMessage.QUERY_EXCEED_TOPIC_NUMBER).log(LogWarnEnum.TS12);
    // "(话题总数 = allTopicTotals,若 limit = limit,最多跳转至 maxPage 页)")
    }
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException)

Example 14 with ServiceException

use of org.neusoft.neubbs.exception.ServiceException 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)

Example 15 with ServiceException

use of org.neusoft.neubbs.exception.ServiceException 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

ServiceException (org.neusoft.neubbs.exception.ServiceException)16 TopicCategoryDO (org.neusoft.neubbs.entity.TopicCategoryDO)3 UserDO (org.neusoft.neubbs.entity.UserDO)3 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)2 TopicDO (org.neusoft.neubbs.entity.TopicDO)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 TopicActionDO (org.neusoft.neubbs.entity.TopicActionDO)1 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)1 UserActionDO (org.neusoft.neubbs.entity.UserActionDO)1