update 同步身分信息

develop
hhb@hotmail.com 5 days ago
parent 032b740238
commit 6a440fe111

@ -197,10 +197,29 @@ public class TeacherServiceImpl implements TeacherService {
teachers.put("gender", genderCount);
teachers.put("degree", degreeCount);
teachers.put("info", teachersList);
teachers.remove("teachers");
List<GpTeacherVo> copyList = new ArrayList<>(teachersList);
// 同步保存,确保数据持久化
asyncTeacherService.asyncSavePtTeacherInfos(Collections.unmodifiableList(copyList));
//asyncTeacherService.syncSavePtTeacherInfos(teachersList); // 假设改为同步方法
// 优化查询与匹配
Set<String> teacherIds = teachersList.stream()
.map(GpTeacherVo::getId)
.collect(Collectors.toSet());
List<PtTeacherInfo> ptTeacherInfos = ptTeacherRepository.findAllTeacher(teacherIds);
Map<String, PtTeacherInfo> idToPtTeacherInfo = ptTeacherInfos.stream()
.collect(Collectors.toMap(PtTeacherInfo::getId, Function.identity()));
teachersList.forEach(teacher -> {
PtTeacherInfo info = idToPtTeacherInfo.get(teacher.getId());
if (info != null) {
teacher.setIdentity(info.getIdentity());
}
});
teachers.put("info", teachersList);
teachers.remove("teachers");
}catch (Exception e) {
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据转换错误");

@ -23,6 +23,7 @@ public class GpTeacherVo {
public String gender ;
public List<String> grade;
public String periodId ;
public List<String> identity;
public Integer version = 1;
@Data
public static class IdNameCode{

@ -7,6 +7,7 @@ import com.azure.spring.data.cosmos.repository.Query;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
@Repository
@ -15,4 +16,6 @@ public interface PtTeacherRepository extends CosmosRepository<PtTeacherInfo, Str
@Query(value = "SELECT * FROM c WHERE ARRAY_CONTAINS(@pairs, {id: c.id, code: c.code}, true) and c.pk = 'PtTeacher'")
List<PtTeacherInfo> findByIdCodePairs(@Param("pairs") List<IdCodePair> pairs);
@Query(value = "SELECT * FROM c WHERE c.pk = 'PtTeacher' and c.id in (@ids) ")
List<PtTeacherInfo> findAllTeacher(Collection<String> ids);
}

@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.List;
@ -29,7 +30,7 @@ public class AsyncTeacherService {
@Autowired
private PtTeacherRepository ptTeacherRepository;
@Async
@Transactional(rollbackFor = Exception.class)
public void asyncSavePtTeacherInfos(List<GpTeacherVo> teachersList) {
try {
Map<String, PtTeacherInfo> existingTeachers = loadExistingTeachers(teachersList);

Loading…
Cancel
Save