whywhyo
2023-10-23 dc460ed61e3b0688addc8ee179edb0e7ebd953ef
zhang-content/src/main/java/com/ruoyi/service/impl/ZAuthorityServiceImpl.java
@@ -11,6 +11,7 @@
import com.ruoyi.domain.ZfFamily;
import com.ruoyi.domain.dto.AuthorityDto;
import com.ruoyi.domain.dto.AuthorityDto2;
import com.ruoyi.domain.dto.AuthorityDtoWithName;
import com.ruoyi.mapper.ZAuthorityMapper;
import com.ruoyi.service.ZAuthorityService;
import com.ruoyi.service.ZInfoUserService;
@@ -20,7 +21,7 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -196,4 +197,82 @@
    }
    @Override
    public AjaxResult getOtherAuthority(AuthorityDto authorityDto) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        Long userId = user.getUserId();
        ZInfoUser myself = zInfoUserService.getById(userId);
        //查看当前用户是不是管理员
        if(myself.getRoleId()!=1 && myself.getRoleId()!=2){
            throw new RuntimeException("你不是家庭管理员,没有权限操作");
        }
        //只能管理自己家庭的权限
        Long fid = myself.getFamilyId();
        //根据家庭的名字查出家庭的id
//        ZfFamily family = zfFamilyService.getByName(authorityDto.getFamilyName());
//        Long fid = family.getId();
        //得到要搜索的模块名字
        String modelName = authorityDto.getModelName();
        //根据模块的名字查出对应的权限码
        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,fid).in(ZAuthority::getAuthority,allCodeList);
        List<ZAuthority> resultData = zAuthorityService.list(lqw);
        //拿到有关用户的id和对应的权限码数组
        HashMap<Long, ArrayList<Long>> userAuthMap = new HashMap<>();
        resultData.forEach(authority->{
           if(userAuthMap.get(authority.getUid()) == null){
               ArrayList<Long> codeList = new ArrayList<>();
               codeList.add(authority.getAuthority());
               userAuthMap.put(authority.getUid(),codeList);
           }else {
               userAuthMap.get(authority.getUid()).add(authority.getAuthority());
           }
        });
        List<AuthorityDtoWithName> returnData = new ArrayList<>();
        for (Long uid : userAuthMap.keySet()) {
            ArrayList<Long> authCodeList = userAuthMap.get(uid);
            List<String> authNameList = zfCodeService.getNameByCode(authCodeList);
            AuthorityDto oneAuth = new AuthorityDto();
            authNameList.forEach(name ->{
                if(name.contains("查看")){
                    oneAuth.setSearch(1);
                }else if(name.contains("删除")){
                    oneAuth.setDelete(1);
                }else if(name.contains("添加")){
                    oneAuth.setInsert(1);
                }else if(name.contains("修改")){
                    oneAuth.setUpdate(1);
                }
            });
            oneAuth.setModelName(modelName);
            oneAuth.setFamilyName(zfFamilyService.getById(fid).getName());
            AuthorityDtoWithName authorityDtoWithName = new AuthorityDtoWithName();
            authorityDtoWithName.setName(zInfoUserService.getInfoById(uid).getNickName());
            authorityDtoWithName.setUserId(uid);
            authorityDtoWithName.setAuthorityInfo(oneAuth);
            returnData.add(authorityDtoWithName);
        }
        return AjaxResult.success(returnData);
    }
}