diff --git a/Tiobon.Core.Api/Controllers/Base/BaseController.cs b/Tiobon.Core.Api/Controllers/Base/BaseController.cs index ca5da490..b8041ac7 100644 --- a/Tiobon.Core.Api/Controllers/Base/BaseController.cs +++ b/Tiobon.Core.Api/Controllers/Base/BaseController.cs @@ -1,5 +1,4 @@ using System.Reflection; -using SkyWalking.NetworkProtocol.V3; namespace Tiobon.Core.Controllers; @@ -80,8 +79,7 @@ public class BaseController /// - [HttpPost] - [Route("BulkInsert")] + [HttpPost, Route("BulkInsert")] public async Task>> BulkInsert([FromBody] List insertModels) { var data = Success>(null, "新增成功"); @@ -114,11 +112,10 @@ public class BaseController - /// 扣费记录 -- 批量更新数据 + /// 批量更新数据 /// /// - [HttpPut] - [Route("BulkUpdate")] + [HttpPut, Route("BulkUpdate")] public async Task BulkUpdate([FromBody] Dictionary editModels) { var data = Success("更新成功"); @@ -147,6 +144,21 @@ public class BaseController + /// 批量删除数据 + /// + /// 主键IDs + /// + [HttpDelete, Route("BulkDelete")] + public async Task BulkDelete([FromBody] long[] Ids) + { + var data = Success("删除成功"); + data.Success = Convert.ToBoolean(await InvokeServiceAsync("DeleteByIds1", [Ids])); + if (!data.Success) + return Failed("删除失败"); + return data; + } #endregion #endregion diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index 7c519fee..eff44bd1 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -116,7 +116,7 @@ - 扣费记录 -- 批量更新数据 + 批量更新数据 @@ -127,6 +127,13 @@ 主键ID + + + 批量删除数据 + + 主键IDs + + 博客管理 diff --git a/Tiobon.Core.IServices/BASE/IBaseServices.cs b/Tiobon.Core.IServices/BASE/IBaseServices.cs index c2552467..7068fe90 100644 --- a/Tiobon.Core.IServices/BASE/IBaseServices.cs +++ b/Tiobon.Core.IServices/BASE/IBaseServices.cs @@ -101,6 +101,7 @@ namespace Tiobon.Core.IServices.BASE Task Delete(TEntity model); Task DeleteByIds(object[] ids); + Task DeleteByIds1(long[] ids); Task Update(long Id, TEditDto model); Task Update(Dictionary editModels); diff --git a/Tiobon.Core.Model/Base/BasePoco.cs b/Tiobon.Core.Model/Base/BasePoco.cs index a190589f..6e7ead8d 100644 --- a/Tiobon.Core.Model/Base/BasePoco.cs +++ b/Tiobon.Core.Model/Base/BasePoco.cs @@ -44,25 +44,25 @@ namespace Tiobon.Core.Model /// /// 创建人 /// - [Display(Name = "创建人")] + [Display(Name = "创建人"), SugarColumn(IsOnlyIgnoreUpdate = true)] public int? CreateBy { get; set; } /// /// 创建时间 /// - [Display(Name = "创建时间")] + [Display(Name = "创建时间"), SugarColumn(IsOnlyIgnoreUpdate = true)] public DateTime? CreateTime { get; set; } /// /// 创建程序 /// - [Display(Name = "创建程序")] + [Display(Name = "创建程序"), SugarColumn(IsOnlyIgnoreUpdate = true)] public string CreateProg { get; set; } /// /// 创建IP /// - [Display(Name = "创建IP")] + [Display(Name = "创建IP"), SugarColumn(IsOnlyIgnoreUpdate = true)] public string CreateIP { get; set; } /// diff --git a/Tiobon.Core.Repository/BASE/BaseRepository.cs b/Tiobon.Core.Repository/BASE/BaseRepository.cs index 6d3b1452..3f02d129 100644 --- a/Tiobon.Core.Repository/BASE/BaseRepository.cs +++ b/Tiobon.Core.Repository/BASE/BaseRepository.cs @@ -201,12 +201,7 @@ namespace Tiobon.Core.Repository.Base return await _db.Updateable(operateAnonymousObjects).ExecuteCommandAsync() > 0; } - public async Task Update( - TEntity entity, - List lstColumns = null, - List lstIgnoreColumns = null, - string where = "" - ) + public async Task Update(TEntity entity, List lstColumns = null, List lstIgnoreColumns = null, string where = "") { IUpdateable up = _db.Updateable(entity); if (lstIgnoreColumns != null && lstIgnoreColumns.Count > 0) diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 3aeaa55d..a2b0bb8b 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using SqlSugar; using Tiobon.Core.Common; +using Tiobon.Core.Common.DB.Dapper.Extensions; using Tiobon.Core.Common.Extensions; using Tiobon.Core.Common.Helper; using Tiobon.Core.Common.UserManager; @@ -549,6 +550,11 @@ namespace Tiobon.Core.Services.BASE return await BaseDal.DeleteById(id); } + /// + /// 删除指定ID的数据 + /// + /// 主键ID + /// public async Task DeleteById1(object id) { var entity = await BaseDal.QueryById(id); @@ -566,6 +572,34 @@ namespace Tiobon.Core.Services.BASE { return await BaseDal.DeleteByIds(ids); } + /// + /// 删除指定ID集合的数据(批量删除) + /// + /// 主键ID集合 + /// + public async Task DeleteByIds1(long[] ids) + { + HttpRequest request = UserContext.Context.Request; + var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + var ip = GetUserIp(UserContext.Context); + + List entities = new List(); + foreach (var id in ids) + { + if (id == null || !BaseDal.Any(id)) + continue; + + var entity = await BaseDal.QueryById(id); + + BasePoco ent = entity as BasePoco; + ent.UpdateIP = ip; + ent.UpdateProg = api; + ent.IsEnable = 0; + entities.Add(entity); + } + + return await BaseDal.Update(entities); + } ///