Skip to content

Commit

Permalink
feat: 作业列表查询接口,添加支持根据作业id列表查询
Browse files Browse the repository at this point in the history
  • Loading branch information
dragove committed Jan 6, 2024
1 parent 688c2d6 commit 9583a17
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* @author LoMu
* Date 2022-12-26 2:48
Expand All @@ -25,6 +27,7 @@ public class CopilotQueriesRequest {
private boolean desc = true;
private String orderBy;
private String language;
private List<Long> copilotIds;

/*
* 这里为了正确接收前端的下划线风格,手动写了三个 setter 用于起别名
Expand All @@ -33,17 +36,27 @@ public class CopilotQueriesRequest {
* (吐槽一下,同样是Get请求,怎么CommentsQueries是驼峰命名,到了CopilotQueries就成了下划线命名)
*/
@JsonIgnore
@SuppressWarnings("unused")
public void setLevel_keyword(String levelKeyword) {
this.levelKeyword = levelKeyword;
}

@JsonIgnore
@SuppressWarnings("unused")
public void setUploader_id(String uploaderId) {
this.uploaderId = uploaderId;
}

@JsonIgnore
@SuppressWarnings("unused")
public void setOrder_by(String orderBy) {
this.orderBy = orderBy;
}

@JsonIgnore
@SuppressWarnings("unused")
public void setCopilot_ids(List<Long> copilotIds) {
this.copilotIds = copilotIds;
}

}
17 changes: 12 additions & 5 deletions src/main/java/plus/maa/backend/service/CopilotService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package plus.maa.backend.service;

import cn.hutool.core.collection.CollectionUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Sets;
Expand Down Expand Up @@ -201,7 +202,7 @@ public Optional<CopilotInfo> getCopilotById(String userIdOrIpAddress, Long id) {

// 新评分系统
RatingType ratingType = ratingRepository.findByTypeAndKeyAndUserId(Rating.KeyType.COPILOT,
Long.toString(copilot.getCopilotId()), userIdOrIpAddress)
Long.toString(copilot.getCopilotId()), userIdOrIpAddress)
.map(Rating::getRating)
.orElse(null);
// 用户点进作业会显示点赞信息
Expand All @@ -225,7 +226,8 @@ public CopilotPageInfo queriesCopilot(@Nullable String userId, CopilotQueriesReq
AtomicReference<String> setKey = new AtomicReference<>();
// 只缓存默认状态下热度和访问量排序的结果,并且最多只缓存前三页
if (request.getPage() <= 3 && request.getDocument() == null && request.getLevelKeyword() == null &&
request.getUploaderId() == null && request.getOperator() == null) {
request.getUploaderId() == null && request.getOperator() == null &&
CollectionUtil.isEmpty(request.getCopilotIds())) {

Optional<CopilotPageInfo> cacheOptional = Optional.ofNullable(request.getOrderBy())
.filter(StringUtils::isNotBlank)
Expand Down Expand Up @@ -279,6 +281,11 @@ public CopilotPageInfo queriesCopilot(@Nullable String userId, CopilotQueriesReq
}
}

// 作业id列表
if (CollectionUtil.isNotEmpty(request.getCopilotIds())) {
andQueries.add(Criteria.where("copilotId").in(request.getCopilotIds()));
}

//标题、描述、神秘代码
if (StringUtils.isNotBlank(request.getDocument())) {
orQueries.add(Criteria.where("doc.title").regex(caseInsensitive(request.getDocument())));
Expand Down Expand Up @@ -341,9 +348,9 @@ public CopilotPageInfo queriesCopilot(@Nullable String userId, CopilotQueriesReq
// 新版评分系统
// 反正目前首页和搜索不会直接展示当前用户有没有点赞,干脆直接不查,要用户点进作业才显示自己是否点赞
List<CopilotInfo> infos = copilots.stream().map(copilot ->
formatCopilot(copilot, null,
maaUsers.get(copilot.getUploaderId()).getUserName(),
commentsCount.get(copilot.getCopilotId())))
formatCopilot(copilot, null,
maaUsers.get(copilot.getUploaderId()).getUserName(),
commentsCount.get(copilot.getCopilotId())))
.toList();

// 计算页面
Expand Down

0 comments on commit 9583a17

Please sign in to comment.