diff --git a/src/main/java/cn/teammodel/config/exception/GlobalExceptionHandler.java b/src/main/java/cn/teammodel/config/exception/GlobalExceptionHandler.java index 46c72d0..0962594 100644 --- a/src/main/java/cn/teammodel/config/exception/GlobalExceptionHandler.java +++ b/src/main/java/cn/teammodel/config/exception/GlobalExceptionHandler.java @@ -5,6 +5,7 @@ import cn.teammodel.common.R; import cn.teammodel.manager.NotificationService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; +import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.validation.BindException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingPathVariableException; @@ -39,6 +40,13 @@ public class GlobalExceptionHandler { return ObjectUtils.isNotEmpty(code) ? R.error(code, e.getMessage()) : R.error(e.getMessage()); } + @ExceptionHandler(HttpMessageNotReadableException.class) + public R handleHttpMsgNotReadableException(HttpMessageNotReadableException e, HttpServletRequest request) + { + log.error(e.getMessage(), e); + return R.error(ErrorCode.PARAMS_ERROR.getCode(), "参数格式有误"); + } + /** * 请求路径中缺少必需的路径变量 */ diff --git a/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java b/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java index 6efc72d..f4dc0fd 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java @@ -1,9 +1,12 @@ package cn.teammodel.controller.admin.controller; -import cn.teammodel.controller.admin.service.AdminAppraiseService; import cn.teammodel.common.R; +import cn.teammodel.controller.admin.service.AdminAppraiseService; import cn.teammodel.model.dto.admin.TimeRangeDto; +import cn.teammodel.model.vo.admin.IndexData; +import cn.teammodel.model.vo.admin.RankPo; import cn.teammodel.model.vo.admin.RankVo; +import cn.teammodel.model.vo.admin.StudentRankVo; import cn.teammodel.model.vo.appraise.RecordVo; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -24,10 +27,11 @@ public class IndexController { private AdminAppraiseService adminAppraiseService; - @GetMapping("/") - public String index(){ - //IndexData indexData = adminAppraiseService.getIndexData("", ""); - return null; + @GetMapping("/{academicYearId}") + @ApiOperation("获取首页数据") + public R index(@PathVariable String academicYearId){ + IndexData indexData = adminAppraiseService.getIndexData(academicYearId); + return R.success(indexData); } @PostMapping("latestRecord") @@ -39,20 +43,26 @@ public class IndexController { @PostMapping("classRank") @ApiOperation("班级评价活跃排行榜: Top10") - public R> classRank(@Valid @RequestBody TimeRangeDto timeRangeDto) { - List res = adminAppraiseService.classRank(timeRangeDto); + public R> classRank(@Valid @RequestBody TimeRangeDto timeRangeDto) { + List res = adminAppraiseService.classRank(timeRangeDto); + return R.success(res); + } + @PostMapping("studentRank") + @ApiOperation("学生评价活跃排行榜: Top10") + public R> studentRank(@Valid @RequestBody TimeRangeDto timeRangeDto) { + List res = adminAppraiseService.studentRank(timeRangeDto); return R.success(res); } @PostMapping("teacherRank") - @ApiOperation("班级评价活跃排行榜: Top10") + @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); + @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 index f062c99..eb54621 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java +++ b/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java @@ -2,7 +2,9 @@ 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.RankPo; import cn.teammodel.model.vo.admin.RankVo; +import cn.teammodel.model.vo.admin.StudentRankVo; import cn.teammodel.model.vo.appraise.RecordVo; import java.util.List; @@ -12,16 +14,18 @@ import java.util.List; * @create 2023-12-06 14:45 */ public interface AdminAppraiseService { - IndexData getIndexData(String period, String academicYearId); + IndexData getIndexData(String academicYearId); /** * 按时期分页获取最新的评价数据 */ List conditionLatestRecord(TimeRangeDto timeRangeDto); - List classRank(TimeRangeDto timeRangeDto); + List classRank(TimeRangeDto timeRangeDto); List teacherRank(TimeRangeDto timeRangeDto); - List appraiseNodeRank(TimeRangeDto timeRangeDto); + List appraiseNodeRank(TimeRangeDto timeRangeDto); + + List studentRank(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 index 7729de9..b4eae77 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java @@ -1,18 +1,18 @@ package cn.teammodel.controller.admin.service.impl; -import cn.teammodel.controller.admin.service.AdminAppraiseService; +import cn.hutool.core.lang.Pair; 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.controller.admin.service.AdminAppraiseService; +import cn.teammodel.dao.*; 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.Student; import cn.teammodel.model.entity.school.Teacher; import cn.teammodel.model.vo.admin.IndexData; +import cn.teammodel.model.vo.admin.RankPo; import cn.teammodel.model.vo.admin.RankVo; +import cn.teammodel.model.vo.admin.StudentRankVo; import cn.teammodel.model.vo.appraise.RecordVo; import cn.teammodel.security.utils.SecurityUtil; import com.azure.spring.data.cosmos.core.query.CosmosPageRequest; @@ -22,7 +22,9 @@ import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.time.Instant; import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.time.temporal.WeekFields; import java.util.*; import java.util.stream.Collectors; @@ -38,22 +40,25 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService { @Resource private TeacherRepository teacherRepository; @Resource + private StudentRepository studentRepository; + @Resource private AppraiseRepository appraiseRepository; @Resource private AppraiseRecordRepository appraiseRecordRepository; @Override - public IndexData getIndexData(String period, String academicYearId) { + public IndexData getIndexData(String academicYearId) { final IndexData indexData = new IndexData(); int totalCount = 0; int criticalCount = 0; + Set creatorIdSet = new HashSet<>(); User loginUser = SecurityUtil.getLoginUser(); String schoolId = loginUser.getSchoolId(); // slice 分段读取 - CosmosPageRequest pageRequest = new CosmosPageRequest(0, 10, null); + CosmosPageRequest pageRequest = new CosmosPageRequest(0, 100, null); Slice slice; Map countByWeek = new HashMap<>(); @@ -75,6 +80,8 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService { if (!item.isPraise()) { criticalCount++; } + // 处理已评价老师总数 + creatorIdSet.add(item.getCreatorId()); } if (slice.hasNext()) { @@ -87,13 +94,14 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService { indexData.setTotalCount(totalCount); indexData.setCriticalCount(criticalCount); indexData.setPraiseCount(totalCount - criticalCount); + indexData.setTeacherCount(creatorIdSet.size()); return indexData; } @Override public List conditionLatestRecord(TimeRangeDto timeRangeDto) { - LocalDateTime startTime = timeRangeDto.getStartTime(); - LocalDateTime endTime = timeRangeDto.getEndTime(); + Long startTime = timeRangeDto.getStartTime(); + Long endTime = timeRangeDto.getEndTime(); String academicYearId = timeRangeDto.getAcademicYearId(); Integer current = timeRangeDto.getCurrent(); Integer size = timeRangeDto.getSize(); @@ -103,77 +111,170 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService { Page page = appraiseRecordRepository.pageLatestRecords( String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, - startTime.toString(), - endTime.toString(), + startTime, + endTime, 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(); + public List classRank(TimeRangeDto timeRangeDto) { + // todo 不要 page| 批评和表扬数量 + Long startTime = timeRangeDto.getStartTime(); + Long endTime = timeRangeDto.getEndTime(); String academicYearId = timeRangeDto.getAcademicYearId(); String schoolId = SecurityUtil.getLoginUser().getSchoolId(); - List rankVoList = appraiseRecordRepository.classRank( + List rankPoList = appraiseRecordRepository.classRank( String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, startTime, endTime ); - Set classIdSet = rankVoList.stream().map(RankVo::getId).collect(Collectors.toSet()); + if (ObjectUtils.isEmpty(rankPoList)) return null; + Set classIdSet = rankPoList.stream().map(RankPo::getId).collect(Collectors.toSet()); // 注意: 如果查询 in 的查询集在数据库中不存在,则在结果集也不会为 null. + if (ObjectUtils.isEmpty(classIdSet)) return rankPoList; 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; + rankPoList.forEach(rankVo -> rankVo.setName(idNameMap.get(rankVo.getId()))); + return rankPoList; } @Override public List teacherRank(TimeRangeDto timeRangeDto) { - String startTime = timeRangeDto.getStartTime() == null ? null : timeRangeDto.getStartTime().toString(); - String endTime = timeRangeDto.getEndTime() == null ? null : timeRangeDto.getEndTime().toString(); + Long startTime = timeRangeDto.getStartTime(); + Long endTime = timeRangeDto.getEndTime(); String academicYearId = timeRangeDto.getAcademicYearId(); String schoolId = SecurityUtil.getLoginUser().getSchoolId(); - List rankVoList = appraiseRecordRepository.teacherRank( + List rankPoList = appraiseRecordRepository.teacherRank( String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, startTime, endTime ); - Set teacherIdSet = rankVoList.stream().map(RankVo::getId).collect(Collectors.toSet()); + // 根据 id 分组 + Map> idRankPoMap = rankPoList.stream().collect(Collectors.groupingBy(RankPo::getId)); + final List rankVos = new ArrayList<>(); + + idRankPoMap.forEach((id, list) -> { + RankVo rankVo = new RankVo(); + int praiseCount = 0; + int criticalCount = 0; + rankVo.setId(id); + + for (RankPo po : list) { + if (po.getIsPraise()) { + praiseCount += po.getCount(); + } else { + criticalCount += po.getCount(); + } + } + rankVo.setPraiseCount(praiseCount); + rankVo.setCriticalCount(criticalCount); + rankVo.setTotalCount(praiseCount + criticalCount); + rankVos.add(rankVo); + }); + // 排序 + List res = rankVos.stream() + .sorted(Comparator.comparing(RankVo::getTotalCount).reversed()) + .collect(Collectors.toList()); + // 设置 name + if (ObjectUtils.isEmpty(res)) return null; + Set teacherIdSet = res.stream().map(RankVo::getId).collect(Collectors.toSet()); + if (ObjectUtils.isEmpty(teacherIdSet)) return res; 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; + res.forEach(rankVo -> rankVo.setName(idNameMap.get(rankVo.getId()))); + return res; } @Override - public List appraiseNodeRank(TimeRangeDto timeRangeDto) { - String startTime = timeRangeDto.getStartTime() == null ? null : timeRangeDto.getStartTime().toString(); - String endTime = timeRangeDto.getEndTime() == null ? null : timeRangeDto.getEndTime().toString(); + public List appraiseNodeRank(TimeRangeDto timeRangeDto) { + Long startTime = timeRangeDto.getStartTime(); + Long endTime = timeRangeDto.getEndTime(); String academicYearId = timeRangeDto.getAcademicYearId(); String schoolId = SecurityUtil.getLoginUser().getSchoolId(); - List rankVoList = appraiseRecordRepository.appraiseNodeRank( + List rankPoList = 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; + if (rankPoList == null) return null; + rankPoList = rankPoList.stream() + .sorted(Comparator.comparing(RankPo::getCount).reversed()) + .collect(Collectors.toList()); + + return rankPoList; + } + + @Override + public List studentRank(TimeRangeDto timeRangeDto) { + Long startTime = timeRangeDto.getStartTime(); + Long endTime = timeRangeDto.getEndTime(); + String academicYearId = timeRangeDto.getAcademicYearId(); + String schoolId = SecurityUtil.getLoginUser().getSchoolId(); + + List rankPoList = appraiseRecordRepository.studentRank( + String.format(PK.PK_APPRAISE_RECORD, schoolId), + academicYearId, + startTime, + endTime + ); + // 根据 id 分组 + Map> idRankPoMap = rankPoList.stream().collect(Collectors.groupingBy(RankPo::getId)); + final List rankVos = new ArrayList<>(); + + idRankPoMap.forEach((id, list) -> { + StudentRankVo rankVo = new StudentRankVo(); + int praiseCount = 0; + int criticalCount = 0; + rankVo.setId(id); + + for (RankPo po : list) { + if (po.getIsPraise()) { + praiseCount += po.getCount(); + } else { + criticalCount += po.getCount(); + } + } + rankVo.setPraiseCount(praiseCount); + rankVo.setCriticalCount(criticalCount); + rankVo.setTotalCount(praiseCount + criticalCount); + rankVos.add(rankVo); + }); + // 排序 + List res = rankVos.stream() + .sorted(Comparator.comparing(StudentRankVo::getTotalCount).reversed()) + .collect(Collectors.toList()); + // 设置 student name + if (ObjectUtils.isEmpty(res)) return null; + Set studentIdSet = res.stream().map(StudentRankVo::getId).collect(Collectors.toSet()); + if (ObjectUtils.isEmpty(studentIdSet)) return res; + List students = studentRepository.findAllByCodeAndIdIn(String.format(PK.STUDENT, schoolId), studentIdSet); + // 提取 Student 中的 name 和 classId + Map> idNameMap = students.stream().collect(Collectors.toMap(Student::getId, item -> new Pair<>(item.getName(), item.getClassId()))); + res.forEach(rankVo -> { + rankVo.setName(idNameMap.get(rankVo.getId()).getKey()); + rankVo.setClassName(idNameMap.get(rankVo.getId()).getValue()); + }); + + // 设置 class name + Set classIds = students.stream().map(Student::getClassId).collect(Collectors.toSet()); + List classes = classRepository.findAllByCodeAndIdIn(String.format(PK.CLASS, schoolId), classIds); + Map idClassNameMap = classes.stream().collect(Collectors.toMap(ClassInfo::getId, ClassInfo::getName)); + res.forEach(rankVo -> rankVo.setClassName(idClassNameMap.getOrDefault(rankVo.getClassName(), null))); + return res; } - private int calculateWeekNum(LocalDateTime localDateTime) { + private int calculateWeekNum(Long timeStamp) { + // second 时间戳转 LocalDateTime + LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(timeStamp), ZoneOffset.UTC); // 获取周字段 todo: 时区或者周的计算 WeekFields weekFields = WeekFields.of(Locale.getDefault()); // 获取当前日期时间所在年的周数 diff --git a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java index b63a7e0..9f2ce5f 100644 --- a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java +++ b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java @@ -1,7 +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.admin.RankPo; import cn.teammodel.model.vo.appraise.AppraiseRecordVo; import cn.teammodel.model.vo.appraise.RecordVo; import com.azure.spring.data.cosmos.repository.CosmosRepository; @@ -60,20 +60,20 @@ public interface AppraiseRecordRepository extends CosmosRepository findAllByAcademicYearId(String code, String academicYearId, Pageable pageable); /** * 最新的评价明细,分页 */ // todo: 调整一下数据结构 - @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 " + - "c.code = @code and" + - "c.academicYearId = @academicYearId and" + - "(IS_NULL(@startTime) or c.createTime >= @startTime) and" + - "(IS_NULL(@endTime) or c.createTime <= @endTime)" + + @Query("select c.id as recordId, c.name as targetName, c.avatar, c.className, 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.academicYearId = @academicYearId and " + + "(IS_NULL(@startTime) or n.createTime >= @startTime) and " + + "(IS_NULL(@endTime) or n.createTime <= @endTime) " + "order by c.createTime desc") - Page pageLatestRecords(String code, String academicYearId, String startTime, String endTime, Pageable pageable); + Page pageLatestRecords(String code, String academicYearId, Long startTime, Long endTime, Pageable pageable); @Query("select c.classId as id, count(1) as count from Student as c join n in c.nodes where( " + @@ -82,21 +82,36 @@ public interface AppraiseRecordRepository extends CosmosRepository= @startTime) and " + "(IS_NULL(@endTime) or n.createTime <= @endTime) " + "group by c.classId") - List classRank(String code, String academicYearId, String startTime, String endTime); + List classRank(String code, String academicYearId, Long startTime, Long endTime); + + @Query("select n.creatorId as id, n.appraiseNode.isPraise, 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, n.appraiseNode.isPraise") + List teacherRank(String code, String academicYearId, Long startTime, Long endTime); - @Query("select n.creatorId as id, count(1) as count from Student as c join n in c.nodes where " + + @Query("select n.appraiseNode.name as name, 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); + "group by n.appraiseNode.name") + List appraiseNodeRank(String code, String academicYearId, Long startTime, Long endTime); - @Query("select n.appraiseNode.id as id, count(1) as count from Student as c join n in c.nodes where " + + /** + * 仅针对学生,不包括班级评价 + */ + @Query("select c.targetId as id, n.appraiseNode.isPraise, 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.targetType = 'student') and " + "(c.code = @code) " + - "group by n.appraiseNode.id") - List appraiseNodeRank(String code, String academicYearId, String startTime, String endTime); + "group by c.targetId, n.appraiseNode.isPraise") + List studentRank(String code, String academicYearId, Long startTime, Long endTime); + + @Query("select * from Student as c where c.code = @code") + List findByCode(String code); } diff --git a/src/main/java/cn/teammodel/dao/StudentRepository.java b/src/main/java/cn/teammodel/dao/StudentRepository.java index ee3ce64..82154e2 100644 --- a/src/main/java/cn/teammodel/dao/StudentRepository.java +++ b/src/main/java/cn/teammodel/dao/StudentRepository.java @@ -6,6 +6,7 @@ import com.azure.spring.data.cosmos.repository.Query; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Set; @Repository public interface StudentRepository extends CosmosRepository { @@ -14,4 +15,7 @@ public interface StudentRepository extends CosmosRepository { @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 findByIdAndCode(String id, String code); + + @Query("select c.id, c.name, c.classId from Student as c where c.code = @code and c.id in (@ids)") + List findAllByCodeAndIdIn(String code, Set ids); } \ No newline at end of file diff --git a/src/main/java/cn/teammodel/model/dto/admin/TimeRangeDto.java b/src/main/java/cn/teammodel/model/dto/admin/TimeRangeDto.java index d88091e..e3bf011 100644 --- a/src/main/java/cn/teammodel/model/dto/admin/TimeRangeDto.java +++ b/src/main/java/cn/teammodel/model/dto/admin/TimeRangeDto.java @@ -1,12 +1,10 @@ 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 @@ -15,10 +13,8 @@ import java.time.LocalDateTime; @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; + private Long startTime; + private Long 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 4b9f978..3c17d07 100644 --- a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java +++ b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java @@ -1,11 +1,8 @@ package cn.teammodel.model.entity.appraise; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; -import java.time.LocalDateTime; - /** * 评价项 * @author winter @@ -24,6 +21,5 @@ public class AppraiseRecordItem { private Boolean pushParent; String creator; String creatorId; - @JsonFormat(pattern = "yyyy-MM-ddTHH:mm:ss") - private LocalDateTime createTime; + private Long 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 8b92f9f..f6387e6 100644 --- a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseTreeNode.java +++ b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseTreeNode.java @@ -1,11 +1,9 @@ package cn.teammodel.model.entity.appraise; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; -import java.time.LocalDateTime; import java.util.List; @Data @@ -17,8 +15,7 @@ public class AppraiseTreeNode { String logo; String creator; String creatorId; - @JsonFormat(pattern = "yyyy-MM-ddTHH:mm:ss") - LocalDateTime createTime; + Long createTime; /** * 排序 */ diff --git a/src/main/java/cn/teammodel/model/vo/admin/IndexData.java b/src/main/java/cn/teammodel/model/vo/admin/IndexData.java index 29e96b0..abd30fd 100644 --- a/src/main/java/cn/teammodel/model/vo/admin/IndexData.java +++ b/src/main/java/cn/teammodel/model/vo/admin/IndexData.java @@ -13,5 +13,6 @@ public class IndexData { private Integer totalCount; private Integer praiseCount; private Integer criticalCount; + private Integer teacherCount; private Map countByWeek; } diff --git a/src/main/java/cn/teammodel/model/vo/admin/RankPo.java b/src/main/java/cn/teammodel/model/vo/admin/RankPo.java new file mode 100644 index 0000000..85f5df4 --- /dev/null +++ b/src/main/java/cn/teammodel/model/vo/admin/RankPo.java @@ -0,0 +1,17 @@ +package cn.teammodel.model.vo.admin; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * @author winter + * @create 2023-12-06 20:17 + */ +@Data +public class RankPo { + private String id; + private String name; + @JsonProperty("isPraise") + private Boolean isPraise; + private Integer count; +} diff --git a/src/main/java/cn/teammodel/model/vo/admin/RankVo.java b/src/main/java/cn/teammodel/model/vo/admin/RankVo.java index 84a63da..441bb03 100644 --- a/src/main/java/cn/teammodel/model/vo/admin/RankVo.java +++ b/src/main/java/cn/teammodel/model/vo/admin/RankVo.java @@ -10,5 +10,7 @@ import lombok.Data; public class RankVo { private String id; private String name; - private Integer count; + private Integer praiseCount; + private Integer criticalCount; + private Integer totalCount; } diff --git a/src/main/java/cn/teammodel/model/vo/admin/StudentRankVo.java b/src/main/java/cn/teammodel/model/vo/admin/StudentRankVo.java new file mode 100644 index 0000000..04d1216 --- /dev/null +++ b/src/main/java/cn/teammodel/model/vo/admin/StudentRankVo.java @@ -0,0 +1,14 @@ +package cn.teammodel.model.vo.admin; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @author winter + * @create 2023-12-07 17:14 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class StudentRankVo extends RankVo{ + private String className; +} 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 b654003..ca1af08 100644 --- a/src/main/java/cn/teammodel/model/vo/appraise/RecordVo.java +++ b/src/main/java/cn/teammodel/model/vo/appraise/RecordVo.java @@ -1,11 +1,8 @@ package cn.teammodel.model.vo.appraise; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; -import java.time.LocalDateTime; - /** * @author winter * @create 2023-12-06 17:43 @@ -13,12 +10,14 @@ import java.time.LocalDateTime; @Data public class RecordVo { private String recordId; - private String name; + private String targetName; private String avatar; + private String appraiseName; private String targetId; private String targetType; - @JsonFormat(pattern = "yyyy-MM-ddTHH:mm:ss") - private LocalDateTime createTime; + private String creatorId; + private String creator; + private Long createTime; @JsonProperty("isPraise") private boolean isPraise; } diff --git a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java index feae83b..14baa57 100644 --- a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java @@ -29,8 +29,8 @@ import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.time.Instant; import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -180,7 +180,7 @@ public class EvaluationServiceImpl implements EvaluationService { newNode.setId(UUID.randomUUID().toString()); newNode.setCreatorId(loginUser.getId()); newNode.setCreator(loginUser.getName()); - newNode.setCreateTime(LocalDateTime.now()); + newNode.setCreateTime(Instant.now().getEpochSecond()); originNodes.add(newNode); return buildTree(appraiseRepository.save(appraise)); @@ -293,7 +293,7 @@ public class EvaluationServiceImpl implements EvaluationService { item.setAppraiseNode(appraiseTreeNode); item.setCreator(loginUser.getName()); item.setCreatorId(loginUser.getId()); - item.setCreateTime(LocalDateTime.now()); + item.setCreateTime(Instant.now().getEpochSecond()); // 处理学校与学生的差异 if (targetType.equals(TARGET_CLASS)){ item.setSpread(spread); diff --git a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java index b061f77..c5722a6 100644 --- a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java +++ b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java @@ -1,5 +1,6 @@ package cn.teammodel; +import cn.teammodel.common.PK; import cn.teammodel.controller.admin.service.AdminAppraiseService; import cn.teammodel.dao.AppraiseRecordRepository; import cn.teammodel.dao.AppraiseRepository; @@ -8,9 +9,10 @@ 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.AppraiseRecord; import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.school.School; -import cn.teammodel.model.vo.admin.RankVo; +import cn.teammodel.model.vo.admin.RankPo; import cn.teammodel.model.vo.appraise.RecordVo; import cn.teammodel.service.EvaluationService; import cn.teammodel.service.impl.EvaluationServiceImpl; @@ -179,31 +181,31 @@ class TeamModelExtensionApplicationTests { public void testIndexData() { TimeRangeDto timeRangeDto = new TimeRangeDto(); timeRangeDto.setAcademicYearId("2023-71fbd0bd-9a46-0490-f6b3-7d16cba4c017"); - List list = adminAppraiseService.appraiseNodeRank(timeRangeDto); + 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) { + @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"); +// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); // // 解析字符串 // LocalDateTime dateTime = LocalDateTime.parse(createTime, formatter); -// node.setTime(dateTime.toString()); +// node.setTime(String.valueOf(dateTime.toEpochSecond(ZoneOffset.UTC))); // } -// cosmosTemplate.upsert(appraiseRecord); -// System.out.println("更新完毕"); -// } -// } - - @Test - public void batchUpdateTimeFormat() { - + cosmosTemplate.upsert(appraiseRecord); + System.out.println("更新完毕"); + } } + +// @Test +// public void batchUpdateTimeFormat() { +// +// } }