tea null
build / build-push (push) Successful in 1m5s

This commit is contained in:
wanghu
2026-09-08 12:04:00 +08:00
parent 2aefd1175b
commit d1a748c0ff
2 changed files with 64 additions and 1 deletions
@@ -3,6 +3,7 @@ package com.yunhai.bschclassmanage.controller.oapi.oa;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.yunhai.bschclassmanage.Repository.SchTeacherGroupRepository;
import com.yunhai.bschclassmanage.Repository.SchTeacherRepository;
import com.yunhai.bschclassmanage.config.Config;
import com.yunhai.bschclassmanage.entity.SchTeacher;
@@ -21,7 +22,10 @@ import org.springframework.web.bind.annotation.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -37,6 +41,9 @@ public class TeainfoController {
@Autowired
private SchTeacherRepository schTeacherRepository;
@Autowired
private SchTeacherGroupRepository schTeacherGroupRepository;
@Autowired
private ISchInfoService schInfoService;
@@ -50,7 +57,11 @@ public class TeainfoController {
// 2. 鐩存帴浣跨敤 uid 鏌ヨ
return schTeacherRepository.findByTeaId(uid) // 鍋囪 findByTeaId 杩斿洖 Optional<SchTeacher>
.map(this::convertToTeaInfoVO) // 灏?SchTeacher 杞负 TeaInfoVO
.map(teacher -> {
fillGroupList(Collections.singletonList(teacher), null);
return teacher;
})
.map(this::convertToTeaInfoVO)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@@ -94,6 +105,30 @@ public class TeainfoController {
return vo;
}
/**
* 批量回填教师的分组列表(groupList 为 @Transient 字段,查询后需要单独填充)。
* schId 不为空时只查该校的组关系,保证取到的 GroupID/SchSerID 属于当前学校。
*/
private void fillGroupList(List<SchTeacher> teachers, Integer schId) {
if (teachers == null || teachers.isEmpty()) {
return;
}
List<Integer> teaIds = teachers.stream()
.map(SchTeacher::getTeaId)
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (teaIds.isEmpty()) {
return;
}
List<SchTeacherGroup> relations = (schId != null)
? schTeacherGroupRepository.findByTeaIdInAndSchId(teaIds, schId)
: schTeacherGroupRepository.findByTeaIdIn(teaIds);
Map<Integer, List<SchTeacherGroup>> groupMap = relations.stream()
.filter(g -> g.getTeaId() != null)
.collect(Collectors.groupingBy(SchTeacherGroup::getTeaId));
teachers.forEach(t -> t.setGroupList(groupMap.getOrDefault(t.getTeaId(), Collections.emptyList())));
}
@PostMapping("GetArrTeainfo")
@Operation(summary = "根据教师id数组 获取教师列表")
public ResponseEntity<List<TeaInfoVO>> getArrTeainfo(@RequestBody String userIds) {
@@ -105,8 +140,10 @@ public class TeainfoController {
List<Integer> uids= Arrays.asList(OtherUtil.convertToArray(userIds));
List<SchTeacher> teachers = schTeacherRepository.findByTeaIdIn(uids);
fillGroupList(teachers, null);
List<TeaInfoVO> voList = teachers.stream()
.map(this::convertToTeaInfoVO)
.filter(Objects::nonNull)
.collect(Collectors.toList());
return voList.isEmpty() ? ResponseEntity.noContent().build() : ResponseEntity.ok(voList);
@@ -141,9 +178,11 @@ public class TeainfoController {
}
List<SchTeacher> teachers = schTeacherService.getSchTeacherList(resolvedSchId);
fillGroupList(teachers, resolvedSchId);
List<TeaInfoVO> voList = teachers.stream()
.map(this::convertToTeaInfoVO)
.filter(Objects::nonNull)
.collect(Collectors.toList());
return voList.isEmpty() ? ResponseEntity.noContent().build() : ResponseEntity.ok(voList);
@@ -1,30 +1,54 @@
package com.yunhai.bschclassmanage.model.oa;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class TeaInfoVO {
@JsonProperty("SchSerID")
private String SchSerID;
@JsonProperty("Teapolitical")
private String Teapolitical;
@JsonProperty("TeaWorkStart")
private String TeaWorkStart;
@JsonProperty("Account")
private String Account;
@JsonProperty("SchSerIDs")
private String SchSerIDs;
@JsonProperty("role")
private Integer role;
@JsonProperty("JiaoYuJu")
private String JiaoYuJu;
@JsonProperty("TeaSex")
private String TeaSex;
@JsonProperty("IsLeadingMiddle")
private Integer IsLeadingMiddle;
@JsonProperty("TeaOriginPlace")
private String TeaOriginPlace;
@JsonProperty("Photo")
private String Photo;
@JsonProperty("TeaIDCard")
private String TeaIDCard;
@JsonProperty("Name")
private String Name;
@JsonProperty("GroupID")
private Integer GroupID;
@JsonProperty("SchName")
private String SchName;
@JsonProperty("TeaTeachStart")
private String TeaTeachStart;
@JsonProperty("TeaSerID")
private String TeaSerID;
@JsonProperty("UserID")
private Integer UserID;
@JsonProperty("TeaNation")
private String TeaNation;
@JsonProperty("Tel")
private String Tel;
@JsonProperty("TeaWorkType")
private String TeaWorkType;
@JsonProperty("TeaNo")
private Integer TeaNo;
@JsonProperty("TeaBirth")
private String TeaBirth;
}