| | |
| | | import cn.hutool.core.lang.Validator; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService { |
| | | public class SysUserServiceImpl extends ServicePlusImpl<SysUserMapper, SysUser, SysUser> implements ISysUserService { |
| | | |
| | | @Autowired |
| | | private SysRoleMapper roleMapper; |
| | |
| | | @DataScope(deptAlias = "d", userAlias = "u", isUser = true) |
| | | public List<SysUser> selectUserList(SysUser user) { |
| | | return baseMapper.selectUserList(user); |
| | | } |
| | | |
| | | /** |
| | | * 根据条件分页查询已分配用户角色列表 |
| | | * |
| | | * @param user 用户信息 |
| | | * @return 用户信息集合信息 |
| | | */ |
| | | @Override |
| | | @DataScope(deptAlias = "d", userAlias = "u", isUser = true) |
| | | public TableDataInfo<SysUser> selectAllocatedList(SysUser user) { |
| | | return PageUtils.buildDataInfo(baseMapper.selectAllocatedList(PageUtils.buildPage(), user)); |
| | | } |
| | | |
| | | /** |
| | | * 根据条件分页查询未分配用户角色列表 |
| | | * |
| | | * @param user 用户信息 |
| | | * @return 用户信息集合信息 |
| | | */ |
| | | @Override |
| | | @DataScope(deptAlias = "d", userAlias = "u", isUser = true) |
| | | public TableDataInfo<SysUser> selectUnallocatedList(SysUser user) { |
| | | return PageUtils.buildDataInfo(baseMapper.selectUnallocatedList(PageUtils.buildPage(), user)); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 用户授权角色 |
| | | * |
| | | * @param userId 用户ID |
| | | * @param roleIds 角色组 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void insertUserAuth(Long userId, Long[] roleIds) |
| | | { |
| | | userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>() |
| | | .eq(SysUserRole::getUserId, userId)); |
| | | insertUserRole(userId, roleIds); |
| | | } |
| | | |
| | | /** |
| | | * 修改用户状态 |
| | | * |
| | | * @param user 用户信息 |
| | |
| | | * 修改用户头像 |
| | | * |
| | | * @param userName 用户名 |
| | | * @param avatar 头像地址 |
| | | * @param avatar 头像地址 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | |
| | | list.add(ur); |
| | | } |
| | | if (list.size() > 0) { |
| | | for (SysUserRole sysUserRole : list) { |
| | | userRoleMapper.insert(sysUserRole); |
| | | } |
| | | userRoleMapper.insertAll(list); |
| | | } |
| | | } |
| | | } |
| | |
| | | list.add(up); |
| | | } |
| | | if (list.size() > 0) { |
| | | for (SysUserPost sysUserPost : list) { |
| | | userPostMapper.insert(sysUserPost); |
| | | } |
| | | userPostMapper.insertAll(list); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 新增用户角色信息 |
| | | * |
| | | * @param userId 用户ID |
| | | * @param roleIds 角色组 |
| | | */ |
| | | public void insertUserRole(Long userId, Long[] roleIds) { |
| | | if (Validator.isNotNull(roleIds)) { |
| | | // 新增用户与角色管理 |
| | | List<SysUserRole> list = new ArrayList<SysUserRole>(); |
| | | for (Long roleId : roleIds) { |
| | | SysUserRole ur = new SysUserRole(); |
| | | ur.setUserId(userId); |
| | | ur.setRoleId(roleId); |
| | | list.add(ur); |
| | | } |
| | | if (list.size() > 0) { |
| | | userRoleMapper.insertAll(list); |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 导入用户数据 |
| | | * |
| | | * @param userList 用户数据列表 |
| | | * @param userList 用户数据列表 |
| | | * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据 |
| | | * @param operName 操作用户 |
| | | * @param operName 操作用户 |
| | | * @return 结果 |
| | | */ |
| | | @Override |