WebFrontUserController.java
10.5 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package com.lhcredit.project.webbusiness.controller;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lhcredit.common.constant.UserConstants;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.security.ShiroUtils;
import com.lhcredit.framework.aspectj.lang.annotation.CheckToken;
import com.lhcredit.framework.aspectj.lang.annotation.Log;
import com.lhcredit.framework.aspectj.lang.enums.BusinessType;
import com.lhcredit.framework.aspectj.lang.enums.OperatorType;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.domain.AjaxResult;
import com.lhcredit.project.business.frontRole.service.IFrontRoleService;
import com.lhcredit.project.business.frontUser.domain.FrontUser;
import com.lhcredit.project.business.frontUser.domain.FrontUserMon;
import com.lhcredit.project.business.frontUser.service.IFrontUserService;
import com.lhcredit.project.business.frontUser.service.TokenManager;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;
/**
* 用户信息对外接口
*
* @author lhcredit
* @date 2023-11-28
*/
@RestController
@RequestMapping("/web/frontUser")
@RequiredArgsConstructor
public class WebFrontUserController extends BaseController {
@Autowired
private IFrontUserService frontUserService;
// private final IFrontUserMonService frontUserService;
//
private final TokenManager tokenManager;
@Autowired
private IFrontRoleService frontRoleService;
//
//// @Autowired
//// private IFrontUserMenuService frontUserMenuService;
//
// @Autowired
// private IFrontUserMonService frontUserMonService;
//
/**
* 查询用户列表接口
*/
@ApiOperation("查询用户列表")
@Log(title = "用户", businessType = BusinessType.LIST, operatorType = OperatorType.WEB)
@GetMapping("/list")
public AjaxResult list(FrontUser frontUser) {
FrontUserMon loginUser=getUserInfo();
frontUser.setId(loginUser.getId());
startPage();
List<FrontUser> list = frontUserService.selectFrontUserByPid(frontUser);
return toAjax(list);
}
//
// /**
// * 查询用户详情接口
// */
// @ApiOperation("查询用户详情")
// @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "int", paramType = "path")
// @Log(title = "用户", businessType = BusinessType.DETAIL, operatorType = OperatorType.WEB)
// @GetMapping("/{id}")
// public AjaxResult detail(@PathVariable int id) {
// FrontUserMon frontUser = frontUserService.changeModel(frontUserService.selectFrontUserById(id));
// if (StringUtils.isNull(frontUser)) {
// return AjaxResult.error("该信息不存在");
// }
// return toAjax(frontUser);
// }
//
// @CheckToken
// @ResponseBody
// @PostMapping("/updatePwd")
// public AjaxResult updatePwd(String newPwd) {
// return frontUserService.updatePwd(getUserInfo().getId(), newPwd);
// }
//
@CheckToken
@ApiOperation(value = "退出登录")
@RequestMapping("/logout")
public AjaxResult logout() {
try {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
tokenManager.loginOff(request.getHeader("Authorization"));
return success("已退出");
} catch (Exception e) {
return loginError("用户登出失败");
}
}
/**
* 新增保存用户接口
*/
@ApiOperation("新增用户")
@ApiImplicitParam(name = "frontUser", value = "用户", dataType = "FrontUser")
@Log(title = "用户", businessType = BusinessType.INSERT, operatorType = OperatorType.WEB)
@PostMapping("/addUser")
public AjaxResult addUser(@RequestBody FrontUser frontUser) {
if (UserConstants.USER_NAME_NOT_UNIQUE.equals(frontUserService.checkLoginNameUnique(frontUser.getLoginName()))) {
return error("保存用户'" + frontUser.getLoginName() + "'失败,登录账号已存在");
}
if(StringUtils.isNotEmpty(frontUser.getWebRoles())){
String[] str=frontUser.getWebRoles().split(",");
Long[] longArray = Arrays.stream(str)
.map(Long::parseLong)
.toArray(Long[]::new);
frontUser.setRoleIds(longArray);
}
frontUser.setCreateBy(ShiroUtils.getLoginName());
frontUser.setCreateTime(new Date());
frontUser.setStorageTime(new Date());
frontUser.setUpdateBy(ShiroUtils.getLoginName());
frontUser.setUpdateTime(new Date());
return toAjax(frontUserService.insertFrontUser(frontUser));
}
/**
* 修改查询接口
*/
@ApiOperation("新增用户")
@ApiImplicitParam(name = "frontUser", value = "用户", dataType = "FrontUser")
@Log(title = "用户", businessType = BusinessType.INSERT, operatorType = OperatorType.WEB)
@PostMapping("/queryUser")
public AjaxResult queryUser(@RequestBody FrontUser frontUser) {
Map map=new HashMap();
if(frontUser.getId()>0){
FrontUser frontUserNew =frontUserService.selectFrontUserById(frontUser.getId());
map.put("frontUser", frontUserNew);
map.put("roles", frontRoleService.selectRolesByUserId(Long.parseLong(frontUser.getId()+"")));
return toAjax(map);
}
return AjaxResult.error("缺少必要参数");
}
/**
* 修改保存用户接口
*/
@ApiOperation("修改用户")
@ApiImplicitParam(name = "frontUser", value = "用户", dataType = "FrontUser")
@Log(title = "用户", businessType = BusinessType.UPDATE, operatorType = OperatorType.WEB)
@PostMapping("/updateUser")
public AjaxResult update(@RequestBody FrontUser frontUser) {
if (StringUtils.isNull(frontUser) || StringUtils.isNull(frontUser.getId())) {
return AjaxResult.error("主键id不能为空");
}
if(StringUtils.isNotEmpty(frontUser.getWebRoles())){
String[] str=frontUser.getWebRoles().split(",");
Long[] longArray = Arrays.stream(str)
.map(Long::parseLong)
.toArray(Long[]::new);
frontUser.setRoleIds(longArray);
}
frontUser.setUpdateBy(ShiroUtils.getLoginName());
frontUser.setUpdateTime(new Date());
return toAjax(frontUserService.updateFrontUser(frontUser));
}
//
// /**
// * 删除用户接口
// */
// @ApiOperation("删除用户")
// @ApiImplicitParam(name = "ids", value = "主键id,多条以英文逗号分隔", required = true, dataType = "String", paramType = "path")
// @Log(title = "用户", businessType = BusinessType.DELETE, operatorType = OperatorType.WEB)
// @DeleteMapping("/{ids}")
// public AjaxResult delete(@PathVariable String ids) {
// return toAjax(frontUserService.deleteFrontUserByIds(ids));
// }
//
//
// /**
// * 用户登录 zhaobh
// */
// @ResponseBody
// @RequestMapping("/webUserLogin.form")
// public AjaxResult webUserLogin(HttpServletRequest request, @RequestBody FrontUserMon frontUser) {
// return frontUserService.webUserLogin(request, frontUser);
// }
//
// /**
// * 查询用户详情接口
// */
// @ApiOperation("个人中心详情")
// @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "int", paramType = "path")
// @Log(title = "用户", businessType = BusinessType.DETAIL, operatorType = OperatorType.WEB)
// @GetMapping("/backUser")
// public AjaxResult backUser() {
// FrontUserMon userInfo = super.getUserInfo();
//
// return toAjax();
// }
//
// /**
// * 查询用户详情接口
// */
// @ApiOperation("个人中心修改")
// @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "int", paramType = "path")
// @Log(title = "用户", businessType = BusinessType.DETAIL, operatorType = OperatorType.WEB)
// @GetMapping("/updateBackUser")
// public AjaxResult updateBackUser(FrontBackUserVo frontBackUserVo) {
// FrontUserMon userInfo = super.getUserInfo();
// userInfo.setUserName(frontBackUserVo.getUserName());
// userInfo.setPassword(frontBackUserVo.getPassword());
// userInfo.setPhone(frontBackUserVo.getPhone());
// userInfo.setMail(frontBackUserVo.getEmail());
// userInfo.setLoginName(frontBackUserVo.getLoginName());
// userInfo.setId(userInfo.getId());
// iFrontUserMonService.updateFrontUser(userInfo);
// //新权限
// List<Integer> newMenuIds = new ArrayList<>();
// frontBackUserVo.getFrontMenuList().stream().forEach(f->{
// if(!ObjectUtils.isEmpty(f.getId()) && f.getIsCheck().equals("1")){
// newMenuIds.add(f.getId().intValue());
// }
// });
// //先删后增加
// frontUserMenuService.deleteFrontUserMenuById(userInfo.getId());
// frontUserMenuService.addMenuIdsById(userInfo.getId(), newMenuIds);
// return AjaxResult.success();
// }
@RequestMapping("/login")
public AjaxResult webLogin(HttpServletRequest request, @RequestBody FrontUserMon frontUserMon){
// HttpSession session = request.getSession(true);
// Object verObj=session.getAttribute("verCode");
// if (null==verObj){
// return AjaxResult.other(4003,"验证码过期");
// }
// String verCode =verObj.toString();
// String code = frontUserMon.getCode();
// if (!verCode.toLowerCase().equals(code.toLowerCase())) {
// return AjaxResult.loginError("验证码错误!");
// }
return frontUserService.webLogin(request, frontUserMon);
}
@RequestMapping("/resetPwd")
public AjaxResult resetPwd( @RequestBody FrontUser user){
FrontUserMon userInfo = getUserInfo();
userInfo.setPassword(user.getPassword());
// user.setModifyPsdPage(0);
userInfo.setModifyPsdPage(0);
return toAjax(frontUserService.resetUserPwd(userInfo));
}
}