fix: 修复评价记录按时间分页失效,改为按时间范围查询

11111
winter 1 year ago
parent aa35b01844
commit 0bae71207b

@ -1,6 +1,5 @@
package cn.teammodel.controller.admin.controller; package cn.teammodel.controller.admin.controller;
import cn.teammodel.common.PageVo;
import cn.teammodel.common.R; import cn.teammodel.common.R;
import cn.teammodel.controller.admin.service.AdminAppraiseService; import cn.teammodel.controller.admin.service.AdminAppraiseService;
import cn.teammodel.model.dto.admin.TimeRangeDto; import cn.teammodel.model.dto.admin.TimeRangeDto;
@ -36,9 +35,9 @@ public class IndexController {
} }
@PostMapping("latestRecord") @PostMapping("latestRecord")
@ApiOperation("查询最新评价(可通过时间范围分页)") @ApiOperation("查询时间范围最近评价(无参则当前周的所有记录)")
public R<PageVo<RecordVo>> latestRecord(@Valid @RequestBody TimeRangeDto timeRangeDto) { public R<List<RecordVo>> latestRecord(@Valid @RequestBody TimeRangeDto timeRangeDto) {
PageVo<RecordVo> res = adminAppraiseService.conditionLatestRecord(timeRangeDto); List<RecordVo> res = adminAppraiseService.conditionLatestRecord(timeRangeDto);
return R.success(res); return R.success(res);
} }

@ -1,6 +1,5 @@
package cn.teammodel.controller.admin.service; package cn.teammodel.controller.admin.service;
import cn.teammodel.common.PageVo;
import cn.teammodel.model.dto.admin.TimeRangeDto; import cn.teammodel.model.dto.admin.TimeRangeDto;
import cn.teammodel.model.vo.admin.IndexData; import cn.teammodel.model.vo.admin.IndexData;
import cn.teammodel.model.vo.admin.RankPo; import cn.teammodel.model.vo.admin.RankPo;
@ -20,7 +19,7 @@ public interface AdminAppraiseService {
/** /**
* *
*/ */
PageVo<RecordVo> conditionLatestRecord(TimeRangeDto timeRangeDto); List<RecordVo> conditionLatestRecord(TimeRangeDto timeRangeDto);
List<RankPo> classRank(TimeRangeDto timeRangeDto); List<RankPo> classRank(TimeRangeDto timeRangeDto);

@ -3,7 +3,6 @@ package cn.teammodel.controller.admin.service.impl;
import cn.hutool.core.lang.Pair; import cn.hutool.core.lang.Pair;
import cn.teammodel.common.ErrorCode; import cn.teammodel.common.ErrorCode;
import cn.teammodel.common.PK; import cn.teammodel.common.PK;
import cn.teammodel.common.PageVo;
import cn.teammodel.config.exception.ServiceException; import cn.teammodel.config.exception.ServiceException;
import cn.teammodel.controller.admin.service.AdminAppraiseService; import cn.teammodel.controller.admin.service.AdminAppraiseService;
import cn.teammodel.dao.*; import cn.teammodel.dao.*;
@ -23,13 +22,12 @@ import cn.teammodel.utils.SchoolDateUtil;
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest; import com.azure.spring.data.cosmos.core.query.CosmosPageRequest;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Slice; import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDate; import java.time.*;
import java.time.LocalDateTime; import java.time.temporal.TemporalAdjusters;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -126,23 +124,33 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService {
} }
@Override @Override
public PageVo<RecordVo> conditionLatestRecord(TimeRangeDto timeRangeDto) { public List<RecordVo> conditionLatestRecord(TimeRangeDto timeRangeDto) {
Long startTime = timeRangeDto.getStartTime(); Long startTime = timeRangeDto.getStartTime();
Long endTime = timeRangeDto.getEndTime(); Long endTime = timeRangeDto.getEndTime();
String academicYearId = timeRangeDto.getAcademicYearId(); String academicYearId = timeRangeDto.getAcademicYearId();
Integer current = timeRangeDto.getCurrent();
Integer size = timeRangeDto.getSize();
String schoolId = SecurityUtil.getLoginUser().getSchoolId(); String schoolId = SecurityUtil.getLoginUser().getSchoolId();
final CosmosPageRequest pageRequest = new CosmosPageRequest(current, size, null); // fixme: 是否对时间范围做一些限制
Page<RecordVo> page = appraiseRecordRepository.pageLatestRecords( // 无参默认当前周
if (startTime == null || endTime == null) {
// 将时间范围调整为当前周的周一到当前时间
LocalDateTime mondayOfCurWeek = LocalDateTime.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
.withHour(0)
.withMinute(0)
.withSecond(0)
.withNano(0);
startTime = mondayOfCurWeek.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli();
endTime = Instant.now().toEpochMilli();
}
List<RecordVo> res = appraiseRecordRepository.latestRecords(
String.format(PK.PK_APPRAISE_RECORD, schoolId), String.format(PK.PK_APPRAISE_RECORD, schoolId),
academicYearId, academicYearId,
startTime, startTime,
endTime, endTime
pageRequest); );
return new PageVo<>(page.getTotalPages(), page.getTotalElements(), page.getContent()); return res;
} }
@Override @Override

