update 教学质量接口内容

develop
hhb@hotmail.com 2 months ago
parent 042979a5ae
commit d8b9df497d

@ -3,6 +3,7 @@ package cn.teammodel.controller.admin.controller;
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.teacher.TeacherDto;
import cn.teammodel.model.dto.admin.weekduty.AdminFindDutyRecordDto;
import cn.teammodel.model.dto.weekDuty.LessonRecordDto;
import cn.teammodel.model.vo.admin.AppraiseNodeRankVo;
@ -79,8 +80,8 @@ public class AdminDutyController {
}
@PostMapping("getTeachingQuality")
@ApiOperation("获取教学质量")
public R<Map<String, Object> > getTeachingQuality(@Valid @RequestBody LessonRecordDto lessonRecordDto , HttpServletRequest request) {
Map<String, Object> res = adminIndexDutyService.getTeachingQuality(lessonRecordDto,request);
public R<List<Map<String, Object>> > getTeachingQuality(@Valid @RequestBody TeacherDto teacherDto , HttpServletRequest request) {
List<Map<String, Object>> res = adminIndexDutyService.getTeachingQuality(teacherDto,request);
return R.success(res);
}
}

@ -1,6 +1,7 @@
package cn.teammodel.controller.admin.service;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto;
import cn.teammodel.model.dto.admin.teacher.TeacherDto;
import cn.teammodel.model.dto.weekDuty.LessonRecordDto;
import cn.teammodel.model.vo.admin.DutyIndexData;
import cn.teammodel.model.vo.admin.DutyNodeRankVo;
@ -25,6 +26,6 @@ public interface AdminIndexDutyService {
List<DutyNodeRankVo> appraiseNodeRank(TimeRangeDto timeRangeDto);
Map<String, Object> getLessonRecord (LessonRecordDto lessonRecordDto, HttpServletRequest request);
Map<String, Object> getTeachingQuality (LessonRecordDto lessonRecordDto, HttpServletRequest request);
List<Map<String, Object>> getTeachingQuality (TeacherDto teacherDto, HttpServletRequest request);
}

