From 155f70979af20ca520a55b89c6ec8cd46c43f8a5 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 31 七月 2024 15:47:33 +0800 Subject: [PATCH] 产品流水表增加多单位存储 --- service/location_forms.go | 48 ++++++++++++++++++++++++++++++++++-------------- 1 files changed, 34 insertions(+), 14 deletions(-) diff --git a/service/location_forms.go b/service/location_forms.go index eafd283..28d686d 100644 --- a/service/location_forms.go +++ b/service/location_forms.go @@ -27,12 +27,18 @@ resp := new(response.LocationForms) resp.Amount = amount.Amount resp.LocationId = amount.LocationId - resp.LocationName = amount.Location.Name + resp.LocationName = amount.Location.JointName resp.ProduceId = amount.Product.ID resp.ProductName = amount.Product.Name resp.ProductTypeName = amount.ProductCategory.Name resp.Unit = amount.Product.Unit resp.Value = resp.Amount.Mul(amount.Product.Cost) + + moreUnit := amount.Product.MoreUnit + if moreUnit != nil && *moreUnit { + resp.AmountMoreUnits = amount.MoreUnitList + } + result = append(result, resp) } @@ -40,10 +46,11 @@ } func (slf *LocationFormsService) BuildSearch(params request.GetLocationForms) (search *models.LocationProductAmountSearch, err error) { - ids := make([]int, 0) + ids := params.LocationIds if params.LocationId != 0 { ids = append(ids, params.LocationId) - } else { + } + if len(ids) == 0 { //鏌ヨ浣嶇疆 locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).SetType(3).FindAll() if err != nil { @@ -94,22 +101,35 @@ var fileName string f := excelize.NewFile() + unitData, unitIndexMap := GetAllUnits() // 鑷畾涔夎〃澶� - headers := []string{"浣嶇疆", "浜у搧", "浜у搧绫诲埆", "鍦ㄥ簱鏁伴噺", "浠峰��"} + headers := []interface{}{"浣嶇疆", "浜у搧", "浜у搧绫诲埆", map[string][]string{"鍦ㄥ簱鏁伴噺": unitData}, "浠峰��"} + lastColumnNumber, err := SetExcelHeaders(headers, f) + if err != nil { + return "", err + } + f.MergeCell("Sheet1", "A1", "A2") // 鍚堝苟鍗曞厓鏍� + f.MergeCell("Sheet1", "B1", "B2") // 鍚堝苟鍗曞厓鏍� + f.MergeCell("Sheet1", "C1", "C2") // 鍚堝苟鍗曞厓鏍� - // 璁剧疆琛ㄥご - for i, header := range headers { - cell := getColumnAlphabet(i+1) + "1" - f.SetCellValue("Sheet1", cell, header) + titleStyle, err := SetHeaderStyle(f) + if err != nil { + return "", err } + lastColumn := getColumnAlphabet(lastColumnNumber) + f.SetCellStyle("Sheet1", "A1", lastColumn+"2", titleStyle) + // 璁剧疆鍒楀 + f.SetColWidth("Sheet1", "A", "C", 30) + for i, v := range dataList { - column := strconv.Itoa(i + 2) - 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) - f.SetCellValue("Sheet1", "E"+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