Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
baihang-report
Project
Project
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
data-spider
baihang-report
Commits
ef3b1124
Commit
ef3b1124
authored
Mar 12, 2020
by
郝彦辉
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
百行每天的重新报送优化成定时任务3
parent
4aeb8643
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
138 additions
and
152 deletions
+138
-152
ManualToolController.java
...cn/quantgroup/report/controller/ManualToolController.java
+0
-58
RoutineWorkTask.java
src/main/java/cn/quantgroup/report/job/RoutineWorkTask.java
+109
-73
HttpRequestUtil.java
...java/cn/quantgroup/report/utils/http/HttpRequestUtil.java
+29
-21
No files found.
src/main/java/cn/quantgroup/report/controller/ManualToolController.java
View file @
ef3b1124
...
...
@@ -5,16 +5,11 @@ import cn.quantgroup.report.service.common.CommonQueryService;
import
cn.quantgroup.report.service.manualTool.CleanningTransactionLogService
;
import
cn.quantgroup.report.service.manualTool.ManualToolService
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.collect.ImmutableMap
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.net.Inet4Address
;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.util.Enumeration
;
import
java.util.Map
;
@Slf4j
...
...
@@ -197,57 +192,4 @@ public class ManualToolController {
return
"deleteTidbCallRecordCF调度完成"
;
}
@RequestMapping
(
"/deleteRedisKey"
)
public
Map
<
String
,
Object
>
deleteRedisKey
(
String
key1
,
String
key2
,
String
key3
){
try
{
manualToolService
.
deleteRedisKey
(
key1
,
key2
,
key3
);
return
ImmutableMap
.
of
(
"code"
,
0
,
"msg"
,
"手动删除redisKey成功"
);
}
catch
(
Exception
e
){
return
ImmutableMap
.
of
(
"code"
,
1
,
"msg"
,
"手动设置redisKey异常"
);
}
}
@RequestMapping
(
"/getRedisVal"
)
public
String
getRedisVal
(
String
key
){
try
{
return
manualToolService
.
getRedisVal
(
key
);
}
catch
(
Exception
e
){
return
"获取redis值异常"
;
}
}
@RequestMapping
(
"/getIp"
)
public
String
getIp
(){
try
{
return
getServerIp
();
}
catch
(
Exception
e
){
return
"获取本地ip异常"
;
}
}
private
String
getServerIp
()
{
try
{
Enumeration
<
NetworkInterface
>
allNetInterfaces
=
NetworkInterface
.
getNetworkInterfaces
();
while
(
allNetInterfaces
.
hasMoreElements
())
{
NetworkInterface
netInterface
=
(
NetworkInterface
)
allNetInterfaces
.
nextElement
();
Enumeration
<
InetAddress
>
addresses
=
netInterface
.
getInetAddresses
();
while
(
addresses
.
hasMoreElements
())
{
InetAddress
ip
=
(
InetAddress
)
addresses
.
nextElement
();
if
(
ip
!=
null
&&
ip
instanceof
Inet4Address
&&
!
ip
.
isLoopbackAddress
()
/* loopback地址即本机地址,IPv4的loopback范围是127.0.0.0 ~ 127.255.255.255 */
&&
ip
.
getHostAddress
().
indexOf
(
":"
)
==
-
1
)
{
System
.
out
.
println
(
"本机的IP = "
+
ip
.
getHostAddress
());
return
ip
.
getHostAddress
();
}
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"获取本地ip异常"
,
e
);
}
return
null
;
}
}
src/main/java/cn/quantgroup/report/job/RoutineWorkTask.java
View file @
ef3b1124
This diff is collapsed.
Click to expand it.
src/main/java/cn/quantgroup/report/utils/http/HttpRequestUtil.java
View file @
ef3b1124
...
...
@@ -825,34 +825,42 @@ public class HttpRequestUtil {
}
}
//重新报送的工具使用,可能慢
public
static
String
doPostTool
(
String
apiUrl
,
Map
<
String
,
Object
>
params
)
{
String
result
=
""
;
httpClient
=
getHttpClient
();
HttpPost
httpPost
=
new
HttpPost
(
apiUrl
);
String
response
=
""
;
try
{
List
<
NameValuePair
>
pairList
=
new
ArrayList
<>(
params
.
size
());
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
params
.
entrySet
())
{
NameValuePair
pair
=
new
BasicNameValuePair
(
entry
.
getKey
(),
entry
.
getValue
().
toString
());
pairList
.
add
(
pair
);
}
httpPost
.
setEntity
(
new
UrlEncodedFormEntity
(
pairList
,
Charset
.
forName
(
"UTF-8"
)));
HttpResponse
response
=
httpClient
.
execute
(
httpPost
);
String
bodyStr
=
JSON
.
toJSONString
(
params
);
byte
[]
body
=
bodyStr
.
getBytes
(
"UTF-8"
);
java
.
net
.
URL
parsedUrl
=
new
java
.
net
.
URL
(
apiUrl
);
java
.
net
.
HttpURLConnection
conn
=
(
java
.
net
.
HttpURLConnection
)
parsedUrl
.
openConnection
();
//int statusCode = response.getStatusLine().getStatusCode();
HttpEntity
entity
=
response
.
getEntity
();
conn
.
setConnectTimeout
(
6000
);
conn
.
setReadTimeout
(
60000
);
//60秒
conn
.
setUseCaches
(
false
);
result
=
EntityUtils
.
toString
(
entity
);
conn
.
setRequestMethod
(
"POST"
);
conn
.
setDoOutput
(
true
);
conn
.
setRequestProperty
(
"Connection"
,
"keep-alive"
);
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
conn
.
setRequestProperty
(
"Content-Length"
,
String
.
valueOf
(
body
.
length
));
OutputStream
outStream
=
conn
.
getOutputStream
();
outStream
.
write
(
body
);
outStream
.
flush
();
outStream
.
close
();
EntityUtils
.
consume
(
entity
);
if
(
conn
.
getResponseCode
()
==
200
){
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
((
InputStream
)
conn
.
getInputStream
(),
"UTF-8"
));
response
=
in
.
readLine
();
in
.
close
();
}
conn
.
disconnect
();
return
response
;
}
catch
(
Exception
e
)
{
log
.
error
(
"doPostTool httpRequest, apiUrl: "
+
apiUrl
+
"请求失败"
,
e
);
throw
new
QGException
(
QGExceptionType
.
COMMON_THIRD_PART_CALL_EXCEPTION
,
e
.
toString
()+
";url="
+
apiUrl
);
}
finally
{
}
catch
(
IOException
e
)
{
log
.
error
(
"doPostTool请求apiUrl: "
+
apiUrl
+
"请求失败"
,
e
);
throw
new
QGException
(
QGExceptionType
.
COMMON_THIRD_PART_CALL_EXCEPTION
,
e
.
toString
()
+
";url:"
+
apiUrl
);
}
finally
{
httpPost
.
releaseConnection
();
}
return
result
;
}
...
...
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