Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hzjtpushService
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangjinjing
hzjtpushService
Commits
4b7f57e1
Commit
4b7f57e1
authored
Jan 31, 2024
by
wangjinjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug 修复
parent
8203c618
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
183 additions
and
105 deletions
+183
-105
.gitignore
.gitignore
+1
-0
src/main/java/com/hzjt/controller/AlarmController.java
src/main/java/com/hzjt/controller/AlarmController.java
+21
-26
src/main/java/com/hzjt/controller/TraffController.java
src/main/java/com/hzjt/controller/TraffController.java
+37
-30
src/main/java/com/hzjt/handler/FileTransferManager.java
src/main/java/com/hzjt/handler/FileTransferManager.java
+124
-49
No files found.
.gitignore
0 → 100644
View file @
4b7f57e1
/.idea/
src/main/java/com/hzjt/controller/AlarmController.java
View file @
4b7f57e1
package
com
.
hzjt
.
controller
;
package
com
.
hzjt
.
controller
;
import
cn.hutool.json.JSONUtil
;
import
com.hzjt.domain.Alarm
;
import
com.hzjt.domain.Alarm
;
import
com.hzjt.domain.AlarmEvents
;
import
com.hzjt.domain.AlarmEvents
;
import
com.hzjt.domain.Ftp
;
import
com.hzjt.domain.Ftp
;
...
@@ -65,22 +66,22 @@ public class AlarmController {
...
@@ -65,22 +66,22 @@ public class AlarmController {
Alarm
alarm
=
TransHelper
.
transAlarmResult
(
alarmEvents
);
Alarm
alarm
=
TransHelper
.
transAlarmResult
(
alarmEvents
);
alarm
.
setDept
(
xzbh
);
alarm
.
setDept
(
xzbh
);
Result
result
=
new
Result
();
Result
result
=
new
Result
();
Traffalarmrecord
traffAlarmRecord
=
new
Traffalarmrecord
();
Traffalarmrecord
traffAlarmRecord
_init
=
new
Traffalarmrecord
();
traffAlarmRecord
.
setAreaid
(
Long
.
valueOf
(
xzbh
));
traffAlarmRecord
_init
.
setAreaid
(
Long
.
valueOf
(
xzbh
));
traffAlarmRecord
.
setRecordtype
(
alarmEvents
.
getEventType
().
toLowerCase
());
traffAlarmRecord
_init
.
setRecordtype
(
alarmEvents
.
getEventType
().
toLowerCase
());
if
(
alarmEvents
.
getStartTime
()
!=
null
)
{
if
(
alarmEvents
.
getStartTime
()
!=
null
)
{
traffAlarmRecord
.
setRecordtime
(
DateUtils
.
getDateString
(
new
Date
(
Long
.
valueOf
(
alarmEvents
.
getStartTime
())
*
1000L
)));
traffAlarmRecord
_init
.
setRecordtime
(
DateUtils
.
getDateString
(
new
Date
(
Long
.
valueOf
(
alarmEvents
.
getStartTime
())
*
1000L
)));
}
}
traffAlarmRecord
.
setFdid
(
alarmEvents
.
getDeviceId
());
traffAlarmRecord
_init
.
setFdid
(
alarmEvents
.
getDeviceId
());
traffAlarmRecord
.
setChannelid
(
0
);
traffAlarmRecord
_init
.
setChannelid
(
0
);
traffAlarmRecord
.
setCreatetime
(
DateUtils
.
getDateString
(
new
Date
()));
traffAlarmRecord
_init
.
setCreatetime
(
DateUtils
.
getDateString
(
new
Date
()));
traffAlarmRecord
.
setObjlable
(
alarm
.
getObjLabel
());
traffAlarmRecord
_init
.
setObjlable
(
alarm
.
getObjLabel
());
traffAlarmRecord
.
setPushstatus
(
9
);
traffAlarmRecord
_init
.
setPushstatus
(
9
);
traffAlarmRecord
.
setProcessstatus
(
"0"
);
traffAlarmRecord
_init
.
setProcessstatus
(
"0"
);
traffAlarmRecord
.
setManualstatus
(
1
);
traffAlarmRecord
_init
.
setManualstatus
(
1
);
traffAlarmRecord
.
setChannelname
(
alarmEvents
.
getDeviceName
());
traffAlarmRecord
_init
.
setChannelname
(
alarmEvents
.
getDeviceName
());
traffAlarmRecord
.
setObjlable
(
alarmEvents
.
getObjectType
());
traffAlarmRecord
_init
.
setObjlable
(
alarmEvents
.
getObjectType
());
List
<
MediaList
>
imgBase64List
=
alarmEvents
.
getMediaList
();
List
<
MediaList
>
imgBase64List
=
alarmEvents
.
getMediaList
();
String
imgEnumHead
=
"IMG"
;
String
imgEnumHead
=
"IMG"
;
int
i
=
0
;
int
i
=
0
;
...
@@ -89,30 +90,31 @@ public class AlarmController {
...
@@ -89,30 +90,31 @@ public class AlarmController {
while
(
var12
.
hasNext
())
{
while
(
var12
.
hasNext
())
{
MediaList
imgs
=
(
MediaList
)
var12
.
next
();
MediaList
imgs
=
(
MediaList
)
var12
.
next
();
if
(
imgs
.
getType
().
contains
(
"jpg"
))
{
if
(
imgs
.
getType
().
contains
(
"jpg"
))
{
TraffAlarmRecordFromImgEnum
.
valueOf
(
imgEnumHead
+
i
).
setImg
(
traffAlarmRecord
,
imgs
.
getSrc
());
TraffAlarmRecordFromImgEnum
.
valueOf
(
imgEnumHead
+
i
).
setImg
(
traffAlarmRecord
_init
,
imgs
.
getSrc
());
++
i
;
++
i
;
}
}
if
(
imgs
.
getType
().
contains
(
"mp4"
))
{
if
(
imgs
.
getType
().
contains
(
"mp4"
))
{
traffAlarmRecord
.
setVideourlfrom
(
imgs
.
getSrc
());
traffAlarmRecord
_init
.
setVideourlfrom
(
imgs
.
getSrc
());
}
}
}
}
if
(
StringEnum
.
ONE
.
getValue
().
equals
(
this
.
checkEnable
))
{
if
(
StringEnum
.
ONE
.
getValue
().
equals
(
this
.
checkEnable
))
{
traffAlarmRecord
.
setCheckstatus
(
9
);
traffAlarmRecord
_init
.
setCheckstatus
(
9
);
}
}
Map
<
Object
,
Object
>
map
=
new
HashMap
();
Map
<
Object
,
Object
>
map
=
new
HashMap
();
map
.
put
(
"type"
,
"alarm"
);
map
.
put
(
"type"
,
"alarm"
);
traffAlarmRecord
.
setEventid
(
"66211"
+
UUIDUtils
.
createuuid
());
traffAlarmRecord
_init
.
setEventid
(
"66211"
+
UUIDUtils
.
createuuid
());
this
.
traffAlarmRecordMapper
.
inserTraffAlarmRecord
(
traffAlarmRecord
);
this
.
traffAlarmRecordMapper
.
inserTraffAlarmRecord
(
traffAlarmRecord
_init
);
map
.
put
(
"data"
,
alarm
);
map
.
put
(
"data"
,
alarm
);
map
.
put
(
"recordid"
,
traffAlarmRecord
.
getRecordid
());
map
.
put
(
"recordid"
,
traffAlarmRecord
_init
.
getRecordid
());
this
.
webSocket
.
GroupSending
(
JsonUtil
.
beanToString
(
map
));
this
.
webSocket
.
GroupSending
(
JsonUtil
.
beanToString
(
map
));
try
{
try
{
Traffalarmrecord
traffAlarmRecord
=
JSONUtil
.
toBean
(
JsonUtil
.
beanToString
(
traffAlarmRecord_init
),
Traffalarmrecord
.
class
);
String
basepath
=
traffAlarmRecord
.
getFdid
()
+
(
traffAlarmRecord
.
getChannelid
()
<
10
?
"0"
+
traffAlarmRecord
.
getChannelid
()
:
traffAlarmRecord
.
getChannelid
())
+
"/"
+
DateUtils
.
formatCurrDayNoSign
();
String
basepath
=
traffAlarmRecord
.
getFdid
()
+
(
traffAlarmRecord
.
getChannelid
()
<
10
?
"0"
+
traffAlarmRecord
.
getChannelid
()
:
traffAlarmRecord
.
getChannelid
())
+
"/"
+
DateUtils
.
formatCurrDayNoSign
();
Map
<
String
,
Object
>
transferRecordMap
=
new
HashMap
();
Map
<
String
,
Object
>
transferRecordMap
=
new
HashMap
();
FileTransferManager
.
fetchUrlsFromRecord
(
traffAlarmRecord
,
transferRecordMap
);
FileTransferManager
.
fetchUrlsFromRecord
(
traffAlarmRecord
,
transferRecordMap
);
...
@@ -121,13 +123,6 @@ public class AlarmController {
...
@@ -121,13 +123,6 @@ public class AlarmController {
Traffalarmrecord
recordBak
=
FileTransferManager
.
traffAlarmRecordUrlUpdate
(
results
);
Traffalarmrecord
recordBak
=
FileTransferManager
.
traffAlarmRecordUrlUpdate
(
results
);
log
.
info
(
"recordBak=={}"
,
JsonUtil
.
beanToString
(
recordBak
));
log
.
info
(
"recordBak=={}"
,
JsonUtil
.
beanToString
(
recordBak
));
log
.
info
(
"traffAlarmRecord=={}"
,
traffAlarmRecord
.
getRecordid
());
log
.
info
(
"traffAlarmRecord=={}"
,
traffAlarmRecord
.
getRecordid
());
// traffAlarmRecord.setRecordid(recordBak.getRecordid());
// traffAlarmRecord.setImg1path(recordBak.getImg1path());
// traffAlarmRecord.setImg2path(recordBak.getImg2path());
// traffAlarmRecord.setImg3path(recordBak.getImg3path());
// traffAlarmRecord.setImg4path(recordBak.getImg4path());
// traffAlarmRecord.setImg5path(recordBak.getImg5path());
// traffAlarmRecord.setVideopath(recordBak.getVideopath());
this
.
traffAlarmRecordMapper
.
updateTraffAlarmRecordUrl
(
recordBak
);
this
.
traffAlarmRecordMapper
.
updateTraffAlarmRecordUrl
(
recordBak
);
traffAlarmRecord
.
setPushdesc
(
"success"
);
traffAlarmRecord
.
setPushdesc
(
"success"
);
traffAlarmRecord
.
setPushstatus
(
0
);
traffAlarmRecord
.
setPushstatus
(
0
);
...
...
src/main/java/com/hzjt/controller/TraffController.java
View file @
4b7f57e1
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
package
com
.
hzjt
.
controller
;
package
com
.
hzjt
.
controller
;
import
cn.hutool.core.codec.Base64Encoder
;
import
cn.hutool.core.codec.Base64Encoder
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.util.concurrent.RateLimiter
;
import
com.google.common.util.concurrent.RateLimiter
;
import
com.hzjt.domain.Alarm
;
import
com.hzjt.domain.Alarm
;
...
@@ -177,51 +178,52 @@ public class TraffController {
...
@@ -177,51 +178,52 @@ public class TraffController {
}
}
public
void
sendevent
(
Alarm
trffClientMessage
,
Sbtdspsr
spr
)
{
public
void
sendevent
(
Alarm
trffClientMessage
,
Sbtdspsr
spr
)
{
Traffalarmrecord
traffAlarmRecord
=
new
Traffalarmrecord
();
Traffalarmrecord
traffAlarmRecord
_init
=
new
Traffalarmrecord
();
traffAlarmRecord
.
setAreaid
(
Long
.
valueOf
(
trffClientMessage
.
getDept
()));
traffAlarmRecord
_init
.
setAreaid
(
Long
.
valueOf
(
trffClientMessage
.
getDept
()));
traffAlarmRecord
.
setRecordtype
(
trffClientMessage
.
getIncident_type
().
toLowerCase
());
traffAlarmRecord
_init
.
setRecordtype
(
trffClientMessage
.
getIncident_type
().
toLowerCase
());
traffAlarmRecord
.
setRecordtime
(
DateUtils
.
getDateString
(
new
Date
(
Long
.
valueOf
(
trffClientMessage
.
getTs
()))));
traffAlarmRecord
_init
.
setRecordtime
(
DateUtils
.
getDateString
(
new
Date
(
Long
.
valueOf
(
trffClientMessage
.
getTs
()))));
traffAlarmRecord
.
setFdid
(
trffClientMessage
.
getVideo_id
());
traffAlarmRecord
_init
.
setFdid
(
trffClientMessage
.
getVideo_id
());
traffAlarmRecord
.
setChannelid
(
0
);
traffAlarmRecord
_init
.
setChannelid
(
0
);
traffAlarmRecord
.
setVideourlfrom
(
trffClientMessage
.
getVideo_record_url
());
traffAlarmRecord
_init
.
setVideourlfrom
(
trffClientMessage
.
getVideo_record_url
());
traffAlarmRecord
.
setCreatetime
(
DateUtils
.
getDateString
(
new
Date
()));
traffAlarmRecord
_init
.
setCreatetime
(
DateUtils
.
getDateString
(
new
Date
()));
traffAlarmRecord
.
setObjlable
(
trffClientMessage
.
getObjLabel
());
traffAlarmRecord
_init
.
setObjlable
(
trffClientMessage
.
getObjLabel
());
traffAlarmRecord
.
setPushstatus
(
9
);
traffAlarmRecord
_init
.
setPushstatus
(
9
);
traffAlarmRecord
.
setProcessstatus
(
"0"
);
traffAlarmRecord
_init
.
setProcessstatus
(
"0"
);
traffAlarmRecord
.
setManualstatus
(
1
);
traffAlarmRecord
_init
.
setManualstatus
(
1
);
traffAlarmRecord
.
setChannelname
(
spr
.
getTdmc
());
traffAlarmRecord
_init
.
setChannelname
(
spr
.
getTdmc
());
List
<
String
>
imgBase64List
=
trffClientMessage
.
getImg_base64
();
List
<
String
>
imgBase64List
=
trffClientMessage
.
getImg_base64
();
String
imgEnumHead
=
"IMG"
;
String
imgEnumHead
=
"IMG"
;
Ftp
ftp
=
this
.
ftpService
.
reloadFtp
();
Ftp
ftp
=
this
.
ftpService
.
reloadFtp
();
String
basepath
;
String
basepath
;
for
(
int
i
=
0
;
i
<
imgBase64List
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
imgBase64List
.
size
();
++
i
)
{
String
path
=
trffClientMessage
.
getVideo_id
()
+
(
traffAlarmRecord
.
getChannelid
()
<
10
?
"0"
+
traffAlarmRecord
.
getChannelid
()
:
traffAlarmRecord
.
getChannelid
())
+
"/"
+
DateUtils
.
formatCurrDayNoSign
();
String
path
=
trffClientMessage
.
getVideo_id
()
+
(
traffAlarmRecord
_init
.
getChannelid
()
<
10
?
"0"
+
traffAlarmRecord_init
.
getChannelid
()
:
traffAlarmRecord_init
.
getChannelid
())
+
"/"
+
DateUtils
.
formatCurrDayNoSign
();
basepath
=
UUIDUtils
.
createuuid
()
+
".jpg"
;
basepath
=
UUIDUtils
.
createuuid
()
+
".jpg"
;
if
(
FTPUtil
.
uploadFile
(
ftp
,
"gstraff/"
+
path
,
basepath
,
(
String
)
imgBase64List
.
get
(
i
)))
{
if
(
FTPUtil
.
uploadFile
(
ftp
,
"gstraff/"
+
path
,
basepath
,
(
String
)
imgBase64List
.
get
(
i
)))
{
TraffAlarmRecordImgEnum
.
valueOf
(
imgEnumHead
+
i
).
setImg
(
traffAlarmRecord
,
path
+
"/"
+
basepath
);
TraffAlarmRecordImgEnum
.
valueOf
(
imgEnumHead
+
i
).
setImg
(
traffAlarmRecord
_init
,
path
+
"/"
+
basepath
);
}
}
}
}
List
<
String
>
imgUrls
=
trffClientMessage
.
getImg_urls
();
List
<
String
>
imgUrls
=
trffClientMessage
.
getImg_urls
();
for
(
int
j
=
0
;
j
<
imgUrls
.
size
();
++
j
)
{
for
(
int
j
=
0
;
j
<
imgUrls
.
size
();
++
j
)
{
TraffAlarmRecordFromImgEnum
.
valueOf
(
imgEnumHead
+
j
).
setImg
(
traffAlarmRecord
,
(
String
)
imgUrls
.
get
(
j
));
TraffAlarmRecordFromImgEnum
.
valueOf
(
imgEnumHead
+
j
).
setImg
(
traffAlarmRecord
_init
,
(
String
)
imgUrls
.
get
(
j
));
}
}
if
(
StringEnum
.
ONE
.
getValue
().
equals
(
this
.
checkEnable
))
{
if
(
StringEnum
.
ONE
.
getValue
().
equals
(
this
.
checkEnable
))
{
traffAlarmRecord
.
setCheckstatus
(
9
);
traffAlarmRecord
_init
.
setCheckstatus
(
9
);
}
}
Map
<
Object
,
Object
>
map
=
new
HashMap
();
Map
<
Object
,
Object
>
map
=
new
HashMap
();
map
.
put
(
"type"
,
"alarm"
);
map
.
put
(
"type"
,
"alarm"
);
traffAlarmRecord
.
setEventid
(
"66211"
+
UUIDUtils
.
createuuid
());
traffAlarmRecord
_init
.
setEventid
(
"66211"
+
UUIDUtils
.
createuuid
());
this
.
traffAlarmRecordMapper
.
inserTraffAlarmRecord
(
traffAlarmRecord
);
this
.
traffAlarmRecordMapper
.
inserTraffAlarmRecord
(
traffAlarmRecord
_init
);
map
.
put
(
"data"
,
trffClientMessage
);
map
.
put
(
"data"
,
trffClientMessage
);
map
.
put
(
"recordid"
,
traffAlarmRecord
.
getRecordid
());
map
.
put
(
"recordid"
,
traffAlarmRecord
_init
.
getRecordid
());
this
.
webSocket
.
GroupSending
(
JsonUtil
.
beanToString
(
map
));
this
.
webSocket
.
GroupSending
(
JsonUtil
.
beanToString
(
map
));
try
{
try
{
Traffalarmrecord
traffAlarmRecord
=
JSONUtil
.
toBean
(
JsonUtil
.
beanToString
(
traffAlarmRecord_init
),
Traffalarmrecord
.
class
);
basepath
=
traffAlarmRecord
.
getFdid
()
+
(
traffAlarmRecord
.
getChannelid
()
<
10
?
"0"
+
traffAlarmRecord
.
getChannelid
()
:
traffAlarmRecord
.
getChannelid
())
+
"/"
+
DateUtils
.
formatCurrDayNoSign
();
basepath
=
traffAlarmRecord
.
getFdid
()
+
(
traffAlarmRecord
.
getChannelid
()
<
10
?
"0"
+
traffAlarmRecord
.
getChannelid
()
:
traffAlarmRecord
.
getChannelid
())
+
"/"
+
DateUtils
.
formatCurrDayNoSign
();
Map
<
String
,
Object
>
transferRecordMap
=
new
HashMap
();
Map
<
String
,
Object
>
transferRecordMap
=
new
HashMap
();
FileTransferManager
.
fetchUrlsFromRecord
(
traffAlarmRecord
,
transferRecordMap
);
FileTransferManager
.
fetchUrlsFromRecord
(
traffAlarmRecord
,
transferRecordMap
);
...
@@ -236,11 +238,10 @@ public class TraffController {
...
@@ -236,11 +238,10 @@ public class TraffController {
Traffalarmrecord
record
=
new
Traffalarmrecord
();
Traffalarmrecord
record
=
new
Traffalarmrecord
();
record
.
setRecordid
(
recordBak
.
getRecordid
());
record
.
setRecordid
(
recordBak
.
getRecordid
());
String
url
=
recordBak
.
getVideourlfrom
();
String
url
=
recordBak
.
getVideourlfrom
();
record
.
setVideopath
(
recordBak
.
getVideopath
());
log
.
info
(
"url:{}"
,
url
);
String
finalBasepath
=
recordBak
.
getVideopath
(
);
log
.
info
(
"bathpath:{}"
,
recordBak
.
getVideopath
()
);
this
.
schedulepool
.
schedule
(()
->
{
this
.
schedulepool
.
schedule
(()
->
{
log
.
info
(
"finalBasepath====={}"
,
finalBasepath
);
try
{
try
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
(
new
URL
(
url
)).
openConnection
();
HttpURLConnection
connection
=
(
HttpURLConnection
)
(
new
URL
(
url
)).
openConnection
();
connection
.
setReadTimeout
(
2000
);
connection
.
setReadTimeout
(
2000
);
...
@@ -248,14 +249,20 @@ public class TraffController {
...
@@ -248,14 +249,20 @@ public class TraffController {
connection
.
setRequestMethod
(
"GET"
);
connection
.
setRequestMethod
(
"GET"
);
if
(
connection
.
getResponseCode
()
==
200
)
{
if
(
connection
.
getResponseCode
()
==
200
)
{
InputStream
inputStream
=
connection
.
getInputStream
();
InputStream
inputStream
=
connection
.
getInputStream
();
log
.
info
(
"url:{}"
,
url
);
//
log.info("url:{}", url);
String
pname
=
DateUtils
.
formatCurrDayNoSign
()
+
"_"
+
record
.
getRecordid
()
+
"_0000_video"
;
String
pname
=
DateUtils
.
formatCurrDayNoSign
()
+
"_"
+
record
.
getRecordid
()
+
"_0000_video"
;
String
fileName
=
pname
+
".mp4"
;
String
fileName
=
pname
+
".mp4"
;
String
ftputl
=
finalBasepath
+
"/"
+
fileName
;
String
ftputl
=
record
.
getVideopath
()
+
"/"
+
fileName
;
boolean
r
=
FTPUtil
.
uploadFile
(
ftp
,
"gstraff/"
+
finalBasepath
,
fileName
,
inputStream
);
if
(
record
.
getVideopath
().
indexOf
(
"/"
)
>
-
1
)
{
if
(
r
)
{
boolean
r
=
FTPUtil
.
uploadFile
(
ftp
,
"gstraff/"
+
recordBak
.
getVideopath
(),
fileName
,
inputStream
);
record
.
setVideopath
(
ftputl
);
log
.
info
(
"video:{} upload success:"
,
ftputl
);
if
(
r
)
{
record
.
setVideopath
(
ftputl
);
log
.
info
(
"video:{} upload success:"
,
ftputl
);
}
else
{
log
.
info
(
"video:{} upload fail:"
,
url
);
record
.
setVideopath
(
""
);
}
}
}
}
else
{
}
else
{
log
.
info
(
"video:{} upload fail:"
,
url
);
log
.
info
(
"video:{} upload fail:"
,
url
);
...
...
src/main/java/com/hzjt/handler/FileTransferManager.java
View file @
4b7f57e1
package
com
.
hzjt
.
handler
;
package
com
.
hzjt
.
handler
;
import
cn.hutool.json.JSONUtil
;
import
com.hzjt.domain.Ftp
;
import
com.hzjt.domain.Ftp
;
import
com.hzjt.domain.Traffalarmrecord
;
import
com.hzjt.domain.Traffalarmrecord
;
import
com.hzjt.domain.TransferResult
;
import
com.hzjt.domain.TransferResult
;
import
com.hzjt.util.DateUtils
;
import
com.hzjt.util.DateUtils
;
import
com.hzjt.util.FTPUtil
;
import
com.hzjt.util.FTPUtil
;
import
com.hzjt.util.JsonUtil
;
import
com.hzjt.util.ThreadPoolUtil
;
import
com.hzjt.util.ThreadPoolUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -32,63 +34,135 @@ public class FileTransferManager {
...
@@ -32,63 +34,135 @@ public class FileTransferManager {
* @throws Exception
* @throws Exception
*/
*/
public
static
List
<
TransferResult
>
transferFile
(
final
Map
<
String
,
Object
>
transferRecord
,
final
Ftp
ftp
,
final
String
basePath
)
throws
Exception
{
public
static
List
<
TransferResult
>
transferFile
(
final
Map
<
String
,
Object
>
transferRecord
,
final
Ftp
ftp
,
final
String
basePath
)
throws
Exception
{
Integer
ret
=
0
;
Long
recordid
=
Long
.
parseLong
(
transferRecord
.
get
(
"recordid"
).
toString
());
final
Long
recordid
=
Long
.
parseLong
(
transferRecord
.
get
(
"recordid"
).
toString
());
int
count
=
0
;
int
count
=
0
;
for
(
String
key
:
transferRecord
.
keySet
())
{
Iterator
var5
=
transferRecord
.
keySet
().
iterator
();
if
(
key
.
equals
(
"img1path"
)
||
key
.
equals
(
"img2path"
)
while
(
true
)
{
||
key
.
equals
(
"img3path"
)
||
key
.
equals
(
"img4path"
)
String
key
;
||
key
.
equals
(
"img5path"
)
||
key
.
equals
(
"videopath"
))
{
do
{
final
String
url
=
transferRecord
.
get
(
key
).
toString
();
if
(!
var5
.
hasNext
())
{
count
++;
List
<
TransferResult
>
listret
=
new
ArrayList
();
completionService
.
submit
(()
->
{
TransferResult
result
=
new
TransferResult
(
recordid
,
key
,
url
,
""
,
false
);
String
filesuff
=
"videopath"
.
equals
(
key
)
?
".mp4"
:
".jpg"
;
String
pname
=
DateUtils
.
formatCurrDayNoSign
()
+
"_"
+
recordid
+
"_0000_"
+
key
.
replace
(
"path"
,
""
);
String
fileName
=
pname
+
filesuff
;
// String ftputl = FTPUtil.getFtpUrl(ftp) + basePath + "/" + fileName;
if
(
key
.
equals
(
"videopath"
))
{
// 视频只存值,先不取值
log
.
info
(
"videopath"
);
result
.
setImgpath
(
basePath
);
result
.
setUrlfrom
(
url
);
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
listret
.
add
(
completionService
.
poll
(
4L
,
TimeUnit
.
SECONDS
).
get
());
}
}
else
{
try
{
return
listret
;
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
}
//延迟连接
connection
.
setReadTimeout
(
2000
);
key
=
(
String
)
var5
.
next
();
connection
.
setConnectTimeout
(
3000
);
}
while
(!
key
.
equals
(
"img1path"
)
&&
!
key
.
equals
(
"img2path"
)
&&
!
key
.
equals
(
"img3path"
)
&&
!
key
.
equals
(
"img4path"
)
&&
!
key
.
equals
(
"img5path"
)
&&
!
key
.
equals
(
"videopath"
));
connection
.
setRequestMethod
(
"GET"
);
if
(
connection
.
getResponseCode
()
==
HttpURLConnection
.
HTTP_OK
)
{
String
url
=
transferRecord
.
get
(
key
).
toString
();
InputStream
inputStream
=
connection
.
getInputStream
();
++
count
;
String
finalKey
=
key
;
boolean
r
=
FTPUtil
.
uploadFile
(
ftp
,
"gstraff/"
+
basePath
,
fileName
,
inputStream
);
completionService
.
submit
(()
->
{
result
.
setResult
(
r
);
log
.
info
(
"recordid:{}"
,
recordid
);
if
(
r
)
{
TransferResult
result
=
new
TransferResult
(
recordid
,
finalKey
,
url
,
""
,
false
);
result
.
setImgpath
(
basePath
+
"/"
+
fileName
);
String
pname
=
DateUtils
.
formatCurrDayNoSign
()
+
"_"
+
recordid
+
"_0000_"
+
finalKey
.
replace
(
"path"
,
""
);
}
String
filesuff
=
"videopath"
.
equals
(
finalKey
)
?
".mp4"
:
".jpg"
;
// log.info("callable thread:" +result.toString());
String
fileName
=
pname
+
filesuff
;
String
ftputl
=
basePath
+
"/"
+
fileName
;
if
(
"videopath"
.
equals
(
finalKey
))
{
result
.
setUrlfrom
(
url
);
result
.
setImgpath
(
ftputl
);
}
else
{
try
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
(
new
URL
(
url
)).
openConnection
();
connection
.
setReadTimeout
(
2000
);
connection
.
setConnectTimeout
(
3000
);
connection
.
setRequestMethod
(
"GET"
);
if
(
connection
.
getResponseCode
()
==
200
)
{
InputStream
inputStream
=
connection
.
getInputStream
();
boolean
r
=
FTPUtil
.
uploadFile
(
ftp
,
"gstraff/"
+
basePath
,
fileName
,
inputStream
);
result
.
setResult
(
r
);
if
(
r
)
{
result
.
setImgpath
(
ftputl
);
log
.
info
(
"imgpath or videopath success:{}"
,
ftputl
);
}
else
{
}
else
{
log
.
error
(
"connection code: "
+
connection
.
getResponseCode
()
+
" ,"
+
result
.
toString
()
);
log
.
info
(
"imgpath or videopath fail:{}"
,
ftputl
);
}
}
}
catch
(
IOException
e
)
{
}
else
{
System
.
out
.
println
(
e
.
toString
());
log
.
error
(
"imgpath or videopath connection error code:{}"
,
connection
.
getResponseCode
()
+
" ,"
+
result
.
toString
());
log
.
error
(
e
.
toString
());
}
}
}
catch
(
IOException
var13
)
{
log
.
error
(
"imgpath or videopath error:{}"
,
var13
.
toString
());
}
}
return
result
;
}
});
}
return
result
;
}
});
List
<
TransferResult
>
listret
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
listret
.
add
(
completionService
.
poll
(
10
,
TimeUnit
.
SECONDS
).
get
());
}
}
return
listret
;
}
}
// /**
// * @param transferRecord
// * @param ftp
// * @param basePath
// * @return
// * @throws Exception
// */
// public static List<TransferResult> transferFile(final Map<String, Object> transferRecord, final Ftp ftp, final String basePath) throws Exception {
// Integer ret = 0;
// final Long recordid = Long.parseLong(transferRecord.get("recordid").toString());
// int count = 0;
// for (String key : transferRecord.keySet()) {
// if (key.equals("img1path") || key.equals("img2path")
// || key.equals("img3path") || key.equals("img4path")
// || key.equals("img5path") || key.equals("videopath")) {
// final String url = transferRecord.get(key).toString();
// count++;
// completionService.submit(() -> {
// TransferResult result = new TransferResult(recordid, key, url, "", false);
//
// String filesuff = "videopath".equals(key) ? ".mp4" : ".jpg";
// String pname = DateUtils.formatCurrDayNoSign() + "_" + recordid + "_0000_" + key.replace("path", "");
// String fileName = pname + filesuff;
//// String ftputl = FTPUtil.getFtpUrl(ftp) + basePath + "/" + fileName;
// if (key.equals("videopath")) {
// // 视频只存值,先不取值
// log.info("videopath");
// result.setImgpath(basePath);
// result.setUrlfrom(url);
//
// }
// else {
// try {
// HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
// //延迟连接
// connection.setReadTimeout(2000);
// connection.setConnectTimeout(3000);
// connection.setRequestMethod("GET");
// if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
// InputStream inputStream = connection.getInputStream();
//
// boolean r = FTPUtil.uploadFile(ftp, "gstraff/" + basePath, fileName, inputStream);
// result.setResult(r);
// if (r) {
// result.setImgpath(basePath + "/" + fileName);
// }
//// log.info("callable thread:" +result.toString());
// } else {
// log.error("connection code: " + connection.getResponseCode() + " ," + result.toString());
// }
// } catch (IOException e) {
// System.out.println(e.toString());
// log.error(e.toString());
// }
// }
// return result;
// });
// }
// }
// List<TransferResult> listret = new ArrayList<>();
// for (int i = 0; i < count; i++) {
// listret.add(completionService.poll(3, TimeUnit.SECONDS).get());
// }
// return listret;
// }
public
static
void
fetchUrlsFromRecord
(
Traffalarmrecord
record
,
Map
<
String
,
Object
>
transferRecord
)
{
public
static
void
fetchUrlsFromRecord
(
Traffalarmrecord
record
,
Map
<
String
,
Object
>
transferRecord
)
{
...
@@ -178,7 +252,8 @@ public class FileTransferManager {
...
@@ -178,7 +252,8 @@ public class FileTransferManager {
}
}
}
}
public
static
Traffalarmrecord
traffAlarmRecordUrlUpdate
(
List
<
TransferResult
>
results
)
throws
Exception
{
public
static
Traffalarmrecord
traffAlarmRecordUrlUpdate
(
List
<
TransferResult
>
resultslist
)
throws
Exception
{
List
<
TransferResult
>
results
=
JSONUtil
.
toList
(
JSONUtil
.
parseArray
(
JSONUtil
.
toJsonStr
(
resultslist
)),
TransferResult
.
class
);
Traffalarmrecord
record
=
new
Traffalarmrecord
();
Traffalarmrecord
record
=
new
Traffalarmrecord
();
for
(
TransferResult
result
:
results
)
{
for
(
TransferResult
result
:
results
)
{
record
.
setRecordid
(
result
.
getRecordid
());
record
.
setRecordid
(
result
.
getRecordid
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment