Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    ''' <summary>
    ''' 不良代码类型表
    ''' </summary>
    Public Class RejectsExplainTable

        Enum ColNames
            ''' <summary>
            ''' 索引
            ''' </summary>
            ID

            ''' <summary>
            ''' 所属维修分类索引
            ''' </summary>
            Matlab

            ''' <summary>
            ''' 名称
            ''' </summary>
            Introductions

            ''' <summary>
            ''' 创建日期
            ''' </summary>
            CreateTime

            ''' <summary>
            ''' 更新时间
            ''' </summary>
            UpdateTime

            ''' <summary>
            ''' 备注
            ''' </summary>
            Remark
        End Enum

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


        ''' <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.Matlab}` varchar(255) NOT NULL COMMENT '不良品代码',")
                builder.Append($"`{ColNames.Introductions}` varchar(255) NOT NULL COMMENT '不良品说明',")
                builder.Append($"`{ColNames.CreateTime}` datetime NOT NULL DEFAULT current_timestamp() COMMENT '创建时间',")
                builder.Append($"`{ColNames.UpdateTime}` datetime NOT NULL DEFAULT current_timestamp() COMMENT '更新时间',")
                builder.Append($"`{ColNames.Remark}` varchar(254) DEFAULT NULL COMMENT '备注',")
                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

