From c54edf3cfec6fb47091976b2fe65ab8a32e7fac8 Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Tue, 5 Dec 2023 10:24:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9A=82=E6=97=B6=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=20Student=20=E5=BA=8F=E5=88=97=E5=8C=96?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++++- .../java/cn/teammodel/common/ErrorCode.java | 2 +- .../exception/GlobalExceptionHandler.java | 3 ++- .../controller/AppraiseController.java | 6 +++--- .../dao/AppraiseRecordRepository.java | 6 +++--- .../cn/teammodel/dao/StudentRepository.java | 7 +++++++ .../model/dto/Appraise/RecallVoteDto.java | 4 ++-- .../model/entity/appraise/AppraiseRecord.java | 1 + .../teammodel/model/entity/school/Student.java | 18 ++++++++++-------- .../model/vo/appraise/AppraiseRecordVo.java | 18 ++++++++++++++++++ .../teammodel/service/EvaluationService.java | 4 ++-- .../service/impl/EvaluationServiceImpl.java | 16 +++++++++------- src/main/resources/application.yml | 2 ++ .../TeamModelExtensionApplicationTests.java | 11 ++++++++++- 14 files changed, 74 insertions(+), 29 deletions(-) create mode 100644 src/main/java/cn/teammodel/model/vo/appraise/AppraiseRecordVo.java diff --git a/README.md b/README.md index de83175..52a6af8 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@ ### 教育评价项 > 学生每学期所有的评价项都在一个项中,按学校进行分区 +> +> 注意: 如果学生中途换班,也就是 classId 发生变动,那么会给这个学生在本学期新开一个文档,也就是说一个学生在一个学期的文档可能不止一个(小概率) +> 分区键: `AppraiseRecord-{学校id}` -Id: `学年 + semesterId` -> eg: 2022.uuid \ No newline at end of file +academicYearId: `学年 + semesterId` -> eg: 2022.uuid \ No newline at end of file diff --git a/src/main/java/cn/teammodel/common/ErrorCode.java b/src/main/java/cn/teammodel/common/ErrorCode.java index 744e048..a7c9eb8 100644 --- a/src/main/java/cn/teammodel/common/ErrorCode.java +++ b/src/main/java/cn/teammodel/common/ErrorCode.java @@ -2,7 +2,7 @@ package cn.teammodel.common; public enum ErrorCode { - SUCCESS(0, "ok"), + SUCCESS(200, "ok"), PARAMS_ERROR(40000, "请求参数错误"), NOT_LOGIN_ERROR(40100, "未登录"), NO_AUTH_ERROR(40101, "无权限"), diff --git a/src/main/java/cn/teammodel/config/exception/GlobalExceptionHandler.java b/src/main/java/cn/teammodel/config/exception/GlobalExceptionHandler.java index a3ca68d..46c72d0 100644 --- a/src/main/java/cn/teammodel/config/exception/GlobalExceptionHandler.java +++ b/src/main/java/cn/teammodel/config/exception/GlobalExceptionHandler.java @@ -1,5 +1,6 @@ package cn.teammodel.config.exception; +import cn.teammodel.common.ErrorCode; import cn.teammodel.common.R; import cn.teammodel.manager.NotificationService; import lombok.extern.slf4j.Slf4j; @@ -69,7 +70,7 @@ public class GlobalExceptionHandler { String requestURI = request.getRequestURI(); log.error("请求地址'{}',发生未知异常.", requestURI, e); notificationService.send("RuntimeException 告警: " + e.getMessage()); - return R.error(e.getMessage()); + return R.error(ErrorCode.SYSTEM_ERROR); } /** diff --git a/src/main/java/cn/teammodel/controller/AppraiseController.java b/src/main/java/cn/teammodel/controller/AppraiseController.java index a1d90e7..310ae12 100644 --- a/src/main/java/cn/teammodel/controller/AppraiseController.java +++ b/src/main/java/cn/teammodel/controller/AppraiseController.java @@ -3,7 +3,7 @@ package cn.teammodel.controller; import cn.teammodel.common.R; import cn.teammodel.model.dto.Appraise.*; import cn.teammodel.model.entity.appraise.Appraise; -import cn.teammodel.model.entity.appraise.AppraiseRecordItem; +import cn.teammodel.model.vo.appraise.AppraiseRecordVo; import cn.teammodel.service.EvaluationService; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.PostMapping; @@ -66,8 +66,8 @@ public class AppraiseController { @PostMapping("findVoteRecord") @ApiOperation(value = "多条件查询当前登录老师的学生评价(投票)") - public R> findMyVoteRecord(@Valid @RequestBody FindVoteRecordDto findVoteRecordDto) { - List res = evaluationService.findVoteRecord(findVoteRecordDto); + public R> findMyVoteRecord(@Valid @RequestBody FindVoteRecordDto findVoteRecordDto) { + List res = evaluationService.findVoteRecord(findVoteRecordDto); return R.success(res); } diff --git a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java index d3ea54d..cec10b8 100644 --- a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java +++ b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java @@ -1,7 +1,7 @@ package cn.teammodel.dao; import cn.teammodel.model.entity.appraise.AppraiseRecord; -import cn.teammodel.model.entity.appraise.AppraiseRecordItem; +import cn.teammodel.model.vo.appraise.AppraiseRecordVo; import com.azure.spring.data.cosmos.repository.CosmosRepository; import com.azure.spring.data.cosmos.repository.Query; import org.springframework.stereotype.Repository; @@ -31,14 +31,14 @@ public interface AppraiseRecordRepository extends CosmosRepository searchNodesByCondition(String targetId, String targetType, String classId, String creatorId, String academicYearId, String code); + List searchNodesByCondition(String targetId, String targetType, String classId, String creatorId, String academicYearId, String code); } diff --git a/src/main/java/cn/teammodel/dao/StudentRepository.java b/src/main/java/cn/teammodel/dao/StudentRepository.java index 7d03de1..ee3ce64 100644 --- a/src/main/java/cn/teammodel/dao/StudentRepository.java +++ b/src/main/java/cn/teammodel/dao/StudentRepository.java @@ -2,9 +2,16 @@ package cn.teammodel.dao; import cn.teammodel.model.entity.school.Student; import com.azure.spring.data.cosmos.repository.CosmosRepository; +import com.azure.spring.data.cosmos.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface StudentRepository extends CosmosRepository { + Student findStudentByIdAndCode(String id, String code); + + @Query("select c.pk, c.code, c.id, c.name, c.gender, c.schoolId, c.periodId, c.year, c.createTime, c.picture, c.mail, c.mobile, c.country, c.classId, c.no, c.groupId, c.groupName, c.guardians, c.irs, c.salt from Student as c where c.id = @id and c.code = @code") + List findByIdAndCode(String id, String code); } \ No newline at end of file diff --git a/src/main/java/cn/teammodel/model/dto/Appraise/RecallVoteDto.java b/src/main/java/cn/teammodel/model/dto/Appraise/RecallVoteDto.java index 2b5cf9d..af39189 100644 --- a/src/main/java/cn/teammodel/model/dto/Appraise/RecallVoteDto.java +++ b/src/main/java/cn/teammodel/model/dto/Appraise/RecallVoteDto.java @@ -12,9 +12,9 @@ import javax.validation.constraints.NotNull; @Data public class RecallVoteDto { @NotNull - @ApiModelProperty("学生评价记录的文档id") + @ApiModelProperty(value = "学生评价记录的文档id", required = true) String recordId; @NotNull - @ApiModelProperty("学生评价记录的具体节点id") + @ApiModelProperty(value = "学生评价记录的具体节点id", required = true) String nodeId; } 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 95e8a77..25ba634 100644 --- a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecord.java +++ b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecord.java @@ -44,6 +44,7 @@ public class AppraiseRecord extends BaseItem { * 学生/class 头像 */ private String avatar; + private String gender; /** * 表扬次数 */ diff --git a/src/main/java/cn/teammodel/model/entity/school/Student.java b/src/main/java/cn/teammodel/model/entity/school/Student.java index 1ce7c6a..69388e2 100644 --- a/src/main/java/cn/teammodel/model/entity/school/Student.java +++ b/src/main/java/cn/teammodel/model/entity/school/Student.java @@ -2,6 +2,7 @@ package cn.teammodel.model.entity.school; import com.azure.spring.data.cosmos.core.mapping.Container; import com.azure.spring.data.cosmos.core.mapping.PartitionKey; +import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; import org.springframework.data.annotation.Id; @@ -10,6 +11,7 @@ import java.util.List; @Data @Container(containerName = "Student") +@JsonInclude(JsonInclude.Include.NON_NULL) public class Student { @Id private String id; @@ -32,16 +34,16 @@ public class Student { private String periodId; private String gender; private Integer graduate; - private List loginInfos; + private List loginInfos; private Long createTime; - private List guardians; + //private List guardians; private String pk; - private Integer ttl; - private String _rid; - private String _self; - private String _etag; - private String _attachments; - private Integer _ts; + @Data + public static class LoginInfo { + private Long time; + private String ip; + private Long expire; + } } diff --git a/src/main/java/cn/teammodel/model/vo/appraise/AppraiseRecordVo.java b/src/main/java/cn/teammodel/model/vo/appraise/AppraiseRecordVo.java new file mode 100644 index 0000000..e33594f --- /dev/null +++ b/src/main/java/cn/teammodel/model/vo/appraise/AppraiseRecordVo.java @@ -0,0 +1,18 @@ +package cn.teammodel.model.vo.appraise; + +import cn.teammodel.model.entity.appraise.AppraiseRecordItem; +import lombok.Data; + +/** + * @author winter + * @create 2023-12-04 15:26 + */ +@Data +public class AppraiseRecordVo { + private String recordId; + private String name; + private String avatar; + private String targetId; + private String targetType; + private AppraiseRecordItem info; +} diff --git a/src/main/java/cn/teammodel/service/EvaluationService.java b/src/main/java/cn/teammodel/service/EvaluationService.java index 7147309..97936a1 100644 --- a/src/main/java/cn/teammodel/service/EvaluationService.java +++ b/src/main/java/cn/teammodel/service/EvaluationService.java @@ -2,8 +2,8 @@ package cn.teammodel.service; import cn.teammodel.model.dto.Appraise.*; import cn.teammodel.model.entity.appraise.Appraise; -import cn.teammodel.model.entity.appraise.AppraiseRecordItem; import cn.teammodel.model.entity.appraise.AppraiseTreeNode; +import cn.teammodel.model.vo.appraise.AppraiseRecordVo; import java.util.List; @@ -49,7 +49,7 @@ public interface EvaluationService { */ void vote(AppraiseVoteDto appraiseVoteDto); - List findVoteRecord(FindVoteRecordDto findVoteRecordDto); + List findVoteRecord(FindVoteRecordDto findVoteRecordDto); void recallVote(RecallVoteDto recallVoteDto); } diff --git a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java index 58f9f66..7de0a08 100644 --- a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java @@ -14,6 +14,7 @@ import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.school.ClassInfo; import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.school.Student; +import cn.teammodel.model.vo.appraise.AppraiseRecordVo; import cn.teammodel.security.utils.SecurityUtil; import cn.teammodel.service.EvaluationService; import cn.teammodel.utils.RepositoryUtil; @@ -78,7 +79,6 @@ public class EvaluationServiceImpl implements EvaluationService { User loginUser = SecurityUtil.getLoginUser(); String schoolId = loginUser.getSchoolId(); Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE); - // todo: 是否要对学段进行鉴权 if (appraise != null) { return this.buildTree(appraise); @@ -240,16 +240,17 @@ public class EvaluationServiceImpl implements EvaluationService { String periodId; String name; String avatar = null; + String gender = null; // 分别对班级和学生的关键信息取值 if (targetType.equals(TARGET_STUDENT)) { - Student student = studentRepository.findStudentByIdAndCode(targetId, String.format(PK.STUDENT, schoolId)); - if (student == null) { - throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "该学生不存在"); - } + List list = studentRepository.findByIdAndCode(targetId, String.format(PK.STUDENT, schoolId)); + Student student = RepositoryUtil.findOne(list, "该学生不存在"); + classId = student.getClassId(); periodId = student.getPeriodId(); name = student.getName(); avatar = student.getPicture(); + gender = student.getGender(); } else if (targetType.equals(TARGET_CLASS)){ ClassInfo classInfo = classRepository.findClassByIdAndCode(targetId, String.format(PK.CLASS, schoolId)); if (classInfo == null) { @@ -300,6 +301,7 @@ public class EvaluationServiceImpl implements EvaluationService { record.setClassId(classId); record.setName(name); record.setAvatar(avatar); + record.setGender(gender); record.setAcademicYearId(academicYearId); record.setPraiseCount(appraiseTreeNode.isPraise() ? 1 : -1); record.setScore(ObjectUtils.isEmpty(appraiseTreeNode.getScore()) ? 0 : appraiseTreeNode.getScore()); @@ -325,7 +327,7 @@ public class EvaluationServiceImpl implements EvaluationService { } @Override - public List findVoteRecord(FindVoteRecordDto findVoteRecordDto) { + public List findVoteRecord(FindVoteRecordDto findVoteRecordDto) { String periodId = findVoteRecordDto.getPeriodId(); String targetId = StringUtils.isBlank(findVoteRecordDto.getTargetId()) ? null : findVoteRecordDto.getTargetId(); String targetType = StringUtils.isBlank(findVoteRecordDto.getTargetType()) ? null : findVoteRecordDto.getTargetType(); @@ -336,7 +338,7 @@ public class EvaluationServiceImpl implements EvaluationService { List semesters = schoolRepository.findSemestersById(schoolId, periodId); String academicYearId = SchoolDateUtil.generateAcademicId(semesters, LocalDate.now()); - List appraiseRecordItems = appraiseRecordRepository.searchNodesByCondition( + List appraiseRecordItems = appraiseRecordRepository.searchNodesByCondition( targetId, targetType, classId, diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f0a1cdd..381811d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,6 +15,8 @@ spring: endpoint: https://cdhabookdep-free.documents.azure.cn:443 database: TEAMModelOS key: JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A== + populate-query-metrics: true + security: oauth2: diff --git a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java index 369ec77..5dfa679 100644 --- a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java +++ b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java @@ -86,8 +86,17 @@ class TeamModelExtensionApplicationTests { //List nodeById = appraiseRepository.findNodeById("habook", "default", "Appraise", "43e23f03-288c-4012-b5f3-4d5c022739a2"); //System.out.println(nodeById); - System.out.println(schoolRepository.findSemestersById("habook", "50fdecdb-6cbd-4c9a-8dc2-a627f4d6b312")); + //System.out.println(schoolRepository.findSemestersById("habook", "50fdecdb-6cbd-4c9a-8dc2-a627f4d6b312")); // 评价记录 + long t1 = System.currentTimeMillis(); + //List student = studentRepository.findByIdAndCode("202201008", String.format(PK.STUDENT, "hbcn")); + String hbcn = cosmosTemplate.findById("hbcn", String.class); + long t2 = System.currentTimeMillis(); + System.out.println(t2 - t1); + System.out.println(hbcn); + + //System.out.println(RepositoryUtil.findOne(student, "error")); + //List record = appraiseRecordRepository.findScoreAndPraise("fakeStudentId1", // "2023-71fbd0bd-9a46-0490-f6b3-7d16cba4c017", // String.format(PK.PK_APPRAISE_RECORD,"habook")