feat: 新增首页数据展示

11111
winter 10 months ago
parent 9ff280a94e
commit 09140678bc

@ -1,14 +1,16 @@
package cn.teammodel.controller.admin.controller; package cn.teammodel.controller.admin.controller;
import cn.teammodel.common.R; 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.dto.admin.weekduty.AdminFindDutyRecordDto;
import cn.teammodel.model.dto.weekDuty.FindDutyRecordDto; import cn.teammodel.model.vo.admin.DutyIndexData;
import cn.teammodel.model.vo.appraise.RecordVo;
import cn.teammodel.model.vo.weekDuty.DutyRecordVo; import cn.teammodel.model.vo.weekDuty.DutyRecordVo;
import cn.teammodel.service.DutyService; import cn.teammodel.service.DutyService;
import org.springframework.web.bind.annotation.PostMapping; import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestBody; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid; import javax.validation.Valid;
@ -20,16 +22,34 @@ import java.util.List;
*/ */
@RestController @RestController
@RequestMapping("admin/duty") @RequestMapping("admin/duty")
@Api(tags = "管理员端-值周巡检")
public class AdminDutyController { public class AdminDutyController {
@Resource @Resource
private DutyService dutyService; private DutyService dutyService;
@Resource
private AdminIndexDutyService adminIndexDutyService;
@PostMapping("records") @PostMapping("records")
@ApiOperation("获取班级评价数据")
public R<List<DutyRecordVo>> findRecords(@Valid @RequestBody AdminFindDutyRecordDto adminFindDutyRecordDto) { public R<List<DutyRecordVo>> findRecords(@Valid @RequestBody AdminFindDutyRecordDto adminFindDutyRecordDto) {
List<DutyRecordVo> res = dutyService.findAdminRecords(adminFindDutyRecordDto); List<DutyRecordVo> res = dutyService.findAdminRecords(adminFindDutyRecordDto);
return R.success(res); return R.success(res);
} }
@GetMapping("index/{periodId}")
@ApiOperation("获取首页数据")
public R<DutyIndexData> index(@PathVariable String periodId){
DutyIndexData dutyIndexData = adminIndexDutyService.getIndexData(periodId);
return R.success(dutyIndexData);
}
@PostMapping("index/latestRecord")
@ApiOperation("查询时间范围最近评价(无参则当前周的所有记录)")
public R<List<RecordVo>> latestRecord(@Valid @RequestBody TimeRangeDto timeRangeDto) {
List<RecordVo> res = adminIndexDutyService.conditionLatestRecord(timeRangeDto);
return R.success(res);
}
} }

