From 9bb979dbfb2c4edc31018a83970567f8734c0b61 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 30 七月 2024 11:42:45 +0800 Subject: [PATCH] 单位字典保存前进行重复校验 --- controllers/product_controller.go | 12 +++++++++++- models/material.go | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/controllers/product_controller.go b/controllers/product_controller.go index 56ab486..eb8890c 100644 --- a/controllers/product_controller.go +++ b/controllers/product_controller.go @@ -1028,6 +1028,16 @@ v.Sort = i + 1 } + //鏍¢獙閲嶅 + m := make(map[string]struct{}) + for _, v := range params { + if _, ok := m[v.Name]; ok { + util.ResponseFormat(c, code.RequestParamError, "鍗曚綅閲嶅锛�"+v.Name) + return + } + m[v.Name] = struct{}{} + } + err := models.WithTransaction(func(tx *gorm.DB) error { err := models.NewUnitDictSearch().SetOrm(tx).Delete() if err != nil { @@ -1041,7 +1051,7 @@ return nil }) if err != nil { - util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎澶辫触") + util.ResponseFormat(c, code.RequestParamError, "淇濆瓨澶辫触") return } diff --git a/models/material.go b/models/material.go index e410f35..75e15d3 100644 --- a/models/material.go +++ b/models/material.go @@ -120,7 +120,7 @@ } UnitItems struct { - Amount decimal.Decimal `json:"amount"` + Amount decimal.Decimal `json:"amount"` //鍦ㄧ墿鏂欎腑涓烘崲绠楃巼锛�1杈呭崟浣�=鎹㈢畻鐜�*涓诲崟浣嶏級锛屽湪鏄庣粏鎴栧簱瀛樹腑涓哄叿浣撳�� Unit string `json:"unit"` Floating bool `json:"floating"` //鏄惁娴姩鍒╃巼 } -- Gitblit v1.8.0