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
4c3e5a68
Commit
4c3e5a68
authored
Apr 06, 2023
by
fudahua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 新版本的下载
parent
2980fe23
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
41 deletions
+53
-41
FlatQueryResultServiceImpl.java
...ud/data/hook/service/impl/FlatQueryResultServiceImpl.java
+53
-41
No files found.
gic-cloud-data-hook-service/src/main/java/com/gic/cloud/data/hook/service/impl/FlatQueryResultServiceImpl.java
View file @
4c3e5a68
...
@@ -53,6 +53,8 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
...
@@ -53,6 +53,8 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.function.Consumer
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/** 自助指标查询服务实现
/** 自助指标查询服务实现
...
@@ -878,8 +880,11 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
...
@@ -878,8 +880,11 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
xlsxFiles
.
add
(
currentFile
.
get
().
filepath
);
xlsxFiles
.
add
(
currentFile
.
get
().
filepath
);
}
}
saveXlsSplitNew
(
currentFile
.
get
().
filepath
,
cells
,
titles
,
currentFile
.
get
(),
count
);
saveXlsSplitNew
(
currentFile
.
get
().
filepath
,
cells
,
titles
,
currentFile
.
get
(),
count
,
false
);
});
});
//结束
saveXlsSplitNew
(
currentFile
.
get
().
filepath
,
null
,
null
,
currentFile
.
get
(),
count
,
true
);
//是否压缩
//是否压缩
boolean
zipFlag
=
(
xlsxFiles
.
size
()
>
1
)
?
true
:
false
;
boolean
zipFlag
=
(
xlsxFiles
.
size
()
>
1
)
?
true
:
false
;
String
cloudFileUrl
=
null
;
String
cloudFileUrl
=
null
;
...
@@ -921,7 +926,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
...
@@ -921,7 +926,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
* @param dirName
* @param dirName
* @param func
* @param func
*/
*/
private
void
readCsvFile
(
String
tableId
,
String
dirName
,
DownloadFunc
func
){
private
void
readCsvFile
(
String
tableId
,
String
dirName
,
DownloadFunc
func
){
File
file
=
new
File
(
SAVE_FOLDER
+
"/"
+
dirName
);
File
file
=
new
File
(
SAVE_FOLDER
+
"/"
+
dirName
);
File
[]
files
=
file
.
listFiles
();
File
[]
files
=
file
.
listFiles
();
List
<
ColumnInfo
>
titles
=
null
;
List
<
ColumnInfo
>
titles
=
null
;
...
@@ -945,6 +950,9 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
...
@@ -945,6 +950,9 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
titles
.
add
(
columnInfoMap
.
get
(
cell
));
titles
.
add
(
columnInfoMap
.
get
(
cell
));
}
}
}
}
if
(
first
)
{
continue
;
}
func
.
deal
(
cells
,
titles
,
first
);
func
.
deal
(
cells
,
titles
,
first
);
first
=
false
;
first
=
false
;
}
while
((
cells
=
csvReader
.
readNext
())!=
null
);
}
while
((
cells
=
csvReader
.
readNext
())!=
null
);
...
@@ -1146,7 +1154,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
...
@@ -1146,7 +1154,7 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
* @param originalFilePath
* @param originalFilePath
* @param cells
* @param cells
*/
*/
private
void
saveXlsSplitNew
(
String
originalFilePath
,
String
[]
cells
,
List
<
ColumnInfo
>
titles
,
XlsxFileInfo
xlsxFileInfo
,
AtomicInteger
count
){
private
void
saveXlsSplitNew
(
String
originalFilePath
,
String
[]
cells
,
List
<
ColumnInfo
>
titles
,
XlsxFileInfo
xlsxFileInfo
,
AtomicInteger
count
,
boolean
endFlag
){
try
{
try
{
if
(
xlsxFileInfo
.
workbook
==
null
)
{
if
(
xlsxFileInfo
.
workbook
==
null
)
{
xlsxFileInfo
.
workbook
=
new
SXSSFWorkbook
(
100
);
xlsxFileInfo
.
workbook
=
new
SXSSFWorkbook
(
100
);
...
@@ -1160,51 +1168,55 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
...
@@ -1160,51 +1168,55 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
}
}
return
;
return
;
}
}
SXSSFWorkbook
wb
=
xlsxFileInfo
.
workbook
;
// 内存中保留 100 行
Sheet
sheet
=
wb
.
getSheetAt
(
0
);
//日期
CellStyle
yyyyMMddhhmmss
=
wb
.
createCellStyle
();
DataFormat
dataFormat
=
wb
.
createDataFormat
();
yyyyMMddhhmmss
.
setDataFormat
(
dataFormat
.
getFormat
(
"yyyy-MM-dd HH:mm:ss"
));
//日期
CellStyle
yyyyMMdd
=
wb
.
createCellStyle
();
DataFormat
yyyyMMddDataFormat
=
wb
.
createDataFormat
();
yyyyMMdd
.
setDataFormat
(
yyyyMMddDataFormat
.
getFormat
(
"yyyy-MM-dd"
));
Row
row
=
sheet
.
createRow
(
count
.
get
());
SXSSFWorkbook
wb
=
xlsxFileInfo
.
workbook
;
// 内存中保留 100 行
for
(
int
j
=
0
;
j
<
cells
.
length
;
j
++){
if
(!
endFlag
)
{
String
type
=
titles
.
get
(
j
).
getType
();
Sheet
sheet
=
wb
.
getSheetAt
(
0
);
Cell
midCell
=
row
.
createCell
(
j
);
//日期
String
columnValue
=
cells
[
j
];
CellStyle
yyyyMMddhhmmss
=
wb
.
createCellStyle
();
if
(
StringUtils
.
isBlank
(
columnValue
))
{
DataFormat
dataFormat
=
wb
.
createDataFormat
();
midCell
.
setCellValue
(
columnValue
);
yyyyMMddhhmmss
.
setDataFormat
(
dataFormat
.
getFormat
(
"yyyy-MM-dd HH:mm:ss"
));
continue
;
}
//日期
switch
(
type
)
{
CellStyle
yyyyMMdd
=
wb
.
createCellStyle
();
case
FlatQueryFieldType
.
DATE
:
DataFormat
yyyyMMddDataFormat
=
wb
.
createDataFormat
();
if
(
columnValue
.
length
()==
10
)
{
yyyyMMdd
.
setDataFormat
(
yyyyMMddDataFormat
.
getFormat
(
"yyyy-MM-dd"
));
midCell
.
setCellStyle
(
yyyyMMdd
);
midCell
.
setCellValue
(
DateUtils
.
parseDate
(
columnValue
,
new
String
[]{
"yyyy-MM-dd"
}));
Row
row
=
sheet
.
createRow
(
count
.
get
());
}
else
{
for
(
int
j
=
0
;
j
<
cells
.
length
;
j
++)
{
midCell
.
setCellStyle
(
yyyyMMddhhmmss
);
String
type
=
titles
.
get
(
j
).
getType
();
midCell
.
setCellValue
(
DateUtils
.
parseDate
(
columnValue
,
new
String
[]{
"yyyy-MM-dd HH:mm:ss"
}));
Cell
midCell
=
row
.
createCell
(
j
);
}
String
columnValue
=
cells
[
j
];
break
;
if
(
StringUtils
.
isBlank
(
columnValue
))
{
case
FlatQueryFieldType
.
NUMBER
:
if
(
columnValue
.
indexOf
(
"."
)>
0
)
{
midCell
.
setCellValue
(
Double
.
valueOf
(
columnValue
));
}
else
{
midCell
.
setCellValue
(
Long
.
valueOf
(
columnValue
));
}
break
;
default
:
midCell
.
setCellValue
(
columnValue
);
midCell
.
setCellValue
(
columnValue
);
continue
;
}
switch
(
type
)
{
case
FlatQueryFieldType
.
DATE
:
if
(
columnValue
.
length
()
==
10
)
{
midCell
.
setCellStyle
(
yyyyMMdd
);
midCell
.
setCellValue
(
DateUtils
.
parseDate
(
columnValue
,
new
String
[]{
"yyyy-MM-dd"
}));
}
else
{
midCell
.
setCellStyle
(
yyyyMMddhhmmss
);
midCell
.
setCellValue
(
DateUtils
.
parseDate
(
columnValue
,
new
String
[]{
"yyyy-MM-dd HH:mm:ss"
}));
}
break
;
case
FlatQueryFieldType
.
NUMBER
:
if
(
columnValue
.
indexOf
(
"."
)
>
0
)
{
midCell
.
setCellValue
(
Double
.
valueOf
(
columnValue
));
}
else
{
midCell
.
setCellValue
(
Long
.
valueOf
(
columnValue
));
}
break
;
default
:
midCell
.
setCellValue
(
columnValue
);
}
}
}
}
}
Integer
limitSize
=
FileUtil
.
getLimitSize
();
Integer
limitSize
=
FileUtil
.
getLimitSize
();
int
c
=
count
.
incrementAndGet
();
int
c
=
count
.
incrementAndGet
();
if
(
c
>=
limitSize
)
{
if
(
c
>=
limitSize
||
endFlag
)
{
FileOutputStream
fileOut
=
new
FileOutputStream
(
originalFilePath
);
FileOutputStream
fileOut
=
new
FileOutputStream
(
originalFilePath
);
wb
.
write
(
fileOut
);
wb
.
write
(
fileOut
);
//fileOut.flush(); // SXSSFWorkbook 使用 auto-flush 模式
//fileOut.flush(); // SXSSFWorkbook 使用 auto-flush 模式
...
...
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