/// <summary> /// 逻辑删除 /// </summary> /// <param name="info">要删除的数据id</param> /// <param name="logonInfo">登录的用户信息</param> /// <returns></returns> public ResultView Delete(T info, TokenLogonInfo logonInfo) { if (info == null) { throw ApiException.EmptyData("无法找到要删除的数据"); } string id = info.Id.ToString(); _logger.LogTrace($"逻辑删除 ==> 类型为:[{typeof(T).FullName}]\t删除ID为:[{id}]"); try { // 判断对应数据是否可以删除. DeleteRemoveCheck(info); OnDeleteRemoveCheck?.Invoke(info, logonInfo); DeleteCheck(info); OnDeleteCheck?.Invoke(info, logonInfo); // 逻辑删除的前置操作 DeleteRemoving(info, logonInfo); Deleting(info, logonInfo); // 逻辑删除前置事件处理 OnDeleting?.Invoke(info, logonInfo); // 设置逻辑删除状态 info.UpdateDate = DateTime.Now; info.UpdaterId = logonInfo.Id; info.UpdaterName = logonInfo.Name; info.IsDelete = true; // 持久化数据 _Dal.UpdateObject(info); // 逻辑删除的后置处理 Deleted(info, logonInfo); DeleteRemoved(info, logonInfo); // 逻辑删除后置事件处理 OnDeleted?.Invoke(info, logonInfo); // 返回保存结果 return(ResultView.Success(id)); } catch (Exception ex) { _logger.LogError(ex, $"逻辑删除异常 ==> 类型为:[{typeof(T).FullName}]\t删除ID为:[{id}]\r\n删除对象:[{info.ToJson()}]"); throw; } }
private static string Delete <T>(Clause clause, Dictionary <string, object> parameters, ITicket ticket = null, bool triggerEvent = false) { if (clause is null) { throw new ArgumentNullException(nameof(clause)); } string sql = ticket is null ? ExtractSql <T>(ClauseType.Delete, clause) : _queriesCache.GetOrAdd(ticket.Id, q => ExtractSql <T>(ClauseType.Delete, clause)); if (!triggerEvent) { return(sql); } var eventArgs = new SqlEventArgs { Sql = sql, Parameters = parameters }; OnDeleting?.Invoke(ticket, eventArgs); return(sql); }