liujiandao
2023-09-20 548030097f2b95dff474c397c7393168c73ab8a2
产品与产品类型功能开发
11个文件已修改
2个文件已添加
3145 ■■■■ 已修改文件
constvar/const.go 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/product_controller.go 214 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 667 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 665 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 461 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
go.mod 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
go.sum 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/db.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/material.go 474 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/product.go 583 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/product_category.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/util.go 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
constvar/const.go
@@ -51,6 +51,22 @@
    StoredProduct                        // 可储存的产品
)
type MaterialMode string
const (
    MaterialModeRaw      MaterialMode = "原材料"
    MaterialModeSemi     MaterialMode = "半成品"
    MaterialModeFinished MaterialMode = "成品"
)
type MaterialStatus int
const (
    MaterialStatusCreate   MaterialStatus = iota // 新建
    MaterialStatusActive                         // 启用
    MaterialStatusInactive = -1                  // 停用
)
// InvoicingStrategy 开票策略
type InvoicingStrategy int
@@ -131,7 +147,7 @@
const (
    CostingMethodStandardPrice CostingMethod = iota + 1 //标准价格
    CostingMethodFIFO                                   //先进先出
    CostingMethodAverageCost                            //
    CostingMethodAverageCost                            //平均成本
)
func (t CostingMethod) Valid() bool {
controllers/product_controller.go
@@ -2,10 +2,12 @@
import (
    "github.com/gin-gonic/gin"
    "github.com/spf13/cast"
    "wms/extend/code"
    "wms/extend/util"
    "wms/models"
    "wms/request"
    "wms/utils"
)
type ProductController struct {
@@ -15,11 +17,11 @@
// @Tags      产品
// @Summary   添加产品
// @Produce   application/json
// @Param     object  body  models.Product true  "产品信息"
// @Param     object  body  models.Material true  "产品信息"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/product/addProduct [post]
func (slf ProductController) AddProduct(c *gin.Context) {
    var params models.Product
    var params models.Material
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
@@ -32,7 +34,16 @@
        util.ResponseFormat(c, code.RequestParamError, "产品售价不能小于等于零")
        return
    }
    err := models.NewProductSearch().Create(&params)
    if params.Model == "" {
        util.ResponseFormat(c, code.RequestParamError, "物料类型不能为空")
        return
    }
    if params.Unit == "" {
        util.ResponseFormat(c, code.RequestParamError, "单位不能为空")
        return
    }
    params.ID = utils.GetUUID()
    err := models.NewMaterialSearch().Create(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "产品信息保存失败")
        return
@@ -45,7 +56,7 @@
// @Summary   获取产品列表
// @Produce   application/json
// @Param     object  body  request.GetProductList true  "查询参数"
// @Success   200 {object} util.ResponseList{data=[]models.Product}    "成功"
// @Success   200 {object} util.ResponseList{data=[]models.Material}    "成功"
// @Router    /api-wms/v1/product/getProductList [post]
func (slf ProductController) GetProductList(c *gin.Context) {
    var params request.GetProductList
@@ -53,7 +64,7 @@
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    search := models.NewProductSearch()
    search := models.NewMaterialSearch()
    if params.PageInfo.Check() {
        search.SetPage(params.Page, params.PageSize)
    }
@@ -70,9 +81,196 @@
// @Tags      产品
// @Summary   获取产品详情
// @Produce   application/json
// @Param     object  body  request.GetProductList true  "查询参数"
// @Success   200 {object} util.ResponseList{data=[]models.Product}    "成功"
// @Router    /api-wms/v1/product/getProductList [post]
// @Param        id    path        string            true    "id"  "查询参数"
// @Success   200 {object} util.Response{data=models.Material}    "成功"
// @Router    /api-wms/v1/product/getProductDetails/{id} [get]
func (slf ProductController) GetProductDetails(c *gin.Context) {
    id := c.Param("id")
    if id == "" {
        util.ResponseFormat(c, code.RequestParamError, "无效id")
        return
    }
    material, err := models.NewMaterialSearch().SetID(id).First()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        return
    }
    util.ResponseFormat(c, code.Success, material)
}
// UpdateProduct
// @Tags      产品
// @Summary   修改产品
// @Produce   application/json
// @Param     object  body  models.Material true  "产品信息"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/product/updateProduct [post]
func (slf ProductController) UpdateProduct(c *gin.Context) {
    var params models.Material
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if params.Name == "" {
        util.ResponseFormat(c, code.RequestParamError, "产品名称不能为空")
        return
    }
    if params.SalePrice.IntPart() <= 0 {
        util.ResponseFormat(c, code.RequestParamError, "产品售价不能小于等于零")
        return
    }
    if params.Model == "" {
        util.ResponseFormat(c, code.RequestParamError, "物料类型不能为空")
        return
    }
    if params.Unit == "" {
        util.ResponseFormat(c, code.RequestParamError, "单位不能为空")
        return
    }
    err := models.NewMaterialSearch().SetID(params.ID).Save(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "产品信息更新失败")
        return
    }
    util.ResponseFormat(c, code.Success, "更新成功")
}
// DeleteProduct
// @Tags      产品
// @Summary   删除产品
// @Produce   application/json
// @Param        id    path        string            true    "id"  "查询参数"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/product/deleteProduct/{id} [delete]
func (slf ProductController) DeleteProduct(c *gin.Context) {
    id := c.Param("id")
    if id == "" {
        util.ResponseFormat(c, code.RequestParamError, "无效id")
        return
    }
    err := models.NewMaterialSearch().SetID(id).Delete()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "删除失败")
        return
    }
    util.ResponseFormat(c, code.Success, "删除成功")
}
// AddProductCategory
// @Tags      产品类型
// @Summary   添加产品类型
// @Produce   application/json
// @Param     object  body  models.ProductCategory true  "产品类型信息"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/product/addProductCategory [post]
func (slf ProductController) AddProductCategory(c *gin.Context) {
    var params models.ProductCategory
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if params.Name == "" {
        util.ResponseFormat(c, code.RequestParamError, "产品类型名称不能为空")
        return
    }
    err := models.NewProductCategorySearch().Create(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "产品类型信息保存失败")
        return
    }
    util.ResponseFormat(c, code.Success, "保存成功")
}
// GetProductCategoryList
// @Tags      产品类型
// @Summary   获取产品类型列表
// @Produce   application/json
// @Param     object  body  request.GetProductList true  "查询参数"
// @Success   200 {object} util.ResponseList{data=[]models.ProductCategory}    "成功"
// @Router    /api-wms/v1/product/getProductCategoryList [post]
func (slf ProductController) GetProductCategoryList(c *gin.Context) {
    var params request.GetProductList
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    search := models.NewProductCategorySearch()
    if params.PageInfo.Check() {
        search.SetPage(params.Page, params.PageSize)
    }
    list, total, err := search.SetKeyword(params.KeyWord).SetOrder("created_at desc").Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        return
    }
    util.ResponseFormatList(c, code.Success, list, int(total))
}
// GetProductCategoryDetails
// @Tags      产品类型
// @Summary   获取产品类型详情
// @Produce   application/json
// @Param        id    path        string            true    "id"  "查询参数"
// @Success   200 {object} util.Response{data=models.Material}    "成功"
// @Router    /api-wms/v1/product/getProductCategoryDetails/{id} [get]
func (slf ProductController) GetProductCategoryDetails(c *gin.Context) {
    id := c.Param("id")
    if id == "" {
        util.ResponseFormat(c, code.RequestParamError, "无效id")
        return
    }
    first, err := models.NewProductCategorySearch().SetID(cast.ToUint(id)).First()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        return
    }
    util.ResponseFormat(c, code.Success, first)
}
// UpdateProductCategory
// @Tags      产品类型
// @Summary   修改产品类型
// @Produce   application/json
// @Param     object  body  models.ProductCategory true  "产品信息"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/product/updateProductCategory [post]
func (slf ProductController) UpdateProductCategory(c *gin.Context) {
    var params models.ProductCategory
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if params.Name == "" {
        util.ResponseFormat(c, code.RequestParamError, "产品类型名称不能为空")
        return
    }
    err := models.NewProductCategorySearch().SetID(params.ID).Save(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "产品类型信息更新失败")
        return
    }
    util.ResponseFormat(c, code.Success, "更新成功")
}
// DeleteProductCategory
// @Tags      产品类型
// @Summary   删除产品类型
// @Produce   application/json
// @Param        id    path        string            true    "id"  "查询参数"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/product/deleteProductCategory/{id} [delete]
func (slf ProductController) DeleteProductCategory(c *gin.Context) {
    id := c.Param("id")
    if id == "" {
        util.ResponseFormat(c, code.RequestParamError, "无效id")
        return
    }
    err := models.NewProductCategorySearch().SetID(cast.ToUint(id)).Delete()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "删除失败")
        return
    }
    util.ResponseFormat(c, code.Success, "删除成功")
}
docs/docs.go
@@ -340,7 +340,7 @@
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.Product"
                            "$ref": "#/definitions/models.Material"
                        }
                    }
                ],
