fix: 暂时解决查询 Student 序列化错误的bug

11111
winter 1 year ago
parent a3922d8c2d
commit c54edf3cfe

@ -17,6 +17,9 @@
### 教育评价项 ### 教育评价项
> 学生每学期所有的评价项都在一个项中,按学校进行分区 > 学生每学期所有的评价项都在一个项中,按学校进行分区
>
> 注意: 如果学生中途换班,也就是 classId 发生变动,那么会给这个学生在本学期新开一个文档,也就是说一个学生在一个学期的文档可能不止一个(小概率)
>
分区键: `AppraiseRecord-{学校id}` 分区键: `AppraiseRecord-{学校id}`
Id: `学年 + semesterId` -> eg: 2022.uuid academicYearId: `学年 + semesterId` -> eg: 2022.uuid

@ -2,7 +2,7 @@ package cn.teammodel.common;
public enum ErrorCode { public enum ErrorCode {
SUCCESS(0, "ok"), SUCCESS(200, "ok"),
PARAMS_ERROR(40000, "请求参数错误"), PARAMS_ERROR(40000, "请求参数错误"),
NOT_LOGIN_ERROR(40100, "未登录"), NOT_LOGIN_ERROR(40100, "未登录"),
NO_AUTH_ERROR(40101, "无权限"), NO_AUTH_ERROR(40101, "无权限"),

@ -1,5 +1,6 @@
package cn.teammodel.config.exception; package cn.teammodel.config.exception;
import cn.teammodel.common.ErrorCode;
import cn.teammodel.common.R; import cn.teammodel.common.R;
import cn.teammodel.manager.NotificationService; import cn.teammodel.manager.NotificationService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -69,7 +70,7 @@ public class GlobalExceptionHandler {
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生未知异常.", requestURI, e); log.error("请求地址'{}',发生未知异常.", requestURI, e);
notificationService.send("RuntimeException 告警: " + e.getMessage()); notificationService.send("RuntimeException 告警: " + e.getMessage());
return R.error(e.getMessage()); return R.error(ErrorCode.SYSTEM_ERROR);
} }
/** /**

@ -3,7 +3,7 @@ package cn.teammodel.controller;
import cn.teammodel.common.R; import cn.teammodel.common.R;
import cn.teammodel.model.dto.Appraise.*; import cn.teammodel.model.dto.Appraise.*;
import cn.teammodel.model.entity.appraise.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 cn.teammodel.service.EvaluationService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -66,8 +66,8 @@ public class AppraiseController {
@PostMapping("findVoteRecord") @PostMapping("findVoteRecord")
@ApiOperation(value = "多条件查询当前登录老师的学生评价(投票)") @ApiOperation(value = "多条件查询当前登录老师的学生评价(投票)")
public R<List<AppraiseRecordItem>> findMyVoteRecord(@Valid @RequestBody FindVoteRecordDto findVoteRecordDto) { public R<List<AppraiseRecordVo>> findMyVoteRecord(@Valid @RequestBody FindVoteRecordDto findVoteRecordDto) {
List<AppraiseRecordItem> res = evaluationService.findVoteRecord(findVoteRecordDto); List<AppraiseRecordVo> res = evaluationService.findVoteRecord(findVoteRecordDto);
return R.success(res); return R.success(res);
} }

@ -1,7 +1,7 @@
package cn.teammodel.dao; package cn.teammodel.dao;
import cn.teammodel.model.entity.appraise.AppraiseRecord; 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.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query; import com.azure.spring.data.cosmos.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -31,14 +31,14 @@ public interface AppraiseRecordRepository extends CosmosRepository<AppraiseRecor
/** /**
* *
*/ */
@Query("select value n from Student as c join n in c.nodes where " + @Query("select c.id as recordId, c.name, c.avatar, c.targetId, c.targetType, n as info from Student as c join n in c.nodes where " +
"(IS_NULL(@targetId) or c.targetId = @targetId) and " + "(IS_NULL(@targetId) or c.targetId = @targetId) and " +
"(IS_NULL(@targetType) or c.targetType = @targetType) and " + "(IS_NULL(@targetType) or c.targetType = @targetType) and " +
"(IS_NULL(@classId) or c.classId = @classId) and " + "(IS_NULL(@classId) or c.classId = @classId) and " +
"(IS_NULL(@creatorId) or n.creatorId = @creatorId) and " + "(IS_NULL(@creatorId) or n.creatorId = @creatorId) and " +
"(IS_NULL(@academicYearId) or c.academicYearId = @academicYearId) and " + "(IS_NULL(@academicYearId) or c.academicYearId = @academicYearId) and " +
"c.code = @code") "c.code = @code")
List<AppraiseRecordItem> searchNodesByCondition(String targetId, String targetType, String classId, String creatorId, String academicYearId, String code); List<AppraiseRecordVo> searchNodesByCondition(String targetId, String targetType, String classId, String creatorId, String academicYearId, String code);
} }

