Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-cloud
Overview
Overview
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
data-hook
gic-cloud
Commits
00adaa76
Commit
00adaa76
authored
Apr 07, 2023
by
fudahua
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-2023-04' into 'developer'
Feature 2023 04 See merge request
!78
parents
c64838a4
35143a96
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
30 deletions
+63
-30
HDFSUtil.java
...c/main/java/com/gic/cloud/data/hook/service/HDFSUtil.java
+1
-1
FlatQueryResultServiceImpl.java
...ud/data/hook/service/impl/FlatQueryResultServiceImpl.java
+61
-28
Test.java
gic-cloud-data-hook-service/src/test/java/Test.java
+1
-1
No files found.
gic-cloud-data-hook-service/src/main/java/com/gic/cloud/data/hook/service/HDFSUtil.java
View file @
00adaa76
...
...
@@ -47,7 +47,7 @@ public class HDFSUtil {
*/
public
boolean
downloadFile
(
String
srcPath
,
String
toPath
)
{
try
{
fileSystem
.
copyToLocalFile
(
fals
e
,
new
Path
(
srcPath
),
new
Path
(
toPath
));
fileSystem
.
copyToLocalFile
(
tru
e
,
new
Path
(
srcPath
),
new
Path
(
toPath
));
return
true
;
}
catch
(
IOException
e
)
{
logger
.
info
(
"下载失败:{}"
,
e
);
...
...
gic-cloud-data-hook-service/src/main/java/com/gic/cloud/data/hook/service/impl/FlatQueryResultServiceImpl.java
View file @
00adaa76
...
...
@@ -105,7 +105,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
private
FlatQueryResultServiceImpl
()
{
log
.
debug
(
"construct"
,
"准备初始化 FlatQuery 查询服务"
);
//
runDealHiveFile(3);
runDealHiveFile
(
3
);
// runDistTask(3);
runDownloadTask
(
3
);
runBalaDownloadTask
(
3
);
...
...
@@ -864,31 +864,31 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
//下载文件
String
dirName
=
"hdfs"
+
task
.
getId
();
String
path
=
HDFS_URL
+
"/"
+
dirName
;
boolean
downloadFlag
=
HDFSUtil
.
getInstance
().
downloadFile
(
path
,
SAVE_FOLDER
);
if
(!
downloadFlag
)
{
logger
.
info
(
"下载失败:{}-{}"
,
path
,
JSONObject
.
toJSONString
(
task
));
return
;
}
List
<
String
>
xlsxFiles
=
new
ArrayList
<>();
AtomicInteger
count
=
new
AtomicInteger
(
0
);
AtomicReference
<
XlsxFileInfo
>
currentFile
=
new
AtomicReference
<>();
readCsvFile
(
condition
,
dirName
,(
cells
,
titles
,
firstFlag
)->{
if
(
count
.
get
()==
0
)
{
XlsxFileInfo
xlsxFileInfo
=
new
XlsxFileInfo
();
xlsxFileInfo
.
filepath
=
SAVE_FOLDER
+
"/"
+
task
.
getId
()
+
xlsxFiles
.
size
()
+
".xlsx"
;
currentFile
.
set
(
xlsxFileInfo
);
xlsxFiles
.
add
(
currentFile
.
get
().
filepath
);
}
saveXlsSplitNew
(
currentFile
.
get
().
filepath
,
cells
,
titles
,
currentFile
.
get
(),
count
,
false
);
count
.
incrementAndGet
();
});
//结束
saveXlsSplitNew
(
currentFile
.
get
().
filepath
,
null
,
null
,
currentFile
.
get
(),
count
,
true
);
//是否压缩
boolean
zipFlag
=
(
xlsxFiles
.
size
()
>
1
)
?
true
:
false
;
String
cloudFileUrl
=
null
;
try
{
boolean
downloadFlag
=
HDFSUtil
.
getInstance
().
downloadFile
(
path
,
SAVE_FOLDER
);
if
(!
downloadFlag
)
{
logger
.
info
(
"下载失败:{}-{}"
,
path
,
JSONObject
.
toJSONString
(
task
));
return
;
}
List
<
String
>
xlsxFiles
=
new
ArrayList
<>();
AtomicInteger
count
=
new
AtomicInteger
(
0
);
AtomicReference
<
XlsxFileInfo
>
currentFile
=
new
AtomicReference
<>();
readCsvFile
(
condition
,
dirName
,(
cells
,
titles
,
firstFlag
)->{
if
(
count
.
get
()==
0
)
{
XlsxFileInfo
xlsxFileInfo
=
new
XlsxFileInfo
();
xlsxFileInfo
.
filepath
=
SAVE_FOLDER
+
"/"
+
task
.
getId
()
+
xlsxFiles
.
size
()
+
".xlsx"
;
currentFile
.
set
(
xlsxFileInfo
);
xlsxFiles
.
add
(
currentFile
.
get
().
filepath
);
}
saveXlsSplitNew
(
currentFile
.
get
().
filepath
,
cells
,
titles
,
currentFile
.
get
(),
count
,
false
);
count
.
incrementAndGet
();
});
//结束
saveXlsSplitNew
(
currentFile
.
get
().
filepath
,
null
,
null
,
currentFile
.
get
(),
count
,
true
);
//是否压缩
boolean
zipFlag
=
(
xlsxFiles
.
size
()
>
1
)
?
true
:
false
;
String
cloudFileUrl
=
null
;
String
taskFileExt
=
task
.
getUseCompress
().
equals
(
Global
.
YES
)
||
zipFlag
?
".zip"
:
task
.
getFormat
().
equals
(
DownloadFileFormat
.
CSV
)
?
".csv"
:
".xlsx"
;
if
(
zipFlag
||
task
.
getUseCompress
().
equals
(
Global
.
YES
))
{
logger
.
info
(
"[ runDownloadTask.run ]: {}"
,
"准备生成自助指标压缩文件 "
+
task
.
getId
()
+
".zip"
);
...
...
@@ -908,10 +908,15 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
task
.
setStatus
(
DownloadTaskStatus
.
COMPLISHED
);
task
.
setOverTime
(
new
Date
());
task
.
setFilePath
(
cloudFileUrl
);
DownloadTaskServiceImpl
.
getInstance
().
updateDownloadTask
(
task
);
}
catch
(
Exception
e
)
{
logger
.
info
(
"异常:{}"
,
e
);
task
.
setStatus
(
DownloadTaskStatus
.
ERROR
);
}
finally
{
DownloadTaskServiceImpl
.
getInstance
().
updateDownloadTask
(
task
);
//删除文件
delFileOrDirByTaskId
(
task
.
getId
());
}
}
...
...
@@ -921,6 +926,35 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
}
private
void
delFileOrDirByTaskId
(
String
taskId
){
File
file
=
new
File
(
SAVE_FOLDER
);
File
[]
files
=
file
.
listFiles
();
for
(
File
midFile
:
files
)
{
if
(
midFile
.
getName
().
indexOf
(
taskId
)!=-
1
)
{
if
(
midFile
.
isDirectory
())
{
delDir
(
midFile
);
}
else
{
midFile
.
delete
();
}
}
}
}
private
void
delDir
(
File
dirFile
)
{
if
(
dirFile
.
getPath
().
startsWith
(
SAVE_FOLDER
))
{
File
[]
files
=
dirFile
.
listFiles
();
for
(
File
file
:
files
)
{
if
(
file
.
isDirectory
())
{
delDir
(
file
);
}
else
{
file
.
delete
();
}
}
dirFile
.
delete
();
}
}
/**
* 读物文件
* @param dirName
...
...
@@ -954,8 +988,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
}
func
.
deal
(
cells
,
titles
,
first
);
}
while
((
cells
=
csvReader
.
readNext
())!=
null
);
csvReader
.
close
();
}
catch
(
Exception
e
)
{
logger
.
info
(
"读取异常:{}"
,
e
);
}
...
...
gic-cloud-data-hook-service/src/test/java/Test.java
View file @
00adaa76
...
...
@@ -18,7 +18,7 @@ public class Test {
@org
.
junit
.
Test
public
void
test
(){
DownloadTask
downloadTask
=
downloadTaskService
.
getDownloadTaskById
(
"1680
778799753
"
);
DownloadTask
downloadTask
=
downloadTaskService
.
getDownloadTaskById
(
"1680
832767459
"
);
flatQueryResultService
.
takeFileNew
(
downloadTask
);
try
{
Thread
.
sleep
(
10000000000L
);
...
...
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