Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    Public Class OrderInternalTable
        Enum ColNames
            ''' <summary>
            ''' 内部订单索引
            ''' </summary>
            ID

            ''' <summary>
            ''' 订单ID
            ''' </summary>
            OrderID

            ''' <summary>
            ''' 内部单号
            ''' </summary>
            InternalNo

            ''' <summary>
            ''' 订单所属公司索引
            ''' </summary>
            CompanyID

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

            ''' <summary>
            ''' 产品类型索引
            ''' </summary>
            ProductTypeID

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

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

            ''' <summary>
            ''' 目标产量
            ''' </summary>
            ObjectiveYield

            ''' <summary>
            ''' 累计目标产量
            ''' </summary>
            ObjectiveYieldTotal

            ''' <summary>
            ''' 订单状态
            ''' </summary>
            OrderStatus

            ''' <summary>
            ''' 交货时间
            ''' </summary>
            DeliveryTime

            ''' <summary>
            ''' 适用站位
            ''' </summary>
            Station

            ''' <summary>
            ''' 条码范围
            ''' </summary>
            BarCode
        End Enum


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

        ''' <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,")
                builder.Append($"`{ColNames.OrderID}` int(11) NOT NULL COMMENT '订单ID',")
                builder.Append($"`{ColNames.CompanyID}` int(11) NOT NULL COMMENT '订单所属公司索引',")
                builder.Append($"`{ColNames.ProductTypeID}` int(11) NOT NULL COMMENT '产品类型索引',")
                builder.Append($"`{ColNames.ProductID}` int(11) NOT NULL COMMENT '产品索引',")
                builder.Append($"`{ColNames.OrderStatus}` int(11) NOT NULL COMMENT '订单状态',")
                builder.Append($"`{ColNames.InternalNo}` varchar(64) 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.DeliveryTime}` datetime DEFAULT NULL COMMENT '交货时间',")
                builder.Append($"`{ColNames.ObjectiveYield}` int(11) DEFAULT NULL COMMENT '目标产量',")
                builder.Append($"`{ColNames.ObjectiveYieldTotal}` int(11) DEFAULT NULL COMMENT '累计目标产量',")
                builder.Append($"`{ColNames.Station}` varchar(64) DEFAULT NULL ,")
                builder.Append($"`{ColNames.BarCode}` varchar(254) DEFAULT NULL ,")
                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