@ -2,9 +2,16 @@ package cn.teammodel.dao;
import cn.teammodel.model.entity.school.Student; import cn.teammodel.model.entity.school.Student;
import com.azure.spring.data.cosmos.repository.CosmosRepository; import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
public interface StudentRepository extends CosmosRepository<Student, String> { public interface StudentRepository extends CosmosRepository<Student, String> {
Student findStudentByIdAndCode(String id, String code); 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<Student> findByIdAndCode(String id, String code);
} }

@ -12,9 +12,9 @@ import javax.validation.constraints.NotNull;
@Data @Data
public class RecallVoteDto { public class RecallVoteDto {
@NotNull @NotNull
@ApiModelProperty("学生评价记录的文档id") @ApiModelProperty(value = "学生评价记录的文档id", required = true)
String recordId; String recordId;
@NotNull @NotNull
@ApiModelProperty("学生评价记录的具体节点id") @ApiModelProperty(value = "学生评价记录的具体节点id", required = true)
String nodeId; String nodeId;
} }

@ -44,6 +44,7 @@ public class AppraiseRecord extends BaseItem {
* /class * /class
*/ */
private String avatar; private String avatar;
private String gender;
/** /**
* *
*/ */

@ -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.Container;
import com.azure.spring.data.cosmos.core.mapping.PartitionKey; import com.azure.spring.data.cosmos.core.mapping.PartitionKey;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data; import lombok.Data;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
@ -10,6 +11,7 @@ import java.util.List;
@Data @Data
@Container(containerName = "Student") @Container(containerName = "Student")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Student { public class Student {
@Id @Id
private String id; private String id;
@ -32,16 +34,16 @@ public class Student {
private String periodId; private String periodId;
private String gender; private String gender;
private Integer graduate; private Integer graduate;
private List<String> loginInfos; private List<LoginInfo> loginInfos;
private Long createTime; private Long createTime;
private List<String> guardians; //private List<String> guardians;
private String pk; 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;
}
} }

@ -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;
}

@ -2,8 +2,8 @@ package cn.teammodel.service;
import cn.teammodel.model.dto.Appraise.*; import cn.teammodel.model.dto.Appraise.*;
import cn.teammodel.model.entity.appraise.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.entity.appraise.AppraiseTreeNode;
import cn.teammodel.model.vo.appraise.AppraiseRecordVo;
import java.util.List; import java.util.List;
@ -49,7 +49,7 @@ public interface EvaluationService {
*/ */
void vote(AppraiseVoteDto appraiseVoteDto); void vote(AppraiseVoteDto appraiseVoteDto);
List<AppraiseRecordItem> findVoteRecord(FindVoteRecordDto findVoteRecordDto); List<AppraiseRecordVo> findVoteRecord(FindVoteRecordDto findVoteRecordDto);
void recallVote(RecallVoteDto recallVoteDto); void recallVote(RecallVoteDto recallVoteDto);
} }

