feat: 值周巡检首页数据总览接口

11111
winter 10 months ago
parent 09140678bc
commit da1bb7fc87

@ -4,8 +4,10 @@ import cn.teammodel.common.R;
import cn.teammodel.controller.admin.service.AdminIndexDutyService;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto;
import cn.teammodel.model.dto.admin.weekduty.AdminFindDutyRecordDto;
import cn.teammodel.model.vo.admin.AppraiseNodeRankVo;
import cn.teammodel.model.vo.admin.DutyIndexData;
import cn.teammodel.model.vo.appraise.RecordVo;
import cn.teammodel.model.vo.admin.DutyNodeRankVo;
import cn.teammodel.model.vo.admin.DutyRankPo;
import cn.teammodel.model.vo.weekDuty.DutyRecordVo;
import cn.teammodel.service.DutyService;
import io.swagger.annotations.Api;
@ -44,12 +46,23 @@ public class AdminDutyController {
return R.success(dutyIndexData);
}
@PostMapping("index/latestRecord")
@ApiOperation("查询时间范围最近评价(无参则当前周的所有记录)")
public R<List<RecordVo>> latestRecord(@Valid @RequestBody TimeRangeDto timeRangeDto) {
List<RecordVo> res = adminIndexDutyService.conditionLatestRecord(timeRangeDto);
@PostMapping("classRank")
@ApiOperation("班级评价活跃排行榜: Top10")
public R<List<DutyRankPo>> classRank(@Valid @RequestBody TimeRangeDto timeRangeDto) {
List<DutyRankPo> res = adminIndexDutyService.classRank(timeRangeDto);
return R.success(res);
}
@PostMapping("teacherRank")
@ApiOperation("老师评价活跃排行榜: Top10")
public R<List<DutyRankPo>> teacherRank(@Valid @RequestBody TimeRangeDto timeRangeDto) {
List<DutyRankPo> res = adminIndexDutyService.teacherRank(timeRangeDto);
return R.success(res);
}
@PostMapping("dutyNodeRank")
@ApiOperation("评价指标活跃排行榜: Top10")
public R<List<DutyNodeRankVo>> appraiseNodeRank(@Valid @RequestBody TimeRangeDto timeRangeDto) {
List<DutyNodeRankVo> res = adminIndexDutyService.appraiseNodeRank(timeRangeDto);
return R.success(res);
}
}

@ -2,7 +2,8 @@ package cn.teammodel.controller.admin.service;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto;
import cn.teammodel.model.vo.admin.DutyIndexData;
import cn.teammodel.model.vo.appraise.RecordVo;
import cn.teammodel.model.vo.admin.DutyNodeRankVo;
import cn.teammodel.model.vo.admin.DutyRankPo;
import java.util.List;
@ -13,5 +14,9 @@ import java.util.List;
public interface AdminIndexDutyService {
DutyIndexData getIndexData(String periodId);
List<RecordVo> conditionLatestRecord(TimeRangeDto timeRangeDto);
List<DutyRankPo> classRank(TimeRangeDto timeRangeDto);
List<DutyRankPo> teacherRank(TimeRangeDto timeRangeDto);
List<DutyNodeRankVo> appraiseNodeRank(TimeRangeDto timeRangeDto);
}

