fix:1.仅分销商导出也使用模板 2.修改分销商、分销商详情模板 3.增加日志
This commit is contained in:
parent
8deb91dea9
commit
37a8318814
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2/log"
|
||||||
"github.com/xuri/excelize/v2"
|
"github.com/xuri/excelize/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -104,12 +105,11 @@ func (b *BbxtTools) StatisOursProductLossSumTotal(ct []string) (err error) {
|
||||||
//总量生成excel
|
//总量生成excel
|
||||||
if len(total) > 0 {
|
if len(total) > 0 {
|
||||||
filePath := b.cacheDir + "/kshj_total" + fmt.Sprintf("%d", time.Now().Unix()) + ".xlsx"
|
filePath := b.cacheDir + "/kshj_total" + fmt.Sprintf("%d", time.Now().Unix()) + ".xlsx"
|
||||||
err = b.SimpleFillExcel(b.excelTempDir+"/"+"kshj_total_v2.xlsx", filePath, total)
|
err = b.SimpleFillExcel(b.excelTempDir+"/"+"kshj_total.xlsx", filePath, total)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(gt) > 0 {
|
if len(gt) > 0 {
|
||||||
filePath := b.cacheDir + "/kshj_gt" + fmt.Sprintf("%d", time.Now().Unix()) + ".xlsx"
|
filePath := b.cacheDir + "/kshj_gt" + fmt.Sprintf("%d", time.Now().Unix()) + ".xlsx"
|
||||||
// err = b.SimpleFillExcel(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, total)
|
|
||||||
err = b.resellerDetailFillExcel(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, gt)
|
err = b.resellerDetailFillExcel(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, gt)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
@ -126,6 +126,20 @@ func (b *BbxtTools) SimpleFillExcel(templatePath, outputPath string, dataSlice i
|
||||||
|
|
||||||
sheet := f.GetSheetName(0)
|
sheet := f.GetSheetName(0)
|
||||||
|
|
||||||
|
// 1.1 获取第二行模板样式
|
||||||
|
resellerTplRow := 2
|
||||||
|
styleIDReseller, err := f.GetCellStyle(sheet, fmt.Sprintf("A%d", resellerTplRow))
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("获取分销商总计样式失败: %v", err)
|
||||||
|
styleIDReseller = 0
|
||||||
|
}
|
||||||
|
// 1.2 获取分销商总计行高
|
||||||
|
rowHeightReseller, err := f.GetRowHeight(sheet, resellerTplRow)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("获取分销商总计行高失败: %v", err)
|
||||||
|
rowHeightReseller = 31 // 默认高度
|
||||||
|
}
|
||||||
|
|
||||||
// 2. 反射获取切片数据
|
// 2. 反射获取切片数据
|
||||||
v := reflect.ValueOf(dataSlice)
|
v := reflect.ValueOf(dataSlice)
|
||||||
if v.Kind() != reflect.Slice {
|
if v.Kind() != reflect.Slice {
|
||||||
|
|
@ -157,12 +171,19 @@ func (b *BbxtTools) SimpleFillExcel(templatePath, outputPath string, dataSlice i
|
||||||
} else {
|
} else {
|
||||||
rowData = []interface{}{item}
|
rowData = []interface{}{item}
|
||||||
}
|
}
|
||||||
|
// 4.1 设置行高
|
||||||
|
f.SetRowHeight(sheet, currentRow, rowHeightReseller)
|
||||||
|
|
||||||
// 5. 填充到Excel
|
// 5. 填充到Excel
|
||||||
for col, value := range rowData {
|
for col, value := range rowData {
|
||||||
cell := fmt.Sprintf("%c%d", 'A'+col, currentRow)
|
cell := fmt.Sprintf("%c%d", 'A'+col, currentRow)
|
||||||
f.SetCellValue(sheet, cell, value)
|
f.SetCellValue(sheet, cell, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5.1 使用第二行模板样式
|
||||||
|
if styleIDReseller != 0 {
|
||||||
|
f.SetCellStyle(sheet, fmt.Sprintf("A%d", currentRow), fmt.Sprintf("B%d", currentRow), styleIDReseller)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. 保存
|
// 6. 保存
|
||||||
|
|
@ -188,22 +209,24 @@ func (b *BbxtTools) resellerDetailFillExcel(templatePath, outputPath string, dat
|
||||||
resellerTplRow := 2
|
resellerTplRow := 2
|
||||||
styleIDReseller, err := f.GetCellStyle(sheet, fmt.Sprintf("A%d", resellerTplRow))
|
styleIDReseller, err := f.GetCellStyle(sheet, fmt.Sprintf("A%d", resellerTplRow))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 如果获取失败,就不应用样式,或者记录日志,这里选择忽略错误继续
|
log.Errorf("获取分销商总计样式失败: %v", err)
|
||||||
styleIDReseller = 0
|
styleIDReseller = 0
|
||||||
}
|
}
|
||||||
rowHeightReseller, err := f.GetRowHeight(sheet, resellerTplRow)
|
rowHeightReseller, err := f.GetRowHeight(sheet, resellerTplRow)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("获取分销商总计行高失败: %v", err)
|
||||||
rowHeightReseller = 31 // 默认高度
|
rowHeightReseller = 31 // 默认高度
|
||||||
}
|
}
|
||||||
// 获取模板样式2:第三行-产品亏损明细
|
// 获取模板样式2:第三行-产品亏损明细
|
||||||
productTplRow := 3
|
productTplRow := 3
|
||||||
styleIDProduct, err := f.GetCellStyle(sheet, fmt.Sprintf("A%d", productTplRow))
|
styleIDProduct, err := f.GetCellStyle(sheet, fmt.Sprintf("A%d", productTplRow))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 如果获取失败,就不应用样式,或者记录日志,这里选择忽略错误继续
|
log.Errorf("获取商品详情样式失败: %v", err)
|
||||||
styleIDProduct = 0
|
styleIDProduct = 0
|
||||||
}
|
}
|
||||||
rowHeightProduct, err := f.GetRowHeight(sheet, productTplRow)
|
rowHeightProduct, err := f.GetRowHeight(sheet, productTplRow)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("获取商品详情行高失败: %v", err)
|
||||||
rowHeightProduct = 25 // 默认高度
|
rowHeightProduct = 25 // 默认高度
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue