Explorar o código

添加接口控制器接口

lichunlei hai 5 meses
pai
achega
62a2cfabe9

+ 107 - 0
Controllers/Admin/ApiControllerController.cs

@@ -0,0 +1,107 @@
+using Vo;
+using Microsoft.AspNetCore.Mvc;
+using Model;
+using Services;
+using Model.Base;
+using Vo.Admin;
+using Mapster;
+using Infrastructure;
+
+
+namespace Controllers.Admin
+{
+    /// <summary>
+    /// ApiController)Controller
+    /// </summary>
+    // [Route("${Router}$")]
+    // [ApiExplorerSettings(GroupName = "ApiController")]
+    public class ApiControllerController : BaseController
+    {
+        /// <summary>
+        /// api分组接口
+        /// </summary>
+        private readonly IApiControllerService _ApiControllerService;
+
+
+        public ApiControllerController(IApiControllerService ApiControllerService)
+        {
+            _ApiControllerService = ApiControllerService;
+
+        }
+
+        /// <summary>
+        /// 列表
+        /// </summary>
+        /// <param name="page">分页对象</param>
+        /// <returns>列表</returns>
+        [HttpGet]
+        [Route("/v1/omega_source/ApiController/getApiControllerList")]
+        public IActionResult getApiControllerList([FromQuery] ApiController param)
+        {
+            var response = _ApiControllerService.GetList(m => m.serviceId == param.serviceId).Adapt<List<GetApiControllerListVo>>();
+            return SUCCESS(response);
+        }
+
+
+        /// <summary>
+        /// 详情
+        /// </summary>
+        /// <param name="param">参数请求体</param>
+        /// <returns>详情</returns>
+        [HttpGet]
+        [Route("/v1/omega_source/ApiController/getApiControllerQuery")]
+        public IActionResult getApiControllerQuery([FromQuery] ApiController param)
+        {
+            var response = _ApiControllerService.GetFirst(m => m.id == param.id).Adapt<GetApiControllerQueryVo>();
+            return SUCCESS(response);
+        }
+
+
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <param name="param">参数请求体</param>
+        /// <returns>添加</returns>
+        [HttpPost]
+        [Route("/v1/omega_source/ApiController/addApiController")]
+        public IActionResult addApiController([FromBody] ApiController param)
+        {
+            var modal = param.Adapt<ApiController>().ToCreate(HttpContext);
+            var response = _ApiControllerService.InsertReturnIdentity(modal);
+            return SUCCESS(response);
+        }
+
+
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="param">参数请求体</param>
+        /// <returns>修改</returns>
+        [HttpPut]
+        [Route("/v1/omega_source/ApiController/updateApiController")]
+        public IActionResult updateApiController([FromBody] ApiController param)
+        {
+            var modal = param.Adapt<ApiController>().ToCreate(HttpContext);
+            var response = _ApiControllerService.Update(modal, true);
+            return SUCCESS(response);
+        }
+
+
+        /// <summary>
+        /// 删除
+        /// </summary>
+        /// <param name="id">ID</param>
+        /// <returns>删除</returns>
+        [HttpDelete]
+        [Route("/v1/omega_source/ApiController/deleteApiController/{id}")]
+        public IActionResult deleteApiController(int id)
+        {
+            var response = _ApiControllerService.Delete(id);
+            return SUCCESS(response);
+        }
+
+
+
+
+    }
+}

+ 21 - 1
Controllers/Admin/ApiInfoController.cs

@@ -24,11 +24,13 @@ namespace Controllers.Admin
         /// </summary>
         private readonly IApiInfoService _ApiInfoService;
         private readonly IApiGroupService _ApiGroupService;
+        private readonly IApiControllerService _ApiControllerService;
 
