| | |
| | | import com.kidgrow.common.annotation.LoginUser; |
| | | import com.kidgrow.common.model.*; |
| | | import com.kidgrow.usercenter.dto.SysRoleOrganizationDto; |
| | | import com.kidgrow.usercenter.dto.SysRoleOrganizationMybatisDto; |
| | | import com.kidgrow.usercenter.mapper.SysRoleMapper; |
| | | import com.kidgrow.usercenter.service.ISysOrganizationService; |
| | | import com.kidgrow.usercenter.service.ISysRoleService; |
| | | import com.kidgrow.usercenter.service.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | |
| | | import com.kidgrow.usercenter.model.SysRoleOrganization; |
| | | import com.kidgrow.usercenter.mapper.SysRoleOrganizationMapper; |
| | | import com.kidgrow.usercenter.service.ISysRoleOrganizationService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © 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 |
| | |
| | | } |
| | | |
| | | @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; |
| | | } |
| | |
| | | } |
| | | return listMap; |
| | | } |
| | | public void getRoleOrg(Map<String, Object> params, SysUser user){ |
| | | List<SysRole> roles = user.getRoles(); |
| | | List<Map<SysRole,List<SysRoleOrganization>>> listroleOrg=new ArrayList<>(); |
| | | if (!roles.isEmpty()) { |
| | | roles.forEach(e->{ |
| | | Map<SysRole,List<SysRoleOrganization>> rolemap=new HashMap<>(); |
| | | Map<String,Object> map=new HashMap<>(); |
| | | map.put("role_id",e.getId()); |
| | | List<SysRoleOrganization> sysRoleOrganizations = baseMapper.selectByMap(map); |
| | | if(sysRoleOrganizations.size()>0){ |
| | | SysRole sysRole = sysRoleMapper.selectById(e.getId()); |
| | | rolemap.put(sysRole,sysRoleOrganizations); |
| | | |
| | | /** |
| | | * 将权限 分装到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); |
| | | params.put("roleOrg", listroleOrg); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getRoleOrgMap(SysUser user) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | getRoleOrg(map, user); |
| | | return map; |
| | | } |
| | | } |