Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pestiot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
史连宁
pestiot
Commits
dedb7743
提交
dedb7743
authored
4月 17, 2024
作者:
史连宁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
压缩图片路径转换
上级
c14fa2f0
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
26 行增加
和
26 行删除
+26
-26
localImageFileCheck.go
solutions/localImageFileCheck.go
+26
-26
没有找到文件。
solutions/localImageFileCheck.go
浏览文件 @
dedb7743
...
...
@@ -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
)
fmt
.
Printf
(
"核验数据量:%d
\n
"
,
allCount
)
for
_
,
task
:=
range
datImageList
{
_
=
p
.
Submit
(
func
()
{
defer
wg
.
Done
()
chackExistFile
(
needDownChan
,
task
,
fileDir
)
})
chackExistFile
(
&
needDownList
,
task
,
fileDir
)
}
wg
.
Wait
()
close
(
needDownChan
)
bar
.
ChangeMax
(
len
(
needDownChan
))
}()
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
,
t
ask
,
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
(
needDown
Chan
chan
datImage
,
task
datImage
,
fileDir
string
)
{
func
chackExistFile
(
needDown
List
*
[]
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
)
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论