-        public ApiInfoController(IApiInfoService ApiInfoService, IApiGroupService ApiGroupService)
+        public ApiInfoController(IApiInfoService ApiInfoService, IApiGroupService ApiGroupService, IApiControllerService ApiControllerService)
         {
             _ApiInfoService = ApiInfoService;
             _ApiGroupService = ApiGroupService;
+            _ApiControllerService = ApiControllerService;
         }
 
           /// <param name="page">分页参数</param>
@@ -85,6 +87,15 @@ namespace Controllers.Admin
         public IActionResult addApiInfo([FromBody] AddApiInfoDto param)
         {
             var modal = param.Adapt<ApiInfo>().ToCreate(HttpContext);
+            var check = _ApiControllerService.Any(m => m.controllerFilePath == param.controllerFilePath);
+            if(!check)
+            {
+                _ApiControllerService.Add(new ApiController()
+                {
+                    controllerFilePath = param.controllerFilePath,
+                    serviceId = param.serviceId
+                });
+            }
             var response = _ApiInfoService.InsertReturnIdentity(modal);
             return SUCCESS(response);
         }
@@ -100,6 +111,15 @@ namespace Controllers.Admin
         public IActionResult updateApiInfo([FromBody] AddApiInfoDto param)
         {
             var modal = param.Adapt<ApiInfo>().ToCreate(HttpContext);
+            var check = _ApiControllerService.Any(m => m.controllerFilePath == param.controllerFilePath);
+            if(!check)
+            {
+                _ApiControllerService.Add(new ApiController()
+                {
+                    controllerFilePath = param.controllerFilePath,
+                    serviceId = param.serviceId
+                });
+            }
             var response = _ApiInfoService.Update(modal, true);
             return SUCCESS(response);
         }

+ 78 - 0
Model/Database/ApiController.cs

@@ -0,0 +1,78 @@
+using Mapster;
+
+
+namespace Model
+{
+    /// <summary>
+    /// 接口控制器 api_controller
+    /// </summary>
+    [SugarTable("api_controller", "接口控制器")]
+    [Tenant("0")]
+    public class ApiController
+    {
+        /// <summary>
+        /// ID
+        /// </summary>
+        [SugarColumn(ColumnDescription = "ID", IsPrimaryKey = true, IsIdentity = true, ColumnName = "id")]
+        public int id { get; set; }
+
+
+        /// <summary>
+        /// 控制器文件路径
+        /// </summary>
+        [SugarColumn(ColumnDescription = "控制器文件路径", Length = 50, ColumnName = "controller_file_path")]
+        public string? controllerFilePath { get; set; }
+
+
+        /// <summary>
+        /// 服务ID
+        /// </summary>
+        [SugarColumn(ColumnDescription = "服务ID", ColumnName = "service_id")]
+        public int serviceId { get; set; }
+
+
+        /// <summary>
+        /// 更新人
+        /// </summary>
+        [SugarColumn(ColumnDescription = "更新人", Length = 32, ColumnName = "update_by")]
+        public string? updateBy { get; set; }
+
+
+        /// <summary>
+        /// 创建人
+        /// </summary>
+        [SugarColumn(ColumnDescription = "创建人", Length = 32, ColumnName = "create_by")]
+        public string? createBy { get; set; }
+
+
+        /// <summary>
+        /// 更新时间
+        /// </summary>
+        [SugarColumn(ColumnDescription = "更新时间", ColumnName = "update_time")]
+        public DateTime? updateTime { get; set; }
+
+
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        [SugarColumn(ColumnDescription = "创建时间", ColumnName = "create_time")]
+        public DateTime? createTime { get; set; }
+
+
+        /// <summary>
+        /// 删除标记
+        /// </summary>
+        [SugarColumn(ColumnDescription = "删除标记", ColumnName = "del_flag")]
+        public int delFlag { get; set; }
+
+
+        /// <summary>
+        /// 版本号
+        /// </summary>
+        [SugarColumn(ColumnDescription = "版本号", ColumnName = "version")]
+        public int version { get; set; }
+
+
+
+    }
+}

