From 2716487d13f3521adeb25a48aa07a89f885d32c7 Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期一, 09 十月 2023 09:36:08 +0800 Subject: [PATCH] 仓库功能修改 --- controllers/operation.go | 38 ++++++++++++++++++++++++++++++-------- 1 files changed, 30 insertions(+), 8 deletions(-) diff --git a/controllers/operation.go b/controllers/operation.go index 9a87ab0..3e1e36f 100644 --- a/controllers/operation.go +++ b/controllers/operation.go @@ -6,6 +6,7 @@ "github.com/gin-gonic/gin" "github.com/shopspring/decimal" "gorm.io/gorm" + "sort" "strconv" "time" "wms/constvar" @@ -46,6 +47,12 @@ util.ResponseFormat(c, code.RequestParamError, err.Error()) return } + + if CheckDetailsRepeat(params.Details) { + util.ResponseFormat(c, code.RequestParamError, "鏄庣粏涓笉鑳藉瓨鍦ㄩ噸澶嶇殑浜у搧") + return + } + operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() if err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) @@ -61,6 +68,23 @@ return } util.ResponseFormat(c, code.Success, "娣诲姞鎴愬姛") +} + +func CheckDetailsRepeat(details []*models.OperationDetails) bool { + detailIDs := []string{} + var tempID string + for _, v := range details { + detailIDs = append(detailIDs, v.ProductId) + } + sort.Strings(detailIDs) + for _, v := range detailIDs { + if v != tempID { + tempID = v + } else { + return true + } + } + return false } func (slf OperationController) FormatLocation(params *models.Operation) error { @@ -152,10 +176,7 @@ search := models.NewOperationSearch() search.SetPage(params.Page, params.PageSize) if params.Number != "" { - search.SetNumber(params.Number) - } - if params.SourceNumber != "" { - search.SetSourceNumber(params.SourceNumber) + search.SetKeyword(params.Number) } list, total, err := search.SetOperationTypeId(params.OperationTypeId).SetPreload(true).SetOrder("created_at desc").Find() if err != nil { @@ -200,6 +221,10 @@ } if err := slf.CheckParams(params); err != nil { util.ResponseFormat(c, code.RequestParamError, err.Error()) + return + } + if CheckDetailsRepeat(params.Details) { + util.ResponseFormat(c, code.RequestParamError, "鏄庣粏涓笉鑳藉瓨鍦ㄩ噸澶嶇殑浜у搧") return } if err := slf.FormatLocation(¶ms); err != nil { @@ -384,10 +409,7 @@ search.SetPage(params.Page, params.PageSize) search.SetPage(params.Page, params.PageSize) if params.Number != "" { - search.SetNumber(params.Number) - } - if params.SourceNumber != "" { - search.SetSourceNumber(params.SourceNumber) + search.SetKeyword(params.Number) } list, total, err := search.SetPreload(true).SetOrder("created_at desc").Find() if err != nil { -- Gitblit v1.8.0