@ -28,9 +28,9 @@ public class IndexController {
@GetMapping("/{periodId}") @GetMapping("/{periodId}")
@ApiOperation("获取首页数据") @ApiOperation("获取首页数据")
public R<IndexData> index(@PathVariable String periodId){ public R<AppraiseIndexData> index(@PathVariable String periodId){
IndexData indexData = adminAppraiseService.getIndexData(periodId); AppraiseIndexData appraiseIndexData = adminAppraiseService.getIndexData(periodId);
return R.success(indexData); return R.success(appraiseIndexData);
} }
@PostMapping("latestRecord") @PostMapping("latestRecord")

@ -13,7 +13,7 @@ import java.util.List;
* @create 2023-12-06 14:45 * @create 2023-12-06 14:45
*/ */
public interface AdminAppraiseService { public interface AdminAppraiseService {
IndexData getIndexData(String periodId); AppraiseIndexData getIndexData(String periodId);
/** /**
* *

@ -0,0 +1,17 @@
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 java.util.List;
/**
* @author winter
* @create 2024-02-28 15:07
*/
public interface AdminIndexDutyService {
DutyIndexData getIndexData(String periodId);
List<RecordVo> conditionLatestRecord(TimeRangeDto timeRangeDto);
}

@ -57,13 +57,13 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService {
private AppraiseRecordRepository appraiseRecordRepository; private AppraiseRecordRepository appraiseRecordRepository;
@Override @Override
public IndexData getIndexData(String periodId) { public AppraiseIndexData getIndexData(String periodId) {
final int SLICE_SIZE = 100; final int SLICE_SIZE = 100;
if (StringUtils.isBlank(periodId)) { if (StringUtils.isBlank(periodId)) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "不能为空"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "不能为空");
} }
final IndexData indexData = new IndexData(); final AppraiseIndexData appraiseIndexData = new AppraiseIndexData();
int totalCount = 0; int totalCount = 0;
int criticalCount = 0; int criticalCount = 0;
Set<String> creatorIdSet = new HashSet<>(); Set<String> creatorIdSet = new HashSet<>();
@ -117,13 +117,13 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService {
} while (slice.hasNext()); } while (slice.hasNext());
// 组装数据 // 组装数据
indexData.setCountByWeek(countByWeek); appraiseIndexData.setCountByWeek(countByWeek);
indexData.setTotalCount(totalCount); appraiseIndexData.setTotalCount(totalCount);
indexData.setCriticalCount(criticalCount); appraiseIndexData.setCriticalCount(criticalCount);
indexData.setPraiseCount(totalCount - criticalCount); appraiseIndexData.setPraiseCount(totalCount - criticalCount);
indexData.setTeacherCount(creatorIdSet.size()); appraiseIndexData.setTeacherCount(creatorIdSet.size());
indexData.setStudentCount(studentSet.size()); appraiseIndexData.setStudentCount(studentSet.size());
return indexData; return appraiseIndexData;
} }
@Override @Override

@ -0,0 +1,122 @@
package cn.teammodel.controller.admin.service.impl;
import cn.teammodel.common.ErrorCode;
import cn.teammodel.common.PK;
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.School;
import cn.teammodel.model.vo.admin.DutyIndexData;
import cn.teammodel.model.vo.admin.DutyIndexPo;
import cn.teammodel.model.vo.appraise.RecordVo;
import cn.teammodel.repository.DutyRecordRepository;
import cn.teammodel.repository.DutyRepository;
import cn.teammodel.repository.SchoolRepository;
import cn.teammodel.security.utils.SecurityUtil;
import cn.teammodel.utils.SchoolDateUtil;
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Slice;
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 static cn.teammodel.utils.SchoolDateUtil.calculateWeekNum;
/**
* @author winter
* @create 2024-02-28 15:07
*/
@Service
public class AdminIndexDutyServiceImpl implements AdminIndexDutyService {
@Resource
private SchoolRepository schoolRepository;
@Resource
private DutyRepository dutyRepository;
@Resource
private DutyRecordRepository dutyRecordRepository;
@Override
public DutyIndexData getIndexData(String periodId) {
User loginUser = SecurityUtil.getLoginUser();
String schoolId = loginUser.getSchoolId();
final int SLICE_SIZE = 100;
if (StringUtils.isBlank(periodId)) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "不能为空");
}
final DutyIndexData DutyIndexData = new DutyIndexData();
int totalCount = 0;
int negetiveCount = 0;
Set<String> creatorIdSet = new HashSet<>();
// todo
Set<String> classIdSet = new HashSet<>();
// 获取学期起止时间
List<School.Semester> semesters = schoolRepository.findSemestersById(schoolId, periodId);
SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now());
String academicYearId = semesterModel.getAcademicYearId();
LocalDateTime startDatetime = semesterModel.getStartDatetime();
LocalDateTime endDatetime = semesterModel.getEndDatetime();
if (startDatetime == null || endDatetime == null) throw new ServiceException(ErrorCode.PARAMS_ERROR);
long totalWeek = calculateWeekNum(startDatetime, endDatetime, null);
// slice 分段读取
CosmosPageRequest pageRequest = new CosmosPageRequest(0, SLICE_SIZE, null);
Slice<DutyIndexPo> slice;
Map<Long, Integer> countByWeek = SchoolDateUtil.createEmptyWeekMap(totalWeek);
do {
slice = dutyRecordRepository.findAllByAcademicYearId(String.format(PK.WEEK_DUTY_RECORD, schoolId), academicYearId, pageRequest);
List<DutyIndexPo> content = slice.getContent();
if (ObjectUtils.isEmpty(content)) {
break;
}
// 分批次计算
for (DutyIndexPo item : content) {
// 处理每周的评价数
long weekNum = calculateWeekNum(startDatetime, endDatetime, item.getCreateTime());
countByWeek.put(weekNum, countByWeek.getOrDefault(weekNum, 0) + 1);
// 处理总评价数
totalCount++;
// 处理批评数
if (item.getDutyTreeNodeScore() < 0) {
negetiveCount++;
}
// 处理已评价老师总数
creatorIdSet.add(item.getCreatorId());
// 处理被评价的学生数
classIdSet.add(item.getClassId());
}
if (slice.hasNext()) {
pageRequest = (CosmosPageRequest) slice.nextPageable();
}
} while (slice.hasNext());
// 组装数据
DutyIndexData.setCountByWeek(countByWeek);
DutyIndexData.setTotalCount(totalCount);
DutyIndexData.setClassCount(classIdSet.size());
DutyIndexData.setPositiveCount(totalCount - negetiveCount);
DutyIndexData.setTeacherCount(creatorIdSet.size());
return DutyIndexData;
}
@Override
public List<RecordVo> conditionLatestRecord(TimeRangeDto timeRangeDto) {
return null;
}
}

