| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.system.pojo.dto.AddSysUserDTO; |
| | | import com.ruoyi.system.pojo.dto.EditSysUserDTO; |
| | | import com.ruoyi.system.pojo.vo.SysDeptPageVO; |
| | | import com.ruoyi.system.pojo.vo.SysRoleVO; |
| | | import com.ruoyi.system.pojo.vo.SysUserPageListVO; |
| | | import com.ruoyi.system.pojo.vo.SysUserVO; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | |
| | | /** |
| | | * 获取用户列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:list')") |
| | | /* @PreAuthorize("@ss.hasPermi('system:user:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(SysUser user) |
| | | { |
| | | startPage(); |
| | | List<SysUser> list = userService.selectUserList(user); |
| | | return getDataTable(list); |
| | | } |
| | | }*/ |
| | | |
| | | @Log(title = "用户管理", businessType = BusinessType.EXPORT) |
| | | /* @Log(title = "用户管理", businessType = BusinessType.EXPORT) |
| | | @PreAuthorize("@ss.hasPermi('system:user:export')") |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, SysUser user) |
| | |
| | | List<SysUser> list = userService.selectUserList(user); |
| | | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); |
| | | util.exportExcel(response, list, "用户数据"); |
| | | } |
| | | }*/ |
| | | |
| | | /* |
| | | @Log(title = "用户管理", businessType = BusinessType.IMPORT) |
| | | @PreAuthorize("@ss.hasPermi('system:user:import')") |
| | | @PostMapping("/importData") |
| | |
| | | String message = userService.importUser(userList, updateSupport, operName); |
| | | return success(message); |
| | | } |
| | | */ |
| | | |
| | | @PostMapping("/importTemplate") |
| | | /* @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) |
| | | { |
| | | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); |
| | | util.importTemplateExcel(response, "用户数据"); |
| | | } |
| | | |
| | | */ |
| | | /** |
| | | * 根据用户编号获取详细信息 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:query')") |
| | | /* @PreAuthorize("@ss.hasPermi('system:user:query')") |
| | | @GetMapping(value = { "/", "/{userId}" }) |
| | | public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) |
| | | { |
| | |
| | | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); |
| | | ajax.put("posts", postService.selectPostAll()); |
| | | return ajax; |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 新增用户 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:add')") |
| | | /* @PreAuthorize("@ss.hasPermi('system:user:add')") |
| | | @Log(title = "用户管理", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@Validated @RequestBody SysUser user) |
| | |
| | | user.setCreateBy(getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | return toAjax(userService.insertUser(user)); |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 修改用户 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | /* @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysUser user) |
| | |
| | | } |
| | | user.setUpdateBy(getUsername()); |
| | | return toAjax(userService.updateUser(user)); |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 删除用户 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:remove')") |
| | | /*@PreAuthorize("@ss.hasPermi('system:user:remove')") |
| | | @Log(title = "用户管理", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{userIds}") |
| | | public AjaxResult remove(@PathVariable Long[] userIds) |
| | |
| | | } |
| | | return toAjax(userService.deleteUserByIds(userIds)); |
| | | } |
| | | |
| | | */ |
| | | /** |
| | | * 重置密码 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") |
| | | /* @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/resetPwd") |
| | | public AjaxResult resetPwd(@RequestBody SysUser user) |
| | |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | user.setUpdateBy(getUsername()); |
| | | return toAjax(userService.resetPwd(user)); |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 状态修改 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | /* @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody SysUser user) |
| | |
| | | userService.checkUserDataScope(user.getUserId()); |
| | | user.setUpdateBy(getUsername()); |
| | | return toAjax(userService.updateUserStatus(user)); |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 根据用户编号获取授权角色 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('system:user:query')") |
| | | /* @PreAuthorize("@ss.hasPermi('system:user:query')") |
| | | @GetMapping("/authRole/{userId}") |
| | | public AjaxResult authRole(@PathVariable("userId") Long userId) |
| | | { |
| | |
| | | ajax.put("user", user); |
| | | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); |
| | | return ajax; |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 用户授权角色 |
| | | */ |
| | | /* *//* |
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @Log(title = "用户管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authRole") |
| | |
| | | roleService.checkRoleDataScope(roleIds); |
| | | userService.insertUserAuth(userId, roleIds); |
| | | return success(); |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 获取部门树列表 |
| | |
| | | { |
| | | return success(deptService.selectDeptTreeList(dept)); |
| | | } |
| | | |
| | | /** |
| | | * 分页 |
| | | */ |
| | | @ApiOperation(value = "账号管理-获取账号分页列表", tags = "系统后台-权限管理") |
| | | @PreAuthorize("@ss.hasPermi('permission:account')") |
| | | @GetMapping("/page/list") |
| | | public R<IPage<SysUserPageListVO>> getSysUserPageList(@RequestParam("pageNum")Integer pageNum, |
| | | @RequestParam("pageSize")Integer pageSize, |
| | | @RequestParam("nickName")String nickName, |
| | | @RequestParam("phone")Integer phone, |
| | | @RequestParam("status")String status) { |
| | | IPage<SysUserPageListVO> page=new Page<>(pageNum,pageSize); |
| | | return R.ok(userService.getSysUserPageList(page,nickName,phone,status)); |
| | | } |
| | | |
| | | /** |
| | | * 角色下拉框 |
| | | */ |
| | | @ApiOperation(value = "账号管理-获取角色下拉框", tags = "系统后台-权限管理") |
| | | @PreAuthorize("@ss.hasPermi('permission:account')") |
| | | @GetMapping("/getOptionSelect") |
| | | public R<List<SysRoleVO>> getOptionSelect() { |
| | | return R.ok(roleService.getOptionSelect()); |
| | | } |
| | | |
| | | /** |
| | | * 部门下拉框 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('permission:account')") |
| | | @ApiOperation(value = "账号管理-部门选择框", tags = "系统后台-权限管理") |
| | | @GetMapping("/list") |
| | | public AjaxResult list() { |
| | | List<SysDeptPageVO> list = deptService.getDeptList(); |
| | | return success(list); |
| | | } |
| | | /** |
| | | * 根据用户编号回显 |
| | | */ |
| | | @ApiOperation(value = "账号管理-查看详情(回显)", tags = "系统后台-权限管理") |
| | | @PreAuthorize("@ss.hasPermi('permission:account')") |
| | | @GetMapping(value ="/{userId}") |
| | | public R<SysUserVO> getInfo(@PathVariable(value = "userId") Long userId) { |
| | | return userService.getInfo(userId); |
| | | |
| | | } |
| | | /** |
| | | * 新增 |
| | | */ |
| | | @ApiOperation(value = "账号管理-查看详情(回显)", tags = "系统后台-权限管理") |
| | | @PreAuthorize("@ss.hasPermi('permission:account')") |
| | | @Log(title = "账号管理", businessType = BusinessType.INSERT) |
| | | @PostMapping("/add") |
| | | public R<Void> add(@Valid @RequestBody AddSysUserDTO dto) { |
| | | userService.add(dto); |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 编辑 |
| | | */ |
| | | @ApiOperation(value = "账号管理-修改用户", tags = "系统后台-权限管理") |
| | | @PreAuthorize("@ss.hasPermi('permission:account')") |
| | | @Log(title = "账号管理", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/edit") |
| | | public R<Void> edit(@Valid @RequestBody EditSysUserDTO dto) { |
| | | userService.edit(dto); |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 冻结 |
| | | */ |
| | | @ApiOperation(value = "账号管理-状态修改", tags = "系统后台-权限管理") |
| | | @PreAuthorize("@ss.hasPermi('permission:account')") |
| | | @Log(title = "账号管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus/{userId}") |
| | | public R<Void> changeStatus(@PathVariable("userId") Long userId) { |
| | | if (Objects.equals(userId, getUserId())) { |
| | | return R.fail("当前用户不能操作"); |
| | | } |
| | | userService.changeStatus(userId); |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 删除 |
| | | */ |
| | | @ApiOperation(value = "账号管理-删除用户", tags = "系统后台-权限管理") |
| | | @PreAuthorize("@ss.hasPermi('permission:account')") |
| | | @Log(title = "账号管理", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{userId}") |
| | | public R remove(@PathVariable("userId") Long userId) { |
| | | if (Objects.equals(userId, getUserId())) { |
| | | return R.fail("当前用户不能删除"); |
| | | } |
| | | return R.ok(userService.deleteUserById(userId)); |
| | | } |
| | | |
| | | /** |
| | | * 重置密码 |
| | | */ |
| | | @ApiOperation(value = "账号管理-重置密码", tags = "系统后台-权限管理") |
| | | @PreAuthorize("@ss.hasPermi('permission:account')") |
| | | @Log(title = "账号管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/resetPassword/{userId}") |
| | | public R<Void> resetPassword(@PathVariable("userId") Long userId) { |
| | | userService.resetPassword(userId); |
| | | return R.ok(); |
| | | } |
| | | } |