feat: 老法规覆盖导入只覆盖导入的字段

This commit is contained in:
2023-12-07 11:00:10 +08:00
parent 520b28eeab
commit b4e604d22b
@@ -957,7 +957,7 @@ public class OldSystemServiceImpl implements OldSystemService {
}
lawsNodeRelationService.removeByStandardId(es.getId());
lawsNodeRelationService.addRelation(treeNode.getId(), null, es.getId());
}catch (Exception e) {
} catch (Exception e) {
log.error("错误数据:{}", ss.toString());
ss.setErrorInfo(e.getMessage());
errImportList.add(ss);
@@ -1050,7 +1050,7 @@ public class OldSystemServiceImpl implements OldSystemService {
LawsDomesticStandard gb = gbMap.get(gbStandSystem.getStandardNumber());
if (gb == null) {
throw new JeroBootException("未找到该国标,标准编号:" + gbStandSystem.getStandardNumber()
+ ",标准名称:" + gbStandSystem.getStandardName());
+ ",标准名称:" + gbStandSystem.getStandardName());
}
if (type.equals("approval")) {
if (!standardType.endsWith("标准")) {
@@ -1339,8 +1339,7 @@ public class OldSystemServiceImpl implements OldSystemService {
if (existingEntity != null) {
// 如果存在,则执行更新操作
entity.setIsAsmsImport("0");
UpdateWrapper<LawsDomesticStandard> updateWrapper = this.getDomesticUpdateWrapper(entity);
domesticStandardService.update(entity, updateWrapper);
domesticStandardService.updateById(entity);
} else {
// 如果不存在,则执行保存操作
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) {
esDatalist = esDatalist.stream().filter(o -> o.getBzfl().contains("企业标准"))
.collect(Collectors.toList());
@@ -1632,5 +1594,4 @@ public class OldSystemServiceImpl implements OldSystemService {
}
}