| | |
| | | package com.ruoyi.system.controller; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.chargingPile.api.feignClient.SiteClient; |
| | | import com.ruoyi.chargingPile.api.model.Site; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.annotation.Logical; |
| | | import com.ruoyi.other.api.domain.TUserSite; |
| | | import com.ruoyi.other.api.feignClient.RoleSiteClient; |
| | | import com.ruoyi.other.api.feignClient.UserSiteClient; |
| | | import com.ruoyi.system.domain.dto.IndexDto; |
| | | import com.ruoyi.system.domain.vo.UserRoleVO; |
| | | import com.ruoyi.system.api.query.ChangeUserQuery; |
| | | import com.ruoyi.system.api.model.*; |
| | | import com.ruoyi.system.domain.SysUserRole; |
| | | import com.ruoyi.system.domain.dto.AddCompanyUserDto; |
| | | import com.ruoyi.system.domain.vo.CompanyUserVo; |
| | | import com.ruoyi.system.domain.vo.TCompanyToUserVo; |
| | | import com.ruoyi.system.query.GetSysUserList; |
| | | import com.ruoyi.system.query.ShopUserStart; |
| | | import com.ruoyi.system.service.*; |
| | | import io.seata.core.context.RootContext; |
| | | import io.seata.spring.annotation.GlobalTransactional; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.core.web.controller.BaseController; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.log.annotation.Log; |
| | |
| | | /** |
| | | * 获取用户列表 |
| | | */ |
| | | @RequiresPermissions(value = {"/systemUserManagement", "/roleManagement/info"}, logical = Logical.OR) |
| | | @GetMapping("/list") |
| | | @ApiOperation(value = "获取系统用户列表", tags = {"管理后台-系统用户管理", "管理后台-角色管理"}) |
| | | public AjaxResult list(GetSysUserList getSysUserList) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取用户选择列表 |
| | | */ |
| | | @PostMapping("/getChangeUserList") |
| | | @ApiOperation(value = "获取用户选择列表", tags = {"管理后台-获取用户选择列表"}) |
| | | public AjaxResult<PageInfo<SysUser>> getChangeUserList(@RequestBody ChangeUserQuery query) { |
| | | return AjaxResult.success(userService.getChangeUserList(query)); |
| | | } |
| | | |
| | | /** |
| | | * 新增用户 |
| | | */ |
| | | @RequiresPermissions(value = {"/systemUserManagement/add"}, logical = Logical.OR) |
| | | @Log(title = "用户管理", businessType = BusinessType.INSERT) |
| | | @PostMapping("/add") |
| | | @ApiOperation(value = "添加系统用户", tags = {"管理后台-系统用户管理"}) |
| | |
| | | user.setCreateBy(SecurityUtils.getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | user.setRoleType(1); |
| | | user.setPassWordUpdate(new Date()); |
| | | userService.insertUser(user); |
| | | SysUserRole sysUserRole = new SysUserRole(); |
| | | sysUserRole.setRoleId(user.getRoleId()); |
| | |
| | | } |
| | | |
| | | |
| | | @RequiresPermissions(value = {"/systemUserManagement/add", "/systemUserManagement/update"}, logical = Logical.OR) |
| | | @GetMapping("/verifyUserNameRepeat/{username}") |
| | | @ApiOperation(value = "校验账号是否重复", tags = {"管理后台-系统用户管理"}) |
| | | public AjaxResult verifyUserNameRepeat(@PathVariable String username){ |
| | |
| | | return success(); |
| | | } |
| | | |
| | | |
| | | |
| | | @RequiresPermissions(value = {"/systemUserManagement/update"}, logical = Logical.OR) |
| | | @GetMapping("/getRoleSiteName/{roleId}") |
| | | @ApiOperation(value = "获取角色对应的站点名称", tags = {"管理后台-系统用户管理"}) |
| | | public AjaxResult<List<String>> getRoleSiteName(@PathVariable Integer roleId){ |
| | | List<Integer> ids = roleSiteClient.getSiteIds(roleId.longValue()).getData(); |
| | | List<Site> data = siteClient.getSiteByIds(ids).getData(); |
| | | if(null == data){ |
| | | return AjaxResult.success(new ArrayList<>()); |
| | | } |
| | | List<String> siteNames = data.stream().map(Site::getName).collect(Collectors.toList()); |
| | | return AjaxResult.success(siteNames); |
| | | } |
| | |
| | | /** |
| | | * 修改用户 |
| | | */ |
| | | @RequiresPermissions(value = {"/systemUserManagement/update"}, logical = Logical.OR) |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/update") |
| | | @ApiOperation(value = "编辑系统用户", tags = {"管理后台-系统用户管理"}) |
| | |
| | | if (user.getPhonenumber() != null) { |
| | | user.setUserName(user.getPhonenumber()); |
| | | } |
| | | user.setPassword(null); |
| | | user.setUpdateBy(SecurityUtils.getUsername()); |
| | | user.setUpdateTime(new Date()); |
| | | userService.updateUser(user); |
| | | |
| | | |
| | | //删除旧的角色数据,添加新的角色 |
| | | userRoleService.remove(new LambdaQueryWrapper<SysUserRole>().eq(SysUserRole::getUserId, user.getUserId())); |
| | | //添加新的角色数据 |
| | | SysUserRole userRole = new SysUserRole(); |
| | | userRole.setUserId(user.getUserId()); |
| | | userRole.setRoleId(user.getRoleId()); |
| | | userRoleService.save(userRole); |
| | | |
| | | //删除旧的站点数据后添加新的 |
| | | userSiteClient.delUserSite(user.getUserId()); |
| | | List<Integer> siteIds = user.getSiteIds(); |
| | |
| | | return success(); |
| | | } |
| | | |
| | | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | /** |
| | | * 删除用户 |
| | | */ |
| | | @RequiresPermissions(value = {"/systemUserManagement/del"}, logical = Logical.OR) |
| | | @Log(title = "用户管理", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{userIds}") |
| | | @ApiOperation(value = "删除系统用户", tags = {"管理后台-系统用户管理"}) |
| | | public AjaxResult remove(@PathVariable Long[] userIds) { |
| | | if (ArrayUtils.contains(userIds, SecurityUtils.getUserId())) { |
| | | if (ArrayUtils.contains(userIds, tokenService.getLoginUser().getUserid())) { |
| | | return error("当前用户不能删除"); |
| | | } |
| | | return toAjax(userService.deleteUserByIds(userIds)); |
| | |
| | | |
| | | |
| | | |
| | | @RequiresPermissions(value = {"/systemUserManagement/forbidden"}, logical = Logical.OR) |
| | | @PostMapping("/shopUserStart") |
| | | @ApiOperation(value = "账号管理--禁用/启用", tags = {"管理后台-系统用户管理"}) |
| | | public AjaxResult shopUserStart(@RequestParam("userId") Long userId, @RequestParam("remark") String remark) { |
| | | if (userId == null) { |
| | | public AjaxResult shopUserStart(@RequestBody ShopUserStart shopUserStart) { |
| | | if (shopUserStart.getUserId() == null) { |
| | | return AjaxResult.error("userId不能为空"); |
| | | } |
| | | SysUser sysUser = userService.selectUserById(userId); |
| | | SysUser sysUser = userService.selectUserById(shopUserStart.getUserId()); |
| | | if (sysUser.getStatus().equals("0")) { |
| | | sysUser.setStatus("1"); |
| | | sysUser.setRemark(remark); |
| | | sysUser.setForbiddenRemark(shopUserStart.getRemark()); |
| | | } else { |
| | | sysUser.setStatus("0"); |
| | | sysUser.setRemark(""); |
| | | sysUser.setForbiddenRemark(""); |
| | | } |
| | | return toAjax(userService.updateUser(sysUser)); |
| | | } |
| | |
| | | } |
| | | |
| | | @PostMapping("/getSysUser") |
| | | public R<SysUser> getSysUser(@RequestBody Long userId) { |
| | | public R<SysUser> getSysUser(@RequestParam("userId") Long userId) { |
| | | try { |
| | | SysUser sysUser = userService.selectUserById(userId); |
| | | return R.ok(sysUser); |
| | |
| | | sysUser.setUpdateBy(SecurityUtils.getUsername()); |
| | | sysUser.setUpdateTime(new Date()); |
| | | userService.updateUser(sysUser); |
| | | userRoleService.deleteSysUserRoleByUserId(sysUser.getUserId()); |
| | | SysUserRole sysUserRole = new SysUserRole(); |
| | | sysUserRole.setRoleId(sysUser.getRoleId()); |
| | | sysUserRole.setUserId(sysUser.getUserId()); |
| | | userRoleService.insertSysUserRole(sysUserRole); |
| | | if(null != sysUser.getRoleId()){ |
| | | userRoleService.deleteSysUserRoleByUserId(sysUser.getUserId()); |
| | | SysUserRole sysUserRole = new SysUserRole(); |
| | | sysUserRole.setRoleId(sysUser.getRoleId()); |
| | | sysUserRole.setUserId(sysUser.getUserId()); |
| | | userRoleService.insertSysUserRole(sysUserRole); |
| | | } |
| | | return R.ok(true); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | sysUserVo.setSysUser(sysUser); |
| | | sysUserVo.setRoles(roles); |
| | | sysUserVo.setPermissions(permissions); |
| | | |
| | | return R.ok(sysUserVo); |
| | | } |
| | | |
| | |
| | | */ |
| | | @GetMapping("/getInfo") |
| | | public AjaxResult getInfo() { |
| | | SysUser user = userService.selectUserById(SecurityUtils.getUserId()); |
| | | SysUser user = userService.selectUserById(tokenService.getLoginUser().getUserid()); |
| | | // 角色集合 |
| | | Set<String> roles = permissionService.getRolePermission(user); |
| | | // 权限集合 |
| | |
| | | /** |
| | | * 重置密码 |
| | | */ |
| | | @RequiresPermissions("system:user:edit") |
| | | @RequiresPermissions(value = {"/systemUserManagement/reset_passwords"}, logical = Logical.OR) |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/resetPwd") |
| | | @ApiOperation(value = "重置密码", tags = {"管理后台-系统用户管理"}) |
| | |
| | | /** |
| | | * 状态修改 |
| | | */ |
| | | @RequiresPermissions("system:user:edit") |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/changeStatus") |
| | | public AjaxResult changeStatus(@RequestBody SysUser user) { |
| | |
| | | /** |
| | | * 根据用户编号获取授权角色 |
| | | */ |
| | | @RequiresPermissions("system:user:query") |
| | | @GetMapping("/authRole/{userId}") |
| | | public AjaxResult authRole(@PathVariable("userId") Long userId) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | |
| | | /** |
| | | * 用户授权角色 |
| | | */ |
| | | @RequiresPermissions("system:user:edit") |
| | | @Log(title = "用户管理", businessType = BusinessType.GRANT) |
| | | @PutMapping("/authRole") |
| | | public AjaxResult insertAuthRole(Long userId, Long[] roleIds) { |
| | |
| | | /** |
| | | * 获取部门树列表 |
| | | */ |
| | | @RequiresPermissions("system:user:list") |
| | | @GetMapping("/deptTree") |
| | | public AjaxResult deptTree(SysDept dept) { |
| | | return success(deptService.selectDeptTreeList(dept)); |
| | |
| | | @ResponseBody |
| | | @PostMapping("/addSysUser") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R addSysUser(@RequestBody SysUser user){ |
| | | public R<Long> addSysUser(@RequestBody SysUser user) { |
| | | if(StringUtils.isEmpty(user.getUserName())){ |
| | | user.setUserName(user.getPhonenumber()); |
| | | } |
| | | if(!org.springframework.util.StringUtils.hasLength(user.getNickName())){ |
| | | user.setNickName(user.getPhonenumber()); |
| | | } |
| | | if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { |
| | | throw new RuntimeException("手机号已开通账号"); |
| | | } |
| | | // if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { |
| | | // throw new RuntimeException("手机号已开通账号"); |
| | | // } |
| | | if (StringUtils.isNotEmpty(user.getUserName()) && !userService.checkUserNameUnique(user)) { |
| | | throw new RuntimeException("登录账号已存在"); |
| | | } |
| | |
| | | sysUserRole.setRoleId(user.getRoleId()); |
| | | sysUserRole.setUserId(user.getUserId()); |
| | | userRoleService.insertSysUserRole(sysUserRole); |
| | | return R.ok(); |
| | | return R.ok(user.getUserId()); |
| | | } |
| | | |
| | | |
| | |
| | | userService.resetPwd(user); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/getSysUserById") |
| | | public SysUser getSysUserById(@RequestParam("userId") Long userId){ |
| | | return userService.getById(userId); |
| | | } |
| | | } |