From 18fc5880e0db4f394fc4e951e653155d7719fe03 Mon Sep 17 00:00:00 2001 From: weizhiqiang <598748873@qq.com> Date: Sat, 10 Dec 2022 14:30:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9B=A2=E9=98=9F=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/AbstractTeamServiceImpl.java | 57 ++++++------------- .../service/impl/TeamBusinessServiceImpl.java | 8 ++- .../service/impl/TeamTemplateServiceImpl.java | 2 +- 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/AbstractTeamServiceImpl.java b/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/AbstractTeamServiceImpl.java index 38e2287c..33fd05a3 100644 --- a/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/AbstractTeamServiceImpl.java +++ b/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/AbstractTeamServiceImpl.java @@ -49,7 +49,11 @@ public class AbstractTeamServiceImpl, T extends Ab String teamId = entity.getId(); List teamRoleList = entity.getTeamRoleList(); String serviceClassName = getServiceClassName(); - saveNewTeamRole(teamId, teamRoleList, serviceClassName, userId); + if (CollectionUtil.isNotEmpty(teamRoleList)) { + saveRole(userId, teamId, teamRoleList, serviceClassName); + } + // 修改团队用户信息 + updateRoleUser(userId, teamId, teamRoleList, serviceClassName, new ArrayList<>()); if (CollectionUtil.isNotEmpty(entity.getTeamObjectPermissionList())) { saveTeamOwnerPermission(teamId, serviceClassName, userId, entity.getTeamObjectPermissionList()); @@ -69,7 +73,7 @@ public class AbstractTeamServiceImpl, T extends Ab updateRole(userId, teamId, newTeamRoleList, serviceClassName, oldTeamRoleList, oldRoleKeys); // 修改团队用户信息 - updateRoleUser(userId, teamId, newTeamRoleList, serviceClassName, oldRoleKeys); + updateRoleUser(userId, teamId, newTeamRoleList, serviceClassName, oldTeamRoleList); // 修改权限信息 updatePermission(entity.getTeamObjectPermissionList(), oldTeam.getTeamObjectPermissionList(), teamId, serviceClassName, userId); @@ -91,7 +95,9 @@ public class AbstractTeamServiceImpl, T extends Ab List addTeamRoleMaps = newTeamRoleList.stream() .filter(item -> !oldRoleKeys.contains(item.getRoleId())).collect(Collectors.toList()); // 新增 - saveNewTeamRole(teamId, addTeamRoleMaps, serviceClassName, userId); + if (CollectionUtil.isNotEmpty(addTeamRoleMaps)) { + saveRole(userId, teamId, addTeamRoleMaps, serviceClassName); + } // (旧数据 - 新数据) 从数据库删除 List deleteTeamRole = oldTeamRoleList.stream() .filter(item -> !newRoleKeys.contains(item.getRoleId())).collect(Collectors.toList()); @@ -102,20 +108,16 @@ public class AbstractTeamServiceImpl, T extends Ab } } - private void updateRoleUser(String userId, String teamId, List newTeamRoleList, String serviceClassName, List oldRoleKeys) { - // 新数据和旧数据交集(团队角色)需要编辑的数据 - List oldTeamRole = newTeamRoleList.stream() - .filter(item -> oldRoleKeys.contains(item.getRoleId())).collect(Collectors.toList()); - + private void updateRoleUser(String userId, String teamId, List newTeamRoleList, String serviceClassName, List oldTeamRole) { // 新数据 - 旧数据 更新到数据库 - List newRoleUser = getTeamRoleUserList(oldTeamRole); - List newRoleUserKeys = newRoleUser.stream().map(bean -> bean.getTeamId() + bean.getUserId()).collect(Collectors.toList()); + List newRoleUser = getTeamRoleUserList(newTeamRoleList); + List newRoleUserKeys = newRoleUser.stream().map(bean -> teamId + bean.getUserId()).collect(Collectors.toList()); // 数据库里面的该团队模板下的用户信息 List oldRoleUser = getTeamRoleUserList(oldTeamRole); - List oldRoleUserKeys = oldRoleUser.stream().map(bean -> bean.getTeamId() + bean.getUserId()).collect(Collectors.toList()); + List oldRoleUserKeys = oldRoleUser.stream().map(bean -> teamId + bean.getUserId()).collect(Collectors.toList()); // 需要新增的用户信息 List addTeamRoleUser = newRoleUser.stream() - .filter(item -> !oldRoleUserKeys.contains(item.getTeamId() + item.getUserId())).collect(Collectors.toList()); + .filter(item -> !oldRoleUserKeys.contains(teamId + item.getUserId())).collect(Collectors.toList()); addTeamRoleUser.forEach(p -> { p.setId(null); p.setTeamId(teamId); @@ -126,7 +128,7 @@ public class AbstractTeamServiceImpl, T extends Ab } // 删除用户关联信息 List deleteRoleUser = oldRoleUser.stream() - .filter(predicate -> !newRoleUserKeys.contains(predicate.getTeamId() + predicate.getUserId())).collect(Collectors.toList()); + .filter(predicate -> !newRoleUserKeys.contains(teamId + predicate.getUserId())).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(deleteRoleUser)) { List deleteRoleUserLinkIds = deleteRoleUser.stream().map(TeamRoleUser::getId).collect(Collectors.toList()); teamRoleUserService.deleteById(deleteRoleUserLinkIds); @@ -171,13 +173,6 @@ public class AbstractTeamServiceImpl, T extends Ab .filter(Objects::nonNull).collect(Collectors.toList()); } - public void saveNewTeamRole(String teamId, List teamRoleList, String serviceClassName, String userId) { - if (CollectionUtil.isNotEmpty(teamRoleList)) { - saveRole(userId, teamId, teamRoleList, serviceClassName); - saveRoleUser(userId, teamId, teamRoleList, serviceClassName); - } - } - public void saveTeamOwnerPermission(String teamId, String serviceClassName, String userId, List addPermission) { addPermission.forEach(bean -> { bean.setTeamId(teamId); @@ -195,27 +190,11 @@ public class AbstractTeamServiceImpl, T extends Ab teamRoleService.createEntity(teamRoleList, userId); } - private void saveRoleUser(String userId, String teamId, List teamRoleList, String serviceClassName) { - List teamRoleUserList = teamRoleList.stream() - .filter(teamRole -> CollectionUtil.isNotEmpty(teamRole.getTeamRoleUserList())) - .flatMap(teamRole -> { - teamRole.getTeamRoleUserList().forEach(teamRoleUser -> { - teamRoleUser.setRoleId(teamRole.getRoleId()); - teamRoleUser.setTeamId(teamId); - teamRoleUser.setTeamKey(serviceClassName); - }); - return teamRole.getTeamRoleUserList().stream(); - }).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(teamRoleUserList)) { - teamRoleUserService.createEntity(teamRoleUserList, userId); - } - } - @Override public T getDataFromDb(String id) { T team = super.getDataFromDb(id); - Map> teamRoleMap = teamRoleService.queryTeamRoleByTeamIds(id); - team.setTeamRoleList(teamRoleMap.get(id)); + Map> teamRoleMap = teamRoleService.queryTeamRoleByTeamIds(team.getId()); + team.setTeamRoleList(teamRoleMap.get(team.getId())); List teamObjectPermissionList = new ArrayList<>(); if (CollectionUtil.isNotEmpty(team.getTeamRoleList())) { // 查询角色权限 @@ -229,7 +208,7 @@ public class AbstractTeamServiceImpl, T extends Ab if (CollectionUtil.isNotEmpty(userIds)) { ownerIds.addAll(userIds); } - List authermissionList = teamObjectPermissionService.queryPermissionByTeamId(id, ownerIds); + List authermissionList = teamObjectPermissionService.queryPermissionByTeamId(team.getId(), ownerIds); teamObjectPermissionList.addAll(authermissionList); } team.setTeamObjectPermissionList(teamObjectPermissionList); diff --git a/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/TeamBusinessServiceImpl.java b/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/TeamBusinessServiceImpl.java index f2c536e4..328073fe 100644 --- a/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/TeamBusinessServiceImpl.java +++ b/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/TeamBusinessServiceImpl.java @@ -20,6 +20,7 @@ import com.skyeye.team.service.TeamBusinessService; import com.skyeye.team.service.TeamTemplateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; @@ -52,6 +53,7 @@ public class TeamBusinessServiceImpl extends AbstractTeamServiceImpl params = inputObject.getParams(); String teamTemplateId = params.get("teamTemplateId").toString(); @@ -101,6 +103,7 @@ public class TeamBusinessServiceImpl extends AbstractTeamServiceImpl params = inputObject.getParams(); String objectId = params.get("objectId").toString(); @@ -117,6 +120,7 @@ public class TeamBusinessServiceImpl extends AbstractTeamServiceImpl params = inputObject.getParams(); String objectId = params.get("objectId").toString(); @@ -126,7 +130,9 @@ public class TeamBusinessServiceImpl extends AbstractTeamServiceImpl enumDataId = enumDataList.stream().map(bean -> bean.get(CommonConstants.ID).toString()).collect(Collectors.toList()); String userId = inputObject.getLogParams().get(CommonConstants.ID).toString(); - iTeamBusinessService.checkAuthPermission(objectId, enumClassName, enumDataId, userId); + Map checkAuthPermission = iTeamBusinessService.checkAuthPermission(objectId, enumClassName, enumDataId, userId); + outputObject.setBean(checkAuthPermission); + outputObject.settotal(CommonNumConstants.NUM_ONE); } } diff --git a/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/TeamTemplateServiceImpl.java b/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/TeamTemplateServiceImpl.java index 6e8b87dc..33a75b9f 100644 --- a/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/TeamTemplateServiceImpl.java +++ b/skyeye-promote/skyeye-base-server/src/main/java/com/skyeye/team/service/impl/TeamTemplateServiceImpl.java @@ -64,7 +64,7 @@ public class TeamTemplateServiceImpl extends AbstractTeamServiceImpl updateWrapper = new UpdateWrapper<>(); updateWrapper.eq(CommonConstants.ID, id); TeamTemplate template = new TeamTemplate();