zhangqian
2023-11-15 6aceac83950d3f17a1137d984df4b1086bfbd016
重构产品
3个文件已添加
12个文件已修改
1325 ■■■■■ 已修改文件
api/v1/test/product.go 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
config.yaml 62 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 330 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 330 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 215 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
initialize/gorm.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/purchase/purchase_products.go 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/attachment.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/material.go 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/product.go 29 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/request/product.go 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/response/product.go 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/purchase/purchase.go 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/test/product.go 89 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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 "用id查询Product"
// @Param data query request.GetById true "用id查询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
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
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": "用id查询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": {
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": "用id查询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": {
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:
initialize/gorm.go
@@ -34,6 +34,7 @@
        test.SupplierType{},
        test.Supplier{},
        test.Contract{},
        test.SupplierMaterial{},
        purchase.Purchase{},
        purchase.PurchaseProducts{},
    )
main.go
@@ -35,6 +35,7 @@
    }
    go test.InitProductServiceConn()
    defer test.CloseProductServiceConn()
    initialize.InitRpcClient()
    defer initialize.CloseRpcClient()
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:供应商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 {
model/test/attachment.go
New file
@@ -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" //缩略图
)
model/test/material.go
New file
@@ -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"
}
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:供应商id;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"
}
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:供应商id;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"`
}
model/test/response/product.go
New file
@@ -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:供应商id;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:"-"`
}
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
        }
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
    }