From 201be38fd71ee487d887e686cf07773ec750a8de Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期四, 26 十月 2023 17:56:50 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS
---
controllers/warehouse.go | 62 +++++++++++++++++++++++++------
1 files changed, 50 insertions(+), 12 deletions(-)
diff --git a/controllers/warehouse.go b/controllers/warehouse.go
index 5dc9857..01c1ba3 100644
--- a/controllers/warehouse.go
+++ b/controllers/warehouse.go
@@ -44,7 +44,7 @@
//鍒涘缓榛樿浣嶇疆
location := &models.Location{
Name: "榛樿浣嶇疆",
- ParentId: params.Code,
+ JointName: params.Code,
Type: constvar.LocationTypeInternal,
ReplenishLocation: true,
}
@@ -54,7 +54,36 @@
return
}
params.LocationId = locationId
- if err := models.NewWarehouseSearch().Create(¶ms); err != nil {
+ err = models.WithTransaction(func(tx *gorm.DB) error {
+ err := models.NewWarehouseSearch().SetOrm(tx).Create(¶ms)
+ if err != nil {
+ return err
+ }
+ //鍒涘缓涓変釜榛樿鎿嶄綔绫诲瀷
+ var types []*models.OperationType
+ inType := &models.OperationType{
+ Name: params.Name + "-鍏ュ簱",
+ BaseOperationType: constvar.BaseOperationTypeIncoming,
+ WarehouseId: params.Id,
+ }
+ types = append(types, inType)
+ outType := &models.OperationType{
+ Name: params.Name + "-鍑哄簱",
+ BaseOperationType: constvar.BaseOperationTypeOutgoing,
+ WarehouseId: params.Id,
+ }
+ types = append(types, outType)
+ internalType := &models.OperationType{
+ Name: params.Name + "-鍐呴儴璋冩嫧",
+ BaseOperationType: constvar.BaseOperationTypeInternal,
+ WarehouseId: params.Id,
+ }
+ types = append(types, internalType)
+ err = models.NewOperationTypeSearch().SetOrm(tx).CreateBatch(types)
+ return err
+ })
+ if err != nil {
+ _ = models.NewLocationSearch().SetID(locationId).Delete()
logx.Errorf("warehouse create err: %v", err)
util.ResponseFormat(c, code.SaveFail, "鎻掑叆澶辫触")
return
@@ -101,7 +130,7 @@
//鏇存柊浣嶇疆淇℃伅
if oldRecord != nil && params.Code != oldRecord.Code {
m := make(map[string]interface{})
- m["parent_id"] = params.Code
+ m["joint_name"] = params.Code
err := models.NewLocationSearch().SetID(oldRecord.LocationId).UpdateByMap(m)
if err != nil {
return errors.New("鏇存柊浣嶇疆淇℃伅澶辫触")
@@ -143,7 +172,7 @@
for _, warehouse := range list {
codes = append(codes, warehouse.Code)
}
- locations, err := models.NewLocationSearch().SetParents(codes).FindNotTotal()
+ locations, err := models.NewLocationSearch().SetJointNames(codes).FindNotTotal()
if err != nil {
util.ResponseFormat(c, code.RequestParamError, "浣嶇疆淇℃伅鏌ユ壘澶辫触")
return
@@ -174,22 +203,31 @@
return
}
- //鍒犻櫎浣嶇疆淇℃伅
first, err := models.NewWarehouseSearch().SetID(id).First()
if err != nil {
util.ResponseFormat(c, code.RequestParamError, "鑾峰彇浠撳簱淇℃伅澶辫触")
return
}
- err = models.NewLocationSearch().SetID(first.LocationId).Delete()
+ err = models.WithTransaction(func(tx *gorm.DB) error {
+ //鍒犻櫎浣嶇疆淇℃伅
+ err = models.NewLocationSearch().SetOrm(tx).SetJointName(first.Code).Delete()
+ if err != nil {
+ return err
+ }
+ //鍒犻櫎鎿嶄綔绫诲瀷
+ err = models.NewOperationTypeSearch().SetOrm(tx).SetWarehouseId(first.Id).Delete()
+ if err != nil {
+ return err
+ }
+ //鍒犻櫎浠撳簱
+ err = models.NewWarehouseSearch().SetOrm(tx).SetID(id).Delete()
+ return err
+ })
if err != nil {
- util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎浣嶇疆淇℃伅澶辫触")
+ util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎浠撳簱澶辫触")
return
}
- err = models.NewWarehouseSearch().SetID(id).Delete()
- if err != nil {
- util.ResponseFormat(c, code.RequestParamError, "鍒犻櫎浠撳簱淇℃伅澶辫触")
- return
- }
+
util.ResponseFormat(c, code.UpdateSuccess, "鍒犻櫎鎴愬姛")
}
--
Gitblit v1.8.0