diff --git a/README.md b/README.md index 6dc219a..de83175 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,12 @@ ## 数据表规则: +> ID 没有特殊之指明则为 UUID ### 教育评价树 分区键: `Appraise` , 表内 `schoolId` 区分学校, `periodId` 区分学区 ### 教育评价项 > 学生每学期所有的评价项都在一个项中,按学校进行分区 -分区键: `AppraiseRecord-{学校id}` \ No newline at end of file +分区键: `AppraiseRecord-{学校id}` +Id: `学年 + semesterId` -> eg: 2022.uuid \ No newline at end of file diff --git a/src/main/java/cn/teammodel/controller/EvaluationController.java b/src/main/java/cn/teammodel/controller/AppraiseController.java similarity index 76% rename from src/main/java/cn/teammodel/controller/EvaluationController.java rename to src/main/java/cn/teammodel/controller/AppraiseController.java index 7a92f09..6f65228 100644 --- a/src/main/java/cn/teammodel/controller/EvaluationController.java +++ b/src/main/java/cn/teammodel/controller/AppraiseController.java @@ -1,10 +1,11 @@ package cn.teammodel.controller; import cn.teammodel.common.R; -import cn.teammodel.model.dto.DeleteNodeDto; -import cn.teammodel.model.dto.GetEvaluateTreeDto; -import cn.teammodel.model.dto.InsertNodeDto; -import cn.teammodel.model.dto.UpdateNodeDto; +import cn.teammodel.model.dto.Appraise.AppraiseVoteDto; +import cn.teammodel.model.dto.Appraise.DeleteNodeDto; +import cn.teammodel.model.dto.Appraise.GetEvaluateTreeDto; +import cn.teammodel.model.dto.Appraise.InsertNodeDto; +import cn.teammodel.model.dto.Appraise.UpdateNodeDto; import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.service.EvaluationService; import io.swagger.annotations.ApiOperation; @@ -22,7 +23,7 @@ import javax.validation.Valid; */ @RestController @RequestMapping("/appraise") -public class EvaluationController { +public class AppraiseController { @Resource private EvaluationService evaluationService; @@ -51,4 +52,13 @@ public class EvaluationController { Appraise appraise = evaluationService.deleteNode(deleteNodeDto); return R.success(appraise); } + + @PostMapping("vote") + @ApiOperation(value = "给某个学生评价(投票)") + public R vote(@Valid @RequestBody AppraiseVoteDto appraiseVoteDto) { + evaluationService.vote(appraiseVoteDto); + return R.success("评价成功"); + } + + } diff --git a/src/main/java/cn/teammodel/controller/HelloController.java b/src/main/java/cn/teammodel/controller/HelloController.java index 3e901f1..c47665c 100644 --- a/src/main/java/cn/teammodel/controller/HelloController.java +++ b/src/main/java/cn/teammodel/controller/HelloController.java @@ -1,7 +1,7 @@ package cn.teammodel.controller; import cn.teammodel.common.R; -import cn.teammodel.dao.EvaluationRepository; +import cn.teammodel.dao.AppraiseRepository; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.GetMapping; @@ -15,7 +15,7 @@ import javax.annotation.Resource; public class HelloController { @Resource - private EvaluationRepository evaluationRepository; + private AppraiseRepository appraiseRepository; @GetMapping("hello") @PreAuthorize("@ss.hasRole('admin')") diff --git a/src/main/java/cn/teammodel/dao/EvaluationRepository.java b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java similarity index 70% rename from src/main/java/cn/teammodel/dao/EvaluationRepository.java rename to src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java index 2fa4a4b..f5be2d4 100644 --- a/src/main/java/cn/teammodel/dao/EvaluationRepository.java +++ b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java @@ -1,7 +1,6 @@ package cn.teammodel.dao; import cn.teammodel.model.entity.appraise.Appraise; -import com.azure.cosmos.models.PartitionKey; import com.azure.spring.data.cosmos.repository.CosmosRepository; import org.springframework.stereotype.Repository; @@ -16,9 +15,6 @@ import org.springframework.stereotype.Repository; * List findByLastname(String lastname, Pageable pageable);
*/ @Repository -public interface EvaluationRepository extends CosmosRepository { - Appraise findBySchoolId(String schoolId, PartitionKey partitionKey); - Appraise findAppraiseBySchoolIdAndPeriodIdAndCode(String schoolId, String periodId, String code); - +public interface AppraiseRecordRepository extends CosmosRepository { } diff --git a/src/main/java/cn/teammodel/dao/AppraiseRepository.java b/src/main/java/cn/teammodel/dao/AppraiseRepository.java new file mode 100644 index 0000000..7bbf01d --- /dev/null +++ b/src/main/java/cn/teammodel/dao/AppraiseRepository.java @@ -0,0 +1,30 @@ +package cn.teammodel.dao; + +import cn.teammodel.model.entity.appraise.Appraise; +import cn.teammodel.model.entity.appraise.AppraiseTreeNode; +import com.azure.cosmos.models.PartitionKey; +import com.azure.spring.data.cosmos.repository.CosmosRepository; +import com.azure.spring.data.cosmos.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author winter + * @create 2023-11-20 14:39
+ * Page findByLastname(String lastname, Pageable pageable);
+ * Slice findByLastname(String lastname, Pageable pageable);
+ * Window findTop10ByLastname(String lastname, ScrollPosition position, Sort sort);
+ * List findByLastname(String lastname, Sort sort);
+ * List findByLastname(String lastname, Sort sort, Limit limit);
+ * List findByLastname(String lastname, Pageable pageable);
+ */ +@Repository +public interface AppraiseRepository extends CosmosRepository { + Appraise findBySchoolId(String schoolId, PartitionKey partitionKey); + Appraise findAppraiseBySchoolIdAndPeriodIdAndCode(String schoolId, String periodId, String code); + @Query("SELECT value n FROM School AS s join n in s.nodes where s.schoolId = @schoolId and s.periodId = @periodId and s.code = @code and n.id = @nodeId") + List findNodeById(@Param("schoolId") String schoolId, @Param("periodId") String periodId, @Param("code") String code, @Param("nodeId") String nodeId); + +} diff --git a/src/main/java/cn/teammodel/dao/SchoolRepository.java b/src/main/java/cn/teammodel/dao/SchoolRepository.java new file mode 100644 index 0000000..4062adb --- /dev/null +++ b/src/main/java/cn/teammodel/dao/SchoolRepository.java @@ -0,0 +1,15 @@ +package cn.teammodel.dao; + +import cn.teammodel.model.entity.school.School; +import com.azure.spring.data.cosmos.repository.CosmosRepository; +import org.springframework.stereotype.Repository; + +/** + * @author winter + * @create 2023-11-28 17:39 + */ +@Repository +public interface SchoolRepository extends CosmosRepository { + //@Query("select c.period.semesters from c where c.id = @id and c.code = @code") + //List findSemestersById(@Param("id") String id, @Param("code") String code); +} diff --git a/src/main/java/cn/teammodel/model/dto/Appraise/AppraiseVoteDto.java b/src/main/java/cn/teammodel/model/dto/Appraise/AppraiseVoteDto.java new file mode 100644 index 0000000..2ca0a7a --- /dev/null +++ b/src/main/java/cn/teammodel/model/dto/Appraise/AppraiseVoteDto.java @@ -0,0 +1,21 @@ +package cn.teammodel.model.dto.Appraise; + +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * @author winter + * @create 2023-11-28 16:16 + */ +@Data +public class AppraiseVoteDto { + @NotNull + private String studentId; + @NotNull // todo: semester 还是 period + private String semesterId; + @NotNull + private String appraiseId; + // 校区 id + private String periodId; +} diff --git a/src/main/java/cn/teammodel/model/dto/DeleteNodeDto.java b/src/main/java/cn/teammodel/model/dto/Appraise/DeleteNodeDto.java similarity index 85% rename from src/main/java/cn/teammodel/model/dto/DeleteNodeDto.java rename to src/main/java/cn/teammodel/model/dto/Appraise/DeleteNodeDto.java index 85de9a4..9a9b3b7 100644 --- a/src/main/java/cn/teammodel/model/dto/DeleteNodeDto.java +++ b/src/main/java/cn/teammodel/model/dto/Appraise/DeleteNodeDto.java @@ -1,4 +1,4 @@ -package cn.teammodel.model.dto; +package cn.teammodel.model.dto.Appraise; import lombok.Data; diff --git a/src/main/java/cn/teammodel/model/dto/GetEvaluateTreeDto.java b/src/main/java/cn/teammodel/model/dto/Appraise/GetEvaluateTreeDto.java similarity index 77% rename from src/main/java/cn/teammodel/model/dto/GetEvaluateTreeDto.java rename to src/main/java/cn/teammodel/model/dto/Appraise/GetEvaluateTreeDto.java index 98855e2..d29c95b 100644 --- a/src/main/java/cn/teammodel/model/dto/GetEvaluateTreeDto.java +++ b/src/main/java/cn/teammodel/model/dto/Appraise/GetEvaluateTreeDto.java @@ -1,4 +1,4 @@ -package cn.teammodel.model.dto; +package cn.teammodel.model.dto.Appraise; import lombok.Data; diff --git a/src/main/java/cn/teammodel/model/dto/InsertNodeDto.java b/src/main/java/cn/teammodel/model/dto/Appraise/InsertNodeDto.java similarity index 90% rename from src/main/java/cn/teammodel/model/dto/InsertNodeDto.java rename to src/main/java/cn/teammodel/model/dto/Appraise/InsertNodeDto.java index 16fe3b5..a03561f 100644 --- a/src/main/java/cn/teammodel/model/dto/InsertNodeDto.java +++ b/src/main/java/cn/teammodel/model/dto/Appraise/InsertNodeDto.java @@ -1,4 +1,4 @@ -package cn.teammodel.model.dto; +package cn.teammodel.model.dto.Appraise; import io.swagger.annotations.ApiModelProperty; import lombok.Data; diff --git a/src/main/java/cn/teammodel/model/dto/UpdateNodeDto.java b/src/main/java/cn/teammodel/model/dto/Appraise/UpdateNodeDto.java similarity index 86% rename from src/main/java/cn/teammodel/model/dto/UpdateNodeDto.java rename to src/main/java/cn/teammodel/model/dto/Appraise/UpdateNodeDto.java index 2b2d2e2..66f450e 100644 --- a/src/main/java/cn/teammodel/model/dto/UpdateNodeDto.java +++ b/src/main/java/cn/teammodel/model/dto/Appraise/UpdateNodeDto.java @@ -1,4 +1,4 @@ -package cn.teammodel.model.dto; +package cn.teammodel.model.dto.Appraise; import lombok.Data; diff --git a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecord.java b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecord.java index ff9cf9b..eaf9257 100644 --- a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecord.java +++ b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecord.java @@ -9,7 +9,8 @@ import lombok.EqualsAndHashCode; import java.util.List; /** - * 一个学生在一个学年(学校+学年 = 分区键)的所有评价记录 + * 一个学生在一个学年(学校+学年 = 分区键)的所有评价记录
+ * 注意: Id 为 学年 + semesterId * @author winter * @create 2023-11-27 11:02 */ @@ -23,6 +24,14 @@ public class AppraiseRecord extends BaseItem { */ private String periodId; private String studentId; + /** + * 表扬次数 + */ + private Integer praiseCount; + /** + * 学生得分 + */ + private Integer score; private List nodes; } diff --git a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java index d852db4..ae9fb02 100644 --- a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java +++ b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java @@ -1,8 +1,11 @@ package cn.teammodel.model.entity.appraise; +import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; +import java.time.LocalDateTime; + /** * 评价项 * @author winter @@ -14,4 +17,8 @@ import lombok.Data; public class AppraiseRecordItem { private String id; private String appraiseNodeId; + String creator; + String creatorId; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; } diff --git a/src/main/java/cn/teammodel/model/entity/school/School.java b/src/main/java/cn/teammodel/model/entity/school/School.java new file mode 100644 index 0000000..9bb3269 --- /dev/null +++ b/src/main/java/cn/teammodel/model/entity/school/School.java @@ -0,0 +1,94 @@ +package cn.teammodel.model.entity.school; + +import cn.teammodel.model.entity.BaseItem; +import com.azure.spring.data.cosmos.core.mapping.Container; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +@EqualsAndHashCode(callSuper = true) +@Container(containerName = "School") +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class School extends BaseItem { + /** + * 学校名字 + */ + private String name; + private String schoolCode; + private String region; + private String province; + private String city; + private String dist; + private String areaId; + private Integer size; + private Integer tsize; + private String address; + private String picture; + private TimeZone timeZone; + private Integer type; + private String standard; + private Integer hpappraise; + private Integer scale; + private Edition edition; + private long createTime; + private boolean isinit; + private boolean openLessonRecord; + //private Module[] modules; + private String pk; + private List period; + private List campuses; + + @Data + public static class Period { + private List majors; + private List grades; + private List subjects; + private List semesters; + private String name; + } + + @Data + public static class Major { + private String id; + private String name; + } + + @Data + public static class Subject { + private String id; + private String name; + private Integer type; + private String bindId; + } + + + @Data + public static class Semester { + private String name; + private Integer start; + private Integer month; + private Integer day; + private String id; + } + @Data + public static class Campus { + private String name; + private String id; + + } + @Data + public static class TimeZone { + private String label; + private String value; + } + + @Data + public static class Edition { + private Integer current; + private Integer record; + private String scaleVersion; + } +} diff --git a/src/main/java/cn/teammodel/service/EvaluationService.java b/src/main/java/cn/teammodel/service/EvaluationService.java index f74472c..37650f4 100644 --- a/src/main/java/cn/teammodel/service/EvaluationService.java +++ b/src/main/java/cn/teammodel/service/EvaluationService.java @@ -1,9 +1,6 @@ package cn.teammodel.service; -import cn.teammodel.model.dto.DeleteNodeDto; -import cn.teammodel.model.dto.GetEvaluateTreeDto; -import cn.teammodel.model.dto.InsertNodeDto; -import cn.teammodel.model.dto.UpdateNodeDto; +import cn.teammodel.model.dto.Appraise.*; import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.AppraiseTreeNode; @@ -45,4 +42,9 @@ public interface EvaluationService { * 删除评价树节点,同时删除其子节点 */ Appraise deleteNode(DeleteNodeDto deleteNodeDto); + + /** + * 给学生评价 + */ + void vote(AppraiseVoteDto appraiseVoteDto); } diff --git a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java index d30bf37..5105614 100644 --- a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java @@ -4,11 +4,8 @@ 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.dao.EvaluationRepository; -import cn.teammodel.model.dto.DeleteNodeDto; -import cn.teammodel.model.dto.GetEvaluateTreeDto; -import cn.teammodel.model.dto.InsertNodeDto; -import cn.teammodel.model.dto.UpdateNodeDto; +import cn.teammodel.dao.AppraiseRepository; +import cn.teammodel.model.dto.Appraise.*; import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.User; @@ -34,7 +31,7 @@ public class EvaluationServiceImpl implements EvaluationService { @Resource CosmosTemplate cosmosTemplate; @Resource - private EvaluationRepository evaluationRepository; + private AppraiseRepository appraiseRepository; /** * 通用的获取 evaluation 的方法: 判断参数,判断数据是否为空
@@ -47,7 +44,7 @@ public class EvaluationServiceImpl implements EvaluationService { String schoolId = loginUser.getSchoolId(); // 拿到要新增节点的原始数据 - Appraise appraise = evaluationRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE); + Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE); if (appraise == null) { throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "学校评价数据不存在"); } @@ -124,7 +121,7 @@ public class EvaluationServiceImpl implements EvaluationService { newNode.setCreateTime(LocalDateTime.now()); originNodes.add(newNode); - return buildTree(evaluationRepository.save(appraise)); + return buildTree(appraiseRepository.save(appraise)); } @Override @@ -145,7 +142,7 @@ public class EvaluationServiceImpl implements EvaluationService { updateNode.setPraise(updateNodeDto.isPraise()); // todo: 为新节点赋值必须参数 (id, creator), 可不可以添加默认值 order ? - return buildTree(evaluationRepository.save(appraise)); + return buildTree(appraiseRepository.save(appraise)); } @Override @@ -166,7 +163,24 @@ public class EvaluationServiceImpl implements EvaluationService { } nodes.removeAll(nodesToDelete); - return buildTree(evaluationRepository.save(appraise)); + return buildTree(appraiseRepository.save(appraise)); + } + + @Override + public void vote(AppraiseVoteDto appraiseVoteDto) { + String studentId = appraiseVoteDto.getStudentId(); + String appraiseId = appraiseVoteDto.getAppraiseId(); + String periodId = appraiseVoteDto.getPeriodId(); + periodId = StringUtils.isEmpty(periodId) ? "default" : periodId; + + User loginUser = SecurityUtil.getLoginUser(); + List nodes = appraiseRepository.findNodeById(loginUser.getSchoolId(), periodId, PK.PK_APPRAISE, appraiseId); + if (ObjectUtils.isEmpty(nodes) || nodes.size() > 1) { + throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "找不到该评价项"); + } + AppraiseTreeNode node = nodes.get(0); + + // 组装 AppraiseRecord } /** diff --git a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java index 565b174..c4df836 100644 --- a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java +++ b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java @@ -1,6 +1,7 @@ package cn.teammodel; -import cn.teammodel.dao.EvaluationRepository; +import cn.teammodel.dao.AppraiseRepository; +import cn.teammodel.dao.SchoolRepository; import cn.teammodel.dao.StudentRepository; import cn.teammodel.manager.DingAlertNotifier; import cn.teammodel.model.entity.appraise.Appraise; @@ -29,7 +30,9 @@ class TeamModelExtensionApplicationTests { @Autowired StudentRepository studentRepository; @Autowired - private EvaluationRepository evaluationRepository; + SchoolRepository schoolRepository; + @Autowired + private AppraiseRepository appraiseRepository; @Test void contextLoads() { @@ -74,17 +77,21 @@ class TeamModelExtensionApplicationTests { @Test public void testSelect() { - Appraise saved = evaluationRepository.findBySchoolId("hbcn", new PartitionKey("evaluation")); - EvaluationService service = new EvaluationServiceImpl(); + //Appraise saved = appraiseRepository.findBySchoolId("hbcn", new PartitionKey("evaluation")); + //EvaluationService service = new EvaluationServiceImpl(); //System.out.println(JSONUtil.parse(service.buildTree(saved.getNodes())).toStringPretty()); + //List nodeById = appraiseRepository.findNodeById("habook", "default", "Appraise", "43e23f03-288c-4012-b5f3-4d5c022739a2"); + //System.out.println(nodeById); + + System.out.println(schoolRepository.findSemestersById("hbcn", "Base")); } @Test public void testUpdate() { //EvaluationTree saved = evaluationTreeRepository.findBySchoolId("hbcn", new PartitionKey("evaluation")); - Appraise saved = evaluationRepository.findBySchoolId("hbcn", new PartitionKey("evaluation")); + Appraise saved = appraiseRepository.findBySchoolId("hbcn", new PartitionKey("evaluation")); EvaluationService service = new EvaluationServiceImpl(); //System.out.println(JSONUtil.parse(service.buildTree(saved.getNodes())).toStringPretty()); - evaluationRepository.save(saved); + appraiseRepository.save(saved); } @Test @@ -99,4 +106,6 @@ class TeamModelExtensionApplicationTests { cosmosTemplate.upsert(appraise); } + + }