fix: 优化销售下滑数据处理和排序逻辑
This commit is contained in:
parent
e695029238
commit
16c113398a
|
|
@ -18,7 +18,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
DownWardValue int32 = 1000
|
||||
DownWardValue int32 = 1500
|
||||
SumFilter int32 = -150
|
||||
)
|
||||
|
||||
|
|
@ -53,11 +53,6 @@ func NewBbxtTools() (*BbxtTools, error) {
|
|||
|
||||
func (b *BbxtTools) DailyReport(now time.Time, downWardValue int32, productName []string, sumFilter int32, ossClient *utils_oss.Client) (reports []*ReportRes, err error) {
|
||||
reports = make([]*ReportRes, 0, 4)
|
||||
statisOfficialProductSumDecline, err := b.GetStatisOfficialProductSumDecline(now, downWardValue, productName, sumFilter)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
productLossReport, err := b.StatisOursProductLossSum(now)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -70,7 +65,10 @@ func (b *BbxtTools) DailyReport(now time.Time, downWardValue int32, productName
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
statisOfficialProductSumDecline, err := b.GetStatisOfficialProductSumDecline(now, downWardValue, productName, sumFilter)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
reports = append(reports, productLossReport...)
|
||||
reports = append(reports, profitRankingSum, statisOfficialProductSum, statisOfficialProductSumDecline)
|
||||
|
||||
|
|
@ -357,19 +355,20 @@ func (b *BbxtTools) GetStatisOfficialProductSumDecline(now time.Time, downWardVa
|
|||
return
|
||||
}
|
||||
var (
|
||||
productSumMap = make(map[int32]ProductSumDecline)
|
||||
productSumMap = make(map[string]ProductSumDecline)
|
||||
)
|
||||
for _, v := range data.OfficialProductSumDecline {
|
||||
if _, ex := productSumMap[v.OfficialProductId]; !ex {
|
||||
productSumMap[v.OfficialProductId] = ProductSumDecline{
|
||||
if _, ex := productSumMap[v.OfficialProductName]; !ex {
|
||||
productSumMap[v.OfficialProductName] = ProductSumDecline{
|
||||
OfficialProductName: v.OfficialProductName,
|
||||
OfficialProductId: v.OfficialProductId,
|
||||
ProductSumReseller: make(map[int32]ProductSumReseller),
|
||||
Index: productMap[v.OfficialProductName],
|
||||
}
|
||||
|
||||
}
|
||||
if v.HistoryOneDiff <= sumFilter || v.HistoryTwoDiff <= sumFilter {
|
||||
productSumMap[v.OfficialProductId].ProductSumReseller[v.ResellerId] = ProductSumReseller{
|
||||
productSumMap[v.OfficialProductName].ProductSumReseller[v.ResellerId] = ProductSumReseller{
|
||||
ResellerName: v.ResellerName,
|
||||
CurrentNum: v.CurrentNum,
|
||||
HistoryOneNum: v.HistoryOneNum,
|
||||
|
|
@ -378,8 +377,14 @@ func (b *BbxtTools) GetStatisOfficialProductSumDecline(now time.Time, downWardVa
|
|||
HistoryTwoDiff: v.HistoryTwoDiff,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
var total = make([]ProductSumDecline, 0, len(productSumMap))
|
||||
for k, _ := range productSumMap {
|
||||
total = append(total, productSumMap[k])
|
||||
}
|
||||
sort.Slice(total, func(i, j int) bool {
|
||||
return total[i].Index > total[j].Index
|
||||
})
|
||||
timeCh := now.Format("1月2日15点")
|
||||
//title := "截至" + timeCh + "销量下滑大于" + fmt.Sprintf("%d", downWardValue) + "明细,分销商仅展示差额大于" + fmt.Sprintf("%d", -sumFilter)
|
||||
title := "截至" + timeCh + "销量下滑较大商品"
|
||||
|
|
@ -388,7 +393,7 @@ func (b *BbxtTools) GetStatisOfficialProductSumDecline(now time.Time, downWardVa
|
|||
return
|
||||
}
|
||||
filePath := b.cacheDir + "/xlxhmx" + fmt.Sprintf("%d%d", time.Now().Unix(), rand.Intn(1000)) + ".xlsx"
|
||||
err = b.OfficialProductSumDeclineExcel(b.excelTempDir+"/"+"/xlxhmx.xlsx", filePath, productSumMap, title)
|
||||
err = b.OfficialProductSumDeclineExcel(b.excelTempDir+"/"+"/xlxhmx.xlsx", filePath, total, title)
|
||||
return &ReportRes{
|
||||
ReportName: "销售下滑明细",
|
||||
Title: title,
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ type ProductSumDecline struct {
|
|||
OfficialProductId int32
|
||||
OfficialProductName string
|
||||
ProductSumReseller map[int32]ProductSumReseller
|
||||
Index int
|
||||
}
|
||||
|
||||
type ProductSumReseller struct {
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ func (u *Uploader) uploadToOSS(fileName string, fileBytes []byte) string {
|
|||
// return url
|
||||
//}
|
||||
|
||||
func (b *BbxtTools) OfficialProductSumDeclineExcel(templatePath, outputPath string, sumMap map[int32]ProductSumDecline, title string) error {
|
||||
func (b *BbxtTools) OfficialProductSumDeclineExcel(templatePath, outputPath string, sumSlice []ProductSumDecline, title string) error {
|
||||
// 1. 读取模板
|
||||
f, err := excelize.OpenFile(templatePath)
|
||||
if err != nil {
|
||||
|
|
@ -227,7 +227,7 @@ func (b *BbxtTools) OfficialProductSumDeclineExcel(templatePath, outputPath stri
|
|||
currentRow := 3
|
||||
pattern := `\$\{(.*?)\}`
|
||||
re := regexp.MustCompile(pattern)
|
||||
for _, product := range sumMap {
|
||||
for _, product := range sumSlice {
|
||||
// 排序 ProductLoss
|
||||
var reseller []ProductSumReseller
|
||||
for _, p := range product.ProductSumReseller {
|
||||
|
|
|
|||
Loading…
Reference in New Issue