liujiandao
2023-09-20 cfb6fbce3687230ccb4704dbc0c87fd411b39af1
仓库字段添加与功能修改
11个文件已修改
759 ■■■■■ 已修改文件
controllers/location.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/warehouse.go 125 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 203 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 203 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 137 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/location.go 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/material.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/warehouse.go 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/location.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/warehouse.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/location.go
@@ -26,7 +26,7 @@
    if params.Keyword != "" {
        search.SetKeyword(params.Keyword)
    }
    if params.ParentId != 0 {
    if params.ParentId != "" {
        search.SetParentId(params.ParentId)
    }
    if params.CompanyId != 0 {
@@ -43,7 +43,7 @@
    if params.Type == 0 {
        return errors.New("请选择正确的位置类型")
    }
    if params.ParentId < 0 {
    if params.ParentId == "" {
        return errors.New("错误参数ParentId")
    }
    if params.CompanyId < 0 {
controllers/warehouse.go
@@ -6,6 +6,8 @@
    "github.com/gin-gonic/gin"
    "github.com/spf13/cast"
    "gorm.io/gorm"
    "strconv"
    "wms/constvar"
    "wms/extend/code"
    "wms/extend/util"
    "wms/models"
@@ -39,6 +41,19 @@
        util.ResponseFormat(c, code.RequestParamError, err.Error())
        return
    }
    //创建默认位置
    location := &models.Location{
        Name:              "默认位置",
        ParentId:          params.Code,
        Type:              constvar.LocationTypeInternal,
        ReplenishLocation: true,
    }
    locationId, err := models.NewLocationSearch().CreateReturnId(location)
    if err != nil {
        util.ResponseFormat(c, code.SaveFail, "位置创建失败")
        return
    }
    params.LocationId = locationId
    if err := models.NewWarehouseSearch().Create(&params); err != nil {
        logx.Errorf("warehouse create err: %v", err)
        util.ResponseFormat(c, code.SaveFail, "插入失败")
@@ -48,39 +63,24 @@
    util.ResponseFormat(c, code.Success, "添加成功")
}
// Update
// UpdateWarehouse
// @Tags      仓库
// @Summary   编辑仓库
// @Produce   application/json
// @Param     object  body request.UpdateWarehouse true  "仓库信息"
// @Param     id  path string true  "仓库id"
// @Param     object  body  models.Warehouse true  "仓库信息"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/warehouse/warehouse/{id} [put]
func (slf WarehouseController) Update(c *gin.Context) {
    id := cast.ToUint(c.Param("id"))
    if id == 0 {
        util.ResponseFormat(c, code.RequestParamError, "空的记录id")
        return
    }
    var (
        reqParams request.UpdateWarehouse
        params    models.Warehouse
    )
    if err := c.BindJSON(&reqParams); err != nil {
// @Router    /api-wms/v1/warehouse/updateWarehouse [post]
func (slf WarehouseController) UpdateWarehouse(c *gin.Context) {
    var params models.Warehouse
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, fmt.Sprintf("参数解析失败: %v"+err.Error()))
        return
    }
    if err := structx.AssignTo(reqParams, &params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, fmt.Sprintf("数据转换错误: %v", err.Error()))
        return
    }
    params.ID = id
    if err := slf.ParamsCheck(params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, err.Error())
        return
    }
    err := models.NewWarehouseSearch().SetID(params.ID).Update(&params)
    err := models.NewWarehouseSearch().SetID(params.Id).Update(&params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "修改失败")
@@ -92,19 +92,31 @@
func (slf WarehouseController) ParamsCheck(params models.Warehouse) (err error) {
    var oldRecord *models.Warehouse
    if params.ID != 0 {
        oldRecord, err = models.NewWarehouseSearch().SetID(params.ID).First()
    if params.Id != 0 {
        oldRecord, err = models.NewWarehouseSearch().SetID(params.Id).First()
        if err == gorm.ErrRecordNotFound {
            return errors.New("记录不存在")
        }
    }
    if oldRecord == nil || params.Code != oldRecord.Code {
        _, err = models.NewWarehouseSearch().SetCode(params.Code).First()
        if err != gorm.ErrRecordNotFound {
    //更新位置信息
    if oldRecord != nil && params.Code != oldRecord.Code {
        m := make(map[string]interface{})
        m["parent_id"] = params.Code
        err := models.NewLocationSearch().SetID(oldRecord.LocationId).UpdateByMap(m)
        if err != nil {
            return errors.New("更新位置信息失败")
        }
    }
    if oldRecord == nil {
        record, err := models.NewWarehouseSearch().SetCode(params.Code).First()
        if record != nil && record.Code == params.Code {
            fmt.Println(err)
            return errors.New("仓库编号重复")
        }
    }
    if params.Code == "" {
        return errors.New("缩写不能为空")
    }
    return nil
}
@@ -126,6 +138,24 @@
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        return
    }
    //获取位置信息
    codes := make([]string, 0)
    for _, warehouse := range list {
        codes = append(codes, warehouse.Code)
    }
    locations, err := models.NewLocationSearch().SetParents(codes).FindNotTotal()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "位置信息查找失败")
        return
    }
    for _, warehouse := range list {
        for _, location := range locations {
            if warehouse.LocationId == location.Id {
                warehouse.WarehouseLocation = warehouse.Code + "/" + location.Name
                break
            }
        }
    }
    util.ResponseFormatList(c, code.Success, list, cast.ToInt(total))
}
@@ -138,16 +168,49 @@
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/warehouse/warehouse/{id} [delete]
func (slf WarehouseController) Delete(c *gin.Context) {
    id := cast.ToUint(c.Param("id"))
    id, _ := strconv.Atoi(c.Param("id"))
    if id == 0 {
        util.ResponseFormat(c, code.RequestParamError, "空的记录id")
        return
    }
    err := models.NewWarehouseSearch().SetID(id).Delete()
    //删除位置信息
    first, err := models.NewWarehouseSearch().SetID(id).First()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "删除失败")
        util.ResponseFormat(c, code.RequestParamError, "获取仓库信息失败")
        return
    }
    err = models.NewLocationSearch().SetID(first.LocationId).Delete()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "删除位置信息失败")
        return
    }
    err = models.NewWarehouseSearch().SetID(id).Delete()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "删除仓库信息失败")
        return
    }
    util.ResponseFormat(c, code.UpdateSuccess, "删除成功")
}
// GetWarehouseDetails
// @Tags      仓库
// @Summary   获取仓库详情
// @Produce   application/json
// @Param     id  path string true  "仓库id"
// @Success   200 {object} util.Response{data=models.Warehouse}    "成功"
// @Router    /api-wms/v1/warehouse/getWarehouseDetails/{id} [get]
func (slf WarehouseController) GetWarehouseDetails(c *gin.Context) {
    id, _ := strconv.Atoi(c.Param("id"))
    if id == 0 {
        util.ResponseFormat(c, code.RequestParamError, "空的记录id")
        return
    }
    first, err := models.NewWarehouseSearch().SetID(id).First()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "获取仓库信息失败")
        return
    }
    util.ResponseFormat(c, code.UpdateSuccess, first)
}
docs/docs.go
@@ -916,6 +916,76 @@
                }
            }
        },
        "/api-wms/v1/warehouse/getWarehouseDetails/{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.Warehouse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/warehouse/updateWarehouse": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "仓库"
                ],
                "summary": "编辑仓库",
                "parameters": [
                    {
                        "description": "仓库信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.Warehouse"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/warehouse/warehouse": {
            "get": {
                "produces": [
@@ -998,41 +1068,6 @@
            }
        },
        "/api-wms/v1/warehouse/warehouse/{id}": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "仓库"
                ],
                "summary": "编辑仓库",
                "parameters": [
                    {
                        "description": "仓库信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateWarehouse"
                        }
                    },
                    {
                        "type": "string",
                        "description": "仓库id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            },
            "delete": {
                "produces": [
                    "application/json"
@@ -1235,6 +1270,24 @@
                "TaskAndObject"
            ]
        },
        "constvar.ProductType": {
            "type": "integer",
            "enum": [
                1,
                2,
                3
            ],
            "x-enum-comments": {
                "Consumables": "消耗品",
                "Server": "服务",
                "StoredProduct": "可储存的产品"
            },
            "x-enum-varnames": [
                "Consumables",
                "Server",
                "StoredProduct"
            ]
        },
        "constvar.ReservationMethod": {
            "type": "integer",
            "enum": [
@@ -1366,7 +1419,7 @@
                },
                "parentId": {
                    "description": "上级id",
                    "type": "integer"
                    "type": "string"
                },
                "replenishLocation": {
                    "description": "是否补充位置",
@@ -1411,6 +1464,10 @@
                "categoryId": {
                    "description": "产品类别id",
                    "type": "integer"
                },
                "categoryName": {
                    "description": "产品类别名称",
                    "type": "string"
                },
                "companyId": {
                    "description": "公司id",
@@ -1464,7 +1521,7 @@
                    "type": "string"
                },
                "invoicingStrategy": {
                    "description": "wms添加字段",
                    "description": "开票策略",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.InvoicingStrategy"
@@ -1530,6 +1587,14 @@
                "productTagName": {
                    "description": "产品标签名称",
                    "type": "string"
                },
                "productType": {
                    "description": "wms添加字段",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.ProductType"
                        }
                    ]
                },
                "purchasePrice": {
                    "description": "采购价格",
@@ -1771,6 +1836,10 @@
                    "description": "入向运输",
                    "type": "integer"
                },
                "locationId": {
                    "description": "位置id",
                    "type": "integer"
                },
                "name": {
                    "description": "仓库名称",
                    "type": "string"
@@ -1798,6 +1867,10 @@
                    }
                },
                "updateTime": {
                    "type": "string"
                },
                "warehouseLocation": {
                    "description": "库存位置",
                    "type": "string"
                }
            }
@@ -2002,6 +2075,10 @@
                },
                "inboundTransportation": {
                    "description": "入向运输",
                    "type": "integer"
                },
                "locationId": {
                    "description": "位置id",
                    "type": "integer"
                },
                "name": {
@@ -2239,58 +2316,6 @@
                "warehouseId": {
                    "description": "仓库id",
                    "type": "integer"
                }
            }
        },
        "request.UpdateWarehouse": {
            "type": "object",
            "required": [
                "code"
            ],
            "properties": {
                "active": {
                    "description": "是否启用,传true就行",
                    "type": "boolean"
                },
                "address": {
                    "description": "地址",
                    "type": "string"
                },
                "buyToResupply": {
                    "description": "购买补给,已购买产品能够发送到此仓库",
                    "type": "boolean"
                },
                "code": {
                    "description": "仓库编码",
                    "type": "string",
                    "maxLength": 5,
                    "minLength": 1
                },
                "id": {
                    "type": "integer"
                },
                "inboundTransportation": {
                    "description": "入向运输",
                    "type": "integer"
                },
                "name": {
                    "description": "仓库名称",
                    "type": "string"
                },
                "outboundTransportation": {
                    "description": "出库运输",
                    "type": "integer"
                },
                "partnerId": {
                    "description": "合作伙伴id",
                    "type": "integer"
                },
                "resupplyWhIds": {
                    "description": "补给来源仓库ID",
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        },
docs/swagger.json
@@ -904,6 +904,76 @@
                }
            }
        },
        "/api-wms/v1/warehouse/getWarehouseDetails/{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.Warehouse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/warehouse/updateWarehouse": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "仓库"
                ],
                "summary": "编辑仓库",
                "parameters": [
                    {
                        "description": "仓库信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/models.Warehouse"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/warehouse/warehouse": {
            "get": {
                "produces": [
@@ -986,41 +1056,6 @@
            }
        },
        "/api-wms/v1/warehouse/warehouse/{id}": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "仓库"
                ],
                "summary": "编辑仓库",
                "parameters": [
                    {
                        "description": "仓库信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateWarehouse"
                        }
                    },
                    {
                        "type": "string",
                        "description": "仓库id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            },
            "delete": {
                "produces": [
                    "application/json"
@@ -1223,6 +1258,24 @@
                "TaskAndObject"
            ]
        },
        "constvar.ProductType": {
            "type": "integer",
            "enum": [
                1,
                2,
                3
            ],
            "x-enum-comments": {
                "Consumables": "消耗品",
                "Server": "服务",
                "StoredProduct": "可储存的产品"
            },
            "x-enum-varnames": [
                "Consumables",
                "Server",
                "StoredProduct"
            ]
        },
        "constvar.ReservationMethod": {
            "type": "integer",
            "enum": [
@@ -1354,7 +1407,7 @@
                },
                "parentId": {
                    "description": "上级id",
                    "type": "integer"
                    "type": "string"
                },
                "replenishLocation": {
                    "description": "是否补充位置",
@@ -1399,6 +1452,10 @@
                "categoryId": {
                    "description": "产品类别id",
                    "type": "integer"
                },
                "categoryName": {
                    "description": "产品类别名称",
                    "type": "string"
                },
                "companyId": {
                    "description": "公司id",
@@ -1452,7 +1509,7 @@
                    "type": "string"
                },
                "invoicingStrategy": {
                    "description": "wms添加字段",
                    "description": "开票策略",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.InvoicingStrategy"
@@ -1518,6 +1575,14 @@
                "productTagName": {
                    "description": "产品标签名称",
                    "type": "string"
                },
                "productType": {
                    "description": "wms添加字段",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.ProductType"
                        }
                    ]
                },
                "purchasePrice": {
                    "description": "采购价格",
@@ -1759,6 +1824,10 @@
                    "description": "入向运输",
                    "type": "integer"
                },
                "locationId": {
                    "description": "位置id",
                    "type": "integer"
                },
                "name": {
                    "description": "仓库名称",
                    "type": "string"
@@ -1786,6 +1855,10 @@
                    }
                },
                "updateTime": {
                    "type": "string"
                },
                "warehouseLocation": {
                    "description": "库存位置",
                    "type": "string"
                }
            }
@@ -1990,6 +2063,10 @@
                },
                "inboundTransportation": {
                    "description": "入向运输",
                    "type": "integer"
                },
                "locationId": {
                    "description": "位置id",
                    "type": "integer"
                },
                "name": {
@@ -2227,58 +2304,6 @@
                "warehouseId": {
                    "description": "仓库id",
                    "type": "integer"
                }
            }
        },
        "request.UpdateWarehouse": {
            "type": "object",
            "required": [
                "code"
            ],
            "properties": {
                "active": {
                    "description": "是否启用,传true就行",
                    "type": "boolean"
                },
                "address": {
                    "description": "地址",
                    "type": "string"
                },
                "buyToResupply": {
                    "description": "购买补给,已购买产品能够发送到此仓库",
                    "type": "boolean"
                },
                "code": {
                    "description": "仓库编码",
                    "type": "string",
                    "maxLength": 5,
                    "minLength": 1
                },
                "id": {
                    "type": "integer"
                },
                "inboundTransportation": {
                    "description": "入向运输",
                    "type": "integer"
                },
                "name": {
                    "description": "仓库名称",
                    "type": "string"
                },
                "outboundTransportation": {
                    "description": "出库运输",
                    "type": "integer"
                },
                "partnerId": {
                    "description": "合作伙伴id",
                    "type": "integer"
                },
                "resupplyWhIds": {
                    "description": "补给来源仓库ID",
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
        },
docs/swagger.yaml
@@ -138,6 +138,20 @@
    - 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
@@ -232,7 +246,7 @@
        type: string
      parentId:
        description: 上级id
        type: integer
        type: string
      replenishLocation:
        description: 是否补充位置
        type: boolean
@@ -263,6 +277,9 @@
      categoryId:
        description: 产品类别id
        type: integer
      categoryName:
        description: 产品类别名称
        type: string
      companyId:
        description: 公司id
        type: integer
@@ -302,7 +319,7 @@
      invoicingStrategy:
        allOf:
        - $ref: '#/definitions/constvar.InvoicingStrategy'
        description: wms添加字段
        description: 开票策略
      isSale:
        description: PurchaseType      constvar.PurchaseType `gorm:"type:int(11);comment:采购类型"
          json:"purchaseType"`
@@ -352,6 +369,10 @@
      productTagName:
        description: 产品标签名称
        type: string
      productType:
        allOf:
        - $ref: '#/definitions/constvar.ProductType'
        description: wms添加字段
      purchasePrice:
        description: 采购价格
        type: number
@@ -510,6 +531,9 @@
      inboundTransportation:
        description: 入向运输
        type: integer
      locationId:
        description: 位置id
        type: integer
      name:
        description: 仓库名称
        type: string
@@ -530,6 +554,9 @@
          type: string
        type: array
      updateTime:
        type: string
      warehouseLocation:
        description: 库存位置
        type: string
    required:
    - code
@@ -668,6 +695,9 @@
        type: string
      inboundTransportation:
        description: 入向运输
        type: integer
      locationId:
        description: 位置id
        type: integer
      name:
        description: 仓库名称
@@ -831,44 +861,6 @@
      warehouseId:
        description: 仓库id
        type: integer
    type: object
  request.UpdateWarehouse:
    properties:
      active:
        description: 是否启用,传true就行
        type: boolean
      address:
        description: 地址
        type: string
      buyToResupply:
        description: 购买补给,已购买产品能够发送到此仓库
        type: boolean
      code:
        description: 仓库编码
        maxLength: 5
        minLength: 1
        type: string
      id:
        type: integer
      inboundTransportation:
        description: 入向运输
        type: integer
      name:
        description: 仓库名称
        type: string
      outboundTransportation:
        description: 出库运输
        type: integer
      partnerId:
        description: 合作伙伴id
        type: integer
      resupplyWhIds:
        description: 补给来源仓库ID
        items:
          type: string
        type: array
    required:
    - code
    type: object
  util.Response:
    properties:
@@ -1453,6 +1445,48 @@
      summary: 修改产品类型
      tags:
      - 产品类型
  /api-wms/v1/warehouse/getWarehouseDetails/{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.Warehouse'
              type: object
      summary: 获取仓库详情
      tags:
      - 仓库
  /api-wms/v1/warehouse/updateWarehouse:
    post:
      parameters:
      - description: 仓库信息
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/models.Warehouse'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 编辑仓库
      tags:
      - 仓库
  /api-wms/v1/warehouse/warehouse:
    get:
      parameters:
@@ -1518,29 +1552,6 @@
          schema:
            $ref: '#/definitions/util.Response'
      summary: 删除仓库
      tags:
      - 仓库
    put:
      parameters:
      - description: 仓库信息
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdateWarehouse'
      - description: 仓库id
        in: path
        name: id
        required: true
        type: string
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 编辑仓库
      tags:
      - 仓库
swagger: "2.0"
models/location.go
@@ -12,15 +12,15 @@
    Location struct {
        WmsModel
        Id                int                   `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name              string                `json:"name" gorm:"index;type:varchar(255);not null;comment:位置名称"`     //位置名称
        ParentId          int                   `json:"parentId" gorm:"type:int;not null"`                             //上级id
        CompanyId         int                   `json:"companyId" gorm:"type:int;not null"`                            //公司id
        Company           Company               `json:"company" gorm:"foreignKey:CompanyId"`                           //公司
        Type              constvar.LocationType `json:"type" gorm:"type:int(11);not null;comment:位置类型"`                //位置类型
        CountFrequency    int                   `json:"countFrequency" gorm:"type:tinyint;not null;comment:盘点频率(天)"`   //盘点频率(天)
        IsScrapLocation   bool                  `json:"isScrapLocation" gorm:"type:tinyint;not null;comment:是否报废位置"`   //是否报废位置
        IsReturnLocation  bool                  `json:"isReturnLocation" gorm:"type:tinyint;not null;comment:是否退货位置"`  //是否退货位置
        ReplenishLocation bool                  `json:"replenishLocation" gorm:"type:tinyint;not null;comment:是否补充位置"` //是否补充位置
        Name              string                `json:"name" gorm:"index;type:varchar(255);not null;comment:位置名称"` //位置名称
        ParentId          string                `json:"parentId" gorm:"type:varchar(255)"`                         //上级id
        CompanyId         int                   `json:"companyId" gorm:"type:int"`                                 //公司id
        Company           Company               `json:"company" gorm:"foreignKey:CompanyId"`                       //公司
        Type              constvar.LocationType `json:"type" gorm:"type:int(11);comment:位置类型"`                     //位置类型
        CountFrequency    int                   `json:"countFrequency" gorm:"type:tinyint;comment:盘点频率(天)"`        //盘点频率(天)
        IsScrapLocation   bool                  `json:"isScrapLocation" gorm:"type:tinyint;comment:是否报废位置"`        //是否报废位置
        IsReturnLocation  bool                  `json:"isReturnLocation" gorm:"type:tinyint;comment:是否退货位置"`       //是否退货位置
        ReplenishLocation bool                  `json:"replenishLocation" gorm:"type:tinyint;comment:是否补充位置"`      //是否补充位置
    }
    LocationSearch struct {
@@ -31,6 +31,7 @@
        Keyword  string
        Orm      *gorm.DB
        Preload  bool
        Parents  []string
    }
)
@@ -57,8 +58,12 @@
    return slf
}
func (slf *LocationSearch) SetID(id uint) *LocationSearch {
    slf.ID = id
func (slf *LocationSearch) SetID(id int) *LocationSearch {
    slf.Id = id
    return slf
}
func (slf *LocationSearch) SetParents(ids []string) *LocationSearch {
    slf.Parents = ids
    return slf
}
@@ -82,7 +87,7 @@
    return slf
}
func (slf *LocationSearch) SetParentId(parentId int) *LocationSearch {
func (slf *LocationSearch) SetParentId(parentId string) *LocationSearch {
    slf.ParentId = parentId
    return slf
}
@@ -93,10 +98,10 @@
}
func (slf *LocationSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Location{})
    var db = slf.Orm.Table(slf.TableName())
    if slf.ID != 0 {
        db = db.Where("id = ?", slf.ID)
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Order != "" {
@@ -115,11 +120,14 @@
        db = db.Where("type=?", slf.Type)
    }
    if slf.ParentId != 0 {
    if slf.ParentId != "" {
        db = db.Where("parent_id=?", slf.ParentId)
    }
    if slf.CompanyId != 0 {
        db = db.Where("company_id=?", slf.CompanyId)
    }
    if len(slf.Parents) != 0 {
        db = db.Where("parent_id in (?)", slf.Parents)
    }
    return db
@@ -134,6 +142,16 @@
    }
    return nil
}
func (slf *LocationSearch) CreateReturnId(record *Location) (int, error) {
    var db = slf.build()
    if err := db.Create(record).Error; err != nil {
        return 0, err
    }
    return record.Id, nil
}
// CreateBatch 批量插入
@@ -183,7 +201,7 @@
func (slf *LocationSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&Location{}).Error
    return db.Unscoped().Delete(&Location{}).Error
}
func (slf *LocationSearch) First() (*Location, error) {
@@ -278,7 +296,9 @@
        records = make([]*Location, 0)
        db      = slf.build()
    )
    if err := db.Find(&records); err != nil {
    err := db.Find(&records)
    if err != nil {
        fmt.Println(err)
        return records, fmt.Errorf("func FindAll err: %v", err)
    }
    return records, nil
models/material.go
@@ -38,11 +38,13 @@
        SalePrice decimal.Decimal `gorm:"type:decimal(35,18);comment:销售单价" json:"salePrice"` //销售单价
        AutoIncr  uint            `gorm:"type:int(11);comment:自增ID;default:0;" json:"-"`
        //wms添加字段
        ProductType             constvar.ProductType       `gorm:"type:int(11);comment:产品类型" json:"productType"`                    //产品类型
        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
        CategoryName            string                     `gorm:"type:varchar(255);comment:产品类别名称" json:"categoryName"`            //产品类别名称
        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"`                 //产品标签id
models/warehouse.go
@@ -25,6 +25,8 @@
        Address                string       `json:"address" gorm:"type:varchar(512);comment:地址"`         //地址
        InboundTransportation  int          `json:"inboundTransportation" gorm:"type:int;comment:入向运输"`  //入向运输
        OutboundTransportation int          `json:"outboundTransportation" gorm:"type:int;comment:出库运输"` //出库运输
        LocationId             int          `json:"locationId" gorm:"type:int;comment:位置id"`             //位置id
        WarehouseLocation      string       `json:"warehouseLocation" gorm:"-"`                          //库存位置
    }
    WarehouseSearch struct {
@@ -66,8 +68,8 @@
    return slf
}
func (slf *WarehouseSearch) SetID(id uint) *WarehouseSearch {
    slf.ID = id
func (slf *WarehouseSearch) SetID(id int) *WarehouseSearch {
    slf.Id = id
    return slf
}
@@ -92,10 +94,10 @@
}
func (slf *WarehouseSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Warehouse{})
    var db = slf.Orm.Table(slf.TableName())
    if slf.ID != 0 {
        db = db.Where("id = ?", slf.ID)
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Order != "" {
@@ -112,6 +114,9 @@
    if slf.Preload {
        db = db.Preload("Company")
    }
    if slf.Code != "" {
        db = db.Where("code = ?", slf.Code)
    }
    return db
@@ -175,7 +180,7 @@
func (slf *WarehouseSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&Warehouse{}).Error
    return db.Unscoped().Delete(&Warehouse{}).Error
}
func (slf *WarehouseSearch) First() (*Warehouse, error) {
request/location.go
@@ -3,6 +3,6 @@
type LocationByType struct {
    Type      int    `json:"type" form:"type"`
    Keyword   string `json:"keyword" form:"keyword"`
    ParentId  int    `json:"parentId" form:"parentId"`
    ParentId  string `json:"parentId" form:"parentId"`
    CompanyId int    `json:"companyId" form:"companyId"`
}
request/warehouse.go
@@ -15,6 +15,7 @@
    Address                string   `json:"address" gorm:"type:varchar(512);comment:地址"`                                               //地址
    InboundTransportation  int      `json:"inboundTransportation" gorm:"type:int;comment:入向运输"`                                        //入向运输
    OutboundTransportation int      `json:"outboundTransportation" gorm:"type:int;comment:出库运输"`                                       //出库运输
    LocationId             int      `json:"locationId" gorm:"type:int;comment:位置id"`                                                   //位置id
}
type UpdateWarehouse struct {
router/router.go
@@ -45,10 +45,11 @@
    warehouseController := new(controllers.WarehouseController)
    warehouseAPI := r.Group(urlPrefix + "/warehouse")
    {
        warehouseAPI.GET("warehouse", warehouseController.List)          // 获取仓库列表
        warehouseAPI.POST("warehouse", warehouseController.Add)          // 新增仓库
        warehouseAPI.PUT("warehouse/:id", warehouseController.Update)    // 修改仓库
        warehouseAPI.DELETE("warehouse/:id", warehouseController.Delete) // 删除仓库
        warehouseAPI.GET("warehouse", warehouseController.List)                              // 获取仓库列表
        warehouseAPI.POST("warehouse", warehouseController.Add)                              // 新增仓库
        warehouseAPI.POST("updateWarehouse", warehouseController.UpdateWarehouse)            // 修改仓库
        warehouseAPI.DELETE("warehouse/:id", warehouseController.Delete)                     // 删除仓库
        warehouseAPI.GET("getWarehouseDetails/:id", warehouseController.GetWarehouseDetails) // 获取仓库详情
    }
    // 作业类型