feat: 老法规覆盖导入只覆盖导入的字段
This commit is contained in:
+1
-40
@@ -1339,8 +1339,7 @@ public class OldSystemServiceImpl implements OldSystemService {
|
|||||||
if (existingEntity != null) {
|
if (existingEntity != null) {
|
||||||
// 如果存在,则执行更新操作
|
// 如果存在,则执行更新操作
|
||||||
entity.setIsAsmsImport("0");
|
entity.setIsAsmsImport("0");
|
||||||
UpdateWrapper<LawsDomesticStandard> updateWrapper = this.getDomesticUpdateWrapper(entity);
|
domesticStandardService.updateById(entity);
|
||||||
domesticStandardService.update(entity, updateWrapper);
|
|
||||||
} else {
|
} else {
|
||||||
// 如果不存在,则执行保存操作
|
// 如果不存在,则执行保存操作
|
||||||
domesticStandardService.save(entity);
|
domesticStandardService.save(entity);
|
||||||
@@ -1378,43 +1377,6 @@ public class OldSystemServiceImpl implements OldSystemService {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
private UpdateWrapper<LawsDomesticStandard> getDomesticUpdateWrapper(LawsDomesticStandard entity) {
|
|
||||||
// 遍历是实体类的所有字段,如果有值则不拼接update语句,如果没有值则拼接语句
|
|
||||||
UpdateWrapper<LawsDomesticStandard> updateWrapper = new UpdateWrapper<>();
|
|
||||||
updateWrapper.eq("id", entity.getId());
|
|
||||||
Field[] fields = entity.getClass().getDeclaredFields();
|
|
||||||
// 创建一个不做处理的数组
|
|
||||||
List<String> ignoreFields = Arrays.asList("id",
|
|
||||||
"serialVersionUID", "delFlag",
|
|
||||||
"createBy", "createTime", "updateBy", "updateTime", "orgCode");
|
|
||||||
for (Field field : fields) {
|
|
||||||
if (!ignoreFields.contains(field.getName())) {
|
|
||||||
field.setAccessible(true);
|
|
||||||
String dbColumnName = convertFieldNameToDbColumnName(field.getName());
|
|
||||||
if (field.get(entity) == null) {
|
|
||||||
updateWrapper.set(dbColumnName, null);
|
|
||||||
} else {
|
|
||||||
updateWrapper.set(dbColumnName, field.get(entity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return updateWrapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 定义一个方法来执行字段名转换
|
|
||||||
private String convertFieldNameToDbColumnName(String fieldName) {
|
|
||||||
StringBuilder dbColumnName = new StringBuilder();
|
|
||||||
for (char c : fieldName.toCharArray()) {
|
|
||||||
if (Character.isUpperCase(c)) {
|
|
||||||
dbColumnName.append("_").append(Character.toLowerCase(c));
|
|
||||||
} else {
|
|
||||||
dbColumnName.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dbColumnName.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void oldSysESImport(List<OldSystemImportDTO> esDatalist, List<OldSystemImportDTO> errImportList) {
|
private void oldSysESImport(List<OldSystemImportDTO> esDatalist, List<OldSystemImportDTO> errImportList) {
|
||||||
esDatalist = esDatalist.stream().filter(o -> o.getBzfl().contains("企业标准"))
|
esDatalist = esDatalist.stream().filter(o -> o.getBzfl().contains("企业标准"))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@@ -1632,5 +1594,4 @@ public class OldSystemServiceImpl implements OldSystemService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user