SysProfileController.java
3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.huaheng.system.controller;
import com.huaheng.system.api.domain.SysRole;
import com.huaheng.system.service.CompanyService;
import com.huaheng.system.service.ISysRoleService;
import com.huaheng.system.service.ISysUserService;
import com.huaheng.system.service.WarehouseService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.huaheng.common.core.web.controller.BaseController;
import com.huaheng.common.core.web.domain.AjaxResult;
import com.huaheng.common.log.annotation.Log;
import com.huaheng.common.log.enums.BusinessType;
import com.huaheng.common.security.utils.SecurityUtils;
import com.huaheng.system.api.domain.SysUser;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* 个人信息 业务处理
*
* @author ruoyi
*/
@RestController
@RequestMapping("/user/profile")
@Api(value = "个人信息", tags = "个人信息")
public class SysProfileController extends BaseController {
@Resource
private ISysUserService userService;
@Resource
private ISysRoleService roleService;
@Resource
private WarehouseService warehouseService;
@Resource
private CompanyService companyService;
/**
* 个人信息
*/
@GetMapping
@ApiOperation(value = "查询个人信息", notes = "查询个人信息")
public AjaxResult profile() {
String username = SecurityUtils.getUsername();
SysUser user = userService.selectUserByUserName(username);
AjaxResult ajax = AjaxResult.success(user);
List<SysRole> roles = roleService.selectRoleAll();
ajax.put("roles", SysUser.isAdmin(user.getUserId()) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
ajax.put("companies", companyService.selectCompanyByUserId(user.getUserId()));
ajax.put("warehouseCodeList", warehouseService.selectWarehouseByUserId(user.getUserId()));
ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(user.getUserId()));
ajax.put("roleIds", roleService.selectRoleListByUserId(user.getUserId()));
return ajax;
}
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping
@ApiOperation(value = "修改个人信息", notes = "修改个人信息")
public AjaxResult updateProfile(@RequestBody SysUser user) {
if (userService.updateUserProfile(user) > 0) {
return AjaxResult.success();
}
return AjaxResult.error("修改个人信息异常,请联系管理员");
}
/**
* 重置密码
*/
@ApiOperation(value = "重置密码", notes = "重置密码")
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd")
public AjaxResult updatePwd(@ApiParam(value = "旧密码", required = true) @RequestParam(value = "oldPassword") String oldPassword,
@ApiParam(value = "新密码", required = true) @RequestParam(value = "newPassword") String newPassword) {
String username = SecurityUtils.getUsername();
SysUser user = userService.selectUserByUserName(username);
String password = user.getPassword();
if (!SecurityUtils.matchesPassword(oldPassword, password)) {
return AjaxResult.error("修改密码失败,旧密码错误");
}
if (SecurityUtils.matchesPassword(newPassword, password)) {
return AjaxResult.error("新密码不能与旧密码相同");
}
if (userService.resetUserPwd(username, SecurityUtils.encryptPassword(newPassword)) > 0) {
return AjaxResult.success();
}
return AjaxResult.error("修改密码异常,请联系管理员");
}
}