[xingyu.guo] feat: 为【添加新任务】增加任务名是否重复的校验
This commit is contained in:
@@ -41,8 +41,7 @@ public class TaskController {
|
||||
|
||||
@PostMapping
|
||||
@Operation(summary = "添加新任务")
|
||||
public CommonResult addTask(@RequestBody @Validated({Ops.CreateG.class}) TaskRequest taskRequest) {
|
||||
System.out.println("Token: " + StpUtil.getTokenValue());
|
||||
public CommonResult addTask(@RequestBody @Validated({Ops.CreateG.class}) TaskRequest taskRequest) throws ErrorParameterException {
|
||||
return CommonResult.success(tasksService.addTask(taskRequest));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.guo.learningprogresstracker.dto.TaskInfo;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||
|
||||
import java.rmi.ServerException;
|
||||
|
||||
@@ -18,7 +19,7 @@ public interface TasksService extends IService<TaskEntity> {
|
||||
|
||||
Page<TaskInfo> taskList(Integer pageNum, Integer pageSize);
|
||||
|
||||
String addTask(TaskRequest taskRequest);
|
||||
String addTask(TaskRequest taskRequest) throws ErrorParameterException;
|
||||
|
||||
TaskInfoResponse getTask(String taskId);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
|
||||
import com.guo.learningprogresstracker.dto.response.TasksListInfoResponse;
|
||||
import com.guo.learningprogresstracker.entity.TaskEntity;
|
||||
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||
import com.guo.learningprogresstracker.mapStruct.RequestConvert;
|
||||
import com.guo.learningprogresstracker.mapStruct.TaskConvert;
|
||||
import com.guo.learningprogresstracker.mapStruct.TaskConvertImpl;
|
||||
@@ -19,6 +20,7 @@ import com.guo.learningprogresstracker.utils.CalculatedPriorityTool;
|
||||
import com.guo.learningprogresstracker.utils.GenerateNumTool;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.ibatis.exceptions.TooManyResultsException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.rmi.ServerException;
|
||||
@@ -48,8 +50,14 @@ public class TasksServiceImpl extends ServiceImpl<TasksMapper, TaskEntity>
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addTask(TaskRequest taskRequest) {
|
||||
public String addTask(TaskRequest taskRequest) throws ErrorParameterException {
|
||||
TaskEntity task= TaskConvert.MAPPER.taskRequestToTaskEntity(taskRequest);
|
||||
|
||||
if (this.exists(Wrappers.lambdaQuery(TaskEntity.class)
|
||||
.eq(TaskEntity::getTaskName, task.getTaskName()))) {
|
||||
throw new ErrorParameterException(String.format("任务名[%s]重复", task.getTaskName()));
|
||||
}
|
||||
|
||||
task.setTaskNum(GenerateNumTool.generateNum("TASK"));
|
||||
PriorityDto priorityDto = RequestConvert.MAPPER.taskRequestToPriorityDto(taskRequest);
|
||||
task.setCalculatedPriority(CalculatedPriorityTool.calculatedPriority(priorityDto));
|
||||
|
||||
Reference in New Issue
Block a user