You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.9 KiB

package com.community.pocket.repository.android;
import com.community.pocket.entity.po.Forum;
import com.community.pocket.entity.po.ForumContent;
import com.community.pocket.entity.vo.ForumQuery;
import com.community.pocket.entity.vo.android.ForumContentVo;
import com.community.pocket.entity.vo.android.ForumReplyForm;
import com.community.pocket.entity.vo.android.ForumVo;
import com.community.pocket.repository.BaseDao;
import com.community.pocket.util.LookupOperationUtil;
import com.community.pocket.util.TableName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 帖子正文详情
*/
@Repository
public class ForumContentDao extends BaseDao<ForumContent> {
private static final Logger LOG = LoggerFactory.getLogger(ForumDao.class);
@Autowired
private ForumDao forumDao;
//查找帖子详情
public List<ForumContentVo> find(ForumQuery queryForum) {
Aggregation aggregation = Aggregation.newAggregation(LookupOperationUtil.infoLookup, Aggregation.match(Criteria.where("forumId").is(queryForum.getForumId())));
return mongoTemplate.aggregate(aggregation, TableName.forumContent, ForumContentVo.class).getMappedResults();
}
/**
* 保存回复
*/
public ForumContent save(ForumReplyForm forumReplyForm) {
ForumContent forumContent = new ForumContent();
forumContent.setContent(forumReplyForm.getContent());
forumContent.setForumId(forumReplyForm.getForumId());
forumContent.setTime(System.currentTimeMillis());
long tower = mongoTemplate.count(new Query(Criteria.where("forumId").is(forumContent.getForumId())), entityClass());
forumContent.setTower(tower + 1);
forumContent.setUsername(forumReplyForm.getUsername());
return save(forumContent);
}
/**
* 保存帖子详情
*/
public ForumContent save(ForumVo forumVo, Forum forum) {
ForumContent forumContent = new ForumContent();
forumContent.setContent(forumVo.getContent());
forumContent.setForumId(forum.getId());
forumContent.setTime(forum.getTime());
forumContent.setTower(1L);
forumContent.setUsername(forum.getUsername());
return save(forumContent);
}
//保存
@Override
public ForumContent save(ForumContent forumContent) {
try {
return mongoTemplate.save(forumContent);
} catch (Exception e) {
e.printStackTrace();
LOG.error(e.toString());
}
return null;
}
@Override
public Class<ForumContent> entityClass() {
return ForumContent.class;
}
}