@@ -354,15 +354,141 @@
                }
            }
        },
        "/api-wms/v1/product/getProductList": {
        "/api-wms/v1/product/addProductCategory": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品类型"
                ],
                "summary": "添加产品类型",
                "parameters": [
                    {
                        "description": "产品类型信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.ProductCategory"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/deleteProduct/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品"
                ],
                "summary": "获取产品详情",
                "summary": "删除产品",
                "parameters": [
                    {
                        "type": "string",
                        "description": "id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/deleteProductCategory/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品类型"
                ],
                "summary": "删除产品类型",
                "parameters": [
                    {
                        "type": "string",
                        "description": "id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/getProductCategoryDetails/{id}": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品类型"
                ],
                "summary": "获取产品类型详情",
                "parameters": [
                    {
                        "type": "string",
                        "description": "id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/models.Material"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/getProductCategoryList": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品类型"
                ],
                "summary": "获取产品类型列表",
                "parameters": [
                    {
                        "description": "查询参数",
@@ -388,12 +514,157 @@
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/models.Product"
                                                "$ref": "#/definitions/models.ProductCategory"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/getProductDetails/{id}": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品"
                ],
                "summary": "获取产品详情",
                "parameters": [
                    {
                        "type": "string",
                        "description": "id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/models.Material"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/getProductList": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品"
                ],
                "summary": "获取产品列表",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.GetProductList"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.ResponseList"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/models.Material"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/updateProduct": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品"
                ],
                "summary": "修改产品",
                "parameters": [
                    {
                        "description": "产品信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.Material"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/updateProductCategory": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品类型"
                ],
                "summary": "修改产品类型",
                "parameters": [
                    {
                        "description": "产品信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.ProductCategory"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
@@ -707,6 +978,52 @@
                "BaseOperationTypeInternal"
            ]
        },
        "constvar.CostingMethod": {
            "type": "integer",
            "enum": [
                1,
                2,
                3
            ],
            "x-enum-comments": {
                "CostingMethodAverageCost": "平均成本",
                "CostingMethodFIFO": "先进先出",
                "CostingMethodStandardPrice": "标准价格"
            },
            "x-enum-varnames": [
                "CostingMethodStandardPrice",
                "CostingMethodFIFO",
                "CostingMethodAverageCost"
            ]
        },
        "constvar.ForceRemovalStrategy": {
            "type": "integer",
            "enum": [
                1,
                2,
                3
            ],
            "x-enum-varnames": [
                "ForceRemovalStrategyFIFO",
                "ForceRemovalStrategyLIFO",
                "ForceRemovalStrategyClosestLocation"
            ]
        },
        "constvar.InventoryValuation": {
            "type": "integer",
            "enum": [
                1,
                2
            ],
            "x-enum-comments": {
                "InventoryValuationAuto": "自动",
                "InventoryValuationManual": "手动"
            },
            "x-enum-varnames": [
                "InventoryValuationManual",
                "InventoryValuationAuto"
            ]
        },
        "constvar.InvoicingStrategy": {
            "type": "integer",
            "enum": [
@@ -761,6 +1078,19 @@
                "LocationTypeTransit"
            ]
        },
        "constvar.MaterialMode": {
            "type": "string",
            "enum": [
                "原材料",
                "半成品",
                "成品"
            ],
            "x-enum-varnames": [
                "MaterialModeRaw",
                "MaterialModeSemi",
                "MaterialModeFinished"
            ]
        },
        "constvar.OperationStatus": {
            "type": "integer",
            "enum": [
@@ -801,24 +1131,6 @@
                "Task",
                "Object",
                "TaskAndObject"
            ]
        },
        "constvar.ProductType": {
            "type": "integer",
            "enum": [
                1,
                2,
                3
            ],
            "x-enum-comments": {
                "Consumables": "消耗品",
                "Server": "服务",
                "StoredProduct": "可储存的产品"
            },
            "x-enum-varnames": [
                "Consumables",
                "Server",
                "StoredProduct"
            ]
        },
        "constvar.ReservationMethod": {
@@ -971,6 +1283,157 @@
                }
            }
        },
        "models.Material": {
            "type": "object",
            "properties": {
                "HSCode": {
                    "type": "string"
                },
                "amount": {
                    "type": "number"
                },
                "barcode": {
                    "description": "条码",
                    "type": "string"
                },
                "buyExplain": {
                    "type": "string"
                },
                "canBePurchased": {
                    "description": "是否可采购",
                    "type": "boolean"
                },
                "categoryId": {
                    "description": "产品类别id",
                    "type": "integer"
                },
                "companyId": {
                    "type": "integer"
                },
                "companyName": {
                    "type": "string"
                },
                "controlStrategy": {
                    "$ref": "#/definitions/constvar.InvoicingStrategy"
                },
                "cost": {
                    "description": "成本",
                    "type": "number"
                },
                "currencyName": {
                    "type": "string"
                },
                "customerTaxes": {
                    "description": "客户税百分比",
                    "type": "number"
                },
                "deliveryAdvanceTime": {
                    "type": "integer"
                },
                "id": {
                    "type": "string"
                },
                "inStorageExplain": {
                    "type": "string"
                },
                "internalNotes": {
                    "description": "内部说明",
                    "type": "string"
                },
                "internalReference": {
                    "description": "内部参考",
                    "type": "string"
                },
                "internalTransferExplain": {
                    "type": "string"
                },
                "invoicingStrategy": {
                    "description": "wms添加字段",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.InvoicingStrategy"
                        }
                    ]
                },
                "isSale": {
                    "description": "PurchaseType      constvar.PurchaseType ` + "`" + `gorm:\"type:int(11);comment:采购类型\" json:\"purchaseType\"` + "`" + `",
                    "type": "boolean"
                },
                "maxInventory": {
                    "type": "number"
                },
                "minInventory": {
                    "description": "Explain           string                  ` + "`" + `gorm:\"type:varchar(512);comment:编号说明\" json:\"explain\"` + "`" + `\nCodeStandardID    string                  ` + "`" + `gorm:\"type:varchar(191);comment:编码规范ID\" json:\"codeStandardID\"` + "`" + `\nSpecs             string                  ` + "`" + `gorm:\"type:varchar(191);comment:物料规格\" json:\"specs\"` + "`" + `\nType              string                  ` + "`" + `gorm:\"type:varchar(191);comment:物料型号\" json:\"type\"` + "`" + `",
                    "type": "number"
                },
                "minPurchaseAmount": {
                    "description": "PurchaseAheadDay  int                     ` + "`" + `gorm:\"type:int(11);comment:采购提前期(天)\" json:\"purchaseAheadDay\"` + "`" + `\nProduceAheadDay   int                     ` + "`" + `gorm:\"type:int(11);comment:制造提前期(天)\" json:\"produceAheadDay\"` + "`" + `",
                    "type": "number"
                },
                "model": {
                    "description": "MaterialType constvar.ProductType  ` + "`" + `gorm:\"index;type:int(11);comment:物料类型(数字)\" json:\"materialType\"` + "`" + `",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.MaterialMode"
                        }
                    ]
                },
                "name": {
                    "type": "string"
                },
                "orderCreation": {
                    "$ref": "#/definitions/constvar.OrderCreation"
                },
                "originCountryId": {
                    "type": "integer"
                },
                "originCountryName": {
                    "type": "string"
                },
                "outStorageExplain": {
                    "type": "string"
                },
                "principal": {
                    "description": "负责人",
                    "type": "string"
                },
                "productTagId": {
                    "description": "产品标签",
                    "type": "integer"
                },
                "productTagName": {
                    "type": "string"
                },
                "purchasePrice": {
                    "type": "number"
                },
                "salePrice": {
                    "type": "number"
                },
                "selectProduct": {
                    "type": "integer"
                },
                "sellExplain": {
                    "type": "string"
                },
                "supplier": {
                    "description": "FSource           string                  ` + "`" + `gorm:\"type:varchar(191);comment:生产车间\" json:\"-\"` + "`" + `\nStatus            constvar.MaterialStatus ` + "`" + `gorm:\"type:int(11);comment:状态\" json:\"status\"` + "`" + `",
                    "type": "string"
                },
                "unit": {
                    "description": "LockAmount        decimal.Decimal         ` + "`" + `gorm:\"type:decimal(35,18);default:0;comment:锁定数量\" json:\"lockAmount\"` + "`" + `",
                    "type": "string"
                },
                "volume": {
                    "description": "体积",
                    "type": "number"
                },
                "weight": {
                    "description": "重量",
                    "type": "number"
                }
            }
        },
        "models.OperationType": {
            "type": "object",
            "properties": {
@@ -1085,150 +1548,50 @@
                }
            }
        },
        "models.Product": {
        "models.ProductCategory": {
            "type": "object",
            "properties": {
                "HSCode": {
                    "type": "string"
                "costingMethod": {
                    "description": "成本方法",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.CostingMethod"
                        }
                    ]
                },
                "barcode": {
                    "description": "条码",
                    "type": "string"
                },
                "buyExplain": {
                    "type": "string"
                },
                "canBePurchased": {
                    "description": "是否可采购",
                    "type": "boolean"
                },
                "canBeSell": {
                    "description": "是否销售",
                    "type": "boolean"
                },
                "categoryId": {
                    "description": "产品分类id",
                    "type": "integer"
                },
                "companyId": {
                    "type": "integer"
                },
                "companyName": {
                    "type": "string"
                },
                "controlStrategy": {
                    "$ref": "#/definitions/constvar.InvoicingStrategy"
                },
                "cost": {
                    "description": "成本",
                    "type": "number"
                },
                "createTime": {
                    "type": "string"
                },
                "currencyId": {
                    "type": "integer"
                },
                "currencyName": {
                    "type": "string"
                },
                "customerAdvanceTime": {
                    "type": "number"
                },
                "customerTaxes": {
                    "description": "客户税百分比",
                    "type": "number"
                },
                "deliveryAdvanceTime": {
                    "type": "number"
                "forceRemovalStrategy": {
                    "description": "强制下架策略",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.ForceRemovalStrategy"
                        }
                    ]
                },
                "id": {
                    "type": "integer"
                },
                "inStorageExplain": {
                    "type": "string"
                },
                "internalNotes": {
                    "description": "内部说明",
                    "type": "string"
                },
                "internalReference": {
                    "description": "内部参考",
                    "type": "string"
                },
                "internalTransferExplain": {
                    "type": "string"
                },
                "invoicingStrategy": {
                    "$ref": "#/definitions/constvar.InvoicingStrategy"
                },
                "name": {
                    "description": "产品名称",
                    "type": "string"
                },
                "objectTemplateId": {
                    "type": "string"
                },
                "orderCreation": {
                    "$ref": "#/definitions/constvar.OrderCreation"
                },
                "originCountryId": {
                    "type": "integer"
                },
                "originCountryName": {
                    "type": "string"
                },
                "outStorageExplain": {
                    "type": "string"
                },
                "price": {
                    "type": "number"
                },
                "principal": {
                    "description": "负责人",
                    "type": "string"
                },
                "productTagId": {
                    "description": "产品标签",
                    "type": "integer"
                },
                "productTagName": {
                    "type": "string"
                },
                "salePrice": {
                    "description": "销售价格",
                    "type": "number"
                },
                "selectProduct": {
                    "type": "integer"
                },
                "sellExplain": {
                    "type": "string"
                },
                "supplierId": {
                    "type": "integer"
                },
                "supplierName": {
                    "type": "string"
                },
                "type": {
                    "description": "产品类型",
                "inventoryValuation": {
                    "description": "库存计价",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.ProductType"
                            "$ref": "#/definitions/constvar.InventoryValuation"
                        }
                    ]
                },
                "updateTime": {
                "name": {
                    "description": "位置名称",
                    "type": "string"
                },
                "volume": {
                    "description": "体积",
                    "type": "number"
                "parentId": {
                    "description": "上级id",
                    "type": "integer"
                },
                "weight": {
                    "description": "重量",
                    "type": "number"
                "routeId": {
                    "type": "integer"
                },
                "routeName": {
                    "description": "公司",
                    "type": "string"
                }
            }
        },
@@ -1706,6 +2069,8 @@
    Description:      "",
    InfoInstanceName: "swagger",
    SwaggerTemplate:  docTemplate,
    LeftDelim:        "{{",
    RightDelim:       "}}",
}
func init() {
docs/swagger.json
@@ -328,7 +328,7 @@
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.Product"
                            "$ref": "#/definitions/models.Material"
                        }
                    }
                ],
