/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package com.vci.ubcs.system.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.vci.ubcs.starter.util.MybatisParameterUtil;
|
import com.vci.ubcs.system.entity.RoleMenu;
|
import com.vci.ubcs.system.mapper.RoleMenuMapper;
|
import com.vci.ubcs.system.service.IRoleMenuService;
|
import com.vci.ubcs.system.service.IRoleService;
|
import com.vci.ubcs.system.user.entity.User;
|
import com.vci.ubcs.system.user.feign.IUserClient;
|
import org.springblade.core.log.exception.ServiceException;
|
import org.springblade.core.secure.utils.AuthUtil;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.utils.Func;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* 服务实现类
|
*
|
* @author Chill
|
*/
|
@Service
|
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu> implements IRoleMenuService {
|
|
@Resource
|
private RoleMenuMapper roleMenuMapper;
|
|
@Resource
|
private IUserClient userClient;
|
|
/**
|
* 根据用户id查询,被授权的菜单id
|
* @param userId
|
* @return
|
*/
|
@Override
|
public List<Long> getMenuIdByUserId(Long userId) {
|
// 根据用户id查询菜单id
|
R<User> userR = userClient.userInfoById((Func.isEmpty(userId) ? AuthUtil.getUserId():userId));
|
if (!userR.isSuccess() || Func.isEmpty(userR.getData())) {
|
throw new ServiceException("用户信息查询失败,原因:"+userR.getMsg());
|
}
|
|
// 当查询条件in大于一千条时
|
List<String> roleIdList = Func.toStrList(userR.getData().getRoleId());
|
//构建查询菜单id的查询条件
|
LambdaQueryWrapper<RoleMenu> roleMenuWrapper = Wrappers.<RoleMenu>query()
|
.lambda().select(RoleMenu::getMenuId);
|
if(roleIdList.size()>=1000){
|
MybatisParameterUtil.cutInParameter(roleMenuWrapper,RoleMenu::getRoleId,roleIdList);
|
}else {
|
roleMenuWrapper.in(RoleMenu::getRoleId,roleIdList);
|
}
|
List<RoleMenu> roleMenus = roleMenuMapper.selectList(roleMenuWrapper);
|
if(roleMenus.isEmpty()){
|
return new ArrayList<>();
|
}
|
return roleMenus.stream().map(RoleMenu::getMenuId).collect(Collectors.toList());
|
}
|
|
|
}
|