新增snlist三条命令

This commit is contained in:
2025-07-16 21:10:09 +08:00
parent eaa75430e7
commit 1355c8ef0d
74 changed files with 1536 additions and 490 deletions

View File

@@ -1,279 +0,0 @@
Namespace UTSModule.Test.Command
''' <summary>
''' UTS串口通讯返回值比较函数静态类
''' </summary>
Public Class CompareFunction
#Region "String"
''' <summary>
''' 仅一个参数字符串比较,忽略大小写
''' </summary>
''' <param name="testReturn">测试命令返回集合</param>
''' <returns></returns>
Public Shared Function StringCompare(testReturn As TestCommandReturn) As Boolean
Return StringCompare(testReturn.RecordValue, testReturn.LowerLimit, testReturn.UpperLimit)
End Function
''' <summary>
''' 仅一个参数字符串是否包含关系,忽略大小写,下限则为目标字符串包含下限,上限则为上限字符串包含目标字符串
''' </summary>
''' <returns></returns>
Public Shared Function StringContain(value As String, lowerLimit As String, upperLimit As String) As Boolean
Dim result As Boolean = True
If String.IsNullOrWhiteSpace(lowerLimit) = False Then '需要比较下限
If value.Contains(lowerLimit) = False Then '不符合条件
result = False
Return result '失败则不用比较上限
End If
End If
If String.IsNullOrWhiteSpace(upperLimit) = False Then '需要比较上限
If upperLimit.Contains(value) = False Then '不符合条件
result = False
End If
End If
Return result
End Function
''' <summary>
''' 仅一个参数字符串比较,忽略大小写
''' </summary>
''' <param name="value">当前值</param>
''' <param name="lowerLimit">下限</param>
''' <param name="upperLimit">上限</param>
''' <returns></returns>
Public Shared Function StringCompare(value As String, lowerLimit As String, upperLimit As String) As Boolean
Dim result As Boolean = True
If String.IsNullOrWhiteSpace(lowerLimit) = False Then '需要比较下限
If String.Compare(value, lowerLimit, True) < 0 Then '不符合条件
result = False
Return result '失败则不用比较上限
End If
End If
If String.IsNullOrWhiteSpace(upperLimit) = False Then '需要比较上限
If String.Compare(value, upperLimit, True) > 0 Then '不符合条件
result = False
End If
End If
Return result
End Function
''' <summary>
''' 多参数字符串列表比较上下限
''' </summary>
''' <param name="param">参数列表</param>
''' <param name="lowerLimit">下限字符串,切割时按冒号切割,位数不足则默认不比较</param>
''' <param name="upperLimit">上限字符串,切割时按冒号切割,位数不足则默认不比较</param>
''' <returns></returns>
Public Shared Function ParamStringListCompare(param As List(Of String), lowerLimit As String, upperLimit As String) As Boolean
Dim lowerList As String() = lowerLimit.Split(":"c)
Dim upperList As String() = upperLimit.Split(":"c)
Dim lower As String
Dim upper As String
If param.Count() = 0 Then
If StringCompare("", lowerList(0), upperList(0)) = False Then Return False
End If
For i As Integer = 0 To param.Count - 1
If i = lowerList.Count() Then
lower = String.Empty
Else
lower = lowerList(i)
End If
If i = upperList.Count() Then
upper = String.Empty
Else
upper = upperList(i)
End If
If StringCompare(param(i), lower, upper) = False Then Return False
Next
Return True
End Function
#End Region
#Region "Double"
''' <summary>
''' 浮点型比较方式
''' </summary>
''' <param name="testReturn"></param>
''' <returns></returns>
Public Shared Function DoubleCompare(testReturn As TestCommandReturn) As Boolean
Return DoubleCompare(testReturn.RecordValue, testReturn.LowerLimit, testReturn.UpperLimit)
End Function
''' <summary>
''' 仅一个参数浮点型比较
''' </summary>
''' <param name="value">当前值</param>
''' <param name="lowerLimit">下限</param>
''' <param name="upperLimit">上限</param>
''' <returns></returns>
Public Shared Function DoubleCompare(value As String, lowerLimit As String, upperLimit As String) As Boolean
Dim result As Boolean = True
Dim compareLower As Boolean = IsNumeric(lowerLimit)
Dim compareUpper As Boolean = IsNumeric(upperLimit)
If IsNumeric(value) = False Then
If compareLower OrElse compareUpper Then result = False
Else
Dim val As Double = CDbl(value)
If compareLower Then
If val < CDbl(lowerLimit) Then
result = False
Return result '失败则不用比较上限
End If
End If
If compareUpper Then
If val > CDbl(upperLimit) Then result = False
End If
End If
Return result
End Function
''' <summary>
''' 多参数浮点型列表比较上下限
''' </summary>
''' <param name="param">参数列表</param>
''' <param name="lowerLimit">下限字符串,切割时按冒号切割,位数不足则默认不比较</param>
''' <param name="upperLimit">上限字符串,切割时按冒号切割,位数不足则默认不比较</param>
''' <returns></returns>
Public Shared Function ParamDoubleListCompare(param As List(Of String), lowerLimit As String, upperLimit As String) As Boolean
Dim lowerList As String() = lowerLimit.Split(":"c)
Dim upperList As String() = upperLimit.Split(":"c)
Dim lower As String
Dim upper As String
If param.Count = 0 Then
If DoubleCompare("", lowerList(0), upperList(0)) = False Then Return False
End If
For i As Integer = 0 To param.Count - 1
If i = lowerList.Count() Then
lower = String.Empty
Else
lower = lowerList(i)
End If
If i = upperList.Count() Then
upper = String.Empty
Else
upper = upperList(i)
End If
If DoubleCompare(param(i), lower, upper) = False Then Return False
Next
Return True
End Function
#End Region
#Region "Integer"
''' <summary>
''' 整数型比较方式
''' </summary>
''' <param name="testReturn"></param>
''' <returns></returns>
Public Shared Function IntegerCompare(testReturn As TestCommandReturn) As Boolean
Return IntegerCompare(testReturn.RecordValue, testReturn.LowerLimit, testReturn.UpperLimit)
End Function
''' <summary>
''' 仅一个参数整数比较,忽略大小写
''' </summary>
''' <param name="value">当前值</param>
''' <param name="lowerLimit">下限</param>
''' <param name="upperLimit">上限</param>
''' <returns></returns>
Public Shared Function IntegerCompare(value As String, lowerLimit As String, upperLimit As String) As Boolean
Dim result As Boolean = True
Dim compareLower As Boolean = IsNumeric(lowerLimit)
Dim compareUpper As Boolean = IsNumeric(upperLimit)
If IsNumeric(value) = False Then
If compareLower OrElse compareUpper Then result = False
Else
Dim val As Double = CInt(value)
If compareLower Then
If val < CInt(lowerLimit) Then
result = False
Return result '失败则不用比较上限
End If
End If
If compareUpper Then
If val > CInt(upperLimit) Then result = False
End If
End If
Return result
End Function
''' <summary>
''' 多参数整数型列表比较上下限
''' </summary>
''' <param name="param">参数列表</param>
''' <param name="lowerLimit">下限字符串,切割时按冒号切割,位数不足则默认不比较</param>
''' <param name="upperLimit">上限字符串,切割时按冒号切割,位数不足则默认不比较</param>
''' <returns></returns>
Public Shared Function ParamIntegerListCompare(param As List(Of String), lowerLimit As String, upperLimit As String) As Boolean
Dim lowerList As String() = lowerLimit.Split(":"c)
Dim upperList As String() = upperLimit.Split(":"c)
Dim lower As String
Dim upper As String
If param.Count = 0 Then
If IntegerCompare("", lowerList(0), upperList(0)) = False Then Return False
End If
For i As Integer = 0 To param.Count - 1
If i = lowerList.Count() Then
lower = String.Empty
Else
lower = lowerList(i)
End If
If i = upperList.Count() Then
upper = String.Empty
Else
upper = upperList(i)
End If
If IntegerCompare(param(i), lower, upper) = False Then Return False
Next
Return True
End Function
#End Region
End Class
End Namespace

