From 8b79ed7a09418d0d0c5d55418dce2241bb9e75d1 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Thu, 18 Apr 2024 11:29:27 +0800 Subject: [PATCH] =?UTF-8?q?Base=E6=96=B0=E5=A2=9E=20=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Base/BaseController.cs | 60 ++++++++++++------- Tiobon.Core.Api/Tiobon.Core.xml | 23 ++----- Tiobon.Core.Services/BASE/BaseServices.cs | 4 +- 3 files changed, 48 insertions(+), 39 deletions(-) diff --git a/Tiobon.Core.Api/Controllers/Base/BaseController.cs b/Tiobon.Core.Api/Controllers/Base/BaseController.cs index af2fbee5..624d5a24 100644 --- a/Tiobon.Core.Api/Controllers/Base/BaseController.cs +++ b/Tiobon.Core.Api/Controllers/Base/BaseController.cs @@ -74,6 +74,26 @@ public class BaseController + /// 批量新增数据 + /// + /// + [HttpPost] + [Route("BulkInsert")] + public async Task>> BulkInsert([FromBody] List insertModels) + { + var data = Success>(null, "新增成功"); + var ids = await InvokeServiceAsync("Add", [insertModels]) as List; + data.Success = ids.Any(); + if (data.Success) + data.Data = ids; + else + return Failed>("新增失败"); + + return data; + } + #endregion #region 更新 @@ -116,26 +136,26 @@ public class BaseController - /// 反射调用service方法 - /// - /// - /// - /// - [NonAction] - private object InvokeService(string methodName, object[] parameters) - { - return _service.GetType().GetMethod(methodName).Invoke(_service, parameters); - } - /// - /// 反射调用service方法 - /// - /// - /// 为要调用重载的方法参数类型:new Type[] { typeof(SaveDataModel) - /// - /// - [NonAction] - private object InvokeService(string methodName, Type[] types, object[] parameters) => _service.GetType().GetMethod(methodName, types).Invoke(_service, parameters); + ///// + ///// 反射调用service方法 + ///// + ///// + ///// + ///// + //[NonAction] + //private object InvokeService(string methodName, object[] parameters) + //{ + // return _service.GetType().GetMethod(methodName).Invoke(_service, parameters); + //} + ///// + ///// 反射调用service方法 + ///// + ///// + ///// 为要调用重载的方法参数类型:new Type[] { typeof(SaveDataModel) + ///// + ///// + //[NonAction] + //private object InvokeService(string methodName, Type[] types, object[] parameters) => _service.GetType().GetMethod(methodName, types).Invoke(_service, parameters); [NonAction] diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index 1af72fab..cc23c1d9 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -40,6 +40,12 @@ + + + 批量新增数据 + + + 更新数据 @@ -55,23 +61,6 @@ 主键ID - - - 反射调用service方法 - - - - - - - - 反射调用service方法 - - - 为要调用重载的方法参数类型:new Type[] { typeof(SaveDataModel) - - - 博客管理 diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 0890a64b..a4b8ed0a 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -433,13 +433,13 @@ namespace Tiobon.Core.Services.BASE HttpRequest request = UserContext.Context.Request; var api = request.Path.ObjToString().TrimEnd('/').ToLower(); var ip = GetUserIp(UserContext.Context); - listEntity.ForEach(entity => + var list = Mapper.Map(listEntity).ToANew>(); + list.ForEach(entity => { BasePoco ent = entity as BasePoco; ent.CreateIP = ip; ent.CreateProg = api; }); - var list = Mapper.Map(listEntity).ToANew>(); return await BaseDal.Add(list); }