forked from rongchao/epmet-cloud-rizhao
8 changed files with 223 additions and 34 deletions
@ -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);
|
|
||||
// }
|
|
||||
//
|
|
||||
// }
|
|
||||
//
|
|
||||
//
|
|
||||
//}
|
|
@ -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<>(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -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(); |
||||
|
} |
@ -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; |
||||
|
|
||||
|
} |
@ -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); |
||||
|
} |
@ -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)); |
||||
|
} |
||||
|
} |
@ -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…
Reference in new issue