View File

@@ -0,0 +1,20 @@
Imports UTS_Core.UTSModule.Test.Command
Public Class CombindRecordCommand
Inherits TestCommandExecutor
Sub New(command As TestCommand)
MyBase.New(command)
End Sub
Public Overrides Function Execute() As TestCommandReturn
'链接本地库
'获取本地库数据
'链接云端库
'获取云端库数据
'失败则写入同步表格
End Function
End Class

View File

@@ -0,0 +1,18 @@
Namespace UTSModule.Test.Command.DatabaseCommand
Public Class DatabaseCommandManager
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
Dim executor As TestCommandExecutor
Select Case command.Name
Case "GetRecord"
Return New GetRecordCommand(command)
Case "SetRecord"
Return New SetRecordCommand(command)
Case "CombindRecord"
Return New CombindRecordCommand(command)
Case Else
Throw New Exception($"Database集,未知命令 {command.Name}")
End Select
Return executor
End Function
End Class
End Namespace

View File

@@ -0,0 +1,25 @@
Imports UTS_Core.UTSModule.Test.Command
Public Class GetRecordCommand
Inherits TestCommandExecutor
Private _sn As String
Private dbFiledName As String
Sub New(command As TestCommand)
MyBase.New(command)
End Sub
Public Overrides Function Execute() As TestCommandReturn
'链接云端库
'获取云端库数据
'链接本地库
'获取本地库数据
End Function
End Class

