- jd.FullSyncStoreSkus
- refactor mtwm.SyncLocalStoreCategory
This commit is contained in:
@@ -86,10 +86,6 @@ func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask t
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) ReadStoreCategories(storeID int) (cats []*model.SkuCategory, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// 此函数根据门店商品信息重建分类信息
|
||||
// 远程有,本地无, --> 删除远程
|
||||
// 远程有,本地有,映射无, --> 添加关联
|
||||
@@ -110,17 +106,10 @@ func (p *PurchaseHandler) SyncLocalStoreCategory(ctx *jxcontext.Context, db *dao
|
||||
return "", err
|
||||
}
|
||||
for _, cat := range localCats {
|
||||
catID := cat.VendorCatID
|
||||
if catID == "" {
|
||||
catID = cat.Name
|
||||
}
|
||||
parentCatID := cat.ParentVendorCatID
|
||||
if parentCatID == "" {
|
||||
parentCatID = cat.ParentCatName
|
||||
}
|
||||
catMap[i][parentCatID+"/"+catID] = cat
|
||||
catMap[i][cat.ParentCatName+"/"+cat.Name] = cat
|
||||
}
|
||||
}
|
||||
identityCatMap := make(map[int]int) // 这里面表示远程有,本地有,且完全相同,可擦掉本地的修改标记
|
||||
if isCheckRemote {
|
||||
strStoreID := utils.Int2Str(storeID)
|
||||
remoteCats, err := api.MtwmAPI.RetailCatList(utils.Int2Str(storeID))
|
||||
@@ -141,7 +130,7 @@ func (p *PurchaseHandler) SyncLocalStoreCategory(ctx *jxcontext.Context, db *dao
|
||||
if localCat.MapID == 0 { // 本地映射没有
|
||||
localCat.MapID = -1 // 表示远程有同名的
|
||||
} else { // 本地映射有
|
||||
localCat.MapID = -2 // 表示不处理
|
||||
identityCatMap[localCat.MapID] = 1
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -174,13 +163,24 @@ func (p *PurchaseHandler) SyncLocalStoreCategory(ctx *jxcontext.Context, db *dao
|
||||
if err = dao.CreateEntity(db, catMap); err != nil {
|
||||
return "", err
|
||||
}
|
||||
} else if v.MapID != -2 {
|
||||
} else if isCheckRemote {
|
||||
catMap := &model.StoreSkuCategoryMap{
|
||||
MtwmSyncStatus: model.SyncFlagNewMask,
|
||||
}
|
||||
updateFields := []string{
|
||||
model.FieldUpdatedAt,
|
||||
model.FieldLastOperator,
|
||||
model.FieldMtwmSyncStatus,
|
||||
}
|
||||
if identityCatMap[v.MapID] == 1 { // 如果一样,则要刷新ID(对于MTWM其实就是名字)
|
||||
catMap.MtwmID = v.Name
|
||||
catMap.MtwmSyncStatus = 0
|
||||
updateFields = append(updateFields, model.FieldMtwmID)
|
||||
}
|
||||
catMap.ID = v.MapID
|
||||
num++
|
||||
if _, err = dao.UpdateEntity(db, catMap, "MtwmSyncStatus"); err != nil {
|
||||
dao.WrapUpdateULEntity(catMap, ctx.GetUserName())
|
||||
if _, err = dao.UpdateEntity(db, catMap, updateFields...); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
@@ -201,10 +201,6 @@ func TranverseRemoteCatList(parentCatName string, remoteCats []*mtwmapi.RetailCa
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) ReadStoreSku(storeID, skuID int) (skuNameExt *model.SkuNameExt, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// hint,如果是异步,返回的是任务ID,如果是同步,返回是本次需要同步的目录数
|
||||
func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
@@ -224,8 +220,14 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
||||
if hint != "0" {
|
||||
return "", errors.New("同步门店商品所需目录失败")
|
||||
}
|
||||
|
||||
storeDetail, err := dao.GetStoreDetail(db, storeID, model.VendorIDMTWM)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
skus, err := dao.GetStoreSkus(db, model.VendorIDMTWM, storeID, skuIDs)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(skus, false))
|
||||
strStoreID := utils.Int2Str(storeID)
|
||||
rootTask := tasksch.NewParallelTask("美团外卖SyncStoreSkus", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx.GetUserName(), func(rootTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
@@ -241,7 +243,7 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
||||
foodData[mtwmapi.KeyAppFoodCode] = utils.Int2Str(skuItem.ID)
|
||||
foodData["name"] = jxutils.ComposeSkuName(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, 30)
|
||||
foodData["description"] = skuItem.Comment
|
||||
foodData["price"] = jxutils.IntPrice2Standard(skuItem.Price)
|
||||
foodData["price"] = jxutils.CaculateSkuVendorPrice(int(skuItem.Price), int(storeDetail.PricePercentage))
|
||||
foodData["min_order_count"] = 1
|
||||
foodData["unit"] = skuItem.Unit
|
||||
foodData["box_num"] = 0
|
||||
@@ -307,7 +309,7 @@ func (p *PurchaseHandler) FullSyncStoreSkus(ctx *jxcontext.Context, parentTask t
|
||||
case 3:
|
||||
_, err = p.SyncStoreCategory(ctx, rootTask, storeID, false)
|
||||
case 4:
|
||||
_, err = p.SyncStoreSkus(ctx, rootTask, storeID, nil, true, isContinueWhenError)
|
||||
// _, err = p.SyncStoreSkus(ctx, rootTask, storeID, nil, true, isContinueWhenError)
|
||||
}
|
||||
return nil, err
|
||||
}, 5)
|
||||
|
||||
Reference in New Issue
Block a user