zhangqian
2023-11-15 03915064efe8fd7f222e4aac199af7e2d37deec6
增加产品类别
1个文件已删除
9个文件已修改
214 ■■■■ 已修改文件
api/v1/test/product.go 65 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/attachment.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/material.go 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/product.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/request/product.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/test/response/product.go 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/test/product.go 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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"
@@ -12,7 +11,6 @@
    "srm/model/test"
    testReq "srm/model/test/request"
    testResp "srm/model/test/response"
    "srm/proto/product"
    "srm/service"
)
@@ -195,6 +193,7 @@
            MaximumStock:     item.MaximumStock,
            Remark:           "",
            SupplierName:     item.Supplier.Name,
            CategoryName:     item.CategoryName,
        })
    }
@@ -242,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([]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 := int64(v.MinInventory)
        productList[k].MinimumStock = min
        max := int64(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)
}
docs/docs.go
@@ -1257,6 +1257,11 @@
                "summary": "分页获取Product列表",
                "parameters": [
                    {
                        "type": "string",
                        "name": "categoryName",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "name": "deliveryTime",
                        "in": "query"
@@ -1292,11 +1297,6 @@
                        "type": "integer",
                        "description": "每页大小",
                        "name": "pageSize",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "name": "productType",
                        "in": "query"
                    },
                    {
@@ -1369,6 +1369,11 @@
                "summary": "分页获取Product列表",
                "parameters": [
                    {
                        "type": "string",
                        "name": "categoryName",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "name": "deliveryTime",
                        "in": "query"
@@ -1404,11 +1409,6 @@
                        "type": "integer",
                        "description": "每页大小",
                        "name": "pageSize",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "name": "productType",
                        "in": "query"
                    },
                    {
@@ -3807,6 +3807,9 @@
        "request.Product": {
            "type": "object",
            "properties": {
                "categoryName": {
                    "type": "string"
                },
                "deliveryTime": {
                    "type": "integer"
                },
@@ -3817,9 +3820,6 @@
                    "type": "string"
                },
                "number": {
                    "type": "string"
                },
                "productType": {
                    "type": "string"
                },
                "purchasePrice": {
@@ -4111,6 +4111,10 @@
        "test.SupplierMaterial": {
            "type": "object",
            "properties": {
                "categoryName": {
                    "description": "产品类别名称",
                    "type": "string"
                },
                "created_at": {
                    "type": "string"
                },
docs/swagger.json
@@ -1248,6 +1248,11 @@
                "summary": "分页获取Product列表",
                "parameters": [
                    {
                        "type": "string",
                        "name": "categoryName",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "name": "deliveryTime",
                        "in": "query"
@@ -1283,11 +1288,6 @@
                        "type": "integer",
                        "description": "每页大小",
                        "name": "pageSize",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "name": "productType",
                        "in": "query"
                    },
                    {
@@ -1360,6 +1360,11 @@
                "summary": "分页获取Product列表",
                "parameters": [
                    {
                        "type": "string",
                        "name": "categoryName",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "name": "deliveryTime",
                        "in": "query"
@@ -1395,11 +1400,6 @@
                        "type": "integer",
                        "description": "每页大小",
                        "name": "pageSize",
                        "in": "query"
                    },
                    {
                        "type": "string",
                        "name": "productType",
                        "in": "query"
                    },
                    {
@@ -3798,6 +3798,9 @@
        "request.Product": {
            "type": "object",
            "properties": {
                "categoryName": {
                    "type": "string"
                },
                "deliveryTime": {
                    "type": "integer"
                },
@@ -3808,9 +3811,6 @@
                    "type": "string"
                },
                "number": {
                    "type": "string"
                },
                "productType": {
                    "type": "string"
                },
                "purchasePrice": {
@@ -4102,6 +4102,10 @@
        "test.SupplierMaterial": {
            "type": "object",
            "properties": {
                "categoryName": {
                    "description": "产品类别名称",
                    "type": "string"
                },
                "created_at": {
                    "type": "string"
                },
docs/swagger.yaml
@@ -658,6 +658,8 @@
    type: object
  request.Product:
    properties:
      categoryName:
        type: string
      deliveryTime:
        type: integer
      modelNumber:
@@ -665,8 +667,6 @@
      name:
        type: string
      number:
        type: string
      productType:
        type: string
      purchasePrice:
        type: number
@@ -860,6 +860,9 @@
    type: object
  test.SupplierMaterial:
    properties:
      categoryName:
        description: 产品类别名称
        type: string
      created_at:
        type: string
      deliveryTime:
@@ -1660,6 +1663,9 @@
      - application/json
      parameters:
      - in: query
        name: categoryName
        type: string
      - in: query
        name: deliveryTime
        type: integer
      - description: 关键字
@@ -1683,9 +1689,6 @@
        in: query
        name: pageSize
        type: integer
      - in: query
        name: productType
        type: string
      - in: query
        name: purchasePrice
        type: number
@@ -1728,6 +1731,9 @@
      - application/json
      parameters:
      - in: query
        name: categoryName
        type: string
      - in: query
        name: deliveryTime
        type: integer
      - description: 关键字
@@ -1751,9 +1757,6 @@
        in: query
        name: pageSize
        type: integer
      - in: query
        name: productType
        type: string
      - in: query
        name: purchasePrice
        type: number
model/test/attachment.go
File was deleted
model/test/material.go
@@ -10,8 +10,6 @@
    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"`
@@ -19,9 +17,7 @@
    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"`
@@ -29,10 +25,8 @@
    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"`
    CategoryName      string          `gorm:"type:varchar(255);comment:产品类别名称" json:"categoryName"` //产品类别名称
}
// PurchaseType 采购类型
model/test/product.go
@@ -19,6 +19,7 @@
    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:最高库存;"`
    CategoryName     string   `gorm:"type:varchar(255);comment:产品类别名称" json:"categoryName"` //产品类别名称
}
// TableName Product 表名
model/test/request/product.go
@@ -24,7 +24,7 @@
    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;"`
    CategoryName     string  `json:"categoryName" form:"categoryName" gorm:"column:category_name;comment:产品类别;size:255;"`
    SupplierName     string  `json:"supplierName" gorm:"-"`
    SupplierNumber   string  `json:"supplierNumber" form:"supplierNumber"`
}
model/test/response/product.go
@@ -15,4 +15,17 @@
    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"` //产品类别名称
}
service/test/product.go
@@ -26,6 +26,7 @@
            DeliveryTime:     p.DeliveryTime,
            ShippingDuration: p.ShippingDuration,
            Specifications:   p.Specifications,
            CategoryName:     p.CategoryName,
        })
    }
@@ -105,3 +106,25 @@
    }
    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
}