refactor: 优化报表生成逻辑和配置更新
This commit is contained in:
parent
a7c9d7ed3b
commit
4e804a4c52
|
|
@ -26,12 +26,11 @@ coze:
|
||||||
|
|
||||||
lsxd:
|
lsxd:
|
||||||
# 统一登录
|
# 统一登录
|
||||||
login_url: "http://api.test.user.1688sup.com/v1/login/phone"
|
login_url: "https://api.user.1688sup.com/v1/login/phone"
|
||||||
phone: "OFJ8UpqOlI7+w3Qklf36ZA=="
|
phone: "ORlviZN7N06W2+WKLe76xg=="
|
||||||
password: "tEbFegH/DRRh6LutFb7o3g=="
|
password: "V5Uh8C4bamEM6UQZh4TCeQ=="
|
||||||
code: "123456"
|
code: "456789"
|
||||||
check_token_url: "http://api.test.user.1688sup.com/v1/user/welcome"
|
check_token_url: "https://api.user.1688sup.com/v1/user/welcome"
|
||||||
|
|
||||||
|
|
||||||
sys:
|
sys:
|
||||||
session_len: 6
|
session_len: 6
|
||||||
|
|
@ -142,7 +141,7 @@ eino_tools:
|
||||||
# == 通用工具 ==
|
# == 通用工具 ==
|
||||||
# 表格转图片
|
# 表格转图片
|
||||||
excel2pic:
|
excel2pic:
|
||||||
base_url: "http://192.168.6.109:8010/api/v1/convert"
|
base_url: "http://192.168.6.115:8010/api/v1/convert"
|
||||||
|
|
||||||
dingtalk:
|
dingtalk:
|
||||||
api_key: "dingsbbntrkeiyazcfdg"
|
api_key: "dingsbbntrkeiyazcfdg"
|
||||||
|
|
|
||||||
|
|
@ -98,13 +98,11 @@ func (g *GroupConfigBiz) GetReportLists(ctx context.Context, groupConfig *model.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//追加电商充值系统统计 - 返回统一使用[]*bbxt.ReportRes
|
//追加电商充值系统统计 - 返回统一使用[]*bbxt.ReportRes
|
||||||
rechargeReports, err := g.rechargeDailyReport(ctx, time.Now(), nil, g.ossClient)
|
rechargeReports, err := g.rechargeDailyReport(ctx, time.Now(), nil, g.ossClient)
|
||||||
if err != nil || len(rechargeReports) == 0 {
|
if err != nil || len(rechargeReports) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
reports = append(reports, rechargeReports...)
|
reports = append(reports, rechargeReports...)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -175,7 +173,7 @@ func (g *GroupConfigBiz) handleReport(ctx context.Context, rec *entitys.Recogniz
|
||||||
if _err != nil {
|
if _err != nil {
|
||||||
return _err
|
return _err
|
||||||
}
|
}
|
||||||
reports = append(reports, repo...)
|
reports = append(reports, repo)
|
||||||
case "report_sales_analysis":
|
case "report_sales_analysis":
|
||||||
product := strings.Split(groupConfig.ProductName, ",")
|
product := strings.Split(groupConfig.ProductName, ",")
|
||||||
repo, _err := rep.GetStatisOfficialProductSum(t, product)
|
repo, _err := rep.GetStatisOfficialProductSum(t, product)
|
||||||
|
|
@ -200,8 +198,9 @@ func (g *GroupConfigBiz) handleReport(ctx context.Context, rec *entitys.Recogniz
|
||||||
if _err != nil {
|
if _err != nil {
|
||||||
return _err
|
return _err
|
||||||
}
|
}
|
||||||
reports = append(reports, repo...)
|
|
||||||
reports = append(reports, rechargeReport...)
|
reports = append(reports, rechargeReport...)
|
||||||
|
reports = append(reports, repo...)
|
||||||
|
|
||||||
case "report_daily_recharge":
|
case "report_daily_recharge":
|
||||||
product := strings.Split(groupConfig.ProductName, ",")
|
product := strings.Split(groupConfig.ProductName, ",")
|
||||||
repo, _err := g.rechargeDailyReport(ctx, t, product, nil)
|
repo, _err := g.rechargeDailyReport(ctx, t, product, nil)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -91,9 +93,7 @@ func (b *BbxtTools) DailyReport(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
reports = append(reports, productLossReport...)
|
reports = append(reports, profitRankingSum, statisOfficialProductSum, statisOfficialProductSumDecline, productLossReport)
|
||||||
reports = append(reports, profitRankingSum, statisOfficialProductSum, statisOfficialProductSumDecline)
|
|
||||||
|
|
||||||
if ossClient != nil {
|
if ossClient != nil {
|
||||||
uploader := NewUploader(ossClient, b.config)
|
uploader := NewUploader(ossClient, b.config)
|
||||||
for _, report := range reports {
|
for _, report := range reports {
|
||||||
|
|
@ -135,7 +135,9 @@ func (b *BbxtTools) ResellerLossSort(ctx context.Context, now time.Time) ([]*Res
|
||||||
reseller := resellerMap[info.ResellerId]
|
reseller := resellerMap[info.ResellerId]
|
||||||
|
|
||||||
// 累加经销商总亏损
|
// 累加经销商总亏损
|
||||||
reseller.Total += info.Loss
|
num1 := decimal.NewFromFloat(reseller.Total)
|
||||||
|
num2 := decimal.NewFromFloat(info.Loss)
|
||||||
|
reseller.Total, _ = num1.Add(num2).Round(2).Float64()
|
||||||
|
|
||||||
// 检查产品是否已存在
|
// 检查产品是否已存在
|
||||||
if _, ok := reseller.ProductLoss[info.OursProductId]; !ok {
|
if _, ok := reseller.ProductLoss[info.OursProductId]; !ok {
|
||||||
|
|
@ -209,14 +211,14 @@ func (b *BbxtTools) ResellerLossToMapResellerLossSumProductRelation(totalDetail
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatisOursProductLossSum 负利润分析
|
// StatisOursProductLossSum 负利润分析
|
||||||
func (b *BbxtTools) StatisOursProductLossSum(ctx context.Context, now time.Time, initFunc LossSumInitFunc) (report []*ReportRes, err error) {
|
func (b *BbxtTools) StatisOursProductLossSum(ctx context.Context, now time.Time, initFunc LossSumInitFunc) (report *ReportRes, err error) {
|
||||||
resellers, err := b.ResellerLossSort(ctx, now)
|
resellers, err := b.ResellerLossSort(ctx, now)
|
||||||
var (
|
var (
|
||||||
total [][]string
|
total [][]string
|
||||||
gt []*ResellerLoss
|
//gt []*ResellerLoss
|
||||||
totalDetail []*ResellerLoss
|
totalDetail []*ResellerLoss
|
||||||
totalSum float64
|
totalSum = decimal.NewFromFloat(0)
|
||||||
totalSum500 float64
|
//totalSum500 float64
|
||||||
)
|
)
|
||||||
// 构建分组
|
// 构建分组
|
||||||
for _, v := range resellers {
|
for _, v := range resellers {
|
||||||
|
|
@ -225,45 +227,46 @@ func (b *BbxtTools) StatisOursProductLossSum(ctx context.Context, now time.Time,
|
||||||
fmt.Sprintf("%s", v.ResellerName),
|
fmt.Sprintf("%s", v.ResellerName),
|
||||||
fmt.Sprintf("%.2f", v.Total),
|
fmt.Sprintf("%.2f", v.Total),
|
||||||
})
|
})
|
||||||
totalSum += v.Total
|
num := decimal.NewFromFloat(v.Total)
|
||||||
|
totalSum = totalSum.Add(num).Round(2)
|
||||||
totalDetail = append(totalDetail, v)
|
totalDetail = append(totalDetail, v)
|
||||||
}
|
}
|
||||||
if v.Total <= -500 && !slices.Contains(ResellerBlackListProduct, v.ResellerName) {
|
//if v.Total <= -500 && !slices.Contains(ResellerBlackListProduct, v.ResellerName) {
|
||||||
gt = append(gt, v)
|
// gt = append(gt, v)
|
||||||
totalSum500 += v.Total
|
// totalSum500 += v.Total
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
report = make([]*ReportRes, 3)
|
//report = make([]*ReportRes, 3)
|
||||||
timeCh := now.Format("1月2日15点")
|
timeCh := now.Format("1月2日15点")
|
||||||
//总量生成excel
|
//总量生成excel
|
||||||
if len(total) > 0 {
|
//if len(total) > 0 {
|
||||||
filePath := b.cacheDir + "/kshj_total" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
|
// filePath := b.cacheDir + "/kshj_total" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
|
||||||
err = b.SimpleFillExcelWithTitle(b.excelTempDir+"/"+"kshj_total.xlsx", filePath, total, "")
|
// err = b.SimpleFillExcelWithTitle(b.excelTempDir+"/"+"kshj_total.xlsx", filePath, total, "")
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
report[0] = &ReportRes{
|
// report[0] = &ReportRes{
|
||||||
ReportName: "分销商负利润统计",
|
// ReportName: "分销商负利润统计",
|
||||||
Title: "截至" + timeCh + "利润累计亏损" + fmt.Sprintf("%.2f", totalSum),
|
// Title: "截至" + timeCh + "利润累计亏损" + fmt.Sprintf("%.2f", totalSum),
|
||||||
Path: filePath,
|
// Path: filePath,
|
||||||
Data: total,
|
// Data: total,
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
if len(gt) > 0 {
|
//if len(gt) > 0 {
|
||||||
filePath := b.cacheDir + "/kshj_gt" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
|
// filePath := b.cacheDir + "/kshj_gt" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
|
||||||
title := "截至" + timeCh + "亏损500以上的分销商和产品"
|
// title := "截至" + timeCh + "亏损500以上的分销商和产品"
|
||||||
err = b.resellerDetailFillExcelV2(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, gt, title)
|
// err = b.resellerDetailFillExcelV2(b.excelTempDir+"/"+"kshj_gt.xlsx", filePath, gt, title)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
report[1] = &ReportRes{
|
// report[1] = &ReportRes{
|
||||||
ReportName: "负利润分析(亏损500以上)",
|
// ReportName: "负利润分析(亏损500以上)",
|
||||||
Title: "截至" + timeCh + "亏损500以上利润累计亏损" + fmt.Sprintf("%.2f", totalSum500),
|
// Title: "截至" + timeCh + "亏损500以上利润累计亏损" + fmt.Sprintf("%.2f", totalSum500),
|
||||||
Path: filePath,
|
// Path: filePath,
|
||||||
Data: total,
|
// Data: total,
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
if len(totalDetail) > 0 {
|
if len(totalDetail) > 0 {
|
||||||
err = initFunc(ctx, now, totalDetail, b)
|
err = initFunc(ctx, now, totalDetail, b)
|
||||||
|
|
@ -271,14 +274,15 @@ func (b *BbxtTools) StatisOursProductLossSum(ctx context.Context, now time.Time,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
filePath := b.cacheDir + "/kshj_total_ana" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
|
filePath := b.cacheDir + "/kshj_total_ana" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
|
||||||
title := "截至" + timeCh + "亏损100以上的分销商&产品负利润原因"
|
totalSumFloat64, _ := totalSum.Float64()
|
||||||
|
title := "截至" + timeCh + "利润累计亏损" + fmt.Sprintf("%.2f", totalSumFloat64) + ",亏损100以上利润原因如下"
|
||||||
err = b.resellerDetailFillExcelAna(b.excelTempDir+"/"+"kshj_total_ana.xlsx", filePath, totalDetail, title)
|
err = b.resellerDetailFillExcelAna(b.excelTempDir+"/"+"kshj_total_ana.xlsx", filePath, totalDetail, title)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
report[2] = &ReportRes{
|
report = &ReportRes{
|
||||||
ReportName: "负利润分析(亏损100以上)",
|
ReportName: "负利润分析(亏损100以上)",
|
||||||
Title: "截至" + timeCh + "亏损100以上利润原因",
|
Title: title,
|
||||||
Path: filePath,
|
Path: filePath,
|
||||||
Data: total,
|
Data: total,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -343,14 +343,17 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
||||||
|
|
||||||
styleD3, err := f.GetCellStyle(sheet, fmt.Sprintf("D%d", tplRowData))
|
styleD3, err := f.GetCellStyle(sheet, fmt.Sprintf("D%d", tplRowData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
styleC3 = 0
|
styleD3 = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
styleE3, err := f.GetCellStyle(sheet, fmt.Sprintf("E%d", tplRowData))
|
styleE3, err := f.GetCellStyle(sheet, fmt.Sprintf("E%d", tplRowData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
styleC3 = 0
|
styleE3 = 0
|
||||||
|
}
|
||||||
|
styleF3, err := f.GetCellStyle(sheet, fmt.Sprintf("F%d", tplRowData))
|
||||||
|
if err != nil {
|
||||||
|
styleF3 = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
rowHeightData, err := f.GetRowHeight(sheet, tplRowData)
|
rowHeightData, err := f.GetRowHeight(sheet, tplRowData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
rowHeightData = 20
|
rowHeightData = 20
|
||||||
|
|
@ -372,11 +375,15 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
||||||
}
|
}
|
||||||
styleTotalD, err := f.GetCellStyle(sheet, fmt.Sprintf("D%d", tplRowTotal))
|
styleTotalD, err := f.GetCellStyle(sheet, fmt.Sprintf("D%d", tplRowTotal))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
styleTotalC = 0
|
styleTotalD = 0
|
||||||
}
|
}
|
||||||
styleTotalE, err := f.GetCellStyle(sheet, fmt.Sprintf("E%d", tplRowTotal))
|
styleTotalE, err := f.GetCellStyle(sheet, fmt.Sprintf("E%d", tplRowTotal))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
styleTotalC = 0
|
styleTotalE = 0
|
||||||
|
}
|
||||||
|
styleTotalF, err := f.GetCellStyle(sheet, fmt.Sprintf("F%d", tplRowTotal))
|
||||||
|
if err != nil {
|
||||||
|
styleTotalF = 0
|
||||||
}
|
}
|
||||||
rowHeightTotal, err := f.GetRowHeight(sheet, tplRowTotal)
|
rowHeightTotal, err := f.GetRowHeight(sheet, tplRowTotal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -408,8 +415,9 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
||||||
f.SetCellValue(sheet, fmt.Sprintf("A%d", currentRow), reseller.ResellerName)
|
f.SetCellValue(sheet, fmt.Sprintf("A%d", currentRow), reseller.ResellerName)
|
||||||
f.SetCellValue(sheet, fmt.Sprintf("B%d", currentRow), p.ProductName)
|
f.SetCellValue(sheet, fmt.Sprintf("B%d", currentRow), p.ProductName)
|
||||||
f.SetCellValue(sheet, fmt.Sprintf("C%d", currentRow), p.Loss)
|
f.SetCellValue(sheet, fmt.Sprintf("C%d", currentRow), p.Loss)
|
||||||
f.SetCellValue(sheet, fmt.Sprintf("D%d", currentRow), reseller.Manager)
|
f.SetCellValue(sheet, fmt.Sprintf("D%d", currentRow), reseller.Total)
|
||||||
f.SetCellValue(sheet, fmt.Sprintf("E%d", currentRow), p.LossReason)
|
f.SetCellValue(sheet, fmt.Sprintf("E%d", currentRow), reseller.Manager)
|
||||||
|
f.SetCellValue(sheet, fmt.Sprintf("F%d", currentRow), p.LossReason)
|
||||||
// 设置样式
|
// 设置样式
|
||||||
if styleA3 != 0 {
|
if styleA3 != 0 {
|
||||||
f.SetCellStyle(sheet, fmt.Sprintf("A%d", currentRow), fmt.Sprintf("A%d", currentRow), styleA3)
|
f.SetCellStyle(sheet, fmt.Sprintf("A%d", currentRow), fmt.Sprintf("A%d", currentRow), styleA3)
|
||||||
|
|
@ -426,7 +434,9 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
||||||
if styleE3 != 0 {
|
if styleE3 != 0 {
|
||||||
f.SetCellStyle(sheet, fmt.Sprintf("E%d", currentRow), fmt.Sprintf("E%d", currentRow), styleE3)
|
f.SetCellStyle(sheet, fmt.Sprintf("E%d", currentRow), fmt.Sprintf("E%d", currentRow), styleE3)
|
||||||
}
|
}
|
||||||
|
if styleF3 != 0 {
|
||||||
|
f.SetCellStyle(sheet, fmt.Sprintf("F%d", currentRow), fmt.Sprintf("F%d", currentRow), styleF3)
|
||||||
|
}
|
||||||
totalLoss += p.Loss
|
totalLoss += p.Loss
|
||||||
currentRow++
|
currentRow++
|
||||||
}
|
}
|
||||||
|
|
@ -436,6 +446,7 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
||||||
if endRow > startRow {
|
if endRow > startRow {
|
||||||
f.MergeCell(sheet, fmt.Sprintf("A%d", startRow), fmt.Sprintf("A%d", endRow))
|
f.MergeCell(sheet, fmt.Sprintf("A%d", startRow), fmt.Sprintf("A%d", endRow))
|
||||||
f.MergeCell(sheet, fmt.Sprintf("D%d", startRow), fmt.Sprintf("D%d", endRow))
|
f.MergeCell(sheet, fmt.Sprintf("D%d", startRow), fmt.Sprintf("D%d", endRow))
|
||||||
|
f.MergeCell(sheet, fmt.Sprintf("E%d", startRow), fmt.Sprintf("E%d", endRow))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -447,7 +458,7 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
||||||
|
|
||||||
f.SetCellValue(sheet, fmt.Sprintf("A%d", currentRow), "合计")
|
f.SetCellValue(sheet, fmt.Sprintf("A%d", currentRow), "合计")
|
||||||
// B列留空,C列填充总亏损
|
// B列留空,C列填充总亏损
|
||||||
f.SetCellValue(sheet, fmt.Sprintf("C%d", currentRow), totalLoss)
|
f.SetCellValue(sheet, fmt.Sprintf("D%d", currentRow), totalLoss)
|
||||||
|
|
||||||
// 设置合计行样式
|
// 设置合计行样式
|
||||||
if styleTotalA != 0 {
|
if styleTotalA != 0 {
|
||||||
|
|
@ -465,7 +476,9 @@ func (b *BbxtTools) resellerDetailFillExcelAna(templatePath, outputPath string,
|
||||||
if styleTotalE != 0 {
|
if styleTotalE != 0 {
|
||||||
f.SetCellStyle(sheet, fmt.Sprintf("E%d", currentRow), fmt.Sprintf("E%d", currentRow), styleTotalE)
|
f.SetCellStyle(sheet, fmt.Sprintf("E%d", currentRow), fmt.Sprintf("E%d", currentRow), styleTotalE)
|
||||||
}
|
}
|
||||||
|
if styleTotalF != 0 {
|
||||||
|
f.SetCellStyle(sheet, fmt.Sprintf("F%d", currentRow), fmt.Sprintf("F%d", currentRow), styleTotalF)
|
||||||
|
}
|
||||||
// 取消合并合计行的A、B列
|
// 取消合并合计行的A、B列
|
||||||
// f.MergeCell(sheet, fmt.Sprintf("A%d", currentRow), fmt.Sprintf("B%d", currentRow))
|
// f.MergeCell(sheet, fmt.Sprintf("A%d", currentRow), fmt.Sprintf("B%d", currentRow))
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Reference in New Issue