优化销量同比分析数据处理逻辑
This commit is contained in:
parent
c478e9f43d
commit
a155cb1e01
|
|
@ -403,10 +403,6 @@ func (b *BbxtTools) GetProfitRankingSum(now time.Time) (report *ReportRes, err e
|
||||||
|
|
||||||
// GetStatisOfficialProductSum 销量同比分析
|
// GetStatisOfficialProductSum 销量同比分析
|
||||||
func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []string) (report *ReportRes, err error) {
|
func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []string) (report *ReportRes, err error) {
|
||||||
var productMap = make(map[string]int)
|
|
||||||
for k, v := range productName {
|
|
||||||
productMap[v] = k
|
|
||||||
}
|
|
||||||
ct := []string{
|
ct := []string{
|
||||||
time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Format("2006-01-02 15:04:05"),
|
time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Format("2006-01-02 15:04:05"),
|
||||||
adjustedTime(now),
|
adjustedTime(now),
|
||||||
|
|
@ -428,7 +424,11 @@ func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []str
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var total = make([][]string, 0)
|
|
||||||
|
// 创建临时map存储产品数据
|
||||||
|
productDataMap := make(map[string][]string)
|
||||||
|
var productNamesInResult []string
|
||||||
|
|
||||||
for _, v := range data.OfficialProductSum {
|
for _, v := range data.OfficialProductSum {
|
||||||
var (
|
var (
|
||||||
yeterDatyDiff string
|
yeterDatyDiff string
|
||||||
|
|
@ -444,14 +444,28 @@ func (b *BbxtTools) GetStatisOfficialProductSum(now time.Time, productName []str
|
||||||
} else {
|
} else {
|
||||||
lastWeekDiff = fmt.Sprintf("%s↓%d", GreenStyle, v.HistoryTwoDiff)
|
lastWeekDiff = fmt.Sprintf("%s↓%d", GreenStyle, v.HistoryTwoDiff)
|
||||||
}
|
}
|
||||||
total = append(total, []string{
|
|
||||||
|
rowData := []string{
|
||||||
fmt.Sprintf("%s", v.OfficialProductName),
|
fmt.Sprintf("%s", v.OfficialProductName),
|
||||||
fmt.Sprintf("%d", v.CurrentNum),
|
fmt.Sprintf("%d", v.CurrentNum),
|
||||||
fmt.Sprintf("%d", v.HistoryOneNum),
|
fmt.Sprintf("%d", v.HistoryOneNum),
|
||||||
yeterDatyDiff,
|
yeterDatyDiff,
|
||||||
fmt.Sprintf("%d", v.HistoryTwoNum),
|
fmt.Sprintf("%d", v.HistoryTwoNum),
|
||||||
lastWeekDiff,
|
lastWeekDiff,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
// 存储到map中,key为产品名
|
||||||
|
productDataMap[v.OfficialProductName] = rowData
|
||||||
|
productNamesInResult = append(productNamesInResult, v.OfficialProductName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按照productName的顺序构建total
|
||||||
|
var total [][]string
|
||||||
|
|
||||||
|
for _, name := range productName {
|
||||||
|
if rowData, exists := productDataMap[name]; exists {
|
||||||
|
total = append(total, rowData)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timeCh := now.Format("1月2日15点")
|
timeCh := now.Format("1月2日15点")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue