1、优化历史汇总(按小时)excel导出接口;

This commit is contained in:
chenlin 2024-12-16 11:35:12 +08:00
parent 16ad7a9b6c
commit 1b2dbab38d

View File

@ -1727,7 +1727,6 @@ func ExportHourSummaryToExcel(data []MgHourSummary, sumData TotalHourSummary, db
// 填充数据
for i, record := range data {
nExcelStartRow += 1
row := i + 2
productName := productMap[record.ProductID] // 获取产品名称
file.SetCellValue(sheet, "A"+strconv.Itoa(row), record.Hour)
@ -1744,9 +1743,7 @@ func ExportHourSummaryToExcel(data []MgHourSummary, sumData TotalHourSummary, db
file.SetCellValue(sheet, "L"+strconv.Itoa(row), record.TotalNewUserUnsubRate)
}
endRow := fmt.Sprintf("L%d", len(data)+1)
// 应用样式到整个表格
_ = file.SetCellStyle(sheet, "A1", endRow, style)
nExcelStartRow += len(data)
totalData := "订单数:" + strconv.FormatInt(int64(len(data)), 10)
end := []interface{}{totalData, "", "",
@ -1761,13 +1758,17 @@ func ExportHourSummaryToExcel(data []MgHourSummary, sumData TotalHourSummary, db
sumData.TotalNewUserUnsubRate,
}
for i, _ := range end {
cell, _ := excelize.CoordinatesToCellName(1+i, nExcelStartRow+2)
cell, _ := excelize.CoordinatesToCellName(1+i, nExcelStartRow+1)
err := file.SetCellValue(sheet, cell, end[i])
if err != nil {
logger.Errorf("file set value err:", err)
}
}
endRow := fmt.Sprintf("L%d", nExcelStartRow+1)
// 应用样式到整个表格
_ = file.SetCellStyle(sheet, "A1", endRow, style)
// 从配置文件读取保存路径和URL前缀
fileName := time.Now().Format("20060102150405") + "_历史汇总按小时.xlsx"
url := MiGuExportUrl + fileName