update 教龄 性别 学历

develop
hhb@hotmail.com 4 weeks ago
parent de621c8541
commit ab78ec557f

@ -1,5 +1,6 @@
package cn.teammodel.controller.admin.service; package cn.teammodel.controller.admin.service;
import cn.teammodel.model.dto.admin.teacher.GpTeacherDto;
import cn.teammodel.model.dto.admin.teacher.TeacherDto; import cn.teammodel.model.dto.admin.teacher.TeacherDto;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;

@ -4,11 +4,14 @@ import cn.teammodel.common.ErrorCode;
import cn.teammodel.common.PK; import cn.teammodel.common.PK;
import cn.teammodel.config.exception.ServiceException; import cn.teammodel.config.exception.ServiceException;
import cn.teammodel.controller.admin.service.TeacherService; 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.dto.admin.teacher.TeacherDto;
import cn.teammodel.model.entity.common.GroupList; 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.LessonRecord;
import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.school.School;
import cn.teammodel.model.entity.school.SchoolTeacher; import cn.teammodel.model.entity.school.SchoolTeacher;
import cn.teammodel.model.vo.admin.GpTeacherVo;
import cn.teammodel.repository.LessonRecordRepository; import cn.teammodel.repository.LessonRecordRepository;
import cn.teammodel.repository.SchoolGroupListRepository; import cn.teammodel.repository.SchoolGroupListRepository;
import cn.teammodel.repository.SchoolRepository; import cn.teammodel.repository.SchoolRepository;
@ -29,6 +32,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.time.*; import java.time.*;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import static cn.teammodel.utils.SchoolDateUtil.calculateWeekNum; 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"); String url = env.getProperty("ies.server-url-get-teacher-all");
try { try {
teachers = GroupUtil.getGroupId(teacherDto,new GroupUtil(env), request,url); 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) { }catch (Exception e) {
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据转换错误"); throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据转换错误");
@ -114,6 +157,109 @@ public class TeacherServiceImpl implements TeacherService {
return teachers; 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 @Override
public Map<Long, Integer> getTeacherByRecord(TeacherDto teacherDto) { public Map<Long, Integer> getTeacherByRecord(TeacherDto teacherDto) {
final int SLICE_SIZE = 100; final int SLICE_SIZE = 100;
@ -226,6 +372,18 @@ public class TeacherServiceImpl implements TeacherService {
return gradeMap; 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) { private static @NotNull Map<String, Integer> getStringIntegerMap(List<School.Subject> subjects, List<SchoolTeacher> schoolTeachers) {
Map<String, String> subjectNameMap = new HashMap<>(); Map<String, String> subjectNameMap = new HashMap<>();
for (School.Subject subject : subjects) { for (School.Subject subject : subjects) {

@ -0,0 +1,12 @@
package cn.teammodel.model.dto.admin.teacher;
import lombok.Data;
import java.util.List;
@Data
public class GpTeacherDto {
private String grant_type = "mobiles_infos";
private String client = "7D340153-3B66-4BAF-8F1E-2EE02F7E1828";
private List<String> mobiles;
}

@ -0,0 +1,114 @@
package cn.teammodel.model.entity.school;
import lombok.Data;
import java.util.ArrayList;
@Data
public class GpTeacher {
public GPBasicInfo basic;
/// <summary>
/// 简介
/// </summary>
public String describe ;
/// <summary>
/// 描述
/// </summary>
public String depict ;
/// <summary>
/// 学段
/// </summary>
public ArrayList<GnericBase> periods ;
/// <summary>
/// 科目
/// </summary>
public ArrayList<GnericBase> subjects ;
/// <summary>
/// 年级
/// </summary>
public ArrayList<GnericBase> grades ;
/// <summary>
/// 从业时间
/// </summary>
public Long practiceTime ;
/// <summary>
/// 最高职称
/// </summary>
public String title ;
/// <summary>
/// 学历
/// </summary>
public String degree ;
public void setBasic(GnericBase basic) {
}
@Data
public static class GPBasicInfo {
/// <summary>
/// 昵称
/// </summary>
public String name ;
/// <summary>
/// 真实名称
/// </summary>
public String fullName ;
/// <summary>
/// 头像
/// </summary>
public String picture ;
/// <summary>
/// 国家或地区
/// </summary>
public String region ;
/// <summary>
/// 省份
/// </summary>
public String province ;
/// <summary>
/// 城市
/// </summary>
public String city ;
/// <summary>
/// 区县
/// </summary>
public String dist ;
/// <summary>
/// 性别,男M 女F保密S
/// </summary>
public String gender ;
/// <summary>
/// 年龄
/// </summary>
public Integer age ;
/// <summary>
/// 详细地址
/// </summary>
public String address ;
}
@Data
public static class GnericBase{
private String id ;
private String name ;
}
}

@ -0,0 +1,10 @@
package cn.teammodel.model.vo.admin;
import lombok.Data;
@Data
public class GpTeacherVo {
public String id ;
public String name ;
public String phone ;
}

@ -76,4 +76,52 @@ public class GroupUtil {
} }
return mapper; return mapper;
} }
public static Map<String, Object> getTeacherInfo(Object obj, GroupUtil groupUtil, HttpServletRequest request) {
Map<String, Object> mapper = new HashMap<>();
String evnStr = groupUtil.env.getProperty("spring.env");
String apiUrl;
if (evnStr != null && evnStr.equalsIgnoreCase("dev")) {
apiUrl = "https://gp.winteach.cn/open_teacher/find";
}else {
apiUrl = "https://gp.winteach.cn/open_teacher/find";
}
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(apiUrl);
//添加请求头
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
// 设置请求体
String jsonContent = JsonUtil.convertToJson(obj);
httpPost.setEntity(new StringEntity(jsonContent, ContentType.create("application/json", "UTF-8")));
// 发送请求
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
// 获取响应实体
HttpEntity entity = response.getEntity();
if (entity != null) {
// 解析响应内容
String jsonString = EntityUtils.toString(entity);
ObjectMapper objectMapper = new ObjectMapper();
mapper = objectMapper.readValue(jsonString, TypeFactory.defaultInstance().constructMapType(Map.class, String.class, Object.class));
}
// 检查响应状态码
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) throw new RuntimeException("Failed : HTTP error code : " + statusCode);
} catch (IOException e) {
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据解析异常");
}
} catch (IOException e) {
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "请求头异常");
}
return mapper;
}
} }

Loading…
Cancel
Save