parent
f07b7e9257
commit
12ad733286
@ -0,0 +1,32 @@
|
|||||||
|
package cn.teammodel.controller.admin.controller;
|
||||||
|
|
||||||
|
import cn.teammodel.common.R;
|
||||||
|
import cn.teammodel.controller.admin.service.TeacherService;
|
||||||
|
import cn.teammodel.model.dto.admin.exam.OverViewDto;
|
||||||
|
import cn.teammodel.model.dto.admin.teacher.TeacherDto;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("admin/teacher")
|
||||||
|
@Api(tags = "教师相关接口内容")
|
||||||
|
public class TeacherController {
|
||||||
|
@Resource
|
||||||
|
private TeacherService teacherService;
|
||||||
|
@PostMapping("getCount")
|
||||||
|
@ApiOperation("获取教师基础数据统计内容")
|
||||||
|
public R<List<Map<String, Integer>>> getCount(@Valid @RequestBody TeacherDto teacherDto) {
|
||||||
|
List<Map<String, Integer>> res = teacherService.getTeacherList(teacherDto);
|
||||||
|
return R.success(res);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package cn.teammodel.controller.admin.service;
|
||||||
|
|
||||||
|
import cn.teammodel.model.dto.admin.teacher.TeacherDto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface TeacherService {
|
||||||
|
List<Map<String,Integer>> getTeacherList(TeacherDto teacherDto);
|
||||||
|
}
|
@ -0,0 +1,139 @@
|
|||||||
|
package cn.teammodel.controller.admin.service.impl;
|
||||||
|
|
||||||
|
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.School;
|
||||||
|
import cn.teammodel.model.entity.school.SchoolTeacher;
|
||||||
|
import cn.teammodel.repository.SchoolGroupListRepository;
|
||||||
|
import cn.teammodel.repository.SchoolRepository;
|
||||||
|
import cn.teammodel.repository.SchoolTeacherRepository;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.*;
|
||||||
|
@Service
|
||||||
|
public class TeacherServiceImpl implements TeacherService {
|
||||||
|
@Resource
|
||||||
|
private SchoolGroupListRepository schoolGroupListRepository;
|
||||||
|
@Resource
|
||||||
|
private SchoolTeacherRepository schoolTeacherRepository;
|
||||||
|
@Resource
|
||||||
|
private SchoolRepository schoolRepository;
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Integer>> getTeacherList(TeacherDto teacherDto) {
|
||||||
|
List<Map<String, Integer>> result = new ArrayList<>();
|
||||||
|
List<GroupList> groupLists = schoolGroupListRepository.findAllByCode("GroupList-" + teacherDto.getCode());
|
||||||
|
List<SchoolTeacher> schoolTeachers = schoolTeacherRepository.findAllByCode("Teacher-" + teacherDto.getCode());
|
||||||
|
List<School> school = schoolRepository.findBaseById(teacherDto.getCode());
|
||||||
|
List<School.Subject> subjects = new ArrayList<>();
|
||||||
|
List<School.Period> periods = new ArrayList<>();
|
||||||
|
for (School sc : school) {
|
||||||
|
if (sc.getPeriod() != null) {
|
||||||
|
// 遍历每个 Period 对象
|
||||||
|
for (School.Period period : sc.getPeriod()) {
|
||||||
|
periods.add(period);
|
||||||
|
// 检查 period 是否有 subjects 列表
|
||||||
|
if (period.getSubjects() != null) {
|
||||||
|
// 将 period 中的 subjects 添加到总的 subjects 列表中
|
||||||
|
subjects.addAll(period.getSubjects());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Integer> updatedSubjectCountMap = getStringIntegerMap(subjects, schoolTeachers);
|
||||||
|
|
||||||
|
// 创建一个映射,用于存储每个职位的教师数量
|
||||||
|
Map<String, Integer> jobCountMap = new HashMap<>();
|
||||||
|
|
||||||
|
// 遍历所有教师
|
||||||
|
for (SchoolTeacher teacher : schoolTeachers) {
|
||||||
|
// 获取教师的职位
|
||||||
|
String job = teacher.getJob();
|
||||||
|
if (job != null) {
|
||||||
|
// 更新每个职位的教师数量
|
||||||
|
jobCountMap.put(job, jobCountMap.getOrDefault(job, 0) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jobCountMap.entrySet().removeIf(entry -> entry.getKey().isEmpty());
|
||||||
|
Map<String, Integer> periodCountMap = getPeriodCountMap(groupLists, periods);
|
||||||
|
|
||||||
|
periodCountMap.entrySet().removeIf(entry -> entry.getKey().isEmpty());
|
||||||
|
updatedSubjectCountMap.entrySet().removeIf(entry -> entry.getKey().isEmpty());
|
||||||
|
result.add(updatedSubjectCountMap);
|
||||||
|
result.add(jobCountMap);
|
||||||
|
result.add(periodCountMap);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static @NotNull Map<String, Integer> getStringIntegerMap(List<School.Subject> subjects, List<SchoolTeacher> schoolTeachers) {
|
||||||
|
Map<String, String> subjectNameMap = new HashMap<>();
|
||||||
|
for (School.Subject subject : subjects) {
|
||||||
|
subjectNameMap.put(subject.getId(), subject.getName());
|
||||||
|
}
|
||||||
|
Map<String, Integer> subjectCountMap = new HashMap<>();
|
||||||
|
|
||||||
|
// 遍历所有教师
|
||||||
|
for (SchoolTeacher teacher : schoolTeachers) {
|
||||||
|
// 获取教师的科目列表
|
||||||
|
List<String> subjectIds = teacher.getSubjectIds();
|
||||||
|
if (subjectIds != null) {
|
||||||
|
for (String subjectId : subjectIds) {
|
||||||
|
// 更新每个科目的教师数量
|
||||||
|
subjectCountMap.put(subjectId, subjectCountMap.getOrDefault(subjectId, 0) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<String, Integer> updatedSubjectCountMap = new HashMap<>();
|
||||||
|
for (Map.Entry<String, Integer> entry : subjectCountMap.entrySet()) {
|
||||||
|
String subjectId = entry.getKey();
|
||||||
|
Integer count = entry.getValue();
|
||||||
|
String subjectName = subjectNameMap.get(subjectId);
|
||||||
|
if (subjectName != null) {
|
||||||
|
updatedSubjectCountMap.put(subjectName, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return updatedSubjectCountMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static @NotNull Map<String, Integer> getPeriodCountMap(List<GroupList> groupLists,List<School.Period> periods) {
|
||||||
|
|
||||||
|
Map<String, String> periodNameMap = new HashMap<>();
|
||||||
|
for (School.Period period : periods) {
|
||||||
|
periodNameMap.put(period.getId(), period.getName());
|
||||||
|
}
|
||||||
|
Map<String, Integer> periodCountMap = getStringIntegerMap(groupLists);
|
||||||
|
// 更新 periodCountMap 的 key 为 period 名称
|
||||||
|
Map<String, Integer> updatedPeriodCountMap = new HashMap<>();
|
||||||
|
for (Map.Entry<String, Integer> entry : periodCountMap.entrySet()) {
|
||||||
|
String periodId = entry.getKey();
|
||||||
|
Integer count = entry.getValue();
|
||||||
|
String periodName = periodNameMap.get(periodId);
|
||||||
|
if (periodName != null) {
|
||||||
|
updatedPeriodCountMap.put(periodName, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return updatedPeriodCountMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static @NotNull Map<String, Integer> getStringIntegerMap(List<GroupList> groupLists) {
|
||||||
|
Map<String, Integer> periodCountMap = new HashMap<>();
|
||||||
|
|
||||||
|
// 遍历所有 GroupList 对象
|
||||||
|
for (GroupList group : groupLists) {
|
||||||
|
// 获取 periodId
|
||||||
|
String periodId = group.getPeriodId();
|
||||||
|
if (periodId != null) {
|
||||||
|
// 计算成员数量
|
||||||
|
int memberCount = group.getMembers().size();
|
||||||
|
// 更新 periodCountMap
|
||||||
|
periodCountMap.put(periodId, periodCountMap.getOrDefault(periodId, 0) + memberCount);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return periodCountMap;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package cn.teammodel.model.dto.admin.teacher;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TeacherDto {
|
||||||
|
@ApiModelProperty("学校编码")
|
||||||
|
public String code;
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package cn.teammodel.model.entity.common;
|
||||||
|
|
||||||
|
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 GroupList extends BaseItem {
|
||||||
|
|
||||||
|
public String school;
|
||||||
|
public String name;
|
||||||
|
public String periodId;
|
||||||
|
public List<Member> members;
|
||||||
|
@Data
|
||||||
|
public static class Member
|
||||||
|
{
|
||||||
|
public String id ;
|
||||||
|
//学生所在的学校
|
||||||
|
public String code ;
|
||||||
|
//帐号类型
|
||||||
|
public int type;
|
||||||
|
public String groupId ;
|
||||||
|
public String groupName ;
|
||||||
|
public String nickname ;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
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 SchoolTeacher extends BaseItem {
|
||||||
|
public String name ;
|
||||||
|
public String picture ;
|
||||||
|
public int size ;
|
||||||
|
public String job ;
|
||||||
|
public List<String> roles ;
|
||||||
|
public List<String> permissions ;
|
||||||
|
public String status ;
|
||||||
|
public long createTime ;
|
||||||
|
/// <summary>
|
||||||
|
/// 教师的科目数组
|
||||||
|
/// </summary>
|
||||||
|
public List<String> subjectIds ;
|
||||||
|
/// <summary>
|
||||||
|
/// 默认的学段id
|
||||||
|
/// </summary>
|
||||||
|
public String periodId ;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package cn.teammodel.repository;
|
||||||
|
|
||||||
|
import cn.teammodel.model.entity.common.GroupList;
|
||||||
|
import cn.teammodel.model.entity.school.SchoolTeacher;
|
||||||
|
import com.azure.spring.data.cosmos.repository.CosmosRepository;
|
||||||
|
import com.azure.spring.data.cosmos.repository.Query;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface SchoolGroupListRepository extends CosmosRepository<GroupList, String> {
|
||||||
|
@Query("select * from GroupList as c where c.code = @code")
|
||||||
|
List<GroupList> findAllByCode(String code);
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package cn.teammodel.repository;
|
||||||
|
|
||||||
|
import cn.teammodel.model.entity.school.SchoolTeacher;
|
||||||
|
import cn.teammodel.model.entity.school.Teacher;
|
||||||
|
import com.azure.spring.data.cosmos.repository.CosmosRepository;
|
||||||
|
import com.azure.spring.data.cosmos.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface SchoolTeacherRepository extends CosmosRepository<SchoolTeacher, String> {
|
||||||
|
@Query("select c.id, c.name,c.job,c.subjectIds from SchoolTeacher as c where c.code = @code")
|
||||||
|
List<SchoolTeacher> findAllByCode(String code);
|
||||||
|
}
|
Loading…
Reference in new issue