Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
di
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
续晓东
di
Commits
999bce9e
Commit
999bce9e
authored
Apr 10, 2020
by
Xuxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成oisstv2定时任务编写
parent
12f456f6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
6 deletions
+66
-6
PullFileTask.java
src/main/java/com/jianju/di/task/PullFileTask.java
+66
-6
No files found.
src/main/java/com/jianju/di/task/PullFileTask.java
View file @
999bce9e
...
@@ -13,6 +13,7 @@ import org.springframework.scheduling.annotation.Scheduled;
...
@@ -13,6 +13,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
...
@@ -82,11 +83,67 @@ public class PullFileTask {
...
@@ -82,11 +83,67 @@ public class PullFileTask {
private
static
final
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
private
static
final
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyyMMdd"
);
private
static
final
SimpleDateFormat
yearDateFormat
=
new
SimpleDateFormat
(
"yyyy"
);
private
static
final
SimpleDateFormat
yearDateFormat
=
new
SimpleDateFormat
(
"yyyy"
);
private
static
final
SimpleDateFormat
yearMonthDateFormat
=
new
SimpleDateFormat
(
"MM"
);
private
static
final
SimpleDateFormat
yearMonthDateFormat
=
new
SimpleDateFormat
(
"MM"
);
private
final
FtpUtil
.
FtpConfig
ftpConfig
=
new
FtpUtil
.
FtpConfig
().
setHost
(
host
).
setPort
(
port
).
setUserName
(
userName
).
setPassword
(
password
);
/**
* Monthly数据入库以及发送di
* 暂定为每晚八点20运行获取上一个月的数据
*/
// @Scheduled(cron = "0 0 20 20 * ?") 目前ftp数据还未准备好,所以暂时先不进行运行
public
void
pullSstvGodasFileAndSendDi
()
throws
Exception
{
FtpUtil
.
FtpConfig
ftpConfig
=
new
FtpUtil
.
FtpConfig
().
setHost
(
host
).
setPort
(
port
).
setUserName
(
userName
).
setPassword
(
password
);
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
new
Date
());
//上一个月
c
.
add
(
Calendar
.
MONTH
,
-
1
);
String
fileName
=
"godas.M."
+
yearMonthDateFormat
.
format
(
c
.
getTime
())+
".grb"
;
log
.
info
(
"开始下载----"
+
fileName
);
long
beforeDown
=
System
.
currentTimeMillis
();
boolean
download
=
FtpUtil
.
download
(
ftpConfig
,
godasMonthlyRemotePath
,
fileName
,
localPath
,
fileName
);
long
afterDown
;
if
(
download
)
{
log
.
info
(
"下载成功"
+
fileName
);
PostGISMannager
postGIS
=
new
PostGISMannager
(
dbHost
,
dbPort
,
dbName
,
godasMonthlyTbName
,
dbUserName
,
dbPassword
);
if
(
postGIS
.
insertGodasToPGMonth
(
godasMonthlyTbName
,
localPath
+
fileName
)
>
0
)
{
// 发送Di
afterDown
=
System
.
currentTimeMillis
();
Date
start
=
new
Date
(
beforeDown
);
long
fileSize
=
new
File
(
localPath
,
fileName
).
length
();
String
diJson
=
sendDi
(
"godas-monthly数据入库"
,
"K.0436.0001.6666"
,
c
.
getTime
(),
new
Date
(
beforeDown
),
new
Date
(
afterDown
),
fileName
,
"1"
,
fileSize
);
OkHttpClient
httpClient
=
new
OkHttpClient
();
RequestBody
requestBody
=
RequestBody
.
create
(
MediaType
.
parse
(
"application/json; charset=utf-8"
),
diJson
);
Request
request
=
new
Request
.
Builder
()
.
url
(
diUrl
)
.
post
(
requestBody
)
.
build
();
//发送请求获取响应
try
{
Response
response
=
httpClient
.
newCall
(
request
).
execute
();
//判断请求是否成功
if
(
response
.
isSuccessful
())
{
//打印服务端返回结果
log
.
info
(
"请求代理返回结果==========:"
+
response
.
body
().
string
());
log
.
info
(
"请求di的Json========="
+
diJson
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
else
{
log
.
info
(
"下载失败"
+
fileName
);
}
}
/**
/**
* Monthly数据入库以及发送di
* Monthly数据入库以及发送di
...
@@ -95,6 +152,7 @@ public class PullFileTask {
...
@@ -95,6 +152,7 @@ public class PullFileTask {
// @Scheduled(cron = "0 0 20 15 * ?") 目前ftp数据还未准备好,所以暂时先不进行运行
// @Scheduled(cron = "0 0 20 15 * ?") 目前ftp数据还未准备好,所以暂时先不进行运行
public
void
pullMonthlyGodasFileAndSendDi
()
throws
Exception
public
void
pullMonthlyGodasFileAndSendDi
()
throws
Exception
{
{
FtpUtil
.
FtpConfig
ftpConfig
=
new
FtpUtil
.
FtpConfig
().
setHost
(
host
).
setPort
(
port
).
setUserName
(
userName
).
setPassword
(
password
);
Calendar
c
=
Calendar
.
getInstance
();
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
new
Date
());
c
.
setTime
(
new
Date
());
//上一个月
//上一个月
...
@@ -152,6 +210,7 @@ public class PullFileTask {
...
@@ -152,6 +210,7 @@ public class PullFileTask {
*/
*/
// @Scheduled(cron = "0 0 20 * * ?") 目前ftp数据还未准备好,所以暂时先不进行运行
// @Scheduled(cron = "0 0 20 * * ?") 目前ftp数据还未准备好,所以暂时先不进行运行
public
void
pullPentadGodasFileAndSendDi
()
throws
Exception
{
public
void
pullPentadGodasFileAndSendDi
()
throws
Exception
{
FtpUtil
.
FtpConfig
ftpConfig
=
new
FtpUtil
.
FtpConfig
().
setHost
(
host
).
setPort
(
port
).
setUserName
(
userName
).
setPassword
(
password
);
Calendar
c
=
Calendar
.
getInstance
();
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
new
Date
());
c
.
setTime
(
new
Date
());
// -2 为ftp上传文件延迟的时间
// -2 为ftp上传文件延迟的时间
...
@@ -211,6 +270,7 @@ public class PullFileTask {
...
@@ -211,6 +270,7 @@ public class PullFileTask {
*/
*/
@Scheduled
(
cron
=
"0 10 20 * * ?"
)
@Scheduled
(
cron
=
"0 10 20 * * ?"
)
public
void
pullOlrFileAndSendDi
()
throws
Exception
{
public
void
pullOlrFileAndSendDi
()
throws
Exception
{
FtpUtil
.
FtpConfig
ftpConfig
=
new
FtpUtil
.
FtpConfig
().
setHost
(
host
).
setPort
(
port
).
setUserName
(
userName
).
setPassword
(
password
);
Calendar
c
=
Calendar
.
getInstance
();
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
new
Date
());
c
.
setTime
(
new
Date
());
c
.
add
(
Calendar
.
DATE
,
-
2
);
c
.
add
(
Calendar
.
DATE
,
-
2
);
...
@@ -298,11 +358,11 @@ public class PullFileTask {
...
@@ -298,11 +358,11 @@ public class PullFileTask {
*
*
* @throws Exception
* @throws Exception
*/
*/
//
@PostConstruct
@PostConstruct
public
void
a
()
throws
Exception
{
public
void
a
()
throws
Exception
{
FtpUtil
.
FtpConfig
ftpConfig
=
new
FtpUtil
.
FtpConfig
().
setHost
(
host
).
setPort
(
port
).
setUserName
(
userName
).
setPassword
(
password
);
FtpUtil
.
FtpConfig
ftpConfig
=
new
FtpUtil
.
FtpConfig
().
setHost
(
host
).
setPort
(
port
).
setUserName
(
userName
).
setPassword
(
password
);
Date
dateStart
=
dateFormat
.
parse
(
"20200
32
5"
);
Date
dateStart
=
dateFormat
.
parse
(
"20200
40
5"
);
Date
dateEnd
=
dateFormat
.
parse
(
"20200
32
5"
);
Date
dateEnd
=
dateFormat
.
parse
(
"20200
40
5"
);
Calendar
c
=
Calendar
.
getInstance
();
Calendar
c
=
Calendar
.
getInstance
();
PostGISMannager
postGIS
=
new
PostGISMannager
(
dbHost
,
dbPort
,
PostGISMannager
postGIS
=
new
PostGISMannager
(
dbHost
,
dbPort
,
dbName
,
olrTbName
,
dbUserName
,
dbPassword
);
dbName
,
olrTbName
,
dbUserName
,
dbPassword
);
...
@@ -322,7 +382,7 @@ public class PullFileTask {
...
@@ -322,7 +382,7 @@ public class PullFileTask {
}
else
{
}
else
{
log
.
info
(
fileName
+
"========入库失败"
);
log
.
info
(
fileName
+
"========入库失败"
);
}
}
}
}
else
{
{
log
.
info
(
fileName
+
"========下载失败"
);
log
.
info
(
fileName
+
"========下载失败"
);
break
;
break
;
...
...
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