Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    Public Class ProductionPlanTable
        Enum ColNames
            ''' <summary>
            ''' 生产计划索引
            ''' </summary>
            ID

            ''' <summary>
            ''' 订单索引
            ''' </summary>
            OrderID

            ''' <summary>
            ''' 内部订单
            ''' </summary>
            OrderInternalID

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

            ''' <summary>
            ''' 产线索引
            ''' </summary>
            ProductionLineID

            ''' <summary>
            ''' 生产时间
            ''' </summary>
            ProductionTime

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

            ''' <summary>
            ''' 已完成产量
            ''' </summary>
            ActualOutput

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

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

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

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

        ''' <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.OrderID}` int(11) NOT NULL COMMENT '订单索引',")
                builder.Append($"`{ColNames.OrderInternalID}` int(11) NOT NULL COMMENT '内部单ID',")
                builder.Append($"`{ColNames.StationID}` int(11) NOT NULL COMMENT '工艺站ID',")
                builder.Append($"`{ColNames.ProductionLineID}` int(11) NOT NULL COMMENT '产线索引',")
                builder.Append($"`{ColNames.ProductionTime}` datetime NOT NULL COMMENT '生产时间',")
                builder.Append($"`{ColNames.UpdateTime}` datetime NOT NULL DEFAULT current_timestamp() COMMENT '更新时间',")
                builder.Append($"`{ColNames.ActualOutput}` int(11) NOT NULL COMMENT '已完成产量',")
                builder.Append($"`{ColNames.ObjectiveYield}` int(11) NOT NULL COMMENT '目标产量',")
                builder.Append($"`{ColNames.ObjectiveYieldTotal}` int(11) NOT NULL COMMENT '累计目标产量',")
                builder.Append($"`{ColNames.Remark}` varchar(255) 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