fix: 修复设置用户组织时 每次会多出来一条垃圾数据问题

pull/9/head
Carina 3 years ago
parent cae8bbd901
commit 3c182b10f9

@ -22,6 +22,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.org.SysOrgModel; import org.opsli.api.wrapper.system.org.SysOrgModel;
import org.opsli.api.wrapper.system.user.UserModel; 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.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
@ -159,30 +161,28 @@ public class UserOrgRefServiceImpl extends ServiceImpl<UserOrgRefMapper, SysUser
wrapper.eq(userIdField, model.getUserId()); wrapper.eq(userIdField, model.getUserId());
boolean removeFlag = super.remove(wrapper); boolean removeFlag = super.remove(wrapper);
// 设置组织
List<SysUserOrgRef> orgRefList = Lists.newArrayList(); // 保障唯一 Key=orgId, Val=Ref
Map<String, SysUserOrgRef> orgRefMap = Maps.newHashMap();
SysOrgModel defModel = model.getDefModel(); SysOrgModel defModel = model.getDefModel();
if(defModel != null){ if(defModel != null){
SysUserOrgRef orgRef = createOrgRef( SysUserOrgRef orgRef = createOrgRef(
model.getUserId(), defModel, DictType.NO_YES_YES.getValue()); model.getUserId(), defModel, DictType.NO_YES_YES.getValue());
orgRefList.add(orgRef); orgRefMap.put(defModel.getId(), orgRef);
} }
List<SysOrgModel> orgModelList = model.getOrgModelList(); List<SysOrgModel> orgModelList = model.getOrgModelList();
if(!CollUtil.isEmpty(orgModelList)){ if(!CollUtil.isEmpty(orgModelList)){
for (SysOrgModel orgModel : orgModelList) { for (SysOrgModel orgModel : orgModelList) {
SysUserOrgRef orgRef = createOrgRef( SysUserOrgRef orgRef = createOrgRef(
model.getUserId(), orgModel, DictType.NO_YES_NO.getValue()); 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); this.updateUserOrgFlag(model.getUserId(), izExistOrg);

Loading…
Cancel
Save