把京西有,平台无且没有待创建标记的商品加上待创建标记
This commit is contained in:
@@ -515,6 +515,30 @@ func (v *VendorSync) PruneMissingStoreSkus(ctx *jxcontext.Context, vendorIDs []i
|
|||||||
return hint, makeSyncError(err)
|
return hint, makeSyncError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 把京西有,平台无且没有待创建标记的商品加上待创建标记
|
||||||
|
// todo,京东到家也应该支持
|
||||||
|
func (v *VendorSync) AddCreateFlagForJxStoreSku(ctx *jxcontext.Context, vendorIDs []int, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
globals.SugarLogger.Debug("AddCreateFlagForJxStoreSku")
|
||||||
|
hint, err = v.LoopStoresMap(ctx, dao.GetDB(), fmt.Sprintf("处理京西有,平台无且没有待创建标记的商品加上待创建标记:%v", storeIDs), isAsync, true, vendorIDs, storeIDs,
|
||||||
|
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||||
|
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||||
|
if len(loopMapInfo.StoreMapList) > 1 {
|
||||||
|
loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||||
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
storeMap := batchItemList[0].(*model.StoreMap)
|
||||||
|
_, err = AddCreateFlagForJxStoreSku(ctx, task, loopMapInfo.VendorID, storeMap.StoreID, storeMap.VendorStoreID, false, isContinueWhenError)
|
||||||
|
return nil, err
|
||||||
|
}, loopMapInfo.StoreMapList)
|
||||||
|
t.AddChild(loopStoreTask).Run()
|
||||||
|
_, err = loopStoreTask.GetResult(0)
|
||||||
|
} else {
|
||||||
|
_, err = AddCreateFlagForJxStoreSku(ctx, t, loopMapInfo.VendorID, loopMapInfo.StoreMapList[0].StoreID, loopMapInfo.StoreMapList[0].VendorStoreID, false, isContinueWhenError)
|
||||||
|
}
|
||||||
|
return nil, partner.AddVendorInfo2Err(err, loopMapInfo.VendorID)
|
||||||
|
}, isContinueWhenError)
|
||||||
|
return hint, makeSyncError(err)
|
||||||
|
}
|
||||||
|
|
||||||
func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) {
|
func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) {
|
||||||
var storeMapList []*model.StoreMap
|
var storeMapList []*model.StoreMap
|
||||||
if storeMapList, err = dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, ""); err != nil {
|
if storeMapList, err = dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, ""); err != nil {
|
||||||
|
|||||||
@@ -550,6 +550,65 @@ func PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, ven
|
|||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 把京西有,平台无且没有待创建标记的商品加上待创建标记
|
||||||
|
func AddCreateFlagForJxStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||||
|
if handler == nil {
|
||||||
|
return "", fmt.Errorf("平台:%s不支持此操作", model.VendorChineseNames[vendorID])
|
||||||
|
}
|
||||||
|
db := dao.GetDB()
|
||||||
|
localSkuList, err := dao.GetStoreSkus2(db, vendorID, storeID, nil, false)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var skuIDList []int
|
||||||
|
seqTaskFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
|
switch step {
|
||||||
|
case 0:
|
||||||
|
remoteSkuList, err2 := handler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
remoteSkuMap := make(map[int]*partner.SkuNameInfo)
|
||||||
|
for _, value := range remoteSkuList {
|
||||||
|
for _, skuInfo := range value.SkuList {
|
||||||
|
remoteSkuMap[skuInfo.SkuID] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, v := range localSkuList {
|
||||||
|
if remoteSkuMap[v.SkuID] == nil && !model.IsSyncStatusNew(v.StoreSkuSyncStatus) && !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) {
|
||||||
|
skuIDList = append(skuIDList, v.SkuID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
if len(skuIDList) > 0 {
|
||||||
|
storeSkuList, err := dao.GetStoresSkusInfo(db, []int{storeID}, skuIDList)
|
||||||
|
if err == nil {
|
||||||
|
for _, skuBind := range storeSkuList {
|
||||||
|
if vendorID == model.VendorIDMTWM {
|
||||||
|
skuBind.MtwmSyncStatus |= model.SyncFlagNewMask
|
||||||
|
} else if vendorID == model.VendorIDEBAI {
|
||||||
|
skuBind.EbaiSyncStatus |= model.SyncFlagNewMask
|
||||||
|
} else if vendorID == model.VendorIDJD {
|
||||||
|
skuBind.JdSyncStatus |= model.SyncFlagNewMask
|
||||||
|
}
|
||||||
|
dao.UpdateEntity(db, skuBind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
task := tasksch.NewSeqTask(fmt.Sprintf("处理京西门店商品加待创建标记:%s", model.VendorChineseNames[vendorID]), ctx, seqTaskFunc, 2)
|
||||||
|
tasksch.HandleTask(task, parentTask, true).Run()
|
||||||
|
if isAsync {
|
||||||
|
hint = task.GetID()
|
||||||
|
} else {
|
||||||
|
_, err = task.GetResult(0)
|
||||||
|
}
|
||||||
|
return hint, err
|
||||||
|
}
|
||||||
|
|
||||||
func ClearRemoteStoreStuffAndSetNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func ClearRemoteStoreStuffAndSetNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
userName := ctx.GetUserName()
|
userName := ctx.GetUserName()
|
||||||
globals.SugarLogger.Debugf("ClearRemoteStoreStuffAndSetNew storeID:%d, isContinueWhenError:%t, userName:%s", storeID, isContinueWhenError, userName)
|
globals.SugarLogger.Debugf("ClearRemoteStoreStuffAndSetNew storeID:%d, isContinueWhenError:%t, userName:%s", storeID, isContinueWhenError, userName)
|
||||||
|
|||||||
@@ -181,3 +181,23 @@ func (c *SyncController) PruneMissingStoreSkus() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 把京西有,平台无且没有待创建标记的商品加上待创建标记
|
||||||
|
// @Description 把京西有,平台无且没有待创建标记的商品加上待创建标记
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param storeIDs formData string false "门店ID列表"
|
||||||
|
// @Param vendorIDs formData string false "运营商ID列表(京东0 美团1 饿百3)"
|
||||||
|
// @Param isAsync formData bool false "是否异步操作"
|
||||||
|
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /AddCreateFlagForJxStoreSku [post]
|
||||||
|
func (c *SyncController) AddCreateFlagForJxStoreSku() {
|
||||||
|
c.callAddCreateFlagForJxStoreSku(func(params *tSyncAddCreateFlagForJxStoreSkuParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
var storeIDs, vendorIDs []int
|
||||||
|
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.VendorIDs, &vendorIDs); err == nil {
|
||||||
|
retVal, err = cms.CurVendorSync.AddCreateFlagForJxStoreSku(params.Ctx, vendorIDs, storeIDs, params.IsAsync, params.IsContinueWhenError)
|
||||||
|
}
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1483,6 +1483,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "AddCreateFlagForJxStoreSku",
|
||||||
|
Router: `/AddCreateFlagForJxStoreSku`,
|
||||||
|
AllowHTTPMethods: []string{"post"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "DeleteRemoteStoreSkus",
|
Method: "DeleteRemoteStoreSkus",
|
||||||
|
|||||||
Reference in New Issue
Block a user