Browse Source

权限:新增了权限初始化器,项目启动的时候读取RequirePermissionEnum枚举类,将新增的放入到数据库

dev_shibei_match
wxz 5 years ago
parent
commit
b6642220f4
  1. 30
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/PermissionInitializer.java
  2. 8
      epmet-gateway/pom.xml
  3. 60
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/config/PermissionInitializer.java
  4. 36
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationDao.java
  5. 56
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/OperationEntity.java
  6. 13
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/OperationService.java
  7. 29
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationServiceImpl.java
  8. 25
      epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationDao.xml

30
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/PermissionInitializer.java

@ -1,30 +0,0 @@
//package com.epmet.commons.tools.config;
//
//import com.epmet.commons.tools.annotation.RequirePermission;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.annotation.Configuration;
//
//import javax.annotation.PostConstruct;
//import java.util.Map;
//
//@Configuration
//public class PermissionInitializer {
//
// @Autowired
// private ApplicationContext applicationContext;
//
// /**
// * 初始化操作权限
// */
// @PostConstruct
// public void initOpePermissions() {
// Map<String, Object> beanMap = applicationContext.getBeansWithAnnotation(RequirePermission.class);
// for (Map.Entry<String, Object> entry : beanMap.entrySet()) {
// System.out.println(entry);
// }
//
// }
//
//
//}

8
epmet-gateway/pom.xml

@ -126,8 +126,8 @@
<gateway.routes.epmet-job-server.uri>lb://epmet-job-server</gateway.routes.epmet-job-server.uri> <gateway.routes.epmet-job-server.uri>lb://epmet-job-server</gateway.routes.epmet-job-server.uri>
<!-- <gateway.routes.epmet-job-server.uri>http://127.0.0.1:8084</gateway.routes.epmet-job-server.uri>--> <!-- <gateway.routes.epmet-job-server.uri>http://127.0.0.1:8084</gateway.routes.epmet-job-server.uri>-->
<!-- 8、用户模块 --> <!-- 8、用户模块 -->
<gateway.routes.epmet-user-server.uri>lb://epmet-user-server</gateway.routes.epmet-user-server.uri> <!-- <gateway.routes.epmet-user-server.uri>lb://epmet-user-server</gateway.routes.epmet-user-server.uri>-->
<!-- <gateway.routes.epmet-user-server.uri>http://127.0.0.1:8087</gateway.routes.epmet-user-server.uri>--> <gateway.routes.epmet-user-server.uri>http://127.0.0.1:8087</gateway.routes.epmet-user-server.uri>
<!-- 9、新模块结构demo --> <!-- 9、新模块结构demo -->
<!-- <gateway.routes.epmet-demo-server.uri>lb://epmet-demo-server</gateway.routes.epmet-demo-server.uri>--> <!-- <gateway.routes.epmet-demo-server.uri>lb://epmet-demo-server</gateway.routes.epmet-demo-server.uri>-->
<gateway.routes.epmet-demo-server.uri>http://127.0.0.1:8088</gateway.routes.epmet-demo-server.uri> <gateway.routes.epmet-demo-server.uri>http://127.0.0.1:8088</gateway.routes.epmet-demo-server.uri>
@ -141,8 +141,8 @@
<gateway.routes.resi-guide-server.uri>lb://resi-guide-server</gateway.routes.resi-guide-server.uri> <gateway.routes.resi-guide-server.uri>lb://resi-guide-server</gateway.routes.resi-guide-server.uri>
<!-- <gateway.routes.resi-guide-server.uri>http://127.0.0.1:8091</gateway.routes.resi-guide-server.uri>--> <!-- <gateway.routes.resi-guide-server.uri>http://127.0.0.1:8091</gateway.routes.resi-guide-server.uri>-->
<!-- 13、政府组织管理 --> <!-- 13、政府组织管理 -->
<gateway.routes.gov-org-server.uri>lb://gov-org-server</gateway.routes.gov-org-server.uri> <!--<gateway.routes.gov-org-server.uri>lb://gov-org-server</gateway.routes.gov-org-server.uri>-->
<!-- <gateway.routes.gov-org-server.uri>http://127.0.0.1:8092</gateway.routes.gov-org-server.uri>--> <gateway.routes.gov-org-server.uri>http://127.0.0.1:8092</gateway.routes.gov-org-server.uri>
<!-- 14、#运营端访问权限控制 --> <!-- 14、#运营端访问权限控制 -->
<gateway.routes.oper-access-server.uri>lb://oper-access-server</gateway.routes.oper-access-server.uri> <gateway.routes.oper-access-server.uri>lb://oper-access-server</gateway.routes.oper-access-server.uri>
<!-- <gateway.routes.oper-access-server.uri>http://127.0.0.1:8093</gateway.routes.oper-access-server.uri>--> <!-- <gateway.routes.oper-access-server.uri>http://127.0.0.1:8093</gateway.routes.oper-access-server.uri>-->

