- isContinueWhenError for CreatePromotion
This commit is contained in:
@@ -30,7 +30,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PromotionLimitedTimeMinPercentage = 80
|
PromotionLimitedTimeMinPercentage = 79
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -49,7 +49,7 @@ const (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
defSearchDays = 7
|
defSearchDays = 7
|
||||||
stockRefreshGap = 1 * time.Minute
|
stockRefreshGap = 5 * time.Minute
|
||||||
userName = "jdpromotion"
|
userName = "jdpromotion"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -197,7 +197,7 @@ func Init() {
|
|||||||
scheduleRoutine()
|
scheduleRoutine()
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params *PromotionParams, userName string) (hint string, err error) {
|
func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueWhenError bool, params *PromotionParams, userName string) (hint string, err error) {
|
||||||
if len(params.SkuPrices) == 0 {
|
if len(params.SkuPrices) == 0 {
|
||||||
return "", ErrEmptySkus
|
return "", ErrEmptySkus
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
|
|||||||
if skuBind.Price*PromotionLimitedTimeMinPercentage/100 < promotionSkuPrice.Price {
|
if skuBind.Price*PromotionLimitedTimeMinPercentage/100 < promotionSkuPrice.Price {
|
||||||
modifyPricesList[skuBind.StoreID] = append(modifyPricesList[skuBind.StoreID], &jdapi.SkuPriceInfo{
|
modifyPricesList[skuBind.StoreID] = append(modifyPricesList[skuBind.StoreID], &jdapi.SkuPriceInfo{
|
||||||
OutSkuId: utils.Int2Str(skuBind.SkuID),
|
OutSkuId: utils.Int2Str(skuBind.SkuID),
|
||||||
Price: promotionSkuPrice.Price*100/PromotionLimitedTimeMinPercentage + 1,
|
Price: promotionSkuPrice.Price*100/PromotionLimitedTimeMinPercentage + 5,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -368,7 +368,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
|
|||||||
} else if step == 1 {
|
} else if step == 1 {
|
||||||
err = promotionHandler.CreatePromotionRules(infoId, "", 1, 1, 1, 1)
|
err = promotionHandler.CreatePromotionRules(infoId, "", 1, 1, 1, 1)
|
||||||
} else if step == 2 {
|
} else if step == 2 {
|
||||||
task2 := tasksch.NewParallelTask("CreateJdPromotion CreatePromotionSku", tasksch.NewParallelConfig().SetBatchSize(MaxPromotionSkuCount), userName, func(task *tasksch.ParallelTask, batchItemList []interface{}, params2 ...interface{}) (retVal interface{}, err error) {
|
task2 := tasksch.NewParallelTask("CreateJdPromotion CreatePromotionSku", tasksch.NewParallelConfig().SetBatchSize(MaxPromotionSkuCount).SetIsContinueWhenError(isContinueWhenError), userName, func(task *tasksch.ParallelTask, batchItemList []interface{}, params2 ...interface{}) (retVal interface{}, err error) {
|
||||||
skus := make([]map[string]interface{}, len(batchItemList))
|
skus := make([]map[string]interface{}, len(batchItemList))
|
||||||
for k, v := range batchItemList {
|
for k, v := range batchItemList {
|
||||||
skus[k] = v.(map[string]interface{})
|
skus[k] = v.(map[string]interface{})
|
||||||
@@ -378,6 +378,9 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync bool, params
|
|||||||
}, promotionPrices)
|
}, promotionPrices)
|
||||||
task.AddChild(task2).Run()
|
task.AddChild(task2).Run()
|
||||||
_, err = task2.GetResult(0)
|
_, err = task2.GetResult(0)
|
||||||
|
if isContinueWhenError && err != nil { // todo isContinueWhenError为true时,强制忽略此步的错误
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
} else if step == 3 {
|
} else if step == 3 {
|
||||||
err = promotionHandler.ConfirmPromotion(infoId, "")
|
err = promotionHandler.ConfirmPromotion(infoId, "")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type PromotionController struct {
|
|||||||
// @Param storeIDs formData string true "json数据,storeID列表[1,2,3]"
|
// @Param storeIDs formData string true "json数据,storeID列表[1,2,3]"
|
||||||
// @Param skuPrices formData string true "json数据,价格信息列表"
|
// @Param skuPrices formData string true "json数据,价格信息列表"
|
||||||
// @Param isAsync formData bool false "是否异步,缺省否(暂时只支持同步)"
|
// @Param isAsync formData bool false "是否异步,缺省否(暂时只支持同步)"
|
||||||
|
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||||
// @Param advertising formData string false "广告语"
|
// @Param advertising formData string false "广告语"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
@@ -51,7 +52,7 @@ func (c *PromotionController) CreatePromotion() {
|
|||||||
}
|
}
|
||||||
if err = utils.UnmarshalUseNumber([]byte(params.StoreIDs), &promotionParams.StoreIDs); err == nil {
|
if err = utils.UnmarshalUseNumber([]byte(params.StoreIDs), &promotionParams.StoreIDs); err == nil {
|
||||||
if err = utils.UnmarshalUseNumber([]byte(params.SkuPrices), &promotionParams.SkuPrices); err == nil {
|
if err = utils.UnmarshalUseNumber([]byte(params.SkuPrices), &promotionParams.SkuPrices); err == nil {
|
||||||
retVal, err = promotion.CreateJdPromotion(params.Ctx, false, params.IsAsync, promotionParams, params.Ctx.GetUserName())
|
retVal, err = promotion.CreateJdPromotion(params.Ctx, false, params.IsAsync, params.IsContinueWhenError, promotionParams, params.Ctx.GetUserName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
|
|||||||
Reference in New Issue
Block a user