From a0d098663f4e5f099fcefa3ca2f4b544a76152c9 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期日, 07 四月 2024 15:53:49 +0800 Subject: [PATCH] location表增加仓库id字段 --- models/warehouse.go | 16 ++++++++-------- models/location.go | 6 ++++++ controllers/location.go | 15 ++++++++++++++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/controllers/location.go b/controllers/location.go index 327c689..ecd21c0 100644 --- a/controllers/location.go +++ b/controllers/location.go @@ -24,7 +24,7 @@ func (slf LocationController) AddLocation(c *gin.Context) { var params models.Location if err := c.BindJSON(¶ms); err != nil { - util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�:"+err.Error()) return } if err := slf.CheckLocation(params); err != nil { @@ -39,6 +39,19 @@ return } params.JointName = first.JointName + "/" + params.Name + if first.WarehouseId != 0 { + params.WarehouseId = first.Id + } else { + //鏍规嵁浠撳簱缂╁啓鏌ヨ浠撳簱 + houseCode := strings.Split(first.JointName, "/")[0] + warehouse, err := models.NewWarehouseSearch().SetCode(houseCode).First() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, err) + return + } + params.WarehouseId = warehouse.Id + } + } else { params.JointName = params.Name } diff --git a/models/location.go b/models/location.go index be55274..bcae4ac 100644 --- a/models/location.go +++ b/models/location.go @@ -27,6 +27,8 @@ NextCount string `json:"nextCount" gorm:"type:varchar(255);comment:涓嬫鐩樼偣"` //涓嬫鐩樼偣 JointName string `json:"jointName" gorm:"type:varchar(255);comment:鎷兼帴鍚嶇О"` //鎷兼帴鍚嶇О Children []*Location `json:"children" gorm:"-"` + WarehouseId int `json:"warehouseId" gorm:"type:int;not null;default:0;comment:浠撳簱ID"` //浠撳簱ID + Warehouse Warehouse `json:"warehouse" gorm:"foreignKey:WarehouseId"` //浠撳簱 } LocationSearch struct { @@ -164,6 +166,10 @@ db = db.Where("is_scrap_location = ?", slf.IsScrapLocation) } + if slf.Preload { + db = db.Preload("Warehouse") + } + return db } diff --git a/models/warehouse.go b/models/warehouse.go index 0b1c74f..df467d2 100644 --- a/models/warehouse.go +++ b/models/warehouse.go @@ -12,14 +12,14 @@ Warehouse struct { WmsModel 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" 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:"-"` //琛ョ粰鏉ユ簮浠撳簱 + 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:鍦板潃"` //鍦板潃 -- Gitblit v1.8.0