京西和平台商品对比-加入数据分析Sheet

This commit is contained in:
Rosy-zhudan
2019-08-16 18:34:21 +08:00
parent 9b09fc9cae
commit 353b187edb

View File

@@ -5,7 +5,6 @@ import (
"strings"
"sync"
"time"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
@@ -19,8 +18,9 @@ import (
)
const (
canWriteTolocal = false
isFilterToBeCreateAndNotSale = !false
canWriteTolocal = !false
needStatistic = true
isFilterToBeCreateAndNotSale = true
parallelCount = 5
fileExt = ".xlsx"
)
@@ -48,7 +48,26 @@ var (
"京西可售状态",
"平台可售状态",
}
statisticTitleList = []string{
"京西和平台商品状态",
"待创建",
"京西可售状态",
"数量",
"占比",
}
statisticDataList = [][]string{
{"京西有,平台无", "是", "下架"},
{"京西有,平台无", "是", "上架"},
{"京西有,平台无", "否", "下架"},
{"京西有,平台无", "否", "上架"},
{"京西无,平台有", "N/A", "N/A"},
{"京西有,平台有", "是", "下架"},
{"京西有,平台有", "是", "上架"},
{"京西有,平台有", "否", "下架"},
{"京西有,平台有", "否", "上架"},
}
diffData DiffDataLock
multiStoreAllSkuInfoMap map[int]map[int]*partner.SkuNameInfo
@@ -74,6 +93,14 @@ type DiffData struct {
VendorStatus string `json:"平台可售状态"`
}
type StatisticData struct {
JxVendorStatus string `json:"京西和平台商品状态"`
ToBeCreate string `json:"待创建"`
JxSaleStatus string `json:"京西可售状态"`
Count string `json:"数量"`
Percent string `json:"占比"`
}
func (d *DiffDataLock) AppendData(vendorID int, diffData DiffData) {
d.locker.Lock()
defer d.locker.Unlock()
@@ -365,6 +392,63 @@ func IsJXCS() bool {
return globals.IsMainProductEnv()
}
func AddStatisticSheet(sheetName string, data []DiffData) (sheet *excel.Obj2ExcelSheetConfig) {
statisticData := make([]StatisticData, 9)
var count [9]int
var percent [9]float32
totalCount := len(data)
for _, rowData := range data {
if rowData.JxSkuName != "" && rowData.VendorSkuName == "" {
if rowData.ToBeCreate == "是" {
if rowData.JxStatus == "下架" {
count[0]++
} else if rowData.JxStatus == "上架" {
count[1]++
}
} else if rowData.ToBeCreate == "否" {
if rowData.JxStatus == "下架" {
count[2]++
} else if rowData.JxStatus == "上架" {
count[3]++
}
}
} else if rowData.JxSkuName == "" && rowData.VendorSkuName != "" {
if rowData.ToBeCreate == "" && rowData.JxStatus == "" {
count[4]++
}
} else if rowData.JxSkuName != "" && rowData.VendorSkuName != "" {
if rowData.ToBeCreate == "是" {
if rowData.JxStatus == "下架" {
count[5]++
} else if rowData.JxStatus == "上架" {
count[6]++
}
} else if rowData.ToBeCreate == "否" {
if rowData.JxStatus == "下架" {
count[7]++
} else if rowData.JxStatus == "上架" {
count[8]++
}
}
}
}
for index, value := range count {
percent[index] = float32(value * 100) / float32(totalCount)
countStr := utils.Int2Str(value)
percentStr := fmt.Sprintf("%.2f%%", percent[index])
subStatisticData := statisticDataList[index]
statisticData[index] = StatisticData{subStatisticData[0], subStatisticData[1], subStatisticData[2], countStr, percentStr}
}
sheetName = sheetName + "统计"
sheet = &excel.Obj2ExcelSheetConfig {
Title: sheetName,
Data: statisticData,
CaptionList: statisticTitleList,
}
return sheet
}
func WriteToExcel(task *tasksch.SeqTask, data map[int][]DiffData) {
var sheetList []*excel.Obj2ExcelSheetConfig
for key, value := range data {
@@ -375,8 +459,13 @@ func WriteToExcel(task *tasksch.SeqTask, data map[int][]DiffData) {
CaptionList: titleList,
}
sheetList = append(sheetList, excelConf)
if needStatistic {
statisticSheet := AddStatisticSheet(sheetName, value)
sheetList = append(sheetList, statisticSheet)
}
baseapi.SugarLogger.Debugf("WriteToExcel:append:%s count:%d", sheetName, len(value))
}
if len(sheetList) > 0 {
excelBin := excel.Obj2Excel(sheetList)
timeStr := utils.Int64ToStr(time.Now().Unix())