| | |
| | | } |
| | | moreUnit := v.Product.MoreUnit |
| | | if moreUnit != nil && *moreUnit { |
| | | data.AmountMoreUnits = CreateMoreUnit(v.Amount, v.Product.MoreUnitList) |
| | | data.AmountMoreUnits = v.MoreUnitList |
| | | } |
| | | result = append(result, data) |
| | | } |
| | |
| | | |
| | | search.Orm = search.Orm.Model(&models.MoveHistory{}). |
| | | Select("number, updated_at, product_name, from_location_id, operation_id,to_location_id, amount, " + |
| | | "unit, operator, base_operation_type, weight, product_id, from_location, to_location, operation_type_name, weight").Order("id desc") |
| | | "unit, operator, base_operation_type, weight, product_id, from_location, to_location, operation_type_name, weight, more_unit_value").Order("id desc") |
| | | if len(ids) > 0 { |
| | | search.Orm = search.Orm.Where("id in ?", ids) |
| | | } |
| | |
| | | |
| | | // 自定义表头 |
| | | headers := []interface{}{"日期", "单号", "产品", "产品编码", "业务类型", "从", "至", map[string][]string{"数量": unitData}, "单位", "重量"} |
| | | |
| | | // 设置表头 |
| | | if err := SetExcelHeader(headers, f); err != nil { |
| | | lastColumnNumber, err := SetExcelHeaders(headers, f) |
| | | if err != nil { |
| | | return "", err |
| | | } |
| | | |
| | | for i := 1; i <= 7; i++ { |
| | | column := getColumnAlphabet(i) |
| | | f.MergeCell("Sheet1", column+"1", column+"2") // 合并单元格 |
| | | } |
| | | |
| | | for i := lastColumnNumber - 2; i <= lastColumnNumber; i++ { |
| | | column := getColumnAlphabet(i) |
| | | f.MergeCell("Sheet1", column+"1", column+"2") // 合并单元格 |
| | | } |
| | | |
| | | style, err := SetHeaderStyle(f) |
| | |
| | | return "", err |
| | | } |
| | | |
| | | lastColumn := getColumnAlphabet(13) |
| | | f.SetCellStyle("Sheet1", "A1", lastColumn+"2", style) |
| | | lastColumn := getColumnAlphabet(lastColumnNumber) |
| | | f.SetCellStyle("Sheet1", "A1", lastColumn, style) |
| | | // 设置列宽 |
| | | f.SetColWidth("Sheet1", "A", "G", 30) |
| | | f.SetColWidth("Sheet1", "H", "K", 15) |
| | | f.SetColWidth("Sheet1", "A", lastColumn, 20) |
| | | |
| | | for i, v := range dataList { |
| | | column := strconv.Itoa(i + 3) |
| | | f.SetCellValue("Sheet1", "A"+column, v.Date) |
| | | f.SetCellValue("Sheet1", "B"+column, v.Number) |
| | | f.SetCellValue("Sheet1", "C"+column, v.ProductName) |
| | | f.SetCellValue("Sheet1", "D"+column, v.ProductId) |
| | | f.SetCellValue("Sheet1", "E"+column, v.OperationTypeName) |
| | | f.SetCellValue("Sheet1", "F"+column, v.FromLocation) |
| | | f.SetCellValue("Sheet1", "G"+column, v.ToLocation) |
| | | f.SetCellValue("Sheet1", "H"+column, v.Amount) |
| | | FillMoreUnitToExcel(v.AmountMoreUnits, 7, i+3, unitIndexMap, f) |
| | | f.SetCellValue("Sheet1", "L"+column, v.Unit) |
| | | f.SetCellValue("Sheet1", "M"+column, v.Weight) |
| | | row := strconv.Itoa(i + 3) |
| | | f.SetCellValue("Sheet1", "A"+row, v.Date) |
| | | f.SetCellValue("Sheet1", "B"+row, v.Number) |
| | | f.SetCellValue("Sheet1", "C"+row, v.ProductName) |
| | | f.SetCellValue("Sheet1", "D"+row, v.ProductId) |
| | | f.SetCellValue("Sheet1", "E"+row, v.OperationTypeName) |
| | | f.SetCellValue("Sheet1", "F"+row, v.FromLocation) |
| | | f.SetCellValue("Sheet1", "G"+row, v.ToLocation) |
| | | v.AmountMoreUnits = append(v.AmountMoreUnits, models.UnitItems{Amount: v.Amount, Unit: v.Unit}) |
| | | FillMoreUnitToExcel(v.AmountMoreUnits, 8, i+3, unitIndexMap, f) |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(8+len(unitData))+row, v.Unit) |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(9+len(unitData))+row, v.Weight) |
| | | } |
| | | |
| | | if params.BaseOperationType == constvar.BaseOperationTypeIncoming { |
| | |
| | | return |
| | | } |
| | | |
| | | func SetExcelHeader(headers []interface{}, f *excelize.File) (err error) { |
| | | // 设置表头 |
| | | var i int |
| | | for _, h := range headers { |
| | | if v, ok := h.(string); ok { |
| | | err = f.SetCellValue("Sheet1", getColumnAlphabet(i)+"1", v) |
| | | if err != nil { |
| | | return |
| | | } |
| | | i++ |
| | | } else if childHeaders, ok := h.(map[string][]string); ok { |
| | | for title, list := range childHeaders { |
| | | err = f.SetCellValue("Sheet1", getColumnAlphabet(i)+"1", title) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | err = f.MergeCell("Sheet1", getColumnAlphabet(i)+"1", getColumnAlphabet(i-1+len(list))+"1") // 合并单元格 |
| | | for _, t := range list { |
| | | err = f.SetCellValue("Sheet1", getColumnAlphabet(i)+"2", t) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | i++ |
| | | } |
| | | } |
| | | } else { |
| | | return errors.New("unsupported header value") |
| | | } |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func SetHeaderStyle(f *excelize.File) (styleInt int, err error) { |
| | | // 设置表头样式 |
| | | style := &excelize.Style{ |
| | |
| | | i := 1 |
| | | for _, h := range headers { |
| | | if v, ok := h.(string); ok { |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(i)+"1", v) |
| | | err = f.SetCellValue("Sheet1", getColumnAlphabet(i)+"1", v) |
| | | if err != nil { |
| | | return |
| | | } |
| | | i++ |
| | | } else if childHeaders, ok := h.(map[string][]string); ok { |
| | | for title, list := range childHeaders { |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(i)+"1", title) |
| | | err = f.MergeCell("Sheet1", getColumnAlphabet(i)+"1", getColumnAlphabet(i-1+len(list))+"1") // 合并单元格 |
| | | err = f.SetCellValue("Sheet1", getColumnAlphabet(i)+"1", title) |
| | | if err != nil { |
| | | return 1, err |
| | | return |
| | | } |
| | | err = f.MergeCell("Sheet1", getColumnAlphabet(i)+"1", getColumnAlphabet(i-1+len(list))+"1") // 合并单元格 |
| | | for _, t := range list { |
| | | f.SetCellValue("Sheet1", getColumnAlphabet(i)+"2", t) |
| | | err = f.SetCellValue("Sheet1", getColumnAlphabet(i)+"2", t) |
| | | if err != nil { |
| | | return |
| | | } |
| | | i++ |
| | | } |
| | | } |
| | | } else { |
| | | return i, errors.New("unsupported header value") |
| | | } |
| | | } |
| | | return i, nil |
| | |
| | | } |
| | | |
| | | headers, headerLen, inputTypes, outputTypes := slf.GetHeaders() |
| | | err = SetExcelHeader(headers, f) |
| | | _, err = SetExcelHeaders(headers, f) |
| | | if err != nil { |
| | | logx.Errorf("SetExcelHeader err:%v", err) |
| | | return "", err |