清除教师不存在的组
This commit is contained in:
@@ -342,36 +342,48 @@ public class SyncUserService implements ISyncUserService {
|
||||
}
|
||||
|
||||
if(isAll){
|
||||
// 清理用户中心不存在的教师:
|
||||
// 学校已存在、但用户中心(teacherUsers)已不存在的教师,需从活跃名单中清理。
|
||||
// 对本次同步涉及的每所学校,将「当前为转入状态、但不在本次下发分组列表」的教师分组标记为转出(OUT)。
|
||||
// 这样既把已从用户中心移除/调离的教师清理出活跃名单,又保留转出记录、可随下次同步逆向恢复(重新 IN)。
|
||||
// 仅针对本次同步覆盖的学校,避免误删未参与本批次的其他学校教师。
|
||||
setTransferTeacher(schIds,incomingGroupKeys);
|
||||
// 本次下发的教师 id 集合(用于判断「教师已不存在」)
|
||||
Set<Integer> teaIdSet = new HashSet<>(teaIds);
|
||||
// 对账学校范围 = 本次下发组涉及的学校 + 本次教师在库中的历史组学校,
|
||||
// 后者可覆盖「教师被调离某校、该校本批无其它教师下发」导致的漏清。
|
||||
Set<Integer> auditSchIds = new HashSet<>(schIds);
|
||||
for (SchTeacherGroup g : groupMap.values()) {
|
||||
if (g.getSchId() != null) auditSchIds.add(g.getSchId());
|
||||
}
|
||||
|
||||
// 清理用户中心不存在的教师/组:
|
||||
// 1) 教师已不存在(teaId 不在本次下发名单)→ 清除其所有组;
|
||||
// 2) 教师存在但某个组已不存在(组 key 不在本次下发)→ 清除该组。
|
||||
// 统一标记为转出(OUT),保留转出记录、可随下次同步逆向恢复(重新 IN)。
|
||||
setTransferTeacher(auditSchIds, teaIdSet, incomingGroupKeys);
|
||||
|
||||
// 同步后使受影响学校的教师缓存失效
|
||||
if (!schIds.isEmpty()) {
|
||||
schTeacherCacheService.clearTeacherCaches(schIds);
|
||||
if (!auditSchIds.isEmpty()) {
|
||||
schTeacherCacheService.clearTeacherCaches(auditSchIds);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setTransferTeacher( Set<Integer> schIds,Set<String> incomingGroupKeys)
|
||||
private void setTransferTeacher( Set<Integer> schIds, Set<Integer> teaIds, Set<String> incomingGroupKeys)
|
||||
{
|
||||
for (Integer schId : schIds) {
|
||||
List<SchTeacherGroup> currentInGroups = schTeacherGroupRepository.findBySchIdAndTransferStatus(schId, TransferStatus.IN.getId());
|
||||
List<SchTeacherGroup> toTransferOut = new ArrayList<>();
|
||||
for (SchTeacherGroup g : currentInGroups) {
|
||||
// 教师已不存在:清除该教师在本校的所有组
|
||||
boolean teacherMissing = g.getTeaId() == null || !teaIds.contains(g.getTeaId());
|
||||
// 教师存在,但该组已不存在(被用户中心移除)
|
||||
String key = buildTeacherGroupKeyWithSchId(g.getTeaId(), g.getGroupId(), g.getSchId());
|
||||
if (!incomingGroupKeys.contains(key)) {
|
||||
boolean groupMissing = !incomingGroupKeys.contains(key);
|
||||
if (teacherMissing || groupMissing) {
|
||||
g.setTransferStatus(TransferStatus.OUT.getId());
|
||||
toTransferOut.add(g);
|
||||
}
|
||||
}
|
||||
if (!toTransferOut.isEmpty()) {
|
||||
schTeacherGroupRepository.saveAll(toTransferOut);
|
||||
log.info("清理用户中心不存在的教师:schId={}, 转出教师分组数={}", schId, toTransferOut.size());
|
||||
log.info("清理用户中心不存在的教师/组:schId={}, 转出教师分组数={}", schId, toTransferOut.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user