| | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.map.MapBuilder; |
| | | import cn.hutool.core.map.MapUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.extra.servlet.ServletUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sandu.common.domain.ResponseVO; |
| | | import com.sandu.common.enums.AdminStatusStatus; |
| | |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.service.*; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.dao.bo.MenuNode; |
| | | import com.sandu.ximon.dao.domain.*; |
| | | import com.sandu.ximon.dao.enums.AdministratorEnums; |
| | | import com.sandu.ximon.dao.enums.MenuEnum; |
| | | import eu.bitwalker.useragentutils.Browser; |
| | | import eu.bitwalker.useragentutils.OperatingSystem; |
| | | import eu.bitwalker.useragentutils.UserAgent; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | if (admin == null) { |
| | | return ResponseUtil.error(ResponseStatusEnums.BAD_CREDENTIALS.getCode(), ResponseStatusEnums.BAD_CREDENTIALS.getMessage()); |
| | | } |
| | | // String session_vcode = (String) request.getSession().getAttribute(loginParam.getKey()); |
| | | String s = RedisUtils.getBean().get(loginParam.getKey()); |
| | | System.out.println(s+"==========================="); |
| | | if (!loginParam.getVlue().equals(s)) { |
| | | log.error(loginParam.getVlue() + "验证码"); |
| | | return ResponseUtil.error(ResponseStatusEnums.BAD_AUTHENTICATION.getCode(), ResponseStatusEnums.BAD_AUTHENTICATION.getMessage()); |
| | |
| | | put("token", properties.getTokenStartWith() + token); |
| | | put("user", admin); |
| | | }}; |
| | | |
| | | |
| | | /** |
| | | * 登录信息日志记录开始 |
| | | */ |
| | | UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent")); |
| | | Browser browser = userAgent.getBrowser(); |
| | | OperatingSystem os = userAgent.getOperatingSystem(); |
| | | String content = "用户ID:" + admin.getId() |
| | | + ",用户名:" + admin.getUsername() |
| | | + ",用户类型:管理员" |
| | | + ",登录IP地址:" + ServletUtil.getClientIP(request) |
| | | + ",操作系统:" + os |
| | | + ",浏览器:" + browser; |
| | | StoreOperationRecordsUtils.storeOperationLoginData(admin.getId(), admin.getUsername(), "管理员登录", content); |
| | | /** |
| | | * 登录信息日志记录结束 |
| | | */ |
| | | return ResponseUtil.success(authInfo); |
| | | } |
| | | |
| | |
| | | |
| | | @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 content = "用户名:" + SecurityUtils.getUsername(); |
| | | StoreOperationRecordsUtils.storeOperationData(null, null, "用管理员退出登录", content); |
| | | String key = String.format("%d_%d", SecurityUtils.getUserDetails().getUserId(), SecurityUtils.getUserDetails().getAdministratorType()); |
| | | redisService.set(key, null); |
| | | return ResponseUtil.success("退出登录成功"); |
| | |
| | | |
| | | @Log("后台用户列表") |
| | | @GetMapping(value = "/list") |
| | | public ResponseVO<Object> listAdmin(BaseConditionVO baseConditionVO, @RequestParam(value = "keyword", required = false) String keyword) { |
| | | public ResponseVO<Object> listAdmin(BaseConditionVO baseConditionVO, |
| | | @RequestParam(value = "keyword", required = false) String keyword, |
| | | @RequestParam(value = "order", required = false) Integer order, |
| | | @RequestParam(value = "seq", required = false) Integer seq) { |
| | | if (!permissionConfig.check(MenuEnum.ADMIN_LIST.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | return ResponseUtil.successPage(adminService.listAdmin(baseConditionVO, keyword)); |
| | | |
| | | // 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); |
| | | return ResponseUtil.successPage(adminService.listAdmin(baseConditionVO, keyword, order, seq)); |
| | | } |
| | | |
| | | @Log("后台用户注册") |
| | | @PostMapping("/register") |
| | | public ResponseVO<Object> register(@Validated @RequestBody AdminParam param) { |
| | | if (!permissionConfig.check(MenuEnum.ADMIN_ADD.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | boolean result = adminService.register(param); |
| | | if (result) { |
| | | return ResponseUtil.success("注册用户成功"); |
| | |
| | | } |
| | | } |
| | | |
| | | // @PreAuthorize("@el.check('admin:edit')") |
| | | |
| | | /** |
| | | * 修改管理员信息 |
| | |
| | | @Log("后台用户修改信息") |
| | | @PostMapping("/update/{adminId}") |
| | | public ResponseVO<Object> updateAdmin(@RequestBody AdminParam param, @PathVariable Long adminId) { |
| | | if (!permissionConfig.check(MenuEnum.ADMIN_INFO_UPDATE.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | boolean result = adminService.updateAdmin(adminId, param); |
| | | if (result) { |
| | | return ResponseUtil.success("修改成功"); |
| | |
| | | } |
| | | } |
| | | |
| | | // @PutMapping("/updateStatus/{id}") |
| | | // public ResponseVO<Object> updateStatus(@PathVariable Long id, @RequestParam(value = "status") Integer status) { |
| | | // checkLevel(id); |
| | | // Admin update = new Admin(); |
| | | // update.setId(id); |
| | | // update.setStatus(status); |
| | | // adminService.updateById(update); |
| | | // return ResponseUtil.success(null); |
| | | // } |
| | | |
| | | @Log("后台用户删除") |
| | | @PostMapping("/del/{adminId}") |
| | | @GetMapping("/del/{adminId}") |
| | | public ResponseVO<Object> deleteAdmin(@PathVariable Long adminId) { |
| | | if (!permissionConfig.check(MenuEnum.ADMIN_DELETE.getCode())) { |
| | | return ResponseUtil.fail("缺少对应用户权限"); |
| | | } |
| | | boolean result = adminService.deleteAdmin(adminId); |
| | | if (result) { |
| | | return ResponseUtil.success("修改成功"); |
| | | return ResponseUtil.success("删除管理员成功!"); |
| | | } else { |
| | | return ResponseUtil.fail("修改失败"); |
| | | return ResponseUtil.fail("删除管理员失败!"); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | // /** |
| | | // * 给管理员分配角色 |
| | | // * |
| | | // * @return |
| | | // */ |
| | | // @PostMapping("/updateAdminRole") |
| | | // @PreAuthorize("@el.check('admin:edit')") |
| | | // public ResponseVO<Object> updateAdminRole(@RequestParam("adminId") Long adminId, |
| | | // @RequestParam("roleIds") List<Long> roleIds) { |
| | | // checkLevel(adminId); |
| | | // adminsRolesService.updateAdminRole(adminId, roleIds); |
| | | // return ResponseUtil.success(""); |
| | | // } |
| | | |
| | | /** |
| | | * 获取用户权限 |
| | | * |
| | | * @return |
| | | */ |
| | | @GetMapping("/getUserPermissionList") |
| | | public ResponseVO<Object> getUserPermissionList() { |
| | | List<MenuNode> userPermissionList; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | userPermissionList = adminService.getUserPermissionList(); |
| | | } else { |
| | | userPermissionList = clientService.getUserPermissionList(); |
| | | } |
| | | |
| | | return ResponseUtil.success(userPermissionList); |
| | | } |
| | | |
| | | |
| | | // /** |
| | | // * 编辑我的信息 |
| | | // * |
| | | // * @param resources |
| | | // * @return |
| | | // */ |
| | | // @PutMapping("/editUserInfo") |
| | | // public ResponseVO<Object> editUserInfo(@RequestBody AdminParam resources) { |
| | | // Long userId = SecurityUtils.getUserId(); |
| | | // Admin admin = new Admin(); |
| | | // admin.setId(userId); |
| | | // admin.setMobile(resources.getMobile()); |
| | | // admin.setEmail(resources.getEmail()); |
| | | // admin.setNickName(resources.getNickName()); |
| | | // adminService.updateById(admin); |
| | | // return ResponseUtil.success(null); |
| | | // } |
| | | |
| | | @GetMapping("/creatUserKey") |
| | | public ResponseVO<Object> creatUserKey(@RequestParam(required = false, value = "userId") Long userId, |
| | | @RequestParam(required = false, value = "requstType") Integer requstType) { |
| | | if (!AdministratorEnums.ADMIN.getCode().equals(SecurityUtils.getAdministratorIdentity())) { |
| | | throw new BusinessException("非超级管理员无法操作!"); |
| | | } |
| | | return ResponseUtil.success(adminService.creatUserKey(userId, requstType)); |
| | | } |
| | | } |