
Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    Public Class StationPacketReleaseLogTable
        Enum ColNames
            ''' <summary>
            ''' 工艺站包索引
            ''' </summary>
            ID

            ''' <summary>
            ''' 项目索引
            ''' </summary>
            ProjectID

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

            ''' <summary>
            ''' 创建时间
            ''' </summary>
            CreateTime

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

            ''' <summary>
            ''' 当前包名
            ''' </summary>
            PacketName

            ''' <summary>
            ''' 当前包MD5值
            ''' </summary>
            PacketMd5

            ''' <summary>
            ''' 记录本版本更改内容
            ''' </summary>
            Description


            ''' <summary>
            ''' 当前包是否有效
            ''' </summary>
            IsValid

            ''' <summary>
            ''' 登录用户索引
            ''' </summary>
            UserID

            ''' <summary>
            ''' 登录用户名称
            ''' </summary>
            UserName

            ''' <summary>
            ''' 发布电脑的公网IP
            ''' </summary>
            PublicIP

            ''' <summary>
            ''' 发布电脑用户名
            ''' </summary>
            ComputerName

            ''' <summary>
            ''' 发布电脑的SID
            ''' </summary>
            SID

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


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

        ''' <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.ProjectID}` int(11) NOT NULL COMMENT '项目ID',")
                builder.Append($"`{ColNames.StationID}` int(11) 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.Description}` text NOT NULL COMMENT '版本说明',")
                builder.Append($"`{ColNames.Remark}` varchar(128) DEFAULT NULL COMMENT ' 备注',")
                builder.Append($"`{ColNames.PacketName}` varchar(128) NOT NULL COMMENT '工艺站包包名',")
                builder.Append($"`{ColNames.PacketMd5}` varchar(32) NOT NULL COMMENT '工艺站包MD5值',")
                builder.Append($"`{ColNames.IsValid}` tinyint(4) NOT NULL DEFAULT 1 COMMENT '是否有效',")

                builder.Append($"`{ColNames.UserID}` int(11) NOT NULL COMMENT '登录用户索引',")
                builder.Append($"`{ColNames.UserName}` varchar(254) NOT NULL COMMENT '登录用户名称',")
                builder.Append($"`{ColNames.PublicIP}` varchar(64) NOT NULL COMMENT '发布电脑的公网IP',")
                builder.Append($"`{ColNames.ComputerName}` varchar(254) NOT NULL COMMENT '发布电脑用户名',")
                builder.Append($"`{ColNames.SID}` varchar(64) NOT NULL COMMENT '发布电脑的SID',")

                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

