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
f03f4acb
Commit
f03f4acb
authored
Feb 01, 2024
by
wangjinjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
改为取完值后直接更新表
parent
4b7f57e1
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
207 additions
and
210 deletions
+207
-210
src/main/java/com/hzjt/config/ScheduleTaskConfig.java
src/main/java/com/hzjt/config/ScheduleTaskConfig.java
+3
-3
src/main/java/com/hzjt/controller/AlarmController.java
src/main/java/com/hzjt/controller/AlarmController.java
+11
-7
src/main/java/com/hzjt/controller/TraffController.java
src/main/java/com/hzjt/controller/TraffController.java
+64
-60
src/main/java/com/hzjt/domain/TransferResult.java
src/main/java/com/hzjt/domain/TransferResult.java
+18
-0
src/main/java/com/hzjt/handler/FileTransferManager.java
src/main/java/com/hzjt/handler/FileTransferManager.java
+51
-82
src/main/java/com/hzjt/redis/Receiver.java
src/main/java/com/hzjt/redis/Receiver.java
+60
-58
No files found.
src/main/java/com/hzjt/config/ScheduleTaskConfig.java
View file @
f03f4acb
...
...
@@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit;
@Slf4j
@Configuration
//
@Configuration
@EnableScheduling
public
class
ScheduleTaskConfig
{
@Autowired
...
...
@@ -39,7 +39,7 @@ public class ScheduleTaskConfig {
@Scheduled
(
cron
=
"0 */1 * * * ?"
)
//每天凌晨2点执行
//
@Scheduled(cron = "0 */1 * * * ?")//每天凌晨2点执行
private
void
statis
()
{
// //取帧
// HttpHeaders headers = new HttpHeaders();
...
...
@@ -69,7 +69,7 @@ public class ScheduleTaskConfig {
}
@Scheduled
(
cron
=
"0 */1 * * * ?"
)
//每一个月执行一次
//
@Scheduled(cron = "0 */1 * * * ?")//每一个月执行一次
private
void
reconnectWebsocket
()
{
final
Calendar
c
=
Calendar
.
getInstance
();
...
...
src/main/java/com/hzjt/controller/AlarmController.java
View file @
f03f4acb
...
...
@@ -35,21 +35,24 @@ import org.springframework.web.bind.annotation.PostMapping;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
@RestController
public
class
AlarmController
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
TraffController
.
class
);
@Value
(
"${alarmrecord.check.enable}"
)
private
String
checkEnable
;
@
Autowired
@
Resource
FtpService
ftpService
;
@
Autowired
@
Resource
private
TraffAlarmRecordMapper
traffAlarmRecordMapper
;
@Autowired
WebSocket
webSocket
;
@
Autowired
@
Resource
SbtdspsrMapper
sbtdspsrMapper
;
public
AlarmController
()
{
public
AlarmController
(
)
{
}
@PostMapping
({
"/sendAlarmEvents"
})
...
...
@@ -120,10 +123,10 @@ public class AlarmController {
FileTransferManager
.
fetchUrlsFromRecord
(
traffAlarmRecord
,
transferRecordMap
);
Ftp
ftp
=
this
.
ftpService
.
reloadFtp
();
List
<
TransferResult
>
results
=
FileTransferManager
.
transferFileIncludVideo
(
transferRecordMap
,
ftp
,
basepath
);
Traffalarmrecord
recordBak
=
FileTransferManager
.
traffAlarmRecordUrlUpdate
(
results
);
log
.
info
(
"recordBak=={}"
,
JsonUtil
.
beanToString
(
recordBak
)
);
FileTransferManager
fileTransferManager
=
new
FileTransferManager
(
);
fileTransferManager
.
traffAlarmRecordUrlUpdate
(
results
,
traffAlarmRecordMapper
);
log
.
info
(
"traffAlarmRecord=={}"
,
traffAlarmRecord
.
getRecordid
());
this
.
traffAlarmRecordMapper
.
updateTraffAlarmRecordUrl
(
recordBak
);
//
this.traffAlarmRecordMapper.updateTraffAlarmRecordUrl(recordBak);
traffAlarmRecord
.
setPushdesc
(
"success"
);
traffAlarmRecord
.
setPushstatus
(
0
);
this
.
traffAlarmRecordMapper
.
updatePushEvent
(
traffAlarmRecord
);
...
...
@@ -136,4 +139,5 @@ public class AlarmController {
return
result
;
}
}
}
src/main/java/com/hzjt/controller/TraffController.java
View file @
f03f4acb
...
...
@@ -53,6 +53,7 @@ import java.util.concurrent.ConcurrentHashMap;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
javax.annotation.Resource
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
...
...
@@ -85,8 +86,6 @@ public class TraffController {
private
SbtdspsrMapper
sbtdspsrMapper
;
@Autowired
TraffFlowService
traffFlowService
;
@Value
(
"${flv.resisvalue}"
)
private
String
resisvalue
;
@Value
(
"${json.resisurl}"
)
private
String
resisjsonvalue
;
@Value
(
"${ftppath}"
)
...
...
@@ -97,8 +96,8 @@ public class TraffController {
private
StringRedisTemplate
stringRedisTemplate
;
@Autowired
RedisDao
redisDao
;
@
Autowired
private
TraffAlarmRecordMapper
traffAlarmRecordMapper
;
@
Resource
TraffAlarmRecordMapper
traffAlarmRecordMapper
;
@Autowired
FtpService
ftpService
;
@Autowired
...
...
@@ -119,10 +118,11 @@ public class TraffController {
Long
eightHour
=
25200000L
;
String
manualStatus
=
"0"
;
private
static
final
String
TYPE
=
"TRAFFIC_INCIDENT_ALARM"
;
ScheduledExecutorService
schedulepool
=
Executors
.
newScheduledThreadPool
(
5
);
@Autowired
public
TraffController
(
@Value
(
"${port}"
)
String
port
,
@Value
(
"${message.dept}"
)
String
dept
,
@Value
(
"${message.rate}"
)
Integer
rate
,
SbtdspsrMapper
sbtdspsrMapper
)
{
public
TraffController
(
@Value
(
"${port}"
)
String
port
,
@Value
(
"${message.dept}"
)
String
dept
,
@Value
(
"${message.rate}"
)
Integer
rate
,
SbtdspsrMapper
sbtdspsrMapper
)
{
this
.
port
=
port
;
this
.
rate
=
rate
;
this
.
dept
=
dept
.
substring
(
0
,
5
);
...
...
@@ -227,68 +227,72 @@ public class TraffController {
basepath
=
traffAlarmRecord
.
getFdid
()
+
(
traffAlarmRecord
.
getChannelid
()
<
10
?
"0"
+
traffAlarmRecord
.
getChannelid
()
:
traffAlarmRecord
.
getChannelid
())
+
"/"
+
DateUtils
.
formatCurrDayNoSign
();
Map
<
String
,
Object
>
transferRecordMap
=
new
HashMap
();
FileTransferManager
.
fetchUrlsFromRecord
(
traffAlarmRecord
,
transferRecordMap
);
List
<
TransferResult
>
results
=
FileTransferManager
.
transferFile
(
transferRecordMap
,
ftp
,
basepath
);
Traffalarmrecord
recordBak
=
FileTransferManager
.
traffAlarmRecordUrlUpdate
(
results
);
log
.
info
(
"recordBakzk====={}"
,
JsonUtil
.
beanToString
(
recordBak
));
if
(
recordBak
!=
null
&&
recordBak
.
getRecordid
()
!=
null
)
{
this
.
traffAlarmRecordMapper
.
updateTraffAlarmRecordUrl
(
recordBak
);
}
Map
<
String
,
Object
>
transferRecordMap2
=
JSONUtil
.
toBean
(
JsonUtil
.
beanToString
(
transferRecordMap
),
Map
.
class
);
FileTransferManager
fileTransferManager
=
new
FileTransferManager
();
List
<
TransferResult
>
results
=
fileTransferManager
.
transferFile
(
transferRecordMap2
,
ftp
,
basepath
,
traffAlarmRecordMapper
);
log
.
info
(
"recordBakzkresults====={}"
,
JsonUtil
.
beanToString
(
results
));
fileTransferManager
.
traffAlarmRecordUrlUpdate
(
results
,
traffAlarmRecordMapper
);
// log.info("recordBakzk====={}", JsonUtil.beanToString(recordBak));
// if (recordBak != null && recordBak.getRecordid() != null) {
// this.traffAlarmRecordMapper.updateTraffAlarmRecordUrl(recordBak);
// }
//取视频流
if
((
null
!=
recordBak
.
getVideourlfrom
()
&&
!
""
.
equalsIgnoreCase
(
recordBak
.
getVideourlfrom
())))
{
Traffalarmrecord
record
=
new
Traffalarmrecord
();
record
.
setRecordid
(
recordBak
.
getRecordid
());
String
url
=
recordBak
.
getVideourlfrom
();
record
.
setVideopath
(
recordBak
.
getVideopath
());
log
.
info
(
"url:{}"
,
url
);
log
.
info
(
"bathpath:{}"
,
recordBak
.
getVideopath
());
this
.
schedulepool
.
schedule
(()
->
{
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
();
// if ((null != recordBak.getVideourlfrom() && !"".equalsIgnoreCase(recordBak.getVideourlfrom()))) {
// Traffalarmrecord record = new Traffalarmrecord();
// record.setRecordid(recordBak.getRecordid());
// String url = recordBak.getVideourlfrom();
// record.setVideopath(recordBak.getVideopath());
// log.info("url:{}", url);
String
pname
=
DateUtils
.
formatCurrDayNoSign
()
+
"_"
+
record
.
getRecordid
()
+
"_0000_video"
;
String
fileName
=
pname
+
".mp4"
;
String
ftputl
=
record
.
getVideopath
()
+
"/"
+
fileName
;
if
(
record
.
getVideopath
().
indexOf
(
"/"
)
>
-
1
)
{
boolean
r
=
FTPUtil
.
uploadFile
(
ftp
,
"gstraff/"
+
recordBak
.
getVideopath
(),
fileName
,
inputStream
);
if
(
r
)
{
record
.
setVideopath
(
ftputl
);
log
.
info
(
"video:{} upload success:"
,
ftputl
);
}
else
{
log
.
info
(
"video:{} upload fail:"
,
url
);
record
.
setVideopath
(
""
);
}
}
}
else
{
log
.
info
(
"video:{} upload fail:"
,
url
);
record
.
setVideopath
(
""
);
}
}
catch
(
IOException
var11
)
{
log
.
error
(
var11
.
toString
());
record
.
setVideopath
(
""
);
return
0
;
}
finally
{
this
.
traffAlarmRecordMapper
.
updateTraffAlarmRecordUrl
(
record
);
}
return
1
;
},
50L
,
TimeUnit
.
SECONDS
);
}
// log.info("bathpath:{}", recordBak.getVideopath());
// this.schedulepool.schedule(() -> {
// 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();
//// log.info("url:{}", url);
// String pname = DateUtils.formatCurrDayNoSign() + "_" + record.getRecordid() + "_0000_video";
// String fileName = pname + ".mp4";
// String ftputl = record.getVideopath() + "/" + fileName;
// if (record.getVideopath().indexOf("/") > -1) {
// boolean r = FTPUtil.uploadFile(ftp, "gstraff/" + recordBak.getVideopath(), fileName, inputStream);
//
// if (r) {
// record.setVideopath(ftputl);
// log.info("video:{} upload success:", ftputl);
// } else {
// log.info("video:{} upload fail:", url);
// record.setVideopath("");
// }
// }
// } else {
// log.info("video:{} upload fail:", url);
// record.setVideopath("");
// }
// } catch (IOException var11) {
// log.error(var11.toString());
// record.setVideopath("");
// return 0;
// } finally {
// this.traffAlarmRecordMapper.updateTraffAlarmRecordUrl(record);
// }
// return 1;
//
// }, 50L, TimeUnit.SECONDS);
// }
recordBak
.
setPushdesc
(
"success"
);
recordBak
.
setPushstatus
(
0
);
this
.
traffAlarmRecordMapper
.
updatePushEvent
(
recordBak
);
traffAlarmRecord
.
setPushdesc
(
"success"
);
traffAlarmRecord
.
setPushstatus
(
0
);
this
.
traffAlarmRecordMapper
.
updatePushEvent
(
traffAlarmRecord
);
}
catch
(
Exception
var16
)
{
log
.
error
(
"alarmevent error :{}"
,
var16
.
toString
());
}
}
private
void
sendtomqtt
(
Alarm
trffClientMessage
,
String
wbbh
,
Traffalarmrecord
traffAlarmRecord
)
{
log
.
info
(
"sendtomqtt"
);
if
(
null
!=
wbbh
&&
!
""
.
equals
(
wbbh
))
{
...
...
src/main/java/com/hzjt/domain/TransferResult.java
View file @
f03f4acb
...
...
@@ -10,6 +10,7 @@ public class TransferResult {
String
pathvalue
;
String
urlfrom
;
String
imgpath
;
String
filename
;
Boolean
result
;
public
TransferResult
()
{
...
...
@@ -23,6 +24,23 @@ public class TransferResult {
this
.
result
=
result
;
}
public
TransferResult
(
Long
recordid
,
String
pathvalue
,
String
urlfrom
,
String
imgpath
,
String
filename
,
Boolean
result
)
{
this
.
recordid
=
recordid
;
this
.
pathvalue
=
pathvalue
;
this
.
urlfrom
=
urlfrom
;
this
.
imgpath
=
imgpath
;
this
.
filename
=
filename
;
this
.
result
=
result
;
}
public
String
getFilename
()
{
return
filename
;
}
public
void
setFilename
(
String
filename
)
{
this
.
filename
=
filename
;
}
public
Long
getRecordid
()
{
return
recordid
;
}
...
...
src/main/java/com/hzjt/handler/FileTransferManager.java
View file @
f03f4acb
...
...
@@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil;
import
com.hzjt.domain.Ftp
;
import
com.hzjt.domain.Traffalarmrecord
;
import
com.hzjt.domain.TransferResult
;
import
com.hzjt.mapper.TraffAlarmRecordMapper
;
import
com.hzjt.util.DateUtils
;
import
com.hzjt.util.FTPUtil
;
import
com.hzjt.util.JsonUtil
;
...
...
@@ -26,6 +27,10 @@ public class FileTransferManager {
private
static
CompletionService
<
TransferResult
>
completionService
=
new
ExecutorCompletionService
<
TransferResult
>(
ThreadPoolUtil
.
getPool
());
static
ScheduledExecutorService
schedulepool
=
Executors
.
newScheduledThreadPool
(
5
);
/**
* @param transferRecord
* @param ftp
...
...
@@ -33,7 +38,7 @@ public class FileTransferManager {
* @return
* @throws Exception
*/
public
static
List
<
TransferResult
>
transferFile
(
final
Map
<
String
,
Object
>
transferRecord
,
final
Ftp
ftp
,
final
String
basePath
)
throws
Exception
{
public
List
<
TransferResult
>
transferFile
(
final
Map
<
String
,
Object
>
transferRecord
,
final
Ftp
ftp
,
final
String
basePath
,
TraffAlarmRecordMapper
traffAlarmRecordMapper
)
throws
Exception
{
Long
recordid
=
Long
.
parseLong
(
transferRecord
.
get
(
"recordid"
).
toString
());
int
count
=
0
;
Iterator
var5
=
transferRecord
.
keySet
().
iterator
();
...
...
@@ -66,6 +71,44 @@ public class FileTransferManager {
if
(
"videopath"
.
equals
(
finalKey
))
{
result
.
setUrlfrom
(
url
);
result
.
setImgpath
(
ftputl
);
result
.
setFilename
(
fileName
);
schedulepool
.
schedule
(()
->
{
Traffalarmrecord
record
=
new
Traffalarmrecord
();
try
{
record
.
setRecordid
(
result
.
getRecordid
());
HttpURLConnection
connection
=
(
HttpURLConnection
)
(
new
URL
(
result
.
getUrlfrom
())).
openConnection
();
connection
.
setReadTimeout
(
2000
);
connection
.
setConnectTimeout
(
3000
);
connection
.
setRequestMethod
(
"GET"
);
log
.
info
(
"video record:{} upload fail:"
,
JsonUtil
.
beanToString
(
result
));
if
(
connection
.
getResponseCode
()
==
200
)
{
InputStream
inputStream
=
connection
.
getInputStream
();
// if (result.getImgpath().indexOf("/") > -1) {
boolean
r
=
FTPUtil
.
uploadFile
(
ftp
,
"gstraff/"
+
basePath
,
result
.
getFilename
(),
inputStream
);
if
(
r
)
{
record
.
setVideopath
(
result
.
getImgpath
());
log
.
info
(
"video:{} upload success:"
,
result
.
getImgpath
());
}
else
{
log
.
info
(
"video:{} upload fail:"
,
result
.
getUrlfrom
());
record
.
setVideopath
(
""
);
}
// }
}
else
{
log
.
info
(
"video:{} upload fail:"
,
url
);
record
.
setVideopath
(
""
);
}
}
catch
(
IOException
var11
)
{
log
.
info
(
"video:{} error:{}"
,
result
.
getUrlfrom
(),
var11
.
toString
());
record
.
setVideopath
(
""
);
return
0
;
}
finally
{
traffAlarmRecordMapper
.
updateTraffAlarmRecordUrl
(
record
);
}
return
1
;
},
50L
,
TimeUnit
.
SECONDS
);
}
else
{
try
{
...
...
@@ -75,10 +118,8 @@ public class FileTransferManager {
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
);
...
...
@@ -98,71 +139,6 @@ public class FileTransferManager {
}
}
// /**
// * @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
)
{
...
...
@@ -211,7 +187,6 @@ public class FileTransferManager {
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
listret
.
add
(
completionService
.
poll
(
10L
,
TimeUnit
.
SECONDS
).
get
());
}
return
listret
;
}
...
...
@@ -251,11 +226,11 @@ public class FileTransferManager {
});
}
}
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
();
public
void
traffAlarmRecordUrlUpdate
(
List
<
TransferResult
>
results
,
TraffAlarmRecordMapper
traffAlarmRecordMapper
)
throws
Exception
{
// List<TransferResult> results = JSONUtil.toList(JSONUtil.parseArray(JSONUtil.toJsonStr(resultslist)), TransferResult.class);
for
(
TransferResult
result
:
results
)
{
log
.
info
(
"results={}"
,
JSONUtil
.
toJsonStr
(
result
));
Traffalarmrecord
record
=
new
Traffalarmrecord
();
record
.
setRecordid
(
result
.
getRecordid
());
if
(
result
.
getResult
())
{
switch
(
result
.
getPathvalue
())
{
...
...
@@ -284,20 +259,14 @@ public class FileTransferManager {
// log.info("unknow pathvalue"+ result.getPathvalue());
break
;
}
// 更新数据
traffAlarmRecordMapper
.
updateTraffAlarmRecordUrl
(
record
);
}
}
return
record
;
}
// public static void main(String[] args) {
// urls.add("http://img63.ddimg.cn/2019/12/18/2019121819114913026.jpg");
// urls.add("http://img62.ddimg.cn/2019/12/18/201912181655214974.jpg");
// urls.add("http://img61.ddimg.cn/2019/12/18/2019121816294684833.jpg");
// urls.add("http://img63.ddimg.cn/2019/12/18/2019121819121717247.jpg");
// urls.add("http://img62.ddimg.cn/2019/12/18/201912181655214974.jpg");
// }
}
src/main/java/com/hzjt/redis/Receiver.java
View file @
f03f4acb
...
...
@@ -25,7 +25,7 @@ import java.util.concurrent.Executors;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
@Service
//
@Service
public
class
Receiver
{
@Autowired
...
...
@@ -112,65 +112,67 @@ public class Receiver {
String
basepath
=
"gstraff/"
+
traffAlarmRecord
.
getFdid
()
+
(
traffAlarmRecord
.
getChannelid
()
<
10
?
"0"
+
traffAlarmRecord
.
getChannelid
()
:
traffAlarmRecord
.
getChannelid
())
+
"/"
+
DateUtils
.
formatCurrDayNoSign
();
Map
<
String
,
Object
>
transferRecordMap
=
new
HashMap
<>();
FileTransferManager
.
fetchUrlsFromRecord
(
traffAlarmRecord
,
transferRecordMap
);
List
<
TransferResult
>
results
=
FileTransferManager
.
transferFile
(
transferRecordMap
,
ftp
,
basepath
);
FileTransferManager
fileTransferManager
=
new
FileTransferManager
();
List
<
TransferResult
>
results
=
fileTransferManager
.
transferFile
(
transferRecordMap
,
ftp
,
basepath
,
traffAlarmRecordMapper
);
// log.info("缓存数据上传结果:" + results.toString());
Traffalarmrecord
recordBak
=
FileTransferManager
.
traffAlarmRecordUrlUpdate
(
results
);
traffAlarmRecord
.
setImg2path
(
recordBak
.
getImg2path
());
traffAlarmRecord
.
setImg3path
(
recordBak
.
getImg3path
());
traffAlarmRecord
.
setImg4path
(
recordBak
.
getImg4path
());
traffAlarmRecord
.
setImg5path
(
recordBak
.
getImg5path
());
traffAlarmRecord
.
setVideopath
(
recordBak
.
getVideopath
());
if
(
traffAlarmRecord
!=
null
&&
traffAlarmRecord
.
getRecordid
()
!=
null
)
{
traffAlarmRecordMapper
.
updateTraffAlarmRecordUrl
(
traffAlarmRecord
);
}
//如果监控视频为空,延时加载重新获取
if
(
null
==
recordBak
.
getVideopath
()
||
""
.
equalsIgnoreCase
(
recordBak
.
getVideopath
()))
{
schedulepool
.
schedule
(()->{
for
(
String
key
:
transferRecordMap
.
keySet
())
{
if
(
key
.
equals
(
"videopath"
))
{
final
String
url
=
transferRecordMap
.
get
(
key
).
toString
();
try
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
//延迟连接
connection
.
setReadTimeout
(
2000
);
connection
.
setConnectTimeout
(
3000
);
connection
.
setRequestMethod
(
"GET"
);
String
pname
=
DateUtils
.
formatCurrDayNoSign
()+
"_"
+
traffAlarmRecord
.
getFdid
()+
"_"
+
traffAlarmRecord
.
getRecordid
()
+
key
.
replace
(
"path"
,
""
);
String
fileName
=
pname
+
".mp4"
;
String
ftputl
=
FTPUtil
.
getFtpUrl
(
ftp
)
+
basepath
+
"/"
+
fileName
;
if
(
connection
.
getResponseCode
()
==
HttpURLConnection
.
HTTP_OK
)
{
InputStream
inputStream
=
connection
.
getInputStream
();
// log.info("url:", url, " --- " + "key:", key);
boolean
r
=
FTPUtil
.
uploadFile
(
ftp
,
basepath
,
fileName
,
inputStream
);
if
(
r
)
traffAlarmRecord
.
setVideopath
(
ftputl
);
//只更新监控
if
(
traffAlarmRecord
!=
null
&&
traffAlarmRecord
.
getRecordid
()
!=
null
)
{
traffAlarmRecordMapper
.
updateTraffAlarmRecordUrl
(
traffAlarmRecord
);
//推送给第三方
ResultObj
obj
=
eventWriteService
.
updateAndAutoSendEvent
(
traffAlarmRecord
);
// log.info("调用接口推送给广达返回信息:" + obj.toString());
}
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
toString
());
log
.
error
(
e
.
toString
());
return
0
;
}
}
}
return
1
;
},
30
,
TimeUnit
.
SECONDS
);
//等待30秒钟执行
}
else
{
//推送给第三方
ResultObj
obj
=
eventWriteService
.
updateAndAutoSendEvent
(
traffAlarmRecord
);
// log.info("调用接口推送给广达返回信息:" + obj.toString());
}
fileTransferManager
.
traffAlarmRecordUrlUpdate
(
results
,
traffAlarmRecordMapper
);
// traffAlarmRecord.setImg2path(recordBak.getImg2path());
// traffAlarmRecord.setImg3path(recordBak.getImg3path());
// traffAlarmRecord.setImg4path(recordBak.getImg4path());
// traffAlarmRecord.setImg5path(recordBak.getImg5path());
// traffAlarmRecord.setVideopath(recordBak.getVideopath());
//
// if (traffAlarmRecord != null && traffAlarmRecord.getRecordid() != null) {
// traffAlarmRecordMapper.updateTraffAlarmRecordUrl(traffAlarmRecord);
// }
// //如果监控视频为空,延时加载重新获取
// if(null==recordBak.getVideopath() || "".equalsIgnoreCase(recordBak.getVideopath())) {
//
// schedulepool.schedule(()->{
// for (String key : transferRecordMap.keySet()) {
// if (key.equals("videopath")) {
// final String url = transferRecordMap.get(key).toString();
// try {
// HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
// //延迟连接
// connection.setReadTimeout(2000);
// connection.setConnectTimeout(3000);
// connection.setRequestMethod("GET");
// String pname = DateUtils.formatCurrDayNoSign()+ "_" + traffAlarmRecord.getFdid()+ "_" + traffAlarmRecord.getRecordid() + key.replace("path", "");
// String fileName = pname + ".mp4";
// String ftputl = FTPUtil.getFtpUrl(ftp) + basepath + "/" + fileName;
// if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
// InputStream inputStream = connection.getInputStream();
//// log.info("url:", url, " --- " + "key:", key);
// boolean r = FTPUtil.uploadFile(ftp, basepath, fileName, inputStream);
// if (r) traffAlarmRecord.setVideopath(ftputl);
// //只更新监控
// if (traffAlarmRecord != null && traffAlarmRecord.getRecordid() != null) {
// traffAlarmRecordMapper.updateTraffAlarmRecordUrl(traffAlarmRecord);
//
// //推送给第三方
// ResultObj obj = eventWriteService.updateAndAutoSendEvent(traffAlarmRecord);
//// log.info("调用接口推送给广达返回信息:" + obj.toString());
//
// }
// }
// } catch (IOException e) {
// System.out.println(e.toString());
// log.error(e.toString());
// return 0;
// }
// }
//
// }
// return 1;
// },30, TimeUnit.SECONDS); //等待30秒钟执行
// }else {
// //推送给第三方
// ResultObj obj = eventWriteService.updateAndAutoSendEvent(traffAlarmRecord);
//// log.info("调用接口推送给广达返回信息:" + obj.toString());
//
// }
}
catch
(
Exception
e
)
{
log
.
error
(
"解析事件告警数据异常 :"
+
e
.
getMessage
());
...
...
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