forked from ddrilling/AsbCloudServer
rider recomendations
This commit is contained in:
parent
5752ad40b7
commit
6565957c34
@ -11,26 +11,26 @@ namespace AsbCloudDb
|
|||||||
{
|
{
|
||||||
public static class EFExtentions
|
public static class EFExtentions
|
||||||
{
|
{
|
||||||
static Dictionary<Type, IQueryStringFactory> QueryFactories { get; set; } = new Dictionary<Type, IQueryStringFactory>();
|
static Dictionary<Type, IQueryStringFactory> QueryFactories { get; set; } = new();
|
||||||
|
|
||||||
static QueryStringFactory<T> GetQueryStringFactory<T>(DbSet<T> dbset)
|
static QueryStringFactory<T> GetQueryStringFactory<T>(DbSet<T> dbSet)
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
var t = typeof(T);
|
var t = typeof(T);
|
||||||
QueryStringFactory<T> factory = (QueryStringFactory<T>)QueryFactories.GetValueOrDefault(t);
|
var factory = (QueryStringFactory<T>)QueryFactories.GetValueOrDefault(t);
|
||||||
if (factory is null)
|
if (factory is null)
|
||||||
{
|
{
|
||||||
factory = new QueryStringFactory<T>(dbset);
|
factory = new QueryStringFactory<T>(dbSet);
|
||||||
QueryFactories.Add(t, factory);
|
QueryFactories.Add(t, factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
return factory;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<int> ExecInsertOrUpdateAsync<T>(this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade database, DbSet<T> dbset, IEnumerable<T> items, CancellationToken token)
|
public static Task<int> ExecInsertOrUpdateAsync<T>(this Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade database, DbSet<T> dbSet, IEnumerable<T> items, CancellationToken token)
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
var factory = GetQueryStringFactory(dbset);
|
var factory = GetQueryStringFactory(dbSet);
|
||||||
var query = factory.MakeInsertOrUpdateSql(items);
|
var query = factory.MakeInsertOrUpdateSql(items);
|
||||||
|
|
||||||
return database.ExecuteSqlRawAsync(query, token);
|
return database.ExecuteSqlRawAsync(query, token);
|
||||||
@ -45,19 +45,18 @@ namespace AsbCloudDb
|
|||||||
private readonly string insertHeader;
|
private readonly string insertHeader;
|
||||||
|
|
||||||
private readonly string pk;
|
private readonly string pk;
|
||||||
private readonly string tableName;
|
|
||||||
private readonly string conflictBody;
|
private readonly string conflictBody;
|
||||||
private readonly IEnumerable<IClrPropertyGetter> getters;
|
private readonly IEnumerable<IClrPropertyGetter> getters;
|
||||||
|
|
||||||
public QueryStringFactory(DbSet<T> dbset)
|
public QueryStringFactory(DbSet<T> dbset)
|
||||||
{
|
{
|
||||||
var ps = dbset.EntityType.GetProperties();
|
var properties = dbset.EntityType.GetProperties();
|
||||||
var pkColsNames = dbset.EntityType.FindPrimaryKey()?.Properties.Select(p => p.GetColumnBaseName());
|
var pkColsNames = dbset.EntityType.FindPrimaryKey()?.Properties.Select(p => p.GetColumnBaseName());
|
||||||
pk = pkColsNames is null ? string.Empty : $"({string.Join(", ", pkColsNames)})";
|
pk = pkColsNames is null ? string.Empty : $"({string.Join(", ", pkColsNames)})";
|
||||||
|
|
||||||
tableName = dbset.EntityType.GetTableName();
|
var tableName = dbset.EntityType.GetTableName();
|
||||||
getters = ps.Select(p => p.GetGetter());
|
getters = properties.Select(p => p.GetGetter());
|
||||||
var colNames = ps.Select(p => $"\"{p.GetColumnBaseName()}\"");
|
var colNames = properties.Select(p => $"\"{p.GetColumnBaseName()}\"");
|
||||||
var colunmsString = $"({string.Join(", ", colNames)})";
|
var colunmsString = $"({string.Join(", ", colNames)})";
|
||||||
|
|
||||||
insertHeader = $"INSERT INTO {tableName} {colunmsString} VALUES ";
|
insertHeader = $"INSERT INTO {tableName} {colunmsString} VALUES ";
|
||||||
@ -87,7 +86,7 @@ namespace AsbCloudDb
|
|||||||
private StringBuilder BuildRows(StringBuilder builder, IEnumerable<T> items)
|
private StringBuilder BuildRows(StringBuilder builder, IEnumerable<T> items)
|
||||||
{
|
{
|
||||||
var list = items.ToList();
|
var list = items.ToList();
|
||||||
for (int i = 0; i < list.Count; i++)
|
for (var i = 0; i < list.Count; i++)
|
||||||
{
|
{
|
||||||
if(i > 0)
|
if(i > 0)
|
||||||
builder.Append(',');
|
builder.Append(',');
|
||||||
|
@ -16,16 +16,15 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
private const string sheetNamePlan = "План";
|
private const string sheetNamePlan = "План";
|
||||||
private const string sheetNameFact = "Факт";
|
private const string sheetNameFact = "Факт";
|
||||||
|
|
||||||
const int headerRowsCount = 1;
|
private const int headerRowsCount = 1;
|
||||||
|
private const int columnSection = 1;
|
||||||
const int columnSection = 1;
|
private const int columnCategory = 2;
|
||||||
const int columnCategory = 2;
|
private const int columnCategoryInfo = 3;
|
||||||
const int columnCategoryInfo = 3;
|
private const int columnDepthStart = 4;
|
||||||
const int columnDepthStart = 4;
|
private const int columnDepthEnd = 5;
|
||||||
const int columnDepthEnd = 5;
|
private const int columnDate = 6;
|
||||||
const int columnDate = 6;
|
private const int columnDuration = 7;
|
||||||
const int columnDuration = 7;
|
private const int columnComment = 8;
|
||||||
const int columnComment = 8;
|
|
||||||
|
|
||||||
private static readonly DateTime dateLimitMin = new DateTime(2001, 1, 1, 0, 0, 0);
|
private static readonly DateTime dateLimitMin = new DateTime(2001, 1, 1, 0, 0, 0);
|
||||||
private static readonly DateTime dateLimitMax = new DateTime(2099, 1, 1, 0, 0, 0);
|
private static readonly DateTime dateLimitMax = new DateTime(2099, 1, 1, 0, 0, 0);
|
||||||
@ -34,10 +33,20 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
|
|
||||||
private List<WellOperationCategory> categories = null;
|
private List<WellOperationCategory> categories = null;
|
||||||
public List<WellOperationCategory> Categories =>
|
public List<WellOperationCategory> Categories
|
||||||
categories ?? (categories = db.WellOperationCategories
|
{
|
||||||
.AsNoTracking()
|
get
|
||||||
.ToList());
|
{
|
||||||
|
if (categories is null)
|
||||||
|
{
|
||||||
|
categories = db.WellOperationCategories
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<WellSectionType> sections = null;
|
private List<WellSectionType> sections = null;
|
||||||
public List<WellSectionType> Sections
|
public List<WellSectionType> Sections
|
||||||
|
Loading…
Reference in New Issue
Block a user