1
This commit is contained in:
@@ -215,20 +215,107 @@ func (v *VendorSync) SyncReorderCategories(ctx *jxcontext.Context, db *dao.DaoDB
|
||||
return SyncReorderCategories(ctx, categoryID, isAsync)
|
||||
}
|
||||
|
||||
// func (v *VendorSync) oldSyncReorderCategories(ctx *jxcontext.Context, db *dao.DaoDB, categoryID int, isAsync bool, userName string) (hint string, err error) {
|
||||
// hint, err = v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("分类重排序:%d", categoryID), isAsync, false, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
// vendorInfo := batchItemList[0].(*MultiStoreVendorInfo)
|
||||
// multiStoresHandler := v.GetMultiStoreHandler(vendorInfo.VendorID)
|
||||
// err2 := multiStoresHandler.ReorderCategories(db, categoryID, userName)
|
||||
// if err2 == nil {
|
||||
// cat := &model.SkuCategory{}
|
||||
// _, err2 = dao.UpdateEntityByKV(db, cat, utils.Params2Map(dao.GetSyncStatusStructField(model.VendorNames[multiStoresHandler.GetVendorID()]), 0), utils.Params2Map(model.FieldParentID, categoryID))
|
||||
// return nil, err2
|
||||
// }
|
||||
// return nil, err2
|
||||
// })
|
||||
// return "", err
|
||||
// }
|
||||
// SyncStore2Time 此方法只适用于定时任务同步门店
|
||||
func (v *VendorSync) SyncStore2Time(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs, storeIDs []int, mustDirty, isAsync bool) (hint string, err error) {
|
||||
userName := ctx.GetUserName()
|
||||
isManageIt := len(storeIDs) == 0 || len(storeIDs) > 5
|
||||
_, hint, err = v.LoopStoresMap2(ctx, nil, db, fmt.Sprintf("同步门店信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs, mustDirty, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (resultList interface{}, err error) {
|
||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||
var failedList []*partner.StoreSkuInfoWithErr
|
||||
handler := v.GetStoreHandler(loopMapInfo.VendorID)
|
||||
if handler != nil {
|
||||
if len(loopMapInfo.StoreMapList) > 1 {
|
||||
loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
var resultList []interface{}
|
||||
var vendorStoreID string
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
db2 := db
|
||||
if len(loopMapInfo.StoreMapList) > 1 {
|
||||
db2 = dao.GetDB()
|
||||
}
|
||||
if storeMap.Status == model.StoreStatusDisabled {
|
||||
resultList = append(resultList, 1)
|
||||
} else if model.IsSyncStatusNew(storeMap.SyncStatus) {
|
||||
storeDetail, _ := dao.GetStoreDetail(db, storeMap.StoreID, storeMap.VendorID, storeMap.VendorOrgCode)
|
||||
if vendorStoreID, err = handler.CreateStore2(db2, storeMap.StoreID, userName, nil, storeDetail); err == nil {
|
||||
resultList = append(resultList, 1)
|
||||
} else {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "创建门店")
|
||||
}
|
||||
} else if model.IsSyncStatusDelete(storeMap.SyncStatus) {
|
||||
if err = handler.DeleteStore(db2, storeMap.StoreID, userName); err == nil {
|
||||
resultList = append(resultList, 1)
|
||||
} else {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "删除门店")
|
||||
}
|
||||
} else {
|
||||
if err = handler.UpdateStore(db2, storeMap.StoreID, userName); err == nil {
|
||||
resultList = append(resultList, 1)
|
||||
} else {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "更新门店")
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
if model.IsSyncStatusNew(storeMap.SyncStatus) {
|
||||
storeMap.VendorStoreID = vendorStoreID
|
||||
storeMap.SyncStatus = 0
|
||||
_, err = dao.UpdateEntity(db, storeMap, "VendorStoreID", model.FieldSyncStatus)
|
||||
} else {
|
||||
storeMap.SyncStatus = 0
|
||||
_, err = dao.UpdateEntity(db, storeMap, model.FieldSyncStatus)
|
||||
}
|
||||
}
|
||||
return resultList, err
|
||||
}, loopMapInfo.StoreMapList)
|
||||
t.AddChild(loopStoreTask).Run()
|
||||
resultList, err = loopStoreTask.GetResult(0)
|
||||
} else {
|
||||
var resultList []interface{}
|
||||
db2 := db
|
||||
var vendorStoreID string
|
||||
storeMap := loopMapInfo.StoreMapList[0]
|
||||
if model.IsSyncStatusNew(storeMap.SyncStatus) {
|
||||
storeDetail, _ := dao.GetStoreDetail(db, storeMap.StoreID, storeMap.VendorID, storeMap.VendorOrgCode)
|
||||
if vendorStoreID, err = handler.CreateStore2(db2, storeMap.StoreID, userName, nil, storeDetail); err == nil {
|
||||
resultList = append(resultList, 1)
|
||||
} else {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "创建门店")
|
||||
}
|
||||
} else if model.IsSyncStatusDelete(storeMap.SyncStatus) {
|
||||
if err = handler.DeleteStore(db2, storeMap.StoreID, userName); err == nil {
|
||||
resultList = append(resultList, 1)
|
||||
} else {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "删除门店")
|
||||
}
|
||||
} else {
|
||||
if err = handler.UpdateStore(db, storeMap.StoreID, userName); err == nil {
|
||||
resultList = append(resultList, 1)
|
||||
} else {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, model.VendorChineseNames[storeMap.VendorID], "更新门店")
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
resultList = []interface{}{1}
|
||||
if model.IsSyncStatusNew(storeMap.SyncStatus) {
|
||||
storeMap.VendorStoreID = vendorStoreID
|
||||
storeMap.SyncStatus = 0
|
||||
_, err = dao.UpdateEntity(db, storeMap, "VendorStoreID", model.FieldSyncStatus)
|
||||
} else {
|
||||
storeMap.SyncStatus = 0
|
||||
_, err = dao.UpdateEntity(db, storeMap, model.FieldSyncStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
err = partner.AddVendorInfo2Err(err, loopMapInfo.VendorID)
|
||||
}
|
||||
if len(failedList) > 0 {
|
||||
t.AddFailedList(failedList)
|
||||
}
|
||||
return resultList, err
|
||||
}, true)
|
||||
return hint, makeSyncError(err)
|
||||
}
|
||||
|
||||
func (v *VendorSync) SyncStore2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs, storeIDs []int, mustDirty, isAsync bool) (hint string, err error) {
|
||||
userName := ctx.GetUserName()
|
||||
|
||||
Reference in New Issue
Block a user