@ -254,12 +254,13 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService {
// 去重后的 nodes
List<AppraiseTreeNode> nodesByName = appraiseRecordRepository.findAppraiseRecordInNames(String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, names);
// 正常情况下 name 一一对应 todo: 临时解决
Map<String, AppraiseTreeNode> nameNodeMap = nodesByName.stream().collect(Collectors.toMap(AppraiseTreeNode::getName, item -> item, (existing, replacement) -> {
if (replacement.getPath() != null) {
return replacement;
}
return existing;
}));
Map<String, AppraiseTreeNode> nameNodeMap = nodesByName.stream()
.collect(Collectors.toMap(AppraiseTreeNode::getName, item -> item, (existing, replacement) -> {
if (replacement.getPath() != null) {
return replacement;
}
return existing;
}));
rankVoList = rankVoList.stream()
.sorted(Comparator.comparing(RankPo::getCount).reversed())
@ -324,7 +325,7 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService {
Map<String, String[]> idNameMap = students.stream().collect(Collectors.toMap(Student::getId, item -> {
String[] studentInfo = new String[3];
studentInfo[0] = item.getName();
studentInfo[1]= item.getClassId();
studentInfo[1] = item.getClassId();
studentInfo[2] = item.getPicture();
return studentInfo;
}));

@ -6,13 +6,18 @@ import cn.teammodel.config.exception.ServiceException;
import cn.teammodel.controller.admin.service.AdminIndexDutyService;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto;
import cn.teammodel.model.entity.User;
import cn.teammodel.model.entity.school.ClassInfo;
import cn.teammodel.model.entity.school.School;
import cn.teammodel.model.entity.school.Teacher;
import cn.teammodel.model.entity.weekDuty.WeekDuty;
import cn.teammodel.model.vo.admin.DutyIndexData;
import cn.teammodel.model.vo.admin.DutyIndexPo;
import cn.teammodel.model.vo.appraise.RecordVo;
import cn.teammodel.model.vo.admin.DutyNodeRankVo;
import cn.teammodel.model.vo.admin.DutyRankPo;
import cn.teammodel.repository.ClassRepository;
import cn.teammodel.repository.DutyRecordRepository;
import cn.teammodel.repository.DutyRepository;
import cn.teammodel.repository.SchoolRepository;
import cn.teammodel.repository.TeacherRepository;
import cn.teammodel.security.utils.SecurityUtil;
import cn.teammodel.utils.SchoolDateUtil;
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest;
@ -24,10 +29,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import static cn.teammodel.utils.SchoolDateUtil.calculateWeekNum;
@ -42,8 +45,10 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService {
private SchoolRepository schoolRepository;
@Resource
private DutyRepository dutyRepository;
private TeacherRepository teacherRepository;
@Resource
private ClassRepository classRepository;
@Resource
private DutyRecordRepository dutyRecordRepository;
@ -116,7 +121,76 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService {
}
@Override
public List<RecordVo> conditionLatestRecord(TimeRangeDto timeRangeDto) {
return null;
public List<DutyRankPo> classRank(TimeRangeDto timeRangeDto) {
Long startTime = timeRangeDto.getStartTime();
Long endTime = timeRangeDto.getEndTime();
String academicYearId = timeRangeDto.getAcademicYearId();
String schoolId = SecurityUtil.getLoginUser().getSchoolId();
List<DutyRankPo> res = dutyRecordRepository.classRank(String.format(PK.WEEK_DUTY_RECORD, schoolId), academicYearId, startTime, endTime);
if (ObjectUtils.isEmpty(res)) return null;
List<String> classIds = res.stream().map(DutyRankPo::getId).collect(Collectors.toList());
if (ObjectUtils.isEmpty(classIds)) {
return null;
}
List<ClassInfo> classes = classRepository.findAllByCodeAndIdIn(String.format(PK.CLASS, schoolId), classIds);
Map<String, String> idNameMap = classes.stream().collect(Collectors.toMap(ClassInfo::getId, ClassInfo::getName));
// reversed sort by score
res = res.stream().peek(s -> s.setName(idNameMap.get(s.getId()))).sorted((a, b) -> b.getScore() - a.getScore()).collect(Collectors.toList());
return res;
}
@Override
public List<DutyRankPo> teacherRank(TimeRangeDto timeRangeDto) {
Long startTime = timeRangeDto.getStartTime();
Long endTime = timeRangeDto.getEndTime();
String academicYearId = timeRangeDto.getAcademicYearId();
String schoolId = SecurityUtil.getLoginUser().getSchoolId();
List<DutyRankPo> res = dutyRecordRepository.teacherRank(String.format(PK.WEEK_DUTY_RECORD, schoolId), academicYearId, startTime, endTime);
// set teacher name
if (ObjectUtils.isEmpty(res)) return null;
Set<String> teacherIdSet = res.stream().map(DutyRankPo::getId).collect(Collectors.toSet());
if (ObjectUtils.isEmpty(teacherIdSet)) return res;
List<Teacher> teachers = teacherRepository.findAllByCodeAndIdIn(PK.COMMON_BASE, teacherIdSet);
Map<String, String> idNameMap = teachers.stream().collect(Collectors.toMap(Teacher::getId, Teacher::getName));
res = res.stream().peek(s -> s.setName(idNameMap.get(s.getId()))).sorted((a, b) -> b.getScore() - a.getScore()).collect(Collectors.toList());
return res;
}
@Override
public List<DutyNodeRankVo> appraiseNodeRank(TimeRangeDto timeRangeDto) {
Long startTime = timeRangeDto.getStartTime();
Long endTime = timeRangeDto.getEndTime();
String academicYearId = timeRangeDto.getAcademicYearId();
String schoolId = SecurityUtil.getLoginUser().getSchoolId();
List<DutyNodeRankVo> res = dutyRecordRepository.dutyNodeRank(String.format(PK.WEEK_DUTY_RECORD, schoolId), academicYearId, startTime, endTime);
if (ObjectUtils.isEmpty(res)) return null;
List<String> names = res.stream().map(DutyNodeRankVo::getName).collect(Collectors.toList());
if (ObjectUtils.isEmpty(names)) return null;
// 去重后的 nodes
List<WeekDuty.DutyTreeNode> nodesByName = dutyRecordRepository.findDutyRecordInNames(String.format(PK.WEEK_DUTY_RECORD, schoolId), academicYearId, names);
// 正常情况下 name 一一对应 // TODO: 2024/2/29
Map<String, WeekDuty.DutyTreeNode> nameNodeMap = nodesByName.stream()
.collect(Collectors.toMap(WeekDuty.DutyTreeNode::getName, item -> item, (existing, replacement) -> {
if (replacement.getPath() != null) {
return replacement;
}
return existing;
}));
res = res.stream()
.sorted(Comparator.comparing(DutyNodeRankVo::getCount).reversed())
// 流中对元素操作但不改变流
.peek(s -> {
WeekDuty.DutyTreeNode node = nameNodeMap.get(s.getName());
if (node != null) {
s.setPath(node.getPath());
s.setScore(node.getScore());
}
})
.collect(Collectors.toList());
return res;
}
}

@ -12,6 +12,6 @@ public class TimeRangeDto {
private Long startTime;
private Long endTime;
@NotNull
// todo: 似乎不需要(如果不传时间那就需要)
// todo: 似乎不需要(有时间范围就不需要这个字段来划分时间,如果不传时间那就需要)
private String academicYearId;
}

@ -0,0 +1,15 @@
package cn.teammodel.model.vo.admin;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author winter
* @create 2024-02-29 15:36
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class DutyNodeRankVo extends DutyRankPo {
private Integer count;
private String[] path;
}

@ -0,0 +1,14 @@
package cn.teammodel.model.vo.admin;
import lombok.Data;
/**
* @author winter
* @create 2024-02-29 11:39
*/
@Data
public class DutyRankPo {
private String id;
private String name;
private Integer score;
}

@ -1,6 +1,9 @@
package cn.teammodel.repository;
import cn.teammodel.model.entity.weekDuty.WeekDuty;
import cn.teammodel.model.entity.weekDuty.WeekDutyRecord;
import cn.teammodel.model.vo.admin.DutyNodeRankVo;
import cn.teammodel.model.vo.admin.DutyRankPo;
import cn.teammodel.model.vo.admin.DutyIndexPo;
import cn.teammodel.model.vo.weekDuty.DutyRecordVo;
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest;
@ -31,5 +34,35 @@ public interface DutyRecordRepository extends CosmosRepository<WeekDutyRecord, S
@Query("select n.id as dutyRecordNodeId, n.dutyTreeNode.id as dutyTreeNodeId, n.dutyTreeNode.name as dutyTreeNodeName, n.dutyTreeNode.score as dutyTreeNodeScore, c.classId, n.creatorId, n.createTime from School as c join n in c.nodes where c.academicYearId = @academicYearId and c.code = @code")
Slice<DutyIndexPo> findAllByAcademicYearId(String code, String academicYearId, CosmosPageRequest pageRequest);
@Query("select SUM(n.dutyTreeNode.score) as score, c.classId as id from School as c join n in c.nodes where " +
"c.academicYearId = @academicYearId and " +
"c.code = @code and " +
"(IS_NULL(@startTime) or n.createTime >= @startTime) and " +
"(IS_NULL(@endTime) or n.createTime <= @endTime) " +
"group by c.classId")
List<DutyRankPo> classRank(String code, String academicYearId, Long startTime, Long endTime);
@Query("select count(n.creatorId) as score, n.creatorId as id from School as c join n in c.nodes where " +
"c.academicYearId = @academicYearId and " +
"c.code = @code and " +
"(IS_NULL(@startTime) or n.createTime >= @startTime) and " +
"(IS_NULL(@endTime) or n.createTime <= @endTime) " +
"group by n.creatorId")
List<DutyRankPo> teacherRank(String code, String academicYearId, Long startTime, Long endTime);
@Query("select count(n.dutyTreeNode.name) as count, n.dutyTreeNode.name from School as c join n in c.nodes where " +
"c.academicYearId = @academicYearId and " +
"c.code = @code and " +
"(IS_NULL(@startTime) or n.createTime >= @startTime) and " +
"(IS_NULL(@endTime) or n.createTime <= @endTime) " +
"group by n.dutyTreeNode.name")
List<DutyNodeRankVo> dutyNodeRank(String code, String academicYearId, Long startTime, Long endTime);
@Query("select n.dutyTreeNode.name, n.dutyTreeNode.path, n.dutyTreeNode.score from School as c join n in c.nodes where " +
"c.academicYearId = @academicYearId and " +
"c.code = @code and " +
"n.dutyTreeNode.name in (@names)")
List<WeekDuty.DutyTreeNode> findDutyRecordInNames(String code, String academicYearId, List<String> names);
}

Loading…
Cancel
Save