feat: 为查询学生评价记录添加分页和排序

11111
winter 1 year ago
parent c54edf3cfe
commit 8f7b1f9cc1

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

@ -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<AppraiseRecor
/**
*
*/
@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(@targetType) or c.targetType = @targetType) and " +
"(IS_NULL(@classId) or c.classId = @classId) and " +
@Query("select Student.id as recordId, Student.name, Student.avatar, Student.targetId, Student.targetType, n as info from Student join n in Student.nodes where " +
"(IS_NULL(@targetId) or Student.targetId = @targetId) and " +
"(IS_NULL(@targetType) or Student.targetType = @targetType) and " +
"(IS_NULL(@classId) or Student.classId = @classId) and " +
"(IS_NULL(@creatorId) or n.creatorId = @creatorId) and " +
"(IS_NULL(@academicYearId) or c.academicYearId = @academicYearId) and " +
"c.code = @code")
List<AppraiseRecordVo> 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<AppraiseRecordVo> searchNodesByCondition(String targetId, String targetType, String classId, String creatorId, String academicYearId, String code, Pageable pageable);
}

@ -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)

@ -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<School.Semester> semesters = schoolRepository.findSemestersById(schoolId, periodId);
String academicYearId = SchoolDateUtil.generateAcademicId(semesters, LocalDate.now());
List<AppraiseRecordVo> appraiseRecordItems = appraiseRecordRepository.searchNodesByCondition(
// 分页
Sort sort = Sort.by("createTime").descending();
final CosmosPageRequest pageRequest = new CosmosPageRequest(findVoteRecordDto.getCurrent(), findVoteRecordDto.getSize(), null, sort);
Page<AppraiseRecordVo> 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<AppraiseRecordVo> content = appraiseRecordItemPage.getContent();
return content;
}
@Override

@ -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<String, LocalDate> getSemesterByNow(List<School.Semester> 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 根据大小排序

@ -18,6 +18,7 @@ spring:
populate-query-metrics: true
security:
oauth2:
resourceserver:

@ -0,0 +1,17 @@
<configuration>
<include resource="/org/springframework/boot/logging/logback/base.xml"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
<logger name="com.azure.cosmos" level="error"/>
<logger name="org.springframework" level="error"/>
<logger name="io.netty" level="error"/>
<!-- This will enable query logging, to include query parameter logging, set this logger to TRACE -->
<logger name="com.azure.cosmos.implementation.SqlQuerySpecLogger" level="DEBUG"/>
</configuration>

@ -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> 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<AppraiseRecord> record = appraiseRecordRepository.findScoreAndPraise("fakeStudentId1",

Loading…
Cancel
Save