From 48efc68c6276e53ab3e90a8accc89a1c40e3e8a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E5=AD=90=E6=9D=8E=C2=B7De?= Date: Sat, 17 Jul 2021 23:02:05 +0800 Subject: [PATCH] Create AccessRoleServiceImpl.java --- .../service/impl/AccessRoleServiceImpl.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/service/impl/AccessRoleServiceImpl.java diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/service/impl/AccessRoleServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/service/impl/AccessRoleServiceImpl.java new file mode 100755 index 00000000..16411774 --- /dev/null +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/accessrole/service/impl/AccessRoleServiceImpl.java @@ -0,0 +1,96 @@ + +package com.anjiplus.template.gaea.business.modules.accessrole.service.impl; + +import com.anji.plus.gaea.bean.TreeNode; +import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper; +import com.anji.plus.gaea.exception.BusinessExceptionBuilder; +import com.anjiplus.template.gaea.business.code.ResponseCode; +import com.anjiplus.template.gaea.business.modules.accessauthority.dao.entity.AccessAuthority; +import com.anjiplus.template.gaea.business.modules.accessauthority.service.AccessAuthorityService; +import com.anjiplus.template.gaea.business.modules.accessrole.controller.dto.AccessRoleDto; +import com.anjiplus.template.gaea.business.modules.accessrole.dao.AccessRoleAuthorityMapper; +import com.anjiplus.template.gaea.business.modules.accessrole.dao.entity.AccessRole; +import com.anjiplus.template.gaea.business.modules.accessrole.dao.entity.AccessRoleAuthority; +import com.anjiplus.template.gaea.business.modules.accessrole.service.AccessRoleService; +import com.anjiplus.template.gaea.business.modules.accessrole.dao.AccessRoleMapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.apache.commons.lang3.StringUtils; +import org.checkerframework.checker.units.qual.A; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** +* @desc AccessRole 角色管理服务实现 +* @author 木子李·De +* @date 2019-02-17 08:50:14.136 +**/ +@Service +public class AccessRoleServiceImpl implements AccessRoleService { + + @Autowired + private AccessRoleMapper accessRoleMapper; + + @Autowired + private AccessRoleAuthorityMapper accessRoleAuthorityMapper; + + @Autowired + private AccessAuthorityService accessAuthorityService; + + @Override + public GaeaBaseMapper getMapper() { + return accessRoleMapper; + } + + @Override + public Map getAuthorityTree(String roleCode, String operator) { + Map result = new HashMap(); + + // 菜单按钮树 + List treeData = accessAuthorityService.getAuthorityTree(operator, true); + + // 该角色已选中的菜单及按钮 + List checkedKeys = accessRoleMapper.checkedAuthoritys(roleCode); + + result.put("treeData", treeData); + result.put("checkedKeys", checkedKeys); + return result; + } + + @Override + public Boolean saveAuthorityTree(AccessRoleDto accessRoleDto) { + // 校验 + String roleCode = accessRoleDto.getRoleCode(); + List authorityList = accessRoleDto.getAuthorityList(); + if(StringUtils.isBlank(roleCode)){ + throw BusinessExceptionBuilder.build(ResponseCode.Not_Empty, roleCode); + } + if(authorityList == null || authorityList.isEmpty()){ + throw BusinessExceptionBuilder.build(ResponseCode.Not_Empty, authorityList); + } + + // 先清除该角色已保存的权限 + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + wrapper.eq(AccessRoleAuthority::getRoleCode, roleCode); + accessRoleAuthorityMapper.delete(wrapper); + + // 保存勾选的权限(菜单和按钮) + authorityList.stream().forEach(authorityStr -> { + if(!authorityStr.contains("_")){ + return; + } + String[] array = authorityStr.split("_"); + AccessRoleAuthority accessRoleAuthority = new AccessRoleAuthority(); + accessRoleAuthority.setRoleCode(roleCode); + accessRoleAuthority.setTarget(array[0].trim()); + accessRoleAuthority.setAction(array[1].trim()); + accessRoleAuthorityMapper.insert(accessRoleAuthority); + }); + return true; + } +} \ No newline at end of file