|
@@ -1,10 +1,7 @@
|
|
|
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;
|
|
@@ -12,23 +9,19 @@ import com.xiaoan.common.util.ResultJson;
|
|
|
import com.xiaoan.domain.dto.request.UserRequest;
|
|
|
import com.xiaoan.domain.backend.UserEntity;
|
|
|
import com.xiaoan.domain.dto.response.UserResponse;
|
|
|
+import com.xiaoan.service.backend.RoleService;
|
|
|
import com.xiaoan.service.backend.UserService;
|
|
|
import com.xiaoan.web.aop.WebControllerLog;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import lombok.Data;
|
|
|
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;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
-import tk.mybatis.mapper.entity.Condition;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.validation.Valid;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -37,7 +30,7 @@ import java.util.*;
|
|
|
* Created by owen on 2020/2/18 0018 12:17
|
|
|
*/
|
|
|
@Log4j2
|
|
|
-@Api(tags = "UserController", description = "后台用户管理")
|
|
|
+@Api(tags = "后台用户管理", value = "UserController")
|
|
|
@RestController
|
|
|
@RequestMapping("api/manage/user")
|
|
|
@Transactional
|
|
@@ -46,6 +39,9 @@ public class UserController extends BaseController {
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RoleService roleService;
|
|
|
+
|
|
|
@RequiresRoles(value = {"admin"}, logical = Logical.OR)
|
|
|
@WebControllerLog(description = "用户管理-查看用户列表/搜索")
|
|
|
@ApiOperation("分页获取用户列表")
|
|
@@ -101,32 +97,6 @@ public class UserController extends BaseController {
|
|
|
n = userService.update(entity);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-// UserEntity entity = userService.findById(param.getId());
|
|
|
-// if (entity == null ){
|
|
|
-// entity = userService.findByUserName(param.getUserName());
|
|
|
-// if (entity != null) {
|
|
|
-// return new ResultJson(MsgCode.ERROR_CODE, "用户名已存在");
|
|
|
-// }
|
|
|
-//
|
|
|
-// entity = new UserEntity();
|
|
|
-// param.setId(null);
|
|
|
-//
|
|
|
-// BeanUtils.copyProperties(param, entity);
|
|
|
-// entity.setPassword(PasswordUtils.encrypt(param.getUserName(), "123456", PasswordUtils.getStaticSalt()));
|
|
|
-//
|
|
|
-// n = userService.save(entity);
|
|
|
-// } else {
|
|
|
-// // 每次修改,删除用户角色表信息,重新添加
|
|
|
-// userService.deleteUserRole(param.getId());
|
|
|
-//
|
|
|
-// BeanUtils.copyProperties(param, entity);
|
|
|
-// entity.setUpdateTime(new Date());
|
|
|
-// n = userService.update(entity);
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
if (n >= 0) {
|
|
|
if (param.getRoleId() != null) {
|
|
|
// 一个用户只有一个角色
|
|
@@ -141,15 +111,35 @@ public class UserController extends BaseController {
|
|
|
@ApiOperation("删除用户")
|
|
|
@GetMapping("delete/{id}")
|
|
|
public ResultJson delete(@PathVariable Long id){
|
|
|
+
|
|
|
+ // 管理员不能删除自己的账号
|
|
|
+ Set<String> roles = roleService.findRoleByUserId(id);
|
|
|
+
|
|
|
+ if (roles.contains("admin")) {
|
|
|
+ log.error("管理员账户不能删除: {}", id);
|
|
|
+ return new ResultJson(MsgCode.e_ADMIN_4101, MsgCode.msg_ADMIN_4101);
|
|
|
+ }
|
|
|
+
|
|
|
userService.deleteById(id);
|
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
|
|
|
}
|
|
|
|
|
|
@RequiresRoles(value = {"admin"}, logical = Logical.OR)
|
|
|
@ApiOperation("删除多用户")
|
|
|
- @GetMapping("delete/all/{id}")
|
|
|
- public ResultJson deleteAll(@PathVariable String id){
|
|
|
- userService.deleteByIds(id);
|
|
|
+ @GetMapping("delete/all/{ids}")
|
|
|
+ public ResultJson deleteAll(@PathVariable String ids){
|
|
|
+
|
|
|
+ // 管理员账户不能删除
|
|
|
+ String[] split = ids.split(",");
|
|
|
+ for (String s : split) {
|
|
|
+ Set<String> roles = roleService.findRoleByUserId(Long.valueOf(s));
|
|
|
+ if (roles.contains("admin")) {
|
|
|
+ log.info("管理员账户不能删除: {}", s);
|
|
|
+ return new ResultJson(MsgCode.e_ADMIN_4101, MsgCode.msg_ADMIN_4101);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ userService.deleteByIds(ids);
|
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
|
|
|
}
|
|
|
|