- fix bug in updateStoreSkusWithoutSync

This commit is contained in:
gazebo
2018-10-24 20:27:22 +08:00
parent 576709a0bd
commit 442b8c6db3
8 changed files with 35 additions and 18 deletions

View File

@@ -4,6 +4,7 @@ import (
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
@@ -22,12 +23,14 @@ type tStoreSkuBindExt struct {
}
// 京东到家,以有库存表示关注(认领)
func (p *PurchaseHandler) SyncStoresSkus(db *dao.DaoDB, storeIDs []int, skuIDs []int, isAsync bool, userName string) (hint string, err error) {
func (p *PurchaseHandler) SyncStoresSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, db *dao.DaoDB, storeIDs []int, skuIDs []int, isAsync bool) (hint string, err error) {
globals.SugarLogger.Debugf("jd SyncStoresSkus, storeIDs:%v, skuIDs:%v", storeIDs, skuIDs)
parallelCount := 1
if len(skuIDs) < MaxSkuBatchSize {
parallelCount = 10
}
task := tasksch.RunManagedParallelTask("SyncStoresSkus", tasksch.NewParallelConfig().SetParallelCount(parallelCount), userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
task := tasksch.NewParallelTask("SyncStoresSkus", tasksch.NewParallelConfig().SetParallelCount(parallelCount), ctx.GetUserName(), func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
storeID := batchItemList[0].(int)
sqlWhere := `
WHERE (t1.deleted_at = ? OR t1.jd_sync_status <> 0) AND t1.store_id = ?
@@ -54,7 +57,7 @@ func (p *PurchaseHandler) SyncStoresSkus(db *dao.DaoDB, storeIDs []int, skuIDs [
}
if err = dao.GetRows(db, &storeSkus, sql, append(sqlParams, sqlWhereParams...)...); err == nil {
outStationNo := utils.Int2Str(storeID)
task := tasksch.RunParallelTask("SyncStoresSkus inner", tasksch.NewParallelConfig().SetBatchSize(MaxSkuBatchSize), userName, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
task := tasksch.RunParallelTask("SyncStoresSkus inner", tasksch.NewParallelConfig().SetBatchSize(MaxSkuBatchSize), ctx.GetUserName(), func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
var skuPriceInfoList []*jdapi.SkuPriceInfo
var skuVendibilityList []*jdapi.StockVendibility
var skuStockList []*jdapi.SkuStock
@@ -93,13 +96,13 @@ func (p *PurchaseHandler) SyncStoresSkus(db *dao.DaoDB, storeIDs []int, skuIDs [
if globals.EnableStoreWrite {
// todo 以下可以优化为并行操作
if len(skuVendibilityList) > 0 {
_, err = api.JdAPI.BatchUpdateVendibility(outStationNo, "", skuVendibilityList, userName)
_, err = api.JdAPI.BatchUpdateVendibility(outStationNo, "", skuVendibilityList, ctx.GetUserName())
}
if err == nil && len(skuPriceInfoList) > 0 {
_, err = api.JdAPI.UpdateVendorStationPrice(outStationNo, "", skuPriceInfoList)
}
if err == nil && len(skuStockList) > 0 {
_, err = api.JdAPI.BatchUpdateCurrentQtys(outStationNo, "", skuStockList, userName)
_, err = api.JdAPI.BatchUpdateCurrentQtys(outStationNo, "", skuStockList, ctx.GetUserName())
}
}
return nil, err
@@ -115,6 +118,8 @@ func (p *PurchaseHandler) SyncStoresSkus(db *dao.DaoDB, storeIDs []int, skuIDs [
return nil, err
}, storeIDs)
ctx.SetTaskOrAddChild(task, parentTask)
task.Run()
if isAsync {
return task.ID, nil
}