mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-23 20:42:42 +08:00
权限优化
This commit is contained in:
parent
1dc7ed0a85
commit
f3e1a6a0de
@ -24,15 +24,15 @@ public class AdminPermissionCheck implements ApplicationRunner {
|
|||||||
private AdminPermissionService permissionService;
|
private AdminPermissionService permissionService;
|
||||||
|
|
||||||
private final String[][] ACTION_PERMISSIONS = {
|
private final String[][] ACTION_PERMISSIONS = {
|
||||||
{"管理员-查看", BPermissionConstant.ADMIN_USER_INDEX},
|
{"管理员", "0", "管理员-查看", BPermissionConstant.ADMIN_USER_INDEX},
|
||||||
{"管理员-添加", BPermissionConstant.ADMIN_USER_STORE},
|
{"管理员", "5", "管理员-添加", BPermissionConstant.ADMIN_USER_STORE},
|
||||||
{"管理员-编辑", BPermissionConstant.ADMIN_USER_UPDATE},
|
{"管理员", "10", "管理员-编辑", BPermissionConstant.ADMIN_USER_UPDATE},
|
||||||
{"管理员-删除", BPermissionConstant.ADMIN_USER_DESTROY},
|
{"管理员", "15", "管理员-删除", BPermissionConstant.ADMIN_USER_DESTROY},
|
||||||
|
|
||||||
{"部门-查看", BPermissionConstant.DEPARTMENT_INDEX},
|
{"部门", "0", "部门-查看", BPermissionConstant.DEPARTMENT_INDEX},
|
||||||
{"部门-添加", BPermissionConstant.DEPARTMENT_STORE},
|
{"部门", "5", "部门-添加", BPermissionConstant.DEPARTMENT_STORE},
|
||||||
{"部门-编辑", BPermissionConstant.DEPARTMENT_UPDATE},
|
{"部门", "10", "部门-编辑", BPermissionConstant.DEPARTMENT_UPDATE},
|
||||||
{"部门-删除", BPermissionConstant.DEPARTMENT_DESTROY},
|
{"部门", "15", "部门-删除", BPermissionConstant.DEPARTMENT_DESTROY},
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,14 +43,17 @@ public class AdminPermissionCheck implements ApplicationRunner {
|
|||||||
|
|
||||||
for (int i = 0; i < ACTION_PERMISSIONS.length; i++) {
|
for (int i = 0; i < ACTION_PERMISSIONS.length; i++) {
|
||||||
String[] item = ACTION_PERMISSIONS[i];
|
String[] item = ACTION_PERMISSIONS[i];
|
||||||
if (slugs.get(item[1]) != null) {//已经存在
|
String tmpSlug = item[3];
|
||||||
|
if (slugs.get(tmpSlug) != null) {//已经存在
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
AdminPermission permission = new AdminPermission();
|
AdminPermission permission = new AdminPermission();
|
||||||
|
|
||||||
permission.setName(item[0]);
|
permission.setGroupName(item[0]);
|
||||||
permission.setSlug(item[1]);
|
permission.setSort(Integer.valueOf(item[1]));
|
||||||
permission.setType("action");
|
permission.setName(item[2]);
|
||||||
|
permission.setSlug(tmpSlug);
|
||||||
|
permission.setType(BPermissionConstant.TYPE_ACTION);
|
||||||
permission.setCreatedAt(now);
|
permission.setCreatedAt(now);
|
||||||
|
|
||||||
list.add(permission);
|
list.add(permission);
|
||||||
|
@ -6,6 +6,9 @@ package xyz.playedu.api.constant;
|
|||||||
*/
|
*/
|
||||||
public class BPermissionConstant {
|
public class BPermissionConstant {
|
||||||
|
|
||||||
|
public final static String TYPE_ACTION = "action";
|
||||||
|
public final static String TYPE_DATA = "data";
|
||||||
|
|
||||||
public final static String ADMIN_USER_INDEX = "admin-user-index";
|
public final static String ADMIN_USER_INDEX = "admin-user-index";
|
||||||
public final static String ADMIN_USER_STORE = "admin-user-store";
|
public final static String ADMIN_USER_STORE = "admin-user-store";
|
||||||
public final static String ADMIN_USER_UPDATE = "admin-user-update";
|
public final static String ADMIN_USER_UPDATE = "admin-user-update";
|
||||||
|
@ -19,11 +19,11 @@ import java.util.List;
|
|||||||
public class AdminPermissionController {
|
public class AdminPermissionController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AdminPermissionService adminPermissionService;
|
private AdminPermissionService permissionService;
|
||||||
|
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
public JsonResponse index() {
|
public JsonResponse index() {
|
||||||
List<AdminPermission> data = adminPermissionService.list();
|
List<AdminPermission> data = permissionService.listOrderBySortAsc();
|
||||||
return JsonResponse.data(data);
|
return JsonResponse.data(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,16 @@ public class AdminPermission implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分组
|
||||||
|
*/
|
||||||
|
private String groupName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 升序
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 权限名
|
* 权限名
|
||||||
*/
|
*/
|
||||||
@ -58,6 +68,8 @@ public class AdminPermission implements Serializable {
|
|||||||
AdminPermission other = (AdminPermission) that;
|
AdminPermission other = (AdminPermission) that;
|
||||||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
||||||
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
|
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
|
||||||
|
&& (this.getGroupName() == null ? other.getGroupName() == null : this.getGroupName().equals(other.getGroupName()))
|
||||||
|
&& (this.getSort() == null ? other.getSort() == null : this.getSort().equals(other.getSort()))
|
||||||
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
|
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
|
||||||
&& (this.getSlug() == null ? other.getSlug() == null : this.getSlug().equals(other.getSlug()))
|
&& (this.getSlug() == null ? other.getSlug() == null : this.getSlug().equals(other.getSlug()))
|
||||||
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()));
|
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()));
|
||||||
@ -69,6 +81,8 @@ public class AdminPermission implements Serializable {
|
|||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||||
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
|
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
|
||||||
|
result = prime * result + ((getGroupName() == null) ? 0 : getGroupName().hashCode());
|
||||||
|
result = prime * result + ((getSort() == null) ? 0 : getSort().hashCode());
|
||||||
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
||||||
result = prime * result + ((getSlug() == null) ? 0 : getSlug().hashCode());
|
result = prime * result + ((getSlug() == null) ? 0 : getSlug().hashCode());
|
||||||
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
|
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
|
||||||
@ -83,6 +97,8 @@ public class AdminPermission implements Serializable {
|
|||||||
sb.append("Hash = ").append(hashCode());
|
sb.append("Hash = ").append(hashCode());
|
||||||
sb.append(", id=").append(id);
|
sb.append(", id=").append(id);
|
||||||
sb.append(", type=").append(type);
|
sb.append(", type=").append(type);
|
||||||
|
sb.append(", groupName=").append(groupName);
|
||||||
|
sb.append(", sort=").append(sort);
|
||||||
sb.append(", name=").append(name);
|
sb.append(", name=").append(name);
|
||||||
sb.append(", slug=").append(slug);
|
sb.append(", slug=").append(slug);
|
||||||
sb.append(", createdAt=").append(createdAt);
|
sb.append(", createdAt=").append(createdAt);
|
||||||
|
@ -5,11 +5,11 @@ import xyz.playedu.api.domain.AdminPermission;
|
|||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
* @description 针对表【admin_permissions】的数据库操作Mapper
|
* @description 针对表【admin_permissions】的数据库操作Mapper
|
||||||
* @createDate 2023-02-20 14:27:50
|
* @createDate 2023-02-21 15:37:02
|
||||||
* @Entity xyz.playedu.api.domain.AdminPermission
|
* @Entity xyz.playedu.api.domain.AdminPermission
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface AdminPermissionMapper extends BaseMapper<AdminPermission> {
|
public interface AdminPermissionMapper extends BaseMapper<AdminPermission> {
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import xyz.playedu.api.domain.AdminPermission;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
@ -14,4 +15,6 @@ public interface AdminPermissionService extends IService<AdminPermission> {
|
|||||||
|
|
||||||
HashMap<String, Boolean> allSlugs();
|
HashMap<String, Boolean> allSlugs();
|
||||||
|
|
||||||
|
List<AdminPermission> listOrderBySortAsc();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,11 @@ public class AdminPermissionServiceImpl extends ServiceImpl<AdminPermissionMappe
|
|||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AdminPermission> listOrderBySortAsc() {
|
||||||
|
return list(query().getWrapper().orderByAsc("group_name", "sort"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
server:
|
||||||
|
port: 9898
|
||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
active: "dev"
|
active: "dev"
|
||||||
|
@ -7,13 +7,16 @@
|
|||||||
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.AdminPermission">
|
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.AdminPermission">
|
||||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||||
<result property="type" column="type" jdbcType="VARCHAR"/>
|
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||||
|
<result property="groupName" column="group_name" jdbcType="VARCHAR"/>
|
||||||
|
<result property="sort" column="sort" jdbcType="INTEGER"/>
|
||||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||||
<result property="slug" column="slug" jdbcType="VARCHAR"/>
|
<result property="slug" column="slug" jdbcType="VARCHAR"/>
|
||||||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id,type,name,
|
id,type,group_name,
|
||||||
slug,created_at
|
sort,name,slug,
|
||||||
|
created_at
|
||||||
</sql>
|
</sql>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user