From 8f7b1f9cc1a6eb7187076738fd662539cc877522 Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Tue, 5 Dec 2023 15:56:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=BA=E6=9F=A5=E8=AF=A2=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E8=AF=84=E4=BB=B7=E8=AE=B0=E5=BD=95=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=92=8C=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/teammodel/common/PageableRequest.java | 16 ++++++++++++++++ .../teammodel/dao/AppraiseRecordRepository.java | 16 +++++++++------- .../model/dto/Appraise/FindVoteRecordDto.java | 5 ++++- .../service/impl/EvaluationServiceImpl.java | 16 +++++++++++++--- .../java/cn/teammodel/utils/SchoolDateUtil.java | 3 ++- src/main/resources/application.yml | 1 + src/main/resources/logback.xml | 17 +++++++++++++++++ .../TeamModelExtensionApplicationTests.java | 5 ++--- 8 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 src/main/java/cn/teammodel/common/PageableRequest.java create mode 100644 src/main/resources/logback.xml diff --git a/src/main/java/cn/teammodel/common/PageableRequest.java b/src/main/java/cn/teammodel/common/PageableRequest.java new file mode 100644 index 0000000..819da51 --- /dev/null +++ b/src/main/java/cn/teammodel/common/PageableRequest.java @@ -0,0 +1,16 @@ +package cn.teammodel.common; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author winter + * @create 2023-12-05 14:58 + */ +@Data +public class PageableRequest { + @ApiModelProperty("当前页码") + private Integer current = 0; + @ApiModelProperty("每页数量") + private Integer size = 10; +} diff --git a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java index cec10b8..40bdb7a 100644 --- a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java +++ b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java @@ -4,6 +4,8 @@ import cn.teammodel.model.entity.appraise.AppraiseRecord; 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.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Repository; import java.util.List; @@ -31,14 +33,14 @@ public interface AppraiseRecordRepository extends CosmosRepository searchNodesByCondition(String targetId, String targetType, String classId, String creatorId, String academicYearId, String code); + "(IS_NULL(@academicYearId) or Student.academicYearId = @academicYearId) and " + + "Student.code = @code") + Page searchNodesByCondition(String targetId, String targetType, String classId, String creatorId, String academicYearId, String code, Pageable pageable); } diff --git a/src/main/java/cn/teammodel/model/dto/Appraise/FindVoteRecordDto.java b/src/main/java/cn/teammodel/model/dto/Appraise/FindVoteRecordDto.java index 19e1781..2fd1492 100644 --- a/src/main/java/cn/teammodel/model/dto/Appraise/FindVoteRecordDto.java +++ b/src/main/java/cn/teammodel/model/dto/Appraise/FindVoteRecordDto.java @@ -1,7 +1,9 @@ package cn.teammodel.model.dto.Appraise; +import cn.teammodel.common.PageableRequest; import io.swagger.annotations.ApiModelProperty; import lombok.Data; +import lombok.EqualsAndHashCode; import javax.validation.constraints.NotNull; @@ -9,8 +11,9 @@ import javax.validation.constraints.NotNull; * @author winter * @create 2023-11-28 16:16 */ +@EqualsAndHashCode(callSuper = true) @Data -public class FindVoteRecordDto { +public class FindVoteRecordDto extends PageableRequest { @NotNull @ApiModelProperty(value = "必要参数,用于获取当前学年,注意: 其他参数不传则默认获取登录老师在该学年下评价的所有记录", required = true) diff --git a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java index 7de0a08..33d6046 100644 --- a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java @@ -20,9 +20,12 @@ import cn.teammodel.service.EvaluationService; import cn.teammodel.utils.RepositoryUtil; import cn.teammodel.utils.SchoolDateUtil; import com.azure.cosmos.models.CosmosPatchOperations; +import com.azure.spring.data.cosmos.core.query.CosmosPageRequest; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -338,15 +341,22 @@ public class EvaluationServiceImpl implements EvaluationService { List semesters = schoolRepository.findSemestersById(schoolId, periodId); String academicYearId = SchoolDateUtil.generateAcademicId(semesters, LocalDate.now()); - List appraiseRecordItems = appraiseRecordRepository.searchNodesByCondition( + // 分页 + Sort sort = Sort.by("createTime").descending(); + final CosmosPageRequest pageRequest = new CosmosPageRequest(findVoteRecordDto.getCurrent(), findVoteRecordDto.getSize(), null, sort); + Page appraiseRecordItemPage = appraiseRecordRepository.searchNodesByCondition( targetId, targetType, classId, teacherId, academicYearId, - String.format(PK.PK_APPRAISE_RECORD, schoolId) + String.format(PK.PK_APPRAISE_RECORD, schoolId), + pageRequest ); - return appraiseRecordItems; + + List content = appraiseRecordItemPage.getContent(); + + return content; } @Override diff --git a/src/main/java/cn/teammodel/utils/SchoolDateUtil.java b/src/main/java/cn/teammodel/utils/SchoolDateUtil.java index 4915a70..be0fca8 100644 --- a/src/main/java/cn/teammodel/utils/SchoolDateUtil.java +++ b/src/main/java/cn/teammodel/utils/SchoolDateUtil.java @@ -1,6 +1,7 @@ package cn.teammodel.utils; import cn.teammodel.common.CommonConstant; +import cn.teammodel.config.exception.ServiceException; import cn.teammodel.model.entity.school.School; import org.apache.commons.lang3.tuple.Pair; @@ -42,7 +43,7 @@ public class SchoolDateUtil { */ public static Pair getSemesterByNow(List semesters, LocalDate date) { if (semesters == null || semesters.isEmpty() || date == null) { - throw new IllegalArgumentException("Invalid input: semesters and date must not be null or empty."); + throw new ServiceException("semesters and date must not be null or empty."); } // 将 semester 根据大小排序 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 381811d..f22fa9e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -18,6 +18,7 @@ spring: populate-query-metrics: true + security: oauth2: resourceserver: diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..b3b201c --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,17 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + diff --git a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java index 5dfa679..3544fcc 100644 --- a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java +++ b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java @@ -7,6 +7,7 @@ import cn.teammodel.dao.StudentRepository; import cn.teammodel.manager.DingAlertNotifier; import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.AppraiseTreeNode; +import cn.teammodel.model.entity.school.School; import cn.teammodel.service.EvaluationService; import cn.teammodel.service.impl.EvaluationServiceImpl; import com.azure.cosmos.models.PartitionKey; @@ -90,11 +91,9 @@ class TeamModelExtensionApplicationTests { // 评价记录 long t1 = System.currentTimeMillis(); //List student = studentRepository.findByIdAndCode("202201008", String.format(PK.STUDENT, "hbcn")); - String hbcn = cosmosTemplate.findById("hbcn", String.class); + School hbcn = cosmosTemplate.findById("hbcn", School.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",