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); }