From 327e399d5a8341ba6ec4b41c18a1088d2e0d7af3 Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Mon, 8 Jan 2024 14:44:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=86=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E5=90=8D=E7=A7=B0=E6=A0=87=E8=AF=86"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AdminAppraiseController.java | 2 + .../admin/controller/IndexController.java | 2 + .../controller/frontend/AiController.java | 2 + .../frontend/AppraiseController.java | 2 + .../controller/frontend/DutyController.java | 23 ++++++++-- .../controller/frontend/HelloController.java | 2 + .../model/dto/weekDuty/InsertDutyNodeDto.java | 4 +- .../model/dto/weekDuty/InsertSpotDto.java | 18 ++++++++ .../model/entity/weekDuty/WeekDuty.java | 2 + .../cn/teammodel/service/DutyService.java | 10 +++-- .../service/impl/DutyServiceImpl.java | 42 ++++++++++++++++--- 11 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 src/main/java/cn/teammodel/model/dto/weekDuty/InsertSpotDto.java diff --git a/src/main/java/cn/teammodel/controller/admin/controller/AdminAppraiseController.java b/src/main/java/cn/teammodel/controller/admin/controller/AdminAppraiseController.java index f3373c8..6392b3d 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/AdminAppraiseController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/AdminAppraiseController.java @@ -4,6 +4,7 @@ import cn.teammodel.common.R; import cn.teammodel.controller.admin.service.AdminAppraiseService; import cn.teammodel.model.dto.admin.UpdateAchievementRuleDto; import cn.teammodel.model.entity.appraise.AchievementRule; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -17,6 +18,7 @@ import java.util.List; */ @RestController @RequestMapping("admin/appraise") +@Api(tags = "管理员端-学生评价管理") public class AdminAppraiseController { @Resource private AdminAppraiseService adminAppraiseService; diff --git a/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java b/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java index 7db0ff2..a35bc06 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java @@ -5,6 +5,7 @@ import cn.teammodel.controller.admin.service.AdminAppraiseService; import cn.teammodel.model.dto.admin.TimeRangeDto; import cn.teammodel.model.vo.admin.*; import cn.teammodel.model.vo.appraise.RecordVo; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -19,6 +20,7 @@ import java.util.List; */ @RestController @RequestMapping("admin/index") +@Api(tags = "管理员端-首页数据") public class IndexController { @Resource private AdminAppraiseService adminAppraiseService; diff --git a/src/main/java/cn/teammodel/controller/frontend/AiController.java b/src/main/java/cn/teammodel/controller/frontend/AiController.java index 427a5ba..f3879bd 100644 --- a/src/main/java/cn/teammodel/controller/frontend/AiController.java +++ b/src/main/java/cn/teammodel/controller/frontend/AiController.java @@ -7,6 +7,7 @@ import cn.teammodel.model.dto.ai.UpdateSessionDto; import cn.teammodel.model.entity.ai.ChatSession; import cn.teammodel.service.ChatMessageService; import cn.teammodel.service.ChatSessionService; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; @@ -19,6 +20,7 @@ import java.util.concurrent.CompletableFuture; @RestController @RequestMapping("/ai") +@Api(tags = "AI 能力") public class AiController { @Resource private ChatSessionService chatSessionService; diff --git a/src/main/java/cn/teammodel/controller/frontend/AppraiseController.java b/src/main/java/cn/teammodel/controller/frontend/AppraiseController.java index 462f7a0..c1699cf 100644 --- a/src/main/java/cn/teammodel/controller/frontend/AppraiseController.java +++ b/src/main/java/cn/teammodel/controller/frontend/AppraiseController.java @@ -7,6 +7,7 @@ import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.vo.appraise.AppraiseRecordVo; import cn.teammodel.model.vo.appraise.StudentReportVo; import cn.teammodel.service.EvaluationService; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -23,6 +24,7 @@ import java.util.List; */ @RestController @RequestMapping("/appraise") +@Api(tags = "学生评价") public class AppraiseController { @Resource private EvaluationService evaluationService; diff --git a/src/main/java/cn/teammodel/controller/frontend/DutyController.java b/src/main/java/cn/teammodel/controller/frontend/DutyController.java index 716bcfe..1e9e0bd 100644 --- a/src/main/java/cn/teammodel/controller/frontend/DutyController.java +++ b/src/main/java/cn/teammodel/controller/frontend/DutyController.java @@ -1,17 +1,17 @@ package cn.teammodel.controller.frontend; +import cn.teammodel.common.IdRequest; import cn.teammodel.common.R; -import cn.teammodel.model.dto.weekDuty.DeleteDutyNodeDto; -import cn.teammodel.model.dto.weekDuty.DutyVoteDto; -import cn.teammodel.model.dto.weekDuty.InsertDutyNodeDto; -import cn.teammodel.model.dto.weekDuty.UpdateDutyNodeDto; +import cn.teammodel.model.dto.weekDuty.*; import cn.teammodel.model.entity.weekDuty.WeekDuty; import cn.teammodel.service.DutyService; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.List; /** * @author winter @@ -19,6 +19,7 @@ import javax.validation.Valid; */ @RestController @RequestMapping("/duty") +@Api(tags = "值周巡检") public class DutyController { @Resource private DutyService dutyService; @@ -58,6 +59,20 @@ public class DutyController { return R.success("评价成功"); } + @PostMapping("/insertSpot") + @ApiOperation("插入值周评价地点") + public R> insertSpot(@RequestBody @Valid InsertSpotDto insertSpotDto) { + List spots = dutyService.insertSpot(insertSpotDto); + return R.success(spots); + } + + @PostMapping("/deleteSpot") + @ApiOperation("删除值周评价地点") + public R> deleteSpot(@RequestBody @Valid IdRequest idRequest) { + List spots = dutyService.deleteSpot(idRequest.getId()); + return R.success(spots); + } + diff --git a/src/main/java/cn/teammodel/controller/frontend/HelloController.java b/src/main/java/cn/teammodel/controller/frontend/HelloController.java index b839a16..2690529 100644 --- a/src/main/java/cn/teammodel/controller/frontend/HelloController.java +++ b/src/main/java/cn/teammodel/controller/frontend/HelloController.java @@ -2,6 +2,7 @@ package cn.teammodel.controller.frontend; import cn.teammodel.common.R; import cn.teammodel.repository.AppraiseRepository; +import io.swagger.annotations.Api; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.GetMapping; @@ -12,6 +13,7 @@ import javax.annotation.Resource; @RestController @RequestMapping("/") +@Api(tags = "鉴权测试") public class HelloController { @Resource diff --git a/src/main/java/cn/teammodel/model/dto/weekDuty/InsertDutyNodeDto.java b/src/main/java/cn/teammodel/model/dto/weekDuty/InsertDutyNodeDto.java index 760bc4a..fc07099 100644 --- a/src/main/java/cn/teammodel/model/dto/weekDuty/InsertDutyNodeDto.java +++ b/src/main/java/cn/teammodel/model/dto/weekDuty/InsertDutyNodeDto.java @@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.PositiveOrZero; /** * @author winter @@ -19,6 +20,7 @@ public class InsertDutyNodeDto { String name; String desc; Integer order = 0; + @PositiveOrZero(message = "score 不能为负数") Integer score = 0; -// Boolean positive = true; + Boolean positive = true; } diff --git a/src/main/java/cn/teammodel/model/dto/weekDuty/InsertSpotDto.java b/src/main/java/cn/teammodel/model/dto/weekDuty/InsertSpotDto.java new file mode 100644 index 0000000..7517b18 --- /dev/null +++ b/src/main/java/cn/teammodel/model/dto/weekDuty/InsertSpotDto.java @@ -0,0 +1,18 @@ +package cn.teammodel.model.dto.weekDuty; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @author winter + * @create 2024-01-03 10:45 + */ + +@Data +public class InsertSpotDto { + @ApiModelProperty(value = "地点名称", required = true) + @NotBlank(message = "name 不能为空") + private String name; +} diff --git a/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDuty.java b/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDuty.java index 088029c..af40b5f 100644 --- a/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDuty.java +++ b/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDuty.java @@ -3,6 +3,7 @@ package cn.teammodel.model.entity.weekDuty; import cn.teammodel.model.entity.BaseItem; import com.azure.spring.data.cosmos.core.mapping.Container; import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -49,6 +50,7 @@ public class WeekDuty extends BaseItem { private Long createTime; } @Data + @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) public static class DutySpot { private String id; diff --git a/src/main/java/cn/teammodel/service/DutyService.java b/src/main/java/cn/teammodel/service/DutyService.java index cf89937..57fb084 100644 --- a/src/main/java/cn/teammodel/service/DutyService.java +++ b/src/main/java/cn/teammodel/service/DutyService.java @@ -1,11 +1,10 @@ package cn.teammodel.service; -import cn.teammodel.model.dto.weekDuty.DeleteDutyNodeDto; -import cn.teammodel.model.dto.weekDuty.DutyVoteDto; -import cn.teammodel.model.dto.weekDuty.InsertDutyNodeDto; -import cn.teammodel.model.dto.weekDuty.UpdateDutyNodeDto; +import cn.teammodel.model.dto.weekDuty.*; import cn.teammodel.model.entity.weekDuty.WeekDuty; +import java.util.List; + /** * @author winter * @create 2024-01-03 10:07 @@ -21,4 +20,7 @@ public interface DutyService { void vote(DutyVoteDto dutyVoteDto); + List insertSpot(InsertSpotDto insertSpotDto); + + List deleteSpot(String id); } diff --git a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java index 3c57f6d..9a86007 100644 --- a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java @@ -4,10 +4,7 @@ import cn.hutool.core.lang.UUID; import cn.teammodel.common.ErrorCode; import cn.teammodel.common.PK; import cn.teammodel.config.exception.ServiceException; -import cn.teammodel.model.dto.weekDuty.DeleteDutyNodeDto; -import cn.teammodel.model.dto.weekDuty.DutyVoteDto; -import cn.teammodel.model.dto.weekDuty.InsertDutyNodeDto; -import cn.teammodel.model.dto.weekDuty.UpdateDutyNodeDto; +import cn.teammodel.model.dto.weekDuty.*; import cn.teammodel.model.entity.User; import cn.teammodel.model.entity.school.ClassInfo; import cn.teammodel.model.entity.school.School; @@ -76,7 +73,8 @@ public class DutyServiceImpl implements DutyService { String pid = insertDutyNodeDto.getPid(); String name = insertDutyNodeDto.getName(); Integer order = insertDutyNodeDto.getOrder(); - Integer score = insertDutyNodeDto.getScore(); + Boolean positive = insertDutyNodeDto.getPositive(); + Integer score = positive ? insertDutyNodeDto.getScore() : -insertDutyNodeDto.getScore(); String desc = insertDutyNodeDto.getDesc(); User user = SecurityUtil.getLoginUser(); @@ -115,7 +113,7 @@ public class DutyServiceImpl implements DutyService { newNode.setDesc(desc); newNode.setPath(path); newNode.setScore(score); - newNode.setPositive(score >= 0); + newNode.setPositive(positive); } } @@ -273,6 +271,38 @@ public class DutyServiceImpl implements DutyService { } } + @Override + public List insertSpot(InsertSpotDto insertSpotDto) { + String schoolId = SecurityUtil.getLoginUser().getSchoolId(); + WeekDuty duty = dutyRepository.findBySchoolIdAndCode(schoolId, PK.WEEK_DUTY); + if (duty == null) { + throw new ServiceException("值周树不存在"); + } + String name = insertSpotDto.getName(); + CosmosPatchOperations operations = CosmosPatchOperations.create().add("/spots/-", new WeekDuty.DutySpot(UUID.randomUUID().toString(), name)); + duty = dutyRepository.save( + duty.getId(), + PK.of(PK.WEEK_DUTY), + WeekDuty.class, + operations + ); + return duty.getSpots(); + } + + @Override + public List deleteSpot(String id) { + String schoolId = SecurityUtil.getLoginUser().getSchoolId(); + WeekDuty duty = dutyRepository.findBySchoolIdAndCode(schoolId, PK.WEEK_DUTY); + if (duty == null) { + throw new ServiceException("值周树不存在"); + } + List spots = duty.getSpots(); + WeekDuty.DutySpot spot = spots.stream().filter(x -> id.equals(x.getId())).findFirst().orElseThrow(() -> new ServiceException("值周评价地点不存在")); + spots.remove(spot); + duty = dutyRepository.save(duty); + return duty.getSpots(); + } + /** * 刷新值周树和 spots 的 id */