价格统计

This commit is contained in:
苏尹岚
2019-12-30 17:08:17 +08:00
parent e82d9851de
commit 2548908b68
5 changed files with 79 additions and 44 deletions

View File

@@ -2247,9 +2247,9 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam
}
for _, v := range skuNameAndPlace {
if skuNameMap[v.ID] != nil {
midPrice, _ := dao.GetMidPriceByNameID(db, cityCode, v.ID, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
if midPrice != 0 {
v.Price = midPrice
priceReferList, _, _ := dao.GetPriceReferSnapshot(db, []int{cityCode}, nil, v.ID, utils.Time2Date(time.Now().AddDate(0, 0, -1)), 0, 9999)
if len(priceReferList) > 0 {
v.Price = priceReferList[0].MidUnitPrice
}
v.Type = skuNameMap[v.ID].BrandID
skuNameAndPlaceList = append(skuNameAndPlaceList, v)
@@ -2813,7 +2813,7 @@ func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync,
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, v.NameID, model.StoreSkuBindStatusNormal)
//有关注过
if len(focusList) > 0 {
price = 0
price = focusList[0].UnitPrice
skuInfoMap[v.NameID] = append(skuInfoMap[v.NameID], &StoreSkuBindSkuInfo{
SkuID: v.ID,
IsSale: 1,
@@ -2920,10 +2920,12 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContin
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, k, model.StoreSkuBindStatusNormal)
//有关注过
if len(focusList) > 0 {
price = 0
price = focusList[0].UnitPrice
} else {
midPrice, _ := dao.GetMidPriceByNameID(db, store.CityCode, k, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
price = midPrice
priceReferList, _, _ := dao.GetPriceReferSnapshot(db, []int{store.CityCode}, nil, k, utils.Time2Date(time.Now().AddDate(0, 0, -1)), 0, 9999)
if len(priceReferList) > 0 {
price = priceReferList[0].MidUnitPrice
}
}
skuBindInfo := &StoreSkuBindInfo{
NameID: k,

View File

@@ -6,7 +6,7 @@ import (
"math"
"time"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
@@ -44,7 +44,7 @@ func StatisticsReportForStoreSkusPrice(ctx *jxcontext.Context, cityCodes, skuIDs
if snapDate != "" {
snapDateParam = utils.Str2Time(snapDate)
}
priceReferSnapshot, totalCount, err := dao.GetPriceReferSnapshot(db, cityCodes, skuIDs, snapDateParam, offset, pageSize)
priceReferSnapshot, totalCount, err := dao.GetPriceReferSnapshot(db, cityCodes, skuIDs, 0, snapDateParam, offset, pageSize)
pagedInfo = &model.PagedInfo{
Data: priceReferSnapshot,
TotalCount: totalCount,
@@ -70,15 +70,23 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err e
priceReferSnapshotDelete := &model.PriceReferSnapshot{SnapshotAt: snapshotAt}
dao.DeleteEntity(db, priceReferSnapshotDeleteHis, "SnapshotAt")
dao.DeleteEntity(db, priceReferSnapshotDelete, "SnapshotAt")
for _, v := range priceReferSnapshot {
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
v.SnapshotAt = snapshotAt
if err = dao.CreateEntity(db, v); err != nil {
return err
}
}
task := tasksch.NewParallelTask("生成价格统计", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
v := batchItemList[0].(*model.PriceReferSnapshot)
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
v.SnapshotAt = snapshotAt
err = dao.CreateEntity(db, v)
priceRefer, err := dao.GetPriceReferUnitPrice(db, v.CityCode, v.NameID, v.SnapshotAt)
v.MidUnitPrice = priceRefer.MidUnitPrice
v.MaxUnitPrice = priceRefer.MaxUnitPrice
v.MinUnitPrice = priceRefer.MinUnitPrice
v.AvgUnitPrice = priceRefer.AvgUnitPrice
_, err = dao.UpdateEntity(db, v, "MidUnitPrice", "MaxUnitPrice", "AvgUnitPrice", "MinUnitPrice")
return retVal, err
}, priceReferSnapshot)
tasksch.HandleTask(task, nil, true).Run()
_, err = task.GetResult(0)
dao.Commit(db)
globals.SugarLogger.Debugf("CreatePriceRefer")
}
return err
}