Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pestiot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
史连宁
pestiot
Commits
e09266a3
提交
e09266a3
authored
2月 20, 2024
作者:
史连宁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
核查本地图片
上级
fd4382bb
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
295 行增加
和
20 行删除
+295
-20
go.mod
go.mod
+10
-3
go.sum
go.sum
+23
-3
main.go
main.go
+22
-8
countEquipmentAvailability.go
solutions/countEquipmentAvailability.go
+8
-1
localImageFileCheck.go
solutions/localImageFileCheck.go
+232
-0
updateUtils.go
utils/updateUtils.go
+0
-5
没有找到文件。
go.mod
浏览文件 @
e09266a3
...
...
@@ -5,7 +5,9 @@ go 1.19
require (
github.com/deckarep/golang-set v1.8.0
github.com/denisenkom/go-mssqldb v0.12.3
github.com/disintegration/imaging v1.6.2
github.com/levigross/grequests v0.0.0-20221222020224-9eee758d18d5
github.com/schollz/progressbar/v3 v3.14.1
github.com/xuri/excelize/v2 v2.8.0
)
...
...
@@ -13,12 +15,17 @@ require (
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/xuri/efp v0.0.0-20230802181842-ad255f2331ca // indirect
github.com/xuri/nfp v0.0.0-20230819163627-dc951e3ffe1a // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/text v0.13.0 // indirect
)
go.sum
浏览文件 @
e09266a3
...
...
@@ -8,6 +8,8 @@ github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsP
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
github.com/denisenkom/go-mssqldb v0.12.3 h1:pBSGx9Tq67pBOTLmxNuirNTeB8Vjmf886Kx+8Y+8shw=
github.com/denisenkom/go-mssqldb v0.12.3/go.mod h1:k0mtMFOnU+AihqFxPMiF05rtiDrorD1Vrm1KEz5hxDo=
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
...
...
@@ -15,8 +17,12 @@ github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/levigross/grequests v0.0.0-20221222020224-9eee758d18d5 h1:AsF9Q1mQoyLv0HzvHFW7O+19dHilOcKU74k7E5ufI1A=
github.com/levigross/grequests v0.0.0-20221222020224-9eee758d18d5/go.mod h1:XfzeIE2WC7CGDhlZJY/rUdqUPy0IPcyI6hoIjhAMNbQ=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
...
...
@@ -28,8 +34,13 @@ github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/richardlehane/msoleps v1.0.3 h1:aznSZzrwYRl3rLKRT3gUk9am7T/mLNSnJINvN0AQoVM=
github.com/richardlehane/msoleps v1.0.3/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/schollz/progressbar/v3 v3.14.1 h1:VD+MJPCr4s3wdhTc7OEJ/Z3dAeBzJ7yKH/P4lC5yRTI=
github.com/schollz/progressbar/v3 v3.14.1/go.mod h1:Zc9xXneTzWXF81TGoqL71u0sBPjULtEHYtj/WVgVy8E=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
...
...
@@ -45,8 +56,10 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.11.0 h1:ds2RoQvBvYTiJkwpSFDwCcDFNX7DqjL2WsUgTNk0Ooo=
golang.org/x/image v0.11.0/go.mod h1:bglhjqbqVuEb9e9+eNR45Jfu7D+T4Qan+NhQk8Ck2P8=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
...
...
@@ -59,8 +72,9 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
...
...
@@ -72,21 +86,27 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
...
...
main.go
浏览文件 @
e09266a3
...
...
@@ -7,6 +7,7 @@ import (
"pestiot/solutions"
"pestiot/utils"
"strings"
"time"
)
// 命令行接收参数
...
...
@@ -16,7 +17,9 @@ var (
endDate
string
devIds
string
solution
string
fileDir
string
mentioneds
string
threadNum
int
)
// 获取命令行参数
...
...
@@ -25,20 +28,23 @@ func getCmdParams() bool {
flag
.
StringVar
(
&
beginDate
,
"beginDate"
,
""
,
"开始时间(必填)(e.g., 2022-07-01)"
)
flag
.
StringVar
(
&
endDate
,
"endDate"
,
""
,
"结束时间(必填)(e.g., 2022-09-30)"
)
flag
.
StringVar
(
&
devIds
,
"devIds"
,
""
,
"设备编号(可选)(e.g., 129301230102,12039912093,21399422244)"
)
flag
.
StringVar
(
&
solution
,
"solution"
,
""
,
"解决方案(必填)(e.g., 01)
\n
01 计算设备可用率
\n
02 灯诱及性诱日统计"
)
flag
.
StringVar
(
&
solution
,
"solution"
,
""
,
"解决方案(必填)(e.g., 01)
\n
01 计算设备可用率
\n
02 灯诱及性诱日统计
\n
03 本地图片核查"
)
flag
.
StringVar
(
&
fileDir
,
"fileDir"
,
""
,
"文件路径(可选)(e.g., D:/iotImage)"
)
flag
.
IntVar
(
&
threadNum
,
"threadNum"
,
100
,
"并发线程数量(可选)(e.g., 100)"
)
flag
.
StringVar
(
&
mentioneds
,
"mentioneds"
,
""
,
"消息提醒人员(可选)(e.g., gpguo@jinhetech.com,eszhong@jinhetech.com)"
)
flag
.
Parse
()
if
provIds
==
""
||
beginDate
==
""
||
endDate
==
""
||
solution
==
""
{
fmt
.
Println
(
"必要参数缺失,请使用 -help 命令查看入参!"
)
return
false
}
else
if
solution
==
"03"
&&
fileDir
==
""
{
fmt
.
Println
(
"本地图片核查请配置文件路径 -fileDir!"
)
return
false
}
else
{
return
true
}
}
func
main
()
{
var
versionCode
int32
=
0
utils
.
CheckUpdate
(
versionCode
)
if
!
getCmdParams
()
{
return
...
...
@@ -56,16 +62,24 @@ func main() {
mentionedList
=
append
(
mentionedList
,
v
)
}
}
for
_
,
provId
:=
range
strings
.
Split
(
provIds
,
","
)
{
fmt
.
Println
(
provId
)
provIdList
:=
strings
.
Split
(
provIds
,
","
)
var
fileList
[][]
string
for
_
,
provId
:=
range
provIdList
{
prov
:=
provId
var
filepath
,
msg
string
if
solution
==
"01"
{
// 计算设备可用率
filepath
,
msg
=
solutions
.
CountEquipmentAvailability
(
prov
Id
,
beginDate
,
endDate
,
devSet
)
filepath
,
msg
=
solutions
.
CountEquipmentAvailability
(
prov
,
beginDate
,
endDate
,
devSet
)
}
else
if
solution
==
"02"
{
filepath
,
msg
=
solutions
.
LightAndSexLureStatistics
(
provId
,
beginDate
,
endDate
)
filepath
,
msg
=
solutions
.
LightAndSexLureStatistics
(
prov
,
beginDate
,
endDate
)
}
else
if
solution
==
"03"
{
filepath
,
msg
=
solutions
.
LocalImageFileCheck
(
prov
,
beginDate
,
endDate
,
fileDir
,
threadNum
)
}
if
filepath
!=
""
{
utils
.
WechatFileUpload
(
filepath
,
msg
,
&
mentionedList
,
nil
)
fileList
=
append
(
fileList
,
[]
string
{
filepath
,
msg
}
)
}
}
for
_
,
itm
:=
range
fileList
{
utils
.
WechatFileUpload
(
itm
[
0
],
itm
[
1
],
&
mentionedList
,
nil
)
time
.
Sleep
(
1
*
time
.
Second
)
}
}
solutions/countEquipmentAvailability.go
浏览文件 @
e09266a3
...
...
@@ -34,7 +34,14 @@ func CountEquipmentAvailability(provId, beginDate, endDate string, devSet mapset
columnList
=
append
(
columnList
,
eneity
.
Column
{
Name
:
v
,
Prop
:
v
})
}
dbInfo
:=
&
eneity
.
DbInfo
{
Server
:
static
.
Server
,
User
:
static
.
User
,
Password
:
static
.
Password
,
Port
:
int32
(
static
.
Port
),
Database
:
static
.
Database
,
Dbtype
:
static
.
Dbtype
}
dbInfo
:=
&
eneity
.
DbInfo
{
Server
:
static
.
Server
,
User
:
static
.
User
,
Password
:
static
.
Password
,
Port
:
int32
(
static
.
Port
),
Database
:
static
.
Database
,
Dbtype
:
static
.
Dbtype
,
}
db
,
err
:=
dbInfo
.
GetConnect
()
if
err
!=
nil
{
fmt
.
Println
(
"sql连接异常:"
,
err
)
...
...
solutions/localImageFileCheck.go
0 → 100644
浏览文件 @
e09266a3
package
solutions
import
(
"database/sql"
"errors"
"fmt"
"github.com/disintegration/imaging"
"github.com/levigross/grequests"
"github.com/schollz/progressbar/v3"
"github.com/xuri/excelize/v2"
"math"
"net/http"
"os"
"pestiot/eneity"
"pestiot/static"
"strings"
"sync"
"time"
)
type
datImage
struct
{
ImageID
int64
ImageCode
string
OriginUrl
sql
.
NullString
}
func
LocalImageFileCheck
(
provId
,
beginDate
,
endDate
,
fileDir
string
,
threadNum
int
)
(
filepath
,
msg
string
)
{
fmt
.
Printf
(
"开始核验T_Dat_Image_%s[%s~%s]的图片
\n
"
,
provId
,
beginDate
,
endDate
)
taskGroup
,
allCount
,
err
:=
getDBImageList
(
provId
,
beginDate
,
endDate
,
threadNum
)
if
err
!=
nil
{
fmt
.
Println
(
"获取数据异常!"
)
return
""
,
""
}
wg
:=
sync
.
WaitGroup
{}
wg
.
Add
(
len
(
taskGroup
))
noImageChan
:=
make
(
chan
[]
interface
{},
allCount
)
fmt
.
Printf
(
"核验数据量:%d,划分组数:%d
\n
"
,
allCount
,
len
(
taskGroup
))
bar
:=
progressbar
.
Default
(
allCount
)
for
_
,
tasks
:=
range
taskGroup
{
tasks
:=
tasks
go
func
()
{
defer
wg
.
Done
()
for
_
,
task
:=
range
tasks
{
originalPath
:=
fmt
.
Sprintf
(
"%s/%s"
,
fileDir
,
strings
.
ReplaceAll
(
task
.
ImageCode
,
"?pa=Y"
,
""
))
pressedPath
:=
strings
.
ReplaceAll
(
originalPath
,
"original"
,
"pressed"
)
noOriginal
:=
false
noPressed
:=
false
if
_
,
err
:=
os
.
Stat
(
originalPath
);
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
noOriginal
=
downOriginalFile
(
originalPath
,
task
)
}
if
_
,
err
:=
os
.
Stat
(
pressedPath
);
err
!=
nil
&&
os
.
IsNotExist
(
err
)
{
noPressed
=
downPressedFile
(
pressedPath
,
task
,
noOriginal
,
originalPath
)
}
if
noOriginal
||
noPressed
{
noImageChan
<-
[]
interface
{}{
task
.
ImageID
,
noOriginal
,
noPressed
,
task
.
ImageCode
,
task
.
OriginUrl
.
String
}
}
bar
.
Add
(
1
)
}
}()
}
wg
.
Wait
()
close
(
noImageChan
)
return
genNoImageDataReport
(
noImageChan
,
fmt
.
Sprintf
(
"%s(%s~%s)"
,
static
.
Citys
[
provId
],
beginDate
,
endDate
))
}
func
getDBImageList
(
provId
,
beginDate
,
endDate
string
,
threadNum
int
)
([][]
datImage
,
int64
,
error
)
{
dbInfo
:=
&
eneity
.
DbInfo
{
Server
:
static
.
Server
,
User
:
static
.
User
,
Password
:
static
.
Password
,
Port
:
int32
(
static
.
Port
),
Database
:
static
.
Database
,
Dbtype
:
static
.
Dbtype
,
}
db
,
err
:=
dbInfo
.
GetConnect
()
if
err
!=
nil
{
fmt
.
Println
(
"sql连接异常:"
,
err
)
return
nil
,
0
,
err
}
sqllan
:=
fmt
.
Sprintf
(
"select ImageID, ImageCode, originurl from T_Dat_Image_%s WITH(NOLOCK) where DataYMD >= '%s' and DataYMD <= '%s'"
,
provId
,
beginDate
,
endDate
)
fmt
.
Println
(
sqllan
)
rows
,
err
:=
db
.
Query
(
sqllan
)
if
err
!=
nil
{
fmt
.
Printf
(
"获取(T_Dat_Image_%s[%s~%s])图片数据异常:%s
\n
"
,
provId
,
beginDate
,
endDate
,
err
.
Error
())
return
nil
,
0
,
err
}
else
{
fmt
.
Println
(
"获取到数据"
)
}
var
datImageList
[]
datImage
for
rows
.
Next
()
{
di
:=
datImage
{}
err
:=
rows
.
Scan
(
&
di
.
ImageID
,
&
di
.
ImageCode
,
&
di
.
OriginUrl
)
if
err
!=
nil
{
fmt
.
Printf
(
"(T_Dat_Image_%s[%s~%s])数据rows.Scan异常:%s
\n
"
,
provId
,
beginDate
,
endDate
,
err
.
Error
())
return
nil
,
0
,
err
}
datImageList
=
append
(
datImageList
,
di
)
}
err
=
db
.
Close
()
if
err
!=
nil
{
fmt
.
Println
(
"数据库连接关闭异常:"
,
err
)
return
nil
,
0
,
err
}
batch
:=
len
(
datImageList
)
/
threadNum
return
splitSlice
(
datImageList
,
batch
+
1
),
int64
(
len
(
datImageList
)),
nil
}
func
downOriginalFile
(
savePath
string
,
di
datImage
)
bool
{
if
di
.
OriginUrl
.
Valid
{
err
:=
downRemoteFile
(
savePath
,
di
.
OriginUrl
.
String
)
if
err
==
nil
{
return
true
}
}
err
:=
downRemoteFile
(
savePath
,
fmt
.
Sprintf
(
"https://iotimage.pestiot.com/iotImage/%s"
,
di
.
ImageCode
))
if
err
==
nil
{
return
true
}
return
false
}
func
downPressedFile
(
savePath
string
,
di
datImage
,
noOriginal
bool
,
originalPath
string
)
bool
{
err
:=
downRemoteFile
(
savePath
,
fmt
.
Sprintf
(
"https://iotimage.pestiot.com/iotImage/%s"
,
strings
.
ReplaceAll
(
di
.
ImageCode
,
"original"
,
"pressed"
)))
if
err
==
nil
{
return
true
}
if
noOriginal
{
return
false
}
err
=
genThumbByOriginFile
(
savePath
,
originalPath
)
if
err
==
nil
{
return
true
}
return
false
}
func
downRemoteFile
(
savePath
,
url
string
)
error
{
response
,
err
:=
grequests
.
Get
(
url
,
&
grequests
.
RequestOptions
{
DialTimeout
:
10
*
time
.
Second
,
RequestTimeout
:
30
*
time
.
Second
,
})
if
err
!=
nil
{
return
errors
.
New
(
fmt
.
Sprintf
(
"[DownloadError]%s"
,
err
.
Error
()))
}
if
response
.
StatusCode
!=
http
.
StatusOK
{
return
errors
.
New
(
fmt
.
Sprintf
(
"[DownloadError][%d]%s"
,
response
.
StatusCode
,
response
.
String
()))
}
err
=
response
.
DownloadToFile
(
savePath
)
return
err
}
func
genNoImageDataReport
(
noImageChan
chan
[]
interface
{},
taskName
string
)
(
filepath
,
msg
string
)
{
if
len
(
noImageChan
)
>
0
{
xlsx
:=
excelize
.
NewFile
()
header
:=
[]
interface
{}{
"ImageID"
,
"原图"
,
"缩略图"
,
"ImageCode"
,
"OriginUrl"
}
err
:=
xlsx
.
SetSheetRow
(
"Sheet1"
,
"A1"
,
&
header
)
idx
:=
0
for
itm
:=
range
noImageChan
{
row
:=
fmt
.
Sprintf
(
"A%d"
,
idx
+
2
)
err
:=
xlsx
.
SetSheetRow
(
"Sheet1"
,
row
,
&
itm
)
if
err
!=
nil
{
fmt
.
Println
(
fmt
.
Sprintf
(
"插入行%s异常:"
,
row
),
err
)
}
idx
++
}
xlsxFilePath
:=
fmt
.
Sprintf
(
"./file/[result]%s图片未下载情况统计结果_%d.xlsx"
,
taskName
,
time
.
Now
()
.
Unix
())
err
=
xlsx
.
SaveAs
(
xlsxFilePath
)
if
err
!=
nil
{
fmt
.
Println
(
"保存excel异常:"
,
err
)
return
""
,
""
}
msg
:=
fmt
.
Sprintf
(
"%s图片存在未下载情况"
,
taskName
)
return
xlsxFilePath
,
msg
}
else
{
return
""
,
""
}
}
func
genThumbByOriginFile
(
savePath
,
originalPath
string
)
error
{
width
:=
400
height
:=
400
// 解码图像
img
,
err
:=
imaging
.
Open
(
originalPath
)
if
err
!=
nil
{
return
errors
.
New
(
fmt
.
Sprintf
(
"[OriginImg2ObjectError]%s"
,
err
.
Error
()))
}
// 获取图像尺寸
imgWidth
:=
img
.
Bounds
()
.
Dx
()
imgHeight
:=
img
.
Bounds
()
.
Dy
()
// 计算缩略图宽高
var
thumbWidth
,
thumbHeight
int
if
imgWidth
>
imgHeight
{
thumbWidth
=
width
thumbHeight
=
int
(
math
.
Floor
(
float64
(
imgHeight
*
width
)
/
float64
(
imgWidth
)))
}
else
{
thumbWidth
=
int
(
math
.
Floor
(
float64
(
imgWidth
*
height
)
/
float64
(
imgHeight
)))
thumbHeight
=
height
}
// 生成缩略图
thumb
:=
imaging
.
Resize
(
img
,
thumbWidth
,
thumbHeight
,
imaging
.
Lanczos
)
err
=
imaging
.
Save
(
thumb
,
savePath
)
return
err
}
func
splitSlice
[
T
any
](
slice
[]
T
,
size
int
)
[][]
T
{
var
result
[][]
T
for
i
:=
0
;
i
<
len
(
slice
);
i
+=
size
{
end
:=
i
+
size
if
end
>
len
(
slice
)
{
end
=
len
(
slice
)
}
result
=
append
(
result
,
slice
[
i
:
end
])
}
return
result
}
utils/updateUtils.go
deleted
100644 → 0
浏览文件 @
fd4382bb
package
utils
func
CheckUpdate
(
curVersionCode
int32
)
{
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论