zhangqian
2023-11-15 03915064efe8fd7f222e4aac199af7e2d37deec6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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"
}