Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hzjtpushwebsocket
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
gszd
hzjtpushwebsocket
Commits
0f52ca5c
Commit
0f52ca5c
authored
May 24, 2021
by
wangjinjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加推送设备功能
parent
eb774678
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
67 deletions
+77
-67
src/main/java/com/hzjt/config/ScheduleTaskConfig.java
src/main/java/com/hzjt/config/ScheduleTaskConfig.java
+10
-5
src/main/java/com/hzjt/service/TraffdevicewriteresultService.java
.../java/com/hzjt/service/TraffdevicewriteresultService.java
+9
-9
src/main/java/com/hzjt/util/FTPUtil.java
src/main/java/com/hzjt/util/FTPUtil.java
+43
-39
src/main/resources/mapper/TraffdevicewriteresultMapper.xml
src/main/resources/mapper/TraffdevicewriteresultMapper.xml
+15
-14
No files found.
src/main/java/com/hzjt/config/ScheduleTaskConfig.java
View file @
0f52ca5c
...
...
@@ -60,16 +60,21 @@ public class ScheduleTaskConfig {
}
@Scheduled
(
cron
=
"0 */2 * * * ?"
)
//每2分钟执行一次
//
@Scheduled(cron = "0 */2 * * * ?")//每2分钟执行一次
private
void
sendToguangda
()
{
//查询所有未推送的数据
List
<
Traffalarmrecord
>
resultlist
=
traffalarmrecordService
.
getTraffalarmrecordBystatus
();
for
(
Traffalarmrecord
record:
resultlist
)
{
ResultObj
obj
=
eventWriteService
.
updateAndAutoSendEvent
(
record
);
if
(
obj
.
getStatus
()
!=
200
)
{
log
.
error
(
record
.
getRecordid
()+
" send to guangda fail"
);
try
{
ResultObj
obj
=
eventWriteService
.
updateAndAutoSendEvent
(
record
);
if
(
obj
.
getStatus
()
!=
200
)
{
log
.
error
(
record
.
getRecordid
()
+
" send to guangda fail"
);
}
else
{
log
.
info
(
record
.
getRecordid
()
+
" send to guangda success"
);
}
}
catch
(
Exception
ex
){
log
.
error
(
record
.
getRecordid
()
+
" send to guangda fail"
+
ex
.
toString
());
}
}
...
...
src/main/java/com/hzjt/service/TraffdevicewriteresultService.java
View file @
0f52ca5c
...
...
@@ -62,17 +62,17 @@ public class TraffdevicewriteresultService {
Traffdevicewriteresult
param
=
new
Traffdevicewriteresult
();
for
(
SbtdspsrParams
val
:
sbtdspsrs
)
{
threadService
.
submit
(()
->
{
//
log.info("sendtoguangda"+val.toString());
//
threadService.submit(() -> {
log
.
info
(
"sendtoguangda"
+
val
.
toString
());
ResultObj
obj
=
sendToGuangda
(
val
,
param
);
obj
.
setData
(
val
.
get
Sbbh
()
+
"_"
+
val
.
getTdb
h
());
return
obj
;
obj
.
setData
(
val
.
get
X
h
());
resultObj
.
add
(
obj
)
;
});
}
for
(
int
i
=
0
;
i
<
sbtdspsrs
.
size
();
i
++)
{
resultObj
.
add
(
threadService
.
poll
(
10
,
TimeUnit
.
SECONDS
).
get
());
// });
}
// for (int i = 0; i < sbtdspsrs.size(); i++) {
// resultObj.add(threadService.poll(10, TimeUnit.SECONDS).get());
// }
}
catch
(
Exception
e
)
{
log
.
error
(
"devicewrite - sendEvent 异常:"
+
e
.
toString
());
...
...
@@ -81,7 +81,7 @@ public class TraffdevicewriteresultService {
return
resultObj
;
}
public
ResultObj
sendToGuangda
(
SbtdspsrParams
val
,
Traffdevicewriteresult
param
)
throws
Exception
{
public
ResultObj
sendToGuangda
(
SbtdspsrParams
val
,
Traffdevicewriteresult
param
){
if
(
val
.
getXzbh
()
==
null
)
{
log
.
error
(
"deviceWritePost {} : regist remsg..."
,
"设备所属单位机构编码必填"
);
return
ResultObj
.
error
(
ResponseEnum
.
E_1002
.
getCode
(),
"设备所属单位机构编码必填"
);
...
...
src/main/java/com/hzjt/util/FTPUtil.java
View file @
0f52ca5c
...
...
@@ -33,8 +33,8 @@ public class FTPUtil {
@PostConstruct
private
void
initHostMap
(){
if
(
ftpHost
==
null
){
log
.
error
(
"ftp
存储组未配置,请先配置
"
);
log
.
error
(
"ftp
存储组未配置,请先配置
"
);
log
.
error
(
"ftp
�洢��δ���ã���������"
);
log
.
error
(
"ftp
�洢��δ���ã���������"
);
return
;
}
...
...
@@ -57,7 +57,7 @@ public class FTPUtil {
return
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"FTP
下载图片出错
"
,
e
);
log
.
error
(
"FTP
����ͼƬ����"
,
e
);
}
finally
{
IOUtils
.
closeQuietly
(
toClient
);
IOUtils
.
closeQuietly
(
is
);
...
...
@@ -70,25 +70,29 @@ public class FTPUtil {
try
{
url
=
new
URL
(
path
);
}
catch
(
MalformedURLException
e
)
{
log
.
error
(
"FTP URL
路径错误
"
+
e
.
toString
());
log
.
error
(
"FTP URL
error
"
+
e
.
toString
());
}
byte
[]
buffer
=
null
;
try
(
InputStream
is
=
url
.
openStream
();
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
(
1000
)){
byte
[]
b
=
new
byte
[
1000
];
int
n
;
while
((
n
=
is
.
read
(
b
))
!=
-
1
)
{
bos
.
write
(
b
,
0
,
n
);
try
{
InputStream
is
=
url
.
openStream
();
if
(
null
!=
is
)
{
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
(
1000
);
byte
[]
b
=
new
byte
[
1000
];
int
n
;
while
((
n
=
is
.
read
(
b
))
!=
-
1
)
{
bos
.
write
(
b
,
0
,
n
);
}
buffer
=
bos
.
toByteArray
();
}
buffer
=
bos
.
toByteArray
();
}
catch
(
Exception
e
)
{
log
.
error
(
"FTP
下载图片出错
"
,
e
);
log
.
error
(
"FTP
error
"
,
e
);
}
return
buffer
;
}
//ftp图片
上传,图片参数为base64封装的
String
//ftpͼƬ
�ϴ���ͼƬ����Ϊbase64��װ��String
public
static
boolean
uploadFile
(
Ftp
ftpUrl
,
String
path
,
String
filename
,
String
inputImg
)
{
boolean
flag
=
true
;
FTPClient
ftpClient
=
null
;
...
...
@@ -97,7 +101,7 @@ public class FTPUtil {
if
(
inputImg
==
null
)
{
return
false
;
}
//base64
解码
//base64
����
BASE64Decoder
decoder
=
new
BASE64Decoder
();
byte
[]
b_img
=
decoder
.
decodeBuffer
(
inputImg
);
input
=
new
ByteArrayInputStream
(
b_img
);
...
...
@@ -107,15 +111,15 @@ public class FTPUtil {
changeWorkingDirectory
(
ftpClient
,
path
);
flag
=
ftpClient
.
storeFile
(
filename
,
input
);
if
(
flag
)
{
// log.info("FTP
上传文件成功!
");
// log.info("FTP
�ϴ��ļ��ɹ���");
}
else
{
flag
=
false
;
log
.
info
(
"FTP
上传文件失败!
"
);
log
.
info
(
"FTP
�ϴ��ļ�ʧ�ܣ�"
);
}
}
}
catch
(
Exception
e
)
{
flag
=
false
;
log
.
error
(
"FTP
文件上传失败!
"
,
e
.
toString
());
log
.
error
(
"FTP
�ļ��ϴ�ʧ�ܣ�"
,
e
.
toString
());
}
finally
{
IOUtils
.
closeQuietly
(
input
);
closeConnect
(
ftpClient
);
...
...
@@ -132,20 +136,20 @@ public class FTPUtil {
changeWorkingDirectory
(
ftpClient
,
path
);
flag
=
ftpClient
.
storeFile
(
filename
,
input
);
if
(
flag
)
{
// log.info("FTP upload success
!
");
// log.info("FTP upload success
��"
);
}
else
{
log
.
info
(
"FTP upload fail
!
"
);
log
.
info
(
"FTP upload fail
��"
);
}
}
else
{
flag
=
false
;
// log.info("FTP server refused connection
!
");
// log.info("FTP server refused connection
��"
);
}
}
catch
(
IOException
e
)
{
flag
=
false
;
log
.
error
(
"FTP upload fail
!
"
,
e
);
log
.
error
(
"FTP upload fail
��"
,
e
);
}
catch
(
Exception
e
)
{
flag
=
false
;
log
.
error
(
"FTP upload fail
!
"
,
e
);
log
.
error
(
"FTP upload fail
��"
,
e
);
}
finally
{
IOUtils
.
closeQuietly
(
input
);
closeConnect
(
ftpClient
);
...
...
@@ -154,7 +158,7 @@ public class FTPUtil {
}
/*
*
得到配置文件中的FTP服务器地
址
*
�õ������ļ��е�FTP��������ַ
*/
public
static
String
getFtpUrl
(
Ftp
ftpUrl
)
{
StringBuffer
buffer
=
new
StringBuffer
();
...
...
@@ -179,13 +183,13 @@ public class FTPUtil {
* @param ftpUrl
* @return
* @throws Exception
* @description 删
除ftp上的文件
* @description ɾ
��ftp�ϵ��ļ�
* @author sunw
*/
public
static
boolean
deleteFileFromFtpUrl
(
String
ftpUrl
)
throws
Exception
{
boolean
flag
=
false
;
if
(
null
==
ftpUrl
||
StringUtils
.
isBlank
(
ftpUrl
))
{
throw
new
Exception
(
"ftpUrl
串为空
"
);
throw
new
Exception
(
"ftpUrl
����"
)
;
}
Map
<
String
,
String
>
result
=
getFtpInfoMapByFullPath
(
ftpUrl
);
String
ftpUser
=
result
.
get
(
"ftpUser"
);
...
...
@@ -197,7 +201,7 @@ public class FTPUtil {
Ftp
ftp
=
FTPUtil
.
getFtpUrlObj
(
ftpIp
,
ftpPort
,
ftpUser
,
ftpPassword
);
FTPClient
ftpClient
=
connectServer
(
ftp
);
if
(
null
==
ftpClient
)
{
throw
new
Exception
(
"ftp
登录失败
"
);
throw
new
Exception
(
"ftp
��¼ʧ�� "
);
}
else
{
String
fullPath
=
(
null
==
path
||
""
.
equals
(
path
.
trim
()))
?
fileName
:
(
path
+
"/"
+
fileName
);
try
{
...
...
@@ -215,12 +219,12 @@ public class FTPUtil {
* @param ftpUrlStr
* @return
* @throws Exception
* @author sunw 通
过图片路径
*
获得ftpuser,ftppassword,ftpip,ftpport,在fpt上的文件路径,文件
realname
* @author sunw ͨ
��ͼƬ·��
*
���ftpuser,ftppassword,ftpip,ftpport,��fpt�ϵ��ļ�·��,�ļ�realna
me
*/
private
static
Map
<
String
,
String
>
getFtpInfoMapByFullPath
(
String
ftpUrlStr
)
throws
Exception
{
if
(
null
==
ftpUrlStr
||
""
.
equals
(
ftpUrlStr
.
trim
()))
{
throw
new
Exception
(
"ftpstr
串为空
"
);
throw
new
Exception
(
"ftpstr
����"
)
;
}
ftpUrlStr
=
ftpUrlStr
.
replaceAll
(
"\\\\"
,
"/"
);
ftpUrlStr
=
changeUrlCharater
(
ftpUrlStr
);
...
...
@@ -232,7 +236,7 @@ public class FTPUtil {
String
ftpPassword
=
ftpUserAndPassword
[
1
];
String
ftpIp
=
ftpIpAndPort
[
0
];
String
ftpPort
=
ftpIpAndPort
.
length
>
1
?
ftpIpAndPort
[
1
]
:
""
;
String
fileName
=
array
[
array
.
length
-
1
];
//
获得文件名
String
fileName
=
array
[
array
.
length
-
1
];
//
������
Map
<
String
,
String
>
resultMap
=
new
HashMap
<
String
,
String
>();
resultMap
.
put
(
"ftpUser"
,
ftpUser
);
resultMap
.
put
(
"ftpPassword"
,
ftpPassword
);
...
...
@@ -257,7 +261,7 @@ public class FTPUtil {
boolean
flag
=
deleteFileFromFtpUrl
(
temp
);
System
.
out
.
println
(
flag
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"删
除文件失败
"
);
System
.
out
.
println
(
"ɾ
���ļ�ʧ��"
);
}
// String [] strSplit = temp.split("/");
// for(int i = 0 ; i < strSplit.length ; i++) {
...
...
@@ -272,7 +276,7 @@ public class FTPUtil {
}
/**
*
连接到服务器
*
���ӵ�������
*/
private
static
FTPClient
connectServer
(
Ftp
ftpUrl
)
{
FTPClient
ftpClient
=
null
;
...
...
@@ -292,18 +296,18 @@ public class FTPUtil {
if
(!
FTPReply
.
isPositiveCompletion
(
reply
))
{
ftpClient
.
disconnect
();
System
.
err
.
println
(
"FTP server refused connection."
);
log
.
info
(
"FTP
服务拒绝连接!
"
);
log
.
info
(
"FTP
����ܾ����ӣ�"
);
}
}
catch
(
SocketException
e
)
{
log
.
error
(
"
登录ftp服务器 "
+
ftpUrl
.
getFtpIp
()
+
" 失败,连接超时!
"
,
e
);
log
.
error
(
"
��¼ftp������ "
+
ftpUrl
.
getFtpIp
()
+
" ʧ��,���ӳ�ʱ��"
,
e
);
}
catch
(
IOException
e
)
{
log
.
error
(
"
登录ftp服务器 "
+
ftpUrl
.
getFtpIp
()
+
" 失败,FTP服务器无法打开!
"
,
e
);
log
.
error
(
"
��¼ftp������ "
+
ftpUrl
.
getFtpIp
()
+
" ʧ�ܣ�FTP����������"
,
e
);
}
return
ftpClient
;
}
/**
*
关闭连接
*
�ر�����
*/
private
static
void
closeConnect
(
FTPClient
ftpClient
)
{
try
{
...
...
@@ -314,12 +318,12 @@ public class FTPUtil {
ftpClient
.
disconnect
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
"
关闭ftp连接失败
"
,
e
);
log
.
error
(
"
�ر�ftp����ʧ��"
,
e
);
}
}
/**
*
进入到服务器的某个目录下
*
���뵽��������ij��Ŀ¼��
*
* @param directory
*/
...
...
@@ -336,12 +340,12 @@ public class FTPUtil {
ftpClient
.
changeWorkingDirectory
(
subPath
);
}
}
catch
(
IOException
ioe
)
{
log
.
error
(
"
改变ftp工作路径失败
"
,
ioe
);
log
.
error
(
"
�ı�ftp����·��ʧ��"
,
io
e
);
}
}
/**
* 转
码[ISO-8859-1 -> GBK] 不同的平台需要不同的转码
* ת
��[ISO-8859-1 -> GBK] ��ͬ��ƽ̨��Ҫ��ͬ��ת��
*
* @param obj
* @return ""
...
...
src/main/resources/mapper/TraffdevicewriteresultMapper.xml
View file @
0f52ca5c
...
...
@@ -2,25 +2,26 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.hzjt.mapper.TraffdevicewriteresultMapper"
>
<select
id=
"querySbtdspsrByXh"
resultType=
"com.hzjt.domain.SbtdspsrParams"
>
SELECT
TA
.*,
A.CREATETIME
,
A.PUSHSTATUS
,
A.PUSHCOUNT
,
A.REMARK
,
A.PUSHDESC
,
p.dept_name
AS
xztreename,
B.remark1 AS
deviceconfig
FROM SBTDSPSR TA
LEFT JOIN TRAFFDEVICEWRITERESULT A ON A.SBBH = TA.SBBH AND A.TDBH = TA.TDBH
LEFT JOIN TRAFFDEVICECONFIG B ON B.FDID = TA.SBBH AND B.CHANNELID = TA.TDBH
LEFT JOIN dept P ON P .dept_id = TA
.xzbh
WHERE 1=1
select
ta
.*,
a.createtime
,
a.pushstatus
,
a.pushcount
,
a.remark
,
a.pushdesc
,
p.dept_name
as
xztreename,
b.remark1 as
deviceconfig
from sbtdspsr ta
left join traffdevicewriteresult a on a.sbbh = ta.sbbh and a.tdbh = ta.tdbh
left join traffdeviceconfig b on b.fdid = ta.sbbh and b.channelid = ta.tdbh
left join dept p on p .dept_id = ta
.xzbh
<where>
<if
test=
"xhs !=null and xhs.size>0 "
>
and TA.XH IN
<foreach
item=
"xh"
collection=
"xhs"
open=
"("
separator=
","
close=
")"
>
#{xh}
</foreach>
</if>
</where>
</select>
</mapper>
\ No newline at end of file
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