From 1d5cb2f03c706c4b1cc36f50fd431f98fdbe7101 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期三, 13 十二月 2023 15:23:33 +0800
Subject: [PATCH] 对number的验证及不重复
---
controllers/product_controller.go | 19 ++++++++++++++++++-
controllers/operation.go | 17 ++++++++++++++++-
request/product_request.go | 1 +
3 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/controllers/operation.go b/controllers/operation.go
index 2a0b25e..e467303 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -77,8 +77,19 @@
}
params.Status = constvar.OperationStatus_Ready
- params.Number = strconv.FormatInt(time.Now().Unix(), 10)
+ //params.Number = strconv.FormatInt(time.Now().Unix(), 10)
params.BaseOperationType = operationType.BaseOperationType
+
+ var numberNum int64
+ if err := mysqlx.GetDB().Model(&models.Operation{}).Where("number=?", params.Number).Count(&numberNum).Error; err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+ if numberNum > 0 {
+ util.ResponseFormat(c, code.RequestParamError, "鍗曞彿宸插瓨鍦�")
+ return
+ }
+
if err := models.NewOperationSearch().Create(¶ms); err != nil {
logx.Errorf("Operation create err: %v", err)
util.ResponseFormat(c, code.SaveFail, "娣诲姞澶辫触锛�"+err.Error())
@@ -145,6 +156,10 @@
return errors.New("璇峰~鍏ユ簮鍗曞彿")
}
+ if params.Number == "" {
+ return errors.New("璇峰~鍏ュ崟鍙�")
+ }
+
if params.OperationTypeId == 0 && int(params.BaseOperationType) == 0 {
return errors.New("鏈瘑鍒璁板綍绫诲瀷")
}
diff --git a/controllers/product_controller.go b/controllers/product_controller.go
index 43a9db0..616b889 100644
--- a/controllers/product_controller.go
+++ b/controllers/product_controller.go
@@ -14,6 +14,7 @@
"wms/extend/util"
"wms/models"
"wms/pkg/logx"
+ "wms/pkg/mysqlx"
"wms/request"
)
@@ -447,12 +448,28 @@
util.ResponseFormat(c, code.RequestParamError, "璇疯緭鍏ユ簮鍗曟嵁")
return
}
+ if params.Number == "" {
+ util.ResponseFormat(c, code.RequestParamError, "璇疯緭鍏ュ崟鍙�")
+ return
+ }
+
+ var numberNum int64
+ if err := mysqlx.GetDB().Model(&models.Operation{}).Where("number=?", params.Number).Count(&numberNum).Error; err != nil {
+ util.ResponseFormat(c, code.RequestParamError, err.Error())
+ return
+ }
+ if numberNum > 0 {
+ util.ResponseFormat(c, code.RequestParamError, "鍗曞彿宸插瓨鍦�")
+ return
+ }
+
detail := &models.OperationDetails{
ProductId: params.ProductId,
Amount: params.Amount,
}
operation := models.Operation{
- Number: strconv.FormatInt(time.Now().Unix(), 10),
+ //Number: strconv.FormatInt(time.Now().Unix(), 10),
+ Number: params.Number,
SourceNumber: params.SourceNumber,
OperationTypeId: 0,
Status: constvar.OperationStatus_Ready,
diff --git a/request/product_request.go b/request/product_request.go
index b484263..8402959 100644
--- a/request/product_request.go
+++ b/request/product_request.go
@@ -24,6 +24,7 @@
ToLocationId int `json:"toLocationId"`
SourceNumber string `json:"sourceNumber"`
//Unit string `json:"unit"`
+ Number string `json:"number"`
}
type QueryDisuseList struct {
--
Gitblit v1.8.0