From 0f49212b8047575ef51e5a3d931748f3f0459ffc Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Mon, 10 Mar 2025 23:25:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=B9=E8=AE=AD=E8=AE=B0=E5=BD=95=E8=A2=AB?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=90=8E=E5=AF=B9=E5=BA=94=E7=9A=84=E8=80=83?= =?UTF-8?q?=E8=AF=95=E7=AE=A1=E7=90=86=E9=87=8C=E9=9D=A2=E4=B9=9F=E8=A6=81?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BA=BA=E5=91=98=E4=BF=A1=E6=81=AF=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E8=80=83=E8=AF=95=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs | 46 ++++++++++++++----- .../Ghre/Ghre_StudyRecordServices.cs | 41 +++++++++++++++-- 2 files changed, 72 insertions(+), 15 deletions(-) diff --git a/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs b/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs index a00cfc53..890b1bce 100644 --- a/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs +++ b/Tiobon.Core.Common/DB/Aop/SqlsugarAop.cs @@ -1,7 +1,9 @@ +using Microsoft.AspNetCore.Http; using Serilog; using SqlSugar; using StackExchange.Profiling; using Tiobon.Core.Common.LogHelper; +using Tiobon.Core.Common.UserManager; using Tiobon.Core.Model; using Tiobon.Core.Model.Models.RootTkey; using Tiobon.Core.Model.Tenants; @@ -113,25 +115,45 @@ public static class SqlSugarAop break; case DataFilterType.UpdateByObject: - var UpdateBy = getType.GetProperty("UpdateBy"); - var dyModifyTime = getType.GetProperty("UpdateTime"); - - if (App.User?.ID > 0 && UpdateBy != null) + if (entityInfo.PropertyName == "UpdateBy") { - try + var UpdateBy = getType.GetProperty("UpdateBy"); + if (App.User?.ID > 0 && UpdateBy != null) { - UpdateBy.SetValue(entityInfo.EntityValue, Convert.ToInt32(App.User.ID)); + try + { + UpdateBy.SetValue(entityInfo.EntityValue, Convert.ToInt32(App.User.ID)); - } - catch (Exception) - { - UpdateBy.SetValue(entityInfo.EntityValue, App.User.ID); + } + catch (Exception) + { + UpdateBy.SetValue(entityInfo.EntityValue, App.User.ID); + } } } + else if (entityInfo.PropertyName == "UpdateTime") + { + + var dyModifyTime = getType.GetProperty("UpdateTime"); + + if (dyModifyTime != null) + dyModifyTime.SetValue(entityInfo.EntityValue, DateTime.Now); + } + //else if (entityInfo.PropertyName == "UpdateTime") + //{ + + // HttpRequest request = UserContext.Context.Request; + // var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + //} + //else if (entityInfo.PropertyName == "UpdateTime") + //{ + + // var dyModifyTime = getType.GetProperty("UpdateTime"); - if (dyModifyTime != null) - dyModifyTime.SetValue(entityInfo.EntityValue, DateTime.Now); + // if (dyModifyTime != null) + // dyModifyTime.SetValue(entityInfo.EntityValue, DateTime.Now); + //} break; } } diff --git a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs index cd0596a1..8696a42c 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs @@ -1,5 +1,4 @@ -using MathNet.Numerics.Distributions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.Linq; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.SS.Util; @@ -1880,5 +1879,41 @@ ORDER BY {filter.orderBy}"; } - #endregion + #endregion + + #region 批量删除 + /// + /// 删除指定ID集合的数据(批量删除) + /// + /// 主键ID集合 + /// + public override async Task DeleteByIds1(long[] ids) + { + + var examRecords = await Db.Queryable() + .Where(it => it.StudyRecordId != null && ids.Contains(it.StudyRecordId.Value)) + .Select(x => new { x.Id, x.StaffId, x.ExamId }).ToListAsync(); + + var examIds = examRecords.Select(x => x.ExamId).ToList(); + var staffIds = examRecords.Select(x => x.StaffId).ToList(); + var examRecordIds = examRecords.Select(x => x.Id).ToList(); + + await Db.Updateable() + .SetColumns(it => new Ghre_ExamRecord() { IsEnable = 0 }, true) + .Where(it => examRecordIds.Contains(it.Id)) + .ExecuteCommandAsync(); + + await Db.Updateable() + .SetColumns(it => new Ghre_ExamStaff() { IsEnable = 0 }, true) + .Where(it => staffIds.Contains(it.StaffId) && it.StaffId != null && it.ExamId != null && examIds.Contains(it.ExamId)) + .ExecuteCommandAsync(); + + await Db.Updateable() + .SetColumns(it => new Ghre_StudyRecord() { IsEnable = 0 }, true) + .Where(it => ids.Contains(it.Id)) + .ExecuteCommandAsync(); + + return true; + } + #endregion } \ No newline at end of file