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;
}
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);
}
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 页)")
}
}
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;
}
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());
}
Aggregations