同步错误返回
This commit is contained in:
@@ -3,9 +3,15 @@ package cms
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
@@ -15,6 +21,19 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/globals/refutil"
|
||||
)
|
||||
|
||||
type SyncErrResult struct {
|
||||
SkuID int `json:"商品ID"`
|
||||
VendorSkuID string `json:"平台商品ID"`
|
||||
NameID int `json:"商品nameID"`
|
||||
VendorPrice int64 `json:"平台价"`
|
||||
ErrMsg string `json:"错误信息"`
|
||||
}
|
||||
|
||||
type SyncErrResultLock struct {
|
||||
syncErrResult []SyncErrResult
|
||||
locker sync.RWMutex
|
||||
}
|
||||
|
||||
type LoopStoreMapInfo struct {
|
||||
VendorID int
|
||||
StoreMapList []*model.StoreMap
|
||||
@@ -45,6 +64,14 @@ var (
|
||||
var (
|
||||
ErrHaveNotImplementedYet = errors.New("还没有实现")
|
||||
ErrEntityNotExist = errors.New("找不到相应实体")
|
||||
SyncErrResultTitle = []string{
|
||||
"商品ID",
|
||||
"平台商品ID",
|
||||
"商品nameID",
|
||||
"平台价",
|
||||
"错误信息",
|
||||
}
|
||||
syncErrResultLock SyncErrResultLock
|
||||
)
|
||||
|
||||
func (p *MultiStoreHandlerWrapper) DeleteCategory(db *dao.DaoDB, cat *model.SkuCategory, userName string) (err error) {
|
||||
@@ -540,9 +567,9 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN
|
||||
taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID])
|
||||
}
|
||||
task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList)
|
||||
task.SetFinishHook(task)
|
||||
failedList := task.GetErrMsg()
|
||||
|
||||
task.SetFinishHook(func(task tasksch.ITask, ctx *jxcontext.Context) {
|
||||
err = WirteToExcelBySyncFailed(task, ctx)
|
||||
})
|
||||
tasksch.HandleTask(task, nil, isManageIt).Run()
|
||||
if !isAsync {
|
||||
resultList, err2 := task.GetResult(0)
|
||||
@@ -698,3 +725,55 @@ func GetTimeMixByInt(begin1, end1, begin2, end2 int16) (beginAt, endAt int16) {
|
||||
}
|
||||
return beginAt, endAt
|
||||
}
|
||||
|
||||
func WirteToExcelBySyncFailed(task tasksch.ITask, ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
sheetList1 []*excel.Obj2ExcelSheetConfig
|
||||
downloadURL1, fileName1 string
|
||||
)
|
||||
syncErrResultLock.syncErrResult = syncErrResultLock.syncErrResult[0:0]
|
||||
failedList := task.GetErrMsg()
|
||||
if len(failedList) == 0 {
|
||||
return
|
||||
}
|
||||
for _, v := range failedList {
|
||||
for _, vv := range v.([]*partner.StoreSkuInfoWithErr) {
|
||||
result := SyncErrResult{
|
||||
SkuID: vv.StoreSkuInfo.SkuID,
|
||||
VendorSkuID: vv.StoreSkuInfo.VendorSkuID,
|
||||
NameID: vv.StoreSkuInfo.NameID,
|
||||
VendorPrice: vv.StoreSkuInfo.VendorPrice,
|
||||
ErrMsg: vv.ErrMsg,
|
||||
}
|
||||
syncErrResultLock.AppendData(result)
|
||||
}
|
||||
}
|
||||
excelConf1 := &excel.Obj2ExcelSheetConfig{
|
||||
Title: "同步错误",
|
||||
Data: syncErrResultLock.syncErrResult,
|
||||
CaptionList: SyncErrResultTitle,
|
||||
}
|
||||
sheetList1 = append(sheetList1, excelConf1)
|
||||
if excelConf1 != nil {
|
||||
downloadURL1, fileName1, err = jxutils.UploadExeclAndPushMsg(sheetList1, time.Now().Format("2006-01-02")+"同步错误返回")
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: download is [%v]", downloadURL1)
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *SyncErrResultLock) AppendData(syncErrResult SyncErrResult) {
|
||||
d.locker.Lock()
|
||||
defer d.locker.Unlock()
|
||||
d.syncErrResult = append(d.syncErrResult, syncErrResult)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user