From b6642220f47bc49e7f4610833f9922f628db2906 Mon Sep 17 00:00:00 2001 From: wxz Date: Thu, 30 Apr 2020 14:29:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=83=E9=99=90=EF=BC=9A=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E4=BA=86=E6=9D=83=E9=99=90=E5=88=9D=E5=A7=8B=E5=8C=96=E5=99=A8?= =?UTF-8?q?=EF=BC=8C=E9=A1=B9=E7=9B=AE=E5=90=AF=E5=8A=A8=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E8=AF=BB=E5=8F=96RequirePermissionEnum=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E7=B1=BB=EF=BC=8C=E5=B0=86=E6=96=B0=E5=A2=9E=E7=9A=84?= =?UTF-8?q?=E6=94=BE=E5=85=A5=E5=88=B0=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/config/PermissionInitializer.java | 30 ---------- epmet-gateway/pom.xml | 8 +-- .../epmet/config/PermissionInitializer.java | 60 +++++++++++++++++++ .../main/java/com/epmet/dao/OperationDao.java | 36 +++++++++++ .../com/epmet/entity/OperationEntity.java | 56 +++++++++++++++++ .../com/epmet/service/OperationService.java | 13 ++++ .../service/impl/OperationServiceImpl.java | 29 +++++++++ .../main/resources/mapper/OperationDao.xml | 25 ++++++++ 8 files changed, 223 insertions(+), 34 deletions(-) delete mode 100644 epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/PermissionInitializer.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/config/PermissionInitializer.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationDao.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/OperationEntity.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/OperationService.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationServiceImpl.java create mode 100644 epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationDao.xml diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/PermissionInitializer.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/PermissionInitializer.java deleted file mode 100644 index b2908f242a..0000000000 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/PermissionInitializer.java +++ /dev/null @@ -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 beanMap = applicationContext.getBeansWithAnnotation(RequirePermission.class); -// for (Map.Entry entry : beanMap.entrySet()) { -// System.out.println(entry); -// } -// -// } -// -// -//} diff --git a/epmet-gateway/pom.xml b/epmet-gateway/pom.xml index 81c41a50ad..63fa8d143f 100644 --- a/epmet-gateway/pom.xml +++ b/epmet-gateway/pom.xml @@ -126,8 +126,8 @@ lb://epmet-job-server - lb://epmet-user-server - + + http://127.0.0.1:8087 http://127.0.0.1:8088 @@ -141,8 +141,8 @@ lb://resi-guide-server - lb://gov-org-server - + + http://127.0.0.1:8092 lb://oper-access-server diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/config/PermissionInitializer.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/config/PermissionInitializer.java new file mode 100644 index 0000000000..a88f27c992 --- /dev/null +++ b/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 operationKeys = getExistsOperationKeys(); + + ArrayList 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 getExistsOperationKeys() { + List operationEntities = operationService.listAllOperations(); + if (!CollectionUtils.isEmpty(operationEntities)) { + return operationEntities.stream().map(ope -> ope.getOperationKey()).collect(Collectors.toSet()); + } + return new HashSet<>(); + } + + +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationDao.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/OperationDao.java new file mode 100644 index 0000000000..427d458215 --- /dev/null +++ b/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 + *

+ * 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. + *

+ * 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. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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 { + + List listAllOperationEntities(); +} \ No newline at end of file diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/OperationEntity.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/OperationEntity.java new file mode 100644 index 0000000000..e599d8c28f --- /dev/null +++ b/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 + *

+ * 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. + *

+ * 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. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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; + +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/OperationService.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/OperationService.java new file mode 100644 index 0000000000..26c9303bbe --- /dev/null +++ b/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 listAllOperations(); + + void createBatch(ArrayList operations2Create); +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/OperationServiceImpl.java new file mode 100644 index 0000000000..ff20e3d2da --- /dev/null +++ b/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 listAllOperations() { + return operationDao.listAllOperationEntities(); + } + + @Transactional + @Override + public void createBatch(ArrayList operations2Create) { + operations2Create.forEach(ope -> operationDao.insert(ope)); + } +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationDao.xml b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationDao.xml new file mode 100644 index 0000000000..18669ed246 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/OperationDao.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file