+FixMtwmCategory
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
@@ -25,6 +26,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
@@ -1198,3 +1200,80 @@ func CheckImages(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hin
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func fixMtwmCategoryList(cats []*partner.BareCategoryInfo, vendorStoreID string, name2CatMap map[string]*model.SkuCategory) (err error) {
|
||||
errList := errlist.New()
|
||||
for _, v := range cats {
|
||||
rFilterCatName := utils.FilterEmoji(v.Name)
|
||||
if cat := name2CatMap[rFilterCatName]; cat != nil {
|
||||
if v.Name != cat.Name || v.VendorCatID != utils.Int2Str(cat.ID) {
|
||||
errList.AddErr(api.MtwmAPI.RetailCatUpdate2(vendorStoreID, "", v.Name, utils.Int2Str(cat.ID), cat.Name, "", "", v.Seq))
|
||||
}
|
||||
} else if rFilterCatName != v.Name {
|
||||
errList.AddErr(api.MtwmAPI.RetailCatUpdate2(vendorStoreID, "", v.Name, "", rFilterCatName, "", "", v.Seq))
|
||||
}
|
||||
errList.AddErr(fixMtwmCategoryList(v.Children, vendorStoreID, name2CatMap))
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
func FixMtwmCategory(ctx *jxcontext.Context, mtwmStoreIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
id2CatMap := make(map[int]*model.SkuCategory)
|
||||
name2CatMap := make(map[string]*model.SkuCategory)
|
||||
var mtwmIDMap map[string]int
|
||||
if len(mtwmStoreIDs) > 0 {
|
||||
mtwmIDMap = make(map[string]int)
|
||||
for _, v := range mtwmStoreIDs {
|
||||
mtwmIDMap[utils.Int2Str(v)] = 1
|
||||
}
|
||||
}
|
||||
task := tasksch.NewParallelTask("修复美团分类信息", tasksch.NewParallelConfig().SetParallelCount(1), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 0:
|
||||
var catList []*model.SkuCategory
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM sku_category t1
|
||||
WHERE t1.deleted_at = ?
|
||||
`
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetRows(db, &catList, sql, utils.DefaultTimeValue); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range catList {
|
||||
v.Name = utils.FilterEmoji(v.Name)
|
||||
id2CatMap[v.ID] = v
|
||||
name2CatMap[v.Name] = v
|
||||
}
|
||||
case 1:
|
||||
storeIDs, err := mtwm.CurPurchaseHandler.GetAllStoresVendorID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subTask := tasksch.NewParallelTask("修复美团分类信息2", tasksch.NewParallelConfig().SetParallelCount(5).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeID := batchItemList[0].(string)
|
||||
if mtwmIDMap == nil || mtwmIDMap[storeID] == 1 {
|
||||
catList, err := mtwm.CurPurchaseHandler.GetStoreAllCategories(ctx, 0, storeID)
|
||||
if err == nil {
|
||||
err = fixMtwmCategoryList(catList, storeID, name2CatMap)
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, storeIDs)
|
||||
tasksch.HandleTask(subTask, task, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return retVal, err
|
||||
}, []int{0, 1})
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = task.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -333,3 +333,22 @@ func (c *TempOpController) CheckStoreAlert() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 修复美团商品分类(emoji)
|
||||
// @Description 修复美团商品分类(emoji)
|
||||
// @Param token header string true "认证token"
|
||||
// @Param mtwmStoreIDs formData string false "门店列表"
|
||||
// @Param isAsync formData bool false "是否异步操作"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /FixMtwmCategory [post]
|
||||
func (c *TempOpController) FixMtwmCategory() {
|
||||
c.callFixMtwmCategory(func(params *tTempopFixMtwmCategoryParams) (retVal interface{}, errCode string, err error) {
|
||||
var mtwmStoreIDs []int
|
||||
if err = jxutils.Strings2Objs(params.MtwmStoreIDs, &mtwmStoreIDs); err == nil {
|
||||
retVal, err = tempop.FixMtwmCategory(params.Ctx, mtwmStoreIDs, params.IsAsync, params.IsContinueWhenError)
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1701,6 +1701,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"],
|
||||
beego.ControllerComments{
|
||||
Method: "FixMtwmCategory",
|
||||
Router: `/FixMtwmCategory`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:TempOpController"],
|
||||
beego.ControllerComments{
|
||||
Method: "PrintMsg",
|
||||
|
||||
Reference in New Issue
Block a user