| | |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.domain.ZAuthority; |
| | | import com.ruoyi.domain.ZfCode; |
| | | import com.ruoyi.domain.ZfFamily; |
| | | import com.ruoyi.domain.dto.AuthorityDto; |
| | | import com.ruoyi.mapper.ZAuthorityMapper; |
| | | import com.ruoyi.service.ZAuthorityService; |
| | | import com.ruoyi.service.ZfCodeService; |
| | | import com.ruoyi.service.ZfFamilyService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Author Jinquan_Ou |
| | |
| | | **/ |
| | | @Service |
| | | public class ZAuthorityServiceImpl extends ServiceImpl<ZAuthorityMapper, ZAuthority> implements ZAuthorityService { |
| | | |
| | | @Resource |
| | | private ZfFamilyService zfFamilyService; |
| | | |
| | | @Resource |
| | | private ZfCodeService zfCodeService; |
| | | |
| | | /** |
| | | * 查询当前用户的权限 |
| | | */ |
| | |
| | | |
| | | return list(lqw); |
| | | } |
| | | |
| | | @Override |
| | | public AuthorityDto getByCondition(AuthorityDto authorityDto) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | String familyName = authorityDto.getFamilyName(); |
| | | String modelName = authorityDto.getModelName(); |
| | | |
| | | //根据家庭的名字查出家庭的id |
| | | Long familyId = zfFamilyService.getByName(familyName).getId(); |
| | | |
| | | //根据模块的名字查出对应的权限码 |
| | | List<ZfCode> zfCodeList = zfCodeService.likeGetByName(modelName); |
| | | List<Long> allCodeList = zfCodeList.stream().map(ZfCode::getCode).collect(Collectors.toList());//权限码数组 |
| | | |
| | | |
| | | //找到对应家庭对应模块的权限数组 |
| | | LambdaQueryWrapper<ZAuthority> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(ZAuthority::getFid,familyId) |
| | | .eq(ZAuthority::getUid,userId) |
| | | .in(ZAuthority::getAuthority,allCodeList); |
| | | List<ZAuthority> authorityList = list(lqw); |
| | | |
| | | List<Long> codeList = authorityList.stream().map(ZAuthority::getAuthority).collect(Collectors.toList());//真正拥有权限的权限码数组 |
| | | List<String> nameList = zfCodeService.getNameByCode(codeList); |
| | | |
| | | AuthorityDto resultData = new AuthorityDto(); |
| | | nameList.forEach(name ->{ |
| | | if(name.contains("查看")){ |
| | | resultData.setSearch(1); |
| | | }else if(name.contains("删除")){ |
| | | resultData.setDelete(1); |
| | | }else if(name.contains("添加")){ |
| | | resultData.setInsert(1); |
| | | }else if(name.contains("修改")){ |
| | | resultData.setUpdate(1); |
| | | } |
| | | }); |
| | | |
| | | resultData.setModelName(modelName); |
| | | resultData.setFamilyName(familyName); |
| | | |
| | | return resultData; |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getAuthorityFamilyName() { |
| | | List<ZAuthority> authorityList = getAuthority(); |
| | | List<Long> familyIds = authorityList.stream().map(ZAuthority::getFid).distinct().collect(Collectors.toList()); |
| | | List<ZfFamily> familyList = zfFamilyService.listByIds(familyIds); |
| | | return familyList.stream().map(ZfFamily::getName).distinct().collect(Collectors.toList()); |
| | | } |
| | | |
| | | } |