@@ -342,15 +342,141 @@
                }
            }
        },
        "/api-wms/v1/product/getProductList": {
        "/api-wms/v1/product/addProductCategory": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品类型"
                ],
                "summary": "添加产品类型",
                "parameters": [
                    {
                        "description": "产品类型信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.ProductCategory"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/deleteProduct/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品"
                ],
                "summary": "获取产品详情",
                "summary": "删除产品",
                "parameters": [
                    {
                        "type": "string",
                        "description": "id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/deleteProductCategory/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品类型"
                ],
                "summary": "删除产品类型",
                "parameters": [
                    {
                        "type": "string",
                        "description": "id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/getProductCategoryDetails/{id}": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品类型"
                ],
                "summary": "获取产品类型详情",
                "parameters": [
                    {
                        "type": "string",
                        "description": "id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/models.Material"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/getProductCategoryList": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品类型"
                ],
                "summary": "获取产品类型列表",
                "parameters": [
                    {
                        "description": "查询参数",
@@ -376,12 +502,157 @@
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/models.Product"
                                                "$ref": "#/definitions/models.ProductCategory"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/getProductDetails/{id}": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品"
                ],
                "summary": "获取产品详情",
                "parameters": [
                    {
                        "type": "string",
                        "description": "id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/models.Material"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/getProductList": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品"
                ],
                "summary": "获取产品列表",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.GetProductList"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.ResponseList"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/models.Material"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/updateProduct": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品"
                ],
                "summary": "修改产品",
                "parameters": [
                    {
                        "description": "产品信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.Material"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/updateProductCategory": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品类型"
                ],
                "summary": "修改产品类型",
                "parameters": [
                    {
                        "description": "产品信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.ProductCategory"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
@@ -695,6 +966,52 @@
                "BaseOperationTypeInternal"
            ]
        },
        "constvar.CostingMethod": {
            "type": "integer",
            "enum": [
                1,
                2,
                3
            ],
            "x-enum-comments": {
                "CostingMethodAverageCost": "平均成本",
                "CostingMethodFIFO": "先进先出",
                "CostingMethodStandardPrice": "标准价格"
            },
            "x-enum-varnames": [
                "CostingMethodStandardPrice",
                "CostingMethodFIFO",
                "CostingMethodAverageCost"
            ]
        },
        "constvar.ForceRemovalStrategy": {
            "type": "integer",
            "enum": [
                1,
                2,
                3
            ],
            "x-enum-varnames": [
                "ForceRemovalStrategyFIFO",
                "ForceRemovalStrategyLIFO",
                "ForceRemovalStrategyClosestLocation"
            ]
        },
        "constvar.InventoryValuation": {
            "type": "integer",
            "enum": [
                1,
                2
            ],
            "x-enum-comments": {
                "InventoryValuationAuto": "自动",
                "InventoryValuationManual": "手动"
            },
            "x-enum-varnames": [
                "InventoryValuationManual",
                "InventoryValuationAuto"
            ]
        },
        "constvar.InvoicingStrategy": {
            "type": "integer",
            "enum": [
@@ -749,6 +1066,19 @@
                "LocationTypeTransit"
            ]
        },
        "constvar.MaterialMode": {
            "type": "string",
            "enum": [
                "原材料",
                "半成品",
                "成品"
            ],
            "x-enum-varnames": [
                "MaterialModeRaw",
                "MaterialModeSemi",
                "MaterialModeFinished"
            ]
        },
        "constvar.OperationStatus": {
            "type": "integer",
            "enum": [
@@ -789,24 +1119,6 @@
                "Task",
                "Object",
                "TaskAndObject"
            ]
        },
        "constvar.ProductType": {
            "type": "integer",
            "enum": [
                1,
                2,
                3
            ],
            "x-enum-comments": {
                "Consumables": "消耗品",
                "Server": "服务",
                "StoredProduct": "可储存的产品"
            },
            "x-enum-varnames": [
                "Consumables",
                "Server",
                "StoredProduct"
            ]
        },
        "constvar.ReservationMethod": {
@@ -959,6 +1271,157 @@
                }
            }
        },
        "models.Material": {
            "type": "object",
            "properties": {
                "HSCode": {
                    "type": "string"
                },
                "amount": {
                    "type": "number"
                },
                "barcode": {
                    "description": "条码",
                    "type": "string"
                },
                "buyExplain": {
                    "type": "string"
                },
                "canBePurchased": {
                    "description": "是否可采购",
                    "type": "boolean"
                },
                "categoryId": {
                    "description": "产品类别id",
                    "type": "integer"
                },
                "companyId": {
                    "type": "integer"
                },
                "companyName": {
                    "type": "string"
                },
                "controlStrategy": {
                    "$ref": "#/definitions/constvar.InvoicingStrategy"
                },
                "cost": {
                    "description": "成本",
                    "type": "number"
                },
                "currencyName": {
                    "type": "string"
                },
                "customerTaxes": {
                    "description": "客户税百分比",
                    "type": "number"
                },
                "deliveryAdvanceTime": {
                    "type": "integer"
                },
                "id": {
                    "type": "string"
                },
                "inStorageExplain": {
                    "type": "string"
                },
                "internalNotes": {
                    "description": "内部说明",
                    "type": "string"
                },
                "internalReference": {
                    "description": "内部参考",
                    "type": "string"
                },
                "internalTransferExplain": {
                    "type": "string"
                },
                "invoicingStrategy": {
                    "description": "wms添加字段",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.InvoicingStrategy"
                        }
                    ]
                },
                "isSale": {
                    "description": "PurchaseType      constvar.PurchaseType `gorm:\"type:int(11);comment:采购类型\" json:\"purchaseType\"`",
                    "type": "boolean"
                },
                "maxInventory": {
                    "type": "number"
                },
                "minInventory": {
                    "description": "Explain           string                  `gorm:\"type:varchar(512);comment:编号说明\" json:\"explain\"`\nCodeStandardID    string                  `gorm:\"type:varchar(191);comment:编码规范ID\" json:\"codeStandardID\"`\nSpecs             string                  `gorm:\"type:varchar(191);comment:物料规格\" json:\"specs\"`\nType              string                  `gorm:\"type:varchar(191);comment:物料型号\" json:\"type\"`",
                    "type": "number"
                },
                "minPurchaseAmount": {
                    "description": "PurchaseAheadDay  int                     `gorm:\"type:int(11);comment:采购提前期(天)\" json:\"purchaseAheadDay\"`\nProduceAheadDay   int                     `gorm:\"type:int(11);comment:制造提前期(天)\" json:\"produceAheadDay\"`",
                    "type": "number"
                },
                "model": {
                    "description": "MaterialType constvar.ProductType  `gorm:\"index;type:int(11);comment:物料类型(数字)\" json:\"materialType\"`",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.MaterialMode"
                        }
                    ]
                },
                "name": {
                    "type": "string"
                },
                "orderCreation": {
                    "$ref": "#/definitions/constvar.OrderCreation"
                },
                "originCountryId": {
                    "type": "integer"
                },
                "originCountryName": {
                    "type": "string"
                },
                "outStorageExplain": {
                    "type": "string"
                },
                "principal": {
                    "description": "负责人",
                    "type": "string"
                },
                "productTagId": {
                    "description": "产品标签",
                    "type": "integer"
                },
                "productTagName": {
                    "type": "string"
                },
                "purchasePrice": {
                    "type": "number"
                },
                "salePrice": {
                    "type": "number"
                },
                "selectProduct": {
                    "type": "integer"
                },
                "sellExplain": {
                    "type": "string"
                },
                "supplier": {
                    "description": "FSource           string                  `gorm:\"type:varchar(191);comment:生产车间\" json:\"-\"`\nStatus            constvar.MaterialStatus `gorm:\"type:int(11);comment:状态\" json:\"status\"`",
                    "type": "string"
                },
                "unit": {
                    "description": "LockAmount        decimal.Decimal         `gorm:\"type:decimal(35,18);default:0;comment:锁定数量\" json:\"lockAmount\"`",
                    "type": "string"
                },
                "volume": {
                    "description": "体积",
                    "type": "number"
                },
                "weight": {
                    "description": "重量",
                    "type": "number"
                }
            }
        },
        "models.OperationType": {
            "type": "object",
            "properties": {
@@ -1073,150 +1536,50 @@
                }
            }
        },
        "models.Product": {
        "models.ProductCategory": {
            "type": "object",
            "properties": {
                "HSCode": {
                    "type": "string"
                "costingMethod": {
                    "description": "成本方法",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.CostingMethod"
                        }
                    ]
                },
                "barcode": {
                    "description": "条码",
                    "type": "string"
                },
                "buyExplain": {
                    "type": "string"
                },
                "canBePurchased": {
                    "description": "是否可采购",
                    "type": "boolean"
                },
                "canBeSell": {
                    "description": "是否销售",
                    "type": "boolean"
                },
                "categoryId": {
                    "description": "产品分类id",
                    "type": "integer"
                },
                "companyId": {
                    "type": "integer"
                },
                "companyName": {
                    "type": "string"
                },
                "controlStrategy": {
                    "$ref": "#/definitions/constvar.InvoicingStrategy"
                },
                "cost": {
                    "description": "成本",
                    "type": "number"
                },
                "createTime": {
                    "type": "string"
                },
                "currencyId": {
                    "type": "integer"
                },
                "currencyName": {
                    "type": "string"
                },
                "customerAdvanceTime": {
                    "type": "number"
                },
                "customerTaxes": {
                    "description": "客户税百分比",
                    "type": "number"
                },
                "deliveryAdvanceTime": {
                    "type": "number"
                "forceRemovalStrategy": {
                    "description": "强制下架策略",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.ForceRemovalStrategy"
                        }
                    ]
                },
                "id": {
                    "type": "integer"
                },
                "inStorageExplain": {
                    "type": "string"
                },
                "internalNotes": {
                    "description": "内部说明",
                    "type": "string"
                },
                "internalReference": {
                    "description": "内部参考",
                    "type": "string"
                },
                "internalTransferExplain": {
                    "type": "string"
                },
                "invoicingStrategy": {
                    "$ref": "#/definitions/constvar.InvoicingStrategy"
                },
                "name": {
                    "description": "产品名称",
                    "type": "string"
                },
                "objectTemplateId": {
                    "type": "string"
                },
                "orderCreation": {
                    "$ref": "#/definitions/constvar.OrderCreation"
                },
                "originCountryId": {
                    "type": "integer"
                },
                "originCountryName": {
                    "type": "string"
                },
                "outStorageExplain": {
                    "type": "string"
                },
                "price": {
                    "type": "number"
                },
                "principal": {
                    "description": "负责人",
                    "type": "string"
                },
                "productTagId": {
                    "description": "产品标签",
                    "type": "integer"
                },
                "productTagName": {
                    "type": "string"
                },
                "salePrice": {
                    "description": "销售价格",
                    "type": "number"
                },
                "selectProduct": {
                    "type": "integer"
                },
                "sellExplain": {
                    "type": "string"
                },
                "supplierId": {
                    "type": "integer"
                },
                "supplierName": {
                    "type": "string"
                },
                "type": {
                    "description": "产品类型",
                "inventoryValuation": {
                    "description": "库存计价",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.ProductType"
                            "$ref": "#/definitions/constvar.InventoryValuation"
                        }
                    ]
                },
                "updateTime": {
                "name": {
                    "description": "位置名称",
                    "type": "string"
                },
                "volume": {
                    "description": "体积",
                    "type": "number"
                "parentId": {
                    "description": "上级id",
                    "type": "integer"
                },
                "weight": {
                    "description": "重量",
                    "type": "number"
                "routeId": {
                    "type": "integer"
                },
                "routeName": {
                    "description": "公司",
                    "type": "string"
                }
            }
        },
docs/swagger.yaml
@@ -13,6 +13,41 @@
    - BaseOperationTypeIncoming
    - BaseOperationTypeOutgoing
    - BaseOperationTypeInternal
  constvar.CostingMethod:
    enum:
    - 1
    - 2
    - 3
    type: integer
    x-enum-comments:
      CostingMethodAverageCost: 平均成本
      CostingMethodFIFO: 先进先出
      CostingMethodStandardPrice: 标准价格
    x-enum-varnames:
    - CostingMethodStandardPrice
    - CostingMethodFIFO
    - CostingMethodAverageCost
  constvar.ForceRemovalStrategy:
    enum:
    - 1
    - 2
    - 3
    type: integer
    x-enum-varnames:
    - ForceRemovalStrategyFIFO
    - ForceRemovalStrategyLIFO
    - ForceRemovalStrategyClosestLocation
  constvar.InventoryValuation:
    enum:
    - 1
    - 2
    type: integer
    x-enum-comments:
      InventoryValuationAuto: 自动
      InventoryValuationManual: 手动
    x-enum-varnames:
    - InventoryValuationManual
    - InventoryValuationAuto
  constvar.InvoicingStrategy:
    enum:
    - 1
@@ -59,6 +94,16 @@
    - LocationTypeInventoryLoss
    - LocationTypeProduction
    - LocationTypeTransit
  constvar.MaterialMode:
    enum:
    - 原材料
    - 半成品
    - 成品
    type: string
    x-enum-varnames:
    - MaterialModeRaw
    - MaterialModeSemi
    - MaterialModeFinished
  constvar.OperationStatus:
    enum:
    - 1
@@ -93,20 +138,6 @@
    - Task
    - Object
    - TaskAndObject
  constvar.ProductType:
    enum:
    - 1
    - 2
    - 3
    type: integer
    x-enum-comments:
      Consumables: 消耗品
      Server: 服务
      StoredProduct: 可储存的产品
    x-enum-varnames:
    - Consumables
    - Server
    - StoredProduct
  constvar.ReservationMethod:
    enum:
    - 1
@@ -212,6 +243,120 @@
      updateTime:
        type: string
    type: object
  models.Material:
    properties:
      HSCode:
        type: string
      amount:
        type: number
      barcode:
        description: 条码
        type: string
      buyExplain:
        type: string
      canBePurchased:
        description: 是否可采购
        type: boolean
      categoryId:
        description: 产品类别id
        type: integer
      companyId:
        type: integer
      companyName:
        type: string
      controlStrategy:
        $ref: '#/definitions/constvar.InvoicingStrategy'
      cost:
        description: 成本
        type: number
      currencyName:
        type: string
      customerTaxes:
        description: 客户税百分比
        type: number
      deliveryAdvanceTime:
        type: integer
      id:
        type: string
      inStorageExplain:
        type: string
      internalNotes:
        description: 内部说明
        type: string
      internalReference:
        description: 内部参考
        type: string
      internalTransferExplain:
        type: string
      invoicingStrategy:
        allOf:
        - $ref: '#/definitions/constvar.InvoicingStrategy'
        description: wms添加字段
      isSale:
        description: PurchaseType      constvar.PurchaseType `gorm:"type:int(11);comment:采购类型"
          json:"purchaseType"`
        type: boolean
      maxInventory:
        type: number
      minInventory:
        description: |-
          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"`
        type: number
      minPurchaseAmount:
        description: |-
          PurchaseAheadDay  int                     `gorm:"type:int(11);comment:采购提前期(天)" json:"purchaseAheadDay"`
          ProduceAheadDay   int                     `gorm:"type:int(11);comment:制造提前期(天)" json:"produceAheadDay"`
        type: number
      model:
        allOf:
        - $ref: '#/definitions/constvar.MaterialMode'
        description: MaterialType constvar.ProductType  `gorm:"index;type:int(11);comment:物料类型(数字)"
          json:"materialType"`
      name:
        type: string
      orderCreation:
        $ref: '#/definitions/constvar.OrderCreation'
      originCountryId:
        type: integer
      originCountryName:
        type: string
      outStorageExplain:
        type: string
      principal:
        description: 负责人
        type: string
      productTagId:
        description: 产品标签
        type: integer
      productTagName:
        type: string
      purchasePrice:
        type: number
      salePrice:
        type: number
      selectProduct:
        type: integer
      sellExplain:
        type: string
      supplier:
        description: |-
          FSource           string                  `gorm:"type:varchar(191);comment:生产车间" json:"-"`
          Status            constvar.MaterialStatus `gorm:"type:int(11);comment:状态" json:"status"`
        type: string
      unit:
        description: LockAmount        decimal.Decimal         `gorm:"type:decimal(35,18);default:0;comment:锁定数量"
          json:"lockAmount"`
        type: string
      volume:
        description: 体积
        type: number
      weight:
        description: 重量
        type: number
    type: object
  models.OperationType:
    properties:
      ReservationDaysBeforePriority:
@@ -282,106 +427,33 @@
        description: 仓库id
        type: integer
    type: object
  models.Product:
  models.ProductCategory:
    properties:
      HSCode:
        type: string
      barcode:
        description: 条码
        type: string
      buyExplain:
        type: string
      canBePurchased:
        description: 是否可采购
        type: boolean
      canBeSell:
        description: 是否销售
        type: boolean
      categoryId:
        description: 产品分类id
        type: integer
      companyId:
        type: integer
      companyName:
        type: string
      controlStrategy:
        $ref: '#/definitions/constvar.InvoicingStrategy'
      cost:
        description: 成本
        type: number
      createTime:
        type: string
      currencyId:
        type: integer
      currencyName:
        type: string
      customerAdvanceTime:
        type: number
      customerTaxes:
        description: 客户税百分比
        type: number
      deliveryAdvanceTime:
        type: number
      costingMethod:
        allOf:
        - $ref: '#/definitions/constvar.CostingMethod'
        description: 成本方法
      forceRemovalStrategy:
        allOf:
        - $ref: '#/definitions/constvar.ForceRemovalStrategy'
        description: 强制下架策略
      id:
        type: integer
      inStorageExplain:
        type: string
      internalNotes:
        description: 内部说明
        type: string
      internalReference:
        description: 内部参考
        type: string
      internalTransferExplain:
        type: string
      invoicingStrategy:
        $ref: '#/definitions/constvar.InvoicingStrategy'
      name:
        description: 产品名称
        type: string
      objectTemplateId:
        type: string
      orderCreation:
        $ref: '#/definitions/constvar.OrderCreation'
      originCountryId:
        type: integer
      originCountryName:
        type: string
      outStorageExplain:
        type: string
      price:
        type: number
      principal:
        description: 负责人
        type: string
      productTagId:
        description: 产品标签
        type: integer
      productTagName:
        type: string
      salePrice:
        description: 销售价格
        type: number
      selectProduct:
        type: integer
      sellExplain:
        type: string
      supplierId:
        type: integer
      supplierName:
        type: string
      type:
      inventoryValuation:
        allOf:
        - $ref: '#/definitions/constvar.ProductType'
        description: 产品类型
      updateTime:
        - $ref: '#/definitions/constvar.InventoryValuation'
        description: 库存计价
      name:
        description: 位置名称
        type: string
      volume:
        description: 体积
        type: number
      weight:
        description: 重量
        type: number
      parentId:
        description: 上级id
        type: integer
      routeId:
        type: integer
      routeName:
        description: 公司
        type: string
    type: object
  models.Warehouse:
    properties:
@@ -902,7 +974,7 @@
        name: object
        required: true
        schema:
          $ref: '#/definitions/models.Product'
          $ref: '#/definitions/models.Material'
      produces:
      - application/json
      responses:
@@ -911,6 +983,133 @@
          schema:
            $ref: '#/definitions/util.Response'
      summary: 添加产品
      tags:
      - 产品
  /api-wms/v1/product/addProductCategory:
    post:
      parameters:
      - description: 产品类型信息
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/models.ProductCategory'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 添加产品类型
      tags:
      - 产品类型
  /api-wms/v1/product/deleteProduct/{id}:
    delete:
      parameters:
      - description: id
        in: path
        name: id
        required: true
        type: string
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 删除产品
      tags:
      - 产品
  /api-wms/v1/product/deleteProductCategory/{id}:
    delete:
      parameters:
      - description: id
        in: path
        name: id
        required: true
        type: string
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 删除产品类型
      tags:
      - 产品类型
  /api-wms/v1/product/getProductCategoryDetails/{id}:
    get:
      parameters:
      - description: id
        in: path
        name: id
        required: true
        type: string
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/util.Response'
            - properties:
                data:
                  $ref: '#/definitions/models.Material'
              type: object
      summary: 获取产品类型详情
      tags:
      - 产品类型
  /api-wms/v1/product/getProductCategoryList:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.GetProductList'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/util.ResponseList'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/models.ProductCategory'
                  type: array
              type: object
      summary: 获取产品类型列表
      tags:
      - 产品类型
  /api-wms/v1/product/getProductDetails/{id}:
    get:
      parameters:
      - description: id
        in: path
        name: id
        required: true
        type: string
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/util.Response'
            - properties:
                data:
                  $ref: '#/definitions/models.Material'
              type: object
      summary: 获取产品详情
      tags:
      - 产品
  /api-wms/v1/product/getProductList:
@@ -933,12 +1132,50 @@
            - properties:
                data:
                  items:
                    $ref: '#/definitions/models.Product'
                    $ref: '#/definitions/models.Material'
                  type: array
              type: object
      summary: 获取产品详情
      summary: 获取产品列表
      tags:
      - 产品
  /api-wms/v1/product/updateProduct:
    post:
      parameters:
      - description: 产品信息
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/models.Material'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 修改产品
      tags:
      - 产品
  /api-wms/v1/product/updateProductCategory:
    post:
      parameters:
      - description: 产品信息
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/models.ProductCategory'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 修改产品类型
      tags:
      - 产品类型
  /api-wms/v1/warehouse/operationType:
    get:
      parameters:
go.mod
@@ -6,6 +6,7 @@
    basic.com/aps/nsqclient.git v0.0.0-20230517072415-37491f4a5d25
    github.com/dgrijalva/jwt-go v3.2.0+incompatible
    github.com/gin-gonic/gin v1.9.0
    github.com/google/uuid v1.1.2
    github.com/nsqio/go-nsq v1.1.0
    github.com/shopspring/decimal v1.3.1
    github.com/spf13/cast v1.5.0
@@ -14,7 +15,7 @@
    github.com/swaggo/gin-swagger v1.6.0
    github.com/swaggo/swag v1.16.1
    go.uber.org/zap v1.24.0
    golang.org/x/crypto v0.11.0
    golang.org/x/crypto v0.12.0
    google.golang.org/genproto v0.0.0-20230323212658-478b75c54725
    gopkg.in/natefinch/lumberjack.v2 v2.2.1
    gorm.io/driver/mysql v1.5.0
@@ -62,9 +63,9 @@
    go.uber.org/atomic v1.9.0 // indirect
    go.uber.org/multierr v1.8.0 // indirect
    golang.org/x/arch v0.4.0 // indirect
    golang.org/x/net v0.12.0 // indirect
    golang.org/x/sys v0.10.0 // indirect
    golang.org/x/text v0.11.0 // indirect
    golang.org/x/net v0.14.0 // indirect
    golang.org/x/sys v0.11.0 // indirect
    golang.org/x/text v0.12.0 // indirect
    golang.org/x/tools v0.11.0 // indirect
    google.golang.org/protobuf v1.31.0 // indirect
    gopkg.in/ini.v1 v1.67.0 // indirect
go.sum
@@ -165,6 +165,7 @@
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
@@ -304,8 +305,8 @@
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -376,8 +377,8 @@
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -440,8 +441,8 @@
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
@@ -453,8 +454,8 @@
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
models/db.go
@@ -82,8 +82,9 @@
        OperationDetails{},
        Scrap{},
        MoveHistory{},
        Product{},
        //Product{},
        ProductCategory{},
        Material{},
    )
    return err
}
models/material.go
New file
@@ -0,0 +1,474 @@
package models
import (
    "fmt"
    "github.com/shopspring/decimal"
    "gorm.io/gorm"
    "wms/constvar"
    "wms/pkg/mysqlx"
)
type (
    // Material 物料
    Material struct {
        BaseModelString
        Name string `gorm:"unique;type:varchar(191);not null;comment:物料名称" json:"name"`
        //MaterialType constvar.ProductType  `gorm:"index;type:int(11);comment:物料类型(数字)" json:"materialType"`
        Model constvar.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            constvar.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      constvar.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:"-"`
        //wms添加字段
        InvoicingStrategy       constvar.InvoicingStrategy `gorm:"type:int(11);comment:开票策略" json:"invoicingStrategy"`
        OrderCreation           constvar.OrderCreation     `gorm:"type:int(11);comment:订单创建" json:"orderCreation"`
        CustomerTaxes           decimal.Decimal            `gorm:"type:decimal(20,2);comment:客户税" json:"customerTaxes"`     //客户税百分比
        Cost                    decimal.Decimal            `gorm:"type:decimal(20,2);comment:成本" json:"cost"`               //成本
        CategoryId              int                        `gorm:"type:int(11);comment:产品类别id" json:"categoryId"`           //产品类别id
        InternalReference       string                     `gorm:"type:varchar(255);comment:内部参考" json:"internalReference"` //内部参考
        Barcode                 string                     `gorm:"type:varchar(255);comment:条码" json:"barcode"`             //条码
        ProductTagId            int                        `gorm:"type:int(11);comment:产品标签id" json:"productTagId"`         //产品标签
        ProductTagName          string                     `gorm:"type:varchar(255);comment:产品标签名称" json:"productTagName"`
        CompanyId               int                        `gorm:"type:int(11);comment:公司id" json:"companyId"`
        CompanyName             string                     `gorm:"type:varchar(255);comment:公司名称" json:"companyName"`
        InternalNotes           string                     `gorm:"type:varchar(512);comment:内部说明" json:"internalNotes"` //内部说明
        SelectProduct           int                        `gorm:"type:int(11);comment:可选产品id" json:"selectProduct"`
        SellExplain             string                     `gorm:"type:varchar(512);comment:销售说明" json:"sellExplain"`
        CanBePurchased          bool                       `gorm:"type:int(11);comment:是否可采购" json:"canBePurchased"` //是否可采购
        CurrencyName            string                     `gorm:"type:varchar(255);comment:币种名称" json:"currencyName"`
        DeliveryAdvanceTime     int                        `gorm:"type:int(11);comment:交货提前时间(天)" json:"deliveryAdvanceTime"`
        ControlStrategy         constvar.InvoicingStrategy `gorm:"type:int(11);comment:控制策略" json:"controlStrategy"`
        BuyExplain              string                     `gorm:"type:varchar(512);comment:采购说明" json:"buyExplain"`
        Principal               string                     `gorm:"type:varchar(255);comment:负责人" json:"principal"` //负责人
        Weight                  decimal.Decimal            `gorm:"type:decimal(20,2);comment:重量" json:"weight"`    //重量
        Volume                  decimal.Decimal            `gorm:"type:decimal(20,2);comment:体积" json:"volume"`    //体积
        HSCode                  string                     `gorm:"type:varchar(255);comment:HS编码" json:"HSCode"`
        OriginCountryId         int                        `gorm:"type:int(11);comment:原产地id" json:"originCountryId"`
        OriginCountryName       string                     `gorm:"type:varchar(255);comment:原产地名称" json:"originCountryName"`
        InStorageExplain        string                     `gorm:"type:varchar(512);comment:入库说明" json:"inStorageExplain"`
        OutStorageExplain       string                     `gorm:"type:varchar(512);comment:出库说明" json:"outStorageExplain"`
        InternalTransferExplain string                     `gorm:"type:varchar(512);comment:内部调拨说明" json:"internalTransferExplain"`
        //CompanyArr              []IdAndName                `gorm:"-" json:"companyArr"`
    }
    MaterialSearch struct {
        Material
        //MaterialTypes   []constvar.MaterialType
        Keyword string
        //SetTemplateType constvar.SetTemplateType
        Order    string
        PageNum  int
        PageSize int
        Ids      []string
        Orm      *gorm.DB
    }
    IdAndName struct {
        Id   string `json:"id"`
        Name string `json:"name"`
    }
)
func (slf Material) TableName() string {
    return "material"
}
func NewMaterialSearch() *MaterialSearch {
    return &MaterialSearch{Orm: mysqlx.GetDB()}
}
func (slf *MaterialSearch) SetOrm(tx *gorm.DB) *MaterialSearch {
    slf.Orm = tx
    return slf
}
func (slf *MaterialSearch) SetPage(page, size int) *MaterialSearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
}
func (slf *MaterialSearch) SetOrder(order string) *MaterialSearch {
    slf.Order = order
    return slf
}
func (slf *MaterialSearch) SetID(id string) *MaterialSearch {
    slf.ID = id
    return slf
}
func (slf *MaterialSearch) SetIsSale(isSale bool) *MaterialSearch {
    slf.IsSale = isSale
    return slf
}
func (slf *MaterialSearch) SetIDs(ids []string) *MaterialSearch {
    slf.Ids = ids
    return slf
}
func (slf *MaterialSearch) SetName(name string) *MaterialSearch {
    slf.Name = name
    return slf
}
//func (slf *MaterialSearch) SetMaterialType(materialType constvar.MaterialType) *MaterialSearch {
//    slf.MaterialType = materialType
//    return slf
//}
//
//func (slf *MaterialSearch) SetMaterialTypes(materialTypes []constvar.MaterialType) *MaterialSearch {
//    slf.MaterialTypes = materialTypes
//    return slf
//}
func (slf *MaterialSearch) SetKeyword(keyword string) *MaterialSearch {
    slf.Keyword = keyword
    return slf
}
func (slf *MaterialSearch) SetTemplateID(id string) *MaterialSearch {
    slf.TemplateID = id
    return slf
}
//
//func (slf *MaterialSearch) SetSetTemplateType(setType constvar.SetTemplateType) *MaterialSearch {
//    slf.SetTemplateType = setType
//    return slf
//}
//func (slf *MaterialSearch) SetStatus(status constvar.MaterialStatus) *MaterialSearch {
//    slf.Status = status
//    return slf
//}
func (slf *MaterialSearch) build() *gorm.DB {
    var db = slf.Orm.Table(slf.TableName())
    if slf.ID != "" {
        db = db.Where("id = ?", slf.ID)
    }
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
    if slf.TemplateID != "" {
        db = db.Where("template_id = ?", slf.TemplateID)
    }
    //if slf.SetTemplateType > 0 {
    //    if slf.SetTemplateType == constvar.SetTemplateTypeWithTemplate { // 模板ID非空
    //        db = db.Where("template_id <> ?", "")
    //    } else if slf.SetTemplateType == constvar.SetTemplateTypeWithNoTemplate {
    //        db = db.Where("template_id = ?", "")
    //    }
    //}
    //if slf.MaterialType > 0 {
    //    db = db.Where("material_type = ?", slf.MaterialType)
    //}
    //if len(slf.MaterialTypes) > 0 {
    //    var query string
    //    for i, materialType := range slf.MaterialTypes {
    //        if i == 0 {
    //            query += fmt.Sprintf("(material_type = %d", materialType)
    //        } else {
    //            query += fmt.Sprintf(" or material_type = %d", materialType)
    //        }
    //        if i == len(slf.MaterialTypes)-1 {
    //            query += ")"
    //        }
    //    }
    //    db = db.Where(query)
    //}
    if slf.Keyword != "" {
        db = db.Where("name LIKE ? or id LIKE ? ", "%"+slf.Keyword+"%", "%"+slf.Keyword+"%")
    }
    if slf.Order != "" {
        db = db.Order(slf.Order)
    }
    //if slf.Status != 0 {
    //    db = db.Where("status = ?", slf.Status)
    //}
    if len(slf.Ids) > 0 {
        db = db.Where("id in ?", slf.Ids)
    }
    if slf.IsSale {
        db = db.Where("is_sale = ?", 1)
    }
    return db
}
// Create 单条插入
func (slf *MaterialSearch) Create(record *Material) error {
    var db = slf.build()
    if err := db.Create(record).Error; err != nil {
        return fmt.Errorf("create err: %v, record: %+v", err, record)
    }
    return nil
}
// CreateBatch 批量插入
func (slf *MaterialSearch) CreateBatch(records []*Material) error {
    var db = slf.build()
    if err := db.Create(&records).Error; err != nil {
        return fmt.Errorf("create batch err: %v, records: %+v", err, records)
    }
    return nil
}
func (slf *MaterialSearch) Save(record *Material) error {
    var db = slf.build()
    if err := db.Omit("CreatedAt").Save(record).Error; err != nil {
        return fmt.Errorf("save err: %v, record: %+v", err, record)
    }
    return nil
}
func (slf *MaterialSearch) UpdateByMap(upMap map[string]interface{}) error {
    var (
        db = slf.build()
    )
    if err := db.Updates(upMap).Error; err != nil {
        return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
    }
    return nil
}
func (slf *MaterialSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error {
    var (
        db = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if err := db.Updates(upMap).Error; err != nil {
        return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap)
    }
    return nil
}
func (slf *MaterialSearch) Delete() error {
    var db = slf.build()
    if err := db.Unscoped().Delete(&Material{}).Error; err != nil {
        return err
    }
    return nil
}
func (slf *MaterialSearch) First() (*Material, error) {
    var (
        record = new(Material)
        db     = slf.build()
    )
    if err := db.First(record).Error; err != nil {
        return record, err
    }
    return record, nil
}
func (slf *MaterialSearch) Find() ([]*Material, int64, error) {
    var (
        records = make([]*Material, 0)
        total   int64
        db      = slf.build()
    )
    if err := db.Count(&total).Error; err != nil {
        return records, total, fmt.Errorf("find count err: %v", err)
    }
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, total, fmt.Errorf("find records err: %v", err)
    }
    return records, total, nil
}
func (slf *MaterialSearch) FindNotTotal() ([]*Material, error) {
    var (
        records = make([]*Material, 0)
        db      = slf.build()
    )
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("find records err: %v", err)
    }
    return records, nil
}
// FindByQuery 指定条件查询.
func (slf *MaterialSearch) FindByQuery(query string, args []interface{}) ([]*Material, int64, error) {
    var (
        records = make([]*Material, 0)
        total   int64
        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if err := db.Count(&total).Error; err != nil {
        return records, total, fmt.Errorf("find by query count err: %v", err)
    }
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
    }
    return records, total, nil
}
// FindByQueryNotTotal 指定条件查询&不查询总条数.
func (slf *MaterialSearch) FindByQueryNotTotal(query string, args []interface{}) ([]*Material, error) {
    var (
        records = make([]*Material, 0)
        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
    }
    return records, nil
}
//func (slf *MaterialSearch) Upsert(materialList []*Material) error {
//    var buffer bytes.Buffer
//    sql := fmt.Sprintf("insert into `%s` (`id`,`created_at`,`updated_at`,`name`,`model`,`material_type`,`explain`,`code_standard_id`,`specs`,"+
//        "`type`,`min_inventory`,`max_inventory`,`amount`,`unit`,`note`,`f_source`, `purchase_type`) values", slf.TableName())
//    if _, err := buffer.WriteString(sql); err != nil {
//        return err
//    }
//
//    for i, e := range materialList {
//        buffer.WriteString(fmt.Sprintf("('%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v','%v', '%d')", e.ID, e.CreatedAt.String(), e.UpdatedAt.String(), e.Name,
//            e.Model, e.MaterialType, e.Explain, e.CodeStandardID, e.Specs, e.Type, e.MinInventory, e.MaxInventory, e.Amount, e.Unit, e.Note, e.FSource, int(e.PurchaseType)))
//        if i == len(materialList)-1 {
//            buffer.WriteString("")
//        } else {
//            buffer.WriteString(",")
//        }
//    }
//    buffer.WriteString(fmt.Sprintf("on duplicate key update `updated_at`=values(`updated_at`), `name`=values(`name`), `specs`=values(`specs`), `type`=values(`type`), " +
//        "`min_inventory`=values(`min_inventory`), `max_inventory`=values(`max_inventory`), `amount`=values(`amount`), `unit`=values(`unit`), `note`=values(`note`), `f_source`=values(`f_source`), `purchase_type`=values(`purchase_type`);"))
//    err := slf.Orm.Exec(buffer.String()).Error
//    if err != nil {
//        logx.Errorf("Upsert sql:%v, err:%v", buffer.String(), err)
//    }
//    return err
//}
func (slf *MaterialSearch) GetMaterialListByIds(ids []string) ([]*Material, error) {
    var (
        records = make([]*Material, 0)
        db      = slf.Orm.Table(slf.TableName()).Where("id in (?)", ids)
    )
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("find records err: %v", err)
    }
    return records, nil
}
//func ExportMaterial(materials []*Material) (string, error) {
//    var fileName string
//    f := excelize.NewFile()
//
//    f.SetCellValue("Sheet1", "A1", "物料编码")
//    f.SetCellValue("Sheet1", "B1", "编码说明")
//    f.SetCellValue("Sheet1", "C1", "物料名称")
//    f.SetCellValue("Sheet1", "D1", "物料规格")
//    f.SetCellValue("Sheet1", "E1", "物料型号")
//    f.SetCellValue("Sheet1", "F1", "供应商")
//    f.SetCellValue("Sheet1", "G1", "采购价格")
//    f.SetCellValue("Sheet1", "H1", "安全库存")
//    f.SetCellValue("Sheet1", "I1", "剩余库存")
//    f.SetCellValue("Sheet1", "J1", "物料类型")
//    f.SetCellValue("Sheet1", "K1", "单位")
//    f.SetCellValue("Sheet1", "L1", "备注")
//
//    for i, m := range materials {
//        f.SetCellValue("Sheet1", "A"+strconv.Itoa(i+2), m.ID)
//        f.SetCellValue("Sheet1", "B"+strconv.Itoa(i+2), m.Explain)
//        f.SetCellValue("Sheet1", "C"+strconv.Itoa(i+2), m.Name)
//        f.SetCellValue("Sheet1", "D"+strconv.Itoa(i+2), m.Specs)
//        f.SetCellValue("Sheet1", "E"+strconv.Itoa(i+2), m.Type)
//        f.SetCellValue("Sheet1", "F"+strconv.Itoa(i+2), m.Supplier)
//        f.SetCellValue("Sheet1", "G"+strconv.Itoa(i+2), m.PurchasePrice.String())
//        f.SetCellValue("Sheet1", "H"+strconv.Itoa(i+2), m.MinInventory.String()+"-"+m.MaxInventory.String())
//        f.SetCellValue("Sheet1", "I"+strconv.Itoa(i+2), m.Amount.String())
//        f.SetCellValue("Sheet1", "J"+strconv.Itoa(i+2), m.Model)
//        f.SetCellValue("Sheet1", "K"+strconv.Itoa(i+2), m.Unit)
//        f.SetCellValue("Sheet1", "L"+strconv.Itoa(i+2), m.Note)
//    }
//
//    fileName = "material.xlsx"
//    if err := f.SaveAs(fileName); err != nil {
//        return fileName, err
//    }
//
//    return fileName, nil
//}
func (slf *MaterialSearch) MaxAutoIncr() (int64, error) {
    type Result struct {
        Max int64
    }
    var (
        result Result
        db     = slf.build()
    )
    err := db.Select("MAX(auto_incr) as max").Scan(&result).Error
    if err != nil {
        return result.Max, fmt.Errorf("max err: %v", err)
    }
    return result.Max, nil
}
models/product.go
@@ -1,293 +1,294 @@
package models
import (
    "fmt"
    "github.com/shopspring/decimal"
    "gorm.io/gorm"
    "wms/constvar"
    "wms/pkg/mysqlx"
)
type (
    // Product 产品
    Product struct {
        WmsModel
        Id                      int                        `gorm:"column:id;primary_key;AUTO_INCREMENT" json:"id"`
        Name                    string                     `gorm:"index;type:varchar(255);not null;comment:产品名称" json:"name"` //产品名称
        Type                    constvar.ProductType       `gorm:"type:int(11);comment:产品类型" json:"type"`                     //产品类型
        InvoicingStrategy       constvar.InvoicingStrategy `gorm:"type:int(11);comment:开票策略" json:"invoicingStrategy"`
        OrderCreation           constvar.OrderCreation     `gorm:"type:int(11);comment:订单创建" json:"orderCreation"`
        ObjectTemplateId        string                     `gorm:"type:varchar(191);comment:项目模版id" json:"objectTemplateId"`
        SalePrice               decimal.Decimal            `gorm:"type:decimal(35,18);comment:销售单价" json:"salePrice"`       //销售价格
        CustomerTaxes           decimal.Decimal            `gorm:"type:decimal(20,2);comment:客户税" json:"customerTaxes"`     //客户税百分比
        Cost                    decimal.Decimal            `gorm:"type:decimal(20,2);comment:成本" json:"cost"`               //成本
        CategoryId              int                        `gorm:"type:int(11);comment:产品类型id" json:"categoryId"`           //产品分类id
        InternalReference       string                     `gorm:"type:varchar(255);comment:内部参考" json:"internalReference"` //内部参考
        Barcode                 string                     `gorm:"type:varchar(255);comment:条码" json:"barcode"`             //条码
        ProductTagId            int                        `gorm:"type:int(11);comment:产品标签id" json:"productTagId"`         //产品标签
        ProductTagName          string                     `gorm:"type:varchar(255);comment:产品标签名称" json:"productTagName"`
        CompanyId               int                        `gorm:"type:int(11);comment:公司id" json:"companyId"`
        CompanyName             string                     `gorm:"type:varchar(255);comment:公司名称" json:"companyName"`
        InternalNotes           string                     `gorm:"type:varchar(512);comment:内部说明" json:"internalNotes"` //内部说明
        CanBeSell               bool                       `gorm:"type:tinyint(1);comment:是否可销售" json:"canBeSell"`      //是否销售
        SelectProduct           int                        `gorm:"type:int(11);comment:可选产品id" json:"selectProduct"`
        SellExplain             string                     `gorm:"type:varchar(512);comment:销售说明" json:"sellExplain"`
        CanBePurchased          bool                       `gorm:"type:int(11);comment:是否可采购" json:"canBePurchased"` //是否可采购
        SupplierId              int                        `gorm:"type:int(11);comment:供应商id" json:"supplierId"`
        SupplierName            string                     `gorm:"type:varchar(255);comment:供应商名称" json:"supplierName"`
        Price                   decimal.Decimal            `gorm:"type:decimal(20,2);comment:价格" json:"price"`
        CurrencyId              int                        `gorm:"type:int(11);comment:币种id" json:"currencyId"`
        CurrencyName            string                     `gorm:"type:varchar(255);comment:币种名称" json:"currencyName"`
        DeliveryAdvanceTime     decimal.Decimal            `gorm:"type:decimal(20,5);comment:提前交货时间" json:"deliveryAdvanceTime"`
        ControlStrategy         constvar.InvoicingStrategy `gorm:"type:int(11);comment:控制策略" json:"controlStrategy"`
        BuyExplain              string                     `gorm:"type:varchar(512);comment:采购说明" json:"buyExplain"`
        Principal               string                     `gorm:"type:varchar(255);comment:负责人" json:"principal"` //负责人
        Weight                  decimal.Decimal            `gorm:"type:decimal(20,2);comment:重量" json:"weight"`    //重量
        Volume                  decimal.Decimal            `gorm:"type:decimal(20,2);comment:体积" json:"volume"`    //体积
        CustomerAdvanceTime     decimal.Decimal            `gorm:"type:decimal(20,5);comment:客户前置时间" json:"customerAdvanceTime"`
        HSCode                  string                     `gorm:"type:varchar(255);comment:HS编码" json:"HSCode"`
        OriginCountryId         int                        `gorm:"type:int(11);comment:原产地id" json:"originCountryId"`
        OriginCountryName       string                     `gorm:"type:varchar(255);comment:原产地名称" json:"originCountryName"`
        InStorageExplain        string                     `gorm:"type:varchar(512);comment:入库说明" json:"inStorageExplain"`
        OutStorageExplain       string                     `gorm:"type:varchar(512);comment:出库说明" json:"outStorageExplain"`
        InternalTransferExplain string                     `gorm:"type:varchar(512);comment:内部调拨说明" json:"internalTransferExplain"`
    }
    ProductSearch struct {
        Product
        Order    string
        PageNum  int
        PageSize int
        Keyword  string
        Orm      *gorm.DB
        Preload  bool
    }
    PurchaseInfo struct {
        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"`
    }
)
func (slf *Product) TableName() string {
    return "wms_product"
}
func (slf *Product) BeforeCreate(db *gorm.DB) error {
    return nil
}
func (slf *Product) AfterFind(db *gorm.DB) error {
    return nil
}
func NewProductSearch() *ProductSearch {
    return &ProductSearch{Orm: mysqlx.GetDB()}
}
func (slf *ProductSearch) SetOrm(tx *gorm.DB) *ProductSearch {
    slf.Orm = tx
    return slf
}
func (slf *ProductSearch) SetPage(page, size int) *ProductSearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
}
func (slf *ProductSearch) SetOrder(order string) *ProductSearch {
    slf.Order = order
    return slf
}
func (slf *ProductSearch) SetID(id uint) *ProductSearch {
    slf.ID = id
    return slf
}
func (slf *ProductSearch) SetName(name string) *ProductSearch {
    slf.Name = name
    return slf
}
func (slf *ProductSearch) SetKeyword(keyword string) *ProductSearch {
    slf.Keyword = keyword
    return slf
}
func (slf *ProductSearch) SetPreload(preload bool) *ProductSearch {
    slf.Preload = preload
    return slf
}
func (slf *ProductSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Product{})
    if slf.ID != 0 {
        db = db.Where("id = ?", slf.ID)
    }
    if slf.Order != "" {
        db = db.Order(slf.Order)
    }
    if slf.Keyword != "" {
        db = db.Where("name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
    }
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
    return db
}
// Create 单条插入
func (slf *ProductSearch) Create(record *Product) error {
    var db = slf.build()
    if err := db.Create(record).Error; err != nil {
        return err
    }
    return nil
}
// CreateBatch 批量插入
func (slf *ProductSearch) CreateBatch(records []*Product) error {
    var db = slf.build()
    if err := db.Create(&records).Error; err != nil {
        return fmt.Errorf("create batch err: %v, records: %+v", err, records)
    }
    return nil
}
func (slf *ProductSearch) Update(record *Product) error {
    var db = slf.build()
    if err := db.Omit("CreatedAt").Updates(record).Error; err != nil {
        return fmt.Errorf("save err: %v, record: %+v", err, record)
    }
    return nil
}
func (slf *ProductSearch) UpdateByMap(upMap map[string]interface{}) error {
    var (
        db = slf.build()
    )
    if err := db.Updates(upMap).Error; err != nil {
        return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
    }
    return nil
}
func (slf *ProductSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error {
    var (
        db = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if err := db.Updates(upMap).Error; err != nil {
        return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap)
    }
    return nil
}
func (slf *ProductSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&Product{}).Error
}
func (slf *ProductSearch) First() (*Product, error) {
    var (
        record = new(Product)
        db     = slf.build()
    )
    if err := db.First(record).Error; err != nil {
        return record, err
    }
    return record, nil
}
func (slf *ProductSearch) Find() ([]*Product, int64, error) {
    var (
        records = make([]*Product, 0)
        total   int64
        db      = slf.build()
    )
    if err := db.Count(&total).Error; err != nil {
        return records, total, fmt.Errorf("find count err: %v", err)
    }
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, total, fmt.Errorf("find records err: %v", err)
    }
    return records, total, nil
}
func (slf *ProductSearch) FindNotTotal() ([]*Product, error) {
    var (
        records = make([]*Product, 0)
        db      = slf.build()
    )
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("find records err: %v", err)
    }
    return records, nil
}
// FindByQuery 指定条件查询.
func (slf *ProductSearch) FindByQuery(query string, args []interface{}) ([]*Product, int64, error) {
    var (
        records = make([]*Product, 0)
        total   int64
        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if err := db.Count(&total).Error; err != nil {
        return records, total, fmt.Errorf("find by query count err: %v", err)
    }
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
    }
    return records, total, nil
}
// FindByQueryNotTotal 指定条件查询&不查询总条数.
func (slf *ProductSearch) FindByQueryNotTotal(query string, args []interface{}) ([]*Product, error) {
    var (
        records = make([]*Product, 0)
        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
    }
    return records, nil
}
//
//import (
//    "fmt"
//    "github.com/shopspring/decimal"
//    "gorm.io/gorm"
//    "wms/constvar"
//    "wms/pkg/mysqlx"
//)
//
//type (
//    // Product 产品
//    Product struct {
//        WmsModel
//        Id                      int                        `gorm:"column:id;primary_key;AUTO_INCREMENT" json:"id"`
//        Name                    string                     `gorm:"index;type:varchar(255);not null;comment:产品名称" json:"name"` //产品名称
//        Type                    constvar.ProductType       `gorm:"type:int(11);comment:产品类型" json:"type"`                     //产品类型
//        InvoicingStrategy       constvar.InvoicingStrategy `gorm:"type:int(11);comment:开票策略" json:"invoicingStrategy"`
//        OrderCreation           constvar.OrderCreation     `gorm:"type:int(11);comment:订单创建" json:"orderCreation"`
//        ObjectTemplateId        string                     `gorm:"type:varchar(191);comment:项目模版id" json:"objectTemplateId"`
//        SalePrice               decimal.Decimal            `gorm:"type:decimal(35,18);comment:销售单价" json:"salePrice"`       //销售价格
//        CustomerTaxes           decimal.Decimal            `gorm:"type:decimal(20,2);comment:客户税" json:"customerTaxes"`     //客户税百分比
//        Cost                    decimal.Decimal            `gorm:"type:decimal(20,2);comment:成本" json:"cost"`               //成本
//        CategoryId              int                        `gorm:"type:int(11);comment:产品类型id" json:"categoryId"`           //产品分类id
//        InternalReference       string                     `gorm:"type:varchar(255);comment:内部参考" json:"internalReference"` //内部参考
//        Barcode                 string                     `gorm:"type:varchar(255);comment:条码" json:"barcode"`             //条码
//        ProductTagId            int                        `gorm:"type:int(11);comment:产品标签id" json:"productTagId"`         //产品标签
//        ProductTagName          string                     `gorm:"type:varchar(255);comment:产品标签名称" json:"productTagName"`
//        CompanyId               int                        `gorm:"type:int(11);comment:公司id" json:"companyId"`
//        CompanyName             string                     `gorm:"type:varchar(255);comment:公司名称" json:"companyName"`
//        InternalNotes           string                     `gorm:"type:varchar(512);comment:内部说明" json:"internalNotes"` //内部说明
//        CanBeSell               bool                       `gorm:"type:tinyint(1);comment:是否可销售" json:"canBeSell"`      //是否销售
//        SelectProduct           int                        `gorm:"type:int(11);comment:可选产品id" json:"selectProduct"`
//        SellExplain             string                     `gorm:"type:varchar(512);comment:销售说明" json:"sellExplain"`
//        CanBePurchased          bool                       `gorm:"type:int(11);comment:是否可采购" json:"canBePurchased"` //是否可采购
//        SupplierId              int                        `gorm:"type:int(11);comment:供应商id" json:"supplierId"`
//        SupplierName            string                     `gorm:"type:varchar(255);comment:供应商名称" json:"supplierName"`
//        Price                   decimal.Decimal            `gorm:"type:decimal(20,2);comment:价格" json:"price"`
//        CurrencyId              int                        `gorm:"type:int(11);comment:币种id" json:"currencyId"`
//        CurrencyName            string                     `gorm:"type:varchar(255);comment:币种名称" json:"currencyName"`
//        DeliveryAdvanceTime     decimal.Decimal            `gorm:"type:decimal(20,5);comment:提前交货时间" json:"deliveryAdvanceTime"`
//        ControlStrategy         constvar.InvoicingStrategy `gorm:"type:int(11);comment:控制策略" json:"controlStrategy"`
//        BuyExplain              string                     `gorm:"type:varchar(512);comment:采购说明" json:"buyExplain"`
//        Principal               string                     `gorm:"type:varchar(255);comment:负责人" json:"principal"` //负责人
//        Weight                  decimal.Decimal            `gorm:"type:decimal(20,2);comment:重量" json:"weight"`    //重量
//        Volume                  decimal.Decimal            `gorm:"type:decimal(20,2);comment:体积" json:"volume"`    //体积
//        CustomerAdvanceTime     decimal.Decimal            `gorm:"type:decimal(20,5);comment:客户前置时间" json:"customerAdvanceTime"`
//        HSCode                  string                     `gorm:"type:varchar(255);comment:HS编码" json:"HSCode"`
//        OriginCountryId         int                        `gorm:"type:int(11);comment:原产地id" json:"originCountryId"`
//        OriginCountryName       string                     `gorm:"type:varchar(255);comment:原产地名称" json:"originCountryName"`
//        InStorageExplain        string                     `gorm:"type:varchar(512);comment:入库说明" json:"inStorageExplain"`
//        OutStorageExplain       string                     `gorm:"type:varchar(512);comment:出库说明" json:"outStorageExplain"`
//        InternalTransferExplain string                     `gorm:"type:varchar(512);comment:内部调拨说明" json:"internalTransferExplain"`
//    }
//
//    ProductSearch struct {
//        Product
//        Order    string
//        PageNum  int
//        PageSize int
//        Keyword  string
//        Orm      *gorm.DB
//        Preload  bool
//    }
//
//    PurchaseInfo struct {
//        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"`
//    }
//)
//
//func (slf *Product) TableName() string {
//    return "wms_product"
//}
//
//func (slf *Product) BeforeCreate(db *gorm.DB) error {
//    return nil
//}
//
//func (slf *Product) AfterFind(db *gorm.DB) error {
//    return nil
//}
//
//func NewProductSearch() *ProductSearch {
//    return &ProductSearch{Orm: mysqlx.GetDB()}
//}
//
//func (slf *ProductSearch) SetOrm(tx *gorm.DB) *ProductSearch {
//    slf.Orm = tx
//    return slf
//}
//
//func (slf *ProductSearch) SetPage(page, size int) *ProductSearch {
//    slf.PageNum, slf.PageSize = page, size
//    return slf
//}
//
//func (slf *ProductSearch) SetOrder(order string) *ProductSearch {
//    slf.Order = order
//    return slf
//}
//
//func (slf *ProductSearch) SetID(id uint) *ProductSearch {
//    slf.ID = id
//    return slf
//}
//
//func (slf *ProductSearch) SetName(name string) *ProductSearch {
//    slf.Name = name
//    return slf
//}
//
//func (slf *ProductSearch) SetKeyword(keyword string) *ProductSearch {
//    slf.Keyword = keyword
//    return slf
//}
//
//func (slf *ProductSearch) SetPreload(preload bool) *ProductSearch {
//    slf.Preload = preload
//    return slf
//}
//
//func (slf *ProductSearch) build() *gorm.DB {
//    var db = slf.Orm.Model(&Product{})
//
//    if slf.ID != 0 {
//        db = db.Where("id = ?", slf.ID)
//    }
//
//    if slf.Order != "" {
//        db = db.Order(slf.Order)
//    }
//
//    if slf.Keyword != "" {
//        db = db.Where("name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
//    }
//
//    if slf.Name != "" {
//        db = db.Where("name = ?", slf.Name)
//    }
//
//    return db
//}
//
//// Create 单条插入
//func (slf *ProductSearch) Create(record *Product) error {
//    var db = slf.build()
//
//    if err := db.Create(record).Error; err != nil {
//        return err
//    }
//
//    return nil
//}
//
//// CreateBatch 批量插入
//func (slf *ProductSearch) CreateBatch(records []*Product) error {
//    var db = slf.build()
//
//    if err := db.Create(&records).Error; err != nil {
//        return fmt.Errorf("create batch err: %v, records: %+v", err, records)
//    }
//
//    return nil
//}
//
//func (slf *ProductSearch) Update(record *Product) error {
//    var db = slf.build()
//
//    if err := db.Omit("CreatedAt").Updates(record).Error; err != nil {
//        return fmt.Errorf("save err: %v, record: %+v", err, record)
//    }
//
//    return nil
//}
//
//func (slf *ProductSearch) UpdateByMap(upMap map[string]interface{}) error {
//    var (
//        db = slf.build()
//    )
//
//    if err := db.Updates(upMap).Error; err != nil {
//        return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
//    }
//
//    return nil
//}
//
//func (slf *ProductSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error {
//    var (
//        db = slf.Orm.Table(slf.TableName()).Where(query, args...)
//    )
//
//    if err := db.Updates(upMap).Error; err != nil {
//        return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap)
//    }
//
//    return nil
//}
//
//func (slf *ProductSearch) Delete() error {
//    var db = slf.build()
//    return db.Delete(&Product{}).Error
//}
//
//func (slf *ProductSearch) First() (*Product, error) {
//    var (
//        record = new(Product)
//        db     = slf.build()
//    )
//
//    if err := db.First(record).Error; err != nil {
//        return record, err
//    }
//
//    return record, nil
//}
//
//func (slf *ProductSearch) Find() ([]*Product, int64, error) {
//    var (
//        records = make([]*Product, 0)
//        total   int64
//        db      = slf.build()
//    )
//
//    if err := db.Count(&total).Error; err != nil {
//        return records, total, fmt.Errorf("find count err: %v", err)
//    }
//    if slf.PageNum*slf.PageSize > 0 {
//        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
//    }
//    if err := db.Find(&records).Error; err != nil {
//        return records, total, fmt.Errorf("find records err: %v", err)
//    }
//
//    return records, total, nil
//}
//
//func (slf *ProductSearch) FindNotTotal() ([]*Product, error) {
//    var (
//        records = make([]*Product, 0)
//        db      = slf.build()
//    )
//
//    if slf.PageNum*slf.PageSize > 0 {
//        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
//    }
//    if err := db.Find(&records).Error; err != nil {
//        return records, fmt.Errorf("find records err: %v", err)
//    }
//
//    return records, nil
//}
//
//// FindByQuery 指定条件查询.
//func (slf *ProductSearch) FindByQuery(query string, args []interface{}) ([]*Product, int64, error) {
//    var (
//        records = make([]*Product, 0)
//        total   int64
//        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
//    )
//
//    if err := db.Count(&total).Error; err != nil {
//        return records, total, fmt.Errorf("find by query count err: %v", err)
//    }
//    if slf.PageNum*slf.PageSize > 0 {
//        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
//    }
//    if err := db.Find(&records).Error; err != nil {
//        return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
//    }
//
//    return records, total, nil
//}
//
//// FindByQueryNotTotal 指定条件查询&不查询总条数.
//func (slf *ProductSearch) FindByQueryNotTotal(query string, args []interface{}) ([]*Product, error) {
//    var (
//        records = make([]*Product, 0)
//        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
//    )
//
//    if slf.PageNum*slf.PageSize > 0 {
//        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
//    }
//    if err := db.Find(&records).Error; err != nil {
//        return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
//    }
//
//    return records, nil
//}
models/product_category.go
@@ -243,3 +243,13 @@
    return records, nil
}
func (slf *ProductCategorySearch) Save(record *ProductCategory) error {
    var db = slf.build()
    if err := db.Omit("CreatedAt").Save(record).Error; err != nil {
        return fmt.Errorf("save err: %v, record: %+v", err, record)
    }
    return nil
}
router/router.go
@@ -73,8 +73,17 @@
    productController := new(controllers.ProductController)
    productAPI := r.Group(urlPrefix + "/product")
    {
        productAPI.POST("addProduct", productController.AddProduct)         // 新增产品
        productAPI.POST("getProductList", productController.GetProductList) // 获取产品列表
        productAPI.POST("addProduct", productController.AddProduct)                  // 新增产品
        productAPI.POST("getProductList", productController.GetProductList)          // 获取产品列表
        productAPI.GET("getProductDetails/:id", productController.GetProductDetails) // 获取产品详情
        productAPI.POST("updateProduct", productController.UpdateProduct)            // 修改产品详情
        productAPI.DELETE("deleteProduct/:id", productController.DeleteProduct)      // 删除产品
        productAPI.POST("addProductCategory", productController.AddProductCategory)                  //添加产品类型
        productAPI.POST("getProductCategoryList", productController.GetProductCategoryList)          //获取产品类型列表
        productAPI.GET("getProductCategoryDetails/:id", productController.GetProductCategoryDetails) //获取产品类型详情
        productAPI.POST("updateProductCategory", productController.UpdateProductCategory)            //修改产品类型
        productAPI.DELETE("deleteProductCategory/:id", productController.DeleteProductCategory)      //删除产品类型
    }
    return r
utils/util.go
New file
@@ -0,0 +1,11 @@
package utils
import (
    "github.com/google/uuid"
    "strings"
)
func GetUUID() string {
    s := uuid.New().String()
    return strings.ReplaceAll(s, "-", "")
}