From 490c8f7008601c8d4b5f2202b1567f9527fb96d7 Mon Sep 17 00:00:00 2001 From: Claude Lee Date: Fri, 27 Sep 2024 15:43:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8F=92=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9D=83=E9=99=90=E7=9A=84=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E5=AF=B9=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=BF=9B=E8=A1=8C=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DhcDataAuthServiceImpl.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/ruoyi-system/src/main/java/com/ruoyi/dhc/service/impl/DhcDataAuthServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/dhc/service/impl/DhcDataAuthServiceImpl.java index 496358a..f8bda52 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/dhc/service/impl/DhcDataAuthServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/dhc/service/impl/DhcDataAuthServiceImpl.java @@ -5,6 +5,7 @@ import com.ruoyi.dhc.domain.DhcDataAuth; import com.ruoyi.dhc.domain.DhcDataAuthDetail; import com.ruoyi.dhc.mapper.DhcDataAuthMapper; import com.ruoyi.dhc.service.IDhcDataAuthService; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -72,6 +73,7 @@ public class DhcDataAuthServiceImpl implements IDhcDataAuthService @Override public int insertDhcDataAuth(DhcDataAuth dhcDataAuth) { + /* if (dhcDataAuth.getDataAuthId() != null) { dhcDataAuthMapper.deleteDhcDataAuthByDataAuthId(dhcDataAuth.getDataAuthId()); dhcDataAuthMapper.deleteDataAuthDetailByDataAuthIds(dhcDataAuth); @@ -81,6 +83,36 @@ public class DhcDataAuthServiceImpl implements IDhcDataAuthService item.setDataAuthId(dhcDataAuth.getDataAuthId()); }); dhcDataAuthMapper.batchAddDataAuthDetail(dhcDataAuth.getDetailList()); + */ + + Long dataAuthId; + int count = 0; + + // 首先按条件找现有已存在的头表,如果已经有了,就不用再建了。 + List dhcDataAuthList = dhcDataAuthMapper.selectDhcDataAuthList(dhcDataAuth); + if (CollectionUtils.isNotEmpty(dhcDataAuthList)) { + DhcDataAuth first = dhcDataAuthList.get(0); + dataAuthId = first.getDataAuthId(); + } else { + dhcDataAuthMapper.insertDhcDataAuth(dhcDataAuth); + dataAuthId = dhcDataAuth.getDataAuthId(); + } + + // 找到现有的所有明细 + DhcDataAuth params = new DhcDataAuth(); + params.setDataAuthId(dataAuthId); + params.setDetailType("0"); + List detailList = dhcDataAuthMapper.selectDhcDataAuthDetailList(params); + + // 遍历明细,检查是否存在,只对不存在的进行插入 + List newDetailList = dhcDataAuth.getDetailList().stream() + .filter(itemToAdd -> detailList.stream().noneMatch(item -> item.getDetailCode().equals(itemToAdd.getDetailCode()))) + .peek(item-> item.setDataAuthId(dataAuthId)).collect(Collectors.toList()); + + if (CollectionUtils.isNotEmpty(newDetailList)) { + dhcDataAuthMapper.batchAddDataAuthDetail(newDetailList); + } + return count; }