| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.domain.entity.SysRole; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.SysUserUpdateStatusDTO; |
| | | import com.ruoyi.system.model.TProjectTeamStaff; |
| | | import com.ruoyi.system.query.SysUserQuery; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.SysUserVO; |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.time.LocalDateTime; |
| | |
| | | */ |
| | | @Api(tags = "用户信息") |
| | | @RestController |
| | | @RequestMapping("/system/user") |
| | | @RequestMapping("") |
| | | public class SysUserController extends BaseController |
| | | { |
| | | @Autowired |
| | |
| | | private ISysDeptService deptService; |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | @Autowired |
| | | private TProjectTeamService projectTeamService; |
| | | @Autowired |
| | | private TProjectTeamStaffService projectTeamStaffService; |
| | | |
| | | /** |
| | | * 获取用户列表 |
| | | */ |
| | | @ApiOperation(value = "获取用户列表") |
| | | @PostMapping("/list") |
| | | @PreAuthorize("@ss.hasPermi('system:user')") |
| | | @PostMapping("/system/user/list") |
| | | // @PreAuthorize("@ss.hasPermi('system:user')") |
| | | public AjaxResult list(@RequestBody SysUserQuery query) |
| | | { |
| | | PageInfo<SysUserVO> list = userService.pageList(query); |
| | |
| | | } |
| | | |
| | | @ApiOperation(value = "获取用户列表-不分页") |
| | | @PostMapping("/listNotPage") |
| | | @PreAuthorize("@ss.hasPermi('system:user')") |
| | | |
| | | @PostMapping("/system/user/listNotPage") |
| | | // @PreAuthorize("@ss.hasPermi('system:user')") |
| | | public AjaxResult listNotPage() |
| | | { |
| | | List<SysUser> list = userService.selectList(); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取用户列表-不分页-根据角色筛选") |
| | | @GetMapping("/system/user/listByRole") |
| | | public AjaxResult listByRole(@RequestParam(value = "roleId",required = false) Long roleId, |
| | | @RequestParam(value = "nickName",required = false) String nickName) |
| | | { |
| | | // 获取当前用户项目组 |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | List<TProjectTeamStaff> staffs = projectTeamStaffService.list(Wrappers.lambdaQuery(TProjectTeamStaff.class) |
| | | .eq(TProjectTeamStaff::getUserId, userId)); |
| | | if (CollectionUtils.isEmpty(staffs)){ |
| | | return AjaxResult.success(new ArrayList<>()); |
| | | } |
| | | List<String> teamIds = staffs.stream().map(TProjectTeamStaff::getTeamId).collect(Collectors.toList()); |
| | | LambdaQueryWrapper<TProjectTeamStaff> wrapper = new LambdaQueryWrapper<>(); |
| | | if(Objects.nonNull(roleId)){ |
| | | wrapper.eq(TProjectTeamStaff::getRoleType,Integer.parseInt(roleId.toString())); |
| | | } |
| | | wrapper.in(TProjectTeamStaff::getTeamId, teamIds); |
| | | List<TProjectTeamStaff> teamStaffs = projectTeamStaffService.list(wrapper); |
| | | List<Long> userIds = teamStaffs.stream().map(TProjectTeamStaff::getUserId).collect(Collectors.toList()); |
| | | |
| | | List<SysUser> list = userService.listByRole(userIds,nickName); |
| | | return AjaxResult.success(list); |
| | | } |
| | | |
| | |
| | | * 获取用户详情 |
| | | */ |
| | | @ApiOperation(value = "获取用户详情") |
| | | @GetMapping("/getDetail") |
| | | @GetMapping("/system/user/getDetail") |
| | | public AjaxResult getDetail(@RequestParam Long userId) |
| | | { |
| | | SysUser sysUser = userService.selectUserById(userId); |
| | |
| | | * 获取用户详情 |
| | | */ |
| | | @ApiOperation(value = "获取用户详情") |
| | | @GetMapping("/queryDetail") |
| | | @GetMapping("/system/user/queryDetail") |
| | | public AjaxResult queryDetail() |
| | | { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | |
| | | * 获取用户数量统计 |
| | | */ |
| | | @ApiOperation(value = "获取用户数量统计") |
| | | @PostMapping("/getUserCount") |
| | | @PostMapping("/system/user/getUserCount") |
| | | public AjaxResult getUserCount() |
| | | { |
| | | Map<String,Integer> map = new HashMap<>(); |
| | |
| | | /** |
| | | * 移除黑名单 |
| | | */ |
| | | @GetMapping("/removeBlackList") |
| | | @GetMapping("/system/user/removeBlackList") |
| | | public AjaxResult removeBlackList(@RequestParam String ids) |
| | | { |
| | | String[] split = ids.split(","); |
| | |
| | | * 新增用户 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:user:add')") |
| | | @ApiOperation(value = "新增用户管理") |
| | | @ApiOperation(value = "新增用户管理",response = SysUser.class) |
| | | @Log(title = "用户信息-新增用户", businessType = BusinessType.INSERT) |
| | | @PostMapping("/add") |
| | | public AjaxResult add(@Validated @RequestBody SysUser user) |
| | | @PostMapping("/api/system/user/add") |
| | | public R<String> add(@RequestBody String param) |
| | | { |
| | | SysUser user = JSON.parseObject(param,SysUser.class); |
| | | user.setUserName(user.getUserName()); |
| | | if (!userService.checkUserNameUnique(user)) |
| | | { |
| | | return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) |
| | | { |
| | | return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | user.setCreateBy(getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword("123456")); |
| | | user.setRoleType(Integer.parseInt(user.getRoleId().toString())); |
| | | userService.insertUser(user); |
| | | return AjaxResult.success(); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @ApiOperation(value = "修改用户管理") |
| | | @Log(title = "用户信息-修改用户", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/edit") |
| | | public AjaxResult edit(@Validated @RequestBody SysUser user) |
| | | @PostMapping("/api/system/user/edit") |
| | | public R edit(@RequestBody String param) |
| | | { |
| | | SysUser user = JSON.parseObject(param,SysUser.class); |
| | | user.setUserName(user.getPhonenumber()); |
| | | // userService.checkUserAllowed(user); |
| | | // userService.checkUserDataScope(user.getUserId()); |
| | | if (!userService.checkUserNameUnique(user)) |
| | | { |
| | | return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) |
| | | { |
| | | return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | |
| | | user.setUpdateBy(getUsername()); |
| | | if(StringUtils.isNotEmpty(user.getPassword())){ |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | } |
| | | return AjaxResult.success(userService.updateUser(user)); |
| | | user.setRoleType(Integer.parseInt(user.getRoleId().toString())); |
| | | return R.ok(userService.updateUser(user)); |
| | | } |
| | | |
| | | /** |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:user:remove')") |
| | | @ApiOperation(value = "批量删除用户") |
| | | @Log(title = "用户信息-批量删除用户", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/deleteById/{ids}") |
| | | @DeleteMapping("/system/user/deleteById/{ids}") |
| | | public AjaxResult remove(@PathVariable String ids) |
| | | { |
| | | String[] split = ids.split(","); |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") |
| | | @ApiOperation(value = "重置密码") |
| | | @Log(title = "用户信息-重置密码", businessType = BusinessType.UPDATE) |
| | | @PostMapping("/resetPwd") |
| | | public AjaxResult resetPwd(@RequestBody SysUser user) |
| | | @PostMapping("/api/system/user/resetPwd") |
| | | public AjaxResult resetPwd(@RequestBody String param) |
| | | { |
| | | SysUser user = JSON.parseObject(param,SysUser.class); |
| | | userService.checkUserAllowed(user); |
| | | // userService.checkUserDataScope(user.getUserId()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | |
| | | */ |
| | | @ApiOperation(value = "状态修改") |
| | | @Log(title = "用户信息-状态修改", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | @PutMapping("/system/user/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody SysUserUpdateStatusDTO dto) |
| | | { |
| | | SysUser loginUser = tokenService.getLoginUser().getUser(); |
| | |
| | | * 根据用户编号获取授权角色 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:user:query')") |
| | | @GetMapping("/authRole/{userId}") |
| | | @GetMapping("/system/user/authRole/{userId}") |
| | | public AjaxResult authRole(@PathVariable("userId") Long userId) |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:user:edit')") |
| | | @Log(title = "用户管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authRole") |
| | | @PutMapping("/system/user/authRole") |
| | | public AjaxResult insertAuthRole(Long userId, Long[] roleIds) |
| | | { |
| | | userService.checkUserDataScope(userId); |
| | |
| | | * 获取部门树列表 |
| | | */ |
| | | // @PreAuthorize("@ss.hasPermi('system:user:list')") |
| | | @GetMapping("/deptTree") |
| | | @GetMapping("/system/user/deptTree") |
| | | public AjaxResult deptTree(SysDept dept) |
| | | { |
| | | return AjaxResult.success(deptService.selectDeptTreeList(dept)); |