@ -5,6 +5,7 @@ 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.dto.admin.teacher.TeacherDto;
import cn.teammodel.model.dto.weekDuty.LessonRecordDto;
import cn.teammodel.model.entity.User;
import cn.teammodel.model.entity.school.ClassInfo;
@ -89,9 +90,9 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService {
// 获取学期起止时间
List<School.Semester> semesters = schoolRepository.findSemestersById(schoolId, timeRangeDto.getPeriodId());
SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now());
LocalDateTime startDatetime = null;
LocalDateTime endDatetime = null;
String academicYearId = null;
LocalDateTime startDatetime;
LocalDateTime endDatetime;
String academicYearId;
if(timeRangeDto.getStartTime() != null) {
startDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeRangeDto.getStartTime()), ZoneId.systemDefault());
endDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeRangeDto.getEndTime()), ZoneId.systemDefault());
@ -244,80 +245,90 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService {
}
@Override
public Map<String, Object> getTeachingQuality(LessonRecordDto lessonRecordDto, HttpServletRequest request) {
/*LocalDateTime now = LocalDateTime.now();
LocalDateTime twoMonthsAgo = now.minusMonths(2);*/
// 转换为时间戳(毫秒)
/* long nowTimestamp = now.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
long twoMonthsAgoTimestamp = twoMonthsAgo.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
lessonRecordDto.setStime(twoMonthsAgoTimestamp);
lessonRecordDto.setEtime(nowTimestamp);*/
public List<Map<String, Object>> getTeachingQuality(TeacherDto teacherDto, HttpServletRequest request) {
List<LessonRecord> records;
LessonRecordQueryService queryService = new LessonRecordQueryService(lessonRecordRepository);
LocalDateTime now = LocalDateTime.now();
Map<String, Object> mapper = new HashMap<>();
List<Map<String, Object>> list = new ArrayList<>();
//Map<String, Object> mapAll = new HashMap<>();
try {
String lessonRecordKey = String.format(PK.PK_LESSON_RECORD, lessonRecordDto.getSchool());
Long startTime = lessonRecordDto.getStime();
Long endTime = lessonRecordDto.getEtime();
String subjectId = lessonRecordDto.getSubjectId().isEmpty() ? null:lessonRecordDto.getSubjectId().get(0);
String tmdId = lessonRecordDto.getTmdid();
String grade = lessonRecordDto.getGrade().isEmpty() ? null :lessonRecordDto.getGrade().get(0);
String periodId = lessonRecordDto.getPeriodId();
String lessonRecordKey = String.format(PK.PK_LESSON_RECORD, teacherDto.getCode());
Long startTime = teacherDto.getStartTime();
Long endTime = teacherDto.getEndTime();
String subjectId = teacherDto.getSubjectId();
String tmdId = teacherDto.getTmdId();
String grade = teacherDto.getGrade();
String periodId = teacherDto.getPeriodId();
records = queryService.queryLessonsInParallel(
lessonRecordKey, startTime, endTime, subjectId, tmdId, grade, periodId
);
// 计算本学期互动总数
int totalClientInteractionCount = records.stream()
.mapToInt(LessonRecord::getClientInteractionCount)
.sum();
mapper.put("totalClientInteractionCount", totalClientInteractionCount);
// 获取当前月和上个月的时间范围
LocalDateTime startOfCurrentMonth = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
LocalDateTime startOfLastMonth = startOfCurrentMonth.minusMonths(1);
LocalDateTime endOfLastMonth = startOfCurrentMonth.minusSeconds(1);
long st = startOfCurrentMonth.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
long et = startOfLastMonth.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
long endMath = endOfLastMonth.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
// 过滤出当前月和上个月的记录
List<LessonRecord> currentMonthRecords = records.stream()
.filter(record -> record.getStartTime() > st )
.collect(Collectors.toList());
List<LessonRecord> lastMonthRecords = records.stream()
.filter(record -> record.getStartTime() > et && record.getStartTime() < endMath)
.collect(Collectors.toList());
// 计算当前月和上个月的clientInteractionCount总数
int currentMonthTotal = currentMonthRecords.stream()
.mapToInt(LessonRecord::getClientInteractionCount)
.sum();
mapper.put("currentMonthTotal", currentMonthTotal);
int lastMonthTotal = lastMonthRecords.stream()
.mapToInt(LessonRecord::getClientInteractionCount)
.sum();
mapper.put("lastMonthTotal", lastMonthTotal);
// 计算百分比变化
double percentageChange = 0;
if (lastMonthTotal != 0) {
percentageChange = ((double) (currentMonthTotal - lastMonthTotal) / lastMonthTotal) * 100;
for(String classId : teacherDto.getClassIds()) {
Map<String, Object> mapper = new HashMap<>();
// 计算本学期互动总数
int totalClientInteractionCount = records.stream().filter(lessonRecord ->
lessonRecord.getGroupIds().contains(classId))
.mapToInt(LessonRecord::getClientInteractionCount)
.sum();
mapper.put("totalClientInteractionCount", totalClientInteractionCount);
int countRecord = (int) records.stream().filter(lessonRecord ->
lessonRecord.getGroupIds().contains(classId)).count();
int engagementIndexAvergeSum = records.stream().filter(lessonRecord ->
lessonRecord.getGroupIds().contains(classId))
.mapToInt(LessonRecord::getEngagementIndexAverge)
.sum();
if (countRecord == 0) {
mapper.put("engagementIndexAverge", 0);
continue;
}else if (engagementIndexAvergeSum == 0) {
mapper.put("engagementIndexAverge", 0);
}else {
mapper.put("engagementIndexAverge", engagementIndexAvergeSum / countRecord);
}
// 获取当前月和上个月的时间范围
LocalDateTime startOfCurrentMonth = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
LocalDateTime startOfLastMonth = startOfCurrentMonth.minusMonths(1);
LocalDateTime endOfLastMonth = startOfCurrentMonth.minusSeconds(1);
long st = startOfCurrentMonth.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
long et = startOfLastMonth.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
long endMath = endOfLastMonth.atZone(ZoneId.of("Asia/Shanghai")).toInstant().toEpochMilli();
// 过滤出当前月和上个月的记录
List<LessonRecord> currentMonthRecords = records.stream()
.filter(record -> record.getStartTime() > st && record.getGroupIds().contains(classId))
.collect(Collectors.toList());
List<LessonRecord> lastMonthRecords = records.stream()
.filter(record -> record.getStartTime() > et && record.getStartTime() < endMath && record.getGroupIds().contains(classId))
.collect(Collectors.toList());
// 计算当前月和上个月的clientInteractionCount总数
int currentMonthTotal = currentMonthRecords.stream()
.mapToInt(LessonRecord::getClientInteractionCount)
.sum();
mapper.put("currentMonthTotal", currentMonthTotal);
int lastMonthTotal = lastMonthRecords.stream()
.mapToInt(LessonRecord::getClientInteractionCount)
.sum();
mapper.put("lastMonthTotal", lastMonthTotal);
// 计算百分比变化
double percentageChange = 0;
if (lastMonthTotal != 0) {
percentageChange = ((double) (currentMonthTotal - lastMonthTotal) / lastMonthTotal) * 100;
}
String formattedPercentageChange = String.format("%.2f", percentageChange);
mapper.put("percentageChange", formattedPercentageChange);
mapper.put("classId", classId);
list.add(mapper);
}
String formattedPercentageChange = String.format("%.2f", percentageChange);
mapper.put("percentageChange", formattedPercentageChange);
//System.out.println("当前月上浮:" + percentageChange);
} catch (InterruptedException | ExecutionException e) {
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据查询异常");
} finally {
queryService.shutdown();
}
return mapper;
return list;
}
}

@ -27,4 +27,5 @@ public class TeacherDto {
public String semesterId;
public List<String> duration = new ArrayList<>();
public List<String> school_shortcode = new ArrayList<>();
private List<String> classIds;
}

@ -201,6 +201,10 @@ public class LessonRecord extends BaseItem {
/// </summary>
public double totalInteractPoint ;
/// <summary>
/// 全班参与度
/// </summary>
public int engagementIndexAverge;
/// <summary>
/// 过期时间,-1永不过期 1577808000000 2020-01-01
/// </summary>
public long expire ;

Loading…
Cancel
Save