+ 8 - 0
Model/Database/ApiInfo.cs

@@ -125,6 +125,14 @@ namespace Model
                 return PublicFunction.transferName(methodName);
             }
         }
+        [SugarColumn(IsIgnore = true)]
+        public string? methodNameFirstUpper 
+        {
+            get
+            {
+                return PublicFunction.transferName(methodName, 1);
+            }
+        }
 
 
         /// <summary>

+ 30 - 0
Model/Vo/Admin/GetApiControllerListVo.cs

@@ -0,0 +1,30 @@
+using Newtonsoft.Json;
+
+namespace Vo.Admin
+{
+    /// <summary>
+    /// 列表
+    /// </summary>
+    public class GetApiControllerListVo
+    {
+        /// <summary>
+        /// ID
+        /// </summary>
+        public int id { get; set; }
+
+
+        /// <summary>
+        /// 控制器文件路径
+        /// </summary>
+        public string controllerFilePath { get; set; }
+
+
+        /// <summary>
+        /// 服务ID
+        /// </summary>
+        public int serviceId { get; set; }
+
+
+
+    }
+}

+ 30 - 0
Model/Vo/Admin/GetApiControllerQueryVo.cs

@@ -0,0 +1,30 @@
+using Newtonsoft.Json;
+
+namespace Vo.Admin
+{
+    /// <summary>
+    /// 详情
+    /// </summary>
+    public class GetApiControllerQueryVo
+    {
+        /// <summary>
+        /// ID
+        /// </summary>
+        public int id { get; set; }
+
+
+        /// <summary>
+        /// 控制器文件路径
+        /// </summary>
+        public string controllerFilePath { get; set; }
+
+
+        /// <summary>
+        /// 服务ID
+        /// </summary>
+        public int serviceId { get; set; }
+
+
+
+    }
+}

+ 19 - 0
Services/ApiControllerService.cs

@@ -0,0 +1,19 @@
+using Attribute;
+using Model;
+using Model.Base;
+using Repository;
+using Service;
+using Microsoft.AspNetCore.Mvc;
+using Vo.Admin;
+
+
+namespace Services
+{
+    /// <summary>
+    /// 接口控制器Service业务层处理
+    /// </summary>
+    [AppService(ServiceType = typeof(IApiControllerService), ServiceLifetime = LifeTime.Transient)]
+    public class ApiControllerService : BaseService<ApiController>, IApiControllerService
+    {
+    }
+}

+ 3 - 0
Services/DatabaseTableService.cs

@@ -285,6 +285,8 @@ namespace Services
         /// <returns>生成java代码-serviceImpl</returns>
         public void makeJavaServiceImpl(ProjectService baseInfo, DatabaseTable table, TokenModel loginUser)
         {
+            var apiInfos = _ApiInfoService.GetList(m => m.serviceId == baseInfo.id && m.linkTableId == table.id && m.apiKind == 1);
+
             MakeData makeData = new();
             string requestId = DateTime.Now.ToString("yyyyMMddHHmmssfff") + Function.get_Random(8);
             makeData.requestId = requestId;
@@ -299,6 +301,7 @@ namespace Services
             makeData.data.Add("author", loginUser.username);
             makeData.data.Add("projectService", baseInfo);
             makeData.data.Add("databaseTable", table);
+            makeData.data.Add("apiInfos", apiInfos);
             RabbitMQClient.Instance.Push("MakeSqlQueue", Newtonsoft.Json.JsonConvert.SerializeObject(makeData));
         }
 

+ 13 - 0
Services/IService/IApiControllerService.cs

@@ -0,0 +1,13 @@
+using Model;
+using Model.Base;
+using Microsoft.AspNetCore.Mvc;
+using Vo.Admin;
+
+
+namespace Services
+{
+    public interface IApiControllerService : IBaseService<ApiController>
+    {
+
+    }
+}