Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    ''' <summary>
    ''' 产品工艺站总表
    ''' </summary>
    Public Class StationListTable

        Enum ColNames
            ''' <summary>
            ''' 工艺站索引
            ''' </summary>
            ID
            ''' <summary>
            ''' 项目索引
            ''' </summary>
            ProjectID
            ''' <summary>
            ''' 工艺站名称
            ''' </summary>
            StationName
            ''' <summary>
            ''' 工艺站类型
            ''' </summary>
            StationType
            ''' <summary>
            ''' 工艺站序号,从1开始
            ''' </summary>
            ArtworkOrder
            ''' <summary>
            ''' Sn总表序号
            ''' </summary>
            SnListOrder
            ''' <summary>
            ''' 工艺站描述
            ''' </summary>
            StationDesc

            ''' <summary>
            ''' 最后更新日期(重复字段等待删除)
            ''' </summary>
            LastUpdateDate

            ''' <summary>
            ''' 修改日期
            ''' </summary>
            UpdateTime

            ''' <summary>
            ''' 测试记录表名
            ''' </summary>
            LogTableName
            ''' <summary>
            ''' 预览图片
            ''' </summary>
            PreviewImage
            ''' <summary>
            ''' 备注
            ''' </summary>
            Remark
            ''' <summary>
            ''' 最新测试包名
            ''' </summary>
            PacketName

            ''' <summary>
            ''' 最新包MD5
            ''' </summary>
            PacketMd5

            ''' <summary>
            ''' 当前站位是否有效
            ''' </summary>
            Isvalid
            ''' <summary>
            ''' 站位条码生成规则，1系统生成，2客户录入
            ''' </summary>
            SnType

            ''' <summary>
            ''' 编辑密码
            ''' </summary>
            EditPwd

            ''' <summary>
            ''' 发布密码
            ''' </summary>
            ReleasePwd
        End Enum

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

        ''' <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.StationName}` varchar(128) NOT NULL COMMENT '工艺站名',")
                builder.Append($"`{ColNames.StationType}` varchar(128) NOT NULL COMMENT '工艺站类型',")
                builder.Append($"`{ColNames.ArtworkOrder}` int(11) NOT NULL COMMENT '测试站位序号',")
                builder.Append($"`{ColNames.SnListOrder}` int(11) NOT NULL COMMENT 'SN总表序号',")
                builder.Append($"`{ColNames.StationDesc}` varchar(128) DEFAULT NULL COMMENT '站位描述',")
                builder.Append($"`{ColNames.LastUpdateDate}` datetime DEFAULT NULL COMMENT '最后一次更新日期时间',")
                builder.Append($"`{ColNames.UpdateTime}` datetime NOT NULL DEFAULT current_timestamp() COMMENT '更新时间',")
                builder.Append($"`{ColNames.LogTableName}` varchar(128) DEFAULT NULL COMMENT '测试记录表名',")
                builder.Append($"`{ColNames.PreviewImage}` mediumblob DEFAULT NULL COMMENT '预览图片',")
                builder.Append($"`{ColNames.Remark}` varchar(128) DEFAULT NULL COMMENT ' 备注',")
                builder.Append($"`{ColNames.PacketName}` varchar(128) DEFAULT NULL COMMENT '最新测试包名',")
                builder.Append($"`{ColNames.PacketMd5}` varchar(32) DEFAULT NULL COMMENT '测试站包MD5值',")
                builder.Append($"`{ColNames.Isvalid}` tinyint(4) not NULL DEFAULT 1 COMMENT '是否有效',")
                builder.Append($"`{ColNames.SnType}` int(11) not NULL DEFAULT 1,")
                builder.Append($"`{ColNames.EditPwd}` varchar(32) DEFAULT NULL COMMENT '编辑密码',")
                builder.Append($"`{ColNames.ReleasePwd}` varchar(32) 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