First pass of new mandator selection

This commit is contained in:
Jonathan Jenne
2021-11-19 16:23:18 +01:00
parent dec45ef493
commit ac50cf661b
19 changed files with 235 additions and 136 deletions

View File

@@ -1,8 +1,9 @@
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Database
Imports MultiTool.Shared.Helpers
Imports MultiTool.Shared.Winline.Entities
Imports System.Text.RegularExpressions
Imports MultiTool.Shared.Templates
Imports MultiTool.Shared.Constants
Namespace Winline
Public Class WinlineData
@@ -10,6 +11,8 @@ Namespace Winline
Private ReadOnly Database As MSSQLServer
Private ReadOnly Config As Config
Private ReadOnly MandatorConfig As MandatorConfig
Private ReadOnly MappingConfig As MappingConfig
Public Articles As New List(Of Article)
Public Accounts As New List(Of Account)
@@ -18,39 +21,12 @@ Namespace Winline
Public Years As List(Of Integer)
Public Const ALL_MESOCOMP = "mesocomp"
Public Const V21_ARTICLENUMBER = "c002"
Public Const V21_ARTICLEDESCRIPTION = "c003"
Public Const V21_MAINARTICLENUMBER = "c011"
Public Const V21_REPLACEMENTARTICLENUMBER = "c123"
Public Const V21_EAN = "c075"
Public Const V50_ACCOUNTNUMBER = "c002"
Public Const V50_ACCOUNTNAME = "c003"
Public Const V50_STREETNAME = "c050"
Public Const V50_ZIPCODE = "c051"
Public Const V50_CITYNAME = "c052"
Public Const V50_GLN = "c260"
Public Const T45_KEY = "c000"
Public Const T45_NAME = "c001"
Public Const T45_CONTACTNUMBER = "c063"
Public Const V05_ACCOUNTID = "c002"
Public Const V05_ACCOUNTNAME = "c003"
Public Const T357_KINDID = "c030"
Public Const T357_KINDNAME = "c001"
Public Const T01_DATABASEINFO = "c004"
Public Const T01_MANDATORID = "c000"
Public Const T01_MANDATORNAME = "c003"
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config)
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config, pMappingConfig As MappingConfig, pMandatorConfig As MandatorConfig)
MyBase.New(pLogConfig, pLogConfig.GetLogger())
Database = pDatabase
Config = pConfig
MandatorConfig = pMandatorConfig
MappingConfig = pMappingConfig
End Sub
<DebuggerStepThrough>
@@ -165,17 +141,14 @@ Namespace Winline
.Server = oDbInfo.Item2
}
'Dim oMandatorConfig As Config.MandatorConfig = Config.Mandators.
' Where(Function(m) oMandator.Id = m.Name).
' SingleOrDefault()
Dim oMandatorConfig As MandatorConfigItem = MandatorConfig.Items.
Where(Function(item) item.Name = oMandator.Id).
SingleOrDefault()
'Dim oMandatorConfig2 = MappingConfiguration.Where(Function(c) c.)
'If oMandatorConfig IsNot Nothing Then
' oMandator.IsWhitelisted = True
' oMandator.Regex = oMandatorConfig.ArticleRegex
' oMandator.Order = oMandatorConfig.Order
'End If
If oMandatorConfig IsNot Nothing Then
oMandator.IsWhitelisted = True
oMandator.Order = oMandatorConfig.OrderKey
End If
Mandators.Add(oMandator)
Next
@@ -411,17 +384,20 @@ Namespace Winline
If p.Fields.ContainsKey("Artikelnummer") Then
Return p.Fields.Item("Artikelnummer").Original
Else
' TODO: Throw or ignore?
Throw New Exceptions.MissingAttributeException("Artikelnummer")
Return Nothing
End If
End Function).
Where(Function(ean) ean IsNot Nothing).
Distinct().
ToList()
Dim oYear = GetWinLineYear()
Dim oMandatorId As String = String.Empty
' TODO: Instead load whitelisted mandators from database
Dim oWhitelistedMandators = Mandators.
Where(Function(m) m.IsWhitelisted = True).
OrderBy(Function(m) m.Order).
ToList()
For Each oEANNumber In oEANNumbers
@@ -453,15 +429,19 @@ Namespace Winline
Dim oArticleNumber As String = ItemEx(oRow, V21_MAINARTICLENUMBER, String.Empty)
' EAN was found, now we need to check it against the Regex of the current Mandantor, if one exists
If oMandator.Regex <> String.Empty Then
Dim oMappingConfigItem = MappingConfig.Items.
Where(Function(item) item.DestinationName = "MANDATOR" And item.DestinationValue = oMandator.Id And item.SourceName = "ARTICLE").
SingleOrDefault()
If oMappingConfigItem IsNot Nothing Then
Try
Dim oRegex As New Regex(oMandator.Regex)
Dim oRegex As New Regex(oMappingConfigItem.SourceRegex)
Dim oMatch = oRegex.Match(oArticleNumber)
' If ArticleNumber matches the regex, we assign it and exit
If oMatch.Success Then
oMandatorId = oMandator.Id
Exit For
Return oMandator
Else
' If it does not match, continue to the next mandator
End If
@@ -469,21 +449,15 @@ Namespace Winline
Logger.Error(ex)
Logger.Warn("Regex [{0}] could not be parsed. Skipping.", oMandator.Regex)
End Try
Else
' If no regex was found, we assume the number matches
oMandatorId = oMandator.Id
Continue For
End If
Next
Next
If oMandatorId = String.Empty Then
Return Nothing
Else
Return oWhitelistedMandators.
Where(Function(m) m.Id = oMandatorId).
Take(1).
SingleOrDefault()
End If
Return Nothing
End Function
''' <summary>