代码优化
This commit is contained in:
parent
ff26f25a99
commit
e0f7ec883e
|
|
@ -31,9 +31,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
|
|
@ -382,7 +380,13 @@ public class TbPeopleServiceImpl implements TbPeopleService {
|
|||
ExcelUtil<TbPeopleDto> util = new ExcelUtil<>(TbPeopleDto.class);
|
||||
List<TbPeopleDto> tbPeopleList = util.importExcel(file.getInputStream());
|
||||
int result = 0;
|
||||
// 使用一个 Set 来记录已经处理过的 idCard,避免重复处理相同的人员数据
|
||||
Set<String> processedIdCards = new HashSet<>();
|
||||
for (TbPeopleDto tbPeople : tbPeopleList) {
|
||||
// 如果当前记录已经处理过,跳过
|
||||
if (processedIdCards.contains(tbPeople.getIdCard())) {
|
||||
continue;
|
||||
}
|
||||
List<TbPeople> peopleList = tbPeopleDao.queryByName(tbPeople);
|
||||
if (CollectionUtils.isNotEmpty(peopleList)) {
|
||||
for (TbPeople people : peopleList) {
|
||||
|
|
@ -399,6 +403,8 @@ public class TbPeopleServiceImpl implements TbPeopleService {
|
|||
dto.setRelName(tbPeople.getRelName());
|
||||
dto.setPostCode(tbPeople.getPostCode());
|
||||
result += tbPeopleDao.update(dto);
|
||||
// 标记该 idCard 已处理
|
||||
processedIdCards.add(tbPeople.getIdCard());
|
||||
} else {
|
||||
//新增操作
|
||||
TbPeople dto = new TbPeople();
|
||||
|
|
@ -409,6 +415,8 @@ public class TbPeopleServiceImpl implements TbPeopleService {
|
|||
dto.setRelName(tbPeople.getRelName());
|
||||
dto.setPostCode(tbPeople.getPostCode());
|
||||
result += tbPeopleDao.insert(dto);
|
||||
// 标记该 idCard 已处理
|
||||
processedIdCards.add(tbPeople.getIdCard());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue