|
@@ -0,0 +1,69 @@
|
|
|
+package com.zglc.fm.service;
|
|
|
+
|
|
|
+import com.zglc.fm.entity.RightsEntity;
|
|
|
+import io.swagger.models.HttpMethod;
|
|
|
+import io.swagger.models.Operation;
|
|
|
+import io.swagger.models.Swagger;
|
|
|
+import org.apache.commons.logging.Log;
|
|
|
+import org.apache.commons.logging.LogFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.ApplicationArguments;
|
|
|
+import org.springframework.boot.ApplicationRunner;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import springfox.documentation.service.Documentation;
|
|
|
+import springfox.documentation.spring.web.DocumentationCache;
|
|
|
+import springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class RightsRegitService implements ApplicationRunner {
|
|
|
+ private RightsService rightsService;
|
|
|
+ private DocumentationCache documentationCache;
|
|
|
+ private ServiceModelToSwagger2Mapper serviceModelToSwagger2Mapper;
|
|
|
+
|
|
|
+ private static Log log = LogFactory.getLog(RightsRegitService.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public RightsRegitService(RightsService rightsService, DocumentationCache documentationCache, ServiceModelToSwagger2Mapper serviceModelToSwagger2Mapper)
|
|
|
+ {
|
|
|
+ this.rightsService = rightsService;
|
|
|
+ this.documentationCache = documentationCache;
|
|
|
+ this.serviceModelToSwagger2Mapper = serviceModelToSwagger2Mapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(ApplicationArguments args) throws Exception {
|
|
|
+ String groupName = "default";
|
|
|
+ Map<String, String> result = new HashMap();
|
|
|
+ Documentation documentation = this.documentationCache.documentationByGroup(groupName);
|
|
|
+ if (documentation != null) {
|
|
|
+ Swagger swagger = this.serviceModelToSwagger2Mapper.mapDocumentation(documentation);
|
|
|
+ swagger.getPaths().forEach((s, path) -> {
|
|
|
+ Map<HttpMethod, Operation> operationMap = path.getOperationMap();
|
|
|
+ operationMap.forEach((httpMethod, operation) -> {
|
|
|
+ String var10000 = (String)result.put(s,operation.getTags().get(0)+ "," + operation.getSummary());
|
|
|
+ });
|
|
|
+ });
|
|
|
+ Iterator var13 = result.entrySet().iterator();
|
|
|
+
|
|
|
+ while(var13.hasNext()) {
|
|
|
+ Map.Entry<String, String> entry = (Map.Entry)var13.next();
|
|
|
+ String apiPath = (String)entry.getKey();
|
|
|
+ String apiSummary = (String)entry.getValue();
|
|
|
+ RightsEntity rightsEntity = (this.rightsService.getRightsByPath(apiPath));
|
|
|
+ if (rightsEntity == null) {
|
|
|
+ rightsEntity = new RightsEntity();
|
|
|
+ rightsEntity.setRightsPath(apiPath);
|
|
|
+ rightsEntity.setRightsName(apiSummary);
|
|
|
+ rightsEntity.setRemark(apiSummary);
|
|
|
+ rightsEntity.setId(-1);
|
|
|
+ rightsService.add(rightsEntity);
|
|
|
+ log.info("add rights :" + rightsEntity.getRightsPath()+","+rightsEntity.getRightsName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|