From e0f7ec883e1f9428c81aeb9f521d45c968ebffc8 Mon Sep 17 00:00:00 2001 From: mashuai Date: Thu, 7 Nov 2024 14:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basic/service/impl/TbPeopleServiceImpl.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bonus-modules/base/src/main/java/com/bonus/base/basic/service/impl/TbPeopleServiceImpl.java b/bonus-modules/base/src/main/java/com/bonus/base/basic/service/impl/TbPeopleServiceImpl.java index a7a03dc..5cd7f6a 100644 --- a/bonus-modules/base/src/main/java/com/bonus/base/basic/service/impl/TbPeopleServiceImpl.java +++ b/bonus-modules/base/src/main/java/com/bonus/base/basic/service/impl/TbPeopleServiceImpl.java @@ -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 util = new ExcelUtil<>(TbPeopleDto.class); List tbPeopleList = util.importExcel(file.getInputStream()); int result = 0; + // 使用一个 Set 来记录已经处理过的 idCard,避免重复处理相同的人员数据 + Set processedIdCards = new HashSet<>(); for (TbPeopleDto tbPeople : tbPeopleList) { + // 如果当前记录已经处理过,跳过 + if (processedIdCards.contains(tbPeople.getIdCard())) { + continue; + } List 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()); } } }