同步错误返回
This commit is contained in:
@@ -628,14 +628,19 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN
|
||||
}
|
||||
task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList)
|
||||
if isAsync {
|
||||
task.SetFinishHook(func(task tasksch.ITask, ctx *jxcontext.Context) {
|
||||
task.SetFinishHook(func(task tasksch.ITask) {
|
||||
var noticeMsg string
|
||||
if len(task.GetErrMsg()) > 10 {
|
||||
err = WirteToExcelBySyncFailed(task, ctx)
|
||||
downloadURL, _, _ := WirteToExcelBySyncFailed(task)
|
||||
noticeMsg = fmt.Sprintf("[详情点我]path1=%s\n", downloadURL)
|
||||
} else {
|
||||
if err != nil {
|
||||
err = buildErrMsg(task)
|
||||
noticeMsg = utils.Format4Output(buildErrMsgJson(task), true)
|
||||
}
|
||||
}
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "同步错误返回", noticeMsg)
|
||||
}
|
||||
})
|
||||
}
|
||||
tasksch.HandleTask(task, nil, isManageIt).Run()
|
||||
@@ -658,41 +663,36 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN
|
||||
}
|
||||
|
||||
func buildErrMsg(task tasksch.ITask) (err error) {
|
||||
var resultL []*SyncErrResult
|
||||
err = fmt.Errorf(utils.Format4Output(buildErrMsgJson(task), true))
|
||||
return makeSyncError(err)
|
||||
}
|
||||
|
||||
func buildErrMsgJson(task tasksch.ITask) (resultL []*SyncErrResult) {
|
||||
failedList := task.GetErrMsg()
|
||||
for _, v := range failedList {
|
||||
for _, vv := range v.([]*partner.StoreSkuInfoWithErr) {
|
||||
if vv.StoreSkuInfo != nil {
|
||||
result := &SyncErrResult{
|
||||
SkuID: vv.StoreSkuInfo.SkuID,
|
||||
StoreID: vv.StoreID,
|
||||
CategoryName: "",
|
||||
VendorID: vv.VendoreID,
|
||||
VendorSkuID: vv.StoreSkuInfo.VendorSkuID,
|
||||
NameID: vv.StoreSkuInfo.NameID,
|
||||
VendorPrice: vv.StoreSkuInfo.VendorPrice,
|
||||
SyncType: vv.SyncType,
|
||||
ErrMsg: vv.ErrMsg,
|
||||
}
|
||||
resultL = append(resultL, result)
|
||||
} else {
|
||||
result := &SyncErrResult{
|
||||
SkuID: 0,
|
||||
StoreID: vv.StoreID,
|
||||
CategoryName: vv.CategoryName,
|
||||
VendorID: vv.VendoreID,
|
||||
VendorSkuID: "",
|
||||
NameID: 0,
|
||||
VendorPrice: 0,
|
||||
SyncType: vv.SyncType,
|
||||
ErrMsg: vv.ErrMsg,
|
||||
}
|
||||
resultL = append(resultL, result)
|
||||
result := &SyncErrResult{
|
||||
SkuID: 0,
|
||||
StoreID: vv.StoreID,
|
||||
CategoryName: vv.CategoryName,
|
||||
VendorID: vv.VendoreID,
|
||||
VendorSkuID: "",
|
||||
NameID: 0,
|
||||
VendorPrice: 0,
|
||||
SyncType: vv.SyncType,
|
||||
ErrMsg: vv.ErrMsg,
|
||||
}
|
||||
if vv.StoreSkuInfo != nil {
|
||||
result.SkuID = vv.StoreSkuInfo.SkuID
|
||||
result.CategoryName = ""
|
||||
result.VendorSkuID = vv.StoreSkuInfo.VendorSkuID
|
||||
result.NameID = vv.StoreSkuInfo.NameID
|
||||
result.VendorPrice = vv.StoreSkuInfo.VendorPrice
|
||||
}
|
||||
resultL = append(resultL, result)
|
||||
}
|
||||
}
|
||||
err = fmt.Errorf(utils.Format4Output(resultL, true))
|
||||
return makeSyncError(err)
|
||||
return resultL
|
||||
}
|
||||
|
||||
func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) {
|
||||
@@ -827,10 +827,9 @@ func GetTimeMixByInt(begin1, end1, begin2, end2 int16) (beginAt, endAt int16) {
|
||||
return beginAt, endAt
|
||||
}
|
||||
|
||||
func WirteToExcelBySyncFailed(task tasksch.ITask, ctx *jxcontext.Context) (err error) {
|
||||
func WirteToExcelBySyncFailed(task tasksch.ITask) (downloadURL, fileName string, err error) {
|
||||
var (
|
||||
sheetList1 []*excel.Obj2ExcelSheetConfig
|
||||
downloadURL1, fileName1 string
|
||||
sheetList1 []*excel.Obj2ExcelSheetConfig
|
||||
)
|
||||
syncErrResultLock.syncErrResult = syncErrResultLock.syncErrResult[0:0]
|
||||
failedList := task.GetErrMsg()
|
||||
@@ -860,21 +859,15 @@ func WirteToExcelBySyncFailed(task tasksch.ITask, ctx *jxcontext.Context) (err e
|
||||
}
|
||||
sheetList1 = append(sheetList1, excelConf1)
|
||||
if excelConf1 != nil {
|
||||
downloadURL1, fileName1, err = jxutils.UploadExeclAndPushMsg(sheetList1, time.Now().Format("200601021504")+"同步错误返回")
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: download is [%v]", downloadURL1)
|
||||
downloadURL, fileName, err = jxutils.UploadExeclAndPushMsg(sheetList1, time.Now().Format("200601021504")+"同步错误返回")
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: download is [%v]", downloadURL)
|
||||
} else {
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!")
|
||||
}
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName1, err)
|
||||
} else {
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||
noticeMsg := fmt.Sprintf("[详情点我]path1=%s\n", downloadURL1)
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, authInfo.UserID, "同步错误返回", noticeMsg)
|
||||
baseapi.SugarLogger.Debugf("WriteToExcel:upload %s success, downloadURL1:%s", fileName1, downloadURL1)
|
||||
}
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName, err)
|
||||
}
|
||||
return err
|
||||
return downloadURL, fileName, err
|
||||
}
|
||||
|
||||
func (d *SyncErrResultLock) AppendData(syncErrResult SyncErrResult) {
|
||||
|
||||
@@ -83,17 +83,21 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
|
||||
var failedList []*partner.StoreSkuInfoWithErr
|
||||
if model.IsSyncStatusDelete(catInfo.CatSyncStatus) { // 删除
|
||||
if model.IsSyncStatusDelete(catInfo.CatSyncStatus) && !dao.IsVendorThingIDEmpty(catInfo.VendorCatID) {
|
||||
failedList, err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID, level)
|
||||
err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID, level)
|
||||
if err != nil && handler.IsErrCategoryNotExist(err) {
|
||||
err = nil
|
||||
} else if err != nil && !handler.IsErrCategoryNotExist(err) {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, vendorID, "删除分类")
|
||||
}
|
||||
}
|
||||
} else if model.IsSyncStatusNew(catInfo.CatSyncStatus) { // 新增
|
||||
failedList, err = handler.CreateStoreCategory(ctx, storeID, vendorStoreID, catInfo)
|
||||
err = handler.CreateStoreCategory(ctx, storeID, vendorStoreID, catInfo)
|
||||
if err != nil && handler.IsErrCategoryExist(err) {
|
||||
if cat, err2 := handler.GetStoreCategory(ctx, storeID, vendorStoreID, catInfo.Name); err2 == nil {
|
||||
catInfo.VendorCatID = cat.VendorCatID
|
||||
err = nil
|
||||
} else if err != nil && !handler.IsErrCategoryExist(err) {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, vendorID, "新增分类")
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
@@ -104,9 +108,11 @@ func SyncStoreCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
|
||||
}
|
||||
}
|
||||
} else if model.IsSyncStatusUpdate(catInfo.CatSyncStatus) { // 修改
|
||||
failedList, err = handler.UpdateStoreCategory(ctx, storeID, vendorStoreID, catInfo)
|
||||
err = handler.UpdateStoreCategory(ctx, storeID, vendorStoreID, catInfo)
|
||||
if err == nil {
|
||||
updateFields = append(updateFields, idFieldName)
|
||||
} else {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(nil, err, storeID, vendorID, "修改分类")
|
||||
}
|
||||
}
|
||||
if len(failedList) > 0 {
|
||||
@@ -797,7 +803,7 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
|
||||
task4Delete := tasksch.NewParallelTask(fmt.Sprintf("删除商家分类,level:%d", level), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
cat := batchItemList[0].(*partner.BareCategoryInfo)
|
||||
_, err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, cat.VendorCatID, level)
|
||||
err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, cat.VendorCatID, level)
|
||||
return nil, err
|
||||
}, levelCat2Delete)
|
||||
tasksch.HandleTask(task4Delete, task, true).Run()
|
||||
|
||||
Reference in New Issue
Block a user