价格统计

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

@@ -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
}