| | |
| | | import java.io.IOException;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | | import java.util.stream.Collectors;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | 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.multipart.MultipartFile;
|
| | | import com.ruoyi.common.core.constant.UserConstants;
|
| | | import com.ruoyi.common.core.domain.R;
|
| | | import com.ruoyi.common.core.utils.SecurityUtils;
|
| | | import com.ruoyi.common.core.utils.StringUtils;
|
| | | import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.common.core.web.controller.BaseController;
|
| | |
| | | import com.ruoyi.common.core.web.page.TableDataInfo;
|
| | | import com.ruoyi.common.log.annotation.Log;
|
| | | import com.ruoyi.common.log.enums.BusinessType;
|
| | | import com.ruoyi.common.security.utils.SecurityUtils;
|
| | | import com.ruoyi.common.security.annotation.PreAuthorize;
|
| | | import com.ruoyi.system.api.domain.SysRole;
|
| | | import com.ruoyi.system.api.domain.SysUser;
|
| | | import com.ruoyi.system.api.model.UserInfo;
|
| | | import com.ruoyi.system.api.model.LoginUser;
|
| | | import com.ruoyi.system.service.ISysPermissionService;
|
| | | import com.ruoyi.system.service.ISysPostService;
|
| | | import com.ruoyi.system.service.ISysRoleService;
|
| | |
| | | /**
|
| | | * 获取用户列表
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:user:list')")
|
| | | @PreAuthorize(hasPermi = "system:user:list")
|
| | | @GetMapping("/list")
|
| | | public TableDataInfo list(SysUser user)
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | @Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
| | | @PreAuthorize("@ss.hasPermi('system:user:export')")
|
| | | @PreAuthorize(hasPermi = "system:user:export")
|
| | | @PostMapping("/export")
|
| | | public void export(HttpServletResponse response, SysUser user) throws IOException
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | @Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
| | | @PreAuthorize("@ss.hasPermi('system:user:import')")
|
| | | @PreAuthorize(hasPermi = "system:user:import")
|
| | | @PostMapping("/importData")
|
| | | public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
|
| | | {
|
| | |
| | | * 获取当前用户信息
|
| | | */
|
| | | @GetMapping("/info/{username}")
|
| | | public R<UserInfo> info(@PathVariable("username") String username)
|
| | | public R<LoginUser> info(@PathVariable("username") String username)
|
| | | {
|
| | | SysUser sysUser = userService.selectUserByUserName(username);
|
| | | if (StringUtils.isNull(sysUser))
|
| | | {
|
| | | return R.failed("用户名或密码错误");
|
| | | return R.fail("用户名或密码错误");
|
| | | }
|
| | | // 角色集合
|
| | | Set<String> roles = permissionService.getRolePermission(sysUser.getUserId());
|
| | | // 权限集合
|
| | | Set<String> permissions = permissionService.getMenuPermission(sysUser.getUserId());
|
| | | UserInfo sysUserVo = new UserInfo();
|
| | | LoginUser sysUserVo = new LoginUser();
|
| | | sysUserVo.setSysUser(sysUser);
|
| | | sysUserVo.setRoles(roles);
|
| | | sysUserVo.setPermissions(permissions);
|
| | |
| | | @GetMapping("getInfo")
|
| | | public AjaxResult getInfo()
|
| | | {
|
| | | Long userId = SecurityUtils.getLoginUser().getUserId();
|
| | | Long userId = SecurityUtils.getUserId();
|
| | | // 角色集合
|
| | | Set<String> roles = permissionService.getRolePermission(userId);
|
| | | // 权限集合
|
| | |
| | | /**
|
| | | * 根据用户编号获取详细信息
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:user:query')")
|
| | | @PreAuthorize(hasPermi = "system:user:query")
|
| | | @GetMapping(value = { "/", "/{userId}" })
|
| | | public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
|
| | | {
|
| | | AjaxResult ajax = AjaxResult.success();
|
| | | ajax.put("roles", roleService.selectRoleAll());
|
| | | List<SysRole> roles = roleService.selectRoleAll();
|
| | | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
| | | ajax.put("posts", postService.selectPostAll());
|
| | | if (StringUtils.isNotNull(userId))
|
| | | {
|
| | |
| | | /**
|
| | | * 新增用户
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:user:add')")
|
| | | @PreAuthorize(hasPermi = "system:user:add")
|
| | | @Log(title = "用户管理", businessType = BusinessType.INSERT)
|
| | | @PostMapping
|
| | | public AjaxResult add(@Validated @RequestBody SysUser user)
|
| | |
| | | /**
|
| | | * 修改用户
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')")
|
| | | @PreAuthorize(hasPermi = "system:user:edit")
|
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
| | | @PutMapping
|
| | | public AjaxResult edit(@Validated @RequestBody SysUser user)
|
| | |
| | | /**
|
| | | * 删除用户
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:user:remove')")
|
| | | @PreAuthorize(hasPermi = "system:user:remove")
|
| | | @Log(title = "用户管理", businessType = BusinessType.DELETE)
|
| | | @DeleteMapping("/{userIds}")
|
| | | public AjaxResult remove(@PathVariable Long[] userIds)
|
| | |
| | | /**
|
| | | * 重置密码
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')")
|
| | | @PreAuthorize(hasPermi = "system:user:edit")
|
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
| | | @PutMapping("/resetPwd")
|
| | | public AjaxResult resetPwd(@RequestBody SysUser user)
|
| | |
| | | /**
|
| | | * 状态修改
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:user:edit')")
|
| | | @PreAuthorize(hasPermi = "system:user:edit")
|
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
| | | @PutMapping("/changeStatus")
|
| | | public AjaxResult changeStatus(@RequestBody SysUser user)
|