|
@@ -1,7 +1,10 @@
|
|
|
package com.xiaoan.web.backend;
|
|
|
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.xiaoan.common.constant.MsgCode;
|
|
|
+import com.xiaoan.common.exception.BaseRuntimeException;
|
|
|
import com.xiaoan.common.model.PageDto;
|
|
|
import com.xiaoan.common.util.PasswordUtils;
|
|
|
import com.xiaoan.common.util.RegexpUtils;
|
|
@@ -15,6 +18,7 @@ import com.xiaoan.web.aop.WebControllerLog;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.shiro.authz.annotation.Logical;
|
|
|
import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -30,6 +34,8 @@ import java.util.*;
|
|
|
* Created by owen on 2020/2/18 0018 12:17
|
|
|
*
|
|
|
* 超级管理员账户,需要手动添加
|
|
|
+ *
|
|
|
+ * 这个不能直接在类管理
|
|
|
*/
|
|
|
@Log4j2
|
|
|
@Api(tags = "后台用户管理", value = "UserController")
|
|
@@ -57,19 +63,52 @@ public class UserController extends BaseController {
|
|
|
@RequiresRoles(value = {"admin"}, logical = Logical.OR)
|
|
|
@ApiOperation("新增或修改用户信息")
|
|
|
@PostMapping("save")
|
|
|
- public ResultJson save(@Valid @RequestBody UserRequest param){
|
|
|
+ public ResultJson save(@RequestBody UserRequest param){
|
|
|
+
|
|
|
|
|
|
-// System.out.println(param.toString());
|
|
|
|
|
|
- int n = 0;
|
|
|
|
|
|
// 验证表单
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(param.getUserName())){
|
|
|
+ log.error("userName: 用户名不能为空");
|
|
|
+ return new ResultJson(MsgCode.e_COMMON_3001, "用户名不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(param.getRealName())){
|
|
|
+ log.error("真实姓名不能为空");
|
|
|
+ return new ResultJson(MsgCode.e_COMMON_3001, "真实姓名不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Validator.isEmail(param.getEmail())) {
|
|
|
+ log.error("email格式有误");
|
|
|
+ return new ResultJson(MsgCode.e_COMMON_3001, "email格式有误");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (param.getDepartmentId() == null) {
|
|
|
+ log.error("部门不能为空");
|
|
|
+ return new ResultJson(MsgCode.e_COMMON_3001, "部门不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (param.getRoleId() == null) {
|
|
|
+ log.error("角色不能为空");
|
|
|
+ return new ResultJson(MsgCode.e_COMMON_3001, "角色不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Validator.isMobile(param.getPhone())) {
|
|
|
+ log.error("手机号码有误");
|
|
|
+ return new ResultJson(MsgCode.e_COMMON_3001, "手机号码有误");
|
|
|
+ }
|
|
|
+
|
|
|
if (RegexpUtils.isContainChinese(param.getUserName())) {
|
|
|
log.error("userName: 不能包含中文");
|
|
|
return new ResultJson(MsgCode.e_COMMON_3003, "用户名不能包含中文字符");
|
|
|
-// throw new BaseRuntimeException(MsgCode.e_COMMON_3003, "用户名不能包含中文字符");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ int n = 0;
|
|
|
+
|
|
|
UserEntity entity = null;
|
|
|
if (param.getId() == null){
|
|
|
entity = userService.findByUserName(param.getUserName());
|
|
@@ -84,10 +123,7 @@ public class UserController extends BaseController {
|
|
|
|
|
|
Integer byMaxNum = userService.findByMaxNum();
|
|
|
// 用于第一条数据
|
|
|
-// if (byMaxNum == null){
|
|
|
-// byMaxNum = 1;
|
|
|
-// }
|
|
|
-// byMaxNum = byMaxNum + 1;
|
|
|
+
|
|
|
byMaxNum = (byMaxNum == null)? 1:byMaxNum + 1;
|
|
|
|
|
|
entity.setUserNum(byMaxNum);
|
|
@@ -172,6 +208,14 @@ public class UserController extends BaseController {
|
|
|
@ApiOperation("修改密码")
|
|
|
@PostMapping("updatePwd")
|
|
|
public ResultJson updatePwd(@RequestParam String oldPassword, @RequestParam String password){
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(oldPassword) || StringUtils.isBlank(password)){
|
|
|
+ log.error("密码不能为空");
|
|
|
+ return new ResultJson(MsgCode.e_COMMON_3001, "密码不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
UserEntity userEntity = userService.findByUserName(getTokenUserName());
|
|
|
|
|
|
// 验证原密码
|
|
@@ -214,12 +258,4 @@ public class UserController extends BaseController {
|
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
-
|
|
|
- String ids = "1111111";
|
|
|
-
|
|
|
- System.out.println(RegexpUtils.isContainChinese(ids));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
}
|