@ -66,14 +66,13 @@ public interface AppraiseRecordRepository extends CosmosRepository<AppraiseRecor
/** /**
* , * ,
*/ */
// todo: 调整一下数据结构
@Query("select c.id as recordId, c.name as targetName, c.avatar, c.className, n.id as recordNodeId, c.targetId, c.targetType, n.creator, n.createTime, n.appraiseNode.name as appraiseName, n.appraiseNode.isPraise from Student as c join n in c.nodes where " + @Query("select c.id as recordId, c.name as targetName, c.avatar, c.className, n.id as recordNodeId, c.targetId, c.targetType, n.creator, n.createTime, n.appraiseNode.name as appraiseName, n.appraiseNode.isPraise from Student as c join n in c.nodes where " +
"c.code = @code and " + "c.code = @code and " +
"c.academicYearId = @academicYearId and " + "c.academicYearId = @academicYearId and " +
"(IS_NULL(@startTime) or n.createTime >= @startTime) and " + "(IS_NULL(@startTime) or n.createTime >= @startTime) and " +
"(IS_NULL(@endTime) or n.createTime <= @endTime) " + "(IS_NULL(@endTime) or n.createTime <= @endTime)"
"order by c.createTime desc") )
Page<RecordVo> pageLatestRecords(String code, String academicYearId, Long startTime, Long endTime, Pageable pageable); List<RecordVo> latestRecords(String code, String academicYearId, Long startTime, Long endTime);
@Query("select c.classId as id, count(1) as count from Student as c join n in c.nodes where( " + @Query("select c.classId as id, count(1) as count from Student as c join n in c.nodes where( " +

@ -1,18 +1,14 @@
package cn.teammodel.model.dto.admin; package cn.teammodel.model.dto.admin;
import cn.teammodel.common.PageableRequest;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
/** /**
* @author winter * @author winter
* @create 2023-12-06 19:03 * @create 2023-12-06 19:03
*/ */
@EqualsAndHashCode(callSuper = true)
@Data @Data
public class TimeRangeDto extends PageableRequest { public class TimeRangeDto {
private Long startTime; private Long startTime;
private Long endTime; private Long endTime;
@NotNull @NotNull

@ -172,4 +172,9 @@ public class TestWithoutSpring {
// System.out.println(ChronoUnit.WEEKS.between(time, time1) + 1); // System.out.println(ChronoUnit.WEEKS.between(time, time1) + 1);
} }
@Test
public void testDate() {
System.out.println(Instant.now().toEpochMilli());
}
} }

Loading…
Cancel
Save