From 79aef24a785581d95343ccd99e9cb362b2bc9c97 Mon Sep 17 00:00:00 2001
From: yinbentan <yinbentan@live.com>
Date: 星期六, 06 七月 2024 21:31:59 +0800
Subject: [PATCH] 调整库存商品位置错误

---
 controllers/operation.go |   37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/controllers/operation.go b/controllers/operation.go
index 41e3932..2f10d27 100644
--- a/controllers/operation.go
+++ b/controllers/operation.go
@@ -9,7 +9,6 @@
 	"github.com/shopspring/decimal"
 	"github.com/xuri/excelize/v2"
 	"gorm.io/gorm"
-	"sort"
 	"strconv"
 	"strings"
 	"time"
@@ -180,19 +179,19 @@
 	params.DealerType = miniDict.Name
 }
 
+// CheckDetailsRepeat 鍑哄簱銆佸叆搴撱�佺洏鐐规秹鍙婁骇鍝侀噸澶嶆�ф鏌ワ紙浠ヤ骇鍝佺紪鍙枫�佸嚭搴撳簱鎴跨紪鍙枫�佸叆搴撳簱鎴跨紪鍙凤級
+// 瀛樺湪閲嶅鍊� true锛� 涓嶅瓨鍦ㄨ繑鍥� false
 func CheckDetailsRepeat(details []*models.OperationDetails) bool {
-	var detailIDs []string
-	var tempID string
-	for _, v := range details {
-		detailIDs = append(detailIDs, v.ProductId)
+	if len(details) == 0 {
+		return false
 	}
-	sort.Strings(detailIDs)
-	for _, v := range detailIDs {
-		if v != tempID {
-			tempID = v
-		} else {
-			return true
-		}
+	var detailKeyMap = make(map[string]bool)
+	for _, v := range details {
+		key := fmt.Sprintf("%v%v%v", v.ProductId, v.FromLocationID, v.ToLocationID)
+		detailKeyMap[key] = true
+	}
+	if len(detailKeyMap) != len(details) { // 闀垮害鐩稿悓锛屼笉瀛樺湪閲嶅鍊硷紱闀垮害涓嶅悓瀛樺湪瀛樺湪涓嶅悓
+		return true
 	}
 	return false
 }
@@ -379,6 +378,10 @@
 	//	}
 	//}
 	userInfo := middleware.GetUserInfo(c)
+	if userInfo == nil {
+		util.ResponseFormat(c, code.SetStatusError, "鐧诲綍鐢ㄦ埛淇℃伅涓虹┖锛岃鐧诲綍鍚庨噸璇曪紒")
+		return
+	}
 	for _, v := range list {
 		v.CreatedBy = userInfo.NickName
 		//if err == nil {
@@ -991,11 +994,13 @@
 	totalAmount := decimal.NewFromInt(0) // 鎬婚噾棰�
 	totalPrice := decimal.NewFromInt(0)  // 鎬讳环
 	rowIndex := 6
+	str := ""
 	for i, v := range operation.Details {
 		//璁剧疆琛ㄥ崟鏈�澶�6鏉℃暟鎹�
 		if i > 6 {
 			break
 		}
+		str += v.Remark
 		f.SetCellValue(sheet, "B"+strconv.Itoa(rowIndex), v.Product.Name)                                                          // 浜у搧鍚嶇О
 		f.SetCellValue(sheet, "C"+strconv.Itoa(rowIndex), v.Product.Specs)                                                         //瑙勬牸
 		f.SetCellValue(sheet, "D"+strconv.Itoa(rowIndex), attributeValueMap[fmt.Sprintf("%d%s", attributeMap["棰滆壊"], v.ProductId)]) //棰滆壊
@@ -1055,7 +1060,8 @@
 	}
 
 	// 澶囨敞 绗�13琛�
-	f.SetCellValue(sheet, "B13", "澶囨敞锛�"+operation.Remark)
+	//f.SetCellValue(sheet, "B13", "澶囨敞锛�"+operation.Comment)
+	f.SetCellValue(sheet, "B13", "澶囨敞锛�"+str)
 	// 绗�14琛�
 	f.SetCellValue(sheet, "C14", operation.Manager)    // 瀹℃牳
 	f.SetCellValue(sheet, "F14", operation.Accountant) // 淇濈
@@ -1103,11 +1109,13 @@
 	totalAmount := decimal.NewFromInt(0) // 鎬婚噾棰�
 	totalPrice := decimal.NewFromInt(0)  // 鎬讳环
 	rowIndex := 5
+	str := ""
 	for i, v := range operation.Details {
 		//璁剧疆琛ㄥ崟鏈�澶�9鏉℃暟鎹�
 		if i > 9 {
 			break
 		}
+		str += v.Remark
 		f.SetCellValue(sheet, "A"+strconv.Itoa(rowIndex), v.Product.Name)    // 鍝佸悕
 		f.SetCellValue(sheet, "B"+strconv.Itoa(rowIndex), v.Product.Type)    // 鍨嬪彿
 		f.SetCellValue(sheet, "C"+strconv.Itoa(rowIndex), v.Product.Unit)    // 鍗曚綅
@@ -1171,7 +1179,8 @@
 		}
 	}
 
-	f.SetCellValue(sheet, "Q5", operation.Remark) // 澶囨敞
+	//f.SetCellValue(sheet, "Q5", operation.Comment) // 澶囨敞
+	f.SetCellValue(sheet, "Q5", str) // 澶囨敞
 
 	// 绗�14琛�
 	f.SetCellValue(sheet, "B15", operation.Manager)    // 涓荤

--
Gitblit v1.8.0