liujiandao
2024-04-09 6dec2342316aecf4084c8f4efb43f33fbb72892f
更新计量单位字典
6个文件已修改
356 ■■■■■ 已修改文件
controllers/product_controller.go 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 111 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 111 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/product_request.go 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/product_controller.go
@@ -16,6 +16,7 @@
    "wms/models"
    "wms/pkg/logx"
    "wms/pkg/mysqlx"
    "wms/pkg/structx"
    "wms/request"
)
@@ -777,3 +778,51 @@
    }
    util.ResponseFormatList(c, code.Success, dicts, int(total))
}
// SaveUnitDict
//
//    @Tags        数据字典
//    @Summary    更新计量单位字典
//    @Produce    application/json
//    @Param        object    body        request.SaveUnitDict    true    "参数"
//    @Success    200        {object}    util.Response            "成功"
//    @Router        /api-wms/v1/product/saveUnitDict [post]
func (slf ProductController) SaveUnitDict(c *gin.Context) {
    var reqParams request.SaveUnitDict
    var params []*models.UnitDict
    if err := c.BindJSON(&reqParams); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if err := structx.AssignTo(reqParams.Data, &params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "数据转换错误")
        return
    }
    for i, v := range params {
        if len(v.Name) == 0 {
            util.ResponseFormat(c, code.RequestParamError, "名称为空")
            return
        }
        v.Sort = i + 1
    }
    err := models.WithTransaction(func(tx *gorm.DB) error {
        err := models.NewUnitDictSearch().SetOrm(tx).Delete()
        if err != nil {
            return err
        }
        err = models.NewUnitDictSearch().SetOrm(tx).CreateBatch(params)
        if err != nil {
            return err
        }
        return nil
    })
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "删除失败")
        return
    }
    util.ResponseFormat(c, code.Success, "添加成功")
}
docs/docs.go
@@ -2116,6 +2116,36 @@
                }
            }
        },
        "/api-wms/v1/product/saveUnitDict": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "数据字典"
                ],
                "summary": "更新计量单位字典",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.SaveUnitDict"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/updateDisuse": {
            "post": {
                "produces": [
@@ -2836,6 +2866,33 @@
                "MaterialModeVirtual"
            ]
        },
        "constvar.OperationSource": {
            "type": "integer",
            "enum": [
                1,
                2,
                3,
                4,
                5,
                6
            ],
            "x-enum-comments": {
                "OperationSourceOutsourcing": "委外入库",
                "OperationSourceOutsourcingApply": "委外领料",
                "OperationSourceProduction": "生产入库",
                "OperationSourceProductionApply": "生产领料",
                "OperationSourcePurchase": "采购入库",
                "OperationSourceSaleDelivery": "销售发货"
            },
            "x-enum-varnames": [
                "OperationSourcePurchase",
                "OperationSourceProduction",
                "OperationSourceOutsourcing",
                "OperationSourceProductionApply",
                "OperationSourceOutsourcingApply",
                "OperationSourceSaleDelivery"
            ]
        },
        "constvar.OperationStatus": {
            "type": "integer",
            "enum": [
@@ -3121,6 +3178,18 @@
                },
                "updateTime": {
                    "type": "string"
                },
                "warehouse": {
                    "description": "仓库",
                    "allOf": [
                        {
                            "$ref": "#/definitions/models.Warehouse"
                        }
                    ]
                },
                "warehouseId": {
                    "description": "仓库ID",
                    "type": "integer"
                }
            }
        },
