From 5d15287b2a06f978485ac6af71e33e1a82b43a65 Mon Sep 17 00:00:00 2001 From: kimi <kimi42345@gmail.com> Date: 星期三, 15 四月 2020 16:29:55 +0800 Subject: [PATCH] fix 上传后生成版本连接池用完不释放问题 --- src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java | 261 ++++++++++++++++++++++++++++++++++----------------- 1 files changed, 172 insertions(+), 89 deletions(-) diff --git a/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java b/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java index 789c6c0..d174081 100644 --- a/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java +++ b/src/main/java/com/highdatas/mdm/service/impl/MasterAuthorServiceImpl.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.mapper.Wrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.highdatas.mdm.controller.MasterAuthorController; +import com.highdatas.mdm.entity.Character; import com.highdatas.mdm.entity.*; import com.highdatas.mdm.mapper.MasterAuthorMapper; import com.highdatas.mdm.pojo.ActivitiStatus; @@ -47,7 +48,7 @@ IFlowsService flowsService; @Override - public HashMap<String, MasterAuthor> merageRoleAuthor(List<String> roleIds) { + public HashMap<String, MasterAuthor> merageRoleAuthor(Set<String> roleIds) { List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIds)); HashMap<String, MasterAuthor> resultMap = new HashMap<>(); @@ -69,52 +70,130 @@ } @Override - public List<SysMenu> getMenu(String userId) { - List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, userId)); - if (masterAuthors.isEmpty()) { - //user 鑾峰彇role - List<TUserRole> roles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq("user_id", userId)); - List<String> roleIds = roles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList()); - masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIds)); + public List<SysMenu> getMenu(Character character) { + MasterAuthorType type = character.getType(); + List<MasterAuthor> masterAuthors = null; + switch (type){ + case role: + masterAuthors = getRoleAuthors(character.getId(), null); + break; + case groupInfo: + masterAuthors = getOneGroupAuthors(character.getId(), null); + break; + case user: + masterAuthors = getUserAuthor(character.getId(), null); } - List<MasterAuthor> groupAuthors = getUserGroupAuthor(userId); - masterAuthors.addAll(groupAuthors); + if (masterAuthors == null || masterAuthors.isEmpty()) { + return null; + } List<String> menuIds = masterAuthors.stream().map(masterAuthor -> masterAuthor.getMenuId()).collect(Collectors.toList()); LinkedHashSet<String> strings = new LinkedHashSet<>(menuIds); LinkedHashSet<String> byParentId = menuService.getByParentId(strings); + if (byParentId == null) { + return null; + } List<SysMenu> sysMenus = menuService.selectBatchIds(byParentId); return sysMenus; } - private List<MasterAuthor> getUserGroupAuthor(String userId) { - //TODO - List<MasterAuthor> result = new ArrayList<>(); - List<String> groupIds = new ArrayList<>(); - for (String groupId : groupIds) { - List<MasterAuthor> masterAuthors = selectList( - new EntityWrapper<MasterAuthor>() - .eq(Constant.TYPE, MasterAuthorType.user) - .eq("is_group", true) - .eq(MasterAuthorController.character_id, groupId)); - if (masterAuthors.isEmpty()) { - //TODO getRoleList; - List<String> roleIds = new ArrayList<>(); - masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq("is_group", true).eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIds)); + private List<MasterAuthor> getUserAuthor(String characterId, MaintainField maintainField) { + Wrapper<MasterAuthor> userWrapper = new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, characterId); + + if (maintainField != null) { + if (maintainField.getId() != null) { + userWrapper.eq("maintain_field_id", maintainField.getId()); } - result.addAll(masterAuthors); + if (maintainField.getTableName() != null) { + userWrapper.eq("table_name",maintainField.getTableName()); + } + } + List<MasterAuthor> masterAuthors = selectList(userWrapper); + if (masterAuthors.isEmpty()) { + //user 鑾峰彇role + Set<String> roleIdSet = DbUtils.getRoleByUser(characterId); + if (roleIdSet.isEmpty()) { + return new ArrayList<>(); + }else { + Wrapper<MasterAuthor> roleWrapper = new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIdSet); + if (maintainField != null) { + roleWrapper.eq("maintain_field_id", maintainField.getId()).eq("table_name",maintainField.getTableName()); + } + masterAuthors = selectList(roleWrapper); + } + } + List<MasterAuthor> groupAuthors = getUserGroupAuthor(characterId, null); + masterAuthors.addAll(groupAuthors); + return masterAuthors; + } + + private List<MasterAuthor> getRoleAuthors(String characterId, MaintainField maintainField) { + Wrapper<MasterAuthor> roleWrapper = new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).eq(MasterAuthorController.character_id, characterId); + if (maintainField != null) { + if (maintainField.getId() != null) { + roleWrapper.eq("maintain_field_id", maintainField.getId()); + } + if (maintainField.getTableName() != null) { + roleWrapper.eq("table_name",maintainField.getTableName()); + } + + } + + return selectList(roleWrapper); + } + + private List<MasterAuthor> getUserGroupAuthor(String userId, MaintainField maintainField) { + Set<String> groupIdList = DbUtils.getGroupByUser(userId); + List<MasterAuthor> result = new ArrayList<>(); + if (groupIdList == null) { + return result; + } + + for (String groupId : groupIdList) { + List<MasterAuthor> oneGroupAuthors = getOneGroupAuthors(groupId, maintainField); + if (oneGroupAuthors == null || oneGroupAuthors.isEmpty()) { + continue; + } + result.addAll(oneGroupAuthors); } return result; + } + @Override + public List<MasterAuthor> getOneGroupAuthors(String groupId, MaintainField maintainField) { + Wrapper<MasterAuthor> userWrapper = new EntityWrapper<MasterAuthor>().eq("user_group", true).eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, groupId); + Wrapper<MasterAuthor> roleWrapper = new EntityWrapper<MasterAuthor>().eq("user_group", true).eq(Constant.TYPE, MasterAuthorType.role).eq(MasterAuthorController.character_id, groupId); + if (maintainField != null) { + if (maintainField.getId() != null) { + userWrapper.eq("maintain_field_id", maintainField.getId()); + roleWrapper.eq("maintain_field_id", maintainField.getId()); + } + if (maintainField.getTableName() != null) { + userWrapper.eq("table_name",maintainField.getTableName()); + roleWrapper.eq("table_name",maintainField.getTableName()); + } + + } + List<MasterAuthor> groupAuthors = selectList(userWrapper); + if (groupAuthors.isEmpty()) { + Set<String> roleByGroup = DbUtils.getRoleByGroup(groupId); + if(roleByGroup.isEmpty()) { + groupAuthors = new ArrayList<>(); + }else { + groupAuthors = selectList(roleWrapper); + } + } + return groupAuthors; } @Override - public List<SysField> getField(String userId, String maintainId) { + public List<SysField> getField(Character character, String maintainId) { Maintain maintain = maintainService.selectById(maintainId); if (maintain == null){ return new ArrayList<>(); } - boolean isAll = checkUnFilterAuthor(userId, maintain.getTableName()); + + boolean isAll = checkUnFilterAuthor(character, maintain.getTableName()); if (isAll) { List<SysField> total = fieldService.getFieldByMaintain(maintainId); return total; @@ -126,20 +205,22 @@ } String maintainFieldId = maintainField.getId(); - List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, userId).eq("maintain_field_id", maintainFieldId)); - if (masterAuthors.size() == 0) { - //user 鑾峰彇role - List<TUserRole> roles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq("user_id", userId)); - List<String> roleIds = roles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList()); - masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIds).eq("maintain_field_id", maintainFieldId)); + MasterAuthorType type = character.getType(); + List<MasterAuthor> masterAuthors = null; + switch (type){ + case role: + masterAuthors = getRoleAuthors(character.getId(), maintainField); + break; + case groupInfo: + masterAuthors = getOneGroupAuthors(character.getId(), maintainField); + break; + case user: + masterAuthors = getUserAuthor(character.getId(), maintainField); } - - List<MasterAuthor> groupAuthors = getUserGroupAuthor(userId); - masterAuthors.addAll(groupAuthors); - - if (masterAuthors.isEmpty()) { + if (masterAuthors == null || masterAuthors.isEmpty()) { return null; } + List<String> authorIds = masterAuthors.stream().map(masterAuthor -> masterAuthor.getId()).collect(Collectors.toList()); List<MasterAuthorDetail> masterAuthorDetails = authorDetailService.selectList(new EntityWrapper<MasterAuthorDetail>().in(Constant.PARENT_ID, authorIds)); Set<String> codes = masterAuthorDetails.stream().map(masterAuthorDetail -> masterAuthorDetail.getField()).collect(Collectors.toSet()); @@ -159,91 +240,93 @@ return fieldList; } - private boolean checkUnFilterAuthor(String userId, String tableName) { - List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.user).eq("is_group", false).eq(MasterAuthorController.character_id, userId).eq("table_name", tableName)); + private boolean checkUnFilterAuthor(Character character, String tableName) { + MasterAuthorType type = character.getType(); + List<MasterAuthor> masterAuthors = null; + MaintainField maintainField = new MaintainField().setTableName(tableName); + switch (type){ + case role: + masterAuthors = getRoleAuthors(character.getId(), maintainField); + break; + case groupInfo: + masterAuthors = getOneGroupAuthors(character.getId(), maintainField); + break; + case user: + masterAuthors = getUserAuthor(character.getId(), maintainField); + } + if (masterAuthors.isEmpty()) { + return false; + } long isAll = masterAuthors.stream().filter(masterAuthor -> masterAuthor.getMaintainFieldId().equalsIgnoreCase(Constant.All)).count(); if (isAll > 0) { return true; - } - if (!masterAuthors.isEmpty()) { + }else { return false; } - Set<String> roleByUser = DbUtils.getRoleByUser(userId); - isAll = selectCount(new EntityWrapper<MasterAuthor>().eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleByUser).eq("table_name", tableName).eq("maintain_field_id", Constant.All_UPCASE)); - if (isAll > 0) { - return true; - } - return false; } @Override - public boolean checkMaintainAuthor(String userId, String maintainId) { + public boolean checkMaintainAuthor(Character character, String maintainId) { Maintain maintain = maintainService.selectById(maintainId); if (maintain == null) { return false; } int checked = 0; - boolean isAll = checkUnFilterAuthor(userId, maintain.getTableName()); + boolean isAll = checkUnFilterAuthor(character, maintain.getTableName()); if (isAll){ return true; - } MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId); if (maintainField == null) { return false; } - //get user author - checked = selectCount(new EntityWrapper<MasterAuthor>() - .eq(Constant.TYPE, MasterAuthorType.user) - .eq(MasterAuthorController.character_id, userId) - .eq("table_name", maintain.getTableName()) - .eq("maintain_field_id", maintainField.getId())); - if (checked > 0) { + MasterAuthorType type = character.getType(); + List<MasterAuthor> masterAuthors = null; + switch (type){ + case role: + masterAuthors = getRoleAuthors(character.getId(), maintainField); + break; + case groupInfo: + masterAuthors = getOneGroupAuthors(character.getId(), maintainField); + break; + case user: + masterAuthors = getUserAuthor(character.getId(), maintainField); + } + if (masterAuthors.isEmpty()) { + return false; + }else { return true; } - List<TUserRole> roles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq("user_id", userId)); - Set<String> collect = roles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toSet()); - checked = selectCount(new EntityWrapper<MasterAuthor>() - .eq(Constant.TYPE, MasterAuthorType.role) - .in(MasterAuthorController.character_id, collect) - .eq("table_name", maintain.getTableName()) - .eq("maintain_field_id", maintainField.getId())); - if (checked > 0) { - return true; - } - return false; } @Override - public String getFilter(String userId, String maintainId) { + public String getFilter(Character character, String maintainId) { Maintain maintain = maintainService.selectById(maintainId); if (maintain == null){ return Constant.WHERE_DEFAULTUN; } - boolean isAll = checkUnFilterAuthor(userId, maintain.getTableName()); + boolean isAll = checkUnFilterAuthor(character, maintain.getTableName()); if (isAll) { return Constant.WHERE_DEFAULT; } MaintainField maintainField = fieldService.getMaintainFieldByMaintain(maintainId); - String maintainFieldId = maintainField.getId(); - - List<MasterAuthor> masterAuthors = selectList(new EntityWrapper<MasterAuthor>() - .eq("table_name", maintain.getTableName()) - .eq(Constant.TYPE, MasterAuthorType.user).eq(MasterAuthorController.character_id, userId).eq("maintain_field_id", maintainFieldId)); - if (masterAuthors.size() == 0) { - //user 鑾峰彇role - List<TUserRole> roles = userRoleService.selectList(new EntityWrapper<TUserRole>().eq("user_id", userId)); - List<String> roleIds = roles.stream().map(tUserRole -> tUserRole.getRoleId()).collect(Collectors.toList()); - masterAuthors = selectList(new EntityWrapper<MasterAuthor>().eq("table_name", maintain.getTableName()).eq(Constant.TYPE, MasterAuthorType.role).in(MasterAuthorController.character_id, roleIds).eq("maintain_field_id", maintainFieldId)); + MasterAuthorType type = character.getType(); + List<MasterAuthor> masterAuthors = null; + switch (type){ + case role: + masterAuthors = getRoleAuthors(character.getId(), maintainField); + break; + case groupInfo: + masterAuthors = getOneGroupAuthors(character.getId(), maintainField); + break; + case user: + masterAuthors = getUserAuthor(character.getId(), maintainField); } - - List<MasterAuthor> groupAuthors = getUserGroupAuthor(userId); - masterAuthors.addAll(groupAuthors); - - if (masterAuthors.isEmpty()){ + if (masterAuthors.isEmpty()) { return Constant.WHERE_DEFAULTUN; } + List<String> authorIds = masterAuthors.stream().map(masterAuthor -> masterAuthor.getId()).collect(Collectors.toList()); List<MasterAuthorDetail> masterAuthorDetails = authorDetailService.selectList(new EntityWrapper<MasterAuthorDetail>().in(Constant.PARENT_ID, authorIds)); if (masterAuthorDetails.isEmpty()) { @@ -286,14 +369,14 @@ } @Override - public Maintain getMaxVersionMaintain(String userId, String tableName) { + public Maintain getMaxVersionMaintain(Character character, String tableName) { List<Maintain> maintainList = maintainService.selectList(new EntityWrapper<Maintain>().eq("table_name", tableName).orderBy("order_no desc")); for (Maintain maintain : maintainList) { ActivitiStatus status = flowsService.getStatusByBusinessId(maintain.getId()); - if (!status.equals(ActivitiStatus.open)) { + if (!ActivitiStatus.open.equals(status)) { continue; } - boolean b = checkMaintainAuthor(userId, maintain.getId()); + boolean b = checkMaintainAuthor(character, maintain.getId()); if (b) { return maintain; } -- Gitblit v1.8.0