From d20acf38c36c11ee4428c3e74a17f5870dc61b51 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期四, 16 十一月 2023 09:51:00 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/SRM --- model/test/response/product.go | 31 + model/test/product.go | 30 model/purchase/purchase_products.go | 14 model/test/material.go | 108 ++++ config.yaml | 62 -- go.mod | 1 core/internal/file_rotatelogs.go | 2 docs/swagger.yaml | 222 +++----- api/v1/test/product.go | 125 ++-- docs/docs.go | 338 ++++-------- docs/swagger.json | 338 ++++-------- go.sum | 24 service/test/product.go | 108 ++-- main.go | 2 model/test/request/product.go | 25 service/purchase/purchase.go | 8 initialize/gorm.go | 3 initialize/internal/gorm.go | 38 - 18 files changed, 661 insertions(+), 818 deletions(-) diff --git a/api/v1/test/product.go b/api/v1/test/product.go index dfb82c9..aba8c67 100644 --- a/api/v1/test/product.go +++ b/api/v1/test/product.go @@ -2,7 +2,6 @@ import ( "github.com/gin-gonic/gin" - "github.com/spf13/cast" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" @@ -11,7 +10,7 @@ "srm/model/common/response" "srm/model/test" testReq "srm/model/test/request" - "srm/proto/product" + testResp "srm/model/test/response" "srm/service" ) @@ -38,7 +37,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 +62,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 +110,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 +134,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 +168,41 @@ 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, + CategoryName: item.CategoryName, + }) + } + + response.OkWithDetailed(response.PageResult{ + List: list, + Total: total, + Page: pageInfo.Page, + PageSize: pageInfo.PageSize, + }, "鑾峰彇鎴愬姛", c) } var ( @@ -222,39 +241,39 @@ return } - cli := product.NewProductServiceClient(productServiceConn) - getProductListResponse, err := cli.GetProductList(c, &product.GetProductListRequest{ - Page: cast.ToInt32(pageInfo.Page), - PageSize: cast.ToInt32(pageInfo.PageSize), - ProductNumber: pageInfo.Number, - ProductName: pageInfo.Name, - }) - rawProductList := getProductListResponse.List - productList := make([]test.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) - productList[k].MinimumStock = min - max := int(v.MaxInventory) - productList[k].MaximumStock = max - productList[k].Remark = v.Node - productList[k].ProductType = v.MaterialMode - } - - if err != nil || getProductListResponse.Code != 0 { + list, total, err := pService.GetMaterials(pageInfo) + if err != nil { global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) response.FailWithMessage("鑾峰彇澶辫触", c) - } else { - response.OkWithDetailed(response.PageResult{ - List: productList, - Total: int64(len(productList)), - Page: pageInfo.Page, - PageSize: pageInfo.PageSize, - }, "鑾峰彇鎴愬姛", c) + return } + productList := make([]testResp.Material, len(list)) + + for _, item := range list { + productList = append(productList, testResp.Material{ + Name: item.Name, + Number: item.ID, + Unit: item.Unit, + Specifications: item.Specs, + ModelNumber: string(item.Model), + MinimumStock: item.MinInventory.IntPart(), + MaximumStock: item.MaxInventory.IntPart(), + Remark: "", + CategoryName: item.CategoryName, + }) + } + + if err != nil { + global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err)) + response.FailWithMessage("鑾峰彇澶辫触", c) + } + + response.OkWithDetailed(response.PageResult{ + List: productList, + Total: total, + Page: pageInfo.Page, + PageSize: pageInfo.PageSize, + }, "鑾峰彇鎴愬姛", c) + } diff --git a/config.yaml b/config.yaml index 3f36495..cf7226f 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 @@ -126,7 +70,7 @@ start: true with_seconds: false zap: - level: info + level: debug prefix: '[srm]' format: console director: log diff --git a/core/internal/file_rotatelogs.go b/core/internal/file_rotatelogs.go index 39e2158..dfd87d0 100644 --- a/core/internal/file_rotatelogs.go +++ b/core/internal/file_rotatelogs.go @@ -17,7 +17,7 @@ // Author [SliverHorn](https://github.com/SliverHorn) func (r *fileRotatelogs) GetWriteSyncer(level string) (zapcore.WriteSyncer, error) { fileWriter, err := rotatelogs.New( - path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d", level+".log"), + path.Join(global.GVA_CONFIG.Zap.Director, level+".log"), rotatelogs.WithClock(rotatelogs.Local), rotatelogs.WithMaxAge(time.Duration(global.GVA_CONFIG.Zap.MaxAge)*24*time.Hour), // 鏃ュ織鐣欏瓨鏃堕棿 rotatelogs.WithRotationTime(time.Hour*24), diff --git a/docs/docs.go b/docs/docs.go index 5a9791a..089c556 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" } ], @@ -1338,7 +1258,7 @@ "parameters": [ { "type": "string", - "name": "created_at", + "name": "categoryName", "in": "query" }, { @@ -1348,29 +1268,8 @@ }, { "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" }, { @@ -1401,18 +1300,8 @@ "in": "query" }, { - "type": "string", - "name": "productType", - "in": "query" - }, - { "type": "number", "name": "purchasePrice", - "in": "query" - }, - { - "type": "string", - "name": "remark", "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" } ], @@ -1486,7 +1370,7 @@ "parameters": [ { "type": "string", - "name": "created_at", + "name": "categoryName", "in": "query" }, { @@ -1496,29 +1380,8 @@ }, { "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" }, { @@ -1549,18 +1412,8 @@ "in": "query" }, { - "type": "string", - "name": "productType", - "in": "query" - }, - { "type": "number", "name": "purchasePrice", - "in": "query" - }, - { - "type": "string", - "name": "remark", "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" } } ], @@ -3719,7 +3567,7 @@ }, "productId": { "description": "浜у搧id", - "type": "integer" + "type": "string" }, "purchaseId": { "description": "閲囪喘id", @@ -3918,6 +3766,15 @@ } } }, + "request.GetById": { + "type": "object", + "properties": { + "id": { + "description": "涓婚敭ID", + "type": "integer" + } + } + }, "request.IdsReq": { "type": "object", "properties": { @@ -3940,13 +3797,57 @@ } } }, + "request.Product": { + "type": "object", + "properties": { + "categoryName": { + "type": "string" + }, + "deliveryTime": { + "type": "integer" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "number": { + "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" } } } @@ -4137,66 +4038,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": { @@ -4260,6 +4101,63 @@ } } }, + "test.SupplierMaterial": { + "type": "object", + "properties": { + "categoryName": { + "description": "浜у搧绫诲埆鍚嶇О", + "type": "string" + }, + "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 af95a95..2223c6e 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" } ], @@ -1329,7 +1249,7 @@ "parameters": [ { "type": "string", - "name": "created_at", + "name": "categoryName", "in": "query" }, { @@ -1339,29 +1259,8 @@ }, { "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" }, { @@ -1392,18 +1291,8 @@ "in": "query" }, { - "type": "string", - "name": "productType", - "in": "query" - }, - { "type": "number", "name": "purchasePrice", - "in": "query" - }, - { - "type": "string", - "name": "remark", "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" } ], @@ -1477,7 +1361,7 @@ "parameters": [ { "type": "string", - "name": "created_at", + "name": "categoryName", "in": "query" }, { @@ -1487,29 +1371,8 @@ }, { "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" }, { @@ -1540,18 +1403,8 @@ "in": "query" }, { - "type": "string", - "name": "productType", - "in": "query" - }, - { "type": "number", "name": "purchasePrice", - "in": "query" - }, - { - "type": "string", - "name": "remark", "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" } } ], @@ -3710,7 +3558,7 @@ }, "productId": { "description": "浜у搧id", - "type": "integer" + "type": "string" }, "purchaseId": { "description": "閲囪喘id", @@ -3909,6 +3757,15 @@ } } }, + "request.GetById": { + "type": "object", + "properties": { + "id": { + "description": "涓婚敭ID", + "type": "integer" + } + } + }, "request.IdsReq": { "type": "object", "properties": { @@ -3931,13 +3788,57 @@ } } }, + "request.Product": { + "type": "object", + "properties": { + "categoryName": { + "type": "string" + }, + "deliveryTime": { + "type": "integer" + }, + "modelNumber": { + "type": "string" + }, + "name": { + "type": "string" + }, + "number": { + "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" } } } @@ -4128,66 +4029,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": { @@ -4251,6 +4092,63 @@ } } }, + "test.SupplierMaterial": { + "type": "object", + "properties": { + "categoryName": { + "description": "浜у搧绫诲埆鍚嶇О", + "type": "string" + }, + "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 227f6c2..2d47c09 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -496,7 +496,7 @@ type: number productId: description: 浜у搧id - type: integer + type: string purchaseId: description: 閲囪喘id type: integer @@ -632,6 +632,12 @@ purchase: $ref: '#/definitions/purchaserequest.Purchase' type: object + request.GetById: + properties: + id: + description: 涓婚敭ID + type: integer + type: object request.IdsReq: properties: ids: @@ -646,11 +652,40 @@ $ref: '#/definitions/test.Industry' type: array type: object + request.Product: + properties: + categoryName: + type: string + deliveryTime: + type: integer + modelNumber: + type: string + name: + type: string + number: + 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: @@ -777,46 +812,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: @@ -857,6 +852,45 @@ updated_at: type: string url: + type: string + type: object + test.SupplierMaterial: + properties: + categoryName: + description: 浜у搧绫诲埆鍚嶇О + type: string + 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: @@ -1562,7 +1596,7 @@ name: data required: true schema: - $ref: '#/definitions/test.Product' + $ref: '#/definitions/request.GetById' produces: - application/json responses: @@ -1603,58 +1637,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: @@ -1673,28 +1659,15 @@ - application/json parameters: - in: query - name: created_at + name: categoryName 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 @@ -1713,14 +1686,8 @@ name: pageSize type: integer - in: query - name: productType - type: string - - in: query name: purchasePrice type: number - - in: query - name: remark - type: string - in: query name: shippingDuration type: integer @@ -1728,7 +1695,7 @@ name: specifications type: string - in: query - name: startCreatedAt + name: supplier type: string - in: query name: supplierId @@ -1741,9 +1708,6 @@ type: string - in: query name: unit - type: string - - in: query - name: updated_at type: string produces: - application/json @@ -1763,28 +1727,15 @@ - application/json parameters: - in: query - name: created_at + name: categoryName 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 @@ -1803,14 +1754,8 @@ name: pageSize type: integer - in: query - name: productType - type: string - - in: query name: purchasePrice type: number - - in: query - name: remark - type: string - in: query name: shippingDuration type: integer @@ -1818,7 +1763,7 @@ name: specifications type: string - in: query - name: startCreatedAt + name: supplier type: string - in: query name: supplierId @@ -1831,9 +1776,6 @@ type: string - in: query name: unit - type: string - - in: query - name: updated_at type: string produces: - application/json @@ -1857,7 +1799,7 @@ name: data required: true schema: - $ref: '#/definitions/test.Product' + $ref: '#/definitions/test.SupplierMaterial' produces: - application/json responses: diff --git a/go.mod b/go.mod index 12de828..ba23ae5 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ gorm.io/driver/postgres v1.5.2 gorm.io/driver/sqlserver v1.5.1 gorm.io/gorm v1.25.2 + moul.io/zapgorm2 v1.3.0 ) require ( diff --git a/go.sum b/go.sum index 6c1574c..5995390 100644 --- a/go.sum +++ b/go.sum @@ -45,10 +45,12 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao= github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= @@ -138,6 +140,7 @@ github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= @@ -223,10 +226,16 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/pgconn v1.10.1/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI= +github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgproto3/v2 v2.2.0/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgtype v1.9.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgx/v4 v4.14.0/go.mod h1:jT3ibf/A0ZVCp89rtCIN0zCJxcE74ypROmHEZYsG/j8= github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU= github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= @@ -237,6 +246,7 @@ github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4= @@ -379,6 +389,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= @@ -392,8 +403,12 @@ go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= +go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= +go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= @@ -445,6 +460,7 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= @@ -482,6 +498,7 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= @@ -508,6 +525,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= @@ -549,8 +567,10 @@ golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -634,6 +654,7 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= @@ -766,6 +787,7 @@ gorm.io/driver/postgres v1.5.2/go.mod h1:fmpX0m2I1PKuR7mKZiEluwrP3hbs+ps7JIGMUBpCgl8= gorm.io/driver/sqlserver v1.5.1 h1:wpyW/pR26U94uaujltiFGXY7fd2Jw5hC9PB1ZF/Y5s4= gorm.io/driver/sqlserver v1.5.1/go.mod h1:AYHzzte2msKTmYBYsSIq8ZUsznLJwBdkB2wpI+kt0nM= +gorm.io/gorm v1.23.6/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= gorm.io/gorm v1.25.2 h1:gs1o6Vsa+oVKG/a9ElL3XgyGfghFfkKA2SInQaCyMho= gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= @@ -784,6 +806,8 @@ modernc.org/memory v1.6.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= modernc.org/sqlite v1.23.0 h1:MWTFBI5H1WLnXpNBh/BTruBVqzzoh28DA0iOnlkkRaM= modernc.org/sqlite v1.23.0/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk= +moul.io/zapgorm2 v1.3.0 h1:+CzUTMIcnafd0d/BvBce8T4uPn6DQnpIrz64cyixlkk= +moul.io/zapgorm2 v1.3.0/go.mod h1:nPVy6U9goFKHR4s+zfSo1xVFaoU7Qgd5DoCdOfzoCqs= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/initialize/gorm.go b/initialize/gorm.go index 245a4a6..42ae347 100644 --- a/initialize/gorm.go +++ b/initialize/gorm.go @@ -34,8 +34,7 @@ test.SupplierType{}, test.Supplier{}, test.Contract{}, - test.Product{}, - test.Member{}, + test.SupplierMaterial{}, purchase.Purchase{}, purchase.PurchaseProducts{}, ) diff --git a/initialize/internal/gorm.go b/initialize/internal/gorm.go index 095c11c..0be474f 100644 --- a/initialize/internal/gorm.go +++ b/initialize/internal/gorm.go @@ -1,13 +1,10 @@ package internal import ( - "gorm.io/gorm/schema" - "log" - "os" - "time" - "gorm.io/gorm" "gorm.io/gorm/logger" + "gorm.io/gorm/schema" + "moul.io/zapgorm2" "srm/global" ) @@ -29,34 +26,7 @@ }, DisableForeignKeyConstraintWhenMigrating: true, } - _default := logger.New(log.New(os.Stdout, "\r\n", log.LstdFlags), logger.Config{ - SlowThreshold: 200 * time.Millisecond, - LogLevel: logger.Warn, - Colorful: true, - }) - var logMode DBBASE - switch global.GVA_CONFIG.System.DbType { - case "mysql": - logMode = &global.GVA_CONFIG.Mysql - case "pgsql": - logMode = &global.GVA_CONFIG.Pgsql - case "oracle": - logMode = &global.GVA_CONFIG.Oracle - default: - logMode = &global.GVA_CONFIG.Mysql - } - - switch logMode.GetLogMode() { - case "silent", "Silent": - config.Logger = _default.LogMode(logger.Silent) - case "error", "Error": - config.Logger = _default.LogMode(logger.Error) - case "warn", "Warn": - config.Logger = _default.LogMode(logger.Warn) - case "info", "Info": - config.Logger = _default.LogMode(logger.Info) - default: - config.Logger = _default.LogMode(logger.Info) - } + dbLogger := zapgorm2.New(global.GVA_LOG).LogMode(logger.Info) + config.Logger = dbLogger return config } diff --git a/main.go b/main.go index af4d670..fe6d232 100644 --- a/main.go +++ b/main.go @@ -65,10 +65,12 @@ test.InitProductServiceConn() qualityinspect.InitConn() purchase_wms.InitPurchaseConn() + test.InitProductServiceConn() } func closeGrpcClient() { test.CloseProductServiceConn() qualityinspect.CloseConn() purchase_wms.ClosePurchaseConn() + test.CloseProductServiceConn() } diff --git a/model/purchase/purchase_products.go b/model/purchase/purchase_products.go index 340b439..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" gorm:"type:int(11);not null;default 0;comment:閲囪喘鍗昳d"` // 閲囪喘鍗昳d - ProductId int `json:"productId" gorm:"type:int(11);not null;default 0;comment:浜у搧id"` // 浜у搧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/material.go b/model/test/material.go new file mode 100644 index 0000000..25053cb --- /dev/null +++ b/model/test/material.go @@ -0,0 +1,108 @@ +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"` + 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"` + TemplateID string `gorm:"type:varchar(191);comment:妯℃澘ID" 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"` + SalePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:閿�鍞崟浠�" json:"salePrice"` + CategoryName string `gorm:"type:varchar(255);comment:浜у搧绫诲埆鍚嶇О" json:"categoryName"` //浜у搧绫诲埆鍚嶇О +} + +// 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 e3d1951..9eeb50e 100644 --- a/model/test/product.go +++ b/model/test/product.go @@ -1,28 +1,28 @@ 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" gorm:"foreignKey:SupplierId;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:鏈�楂樺簱瀛�;"` + CategoryName string `gorm:"type:varchar(255);comment:浜у搧绫诲埆鍚嶇О" json:"categoryName"` //浜у搧绫诲埆鍚嶇О } // 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..4949214 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;"` + CategoryName string `json:"categoryName" form:"categoryName" gorm:"column:category_name;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..928f4a7 --- /dev/null +++ b/model/test/response/product.go @@ -0,0 +1,31 @@ +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:"-"` + CategoryName string `gorm:"type:varchar(255);comment:浜у搧绫诲埆鍚嶇О" json:"categoryName"` //浜у搧绫诲埆鍚嶇О +} + +type Material 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;"` + Unit string `json:"unit" form:"unit" gorm:"column:unit;comment:璁¢噺鍗曚綅;size:255;"` + 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;"` + 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;"` + CategoryName string `gorm:"type:varchar(255);comment:浜у搧绫诲埆鍚嶇О" json:"categoryName"` //浜у搧绫诲埆鍚嶇О +} diff --git a/service/purchase/purchase.go b/service/purchase/purchase.go index 58a6e2d..b8654f4 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..8ad82b5 100644 --- a/service/test/product.go +++ b/service/test/product.go @@ -12,54 +12,67 @@ // 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, + CategoryName: p.CategoryName, + }) + } + + 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("Supplier").Or("Supplier.name LIKE ?", "%"+info.Keyword+"%") } if info.Name != "" { db = db.Where("name LIKE ?", "%"+info.Name+"%") @@ -67,48 +80,9 @@ 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,14 +95,36 @@ } // 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 } return } + +// GetMaterials 鑾峰彇鐗╂枡 +func (pService *ProductService) GetMaterials(info testReq.ProductSearch) (list []test.Material, total int64, err error) { + limit := info.PageSize + offset := info.PageSize * (info.Page - 1) + // 鍒涘缓db + db := global.GVA_DB.Model(&test.Material{}) + var ps []test.Material + if info.Keyword != "" { + db = db.Where("name LIKE ? or number LIKE ?", "%"+info.Name+"%", "%"+info.Number+"%") + } + + db = db.Where("purchase_type = ?", test.PurchaseTypeOutSource) + + err = db.Count(&total).Error + if err != nil { + return + } + + err = db.Limit(limit).Offset(offset).Find(&ps).Error + return ps, total, err +} -- Gitblit v1.8.0