From d5785f7ecec215960c4d100bf129e1abeca9d5cb Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 30 七月 2024 20:11:03 +0800 Subject: [PATCH] 位置报表多单位使用动态表头及相应数据调整(数据使用存储的多单位数据,并展示在对应单位下面) --- service/location_forms.go | 22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-) diff --git a/service/location_forms.go b/service/location_forms.go index 27932a2..262fa59 100644 --- a/service/location_forms.go +++ b/service/location_forms.go @@ -36,7 +36,7 @@ moreUnit := amount.Product.MoreUnit if moreUnit != nil && *moreUnit { - resp.AmountMoreUnits = CreateMoreUnit(resp.Amount, amount.Product.MoreUnitList) + resp.AmountMoreUnits = amount.MoreUnitList } result = append(result, resp) @@ -101,11 +101,12 @@ var fileName string f := excelize.NewFile() + unitData, unitIndexMap := GetAllUnits() // 鑷畾涔夎〃澶� - headers := []interface{}{"浣嶇疆", "浜у搧", "浜у搧绫诲埆", map[string][]string{"鍦ㄥ簱鏁伴噺": {"浠�", "鍖�", "绫�", "閲嶉噺"}}, "浠峰��"} + headers := []interface{}{"浣嶇疆", "浜у搧", "浜у搧绫诲埆", map[string][]string{"鍦ㄥ簱鏁伴噺": unitData}, "浠峰��"} // 璁剧疆琛ㄥご - var i int + i := 1 for _, h := range headers { if v, ok := h.(string); ok { f.SetCellValue("Sheet1", getColumnAlphabet(i)+"1", v) @@ -146,16 +147,15 @@ f.SetCellStyle("Sheet1", "A1", lastColumn+"2", titleStyle) // 璁剧疆鍒楀 f.SetColWidth("Sheet1", "A", "C", 30) - f.SetColWidth("Sheet1", "D", lastColumn, 15) for i, v := range dataList { - column := strconv.Itoa(i + 3) - f.SetCellValue("Sheet1", "A"+column, v.LocationName) - f.SetCellValue("Sheet1", "B"+column, v.ProductName) - f.SetCellValue("Sheet1", "C"+column, v.ProductTypeName) - f.SetCellValue("Sheet1", "D"+column, v.Amount) - FillMoreUnitToExcel(v.Amount, v.AmountMoreUnits, 4, i+2, f) - f.SetCellValue("Sheet1", "H"+column, v.Value) + row := strconv.Itoa(i + 3) + f.SetCellValue("Sheet1", "A"+row, v.LocationName) + f.SetCellValue("Sheet1", "B"+row, v.ProductName) + f.SetCellValue("Sheet1", "C"+row, v.ProductTypeName) + v.AmountMoreUnits = append(v.AmountMoreUnits, models.UnitItems{Amount: v.Amount, Unit: v.Unit}) + FillMoreUnitToExcel(v.AmountMoreUnits, 4, i+3, unitIndexMap, f) + f.SetCellValue("Sheet1", getColumnAlphabet(4+len(unitData))+row, v.Value) } fileName = fmt.Sprintf("浣嶇疆鎶ヨ〃%s.xlsx", time.Now().Format("2006-01-02-1504")) -- Gitblit v1.8.0