Browse Source

修改管理员角色不能修改

wuweihao 5 năm trước cách đây
mục cha
commit
017a64f908

+ 2 - 2
gis_domain/src/main/java/com/gis/domain/po/SysRoleEntity.java

@@ -12,8 +12,8 @@ public class SysRoleEntity extends BaseEntity implements Serializable {
 
     private static final long serialVersionUID = -8093446477843493946L;
 
-//    @ApiModelProperty(value = "角色key")
-//    private String roleKey;
+    @ApiModelProperty(value = "角色key")
+    private String roleKey;
 
     @ApiModelProperty(value = "角色名称")
     private String roleName;

+ 3 - 2
gis_domain/src/main/java/com/gis/domain/po/SysUserEntity.java

@@ -46,8 +46,9 @@ public class SysUserEntity extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "头像url")
     private String icon;
 
-//    @ApiModelProperty(value = "超级管理员,1:是, 0:否")
-//    private Integer sysManager;
+    /** 设置默认超级管理员使用*/
+    @ApiModelProperty(value = "超级管理员,1:是, 0:否")
+    private Integer sysManager;
 
 
 

+ 0 - 21
gis_mapper/src/main/java/com/gis/mapper/provider/QuestionProvider.java

@@ -33,25 +33,4 @@ public class QuestionProvider {
         return sql.toString();
     }
 
-
-//    public String vFindById(Long id){
-//        StringBuffer sql = new StringBuffer(
-//                "select id, type, level from tb_question where rec_status = 'A' ");
-//
-//        String searchKey = param.getSearchKey();
-//        if(!StringUtils.isAllBlank(searchKey)){
-//            sql.append(" and (( poet like '%").append(searchKey).append("%' )");
-////            sql.append(" or ( type like '%").append(searchKey).append("%' )");
-//            sql.append(" or ( related like '%").append(searchKey).append("%' ))");
-//        }
-//
-//        Integer type = param.getType();
-//        if (type != null) {
-//            sql.append(" and type = ").append(type);
-//        }
-//
-//        sql.append(" order by create_time desc");
-//        log.info("sql: {}", sql.toString());
-//        return sql.toString();
-//    }
 }

+ 3 - 3
gis_web/src/main/java/com/gis/web/controller/IndexController.java

@@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit;
 /**
  * Created by owen on 2020/2/19 0019 15:53
  */
-@Api(value = "IndexController",tags = "登录管理")
+@Api(value = "IndexController",tags = "a登录管理")
 @RestController
 @Transactional
 @Log4j2
