From 5c61bdb147458adbb0a87b27c2299f86f739da0a Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期一, 29 七月 2024 20:33:53 +0800 Subject: [PATCH] 新增出入库调拨操作时明细支持多单位传参 --- models/operation.go | 3 + docs/swagger.yaml | 8 ++++ request/operation.go | 4 ++ docs/docs.go | 12 ++++++ models/operation_details.go | 35 +++++++++++++++++ docs/swagger.json | 12 ++++++ 6 files changed, 73 insertions(+), 1 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 6d7e4cc..19463a0 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -5636,6 +5636,12 @@ "description": "鏄惁璋冩嫧浜х敓鐨勫嚭搴�", "type": "boolean" }, + "moreUnitList": { + "type": "array", + "items": { + "$ref": "#/definitions/models.UnitItems" + } + }, "operationId": { "description": "鎿嶄綔璁板綍id", "type": "integer" @@ -6947,6 +6953,12 @@ "description": "Unit string ` + "`" + `json:\"unit\"` + "`" + ` //鍗曚綅\nProduct models.Material ` + "`" + `json:\"product\" ` + "`" + ` // 浜у搧", "type": "integer" }, + "moreUnitList": { + "type": "array", + "items": { + "$ref": "#/definitions/models.UnitItems" + } + }, "productId": { "description": "浜у搧id", "type": "string" diff --git a/docs/swagger.json b/docs/swagger.json index 3bc9602..bd6c741 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -5625,6 +5625,12 @@ "description": "鏄惁璋冩嫧浜х敓鐨勫嚭搴�", "type": "boolean" }, + "moreUnitList": { + "type": "array", + "items": { + "$ref": "#/definitions/models.UnitItems" + } + }, "operationId": { "description": "鎿嶄綔璁板綍id", "type": "integer" @@ -6936,6 +6942,12 @@ "description": "Unit string `json:\"unit\"` //鍗曚綅\nProduct models.Material `json:\"product\" ` // 浜у搧", "type": "integer" }, + "moreUnitList": { + "type": "array", + "items": { + "$ref": "#/definitions/models.UnitItems" + } + }, "productId": { "description": "浜у搧id", "type": "string" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index e3e5cb4..0d08290 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1118,6 +1118,10 @@ isInternalOutput: description: 鏄惁璋冩嫧浜х敓鐨勫嚭搴� type: boolean + moreUnitList: + items: + $ref: '#/definitions/models.UnitItems' + type: array operationId: description: 鎿嶄綔璁板綍id type: integer @@ -2023,6 +2027,10 @@ Unit string `json:"unit"` //鍗曚綅 Product models.Material `json:"product" ` // 浜у搧 type: integer + moreUnitList: + items: + $ref: '#/definitions/models.UnitItems' + type: array productId: description: 浜у搧id type: string diff --git a/models/operation.go b/models/operation.go index 66a33be..a7a3f93 100644 --- a/models/operation.go +++ b/models/operation.go @@ -93,11 +93,12 @@ return &OperationSearch{Orm: mysqlx.GetDB()} } -func (slf *OperationSearch) BeforeCreate(tx *gorm.DB) { +func (slf *OperationSearch) BeforeCreate(tx *gorm.DB) error { for k := range slf.Details { slf.Details[k].BaseOperationType = slf.BaseOperationType slf.Details[k].DealerType = slf.DealerType } + return nil } func (slf *OperationSearch) SetOrm(tx *gorm.DB) *OperationSearch { diff --git a/models/operation_details.go b/models/operation_details.go index a00b670..f57c5b3 100644 --- a/models/operation_details.go +++ b/models/operation_details.go @@ -1,6 +1,7 @@ package models import ( + "encoding/json" "fmt" "github.com/shopspring/decimal" "gorm.io/gorm" @@ -39,6 +40,9 @@ // 鍢夎仈浠撳偍娣诲姞 SilkMarket銆丼ilkMarketClose SilkMarket string `json:"silkMarket" gorm:"type:varchar(255);comment:搴勫彛"` // 搴勫彛 SilkMarketClose string `json:"silkMarketClose" gorm:"type:varchar(10);comment:搴勫彛鍏抽棴"` // 搴勫彛鍏抽棴 + + MoreUnitList []UnitItems `json:"moreUnitList" gorm:"-"` + MoreUnitValue string `json:"-" gorm:"type:varchar(255);comment:澶氬崟浣嶅��"` } OperationDetailsSearch struct { @@ -62,6 +66,37 @@ return &OperationDetailsSearch{Orm: mysqlx.GetDB()} } +func (slf *OperationDetails) AfterFind(tx *gorm.DB) (err error) { + if slf.MoreUnitValue != "" { + var arr []UnitItems + err := json.Unmarshal([]byte(slf.MoreUnitValue), &arr) + if err != nil { + return err + } + slf.MoreUnitList = arr + } + + return +} + +func (slf *OperationDetails) BeforeCreate(tx *gorm.DB) (err error) { + if len(slf.MoreUnitList) != 0 { + items := make([]UnitItems, 0) + for k, item := range slf.MoreUnitList { + if item.Unit != "" && !item.Amount.IsZero() { + items = append(items, slf.MoreUnitList[k]) + } + } + + str, err := json.Marshal(items) + if err != nil { + return err + } + slf.MoreUnitValue = string(str) + } + return +} + func (slf *OperationDetailsSearch) SetOrm(tx *gorm.DB) *OperationDetailsSearch { slf.Orm = tx return slf diff --git a/request/operation.go b/request/operation.go index f01efd0..a88d06b 100644 --- a/request/operation.go +++ b/request/operation.go @@ -3,6 +3,7 @@ import ( "github.com/shopspring/decimal" "wms/constvar" + "wms/models" ) type AddOperation struct { @@ -62,6 +63,9 @@ SalePrice decimal.Decimal `json:"salePrice"` //閿�鍞崟浠� SilkMarket string `json:"silkMarket"` // 搴勫彛 SilkMarketClose string `json:"silkMarketClose"` // 搴勫彛鍏抽棴 + + MoreUnitList []models.UnitItems `json:"moreUnitList" gorm:"-"` + MoreUnitValue string `json:"-" gorm:"type:varchar(255);comment:澶氬崟浣嶅��"` } type OperationList struct { -- Gitblit v1.8.0