提交 dedb7743 作者: 史连宁

压缩图片路径转换

上级 c14fa2f0
......@@ -38,37 +38,25 @@ func LocalImageFileCheck(provId, beginDate, endDate, fileDir string, threadNum i
return "", "", 0
}
needDownChan := make(chan datImage, allCount)
var needDownList []datImage
bar := progressbar.Default(allCount)
go func() {
wg := sync.WaitGroup{}
wg.Add(len(datImageList))
p, _ := ants.NewPool(threadNum)
defer p.Release()
fmt.Printf("核验数据量:%d,协程池容量:%d\n", allCount, threadNum)
for _, task := range datImageList {
_ = p.Submit(func() {
defer wg.Done()
chackExistFile(needDownChan, task, fileDir)
})
}
wg.Wait()
close(needDownChan)
bar.ChangeMax(len(needDownChan))
}()
fmt.Printf("核验数据量:%d\n", allCount)
for _, task := range datImageList {
chackExistFile(&needDownList, task, fileDir)
}
bar := progressbar.Default(int64(len(needDownList)))
noImageChan := make(chan []interface{}, allCount)
wg := sync.WaitGroup{}
wg.Add(len(needDownList))
pd, _ := ants.NewPool(threadNumNet)
defer pd.Release()
fmt.Printf("下载协程池容量:%d\n", threadNumNet)
for task := range needDownChan {
wg.Add(1)
for _, task := range needDownList {
t := task
_ = pd.Submit(func() {
defer wg.Done()
dwonloadOne(noImageChan, task, fileDir)
dwonloadOne(noImageChan, t, fileDir)
bar.Add(1)
})
}
......@@ -79,7 +67,7 @@ func LocalImageFileCheck(provId, beginDate, endDate, fileDir string, threadNum i
return f, m, len(datImageList)
}
func chackExistFile(needDownChan chan datImage, task datImage, fileDir string) {
func chackExistFile(needDownList *[]datImage, task datImage, fileDir string) {
originalPath := fmt.Sprintf("%s/%s", fileDir, strings.ReplaceAll(task.ImageCode, "?pa=Y", ""))
pressedPath := strings.ReplaceAll(originalPath, "original", "pressed")
task.noOriginal = false
......@@ -91,7 +79,7 @@ func chackExistFile(needDownChan chan datImage, task datImage, fileDir string) {
task.noPressed = true
}
if task.noOriginal || task.noPressed {
needDownChan <- task
*needDownList = append(*needDownList, task)
}
}
......@@ -99,13 +87,13 @@ func dwonloadOne(noImageChan chan []interface{}, task datImage, fileDir string)
originalPath := fmt.Sprintf("%s/%s", fileDir, strings.ReplaceAll(task.ImageCode, "?pa=Y", ""))
pressedPath := strings.ReplaceAll(originalPath, "original", "pressed")
if task.noOriginal {
task.noOriginal = downOriginalFile(originalPath, task)
task.noOriginal = !downOriginalFile(originalPath, task)
}
if task.noPressed {
task.noPressed = downPressedFile(pressedPath, task, task.noOriginal, originalPath)
task.noPressed = !downPressedFile(pressedPath, task, task.noOriginal, originalPath)
}
if task.noOriginal || task.noPressed {
noImageChan <- []interface{}{task.ImageID, task.noOriginal, task.noPressed, task.ImageCode, task.OriginUrl.String}
noImageChan <- []interface{}{task.ImageID, !task.noOriginal, !task.noPressed, task.ImageCode, task.OriginUrl.String}
}
}
......@@ -166,11 +154,14 @@ func downOriginalFile(savePath string, di datImage) bool {
}
func downPressedFile(savePath string, di datImage, noOriginal bool, originalPath string) bool {
filePath := strings.ReplaceAll(di.ImageCode, "original", "pressed")
fileNameIdx := strings.LastIndex(filePath, "/") + 1
fileName := filePath[fileNameIdx:]
err := downRemoteFile(
savePath,
fmt.Sprintf(
"https://iotimage.pestiot.com/iotImage/%s",
strings.ReplaceAll(di.ImageCode, "original", "pressed")))
strings.ReplaceAll(filePath, fileName, "p"+fileName)))
if err == nil {
return true
}
......@@ -195,11 +186,20 @@ func downRemoteFile(savePath, url string) error {
if response.StatusCode != http.StatusOK {
return errors.New(fmt.Sprintf("[DownloadError][%d]%s", response.StatusCode, response.String()))
}
spIdx := strings.LastIndexByte(savePath, '/')
err = os.MkdirAll(savePath[:spIdx], os.ModeDir)
if err != nil {
return err
}
err = response.DownloadToFile(savePath)
return err
if err != nil {
return err
}
return nil
}
func genNoImageDataReport(noImageChan chan []interface{}, taskName string) (filepath, msg string) {
fmt.Printf("生成报告,%d条", len(noImageChan))
if len(noImageChan) > 0 {
xlsx := excelize.NewFile()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论