From 81827a26b91b07c997716f5f595e9e3121c18cf5 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期五, 17 十一月 2023 18:09:11 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS --- controllers/product_controller.go | 22 +++++++++- models/product_category.go | 11 +++-- controllers/report_forms_controller.go | 2 models/location_product_amount.go | 33 ++++++++++++++++ 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index 054b4ca..3a40e59 100644 --- a/controllers/product_controller.go +++ b/controllers/product_controller.go @@ -214,6 +214,22 @@ return } + //鏇存柊鍦ㄥ簱鐨勪骇鍝佺被鍨� + if params.CategoryId > 0 { + find, _ := models.NewLocationProductAmountSearch().SetProductId(params.ID).Find() + if len(find) > 0 { + var ids []int + for _, f := range find { + if f.ProductCategoryID != params.CategoryId { + ids = append(ids, f.Id) + } + } + m := make(map[string]interface{}) + m["productCategoryId"] = params.CategoryId + _ = models.NewLocationProductAmountSearch().SetIds(ids).UpdateByMap(m) + } + } + materialAttachmentList := []*models.MaterialAttachment{} for _, v := range params.AttachmentIDs { ma := &models.MaterialAttachment{MaterialID: params.ID, AttachmentID: v} @@ -318,7 +334,7 @@ return } - first, err := models.NewProductCategorySearch().SetID(cast.ToUint(id)).First() + first, err := models.NewProductCategorySearch().SetID(cast.ToInt(id)).First() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鏌ユ壘澶辫触") return @@ -343,7 +359,7 @@ util.ResponseFormat(c, code.RequestParamError, "浜у搧绫诲瀷鍚嶇О涓嶈兘涓虹┖") return } - err := models.NewProductCategorySearch().SetID(params.ID).Save(¶ms) + err := models.NewProductCategorySearch().SetID(params.Id).Save(¶ms) if err != nil { util.ResponseFormat(c, code.RequestParamError, "浜у搧绫诲瀷淇℃伅鏇存柊澶辫触") return @@ -364,7 +380,7 @@ util.ResponseFormat(c, code.RequestParamError, "鏃犳晥id") return } - err := models.NewProductCategorySearch().SetID(cast.ToUint(id)).Delete() + err := models.NewProductCategorySearch().SetID(cast.ToInt(id)).Delete() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎澶辫触") return diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go index a15025a..ca58506 100644 --- a/controllers/report_forms_controller.go +++ b/controllers/report_forms_controller.go @@ -236,7 +236,7 @@ ids = append(ids, params.LocationId) } else { //鏌ヨ浣嶇疆 - locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).FindAll() + locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).SetType(3).FindAll() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浣嶇疆澶辫触") return diff --git a/models/location_product_amount.go b/models/location_product_amount.go index dc1d0c3..4f1af2b 100644 --- a/models/location_product_amount.go +++ b/models/location_product_amount.go @@ -17,7 +17,7 @@ LocationId int `json:"locationId" gorm:"type:int;not null;comment:浣嶇疆id"` //浣嶇疆id Location Location `json:"location" gorm:"foreignKey:LocationId;references:id"` ProductCategoryID int `json:"productCategoryId" gorm:"type:int;not null;comment:浜у搧绉嶇被id"` //浜у搧绉嶇被id - ProductCategory ProductCategory `json:"productCategory" gorm:"foreignKey:ProductCategoryID;references:ID"` + ProductCategory ProductCategory `json:"productCategory" gorm:"foreignKey:ProductCategoryID;references:Id"` ProductId string `json:"productId" gorm:"type:varchar(191);not null;comment:浜у搧id"` //浜у搧id Product Material `json:"product" gorm:"foreignKey:ProductId;references:ID"` Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:搴撳瓨鏁伴噺"` //搴撳瓨鏁伴噺 @@ -35,6 +35,7 @@ //LocationProductIds []int LocationIds []int ProductIds []string + Ids []int } LocationProductAmountWithOperation struct { @@ -80,6 +81,11 @@ func (slf *LocationProductAmountSearch) SetID(id int) *LocationProductAmountSearch { slf.Id = id + return slf +} + +func (slf *LocationProductAmountSearch) SetIds(ids []int) *LocationProductAmountSearch { + slf.Ids = ids return slf } @@ -151,6 +157,10 @@ if slf.ProductId != "" { db = db.Where("product_id=?", slf.ProductId) + } + + if len(slf.Ids) > 0 { + db = db.Where("id in (?)", slf.Ids) } return db @@ -247,3 +257,24 @@ return record, db.First(&record) } + +func (slf *LocationProductAmountSearch) Count() (int64, error) { + var ( + total int64 + db = slf.build() + ) + err := db.Count(&total).Error + return total, err +} + +func (slf *LocationProductAmountSearch) UpdateByMap(upMap map[string]interface{}) error { + var ( + db = slf.build() + ) + + if err := db.Updates(upMap).Error; err != nil { + return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap) + } + + return nil +} diff --git a/models/product_category.go b/models/product_category.go index 62f611d..af90da8 100644 --- a/models/product_category.go +++ b/models/product_category.go @@ -10,7 +10,8 @@ type ( // ProductCategory 浜у搧鍒嗙被 ProductCategory struct { - BaseModelInt + WmsModel + Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` Name string `json:"name" gorm:"index;type:varchar(255);not null;comment:鍒嗙被鍚嶇О"` //鍒嗙被鍚嶇О ParentId int `json:"parentId" gorm:"type:int;comment:涓婄骇鍒嗙被id"` //涓婄骇id RouteId int `json:"routeId" gorm:"type:int;comment:璺嚎id"` //璺嚎id @@ -55,8 +56,8 @@ return slf } -func (slf *ProductCategorySearch) SetID(id uint) *ProductCategorySearch { - slf.ID = id +func (slf *ProductCategorySearch) SetID(id int) *ProductCategorySearch { + slf.Id = id return slf } @@ -82,8 +83,8 @@ func (slf *ProductCategorySearch) build() *gorm.DB { var db = slf.Orm.Model(&ProductCategory{}) - if slf.ID != 0 { - db = db.Where("id = ?", slf.ID) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) } if slf.Order != "" { -- Gitblit v1.8.0