- 将skuName中的图片外移至dataResource
This commit is contained in:
@@ -18,19 +18,14 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
"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"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"github.com/qiniu/api.v7/storage"
|
||||
)
|
||||
|
||||
const (
|
||||
qiniuTokenExpires = 300 // 七牛TOKEN有效时间,5分钟
|
||||
|
||||
SendMsgTypeOpenStoreRequest = "openStoreRequest"
|
||||
)
|
||||
|
||||
@@ -51,14 +46,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
type UploadResTokenInfo struct {
|
||||
Token string `json:"token,omitempty"`
|
||||
Expires uint64 `json:"expires,omitempty"`
|
||||
FileName string `json:"fileName,omitempty"`
|
||||
Hit bool `json:"hit,omitempty"`
|
||||
Img string `json:"img,omitempty"`
|
||||
}
|
||||
|
||||
func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||
buildTimeStr := ""
|
||||
if !utils.IsTimeZero(buildTime) {
|
||||
@@ -108,71 +95,6 @@ func GetServiceInfo(ctx *jxcontext.Context) interface{} {
|
||||
return serviceInfo
|
||||
}
|
||||
|
||||
func GetQiniuUploadToken(ctx *jxcontext.Context, suffix, hashCode string) (upTokenInfo *UploadResTokenInfo, err error) {
|
||||
imgURL := ""
|
||||
if hashCode != "" {
|
||||
imgURL, _ = GetDataResource(ctx, hashCode)
|
||||
}
|
||||
|
||||
putPolicy := storage.PutPolicy{
|
||||
Scope: globals.QiniuBucket,
|
||||
Expires: qiniuTokenExpires,
|
||||
}
|
||||
upTokenInfo = &UploadResTokenInfo{
|
||||
Token: putPolicy.UploadToken(api.QiniuAPI),
|
||||
Expires: putPolicy.Expires,
|
||||
FileName: jxutils.GenPicFileName(suffix),
|
||||
Hit: imgURL != "",
|
||||
Img: imgURL,
|
||||
}
|
||||
return upTokenInfo, err
|
||||
}
|
||||
|
||||
func RegisterDataResource(ctx *jxcontext.Context, name, resourceURL, mimeType, hashCode string) (dataRes *model.DataResource, err error) {
|
||||
if model.ValideMimeTypes[mimeType] == 0 {
|
||||
return nil, fmt.Errorf("MIME type:%s非法", mimeType)
|
||||
}
|
||||
dataRes = &model.DataResource{
|
||||
Name: name,
|
||||
HashCode: hashCode,
|
||||
ResoureType: mimeType,
|
||||
MainURL: resourceURL,
|
||||
}
|
||||
vendorID := jxutils.GuessDataResourceVendor(resourceURL)
|
||||
switch vendorID {
|
||||
case model.VendorIDQiNiuCloud:
|
||||
dataRes.QiniuURL = resourceURL
|
||||
case model.VendorIDEBAI:
|
||||
dataRes.EbaiURL = resourceURL
|
||||
case model.VendorIDMTWM:
|
||||
dataRes.MtwmURL = resourceURL
|
||||
}
|
||||
|
||||
dao.WrapAddIDCULEntity(dataRes, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(dao.GetDB(), dataRes); err != nil {
|
||||
dataRes = nil
|
||||
}
|
||||
return dataRes, err
|
||||
}
|
||||
|
||||
func GetDataResource(ctx *jxcontext.Context, hashCode string) (resourceURL string, err error) {
|
||||
db := dao.GetDB()
|
||||
dataRes, err := dao.GetDataResource(db, hashCode, "")
|
||||
if err != nil {
|
||||
if dao.IsNoRowsError(err) {
|
||||
skuName, err2 := dao.GetSkuNameByHashCode(db, hashCode)
|
||||
if err = err2; err == nil {
|
||||
resourceURL = skuName.Img
|
||||
} else if dao.IsNoRowsError(err) {
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resourceURL = dataRes.MainURL
|
||||
}
|
||||
return resourceURL, err
|
||||
}
|
||||
|
||||
func GetPlaces(ctx *jxcontext.Context, keyword string, includeDisabled bool, params map[string]interface{}) ([]*model.Place, error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
|
||||
Reference in New Issue
Block a user