|
|
@ -1,14 +1,24 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Data; |
|
|
|
using System.Data; |
|
|
|
|
|
|
|
using System.Diagnostics; |
|
|
|
using System.Linq.Expressions; |
|
|
|
using System.Linq.Expressions; |
|
|
|
|
|
|
|
using System.Reflection; |
|
|
|
using AgileObjects.AgileMapper; |
|
|
|
using AgileObjects.AgileMapper; |
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
|
|
|
|
using Microsoft.IdentityModel.Tokens; |
|
|
|
|
|
|
|
using MongoDB.Driver; |
|
|
|
|
|
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
|
|
|
|
|
|
|
using SharpCompress.Common; |
|
|
|
using SqlSugar; |
|
|
|
using SqlSugar; |
|
|
|
using Tiobon.Core.Common; |
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
|
|
|
using Tiobon.Core.Common.Extensions; |
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
|
|
|
|
using Tiobon.Core.Common.HttpContextUser; |
|
|
|
using Tiobon.Core.Common.UserManager; |
|
|
|
using Tiobon.Core.Common.UserManager; |
|
|
|
using Tiobon.Core.IRepository.Base; |
|
|
|
using Tiobon.Core.IRepository.Base; |
|
|
|
using Tiobon.Core.IServices.BASE; |
|
|
|
using Tiobon.Core.IServices.BASE; |
|
|
|
using Tiobon.Core.Model; |
|
|
|
using Tiobon.Core.Model; |
|
|
|
|
|
|
|
using Tiobon.Core.Repository.Base; |
|
|
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services.BASE |
|
|
|
namespace Tiobon.Core.Services.BASE |
|
|
|
{ |
|
|
|
{ |
|
|
@ -31,9 +41,10 @@ namespace Tiobon.Core.Services.BASE |
|
|
|
|
|
|
|
|
|
|
|
public ISqlSugarClient Db => BaseDal.Db; |
|
|
|
public ISqlSugarClient Db => BaseDal.Db; |
|
|
|
|
|
|
|
|
|
|
|
public async Task<TEntity> QueryById(object objId) |
|
|
|
public async Task<TEntityDto> QueryById(object objId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return await BaseDal.QueryById(objId); |
|
|
|
var data = await BaseDal.QueryById(objId); |
|
|
|
|
|
|
|
return Mapper.Map(data).ToANew<TEntityDto>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
@ -42,9 +53,10 @@ namespace Tiobon.Core.Services.BASE |
|
|
|
/// <param name="objId">id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件</param> |
|
|
|
/// <param name="objId">id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件</param> |
|
|
|
/// <param name="blnUseCache">是否使用缓存</param> |
|
|
|
/// <param name="blnUseCache">是否使用缓存</param> |
|
|
|
/// <returns>数据实体</returns> |
|
|
|
/// <returns>数据实体</returns> |
|
|
|
public async Task<TEntity> QueryById(object objId, bool blnUseCache = false) |
|
|
|
public async Task<TEntityDto> QueryById(object objId, bool blnUseCache = false) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return await BaseDal.QueryById(objId, blnUseCache); |
|
|
|
var data = await BaseDal.QueryById(objId, blnUseCache); |
|
|
|
|
|
|
|
return Mapper.Map(data).ToANew<TEntityDto>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
@ -52,9 +64,10 @@ namespace Tiobon.Core.Services.BASE |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="lstIds">id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件</param> |
|
|
|
/// <param name="lstIds">id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件</param> |
|
|
|
/// <returns>数据实体列表</returns> |
|
|
|
/// <returns>数据实体列表</returns> |
|
|
|
public async Task<List<TEntity>> QueryByIDs(object[] lstIds) |
|
|
|
public async Task<List<TEntityDto>> QueryByIDs(object[] lstIds) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return await BaseDal.QueryByIDs(lstIds); |
|
|
|
var data = await BaseDal.QueryByIDs(lstIds); |
|
|
|
|
|
|
|
return Mapper.Map(data).ToANew<List<TEntityDto>>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
@ -62,10 +75,22 @@ namespace Tiobon.Core.Services.BASE |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="entity">博文实体类</param> |
|
|
|
/// <param name="entity">博文实体类</param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<long> Add(TEntity entity) |
|
|
|
public async Task<long> Add(TInsertDto entity) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var userId = UserContext.Current.User_Id; |
|
|
|
var userId = UserContext.Current.User_Id; |
|
|
|
return await BaseDal.Add(entity); |
|
|
|
HttpRequest request = UserContext.Context.Request; |
|
|
|
|
|
|
|
var api = request.Path.ObjToString().TrimEnd('/').ToLower(); |
|
|
|
|
|
|
|
var ip = GetUserIp(UserContext.Context); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BasePoco ent = entity as BasePoco; |
|
|
|
|
|
|
|
if (ent.CreateBy != null) |
|
|
|
|
|
|
|
ent.CreateBy = userId; |
|
|
|
|
|
|
|
ent.CreateTime = DateTime.Now; |
|
|
|
|
|
|
|
ent.CreateIP = ip; |
|
|
|
|
|
|
|
ent.CreateProg = api; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var entity1 = Mapper.Map(entity).ToANew<TEntity>(); |
|
|
|
|
|
|
|
return await BaseDal.Add(entity1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
@ -73,9 +98,23 @@ namespace Tiobon.Core.Services.BASE |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="listEntity">实体集合</param> |
|
|
|
/// <param name="listEntity">实体集合</param> |
|
|
|
/// <returns>影响行数</returns> |
|
|
|
/// <returns>影响行数</returns> |
|
|
|
public async Task<List<long>> Add(List<TEntity> listEntity) |
|
|
|
public async Task<List<long>> Add(List<TInsertDto> listEntity) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return await BaseDal.Add(listEntity); |
|
|
|
var userId = UserContext.Current.User_Id; |
|
|
|
|
|
|
|
HttpRequest request = UserContext.Context.Request; |
|
|
|
|
|
|
|
var api = request.Path.ObjToString().TrimEnd('/').ToLower(); |
|
|
|
|
|
|
|
var ip = GetUserIp(UserContext.Context); |
|
|
|
|
|
|
|
listEntity.ForEach(entity => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
BasePoco ent = entity as BasePoco; |
|
|
|
|
|
|
|
if (ent.CreateBy != null) |
|
|
|
|
|
|
|
ent.CreateBy = userId; |
|
|
|
|
|
|
|
ent.CreateTime = DateTime.Now; |
|
|
|
|
|
|
|
ent.CreateIP = ip; |
|
|
|
|
|
|
|
ent.CreateProg = api; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
var list = Mapper.Map(listEntity).ToANew<List<TEntity>>(); |
|
|
|
|
|
|
|
return await BaseDal.Add(list); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
@ -83,8 +122,23 @@ namespace Tiobon.Core.Services.BASE |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="entity">博文实体类</param> |
|
|
|
/// <param name="entity">博文实体类</param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<bool> Update(TEntity entity) |
|
|
|
public async Task<bool> Update(long Id, TEditDto editModel) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
var userId = UserContext.Current.User_Id; |
|
|
|
|
|
|
|
HttpRequest request = UserContext.Context.Request; |
|
|
|
|
|
|
|
var api = request.Path.ObjToString().TrimEnd('/').ToLower(); |
|
|
|
|
|
|
|
var ip = GetUserIp(UserContext.Context); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (editModel == null || !await BaseDal.AnyAsync(Id)) |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var entity = await BaseDal.QueryById(Id); |
|
|
|
|
|
|
|
ConvertTEditDto2TEntity(editModel, entity); |
|
|
|
|
|
|
|
BasePoco ent = entity as BasePoco; |
|
|
|
|
|
|
|
ent.UpdateBy = userId; |
|
|
|
|
|
|
|
ent.UpdateTime = DateTime.Now; |
|
|
|
|
|
|
|
ent.UpdateIP = ip; |
|
|
|
|
|
|
|
ent.UpdateProg = api; |
|
|
|
return await BaseDal.Update(entity); |
|
|
|
return await BaseDal.Update(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// <summary> |
|
|
@ -92,13 +146,36 @@ namespace Tiobon.Core.Services.BASE |
|
|
|
/// </summary> |
|
|
|
/// </summary> |
|
|
|
/// <param name="entity">博文实体类</param> |
|
|
|
/// <param name="entity">博文实体类</param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
public async Task<bool> Update(List<TEntity> entity) |
|
|
|
public async Task<bool> Update(List<TEntity> listEntity) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return await BaseDal.Update(entity); |
|
|
|
var userId = UserContext.Current.User_Id; |
|
|
|
|
|
|
|
HttpRequest request = UserContext.Context.Request; |
|
|
|
|
|
|
|
var api = request.Path.ObjToString().TrimEnd('/').ToLower(); |
|
|
|
|
|
|
|
var ip = GetUserIp(UserContext.Context); |
|
|
|
|
|
|
|
listEntity.ForEach(entity => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
BasePoco ent = entity as BasePoco; |
|
|
|
|
|
|
|
if (ent.UpdateBy != null) |
|
|
|
|
|
|
|
ent.UpdateBy = userId; |
|
|
|
|
|
|
|
ent.UpdateTime = DateTime.Now; |
|
|
|
|
|
|
|
ent.UpdateIP = ip; |
|
|
|
|
|
|
|
ent.UpdateProg = api; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return await BaseDal.Update(listEntity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> Update(TEntity entity, string where) |
|
|
|
public async Task<bool> Update(TEntity entity, string where) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
var userId = UserContext.Current.User_Id; |
|
|
|
|
|
|
|
HttpRequest request = UserContext.Context.Request; |
|
|
|
|
|
|
|
var api = request.Path.ObjToString().TrimEnd('/').ToLower(); |
|
|
|
|
|
|
|
var ip = GetUserIp(UserContext.Context); |
|
|
|
|
|
|
|
BasePoco ent = entity as BasePoco; |
|
|
|
|
|
|
|
if (ent.UpdateBy != null) |
|
|
|
|
|
|
|
ent.UpdateBy = userId; |
|
|
|
|
|
|
|
ent.UpdateTime = DateTime.Now; |
|
|
|
|
|
|
|
ent.UpdateIP = ip; |
|
|
|
|
|
|
|
ent.UpdateProg = api; |
|
|
|
return await BaseDal.Update(entity, where); |
|
|
|
return await BaseDal.Update(entity, where); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -381,5 +458,76 @@ namespace Tiobon.Core.Services.BASE |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetUserIp(HttpContext context) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string realIP = null; |
|
|
|
|
|
|
|
string forwarded = null; |
|
|
|
|
|
|
|
string remoteIpAddress = context.Connection.RemoteIpAddress.ToString(); |
|
|
|
|
|
|
|
if (context.Request.Headers.ContainsKey("X-Real-IP")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
realIP = context.Request.Headers["X-Real-IP"].ToString(); |
|
|
|
|
|
|
|
if (realIP != remoteIpAddress) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
remoteIpAddress = realIP; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (context.Request.Headers.ContainsKey("X-Forwarded-For")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
forwarded = context.Request.Headers["X-Forwarded-For"].ToString(); |
|
|
|
|
|
|
|
if (forwarded != remoteIpAddress) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
remoteIpAddress = forwarded; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
remoteIpAddress = remoteIpAddress.Replace("::ffff:", null); |
|
|
|
|
|
|
|
return remoteIpAddress; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 辅助方法 |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 转换TEditDto2TEntity |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="pTargetObjSrc"></param> |
|
|
|
|
|
|
|
/// <param name="pTargetObjDest"></param> |
|
|
|
|
|
|
|
/// <returns></returns> |
|
|
|
|
|
|
|
protected void ConvertTEditDto2TEntity(TEditDto source, TEntity dest) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
foreach (PropertyInfo mItem in typeof(TEditDto).GetProperties()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (dest.HasField(mItem.Name)) |
|
|
|
|
|
|
|
dest.SetValueForField(mItem.Name, mItem.GetValue(source, null)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//dest.SetValueForField(DbConsts.ColunmName_LastModificationTime, DateTimeHelper.Now()); |
|
|
|
|
|
|
|
//if (_currentUserId != default) |
|
|
|
|
|
|
|
//{ |
|
|
|
|
|
|
|
// //dest.SetValueForField(DbConsts.ColunmName_LastModifierId, _currentUserId); |
|
|
|
|
|
|
|
// dest.SetValueForField(DbConsts.ColunmName_LastModifier, _currentUserName); |
|
|
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (_currentTenantId != null) |
|
|
|
|
|
|
|
//{ |
|
|
|
|
|
|
|
// dest.SetValueForField(DbConsts.ColunmName_TenantId, _currentTenantId); |
|
|
|
|
|
|
|
//} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 获取根据ID查询的条件 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="id"></param> |
|
|
|
|
|
|
|
/// <returns></returns> |
|
|
|
|
|
|
|
protected QueryFilter QueryFilterById(Guid id) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return new QueryFilter |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
PageIndex = 1, |
|
|
|
|
|
|
|
PageSize = 1, |
|
|
|
|
|
|
|
Sorting = string.Empty, |
|
|
|
|
|
|
|
Predicate = "Id=@0", |
|
|
|
|
|
|
|
PredicateValues = new object[] { id } |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |