| | |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "strings" |
| | | "wms/constvar" |
| | | "wms/pkg/mysqlx" |
| | | ) |
| | | |
| | | type ( |
| | | // Warehouse 部门信息 |
| | | // Warehouse 仓库 |
| | | Warehouse struct { |
| | | WmsModel |
| | | Name string `json:"name" gorm:"index;type:varchar(255);not null;comment:仓库名称"` //仓库名称 |
| | | Active bool `json:"active" gorm:"type:tinyint(1);not null;comment:是否激活"` //是否启用,传true就行 |
| | | Code string `json:"code" binding:"required,min=1,max=5" gorm:"index;type:varchar(255);not null;comment:仓库编码"` //仓库编码 |
| | | PartnerID int `json:"partnerId" gorm:"type:int;not null;comment:合作伙伴id"` //合作伙伴id |
| | | BuyToResupply bool `json:"buyToResupply" gorm:"type:tinyint(1);not null;comment:是否购买补给"` //是否购买补给,已购买产品能够发送到此仓库 |
| | | ResupplyWhIdsStr string `json:"-" gorm:"column:resupply_wh_ids;type:varchar(255);not null;comment:补给来源仓库ID"` //补给来源仓库ID |
| | | ResupplyWhIds []string `json:"resupplyWhIds" gorm:"-"` //补给来源仓库ID |
| | | ResupplyWh []*Warehouse `json:"resupplyWh" gorm:"-"` //补给来源仓库 |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | Name string `json:"name" gorm:"index;type:varchar(255);not null;comment:仓库名称"` //仓库名称 |
| | | Active bool `json:"active" gorm:"type:tinyint(1);not null;comment:是否激活"` //是否启用,传true就行 |
| | | Code string `json:"code" gorm:"index;type:varchar(255);not null;comment:仓库编码"` //仓库编码 |
| | | PartnerID int `json:"partnerId" gorm:"type:int;not null;comment:合作伙伴id"` //合作伙伴id |
| | | BuyToResupply bool `json:"buyToResupply" gorm:"type:tinyint(1);not null;comment:是否购买补给"` //是否购买补给,已购买产品能够发送到此仓库 |
| | | ResupplyWhIdsStr string `json:"-" gorm:"column:resupply_wh_ids;type:varchar(255);not null;comment:补给来源仓库ID"` //补给来源仓库ID |
| | | ResupplyWhIds []string `json:"resupplyWhIds" gorm:"-"` //补给来源仓库ID |
| | | ResupplyWh []*Warehouse `json:"resupplyWh" gorm:"-"` //补给来源仓库 |
| | | CompanyId int `json:"companyId" gorm:"type:int;not null;comment:公司id"` |
| | | Company Company `json:"company" gorm:"foreignKey:CompanyId"` |
| | | Address string `json:"address" gorm:"type:varchar(512);comment:地址"` //地址 |
| | | InboundTransportation int `json:"inboundTransportation" gorm:"type:int;comment:入向运输"` //入向运输 |
| | | OutboundTransportation int `json:"outboundTransportation" gorm:"type:int;comment:出库运输"` //出库运输 |
| | | LocationId int `json:"locationId" gorm:"type:int;comment:位置id"` //默认位置id |
| | | WarehouseLocation string `json:"warehouseLocation" gorm:"-"` //库存位置 |
| | | Contacts string `json:"contacts" gorm:"type:varchar(255);comment:联系人"` //联系人 |
| | | FileTemplateCategoryIn constvar.FileTemplateCategory `json:"fileTemplateCategoryIn" gorm:"type:int(11);comment:入库模版种类"` |
| | | FileTemplateCategoryOut constvar.FileTemplateCategory `json:"fileTemplateCategoryOut" gorm:"type:int(11);comment:出库模版种类"` |
| | | OpenMonthStats constvar.BoolType `gorm:"type:int(11);default:2;comment:是否开启月度统计" json:"openMonthStats"` //是否开启月度统计 |
| | | } |
| | | |
| | | WarehouseSearch struct { |
| | |
| | | PageSize int |
| | | Keyword string |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | Codes []string |
| | | } |
| | | ) |
| | | |
| | | func (slf *Warehouse) TableName() string { |
| | | return "warehouse" |
| | | return "wms_warehouse" |
| | | } |
| | | |
| | | func (slf *Warehouse) BeforeCreate(tx *gorm.DB) (err error) { |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WarehouseSearch) SetID(id uint) *WarehouseSearch { |
| | | slf.ID = id |
| | | func (slf *WarehouseSearch) SetID(id int) *WarehouseSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WarehouseSearch) SetCode(code string) *WarehouseSearch { |
| | | slf.Code = code |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WarehouseSearch) SetCodes(codes []string) *WarehouseSearch { |
| | | slf.Codes = codes |
| | | return slf |
| | | } |
| | | |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WarehouseSearch) SetPreload(preload bool) *WarehouseSearch { |
| | | slf.Preload = preload |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WarehouseSearch) SetOpenMonthStats(open constvar.BoolType) *WarehouseSearch { |
| | | slf.OpenMonthStats = open |
| | | return slf |
| | | } |
| | | |
| | | func (slf *WarehouseSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Table(slf.TableName()) |
| | | |
| | | if slf.ID != 0 { |
| | | db = db.Where("id = ?", slf.ID) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | |
| | | if slf.Order != "" { |
| | |
| | | if slf.Keyword != "" { |
| | | db = db.Where("name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | } |
| | | |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Preload("Company") |
| | | } |
| | | |
| | | if slf.Code != "" { |
| | | db = db.Where("code = ?", slf.Code) |
| | | } |
| | | |
| | | if len(slf.Codes) > 0 { |
| | | db = db.Where("code in ?", slf.Codes) |
| | | } |
| | | |
| | | if slf.OpenMonthStats != 0 { |
| | | db = db.Where("open_month_stats = ?", slf.OpenMonthStats) |
| | | } |
| | | |
| | | return db |
| | |
| | | |
| | | func (slf *WarehouseSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&Warehouse{}).Error |
| | | return db.Unscoped().Delete(&Warehouse{}).Error |
| | | } |
| | | |
| | | func (slf *WarehouseSearch) First() (*Warehouse, error) { |