From a48026b8a0c952bb84065abaf164eb4763537066 Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期四, 16 十一月 2023 14:33:59 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS --- response/report_forms_response.go | 4 ++ controllers/report_forms_controller.go | 69 ++++++++++++++++++++-------------- models/location_product_amount.go | 8 +++- docs/swagger.yaml | 9 ++++ docs/docs.go | 15 +++++++ docs/swagger.json | 13 ++++++ 6 files changed, 88 insertions(+), 30 deletions(-) diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go index d7bccab..a15025a 100644 --- a/controllers/report_forms_controller.go +++ b/controllers/report_forms_controller.go @@ -163,42 +163,55 @@ } //鑾峰彇鎿嶄綔璇︽儏 detailsSearch := models.NewOperationDetailsSearch() - if params.PageInfo.Check() { - detailsSearch.SetPage(params.Page, params.PageSize) + var ( + result []*response.InventoryHistory + total int64 + ) + detailsSearch.Orm = detailsSearch.Orm.Model(&models.OperationDetails{}). + Select("wms_operation.number, wms_operation.updated_at as date, material.name as product_name, wms_operation.from_location_id,"+ + "wms_operation.to_location_id, wms_operation_details.amount, material.unit, wms_operation.contacter_name as contacted_name,"+ + "wms_operation.base_operation_type, material.weight, wms_operation_details.product_id"). + Joins("left join wms_operation on wms_operation_details.operation_id = wms_operation.id"). + Joins("left join material on wms_operation_details.product_id = material.id"). + Where("wms_operation.status = ?", constvar.OperationStatus_Finish).Order("wms_operation.created_at desc") + if params.ProduceId != "" { + detailsSearch.Orm = detailsSearch.Orm.Where("wms_operation_details.product_id = ?", params.ProduceId) } - details, total, err := detailsSearch.SetPreload(true).SetProductId(params.ProduceId).Find() + if params.BaseOperationType != 0 { + detailsSearch.Orm = detailsSearch.Orm.Where("wms_operation.base_operation_type = ?", params.BaseOperationType) + } + + err := detailsSearch.Orm.Count(&total).Error if err != nil { - util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鎿嶄綔璇︽儏澶辫触") + util.ResponseFormat(c, code.RequestParamError, "鏌ヨtotal澶辫触") return } - var operationIds []int - for _, detail := range details { - operationIds = append(operationIds, detail.OperationID) + if params.Page*params.PageSize > 0 { + detailsSearch.Orm = detailsSearch.Orm.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize) } - //鑾峰彇宸插畬鎴愮殑鎿嶄綔璁板綍 - operations, err := models.NewOperationSearch().SetIds(operationIds).SetBaseOperationType(params.BaseOperationType). - SetStatus(constvar.OperationStatus_Finish).FindNotTotal() + + err = detailsSearch.Orm.Find(&result).Error if err != nil { - util.ResponseFormat(c, code.RequestParamError, "鏌ヨ鎿嶄綔璁板綍澶辫触") + util.ResponseFormat(c, code.RequestParamError, fmt.Errorf("鏌ヨ鎿嶄綔鏄庣粏澶辫触: %v", err)) return } - var result []response.InventoryHistory - for _, detail := range details { - var resp response.InventoryHistory - resp.Amount = detail.Amount - resp.Unit = detail.Product.Unit - resp.ProductName = detail.Product.Name - for _, operation := range operations { - if detail.OperationID == operation.Id { - resp.Number = operation.Number - resp.Date = operation.UpdateTime - resp.Status = "瀹屾垚" - resp.ContactedName = operation.ContacterName - resp.FromLocation = operation.FromLocation.Name - resp.ToLocation = operation.ToLocation.Name - resp.BaseOperationType = operation.BaseOperationType - result = append(result, resp) - break + var locationIds []int + for _, history := range result { + locationIds = append(locationIds, history.FromLocationId, history.ToLocationId) + } + locations, err := models.NewLocationSearch().SetIds(locationIds).FindNotTotal() + if err != nil { + util.ResponseFormat(c, code.RequestParamError, fmt.Errorf("鏌ヨ浣嶇疆澶辫触: %v", err)) + return + } + for _, history := range result { + history.Status = "瀹屾垚" + for _, location := range locations { + if history.ToLocationId == location.Id { + history.ToLocation = location.Name + } + if history.FromLocationId == location.Id { + history.FromLocation = location.Name } } } diff --git a/docs/docs.go b/docs/docs.go index 73253d7..fba7780 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -4519,8 +4519,14 @@ "description": "婧愪綅缃�", "type": "string" }, + "fromLocationId": { + "type": "integer" + }, "number": { "description": "鍗曞彿", + "type": "string" + }, + "productId": { "type": "string" }, "productName": { @@ -4535,9 +4541,16 @@ "description": "鐩爣浣嶇疆", "type": "string" }, + "toLocationId": { + "type": "integer" + }, "unit": { "description": "鍗曚綅", "type": "string" + }, + "weight": { + "description": "閲嶉噺", + "type": "number" } } }, @@ -4639,6 +4652,8 @@ Description: "", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", } func init() { diff --git a/docs/swagger.json b/docs/swagger.json index bfa1ebf..cfb93c0 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -4507,8 +4507,14 @@ "description": "婧愪綅缃�", "type": "string" }, + "fromLocationId": { + "type": "integer" + }, "number": { "description": "鍗曞彿", + "type": "string" + }, + "productId": { "type": "string" }, "productName": { @@ -4523,9 +4529,16 @@ "description": "鐩爣浣嶇疆", "type": "string" }, + "toLocationId": { + "type": "integer" + }, "unit": { "description": "鍗曚綅", "type": "string" + }, + "weight": { + "description": "閲嶉噺", + "type": "number" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0072923..653c219 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1490,8 +1490,12 @@ fromLocation: description: 婧愪綅缃� type: string + fromLocationId: + type: integer number: description: 鍗曞彿 + type: string + productId: type: string productName: description: 浜у搧鍚嶇О @@ -1502,9 +1506,14 @@ toLocation: description: 鐩爣浣嶇疆 type: string + toLocationId: + type: integer unit: description: 鍗曚綅 type: string + weight: + description: 閲嶉噺 + type: number type: object response.LocationForms: properties: diff --git a/models/location_product_amount.go b/models/location_product_amount.go index 94cf597..dc1d0c3 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"` + 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:搴撳瓨鏁伴噺"` //搴撳瓨鏁伴噺 @@ -124,7 +124,11 @@ } if slf.Keyword != "" { - db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) + db = db.Joins("left join wms_location on wms_location_product_amount.location_id = wms_location.id"). + Joins("left join material on wms_location_product_amount.product_id = material.id"). + Joins("left join wms_product_category on wms_location_product_amount.product_category_id = wms_product_category.id"). + Where("wms_location.name like ?", "%"+slf.Keyword+"%").Or("material.name like ?", "%"+slf.Keyword+"%"). + Or("wms_product_category.name like ?", "%"+slf.Keyword+"%") } if slf.Preload { diff --git a/response/report_forms_response.go b/response/report_forms_response.go index 200903d..4a60e50 100644 --- a/response/report_forms_response.go +++ b/response/report_forms_response.go @@ -29,6 +29,10 @@ ContactedName string `json:"contactedName"` //瀹屾垚鑰� Status string `json:"status"` //鐘舵�� BaseOperationType constvar.BaseOperationType `json:"baseOperationType"` //鍩虹浣滀笟绫诲瀷 + Weight decimal.Decimal `json:"weight"` //閲嶉噺 + ProductId string `json:"productId"` + FromLocationId int `json:"fromLocationId"` + ToLocationId int `json:"toLocationId"` } type LocationForms struct { -- Gitblit v1.8.0