up
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"image"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -1113,12 +1114,12 @@ func CheckImages(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hin
|
||||
rootTask := tasksch.NewSeqTask("检查图片的有效性", ctx,
|
||||
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0: // 计算SkuName中缺失的hashCode(注意是DescImg不是Img)
|
||||
case 0: // 检查图片的格式与大小
|
||||
var imgList []*model.DataResource
|
||||
if err = dao.GetRows(db, &imgList, `
|
||||
SELECT t1.*
|
||||
FROM data_resource t1
|
||||
WHERE t1.use_type = 1
|
||||
WHERE t1.use_type = 1 AND t1.remark <> ''
|
||||
`); err == nil && len(imgList) > 0 {
|
||||
calcTask := tasksch.NewParallelTask("检查京西图片的有效性",
|
||||
tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError).SetParallelCount(5), ctx,
|
||||
@@ -1128,7 +1129,13 @@ func CheckImages(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hin
|
||||
if err = err2; err == nil {
|
||||
errMsg := ""
|
||||
if hashCode != dataRes.HashCode {
|
||||
errMsg += fmt.Sprintf("hashcode:%s", hashCode)
|
||||
errMsg = fmt.Sprintf("hashcode:%s", hashCode)
|
||||
dataRes.HashCode = hashCode
|
||||
}
|
||||
resType := http.DetectContentType(binaryData)
|
||||
if resType != dataRes.ResourceType {
|
||||
errMsg += "," + resType
|
||||
dataRes.ResourceType = resType
|
||||
}
|
||||
var img image.Image
|
||||
if dataRes.ResourceType == "image/png" {
|
||||
@@ -1137,13 +1144,17 @@ func CheckImages(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hin
|
||||
img, err = jpeg.Decode(bytes.NewReader(binaryData))
|
||||
}
|
||||
if err == nil {
|
||||
if img.Bounds().Dx() != 800 || img.Bounds().Dy() != 800 {
|
||||
errMsg += fmt.Sprintf("size:%dx%d", img.Bounds().Dx(), img.Bounds().Dy())
|
||||
if img != nil {
|
||||
if img.Bounds().Dx() != 800 || img.Bounds().Dy() != 800 {
|
||||
errMsg += fmt.Sprintf(",size:%dx%d", img.Bounds().Dx(), img.Bounds().Dy())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errMsg += "," + err.Error()
|
||||
}
|
||||
if errMsg != "" {
|
||||
dataRes.Remark += errMsg
|
||||
dao.UpdateEntity(db, dataRes, "Remark")
|
||||
dataRes.Remark = errMsg
|
||||
dao.UpdateEntity(dao.GetDB(), dataRes, "Remark", "ResourceType", "HashCode")
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
@@ -1151,19 +1162,24 @@ func CheckImages(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hin
|
||||
tasksch.HandleTask(calcTask, task, false).Run()
|
||||
_, err = calcTask.GetResult(0)
|
||||
}
|
||||
case 1: // 从SkuName添加缺失的图片至DataResource
|
||||
case 1: // 检查京东商品图片
|
||||
skuNameInfo, err2 := cms.GetSkuNames(ctx, "", false, map[string]interface{}{}, 0, -1)
|
||||
if err = err2; err == nil && len(skuNameInfo.SkuNames) > 0 {
|
||||
calcTask := tasksch.NewParallelTask("检查京西图片的有效性",
|
||||
tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError).SetParallelCount(5), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
skuName := batchItemList[0].(*model.SkuNameExt)
|
||||
if len(skuName.Skus) > 0 {
|
||||
imgList, err2 := api.JdAPI.GetSkuPageImageInfo(skuName.Skus[0].JdID)
|
||||
if err = err2; err == nil {
|
||||
if len(imgList) == 0 {
|
||||
err = fmt.Errorf("skuName:%d, sku:%d, jdid:%d, 没有图片", skuName.ID, skuName.Skus[0].ID, skuName.Skus[0].JdID)
|
||||
for _, sku := range skuName.Skus {
|
||||
if sku.JdID != 0 {
|
||||
imgList, err2 := api.JdAPI.GetSkuPageImageInfo(sku.JdID)
|
||||
if err = err2; err == nil {
|
||||
if len(imgList) == 0 {
|
||||
err = fmt.Errorf("skuName:%d, sku:%d, jdid:%d, 没有图片", skuName.ID, sku.ID, sku.JdID)
|
||||
skuName.ImgHashCode = "np"
|
||||
dao.UpdateEntity(dao.GetDB(), &skuName.SkuName, "ImgHashCode")
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
|
||||
Reference in New Issue
Block a user