@ -10,7 +10,7 @@ import java.util.Map;
* @create 2023-12-06 14:47 * @create 2023-12-06 14:47
*/ */
@Data @Data
public class IndexData { public class AppraiseIndexData {
@ApiModelProperty("评价数据的总数") @ApiModelProperty("评价数据的总数")
private Integer totalCount = 0; private Integer totalCount = 0;
@ApiModelProperty("表扬总数") @ApiModelProperty("表扬总数")

@ -0,0 +1,26 @@
package cn.teammodel.model.vo.admin;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Map;
/**
* @author winter
* @create 2024-02-28 15:15
*/
@Data
public class DutyIndexData {
@ApiModelProperty("值周巡检评价数据的总数")
private Integer totalCount = 0;
@ApiModelProperty("加分总数")
private Integer positiveCount = 0;
@ApiModelProperty("扣分总数")
private Integer negetiveCount = 0;
@ApiModelProperty("使用老师的总数")
private Integer teacherCount = 0;
@ApiModelProperty("被评价班级的总数")
private Integer classCount = 0;
@ApiModelProperty("学期中按周分布的评价数据")
private Map<Long, Integer> countByWeek;
}

@ -0,0 +1,18 @@
package cn.teammodel.model.vo.admin;
import lombok.Data;
/**
* @author winter
* @create 2024-02-29 10:02
*/
@Data
public class DutyIndexPo {
private String classId;
private String dutyRecordNodeId;
private String dutyTreeNodeId;
private String dutyTreeNodeName;
private Integer dutyTreeNodeScore;
private String creatorId;
private Long createTime;
}

@ -1,9 +1,12 @@
package cn.teammodel.repository; package cn.teammodel.repository;
import cn.teammodel.model.entity.weekDuty.WeekDutyRecord; import cn.teammodel.model.entity.weekDuty.WeekDutyRecord;
import cn.teammodel.model.vo.admin.DutyIndexPo;
import cn.teammodel.model.vo.weekDuty.DutyRecordVo; import cn.teammodel.model.vo.weekDuty.DutyRecordVo;
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest;
import com.azure.spring.data.cosmos.repository.CosmosRepository; import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query; import com.azure.spring.data.cosmos.repository.Query;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@ -25,5 +28,8 @@ public interface DutyRecordRepository extends CosmosRepository<WeekDutyRecord, S
"AND (IS_NULL(@startTime) or n.createTime >= @startTime) " + "AND (IS_NULL(@startTime) or n.createTime >= @startTime) " +
"AND (IS_NULL(@endTime) or n.createTime <= @endTime)") "AND (IS_NULL(@endTime) or n.createTime <= @endTime)")
List<DutyRecordVo> findRecordsByConditions(String code, String academicYearId, String userId, String classId, Boolean positive, Long startTime, Long endTime); List<DutyRecordVo> findRecordsByConditions(String code, String academicYearId, String userId, String classId, Boolean positive, Long startTime, Long endTime);
@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);
} }

@ -18,4 +18,5 @@ public interface DutyRepository extends CosmosRepository<WeekDuty, String> {
@Query("select value n from c join n in c.nodes where c.schoolId = @schoolId and c.code = 'Duty' and n.id = @nodeId") @Query("select value n from c join n in c.nodes where c.schoolId = @schoolId and c.code = 'Duty' and n.id = @nodeId")
List<WeekDuty.DutyTreeNode> findDutyNodeById(String nodeId, String schoolId); List<WeekDuty.DutyTreeNode> findDutyNodeById(String nodeId, String schoolId);
} }

Loading…
Cancel
Save