package test
|
|
import (
|
"github.com/shopspring/decimal"
|
)
|
|
// Material 结构体
|
type Material struct {
|
ID string
|
Name string `gorm:"type:varchar(191);not null;comment:物料名称" json:"name"`
|
MaterialType MaterialType `gorm:"index;type:int(11);comment:物料类型(数字)" json:"materialType"`
|
Model MaterialMode `gorm:"type:varchar(191);not null;comment:物料类型(字符串)" json:"model"`
|
Specs string `gorm:"type:varchar(191);comment:物料规格" json:"specs"`
|
Type string `gorm:"type:varchar(191);comment:物料型号" json:"type"`
|
MinInventory decimal.Decimal `gorm:"type:decimal(35,18);comment:最小库存" json:"minInventory"`
|
MaxInventory decimal.Decimal `gorm:"type:decimal(35,18);comment:最大库存" json:"maxInventory"`
|
Amount decimal.Decimal `gorm:"type:decimal(35,18);comment:数量" json:"amount"`
|
LockAmount decimal.Decimal `gorm:"type:decimal(35,18);default:0;comment:锁定数量" json:"lockAmount"`
|
Unit string `gorm:"type:varchar(100);comment:单位" json:"unit"`
|
TemplateID string `gorm:"type:varchar(191);comment:模板ID" json:"-"`
|
Status MaterialStatus `gorm:"type:int(11);comment:状态" json:"status"`
|
Supplier string `gorm:"type:varchar(191);comment:供应商" json:"supplier"`
|
PurchasePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:采购价格" json:"purchasePrice"`
|
PurchaseAheadDay int `gorm:"type:int(11);comment:采购提前期(天)" json:"purchaseAheadDay"`
|
ProduceAheadDay int `gorm:"type:int(11);comment:制造提前期(天)" json:"produceAheadDay"`
|
MinPurchaseAmount decimal.Decimal `gorm:"type:decimal(35,18);comment:最小采购量" json:"minPurchaseAmount"`
|
PurchaseType PurchaseType `gorm:"type:int(11);comment:采购类型" json:"purchaseType"`
|
SalePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:销售单价" json:"salePrice"`
|
CategoryName string `gorm:"type:varchar(255);comment:产品类别名称" json:"categoryName"` //产品类别名称
|
}
|
|
// PurchaseType 采购类型
|
type PurchaseType int
|
|
const (
|
PurchaseTypeOutSource PurchaseType = iota + 1 // 采购
|
PurchaseTypeSelf // 自制
|
PurchaseTypeEntrust // 委外
|
)
|
|
type MaterialStatus int
|
|
const (
|
MaterialStatusCreate MaterialStatus = iota // 新建
|
MaterialStatusActive // 启用
|
MaterialStatusInactive = -1 // 停用
|
)
|
|
// MaterialMode 物料类型(字符串)
|
type MaterialMode string
|
|
const (
|
MaterialModeRaw MaterialMode = "原材料"
|
MaterialModeSemi MaterialMode = "半成品"
|
MaterialModeFinished MaterialMode = "成品"
|
MaterialModeAuxiliary MaterialMode = "辅料" //辅料
|
MaterialModeConsumables MaterialMode = "耗材" //耗材
|
MaterialModeOther MaterialMode = "其他" //其他
|
)
|
|
func (t MaterialMode) Valid() bool {
|
if t != MaterialModeRaw &&
|
t != MaterialModeSemi &&
|
t != MaterialModeAuxiliary &&
|
t != MaterialModeConsumables &&
|
t != MaterialModeOther &&
|
t != MaterialModeFinished {
|
return false
|
}
|
return true
|
}
|
|
func (t MaterialMode) Type() MaterialType {
|
switch t {
|
case MaterialModeRaw:
|
return MaterialTypeRaw
|
case MaterialModeSemi:
|
return MaterialTypeSemi
|
case MaterialModeFinished:
|
return MaterialTypeFinished
|
}
|
return MaterialType(0)
|
}
|
|
// MaterialType 物料类型(数字)
|
type MaterialType int
|
|
const (
|
MaterialTypeRaw = iota + 1 // 原材料
|
MaterialTypeSemi // 半成品
|
MaterialTypeFinished // 成品
|
MaterialTypeAuxiliary //辅料
|
MaterialTypeConsumables //耗材
|
MaterialTypeOther //其他
|
)
|
|
func (t MaterialType) Valid() bool {
|
if t < MaterialTypeRaw ||
|
t > MaterialTypeFinished {
|
return false
|
}
|
return true
|
}
|
|
// TableName Product 表名
|
func (Material) TableName() string {
|
return "material"
|
}
|