From 1dd416deaf053a23a56b42a1ab18fe9f621fefb0 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期一, 13 十一月 2023 20:01:30 +0800
Subject: [PATCH] 仓库与位置修改
---
request/report_forms_request.go | 1
controllers/report_forms_controller.go | 21 ++++++----
models/location.go | 10 +++++
controllers/warehouse.go | 45 +++++++++++++++++++---
docs/swagger.yaml | 2 +
controllers/location.go | 3 +
docs/docs.go | 5 ++
docs/swagger.json | 3 +
8 files changed, 73 insertions(+), 17 deletions(-)
diff --git a/controllers/location.go b/controllers/location.go
index ff2d5c4..e1102fa 100644
--- a/controllers/location.go
+++ b/controllers/location.go
@@ -4,6 +4,7 @@
"errors"
"github.com/gin-gonic/gin"
"strconv"
+ "strings"
"wms/extend/code"
"wms/extend/util"
"wms/models"
@@ -159,7 +160,7 @@
}
params.JointName = first.JointName + "/" + params.Name
} else {
- params.JointName = params.Name
+ params.JointName = strings.Split(params.JointName, "/")[0] + "/" + params.Name
}
err := models.NewLocationSearch().Update(¶ms)
if err != nil {
diff --git a/controllers/report_forms_controller.go b/controllers/report_forms_controller.go
index c137692..e69f3d4 100644
--- a/controllers/report_forms_controller.go
+++ b/controllers/report_forms_controller.go
@@ -218,16 +218,19 @@
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
return
}
-
- //鏌ヨ浣嶇疆
- locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).FindAll()
- if err != nil {
- util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浣嶇疆澶辫触")
- return
- }
ids := make([]int, 0)
- for _, location := range locations {
- ids = append(ids, location.Id)
+ if params.LocationId != 0 {
+ ids = append(ids, params.LocationId)
+ } else {
+ //鏌ヨ浣嶇疆
+ locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).FindAll()
+ if err != nil {
+ util.ResponseFormat(c, code.RequestParamError, "鏌ヨ浣嶇疆澶辫触")
+ return
+ }
+ for _, location := range locations {
+ ids = append(ids, location.Id)
+ }
}
amounts, total, err := models.NewLocationProductAmountSearch().SetPage(params.Page, params.PageSize).SetPreload(true).SetKeyword(params.KeyWord).SetProductId(params.ProductId).SetLocationIds(ids).FindByPage()
diff --git a/controllers/warehouse.go b/controllers/warehouse.go
index 01c1ba3..bc2aa7f 100644
--- a/controllers/warehouse.go
+++ b/controllers/warehouse.go
@@ -7,6 +7,7 @@
"github.com/spf13/cast"
"gorm.io/gorm"
"strconv"
+ "strings"
"wms/constvar"
"wms/extend/code"
"wms/extend/util"
@@ -41,12 +42,24 @@
util.ResponseFormat(c, code.RequestParamError, err.Error())
return
}
+ //鍒涘缓瑙嗗浘
+ view := &models.Location{
+ Name: params.Code,
+ JointName: params.Code,
+ Type: constvar.LocationTypeView,
+ }
+ id, err := models.NewLocationSearch().CreateReturnId(view)
+ if err != nil {
+ util.ResponseFormat(c, code.SaveFail, "瑙嗗浘鍒涘缓澶辫触")
+ return
+ }
//鍒涘缓榛樿浣嶇疆
location := &models.Location{
Name: "榛樿浣嶇疆",
- JointName: params.Code,
+ JointName: params.Code + "/榛樿浣嶇疆",
Type: constvar.LocationTypeInternal,
ReplenishLocation: true,
+ ParentId: id,
}
locationId, err := models.NewLocationSearch().CreateReturnId(location)
if err != nil {
@@ -129,9 +142,27 @@
}
//鏇存柊浣嶇疆淇℃伅
if oldRecord != nil && params.Code != oldRecord.Code {
- m := make(map[string]interface{})
- m["joint_name"] = params.Code
- err := models.NewLocationSearch().SetID(oldRecord.LocationId).UpdateByMap(m)
+ locations, err := models.NewLocationSearch().SetJointName(oldRecord.Code).FindNotTotal()
+ if err != nil {
+ return errors.New("鏌ヨ浣嶇疆淇℃伅澶辫触")
+ }
+
+ err = models.WithTransaction(func(db *gorm.DB) error {
+ for _, location := range locations {
+ m := make(map[string]interface{})
+ index := strings.Index(location.JointName, "/")
+ if index > 0 {
+ m["joint_name"] = params.Code + location.JointName[index:]
+ } else {
+ m["joint_name"] = params.Code
+ }
+ err = models.NewLocationSearch().SetOrm(db).SetID(location.Id).UpdateByMap(m)
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+ })
if err != nil {
return errors.New("鏇存柊浣嶇疆淇℃伅澶辫触")
}
@@ -168,11 +199,11 @@
return
}
//鑾峰彇浣嶇疆淇℃伅
- codes := make([]string, 0)
+ ids := make([]int, 0)
for _, warehouse := range list {
- codes = append(codes, warehouse.Code)
+ ids = append(ids, warehouse.LocationId)
}
- locations, err := models.NewLocationSearch().SetJointNames(codes).FindNotTotal()
+ locations, err := models.NewLocationSearch().SetIds(ids).FindNotTotal()
if err != nil {
util.ResponseFormat(c, code.RequestParamError, "浣嶇疆淇℃伅鏌ユ壘澶辫触")
return
diff --git a/docs/docs.go b/docs/docs.go
index 2d9e716..794a765 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -3656,6 +3656,9 @@
"keyWord": {
"type": "string"
},
+ "locationId": {
+ "type": "integer"
+ },
"page": {
"description": "椤电爜",
"type": "integer"
@@ -4372,6 +4375,8 @@
Description: "",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
+ LeftDelim: "{{",
+ RightDelim: "}}",
}
func init() {
diff --git a/docs/swagger.json b/docs/swagger.json
index 61c30f6..9cbcfea 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -3644,6 +3644,9 @@
"keyWord": {
"type": "string"
},
+ "locationId": {
+ "type": "integer"
+ },
"page": {
"description": "椤电爜",
"type": "integer"
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index 7346a4a..6754d44 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -994,6 +994,8 @@
properties:
keyWord:
type: string
+ locationId:
+ type: integer
page:
description: 椤电爜
type: integer
diff --git a/models/location.go b/models/location.go
index 028e875..ad60d86 100644
--- a/models/location.go
+++ b/models/location.go
@@ -38,6 +38,7 @@
Orm *gorm.DB
Preload bool
JointNames []string
+ Ids []int
}
)
@@ -66,6 +67,11 @@
func (slf *LocationSearch) SetID(ID int) *LocationSearch {
slf.Id = ID
+ return slf
+}
+
+func (slf *LocationSearch) SetIds(ids []int) *LocationSearch {
+ slf.Ids = ids
return slf
}
@@ -116,6 +122,10 @@
db = db.Where("id = ?", slf.Id)
}
+ if len(slf.Ids) > 0 {
+ db = db.Where("id in (?)", slf.Ids)
+ }
+
if slf.Order != "" {
db = db.Order(slf.Order)
}
diff --git a/request/report_forms_request.go b/request/report_forms_request.go
index 729a0e4..5956eaa 100644
--- a/request/report_forms_request.go
+++ b/request/report_forms_request.go
@@ -23,4 +23,5 @@
KeyWord string `json:"keyWord"`
WareHouseCode string `json:"wareHouseCode"`
ProductId string `json:"productId"`
+ LocationId int `json:"locationId"`
}
--
Gitblit v1.8.0