use of org.neusoft.neubbs.entity.TopicCategoryDO in project neubbs by nuitcoder.
the class TopicCategoryDAOTest method testGetTopicCategoryByNick.
/**
* 测试(昵称)获取话题分类
*/
@Test
@Transactional
public void testGetTopicCategoryByNick() {
TopicCategoryDO category = this.savaTestTopicCategoryDOToDatabase();
String categoryNick = category.getNick();
Assert.assertNotNull(topicCategoryDAO.getTopicCategoryByNick(categoryNick));
System.out.println("get topic category information: " + topicCategoryDAO.getTopicCategoryByNick(categoryNick));
}
use of org.neusoft.neubbs.entity.TopicCategoryDO 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.TopicCategoryDO in project neubbs by nuitcoder.
the class TopicServiceImpl method saveCategory.
@Override
public Map<String, Object> saveCategory(String categoryNick, String categoryName) {
if (topicCategoryDAO.getTopicCategoryByNick(categoryNick) != null) {
throw new ServiceException(ApiMessage.ALREADY_EXIST_CATEGORY_NICK).log(LogWarnEnum.TS14);
}
if (topicCategoryDAO.getTopicCategoryByName(categoryName) != null) {
throw new ServiceException(ApiMessage.ALREADY_EXIST_CATEGORY_NAME).log(LogWarnEnum.TS15);
}
TopicCategoryDO category = new TopicCategoryDO();
category.setNick(categoryNick);
category.setName(categoryName);
topicCategoryDAO.saveTopicCategory(category);
return this.getTopicCategoryInfoMap(category);
}
use of org.neusoft.neubbs.entity.TopicCategoryDO 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.TopicCategoryDO in project neubbs by nuitcoder.
the class TopicServiceImpl method listAllTopicCategories.
@Override
public List<Map<String, Object>> listAllTopicCategories() {
List<TopicCategoryDO> dbQueryCategoryList = topicCategoryDAO.listAllTopicCategory();
List<Map<String, Object>> resultCategoryList = new ArrayList<>(dbQueryCategoryList.size());
for (TopicCategoryDO category : dbQueryCategoryList) {
resultCategoryList.add(this.getTopicCategoryInfoMap(category));
}
return resultCategoryList;
}
Aggregations