mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-08 02:16:49 +08:00
收藏增加回答
This commit is contained in:
@@ -6,6 +6,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.module.interaction.dto.*;
|
||||
import com.xboe.module.qa.entity.Question;
|
||||
import com.xboe.module.qa.service.IQuestionService;
|
||||
import com.xboe.school.study.service.IStudyCourseService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -43,6 +45,9 @@ public class FavoritesApi extends ApiBaseController {
|
||||
@Autowired
|
||||
IStudyCourseService studyCourseService;
|
||||
|
||||
@Autowired
|
||||
IQuestionService questionService;
|
||||
|
||||
/**
|
||||
* 此处的查询需要再讨论一下,因为有不同的内容,前端呈现的也不一样
|
||||
*
|
||||
@@ -104,6 +109,26 @@ public class FavoritesApi extends ApiBaseController {
|
||||
return success(articlePage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 我收藏的问答
|
||||
* */
|
||||
@PostMapping("/favorite-answer")
|
||||
public JsonResponse<PageList<FavoritesAnswerDto>> findAnswerPage(Pagination pager,String keyword,Boolean isBest){
|
||||
String aid = this.getCurrent().getAccountId();
|
||||
PageList<FavoritesAnswerDto> answerPage = service.findAnswerPage(pager.getPageIndex(), pager.getPageSize(), keyword, isBest, aid);
|
||||
List<String> qids = answerPage.getList().stream().map(FavoritesAnswerDto::getQid).collect(Collectors.toList());
|
||||
//查出问题标题
|
||||
List<Question> questions = questionService.title(qids);
|
||||
for (FavoritesAnswerDto f:answerPage.getList()) {
|
||||
for (Question q:questions) {
|
||||
if(f.getQid().equals(q.getId())){
|
||||
f.setQtitle(q.getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
return success(answerPage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -222,6 +247,7 @@ public class FavoritesApi extends ApiBaseController {
|
||||
public JsonResponse<PageList<FavoriteTotalDto>> queryAll(Pagination pager,String keyword){
|
||||
String aid = this.getCurrent().getAccountId();
|
||||
PageList<FavoriteTotalDto> favoriteTotalDtoPageList = service.queryAll(pager.getPageIndex(), pager.getPageSize(), aid, keyword);
|
||||
|
||||
List<String> courseIds = favoriteTotalDtoPageList.getList().stream().filter(favoriteTotalDto -> favoriteTotalDto.getType() == 1).
|
||||
map(FavoriteTotalDto::getId).collect(Collectors.toList());
|
||||
List<Object[]> progress = studyCourseService.progress(aid, courseIds);
|
||||
@@ -235,6 +261,18 @@ public class FavoritesApi extends ApiBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
List<String> qids = favoriteTotalDtoPageList.getList().stream().filter(favoriteTotalDto -> favoriteTotalDto.getType() == 5).
|
||||
map(FavoriteTotalDto::getQid).collect(Collectors.toList());
|
||||
|
||||
List<Question> questions = questionService.title(qids);
|
||||
for (FavoriteTotalDto f:favoriteTotalDtoPageList.getList()) {
|
||||
for (Question q:questions) {
|
||||
if(f.getQid().equals(q.getId())){
|
||||
f.setTitle(q.getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return success(favoriteTotalDtoPageList);
|
||||
}
|
||||
|
||||
@@ -86,6 +86,11 @@ public class FavoriteTotalDto {
|
||||
* */
|
||||
private Float progress;
|
||||
|
||||
/**
|
||||
* qid
|
||||
* */
|
||||
private String qid;
|
||||
|
||||
|
||||
public FavoriteTotalDto() {
|
||||
}
|
||||
@@ -94,4 +99,6 @@ public class FavoriteTotalDto {
|
||||
this.favoritesTime=favoritesTime;
|
||||
this.type=type;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.xboe.module.interaction.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class FavoritesAnswerDto {
|
||||
|
||||
/**
|
||||
* 问题标题
|
||||
* */
|
||||
|
||||
private String qtitle;
|
||||
|
||||
/**
|
||||
* 问题id
|
||||
* */
|
||||
|
||||
private String qid;
|
||||
|
||||
/**
|
||||
* 答案内容
|
||||
* */
|
||||
|
||||
private String answer;
|
||||
|
||||
|
||||
private Integer praises;
|
||||
|
||||
|
||||
private Integer shares;
|
||||
|
||||
|
||||
private Integer favorites;
|
||||
|
||||
|
||||
/**
|
||||
* 收藏时间
|
||||
* */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime favoeiteTime;
|
||||
|
||||
|
||||
/**
|
||||
* 收藏id
|
||||
* */
|
||||
|
||||
private String favoriteId;
|
||||
|
||||
/**
|
||||
* 收藏人id
|
||||
* */
|
||||
private String favorSysCreateId;
|
||||
|
||||
/**
|
||||
* 答案作者id
|
||||
* */
|
||||
private String sysCreateAid;
|
||||
|
||||
/**
|
||||
* 答案作者id
|
||||
* */
|
||||
private String sysCreateBy;
|
||||
|
||||
/**
|
||||
* 图片
|
||||
* */
|
||||
private String images;
|
||||
|
||||
private Integer objType;
|
||||
|
||||
/**
|
||||
* 答案id
|
||||
* */
|
||||
private String answerId;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public interface IFavoritesService {
|
||||
PageList<FavoriteDto> findCoursePage(int pageIndex, int pageSize, Favorites favorite,Integer type,String keyword,String aid);
|
||||
|
||||
/**
|
||||
* 查询收藏的问答
|
||||
* 查询收藏的问题
|
||||
* @param pageIndex
|
||||
* @param pageSize
|
||||
* @param favorite
|
||||
@@ -33,6 +33,13 @@ public interface IFavoritesService {
|
||||
* @return
|
||||
*/
|
||||
PageList<FavoriteQaDto> findQaPage(int pageIndex, int pageSize, Favorites favorite,Boolean isResolve,String keyword,String aid);
|
||||
|
||||
|
||||
/**
|
||||
* 查询收藏的回答
|
||||
* */
|
||||
PageList<FavoritesAnswerDto> findAnswerPage(int pageIndex,int pageSize,String keyWord,Boolean isBest,String aid);
|
||||
|
||||
/**
|
||||
* 查询收藏的案例
|
||||
// * */
|
||||
|
||||
@@ -12,6 +12,9 @@ import java.util.Set;
|
||||
import javax.annotation.Resource;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import com.xboe.module.interaction.dto.*;
|
||||
import com.xboe.module.qa.dao.AnswerDao;
|
||||
import com.xboe.module.qa.entity.Answer;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@@ -33,11 +36,6 @@ import com.xboe.module.boecase.entity.Cases;
|
||||
import com.xboe.module.course.dao.CourseDao;
|
||||
import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.interaction.dao.FavoritesDao;
|
||||
import com.xboe.module.interaction.dto.FavoriteArticleDto;
|
||||
import com.xboe.module.interaction.dto.FavoriteCaseDto;
|
||||
import com.xboe.module.interaction.dto.FavoriteDto;
|
||||
import com.xboe.module.interaction.dto.FavoriteQaDto;
|
||||
import com.xboe.module.interaction.dto.FavoriteTotalDto;
|
||||
import com.xboe.module.interaction.entity.Favorites;
|
||||
import com.xboe.module.interaction.service.IFavoritesService;
|
||||
import com.xboe.module.qa.dao.QuestionDao;
|
||||
@@ -70,6 +68,9 @@ public class FavoritesServiceImpl implements IFavoritesService{
|
||||
@Resource
|
||||
CasesDao casesDao;
|
||||
|
||||
@Autowired
|
||||
AnswerDao answerDao;
|
||||
|
||||
|
||||
@Override
|
||||
@Caching(evict = {@CacheEvict(value = CacheName.FAVOR, key = "'" + CacheName.KEY_FAVOR + "'+#favorite.objType+#favorite.objId+#favorite.sysCreateAid")})
|
||||
@@ -123,7 +124,7 @@ public class FavoritesServiceImpl implements IFavoritesService{
|
||||
builder.addFilter(FieldFilters.eq("sysCreateAid",aid));
|
||||
builder.setPageIndex(pageIndex);
|
||||
builder.setPageSize(pageSize);
|
||||
builder.addOrder(OrderCondition.desc("id"));
|
||||
builder.addOrder(OrderCondition.desc("sysCreateTime"));
|
||||
if(StringUtils.isNotBlank(keyWord)){
|
||||
builder.addFilter(FieldFilters.like("title", LikeMatchMode.ANYWHERE,keyWord));
|
||||
}
|
||||
@@ -137,9 +138,12 @@ public class FavoritesServiceImpl implements IFavoritesService{
|
||||
//案例id集合
|
||||
Set<String> caseList = new HashSet<>();
|
||||
// Map<String,FavoriteTotalDto> map = new HashMap<>();
|
||||
|
||||
//笔记id集合
|
||||
Set<String> noteList = new HashSet<>();
|
||||
|
||||
//回答id集合
|
||||
Set<String> answerList = new HashSet<>();
|
||||
|
||||
for (Favorites f: page.getList()) {
|
||||
FavoriteTotalDto favoriteTotalDto = new FavoriteTotalDto();
|
||||
favoriteTotalDto.setFavoritesTime(f.getSysCreateTime());
|
||||
@@ -164,6 +168,9 @@ public class FavoritesServiceImpl implements IFavoritesService{
|
||||
if(f.getObjType()==6){
|
||||
noteList.add(f.getObjId());
|
||||
}
|
||||
if(f.getObjType()==5){
|
||||
answerList.add(f.getObjId());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -313,6 +320,33 @@ public class FavoritesServiceImpl implements IFavoritesService{
|
||||
}
|
||||
}
|
||||
|
||||
if(!answerList.isEmpty()){
|
||||
QueryBuilder from = QueryBuilder.from(Answer.class);
|
||||
from.addFilter(FieldFilters.in("id", answerList));
|
||||
from.addFields("id","content","images","praises","shares","favorites","sysCreateAid","sysCreateBy","qid","sysCreateTime");
|
||||
try {
|
||||
List<Object[]> listFields = articleDao.findListFields(builder.builder());
|
||||
for (Object[] o:listFields) {
|
||||
for (FavoriteTotalDto favoriteTotalDto : list.getList()) {
|
||||
|
||||
favoriteTotalDto.setContent((String) o[1]);
|
||||
favoriteTotalDto.setImage((String) o[2]);
|
||||
favoriteTotalDto.setPraises((Integer) o[3]);
|
||||
favoriteTotalDto.setShares((Integer) o[4]);
|
||||
favoriteTotalDto.setFavorites((Integer) o[5]);
|
||||
favoriteTotalDto.setAuthorId((String) o[6]);
|
||||
favoriteTotalDto.setAuthorName((String) o[7]);
|
||||
favoriteTotalDto.setQid((String) o[8]);
|
||||
favoriteTotalDto.setPublishTime((LocalDateTime) o[9]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
list.setCount(page.getCount());
|
||||
list.setPageSize(pageSize);
|
||||
return list;
|
||||
@@ -390,7 +424,7 @@ public class FavoritesServiceImpl implements IFavoritesService{
|
||||
query.addFields("c.deadTime","c.views","c.comments","c.praises","c.shares","c.favorites","f.objType");
|
||||
query.setPageIndex(pageIndex);
|
||||
query.setPageSize(pageSize);
|
||||
query.addOrder(OrderCondition.desc("f.id"));
|
||||
query.addOrder(OrderCondition.desc("f.sysCreateTime"));
|
||||
query.addFilter(FieldFilters.eqField("f.objId","c.id"));
|
||||
query.addFilter(FieldFilters.eq("f.objType",BoedxResourceType.Course.value()));
|
||||
//查询用户自己的课程收藏,
|
||||
@@ -458,7 +492,7 @@ public class FavoritesServiceImpl implements IFavoritesService{
|
||||
QueryBuilder query=QueryBuilder.from(from);
|
||||
query.setPageIndex(pageIndex);
|
||||
query.setPageSize(pageSize);
|
||||
query.addOrder(OrderCondition.desc("f.id"));
|
||||
query.addOrder(OrderCondition.desc("f.sysCreateTime"));
|
||||
query.addFilter(FieldFilters.eqField("f.objId","q.id"));
|
||||
query.addFilter(FieldFilters.eq("f.objType",BoedxResourceType.QA.value()));
|
||||
//查询用户自己的问答收藏,
|
||||
@@ -526,6 +560,53 @@ public class FavoritesServiceImpl implements IFavoritesService{
|
||||
// return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageList<FavoritesAnswerDto> findAnswerPage(int pageIndex, int pageSize, String keyWord, Boolean isBest, String aid) {
|
||||
PageList<FavoritesAnswerDto> pageList = new PageList<>();
|
||||
pageList.setList(new ArrayList<FavoritesAnswerDto>());
|
||||
pageList.setPageSize(pageSize);
|
||||
String from =Favorites.class.getSimpleName()+" f,"+ Answer.class.getSimpleName()+" a";
|
||||
QueryBuilder builder=QueryBuilder.from(from);
|
||||
builder.setPageIndex(pageIndex);
|
||||
builder.setPageSize(pageSize);
|
||||
builder.addOrder(OrderCondition.desc("f.sysCreateTime"));
|
||||
builder.addFilter(FieldFilters.eq("f.objId","a.id"));
|
||||
builder.addFilter(FieldFilters.eq("f.objType",BoedxResourceType.Answer.value()));
|
||||
builder.addFilter(FieldFilters.eq("f.sysCreateAid",aid));
|
||||
if(StringUtils.isNotBlank(keyWord)){
|
||||
builder.addFilter(FieldFilters.like("a.content",keyWord));
|
||||
}
|
||||
builder.addFields("f.id","f.sysCreateTime","f.sysCreateAid,f.objType","a.id","a.content","a.praises","a.shares","a.favorites","a.sysCreateAid","a.qid","a.sysCreateBy","a.images");
|
||||
PageList<Object[]> pageFields=null;
|
||||
try {
|
||||
pageFields=dao.findPageFields(builder.builder());
|
||||
pageList.setPageSize(pageSize);
|
||||
pageList.setCount(pageFields.getCount());
|
||||
for (Object[] o:pageFields.getList()) {
|
||||
FavoritesAnswerDto favoritesAnswerDto = new FavoritesAnswerDto();
|
||||
favoritesAnswerDto.setFavoriteId((String) o[0]);
|
||||
favoritesAnswerDto.setFavoeiteTime((LocalDateTime) o[1]);
|
||||
favoritesAnswerDto.setFavorSysCreateId((String) o[2]);
|
||||
favoritesAnswerDto.setObjType((Integer) o[3]);
|
||||
favoritesAnswerDto.setAnswerId((String) o[4]);
|
||||
favoritesAnswerDto.setAnswer((String) o[5]);
|
||||
favoritesAnswerDto.setPraises((Integer) o[6]);
|
||||
favoritesAnswerDto.setShares((Integer) o[7]);
|
||||
favoritesAnswerDto.setFavorites((Integer) o[8]);
|
||||
favoritesAnswerDto.setSysCreateAid((String) o[9]);
|
||||
favoritesAnswerDto.setQid((String) o[10]);
|
||||
favoritesAnswerDto.setSysCreateBy((String) o[11]);
|
||||
favoritesAnswerDto.setImages((String) o[12]);
|
||||
pageList.getList().add(favoritesAnswerDto);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("收藏回答关联错误",e);
|
||||
}
|
||||
return pageList;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询我收藏的案例
|
||||
* */
|
||||
@@ -540,7 +621,7 @@ public class FavoritesServiceImpl implements IFavoritesService{
|
||||
QueryBuilder builder = QueryBuilder.from(from);
|
||||
builder.setPageIndex(pageIndex);
|
||||
builder.setPageSize(pageSize);
|
||||
builder.addOrder(OrderCondition.desc("f.id"));
|
||||
builder.addOrder(OrderCondition.desc("f.sysCreateTime"));
|
||||
builder.addFilter(FieldFilters.eqField("f.objId","c.id"));
|
||||
builder.addFilter(FieldFilters.eq("f.objType",BoedxResourceType.Case.value()));
|
||||
builder.addFilter(FieldFilters.eq("f.sysCreateAid",aid));
|
||||
@@ -585,7 +666,7 @@ public class FavoritesServiceImpl implements IFavoritesService{
|
||||
QueryBuilder builder = QueryBuilder.from(from);
|
||||
builder.setPageIndex(pageIndex);
|
||||
builder.setPageSize(pageSize);
|
||||
builder.addOrder(OrderCondition.desc("f.id"));
|
||||
builder.addOrder(OrderCondition.desc("f.sysCreateTime"));
|
||||
builder.addFilter(FieldFilters.eqField("f.objId","a.id"));
|
||||
builder.addFilter(FieldFilters.eq("f.objType",BoedxResourceType.Article.value()));
|
||||
builder.addFilter(FieldFilters.eq("f.sysCreateAid",aid));
|
||||
|
||||
@@ -97,5 +97,10 @@ public interface IQuestionService {
|
||||
* */
|
||||
List<Question> indexQaAnswers(Integer num);
|
||||
|
||||
/**
|
||||
* 查询该回答的问答标题
|
||||
* */
|
||||
List<Question> title(List<String> aid);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -482,5 +482,16 @@ public class QuestionServiceImpl implements IQuestionService {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Question> title(List<String> qid) {
|
||||
QueryBuilder builder = QueryBuilder.from(Question.class);
|
||||
builder.addFilter(FieldFilters.in("id",qid));
|
||||
builder.addFields("new Question(id,title)");
|
||||
List<Question> list = questionDao.findList(builder.builder());
|
||||
return list;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user