| | |
| | | package com.kidgrow.usercenter.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.kidgrow.common.annotation.LoginUser; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.kidgrow.common.model.*; |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | | import com.kidgrow.usercenter.dto.SysRoleOrganizationDto; |
| | | import com.kidgrow.usercenter.service.ISysOrganizationService; |
| | | import com.kidgrow.usercenter.service.ISysRoleService; |
| | | import com.kidgrow.usercenter.dto.SysRoleOrganizationMybatisDto; |
| | | import com.kidgrow.usercenter.mapper.SysRoleMapper; |
| | | import com.kidgrow.usercenter.mapper.SysRoleOrganizationMapper; |
| | | import com.kidgrow.usercenter.model.SysRoleOrganization; |
| | | import com.kidgrow.usercenter.service.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import com.kidgrow.usercenter.model.SysRoleOrganization; |
| | | import com.kidgrow.usercenter.mapper.SysRoleOrganizationMapper; |
| | | import com.kidgrow.usercenter.service.ISysRoleOrganizationService; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | |
| | | public class SysRoleOrganizationServiceImpl extends SuperServiceImpl<SysRoleOrganizationMapper, SysRoleOrganization> implements ISysRoleOrganizationService { |
| | | |
| | | |
| | | private final Integer TYPE_QUAN_BU = 1;//全部数据权限 |
| | | private final Integer TYPE_ZI_DING_YI = 2;//自定义数据权限 |
| | | private final Integer TYPE_BEN_BU_MEN = 3;//本部门数据权限 |
| | | private final Integer TYPE_BEN_BU_MEN_YI_XIA = 4;//本部门及以下数据权限 |
| | | private final Integer TYPE_BEN_REN = 5;//仅本人数据权限不能为空 |
| | | @Autowired |
| | | private ISysOrganizationService iSysOrganizationService; |
| | | @Autowired |
| | | private ISysRoleService iSysRoleService; |
| | | @Autowired |
| | | private ISysRoleUserService iSysRoleUserService; |
| | | @Autowired |
| | | private ISysUserOrgService iSysUserOrgService; |
| | | @Autowired |
| | | private SysOrganizationServiceImpl sysOrganizationService; |
| | | @Autowired |
| | | private SysRoleMapper sysRoleMapper; |
| | | |
| | | /** |
| | | * 列表 |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveOrUpdateSer(SysRoleOrganizationDto sysRoleOrganizationDto, SysUser user) { |
| | | if (sysRoleOrganizationDto.getRoleId() != null) { |
| | | SysRole sysRole = iSysRoleService.getById(sysRoleOrganizationDto.getRoleId()); |
| | |
| | | } |
| | | SysRoleOrganization sysRoleOrganization = new SysRoleOrganization(); |
| | | sysRoleOrganization.setRoleId(sysRoleOrganizationDto.getRoleId()); |
| | | List<SysOrganization> organizations = user.getOrganizations(); |
| | | // 1代表全部数据权限,2自定义数据权限,3本部门数据权限,4本部门及以下数据权限,5仅本人数据权限不能为空") |
| | | //先清除数据 |
| | | if(sysRoleOrganizationDto.getRoleId()!=null){ |
| | | Map<String,Object> map=new HashMap<>(); |
| | | map.put("role_id",sysRoleOrganizationDto.getRoleId()); |
| | | map.put("is_del",0); |
| | | if (sysRoleOrganizationDto.getRoleId() != null) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("role_id", sysRoleOrganizationDto.getRoleId()); |
| | | map.put("is_del", 0); |
| | | List<SysRoleOrganization> sysRoleOrganizations = baseMapper.selectByMap(map); |
| | | List<Long> collect = sysRoleOrganizations.stream().map(e -> e.getId()).collect(Collectors.toList()); |
| | | if(collect.size()>0){ |
| | | if (collect.size() > 0) { |
| | | int i = baseMapper.deleteBatchIds(collect); |
| | | } |
| | | } |
| | | |
| | | //全部数据 |
| | | if (sysRoleOrganizationDto.getType() == TYPE_QUAN_BU) { |
| | | // sysRoleOrganization.setOrgCode("10"); |
| | | // if (organizations != null && organizations.size() > 0) { |
| | | // sysRoleOrganization.setOrgId(organizations.get(organizations.size()-1).getId()); |
| | | // } |
| | | // baseMapper.insert(sysRoleOrganization); |
| | | } |
| | | //2自定义数据权限 |
| | | if (sysRoleOrganizationDto.getType() == TYPE_ZI_DING_YI) { |
| | | |
| | | List<Long> orgIds = sysRoleOrganizationDto.getOrgIds(); |
| | | orgIds.forEach(e -> { |
| | | sysRoleOrganization.setId(null); |
| | |
| | | } |
| | | baseMapper.insert(sysRoleOrganization); |
| | | }); |
| | | }else { |
| | | |
| | | } |
| | | //3本部门数据权限 |
| | | if (sysRoleOrganizationDto.getType() == TYPE_BEN_BU_MEN) { |
| | | if (organizations != null && organizations.size() > 0) { |
| | | sysRoleOrganization.setOrgCode(organizations.get(organizations.size()-1).getOrgCode()); |
| | | sysRoleOrganization.setOrgId(organizations.get(organizations.size()-1).getId()); |
| | | baseMapper.insert(sysRoleOrganization); |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | //4本部门及以下数据权限 |
| | | if (sysRoleOrganizationDto.getType() == TYPE_BEN_BU_MEN_YI_XIA) { |
| | | if (organizations != null && organizations.size() > 0) { |
| | | sysRoleOrganization.setOrgCode(organizations.get(organizations.size()-1).getOrgCode()); |
| | | sysRoleOrganization.setOrgId(organizations.get(organizations.size()-1).getId()); |
| | | baseMapper.insert(sysRoleOrganization); |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | //5仅本人数据权限不能为空 |
| | | if (sysRoleOrganizationDto.getType() == TYPE_BEN_REN) { |
| | | sysRoleOrganization.setOrgCode(organizations.get(organizations.size()-1).getOrgCode()); |
| | | sysRoleOrganization.setOrgId(organizations.get(organizations.size()-1).getId()); |
| | | baseMapper.insert(sysRoleOrganization); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | public List<Map<String, Object>> getTreeData(Long MyId, List<SysOrganization> sysOrganizations, List<Long> col) { |
| | | List<Map<String, Object>> listMap = new ArrayList<>(); |
| | | Map<Long, SysOrganization> collect = sysOrganizations.stream().collect(Collectors.toMap(SysOrganization::getId, SysOrganization -> SysOrganization)); |
| | | List<Long> idList = sysOrganizations.stream().filter(e -> e.getOrgParentId() == MyId).map(e -> e.getId()).collect(Collectors.toList()); |
| | | List<Long> idList = sysOrganizations.stream().filter(e -> e.getOrgParentId() .equals(MyId)).map(e -> e.getId()).collect(Collectors.toList()); |
| | | for (Long id : idList |
| | | ) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | |
| | | map.put("name", collect.get(id).getOrgName()); |
| | | map.put("level", collect.get(id).getOrgLevel()); |
| | | map.put("checked", col.contains(id)); |
| | | List<Long> childs = sysOrganizations.stream().filter(e -> e.getOrgParentId() == id).map(e -> e.getId()).collect(Collectors.toList()); |
| | | List<Long> childs = sysOrganizations.stream().filter(e -> e.getOrgParentId().equals(id)).map(e -> e.getId()).collect(Collectors.toList()); |
| | | if (childs.size() > 0) { |
| | | List<Map<String, Object>> treeData = getTreeData(id, sysOrganizations, col); |
| | | map.put("children", treeData); |
| | |
| | | } |
| | | return listMap; |
| | | } |
| | | |
| | | /** |
| | | * 将权限 分装到map对像 |
| | | * |
| | | * @param params |
| | | * @param user |
| | | */ |
| | | |
| | | public void getRoleOrg(Map<String, Object> params, SysUser user) { |
| | | //获取角色接口 |
| | | List<SysRole> roles = iSysRoleUserService.findRolesByUserId(user.getId()); |
| | | List<SysOrganization> listUser = iSysUserOrgService.getListUser(user.getId()); |
| | | List<Map<Integer, Object>> listroleOrg = new ArrayList<>(); |
| | | if(listUser!=null){ |
| | | if (!roles.isEmpty()) { |
| | | int index=0; |
| | | for (SysRole e : roles) { |
| | | Map<Integer, Object> rolemap = new HashMap<>(); |
| | | SysRoleOrganizationMybatisDto dto=new SysRoleOrganizationMybatisDto(); |
| | | if(e.getType() == 1){ |
| | | dto.setFlag(index==0); |
| | | dto.setObject(user.getId()); |
| | | rolemap.put(e.getType(), dto); |
| | | }else if (e.getType() == 2) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("role_id", e.getId()); |
| | | List<SysRoleOrganization> sysRoleOrganizations = baseMapper.selectByMap(map); |
| | | if (sysRoleOrganizations.size() > 0) { |
| | | dto.setFlag(index==0); |
| | | dto.setObject(sysRoleOrganizations); |
| | | rolemap.put(e.getType(), dto); |
| | | } |
| | | } else if (e.getType() == 3) { |
| | | dto.setFlag(index==0); |
| | | dto.setObject(user.getOrganizations().get(user.getOrganizations().size() - 1).getOrgCode()); |
| | | rolemap.put(e.getType(), dto); |
| | | } else if (e.getType() == 4) { |
| | | dto.setFlag(index==0); |
| | | dto.setObject(user.getOrganizations().get(user.getOrganizations().size() - 1).getOrgCode()); |
| | | rolemap.put(e.getType(), dto); |
| | | } else if (e.getType() == 5) { |
| | | dto.setFlag(index==0); |
| | | dto.setObject(user.getId()); |
| | | rolemap.put(e.getType(), dto); |
| | | } |
| | | index+=1; |
| | | listroleOrg.add(rolemap); |
| | | }; |
| | | } |
| | | } |
| | | //添加权限控制 |
| | | params.put("roleOrg", listroleOrg); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getRoleOrgMap(SysUser user) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | getRoleOrg(map, user); |
| | | return map; |
| | | } |
| | | } |