From 1dcd7823312b8b6faba78d3de96c9a82d15ef28a Mon Sep 17 00:00:00 2001 From: "hhb@hotmail.com" Date: Thu, 14 Nov 2024 16:56:51 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=95=99=E5=B8=88=E7=9C=8B=E6=9D=BF?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/teammodel/common/PK.java | 1 + .../admin/controller/TeacherController.java | 12 + .../admin/service/TeacherService.java | 2 + .../service/impl/TeacherServiceImpl.java | 110 +++++++ .../model/dto/admin/teacher/TeacherDto.java | 4 +- .../model/entity/school/LessonRecord.java | 268 ++++++++++++++++++ .../repository/LessonRecordRepository.java | 25 ++ 7 files changed, 420 insertions(+), 2 deletions(-) create mode 100644 src/main/java/cn/teammodel/model/entity/school/LessonRecord.java create mode 100644 src/main/java/cn/teammodel/repository/LessonRecordRepository.java diff --git a/src/main/java/cn/teammodel/common/PK.java b/src/main/java/cn/teammodel/common/PK.java index 43c5a63..0fdfcd5 100644 --- a/src/main/java/cn/teammodel/common/PK.java +++ b/src/main/java/cn/teammodel/common/PK.java @@ -18,6 +18,7 @@ public interface PK { */ String PK_APPRAISE_RECORD = "AppraiseRecord-%s"; String COMMON_BASE = "Base"; + String PK_LESSON_RECORD = "LessonRecord-%s"; /** * 学生,拼接学校 id */ diff --git a/src/main/java/cn/teammodel/controller/admin/controller/TeacherController.java b/src/main/java/cn/teammodel/controller/admin/controller/TeacherController.java index e95a9c2..b6bec58 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/TeacherController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/TeacherController.java @@ -35,5 +35,17 @@ public class TeacherController { Map res = teacherService.getTeacherDetail(teacherDto,request); return R.success(res); } + @PostMapping("getTeacherCountRecordOfWeek") + @ApiOperation("获取当前学期指定教师每周课程数") + public R> getTeacherCountRecordOfWeek(@Valid @RequestBody TeacherDto teacherDto) { + Map res = teacherService.getTeacherByRecord(teacherDto); + return R.success(res); + } + @PostMapping("getTeacherLearningCategoryCount") + @ApiOperation("获取指定教师教学法统计") + public R> getTeacherLearningCategoryCount(@Valid @RequestBody TeacherDto teacherDto) { + Map res = teacherService.getTeacherLearningCategory(teacherDto); + return R.success(res); + } } diff --git a/src/main/java/cn/teammodel/controller/admin/service/TeacherService.java b/src/main/java/cn/teammodel/controller/admin/service/TeacherService.java index f1592fe..8f47505 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/TeacherService.java +++ b/src/main/java/cn/teammodel/controller/admin/service/TeacherService.java @@ -9,4 +9,6 @@ import java.util.Map; public interface TeacherService { List> getTeacherList(TeacherDto teacherDto); Map getTeacherDetail(TeacherDto teacherDto, HttpServletRequest request); + Map getTeacherByRecord(TeacherDto teacherDto); + Map getTeacherLearningCategory(TeacherDto teacherDto); } diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/TeacherServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/TeacherServiceImpl.java index b9d9dcb..baf6a1b 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/TeacherServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/TeacherServiceImpl.java @@ -1,24 +1,36 @@ 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.TeacherService; import cn.teammodel.model.dto.admin.teacher.TeacherDto; import cn.teammodel.model.entity.common.GroupList; +import cn.teammodel.model.entity.school.LessonRecord; import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.school.SchoolTeacher; +import cn.teammodel.model.vo.appraise.RecordVo; +import cn.teammodel.repository.LessonRecordRepository; import cn.teammodel.repository.SchoolGroupListRepository; import cn.teammodel.repository.SchoolRepository; import cn.teammodel.repository.SchoolTeacherRepository; import cn.teammodel.utils.GroupUtil; +import cn.teammodel.utils.SchoolDateUtil; +import com.azure.spring.data.cosmos.core.query.CosmosPageRequest; +import org.apache.commons.lang3.ObjectUtils; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; +import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.time.*; import java.util.*; + +import static cn.teammodel.utils.SchoolDateUtil.calculateWeekNum; + @Service public class TeacherServiceImpl implements TeacherService { @Resource @@ -27,6 +39,8 @@ public class TeacherServiceImpl implements TeacherService { private SchoolTeacherRepository schoolTeacherRepository; @Resource private SchoolRepository schoolRepository; + @Resource + private LessonRecordRepository lessonRecordRepository; @Autowired private Environment env; @Override @@ -95,6 +109,102 @@ public class TeacherServiceImpl implements TeacherService { return teachers; } + @Override + public Map getTeacherByRecord(TeacherDto teacherDto) { + final int SLICE_SIZE = 100; + // 获取学期起止时间 + List semesters = schoolRepository.findSemestersById(teacherDto.getCode(), teacherDto.getPeriodId()); + SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now()); + LocalDateTime startDatetime = null; + LocalDateTime endDatetime = null; + if(teacherDto.getStartTime() != null) { + startDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getStartTime()), ZoneId.systemDefault()); + endDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getEndTime()), ZoneId.systemDefault()); + }else { + startDatetime = semesterModel.getStartDatetime(); + 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 slice; + Map countByWeek = SchoolDateUtil.createEmptyWeekMap(totalWeek); + + do { + slice = lessonRecordRepository.findAllByAcademicYearId(String.format(PK.PK_LESSON_RECORD, teacherDto.getCode()), teacherDto.getTmdId(),pageRequest); + List content = slice.getContent(); + if (ObjectUtils.isEmpty(content)) { + break; + } + + // 分批次计算 + for (LessonRecord item : content) { + // 处理每周的课程数 + long weekNum = calculateWeekNum(startDatetime, endDatetime, item.getStartTime()); + countByWeek.put(weekNum, countByWeek.getOrDefault(weekNum, 0) + 1); + } + + if (slice.hasNext()) { + pageRequest = (CosmosPageRequest) slice.nextPageable(); + } + } while (slice.hasNext()); + countByWeek.entrySet().removeIf(entry -> entry.getKey() == -1); + return countByWeek; + } + + @Override + public Map getTeacherLearningCategory(TeacherDto teacherDto) { + + Map LearningCategory = new HashMap<>(Collections.emptyMap()); + try { + // 获取学期起止时间 + List semesters = schoolRepository.findSemestersById(teacherDto.getCode(), teacherDto.getPeriodId()); + SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now()); + LocalDateTime startDatetime = null; + LocalDateTime endDatetime = null; + if(teacherDto.getStartTime() != null) { + startDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getStartTime()), ZoneId.systemDefault()); + endDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getEndTime()), ZoneId.systemDefault()); + }else { + startDatetime = semesterModel.getStartDatetime(); + endDatetime = semesterModel.getEndDatetime(); + } + if (startDatetime == null || endDatetime == null) throw new ServiceException(ErrorCode.PARAMS_ERROR); + + // 将 LocalDateTime 转换为 Long 类型的时间戳 + long startTimestamp = startDatetime.toInstant(ZoneOffset.UTC).toEpochMilli(); + long endTimestamp = endDatetime.toInstant(ZoneOffset.UTC).toEpochMilli(); + + List lessonRecords = lessonRecordRepository.getLessonsByConditions(String.format(PK.PK_LESSON_RECORD, teacherDto.getCode()), startTimestamp, endTimestamp, teacherDto.getTmdId()); + int cooperationCount = 0; + int internetCount = 0; + int taskCount = 0; + int examCount = 0; + int diffentialCount = 0; + + for (LessonRecord record : lessonRecords) { + if (record.getLearningCategory() != null) { + cooperationCount += record.getLearningCategory().getCooperation(); + internetCount += record.getLearningCategory().getInteraction(); + taskCount += record.getLearningCategory().getTask(); + examCount += record.getLearningCategory().getExam(); + diffentialCount += record.getLearningCategory().getDiffential(); + } + } + LearningCategory.put("cooperation", cooperationCount); + LearningCategory.put("internet", internetCount); + LearningCategory.put("task", taskCount); + LearningCategory.put("exam", examCount); + LearningCategory.put("diffential", diffentialCount); + }catch (Exception e) { + throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据转换错误"); + + } + return LearningCategory; + } + private static @NotNull Map getStringIntegerMap(List subjects, List schoolTeachers) { Map subjectNameMap = new HashMap<>(); for (School.Subject subject : subjects) { diff --git a/src/main/java/cn/teammodel/model/dto/admin/teacher/TeacherDto.java b/src/main/java/cn/teammodel/model/dto/admin/teacher/TeacherDto.java index 7fd3dd6..b5f3712 100644 --- a/src/main/java/cn/teammodel/model/dto/admin/teacher/TeacherDto.java +++ b/src/main/java/cn/teammodel/model/dto/admin/teacher/TeacherDto.java @@ -11,8 +11,8 @@ public class TeacherDto { public String school_code; @ApiModelProperty("TmdId") public String tmdId; - public long startTime; - public long endTime; + public Long startTime; + public Long endTime; @ApiModelProperty("学段Id") public String periodId; } diff --git a/src/main/java/cn/teammodel/model/entity/school/LessonRecord.java b/src/main/java/cn/teammodel/model/entity/school/LessonRecord.java new file mode 100644 index 0000000..2672571 --- /dev/null +++ b/src/main/java/cn/teammodel/model/entity/school/LessonRecord.java @@ -0,0 +1,268 @@ +package cn.teammodel.model.entity.school; + +import cn.teammodel.model.entity.BaseItem; +import com.azure.spring.data.cosmos.core.mapping.Container; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.List; + +@EqualsAndHashCode(callSuper = true) +@Container(containerName = "School") +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class LessonRecord extends BaseItem { + /// + ///必填 教师醍摩豆id + /// + public String tmdid ; + /// + /// 教师醍摩豆id名称 + /// + public String tmdname ; + /// + /// 教师醍摩豆id名称 + /// + public String tmdpicture ; + /// + ///必填 课堂名称 + /// + public String name ; + /// + ///必填 scope==school必填 | String | 学校id + /// + public String school ; + /// + ///必填 private/school| + /// + public String scope ; + /// + ///必填 视频封面地址 + /// +// public String poster ; + /// + ///必填 开始时间(时间戳) 1606393763434 + /// + public long startTime ; + /// + ///必填 上课时长,最后更新 + /// + public double duration ; + /// + ///选填 t分,科技应用 ,最后更新 + /// + public int tScore ; + /// + ///选填 p分,教法应用 ,最后更新 + /// + public int pScore ; + /// + ///选填 t灯,科技应用 0红灯,1 黄灯,2绿灯 + /// + public int tLevel ; + /// + ///选填 p灯,教法应用 0红灯,1 黄灯,2绿灯 + /// + public int pLevel ; + /// + ///选填 选用IES5的课程id + /// + public String courseId ; + /// + /// 选填 课程名称 是因支持VR/AR那边课例 + /// + public String courseName ; + /// + ///选填 选用IES5固定名单的id + /// + public List groupIds ; + public List groupNames ; + /// + ///选填 学生人数 ,最后更新 + /// + public int mCount ; + /// + ///选填 议课次数,大于1则是优课,苏格拉底获取 + /// + public int discuss ; + /// + ///选填 科技互动次数, + /// + public int techCount ; + /// + /// 学 不填 段id,由课程或者名单获取 + /// + public String periodId ; + /// + /// 选填 学段名称 是因支持VR/AR那边课例 + /// + public String periodName ; + /// + /// 不填 科目id,由课程id获取 + /// + public String subjectId ; + /// + /// 选填 科目名称 是因支持VR/AR那边课例 + /// + public String subjecName ; + /// + /// 不填 年级id,由名单id获取 + /// + public List grade ; + public List gradeName ; + /// + /// 不填 收藏次数,IES5更新 + /// + public int favorite ; + /// + /// 不填 点赞数 + /// + public int like ; + /// + /// 不填 分享转发数 + /// + public int share ; + /// + /// 不填 ["混合学习","语文教研"]课例类别,tag标签,IES5维护 + /// + public List category ; + /// + /// 0 是否包含视频,1包含视频 + /// + public int hasVideo ; + //public long videoSize ; + /// + /// + /// 科技互动详细次数。[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49] + /// + public List tech ; + public int status ; + /// + /// 专家好课,默认0, 1 是好课 + /// + public int excellent ; + /// + /// 出席人数 + /// + public int attendCount ; + /// + /// 总人数 + /// + public int clientCount ; + /// + ///出席率 + /// + public double attendRate ; + /// + /// 小组数 + /// + public int groupCount ; + /// + /// 任务总数,作品收集任务数 + /// + public int collateTaskCount ; + /// + /// 作品总数 + /// + public int collateCount ; + /// + /// 推送总数(页面,资源,讯息,差异化) + /// + public int pushCount ; + /// + /// 总计分 + /// + public double totalPoint ; + /// + /// 测验总题数 + /// + public int examQuizCount ; + /// + /// 互动题数 + /// + public int interactionCount ; + /// + /// 测验得分率 + /// + public double examPointRate ; + /// + /// 学生互动总数 + /// + public int clientInteractionCount ; + /// + /// 学生互动率 + /// + public double clientInteractionAverge ; + + public int examCount ; + /// + /// 总互动分 + /// + public double totalInteractPoint ; + /// + /// 过期时间,-1永不过期, 1577808000000 2020-01-01 + /// + public long expire ; + /// + /// 先使用这种模式,["all","student"], 暂不 开放 school【开放给部分学校查看】,teacher【开放给部分教师查看】 ["all","school","teacher","student"] + /// + public List show ; + /// + /// 暂不 开放 school【开放给部分学校查看】学校编码 + /// + public List showSchs ; + /// + /// 暂不 开放 teacher【开放给部分教师查看】醍摩豆id + /// + public List showTchs ; + /// + /// 设置强制保留的 =1 ,不会被自动清理的。但是可以被手动清理。 + /// + public int save ; + /// + /// 默认未上传 + /// + public int upload ; + + public LearningCategory learningCategory ; + public int hitaClientCmpCount ; + /// + /// 课例来源 0 本公司 1 第三方公司 是因支持VR/AR那边课例 + /// + public int source ; + + @Data + public static class LearningCategory { + /// + /// //合作學習 + /// + public int cooperation ; + /// + /// 互動學習 + /// + public int interaction ; + /// + /// 任務學習 + /// + public int task; + /// + /// 測驗學習 + /// + public int exam ; + /// + /// 差異化學習 + /// + public int diffential ; + /// + /// 只會有 1跟0,有進行1個以上的智慧評分活動就是1,反之是0 + /// + public int smartRating ; + /// + /// 只會有 1跟0,有進行1個以上的協作活動就是1,反之是0 + /// + public int cowork ; + + + } +} diff --git a/src/main/java/cn/teammodel/repository/LessonRecordRepository.java b/src/main/java/cn/teammodel/repository/LessonRecordRepository.java new file mode 100644 index 0000000..49f0c0e --- /dev/null +++ b/src/main/java/cn/teammodel/repository/LessonRecordRepository.java @@ -0,0 +1,25 @@ +package cn.teammodel.repository; + +import cn.teammodel.model.entity.school.LessonRecord; +import cn.teammodel.model.vo.appraise.RecordVo; +import com.azure.spring.data.cosmos.repository.CosmosRepository; +import com.azure.spring.data.cosmos.repository.Query; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface LessonRecordRepository extends CosmosRepository { + @Query("select * from LessonRecord as c where " + + "c.code = @code and " + + "(IS_NULL(@startTime) or c.startTime >= @startTime) and " + + "(IS_NULL(@endTime) or c.startTime <= @endTime) and" + + " c.tmdid = @tmdId") + List getLessonsByConditions(String code, Long startTime, Long endTime,String tmdId); + + @Query("select * from LessonRecord as c where c.code = @code and c.expire<=0 and c.status<>404 and c.tmdid = @tmdId ") + Slice findAllByAcademicYearId(String code, String tmdId,Pageable pageable); + +}