| | |
| | | package com.sandu.ximon.admin.controller; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.map.MapBuilder; |
| | | import cn.hutool.core.map.MapUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.enums.AdminStatusStatus; |
| | | import com.sandu.common.enums.ResponseStatusEnums; |
| | | import com.sandu.common.enums.RoleLevelStatus; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.log.Log; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.redis.RedisService; |
| | | import com.sandu.common.redis.UserModel; |
| | | import com.sandu.common.security.LoginUserInfo; |
| | | import com.sandu.common.security.annotation.AnonymousAccess; |
| | | import com.sandu.common.security.config.SecurityProperties; |
| | | import com.sandu.common.security.token.TokenProvider; |
| | | import com.sandu.common.util.IpUtil; |
| | | import com.sandu.common.util.ResponseUtil; |
| | | import com.sandu.ximon.admin.dto.AdminDto; |
| | | import com.sandu.ximon.admin.dto.ClientDto; |
| | | import com.sandu.ximon.admin.param.AdminLoginParam; |
| | | import com.sandu.ximon.admin.param.AdminParam; |
| | | import com.sandu.ximon.admin.param.PwdParam; |
| | |
| | | private final TokenProvider tokenProvider; |
| | | private final AdminRoleRelationService adminRoleRelationService; |
| | | private PermissionConfig permissionConfig; |
| | | private final RedisService redisService; |
| | | |
| | | @Log("后台用户登录") |
| | | @AnonymousAccess |
| | |
| | | loginUserInfo.setAccount(admin.getUsername()); |
| | | loginUserInfo.setStatus(admin.getStatus()); |
| | | loginUserInfo.setIp(IpUtil.getRealIp()); |
| | | loginUserInfo.setAdministratorType(AdministratorEnums.ADMIN.getCode()); |
| | | |
| | | //确定用户角色权限 |
| | | AdminRoleRelation adminRoleRelation = adminRoleRelationService.getOne(Wrappers.lambdaQuery(AdminRoleRelation.class).eq(AdminRoleRelation::getAdminId, loginUserInfo.getUserId())); |
| | | Role role = roleService.getOne(Wrappers.lambdaQuery(Role.class).eq(Role::getId, adminRoleRelation.getRoleId())); |
| | | if (role != null && role.getLevel().equals(RoleLevelStatus.SUPER.getCode())) { |
| | | loginUserInfo.setAdministratorType(AdministratorEnums.ADMIN.getCode()); |
| | | } else { |
| | | loginUserInfo.setAdministratorType(AdministratorEnums.CUSTOMER.getCode()); |
| | | } |
| | | |
| | | loginUserInfo.setPermission(grantedAuthorities.stream().map(GrantedAuthority::getAuthority).collect(Collectors.joining(","))); |
| | | |
| | | // 生成令牌 |
| | |
| | | // @Log("后台用户信息") |
| | | @GetMapping(value = "/info") |
| | | public ResponseVO<Object> getUserInfo() { |
| | | System.out.println(SecurityUtils.getUserDetails().getAdministratorType() + " ---------"); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<Role> roles; |
| | | MapBuilder<Object, Object> builder; |
| | |
| | | } else { |
| | | Client client = clientService.getById(userId); |
| | | roles = roleService.listByClientId(client.getId()); |
| | | builder = MapUtil.builder().put("admin", client); |
| | | //为了保持返回数据格式一致 |
| | | Admin admin = new Admin(); |
| | | admin.setId(client.getId()); |
| | | admin.setIcon(client.getIcon()); |
| | | admin.setNickName(client.getLinkMan()); |
| | | admin.setMobile(client.getMobile()); |
| | | admin.setLoginTime(client.getLoginTime()); |
| | | admin.setCreateTime(client.getCreateTime()); |
| | | builder = MapUtil.builder().put("admin", admin); |
| | | |
| | | } |
| | | if (CollectionUtil.isEmpty(roles)) { |
| | |
| | | builder.put("menus", menuNodeList); |
| | | } |
| | | return ResponseUtil.success(builder.build()); |
| | | } |
| | | |
| | | @GetMapping(value = "/logout") |
| | | public ResponseVO<Object> LogOut() { |
| | | // redisService.set(UserModel.USER_INFO.key(SecurityUtils.getUserId().toString() + SecurityUtils.getUserDetails().getAdministratorType()), null); |
| | | // redisService.set(UserModel.USER_TOKEN.key(UserModel.USER_TOKEN.key(SecurityUtils.getUserDetails().getToken())), null); |
| | | |
| | | |
| | | String key = String.format("%d_%d", SecurityUtils.getUserDetails().getUserId(), SecurityUtils.getUserDetails().getAdministratorType()); |
| | | redisService.set(key, null); |
| | | return ResponseUtil.success("退出登录成功"); |
| | | } |
| | | |
| | | private MenuNode covertMenuNode(Menu menu, List<Menu> menuList) { |
| | |
| | | if (!permissionConfig.check(MenuEnum.ADMIN_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | LambdaQueryWrapper<Admin> wrapper = Wrappers.lambdaQuery(Admin.class); |
| | | if (keyword != null) { |
| | | wrapper.like(Admin::getNickName, keyword) |
| | | .or(adminLambdaQueryWrapper -> { |
| | | adminLambdaQueryWrapper.like(Admin::getUsername, keyword); |
| | | }); |
| | | } |
| | | List<Admin> list = adminService.list(wrapper); |
| | | return ResponseUtil.successPage(adminService.listAdmin(baseConditionVO, keyword)); |
| | | |
| | | List<AdminDto> adminDtoList = new ArrayList<>(); |
| | | for (Admin demo : list) { |
| | | AdminDto adminDto = new AdminDto(); |
| | | BeanUtil.copyProperties(demo, adminDto); |
| | | AdminRoleRelation one = adminRoleRelationService.getOne(Wrappers.lambdaQuery(AdminRoleRelation.class) |
| | | .eq(AdminRoleRelation::getAdminId, demo.getId())); |
| | | |
| | | if (one != null) { |
| | | adminDto.setRoleId(one.getRoleId()); |
| | | } |
| | | adminDtoList.add(adminDto); |
| | | |
| | | } |
| | | return ResponseUtil.successPage(adminDtoList); |
| | | // PageHelper.startPage(baseConditionVO.getPageNo(), baseConditionVO.getPageSize()); |
| | | // LambdaQueryWrapper<Admin> wrapper = Wrappers.lambdaQuery(Admin.class); |
| | | // if (keyword != null) { |
| | | // wrapper.like(Admin::getNickName, keyword) |
| | | // .or(adminLambdaQueryWrapper -> { |
| | | // adminLambdaQueryWrapper.like(Admin::getUsername, keyword); |
| | | // }); |
| | | // } |
| | | // List<Admin> list = adminService.list(wrapper); |
| | | // |
| | | // List<AdminDto> adminDtoList = new ArrayList<>(); |
| | | // for (Admin demo : list) { |
| | | // AdminDto adminDto = new AdminDto(); |
| | | // BeanUtil.copyProperties(demo, adminDto); |
| | | // AdminRoleRelation one = adminRoleRelationService.getOne(Wrappers.lambdaQuery(AdminRoleRelation.class) |
| | | // .eq(AdminRoleRelation::getAdminId, demo.getId())); |
| | | // |
| | | // if (one != null) { |
| | | // adminDto.setRoleId(one.getRoleId()); |
| | | // } |
| | | // adminDtoList.add(adminDto); |
| | | // |
| | | // } |
| | | // return ResponseUtil.successPage(adminDtoList); |
| | | } |
| | | |
| | | @Log("后台用户注册") |