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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.yiboshi.science.rest.v1;
import com.yiboshi.arch.base.ResponseDataModel;
import com.yiboshi.science.base.Pagination;
import com.yiboshi.science.config.annotation.Logs;
import com.yiboshi.science.config.security.SecurityUserHolder;
import com.yiboshi.science.entity.ComExpert;
import com.yiboshi.science.entity.ComExpertSpec;
import com.yiboshi.science.entity.SystemUser;
import com.yiboshi.science.enumeration.CommonEnum;
import com.yiboshi.science.param.dto.ComExpertSpecDTO;
import com.yiboshi.science.param.dto.ComPersonDTO;
import com.yiboshi.science.param.dto.SystemUserDTO;
import com.yiboshi.science.param.query.SystemUserQueryVO;
import com.yiboshi.science.rest.BaseController;
import com.yiboshi.science.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 功能:用户信息表 接口
*
* @author lkl
* @version 2021-08-26
*/
@Api(tags = "system-user", description = "用户信息表")
@RestController
@RequestMapping("/v1/science-admin/system-user")
public class SystemUserController extends BaseController<SystemUserService, SystemUserQueryVO, SystemUserDTO, SystemUser> {
@Autowired
private SystemUserService systemUserService;
@Autowired
private SystemUserRoleService systemUserRoleService;
@Autowired
private ComExpertService comExpertService;
/**
* 功能:分页查询
*
* @param vo 查询条件
*/
@ApiOperation(value = "1.02 分页查询", httpMethod = "GET", notes = "1.02 根据参数获取列表")
@GetMapping
@RequestMapping("/getListByPage")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseDataModel<Pagination<SystemUserDTO>> getListByPage(@Validated SystemUserQueryVO vo, BindingResult bindingResult) {
Pagination<SystemUserDTO> page = systemUserService.getListByPage(vo);
if (null != page && null != page.getDataList() && page.getDataList().size() != 0) {
page.getDataList().forEach((e) -> {
e.setStateName(CommonEnum.userState.getEnum(e.getNoteState()).getDescription());
});
}
return ResponseDataModel.ok(page);
}
/**
* 功能:修改人员状态
*
* @param e 输入值
*/
@ApiOperation(value = "1.02", httpMethod = "POST", notes = "1.02 修改人员状态")
@RequestMapping("/updateState")
@PostMapping
@Logs(value = CommonEnum.logType.userStateUpdate)
public ResponseDataModel<String> updateState(@RequestBody SystemUser e) {
return ResponseDataModel.ok(systemUserService.updateStateById(e.getId(), e.getNoteState()));
}
@ApiOperation(value = "重置密码", httpMethod = "POST", notes = "重置密码")
@RequestMapping("/resetUserPwd")
@PostMapping
@Logs(value = CommonEnum.logType.userReset)
public ResponseDataModel<String> resetUserPwd(@Validated @RequestBody ComPersonDTO dto) {
return ResponseDataModel.ok(systemUserService.resetPwd(dto));
}
@ApiOperation(value = "通过Id获取用户信息", httpMethod = "GET", notes = "通过Id获取用户信息")
@GetMapping
@RequestMapping("/getSystemUserById")
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseDataModel<SystemUserDTO> getSystemUserById(String id) {
SystemUserDTO systemUserDTO = systemUserService.getSystemUserById(id);
systemUserDTO.setRole(systemUserRoleService.getRolesListByUserId(id));
return ResponseDataModel.ok(systemUserDTO);
}
@ApiOperation(value = "更新系统用户信息", httpMethod = "POST", notes = "更新系统用户信息")
@RequestMapping("/updateSystemUser")
@PostMapping
@PreAuthorize("hasAnyRole('ADMIN')")
public ResponseDataModel<String> updateSystemUser(@Validated @RequestBody SystemUserDTO dto) {
SystemUser user = systemUserService.getById(dto.getId());
String r = StringUtils.join(dto.getRole().toArray(), ",");
List<String> roles = systemUserRoleService.getRolesListByUserId(dto.getId());
for (String e : roles) {
if (!r.contains(e)) {
systemUserRoleService.deleteRoleByUserId(dto.getId(), e);
}
}
String s = StringUtils.join(roles.toArray(), ",");
for (String e : dto.getRole()) {
if (!s.contains(e)) {
systemUserRoleService.addRoleByUserId(dto.getId(), e);
if (e.equals(CommonEnum.systemRole.expert.getCode().toString())) {
ComExpert comExpert = new ComExpert();
comExpert.setPersonId(user.getPersonId());
comExpert = comExpertService.getEntity(comExpert);
if (null == comExpert) {
comExpert = new ComExpert();
comExpert.setPersonId(user.getPersonId());
comExpert.setExpertState(1);
comExpert.setReportState(1);
comExpertService.insert(comExpert);
}
}
}
}
return ResponseDataModel.ok(systemUserService.updateSystemUser(dto));
}
}