Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    ''' <summary>
    ''' 用户操作记录总表
    ''' </summary>
    Public Class LogTable
        Enum ColNamesEnum
            ID
            ''' <summary>
            ''' 操作者
            ''' </summary>
            UserID
            ''' <summary>
            ''' 操作时间
            ''' </summary>
            DateTime
            ''' <summary>
            ''' 操作内容说明
            ''' </summary>
            Operation
        End Enum

        Public Shared Property TableName() As String = "TBL_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($"`{ColNamesEnum.ID}` int(11) Not NULL,")
                builder.Append($"`{ColNamesEnum.UserID}` int(11) DEFAULT NULL COMMENT '用户索引',")
                builder.Append($"`{ColNamesEnum.DateTime}` datetime DEFAULT NULL COMMENT '操作时间',")
                builder.Append($"`{ColNamesEnum.Operation}` varchar(254) DEFAULT NULL COMMENT '操作内容说明',")

                builder.Append($"PRIMARY KEY (`{ColNamesEnum.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