@ -14,6 +14,7 @@ import cn.teammodel.model.entity.appraise.AppraiseTreeNode;
import cn.teammodel.model.entity.school.ClassInfo; import cn.teammodel.model.entity.school.ClassInfo;
import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.school.School;
import cn.teammodel.model.entity.school.Student; import cn.teammodel.model.entity.school.Student;
import cn.teammodel.model.vo.appraise.AppraiseRecordVo;
import cn.teammodel.security.utils.SecurityUtil; import cn.teammodel.security.utils.SecurityUtil;
import cn.teammodel.service.EvaluationService; import cn.teammodel.service.EvaluationService;
import cn.teammodel.utils.RepositoryUtil; import cn.teammodel.utils.RepositoryUtil;
@ -78,7 +79,6 @@ public class EvaluationServiceImpl implements EvaluationService {
User loginUser = SecurityUtil.getLoginUser(); User loginUser = SecurityUtil.getLoginUser();
String schoolId = loginUser.getSchoolId(); String schoolId = loginUser.getSchoolId();
Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE); Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE);
// todo: 是否要对学段进行鉴权 // todo: 是否要对学段进行鉴权
if (appraise != null) { if (appraise != null) {
return this.buildTree(appraise); return this.buildTree(appraise);
@ -240,16 +240,17 @@ public class EvaluationServiceImpl implements EvaluationService {
String periodId; String periodId;
String name; String name;
String avatar = null; String avatar = null;
String gender = null;
// 分别对班级和学生的关键信息取值 // 分别对班级和学生的关键信息取值
if (targetType.equals(TARGET_STUDENT)) { if (targetType.equals(TARGET_STUDENT)) {
Student student = studentRepository.findStudentByIdAndCode(targetId, String.format(PK.STUDENT, schoolId)); List<Student> list = studentRepository.findByIdAndCode(targetId, String.format(PK.STUDENT, schoolId));
if (student == null) { Student student = RepositoryUtil.findOne(list, "该学生不存在");
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "该学生不存在");
}
classId = student.getClassId(); classId = student.getClassId();
periodId = student.getPeriodId(); periodId = student.getPeriodId();
name = student.getName(); name = student.getName();
avatar = student.getPicture(); avatar = student.getPicture();
gender = student.getGender();
} else if (targetType.equals(TARGET_CLASS)){ } else if (targetType.equals(TARGET_CLASS)){
ClassInfo classInfo = classRepository.findClassByIdAndCode(targetId, String.format(PK.CLASS, schoolId)); ClassInfo classInfo = classRepository.findClassByIdAndCode(targetId, String.format(PK.CLASS, schoolId));
if (classInfo == null) { if (classInfo == null) {
@ -300,6 +301,7 @@ public class EvaluationServiceImpl implements EvaluationService {
record.setClassId(classId); record.setClassId(classId);
record.setName(name); record.setName(name);
record.setAvatar(avatar); record.setAvatar(avatar);
record.setGender(gender);
record.setAcademicYearId(academicYearId); record.setAcademicYearId(academicYearId);
record.setPraiseCount(appraiseTreeNode.isPraise() ? 1 : -1); record.setPraiseCount(appraiseTreeNode.isPraise() ? 1 : -1);
record.setScore(ObjectUtils.isEmpty(appraiseTreeNode.getScore()) ? 0 : appraiseTreeNode.getScore()); record.setScore(ObjectUtils.isEmpty(appraiseTreeNode.getScore()) ? 0 : appraiseTreeNode.getScore());
@ -325,7 +327,7 @@ public class EvaluationServiceImpl implements EvaluationService {
} }
@Override @Override
public List<AppraiseRecordItem> findVoteRecord(FindVoteRecordDto findVoteRecordDto) { public List<AppraiseRecordVo> findVoteRecord(FindVoteRecordDto findVoteRecordDto) {
String periodId = findVoteRecordDto.getPeriodId(); String periodId = findVoteRecordDto.getPeriodId();
String targetId = StringUtils.isBlank(findVoteRecordDto.getTargetId()) ? null : findVoteRecordDto.getTargetId(); String targetId = StringUtils.isBlank(findVoteRecordDto.getTargetId()) ? null : findVoteRecordDto.getTargetId();
String targetType = StringUtils.isBlank(findVoteRecordDto.getTargetType()) ? null : findVoteRecordDto.getTargetType(); String targetType = StringUtils.isBlank(findVoteRecordDto.getTargetType()) ? null : findVoteRecordDto.getTargetType();
@ -336,7 +338,7 @@ public class EvaluationServiceImpl implements EvaluationService {
List<School.Semester> semesters = schoolRepository.findSemestersById(schoolId, periodId); List<School.Semester> semesters = schoolRepository.findSemestersById(schoolId, periodId);
String academicYearId = SchoolDateUtil.generateAcademicId(semesters, LocalDate.now()); String academicYearId = SchoolDateUtil.generateAcademicId(semesters, LocalDate.now());
List<AppraiseRecordItem> appraiseRecordItems = appraiseRecordRepository.searchNodesByCondition( List<AppraiseRecordVo> appraiseRecordItems = appraiseRecordRepository.searchNodesByCondition(
targetId, targetId,
targetType, targetType,
classId, classId,

@ -15,6 +15,8 @@ spring:
endpoint: https://cdhabookdep-free.documents.azure.cn:443 endpoint: https://cdhabookdep-free.documents.azure.cn:443
database: TEAMModelOS database: TEAMModelOS
key: JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A== key: JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==
populate-query-metrics: true
security: security:
oauth2: oauth2:

@ -86,8 +86,17 @@ class TeamModelExtensionApplicationTests {
//List<AppraiseTreeNode> nodeById = appraiseRepository.findNodeById("habook", "default", "Appraise", "43e23f03-288c-4012-b5f3-4d5c022739a2"); //List<AppraiseTreeNode> nodeById = appraiseRepository.findNodeById("habook", "default", "Appraise", "43e23f03-288c-4012-b5f3-4d5c022739a2");
//System.out.println(nodeById); //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> 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<AppraiseRecord> record = appraiseRecordRepository.findScoreAndPraise("fakeStudentId1", //List<AppraiseRecord> record = appraiseRecordRepository.findScoreAndPraise("fakeStudentId1",
// "2023-71fbd0bd-9a46-0490-f6b3-7d16cba4c017", // "2023-71fbd0bd-9a46-0490-f6b3-7d16cba4c017",
// String.format(PK.PK_APPRAISE_RECORD,"habook") // String.format(PK.PK_APPRAISE_RECORD,"habook")

Loading…
Cancel
Save