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