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
b80e16fe
Commit
b80e16fe
authored
Apr 07, 2023
by
fudahua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 新版本的下载
parent
08bb27ae
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
30 deletions
+31
-30
FlatQueryResultServiceImpl.java
...ud/data/hook/service/impl/FlatQueryResultServiceImpl.java
+30
-29
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/impl/FlatQueryResultServiceImpl.java
View file @
b80e16fe
...
@@ -105,7 +105,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
...
@@ -105,7 +105,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
private
FlatQueryResultServiceImpl
()
{
private
FlatQueryResultServiceImpl
()
{
log
.
debug
(
"construct"
,
"准备初始化 FlatQuery 查询服务"
);
log
.
debug
(
"construct"
,
"准备初始化 FlatQuery 查询服务"
);
//
runDealHiveFile(3);
runDealHiveFile
(
3
);
// runDistTask(3);
// runDistTask(3);
runDownloadTask
(
3
);
runDownloadTask
(
3
);
runBalaDownloadTask
(
3
);
runBalaDownloadTask
(
3
);
...
@@ -864,31 +864,31 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
...
@@ -864,31 +864,31 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
//下载文件
//下载文件
String
dirName
=
"hdfs"
+
task
.
getId
();
String
dirName
=
"hdfs"
+
task
.
getId
();
String
path
=
HDFS_URL
+
"/"
+
dirName
;
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
{
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"
;
String
taskFileExt
=
task
.
getUseCompress
().
equals
(
Global
.
YES
)
||
zipFlag
?
".zip"
:
task
.
getFormat
().
equals
(
DownloadFileFormat
.
CSV
)
?
".csv"
:
".xlsx"
;
if
(
zipFlag
||
task
.
getUseCompress
().
equals
(
Global
.
YES
))
{
if
(
zipFlag
||
task
.
getUseCompress
().
equals
(
Global
.
YES
))
{
logger
.
info
(
"[ runDownloadTask.run ]: {}"
,
"准备生成自助指标压缩文件 "
+
task
.
getId
()
+
".zip"
);
logger
.
info
(
"[ runDownloadTask.run ]: {}"
,
"准备生成自助指标压缩文件 "
+
task
.
getId
()
+
".zip"
);
...
@@ -908,11 +908,13 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
...
@@ -908,11 +908,13 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
task
.
setStatus
(
DownloadTaskStatus
.
COMPLISHED
);
task
.
setStatus
(
DownloadTaskStatus
.
COMPLISHED
);
task
.
setOverTime
(
new
Date
());
task
.
setOverTime
(
new
Date
());
task
.
setFilePath
(
cloudFileUrl
);
task
.
setFilePath
(
cloudFileUrl
);
DownloadTaskServiceImpl
.
getInstance
().
updateDownloadTask
(
task
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
info
(
"异常:{}"
,
e
);
logger
.
info
(
"异常:{}"
,
e
);
task
.
setStatus
(
DownloadTaskStatus
.
ERROR
);
}
finally
{
}
finally
{
DownloadTaskServiceImpl
.
getInstance
().
updateDownloadTask
(
task
);
//删除文件
//删除文件
delFileOrDirByTaskId
(
task
.
getId
());
delFileOrDirByTaskId
(
task
.
getId
());
}
}
...
@@ -928,7 +930,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
...
@@ -928,7 +930,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
File
file
=
new
File
(
SAVE_FOLDER
);
File
file
=
new
File
(
SAVE_FOLDER
);
File
[]
files
=
file
.
listFiles
();
File
[]
files
=
file
.
listFiles
();
for
(
File
midFile
:
files
)
{
for
(
File
midFile
:
files
)
{
if
(
midFile
.
getName
().
equals
(
taskId
)
)
{
if
(
midFile
.
getName
().
indexOf
(
taskId
)!=-
1
)
{
if
(
midFile
.
isDirectory
())
{
if
(
midFile
.
isDirectory
())
{
delDir
(
midFile
);
delDir
(
midFile
);
}
else
{
}
else
{
...
@@ -986,8 +988,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
...
@@ -986,8 +988,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
}
}
func
.
deal
(
cells
,
titles
,
first
);
func
.
deal
(
cells
,
titles
,
first
);
}
while
((
cells
=
csvReader
.
readNext
())!=
null
);
}
while
((
cells
=
csvReader
.
readNext
())!=
null
);
csvReader
.
close
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
info
(
"读取异常:{}"
,
e
);
logger
.
info
(
"读取异常:{}"
,
e
);
}
}
...
...
gic-cloud-data-hook-service/src/test/java/Test.java
View file @
b80e16fe
...
@@ -18,7 +18,7 @@ public class Test {
...
@@ -18,7 +18,7 @@ public class Test {
@org
.
junit
.
Test
@org
.
junit
.
Test
public
void
test
(){
public
void
test
(){
DownloadTask
downloadTask
=
downloadTaskService
.
getDownloadTaskById
(
"1680
778799753
"
);
DownloadTask
downloadTask
=
downloadTaskService
.
getDownloadTaskById
(
"1680
832767459
"
);
flatQueryResultService
.
takeFileNew
(
downloadTask
);
flatQueryResultService
.
takeFileNew
(
downloadTask
);
try
{
try
{
Thread
.
sleep
(
10000000000L
);
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