@@ -72,8 +72,8 @@ public class IndexController extends BaseController {
 
         // 检查账号是否启用
         if (userEntity.getStatus() != 0) {
-            log.error("账号已停用: {}", userEntity.getUserName());
-            return Result.failure("账号已停用");
+            log.error("账号已停用或注销: {}", userEntity.getUserName());
+            return Result.failure("账号已停用或注销");
         }
 
 

+ 52 - 4
gis_web/src/main/java/com/gis/web/controller/SysRoleController.java

@@ -4,6 +4,7 @@ package com.gis.web.controller;
 import com.gis.common.util.Result;
 import com.gis.domain.po.SysRoleEntity;
 import com.gis.domain.dto.RoleDto;
+import com.gis.domain.po.SysUserEntity;
 import com.gis.domain.vo.UserVo;
 import com.gis.service.SysResourceService;
 import com.gis.service.SysRoleService;
@@ -17,6 +18,7 @@ import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import tk.mybatis.mapper.entity.Condition;
 
 import javax.validation.Valid;
 import java.util.Date;
@@ -71,6 +73,11 @@ public class SysRoleController extends BaseController {
                 return Result.failure("对象id不存在");
             }
 
+            if ("sys_admin".equals(entity.getRoleKey())) {
+                log.error("超级管理员角色不能修改: {}");
+                return Result.failure("超级管理员角色不能修改");
+            }
+
             BeanUtils.copyProperties(param, entity);
             entity.setUpdateTime(new Date());
             sysRoleService.update(entity);
@@ -124,11 +131,52 @@ public class SysRoleController extends BaseController {
         return Result.success(resultMap);
     }
 
+    /**
+     * 思考:
+     * 1. 定义一个超级管理员角色,而且这个角色是不可以删除、修改的
+     * 2. 前端判断这个roleKey,如果是,就不做任何判断
+     * 3. 删除角色后,用户的权限怎么去定义
+     */
+//    @ApiOperation("删除角色")
+//    @GetMapping("removes/{ids}")
+//    public Result removes(@PathVariable String ids) {
+//        sysRoleService.deleteByIds(ids);
+//        return Result.success();
+//    }
+
+    @ApiOperation("启用、停用、注销角色")
+    @GetMapping("setStatus/{id}/{status}")
+    public Result setStatus(@PathVariable Long id, @PathVariable Integer status) {
+
+        SysRoleEntity entity = sysRoleService.findById(id);
+        if (entity == null) {
+            log.error("对象不存在: {}", id);
+            return Result.failure("对象不存在");
+        }
+
+        // 管理员账号不能停用
+        if ("sys_admin".equals(entity.getRoleKey())) {
+            log.error("超级管理员角色不能停用/注销: {}", id);
+            return Result.failure("超级管理员角色不能停用/注销");
+        }
+
+        if (status != 1){
+            Condition condition = new Condition(SysUserEntity.class);
+            condition.and().andEqualTo("recStatus", "A");
+            condition.and().andEqualTo("roleId", id);
+            List<SysUserEntity> roles = sysUserService.findAll(condition);
+
+            if (roles.size() > 0) {
+                log.error("该角色已跟用户绑定,不能停用/注销: {}", id);
+                return Result.failure("该角色已跟用户绑定,不能停用/注销");
+            }
+        }
+
+
 
-    @ApiOperation("删除角色")
-    @GetMapping("removes/{ids}")
-    public Result removes(@PathVariable String ids) {
-        sysRoleService.deleteByIds(ids);
+        entity.setStatus(status);
+        entity.setUpdateTime(new Date());
+        sysRoleService.update(entity);
         return Result.success();
     }
 

+ 9 - 4
gis_web/src/main/java/com/gis/web/controller/SysUserController.java

@@ -74,6 +74,11 @@ public class SysUserController extends BaseController {
                 log.error("用户不存在: {}", param.getId());
                 return Result.failure("用户不存在");
             }
+
+            SysUserEntity phoneUser = userService.findByPhone(param.getPhone());
+            if(phoneUser != null && phoneUser.getId().longValue() != user.getId().longValue()) {
+                return Result.failure("该手机号码已存在,请重新输入");
+            }
             BeanUtils.copyProperties(param, user);
             user.setUpdateTime(new Date());
             userService.update(user);
@@ -146,10 +151,10 @@ public class SysUserController extends BaseController {
         }
 
         // 管理员账号不能停用
-//        if (entity.getSysManager() == 1) {
-//            log.error("管理员账户不能停用/注销: {}", id);
-//            return Result.failure("管理员账户不能停用/注销");
-//        }
+        if (entity.getSysManager() == 1) {
+            log.error("超级管理员账户不能停用/注销: {}", id);
+            return Result.failure("超级管理员账户不能停用/注销");
+        }
 
         entity.setStatus(status);
         entity.setUpdateTime(new Date());

+ 4 - 3
gis_web/src/main/java/com/gis/web/shiro/MyRealm.java

@@ -74,10 +74,10 @@ public class MyRealm extends AuthorizingRealm {
         Set<String> permissions = new HashSet<>();
 
 
-
-
+//        SysUserEntity dbUserEntity = userService.findByUserName(JwtUtil.getTokenStringValue(token, "userName"));
+//
 //        List<SysResourceEntity> all = null;
-        // 设置角色、权限
+//         //设置角色、权限
 //        if (dbUserEntity.getSysManager() == 1) {
 //            all = sysResourceService.findAll();
 //        } else {
@@ -86,6 +86,7 @@ public class MyRealm extends AuthorizingRealm {
 //
 //        }
 
+
         Long roleId = JwtUtil.getTokenLongValue(token, "roleId");
         List<SysResourceEntity> all = sysResourceService.findResourceByRoleId(roleId);