Accept Merge Request #153: (su -> mark)
Merge Request: 商品库,门店,同步错误返回 Created By: @苏尹岚 Accepted By: @苏尹岚 URL: https://rosydev.coding.net/p/jx-callback/d/jx-callback/git/merge/153
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/partner/putils"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -230,6 +232,7 @@ func (v *VendorSync) SyncStore2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs
|
||||
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 {
|
||||
@@ -245,6 +248,8 @@ func (v *VendorSync) SyncStore2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs
|
||||
storeMap.SyncStatus = 0
|
||||
_, err = dao.UpdateEntity(db2, storeMap, model.FieldSyncStatus)
|
||||
resultList = append(resultList, 1)
|
||||
} else {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, storeMap.VendorID, "同步门店")
|
||||
}
|
||||
return resultList, err
|
||||
}, loopMapInfo.StoreMapList)
|
||||
@@ -255,6 +260,8 @@ func (v *VendorSync) SyncStore2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs
|
||||
if err = handler.UpdateStore(db, storeMap.StoreID, userName); err == nil {
|
||||
storeMap.SyncStatus = 0
|
||||
_, err = dao.UpdateEntity(db, storeMap, model.FieldSyncStatus)
|
||||
} else {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeMap.StoreID, storeMap.VendorID, "同步门店")
|
||||
}
|
||||
if err == nil {
|
||||
resultList = []interface{}{1}
|
||||
@@ -262,6 +269,9 @@ func (v *VendorSync) SyncStore2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs
|
||||
}
|
||||
err = partner.AddVendorInfo2Err(err, loopMapInfo.VendorID)
|
||||
}
|
||||
if len(failedList) > 0 {
|
||||
t.AddFailedList(failedList)
|
||||
}
|
||||
return resultList, err
|
||||
}, true)
|
||||
return hint, makeSyncError(err)
|
||||
@@ -621,23 +631,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
}
|
||||
task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList)
|
||||
if isAsync {
|
||||
task.SetFinishHook(func(task tasksch.ITask) {
|
||||
var noticeMsg string
|
||||
if ctx.GetUserName() != "jxadmin" {
|
||||
if len(task.GetFailedList()) > 10 {
|
||||
downloadURL, _, _ := WirteToExcelBySyncFailed(task)
|
||||
noticeMsg = "您此次的同步任务错误详情返回如下: "
|
||||
noticeMsg += fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL)
|
||||
} else if len(task.GetFailedList()) > 0 && len(task.GetFailedList()) <= 10 {
|
||||
if task.GetErr() != nil {
|
||||
noticeMsg = utils.Format4Output(buildErrMsgJson(task), true)
|
||||
}
|
||||
}
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "同步错误返回", noticeMsg)
|
||||
}
|
||||
}
|
||||
})
|
||||
buildSetFinishHook(task, ctx)
|
||||
}
|
||||
tasksch.HandleTask(task, parentTask, isManageIt).Run()
|
||||
if !isAsync {
|
||||
@@ -658,6 +652,26 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
return task, hint, err
|
||||
}
|
||||
|
||||
func buildSetFinishHook(task tasksch.ITask, ctx *jxcontext.Context) {
|
||||
task.SetFinishHook(func(task tasksch.ITask) {
|
||||
var noticeMsg string
|
||||
if ctx.GetUserName() != "jxadmin" {
|
||||
if len(task.GetFailedList()) > 10 {
|
||||
downloadURL, _, _ := WirteToExcelBySyncFailed(task)
|
||||
noticeMsg = "您此次的同步任务错误详情返回如下: "
|
||||
noticeMsg += fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL)
|
||||
} else if len(task.GetFailedList()) > 0 && len(task.GetFailedList()) <= 10 {
|
||||
if task.GetErr() != nil {
|
||||
noticeMsg = utils.Format4Output(buildErrMsgJson(task), true)
|
||||
}
|
||||
}
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "同步错误返回", noticeMsg)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func buildErrMsg(task tasksch.ITask) (err error) {
|
||||
err = fmt.Errorf(utils.Format4Output(buildErrMsgJson(task), true))
|
||||
return makeSpecSyncError(err)
|
||||
|
||||
@@ -137,6 +137,7 @@ func SyncSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []int,
|
||||
task := tasksch.NewParallelTask(fmt.Sprintf("同步商品:%v,%v", nameIDs, skuIDs), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
skuVendorInfo := batchItemList[0].(*dao.StoreSkuSyncInfo)
|
||||
var failedList []*partner.StoreSkuInfoWithErr
|
||||
if skuVendorInfo.VendorCatID == "" {
|
||||
return nil, fmt.Errorf("商品:%d的商家分类没有同步", skuVendorInfo.SkuID)
|
||||
}
|
||||
@@ -150,25 +151,44 @@ func SyncSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []int,
|
||||
if !dao.IsVendorThingIDEmpty(skuVendorInfo.VendorSkuID) &&
|
||||
model.IsSyncStatusNeedDelete(skuVendorInfo.SkuSyncStatus) {
|
||||
err = multiStoresHandler.DeleteSku2(ctx, skuVendorInfo.VendorOrgCode, storeSkuSyncInfo2Bare(skuVendorInfo))
|
||||
if err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(skuVendorInfo, err, 0, skuVendorInfo.VendorID, "删除商品")
|
||||
}
|
||||
}
|
||||
} else if model.IsSyncStatusNew(skuVendorInfo.SkuSyncStatus) { // 新增
|
||||
err = multiStoresHandler.CreateSku2(ctx, skuVendorInfo)
|
||||
if err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(skuVendorInfo, err, 0, skuVendorInfo.VendorID, "新增商品")
|
||||
}
|
||||
} else if model.IsSyncStatusUpdate(skuVendorInfo.SkuSyncStatus) { // 修改
|
||||
err = multiStoresHandler.UpdateSku2(ctx, skuVendorInfo)
|
||||
if err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(skuVendorInfo, err, 0, skuVendorInfo.VendorID, "修改商品")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = fmt.Errorf("平台:%d不合法", skuVendorInfo.VendorID)
|
||||
}
|
||||
if len(failedList) > 0 {
|
||||
task.AddFailedList(failedList)
|
||||
}
|
||||
if err = OnThingSync(ctx, dao.GetDB(), SkuVendor2ThingMap(skuVendorInfo), err); err == nil {
|
||||
retVal = []int{1}
|
||||
}
|
||||
return retVal, err
|
||||
}, skuList)
|
||||
if isAsync {
|
||||
buildSetFinishHook(task, ctx)
|
||||
}
|
||||
tasksch.HandleTask(task, parentTask, len(skuList) == 0 || len(skuList) > 10).Run()
|
||||
if isAsync {
|
||||
hint = task.GetID()
|
||||
} else {
|
||||
resultList, err2 := task.GetResult(0)
|
||||
if len(task.GetFailedList()) > 0 {
|
||||
err2 = buildErrMsg(task)
|
||||
err2 = makeSyncError(err2)
|
||||
}
|
||||
if err = err2; err == nil {
|
||||
hint = utils.Int2Str(len(resultList))
|
||||
}
|
||||
|
||||
@@ -272,6 +272,23 @@ func GetErrMsg2FailedSingleList(storeSkuList interface{}, err error, storeID, ve
|
||||
SyncType: syncType,
|
||||
}
|
||||
failedList = append(failedList, storeSkuInfoWithErr)
|
||||
} else if storeSku, ok := storeSkuList.(*dao.StoreSkuSyncInfo); ok {
|
||||
storeSkuInfo := &partner.StoreSkuInfo{
|
||||
SkuID: storeSku.SkuID,
|
||||
VendorSkuID: storeSku.VendorSkuID,
|
||||
NameID: storeSku.NameID,
|
||||
VendorNameID: storeSku.VendorNameID,
|
||||
VendorPrice: storeSku.VendorPrice,
|
||||
Status: storeSku.Status,
|
||||
}
|
||||
storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{
|
||||
StoreSkuInfo: storeSkuInfo,
|
||||
ErrMsg: errExt.ErrMsg(),
|
||||
StoreID: storeID,
|
||||
VendoreID: vendorID,
|
||||
SyncType: syncType,
|
||||
}
|
||||
failedList = append(failedList, storeSkuInfoWithErr)
|
||||
} else {
|
||||
storeSkuInfoWithErr := &partner.StoreSkuInfoWithErr{
|
||||
ErrMsg: errExt.ErrMsg(),
|
||||
|
||||
Reference in New Issue
Block a user