From d5785f7ecec215960c4d100bf129e1abeca9d5cb Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期二, 30 七月 2024 20:11:03 +0800
Subject: [PATCH] 位置报表多单位使用动态表头及相应数据调整(数据使用存储的多单位数据,并展示在对应单位下面)

---
 service/more_units.go |   72 +++++++++++++++++++++++++++++++-----
 1 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/service/more_units.go b/service/more_units.go
index 5abdb09..6982f4e 100644
--- a/service/more_units.go
+++ b/service/more_units.go
@@ -23,17 +23,54 @@
 	return moreValueArr
 }
 
-func FillMoreUnitToExcel(amount decimal.Decimal, units []models.UnitItems, startIndex int, column int, f *excelize.File) {
-	columnStr := strconv.Itoa(column)
-	for _, v := range units {
-		switch v.Unit {
-		case "鍖�":
-			f.SetCellValue("Sheet1", getColumnAlphabet(startIndex)+columnStr, v.Amount.Mul(amount))
-		case "绫�":
-			f.SetCellValue("Sheet1", getColumnAlphabet(startIndex+1)+columnStr, v.Amount.Mul(amount))
-		case "閲嶉噺":
-			f.SetCellValue("Sheet1", getColumnAlphabet(startIndex+2)+columnStr, v.Amount.Mul(amount))
+func AddMoreUnit(units []models.UnitItems, units2 []models.UnitItems) []models.UnitItems {
+	moreValueArr := make([]models.UnitItems, 0, len(units))
+	for _, unitItem1 := range units {
+		for _, unitItem2 := range units2 {
+			if unitItem1.Unit == unitItem2.Unit {
+				moreValueArr = append(moreValueArr, models.UnitItems{
+					Amount:   unitItem1.Amount.Add(unitItem2.Amount),
+					Unit:     unitItem1.Unit,
+					Floating: unitItem1.Floating,
+				})
+			}
 		}
+	}
+	return moreValueArr
+}
+
+// MoreUnitIsEnough 澶氬崟浣嶅簱瀛樻槸鍚﹁冻澶�
+func MoreUnitIsEnough(units []models.UnitItems, units2 []models.UnitItems) bool {
+	for _, unitItem1 := range units {
+		for _, unitItem2 := range units2 {
+			if unitItem1.Amount.LessThan(unitItem2.Amount) {
+				return false
+			}
+		}
+	}
+	return true
+}
+
+func SubMoreUnit(units []models.UnitItems, units2 []models.UnitItems) []models.UnitItems {
+	moreValueArr := make([]models.UnitItems, 0, len(units))
+	for _, unitItem1 := range units {
+		for _, unitItem2 := range units2 {
+			if unitItem1.Unit == unitItem2.Unit {
+				moreValueArr = append(moreValueArr, models.UnitItems{
+					Amount:   unitItem1.Amount.Sub(unitItem2.Amount),
+					Unit:     unitItem1.Unit,
+					Floating: unitItem1.Floating,
+				})
+			}
+		}
+	}
+	return moreValueArr
+}
+
+func FillMoreUnitToExcel(units []models.UnitItems, startIndex int, row int, unitIndexMap map[string]int, f *excelize.File) {
+	rowStr := strconv.Itoa(row)
+	for _, v := range units {
+		f.SetCellValue("Sheet1", getColumnAlphabet(startIndex+unitIndexMap[v.Unit])+rowStr, v.Amount)
 	}
 	return
 }
@@ -88,3 +125,18 @@
 	}
 	return f.NewStyle(style)
 }
+
+func GetAllUnits() (allUnits []string, unitIndexMap map[string]int) {
+	units, err := models.NewUnitDictSearch().FindNotTotal()
+	allUnits = make([]string, 0, len(units))
+	unitIndexMap = make(map[string]int)
+	if err != nil {
+		return
+	}
+
+	for k, v := range units {
+		allUnits = append(allUnits, v.Name)
+		unitIndexMap[v.Name] = k
+	}
+	return
+}

--
Gitblit v1.8.0