- VERSION 4.11.22

- Se modifico el código de cargar día para que guarde tambien en cat_gunaprod2 la informacion de las promos
This commit is contained in:
Jose Alberto Guerra Ugalde
2024-11-28 15:16:54 -06:00
parent 007f6ddca7
commit ff1d910052
7 changed files with 179 additions and 51 deletions

View File

@@ -4,9 +4,7 @@ ModulesStructureVersion=1
Type=Class
Version=6.8
@EndOfDesignText@
'Necesita la libreria RandomAccessFile
'Class module
''Class module
Sub Class_Globals
Private mTarget As Object
Type DBResult (Tag As Object, Columns As Map, Rows As List)
@@ -17,7 +15,11 @@ Sub Class_Globals
,T_DOUBLE = 6, T_BOOLEAN = 7, T_BLOB = 8 As Byte
Private VERSION As Float = 0.9
Private tempArray(1) As Object
Dim jobTagAnterior As String = "" 'Mod por CHV - 211027
Dim jobTagAnterior As String = "" 'Mod por CHV - 211109
Dim reqsList, timesList As List
Dim inicioRequest As Long 'ignore
Dim inicioJobDone As Long 'ignore
Dim inicioRequestMap, inicioJobDoneMap As Map
End Sub
'Target - The module that handles JobDone (usually Me).
@@ -34,8 +36,10 @@ End Sub
Public Sub ExecuteQuery(Command As DBCommand, Limit As Int, Tag As Object)
Dim j As HttpJob
Dim ms As OutputStream
Dim out2 As OutputStream = StartJob(j,ms, Tag)
Dim out2 As OutputStream = StartJob(j, ms, Tag)
' If reqsList.IsInitialized Then reqsList.Add(Tag)
' If timesList.IsInitialized Then timesList.Add(DateTime.now)
WriteObject(Command.Name, out2)
WriteInt(Limit, out2)
WriteList(Command.Parameters, out2)
@@ -43,13 +47,30 @@ Public Sub ExecuteQuery(Command As DBCommand, Limit As Int, Tag As Object)
j.PostBytes(link & "?method=query", ms.ToBytesArray)
End Sub
'Sends a query request.
'Command - Query name and parameters.
'Limit - Maximum rows to return or 0 for no limit.
'Tag - An object that will be returned in the result.
'Timeout - The http request timeout in ms, or 0 if default (30 secs)
Public Sub ExecuteQuery3(Command As DBCommand, Limit As Int, Tag As Object, Timeout As Int) 'Mod por CHV, agregué el parametro Timeout - 211229
Dim j As HttpJob
Dim ms As OutputStream
Dim out2 As OutputStream = StartJob(j,ms, Tag)
WriteObject(Command.Name, out2)
WriteInt(Limit, out2)
WriteList(Command.Parameters, out2)
out2.Close
j.PostBytes(link & "?method=query", ms.ToBytesArray)
If Timeout <> 0 Then j.GetRequest.Timeout = Timeout
End Sub
'Executes a batch of (non-select) commands.
'ListOfCommands - List of the commands that will be executes.
'Tag - An object that will be returned in the result.
Public Sub ExecuteBatch(ListOfCommands As List, Tag As Object)
Dim j As HttpJob
Dim ms As OutputStream
Dim out2 As OutputStream = StartJob(j,ms, Tag)
Dim out2 As OutputStream = StartJob(j, ms, Tag)
WriteInt(ListOfCommands.Size, out2)
For Each Command As DBCommand In ListOfCommands
WriteObject(Command.Name, out2)
@@ -61,10 +82,15 @@ End Sub
'Similar to ExecuteBatch. Sends a single command.
Public Sub ExecuteCommand(Command As DBCommand, Tag As Object)
' If reqsList.IsInitialized Then reqsList.Add(Tag)
' If timesList.IsInitialized Then timesList.Add(DateTime.now)
ExecuteBatch(Array As DBCommand(Command), Tag)
End Sub
Private Sub StartJob(j As HttpJob, MemoryStream As OutputStream, Tag As Object) As OutputStream
' inicioRequest = DateTime.now
If reqsList.IsInitialized Then reqsList.Add(Tag)
If timesList.IsInitialized Then timesList.Add(DateTime.now)
j.Initialize("DBRequest", mTarget)
j.Tag = Tag
MemoryStream.InitializeToBytesArray(0)
@@ -115,7 +141,7 @@ Private Sub WriteObject(o As Object, out As OutputStream)
Else If GetType(tempArray(0)) = "[B" Then
data = o
out.WriteBytes(Array As Byte(T_BLOB), 0, 1)
WriteInt(data.Length, out)
WriteInt(data.Length, out)
Else 'If o Is String Then (treat all other values as string)
out.WriteBytes(Array As Byte(T_STRING), 0, 1)
data = bc.StringToBytes(o, "UTF8")
@@ -188,7 +214,13 @@ End Sub
'Handles the Job result and returns a DBResult.
Public Sub HandleJob(Job As HttpJob) As DBResult
Dim start As Long = DateTime.Now
If jobTagAnterior <> Job.Tag Then
' inicioJobDone = DateTime.Now 'ignore
If inicioJobDoneMap.IsInitialized Then inicioJobDoneMap.Put(Job.Tag, DateTime.Now)
' tiempos.Put(Job.taskId, CreateMap("inicioJobDone":inicioJobDone))
' Log(tiempos)
' Log("############# " & Job.taskId)
End If
Dim In As InputStream = Job.GetInputStream
Dim cs As CompressedStreams
In = cs.WrapInputStream(In, "gzip")
@@ -199,8 +231,6 @@ Public Sub HandleJob(Job As HttpJob) As DBResult
table.Columns.Initialize
table.rows.Initialize
table.Tag = Job.Tag
If jobTagAnterior <> Job.Tag Then LogColor("HandleJob: '"&Job.Tag&"'", Colors.Blue) 'Mod por CHV - 211023
jobTagAnterior = Job.Tag 'Mod por CHV - 211023
If method = "query" Then
Dim numberOfColumns As Int = ReadInt(In)
For i = 0 To numberOfColumns - 1
@@ -222,9 +252,14 @@ Public Sub HandleJob(Job As HttpJob) As DBResult
Next
End If
In.Close
' Log("HandleJob: " & (DateTime.Now - start))
' Log("HandleJob: " & (DateTime.Now - start))'Comentado por CHV - 211112
If jobTagAnterior <> table.Tag Then
LogColor("HandleJob: '"&table.Tag&"'" & " - Registros: " & table.Rows.Size, Colors.RGB(115, 0, 140)) 'Mod por CHV - 211109
End If
jobTagAnterior = table.Tag 'Mod por CHV - 211109
Return table
End Sub
'Reads a file and returns the file as a bytes array.
Public Sub FileToBytes(Dir As String, FileName As String) As Byte()
Dim out As OutputStream
@@ -234,6 +269,7 @@ Public Sub FileToBytes(Dir As String, FileName As String) As Byte()
out.Close
Return out.ToBytesArray
End Sub
'Converts an image to a bytes array (for BLOB fields).
Public Sub ImageToBytes(Image As Bitmap) As Byte()
Dim out As OutputStream
@@ -242,6 +278,7 @@ Public Sub ImageToBytes(Image As Bitmap) As Byte()
out.Close
Return out.ToBytesArray
End Sub
'Converts a bytes array to an image (for BLOB fields).
Public Sub BytesToImage(bytes() As Byte) As Bitmap
Dim In As InputStream
@@ -250,6 +287,7 @@ Public Sub BytesToImage(bytes() As Byte) As Bitmap
bmp.Initialize2(In)
Return bmp
End Sub
'Prints the table to the logs.
Public Sub PrintTable(Table As DBResult)
Log("Tag: " & Table.Tag & ", Columns: " & Table.Columns.Size & ", Rows: " & Table.Rows.Size)
@@ -265,8 +303,58 @@ Public Sub PrintTable(Table As DBResult)
For Each record As Object In row
sb.Append(record).Append(TAB)
Next
ToastMessageShow(sb.ToString, True)
Log(sb.ToString)
Next
End Sub
Sub requestTimes(tag As String) As Map 'ignore
Private times As Map
times.Initialize
' Log("###### " & tag)
' Log(reqsList.IsInitialized)
If reqsList.IsInitialized Then
' Log(reqsList)
' Private pos As Int = reqsList.IndexOf(tag)
If inicioRequestMap.ContainsKey(tag) Then
inicioRequest = inicioRequestMap.Get(tag)
' Log(">>>>>>> From inicioRequestMap")
End If
If inicioJobDoneMap.ContainsKey(tag) Then
inicioJobDone = inicioJobDoneMap.Get(tag)
' Log(">>>>>>> From inicioJobDoneMap")
End If
End If
' Log($"${inicioJobDone} - ${inicioRequest}"$)
Private requestTime As String = NumberFormat2(((inicioJobDone - inicioRequest) / 1000),1,5,0,False)
Private JobDoneTime As String = NumberFormat2(((DateTime.Now - inicioJobDone) / 1000),1,5,0,False)
times.Put("requestTime", requestTime)
times.Put("jobDoneTime", JobDoneTime)
times.Put("totalTime", NumberFormat2((JobDoneTime + requestTime),1,5,0,False))
Return times
End Sub
'Initializes request tracking
Sub trackInit 'ignore
Log(">>>>>>>>> TRACKINIT ")
reqsList.Initialize
timesList.Initialize
inicioRequestMap.Initialize
inicioJobDoneMap.Initialize
End Sub
Sub trackNext(job As HttpJob)
If reqsList.IsInitialized Then 'Si tenemos lista de requests, la procesamos.
Private quitamos As String = ""
If reqsList.IndexOf(job.tag) <> -1 Then
Private pos As Int = reqsList.IndexOf(job.tag)
If pos <> -1 Then
inicioRequestMap.Put(job.Tag, timesList.Get(pos))
reqsList.RemoveAt(pos)
timesList.RemoveAt(pos)
End If
quitamos = $"Quitamos ${job.tag} - "$
End If
LogColor(">>>>>> Requests: " & reqsList.Size & " - " & quitamos & reqsList, Colors.Blue)
LogColor(">>>>>> inicioRequestMap:" & inicioRequestMap.Size & " - " & inicioRequestMap, Colors.Magenta)
End If
End Sub