60
epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/config/PermissionInitializer.java

@ -0,0 +1,60 @@
package com.epmet.config;
import com.epmet.commons.tools.enums.RequirePermissionEnum;
import com.epmet.entity.OperationEntity;
import com.epmet.service.OperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils;
import javax.annotation.PostConstruct;
import java.util.*;
import java.util.stream.Collectors;
@Configuration
public class PermissionInitializer {
@Autowired
private OperationService operationService;
/**
* 初始化操作权限
*/
@PostConstruct
public void initOpePermissions() {
Set<String> operationKeys = getExistsOperationKeys();
ArrayList<OperationEntity> operations2Create = new ArrayList<>();
RequirePermissionEnum[] requirePermissionEnums = RequirePermissionEnum.values();
Arrays.stream(requirePermissionEnums).forEach(perm -> {
String key = perm.getKey();
if (!operationKeys.contains(key)) {
OperationEntity operationEntity = new OperationEntity();
operationEntity.setOperationKey(key);
operationEntity.setBrief(perm.getBrief());
operationEntity.setOperationName(perm.getName());
operations2Create.add(operationEntity);
}
});
if (!CollectionUtils.isEmpty(operations2Create)) {
operationService.createBatch(operations2Create);
}
}
/**
* 获取现有的操作key列表
* @return
*/
public Set<String> getExistsOperationKeys() {
List<OperationEntity> operationEntities = operationService.listAllOperations();
if (!CollectionUtils.isEmpty(operationEntities)) {
return operationEntities.stream().map(ope -> ope.getOperationKey()).collect(Collectors.toSet());
}
return new HashSet<>();
}
}

36
epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationDao.java

@ -0,0 +1,36 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.dao;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.entity.OperationEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 操作类型表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-04-30
*/
@Mapper
public interface OperationDao extends BaseDao<OperationEntity> {
List<OperationEntity> listAllOperationEntities();
}

56
epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/OperationEntity.java

@ -0,0 +1,56 @@
/**
* Copyright 2018 人人开源 https://www.renren.io
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.epmet.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.epmet.commons.mybatis.entity.BaseEpmetEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 操作类型表
*
* @author generator generator@elink-cn.com
* @since v1.0.0 2020-04-30
*/
@Data
@EqualsAndHashCode(callSuper=false)
@TableName("operation")
public class OperationEntity extends BaseEpmetEntity {
private static final long serialVersionUID = 1L;
/**
*
*/
private String operationKey;
/**
*
*/
private String operationName;
/**
* 操作简介
*/
private String brief;
}

13
epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/OperationService.java

@ -0,0 +1,13 @@
package com.epmet.service;
import com.epmet.entity.OperationEntity;
import java.util.ArrayList;
import java.util.List;
public interface OperationService {
List<OperationEntity> listAllOperations();
void createBatch(ArrayList<OperationEntity> operations2Create);
}

29
epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationServiceImpl.java

@ -0,0 +1,29 @@
package com.epmet.service.impl;
import com.epmet.dao.OperationDao;
import com.epmet.entity.OperationEntity;
import com.epmet.service.OperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service
public class OperationServiceImpl implements OperationService {
@Autowired
private OperationDao operationDao;
@Override
public List<OperationEntity> listAllOperations() {
return operationDao.listAllOperationEntities();
}
@Transactional
@Override
public void createBatch(ArrayList<OperationEntity> operations2Create) {
operations2Create.forEach(ope -> operationDao.insert(ope));
}
}

25
epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationDao.xml

@ -0,0 +1,25 @@
<?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="com.epmet.dao.OperationDao">
<resultMap type="com.epmet.entity.OperationEntity" id="operationMap">
<result property="id" column="ID"/>
<result property="operationKey" column="OPERATION_KEY"/>
<result property="operationName" column="OPERATION_NAME"/>
<result property="brief" column="BRIEF"/>
<result property="delFlag" column="DEL_FLAG"/>
<result property="revision" column="REVISION"/>
<result property="createdBy" column="CREATED_BY"/>
<result property="createdTime" column="CREATED_TIME"/>
<result property="updatedBy" column="UPDATED_BY"/>
<result property="updatedTime" column="UPDATED_TIME"/>
</resultMap>
<select id="listAllOperationEntities" resultType="com.epmet.entity.OperationEntity">
SELECT o.*
FROM operation o
</select>
</mapper>
Loading…
Cancel
Save