|
|
|
|
@ -1,393 +1,542 @@
|
|
|
|
|
package com.ruoyi.web.controller.system;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Dict;
|
|
|
|
|
import com.ruoyi.common.utils.mail.TemplateMailUtil;
|
|
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
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.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.common.core.domain.Ztree;
|
|
|
|
|
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.core.page.TableDataInfo;
|
|
|
|
|
import com.ruoyi.common.core.text.Convert;
|
|
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
|
import com.ruoyi.common.utils.ShiroUtils;
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
|
|
import com.ruoyi.framework.shiro.service.SysPasswordService;
|
|
|
|
|
import com.ruoyi.framework.shiro.util.AuthorizationUtils;
|
|
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
|
|
|
import com.ruoyi.system.service.ISysPostService;
|
|
|
|
|
import com.ruoyi.system.service.ISysRoleService;
|
|
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户信息
|
|
|
|
|
*
|
|
|
|
|
* @author ruoyi
|
|
|
|
|
*/
|
|
|
|
|
@Controller
|
|
|
|
|
@RequestMapping("/system/user")
|
|
|
|
|
public class SysUserController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
private String prefix = "system/user";
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysUserService userService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysRoleService roleService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysDeptService deptService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysPostService postService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysPasswordService passwordService;
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:user:view")
|
|
|
|
|
@GetMapping()
|
|
|
|
|
public String user()
|
|
|
|
|
{
|
|
|
|
|
return prefix + "/user";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@PostMapping("/list")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public TableDataInfo list(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
startPage();
|
|
|
|
|
List<SysUser> list = userService.selectUserList(user);
|
|
|
|
|
return getDataTable(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
|
|
|
|
@RequiresPermissions("system:user:export")
|
|
|
|
|
@PostMapping("/export")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult export(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
List<SysUser> list = userService.selectUserList(user);
|
|
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
|
|
|
|
return util.exportExcel(list, "用户数据");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
|
|
|
|
@RequiresPermissions("system:user:import")
|
|
|
|
|
@PostMapping("/importData")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
|
|
|
|
|
{
|
|
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
|
|
|
|
List<SysUser> userList = util.importExcel(file.getInputStream());
|
|
|
|
|
String message = userService.importUser(userList, updateSupport, getLoginName());
|
|
|
|
|
return AjaxResult.success(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:user:view")
|
|
|
|
|
@GetMapping("/importTemplate")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult importTemplate()
|
|
|
|
|
{
|
|
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
|
|
|
|
return util.importTemplateExcel("用户数据");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增用户
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:add")
|
|
|
|
|
@GetMapping("/add")
|
|
|
|
|
public String add(ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
mmap.put("roles", roleService.selectRoleAll().stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
|
|
|
|
mmap.put("posts", postService.selectPostAll());
|
|
|
|
|
return prefix + "/add";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增保存用户
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:add")
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
|
|
|
|
@PostMapping("/add")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult addSave(@Validated SysUser user)
|
|
|
|
|
{
|
|
|
|
|
deptService.checkDeptDataScope(user.getDeptId());
|
|
|
|
|
roleService.checkRoleDataScope(user.getRoleIds());
|
|
|
|
|
if (!userService.checkLoginNameUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("新增用户'" + user.getLoginName() + "'失败,登录账号已存在");
|
|
|
|
|
}
|
|
|
|
|
else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("新增用户'" + user.getLoginName() + "'失败,手机号码已存在");
|
|
|
|
|
}
|
|
|
|
|
else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
|
|
|
|
|
}
|
|
|
|
|
user.setSalt(ShiroUtils.randomSalt());
|
|
|
|
|
user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
|
|
|
|
|
user.setPwdUpdateDate(DateUtils.getNowDate());
|
|
|
|
|
user.setCreateBy(getLoginName());
|
|
|
|
|
return toAjax(userService.insertUser(user));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改用户
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@GetMapping("/edit/{userId}")
|
|
|
|
|
public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserDataScope(userId);
|
|
|
|
|
List<SysRole> roles = roleService.selectRolesByUserId(userId);
|
|
|
|
|
mmap.put("user", userService.selectUserById(userId));
|
|
|
|
|
mmap.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
|
|
|
|
mmap.put("posts", postService.selectPostsByUserId(userId));
|
|
|
|
|
return prefix + "/edit";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询用户详细
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/view/{userId}")
|
|
|
|
|
public String view(@PathVariable("userId") Long userId, ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserDataScope(userId);
|
|
|
|
|
mmap.put("user", userService.selectUserById(userId));
|
|
|
|
|
mmap.put("roleGroup", userService.selectUserRoleGroup(userId));
|
|
|
|
|
mmap.put("postGroup", userService.selectUserPostGroup(userId));
|
|
|
|
|
return prefix + "/view";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改保存用户
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PostMapping("/edit")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult editSave(@Validated SysUser user)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserAllowed(user);
|
|
|
|
|
userService.checkUserDataScope(user.getUserId());
|
|
|
|
|
deptService.checkDeptDataScope(user.getDeptId());
|
|
|
|
|
roleService.checkRoleDataScope(user.getRoleIds());
|
|
|
|
|
if (!userService.checkLoginNameUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("修改用户'" + user.getLoginName() + "'失败,登录账号已存在");
|
|
|
|
|
}
|
|
|
|
|
else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("修改用户'" + user.getLoginName() + "'失败,手机号码已存在");
|
|
|
|
|
}
|
|
|
|
|
else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("修改用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
|
|
|
|
|
}
|
|
|
|
|
user.setUpdateBy(getLoginName());
|
|
|
|
|
AuthorizationUtils.clearAllCachedAuthorizationInfo();
|
|
|
|
|
return toAjax(userService.updateUser(user));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:user:resetPwd")
|
|
|
|
|
@GetMapping("/resetPwd/{userId}")
|
|
|
|
|
public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
mmap.put("user", userService.selectUserById(userId));
|
|
|
|
|
return prefix + "/resetPwd";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:user:resetPwd")
|
|
|
|
|
@Log(title = "重置密码", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PostMapping("/resetPwd")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult resetPwdSave(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserAllowed(user);
|
|
|
|
|
userService.checkUserDataScope(user.getUserId());
|
|
|
|
|
user.setSalt(ShiroUtils.randomSalt());
|
|
|
|
|
String realPassword = user.getPassword();
|
|
|
|
|
user.setPassword(passwordService.encryptPassword(user.getLoginName(), realPassword, user.getSalt()));
|
|
|
|
|
if (userService.resetUserPwd(user) > 0)
|
|
|
|
|
{
|
|
|
|
|
SysUser dbUser = userService.selectUserById(user.getUserId());
|
|
|
|
|
if (dbUser!=null && StringUtils.isNotEmpty(dbUser.getEmail())){
|
|
|
|
|
TemplateMailUtil.sendTemplateMail(Collections.singletonList(dbUser.getEmail()),"密码重置", TemplateMailUtil.MailTemplate.PASSWORD_RESET, Dict.of("password", realPassword));
|
|
|
|
|
}
|
|
|
|
|
if (ShiroUtils.getUserId().longValue() == user.getUserId().longValue())
|
|
|
|
|
{
|
|
|
|
|
setSysUser(dbUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
return error();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 进入授权角色页
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@GetMapping("/authRole/{userId}")
|
|
|
|
|
public String authRole(@PathVariable("userId") Long userId, ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
SysUser user = userService.selectUserById(userId);
|
|
|
|
|
// 获取用户所属的角色列表
|
|
|
|
|
List<SysRole> roles = roleService.selectRolesByUserId(userId);
|
|
|
|
|
mmap.put("user", user);
|
|
|
|
|
mmap.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
|
|
|
|
return prefix + "/authRole";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户授权角色
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.GRANT)
|
|
|
|
|
@PostMapping("/authRole/insertAuthRole")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserDataScope(userId);
|
|
|
|
|
roleService.checkRoleDataScope(roleIds);
|
|
|
|
|
userService.insertUserAuth(userId, roleIds);
|
|
|
|
|
AuthorizationUtils.clearAllCachedAuthorizationInfo();
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:user:remove")
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
|
|
|
|
@PostMapping("/remove")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult remove(String ids)
|
|
|
|
|
{
|
|
|
|
|
if (ArrayUtils.contains(Convert.toLongArray(ids), getUserId()))
|
|
|
|
|
{
|
|
|
|
|
return error("当前用户不能删除");
|
|
|
|
|
}
|
|
|
|
|
return toAjax(userService.deleteUserByIds(ids));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验用户名
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/checkLoginNameUnique")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public boolean checkLoginNameUnique(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
return userService.checkLoginNameUnique(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验手机号码
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/checkPhoneUnique")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public boolean checkPhoneUnique(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
return userService.checkPhoneUnique(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验email邮箱
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/checkEmailUnique")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public boolean checkEmailUnique(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
return userService.checkEmailUnique(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户状态修改
|
|
|
|
|
*/
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@PostMapping("/changeStatus")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult changeStatus(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserAllowed(user);
|
|
|
|
|
userService.checkUserDataScope(user.getUserId());
|
|
|
|
|
return toAjax(userService.changeStatus(user));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载部门列表树
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/deptTreeData")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public List<Ztree> deptTreeData()
|
|
|
|
|
{
|
|
|
|
|
List<Ztree> ztrees = deptService.selectDeptTree(new SysDept());
|
|
|
|
|
return ztrees;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 选择部门树
|
|
|
|
|
*
|
|
|
|
|
* @param deptId 部门ID
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/selectDeptTree/{deptId}")
|
|
|
|
|
public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
SysDept value = deptService.selectDeptById(deptId);
|
|
|
|
|
mmap.put("dept", value==null?new SysDept():value);
|
|
|
|
|
return prefix + "/deptTree";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------VUE页面使用---------------------------
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/list")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public TableDataInfo listPage(SysUser user) {
|
|
|
|
|
startPage();
|
|
|
|
|
List<SysUser> list = userService.selectUserList(user);
|
|
|
|
|
return getDataTable(list);
|
|
|
|
|
}
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/{userId}")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult query(@PathVariable("userId") Long userId) {
|
|
|
|
|
return success(userService.selectUserById(userId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取部门树列表
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/deptTree")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult deptTree(SysDept dept) {
|
|
|
|
|
return success(deptService.selectDeptTreeList(dept));
|
|
|
|
|
}
|
|
|
|
|
package com.ruoyi.web.controller.system;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.Dict;
|
|
|
|
|
import com.ruoyi.common.config.RuoYiConfig;
|
|
|
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
|
|
|
import com.ruoyi.common.utils.mail.TemplateMailUtil;
|
|
|
|
|
import com.ruoyi.system.domain.SysPost;
|
|
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
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.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.common.core.domain.Ztree;
|
|
|
|
|
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.core.page.TableDataInfo;
|
|
|
|
|
import com.ruoyi.common.core.text.Convert;
|
|
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
|
|
import com.ruoyi.common.utils.ShiroUtils;
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
|
|
import com.ruoyi.framework.shiro.service.SysPasswordService;
|
|
|
|
|
import com.ruoyi.framework.shiro.util.AuthorizationUtils;
|
|
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
|
|
|
import com.ruoyi.system.service.ISysPostService;
|
|
|
|
|
import com.ruoyi.system.service.ISysRoleService;
|
|
|
|
|
import com.ruoyi.system.service.ISysUserService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户信息
|
|
|
|
|
*
|
|
|
|
|
* @author ruoyi
|
|
|
|
|
*/
|
|
|
|
|
@Controller
|
|
|
|
|
@RequestMapping("/system/user")
|
|
|
|
|
public class SysUserController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
private String prefix = "system/user";
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysUserService userService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysRoleService roleService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysDeptService deptService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysPostService postService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysPasswordService passwordService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private RuoYiConfig ruoYiConfig;
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:user:view")
|
|
|
|
|
@GetMapping()
|
|
|
|
|
public String user()
|
|
|
|
|
{
|
|
|
|
|
return prefix + "/user";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@PostMapping("/list")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public TableDataInfo list(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
startPage();
|
|
|
|
|
List<SysUser> list = userService.selectUserList(user);
|
|
|
|
|
return getDataTable(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
|
|
|
|
@RequiresPermissions("system:user:export")
|
|
|
|
|
@PostMapping("/export")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult export(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
List<SysUser> list = userService.selectUserList(user);
|
|
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
|
|
|
|
return util.exportExcel(list, "用户数据");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
|
|
|
|
@RequiresPermissions("system:user:import")
|
|
|
|
|
@PostMapping("/importData")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
|
|
|
|
|
{
|
|
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
|
|
|
|
List<SysUser> userList = util.importExcel(file.getInputStream());
|
|
|
|
|
String message = userService.importUser(userList, updateSupport, getLoginName());
|
|
|
|
|
return AjaxResult.success(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:user:view")
|
|
|
|
|
@GetMapping("/importTemplate")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult importTemplate()
|
|
|
|
|
{
|
|
|
|
|
ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
|
|
|
|
return util.importTemplateExcel("用户数据");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增用户
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:add")
|
|
|
|
|
@GetMapping("/add")
|
|
|
|
|
public String add(ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
mmap.put("roles", roleService.selectRoleAll().stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
|
|
|
|
mmap.put("posts", postService.selectPostAll());
|
|
|
|
|
return prefix + "/add";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增保存用户
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:add")
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
|
|
|
|
@PostMapping("/add")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult addSave(@Validated SysUser user)
|
|
|
|
|
{
|
|
|
|
|
deptService.checkDeptDataScope(user.getDeptId());
|
|
|
|
|
roleService.checkRoleDataScope(user.getRoleIds());
|
|
|
|
|
if (!userService.checkLoginNameUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("新增用户'" + user.getLoginName() + "'失败,登录账号已存在");
|
|
|
|
|
}
|
|
|
|
|
else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("新增用户'" + user.getLoginName() + "'失败,手机号码已存在");
|
|
|
|
|
}
|
|
|
|
|
else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
|
|
|
|
|
}
|
|
|
|
|
user.setSalt(ShiroUtils.randomSalt());
|
|
|
|
|
user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
|
|
|
|
|
user.setPwdUpdateDate(DateUtils.getNowDate());
|
|
|
|
|
user.setCreateBy(getLoginName());
|
|
|
|
|
return toAjax(userService.insertUser(user));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改用户
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@GetMapping("/edit/{userId}")
|
|
|
|
|
public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserDataScope(userId);
|
|
|
|
|
List<SysRole> roles = roleService.selectRolesByUserId(userId);
|
|
|
|
|
mmap.put("user", userService.selectUserById(userId));
|
|
|
|
|
mmap.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
|
|
|
|
mmap.put("posts", postService.selectPostsByUserId(userId));
|
|
|
|
|
return prefix + "/edit";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询用户详细
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/view/{userId}")
|
|
|
|
|
public String view(@PathVariable("userId") Long userId, ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserDataScope(userId);
|
|
|
|
|
mmap.put("user", userService.selectUserById(userId));
|
|
|
|
|
mmap.put("roleGroup", userService.selectUserRoleGroup(userId));
|
|
|
|
|
mmap.put("postGroup", userService.selectUserPostGroup(userId));
|
|
|
|
|
return prefix + "/view";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改保存用户
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PostMapping("/edit")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult editSave(@Validated SysUser user)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserAllowed(user);
|
|
|
|
|
userService.checkUserDataScope(user.getUserId());
|
|
|
|
|
deptService.checkDeptDataScope(user.getDeptId());
|
|
|
|
|
roleService.checkRoleDataScope(user.getRoleIds());
|
|
|
|
|
if (!userService.checkLoginNameUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("修改用户'" + user.getLoginName() + "'失败,登录账号已存在");
|
|
|
|
|
}
|
|
|
|
|
else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("修改用户'" + user.getLoginName() + "'失败,手机号码已存在");
|
|
|
|
|
}
|
|
|
|
|
else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
|
|
|
|
{
|
|
|
|
|
return error("修改用户'" + user.getLoginName() + "'失败,邮箱账号已存在");
|
|
|
|
|
}
|
|
|
|
|
user.setUpdateBy(getLoginName());
|
|
|
|
|
AuthorizationUtils.clearAllCachedAuthorizationInfo();
|
|
|
|
|
return toAjax(userService.updateUser(user));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresPermissions("system:user:resetPwd")
|
|
|
|
|
@GetMapping("/resetPwd/{userId}")
|
|
|
|
|
public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
mmap.put("user", userService.selectUserById(userId));
|
|
|
|
|
return prefix + "/resetPwd";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: The frontend expects a PUT request to '/resetPwd' with a JSON body. This endpoint uses POST and takes form data.
|
|
|
|
|
@RequiresPermissions("system:user:resetPwd")
|
|
|
|
|
@Log(title = "重置密码", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PostMapping("/resetPwd")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult resetPwdSave(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserAllowed(user);
|
|
|
|
|
userService.checkUserDataScope(user.getUserId());
|
|
|
|
|
user.setSalt(ShiroUtils.randomSalt());
|
|
|
|
|
String realPassword = user.getPassword();
|
|
|
|
|
user.setPassword(passwordService.encryptPassword(user.getLoginName(), realPassword, user.getSalt()));
|
|
|
|
|
if (userService.resetUserPwd(user) > 0)
|
|
|
|
|
{
|
|
|
|
|
SysUser dbUser = userService.selectUserById(user.getUserId());
|
|
|
|
|
if (dbUser!=null && StringUtils.isNotEmpty(dbUser.getEmail())){
|
|
|
|
|
TemplateMailUtil.sendTemplateMail(Collections.singletonList(dbUser.getEmail()),"密码重置", TemplateMailUtil.MailTemplate.PASSWORD_RESET, Dict.of("password", realPassword));
|
|
|
|
|
}
|
|
|
|
|
if (ShiroUtils.getUserId().longValue() == user.getUserId().longValue())
|
|
|
|
|
{
|
|
|
|
|
setSysUser(dbUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
return error();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 进入授权角色页
|
|
|
|
|
*/
|
|
|
|
|
// TODO: The frontend expects a GET request to this URL that returns JSON data (user and roles), not a view name.
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@GetMapping("/authRole/{userId}")
|
|
|
|
|
public String authRole(@PathVariable("userId") Long userId, ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
SysUser user = userService.selectUserById(userId);
|
|
|
|
|
// 获取用户所属的角色列表
|
|
|
|
|
List<SysRole> roles = roleService.selectRolesByUserId(userId);
|
|
|
|
|
mmap.put("user", user);
|
|
|
|
|
mmap.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
|
|
|
|
return prefix + "/authRole";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户授权角色
|
|
|
|
|
*/
|
|
|
|
|
// TODO: The frontend expects a PUT request to '/system/user/authRole'. This endpoint is at '/authRole/insertAuthRole' and uses POST.
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.GRANT)
|
|
|
|
|
@PostMapping("/authRole/insertAuthRole")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserDataScope(userId);
|
|
|
|
|
roleService.checkRoleDataScope(roleIds);
|
|
|
|
|
userService.insertUserAuth(userId, roleIds);
|
|
|
|
|
AuthorizationUtils.clearAllCachedAuthorizationInfo();
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: The frontend expects a DELETE request to '/system/user/{userIds}'. This endpoint is at '/remove' and uses POST.
|
|
|
|
|
@RequiresPermissions("system:user:remove")
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
|
|
|
|
@PostMapping("/remove")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult remove(String ids)
|
|
|
|
|
{
|
|
|
|
|
if (ArrayUtils.contains(Convert.toLongArray(ids), getUserId()))
|
|
|
|
|
{
|
|
|
|
|
return error("当前用户不能删除");
|
|
|
|
|
}
|
|
|
|
|
return toAjax(userService.deleteUserByIds(ids));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验用户名
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/checkLoginNameUnique")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public boolean checkLoginNameUnique(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
return userService.checkLoginNameUnique(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验手机号码
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/checkPhoneUnique")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public boolean checkPhoneUnique(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
return userService.checkPhoneUnique(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验email邮箱
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping("/checkEmailUnique")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public boolean checkEmailUnique(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
return userService.checkEmailUnique(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户状态修改
|
|
|
|
|
*/
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@PostMapping("/changeStatus")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult changeStatus(SysUser user)
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserAllowed(user);
|
|
|
|
|
userService.checkUserDataScope(user.getUserId());
|
|
|
|
|
return toAjax(userService.changeStatus(user));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载部门列表树
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/deptTreeData")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public List<Ztree> deptTreeData()
|
|
|
|
|
{
|
|
|
|
|
List<Ztree> ztrees = deptService.selectDeptTree(new SysDept());
|
|
|
|
|
return ztrees;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 选择部门树
|
|
|
|
|
*
|
|
|
|
|
* @param deptId 部门ID
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/selectDeptTree/{deptId}")
|
|
|
|
|
public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap)
|
|
|
|
|
{
|
|
|
|
|
SysDept value = deptService.selectDeptById(deptId);
|
|
|
|
|
mmap.put("dept", value==null?new SysDept():value);
|
|
|
|
|
return prefix + "/deptTree";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------VUE页面使用---------------------------
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/list")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public TableDataInfo listPage(SysUser user) {
|
|
|
|
|
startPage();
|
|
|
|
|
List<SysUser> list = userService.selectUserList(user);
|
|
|
|
|
return getDataTable(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: The frontend 'getUser' call expects this endpoint to return not just the user, but also 'posts', 'roles', 'postIds', and 'roleIds' for the add/edit dialog.
|
|
|
|
|
/**
|
|
|
|
|
* 根据用户编号获取详细信息
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = { "/", "/{userId}" })
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
|
|
|
|
|
{
|
|
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
|
|
if (StringUtils.isNotNull(userId))
|
|
|
|
|
{
|
|
|
|
|
userService.checkUserDataScope(userId);
|
|
|
|
|
SysUser sysUser = userService.selectUserById(userId);
|
|
|
|
|
ajax.put(AjaxResult.DATA_TAG, sysUser);
|
|
|
|
|
List<SysPost> postList = postService.selectPostsByUserId(userId);
|
|
|
|
|
ajax.put("postIds", postList.stream().filter(SysPost::isFlag).map(SysPost::getPostId).collect(Collectors.toList()));
|
|
|
|
|
ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
return ajax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取部门树列表
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:list")
|
|
|
|
|
@GetMapping("/deptTree")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult deptTree(SysDept dept) {
|
|
|
|
|
return success(deptService.selectDeptTreeList(dept));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 新增保存用户
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:add")
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
|
|
|
|
@PostMapping()
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult insertUser(@RequestBody @Validated SysUser user)
|
|
|
|
|
{
|
|
|
|
|
return addSave(user);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 修改保存用户
|
|
|
|
|
*/
|
|
|
|
|
@RequiresPermissions("system:user:edit")
|
|
|
|
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PutMapping()
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult updateUser(@RequestBody @Validated SysUser user)
|
|
|
|
|
{
|
|
|
|
|
return editSave(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------新增的个人信息 业务处理---------------------------
|
|
|
|
|
/**
|
|
|
|
|
* 个人信息
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/profile")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult profile()
|
|
|
|
|
{
|
|
|
|
|
SysUser user = getSysUser();
|
|
|
|
|
AjaxResult ajax = AjaxResult.success(user);
|
|
|
|
|
ajax.put("roleGroup", userService.selectUserRoleGroup(user.getUserId()));
|
|
|
|
|
ajax.put("postGroup", userService.selectUserPostGroup(user.getUserId()));
|
|
|
|
|
return ajax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改用户
|
|
|
|
|
*/
|
|
|
|
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PutMapping("/profile")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult updateProfile(@RequestBody SysUser user)
|
|
|
|
|
{
|
|
|
|
|
SysUser currentUser = getSysUser();
|
|
|
|
|
currentUser.setUserName(user.getUserName());
|
|
|
|
|
currentUser.setEmail(user.getEmail());
|
|
|
|
|
currentUser.setPhonenumber(user.getPhonenumber());
|
|
|
|
|
currentUser.setSex(user.getSex());
|
|
|
|
|
if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(currentUser))
|
|
|
|
|
{
|
|
|
|
|
return error("修改用户'" + currentUser.getLoginName() + "'失败,手机号码已存在");
|
|
|
|
|
}
|
|
|
|
|
else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(currentUser))
|
|
|
|
|
{
|
|
|
|
|
return error("修改用户'" + currentUser.getLoginName() + "'失败,邮箱账号已存在");
|
|
|
|
|
}
|
|
|
|
|
if (userService.updateUserInfo(currentUser) > 0)
|
|
|
|
|
{
|
|
|
|
|
setSysUser(currentUser);
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
return error();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重置密码
|
|
|
|
|
*/
|
|
|
|
|
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PutMapping("/profile/updatePwd")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult updatePwd(String oldPassword, String newPassword)
|
|
|
|
|
{
|
|
|
|
|
SysUser user = getSysUser();
|
|
|
|
|
if (!passwordService.matches(user, oldPassword))
|
|
|
|
|
{
|
|
|
|
|
return error("修改密码失败,旧密码错误");
|
|
|
|
|
}
|
|
|
|
|
if (passwordService.matches(user, newPassword))
|
|
|
|
|
{
|
|
|
|
|
return error("新密码不能与旧密码相同");
|
|
|
|
|
}
|
|
|
|
|
user.setSalt(ShiroUtils.randomSalt());
|
|
|
|
|
user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt()));
|
|
|
|
|
user.setPwdUpdateDate(DateUtils.getNowDate());
|
|
|
|
|
if (userService.resetUserPwd(user) > 0)
|
|
|
|
|
{
|
|
|
|
|
setSysUser(userService.selectUserById(user.getUserId()));
|
|
|
|
|
return success();
|
|
|
|
|
}
|
|
|
|
|
return error("修改密码异常,请联系管理员");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 头像上传
|
|
|
|
|
*/
|
|
|
|
|
@Log(title = "用户头像", businessType = BusinessType.UPDATE)
|
|
|
|
|
@PostMapping("/profile/avatar")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException
|
|
|
|
|
{
|
|
|
|
|
if (!file.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
SysUser currentUser = getSysUser();
|
|
|
|
|
String avatar = FileUploadUtils.upload(ruoYiConfig.getAvatarPath(), file);
|
|
|
|
|
currentUser.setAvatar(avatar);
|
|
|
|
|
if (userService.updateUserInfo(currentUser) > 0)
|
|
|
|
|
{
|
|
|
|
|
setSysUser(currentUser);
|
|
|
|
|
return AjaxResult.success().put("imgUrl", avatar);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return error();
|
|
|
|
|
}
|
|
|
|
|
}
|