From 0d86d93cff554f54f83927d4f8bf03ed8c847883 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 29 八月 2023 17:14:54 +0800 Subject: [PATCH] fix&字段完善 --- api/v1/purchase/purchase.go | 27 +++ model/purchase/purchase.go | 2 model/purchase/purchase_products.go | 10 + config.yaml | 2 model/purchase/response/purchase.go | 26 +++ docs/swagger.yaml | 60 +++++++++ docs/docs.go | 83 +++++++++++++ service/purchase/purchase.go | 31 ++++ docs/swagger.json | 83 +++++++++++++ 9 files changed, 301 insertions(+), 23 deletions(-) diff --git a/api/v1/purchase/purchase.go b/api/v1/purchase/purchase.go index c82be66..73eafdd 100644 --- a/api/v1/purchase/purchase.go +++ b/api/v1/purchase/purchase.go @@ -29,7 +29,7 @@ // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body purchaserequest.AddPurchase true "閲囪喘鍗曠敤鎴峰悕, 閲囪喘鍗曟墜鏈哄彿鐮�" +// @Param data body purchaserequest.AddPurchase true "閲囪喘鍗�,閲囪喘鍗曚骇鍝�" // @Success 200 {object} response.Response{msg=string} "鍒涘缓閲囪喘鍗�" // @Router /purchase/purchase [post] func (e *PurchaseApi) CreatePurchase(c *gin.Context) { @@ -149,7 +149,26 @@ response.FailWithMessage("鑾峰彇澶辫触", c) return } - response.OkWithDetailed(purchaseRes.PurchaseResponse{Purchase: data, ProductList: productList}, "鑾峰彇鎴愬姛", c) + respProductList := make([]*purchaseRes.PurchaseProducts, len(productList)) + err = mapstructure.Decode(productList, &respProductList) + if err != nil { + global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) + response.FailWithMessage("鑾峰彇澶辫触", c) + return + } + for k, item := range productList { + respProductList[k].Amount = item.Amount + respProductList[k].Price = item.Price + respProductList[k].Total = item.Total + err = mapstructure.Decode(item.Product, &respProductList[k]) + if err != nil { + global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) + response.FailWithMessage("鑾峰彇澶辫触", c) + return + } + } + + response.OkWithDetailed(purchaseRes.PurchaseResponse{Purchase: data, ProductList: respProductList}, "鑾峰彇鎴愬姛", c) } // GetPurchaseList @@ -173,14 +192,14 @@ response.FailWithMessage(err.Error(), c) return } - PurchaseList, total, err := service.NewPurchaseService().GetPurchaseList(pageInfo) + purchaseList, total, err := service.NewPurchaseService().GetPurchaseList(pageInfo) if err != nil { global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) response.FailWithMessage("鑾峰彇澶辫触"+err.Error(), c) return } response.OkWithDetailed(response.PageResult{ - List: PurchaseList, + List: purchaseList, Total: total, Page: pageInfo.Page, PageSize: pageInfo.PageSize, diff --git a/config.yaml b/config.yaml index a172756..0cfd477 100644 --- a/config.yaml +++ b/config.yaml @@ -182,7 +182,7 @@ iplimit-time: 3600 use-multipoint: false use-redis: false - grpc-url: 192.168.20.118:9091 + grpc-url: 192.168.20.119:9091 grpc-admin-url: 192.168.20.119:50051 tencent-cos: bucket: xxxxx-10005608 diff --git a/docs/docs.go b/docs/docs.go index 92af44b..fb4982c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -4629,7 +4629,7 @@ "summary": "鍒涘缓閲囪喘鍗�", "parameters": [ { - "description": "閲囪喘鍗曠敤鎴峰悕, 閲囪喘鍗曟墜鏈哄彿鐮�", + "description": "閲囪喘鍗�,閲囪喘鍗曚骇鍝�", "name": "data", "in": "body", "required": true, @@ -8425,8 +8425,16 @@ "description": "鍒涘缓鏃堕棿", "type": "string" }, + "creator": { + "description": "鍒跺崟浜�", + "type": "string" + }, "deliveryDate": { "description": "浜や粯鏃ユ湡", + "type": "string" + }, + "handledBy": { + "description": "缁忓姙浜�", "type": "string" }, "id": { @@ -8441,6 +8449,10 @@ "description": "閲囪喘缂栧彿", "type": "string" }, + "orderType": { + "description": "鍗曟嵁绫诲瀷", + "type": "string" + }, "phone": { "description": "鑱旂郴浜虹數璇�", "type": "string" @@ -8451,6 +8463,10 @@ "purchaseTypeId": { "description": "閲囪喘绫诲瀷id", "type": "integer" + }, + "quantity": { + "description": "閲囪喘鏁伴噺", + "type": "number" }, "remark": { "description": "澶囨敞", @@ -8474,6 +8490,10 @@ "supplierId": { "description": "渚涘簲鍟唅d", "type": "integer" + }, + "warehouse": { + "description": "鏀惰揣浠撳簱", + "type": "string" } } }, @@ -8496,6 +8516,9 @@ "description": "閲囪喘鍗曚环", "type": "number" }, + "product": { + "$ref": "#/definitions/test.Product" + }, "productId": { "description": "浜у搧id", "type": "integer" @@ -8517,6 +8540,10 @@ "purchase.PurchaseType": { "type": "object", "properties": { + "created_at": { + "description": "鍒涘缓鏃堕棿", + "type": "string" + }, "id": { "description": "涓婚敭ID", "type": "integer" @@ -9093,13 +9120,65 @@ } } }, + "response.PurchaseProducts": { + "type": "object", + "properties": { + "amount": { + "description": "閲囪喘鏁伴噺", + "type": "number" + }, + "deliveryTime": { + "type": "integer" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "number": { + "type": "string" + }, + "price": { + "description": "閲囪喘鍗曚环", + "type": "number" + }, + "productId": { + "description": "浜у搧id", + "type": "integer" + }, + "productType": { + "type": "string" + }, + "purchaseId": { + "description": "閲囪喘id", + "type": "integer" + }, + "purchasePrice": { + "type": "number" + }, + "shippingDuration": { + "type": "integer" + }, + "specifications": { + "type": "string" + }, + "total": { + "description": "閲囪喘鎬讳环", + "type": "number" + }, + "unit": { + "type": "string" + } + } + }, "response.PurchaseResponse": { "type": "object", "properties": { "productList": { "type": "array", "items": { - "$ref": "#/definitions/purchase.PurchaseProducts" + "$ref": "#/definitions/response.PurchaseProducts" } }, "purchase": { diff --git a/docs/swagger.json b/docs/swagger.json index 864a908..6e56b99 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -4620,7 +4620,7 @@ "summary": "鍒涘缓閲囪喘鍗�", "parameters": [ { - "description": "閲囪喘鍗曠敤鎴峰悕, 閲囪喘鍗曟墜鏈哄彿鐮�", + "description": "閲囪喘鍗�,閲囪喘鍗曚骇鍝�", "name": "data", "in": "body", "required": true, @@ -8416,8 +8416,16 @@ "description": "鍒涘缓鏃堕棿", "type": "string" }, + "creator": { + "description": "鍒跺崟浜�", + "type": "string" + }, "deliveryDate": { "description": "浜や粯鏃ユ湡", + "type": "string" + }, + "handledBy": { + "description": "缁忓姙浜�", "type": "string" }, "id": { @@ -8432,6 +8440,10 @@ "description": "閲囪喘缂栧彿", "type": "string" }, + "orderType": { + "description": "鍗曟嵁绫诲瀷", + "type": "string" + }, "phone": { "description": "鑱旂郴浜虹數璇�", "type": "string" @@ -8442,6 +8454,10 @@ "purchaseTypeId": { "description": "閲囪喘绫诲瀷id", "type": "integer" + }, + "quantity": { + "description": "閲囪喘鏁伴噺", + "type": "number" }, "remark": { "description": "澶囨敞", @@ -8465,6 +8481,10 @@ "supplierId": { "description": "渚涘簲鍟唅d", "type": "integer" + }, + "warehouse": { + "description": "鏀惰揣浠撳簱", + "type": "string" } } }, @@ -8487,6 +8507,9 @@ "description": "閲囪喘鍗曚环", "type": "number" }, + "product": { + "$ref": "#/definitions/test.Product" + }, "productId": { "description": "浜у搧id", "type": "integer" @@ -8508,6 +8531,10 @@ "purchase.PurchaseType": { "type": "object", "properties": { + "created_at": { + "description": "鍒涘缓鏃堕棿", + "type": "string" + }, "id": { "description": "涓婚敭ID", "type": "integer" @@ -9084,13 +9111,65 @@ } } }, + "response.PurchaseProducts": { + "type": "object", + "properties": { + "amount": { + "description": "閲囪喘鏁伴噺", + "type": "number" + }, + "deliveryTime": { + "type": "integer" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "number": { + "type": "string" + }, + "price": { + "description": "閲囪喘鍗曚环", + "type": "number" + }, + "productId": { + "description": "浜у搧id", + "type": "integer" + }, + "productType": { + "type": "string" + }, + "purchaseId": { + "description": "閲囪喘id", + "type": "integer" + }, + "purchasePrice": { + "type": "number" + }, + "shippingDuration": { + "type": "integer" + }, + "specifications": { + "type": "string" + }, + "total": { + "description": "閲囪喘鎬讳环", + "type": "number" + }, + "unit": { + "type": "string" + } + } + }, "response.PurchaseResponse": { "type": "object", "properties": { "productList": { "type": "array", "items": { - "$ref": "#/definitions/purchase.PurchaseProducts" + "$ref": "#/definitions/response.PurchaseProducts" } }, "purchase": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 6547ff2..d593c53 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -702,8 +702,14 @@ created_at: description: 鍒涘缓鏃堕棿 type: string + creator: + description: 鍒跺崟浜� + type: string deliveryDate: description: 浜や粯鏃ユ湡 + type: string + handledBy: + description: 缁忓姙浜� type: string id: description: 涓婚敭ID @@ -714,6 +720,9 @@ number: description: 閲囪喘缂栧彿 type: string + orderType: + description: 鍗曟嵁绫诲瀷 + type: string phone: description: 鑱旂郴浜虹數璇� type: string @@ -722,6 +731,9 @@ purchaseTypeId: description: 閲囪喘绫诲瀷id type: integer + quantity: + description: 閲囪喘鏁伴噺 + type: number remark: description: 澶囨敞 type: string @@ -737,6 +749,9 @@ supplierId: description: 渚涘簲鍟唅d type: integer + warehouse: + description: 鏀惰揣浠撳簱 + type: string type: object purchase.PurchaseProducts: properties: @@ -752,6 +767,8 @@ price: description: 閲囪喘鍗曚环 type: number + product: + $ref: '#/definitions/test.Product' productId: description: 浜у搧id type: integer @@ -767,6 +784,9 @@ type: object purchase.PurchaseType: properties: + created_at: + description: 鍒涘缓鏃堕棿 + type: string id: description: 涓婚敭ID type: integer @@ -1162,11 +1182,47 @@ $ref: '#/definitions/request.CasbinInfo' type: array type: object + response.PurchaseProducts: + properties: + amount: + description: 閲囪喘鏁伴噺 + type: number + deliveryTime: + type: integer + modelNumber: + type: string + name: + type: string + number: + type: string + price: + description: 閲囪喘鍗曚环 + type: number + productId: + description: 浜у搧id + type: integer + productType: + type: string + purchaseId: + description: 閲囪喘id + type: integer + purchasePrice: + type: number + shippingDuration: + type: integer + specifications: + type: string + total: + description: 閲囪喘鎬讳环 + type: number + unit: + type: string + type: object response.PurchaseResponse: properties: productList: items: - $ref: '#/definitions/purchase.PurchaseProducts' + $ref: '#/definitions/response.PurchaseProducts' type: array purchase: $ref: '#/definitions/purchase.Purchase' @@ -4508,7 +4564,7 @@ consumes: - application/json parameters: - - description: 閲囪喘鍗曠敤鎴峰悕, 閲囪喘鍗曟墜鏈哄彿鐮� + - description: 閲囪喘鍗�,閲囪喘鍗曚骇鍝� in: body name: data required: true diff --git a/model/purchase/purchase.go b/model/purchase/purchase.go index 4627f87..198fe97 100644 --- a/model/purchase/purchase.go +++ b/model/purchase/purchase.go @@ -23,6 +23,8 @@ Status OrderStatus `json:"status" form:"status" gorm:"type:tinyint(1);not null;default 0;comment:鐘舵��"` //鐘舵�� HandledBy string `json:"handledBy" form:"handledBy" gorm:"type:varchar(255);not null;default '';comment:缁忓姙浜�"` //缁忓姙浜� Creator string `json:"creator" form:"creator" gorm:"type:varchar(255);not null;default '';comment:鍒跺崟浜�"` //鍒跺崟浜� + OrderType string `json:"orderType" form:"orderType" gorm:"type:varchar(255);not null;default '';comment:鍗曟嵁绫诲瀷"` //鍗曟嵁绫诲瀷 + Warehouse string `json:"warehouse" form:"warehouse" gorm:"type:varchar(255);not null;default '';comment:鏀惰揣浠撳簱"` //鏀惰揣浠撳簱 } type OrderStatus int diff --git a/model/purchase/purchase_products.go b/model/purchase/purchase_products.go index 53aa43d..20373de 100644 --- a/model/purchase/purchase_products.go +++ b/model/purchase/purchase_products.go @@ -3,14 +3,16 @@ import ( "github.com/shopspring/decimal" "srm/global" + "srm/model/test" ) type PurchaseProducts struct { global.GVA_MODEL PurchaseId int `json:"purchaseId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:閲囪喘绫诲瀷id"` // 閲囪喘id ProductId int `json:"productId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:渚涘簲鍟唅d"` // 浜у搧id - Amount decimal.Decimal `json:"amount" form:"amount" gorm:"type:decimal(12,2);not null;default 0;comment:閲囪喘鏁伴噺"` // 閲囪喘鏁伴噺 - Price decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(12,2);not null;default 0.00;comment:閲囪喘鍗曚环"` // 閲囪喘鍗曚环 - Total decimal.Decimal `json:"total" form:"total" gorm:"type:decimal(12,2);not null;default 0.00;comment:閲囪喘鎬讳环"` // 閲囪喘鎬讳环 - Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null; default '';comment:鎻忚堪"` //鎻忚堪 + Product test.Product `json:"product" gorm:"foreignKey:ProductId"` + Amount decimal.Decimal `json:"amount" form:"amount" gorm:"type:decimal(12,2);not null;default 0;comment:閲囪喘鏁伴噺"` // 閲囪喘鏁伴噺 + Price decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(12,2);not null;default 0.00;comment:閲囪喘鍗曚环"` // 閲囪喘鍗曚环 + Total decimal.Decimal `json:"total" form:"total" gorm:"type:decimal(12,2);not null;default 0.00;comment:閲囪喘鎬讳环"` // 閲囪喘鎬讳环 + Remark string `json:"remark" form:"remark" gorm:"type:varchar(1000);not null; default '';comment:鎻忚堪"` //鎻忚堪 } diff --git a/model/purchase/response/purchase.go b/model/purchase/response/purchase.go index dad6b28..2588e67 100644 --- a/model/purchase/response/purchase.go +++ b/model/purchase/response/purchase.go @@ -1,8 +1,28 @@ package response -import "srm/model/purchase" +import ( + "github.com/shopspring/decimal" + "srm/model/purchase" +) type PurchaseResponse struct { - Purchase purchase.Purchase `json:"purchase"` - ProductList []*purchase.PurchaseProducts `json:"productList"` + Purchase purchase.Purchase `json:"purchase"` + ProductList []*PurchaseProducts `json:"productList"` +} + +type PurchaseProducts struct { + PurchaseId int `json:"purchaseId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:閲囪喘绫诲瀷id"` // 閲囪喘id + ProductId int `json:"productId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:渚涘簲鍟唅d"` // 浜у搧id + Amount decimal.Decimal `json:"amount" form:"amount" gorm:"type:decimal(12,2);not null;default 0;comment:閲囪喘鏁伴噺"` // 閲囪喘鏁伴噺 + Price decimal.Decimal `json:"price" form:"price" gorm:"type:decimal(12,2);not null;default 0.00;comment:閲囪喘鍗曚环"` // 閲囪喘鍗曚环 + Total decimal.Decimal `json:"total" form:"total" gorm:"type:decimal(12,2);not null;default 0.00;comment:閲囪喘鎬讳环"` // 閲囪喘鎬讳环 + Name string `json:"name" form:"name" gorm:"column:name;comment:鍚嶇О;size:255;"` + Number string `json:"number" form:"number" gorm:"column:number;comment:缂栫爜;size:255;"` + Unit string `json:"unit" form:"unit" gorm:"column:unit;comment:璁¢噺鍗曚綅;size:255;"` + PurchasePrice *float64 `json:"purchasePrice" form:"purchasePrice" gorm:"column:purchase_price;comment:閲囪喘浠锋牸;"` + DeliveryTime *int `json:"deliveryTime" form:"deliveryTime" gorm:"column:delivery_time;comment:;size:11;"` + ShippingDuration *int `json:"shippingDuration" form:"shippingDuration" gorm:"column:shipping_duration;comment:鐗╂祦鏃堕暱;size:11;"` + Specifications string `json:"specifications" form:"specifications" gorm:"column:specifications;comment:瑙勬牸;size:255;"` + ModelNumber string `json:"modelNumber" form:"modelNumber" gorm:"column:model_number;comment:鍨嬪彿;size:255;"` + ProductType string `json:"productType" form:"productType" gorm:"column:product_type;comment:浜у搧绫诲埆;size:255;"` } diff --git a/service/purchase/purchase.go b/service/purchase/purchase.go index bbef0f1..352395d 100644 --- a/service/purchase/purchase.go +++ b/service/purchase/purchase.go @@ -132,7 +132,7 @@ func (slf *PurchaseService) GetPurchaseProductList(purchaseId uint) (list []*purchase.PurchaseProducts, err error) { db := global.GVA_DB.Model(&purchase.PurchaseProducts{}) list = make([]*purchase.PurchaseProducts, 0) - err = db.Where("purchase_id = ?", purchaseId).Find(&list).Error + err = db.Where("purchase_id = ?", purchaseId).Preload("Product").Find(&list).Error return list, err } @@ -214,15 +214,36 @@ } func (slf *PurchaseService) SavePurchaseType(list []*purchase.PurchaseType) (err error) { + ids := make([]uint, 0) + newRecords := make([]*purchase.PurchaseType, 0) + for _, item := range list { + if item.ID != 0 { + ids = append(ids, item.ID) + } else { + newRecords = append(newRecords, item) + } + } err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { - err = tx.Where("1 = ?", 1).Delete(&purchase.PurchaseType{}).Error + err = tx.Where("id not in ?", ids).Delete(&purchase.PurchaseType{}).Error if err != nil { return err } - for _, item := range list { - item.ID = 0 + if len(newRecords) > 0 { + err = tx.Create(newRecords).Error + if err != nil { + return err + } } - return tx.Create(list).Error + + for _, item := range list { + if item.ID != 0 { + err = tx.Save(item).Error + if err != nil { + return err + } + } + } + return nil }) return err } -- Gitblit v1.8.0