From 3c182b10f9fbc8171e9103eb13b9f8ec780ca07e Mon Sep 17 00:00:00 2001 From: Carina Date: Sun, 5 Dec 2021 17:18:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=BB=84=E7=BB=87=E6=97=B6=20=E6=AF=8F?= =?UTF-8?q?=E6=AC=A1=E4=BC=9A=E5=A4=9A=E5=87=BA=E6=9D=A5=E4=B8=80=E6=9D=A1?= =?UTF-8?q?=E5=9E=83=E5=9C=BE=E6=95=B0=E6=8D=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/UserOrgRefServiceImpl.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java index 5077f11..fa39f1a 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/user/service/impl/UserOrgRefServiceImpl.java @@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import org.apache.commons.lang3.StringUtils; import org.opsli.api.wrapper.system.org.SysOrgModel; import org.opsli.api.wrapper.system.user.UserModel; @@ -50,6 +51,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Map; /** @@ -159,30 +161,28 @@ public class UserOrgRefServiceImpl extends ServiceImpl orgRefList = Lists.newArrayList(); + + // 保障唯一 Key=orgId, Val=Ref + Map orgRefMap = Maps.newHashMap(); SysOrgModel defModel = model.getDefModel(); if(defModel != null){ SysUserOrgRef orgRef = createOrgRef( model.getUserId(), defModel, DictType.NO_YES_YES.getValue()); - orgRefList.add(orgRef); + orgRefMap.put(defModel.getId(), orgRef); } + List orgModelList = model.getOrgModelList(); if(!CollUtil.isEmpty(orgModelList)){ for (SysOrgModel orgModel : orgModelList) { SysUserOrgRef orgRef = createOrgRef( model.getUserId(), orgModel, DictType.NO_YES_NO.getValue()); - orgRefList.add(orgRef); + orgRefMap.putIfAbsent(orgModel.getId(), orgRef); } } - boolean izExistOrg = false; - - if(!CollUtil.isEmpty(orgRefList)){ - // 批量保存 - izExistOrg = super.saveBatch(orgRefList); - } + // 批量保存 + boolean izExistOrg = super.saveBatch(orgRefMap.values()); // 修改用户组织状态 this.updateUserOrgFlag(model.getUserId(), izExistOrg);