mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-20 01:52:42 +08:00
新增permission的初始化
This commit is contained in:
parent
404305aa71
commit
1dc7ed0a85
@ -2,7 +2,6 @@ package xyz.playedu.api;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
@EnableAsync
|
||||
|
@ -0,0 +1,65 @@
|
||||
package xyz.playedu.api.checks;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.domain.AdminPermission;
|
||||
import xyz.playedu.api.service.AdminPermissionService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/2/20 14:31
|
||||
*/
|
||||
@Component
|
||||
public class AdminPermissionCheck implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private AdminPermissionService permissionService;
|
||||
|
||||
private final String[][] ACTION_PERMISSIONS = {
|
||||
{"管理员-查看", BPermissionConstant.ADMIN_USER_INDEX},
|
||||
{"管理员-添加", BPermissionConstant.ADMIN_USER_STORE},
|
||||
{"管理员-编辑", BPermissionConstant.ADMIN_USER_UPDATE},
|
||||
{"管理员-删除", BPermissionConstant.ADMIN_USER_DESTROY},
|
||||
|
||||
{"部门-查看", BPermissionConstant.DEPARTMENT_INDEX},
|
||||
{"部门-添加", BPermissionConstant.DEPARTMENT_STORE},
|
||||
{"部门-编辑", BPermissionConstant.DEPARTMENT_UPDATE},
|
||||
{"部门-删除", BPermissionConstant.DEPARTMENT_DESTROY},
|
||||
};
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
HashMap<String, Boolean> slugs = permissionService.allSlugs();
|
||||
List<AdminPermission> list = new ArrayList<>();
|
||||
Date now = new Date();
|
||||
|
||||
for (int i = 0; i < ACTION_PERMISSIONS.length; i++) {
|
||||
String[] item = ACTION_PERMISSIONS[i];
|
||||
if (slugs.get(item[1]) != null) {//已经存在
|
||||
continue;
|
||||
}
|
||||
AdminPermission permission = new AdminPermission();
|
||||
|
||||
permission.setName(item[0]);
|
||||
permission.setSlug(item[1]);
|
||||
permission.setType("action");
|
||||
permission.setCreatedAt(now);
|
||||
|
||||
list.add(permission);
|
||||
}
|
||||
|
||||
if (list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
permissionService.saveBatch(list);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package xyz.playedu.api.constant;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/2/21 14:57
|
||||
*/
|
||||
public class BPermissionConstant {
|
||||
|
||||
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_UPDATE = "admin-user-update";
|
||||
public final static String ADMIN_USER_DESTROY = "admin-user-destroy";
|
||||
|
||||
public final static String DEPARTMENT_INDEX = "department-index";
|
||||
public final static String DEPARTMENT_STORE = "department-store";
|
||||
public final static String DEPARTMENT_UPDATE = "department-update";
|
||||
public final static String DEPARTMENT_DESTROY = "department-destroy";
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import xyz.playedu.api.domain.AdminPermission;
|
||||
import xyz.playedu.api.service.AdminPermissionService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/2/20 14:19
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/backend/v1/admin-permission")
|
||||
public class AdminPermissionController {
|
||||
|
||||
@Autowired
|
||||
private AdminPermissionService adminPermissionService;
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index() {
|
||||
List<AdminPermission> data = adminPermissionService.list();
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
}
|
93
src/main/java/xyz/playedu/api/domain/AdminPermission.java
Normal file
93
src/main/java/xyz/playedu/api/domain/AdminPermission.java
Normal file
@ -0,0 +1,93 @@
|
||||
package xyz.playedu.api.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName admin_permissions
|
||||
*/
|
||||
@TableName(value ="admin_permissions")
|
||||
@Data
|
||||
public class AdminPermission implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 类型[行为:action,数据:data]
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 权限名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* slug
|
||||
*/
|
||||
private String slug;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Date createdAt;
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
return true;
|
||||
}
|
||||
if (that == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != that.getClass()) {
|
||||
return false;
|
||||
}
|
||||
AdminPermission other = (AdminPermission) that;
|
||||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
||||
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
|
||||
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
|
||||
&& (this.getSlug() == null ? other.getSlug() == null : this.getSlug().equals(other.getSlug()))
|
||||
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
|
||||
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
|
||||
result = prime * result + ((getSlug() == null) ? 0 : getSlug().hashCode());
|
||||
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" [");
|
||||
sb.append("Hash = ").append(hashCode());
|
||||
sb.append(", id=").append(id);
|
||||
sb.append(", type=").append(type);
|
||||
sb.append(", name=").append(name);
|
||||
sb.append(", slug=").append(slug);
|
||||
sb.append(", createdAt=").append(createdAt);
|
||||
sb.append(", serialVersionUID=").append(serialVersionUID);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package xyz.playedu.api.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import xyz.playedu.api.domain.AdminPermission;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【admin_permissions】的数据库操作Mapper
|
||||
* @createDate 2023-02-20 14:27:50
|
||||
* @Entity xyz.playedu.api.domain.AdminPermission
|
||||
*/
|
||||
@Mapper
|
||||
public interface AdminPermissionMapper extends BaseMapper<AdminPermission> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
package xyz.playedu.api.service;
|
||||
|
||||
import xyz.playedu.api.domain.AdminPermission;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【admin_permissions】的数据库操作Service
|
||||
* @createDate 2023-02-20 14:27:50
|
||||
*/
|
||||
public interface AdminPermissionService extends IService<AdminPermission> {
|
||||
|
||||
HashMap<String, Boolean> allSlugs();
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import xyz.playedu.api.domain.AdminPermission;
|
||||
import xyz.playedu.api.service.AdminPermissionService;
|
||||
import xyz.playedu.api.mapper.AdminPermissionMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【admin_permissions】的数据库操作Service实现
|
||||
* @createDate 2023-02-20 14:27:50
|
||||
*/
|
||||
@Service
|
||||
public class AdminPermissionServiceImpl extends ServiceImpl<AdminPermissionMapper, AdminPermission> implements AdminPermissionService {
|
||||
|
||||
@Override
|
||||
public HashMap<String, Boolean> allSlugs() {
|
||||
List<AdminPermission> data = list();
|
||||
HashMap<String, Boolean> map = new HashMap<>();
|
||||
for (AdminPermission permission : data) {
|
||||
map.put(permission.getSlug(), true);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
19
src/main/resources/mapper/AdminPermissionMapper.xml
Normal file
19
src/main/resources/mapper/AdminPermissionMapper.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="xyz.playedu.api.mapper.AdminPermissionMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.AdminPermission">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="type" column="type" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="slug" column="slug" jdbcType="VARCHAR"/>
|
||||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,type,name,
|
||||
slug,created_at
|
||||
</sql>
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user