|
@@ -37,28 +37,12 @@ public class OrgCenterDataDisposeServiceImpl implements OrgCenterDataDisposeServ
|
|
|
if (Objects.isNull(result) || result.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
- // 删除原有学校
|
|
|
+ // 禁用原有学校
|
|
|
List<BasicSchool> basicSchoolList = basicSchoolService.list();
|
|
|
- List<Long> oldIdList = basicSchoolList.stream().map(BasicSchool::getId).collect(Collectors.toList());
|
|
|
- List<Long> newIdList = result.stream().map(e -> SystemConstant.convertIdToLong(String.valueOf(e.get("id")))).collect(Collectors.toList());
|
|
|
- List<Long> needDisable = new ArrayList<>();
|
|
|
- List<Long> needDelete = new ArrayList<>();
|
|
|
- for (Long aLong : oldIdList) {
|
|
|
- if (!newIdList.contains(aLong)) {
|
|
|
- needDisable.add(aLong);
|
|
|
- } else {
|
|
|
- needDelete.add(aLong);
|
|
|
- }
|
|
|
- }
|
|
|
- if (needDisable.size() > 0) {
|
|
|
- basicSchoolService.update(new UpdateWrapper<BasicSchool>().lambda().set(BasicSchool::getEnable, false).in(BasicSchool::getId, needDisable));
|
|
|
- }
|
|
|
- if (needDelete.size() > 0) {
|
|
|
- basicSchoolService.remove(new QueryWrapper<BasicSchool>().lambda().in(BasicSchool::getId, needDelete));
|
|
|
- }
|
|
|
+ basicSchoolService.update(new UpdateWrapper<BasicSchool>().lambda().set(BasicSchool::getEnable, false).gt(BasicSchool::getId,0));
|
|
|
+
|
|
|
|
|
|
for (Map map : result) {
|
|
|
- Long id = SystemConstant.convertIdToLong(String.valueOf(map.get("id")));
|
|
|
String code = String.valueOf(map.get("code"));
|
|
|
String name = String.valueOf(map.get("name"));
|
|
|
String logo = String.valueOf(map.get("logo"));
|
|
@@ -67,20 +51,30 @@ public class OrgCenterDataDisposeServiceImpl implements OrgCenterDataDisposeServ
|
|
|
Map typeMap = JSONObject.parseObject(String.valueOf(map.get("type")));
|
|
|
String typeCode = String.valueOf(typeMap.get("code"));
|
|
|
String typeName = String.valueOf(typeMap.get("name"));
|
|
|
- if (!Arrays.stream(OrgCenterTypeEnum.values()).map(OrgCenterTypeEnum::getTypeCode).collect(Collectors.toList()).contains(typeCode)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("机构类型在枚举中不存在 + typeCode = " + typeCode);
|
|
|
+
|
|
|
+ List<BasicSchool> oldSchoolList = basicSchoolList.stream().filter(e -> e.getCode().equals(code)).collect(Collectors.toList());
|
|
|
+ if (oldSchoolList.size() > 1){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("学校信息异常");
|
|
|
}
|
|
|
- if (!OrgCenterTypeEnum.PARTNER.getTypeCode().equals(typeCode)) {
|
|
|
- BasicSchool school = new BasicSchool();
|
|
|
- school.setId(id);
|
|
|
- school.setCode(code);
|
|
|
- school.setName(name);
|
|
|
- school.setEnable(true);
|
|
|
- school.setAccessKey(accessKey);
|
|
|
- school.setAccessSecret(accessSecret);
|
|
|
- school.setLogo(logo);
|
|
|
- basicSchoolService.save(school);
|
|
|
+ Long schoolId;
|
|
|
+ if (oldSchoolList.size() > 0){
|
|
|
+ // 系统中原先就有该学校 -》 更新
|
|
|
+ BasicSchool oldSchool = oldSchoolList.get(0);
|
|
|
+ schoolId = oldSchool.getId();
|
|
|
+ }else {
|
|
|
+ // 系统中没有该学校 -》 新增 (系统中如果id被占用会报错)
|
|
|
+ schoolId = SystemConstant.getDbUuid();
|
|
|
}
|
|
|
+
|
|
|
+ BasicSchool school = new BasicSchool();
|
|
|
+ school.setId(schoolId);
|
|
|
+ school.setCode(code);
|
|
|
+ school.setName(name);
|
|
|
+ school.setEnable(true);
|
|
|
+ school.setAccessKey(accessKey);
|
|
|
+ school.setAccessSecret(accessSecret);
|
|
|
+ school.setLogo(logo);
|
|
|
+ basicSchoolService.saveOrUpdate(school);
|
|
|
}
|
|
|
}
|
|
|
}
|