价格统计
This commit is contained in:
@@ -76,6 +76,26 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err e
|
|||||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||||
v.SnapshotAt = snapshotAt
|
v.SnapshotAt = snapshotAt
|
||||||
err = dao.CreateEntity(db, v)
|
err = dao.CreateEntity(db, v)
|
||||||
|
return retVal, err
|
||||||
|
}, priceReferSnapshot)
|
||||||
|
tasksch.HandleTask(task, nil, true).Run()
|
||||||
|
_, err = task.GetResult(0)
|
||||||
|
dao.Commit(db)
|
||||||
|
}
|
||||||
|
dao.Begin(db)
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil || err != nil {
|
||||||
|
dao.Rollback(db)
|
||||||
|
if r != nil {
|
||||||
|
panic(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
priceReferList, err := dao.GetPriceReferSnapshotNoPage(db, nil, nil, nil, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||||
|
if len(priceReferList) > 0 {
|
||||||
|
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)
|
||||||
priceRefer, err := dao.GetPriceReferUnitPrice(db, v.CityCode, v.NameID, v.SnapshotAt)
|
priceRefer, err := dao.GetPriceReferUnitPrice(db, v.CityCode, v.NameID, v.SnapshotAt)
|
||||||
v.MidUnitPrice = priceRefer.MidUnitPrice
|
v.MidUnitPrice = priceRefer.MidUnitPrice
|
||||||
v.MaxUnitPrice = priceRefer.MaxUnitPrice
|
v.MaxUnitPrice = priceRefer.MaxUnitPrice
|
||||||
@@ -86,7 +106,7 @@ func BeginSavePriceRefer(ctx *jxcontext.Context, cityCodes, skuIDs []int) (err e
|
|||||||
}, priceReferSnapshot)
|
}, priceReferSnapshot)
|
||||||
tasksch.HandleTask(task, nil, true).Run()
|
tasksch.HandleTask(task, nil, true).Run()
|
||||||
_, err = task.GetResult(0)
|
_, err = task.GetResult(0)
|
||||||
dao.Commit(db)
|
|
||||||
}
|
}
|
||||||
|
dao.Commit(db)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -292,3 +292,33 @@ func GetPriceReferSnapshot(db *DaoDB, cityCodes, skuIDs []int, skuNameID int, sn
|
|||||||
}
|
}
|
||||||
return priceReferSnapshot, totalCount, err
|
return priceReferSnapshot, totalCount, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetPriceReferSnapshotNoPage(db *DaoDB, cityCodes, skuIDs, skuNameIDs []int, snapDate time.Time) (priceReferSnapshot []*model.PriceReferSnapshot, err error) {
|
||||||
|
sql := `
|
||||||
|
SELECT a.*
|
||||||
|
FROM price_refer_snapshot a
|
||||||
|
WHERE 1=1
|
||||||
|
AND a.deleted_at = ?
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
}
|
||||||
|
if len(skuNameIDs) > 0 {
|
||||||
|
sql += " AND a.name_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||||
|
sqlParams = append(sqlParams, skuNameIDs)
|
||||||
|
}
|
||||||
|
if len(skuIDs) > 0 {
|
||||||
|
sql += " AND a.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||||
|
sqlParams = append(sqlParams, skuIDs)
|
||||||
|
}
|
||||||
|
if len(cityCodes) > 0 {
|
||||||
|
sql += " AND a.city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")"
|
||||||
|
sqlParams = append(sqlParams, cityCodes)
|
||||||
|
}
|
||||||
|
if !utils.IsTimeZero(snapDate) {
|
||||||
|
sql += " AND a.snapshot_at = ?"
|
||||||
|
sqlParams = append(sqlParams, snapDate)
|
||||||
|
}
|
||||||
|
err = GetRows(db, &priceReferSnapshot, sql, sqlParams...)
|
||||||
|
return priceReferSnapshot, err
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user