This commit is contained in:
@@ -132,7 +132,8 @@ namespace AyaNova.Biz
|
|||||||
[CoreBizObject]
|
[CoreBizObject]
|
||||||
PartAssembly = 65,
|
PartAssembly = 65,
|
||||||
[CoreBizObject]
|
[CoreBizObject]
|
||||||
PartWarehouse = 66
|
PartWarehouse = 66,
|
||||||
|
PartInventory = 67
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
183
server/AyaNova/biz/PartInventoryBiz.cs
Normal file
183
server/AyaNova/biz/PartInventoryBiz.cs
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Linq;
|
||||||
|
using AyaNova.Util;
|
||||||
|
using AyaNova.Api.ControllerHelpers;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using AyaNova.Models;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace AyaNova.Biz
|
||||||
|
{
|
||||||
|
internal class PartInventoryBiz : BizObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject
|
||||||
|
{
|
||||||
|
internal PartInventoryBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles)
|
||||||
|
{
|
||||||
|
ct = dbcontext;
|
||||||
|
UserId = currentUserId;
|
||||||
|
UserTranslationId = userTranslationId;
|
||||||
|
CurrentUserRoles = UserRoles;
|
||||||
|
BizType = AyaType.PartInventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static PartInventoryBiz GetBiz(AyContext ct, Microsoft.AspNetCore.Http.HttpContext httpContext = null)
|
||||||
|
{
|
||||||
|
if (httpContext != null)
|
||||||
|
return new PartInventoryBiz(ct, UserIdFromContext.Id(httpContext.Items), UserTranslationIdFromContext.Id(httpContext.Items), UserRolesFromContext.Roles(httpContext.Items));
|
||||||
|
else
|
||||||
|
return new PartInventoryBiz(ct, 1, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, AuthorizationRoles.BizAdminFull);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//EXISTS
|
||||||
|
internal async Task<bool> ExistsAsync(long id)
|
||||||
|
{
|
||||||
|
return await ct.PartInventory.AnyAsync(z => z.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//CREATE
|
||||||
|
//
|
||||||
|
internal async Task<PartInventory> CreateAsync(PartInventory newObject)
|
||||||
|
{
|
||||||
|
await ValidateAsync(newObject, null);
|
||||||
|
if (HasErrors)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
await ct.PartInventory.AddAsync(newObject);
|
||||||
|
await ct.SaveChangesAsync();
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||||
|
await SearchIndexAsync(newObject, true);
|
||||||
|
|
||||||
|
return newObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//GET
|
||||||
|
//
|
||||||
|
internal async Task<PartInventory> GetAsync(long id, bool logTheGetEvent = true)
|
||||||
|
{
|
||||||
|
var ret = await ct.PartInventory.AsNoTracking().SingleOrDefaultAsync(m => m.Id == id);
|
||||||
|
if (logTheGetEvent && ret != null)
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Retrieved), ct);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//SEARCH
|
||||||
|
//
|
||||||
|
private async Task SearchIndexAsync(PartInventory obj, bool isNew)
|
||||||
|
{
|
||||||
|
var SearchParams = new Search.SearchIndexProcessObjectParameters(UserTranslationId, obj.Id, BizType);
|
||||||
|
DigestSearchText(obj, SearchParams);
|
||||||
|
if (isNew)
|
||||||
|
await Search.ProcessNewObjectKeywordsAsync(SearchParams);
|
||||||
|
else
|
||||||
|
await Search.ProcessUpdatedObjectKeywordsAsync(SearchParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Search.SearchIndexProcessObjectParameters> GetSearchResultSummary(long id)
|
||||||
|
{
|
||||||
|
var obj = await GetAsync(id, false);
|
||||||
|
var SearchParams = new Search.SearchIndexProcessObjectParameters();
|
||||||
|
DigestSearchText(obj, SearchParams);
|
||||||
|
return SearchParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DigestSearchText(PartInventory obj, Search.SearchIndexProcessObjectParameters searchParams)
|
||||||
|
{
|
||||||
|
if (obj != null)
|
||||||
|
searchParams.AddText(obj.Description);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//VALIDATION
|
||||||
|
//
|
||||||
|
|
||||||
|
private async Task ValidateAsync(PartInventory proposedObj, PartInventory currentObj)
|
||||||
|
{
|
||||||
|
|
||||||
|
bool isNew = currentObj == null;
|
||||||
|
|
||||||
|
//Name required
|
||||||
|
if (string.IsNullOrWhiteSpace(proposedObj.Name))
|
||||||
|
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//If name is otherwise OK, check that name is unique
|
||||||
|
if (!PropertyHasErrors("Name"))
|
||||||
|
{
|
||||||
|
//Use Any command is efficient way to check existance, it doesn't return the record, just a true or false
|
||||||
|
if (await ct.PartInventory.AnyAsync(m => m.Name == proposedObj.Name && m.Id != proposedObj.Id))
|
||||||
|
{
|
||||||
|
AddError(ApiErrorCode.VALIDATION_NOT_UNIQUE, "Name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//REPORTING
|
||||||
|
//
|
||||||
|
public async Task<JArray> GetReportData(long[] idList)
|
||||||
|
{
|
||||||
|
JArray ReportData = new JArray();
|
||||||
|
while (idList.Any())
|
||||||
|
{
|
||||||
|
var batch = idList.Take(IReportAbleObject.REPORT_DATA_BATCH_SIZE);
|
||||||
|
idList = idList.Skip(IReportAbleObject.REPORT_DATA_BATCH_SIZE).ToArray();
|
||||||
|
//query for this batch, comes back in db natural order unfortunately
|
||||||
|
var batchResults = await ct.PartInventory.AsNoTracking().Where(z => batch.Contains(z.Id)).ToArrayAsync();
|
||||||
|
//order the results back into original
|
||||||
|
var orderedList = from id in batch join z in batchResults on id equals z.Id select z;
|
||||||
|
foreach (PartInventory w in orderedList)
|
||||||
|
{
|
||||||
|
var jo = JObject.FromObject(w);
|
||||||
|
if (!JsonUtil.JTokenIsNullOrEmpty(jo["CustomFields"]))
|
||||||
|
jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]);
|
||||||
|
ReportData.Add(jo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ReportData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// IMPORT EXPORT
|
||||||
|
//
|
||||||
|
public async Task<JArray> GetExportData(long[] idList)
|
||||||
|
{
|
||||||
|
//for now just re-use the report data code
|
||||||
|
//this may turn out to be the pattern for most biz object types but keeping it seperate allows for custom usage from time to time
|
||||||
|
return await GetReportData(idList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
}//eoc
|
||||||
|
|
||||||
|
|
||||||
|
}//eons
|
||||||
|
|
||||||
@@ -40,6 +40,7 @@ namespace AyaNova.Models
|
|||||||
public virtual DbSet<Notification> Notification { get; set; }
|
public virtual DbSet<Notification> Notification { get; set; }
|
||||||
public virtual DbSet<NotifyDeliveryLog> NotifyDeliveryLog { get; set; }
|
public virtual DbSet<NotifyDeliveryLog> NotifyDeliveryLog { get; set; }
|
||||||
public virtual DbSet<Part> Part { get; set; }
|
public virtual DbSet<Part> Part { get; set; }
|
||||||
|
public virtual DbSet<PartInventory> PartInventory { get; set; }
|
||||||
public virtual DbSet<PartWarehouse> PartWarehouse { get; set; }
|
public virtual DbSet<PartWarehouse> PartWarehouse { get; set; }
|
||||||
public virtual DbSet<PartSerial> PartSerial { get; set; }
|
public virtual DbSet<PartSerial> PartSerial { get; set; }
|
||||||
public virtual DbSet<PartAssembly> PartAssembly { get; set; }
|
public virtual DbSet<PartAssembly> PartAssembly { get; set; }
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ namespace AyaNova.Util
|
|||||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
|
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
|
||||||
private const int DESIRED_SCHEMA_LEVEL = 15;
|
private const int DESIRED_SCHEMA_LEVEL = 15;
|
||||||
|
|
||||||
internal const long EXPECTED_COLUMN_COUNT = 676;
|
internal const long EXPECTED_COLUMN_COUNT = 687;
|
||||||
internal const long EXPECTED_INDEX_COUNT = 119;
|
internal const long EXPECTED_INDEX_COUNT = 122;
|
||||||
|
|
||||||
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
|
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImporting WHEN NEW TABLES ADDED!!!!
|
||||||
|
|
||||||
@@ -687,10 +687,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
|||||||
// await ExecQueryAsync("CREATE INDEX idx_apartassemblyitem_partid ON apartassemblyitem(partid)");
|
// await ExecQueryAsync("CREATE INDEX idx_apartassemblyitem_partid ON apartassemblyitem(partid)");
|
||||||
// await ExecQueryAsync("CREATE INDEX idx_apartassemblyitem_partassemblyid ON apartassemblyitem(partassemblyid)");
|
// await ExecQueryAsync("CREATE INDEX idx_apartassemblyitem_partassemblyid ON apartassemblyitem(partassemblyid)");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//PART INVENTORY
|
//PART INVENTORY
|
||||||
|
|
||||||
await ExecQueryAsync("CREATE TABLE apartinventory (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, description text null, " +
|
await ExecQueryAsync("CREATE TABLE apartinventory (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, description text null, " +
|
||||||
"entrydate timestamp not null, lastentrydate timestamp null, partid bigint not null references apart, partwarehouseid bigint not null references apartwarehouse, " +
|
"entrydate timestamp not null, lastentrydate timestamp null, partid bigint not null references apart, partwarehouseid bigint not null references apartwarehouse, " +
|
||||||
"sourcetype integer not null, sourceid bigint not null, " +
|
"sourcetype integer not null, sourceid bigint not null, " +
|
||||||
@@ -707,8 +704,6 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
|||||||
//see what if any index tuning will help with a huge db of realistic data doing most common ops
|
//see what if any index tuning will help with a huge db of realistic data doing most common ops
|
||||||
//await ExecQueryAsync("CREATE INDEX idx_PartInventory_SourceId_SourceType ON apartinventory (sourceid, sourcetype);");
|
//await ExecQueryAsync("CREATE INDEX idx_PartInventory_SourceId_SourceType ON apartinventory (sourceid, sourcetype);");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//PROJECT
|
//PROJECT
|
||||||
await ExecQueryAsync("CREATE TABLE aproject (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text not null unique, active bool not null, " +
|
await ExecQueryAsync("CREATE TABLE aproject (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text not null unique, active bool not null, " +
|
||||||
"notes text, wiki text, customfields text, tags varchar(255) ARRAY, " +
|
"notes text, wiki text, customfields text, tags varchar(255) ARRAY, " +
|
||||||
|
|||||||
Reference in New Issue
Block a user