From 6dec2342316aecf4084c8f4efb43f33fbb72892f Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期二, 09 四月 2024 14:07:43 +0800 Subject: [PATCH] 更新计量单位字典 --- controllers/product_controller.go | 49 ++++++++ request/product_request.go | 9 + docs/swagger.yaml | 75 +++++++++++ docs/docs.go | 111 +++++++++++++++++- docs/swagger.json | 111 +++++++++++++++++- router/router.go | 1 6 files changed, 337 insertions(+), 19 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index b91d30f..a99ac83 100644 --- a/controllers/product_controller.go +++ b/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, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�") + return + } + if err := structx.AssignTo(reqParams.Data, ¶ms); 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, "娣诲姞鎴愬姛") +} diff --git a/docs/docs.go b/docs/docs.go index 07d8fc6..b81598e 100644 --- a/docs/docs.go +++ b/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:婧愪綅缃甶d\"` + "`" + ` //婧愪綅缃甶d\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": { diff --git a/docs/swagger.json b/docs/swagger.json index 6285131..a6c10ac 100644 --- a/docs/swagger.json +++ b/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:婧愪綅缃甶d\"` //婧愪綅缃甶d\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": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 7c2ffd4..7ffb926 100644 --- a/docs/swagger.yaml +++ b/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: diff --git a/request/product_request.go b/request/product_request.go index 8402959..e9e10a1 100644 --- a/request/product_request.go +++ b/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"` +} diff --git a/router/router.go b/router/router.go index 7bd6d6d..b28aef4 100644 --- a/router/router.go +++ b/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) //鏇存柊璁¢噺鍗曚綅瀛楀吀 } -- Gitblit v1.8.0