|
|
|
@ -4,11 +4,14 @@ 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.GpTeacherDto;
|
|
|
|
|
import cn.teammodel.model.dto.admin.teacher.TeacherDto;
|
|
|
|
|
import cn.teammodel.model.entity.common.GroupList;
|
|
|
|
|
import cn.teammodel.model.entity.school.GpTeacher;
|
|
|
|
|
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.admin.GpTeacherVo;
|
|
|
|
|
import cn.teammodel.repository.LessonRecordRepository;
|
|
|
|
|
import cn.teammodel.repository.SchoolGroupListRepository;
|
|
|
|
|
import cn.teammodel.repository.SchoolRepository;
|
|
|
|
@ -29,6 +32,7 @@ import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.time.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static cn.teammodel.utils.SchoolDateUtil.calculateWeekNum;
|
|
|
|
|
|
|
|
|
@ -107,6 +111,45 @@ public class TeacherServiceImpl implements TeacherService {
|
|
|
|
|
String url = env.getProperty("ies.server-url-get-teacher-all");
|
|
|
|
|
try {
|
|
|
|
|
teachers = GroupUtil.getGroupId(teacherDto,new GroupUtil(env), request,url);
|
|
|
|
|
List<GpTeacherVo> teachersList = new ArrayList<>();
|
|
|
|
|
for (Map.Entry<String, Object> entry : teachers.entrySet()) {
|
|
|
|
|
// 假设 entry.getValue() 返回的是 List<Map<String, Object>>
|
|
|
|
|
List<Map<String, Object>> mapList = (List<Map<String, Object>>) entry.getValue();
|
|
|
|
|
for (Map<String, Object> map : mapList) {
|
|
|
|
|
// 将 Map 转换为 GpTeacherVo 对象
|
|
|
|
|
GpTeacherVo teacher = convertToGpTeacherVo(map);
|
|
|
|
|
teachersList.add(teacher);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<String> phones = new ArrayList<>();
|
|
|
|
|
// 进一步处理 teachersList
|
|
|
|
|
for (GpTeacherVo teacher : teachersList) {
|
|
|
|
|
phones.add(teacher.getPhone());
|
|
|
|
|
}
|
|
|
|
|
GpTeacherDto gpTeacherDto = new GpTeacherDto();
|
|
|
|
|
gpTeacherDto.setMobiles(phones);
|
|
|
|
|
Map<String, Object> tBase = getTeacherBase(gpTeacherDto, request);
|
|
|
|
|
List<GpTeacher> gpTeachers = new ArrayList<>();
|
|
|
|
|
for (Map.Entry<String, Object> entry : tBase.entrySet()) {
|
|
|
|
|
if (entry.getKey().equals("teachers")) {
|
|
|
|
|
List<Map<String, Object>> dataList = (List<Map<String, Object>>) entry.getValue();
|
|
|
|
|
for (Map<String, Object> dataMap : dataList) {
|
|
|
|
|
GpTeacher gpTeacher = convertToGpTeacher(dataMap);
|
|
|
|
|
gpTeachers.add(gpTeacher);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Map<String, Long> genderCount = gpTeachers.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(gpTeacher -> gpTeacher.getBasic().getGender(), Collectors.counting()));
|
|
|
|
|
Map<String, Long> degreeCount = gpTeachers.stream()
|
|
|
|
|
.filter(gpTeacher -> gpTeacher.getDegree() != null)
|
|
|
|
|
.collect(Collectors.groupingBy(GpTeacher::getDegree, Collectors.counting()));
|
|
|
|
|
Map<String, Integer> practiceCount = getStringIntegerMap(teacherDto, gpTeachers);
|
|
|
|
|
|
|
|
|
|
teachers.put("practice", practiceCount);
|
|
|
|
|
teachers.put("gender", genderCount);
|
|
|
|
|
teachers.put("degree", degreeCount);
|
|
|
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据转换错误");
|
|
|
|
|
|
|
|
|
@ -114,6 +157,109 @@ public class TeacherServiceImpl implements TeacherService {
|
|
|
|
|
return teachers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static @NotNull Map<String, Integer> getStringIntegerMap(TeacherDto teacherDto, List<GpTeacher> gpTeachers) {
|
|
|
|
|
Map<String,Integer> practiceCount = new HashMap<>();
|
|
|
|
|
for (GpTeacher gpTeacher : gpTeachers) {
|
|
|
|
|
if(gpTeacher.practiceTime > 0) {
|
|
|
|
|
// 将时间戳转换为 LocalDateTime
|
|
|
|
|
LocalDateTime dateTime = LocalDateTime.ofInstant(
|
|
|
|
|
Instant.ofEpochMilli(gpTeacher.practiceTime),
|
|
|
|
|
ZoneId.systemDefault()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 获取年份
|
|
|
|
|
int year = dateTime.getYear();
|
|
|
|
|
practiceCount.put(gpTeacher.basic.name, teacherDto.year - year);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return practiceCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private GpTeacherVo convertToGpTeacherVo(Map<String, Object> map) {
|
|
|
|
|
GpTeacherVo teacher = new GpTeacherVo();
|
|
|
|
|
// 假设 GpTeacherVo 有以下属性:name, age, subject
|
|
|
|
|
teacher.setName((String) map.get("name"));
|
|
|
|
|
teacher.setPhone((String) map.get("phone"));
|
|
|
|
|
teacher.setId((String) map.get("id"));
|
|
|
|
|
// 根据实际属性进行转换
|
|
|
|
|
return teacher;
|
|
|
|
|
}
|
|
|
|
|
private GpTeacher convertToGpTeacher(Map<String, Object> map) {
|
|
|
|
|
GpTeacher teacher = new GpTeacher();
|
|
|
|
|
// 假设 GpTeacherVo 有以下属性:name, age, subject
|
|
|
|
|
Object describeObj = map.get("describe");
|
|
|
|
|
if (describeObj instanceof String) {
|
|
|
|
|
teacher.setDescribe((String) describeObj);
|
|
|
|
|
} else {
|
|
|
|
|
teacher.setDescribe(null); // 或者设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
Object depictObj = map.get("depict");
|
|
|
|
|
if (depictObj instanceof String) {
|
|
|
|
|
teacher.setDepict((String) depictObj);
|
|
|
|
|
} else {
|
|
|
|
|
teacher.setDepict(null); // 或者设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
teacher.setPeriods((ArrayList<GpTeacher.GnericBase>) map.get("periods"));
|
|
|
|
|
teacher.setSubjects((ArrayList<GpTeacher.GnericBase>) map.get("subjects"));
|
|
|
|
|
teacher.setGrades((ArrayList<GpTeacher.GnericBase>) map.get("grades"));
|
|
|
|
|
Object practiceTimeObj = map.get("practiceTime");
|
|
|
|
|
if (practiceTimeObj instanceof Long) {
|
|
|
|
|
teacher.setPracticeTime((Long) practiceTimeObj);
|
|
|
|
|
} else {
|
|
|
|
|
teacher.setPracticeTime(0L); // 或者设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
Object titleObj = map.get("title");
|
|
|
|
|
if (titleObj instanceof String) {
|
|
|
|
|
teacher.setTitle((String) titleObj);
|
|
|
|
|
} else {
|
|
|
|
|
teacher.setTitle(null); // 或者设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
Object degreeObj = map.get("degree");
|
|
|
|
|
if (degreeObj instanceof String) {
|
|
|
|
|
teacher.setDegree((String) degreeObj);
|
|
|
|
|
} else {
|
|
|
|
|
teacher.setDegree(null); // 或者设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
Map<String, Object> basicMap = (Map<String, Object>) map.get("basic");
|
|
|
|
|
//teacher.setBasic(new GpTeacher.GPBasicInfo(basicMap.get("name").toString(),basicMap.get("fullName").toString(),basicMap.get("picture").toString(),basicMap.get("region").toString(),basicMap.get("province").toString(),basicMap.get("city").toString(),basicMap.get("dist").toString(),basicMap.get("gender").toString(),basicMap.get("age").toString(),basicMap.get("address").toString()));
|
|
|
|
|
GpTeacher.GPBasicInfo basic = new GpTeacher.GPBasicInfo();
|
|
|
|
|
Object nameObj = basicMap.get("name");
|
|
|
|
|
if (nameObj instanceof String) {
|
|
|
|
|
basic.setName((String) nameObj);
|
|
|
|
|
} else {
|
|
|
|
|
basic.setName(null); // 或者设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
Object fullNameObj = basicMap.get("fullName");
|
|
|
|
|
if (fullNameObj instanceof String) {
|
|
|
|
|
basic.setFullName((String) fullNameObj);
|
|
|
|
|
} else {
|
|
|
|
|
basic.setFullName(null); // 或者设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
Object distObj = basicMap.get("dist");
|
|
|
|
|
if (distObj instanceof String) {
|
|
|
|
|
basic.setDist((String) distObj);
|
|
|
|
|
} else {
|
|
|
|
|
basic.setDist(null); // 或者设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
Object genderObj = basicMap.get("gender");
|
|
|
|
|
if (genderObj instanceof String) {
|
|
|
|
|
basic.setGender((String) genderObj);
|
|
|
|
|
} else {
|
|
|
|
|
basic.setGender(null); // 或者设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
Object ageObj = basicMap.get("age");
|
|
|
|
|
if (ageObj instanceof Integer) {
|
|
|
|
|
basic.setAge((Integer) ageObj);
|
|
|
|
|
} else {
|
|
|
|
|
basic.setAge(0); // 或者设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
teacher.basic = basic;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据实际属性进行转换
|
|
|
|
|
return teacher;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<Long, Integer> getTeacherByRecord(TeacherDto teacherDto) {
|
|
|
|
|
final int SLICE_SIZE = 100;
|
|
|
|
@ -226,6 +372,18 @@ public class TeacherServiceImpl implements TeacherService {
|
|
|
|
|
return gradeMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> getTeacherBase(GpTeacherDto gpTeacherDto, HttpServletRequest request) {
|
|
|
|
|
|
|
|
|
|
Map<String, Object> gradeMap;
|
|
|
|
|
try {
|
|
|
|
|
gradeMap = GroupUtil.getTeacherInfo(gpTeacherDto,new GroupUtil(env), request);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据转换错误");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return gradeMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|