From 97f8c17ef33e511d515164f1b1f00dd0fb9cd01f Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期三, 18 十月 2023 09:56:19 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS --- models/operation_type.go | 9 +++ response/report_forms_response.go | 18 +++--- controllers/report_forms_controller.go | 5 + models/material.go | 2 controllers/warehouse.go | 56 +++++++++++++++--- docs/swagger.yaml | 10 ++- docs/docs.go | 18 +++-- docs/swagger.json | 16 ++-- 8 files changed, 93 insertions(+), 41 deletions(-) diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go index d9ea817..db62c73 100644 --- a/controllers/report_forms_controller.go +++ b/controllers/report_forms_controller.go @@ -134,7 +134,7 @@ for _, detail := range details { operationIds = append(operationIds, detail.OperationID) } - //鑾峰彇鎿嶄綔璁板綍 + //鑾峰彇宸插畬鎴愮殑鎿嶄綔璁板綍 operations, err := models.NewOperationSearch().SetIds(operationIds).SetStatus(constvar.OperationStatus_Finish).FindNotTotal() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鎿嶄綔璁板綍澶辫触") @@ -145,11 +145,12 @@ var resp response.InventoryHistory resp.Amount = detail.Amount resp.Unit = params.Unit + resp.ProductName = params.ProductName for _, operation := range operations { if detail.OperationID == operation.Id { resp.Number = operation.Number resp.Date = operation.UpdateTime - resp.BaseOperationType = operation.BaseOperationType + resp.Status = "瀹屾垚" resp.ContactedName = operation.ContacterName resp.FromLocation = operation.FromLocation.Name resp.ToLocation = operation.ToLocation.Name diff --git a/controllers/warehouse.go b/controllers/warehouse.go index 8606ee1..01c1ba3 100644 --- a/controllers/warehouse.go +++ b/controllers/warehouse.go @@ -54,7 +54,36 @@ return } params.LocationId = locationId - if err := models.NewWarehouseSearch().Create(¶ms); err != nil { + err = models.WithTransaction(func(tx *gorm.DB) error { + err := models.NewWarehouseSearch().SetOrm(tx).Create(¶ms) + if err != nil { + return err + } + //鍒涘缓涓変釜榛樿鎿嶄綔绫诲瀷 + var types []*models.OperationType + inType := &models.OperationType{ + Name: params.Name + "-鍏ュ簱", + BaseOperationType: constvar.BaseOperationTypeIncoming, + WarehouseId: params.Id, + } + types = append(types, inType) + outType := &models.OperationType{ + Name: params.Name + "-鍑哄簱", + BaseOperationType: constvar.BaseOperationTypeOutgoing, + WarehouseId: params.Id, + } + types = append(types, outType) + internalType := &models.OperationType{ + Name: params.Name + "-鍐呴儴璋冩嫧", + BaseOperationType: constvar.BaseOperationTypeInternal, + WarehouseId: params.Id, + } + types = append(types, internalType) + err = models.NewOperationTypeSearch().SetOrm(tx).CreateBatch(types) + return err + }) + if err != nil { + _ = models.NewLocationSearch().SetID(locationId).Delete() logx.Errorf("warehouse create err: %v", err) util.ResponseFormat(c, code.SaveFail, "鎻掑叆澶辫触") return @@ -174,22 +203,31 @@ return } - //鍒犻櫎浣嶇疆淇℃伅 first, err := models.NewWarehouseSearch().SetID(id).First() if err != nil { util.ResponseFormat(c, code.RequestParamError, "鑾峰彇浠撳簱淇℃伅澶辫触") return } - err = models.NewLocationSearch().SetID(first.LocationId).Delete() + err = models.WithTransaction(func(tx *gorm.DB) error { + //鍒犻櫎浣嶇疆淇℃伅 + err = models.NewLocationSearch().SetOrm(tx).SetJointName(first.Code).Delete() + if err != nil { + return err + } + //鍒犻櫎鎿嶄綔绫诲瀷 + err = models.NewOperationTypeSearch().SetOrm(tx).SetWarehouseId(first.Id).Delete() + if err != nil { + return err + } + //鍒犻櫎浠撳簱 + err = models.NewWarehouseSearch().SetOrm(tx).SetID(id).Delete() + return err + }) if err != nil { - util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎浣嶇疆淇℃伅澶辫触") + util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎浠撳簱澶辫触") return } - err = models.NewWarehouseSearch().SetID(id).Delete() - if err != nil { - util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎浠撳簱淇℃伅澶辫触") - return - } + util.ResponseFormat(c, code.UpdateSuccess, "鍒犻櫎鎴愬姛") } diff --git a/docs/docs.go b/docs/docs.go index 1fdd00a..d00b1a0 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -3570,14 +3570,6 @@ "description": "鏁伴噺", "type": "number" }, - "baseOperationType": { - "description": "鍩虹浣滀笟绫诲瀷", - "allOf": [ - { - "$ref": "#/definitions/constvar.BaseOperationType" - } - ] - }, "contactedName": { "description": "瀹屾垚鑰�", "type": "string" @@ -3592,6 +3584,14 @@ }, "number": { "description": "鍗曞彿", + "type": "string" + }, + "productName": { + "description": "浜у搧鍚嶇О", + "type": "string" + }, + "status": { + "description": "鐘舵��", "type": "string" }, "toLocation": { @@ -3702,6 +3702,8 @@ Description: "", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { diff --git a/docs/swagger.json b/docs/swagger.json index 95777bf..21bebce 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -3558,14 +3558,6 @@ "description": "鏁伴噺", "type": "number" }, - "baseOperationType": { - "description": "鍩虹浣滀笟绫诲瀷", - "allOf": [ - { - "$ref": "#/definitions/constvar.BaseOperationType" - } - ] - }, "contactedName": { "description": "瀹屾垚鑰�", "type": "string" @@ -3582,6 +3574,14 @@ "description": "鍗曞彿", "type": "string" }, + "productName": { + "description": "浜у搧鍚嶇О", + "type": "string" + }, + "status": { + "description": "鐘舵��", + "type": "string" + }, "toLocation": { "description": "鐩爣浣嶇疆", "type": "string" diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 04865e9..9d205d5 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1173,10 +1173,6 @@ amount: description: 鏁伴噺 type: number - baseOperationType: - allOf: - - $ref: '#/definitions/constvar.BaseOperationType' - description: 鍩虹浣滀笟绫诲瀷 contactedName: description: 瀹屾垚鑰� type: string @@ -1189,6 +1185,12 @@ number: description: 鍗曞彿 type: string + productName: + description: 浜у搧鍚嶇О + type: string + status: + description: 鐘舵�� + type: string toLocation: description: 鐩爣浣嶇疆 type: string diff --git a/models/material.go b/models/material.go index 77f3181..7fc8138 100644 --- a/models/material.go +++ b/models/material.go @@ -12,7 +12,7 @@ // Material 鐗╂枡 Material struct { BaseModelString - Name string `gorm:"unique;type:varchar(191);not null;comment:鐗╂枡鍚嶇О" json:"name"` //鐗╂枡鍚嶇О + Name string `gorm:"type:varchar(191);not null;comment:鐗╂枡鍚嶇О" json:"name"` //鐗╂枡鍚嶇О //MaterialType constvar.ProductType `gorm:"index;type:int(11);comment:鐗╂枡绫诲瀷(鏁板瓧)" json:"materialType"` Model constvar.MaterialMode `gorm:"type:varchar(191);not null;comment:鐗╂枡绫诲瀷(瀛楃涓�)" json:"model"` //鐗╂枡绫诲瀷(瀛楃涓�) //Explain string `gorm:"type:varchar(512);comment:缂栧彿璇存槑" json:"explain"` diff --git a/models/operation_type.go b/models/operation_type.go index 26842f7..4c5f86a 100644 --- a/models/operation_type.go +++ b/models/operation_type.go @@ -103,6 +103,11 @@ return slf } +func (slf *OperationTypeSearch) SetWarehouseId(warehouseId int) *OperationTypeSearch { + slf.WarehouseId = warehouseId + return slf +} + func (slf *OperationTypeSearch) build() *gorm.DB { var db = slf.Orm.Model(&OperationType{}) @@ -126,6 +131,10 @@ db = db.Preload("Company").Preload("Warehouse").Preload("DefaultLocationSrc").Preload("DefaultLocationDest") } + if slf.WarehouseId > 0 { + db = db.Where("warehouse_id = ?", slf.WarehouseId) + } + return db } diff --git a/response/report_forms_response.go b/response/report_forms_response.go index 63ee819..8bf283c 100644 --- a/response/report_forms_response.go +++ b/response/report_forms_response.go @@ -2,7 +2,6 @@ import ( "github.com/shopspring/decimal" - "wms/constvar" ) type InventoryForms struct { @@ -19,14 +18,15 @@ } type InventoryHistory struct { - Number string `json:"number"` //鍗曞彿 - Date string `json:"date"` //鏃ユ湡 - FromLocation string `json:"fromLocation"` //婧愪綅缃� - ToLocation string `json:"toLocation"` //鐩爣浣嶇疆 - Amount decimal.Decimal `json:"amount"` //鏁伴噺 - Unit string `json:"unit"` //鍗曚綅 - ContactedName string `json:"contactedName"` //瀹屾垚鑰� - BaseOperationType constvar.BaseOperationType `json:"baseOperationType"` //鍩虹浣滀笟绫诲瀷 + Number string `json:"number"` //鍗曞彿 + Date string `json:"date"` //鏃ユ湡 + ProductName string `json:"productName"` //浜у搧鍚嶇О + FromLocation string `json:"fromLocation"` //婧愪綅缃� + ToLocation string `json:"toLocation"` //鐩爣浣嶇疆 + Amount decimal.Decimal `json:"amount"` //鏁伴噺 + Unit string `json:"unit"` //鍗曚綅 + ContactedName string `json:"contactedName"` //瀹屾垚鑰� + Status string `json:"status"` //鐘舵�� } type LocationForms struct { -- Gitblit v1.8.0