Parcourir la source

生成api文档

lichunlei il y a 7 mois
Parent
commit
d5679ee541

+ 6 - 3
Controllers/Admin/ApiGroupController.cs

@@ -7,6 +7,7 @@ using Vo.Admin;
 using Dto.Admin;
 using Dto.Admin;
 using Mapster;
 using Mapster;
 using Infrastructure;
 using Infrastructure;
+using Util;
 
 
 
 
 namespace Controllers.Admin
 namespace Controllers.Admin
@@ -22,12 +23,12 @@ namespace Controllers.Admin
         /// api分组接口
         /// api分组接口
         /// </summary>
         /// </summary>
         private readonly IApiGroupService _ApiGroupService;
         private readonly IApiGroupService _ApiGroupService;
+        private readonly IApiInfoService _ApiInfoService;
 
 
-
-        public ApiGroupController(IApiGroupService ApiGroupService)
+        public ApiGroupController(IApiGroupService ApiGroupService, IApiInfoService ApiInfoService)
         {
         {
             _ApiGroupService = ApiGroupService;
             _ApiGroupService = ApiGroupService;
-
+            _ApiInfoService = ApiInfoService;
         }
         }
 
 
           /// <param name="page">分页参数</param>
           /// <param name="page">分页参数</param>
@@ -113,6 +114,8 @@ namespace Controllers.Admin
         [Route("/v1/omega_source/ApiGroup/makeApiDoc")]
         [Route("/v1/omega_source/ApiGroup/makeApiDoc")]
         public IActionResult makeApiDoc([FromBody] ApiGroup param)
         public IActionResult makeApiDoc([FromBody] ApiGroup param)
         {
         {
+            TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
+            _ApiGroupService.makeApiDoc(param.serviceId, loginUser);
             return SUCCESS("ok");
             return SUCCESS("ok");
         }
         }
 
 

+ 6 - 5
Feign/IProject.cs

@@ -1,4 +1,5 @@
 using Common;
 using Common;
+using Vo.Feign;
 
 
 namespace Feign
 namespace Feign
 {
 {
@@ -11,10 +12,10 @@ namespace Feign
         //     return Newtonsoft.Json.JsonConvert.DeserializeObject<List<PageForMiniProgramVo>>(content);
         //     return Newtonsoft.Json.JsonConvert.DeserializeObject<List<PageForMiniProgramVo>>(content);
         // }
         // }
 
 
-        // public static List<ModuleTreeVo> getProject()
-        // {
-        //     string content = Function.GetWebRequest(Utils.FeignUrl["ym_material"] + "/v1/pub/getBlockForModuleList");
-        //     return Newtonsoft.Json.JsonConvert.DeserializeObject<List<ModuleTreeVo>>(content);
-        // }
+        public static GetProjectServiceQueryVo getProject(int id)
+        {
+            string content = Function.GetWebRequest(Utils.FeignUrl["omega_project"] + "/v1/omega_project/ProjectService/getProjectServiceQuery?id=" + id);
+            return Newtonsoft.Json.JsonConvert.DeserializeObject<GetProjectServiceQueryVo>(content);
+        }
     }
     }
 }
 }

+ 7 - 0
Model/Database/ApiGroup.cs

@@ -73,6 +73,13 @@ namespace Model
         public string? groupName { get; set; }
         public string? groupName { get; set; }
 
 
 
 
+        /// <summary>
+        /// 分组标题
+        /// </summary>
+        [SugarColumn(ColumnDescription = "分组标题", Length = 50, ColumnName = "group_title")]
+        public string? groupTitle { get; set; }
+
+
         /// <summary>
         /// <summary>
         /// 应用端ID
         /// 应用端ID
         /// </summary>
         /// </summary>

+ 2 - 1
Model/Database/ApiInfo.cs

@@ -72,6 +72,8 @@ namespace Model
         /// </summary>
         /// </summary>
         [SugarColumn(ColumnDescription = "接口分组ID", ColumnName = "group_id")]
         [SugarColumn(ColumnDescription = "接口分组ID", ColumnName = "group_id")]
         public int groupId { get; set; }
         public int groupId { get; set; }
+        [SugarColumn(IsIgnore = true)]
+        public string groupName { get; set; }
 
 
 
 
         /// <summary>
         /// <summary>
@@ -130,7 +132,6 @@ namespace Model
         public List<ApiParamObject> apiParam { get; set; }
         public List<ApiParamObject> apiParam { get; set; }
 
 
 
 
-
     }
     }
 
 
     public class ApiParamObject
     public class ApiParamObject

+ 54 - 0
Model/Vo/Feign/GetProjectServiceQueryVo.cs

