Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    Public Class RepairLogTable
        Enum ColNames
            ''' <summary>
            ''' 维修日志索引
            ''' </summary>
            ID

            ''' <summary>
            ''' 维修产品索引
            ''' </summary>
            ProductID

            ''' <summary>
            ''' 所属站位索引
            ''' </summary>
            StationID

            ''' <summary>
            ''' 所属订单索引
            ''' </summary>
            OrderID

            ''' <summary>
            ''' 维修所属测试日志索引
            ''' </summary>
            TestLogID

            ''' <summary>
            ''' 维修产品条码
            ''' </summary>
            DUT_SN

            ''' <summary>
            ''' 测试日志所属测试流程名称
            ''' </summary>
            TestPlan

            ''' <summary>
            ''' 产品测试日志失败步骤名
            ''' </summary>
            FailSteps

            ''' <summary>
            ''' 产品测试日志失败信息
            ''' </summary>
            FailMsg

            ''' <summary>
            ''' 产品测试日志错误代码
            ''' </summary>
            ErrCode

            ''' <summary>
            ''' 维修产品日期
            ''' </summary>
            RepairDate

            ''' <summary>
            ''' 当条记录更新时间
            ''' </summary>
            UpdateTime

            ''' <summary>
            ''' 维修原因类型
            ''' </summary>
            RepairType

            ''' <summary>
            ''' 维修原因
            ''' </summary>
            RepairReason

            ''' <summary>
            ''' 维修来源
            ''' </summary>
            RepairSource

            ''' <summary>
            ''' 维修来源订单号
            ''' </summary>
            DocuNumber

            ''' <summary>
            ''' 维修人工注释
            ''' </summary>
            RepairComment

            ''' <summary>
            ''' 维修产品结果索引
            ''' </summary>
            RepairResult

            ''' <summary>
            ''' 产品图像文件名1
            ''' </summary>
            ProductImg1

            ''' <summary>
            ''' 产品图像文件名2
            ''' </summary>
            ProductImg2

            ''' <summary>
            ''' 产品图像文件名3
            ''' </summary>
            ProductImg3

            ''' <summary>
            ''' 产品图像文件名4
            ''' </summary>
            ProductImg4
        End Enum

        Public Shared Property TableName() As String = "TBL_RepairLog"

        ''' <summary>
        ''' 建表语句
        ''' </summary>
        ''' <returns>建表语句</returns>
        Public Shared Function CreateTableString(dbName As String, Optional dbType As DbExecutor.DbTypeEnum = DbExecutor.DbTypeEnum.Mysql) As String
            Dim builder As New StringBuilder
            If dbType = DbExecutor.DbTypeEnum.Mysql Then
                builder.Append($"CREATE TABLE If Not Exists `{dbName}`.`{TableName}` ")
                builder.Append("(")
                builder.Append($"`{ColNames.ID}` int(11) NOT NULL AUTO_INCREMENT COMMENT '维修日志索引',")
                builder.Append($"`{ColNames.ProductID}` int(11) Not NULL COMMENT '维修产品索引',")
                builder.Append($"`{ColNames.StationID}` int(11) Not NULL COMMENT '站位索引',")
                builder.Append($"`{ColNames.OrderID}` int(11) Not NULL COMMENT '订单索引',")
                builder.Append($"`{ColNames.TestLogID}` int(11) Not NULL COMMENT '测试记录索引',")
                builder.Append($"`{ColNames.DUT_SN}` varchar(64) NOT NULL COMMENT '维修产品条码',")
                builder.Append($"`{ColNames.TestPlan}` varchar(64) DEFAULT NULL COMMENT '测试流程名称',")
                builder.Append($"`{ColNames.FailSteps}` varchar(254) DEFAULT NULL COMMENT '错误步骤',")
                builder.Append($"`{ColNames.FailMsg}` varchar(254) DEFAULT NULL COMMENT '错误提示信息',")
                builder.Append($"`{ColNames.ErrCode}` varchar(32) DEFAULT NULL COMMENT '产品错误代码',")
                builder.Append($"`{ColNames.RepairDate}` datetime NOT NULL DEFAULT current_timestamp() COMMENT '维修产品日期',")
                builder.Append($"`{ColNames.UpdateTime}` datetime NOT NULL DEFAULT current_timestamp() COMMENT '更新时间',")
                builder.Append($"`{ColNames.RepairType}` int(11) NOT NULL COMMENT '维修类型索引',")
                builder.Append($"`{ColNames.RepairReason}` int(11) NOT NULL COMMENT '维修原因索引',")
                builder.Append($"`{ColNames.RepairSource}` int(11) NOT NULL COMMENT '维修来源索引',")
                builder.Append($"`{ColNames.DocuNumber}` varchar(64) DEFAULT NULL COMMENT '返修来源订单号',")
                builder.Append($"`{ColNames.RepairComment}` varchar(254) DEFAULT NULL COMMENT '维修人工注释',")
                builder.Append($"`{ColNames.RepairResult}` int(11) NOT NULL DEFAULT 0 COMMENT '维修产品结果',")
                builder.Append($"`{ColNames.ProductImg1}` varchar(64) DEFAULT NULL COMMENT '产品图像文件名1',")
                builder.Append($"`{ColNames.ProductImg2}` varchar(64) DEFAULT NULL COMMENT '产品图像文件名2',")
                builder.Append($"`{ColNames.ProductImg3}` varchar(64) DEFAULT NULL COMMENT '产品图像文件名3',")
                builder.Append($"`{ColNames.ProductImg4}` varchar(64) DEFAULT NULL COMMENT '产品图像文件名4',")
                builder.Append($"PRIMARY KEY (`{ColNames.ID}`) ")
                builder.Append(")")
                builder.Append("ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;")
            Else
                Throw New Exception($"{TableName}-Invalid db type :{dbType}")
            End If

            Return builder.ToString()
        End Function
    End Class
End NameSpace