View File

@@ -0,0 +1,19 @@
Imports UTS_Core.UTSModule.Test.Command
Public Class SetRecordCommand
Inherits TestCommandExecutor
Sub New(command As TestCommand)
MyBase.New(command)
End Sub
Public Overrides Function Execute() As TestCommandReturn
'链接本地库
'获取本地库数据
'链接云端库
'获取云端库数据
'失败则写入同步表格
End Function
End Class

View File

@@ -0,0 +1,84 @@
Imports UTS_Core.Database
Imports UTS_Core.UTSModule
Imports UTS_Core.UTSModule.DbConnect
Imports UTS_Core.UTSModule.DbTableModel.Customer
Imports UTS_Core.UTSModule.Test.Command
Public Class CombindRecordCommand
Inherits TestCommandExecutor
Private _filedNames As New List(Of String)
Private _dutSn As String
Private _dutSn2 As String
Sub New(command As TestCommand)
MyBase.New(command)
_dutSn = command.Parameter(0)
_dutSn2 = command.Parameter(1)
_filedNames.Add(command.Parameter(0))
End Sub
Public Overrides Function Execute() As TestCommandReturn
CommandReturn.ExecuteResult = True
CommandReturn.RecordValue = "True"
Dim filedName As String = _filedNames(0)
Dim updateString As String = $"t1.`{filedName}` = t2.`{filedName}`"
For i As Integer = 1 To _filedNames.Count - 1
updateString += $",t1.`{filedName}` = t2.`{filedName}` "
Next
Dim saveDbCmdText As String = String.Empty
Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
Dim cmdText As String = $"UPDATE `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t1 JOIN `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t2 ON t2.`{SnListTable.ColNames.BarCode}` = '{_dutSn2}' SET {updateString} WHERE t1.`{SnListTable.ColNames.BarCode}` = '{_dutSn}';"
Try
db.Open()
db.ExecuteNonQuery(cmdText)
db.Close()
Catch ex As Exception
saveDbCmdText = cmdText '云端执行,使用本地执行
End Try
End Using
'本地存储
Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
Try
db.Open()
Catch ex As Exception
CommandReturn.ExecuteResult = False
CommandReturn.RecordValue = "False"
CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
End Try
Try
Dim cmdText As String = $"UPDATE `{SnListTable.TableName}` t1 JOIN `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t2 ON t2.`{SnListTable.ColNames.BarCode}` = '{_dutSn2}' SET {updateString} WHERE t1.`{SnListTable.ColNames.BarCode}` = '{_dutSn}';"
db.ExecuteNonQuery(cmdText)
Catch ex As Exception
CommandReturn.ExecuteResult = False
CommandReturn.RecordValue = "False"
CommandReturn.ExecuteResultTipString = $"本地数据库保存失败,{ex.Message}"
End Try
'本地缓存
Try
If String.IsNullOrEmpty(saveDbCmdText) Then
DbConnector.SaveCmdStringToCacheTable(db, saveDbCmdText)
CommandReturn.ExecuteResultTipString = "本地缓存成功"
End If
Catch ex As Exception
CommandReturn.ExecuteResult = False
CommandReturn.RecordValue = "False"
CommandReturn.ExecuteResultTipString = $"本地数据库缓存失败,{ex.Message}"
End Try
db.Close()
End Using
End Function
End Class

View File

@@ -3,10 +3,14 @@
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
Dim executor As TestCommandExecutor
Select Case command.Name
Case "Get_DB_Data"
executor = New CheckUtsPlatformExecutor(command)
Case "GetRecord"
Return New GetRecordCommand(command)
Case "SetRecord"
Return New SetRecordCommand(command)
Case "CombindRecord"
Return New CombindRecordCommand(command)
Case Else
Throw New Exception($"System集,未知命令 {command.Name}")
Throw New Exception($"Database集,未知命令 {command.Name}")
End Select
Return executor
End Function