@@ -0,0 +1,54 @@
+using Newtonsoft.Json;
+
+namespace Vo.Feign
+{
+    /// <summary>
+    /// 详情
+    /// </summary>
+    public class GetProjectServiceQueryVo
+    {
+        /// <summary>
+        /// ID
+        /// </summary>
+        public int id { get; set; }
+
+
+        /// <summary>
+        /// 服务名称
+        /// </summary>
+        public string serviceName { get; set; }
+
+
+        /// <summary>
+        /// 服务标题
+        /// </summary>
+        public string serviceTitle { get; set; }
+
+
+        /// <summary>
+        /// 应用端
+        /// </summary>
+        public int appId { get; set; }
+
+
+        /// <summary>
+        /// 开发语言
+        /// </summary>
+        public string devLanguage { get; set; }
+
+
+        /// <summary>
+        /// 服务器
+        /// </summary>
+        public int[] serverList { get; set; }
+
+
+        /// <summary>
+        /// 数据库
+        /// </summary>
+        public int[] databaseList { get; set; }
+
+
+
+    }
+}

+ 2 - 0
Program.cs

@@ -131,5 +131,7 @@ ModelVoAdapt.Map(); //模型字段类型映射配置
 
 
 // RabbitMQClient.Instance.Conn("MakeSqlQueue");
 // RabbitMQClient.Instance.Conn("MakeSqlQueue");
 // MakeHelper.Instance.Start("MakeSqlCallBackQueue");
 // MakeHelper.Instance.Start("MakeSqlCallBackQueue");
+// RabbitMQClient.Instance.Conn("MakeApiDocQueue");
+// MakeHelper.Instance.Start("MakeApiDocCallBackQueue");
 
 
 app.Run();
 app.Run();

+ 31 - 4
Services/ApiGroupService.cs

@@ -5,6 +5,8 @@ using Repository;
 using Service;
 using Service;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc;
 using Vo.Admin;
 using Vo.Admin;
+using Common;
+using Custom;
 
 
 
 
 namespace Services
 namespace Services
@@ -15,6 +17,13 @@ namespace Services
     [AppService(ServiceType = typeof(IApiGroupService), ServiceLifetime = LifeTime.Transient)]
     [AppService(ServiceType = typeof(IApiGroupService), ServiceLifetime = LifeTime.Transient)]
     public class ApiGroupService : BaseService<ApiGroup>, IApiGroupService
     public class ApiGroupService : BaseService<ApiGroup>, IApiGroupService
     {
     {
+        private readonly IApiInfoService _ApiInfoService;
+
+        public ApiGroupService(IApiInfoService ApiInfoService)
+        {
+            _ApiInfoService = ApiInfoService;
+        }
+
         /// <summary>
         /// <summary>
         /// 接口分组-列表
         /// 接口分组-列表
         /// </summary>
         /// </summary>
@@ -40,13 +49,31 @@ namespace Services
         /// 生成api文档
         /// 生成api文档
         /// </summary>
         /// </summary>
         /// <param name="serviceId">服务id</param>
         /// <param name="serviceId">服务id</param>
-        public void makeApiDoc(int serviceId)
+        public void makeApiDoc(int serviceId, TokenModel loginUser)
         {
         {
-            var apiGroups =  GetList(m => m.serviceId == serviceId);
-            foreach (var group in apiGroups)
+            var service = Feign.IProject.getProject(serviceId);
+            var apiGroups = GetList(m => m.serviceId == serviceId);
+            var apiInfos = _ApiInfoService.GetList(m => m.serviceId == serviceId);
+            foreach(var apiInfo in apiInfos)
             {
             {
-                
+                apiInfo.groupName = apiGroups.FirstOrDefault(m => m.id == apiInfo.groupId).groupTitle;
             }
             }
+
+            MakeData makeData = new();
+            string requestId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(8);
+            makeData.requestId = requestId;
+            makeData.modePath = "ApiDoc/doc.json";
+            Dictionary<string, string> attach = new();
+            attach.Add("id", serviceId.ToString());
+            attach.Add("kind", "apidoc");
+            attach.Add("operator", loginUser.username);
+            makeData.attach = Newtonsoft.Json.JsonConvert.SerializeObject(attach);
+            makeData.data = new Dictionary<string, object>();
+            makeData.data.Add("serviceName", service.serviceName);
+            makeData.data.Add("serviceTitle", service.serviceTitle);
+            makeData.data.Add("apiGroup", apiGroups);
+            makeData.data.Add("apiInfo", apiInfos);
+            RabbitMQClient.Instance.Push("MakeApiDocQueue", Newtonsoft.Json.JsonConvert.SerializeObject(makeData));
         }
         }
 
 
         /// <summary>
         /// <summary>

+ 1 - 1
Services/IService/IApiGroupService.cs

@@ -21,7 +21,7 @@ namespace Services
         /// 生成api文档
         /// 生成api文档
         /// </summary>
         /// </summary>
         /// <param name="serviceId">服务id</param>
         /// <param name="serviceId">服务id</param>
-        Dictionary<string, object> makeApiDoc(int serviceId);
+        void makeApiDoc(int serviceId, TokenModel loginUser);
 
 
 
 
         /// <summary>
         /// <summary>