From 5edfcdd47d69b6537074dcc58c12ce22526dc937 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 27 Dec 2022 22:42:42 +0000 Subject: [PATCH] --- .vscode/launch.json | 2 +- server/DataList/CustomerDataList.cs | 8 ++++ server/Startup.cs | 4 ++ server/biz/CustomerBiz.cs | 1 + server/biz/GlobalBizSettingsBiz.cs | 64 ++++++++++++++++++++++++++++- server/models/Customer.cs | 7 ++-- server/util/AySchema.cs | 21 ++++++++-- 7 files changed, 97 insertions(+), 10 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index b4e9329..3300e7e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -35,7 +35,7 @@ "SOCKEYE_DB_CONNECTION": "Server=localhost;Username=postgres;Password=sockeye;Database=sockeye;CommandTimeout=300;", "SOCKEYE_DATA_PATH": "c:\\temp\\sockeye", "SOCKEYE_USE_URLS": "http://*:7676;", - //"SOCKEYE_PERMANENTLY_ERASE_DATABASE":"true", + "SOCKEYE_PERMANENTLY_ERASE_DATABASE":"true", //"SOCKEYE_REMOVE_LICENSE_FROM_DB":"true", //"SOCKEYE_REPORT_RENDERING_TIMEOUT":"1", "SOCKEYE_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_14\\bin" diff --git a/server/DataList/CustomerDataList.cs b/server/DataList/CustomerDataList.cs index ffd9455..0f8633d 100644 --- a/server/DataList/CustomerDataList.cs +++ b/server/DataList/CustomerDataList.cs @@ -48,6 +48,14 @@ namespace Sockeye.DataList SqlValueColumnName = "acustomer.active" }); + FieldDefinitions.Add(new DataListFieldDefinition + { + TKey = "DoNotContact", + FieldKey = "DoNotContact", + UiFieldDataType = (int)UiFieldDataType.Bool, + SqlValueColumnName = "acustomer.donotcontact" + }); + FieldDefinitions.Add(new DataListFieldDefinition { TKey = "Tags", diff --git a/server/Startup.cs b/server/Startup.cs index 9a5801d..24f96bb 100644 --- a/server/Startup.cs +++ b/server/Startup.cs @@ -662,6 +662,10 @@ namespace Sockeye Console.WriteLine("Forced shutdown: Ctrl+C keyboard shortcut"); Console.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); + + + GlobalBizSettingsBiz biz = GlobalBizSettingsBiz.GetBiz(dbContext); + biz.ImportRockfish(dbContext, _newLog).Wait(); } diff --git a/server/biz/CustomerBiz.cs b/server/biz/CustomerBiz.cs index f0b4012..f9ae8f2 100644 --- a/server/biz/CustomerBiz.cs +++ b/server/biz/CustomerBiz.cs @@ -250,6 +250,7 @@ namespace Sockeye.Biz .AddText(obj.Region) .AddText(obj.Country) .AddText(obj.AddressPostal) + .AddText(obj.DbId) .AddCustomFields(obj.CustomFields); } diff --git a/server/biz/GlobalBizSettingsBiz.cs b/server/biz/GlobalBizSettingsBiz.cs index 8503588..0a660f1 100644 --- a/server/biz/GlobalBizSettingsBiz.cs +++ b/server/biz/GlobalBizSettingsBiz.cs @@ -201,11 +201,70 @@ namespace Sockeye.Biz */ res = await client.GetAsync($"{URL_ROCKFISH}api/customer/list"); responseText = await res.Content.ReadAsStringAsync(); - var d = JArray.Parse(responseText); - // + var jaCustomerList = JArray.Parse(responseText); + foreach (JObject jCustomerListItem in jaCustomerList) + { + res = await client.GetAsync($"{URL_ROCKFISH}api/customer/{jCustomerListItem["id"].Value()}"); + + var jCustomer = JObject.Parse(await res.Content.ReadAsStringAsync()); + + //SITES + res = await client.GetAsync($"{URL_ROCKFISH}api/customer/{jCustomerListItem["id"].Value()}/sites"); + var jaSiteList = JArray.Parse(await res.Content.ReadAsStringAsync()); + + bool multiSite = jaSiteList.Count() > 1; + + foreach (JObject jSite in jaSiteList) + { + var CustomerName = jCustomer["name"].Value(); + if (multiSite) + CustomerName += " - " + jSite["name"].Value(); + + //Create customer if we don't have one already + if (await ct.Customer.AnyAsync(z => z.Name == CustomerName)) + continue;//already have this one so no need to process it again + { + //CREATE CUSTOMER + Customer c = new Customer(); + c.Name = CustomerName; + c.Country = jSite["country"].Value(); + c.Region = jSite["stateProvince"].Value(); + c.DoNotContact = jCustomer["doNotContact"].Value(); + c.Notes = jCustomer["notes"].Value(); + c.DbId = jSite["dbId"].Value(); + if (c.DbId == "v7_no_dbid"){ + c.DbId=null; + c.Tags.Add("v7"); + } + else + c.Tags.Add("raven"); + + if (jSite["hosted"].Value() == true) + c.Tags.Add("hosted"); + + var adminEmail = jCustomer["adminEmail"].Value(); + if (!string.IsNullOrWhiteSpace(adminEmail)) + c.Notes += "\nAdmin Email: " + adminEmail; + c.EmailAddress = jCustomer["adminEmail"].Value(); + CustomerBiz biz = CustomerBiz.GetBiz(ct); + var NewObject = await biz.CreateAsync(c); + + //Add all customer related shit here + + + } + + } + + + + + + + }//end of all customers iteration } catch (Exception ex) { @@ -214,6 +273,7 @@ namespace Sockeye.Biz } + log.LogInformation("FINISHED IMPORTING"); //in the correct order retrieve every object and if it's not already present in sockeye, import it //this should be callable any time and it will just update so it can be test live in sync / parallel until ready to switch over //await Task.CompletedTask; diff --git a/server/models/Customer.cs b/server/models/Customer.cs index b93a518..2cbfda2 100644 --- a/server/models/Customer.cs +++ b/server/models/Customer.cs @@ -10,7 +10,6 @@ namespace Sockeye.Models //NOTE: Any non required field (nullable in DB) sb nullable here, i.e. decimal? not decimal, //otherwise the server will call it an invalid record if the field isn't sent from client - //#### MIRRORED IN QBI !! public class Customer : ICoreBizObjectModel { public long Id { get; set; } @@ -19,14 +18,14 @@ namespace Sockeye.Models [Required] public string Name { get; set; } public bool Active { get; set; } + public bool DoNotContact { get; set; } + public string DbId { get; set; } public string Notes { get; set; } public string Wiki { get; set; } public string CustomFields { get; set; } public List Tags { get; set; } - //cant use these due to import v7 malformed shit adn can't be arsed to deal with that - //[Url] public string WebAddress { get; set; } public string AlertNotes { get; set; } public bool BillHeadOffice { get; set; } @@ -35,7 +34,7 @@ namespace Sockeye.Models public string HeadOfficeViz { get; set; } public string TechNotes { get; set; } public string AccountNumber { get; set; } - + public string Phone1 { get; set; } public string Phone2 { get; set; } public string Phone3 { get; set; } diff --git a/server/util/AySchema.cs b/server/util/AySchema.cs index be1544f..b341f31 100644 --- a/server/util/AySchema.cs +++ b/server/util/AySchema.cs @@ -22,9 +22,9 @@ namespace Sockeye.Util //!!!!WARNING: BE SURE TO UPDATE THE DbUtil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync WHEN NEW TABLES ADDED!!!! private const int DESIRED_SCHEMA_LEVEL = 16; - internal const long EXPECTED_COLUMN_COUNT = 495; + internal const long EXPECTED_COLUMN_COUNT = 497; internal const long EXPECTED_INDEX_COUNT = 71; - internal const long EXPECTED_CHECK_CONSTRAINTS = 237; + internal const long EXPECTED_CHECK_CONSTRAINTS = 238; internal const long EXPECTED_FOREIGN_KEY_CONSTRAINTS = 32; internal const long EXPECTED_VIEWS = 0; internal const long EXPECTED_ROUTINES = 2; @@ -491,7 +491,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); //CUSTOMER await ExecQueryAsync("CREATE TABLE acustomer (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, donotcontact BOOL NOT NULL DEFAULT false, dbid TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, " + "webaddress TEXT, alertnotes TEXT, billheadoffice BOOL, technotes TEXT, accountnumber TEXT, " + "phone1 TEXT, phone2 TEXT, phone3 TEXT, phone4 TEXT, phone5 TEXT, emailaddress TEXT, " + "postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(9,6), longitude DECIMAL(9,6) " @@ -1220,6 +1220,21 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); #endregion gzcase + #region CUSTOMER ADDITIONS + //english translations + await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'DoNotContact', 'Do not contact' FROM atranslation t where t.baselanguage = 'en'"); + + //spanish translations + await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'DoNotContact', 'Do not contact' FROM atranslation t where t.baselanguage = 'es'"); + + //french translations + await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'DoNotContact', 'Do not contact' FROM atranslation t where t.baselanguage = 'fr'"); + + //german translations + await ExecQueryAsync("INSERT INTO atranslationitem(translationid,key,display) SELECT t.id, 'DoNotContact', 'Do not contact' FROM atranslation t where t.baselanguage = 'de'"); + + #endregion customer additions + currentSchema = 16; await SetSchemaLevelAsync(currentSchema);