| | |
| | | ParentId int `json:"parentId" gorm:"type:int;not null"` //上级id |
| | | CompanyId int `json:"companyId" gorm:"type:int;not null"` //公司id |
| | | Company Company `json:"company" gorm:"foreignKey:CompanyId"` //公司 |
| | | Type constvar.LocationType `json:"type" gorm:"type:tinyint;not null;comment:位置类型"` //位置类型 |
| | | Type constvar.LocationType `json:"type" gorm:"type:int(11);not null;comment:位置类型"` //位置类型 |
| | | CountFrequency int `json:"countFrequency" gorm:"type:tinyint;not null;comment:盘点频率(天)"` //盘点频率(天) |
| | | IsScrapLocation bool `json:"isScrapLocation" gorm:"type:tinyint;not null;comment:是否报废位置"` //是否报废位置 |
| | | IsReturnLocation bool `json:"isReturnLocation" gorm:"type:tinyint;not null;comment:是否退货位置"` //是否退货位置 |
| | |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationSearch) SetType(_type int) *LocationSearch { |
| | | slf.Type = constvar.LocationType(_type) |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationSearch) SetParentId(parentId int) *LocationSearch { |
| | | slf.ParentId = parentId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationSearch) SetCompanyId(companyId int) *LocationSearch { |
| | | slf.CompanyId = companyId |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&Location{}) |
| | | |
| | |
| | | |
| | | if slf.Name != "" { |
| | | db = db.Where("name = ?", slf.Name) |
| | | } |
| | | |
| | | if slf.Type != 0 { |
| | | db = db.Where("type=?", slf.Type) |
| | | } |
| | | |
| | | if slf.ParentId != 0 { |
| | | db = db.Where("parent_id=?", slf.ParentId) |
| | | } |
| | | if slf.CompanyId != 0 { |
| | | db = db.Where("company_id=?", slf.CompanyId) |
| | | } |
| | | |
| | | return db |
| | |
| | | |
| | | return records, nil |
| | | } |
| | | |
| | | func (slf *LocationSearch) FindAll() ([]*Location, error) { |
| | | var ( |
| | | records = make([]*Location, 0) |
| | | db = slf.build() |
| | | ) |
| | | if err := db.Find(&records); err != nil { |
| | | return records, fmt.Errorf("func FindAll err: %v", err) |
| | | } |
| | | return records, nil |
| | | } |