同步错误返回

This commit is contained in:
苏尹岚
2020-01-09 14:02:32 +08:00
parent 77e4fb078f
commit e6c59c4850
8 changed files with 176 additions and 198 deletions

View File

@@ -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) {