From 83c980dcae93e5e35568ec12df2ffd16fbedfb6b Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Thu, 7 Dec 2023 12:12:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=AE=A1=E7=90=86=E5=91=98=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/IndexController.java | 22 --- .../admin/service/AdminAppraiseService.java | 12 -- .../impl/AdminAppraiseServiceImpl.java | 90 --------- .../admin/controller/IndexController.java | 59 ++++++ .../admin/service/AdminAppraiseService.java | 27 +++ .../impl/AdminAppraiseServiceImpl.java | 183 ++++++++++++++++++ .../dao/AppraiseRecordRepository.java | 34 +++- .../cn/teammodel/dao/AppraiseRepository.java | 3 + .../cn/teammodel/dao/ClassRepository.java | 8 +- .../cn/teammodel/dao/TeacherRepository.java | 19 ++ .../model/dto/admin/TimeRangeDto.java | 25 +++ .../entity/appraise/AppraiseRecordItem.java | 2 +- .../entity/appraise/AppraiseTreeNode.java | 2 +- .../model/entity/school/Teacher.java | 53 +++++ .../cn/teammodel/model/vo/admin/RankVo.java | 14 ++ .../teammodel/model/vo/appraise/RecordVo.java | 2 +- .../TeamModelExtensionApplicationTests.java | 33 +++- 17 files changed, 453 insertions(+), 135 deletions(-) delete mode 100644 src/main/java/cn/teammodel/admin/controller/IndexController.java delete mode 100644 src/main/java/cn/teammodel/admin/service/AdminAppraiseService.java delete mode 100644 src/main/java/cn/teammodel/admin/service/impl/AdminAppraiseServiceImpl.java create mode 100644 src/main/java/cn/teammodel/controller/admin/controller/IndexController.java create mode 100644 src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java create mode 100644 src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java create mode 100644 src/main/java/cn/teammodel/dao/TeacherRepository.java create mode 100644 src/main/java/cn/teammodel/model/dto/admin/TimeRangeDto.java create mode 100644 src/main/java/cn/teammodel/model/entity/school/Teacher.java create mode 100644 src/main/java/cn/teammodel/model/vo/admin/RankVo.java diff --git a/src/main/java/cn/teammodel/admin/controller/IndexController.java b/src/main/java/cn/teammodel/admin/controller/IndexController.java deleted file mode 100644 index 38cf3dc..0000000 --- a/src/main/java/cn/teammodel/admin/controller/IndexController.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.teammodel.admin.controller; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * 管理员首页 - * @author winter - * @create 2023-12-06 14:37 - */ -@RestController -@RequestMapping("admin/index") -public class IndexController { - - - @RequestMapping("/") - public String index(){ - - return null; - } - -} diff --git a/src/main/java/cn/teammodel/admin/service/AdminAppraiseService.java b/src/main/java/cn/teammodel/admin/service/AdminAppraiseService.java deleted file mode 100644 index d9c268e..0000000 --- a/src/main/java/cn/teammodel/admin/service/AdminAppraiseService.java +++ /dev/null @@ -1,12 +0,0 @@ -package cn.teammodel.admin.service; - -import cn.teammodel.model.vo.admin.IndexData; - -/** - * @author winter - * @create 2023-12-06 14:45 - */ -public interface AdminAppraiseService { - IndexData getIndexData(String period, String academicYearId); - -} diff --git a/src/main/java/cn/teammodel/admin/service/impl/AdminAppraiseServiceImpl.java b/src/main/java/cn/teammodel/admin/service/impl/AdminAppraiseServiceImpl.java deleted file mode 100644 index f2d3b46..0000000 --- a/src/main/java/cn/teammodel/admin/service/impl/AdminAppraiseServiceImpl.java +++ /dev/null @@ -1,90 +0,0 @@ -package cn.teammodel.admin.service.impl; - -import cn.teammodel.admin.service.AdminAppraiseService; -import cn.teammodel.common.PK; -import cn.teammodel.dao.AppraiseRecordRepository; -import cn.teammodel.dao.AppraiseRepository; -import cn.teammodel.model.vo.admin.IndexData; -import cn.teammodel.model.vo.appraise.RecordVo; -import com.azure.spring.data.cosmos.core.CosmosTemplate; -import com.azure.spring.data.cosmos.core.query.CosmosPageRequest; -import org.apache.commons.lang3.ObjectUtils; -import org.springframework.data.domain.Slice; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.time.LocalDateTime; -import java.time.temporal.WeekFields; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -/** - * @author winter - * @create 2023-12-06 14:46 - */ -@Service -public class AdminAppraiseServiceImpl implements AdminAppraiseService { - @Resource - private CosmosTemplate cosmosTemplate; - @Resource - private AppraiseRepository appraiseRepository; - @Resource - private AppraiseRecordRepository appraiseRecordRepository; - - @Override - public IndexData getIndexData(String period, String academicYearId) { - final IndexData indexData = new IndexData(); - int totalCount = 0; - int criticalCount = 0; - - //User loginUser = SecurityUtil.getLoginUser(); - String schoolId = "habook"; - - // slice 分段读取 - CosmosPageRequest pageRequest = new CosmosPageRequest(0, 10, null); - Slice slice; - Map countByWeek = new HashMap<>(); - - do { - slice = appraiseRecordRepository.findAllByAcademicYearId(String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, pageRequest); - List content = slice.getContent(); - if (ObjectUtils.isEmpty(content)) { - return indexData; - } - - // 分批次计算 - for (RecordVo item : content) { - // 处理每周的评价数 - int weekNum = calculateWeekNum(item.getCreateTime()); - countByWeek.put(weekNum, countByWeek.getOrDefault(weekNum, 0) + 1); - // 处理总评价数 - totalCount++; - // 处理批评数 - if (!item.isPraise()) { - criticalCount++; - } - } - - if (slice.hasNext()) { - pageRequest = (CosmosPageRequest) slice.nextPageable(); - } - } while (slice.hasNext()); - - // 组装数据 - indexData.setCountByWeek(countByWeek); - indexData.setTotalCount(totalCount); - indexData.setCriticalCount(criticalCount); - indexData.setPraiseCount(totalCount - criticalCount); - return indexData; - } - - private int calculateWeekNum(LocalDateTime localDateTime) { - // 获取周字段 todo: 时区或者周的计算 - WeekFields weekFields = WeekFields.of(Locale.getDefault()); - // 获取当前日期时间所在年的周数 - return localDateTime.get(weekFields.weekOfWeekBasedYear()); - } - -} diff --git a/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java b/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java new file mode 100644 index 0000000..6efc72d --- /dev/null +++ b/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java @@ -0,0 +1,59 @@ +package cn.teammodel.controller.admin.controller; + +import cn.teammodel.controller.admin.service.AdminAppraiseService; +import cn.teammodel.common.R; +import cn.teammodel.model.dto.admin.TimeRangeDto; +import cn.teammodel.model.vo.admin.RankVo; +import cn.teammodel.model.vo.appraise.RecordVo; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.List; + +/** + * 管理员首页 + * @author winter + * @create 2023-12-06 14:37 + */ +@RestController +@RequestMapping("admin/index") +public class IndexController { + @Resource + private AdminAppraiseService adminAppraiseService; + + + @GetMapping("/") + public String index(){ + //IndexData indexData = adminAppraiseService.getIndexData("", ""); + return null; + } + + @PostMapping("latestRecord") + @ApiOperation("查询最新评价(可通过时间范围分页)") + public R> latestRecord(@Valid @RequestBody TimeRangeDto timeRangeDto) { + List res = adminAppraiseService.conditionLatestRecord(timeRangeDto); + return R.success(res); + } + + @PostMapping("classRank") + @ApiOperation("班级评价活跃排行榜: Top10") + public R> classRank(@Valid @RequestBody TimeRangeDto timeRangeDto) { + List res = adminAppraiseService.classRank(timeRangeDto); + return R.success(res); + } + @PostMapping("teacherRank") + @ApiOperation("班级评价活跃排行榜: Top10") + public R> teacherRank(@Valid @RequestBody TimeRangeDto timeRangeDto) { + List res = adminAppraiseService.teacherRank(timeRangeDto); + return R.success(res); + } + @PostMapping("appraiseNodeRank") + @ApiOperation("班级评价活跃排行榜: Top10") + public R> appraiseNodeRank(@Valid @RequestBody TimeRangeDto timeRangeDto) { + List res = adminAppraiseService.appraiseNodeRank(timeRangeDto); + return R.success(res); + } + +} diff --git a/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java b/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java new file mode 100644 index 0000000..f062c99 --- /dev/null +++ b/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java @@ -0,0 +1,27 @@ +package cn.teammodel.controller.admin.service; + +import cn.teammodel.model.dto.admin.TimeRangeDto; +import cn.teammodel.model.vo.admin.IndexData; +import cn.teammodel.model.vo.admin.RankVo; +import cn.teammodel.model.vo.appraise.RecordVo; + +import java.util.List; + +/** + * @author winter + * @create 2023-12-06 14:45 + */ +public interface AdminAppraiseService { + IndexData getIndexData(String period, String academicYearId); + + /** + * 按时期分页获取最新的评价数据 + */ + List conditionLatestRecord(TimeRangeDto timeRangeDto); + + List classRank(TimeRangeDto timeRangeDto); + + List teacherRank(TimeRangeDto timeRangeDto); + + List appraiseNodeRank(TimeRangeDto timeRangeDto); +} diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java new file mode 100644 index 0000000..7729de9 --- /dev/null +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java @@ -0,0 +1,183 @@ +package cn.teammodel.controller.admin.service.impl; + +import cn.teammodel.controller.admin.service.AdminAppraiseService; +import cn.teammodel.common.PK; +import cn.teammodel.dao.AppraiseRecordRepository; +import cn.teammodel.dao.AppraiseRepository; +import cn.teammodel.dao.ClassRepository; +import cn.teammodel.dao.TeacherRepository; +import cn.teammodel.model.dto.admin.TimeRangeDto; +import cn.teammodel.model.entity.User; +import cn.teammodel.model.entity.appraise.AppraiseTreeNode; +import cn.teammodel.model.entity.school.ClassInfo; +import cn.teammodel.model.entity.school.Teacher; +import cn.teammodel.model.vo.admin.IndexData; +import cn.teammodel.model.vo.admin.RankVo; +import cn.teammodel.model.vo.appraise.RecordVo; +import cn.teammodel.security.utils.SecurityUtil; +import com.azure.spring.data.cosmos.core.query.CosmosPageRequest; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Slice; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.time.temporal.WeekFields; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author winter + * @create 2023-12-06 14:46 + */ +@Service +public class AdminAppraiseServiceImpl implements AdminAppraiseService { + @Resource + private ClassRepository classRepository; + @Resource + private TeacherRepository teacherRepository; + @Resource + private AppraiseRepository appraiseRepository; + + @Resource + private AppraiseRecordRepository appraiseRecordRepository; + + @Override + public IndexData getIndexData(String period, String academicYearId) { + final IndexData indexData = new IndexData(); + int totalCount = 0; + int criticalCount = 0; + + User loginUser = SecurityUtil.getLoginUser(); + String schoolId = loginUser.getSchoolId(); + + // slice 分段读取 + CosmosPageRequest pageRequest = new CosmosPageRequest(0, 10, null); + Slice slice; + Map countByWeek = new HashMap<>(); + + do { + slice = appraiseRecordRepository.findAllByAcademicYearId(String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, pageRequest); + List content = slice.getContent(); + if (ObjectUtils.isEmpty(content)) { + return indexData; + } + + // 分批次计算 + for (RecordVo item : content) { + // 处理每周的评价数 + int weekNum = calculateWeekNum(item.getCreateTime()); + countByWeek.put(weekNum, countByWeek.getOrDefault(weekNum, 0) + 1); + // 处理总评价数 + totalCount++; + // 处理批评数 + if (!item.isPraise()) { + criticalCount++; + } + } + + if (slice.hasNext()) { + pageRequest = (CosmosPageRequest) slice.nextPageable(); + } + } while (slice.hasNext()); + + // 组装数据 + indexData.setCountByWeek(countByWeek); + indexData.setTotalCount(totalCount); + indexData.setCriticalCount(criticalCount); + indexData.setPraiseCount(totalCount - criticalCount); + return indexData; + } + + @Override + public List conditionLatestRecord(TimeRangeDto timeRangeDto) { + LocalDateTime startTime = timeRangeDto.getStartTime(); + LocalDateTime endTime = timeRangeDto.getEndTime(); + String academicYearId = timeRangeDto.getAcademicYearId(); + Integer current = timeRangeDto.getCurrent(); + Integer size = timeRangeDto.getSize(); + String schoolId = SecurityUtil.getLoginUser().getSchoolId(); + + final CosmosPageRequest pageRequest = new CosmosPageRequest(current, size, null); + Page page = appraiseRecordRepository.pageLatestRecords( + String.format(PK.PK_APPRAISE_RECORD, schoolId), + academicYearId, + startTime.toString(), + endTime.toString(), + pageRequest); + + return page.getContent(); + } + + @Override + public List classRank(TimeRangeDto timeRangeDto) { + // todo 不要 page + String startTime = timeRangeDto.getStartTime() == null ? null : timeRangeDto.getStartTime().toString(); + String endTime = timeRangeDto.getEndTime() == null ? null : timeRangeDto.getEndTime().toString(); + String academicYearId = timeRangeDto.getAcademicYearId(); + String schoolId = SecurityUtil.getLoginUser().getSchoolId(); + + List rankVoList = appraiseRecordRepository.classRank( + String.format(PK.PK_APPRAISE_RECORD, schoolId), + academicYearId, + startTime, + endTime + ); + Set classIdSet = rankVoList.stream().map(RankVo::getId).collect(Collectors.toSet()); + // 注意: 如果查询 in 的查询集在数据库中不存在,则在结果集也不会为 null. + List classes = classRepository.findAllByCodeAndIdIn(String.format(PK.CLASS, schoolId), classIdSet); + Map idNameMap = classes.stream().collect(Collectors.toMap(ClassInfo::getId, ClassInfo::getName)); + rankVoList.forEach(rankVo -> rankVo.setName(idNameMap.get(rankVo.getId()))); + return rankVoList; + } + + @Override + public List teacherRank(TimeRangeDto timeRangeDto) { + String startTime = timeRangeDto.getStartTime() == null ? null : timeRangeDto.getStartTime().toString(); + String endTime = timeRangeDto.getEndTime() == null ? null : timeRangeDto.getEndTime().toString(); + String academicYearId = timeRangeDto.getAcademicYearId(); + String schoolId = SecurityUtil.getLoginUser().getSchoolId(); + + List rankVoList = appraiseRecordRepository.teacherRank( + String.format(PK.PK_APPRAISE_RECORD, schoolId), + academicYearId, + startTime, + endTime + ); + Set teacherIdSet = rankVoList.stream().map(RankVo::getId).collect(Collectors.toSet()); + List teachers = teacherRepository.findAllByCodeAndIdIn(PK.COMMON_BASE, teacherIdSet); + Map idNameMap = teachers.stream().collect(Collectors.toMap(Teacher::getId, Teacher::getName)); + rankVoList.forEach(rankVo -> rankVo.setName(idNameMap.get(rankVo.getId()))); + return rankVoList; + } + + @Override + public List appraiseNodeRank(TimeRangeDto timeRangeDto) { + String startTime = timeRangeDto.getStartTime() == null ? null : timeRangeDto.getStartTime().toString(); + String endTime = timeRangeDto.getEndTime() == null ? null : timeRangeDto.getEndTime().toString(); + String academicYearId = timeRangeDto.getAcademicYearId(); + String schoolId = SecurityUtil.getLoginUser().getSchoolId(); + + List rankVoList = appraiseRecordRepository.appraiseNodeRank( + String.format(PK.PK_APPRAISE_RECORD, schoolId), + academicYearId, + startTime, + endTime + ); + + Set appraiseNodeIdSet = rankVoList.stream().map(RankVo::getId).collect(Collectors.toSet()); + List appraises = appraiseRepository.findAllByCodeAndIdIn(PK.PK_APPRAISE, appraiseNodeIdSet); + Map idNameMap = appraises.stream().collect(Collectors.toMap(AppraiseTreeNode::getId, AppraiseTreeNode::getName)); + rankVoList.forEach(rankVo -> rankVo.setName(idNameMap.get(rankVo.getId()))); + return rankVoList; + } + + private int calculateWeekNum(LocalDateTime localDateTime) { + // 获取周字段 todo: 时区或者周的计算 + WeekFields weekFields = WeekFields.of(Locale.getDefault()); + // 获取当前日期时间所在年的周数 + return localDateTime.get(weekFields.weekOfWeekBasedYear()); + } + +} diff --git a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java index f141537..b63a7e0 100644 --- a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java +++ b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java @@ -1,6 +1,7 @@ package cn.teammodel.dao; import cn.teammodel.model.entity.appraise.AppraiseRecord; +import cn.teammodel.model.vo.admin.RankVo; import cn.teammodel.model.vo.appraise.AppraiseRecordVo; import cn.teammodel.model.vo.appraise.RecordVo; import com.azure.spring.data.cosmos.repository.CosmosRepository; @@ -24,7 +25,6 @@ import java.util.List; */ @Repository public interface AppraiseRecordRepository extends CosmosRepository { - /** * 查询评价记录 */ @@ -67,8 +67,36 @@ public interface AppraiseRecordRepository extends CosmosRepository= @startTime) and" + + "(IS_NULL(@endTime) or c.createTime <= @endTime)" + "order by c.createTime desc") - Page pageLatestRecords(String code, Pageable pageable); + Page pageLatestRecords(String code, String academicYearId, String startTime, String endTime, Pageable pageable); + + + @Query("select c.classId as id, count(1) as count from Student as c join n in c.nodes where( " + + "c.code = @code) and " + + "(c.academicYearId = @academicYearId) and " + + "(IS_NULL(@startTime) or n.createTime >= @startTime) and " + + "(IS_NULL(@endTime) or n.createTime <= @endTime) " + + "group by c.classId") + List classRank(String code, String academicYearId, String startTime, String endTime); + + @Query("select n.creatorId as id, count(1) as count from Student as c join n in c.nodes where " + + "(c.academicYearId = @academicYearId) and " + + "(IS_NULL(@startTime) or n.createTime >= @startTime) and " + + "(IS_NULL(@endTime) or n.createTime <= @endTime) and " + + "(c.code = @code) " + + "group by n.creatorId") + List teacherRank(String code, String academicYearId, String startTime, String endTime); + @Query("select n.appraiseNode.id as id, count(1) as count from Student as c join n in c.nodes where " + + "(c.academicYearId = @academicYearId) and " + + "(IS_NULL(@startTime) or n.createTime >= @startTime) and " + + "(IS_NULL(@endTime) or n.createTime <= @endTime) and " + + "(c.code = @code) " + + "group by n.appraiseNode.id") + List appraiseNodeRank(String code, String academicYearId, String startTime, String endTime); } diff --git a/src/main/java/cn/teammodel/dao/AppraiseRepository.java b/src/main/java/cn/teammodel/dao/AppraiseRepository.java index f2aa592..388c73e 100644 --- a/src/main/java/cn/teammodel/dao/AppraiseRepository.java +++ b/src/main/java/cn/teammodel/dao/AppraiseRepository.java @@ -9,6 +9,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Set; /** * @author winter @@ -33,4 +34,6 @@ public interface AppraiseRepository extends CosmosRepository { @Query("SELECT value n FROM School AS s join n in s.nodes where s.code = @code and n.id = @nodeId") List findNodeById(@Param("code") String code, @Param("nodeId") String nodeId); + @Query("select n.id, n.name from School as c join n in c.nodes where c.code = @code and n.id in (@ids)") + List findAllByCodeAndIdIn(String code, Set ids); } diff --git a/src/main/java/cn/teammodel/dao/ClassRepository.java b/src/main/java/cn/teammodel/dao/ClassRepository.java index 7b1a2bc..b04ec89 100644 --- a/src/main/java/cn/teammodel/dao/ClassRepository.java +++ b/src/main/java/cn/teammodel/dao/ClassRepository.java @@ -2,14 +2,20 @@ package cn.teammodel.dao; import cn.teammodel.model.entity.school.ClassInfo; import com.azure.spring.data.cosmos.repository.CosmosRepository; +import com.azure.spring.data.cosmos.repository.Query; import org.springframework.stereotype.Repository; +import java.util.Collection; +import java.util.List; + /** * @author winter * @create 2023-12-01 16:37 */ @Repository public interface ClassRepository extends CosmosRepository { - ClassInfo findClassByIdAndCode(String targetId, String format); + + @Query("select c.id, c.name from School as c where c.code = @code and c.id in (@ids)") + List findAllByCodeAndIdIn(String code, Collection ids); } diff --git a/src/main/java/cn/teammodel/dao/TeacherRepository.java b/src/main/java/cn/teammodel/dao/TeacherRepository.java new file mode 100644 index 0000000..c47f18a --- /dev/null +++ b/src/main/java/cn/teammodel/dao/TeacherRepository.java @@ -0,0 +1,19 @@ +package cn.teammodel.dao; + +import cn.teammodel.model.entity.school.Teacher; +import com.azure.spring.data.cosmos.repository.CosmosRepository; +import com.azure.spring.data.cosmos.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.Collection; +import java.util.List; + +/** + * @author winter + * @create 2023-11-28 17:39 + */ +@Repository +public interface TeacherRepository extends CosmosRepository { + @Query("select c.id, c.name from Teacher as c where c.code = @code and c.id in (@ids)") + List findAllByCodeAndIdIn(String code, Collection ids); +} diff --git a/src/main/java/cn/teammodel/model/dto/admin/TimeRangeDto.java b/src/main/java/cn/teammodel/model/dto/admin/TimeRangeDto.java new file mode 100644 index 0000000..d88091e --- /dev/null +++ b/src/main/java/cn/teammodel/model/dto/admin/TimeRangeDto.java @@ -0,0 +1,25 @@ +package cn.teammodel.model.dto.admin; + +import cn.teammodel.common.PageableRequest; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; + +/** + * @author winter + * @create 2023-12-06 19:03 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class TimeRangeDto extends PageableRequest { + @JsonFormat(pattern = "yyyy-MM-ddTHH:mm:ss.fffffffZ") + private LocalDateTime startTime; + @JsonFormat(pattern = "yyyy-MM-ddTHH:mm:ss.fffffffZ") + private LocalDateTime endTime; + @NotNull + // todo: 似乎不需要(如果不传时间那就需要) + private String academicYearId; +} diff --git a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java index 7fde2f4..4b9f978 100644 --- a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java +++ b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java @@ -24,6 +24,6 @@ public class AppraiseRecordItem { private Boolean pushParent; String creator; String creatorId; - @JsonFormat(pattern = "yyyy-MM-ddTHH:mm:ss.fffffffZ") + @JsonFormat(pattern = "yyyy-MM-ddTHH:mm:ss") private LocalDateTime createTime; } diff --git a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseTreeNode.java b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseTreeNode.java index 5927e9e..8b92f9f 100644 --- a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseTreeNode.java +++ b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseTreeNode.java @@ -17,7 +17,7 @@ public class AppraiseTreeNode { String logo; String creator; String creatorId; - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-ddTHH:mm:ss") LocalDateTime createTime; /** * 排序 diff --git a/src/main/java/cn/teammodel/model/entity/school/Teacher.java b/src/main/java/cn/teammodel/model/entity/school/Teacher.java new file mode 100644 index 0000000..6f91aed --- /dev/null +++ b/src/main/java/cn/teammodel/model/entity/school/Teacher.java @@ -0,0 +1,53 @@ +package cn.teammodel.model.entity.school; + +import cn.teammodel.model.entity.BaseItem; +import com.azure.spring.data.cosmos.core.mapping.Container; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +@EqualsAndHashCode(callSuper = true) +@Container(containerName = "Teacher") +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Teacher extends BaseItem { + private String name; + private String picture; + private int size; + private String defaultSchool; + private List schools; + private List areas; + private List loginInfos; + private long createTime; + //private List binds; + private int lessonLimit; + //private List lessonShow; + private String lang; + private String pk; + + @Data + public static class School { + private String schoolId; + private String name; + private String status; + private long time; + private String picture; + private String areaId; + } + + @Data + public static class Area { + private String areaId; + private String name; + private String status; + } + + @Data + public static class LoginInfo { + private long time; + private String ip; + private long expire; + } +} diff --git a/src/main/java/cn/teammodel/model/vo/admin/RankVo.java b/src/main/java/cn/teammodel/model/vo/admin/RankVo.java new file mode 100644 index 0000000..84a63da --- /dev/null +++ b/src/main/java/cn/teammodel/model/vo/admin/RankVo.java @@ -0,0 +1,14 @@ +package cn.teammodel.model.vo.admin; + +import lombok.Data; + +/** + * @author winter + * @create 2023-12-06 20:17 + */ +@Data +public class RankVo { + private String id; + private String name; + private Integer count; +} diff --git a/src/main/java/cn/teammodel/model/vo/appraise/RecordVo.java b/src/main/java/cn/teammodel/model/vo/appraise/RecordVo.java index 1b5e5bd..b654003 100644 --- a/src/main/java/cn/teammodel/model/vo/appraise/RecordVo.java +++ b/src/main/java/cn/teammodel/model/vo/appraise/RecordVo.java @@ -17,7 +17,7 @@ public class RecordVo { private String avatar; private String targetId; private String targetType; - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-ddTHH:mm:ss") private LocalDateTime createTime; @JsonProperty("isPraise") private boolean isPraise; diff --git a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java index 4ec1db7..b061f77 100644 --- a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java +++ b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java @@ -1,15 +1,16 @@ package cn.teammodel; -import cn.teammodel.admin.service.AdminAppraiseService; +import cn.teammodel.controller.admin.service.AdminAppraiseService; import cn.teammodel.dao.AppraiseRecordRepository; import cn.teammodel.dao.AppraiseRepository; import cn.teammodel.dao.SchoolRepository; import cn.teammodel.dao.StudentRepository; import cn.teammodel.manager.DingAlertNotifier; +import cn.teammodel.model.dto.admin.TimeRangeDto; import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.school.School; -import cn.teammodel.model.vo.admin.IndexData; +import cn.teammodel.model.vo.admin.RankVo; import cn.teammodel.model.vo.appraise.RecordVo; import cn.teammodel.service.EvaluationService; import cn.teammodel.service.impl.EvaluationServiceImpl; @@ -114,6 +115,7 @@ class TeamModelExtensionApplicationTests { //); //System.out.println(record); } + @Test public void testUpdate() { //EvaluationTree saved = evaluationTreeRepository.findBySchoolId("hbcn", new PartitionKey("evaluation")); @@ -175,10 +177,33 @@ class TeamModelExtensionApplicationTests { @Test public void testIndexData() { - IndexData indexData = adminAppraiseService.getIndexData("", "2023-71fbd0bd-9a46-0490-f6b3-7d16cba4c017"); - System.out.println(indexData); + TimeRangeDto timeRangeDto = new TimeRangeDto(); + timeRangeDto.setAcademicYearId("2023-71fbd0bd-9a46-0490-f6b3-7d16cba4c017"); + List list = adminAppraiseService.appraiseNodeRank(timeRangeDto); + System.out.println(list); } +// @Test +// public void batchUpdateTimeFormat() { +// // 批量更改所有 appraiseRecord 的时间格式为标准的 utf +// List appraiseRecords = appraiseRecordRepository.findByCode(String.format(PK.PK_APPRAISE_RECORD, "hbcn")); +// for (AppraiseRecord appraiseRecord : appraiseRecords) { +// List nodes = appraiseRecord.getNodes(); +// // 处理 node 中的时间 +// for (AppraiseRecordItem node : nodes) { +// String createTime = node.getTime(); +// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); +// // 解析字符串 +// LocalDateTime dateTime = LocalDateTime.parse(createTime, formatter); +// node.setTime(dateTime.toString()); +// } +// cosmosTemplate.upsert(appraiseRecord); +// System.out.println("更新完毕"); +// } +// } + @Test + public void batchUpdateTimeFormat() { + } }