- PruneMissingStoreSkus
This commit is contained in:
@@ -517,6 +517,33 @@ func (v *VendorSync) DeleteRemoteStoreSkus(ctx *jxcontext.Context, db *dao.DaoDB
|
||||
return hint, makeSyncError(err)
|
||||
}
|
||||
|
||||
// 将平台有,但本地没有的门店商品清除
|
||||
// todo,京东到家也应该支持
|
||||
func (v *VendorSync) PruneMissingStoreSkus(ctx *jxcontext.Context, vendorIDs []int, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debug("PruneMissingStoreSkus")
|
||||
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 handler, _ := v.GetStoreHandler(loopMapInfo.VendorID).(partner.ISingleStoreHandler); handler != nil {
|
||||
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)
|
||||
storeID := storeMap.StoreID
|
||||
_, err = handler.PruneMissingStoreSkus(ctx, task, storeID, false, isContinueWhenError)
|
||||
return nil, err
|
||||
}, loopMapInfo.StoreMapList)
|
||||
t.AddChild(loopStoreTask).Run()
|
||||
_, err = loopStoreTask.GetResult(0)
|
||||
} else {
|
||||
_, err = handler.PruneMissingStoreSkus(ctx, t, loopMapInfo.StoreMapList[0].StoreID, 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) {
|
||||
var storeMapList []*model.StoreMap
|
||||
if storeMapList, err = dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes); err != nil {
|
||||
|
||||
@@ -265,6 +265,8 @@ type ISingleStoreHandler interface {
|
||||
SyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync bool) (hint string, err error)
|
||||
|
||||
RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error)
|
||||
|
||||
PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error)
|
||||
}
|
||||
|
||||
type CreateWaybillPolicy func(refDeliveryFee, refAddFee, deliveryFee int64) (errStr string)
|
||||
|
||||
@@ -185,6 +185,46 @@ func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask t
|
||||
return rootTask.ID, err
|
||||
}
|
||||
|
||||
// todo 往上提
|
||||
func (p *PurchaseHandler) PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
localSkuList, err := dao.GetStoreSkus2(db, model.VendorIDEBAI, storeID, nil, false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
localSkuMap := make(map[int]*dao.StoreSkuSyncInfo)
|
||||
for _, v := range localSkuList {
|
||||
localSkuMap[v.SkuID] = v
|
||||
}
|
||||
var vendorSkuID2Delete []string
|
||||
task := tasksch.NewSeqTask("ebai PruneMissingStoreSkus", ctx,
|
||||
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
remoteSkuList, err2 := p.GetAllRemoteSkus(ctx, storeID, parentTask)
|
||||
if err = err2; err == nil {
|
||||
for _, v := range remoteSkuList {
|
||||
if localSkuMap[int(utils.Str2Int64WithDefault(v.CustomSkuID, 0))] == nil {
|
||||
vendorSkuID2Delete = append(vendorSkuID2Delete, utils.Int64ToStr(v.SkuID))
|
||||
}
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
if len(vendorSkuID2Delete) > 0 {
|
||||
err = p.DeleteRemoteSkus(ctx, task, storeID, vendorSkuID2Delete)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}, 2)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
if isAsync {
|
||||
hint = task.GetID()
|
||||
} else {
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteRemoteStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
userName := ctx.GetUserName()
|
||||
globals.SugarLogger.Debugf("ebai DeleteRemoteStoreSkus storeID:%d, isContinueWhenError:%t, userName:%s", storeID, isContinueWhenError, userName)
|
||||
|
||||
@@ -34,3 +34,7 @@ func (p *PurchaseHandler) GetStoresSku(ctx *jxcontext.Context, parentTask tasksc
|
||||
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
|
||||
return outStoreSkuList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -518,6 +518,47 @@ func (p *PurchaseHandler) DeleteRemoteCategories(ctx *jxcontext.Context, parentT
|
||||
return err
|
||||
}
|
||||
|
||||
// todo 往上提
|
||||
func (p *PurchaseHandler) PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
localSkuList, err := dao.GetStoreSkus2(db, model.VendorIDEBAI, storeID, nil, false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
localSkuMap := make(map[string]*dao.StoreSkuSyncInfo)
|
||||
for _, v := range localSkuList {
|
||||
localSkuMap[utils.Int2Str(v.SkuID)] = v
|
||||
}
|
||||
var vendorSkuID2Delete []string
|
||||
task := tasksch.NewSeqTask("mtwm PruneMissingStoreSkus", ctx,
|
||||
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
remoteSkuList, err2 := p.GetAllRemoteSkus(storeID)
|
||||
if err = err2; err == nil {
|
||||
for _, v := range remoteSkuList {
|
||||
skuIDStr := utils.Interface2String(v["app_food_code"])
|
||||
if localSkuMap[skuIDStr] == nil {
|
||||
vendorSkuID2Delete = append(vendorSkuID2Delete, skuIDStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
if len(vendorSkuID2Delete) > 0 {
|
||||
err = p.DeleteRemoteSkus(ctx, task, storeID, vendorSkuID2Delete)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}, 2)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
if isAsync {
|
||||
hint = task.GetID()
|
||||
} else {
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) DeleteRemoteStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
userName := ctx.GetUserName()
|
||||
globals.SugarLogger.Debugf("mtwm DeleteRemoteStoreSkus storeID:%d, isContinueWhenError:%t, userName:%s", storeID, isContinueWhenError, userName)
|
||||
|
||||
@@ -341,3 +341,7 @@ func composeFakeDelName(name string) string {
|
||||
func (p *PurchaseHandler) GetStoresSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeIDs []int) (storeSkuList []*model.StoreSkuBind, err error) {
|
||||
return storeSkuList, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -161,3 +161,23 @@ func (c *SyncController) SyncSkuNames() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 删除本地没有的平台门店商品信息
|
||||
// @Description 删除本地没有的平台门店商品信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeIDs query string true "门店ID列表"
|
||||
// @Param vendorIDs query string true "厂商ID列表"
|
||||
// @Param isAsync query bool false "是否异步操作"
|
||||
// @Param isContinueWhenError query bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /PruneMissingStoreSkus [delete]
|
||||
func (c *SyncController) PruneMissingStoreSkus() {
|
||||
c.callPruneMissingStoreSkus(func(params *tSyncPruneMissingStoreSkusParams) (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.PruneMissingStoreSkus(params.Ctx, vendorIDs, storeIDs, params.IsAsync, params.IsContinueWhenError)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1420,6 +1420,15 @@ func init() {
|
||||
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.ControllerComments{
|
||||
Method: "PruneMissingStoreSkus",
|
||||
Router: `/PruneMissingStoreSkus`,
|
||||
AllowHTTPMethods: []string{"delete"},
|
||||
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.ControllerComments{
|
||||
Method: "RefreshAllSkusID",
|
||||
|
||||
Reference in New Issue
Block a user