From 6aceac83950d3f17a1137d984df4b1086bfbd016 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 15 十一月 2023 16:25:29 +0800 Subject: [PATCH] 重构产品 --- model/test/response/product.go | 18 model/test/product.go | 29 model/purchase/purchase_products.go | 14 model/test/material.go | 114 ++++ config.yaml | 62 -- docs/swagger.yaml | 215 +++------ api/v1/test/product.go | 66 +- docs/docs.go | 330 ++++--------- docs/swagger.json | 330 ++++--------- service/test/product.go | 89 +-- main.go | 1 model/test/attachment.go | 23 + model/test/request/product.go | 25 service/purchase/purchase.go | 8 initialize/gorm.go | 1 15 files changed, 576 insertions(+), 749 deletions(-) diff --git a/api/v1/test/product.go b/api/v1/test/product.go index dfb82c9..bcd2eea 100644 --- a/api/v1/test/product.go +++ b/api/v1/test/product.go @@ -11,6 +11,7 @@ "srm/model/common/response" "srm/model/test" testReq "srm/model/test/request" + testResp "srm/model/test/response" "srm/proto/product" "srm/service" ) @@ -38,7 +39,7 @@ } for _, t := range p.List { var num int64 - db := global.GVA_DB.Model(&test.Product{}) + db := global.GVA_DB.Model(&test.SupplierMaterial{}) err := db.Where("number = ?", t.Number).Where("supplier_id = ?", t.SupplierId).Count(&num).Error if err != nil { response.FailWithMessage(err.Error(), c) @@ -63,17 +64,17 @@ // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body test.Product true "鍒犻櫎Product" +// @Param data body request.GetById true "鍒犻櫎Product" // @Success 200 {string} string "{"success":true,"data":{},"msg":"鍒犻櫎鎴愬姛"}" // @Router /p/deleteProduct [delete] func (pApi *ProductApi) DeleteProduct(c *gin.Context) { - var p test.Product + var p request.GetById err := c.ShouldBindJSON(&p) if err != nil { response.FailWithMessage(err.Error(), c) return } - if err := pService.DeleteProduct(p); err != nil { + if err := pService.DeleteProduct(p.ID); err != nil { global.GVA_LOG.Error("鍒犻櫎澶辫触!", zap.Error(err)) response.FailWithMessage("鍒犻櫎澶辫触", c) } else { @@ -111,11 +112,11 @@ // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body test.Product true "鏇存柊Product" +// @Param data body test.SupplierMaterial true "鏇存柊Product" // @Success 200 {string} string "{"success":true,"data":{},"msg":"鏇存柊鎴愬姛"}" // @Router /p/updateProduct [put] func (pApi *ProductApi) UpdateProduct(c *gin.Context) { - var p test.Product + var p test.SupplierMaterial err := c.ShouldBindJSON(&p) if err != nil { response.FailWithMessage(err.Error(), c) @@ -135,11 +136,11 @@ // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data query test.Product true "鐢╥d鏌ヨProduct" +// @Param data query request.GetById true "鐢╥d鏌ヨProduct" // @Success 200 {string} string "{"success":true,"data":{},"msg":"鏌ヨ鎴愬姛"}" // @Router /p/findProduct [get] func (pApi *ProductApi) FindProduct(c *gin.Context) { - var p test.Product + var p request.GetById err := c.ShouldBindQuery(&p) if err != nil { response.FailWithMessage(err.Error(), c) @@ -169,21 +170,40 @@ response.FailWithMessage(err.Error(), c) return } - if list, total, err := pService.GetProductInfoList(pageInfo); err != nil { + list, total, err := pService.GetProductInfoList(pageInfo) + if err != nil { global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) response.FailWithMessage("鑾峰彇澶辫触", c) - } else { - //娣诲姞渚涘簲鍟嗗悕绉� - for i := 0; i < len(list); i++ { - list[i].SupplierName = list[i].Supplier.Name - } - response.OkWithDetailed(response.PageResult{ - List: list, - Total: total, - Page: pageInfo.Page, - PageSize: pageInfo.PageSize, - }, "鑾峰彇鎴愬姛", c) + return } + + productList := make([]testResp.Product, 0, len(list)) + + for _, item := range list { + productList = append(productList, testResp.Product{ + Name: item.Name, + Number: item.Number, + SupplierId: item.SupplierId, + Unit: item.Unit, + PurchasePrice: item.PurchasePrice, + DeliveryTime: item.DeliveryTime, + ShippingDuration: item.ShippingDuration, + Specifications: item.Specifications, + ModelNumber: item.ModelNumber, + ProductType: "", + MinimumStock: item.MinimumStock, + MaximumStock: item.MaximumStock, + Remark: "", + SupplierName: item.Supplier.Name, + }) + } + + response.OkWithDetailed(response.PageResult{ + List: list, + Total: total, + Page: pageInfo.Page, + PageSize: pageInfo.PageSize, + }, "鑾峰彇鎴愬姛", c) } var ( @@ -230,16 +250,16 @@ ProductName: pageInfo.Name, }) rawProductList := getProductListResponse.List - productList := make([]test.Product, len(rawProductList)) + productList := make([]testResp.Product, len(rawProductList)) for k, v := range rawProductList { productList[k].Number = v.Number productList[k].Name = v.Name productList[k].Unit = v.Unit productList[k].PurchasePrice = v.SalePrice - min := int(v.MinInventory) + min := int64(v.MinInventory) productList[k].MinimumStock = min - max := int(v.MaxInventory) + max := int64(v.MaxInventory) productList[k].MaximumStock = max productList[k].Remark = v.Node productList[k].ProductType = v.MaterialMode diff --git a/config.yaml b/config.yaml index 42698de..456869a 100644 --- a/config.yaml +++ b/config.yaml @@ -28,20 +28,6 @@ singular: false log-zap: false disable: true -mssql: - prefix: "" - port: "" - config: "" - db-name: "" - username: "" - password: "" - path: "" - engine: "" - log-mode: "" - max-idle-conns: 10 - max-open-conns: 100 - singular: false - log-zap: false mysql: prefix: "" port: "3306" @@ -51,53 +37,11 @@ password: c++java123 path: 192.168.20.119 engine: "" - log-mode: error + log-mode: info max-idle-conns: 10 max-open-conns: 100 singular: false - log-zap: false -oracle: - prefix: "" - port: "" - config: "" - db-name: "" - username: "" - password: "" - path: "" - engine: "" - log-mode: "" - max-idle-conns: 10 - max-open-conns: 100 - singular: false - log-zap: false -pgsql: - prefix: "" - port: "" - config: "" - db-name: "" - username: "" - password: "" - path: "" - engine: "" - log-mode: "" - max-idle-conns: 10 - max-open-conns: 100 - singular: false - log-zap: false -sqlite: - prefix: "" - port: "" - config: "" - db-name: "" - username: "" - password: "" - path: "" - engine: "" - log-mode: "" - max-idle-conns: 10 - max-open-conns: 100 - singular: false - log-zap: false + log-zap: true system: env: public db-type: mysql @@ -129,7 +73,7 @@ start: true with_seconds: false zap: - level: info + level: debug prefix: '[srm]' format: console director: log diff --git a/docs/docs.go b/docs/docs.go index 9706af8..a8e10bb 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1151,7 +1151,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/test.Product" + "$ref": "#/definitions/request.GetById" } } ], @@ -1222,89 +1222,9 @@ "summary": "鐢╥d鏌ヨProduct", "parameters": [ { - "type": "string", - "name": "created_at", - "in": "query" - }, - { - "type": "integer", - "name": "deliveryTime", - "in": "query" - }, - { "type": "integer", "description": "涓婚敭ID", "name": "id", - "in": "query" - }, - { - "type": "integer", - "name": "maximumStock", - "in": "query" - }, - { - "type": "integer", - "name": "minimumStock", - "in": "query" - }, - { - "type": "string", - "name": "modelNumber", - "in": "query" - }, - { - "type": "string", - "name": "name", - "in": "query" - }, - { - "type": "string", - "name": "number", - "in": "query" - }, - { - "type": "string", - "name": "productType", - "in": "query" - }, - { - "type": "number", - "name": "purchasePrice", - "in": "query" - }, - { - "type": "string", - "name": "remark", - "in": "query" - }, - { - "type": "integer", - "name": "shippingDuration", - "in": "query" - }, - { - "type": "string", - "name": "specifications", - "in": "query" - }, - { - "type": "integer", - "name": "supplierId", - "in": "query" - }, - { - "type": "string", - "name": "supplierName", - "in": "query" - }, - { - "type": "string", - "name": "unit", - "in": "query" - }, - { - "type": "string", - "name": "updated_at", "in": "query" } ], @@ -1337,40 +1257,14 @@ "summary": "鍒嗛〉鑾峰彇Product鍒楄〃", "parameters": [ { - "type": "string", - "name": "created_at", - "in": "query" - }, - { "type": "integer", "name": "deliveryTime", "in": "query" }, { "type": "string", - "name": "endCreatedAt", - "in": "query" - }, - { - "type": "integer", - "description": "涓婚敭ID", - "name": "id", - "in": "query" - }, - { - "type": "string", "description": "鍏抽敭瀛�", "name": "keyword", - "in": "query" - }, - { - "type": "integer", - "name": "maximumStock", - "in": "query" - }, - { - "type": "integer", - "name": "minimumStock", "in": "query" }, { @@ -1411,11 +1305,6 @@ "in": "query" }, { - "type": "string", - "name": "remark", - "in": "query" - }, - { "type": "integer", "name": "shippingDuration", "in": "query" @@ -1427,7 +1316,7 @@ }, { "type": "string", - "name": "startCreatedAt", + "name": "supplier", "in": "query" }, { @@ -1448,11 +1337,6 @@ { "type": "string", "name": "unit", - "in": "query" - }, - { - "type": "string", - "name": "updated_at", "in": "query" } ], @@ -1485,40 +1369,14 @@ "summary": "鍒嗛〉鑾峰彇Product鍒楄〃", "parameters": [ { - "type": "string", - "name": "created_at", - "in": "query" - }, - { "type": "integer", "name": "deliveryTime", "in": "query" }, { "type": "string", - "name": "endCreatedAt", - "in": "query" - }, - { - "type": "integer", - "description": "涓婚敭ID", - "name": "id", - "in": "query" - }, - { - "type": "string", "description": "鍏抽敭瀛�", "name": "keyword", - "in": "query" - }, - { - "type": "integer", - "name": "maximumStock", - "in": "query" - }, - { - "type": "integer", - "name": "minimumStock", "in": "query" }, { @@ -1559,11 +1417,6 @@ "in": "query" }, { - "type": "string", - "name": "remark", - "in": "query" - }, - { "type": "integer", "name": "shippingDuration", "in": "query" @@ -1575,7 +1428,7 @@ }, { "type": "string", - "name": "startCreatedAt", + "name": "supplier", "in": "query" }, { @@ -1596,11 +1449,6 @@ { "type": "string", "name": "unit", - "in": "query" - }, - { - "type": "string", - "name": "updated_at", "in": "query" } ], @@ -1638,7 +1486,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/test.Product" + "$ref": "#/definitions/test.SupplierMaterial" } } ], @@ -3726,7 +3574,7 @@ }, "productId": { "description": "浜у搧id", - "type": "integer" + "type": "string" }, "purchaseId": { "description": "閲囪喘id", @@ -3925,6 +3773,15 @@ } } }, + "request.GetById": { + "type": "object", + "properties": { + "id": { + "description": "涓婚敭ID", + "type": "integer" + } + } + }, "request.IdsReq": { "type": "object", "properties": { @@ -3947,13 +3804,57 @@ } } }, + "request.Product": { + "type": "object", + "properties": { + "deliveryTime": { + "type": "integer" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "number": { + "type": "string" + }, + "productType": { + "type": "string" + }, + "purchasePrice": { + "type": "number" + }, + "shippingDuration": { + "type": "integer" + }, + "specifications": { + "type": "string" + }, + "supplier": { + "type": "string" + }, + "supplierId": { + "type": "integer" + }, + "supplierName": { + "type": "string" + }, + "supplierNumber": { + "type": "string" + }, + "unit": { + "type": "string" + } + } + }, "request.ProductCreate": { "type": "object", "properties": { "list": { "type": "array", "items": { - "$ref": "#/definitions/test.Product" + "$ref": "#/definitions/request.Product" } } } @@ -4144,66 +4045,6 @@ } } }, - "test.Product": { - "type": "object", - "properties": { - "created_at": { - "type": "string" - }, - "deliveryTime": { - "type": "integer" - }, - "id": { - "description": "涓婚敭ID", - "type": "integer" - }, - "maximumStock": { - "type": "integer" - }, - "minimumStock": { - "type": "integer" - }, - "modelNumber": { - "type": "string" - }, - "name": { - "type": "string" - }, - "number": { - "type": "string" - }, - "productType": { - "type": "string" - }, - "purchasePrice": { - "type": "number" - }, - "remark": { - "type": "string" - }, - "shippingDuration": { - "type": "integer" - }, - "specifications": { - "type": "string" - }, - "supplier": { - "$ref": "#/definitions/test.Supplier" - }, - "supplierId": { - "type": "integer" - }, - "supplierName": { - "type": "string" - }, - "unit": { - "type": "string" - }, - "updated_at": { - "type": "string" - } - } - }, "test.Supplier": { "type": "object", "properties": { @@ -4267,6 +4108,59 @@ } } }, + "test.SupplierMaterial": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "deliveryTime": { + "description": "渚涜揣鏃堕暱", + "type": "integer" + }, + "id": { + "description": "涓婚敭ID", + "type": "integer" + }, + "maximumStock": { + "type": "integer" + }, + "minimumStock": { + "type": "integer" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "number": { + "type": "string" + }, + "purchasePrice": { + "type": "number" + }, + "shippingDuration": { + "description": "鐗╂祦鏃堕暱", + "type": "integer" + }, + "specifications": { + "type": "string" + }, + "supplier": { + "$ref": "#/definitions/test.Supplier" + }, + "supplierId": { + "type": "integer" + }, + "unit": { + "type": "string" + }, + "updated_at": { + "type": "string" + } + } + }, "test.SupplierType": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 06dd49f..285d41b 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1142,7 +1142,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/test.Product" + "$ref": "#/definitions/request.GetById" } } ], @@ -1213,89 +1213,9 @@ "summary": "鐢╥d鏌ヨProduct", "parameters": [ { - "type": "string", - "name": "created_at", - "in": "query" - }, - { - "type": "integer", - "name": "deliveryTime", - "in": "query" - }, - { "type": "integer", "description": "涓婚敭ID", "name": "id", - "in": "query" - }, - { - "type": "integer", - "name": "maximumStock", - "in": "query" - }, - { - "type": "integer", - "name": "minimumStock", - "in": "query" - }, - { - "type": "string", - "name": "modelNumber", - "in": "query" - }, - { - "type": "string", - "name": "name", - "in": "query" - }, - { - "type": "string", - "name": "number", - "in": "query" - }, - { - "type": "string", - "name": "productType", - "in": "query" - }, - { - "type": "number", - "name": "purchasePrice", - "in": "query" - }, - { - "type": "string", - "name": "remark", - "in": "query" - }, - { - "type": "integer", - "name": "shippingDuration", - "in": "query" - }, - { - "type": "string", - "name": "specifications", - "in": "query" - }, - { - "type": "integer", - "name": "supplierId", - "in": "query" - }, - { - "type": "string", - "name": "supplierName", - "in": "query" - }, - { - "type": "string", - "name": "unit", - "in": "query" - }, - { - "type": "string", - "name": "updated_at", "in": "query" } ], @@ -1328,40 +1248,14 @@ "summary": "鍒嗛〉鑾峰彇Product鍒楄〃", "parameters": [ { - "type": "string", - "name": "created_at", - "in": "query" - }, - { "type": "integer", "name": "deliveryTime", "in": "query" }, { "type": "string", - "name": "endCreatedAt", - "in": "query" - }, - { - "type": "integer", - "description": "涓婚敭ID", - "name": "id", - "in": "query" - }, - { - "type": "string", "description": "鍏抽敭瀛�", "name": "keyword", - "in": "query" - }, - { - "type": "integer", - "name": "maximumStock", - "in": "query" - }, - { - "type": "integer", - "name": "minimumStock", "in": "query" }, { @@ -1402,11 +1296,6 @@ "in": "query" }, { - "type": "string", - "name": "remark", - "in": "query" - }, - { "type": "integer", "name": "shippingDuration", "in": "query" @@ -1418,7 +1307,7 @@ }, { "type": "string", - "name": "startCreatedAt", + "name": "supplier", "in": "query" }, { @@ -1439,11 +1328,6 @@ { "type": "string", "name": "unit", - "in": "query" - }, - { - "type": "string", - "name": "updated_at", "in": "query" } ], @@ -1476,40 +1360,14 @@ "summary": "鍒嗛〉鑾峰彇Product鍒楄〃", "parameters": [ { - "type": "string", - "name": "created_at", - "in": "query" - }, - { "type": "integer", "name": "deliveryTime", "in": "query" }, { "type": "string", - "name": "endCreatedAt", - "in": "query" - }, - { - "type": "integer", - "description": "涓婚敭ID", - "name": "id", - "in": "query" - }, - { - "type": "string", "description": "鍏抽敭瀛�", "name": "keyword", - "in": "query" - }, - { - "type": "integer", - "name": "maximumStock", - "in": "query" - }, - { - "type": "integer", - "name": "minimumStock", "in": "query" }, { @@ -1550,11 +1408,6 @@ "in": "query" }, { - "type": "string", - "name": "remark", - "in": "query" - }, - { "type": "integer", "name": "shippingDuration", "in": "query" @@ -1566,7 +1419,7 @@ }, { "type": "string", - "name": "startCreatedAt", + "name": "supplier", "in": "query" }, { @@ -1587,11 +1440,6 @@ { "type": "string", "name": "unit", - "in": "query" - }, - { - "type": "string", - "name": "updated_at", "in": "query" } ], @@ -1629,7 +1477,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/test.Product" + "$ref": "#/definitions/test.SupplierMaterial" } } ], @@ -3717,7 +3565,7 @@ }, "productId": { "description": "浜у搧id", - "type": "integer" + "type": "string" }, "purchaseId": { "description": "閲囪喘id", @@ -3916,6 +3764,15 @@ } } }, + "request.GetById": { + "type": "object", + "properties": { + "id": { + "description": "涓婚敭ID", + "type": "integer" + } + } + }, "request.IdsReq": { "type": "object", "properties": { @@ -3938,13 +3795,57 @@ } } }, + "request.Product": { + "type": "object", + "properties": { + "deliveryTime": { + "type": "integer" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "number": { + "type": "string" + }, + "productType": { + "type": "string" + }, + "purchasePrice": { + "type": "number" + }, + "shippingDuration": { + "type": "integer" + }, + "specifications": { + "type": "string" + }, + "supplier": { + "type": "string" + }, + "supplierId": { + "type": "integer" + }, + "supplierName": { + "type": "string" + }, + "supplierNumber": { + "type": "string" + }, + "unit": { + "type": "string" + } + } + }, "request.ProductCreate": { "type": "object", "properties": { "list": { "type": "array", "items": { - "$ref": "#/definitions/test.Product" + "$ref": "#/definitions/request.Product" } } } @@ -4135,66 +4036,6 @@ } } }, - "test.Product": { - "type": "object", - "properties": { - "created_at": { - "type": "string" - }, - "deliveryTime": { - "type": "integer" - }, - "id": { - "description": "涓婚敭ID", - "type": "integer" - }, - "maximumStock": { - "type": "integer" - }, - "minimumStock": { - "type": "integer" - }, - "modelNumber": { - "type": "string" - }, - "name": { - "type": "string" - }, - "number": { - "type": "string" - }, - "productType": { - "type": "string" - }, - "purchasePrice": { - "type": "number" - }, - "remark": { - "type": "string" - }, - "shippingDuration": { - "type": "integer" - }, - "specifications": { - "type": "string" - }, - "supplier": { - "$ref": "#/definitions/test.Supplier" - }, - "supplierId": { - "type": "integer" - }, - "supplierName": { - "type": "string" - }, - "unit": { - "type": "string" - }, - "updated_at": { - "type": "string" - } - } - }, "test.Supplier": { "type": "object", "properties": { @@ -4258,6 +4099,59 @@ } } }, + "test.SupplierMaterial": { + "type": "object", + "properties": { + "created_at": { + "type": "string" + }, + "deliveryTime": { + "description": "渚涜揣鏃堕暱", + "type": "integer" + }, + "id": { + "description": "涓婚敭ID", + "type": "integer" + }, + "maximumStock": { + "type": "integer" + }, + "minimumStock": { + "type": "integer" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "number": { + "type": "string" + }, + "purchasePrice": { + "type": "number" + }, + "shippingDuration": { + "description": "鐗╂祦鏃堕暱", + "type": "integer" + }, + "specifications": { + "type": "string" + }, + "supplier": { + "$ref": "#/definitions/test.Supplier" + }, + "supplierId": { + "type": "integer" + }, + "unit": { + "type": "string" + }, + "updated_at": { + "type": "string" + } + } + }, "test.SupplierType": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 5610a5e..daac693 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -500,7 +500,7 @@ type: number productId: description: 浜у搧id - type: integer + type: string purchaseId: description: 閲囪喘id type: integer @@ -636,6 +636,12 @@ purchase: $ref: '#/definitions/purchaserequest.Purchase' type: object + request.GetById: + properties: + id: + description: 涓婚敭ID + type: integer + type: object request.IdsReq: properties: ids: @@ -650,11 +656,40 @@ $ref: '#/definitions/test.Industry' type: array type: object + request.Product: + properties: + deliveryTime: + type: integer + modelNumber: + type: string + name: + type: string + number: + type: string + productType: + type: string + purchasePrice: + type: number + shippingDuration: + type: integer + specifications: + type: string + supplier: + type: string + supplierId: + type: integer + supplierName: + type: string + supplierNumber: + type: string + unit: + type: string + type: object request.ProductCreate: properties: list: items: - $ref: '#/definitions/test.Product' + $ref: '#/definitions/request.Product' type: array type: object request.SupplierStatus: @@ -781,46 +816,6 @@ uuid: type: string type: object - test.Product: - properties: - created_at: - type: string - deliveryTime: - type: integer - id: - description: 涓婚敭ID - type: integer - maximumStock: - type: integer - minimumStock: - type: integer - modelNumber: - type: string - name: - type: string - number: - type: string - productType: - type: string - purchasePrice: - type: number - remark: - type: string - shippingDuration: - type: integer - specifications: - type: string - supplier: - $ref: '#/definitions/test.Supplier' - supplierId: - type: integer - supplierName: - type: string - unit: - type: string - updated_at: - type: string - type: object test.Supplier: properties: account: @@ -861,6 +856,42 @@ updated_at: type: string url: + type: string + type: object + test.SupplierMaterial: + properties: + created_at: + type: string + deliveryTime: + description: 渚涜揣鏃堕暱 + type: integer + id: + description: 涓婚敭ID + type: integer + maximumStock: + type: integer + minimumStock: + type: integer + modelNumber: + type: string + name: + type: string + number: + type: string + purchasePrice: + type: number + shippingDuration: + description: 鐗╂祦鏃堕暱 + type: integer + specifications: + type: string + supplier: + $ref: '#/definitions/test.Supplier' + supplierId: + type: integer + unit: + type: string + updated_at: type: string type: object test.SupplierType: @@ -1566,7 +1597,7 @@ name: data required: true schema: - $ref: '#/definitions/test.Product' + $ref: '#/definitions/request.GetById' produces: - application/json responses: @@ -1607,58 +1638,10 @@ consumes: - application/json parameters: - - in: query - name: created_at - type: string - - in: query - name: deliveryTime - type: integer - description: 涓婚敭ID in: query name: id type: integer - - in: query - name: maximumStock - type: integer - - in: query - name: minimumStock - type: integer - - in: query - name: modelNumber - type: string - - in: query - name: name - type: string - - in: query - name: number - type: string - - in: query - name: productType - type: string - - in: query - name: purchasePrice - type: number - - in: query - name: remark - type: string - - in: query - name: shippingDuration - type: integer - - in: query - name: specifications - type: string - - in: query - name: supplierId - type: integer - - in: query - name: supplierName - type: string - - in: query - name: unit - type: string - - in: query - name: updated_at - type: string produces: - application/json responses: @@ -1677,28 +1660,12 @@ - application/json parameters: - in: query - name: created_at - type: string - - in: query name: deliveryTime - type: integer - - in: query - name: endCreatedAt - type: string - - description: 涓婚敭ID - in: query - name: id type: integer - description: 鍏抽敭瀛� in: query name: keyword type: string - - in: query - name: maximumStock - type: integer - - in: query - name: minimumStock - type: integer - in: query name: modelNumber type: string @@ -1723,16 +1690,13 @@ name: purchasePrice type: number - in: query - name: remark - type: string - - in: query name: shippingDuration type: integer - in: query name: specifications type: string - in: query - name: startCreatedAt + name: supplier type: string - in: query name: supplierId @@ -1745,9 +1709,6 @@ type: string - in: query name: unit - type: string - - in: query - name: updated_at type: string produces: - application/json @@ -1767,28 +1728,12 @@ - application/json parameters: - in: query - name: created_at - type: string - - in: query name: deliveryTime - type: integer - - in: query - name: endCreatedAt - type: string - - description: 涓婚敭ID - in: query - name: id type: integer - description: 鍏抽敭瀛� in: query name: keyword type: string - - in: query - name: maximumStock - type: integer - - in: query - name: minimumStock - type: integer - in: query name: modelNumber type: string @@ -1813,16 +1758,13 @@ name: purchasePrice type: number - in: query - name: remark - type: string - - in: query name: shippingDuration type: integer - in: query name: specifications type: string - in: query - name: startCreatedAt + name: supplier type: string - in: query name: supplierId @@ -1835,9 +1777,6 @@ type: string - in: query name: unit - type: string - - in: query - name: updated_at type: string produces: - application/json @@ -1861,7 +1800,7 @@ name: data required: true schema: - $ref: '#/definitions/test.Product' + $ref: '#/definitions/test.SupplierMaterial' produces: - application/json responses: diff --git a/initialize/gorm.go b/initialize/gorm.go index a99ef06..42ae347 100644 --- a/initialize/gorm.go +++ b/initialize/gorm.go @@ -34,6 +34,7 @@ test.SupplierType{}, test.Supplier{}, test.Contract{}, + test.SupplierMaterial{}, purchase.Purchase{}, purchase.PurchaseProducts{}, ) diff --git a/main.go b/main.go index a8d8ebe..50fa538 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,7 @@ } go test.InitProductServiceConn() + defer test.CloseProductServiceConn() initialize.InitRpcClient() defer initialize.CloseRpcClient() diff --git a/model/purchase/purchase_products.go b/model/purchase/purchase_products.go index e372392..c89a3c3 100644 --- a/model/purchase/purchase_products.go +++ b/model/purchase/purchase_products.go @@ -8,13 +8,13 @@ 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 - Product test.Product `json:"-" 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:鎻忚堪"` //鎻忚堪 + PurchaseId int `json:"purchaseId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:閲囪喘绫诲瀷id"` // 閲囪喘id + ProductId string `json:"productId" form:"productId" gorm:"type:varchar(255);not null;default '';comment:浜у搧id"` // 浜у搧id + Product test.SupplierMaterial `json:"-" 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:鎻忚堪"` //鎻忚堪 } func (PurchaseProducts) TableName() string { diff --git a/model/test/attachment.go b/model/test/attachment.go new file mode 100644 index 0000000..fd58dc0 --- /dev/null +++ b/model/test/attachment.go @@ -0,0 +1,23 @@ +package test + +// Attachment 缁撴瀯浣� +type Attachment struct { + ID uint `gorm:"primarykey"` // 涓婚敭ID + FileName string `json:"fileName" gorm:"type:varchar(127);comment:鏂囦欢鍚�"` + FileUrl string `json:"FileUrl" gorm:"type:varchar(255);comment:鏂囦欢鍦板潃"` + Ext string `json:"ext" gorm:"type:varchar(15);comment:鏂囦欢鍚庣紑鍚�"` + FileType FileType `json:"fileType" gorm:"type:varchar(31);comment:鏂囦欢绫诲瀷 pic:鍥剧墖;thumbnail:缂╃暐鍥�;file:鏂囦欢"` +} + +// TableName MaterialAttachment 琛ㄥ悕 +func (Attachment) TableName() string { + return "attachment" +} + +type FileType string + +const ( + FileType_File FileType = "file" //鏂囦欢 + FileType_Picture FileType = "picture" //鍥剧墖 + FileType_Thumbnail FileType = "thumbnail" //缂╃暐鍥� +) diff --git a/model/test/material.go b/model/test/material.go new file mode 100644 index 0000000..31d322d --- /dev/null +++ b/model/test/material.go @@ -0,0 +1,114 @@ +package test + +import ( + "github.com/shopspring/decimal" +) + +// Material 缁撴瀯浣� +type Material struct { + ID string + Name string `gorm:"type:varchar(191);not null;comment:鐗╂枡鍚嶇О" json:"name"` + MaterialType MaterialType `gorm:"index;type:int(11);comment:鐗╂枡绫诲瀷(鏁板瓧)" json:"materialType"` + Model MaterialMode `gorm:"type:varchar(191);not null;comment:鐗╂枡绫诲瀷(瀛楃涓�)" json:"model"` + Explain string `gorm:"type:varchar(512);comment:缂栧彿璇存槑" json:"explain"` + CodeStandardID string `gorm:"type:varchar(191);comment:缂栫爜瑙勮寖ID" json:"codeStandardID"` + Specs string `gorm:"type:varchar(191);comment:鐗╂枡瑙勬牸" json:"specs"` + Type string `gorm:"type:varchar(191);comment:鐗╂枡鍨嬪彿" json:"type"` + MinInventory decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�灏忓簱瀛�" json:"minInventory"` + MaxInventory decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�澶у簱瀛�" json:"maxInventory"` + Amount decimal.Decimal `gorm:"type:decimal(35,18);comment:鏁伴噺" json:"amount"` + LockAmount decimal.Decimal `gorm:"type:decimal(35,18);default:0;comment:閿佸畾鏁伴噺" json:"lockAmount"` + Unit string `gorm:"type:varchar(100);comment:鍗曚綅" json:"unit"` + Note string `gorm:"type:varchar(1024);comment:澶囨敞" json:"note"` + TemplateID string `gorm:"type:varchar(191);comment:妯℃澘ID" json:"-"` + FSource string `gorm:"type:varchar(191);comment:鐢熶骇杞﹂棿" json:"-"` + Status MaterialStatus `gorm:"type:int(11);comment:鐘舵��" json:"status"` + Supplier string `gorm:"type:varchar(191);comment:渚涘簲鍟�" json:"supplier"` + PurchasePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:閲囪喘浠锋牸" json:"purchasePrice"` + PurchaseAheadDay int `gorm:"type:int(11);comment:閲囪喘鎻愬墠鏈�(澶�)" json:"purchaseAheadDay"` + ProduceAheadDay int `gorm:"type:int(11);comment:鍒堕�犳彁鍓嶆湡(澶�)" json:"produceAheadDay"` + MinPurchaseAmount decimal.Decimal `gorm:"type:decimal(35,18);comment:鏈�灏忛噰璐噺" json:"minPurchaseAmount"` + PurchaseType PurchaseType `gorm:"type:int(11);comment:閲囪喘绫诲瀷" json:"purchaseType"` + IsSale *bool `gorm:"type:tinyint(1);comment:鏄惁閿�鍞�" json:"isSale"` + SalePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:閿�鍞崟浠�" json:"salePrice"` + AutoIncr uint `gorm:"type:int(11);comment:鑷ID;default:0;" json:"autoIncr"` + AttachmentList []*Attachment `json:"attachmentList" gorm:"many2many:material_attachment"` +} + +// PurchaseType 閲囪喘绫诲瀷 +type PurchaseType int + +const ( + PurchaseTypeOutSource PurchaseType = iota + 1 // 閲囪喘 + PurchaseTypeSelf // 鑷埗 + PurchaseTypeEntrust // 濮斿 +) + +type MaterialStatus int + +const ( + MaterialStatusCreate MaterialStatus = iota // 鏂板缓 + MaterialStatusActive // 鍚敤 + MaterialStatusInactive = -1 // 鍋滅敤 +) + +// MaterialMode 鐗╂枡绫诲瀷(瀛楃涓诧級 +type MaterialMode string + +const ( + MaterialModeRaw MaterialMode = "鍘熸潗鏂�" + MaterialModeSemi MaterialMode = "鍗婃垚鍝�" + MaterialModeFinished MaterialMode = "鎴愬搧" + MaterialModeAuxiliary MaterialMode = "杈呮枡" //杈呮枡 + MaterialModeConsumables MaterialMode = "鑰楁潗" //鑰楁潗 + MaterialModeOther MaterialMode = "鍏朵粬" //鍏朵粬 +) + +func (t MaterialMode) Valid() bool { + if t != MaterialModeRaw && + t != MaterialModeSemi && + t != MaterialModeAuxiliary && + t != MaterialModeConsumables && + t != MaterialModeOther && + t != MaterialModeFinished { + return false + } + return true +} + +func (t MaterialMode) Type() MaterialType { + switch t { + case MaterialModeRaw: + return MaterialTypeRaw + case MaterialModeSemi: + return MaterialTypeSemi + case MaterialModeFinished: + return MaterialTypeFinished + } + return MaterialType(0) +} + +// MaterialType 鐗╂枡绫诲瀷(鏁板瓧) +type MaterialType int + +const ( + MaterialTypeRaw = iota + 1 // 鍘熸潗鏂� + MaterialTypeSemi // 鍗婃垚鍝� + MaterialTypeFinished // 鎴愬搧 + MaterialTypeAuxiliary //杈呮枡 + MaterialTypeConsumables //鑰楁潗 + MaterialTypeOther //鍏朵粬 +) + +func (t MaterialType) Valid() bool { + if t < MaterialTypeRaw || + t > MaterialTypeFinished { + return false + } + return true +} + +// TableName Product 琛ㄥ悕 +func (Material) TableName() string { + return "material" +} diff --git a/model/test/product.go b/model/test/product.go index 1d8fe9a..258f6c0 100644 --- a/model/test/product.go +++ b/model/test/product.go @@ -1,28 +1,27 @@ package test -import "srm/global" +import ( + "srm/global" +) -// Product 缁撴瀯浣� -type Product struct { +// SupplierMaterial 缁撴瀯浣� +type SupplierMaterial struct { global.GVA_MODEL - Name string `json:"name" form:"name" gorm:"column:name;comment:鍚嶇О;size:255;"` - Number string `json:"number" form:"number" gorm:"column:number;comment:缂栫爜;size:255;"` + Name string `gorm:"type:varchar(191);not null;comment:鐗╂枡鍚嶇О" json:"name"` + Number string `json:"number" form:"number" gorm:"column:number;comment:鐗╂枡缂栫爜;size:255;"` SupplierId uint `json:"supplierId" form:"supplierId" gorm:"column:supplier_id;comment:渚涘簲鍟唅d;size:255;"` - Supplier Supplier `json:"supplier" form:"supplier" gorm:"foreignKey:SupplierId;references:ID;comment:渚涘簲鍟�"` + Supplier Supplier `json:"supplier" form:"supplier" gorm:"foreignKey:SupplierId;comment:渚涘簲鍟�"` 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;"` + 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;"` - MinimumStock int `json:"minimumStock" form:"minimumStock" gorm:"column:minimum_stock;comment:鏈�浣庡簱瀛�;"` - MaximumStock int `json:"maximumStock" form:"maximumStock" gorm:"column:maximum_stock;comment:鏈�楂樺簱瀛�;"` - Remark string `json:"remark" form:"remark" gorm:"column:remark;comment:澶囨敞;size:255;"` - SupplierName string `json:"supplierName" gorm:"-"` + MinimumStock int64 `json:"minimumStock" form:"minimumStock" gorm:"column:minimum_stock;comment:鏈�浣庡簱瀛�;"` + MaximumStock int64 `json:"maximumStock" form:"maximumStock" gorm:"column:maximum_stock;comment:鏈�楂樺簱瀛�;"` } // TableName Product 琛ㄥ悕 -func (Product) TableName() string { - return "srm_product" +func (SupplierMaterial) TableName() string { + return "srm_supplier_material" } diff --git a/model/test/request/product.go b/model/test/request/product.go index b9c3c28..1268b07 100644 --- a/model/test/request/product.go +++ b/model/test/request/product.go @@ -2,18 +2,29 @@ import ( "srm/model/common/request" - "srm/model/test" - "time" ) type ProductSearch struct { - test.Product - SupplierNumber string `json:"supplierNumber" form:"supplierNumber"` - StartCreatedAt *time.Time `json:"startCreatedAt" form:"startCreatedAt"` - EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"` + Product request.PageInfo } type ProductCreate struct { - List []*test.Product `json:"list"` + List []*Product `json:"list"` +} + +type Product struct { + Name string `json:"name" form:"name" gorm:"column:name;comment:鍚嶇О;size:255;"` + Number string `json:"number" form:"number" gorm:"column:number;comment:缂栫爜;size:255;"` + SupplierId uint `json:"supplierId" form:"supplierId" gorm:"column:supplier_id;comment:渚涘簲鍟唅d;size:255;"` + Supplier string `json:"supplier" form:"supplier" gorm:"foreignKey:SupplierId;references:ID;comment:渚涘簲鍟�"` + 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;"` + SupplierName string `json:"supplierName" gorm:"-"` + SupplierNumber string `json:"supplierNumber" form:"supplierNumber"` } diff --git a/model/test/response/product.go b/model/test/response/product.go new file mode 100644 index 0000000..853d096 --- /dev/null +++ b/model/test/response/product.go @@ -0,0 +1,18 @@ +package productresponse + +type Product struct { + Name string `json:"name" form:"name" gorm:"column:name;comment:鍚嶇О;size:255;"` + Number string `json:"number" form:"number" gorm:"column:number;comment:缂栫爜;size:255;"` + SupplierId uint `json:"supplierId" form:"supplierId" gorm:"column:supplier_id;comment:渚涘簲鍟唅d;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;"` + MinimumStock int64 `json:"minimumStock" form:"minimumStock" gorm:"column:minimum_stock;comment:鏈�浣庡簱瀛�;"` + MaximumStock int64 `json:"maximumStock" form:"maximumStock" gorm:"column:maximum_stock;comment:鏈�楂樺簱瀛�;"` + Remark string `json:"remark" form:"remark" gorm:"column:remark;comment:澶囨敞;size:255;"` + SupplierName string `json:"supplierName" gorm:"-"` +} diff --git a/service/purchase/purchase.go b/service/purchase/purchase.go index 87c542e..2a3a9cb 100644 --- a/service/purchase/purchase.go +++ b/service/purchase/purchase.go @@ -131,10 +131,10 @@ var purchaseList = make([]*purchase.Purchase, 0) if info.Keyword != "" { db.Distinct("srm_purchase.id").Joins("left join srm_purchase_products on srm_purchase_products.purchase_id = srm_purchase.id"). - Joins("left join srm_product on srm_product.Id = srm_purchase_products.product_id"). + Joins("left join material on material.id = srm_purchase_products.product_id"). Joins("left join srm_supplier on srm_supplier.Id = srm_purchase.supplier_id"). Where("srm_purchase.name like ?", "%"+info.Keyword+"%"). - Or("srm_product.name like ?", "%"+info.Keyword+"%"). + Or("material.name like ?", "%"+info.Keyword+"%"). Or("srm_supplier.name like ?", "%"+info.Keyword+"%") err = db.Limit(limit).Offset(offset).Find(&ids).Error if err != nil { @@ -212,7 +212,7 @@ } productIds := make([]uint, 0, len(productList)) for _, product := range productList { - productIds = append(productIds, uint(product.ProductId)) + productIds = append(productIds, product.ID) } productService := &test.ProductService{} _, productMap, err := productService.GetProducts(productIds) @@ -221,7 +221,7 @@ } inspectOrders := make([]*qualityinspect.QualityInspect, 0, len(productList)) for _, productItem := range productList { - product := productMap[uint(productItem.ProductId)] + product := productMap[productItem.ID] if product == nil { continue } diff --git a/service/test/product.go b/service/test/product.go index b4d05c2..7a93660 100644 --- a/service/test/product.go +++ b/service/test/product.go @@ -12,103 +12,72 @@ // CreateProduct 鍒涘缓Product璁板綍 // Author [piexlmax](https://github.com/piexlmax) -func (pService *ProductService) CreateProduct(p []*test.Product) (err error) { - err = global.GVA_DB.Create(p).Error +func (pService *ProductService) CreateProduct(pList []*testReq.Product) (err error) { + + products := make([]*test.SupplierMaterial, 0, len(pList)) + + for _, p := range pList { + products = append(products, &test.SupplierMaterial{ + Name: p.Name, + Number: p.Number, + SupplierId: p.SupplierId, + Unit: p.Unit, + PurchasePrice: p.PurchasePrice, + DeliveryTime: p.DeliveryTime, + ShippingDuration: p.ShippingDuration, + Specifications: p.Specifications, + }) + } + + err = global.GVA_DB.Create(products).Error return err } // DeleteProduct 鍒犻櫎Product璁板綍 // Author [piexlmax](https://github.com/piexlmax) -func (pService *ProductService) DeleteProduct(p test.Product) (err error) { - err = global.GVA_DB.Delete(&p).Error +func (pService *ProductService) DeleteProduct(id int) (err error) { + err = global.GVA_DB.Delete(&test.SupplierMaterial{}, "id = ?", id).Error return err } // DeleteProductByIds 鎵归噺鍒犻櫎Product璁板綍 // Author [piexlmax](https://github.com/piexlmax) func (pService *ProductService) DeleteProductByIds(ids request.IdsReq) (err error) { - err = global.GVA_DB.Delete(&[]test.Product{}, "id in ?", ids.Ids).Error + err = global.GVA_DB.Delete(&[]test.SupplierMaterial{}, "id in ?", ids.Ids).Error return err } // UpdateProduct 鏇存柊Product璁板綍 // Author [piexlmax](https://github.com/piexlmax) -func (pService *ProductService) UpdateProduct(p test.Product) (err error) { +func (pService *ProductService) UpdateProduct(p test.SupplierMaterial) (err error) { err = global.GVA_DB.Updates(&p).Error return err } // GetProduct 鏍规嵁id鑾峰彇Product璁板綍 // Author [piexlmax](https://github.com/piexlmax) -func (pService *ProductService) GetProduct(id uint) (p test.Product, err error) { +func (pService *ProductService) GetProduct(id int) (p test.SupplierMaterial, err error) { err = global.GVA_DB.Where("id = ?", id).First(&p).Error return } // GetProductInfoList 鍒嗛〉鑾峰彇Product璁板綍 // Author [piexlmax](https://github.com/piexlmax) -func (pService *ProductService) GetProductInfoList(info testReq.ProductSearch) (list []test.Product, total int64, err error) { +func (pService *ProductService) GetProductInfoList(info testReq.ProductSearch) (list []test.SupplierMaterial, total int64, err error) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) // 鍒涘缓db - db := global.GVA_DB.Model(&test.Product{}) - var ps []test.Product - // 濡傛灉鏈夋潯浠舵悳绱� 涓嬫柟浼氳嚜鍔ㄥ垱寤烘悳绱㈣鍙� + db := global.GVA_DB.Model(&test.SupplierMaterial{}) + var ps []test.SupplierMaterial //鎼滅储妗嗗悎涓�娣诲姞鏌ヨ鏉′欢 if info.Keyword != "" { - db = db.Where("srm_product.name LIKE ?", "%"+info.Keyword+"%").Joins("srm_supplier").Or("srm_supplier.name LIKE ?", "%"+info.Keyword+"%") - } - if info.StartCreatedAt != nil && info.EndCreatedAt != nil { - db = db.Where("created_at BETWEEN ? AND ?", info.StartCreatedAt, info.EndCreatedAt) + db = db.Where("srm_supplier_material.name LIKE ?", "%"+info.Keyword+"%").Joins("srm_supplier").Or("srm_supplier.name LIKE ?", "%"+info.Keyword+"%") } if info.Name != "" { db = db.Where("name LIKE ?", "%"+info.Name+"%") } if info.Number != "" { db = db.Where("number LIKE ?", "%"+info.Number+"%") - } - if info.Unit != "" { - db = db.Where("unit LIKE ?", "%"+info.Unit+"%") - } - - if info.SupplierId != 0 { - db = db.Where("supplier_id = ?", info.SupplierId) - } - - if info.MaximumStock != 0 { - db = db.Where("maximum_stock = ?", info.MaximumStock) - } - - if info.MinimumStock != 0 { - db = db.Where("minimum_stock = ?", info.MinimumStock) - } - - if info.PurchasePrice != 0 { - db = db.Where("purchase_price = ?", info.PurchasePrice) - } - - if info.Specifications != "" { - db = db.Where("specifications LIKE ?", "%"+info.Specifications+"%") - } - - if info.ModelNumber != "" { - db = db.Where("model_number LIKE ?", "%"+info.ModelNumber+"%") - } - - if info.ProductType != "" { - db = db.Where("product_type LIKE ?", "%"+info.ProductType+"%") - } - - if info.SupplierNumber != "" { - db = db.Joins("srm_supplier").Where("srm_supplier.number LIKE ?", "%"+info.SupplierNumber+"%") - } - - if info.DeliveryTime != 0 { - db = db.Where("delivery_time = ?", info.DeliveryTime) - } - - if info.ShippingDuration != 0 { - db = db.Where("shipping_duration = ?", info.ShippingDuration) } err = db.Count(&total).Error @@ -121,12 +90,12 @@ } // GetProducts 鏍规嵁ids鑾峰彇Product璁板綍 -func (pService *ProductService) GetProducts(ids []uint) (p []*test.Product, m map[uint]*test.Product, err error) { +func (pService *ProductService) GetProducts(ids []uint) (p []*test.SupplierMaterial, m map[uint]*test.SupplierMaterial, err error) { err = global.GVA_DB.Where("id in ?", ids).Find(&p).Error if err != nil { return } - m = make(map[uint]*test.Product, len(p)) + m = make(map[uint]*test.SupplierMaterial, len(p)) for _, product := range p { m[product.ID] = product } -- Gitblit v1.8.0