| 
						
						
							
								
							
						
						
					 | 
					@ -4,13 +4,11 @@ import com.epmet.commons.tools.enums.RequirePermissionEnum; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.entity.OperationEntity; | 
					 | 
					 | 
					import com.epmet.entity.OperationEntity; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.service.OperationService; | 
					 | 
					 | 
					import com.epmet.service.OperationService; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import org.springframework.beans.factory.annotation.Autowired; | 
					 | 
					 | 
					import org.springframework.beans.factory.annotation.Autowired; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import org.springframework.context.ApplicationContext; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import org.springframework.context.annotation.Configuration; | 
					 | 
					 | 
					import org.springframework.context.annotation.Configuration; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import org.springframework.util.CollectionUtils; | 
					 | 
					 | 
					import org.springframework.util.CollectionUtils; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import javax.annotation.PostConstruct; | 
					 | 
					 | 
					import javax.annotation.PostConstruct; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.util.*; | 
					 | 
					 | 
					import java.util.*; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.util.stream.Collectors; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					@Configuration | 
					 | 
					 | 
					@Configuration | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					public class PermissionInitializer { | 
					 | 
					 | 
					public class PermissionInitializer { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -23,38 +21,49 @@ public class PermissionInitializer { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					     */ | 
					 | 
					 | 
					     */ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    @PostConstruct | 
					 | 
					 | 
					    @PostConstruct | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    public void initOpePermissions() { | 
					 | 
					 | 
					    public void initOpePermissions() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        Set<String> operationKeys = getExistsOperationKeys(); | 
					 | 
					 | 
					        final Map<String, OperationEntity> existsOpesMap = new HashMap<>(); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        List<OperationEntity> allExistsOpeEntities = operationService.listAllOperations(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        allExistsOpeEntities.stream().forEach(ope -> existsOpesMap.put(ope.getOperationKey(), ope)); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        ArrayList<OperationEntity> operations2Create = new ArrayList<>(); | 
					 | 
					 | 
					        ArrayList<OperationEntity> operations2Create = new ArrayList<>(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        ArrayList<OperationEntity> operations2Update = new ArrayList<>(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        RequirePermissionEnum[] requirePermissionEnums = RequirePermissionEnum.values(); | 
					 | 
					 | 
					        // 1.收集需要添加的
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        Arrays.stream(requirePermissionEnums).forEach(perm -> { | 
					 | 
					 | 
					        List<RequirePermissionEnum> permEnums = Arrays.asList(RequirePermissionEnum.values()); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        for (RequirePermissionEnum perm : permEnums) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            String key = perm.getKey(); | 
					 | 
					 | 
					            String key = perm.getKey(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            if (!operationKeys.contains(key)) { | 
					 | 
					 | 
					            if (!existsOpesMap.containsKey(key)) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					                OperationEntity operationEntity = new OperationEntity(); | 
					 | 
					 | 
					                OperationEntity operationEntity = new OperationEntity(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                operationEntity.setOperationKey(key); | 
					 | 
					 | 
					                operationEntity.setOperationKey(key); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                operationEntity.setBrief(perm.getBrief()); | 
					 | 
					 | 
					                operationEntity.setBrief(perm.getBrief()); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                operationEntity.setOperationName(perm.getName()); | 
					 | 
					 | 
					                operationEntity.setOperationName(perm.getName()); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                operations2Create.add(operationEntity); | 
					 | 
					 | 
					                operations2Create.add(operationEntity); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        }); | 
					 | 
					 | 
					        } | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        //2.收集需要修改的
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        for (RequirePermissionEnum perm : permEnums) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            String key = perm.getKey(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            String name = perm.getName(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            String brief = perm.getBrief(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            if (existsOpesMap.containsKey(key)) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                OperationEntity ope = existsOpesMap.get(key); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                if (!ope.getOperationName().equals(name) || !ope.getBrief().equals(brief)) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    // name或者brief发生过变化的,需要更新
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    ope.setBrief(brief); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    ope.setOperationName(name); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    operations2Update.add(ope); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        //3.批量添加和修改
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        if (!CollectionUtils.isEmpty(operations2Create)) { | 
					 | 
					 | 
					        if (!CollectionUtils.isEmpty(operations2Create)) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            operationService.createBatch(operations2Create); | 
					 | 
					 | 
					            operationService.createBatch(operations2Create); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    /** | 
					 | 
					 | 
					        if (!CollectionUtils.isEmpty(operations2Update)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					     * 获取现有的操作key列表 | 
					 | 
					 | 
					            operationService.updateBatch(operations2Update); | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					     * @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<>(); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					} | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
					 | 
					
  |