架构性调整【懒得区分了,哈哈哈哈】,主要是跑通了第一个功能测试
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
<description>LearningProgressTracker</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<mapstruct.version>1.5.5.Final</mapstruct.version>
|
||||
<lombok.version>1.18.30</lombok.version>
|
||||
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -31,8 +34,9 @@
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@@ -51,6 +55,7 @@
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-mysql</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--引入mysql-connector-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
@@ -63,6 +68,18 @@
|
||||
<version>1.2.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>${mapstruct.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>${mapstruct.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
@@ -99,15 +116,31 @@
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<forceJavacCompilerUse>true</forceJavacCompilerUse>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
<version>${lombok.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>${mapstruct.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok-mapstruct-binding</artifactId>
|
||||
<version>${lombok-mapstruct-binding.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.guo.learningprogresstracker.config;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.guo.learningprogresstracker.entity.UserEntity;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 用于配置
|
||||
*
|
||||
* @author guo
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class AutoTableField implements MetaObjectHandler {
|
||||
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
log.info("insert autoField");
|
||||
this.strictInsertFill(metaObject, "createdBy", StpUtil::getLoginIdAsString, String.class);
|
||||
this.strictInsertFill(metaObject, "createdTime", LocalDateTime::now, LocalDateTime.class);
|
||||
this.strictInsertFill(metaObject, "lastModifiedBy", StpUtil::getLoginIdAsString, String.class);
|
||||
this.strictInsertFill(metaObject, "lastModifiedTime", LocalDateTime::now, LocalDateTime.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
this.strictInsertFill(metaObject, "lastModifiedBy", StpUtil::getLoginIdAsString, String.class);
|
||||
this.strictInsertFill(metaObject, "lastModifiedTime", LocalDateTime::now, LocalDateTime.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class StudySessionController {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,26 +1,59 @@
|
||||
package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.CommonResult;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import com.guo.learningprogresstracker.service.TasksService;
|
||||
import com.guo.learningprogresstracker.service.impl.TasksServiceImpl;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.scheduling.config.Task;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 任务控制层
|
||||
* @author guo
|
||||
*/
|
||||
@Controller
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class TaskController {
|
||||
|
||||
private final TasksService tasksService;
|
||||
|
||||
public TaskController(TasksServiceImpl tasksService) {
|
||||
this.tasksService = tasksService;
|
||||
@PostMapping("/tasks")
|
||||
@Operation(summary = "添加新任务")
|
||||
public CommonResult addTask(@RequestBody TaskRequest taskRequest) {
|
||||
return CommonResult.success(tasksService.addTask(taskRequest));
|
||||
}
|
||||
|
||||
@Operation(summary = "任务详情API-未完成")
|
||||
@GetMapping("/tasks/{taskId}")
|
||||
public CommonResult<TaskInfoResult> showTask(@PathVariable("taskId") String taskId) {
|
||||
public CommonResult showTask(@PathVariable("taskId") String taskId) {
|
||||
return CommonResult.success(tasksService.showTask(taskId));
|
||||
}
|
||||
|
||||
@PutMapping("/tasks/{taskId}")
|
||||
@Operation(summary = "更新任务详情")
|
||||
public CommonResult updateTask(@PathVariable("taskId") String taskId, @RequestBody Task updatedTask) {
|
||||
// return CommonResult.success(tasksService.updateTask(taskId, updatedTask));
|
||||
return null;
|
||||
}
|
||||
|
||||
@DeleteMapping("/tasks/{taskId}")
|
||||
@Operation(summary = "删除指定任务")
|
||||
public CommonResult deleteTask(@PathVariable("taskId") String taskId) {
|
||||
// return CommonResult.success(tasksService.deleteTask(taskId));
|
||||
return null;
|
||||
}
|
||||
|
||||
@GetMapping("/tasks")
|
||||
@Operation(summary = "获取所有任务列表")
|
||||
public CommonResult listTasks() {
|
||||
// return CommonResult.success(tasksService.listTasks());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.guo.learningprogresstracker.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PriorityDto {
|
||||
/**
|
||||
* 用户设置的任务紧急性
|
||||
*/
|
||||
private Integer urgency;
|
||||
|
||||
/**
|
||||
* 用户设置的任务重要性
|
||||
*/
|
||||
private Integer importance;
|
||||
|
||||
/**
|
||||
* 任务的内容难度
|
||||
*/
|
||||
private Integer contentDifficulty;
|
||||
|
||||
/**
|
||||
* 任务的未来价值
|
||||
*/
|
||||
private Integer futureValue;
|
||||
|
||||
/**
|
||||
* 用户对任务的主观优先级
|
||||
*/
|
||||
private Integer subjectivePriority;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.guo.learningprogresstracker.dto.request;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 学习任务-请求参数-创建
|
||||
*/
|
||||
@Data
|
||||
public class TaskRequest {
|
||||
static class Create{}
|
||||
/**
|
||||
* 学习任务的名称
|
||||
*/
|
||||
@NotEmpty(message = "必须指定非空的任务名称", groups = TaskRequest.Create.class)
|
||||
private String taskName;
|
||||
|
||||
/**
|
||||
* 学习材料的存储URL
|
||||
*/
|
||||
private String materialUrl;
|
||||
|
||||
/**
|
||||
* 用户设置的任务紧急性
|
||||
*/
|
||||
@NotEmpty(message = "必须指定【任务紧急性】指标", groups = Create.class)
|
||||
private Integer urgency;
|
||||
|
||||
/**
|
||||
* 用户设置的任务重要性
|
||||
*/
|
||||
@NotEmpty(message = "必须指定【任务重要性】指标", groups = Create.class)
|
||||
private Integer importance;
|
||||
|
||||
/**
|
||||
* 任务的内容难度
|
||||
*/
|
||||
@NotEmpty(message = "必须指定【内容难度】指标", groups = Create.class)
|
||||
private Integer contentDifficulty;
|
||||
|
||||
/**
|
||||
* 任务的未来价值
|
||||
*/
|
||||
@NotEmpty(message = "必须指定【未来价值】指标", groups = Create.class)
|
||||
private Integer futureValue;
|
||||
|
||||
/**
|
||||
* 用户对任务的主观优先级
|
||||
*/
|
||||
@NotEmpty(message = "必须指定【主观优先级】指标", groups = Create.class)
|
||||
private Integer subjectivePriority;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.guo.learningprogresstracker.dto.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TaskInfoResponse {
|
||||
// 任务列表
|
||||
private List<TaskInfo> taskList;
|
||||
|
||||
|
||||
static class TaskInfo{
|
||||
// 任务名称
|
||||
private String taskName;
|
||||
// 任务描述
|
||||
private String taskDescription;
|
||||
// 任务优先级
|
||||
private Integer taskPriority;
|
||||
// 上次该任务学习情况
|
||||
private String lastLearningStatus;
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,12 @@ public class BaseEntity {
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createdBy;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String updatedBy;
|
||||
private LocalDateTime lastModifiedTime;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String lastModifiedBy;
|
||||
}
|
||||
|
||||
@@ -33,29 +33,6 @@ public class StudyExpectationsEntity extends BaseEntity implements Serializable
|
||||
@TableField(value = "description")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "created_time")
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "created_by")
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "last_modified_time")
|
||||
private LocalDateTime lastModifiedTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "last_modified_by")
|
||||
private String lastModifiedBy;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -33,29 +33,6 @@ public class StudyReportFragmentsEntity extends BaseEntity implements Serializab
|
||||
@TableField(value = "content")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "created_time")
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "created_by")
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "last_modified_time")
|
||||
private LocalDateTime lastModifiedTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "last_modified_by")
|
||||
private String lastModifiedBy;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -33,29 +33,6 @@ public class StudyReportsEntity extends BaseEntity implements Serializable {
|
||||
@TableField(value = "content")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "created_time")
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "created_by")
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "last_modified_time")
|
||||
private LocalDateTime lastModifiedTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "last_modified_by")
|
||||
private String lastModifiedBy;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -63,29 +63,6 @@ public class StudySessionsEntity extends BaseEntity implements Serializable {
|
||||
@TableField(value = "session_state")
|
||||
private String sessionState;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "created_by")
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "last_modified_time")
|
||||
private LocalDateTime lastModifiedTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "last_modified_by")
|
||||
private String lastModifiedBy;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "created_time")
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -6,9 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Null;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 存储学习任务的基本信息,包括优先级的多维度计算
|
||||
@@ -17,11 +16,15 @@ import lombok.Data;
|
||||
@TableName(value ="tasks")
|
||||
@Data
|
||||
public class TaskEntity extends BaseEntity implements Serializable {
|
||||
|
||||
@TableId(value = "id",type = IdType.AUTO)
|
||||
private int id;
|
||||
|
||||
/**
|
||||
*
|
||||
* 任务编码
|
||||
*/
|
||||
@TableId(value = "task_id", type = IdType.AUTO)
|
||||
private Integer taskId;
|
||||
@TableField(value = "task_num")
|
||||
private String taskNum;
|
||||
|
||||
/**
|
||||
* 学习任务的名称
|
||||
|
||||
@@ -31,29 +31,6 @@ public class UserTaskEntity extends BaseEntity implements Serializable {
|
||||
@TableField(value = "task_id")
|
||||
private Integer taskId;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "created_time")
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "created_by")
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "last_modified_time")
|
||||
private LocalDateTime lastModifiedTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField(value = "last_modified_by")
|
||||
private String lastModifiedBy;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.guo.learningprogresstracker.mapStruct;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.PriorityDto;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* @author guo
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface RequestConvert {
|
||||
RequestConvert MAPPER = Mappers.getMapper(RequestConvert.class);
|
||||
|
||||
PriorityDto taskRequestToPriorityDto(TaskRequest taskRequest);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.guo.learningprogresstracker.mapStruct;
|
||||
|
||||
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 任务相关转换
|
||||
* @author guo
|
||||
*/
|
||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface TaskConvert {
|
||||
TaskConvert MAPPER = Mappers.getMapper(TaskConvert.class);
|
||||
|
||||
TaskEntity taskRequestToTaskEntity(TaskRequest taskRequest);
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.guo.learningprogresstracker.mapper;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.TasksEntity;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* @Entity com.guo.learningprogresstracker.entity.TasksEntity
|
||||
*/
|
||||
@Mapper
|
||||
public interface TasksMapper extends BaseMapper<TasksEntity> {
|
||||
public interface TasksMapper extends BaseMapper<TaskEntity> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.guo.learningprogresstracker.service;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.TasksEntity;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
@@ -8,6 +10,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* @description 针对表【tasks(存储学习任务的基本信息,包括优先级的多维度计算)】的数据库操作Service
|
||||
* @createDate 2024-06-09 15:28:48
|
||||
*/
|
||||
public interface TasksService extends IService<TasksEntity> {
|
||||
public interface TasksService extends IService<TaskEntity> {
|
||||
|
||||
TaskInfoResponse showTask(String taskId);
|
||||
|
||||
String addTask(TaskRequest taskRequest);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guo.learningprogresstracker.entity.TasksEntity;
|
||||
import com.guo.learningprogresstracker.dto.PriorityDto;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.guo.learningprogresstracker.mapStruct.RequestConvert;
|
||||
import com.guo.learningprogresstracker.mapStruct.TaskConvert;
|
||||
import com.guo.learningprogresstracker.service.TasksService;
|
||||
import com.guo.learningprogresstracker.mapper.TasksMapper;
|
||||
import com.guo.learningprogresstracker.utils.CalculatedPriorityTool;
|
||||
import com.guo.learningprogresstracker.utils.GenerateNumTool;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -12,9 +20,27 @@ import org.springframework.stereotype.Service;
|
||||
* @createDate 2024-06-09 15:28:48
|
||||
*/
|
||||
@Service
|
||||
public class TasksServiceImpl extends ServiceImpl<TasksMapper, TasksEntity>
|
||||
@RequiredArgsConstructor
|
||||
public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
||||
implements TasksService{
|
||||
|
||||
|
||||
@Override
|
||||
public TaskInfoResponse showTask(String taskId) {
|
||||
|
||||
TaskInfoResponse result = new TaskInfoResponse();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addTask(TaskRequest taskRequest) {
|
||||
TaskEntity task= TaskConvert.MAPPER.taskRequestToTaskEntity(taskRequest);
|
||||
task.setTaskNum(GenerateNumTool.generateNum("TASK"));
|
||||
PriorityDto priorityDto = RequestConvert.MAPPER.taskRequestToPriorityDto(taskRequest);
|
||||
task.setCalculatedPriority(CalculatedPriorityTool.calculatedPriority(priorityDto));
|
||||
this.save(task);
|
||||
return task.getTaskNum();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.guo.learningprogresstracker.utils;
|
||||
|
||||
import com.guo.learningprogresstracker.dto.PriorityDto;
|
||||
|
||||
/**
|
||||
* 加权优先级计算工具
|
||||
*
|
||||
* @author guo
|
||||
*/
|
||||
public class CalculatedPriorityTool {
|
||||
|
||||
/**
|
||||
* 通过用户选择的5个选项,结合定义的权重计算任务的加权优先级。
|
||||
* 急迫性 (Urgency)
|
||||
* 急迫性代表任务的紧急程度。权重:0.35
|
||||
* <p>
|
||||
* 重要性 (Importance)
|
||||
* 重要性指示任务的重要程度。权重:0.25
|
||||
* <p>
|
||||
* 内容难度 (Content Difficulty)
|
||||
* 内容难度衡量任务内容的复杂性。权重:0.20
|
||||
* <p>
|
||||
* 未来价值 (Future Value)
|
||||
* 未来价值估计完成任务的长期价值。权重:0.10
|
||||
* <p>
|
||||
* 主观优先级 (Subjective Priority)
|
||||
* 主观优先级是用户对任务优先级的个人评估。权重:0.10
|
||||
*
|
||||
* @param priorityDto
|
||||
* @return
|
||||
*/
|
||||
public static Double calculatedPriority(PriorityDto priorityDto) {
|
||||
// 暂时写死权重,也许可以考虑让用户自行配置权重
|
||||
return (priorityDto.getUrgency() * 0.35) +
|
||||
(priorityDto.getImportance() * 0.25) +
|
||||
(priorityDto.getContentDifficulty() * 0.20) +
|
||||
(priorityDto.getFutureValue() * 0.10) +
|
||||
(priorityDto.getSubjectivePriority() * 0.10);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import java.util.Date;
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
public class GenerateNumTool {
|
||||
public static int getNextSequence() {
|
||||
private static int getNextSequence() {
|
||||
// 获取当前时间的毫秒级时间戳
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
@@ -27,7 +27,18 @@ public class GenerateNumTool {
|
||||
* @param separator
|
||||
* @return
|
||||
*/
|
||||
public String generateNum(String prefix, String separator) {
|
||||
public static String generateNum(String prefix, String separator) {
|
||||
String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
||||
|
||||
// 唯一的后缀
|
||||
int sequence = getNextSequence();
|
||||
|
||||
// 返回完整的 taskNum
|
||||
return prefix + separator + currentDate + separator + sequence;
|
||||
}
|
||||
|
||||
public static String generateNum(String prefix) {
|
||||
String separator = "-";
|
||||
String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
||||
|
||||
// 唯一的后缀
|
||||
|
||||
@@ -9,7 +9,7 @@ spring:
|
||||
password:
|
||||
flyway:
|
||||
# 是否启动 flyway
|
||||
enabled: true
|
||||
enabled: false
|
||||
# 文件编码
|
||||
encoding: UTF-8
|
||||
# SQL 脚本位置,默认位于 classpath 下的 db/migration 目录
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.guo.learningprogresstracker.mapper.TasksMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.guo.learningprogresstracker.entity.TasksEntity">
|
||||
<resultMap id="BaseResultMap" type="com.guo.learningprogresstracker.entity.TaskEntity">
|
||||
<id property="taskId" column="task_id" jdbcType="INTEGER"/>
|
||||
<result property="taskName" column="task_name" jdbcType="VARCHAR"/>
|
||||
<result property="materialUrl" column="material_url" jdbcType="VARCHAR"/>
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
|
||||
import com.guo.learningprogresstracker.entity.CommonResult;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@SpringBootTest
|
||||
class TaskControllerTest {
|
||||
|
||||
@Autowired
|
||||
private TaskController taskController;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
StpUtil.login("测试用户", "test_driver");
|
||||
}
|
||||
@Test
|
||||
void addTask() {
|
||||
TaskRequest taskRequest = mock(TaskRequest.class);
|
||||
// 设置学习任务的名称
|
||||
when(taskRequest.getTaskName()).thenReturn("测试任务名称");
|
||||
|
||||
// 设置学习材料的存储URL
|
||||
when(taskRequest.getMaterialUrl()).thenReturn("http://example.com/material");
|
||||
|
||||
// 设置用户设置的任务紧急性
|
||||
when(taskRequest.getUrgency()).thenReturn(5);
|
||||
|
||||
// 设置用户设置的任务重要性
|
||||
when(taskRequest.getImportance()).thenReturn(3);
|
||||
|
||||
// 设置任务的内容难度
|
||||
when(taskRequest.getContentDifficulty()).thenReturn(4);
|
||||
|
||||
// 设置任务的未来价值
|
||||
when(taskRequest.getFutureValue()).thenReturn(5);
|
||||
|
||||
// 设置用户对任务的主观优先级
|
||||
when(taskRequest.getSubjectivePriority()).thenReturn(2);
|
||||
CommonResult commonResult = taskController.addTask(taskRequest);
|
||||
|
||||
// 验证 addTask 是否被调用一次
|
||||
assertEquals(commonResult.getCode(), 200,"测试数据插入失败");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void showTask() {
|
||||
String taskId = mock(String.class);
|
||||
TaskInfoResponse mockData = mock(TaskInfoResponse.class);
|
||||
|
||||
CommonResult commonResult = taskController.showTask(taskId);
|
||||
assertEquals(commonResult.getCode(),200,"获取数据失败");
|
||||
assertNotNull(commonResult.getData(),"返回值中不存在数据");
|
||||
assertEquals(commonResult.getData(),mockData,"返回值携带数据不正确");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTask() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteTask() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTasks() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user