From f2cdd37d118b4c1f55c21ccdd511c0e6ccec9208 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期二, 19 九月 2023 19:56:06 +0800 Subject: [PATCH] 1.获取入库列表、修改入库信息接口服务。 --- models/location.go | 39 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 38 insertions(+), 1 deletions(-) diff --git a/models/location.go b/models/location.go index 41e6992..5bcffe7 100644 --- a/models/location.go +++ b/models/location.go @@ -16,7 +16,7 @@ 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:鏄惁閫�璐т綅缃�"` //鏄惁閫�璐т綅缃� @@ -77,6 +77,21 @@ 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{}) @@ -94,6 +109,17 @@ 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 @@ -246,3 +272,14 @@ 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 +} -- Gitblit v1.8.0