139 lines
3.0 KiB
Go
139 lines
3.0 KiB
Go
package cms
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"sync"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
|
"git.rosy.net.cn/jx-callback/business/partner"
|
|
)
|
|
|
|
type SyncErrResult struct {
|
|
SkuID int `json:"商品ID"`
|
|
CategoryName string `json:"分类名"`
|
|
StoreID int `json:"门店ID"`
|
|
VendorName string `json:"平台名"`
|
|
VendorSkuID string `json:"平台商品ID"`
|
|
NameID int `json:"商品nameID"`
|
|
VendorPrice int64 `json:"平台价"`
|
|
SyncType string `json:"同步类型"`
|
|
ErrMsg string `json:"错误信息"`
|
|
}
|
|
|
|
type SyncErrResultLock struct {
|
|
syncErrResult []SyncErrResult
|
|
locker sync.RWMutex
|
|
}
|
|
|
|
type LoopStoreMapInfo struct {
|
|
VendorID int
|
|
// StoreMapList []*model.StoreMap
|
|
}
|
|
|
|
type VendorSync struct {
|
|
}
|
|
|
|
type SyncError struct {
|
|
Original error `json:"original"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type SpecSyncError struct {
|
|
SpecErr error `json:"specErr"`
|
|
}
|
|
|
|
// 对于多门店平台接口的通用处理
|
|
type MultiStoreHandlerWrapper struct {
|
|
partner.IMultipleStoresHandler
|
|
}
|
|
|
|
// 对于单门店平台接口的通用处理
|
|
type SingleStoreHandlerWrapper struct {
|
|
partner.ISingleStoreHandler
|
|
}
|
|
|
|
var (
|
|
CurVendorSync VendorSync
|
|
)
|
|
|
|
var (
|
|
ErrHaveNotImplementedYet = errors.New("还没有实现")
|
|
ErrEntityNotExist = errors.New("找不到相应实体")
|
|
SyncErrResultTitle = []string{
|
|
"商品ID",
|
|
"分类名",
|
|
"门店ID",
|
|
"平台名",
|
|
"平台商品ID",
|
|
"商品nameID",
|
|
"平台价",
|
|
"同步类型",
|
|
"错误信息",
|
|
}
|
|
syncErrResultLock SyncErrResultLock
|
|
)
|
|
|
|
func buildErrMsg(task tasksch.ITask) (err error) {
|
|
err = fmt.Errorf(utils.Format4Output(buildErrMsgJson(task), true))
|
|
return makeSpecSyncError(err)
|
|
}
|
|
|
|
func buildErrMsgJson(task tasksch.ITask) (resultL []*SyncErrResult) {
|
|
failedList := task.GetFailedList()
|
|
for _, v := range failedList {
|
|
for _, vv := range v.([]*partner.StoreSkuInfoWithErr) {
|
|
result := &SyncErrResult{
|
|
SkuID: 0,
|
|
StoreID: vv.StoreID,
|
|
CategoryName: vv.CategoryName,
|
|
VendorName: vv.VendoreName,
|
|
VendorSkuID: "",
|
|
NameID: 0,
|
|
VendorPrice: 0,
|
|
SyncType: vv.SyncType,
|
|
ErrMsg: vv.ErrMsg,
|
|
}
|
|
if vv.StoreSkuInfo != nil {
|
|
result.SkuID = vv.StoreSkuInfo.SkuID
|
|
result.VendorSkuID = vv.StoreSkuInfo.VendorSkuID
|
|
result.NameID = vv.StoreSkuInfo.NameID
|
|
result.VendorPrice = vv.StoreSkuInfo.VendorPrice
|
|
}
|
|
resultL = append(resultL, result)
|
|
}
|
|
}
|
|
return resultL
|
|
}
|
|
|
|
func makeSyncError(err error) (newErr error) {
|
|
if err != nil {
|
|
if _, ok := err.(*SyncError); !ok {
|
|
return &SyncError{
|
|
Original: err,
|
|
}
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func makeSpecSyncError(err error) (newErr error) {
|
|
if err != nil {
|
|
if _, ok := err.(*SpecSyncError); !ok {
|
|
return &SpecSyncError{
|
|
SpecErr: err,
|
|
}
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (e *SpecSyncError) Error() string {
|
|
return e.SpecErr.Error()
|
|
}
|
|
|
|
func (e *SyncError) Error() string {
|
|
return fmt.Sprintf("本地数据修改成功,但同步失败,请根据错误提示处理!,同步错误信息:%s", e.Original.Error())
|
|
}
|