| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.domain.ZAuthority; |
| | | import com.ruoyi.domain.ZInfoUser; |
| | | import com.ruoyi.domain.ZfCode; |
| | | import com.ruoyi.domain.ZfFamily; |
| | | import com.ruoyi.domain.dto.AuthorityDto; |
| | | import com.ruoyi.domain.dto.AuthorityDto2; |
| | | import com.ruoyi.mapper.ZAuthorityMapper; |
| | | import com.ruoyi.service.ZAuthorityService; |
| | | import com.ruoyi.service.ZInfoUserService; |
| | | import com.ruoyi.service.ZfCodeService; |
| | | import com.ruoyi.service.ZfFamilyService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | |
| | | |
| | | @Resource |
| | | private ZfCodeService zfCodeService; |
| | | |
| | | @Resource |
| | | private ZAuthorityService zAuthorityService; |
| | | |
| | | @Resource |
| | | private ZInfoUserService zInfoUserService; |
| | | |
| | | /** |
| | | * 查询当前用户的权限 |
| | |
| | | return familyList.stream().map(ZfFamily::getName).distinct().collect(Collectors.toList()); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param authorityDto 传入了用户id、modelName |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult managerAuthority(AuthorityDto2 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 uid = authorityDto.getUid(); |
| | | Long fid = myself.getFamilyId(); |
| | | 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) |
| | | .eq(ZAuthority::getUid,uid) |
| | | .in(ZAuthority::getAuthority,allCodeList); |
| | | List<ZAuthority> authorityList = list(lqw); |
| | | |
| | | //先删掉现在所有的权限 |
| | | List<Long> idList = authorityList.stream().map(ZAuthority::getId).collect(Collectors.toList()); |
| | | zAuthorityService.removeBatchByIds(idList); |
| | | |
| | | //再添加新设置的权限 |
| | | if(authorityDto.getSearch() == 1){ |
| | | //根据模块的名字查到权限码,只会有一个结果 |
| | | List<ZfCode> zfcode = zfCodeService.likeGetByName(modelName + "查看"); |
| | | ZAuthority zAuthority = new ZAuthority(); |
| | | zAuthority.setFid(fid); |
| | | zAuthority.setUid(uid); |
| | | zAuthority.setAuthority(zfcode.get(0).getCode()); |
| | | zAuthorityService.save(zAuthority); |
| | | } |
| | | |
| | | if(authorityDto.getInsert() == 1){ |
| | | //根据模块的名字查到权限码,只会有一个结果 |
| | | List<ZfCode> zfcode = zfCodeService.likeGetByName(modelName + "添加"); |
| | | ZAuthority zAuthority = new ZAuthority(); |
| | | zAuthority.setFid(fid); |
| | | zAuthority.setUid(uid); |
| | | zAuthority.setAuthority(zfcode.get(0).getCode()); |
| | | zAuthorityService.save(zAuthority); |
| | | } |
| | | |
| | | if(authorityDto.getUpdate() == 1){ |
| | | //根据模块的名字查到权限码,只会有一个结果 |
| | | List<ZfCode> zfcode = zfCodeService.likeGetByName(modelName + "修改"); |
| | | ZAuthority zAuthority = new ZAuthority(); |
| | | zAuthority.setFid(fid); |
| | | zAuthority.setUid(uid); |
| | | zAuthority.setAuthority(zfcode.get(0).getCode()); |
| | | zAuthorityService.save(zAuthority); |
| | | } |
| | | |
| | | if(authorityDto.getDelete() == 1){ |
| | | //根据模块的名字查到权限码,只会有一个结果 |
| | | List<ZfCode> zfcode = zfCodeService.likeGetByName(modelName + "删除"); |
| | | ZAuthority zAuthority = new ZAuthority(); |
| | | zAuthority.setFid(fid); |
| | | zAuthority.setUid(uid); |
| | | zAuthority.setAuthority(zfcode.get(0).getCode()); |
| | | zAuthorityService.save(zAuthority); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | |
| | | } |
| | | |
| | | } |