- FullSyncStoresSkus
This commit is contained in:
@@ -315,6 +315,27 @@ func (v *VendorSync) SyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendo
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
globals.SugarLogger.Debug("FullSyncStoresSkus")
|
||||||
|
return v.LoopStoresMap(ctx, db, "FullSyncStoresSkus", isAsync, vendorIDs, storeIDs, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||||
|
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||||
|
if handler := v.GetSingleStoreHandler(loopMapInfo.VendorID); handler != nil {
|
||||||
|
if len(loopMapInfo.StoreMapList) > 1 {
|
||||||
|
loopStoreTask := tasksch.NewSeqTask("FullSyncStoresSkus loop stores", ctx.GetUserName(), func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
|
storeID := loopMapInfo.StoreMapList[step].StoreID
|
||||||
|
_, err = handler.FullSyncStoreSkus(ctx, task, storeID, false, isContinueWhenError)
|
||||||
|
return nil, err
|
||||||
|
}, len(loopMapInfo.StoreMapList))
|
||||||
|
t.AddChild(loopStoreTask).Run()
|
||||||
|
_, err = loopStoreTask.GetResult(0)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = handler.FullSyncStoreSkus(ctx, t, loopMapInfo.StoreMapList[0].StoreID, false, isContinueWhenError)
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc) (hint string, err error) {
|
func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc) (hint string, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT t1.*
|
SELECT t1.*
|
||||||
@@ -332,7 +353,7 @@ func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskNa
|
|||||||
sql += " AND t1.store_id IN (" + dao.GenQuestionMarks(len(storeIDs)) + ")"
|
sql += " AND t1.store_id IN (" + dao.GenQuestionMarks(len(storeIDs)) + ")"
|
||||||
sqlParams = append(sqlParams, storeIDs)
|
sqlParams = append(sqlParams, storeIDs)
|
||||||
}
|
}
|
||||||
|
sql += " ORDER BY t1.store_id, t1.vendor_id"
|
||||||
var storeMapList []*model.StoreMap
|
var storeMapList []*model.StoreMap
|
||||||
if err = dao.GetRows(db, &storeMapList, sql, sqlParams...); err != nil {
|
if err = dao.GetRows(db, &storeMapList, sql, sqlParams...); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
@@ -120,6 +120,9 @@ type ISingleStoreHandler interface {
|
|||||||
|
|
||||||
ReadStoreSku(storeID, skuID int) (skuNameExt *model.SkuNameExt, err error)
|
ReadStoreSku(storeID, skuID int) (skuNameExt *model.SkuNameExt, err error)
|
||||||
RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error)
|
RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error)
|
||||||
|
|
||||||
|
// !!!注意,此操作会先清除门店已有的商品,一般用于初始化,小心使用
|
||||||
|
FullSyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type IDeliveryPlatformHandler interface {
|
type IDeliveryPlatformHandler interface {
|
||||||
|
|||||||
@@ -131,13 +131,40 @@ func (p *PurchaseHandler) createCatByStoreSkus(ctx *jxcontext.Context, parentTas
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if _, err = p.SyncStoreCategory(ctx, parentTask, storeID, false); err != nil {
|
||||||
if _, err = p.SyncStoreCategory(ctx, parentTask, storeID, false); err != nil {
|
return 0, err
|
||||||
return 0, err
|
}
|
||||||
}
|
}
|
||||||
return num, nil
|
return num, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
userName := ctx.GetUserName()
|
||||||
|
globals.SugarLogger.Debugf("FullSyncStoreSkus storeID:%d, isContinueWhenError:%t, userName:%s", storeID, isContinueWhenError, userName)
|
||||||
|
|
||||||
|
rootTask := tasksch.NewSeqTask("FullSyncStoreSkus", userName, func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
|
switch step {
|
||||||
|
case 0:
|
||||||
|
err = p.DeleteRemoteSkus(storeID, nil)
|
||||||
|
case 1:
|
||||||
|
err = p.DeleteRemoteCategories(storeID, nil)
|
||||||
|
case 2:
|
||||||
|
db := dao.GetDB()
|
||||||
|
err = p.SyncLocalStoreCategory(db, storeID, userName)
|
||||||
|
case 3:
|
||||||
|
_, err = p.SyncStoreCategory(ctx, rootTask, storeID, false)
|
||||||
|
case 4:
|
||||||
|
_, err = p.SyncStoreSkus(ctx, rootTask, storeID, nil, true, isContinueWhenError)
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}, 5)
|
||||||
|
tasksch.AddChild(parentTask, rootTask).Run()
|
||||||
|
if !isAsync {
|
||||||
|
_, err = rootTask.GetResult(0)
|
||||||
|
}
|
||||||
|
return rootTask.ID, err
|
||||||
|
}
|
||||||
|
|
||||||
func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
userName := ctx.GetUserName()
|
userName := ctx.GetUserName()
|
||||||
globals.SugarLogger.Debugf("SyncStoreSkus storeID:%d, skuIDs:%v, isContinueWhenError:%t, userName:%s", storeID, skuIDs, isContinueWhenError, userName)
|
globals.SugarLogger.Debugf("SyncStoreSkus storeID:%d, skuIDs:%v, isContinueWhenError:%t, userName:%s", storeID, skuIDs, isContinueWhenError, userName)
|
||||||
@@ -145,12 +172,9 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
|||||||
var storeSkuInfoList []*tStoreSkuFullInfo
|
var storeSkuInfoList []*tStoreSkuFullInfo
|
||||||
var num int64
|
var num int64
|
||||||
strStoreID := utils.Int2Str(storeID)
|
strStoreID := utils.Int2Str(storeID)
|
||||||
rootTask := tasksch.NewSeqTask("SyncStoreSkus cat", userName, func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
rootTask := tasksch.NewSeqTask("SyncStoreSkus", userName, func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
if step == 0 {
|
if step == 0 {
|
||||||
db := dao.GetDB()
|
db := dao.GetDB()
|
||||||
if err = p.SyncLocalStoreCategory(db, storeID, userName); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
if storeSkuInfoList, err = p.getDirtyStoreSkus(db, storeID, skuIDs); err != nil {
|
if storeSkuInfoList, err = p.getDirtyStoreSkus(db, storeID, skuIDs); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -24,3 +24,7 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
|||||||
func (p *PurchaseHandler) RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error) {
|
func (p *PurchaseHandler) RefreshStoresAllSkusID(ctx *jxcontext.Context, parentTask tasksch.ITask, isAsync bool, storeIDs []int) (hint string, err error) {
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
return hint, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -113,3 +113,29 @@ func (c *SyncController) RefreshAllSkusID() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 全新初始化商家商品信息
|
||||||
|
// @Description 全新初始化商家商品信息(!!!此操作会先清除平台上已有的商品及分类信息),此操作只适用于单门店模式平台
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param storeIDs formData string true "门店ID列表"
|
||||||
|
// @Param vendorIDs formData string true "厂商ID列表"
|
||||||
|
// @Param isAsync formData bool true "是否异步操作"
|
||||||
|
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /FullSyncStoresSkus [put]
|
||||||
|
func (c *SyncController) FullSyncStoresSkus() {
|
||||||
|
c.callFullSyncStoresSkus(func(params *tSyncFullSyncStoresSkusParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
db := dao.GetDB()
|
||||||
|
var storeIDs []int
|
||||||
|
var vendorIDs []int
|
||||||
|
if err = utils.UnmarshalUseNumber([]byte(params.StoreIDs), &storeIDs); err != nil {
|
||||||
|
return retVal, "", err
|
||||||
|
}
|
||||||
|
if err = utils.UnmarshalUseNumber([]byte(params.VendorIDs), &vendorIDs); err != nil {
|
||||||
|
return retVal, "", err
|
||||||
|
}
|
||||||
|
retVal, err = cms.CurVendorSync.FullSyncStoresSkus(params.Ctx, db, vendorIDs, storeIDs, params.IsAsync, params.IsContinueWhenError)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -591,6 +591,14 @@ func init() {
|
|||||||
MethodParams: param.Make(),
|
MethodParams: param.Make(),
|
||||||
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: "FullSyncStoresSkus",
|
||||||
|
Router: `/FullSyncStoresSkus`,
|
||||||
|
AllowHTTPMethods: []string{"put"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
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: "RefreshAllSkusID",
|
Method: "RefreshAllSkusID",
|
||||||
|
|||||||
Reference in New Issue
Block a user