商品详情描述图片加入DataResource管理,老数据还未迁移

This commit is contained in:
gazebo
2019-09-26 20:55:08 +08:00
parent 998c087d9f
commit 8a1d364e4e
15 changed files with 141 additions and 80 deletions

View File

@@ -5,7 +5,6 @@ import (
"strings"
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
@@ -76,7 +75,7 @@ func getMimeTypeFromURL(resourceURL string) (mimeType string) {
return mimeType
}
func RegisterDataResource(ctx *jxcontext.Context, name, resourceURL, mimeType, hashCode string, resBinary []byte, isUpload2Vendor, isAsync bool) (dataRes *model.DataResource, err error) {
func RegisterDataResource(ctx *jxcontext.Context, name, resourceURL, mimeType, hashCode string, resBinary []byte, imgType int, isAsync bool) (dataRes *model.DataResource, err error) {
if model.ValidMimeTypes[mimeType] == nil {
return nil, fmt.Errorf("MIME type:%s非法", mimeType)
}
@@ -85,7 +84,7 @@ func RegisterDataResource(ctx *jxcontext.Context, name, resourceURL, mimeType, h
HashCode: hashCode,
ResourceType: mimeType,
MainURL: resourceURL,
IsVendor: int8(utils.Bool2Int(isUpload2Vendor)),
IsVendor: int8(imgType),
}
vendorID := jxutils.GuessDataResourceVendor(resourceURL)
@@ -105,14 +104,14 @@ func RegisterDataResource(ctx *jxcontext.Context, name, resourceURL, mimeType, h
}
return dataRes, err
}
if isUpload2Vendor {
if imgType > 0 {
// 忽略上传错误
UploadImage2Vendors(ctx, nil, dataRes, resBinary, isAsync)
}
return dataRes, err
}
func TryRegisterDataResource(ctx *jxcontext.Context, name, resourceURL string, isAllowDownLoad, isUpload2Vendor, isAsync bool) (dataRes *model.DataResource, err error) {
func TryRegisterDataResource(ctx *jxcontext.Context, name, resourceURL string, isAllowDownLoad bool, imgType int, isAsync bool) (dataRes *model.DataResource, err error) {
dataRes = &model.DataResource{
MainURL: resourceURL,
}
@@ -138,7 +137,7 @@ func TryRegisterDataResource(ctx *jxcontext.Context, name, resourceURL string, i
} else {
hashCode = value.(string)
}
return RegisterDataResource(ctx, name, resourceURL, getMimeTypeFromURL(resourceURL), hashCode, resBinary, isUpload2Vendor, isAsync)
return RegisterDataResource(ctx, name, resourceURL, getMimeTypeFromURL(resourceURL), hashCode, resBinary, imgType, isAsync)
}
func GetDataResource(ctx *jxcontext.Context, hashCode string) (resourceURL string, err error) {
@@ -185,7 +184,7 @@ func UploadImage2Vendors(ctx *jxcontext.Context, parentTask tasksch.ITask, dataR
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
vendorID := batchItemList[0].(int)
if handler := partner.GetPurchasePlatformFromVendorID(vendorID); handler != nil {
imgHint, err2 := handler.UploadImg(ctx, dataRes.MainURL, imgData, imgName)
imgHint, err2 := handler.UploadImg(ctx, dataRes.MainURL, imgData, imgName, int(dataRes.IsVendor))
if err = err2; err == nil {
retVal = [][]interface{}{
[]interface{}{