parent
9ff280a94e
commit
09140678bc
@ -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);
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in new issue