|
|
@ -1,13 +1,19 @@ |
|
|
|
package com.community.pocket.repository.android; |
|
|
|
package com.community.pocket.repository.android; |
|
|
|
|
|
|
|
|
|
|
|
import com.community.pocket.entity.po.Forum; |
|
|
|
import com.community.pocket.entity.po.Forum; |
|
|
|
|
|
|
|
import com.community.pocket.entity.po.android.Complain; |
|
|
|
|
|
|
|
import com.community.pocket.entity.po.android.MyInfo; |
|
|
|
|
|
|
|
import com.community.pocket.entity.vo.ForumQuery; |
|
|
|
|
|
|
|
import com.community.pocket.entity.vo.Page; |
|
|
|
import com.community.pocket.entity.vo.android.*; |
|
|
|
import com.community.pocket.entity.vo.android.*; |
|
|
|
|
|
|
|
import com.community.pocket.entity.vo.web.ForumCheck; |
|
|
|
import com.community.pocket.repository.BaseDao; |
|
|
|
import com.community.pocket.repository.BaseDao; |
|
|
|
import com.community.pocket.util.TableName; |
|
|
|
import com.community.pocket.util.TableName; |
|
|
|
import org.bson.types.ObjectId; |
|
|
|
import org.bson.types.ObjectId; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
|
|
import org.springframework.data.domain.PageRequest; |
|
|
|
import org.springframework.data.domain.Sort; |
|
|
|
import org.springframework.data.domain.Sort; |
|
|
|
import org.springframework.data.mongodb.core.aggregation.Aggregation; |
|
|
|
import org.springframework.data.mongodb.core.aggregation.Aggregation; |
|
|
|
import org.springframework.data.mongodb.core.aggregation.AggregationOperation; |
|
|
|
import org.springframework.data.mongodb.core.aggregation.AggregationOperation; |
|
|
@ -16,6 +22,7 @@ import org.springframework.data.mongodb.core.query.Criteria; |
|
|
|
import org.springframework.data.mongodb.core.query.Query; |
|
|
|
import org.springframework.data.mongodb.core.query.Query; |
|
|
|
import org.springframework.data.mongodb.core.query.Update; |
|
|
|
import org.springframework.data.mongodb.core.query.Update; |
|
|
|
import org.springframework.stereotype.Repository; |
|
|
|
import org.springframework.stereotype.Repository; |
|
|
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
@ -31,18 +38,33 @@ public class ForumDao extends BaseDao<Forum> { |
|
|
|
@Value("${forum.content-length}") |
|
|
|
@Value("${forum.content-length}") |
|
|
|
private int contentLength; |
|
|
|
private int contentLength; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//活动贴
|
|
|
|
|
|
|
|
//关联帖子外键属性
|
|
|
|
|
|
|
|
private static final String idKey = "_id"; |
|
|
|
|
|
|
|
//定义管道操作
|
|
|
|
|
|
|
|
private static final String activeKey = "activeDto"; |
|
|
|
|
|
|
|
//关联
|
|
|
|
|
|
|
|
private static final LookupOperation activeforumLookup = LookupOperation.newLookup().from(TableName.active).localField(idKey).foreignField(idKey).as(activeKey); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//投诉贴
|
|
|
|
|
|
|
|
//关联属性
|
|
|
|
|
|
|
|
private static final String complainKey = "complainDto"; |
|
|
|
|
|
|
|
//定义管道操作
|
|
|
|
|
|
|
|
private static final LookupOperation complainforumLookup = LookupOperation.newLookup().from(TableName.complain).localField(idKey).foreignField(idKey).as(complainKey); |
|
|
|
|
|
|
|
//关联属性
|
|
|
|
|
|
|
|
private static final String infoKey = "info"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//关联用户外键属性
|
|
|
|
|
|
|
|
private static final String usernameKey = "username"; |
|
|
|
|
|
|
|
//定义管道操作
|
|
|
|
|
|
|
|
private static final LookupOperation infoLookup = LookupOperation.newLookup().from(TableName.info).localField(usernameKey).foreignField(idKey).as(infoKey); |
|
|
|
|
|
|
|
|
|
|
|
//添加回复数
|
|
|
|
//添加回复数
|
|
|
|
public boolean update(ForumReplyForm forumReplyForm) { |
|
|
|
public boolean update(ForumReplyForm forumReplyForm) { |
|
|
|
return mongoTemplate.updateFirst(new Query(Criteria.where("id").is(new ObjectId(forumReplyForm.getForumId()))), |
|
|
|
return mongoTemplate.updateFirst(new Query(Criteria.where("id").is(new ObjectId(forumReplyForm.getForumId()))), |
|
|
|
new Update().inc("reply", 1), entityClass()).wasAcknowledged(); |
|
|
|
new Update().inc("reply", 1), entityClass()).wasAcknowledged(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//关联用户表查询
|
|
|
|
|
|
|
|
private static final LookupOperation lookupOperation = LookupOperation.newLookup(). |
|
|
|
|
|
|
|
from(TableName.info). //关联从表名
|
|
|
|
|
|
|
|
localField("username"). //主表关联字段
|
|
|
|
|
|
|
|
foreignField("_id").//从表关联的字段
|
|
|
|
|
|
|
|
as("myInfo"); //查询结果名
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查找热门贴
|
|
|
|
//查找热门贴
|
|
|
|
public List<ForumHot> rankReply(Forum.ForumType type, int num) { |
|
|
|
public List<ForumHot> rankReply(Forum.ForumType type, int num) { |
|
|
@ -50,7 +72,7 @@ public class ForumDao extends BaseDao<Forum> { |
|
|
|
List<Forum> forumList =mongoTemplate.find(new Query(Criteria.where("forumType").is(type)).with(Sort.by("reply").descending()).limit(num),entityClass()); |
|
|
|
List<Forum> forumList =mongoTemplate.find(new Query(Criteria.where("forumType").is(type)).with(Sort.by("reply").descending()).limit(num),entityClass()); |
|
|
|
for(Forum forum:forumList){ |
|
|
|
for(Forum forum:forumList){ |
|
|
|
ForumHot forumHot=new ForumHot(); |
|
|
|
ForumHot forumHot=new ForumHot(); |
|
|
|
forumHot.setForumId(forum.getId().toString()); |
|
|
|
forumHot.setForumId(forum.getId()); |
|
|
|
forumHot.setReply(forum.getReply()); |
|
|
|
forumHot.setReply(forum.getReply()); |
|
|
|
forumHot.setTitle(forum.getTitle()); |
|
|
|
forumHot.setTitle(forum.getTitle()); |
|
|
|
forumHots.add(forumHot); |
|
|
|
forumHots.add(forumHot); |
|
|
@ -59,10 +81,11 @@ public class ForumDao extends BaseDao<Forum> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//查找帖子
|
|
|
|
//查找帖子
|
|
|
|
private List<ForumVo> loadForum(AggregationOperation... operation) { |
|
|
|
private List<ForumDto> loadForum(AggregationOperation... operation) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Aggregation aggregation = Aggregation.newAggregation(operation); |
|
|
|
Aggregation aggregation = Aggregation.newAggregation(operation); |
|
|
|
return mongoTemplate.aggregate(aggregation, TableName.forum, ForumVo.class).getMappedResults(); |
|
|
|
LOG.info(aggregation.toString()); |
|
|
|
|
|
|
|
return mongoTemplate.aggregate(aggregation, TableName.forum, ForumDto.class).getMappedResults(); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
LOG.error(e.toString()); |
|
|
|
LOG.error(e.toString()); |
|
|
@ -70,29 +93,62 @@ public class ForumDao extends BaseDao<Forum> { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//查找所有帖子
|
|
|
|
//设置投诉贴投诉人详细信息
|
|
|
|
public List<ForumVo> loadNewForum() { |
|
|
|
private void loadComplain(ForumDto forumDto) { |
|
|
|
return loadForum(lookupOperation, Aggregation.unwind("myInfo"), Aggregation.sort(Sort.by("time").descending())); |
|
|
|
Complain complain = forumDto.getComplainDto(); |
|
|
|
|
|
|
|
complain.setInfo(mongoTemplate.findOne(new Query(Criteria.where(idKey).is(complain.getComplain())), MyInfo.class)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//查找最新帖子
|
|
|
|
//查询最新帖子
|
|
|
|
public List<ForumVo> loadMyForum(String username) { |
|
|
|
public Page<ForumDto> loadForum(ForumQuery forumQuery) { |
|
|
|
return loadForum(lookupOperation, Aggregation.unwind("myInfo"), Aggregation.match(Criteria.where("username").is(username)), Aggregation.sort(Sort.by("time").descending())); |
|
|
|
// 根据审核状态按时间从大到小排序的帖子
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Criteria criteria = new Criteria(); |
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(forumQuery.getStatus())) { |
|
|
|
|
|
|
|
Criteria.where("status").is(forumQuery.getStatus()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!StringUtils.isEmpty(forumQuery.getUsername())) { |
|
|
|
|
|
|
|
criteria = criteria.and("username").is(forumQuery.getUsername()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Query query = new Query(criteria).with(PageRequest.of(forumQuery.getCurrentPage().intValue() - 1, pageSize)); |
|
|
|
|
|
|
|
long currentCount = mongoTemplate.count(query, entityClass()); |
|
|
|
|
|
|
|
if (currentCount > 0) { |
|
|
|
|
|
|
|
long count = mongoTemplate.count(new Query(criteria), entityClass()); |
|
|
|
|
|
|
|
Page<ForumDto> page = new Page<>(count, forumQuery.getCurrentPage(), pageSize); |
|
|
|
|
|
|
|
List<ForumDto> forumDtos = loadForum(complainforumLookup, activeforumLookup, infoLookup, Aggregation.match(criteria), Aggregation.skip((forumQuery.getCurrentPage() - 1) * pageSize), Aggregation.limit(pageSize), Aggregation.sort(Sort.by("time").descending())); |
|
|
|
|
|
|
|
if (forumDtos != null) { |
|
|
|
|
|
|
|
for (ForumDto forumDto : forumDtos) { |
|
|
|
|
|
|
|
if (forumDto.getComplainDto() != null) { |
|
|
|
|
|
|
|
loadComplain(forumDto); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
page.setList(forumDtos); |
|
|
|
|
|
|
|
return page; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return new Page<>(0L, forumQuery.getCurrentPage(), pageSize); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
LOG.error(e.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//保存活动贴
|
|
|
|
//保存活动贴
|
|
|
|
public Forum save(ActiveForm activeForm){ |
|
|
|
public Forum save(ActiveVo activeVo) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Forum forum=new Forum(); |
|
|
|
Forum forum = new Forum(); |
|
|
|
forum.setUsername(activeForm.getUsername()); |
|
|
|
forum.setUsername(activeVo.getUsername()); |
|
|
|
forum.setForumType(Forum.ForumType.active); |
|
|
|
forum.setForumType(Forum.ForumType.active); |
|
|
|
forum.setReply(0); |
|
|
|
forum.setReply(0); |
|
|
|
forum.setTitle(activeForm.getTitle()); |
|
|
|
forum.setTitle(activeVo.getTitle()); |
|
|
|
forum.setTime(System.currentTimeMillis()); |
|
|
|
forum.setTime(System.currentTimeMillis()); |
|
|
|
if(activeForm.getContent().length()>contentLength){ |
|
|
|
forum.setStatus(Forum.ForumStatus.uncheck); |
|
|
|
forum.setContent(activeForm.getContent().substring(0,contentLength)); |
|
|
|
if (activeVo.getContent().length() > contentLength) { |
|
|
|
}else{ |
|
|
|
forum.setContent(activeVo.getContent().substring(0, contentLength)); |
|
|
|
forum.setContent(activeForm.getContent()); |
|
|
|
} else { |
|
|
|
|
|
|
|
forum.setContent(activeVo.getContent()); |
|
|
|
} |
|
|
|
} |
|
|
|
return save(forum); |
|
|
|
return save(forum); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
@ -103,15 +159,16 @@ public class ForumDao extends BaseDao<Forum> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//保存动态
|
|
|
|
//保存动态
|
|
|
|
public Forum save(ForumForm forumForm){ |
|
|
|
public Forum save(ForumVo forumVo) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Forum forum=new Forum(); |
|
|
|
Forum forum = new Forum(); |
|
|
|
forum.setContent(forumForm.getContent()); |
|
|
|
forum.setContent(forumVo.getContent()); |
|
|
|
forum.setTitle(forumForm.getTitle()); |
|
|
|
forum.setTitle(forumVo.getTitle()); |
|
|
|
forum.setForumType(Forum.ForumType.topic); |
|
|
|
forum.setForumType(Forum.ForumType.topic); |
|
|
|
forum.setTime(System.currentTimeMillis()); |
|
|
|
forum.setTime(System.currentTimeMillis()); |
|
|
|
forum.setReply(0); |
|
|
|
forum.setReply(0); |
|
|
|
forum.setUsername(forumForm.getUsername()); |
|
|
|
forum.setUsername(forumVo.getUsername()); |
|
|
|
|
|
|
|
forum.setStatus(Forum.ForumStatus.uncheck); |
|
|
|
return save(forum); |
|
|
|
return save(forum); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
@ -121,15 +178,16 @@ public class ForumDao extends BaseDao<Forum> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//保存投诉
|
|
|
|
//保存投诉
|
|
|
|
public Forum save(ComplainForm complainForm){ |
|
|
|
public Forum save(ComplainVo complainVo) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Forum forum=new Forum(); |
|
|
|
Forum forum = new Forum(); |
|
|
|
forum.setContent(complainForm.getContent()); |
|
|
|
forum.setContent(complainVo.getContent()); |
|
|
|
forum.setTitle(complainForm.getTitle()); |
|
|
|
forum.setTitle(complainVo.getTitle()); |
|
|
|
forum.setForumType(Forum.ForumType.complan); |
|
|
|
forum.setForumType(Forum.ForumType.complan); |
|
|
|
forum.setTime(System.currentTimeMillis()); |
|
|
|
forum.setTime(System.currentTimeMillis()); |
|
|
|
forum.setReply(0); |
|
|
|
forum.setReply(0); |
|
|
|
forum.setUsername(complainForm.getUsername()); |
|
|
|
forum.setUsername(complainVo.getUsername()); |
|
|
|
|
|
|
|
forum.setStatus(Forum.ForumStatus.uncheck); |
|
|
|
return save(forum); |
|
|
|
return save(forum); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
@ -138,6 +196,11 @@ public class ForumDao extends BaseDao<Forum> { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//审核帖子
|
|
|
|
|
|
|
|
public boolean check(ForumCheck forumCheck) { |
|
|
|
|
|
|
|
return mongoTemplate.updateFirst(new Query(Criteria.where(idKey).is(forumCheck.getId())), Update.update("status", forumCheck.getStatus()), entityClass()).wasAcknowledged(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//保存
|
|
|
|
//保存
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Forum save(Forum forum) { |
|
|
|
public Forum save(Forum forum) { |
|
|
|