feat: 新增任务下拉选项接口
This commit is contained in:
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.protobuf.ServiceException;
|
||||
import com.guo.learningprogresstracker.common.Ops;
|
||||
import com.guo.learningprogresstracker.dto.TaskInfo;
|
||||
import com.guo.learningprogresstracker.dto.TaskOption;
|
||||
import com.guo.learningprogresstracker.dto.request.CreateTaskApplicationRequest;
|
||||
import com.guo.learningprogresstracker.dto.response.StudySessionResponse;
|
||||
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
|
||||
@@ -128,6 +129,12 @@ public class TaskController {
|
||||
return CommonResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("/options")
|
||||
@Operation(summary = "全部任务的最小选项(归类下拉用)")
|
||||
public CommonResult<List<TaskOption>> taskOptions() {
|
||||
return CommonResult.success(tasksService.taskOptions());
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "获取所有任务列表")
|
||||
public CommonResult<Page<TaskInfo>> tasksList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.guo.learningprogresstracker.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 任务的最小选项(任务编号 + 名称),供「归类到已有任务」这类下拉使用。
|
||||
*
|
||||
* <p>刻意不复用 {@code /review/tasks}:那条接口会做复习统计聚合(时长/报告数/碎片数),
|
||||
* 且现在已按页返回;下拉需要的是全部任务的一个最小列表。也不复用分页的 {@code /tasks},
|
||||
* 否则任务多起来下拉会悄悄只显示第一页。</p>
|
||||
*
|
||||
* <p>排序与任务列表一致(优先级倒序),保证下拉里的顺序稳定。</p>
|
||||
*/
|
||||
public record TaskOption(
|
||||
@Schema(description = "任务编号")
|
||||
String taskNum,
|
||||
@Schema(description = "任务名称")
|
||||
String taskName) {
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.guo.learningprogresstracker.dto.TaskDeletionSummary;
|
||||
import com.guo.learningprogresstracker.dto.TaskInfo;
|
||||
import com.guo.learningprogresstracker.dto.TaskOption;
|
||||
import com.guo.learningprogresstracker.dto.request.CreateTaskApplicationRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateTaskApplicationRequest;
|
||||
@@ -25,6 +26,11 @@ public interface TasksService extends IService<TaskEntity> {
|
||||
|
||||
Page<TaskInfo> taskList(Integer pageNum, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 全部任务的最小选项(编号 + 名称),按优先级倒序;供归类下拉等选择场景使用。
|
||||
*/
|
||||
List<TaskOption> taskOptions();
|
||||
|
||||
String addTask(TaskRequest taskRequest) throws ErrorParameterException;
|
||||
|
||||
TaskInfoResponse getTask(String taskId);
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guo.learningprogresstracker.dto.PriorityDto;
|
||||
import com.guo.learningprogresstracker.dto.TaskDeletionSummary;
|
||||
import com.guo.learningprogresstracker.dto.TaskInfo;
|
||||
import com.guo.learningprogresstracker.dto.TaskOption;
|
||||
import com.guo.learningprogresstracker.dto.request.CreateTaskApplicationRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import com.guo.learningprogresstracker.dto.request.UpdateTaskApplicationRequest;
|
||||
@@ -31,6 +32,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 针对表【tasks(存储学习任务的基本信息,包括优先级的多维度计算)】的数据库操作Service实现
|
||||
@@ -58,6 +60,19 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskOption> taskOptions() {
|
||||
// 只查两列,不做任何聚合:下拉要的是全部任务,不是一页
|
||||
return tasksMapper.selectList(Wrappers.<TaskEntity>lambdaQuery()
|
||||
.select(TaskEntity::getTaskNum, TaskEntity::getTaskName)
|
||||
.orderByDesc(TaskEntity::getCalculatedPriority)
|
||||
.orderByDesc(TaskEntity::getId))
|
||||
.stream()
|
||||
.filter(task -> task.getTaskNum() != null && !task.getTaskNum().isBlank())
|
||||
.map(task -> new TaskOption(task.getTaskNum(), task.getTaskName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addTask(TaskRequest taskRequest) throws ErrorParameterException {
|
||||
TaskEntity task = TaskConvert.MAPPER.taskRequestToTaskEntity(taskRequest);
|
||||
|
||||
Reference in New Issue
Block a user