爆肝,重构框架,你懂得

This commit is contained in:
chenchun
2023-01-01 23:06:11 +08:00
parent dbe020dc94
commit b9384afd5d
276 changed files with 5205 additions and 3281 deletions

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Model.Base
{
public class Entity<Key> : IEntity<Key>
{
public Key Id { get; set; }
public object[] GetKeys()
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Model.Base
{
[Serializable]
public abstract class EntityDto<TKey> : EntityDto, IEntityDto<TKey>, IEntityDto
{
//
// 摘要:
// Id of the entity.
public TKey Id { get; set; }
public override string ToString()
{
return $"[DTO: {GetType().Name}] Id = {Id}";
}
}
[Serializable]
public abstract class EntityDto : IEntityDto
{
public override string ToString()
{
return "[DTO: " + GetType().Name + "]";
}
}
}

View File

@@ -0,0 +1,23 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Model.Base
{
public interface IBaseModelEntity
{
public long Id { get; set; }
public long? CreateUser { get; set; }
public long? ModifyUser { get; set; }
public DateTime? CreateTime { get; set; }
public DateTime? ModifyTime { get; set; }
public bool? IsDeleted { get; set; }
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Model.Base
{
/// <summary>
/// Defines an entity. It's primary key may not be "Id" or it may have a composite primary key.
/// Use <see cref="IEntity{TKey}"/> where possible for better integration to repositories and other structures in the framework.
/// </summary>
public interface IEntity
{
/// <summary>
/// Returns an array of ordered keys for this entity.
/// </summary>
/// <returns></returns>
object[] GetKeys();
}
/// <summary>
/// Defines an entity with a single primary key with "Id" property.
/// </summary>
/// <typeparam name="TKey">Type of the primary key of the entity</typeparam>
public interface IEntity<TKey> : IEntity
{
/// <summary>
/// Unique identifier for this entity.
/// </summary>
TKey Id { get; }
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Model.Base
{
public interface IEntityDto
{
}
public interface IEntityDto<TKey> : IEntityDto
{
TKey Id { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Model.Base
{
public interface IMultiTenant
{
Guid? TenantId { get; }
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Model.Base.Query
{
public class QueryPageCondition
{
public int Index { get; set; }
public int Size { get; set; }
public List<QueryParameter> Parameters { get; set; } = new List<QueryParameter>();
public List<string> OrderBys { get; set; } = new List<string>();
public bool IsAsc { get; set; } = false;
}
public class QueryCondition
{
public List<QueryParameter> Parameters { get; set; } = new List<QueryParameter>();
public List<string> OrderBys { get; set; } = new List<string>();
public bool IsAsc { get; set; } = false;
}
}

View File

@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Model.Base.Query
{
public class QueryParameter
{
public string Key { get; set; }
public string Value { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
public ConditionalType Type { get; set; } = ConditionalType.Like;
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Model.Base.Query
{
public static class QueryParametersExtensions
{
//public static QueryParameters SetParameters(this QueryParameters queryParameters, Dictionary<string, string> dic, bool IsTenant = true)
//{
// //var httpcontext = ServiceLocator.Instance.GetService<IHttpContextAccessor>().HttpContext;
// queryParameters.OrderBys = new List<string> { "CreateTime" };
// foreach (var p in dic)
// {
// QueryParameter qp = null;
// if (p.Key == "IsDeleted" || p.Key == "Id")
// {
// qp = new QueryParameter() { FieldName = p.Key, FieldValue = p.Value, ConditionalType = ConditionalType.Equal };
// }
// else
// {
// qp = new QueryParameter() { FieldName = p.Key, FieldValue = p.Value };
// }
// queryParameters.Parameters.Add(qp);
// }
// if (IsTenant)
// {
// //if (httpcontext.Request.Headers["TenantLevel"].ToString() == "0")
// //{
// // queryParameters.Parameters.Add(new QueryParameter() { ConditionalType = ConditionalType.Equal, FieldName = "TenantId", FieldValue = httpcontext.Request.Headers["TenantId"].ToString() });
// //}
// }
// return queryParameters;
//}
}
}