@@ -3480,6 +3549,14 @@
                    "description": "FromLocationID    int                      ` + "`" + `json:\"fromLocationId\"   gorm:\"type:int;not null;comment:源位置id\"` + "`" + `         //源位置id\nFromLocation      Location                 ` + "`" + `json:\"fromLocation\"     gorm:\"foreignKey:FromLocationID;references:Id\"` + "`" + ` //源位置\nToLocationID      int                      ` + "`" + `json:\"toLocationId\"    gorm:\"type:int;not null;comment:目标位置id\"` + "`" + `         //目标位置id\nToLocation        Location                 ` + "`" + `json:\"toLocation\"      gorm:\"foreignKey:ToLocationID;references:Id\"` + "`" + `    //目标位置",
                    "type": "string"
                },
                "operationSource": {
                    "description": "操作来源",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.OperationSource"
                        }
                    ]
                },
                "operationTypeId": {
                    "description": "作业类型id",
                    "type": "integer"
@@ -3495,6 +3572,9 @@
                    "type": "string"
                },
                "receiverPhone": {
                    "type": "string"
                },
                "salesDetailsNumber": {
                    "type": "string"
                },
                "source": {
@@ -3725,9 +3805,6 @@
        },
        "models.Warehouse": {
            "type": "object",
            "required": [
                "code"
            ],
            "properties": {
                "active": {
                    "description": "是否启用,传true就行",
@@ -3743,9 +3820,7 @@
                },
                "code": {
                    "description": "仓库编码",
                    "type": "string",
                    "maxLength": 5,
                    "minLength": 1
                    "type": "string"
                },
                "company": {
                    "$ref": "#/definitions/models.Company"
@@ -3768,7 +3843,7 @@
                    "type": "integer"
                },
                "locationId": {
                    "description": "位置id",
                    "description": "默认位置id",
                    "type": "integer"
                },
                "name": {
@@ -4466,6 +4541,28 @@
                }
            }
        },
        "request.SaveUnitDict": {
            "type": "object",
            "properties": {
                "data": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UnitDict"
                    }
                }
            }
        },
        "request.UnitDict": {
            "type": "object",
            "properties": {
                "isDefault": {
                    "type": "boolean"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateCompany": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -2104,6 +2104,36 @@
                }
            }
        },
        "/api-wms/v1/product/saveUnitDict": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "数据字典"
                ],
                "summary": "更新计量单位字典",
                "parameters": [
                    {
                        "description": "参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.SaveUnitDict"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/updateDisuse": {
            "post": {
                "produces": [
@@ -2824,6 +2854,33 @@
                "MaterialModeVirtual"
            ]
        },
        "constvar.OperationSource": {
            "type": "integer",
            "enum": [
                1,
                2,
                3,
                4,
                5,
                6
            ],
            "x-enum-comments": {
                "OperationSourceOutsourcing": "委外入库",
                "OperationSourceOutsourcingApply": "委外领料",
                "OperationSourceProduction": "生产入库",
                "OperationSourceProductionApply": "生产领料",
                "OperationSourcePurchase": "采购入库",
                "OperationSourceSaleDelivery": "销售发货"
            },
            "x-enum-varnames": [
                "OperationSourcePurchase",
                "OperationSourceProduction",
                "OperationSourceOutsourcing",
                "OperationSourceProductionApply",
                "OperationSourceOutsourcingApply",
                "OperationSourceSaleDelivery"
            ]
        },
        "constvar.OperationStatus": {
            "type": "integer",
            "enum": [
@@ -3109,6 +3166,18 @@
                },
                "updateTime": {
                    "type": "string"
                },
                "warehouse": {
                    "description": "仓库",
                    "allOf": [
                        {
                            "$ref": "#/definitions/models.Warehouse"
                        }
                    ]
                },
                "warehouseId": {
                    "description": "仓库ID",
                    "type": "integer"
                }
            }
        },
@@ -3468,6 +3537,14 @@
                    "description": "FromLocationID    int                      `json:\"fromLocationId\"   gorm:\"type:int;not null;comment:源位置id\"`         //源位置id\nFromLocation      Location                 `json:\"fromLocation\"     gorm:\"foreignKey:FromLocationID;references:Id\"` //源位置\nToLocationID      int                      `json:\"toLocationId\"    gorm:\"type:int;not null;comment:目标位置id\"`         //目标位置id\nToLocation        Location                 `json:\"toLocation\"      gorm:\"foreignKey:ToLocationID;references:Id\"`    //目标位置",
                    "type": "string"
                },
                "operationSource": {
                    "description": "操作来源",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.OperationSource"
                        }
                    ]
                },
                "operationTypeId": {
                    "description": "作业类型id",
                    "type": "integer"
@@ -3483,6 +3560,9 @@
                    "type": "string"
                },
                "receiverPhone": {
                    "type": "string"
                },
                "salesDetailsNumber": {
                    "type": "string"
                },
                "source": {
@@ -3713,9 +3793,6 @@
        },
        "models.Warehouse": {
            "type": "object",
            "required": [
                "code"
            ],
            "properties": {
                "active": {
                    "description": "是否启用,传true就行",
@@ -3731,9 +3808,7 @@
                },
                "code": {
                    "description": "仓库编码",
                    "type": "string",
                    "maxLength": 5,
                    "minLength": 1
                    "type": "string"
                },
                "company": {
                    "$ref": "#/definitions/models.Company"
@@ -3756,7 +3831,7 @@
                    "type": "integer"
                },
                "locationId": {
                    "description": "位置id",
                    "description": "默认位置id",
                    "type": "integer"
                },
                "name": {
@@ -4454,6 +4529,28 @@
                }
            }
        },
        "request.SaveUnitDict": {
            "type": "object",
            "properties": {
                "data": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.UnitDict"
                    }
                }
            }
        },
        "request.UnitDict": {
            "type": "object",
            "properties": {
                "isDefault": {
                    "type": "boolean"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateCompany": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -184,6 +184,29 @@
    - MaterialModeConsumables
    - MaterialModeOther
    - MaterialModeVirtual
  constvar.OperationSource:
    enum:
    - 1
    - 2
    - 3
    - 4
    - 5
    - 6
    type: integer
    x-enum-comments:
      OperationSourceOutsourcing: 委外入库
      OperationSourceOutsourcingApply: 委外领料
      OperationSourceProduction: 生产入库
      OperationSourceProductionApply: 生产领料
      OperationSourcePurchase: 采购入库
      OperationSourceSaleDelivery: 销售发货
    x-enum-varnames:
    - OperationSourcePurchase
    - OperationSourceProduction
    - OperationSourceOutsourcing
    - OperationSourceProductionApply
    - OperationSourceOutsourcingApply
    - OperationSourceSaleDelivery
  constvar.OperationStatus:
    enum:
    - 1
@@ -394,6 +417,13 @@
          gorm:"foreignKey:CompanyId"`                       //公司
      updateTime:
        type: string
      warehouse:
        allOf:
        - $ref: '#/definitions/models.Warehouse'
        description: 仓库
      warehouseId:
        description: 仓库ID
        type: integer
    type: object
  models.LogisticCompany:
    properties:
@@ -653,6 +683,10 @@
          ToLocationID      int                      `json:"toLocationId"    gorm:"type:int;not null;comment:目标位置id"`         //目标位置id
          ToLocation        Location                 `json:"toLocation"      gorm:"foreignKey:ToLocationID;references:Id"`    //目标位置
        type: string
      operationSource:
        allOf:
        - $ref: '#/definitions/constvar.OperationSource'
        description: 操作来源
      operationTypeId:
        description: 作业类型id
        type: integer
@@ -664,6 +698,8 @@
      receiverName:
        type: string
      receiverPhone:
        type: string
      salesDetailsNumber:
        type: string
      source:
        type: string
@@ -825,8 +861,6 @@
        type: boolean
      code:
        description: 仓库编码
        maxLength: 5
        minLength: 1
        type: string
      company:
        $ref: '#/definitions/models.Company'
@@ -843,7 +877,7 @@
        description: 入向运输
        type: integer
      locationId:
        description: 位置id
        description: 默认位置id
        type: integer
      name:
        description: 仓库名称
@@ -869,8 +903,6 @@
      warehouseLocation:
        description: 库存位置
        type: string
    required:
    - code
    type: object
  request.AddCompany:
    properties:
@@ -1331,6 +1363,20 @@
        description: 每页大小
        type: integer
      productId:
        type: string
    type: object
  request.SaveUnitDict:
    properties:
      data:
        items:
          $ref: '#/definitions/request.UnitDict'
        type: array
    type: object
  request.UnitDict:
    properties:
      isDefault:
        type: boolean
      name:
        type: string
    type: object
  request.UpdateCompany:
@@ -2981,6 +3027,25 @@
      summary: 产品历史出入库信息
      tags:
      - 产品
  /api-wms/v1/product/saveUnitDict:
    post:
      parameters:
      - description: 参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.SaveUnitDict'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 更新计量单位字典
      tags:
      - 数据字典
  /api-wms/v1/product/updateDisuse:
    post:
      parameters:
request/product_request.go
@@ -60,3 +60,12 @@
    ProductId   string          `gorm:"column:product_id"`
    TotalAmount decimal.Decimal `gorm:"column:total_amount"`
}
type UnitDict struct {
    Name      string `gorm:"unique;type:varchar(191);not null;comment:名称" json:"name"`
    IsDefault bool   `gorm:"type:tinyint(1);comment:是否默认" json:"isDefault"`
}
type SaveUnitDict struct {
    Data []*UnitDict `json:"data"`
}
router/router.go
@@ -122,6 +122,7 @@
        productAPI.PUT("cancelDisuse/:id", productController.CancelDisuse) //取消报废
        productAPI.GET("getUserInfo", productController.GetUserInfo)       //获取登录用户信息
        productAPI.GET("getUnitInfo", productController.GetUnitInfo)       //获取单位信息
        productAPI.POST("saveUnitDict", productController.SaveUnitDict)    //更新计量单位字典
    }