From 69f0410081da54e6cea8a04a07fd0119a8edc623 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期六, 30 三月 2024 11:38:42 +0800 Subject: [PATCH] 采购单修改 --- api/v1/purchase/purchase.go | 86 +++++++---- model/purchase/response/purchase.go | 41 +++-- docs/swagger.yaml | 69 ++++++--- docs/docs.go | 94 +++++++++---- service/purchase/purchase.go | 13 + docs/swagger.json | 94 +++++++++---- 6 files changed, 263 insertions(+), 134 deletions(-) diff --git a/api/v1/purchase/purchase.go b/api/v1/purchase/purchase.go index e571258..b81fe5a 100644 --- a/api/v1/purchase/purchase.go +++ b/api/v1/purchase/purchase.go @@ -394,59 +394,75 @@ return } - operationInfos := make([]purchaseRes.OperationInfo, 0) + var operationInfos purchaseRes.OperationInfo + productInfos := make([]purchaseRes.ProductInfo, 0) + inWarehouseInfos := make([]purchaseRes.InWarehouseInfo, 0) + productMap := make(map[string]*purchaseRes.ProductInfo) if len(info.Operations) > 0 { for _, operation := range info.Operations { - var oi purchaseRes.OperationInfo - oi.Number = operation.ProductId - oi.Name = operation.ProductName - oi.OperationNumber = operation.Number - oi.Status = operation.Status - oi.Principal = data.Principal - oi.WarehouseName = data.Warehouse + var pi purchaseRes.ProductInfo + var iwi purchaseRes.InWarehouseInfo + if p, ok := productMap[operation.ProductId]; ok { + pi = *p + } + pi.Number = operation.ProductId + pi.Name = operation.ProductName + iwi.Number = operation.ProductId + iwi.Name = operation.ProductName + iwi.OperationNumber = operation.Number + iwi.Status = operation.Status + iwi.Principal = data.Principal + iwi.WarehouseName = data.Warehouse if operation.OverTime != "" { - oi.OverTime = operation.OverTime - oi.OverAmount = operation.Amount + iwi.OverTime = operation.OverTime + iwi.OverAmount = operation.Amount + pi.OverAmount = pi.OverAmount + operation.Amount } for _, products := range productList { if products.Product.Number == operation.ProductId { - oi.Amount = products.Amount - oi.PurchasePrice = products.Price - oi.Total = products.Total - oi.Unit = products.Product.Unit - oi.Specifications = products.Product.Specifications - oi.ModelNumber = products.Product.ModelNumber + pi.Amount = products.Amount + pi.PurchasePrice = products.Price + pi.Total = products.Total + pi.Unit = products.Product.Unit + pi.Specifications = products.Product.Specifications + pi.ModelNumber = products.Product.ModelNumber break } } for _, confirm := range confirmInfo { if operation.ProductId == confirm.ProductId { - oi.SendAmount = confirm.OverReceiveAmount.IntPart() + pi.SendAmount = confirm.OverReceiveAmount.IntPart() break } } - operationInfos = append(operationInfos, oi) + inWarehouseInfos = append(inWarehouseInfos, iwi) + productMap[operation.ProductId] = &pi } } else { for _, products := range productList { - var oi purchaseRes.OperationInfo - oi.Number = products.Product.Number - oi.Name = products.Product.Name - oi.Amount = products.Amount - oi.PurchasePrice = products.Price - oi.Total = products.Total - oi.Unit = products.Product.Unit - oi.Specifications = products.Product.Specifications - oi.ModelNumber = products.Product.ModelNumber + var pi purchaseRes.ProductInfo + pi.Number = products.Product.Number + pi.Name = products.Product.Name + pi.Amount = products.Amount + pi.PurchasePrice = products.Price + pi.Total = products.Total + pi.Unit = products.Product.Unit + pi.Specifications = products.Product.Specifications + pi.ModelNumber = products.Product.ModelNumber for _, confirm := range confirmInfo { if products.Product.Number == confirm.ProductId { - oi.SendAmount = confirm.OverReceiveAmount.IntPart() + pi.SendAmount = confirm.OverReceiveAmount.IntPart() break } } - operationInfos = append(operationInfos, oi) + productMap[pi.Number] = &pi } } + for _, productInfo := range productMap { + productInfos = append(productInfos, *productInfo) + } + operationInfos.InWarehouseInfos = inWarehouseInfos + operationInfos.ProductInfos = productInfos response.OkWithData(operationInfos, c) } @@ -739,13 +755,17 @@ } product := make([]*purchase_wms.PurchaseProduct, 0) ids := make([]int, 0) + productMap := make(map[string]int64) for _, inspection := range inspectionList { - var p purchase_wms.PurchaseProduct - p.Id = inspection.ProductId - p.Amount = inspection.Amount.IntPart() - product = append(product, &p) + productMap[inspection.ProductId] = inspection.Amount.IntPart() ids = append(ids, int(inspection.ID)) } + for k, v := range productMap { + var p purchase_wms.PurchaseProduct + p.Id = k + p.Amount = v + product = append(product, &p) + } client := purchase_wms.NewPurchaseServiceClient(purchase_wms.PurchaseConn) _, err = client.PurchaseToWms(context.Background(), &purchase_wms.PurchaseToWmsRequest{ Number: purchaseData.Number, diff --git a/docs/docs.go b/docs/docs.go index 853f041..9ebef61 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -4125,7 +4125,7 @@ "type": "string" }, "sourceOrder": { - "description": "鏉ユ簮鍗曟嵁", + "description": "鏉ユ簮鍗曟嵁 ,閿�鍞槑缁嗙紪鐮�", "type": "string" }, "status": { @@ -4690,17 +4690,9 @@ } } }, - "response.OperationInfo": { + "response.InWarehouseInfo": { "type": "object", "properties": { - "amount": { - "description": "閲囪喘鏁�", - "type": "number" - }, - "modelNumber": { - "description": "鍨嬪彿", - "type": "string" - }, "name": { "description": "浜у搧鍚嶇О", "type": "string" @@ -4725,32 +4717,29 @@ "description": "璐熻矗浜�", "type": "string" }, - "purchasePrice": { - "description": "鍗曚环", - "type": "number" - }, - "sendAmount": { - "description": "鍙戣揣鏁�", - "type": "integer" - }, - "specifications": { - "description": "瑙勬牸", - "type": "string" - }, "status": { "type": "integer" - }, - "total": { - "description": "鎬讳环", - "type": "number" - }, - "unit": { - "description": "鍗曚綅", - "type": "string" }, "warehouseName": { "description": "浠撳簱鍚�", "type": "string" + } + } + }, + "response.OperationInfo": { + "type": "object", + "properties": { + "inWarehouseInfos": { + "type": "array", + "items": { + "$ref": "#/definitions/response.InWarehouseInfo" + } + }, + "productInfos": { + "type": "array", + "items": { + "$ref": "#/definitions/response.ProductInfo" + } } } }, @@ -4769,6 +4758,51 @@ } } }, + "response.ProductInfo": { + "type": "object", + "properties": { + "amount": { + "description": "閲囪喘鏁�", + "type": "number" + }, + "modelNumber": { + "description": "鍨嬪彿", + "type": "string" + }, + "name": { + "description": "浜у搧鍚嶇О", + "type": "string" + }, + "number": { + "description": "浜у搧缂栫爜", + "type": "string" + }, + "overAmount": { + "description": "鍏ュ簱鏁�", + "type": "integer" + }, + "purchasePrice": { + "description": "鍗曚环", + "type": "number" + }, + "sendAmount": { + "description": "鏀惰揣鏁�", + "type": "integer" + }, + "specifications": { + "description": "瑙勬牸", + "type": "string" + }, + "total": { + "description": "鎬讳环", + "type": "number" + }, + "unit": { + "description": "鍗曚綅", + "type": "string" + } + } + }, "response.PurchaseProducts": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 9a104d4..aa52a00 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -4116,7 +4116,7 @@ "type": "string" }, "sourceOrder": { - "description": "鏉ユ簮鍗曟嵁", + "description": "鏉ユ簮鍗曟嵁 ,閿�鍞槑缁嗙紪鐮�", "type": "string" }, "status": { @@ -4681,17 +4681,9 @@ } } }, - "response.OperationInfo": { + "response.InWarehouseInfo": { "type": "object", "properties": { - "amount": { - "description": "閲囪喘鏁�", - "type": "number" - }, - "modelNumber": { - "description": "鍨嬪彿", - "type": "string" - }, "name": { "description": "浜у搧鍚嶇О", "type": "string" @@ -4716,32 +4708,29 @@ "description": "璐熻矗浜�", "type": "string" }, - "purchasePrice": { - "description": "鍗曚环", - "type": "number" - }, - "sendAmount": { - "description": "鍙戣揣鏁�", - "type": "integer" - }, - "specifications": { - "description": "瑙勬牸", - "type": "string" - }, "status": { "type": "integer" - }, - "total": { - "description": "鎬讳环", - "type": "number" - }, - "unit": { - "description": "鍗曚綅", - "type": "string" }, "warehouseName": { "description": "浠撳簱鍚�", "type": "string" + } + } + }, + "response.OperationInfo": { + "type": "object", + "properties": { + "inWarehouseInfos": { + "type": "array", + "items": { + "$ref": "#/definitions/response.InWarehouseInfo" + } + }, + "productInfos": { + "type": "array", + "items": { + "$ref": "#/definitions/response.ProductInfo" + } } } }, @@ -4760,6 +4749,51 @@ } } }, + "response.ProductInfo": { + "type": "object", + "properties": { + "amount": { + "description": "閲囪喘鏁�", + "type": "number" + }, + "modelNumber": { + "description": "鍨嬪彿", + "type": "string" + }, + "name": { + "description": "浜у搧鍚嶇О", + "type": "string" + }, + "number": { + "description": "浜у搧缂栫爜", + "type": "string" + }, + "overAmount": { + "description": "鍏ュ簱鏁�", + "type": "integer" + }, + "purchasePrice": { + "description": "鍗曚环", + "type": "number" + }, + "sendAmount": { + "description": "鏀惰揣鏁�", + "type": "integer" + }, + "specifications": { + "description": "瑙勬牸", + "type": "string" + }, + "total": { + "description": "鎬讳环", + "type": "number" + }, + "unit": { + "description": "鍗曚綅", + "type": "string" + } + } + }, "response.PurchaseProducts": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index a1b21f2..37c765c 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -506,7 +506,7 @@ description: 绛剧害鏃ユ湡 type: string sourceOrder: - description: 鏉ユ簮鍗曟嵁 + description: 鏉ユ簮鍗曟嵁 ,閿�鍞槑缁嗙紪鐮� type: string status: allOf: @@ -888,14 +888,8 @@ $ref: '#/definitions/test.SupplierType' type: array type: object - response.OperationInfo: + response.InWarehouseInfo: properties: - amount: - description: 閲囪喘鏁� - type: number - modelNumber: - description: 鍨嬪彿 - type: string name: description: 浜у搧鍚嶇О type: string @@ -914,26 +908,22 @@ principal: description: 璐熻矗浜� type: string - purchasePrice: - description: 鍗曚环 - type: number - sendAmount: - description: 鍙戣揣鏁� - type: integer - specifications: - description: 瑙勬牸 - type: string status: type: integer - total: - description: 鎬讳环 - type: number - unit: - description: 鍗曚綅 - type: string warehouseName: description: 浠撳簱鍚� type: string + type: object + response.OperationInfo: + properties: + inWarehouseInfos: + items: + $ref: '#/definitions/response.InWarehouseInfo' + type: array + productInfos: + items: + $ref: '#/definitions/response.ProductInfo' + type: array type: object response.PageResult: properties: @@ -945,6 +935,39 @@ total: type: integer type: object + response.ProductInfo: + properties: + amount: + description: 閲囪喘鏁� + type: number + modelNumber: + description: 鍨嬪彿 + type: string + name: + description: 浜у搧鍚嶇О + type: string + number: + description: 浜у搧缂栫爜 + type: string + overAmount: + description: 鍏ュ簱鏁� + type: integer + purchasePrice: + description: 鍗曚环 + type: number + sendAmount: + description: 鏀惰揣鏁� + type: integer + specifications: + description: 瑙勬牸 + type: string + total: + description: 鎬讳环 + type: number + unit: + description: 鍗曚綅 + type: string + type: object response.PurchaseProducts: properties: amount: diff --git a/model/purchase/response/purchase.go b/model/purchase/response/purchase.go index a66dcc4..ec3a5a8 100644 --- a/model/purchase/response/purchase.go +++ b/model/purchase/response/purchase.go @@ -51,19 +51,30 @@ } type OperationInfo struct { - Number string `json:"number"` //浜у搧缂栫爜 - Name string `json:"name"` //浜у搧鍚嶇О - Specifications string `json:"specifications"` //瑙勬牸 - ModelNumber string `json:"modelNumber"` //鍨嬪彿 - Amount decimal.Decimal `json:"amount"` //閲囪喘鏁� - SendAmount int64 `json:"sendAmount"` //鏀惰揣鏁� - OverAmount int64 `json:"overAmount"` //鍏ュ簱鏁� - Unit string `json:"unit"` //鍗曚綅 - PurchasePrice decimal.Decimal `json:"purchasePrice"` //鍗曚环 - Total decimal.Decimal `json:"total"` //鎬讳环 - OperationNumber string `json:"operationNumber"` //鍏ュ簱鍗曞彿 - WarehouseName string `json:"warehouseName"` //浠撳簱鍚� - OverTime string `json:"overTime"` //鍏ュ簱鏃堕棿 - Status int64 `json:"status"` - Principal string `json:"principal"` //璐熻矗浜� + ProductInfos []ProductInfo `json:"productInfos"` + InWarehouseInfos []InWarehouseInfo `json:"inWarehouseInfos"` +} + +type ProductInfo struct { + Number string `json:"number"` //浜у搧缂栫爜 + Name string `json:"name"` //浜у搧鍚嶇О + Specifications string `json:"specifications"` //瑙勬牸 + ModelNumber string `json:"modelNumber"` //鍨嬪彿 + Amount decimal.Decimal `json:"amount"` //閲囪喘鏁� + SendAmount int64 `json:"sendAmount"` //鏀惰揣鏁� + OverAmount int64 `json:"overAmount"` //鍏ュ簱鏁� + Unit string `json:"unit"` //鍗曚綅 + PurchasePrice decimal.Decimal `json:"purchasePrice"` //鍗曚环 + Total decimal.Decimal `json:"total"` //鎬讳环 +} + +type InWarehouseInfo struct { + Number string `json:"number"` //浜у搧缂栫爜 + Name string `json:"name"` //浜у搧鍚嶇О + OperationNumber string `json:"operationNumber"` //鍏ュ簱鍗曞彿 + WarehouseName string `json:"warehouseName"` //浠撳簱鍚� + OverTime string `json:"overTime"` //鍏ュ簱鏃堕棿 + Status int64 `json:"status"` + Principal string `json:"principal"` //璐熻矗浜� + OverAmount int64 `json:"overAmount"` //鍏ュ簱鏁� } diff --git a/service/purchase/purchase.go b/service/purchase/purchase.go index 05171f4..aeba8f3 100644 --- a/service/purchase/purchase.go +++ b/service/purchase/purchase.go @@ -410,15 +410,22 @@ func (slf *PurchaseService) UpdatePurchaseStatus(number string, status int) error { var total int64 - err := global.GVA_DB.Model(&purchase.PurchaseQualityInspection{}).Where("purchase_number = ?", number).Where("status = ?", status).Count(&total).Error + err := global.GVA_DB.Model(&purchase.Purchase{}).Where("number = ?", number).Where("status = ?", purchase.OrderStatusWaitQuality).Count(&total).Error if err != nil { return err } - if total == 0 { - err = global.GVA_DB.Model(&purchase.Purchase{}).Where("number = ?", number).Updates(map[string]interface{}{"status": purchase.OrderStatusReceived}).Error + if total > 0 { + err = global.GVA_DB.Model(&purchase.PurchaseQualityInspection{}).Where("purchase_number = ?", number).Where("status = ?", status).Count(&total).Error if err != nil { return err } + + if total == 0 { + err = global.GVA_DB.Model(&purchase.Purchase{}).Where("number = ?", number).Updates(map[string]interface{}{"status": purchase.OrderStatusReceived}).Error + if err != nil { + return err + } + } } return nil } -- Gitblit v1.8.0