View File

@@ -0,0 +1,70 @@
Imports UTS_Core.Database
Imports UTS_Core.UTSModule
Imports UTS_Core.UTSModule.DbConnect
Imports UTS_Core.UTSModule.DbTableModel.Customer
Imports UTS_Core.UTSModule.Test.Command
Public Class GetRecordCommand
Inherits TestCommandExecutor
Private _filedName As String
Private _dutSn As String
Sub New(command As TestCommand)
MyBase.New(command)
_dutSn = command.Parameter(0)
_filedName = command.Parameter(1)
End Sub
Public Overrides Function Execute() As TestCommandReturn
'优先查询云端
Dim useLocalSearch As Boolean = False
Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
Dim cmdText As String = db.CmdHelper.DbSearch(UtsDb.RemotePrivateDb, _filedName, SnListTable.TableName, condition)
Try
db.Open()
CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
CommandReturn.ExecuteResult = True
db.Close()
Catch ex As Exception
useLocalSearch = True '云端查询失败,使用本地查询
End Try
End Using
'本地存储
If useLocalSearch Then
Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
Try
db.Open()
Catch ex As Exception
CommandReturn.ExecuteResult = False
CommandReturn.RecordValue = ""
CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
End Try
Try
' Dim condition As String = $"`{SnListTable.ColNames.ProductID}` = '{Station.ParentProject.Index}' and `{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
Dim cmdText As String = db.CmdHelper.Search(_filedName, SnListTable.TableName, condition)
CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
CommandReturn.ExecuteResult = True
CommandReturn.ExecuteResultTipString = $"本地数据库查询成功"
Catch ex As Exception
CommandReturn.ExecuteResult = False
CommandReturn.RecordValue = ""
CommandReturn.ExecuteResultTipString = $"本地数据库查询失败,{ex.Message}"
End Try
db.Close()
End Using
End If
Return CommandReturn
End Function
End Class

View File

@@ -0,0 +1,86 @@
Imports UTS_Core.Database
Imports UTS_Core.UTSModule
Imports UTS_Core.UTSModule.DbConnect
Imports UTS_Core.UTSModule.DbTableModel.Customer
Imports UTS_Core.UTSModule.Test.Command
Public Class SetRecordCommand
Inherits TestCommandExecutor
Private _filedName As String
Private _filedValue As String
Private _dutSn As String
Sub New(command As TestCommand)
MyBase.New(command)
_dutSn = command.Parameter(0)
_filedName = command.Parameter(1)
_filedValue = command.Parameter(2)
End Sub
Public Overrides Function Execute() As TestCommandReturn
CommandReturn.ExecuteResult = True
CommandReturn.RecordValue = "True"
'优先储存云端
Dim saveDbCmdText As String = String.Empty
Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
Dim updateString As String = $"`{_filedName}` = {_filedValue}"
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
Dim cmdText As String = db.CmdHelper.DbUpdate(UtsDb.RemotePrivateDb, SnListTable.TableName, updateString, condition)
Try
db.Open()
db.ExecuteNonQuery(cmdText)
db.Close()
Catch ex As Exception
saveDbCmdText = cmdText '云端存储失败,转存本地
End Try
End Using
'本地存储
Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
Try
db.Open()
Catch ex As Exception
CommandReturn.ExecuteResult = False
CommandReturn.RecordValue = "False"
CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
End Try
Try
Dim updateString As String = $"`{_filedName}` = {_filedValue}"
' Dim condition As String = $"`{SnListTable.ColNames.ProductID}` = '{Station.ParentProject.Index}' and `{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
Dim cmdText As String = db.CmdHelper.Update(SnListTable.TableName, updateString, condition)
db.ExecuteNonQuery(cmdText)
Catch ex As Exception
CommandReturn.ExecuteResult = False
CommandReturn.RecordValue = "False"
CommandReturn.ExecuteResultTipString = $"本地数据库保存失败,{ex.Message}"
End Try
'本地缓存
Try
If String.IsNullOrEmpty(saveDbCmdText) Then
DbConnector.SaveCmdStringToCacheTable(db, saveDbCmdText)
CommandReturn.ExecuteResultTipString = "本地缓存成功"
End If
Catch ex As Exception
CommandReturn.ExecuteResult = False
CommandReturn.RecordValue = "False"
CommandReturn.ExecuteResultTipString = $"本地数据库缓存失败,{ex.Message}"
End Try
db.Close()
End Using
Return CommandReturn
End Function
End Class