Toggle navigation
Toggle navigation
This project
Loading...
Sign in
monitor_v3
/
anji-plus-report
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
zhichao
2 years ago
Commit
3faa8c7048ec88d171443d01feac104c81af2050
1 parent
cec56d00
fix:容量视图基本信息左侧图存入库
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
26 additions
and
507 deletions
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/controller/ReportDashboardController.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/ReportDashboardService.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/impl/ReportDashboardServiceImpl.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/entity/GaeaFile.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/service/GaeaFileService.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/service/impl/GaeaFileServiceImpl.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/ReportExcelController.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/ReportExcelService.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/controller/ReportDashboardController.java
View file @
3faa8c7
...
...
@@ -74,31 +74,4 @@ public class ReportDashboardController {
return
ResponseBean
.
builder
().
data
(
reportDashboardService
.
getChartData
(
dto
)).
build
();
}
/**
* 导出大屏
*
* @param reportCode
* @return
*/
@GetMapping
(
"/export"
)
@Permission
(
code
=
"export"
,
name
=
"导出大屏"
)
public
ResponseEntity
<
byte
[]>
exportDashboard
(
HttpServletRequest
request
,
HttpServletResponse
response
,
@RequestParam
(
"reportCode"
)
String
reportCode
,
@RequestParam
(
value
=
"showDataSet"
,
required
=
false
,
defaultValue
=
"1"
)
Integer
showDataSet
)
{
return
reportDashboardService
.
exportDashboard
(
request
,
response
,
reportCode
,
showDataSet
);
}
/**
* 导入大屏
*
* @param file 导入的zip文件
* @param reportCode
* @return
*/
@PostMapping
(
"/import/{reportCode}"
)
@Permission
(
code
=
"import"
,
name
=
"导入大屏"
)
public
ResponseBean
importDashboard
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@PathVariable
(
"reportCode"
)
String
reportCode
)
{
reportDashboardService
.
importDashboard
(
file
,
reportCode
);
return
ResponseBean
.
builder
().
build
();
}
}
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/ReportDashboardService.java
View file @
3faa8c7
...
...
@@ -40,22 +40,4 @@ public interface ReportDashboardService extends GaeaBaseService<ReportDashboardP
* @return
*/
Object
getChartData
(
ChartDto
dto
);
/**
* 导出大屏,zip文件
* @param request
* @param response
* @param reportCode
* @return
*/
ResponseEntity
<
byte
[]>
exportDashboard
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
reportCode
,
Integer
showDataSet
);
/**
* 导入大屏zip
* @param file
* @param reportCode
* @return
*/
void
importDashboard
(
MultipartFile
file
,
String
reportCode
);
}
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dashboard/service/impl/ReportDashboardServiceImpl.java
View file @
3faa8c7
...
...
@@ -70,9 +70,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
@Autowired
private
DataSetService
dataSetService
;
@Autowired
private
GaeaFileService
gaeaFileService
;
@Value
(
"${customer.file.downloadPath:''}"
)
private
String
fileDownloadPath
;
...
...
@@ -111,7 +108,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
value
.
setCollapse
(
StringUtils
.
isNotBlank
(
reportDashboardWidget
.
getCollapse
())
?
JSONObject
.
parseObject
(
reportDashboardWidget
.
getCollapse
())
:
new
JSONObject
());
//实时数据的替换
analysisData
(
value
);
reportDashboardWidgetDto
.
setType
(
reportDashboardWidget
.
getType
());
reportDashboardWidgetDto
.
setValue
(
value
);
reportDashboardWidgetDto
.
setOptions
(
JSONObject
.
parseObject
(
reportDashboardWidget
.
getOptions
()));
...
...
@@ -196,203 +192,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
// return getTarget(chartType).transform(dto, result.getData());
}
/**
* 导出大屏,zip文件
*
* @param request
* @param response
* @param reportCode
* @return
*/
@Override
public
ResponseEntity
<
byte
[]>
exportDashboard
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
reportCode
,
Integer
showDataSet
)
{
String
userAgent
=
request
.
getHeader
(
"User-Agent"
);
boolean
isIeBrowser
=
userAgent
.
indexOf
(
"MSIE"
)
>
0
;
ReportDashboardObjectDto
detail
=
getDetail
(
reportCode
);
List
<
ReportDashboardWidgetDto
>
widgets
=
detail
.
getDashboard
().
getWidgets
();
detail
.
setWidgets
(
widgets
);
detail
.
getDashboard
().
setWidgets
(
null
);
//1.组装临时目录,/app/disk/upload/zip/临时文件夹
String
path
=
dictPath
+
ZIP_PATH
+
UuidUtil
.
generateShortUuid
();
//将涉及到的图片保存下来(1.背景图,2.组件为图片的)
String
backgroundImage
=
detail
.
getDashboard
().
getBackgroundImage
();
zipLoadImage
(
backgroundImage
,
path
);
detail
.
getWidgets
().
stream
().
filter
(
reportDashboardWidgetDto
->
"widget-image"
.
equals
(
reportDashboardWidgetDto
.
getType
())).
forEach
(
reportDashboardWidgetDto
->
{
String
imageAddress
=
reportDashboardWidgetDto
.
getValue
().
getSetup
().
getString
(
"imageAdress"
);
zipLoadImage
(
imageAddress
,
path
);
});
//showDataSet == 0 代表不包含数据集
if
(
0
==
showDataSet
)
{
detail
.
getWidgets
().
forEach
(
reportDashboardWidgetDto
->
{
ReportDashboardWidgetValueDto
value
=
reportDashboardWidgetDto
.
getValue
();
JSONObject
data
=
value
.
getData
();
if
(
null
!=
data
&&
data
.
containsKey
(
"dataType"
))
{
reportDashboardWidgetDto
.
getValue
().
getData
().
put
(
"dataType"
,
"staticData"
);
}
});
}
//2.将大屏设计到的json文件保存
String
jsonPath
=
path
+
"/"
+
JSON_PATH
;
FileUtil
.
WriteStringToFile
(
jsonPath
,
JSONObject
.
toJSONString
(
detail
));
//将path文件夹打包zip
String
zipPath
=
path
+
".zip"
;
FileUtil
.
compress
(
path
,
zipPath
);
File
file
=
new
File
(
zipPath
);
ResponseEntity
.
BodyBuilder
builder
=
ResponseEntity
.
ok
();
builder
.
contentLength
(
file
.
length
());
//application/octet-stream 二进制数据流(最常见的文件下载)
builder
.
contentType
(
MediaType
.
APPLICATION_OCTET_STREAM
);
if
(
isIeBrowser
)
{
builder
.
header
(
"Content-Disposition"
,
"attachment; filename="
+
reportCode
+
".zip"
);
}
else
{
builder
.
header
(
"Content-Disposition"
,
"attacher; filename*=UTF-8''"
+
reportCode
+
".zip"
);
}
ResponseEntity
<
byte
[]>
body
=
builder
.
body
(
FileUtils
.
readFileToByteArray
(
file
));
//删除zip文件
file
.
delete
();
//删除path临时文件夹
FileUtil
.
delete
(
path
);
log
.
info
(
"删除临时文件:{},{}"
,
zipPath
,
path
);
return
body
;
}
/**
* 导入大屏zip
*
* @param file
* @param reportCode
* @return
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
importDashboard
(
MultipartFile
file
,
String
reportCode
)
{
log
.
info
(
"导入开始,{}"
,
reportCode
);
//1.组装临时目录,/app/disk/upload/zip/临时文件夹
String
path
=
dictPath
+
ZIP_PATH
+
UuidUtil
.
generateShortUuid
();
//2.解压
FileUtil
.
decompress
(
file
,
path
);
// path/uuid/
File
parentPath
=
new
File
(
path
);
//获取打包的第一层目录
File
firstFile
=
parentPath
.
listFiles
()[
0
];
File
[]
files
=
firstFile
.
listFiles
();
//定义map
Map
<
String
,
String
>
fileMap
=
new
HashMap
<>();
String
content
=
""
;
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
File
childFile
=
files
[
i
];
if
(
JSON_PATH
.
equals
(
childFile
.
getName
()))
{
//json文件
content
=
FileUtil
.
readFile
(
childFile
);
}
else
if
(
"image"
.
equals
(
childFile
.
getName
()))
{
File
[]
imageFiles
=
childFile
.
listFiles
();
//所有需要上传的图片
for
(
File
imageFile
:
imageFiles
)
{
//查看是否存在此image
String
fileName
=
imageFile
.
getName
().
split
(
"\\."
)[
0
];
//根据fileId,从gaea_file中读出filePath
LambdaQueryWrapper
<
GaeaFile
>
queryWrapper
=
Wrappers
.
lambdaQuery
();
queryWrapper
.
eq
(
GaeaFile:
:
getFileId
,
fileName
);
GaeaFile
gaeaFile
=
gaeaFileService
.
selectOne
(
queryWrapper
);
if
(
null
==
gaeaFile
)
{
GaeaFile
upload
=
gaeaFileService
.
upload
(
imageFile
,
fileName
);
log
.
info
(
"存入图片: {}"
,
upload
.
getFilePath
());
fileMap
.
put
(
fileName
,
upload
.
getUrlPath
());
}
}
}
}
//解析cotent
ReportDashboardObjectDto
detail
=
JSONObject
.
parseObject
(
content
,
ReportDashboardObjectDto
.
class
);
//将涉及到的图片路径替换(1.背景图,2.组件为图片的)
String
backgroundImage
=
detail
.
getDashboard
().
getBackgroundImage
();
detail
.
getDashboard
().
setBackgroundImage
(
replaceUrl
(
backgroundImage
,
fileMap
));
detail
.
getWidgets
().
stream
().
filter
(
reportDashboardWidgetDto
->
"widget-image"
.
equals
(
reportDashboardWidgetDto
.
getType
())).
forEach
(
reportDashboardWidgetDto
->
{
String
imageAddress
=
reportDashboardWidgetDto
.
getValue
().
getSetup
().
getString
(
"imageAdress"
);
String
address
=
replaceUrl
(
imageAddress
,
fileMap
);
reportDashboardWidgetDto
.
getValue
().
getSetup
().
put
(
"imageAdress"
,
address
);
reportDashboardWidgetDto
.
getOptions
().
getJSONArray
(
"setup"
).
getJSONObject
(
4
).
put
(
"value"
,
address
);
});
//将新的大屏编码赋值
detail
.
setReportCode
(
reportCode
);
//解析结束,删除临时文件夹
FileUtil
.
delete
(
path
);
log
.
info
(
"解析成功,开始存入数据库..."
);
insertDashboard
(
detail
);
}
private
String
replaceUrl
(
String
imageAddress
,
Map
<
String
,
String
>
fileMap
)
{
if
(
StringUtils
.
isBlank
(
imageAddress
))
{
return
""
;
}
String
fileId
=
imageAddress
.
substring
(
imageAddress
.
trim
().
length
()
-
36
);
String
orDefault
=
fileMap
.
getOrDefault
(
fileId
,
null
);
if
(
StringUtils
.
isBlank
(
orDefault
))
{
return
imageAddress
;
}
return
orDefault
;
}
/**
* 将大屏涉及到的图片存入指定文件夹
*
* @param imageAddress
* @param path
*/
private
void
zipLoadImage
(
String
imageAddress
,
String
path
)
{
//http://10.108.26.197:9095/file/download/1d9bcd35-82a1-4f08-9465-b66b930b6a8d
if
(
imageAddress
.
trim
().
startsWith
(
fileDownloadPath
))
{
//以fileDownloadPath为前缀的代表为上传的图片
String
fileName
=
imageAddress
.
substring
(
fileDownloadPath
.
length
()
+
1
);
//根据fileId,从gaea_file中读出filePath
LambdaQueryWrapper
<
GaeaFile
>
queryWrapper
=
Wrappers
.
lambdaQuery
();
queryWrapper
.
eq
(
GaeaFile:
:
getFileId
,
fileName
);
GaeaFile
gaeaFile
=
gaeaFileService
.
selectOne
(
queryWrapper
);
if
(
null
!=
gaeaFile
)
{
String
fileType
=
gaeaFile
.
getFileType
();
path
=
path
+
"/image/"
+
fileName
+
"."
+
fileType
;
//path = /app/disk/upload/zip/UUID/image
//原始文件的路径
String
filePath
=
gaeaFile
.
getFilePath
();
FileUtil
.
copyFileUsingFileChannels
(
filePath
,
path
);
}
}
}
public
ChartStrategy
getTarget
(
String
type
)
{
for
(
String
s
:
queryServiceImplMap
.
keySet
())
{
if
(
s
.
contains
(
type
))
{
return
queryServiceImplMap
.
get
(
s
);
}
}
throw
BusinessExceptionBuilder
.
build
(
ResponseCode
.
RULE_CONTENT_NOT_EXIST
);
}
@Override
public
void
afterPropertiesSet
()
{
Map
<
String
,
ChartStrategy
>
beanMap
=
applicationContext
.
getBeansOfType
(
ChartStrategy
.
class
);
...
...
@@ -407,26 +206,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
this
.
applicationContext
=
applicationContext
;
}
/**
* 解析图层数据
*
* @param dto
*/
public
void
analysisData
(
ReportDashboardWidgetValueDto
dto
)
{
// if (StringUtils.isBlank(reportDashboardWidgetDto.getSetCode())) {
// return;
// }
// DataSetDto dto = new DataSetDto();
// dto.setSetCode(reportDashboardWidgetDto.getSetCode());
// if (reportDashboardWidgetDto.getContextData() != null && reportDashboardWidgetDto.getContextData().size() > 0) {
// dto.setContextData(reportDashboardWidgetDto.getContextData());
// }
// OriginalDataDto data = dataSetService.getData(dto);
// reportDashboardWidgetDto.setData(JSONObject.toJSONString(data.getData()));
}
public
List
<
JSONObject
>
buildTimeLine
(
List
<
JSONObject
>
data
,
ChartDto
dto
)
{
Map
<
String
,
String
>
chartProperties
=
dto
.
getChartProperties
();
if
(
null
==
chartProperties
||
chartProperties
.
size
()
<
1
)
{
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/entity/GaeaFile.java
View file @
3faa8c7
package
com
.
anjiplus
.
template
.
gaea
.
business
.
modules
.
file
.
entity
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.anji.plus.gaea.curd.entity.GaeaBaseEntity
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
@@ -23,12 +24,12 @@ public class GaeaFile extends GaeaBaseEntity implements Serializable {
@ApiModelProperty
(
value
=
"文件类型"
)
private
String
fileType
;
@ApiModelProperty
(
value
=
"文件路径"
)
private
String
filePath
;
@ApiModelProperty
(
value
=
"文件名称"
)
private
String
fileName
;
@ApiModelProperty
(
value
=
"url
路径
"
)
@ApiModelProperty
(
value
=
"url
地址
"
)
private
String
urlPath
;
@ApiModelProperty
(
value
=
"内容说明"
)
private
String
fileInstruction
;
@ApiModelProperty
(
value
=
"文件"
)
private
String
file
;
}
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/service/GaeaFileService.java
View file @
3faa8c7
...
...
@@ -22,29 +22,10 @@ public interface GaeaFileService extends GaeaBaseService<GaeaFileParam, GaeaFile
* 文件上传
*
* @param multipartFile 文件
* @param file 文件
* @param customFileName 自定义文件名,默认给null
* @return
*/
GaeaFile
upload
(
MultipartFile
multipartFile
,
File
file
,
String
customFileName
);
/**
* 文件上传
*
* @param multipartFile 文件
* @return
*/
GaeaFile
upload
(
MultipartFile
multipartFile
);
/**
* 文件上传
*
* @param file 二选一
* @param customFileName 自定义文件名
* @return
*/
GaeaFile
upload
(
File
file
,
String
customFileName
);
/**
* 根据fileId显示图片或者下载文件
*
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/file/service/impl/GaeaFileServiceImpl.java
View file @
3faa8c7
...
...
@@ -24,15 +24,13 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
org.springframework.web.multipart.MultipartFile
;
import
sun.misc.BASE64Encoder
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.UUID
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -45,15 +43,9 @@ import java.util.stream.Collectors;
@Slf4j
public
class
GaeaFileServiceImpl
implements
GaeaFileService
{
@Value
(
"${customer.file.dist-path:''}"
)
private
String
dictPath
;
@Value
(
"${customer.file.white-list:''}"
)
private
String
whiteList
;
@Value
(
"${customer.file.excelSuffix:''}"
)
private
String
excelSuffix
;
@Value
(
"${customer.file.downloadPath:''}"
)
private
String
fileDownloadPath
;
...
...
@@ -65,18 +57,20 @@ public class GaeaFileServiceImpl implements GaeaFileService {
return
gaeaFileMapper
;
}
/**
* 文件上传
*
* @param multipartFile 文件
* @return
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
GaeaFile
upload
(
MultipartFile
multipartFile
,
File
file
,
String
customFileName
)
{
public
GaeaFile
upload
(
MultipartFile
multipartFile
)
{
try
{
String
fileName
=
""
;
if
(
null
!=
multipartFile
)
{
fileName
=
multipartFile
.
getOriginalFilename
();
}
else
{
fileName
=
file
.
getName
();
if
(
multipartFile
==
null
){
throw
new
RuntimeException
(
"文件不能为空"
);
}
String
fileName
=
multipartFile
.
getOriginalFilename
();
if
(
StringUtils
.
isBlank
(
fileName
))
{
throw
BusinessExceptionBuilder
.
build
(
ResponseCode
.
FILE_EMPTY_FILENAME
);
}
...
...
@@ -90,36 +84,14 @@ public class GaeaFileServiceImpl implements GaeaFileService {
throw
BusinessExceptionBuilder
.
build
(
ResponseCode
.
FILE_SUFFIX_UNSUPPORTED
);
}
// 生成文件唯一性标识
String
fileId
;
if
(
StringUtils
.
isBlank
(
customFileName
))
{
fileId
=
UUID
.
randomUUID
().
toString
();
}
else
{
fileId
=
customFileName
;
}
String
newFileName
=
fileId
+
suffixName
;
// 本地文件保存路径
String
filePath
=
dictPath
+
newFileName
;
String
urlPath
=
fileDownloadPath
+
"/"
+
fileId
;
GaeaFile
gaeaFile
=
new
GaeaFile
();
gaeaFile
.
setFilePath
(
filePath
);
String
fileId
=
UUID
.
randomUUID
().
toString
(
);
gaeaFile
.
setFileId
(
fileId
);
gaeaFile
.
setUrlPath
(
urlPath
);
gaeaFile
.
setFile
(
new
BASE64Encoder
().
encode
(
multipartFile
.
getBytes
()));
gaeaFile
.
setFileName
(
fileInstruction
);
gaeaFile
.
setFileType
(
suffixName
.
replace
(
"."
,
""
));
gaeaFile
.
set
FileInstruction
(
fileInstruction
);
gaeaFile
.
set
UrlPath
(
fileDownloadPath
+
"/"
+
fileId
);
gaeaFileMapper
.
insert
(
gaeaFile
);
//写文件 将文件保存/app/dictPath/upload/下
java
.
io
.
File
dest
=
new
java
.
io
.
File
(
dictPath
+
newFileName
);
java
.
io
.
File
parentFile
=
dest
.
getParentFile
();
if
(!
parentFile
.
exists
())
{
parentFile
.
mkdirs
();
}
if
(
null
!=
multipartFile
)
{
multipartFile
.
transferTo
(
dest
);
}
else
{
FileUtil
.
copyFileUsingFileChannels
(
file
,
dest
);
}
// 将完整的http访问路径返回
return
gaeaFile
;
}
catch
(
Exception
e
)
{
...
...
@@ -129,29 +101,6 @@ public class GaeaFileServiceImpl implements GaeaFileService {
}
}
/**
* 文件上传
*
* @param multipartFile 文件
* @return
*/
@Override
public
GaeaFile
upload
(
MultipartFile
multipartFile
)
{
return
upload
(
multipartFile
,
null
,
null
);
}
/**
* 文件上传
*
* @param file 文件
* @param customFileName 自定义文件名
* @return
*/
@Override
public
GaeaFile
upload
(
File
file
,
String
customFileName
)
{
return
upload
(
null
,
file
,
customFileName
);
}
@Override
public
ResponseEntity
<
byte
[]>
download
(
HttpServletRequest
request
,
HttpServletResponse
response
,
String
fileId
)
{
try
{
...
...
@@ -165,17 +114,12 @@ public class GaeaFileServiceImpl implements GaeaFileService {
throw
BusinessExceptionBuilder
.
build
(
ResponseCode
.
FILE_ONT_EXSIT
);
}
//解析文件路径、文件名和后缀
String
filePath
=
gaeaFile
.
getFilePath
();
if
(
StringUtils
.
isBlank
(
filePath
))
{
throw
BusinessExceptionBuilder
.
build
(
ResponseCode
.
FILE_ONT_EXSIT
);
}
String
filename
=
filePath
.
substring
(
filePath
.
lastIndexOf
(
File
.
separator
));
String
fileSuffix
=
filename
.
substring
(
filename
.
lastIndexOf
(
"."
));
byte
[]
decode
=
Base64
.
getMimeDecoder
().
decode
(
gaeaFile
.
getFile
());
String
filename
=
gaeaFile
.
getFileName
();
String
fileSuffix
=
"."
+
gaeaFile
.
getFileType
();
//根据文件后缀来判断,是显示图片\视频\音频,还是下载文件
File
file
=
new
File
(
filePath
);
ResponseEntity
.
BodyBuilder
builder
=
ResponseEntity
.
ok
();
builder
.
contentLength
(
file
.
length
());
if
(
StringPatternUtil
.
stringMatchIgnoreCase
(
fileSuffix
,
"(.png|.jpg|.jpeg|.bmp|.gif|.icon)"
))
{
builder
.
cacheControl
(
CacheControl
.
noCache
()).
contentType
(
MediaType
.
IMAGE_PNG
);
}
else
if
(
StringPatternUtil
.
stringMatchIgnoreCase
(
fileSuffix
,
"(.flv|.swf|.mkv|.avi|.rm|.rmvb|.mpeg|.mpg|.ogg|.ogv|.mov|.wmv|.mp4|.webm|.wav|.mid|.mp3|.aac)"
))
{
...
...
@@ -190,33 +134,10 @@ public class GaeaFileServiceImpl implements GaeaFileService {
builder
.
header
(
"Content-Disposition"
,
"attacher; filename*=UTF-8''"
+
filename
);
}
}
return
builder
.
body
(
FileUtils
.
readFileToByteArray
(
file
)
);
return
builder
.
body
(
decode
);
}
catch
(
Exception
e
)
{
log
.
error
(
"file download error: {}"
,
e
);
return
null
;
}
}
/**
* 批处理操作后续处理
* 删除本地已经存在的文件
*
* @param entities
* @param operationEnum 操作类型
* @throws BusinessException 阻止程序继续执行或回滚事务
*/
@Override
public
void
processBatchAfterOperation
(
List
<
GaeaFile
>
entities
,
BaseOperationEnum
operationEnum
)
throws
BusinessException
{
if
(
operationEnum
.
equals
(
BaseOperationEnum
.
DELETE_BATCH
))
{
// 删除本地文件
entities
.
forEach
(
gaeaFile
->
{
String
filePath
=
gaeaFile
.
getFilePath
();
File
file
=
new
File
(
filePath
);
if
(
file
.
exists
())
{
file
.
delete
();
}
});
}
}
}
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/controller/ReportExcelController.java
View file @
3faa8c7
...
...
@@ -58,17 +58,6 @@ public class ReportExcelController extends GaeaBaseController<ReportExcelParam,
return
ResponseBean
.
builder
().
data
(
result
).
build
();
}
@PostMapping
(
"/exportExcel"
)
@Permission
(
code
=
"export"
,
name
=
"导出"
)
@GaeaAuditLog
(
pageTitle
=
"报表导出"
)
public
ResponseBean
exportExcel
(
@RequestBody
ReportExcelDto
reportExcelDto
)
{
return
ResponseBean
.
builder
().
code
(
ResponseCode
.
SUCCESS_CODE
)
.
data
(
reportExcelService
.
exportExcel
(
reportExcelDto
))
.
message
(
"导出成功,请稍后在文件管理中查看"
).
build
();
}
// @PostMapping("/exportPdf")
// public ResponseBean exportPdf(@RequestBody ReportExcelDto reportExcelDto) {
// reportExcelService.exportPdf(reportExcelDto);
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/ReportExcelService.java
View file @
3faa8c7
...
...
@@ -29,15 +29,4 @@ public interface ReportExcelService extends GaeaBaseService<ReportExcelParam, Re
* @return
*/
ReportExcelDto
preview
(
ReportExcelDto
reportExcelDto
);
/**
* 导出为excel
*
* @param reportExcelDto
* @return
*/
Boolean
exportExcel
(
ReportExcelDto
reportExcelDto
);
// Boolean exportPdf(ReportExcelDto reportExcelDto);
}
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportexcel/service/impl/ReportExcelServiceImpl.java
View file @
3faa8c7
...
...
@@ -128,41 +128,6 @@ public class ReportExcelServiceImpl implements ReportExcelService {
return
reportExcelDto
;
}
@Override
public
Boolean
exportExcel
(
ReportExcelDto
reportExcelDto
)
{
String
reportCode
=
reportExcelDto
.
getReportCode
();
String
exportType
=
reportExcelDto
.
getExportType
();
logger
.
error
(
"导出..."
);
if
(
exportType
.
equals
(
ExportTypeEnum
.
GAEA_TEMPLATE_EXCEL
.
getCodeValue
()))
{
ReportExcelDto
report
=
detailByReportCode
(
reportCode
);
reportExcelDto
.
setJsonStr
(
report
.
getJsonStr
());
String
jsonStr
=
analysisReportData
(
reportExcelDto
);
List
<
JSONObject
>
lists
=(
List
<
JSONObject
>
)
JSON
.
parse
(
jsonStr
);
OutputStream
out
;
try
{
String
fileId
=
UUID
.
randomUUID
().
toString
();
String
filePath
=
dictPath
+
File
.
separator
+
fileId
+
".xlsx"
;
String
urlPath
=
fileDownloadPath
+
java
.
io
.
File
.
separator
+
fileId
;
GaeaFile
gaeaFile
=
new
GaeaFile
();
gaeaFile
.
setFilePath
(
filePath
);
gaeaFile
.
setFileId
(
fileId
);
gaeaFile
.
setUrlPath
(
urlPath
);
gaeaFile
.
setFileType
(
"xlsx"
);
gaeaFile
.
setFileInstruction
(
reportCode
+
".xlsx"
);
out
=
new
FileOutputStream
(
filePath
);
XlsUtil
.
exportXlsFile
(
out
,
true
,
lists
);
gaeaFileMapper
.
insert
(
gaeaFile
);
logger
.
info
(
"导出成功:{}"
,
gaeaFile
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"导出失败"
,
e
);
}
}
return
true
;
}
/**
* 解析报表数据,动态插入列表数据和对象数据
*/
...
...
@@ -182,67 +147,6 @@ public class ReportExcelServiceImpl implements ReportExcelService {
}
/**
* 解析单sheet data
*
* @param dbObject
*/
private
void
analysisSheet
(
JSONObject
dbObject
,
String
setParma
)
{
//data是一个二维数组
if
(
dbObject
.
containsKey
(
"data"
)
&&
null
!=
dbObject
.
get
(
"data"
))
{
List
<
JSONArray
>
data
=
(
List
<
JSONArray
>)
dbObject
.
get
(
"data"
);
//行
for
(
int
r
=
0
;
r
<
data
.
size
();
r
++)
{
JSONArray
jsonArray
=
data
.
get
(
r
);
//列
for
(
int
c
=
0
;
c
<
jsonArray
.
size
();
c
++)
{
//单元格
JSONObject
cell
=
jsonArray
.
getJSONObject
(
c
);
if
(
null
!=
cell
&&
cell
.
containsKey
(
"v"
)
&&
StringUtils
.
isNotBlank
(
cell
.
getString
(
"v"
)))
{
String
v
=
cell
.
getString
(
"v"
);
DataSetDto
dataSet
=
getDataSet
(
v
,
setParma
);
if
(
null
!=
dataSet
)
{
OriginalDataDto
originalDataDto
=
dataSetService
.
getData
(
dataSet
);
if
(
null
!=
originalDataDto
.
getData
())
{
if
(
originalDataDto
.
getData
().
size
()
==
1
)
{
//对象
JSONObject
jsonObject
=
originalDataDto
.
getData
().
get
(
0
);
String
fieldLabel
=
jsonObject
.
getString
(
dataSet
.
getFieldLabel
());
String
replace
=
v
.
replace
(
"#{"
.
concat
(
dataSet
.
getSetCode
()).
concat
(
"."
).
concat
(
dataSet
.
getFieldLabel
()).
concat
(
"}"
),
fieldLabel
);
dbObject
.
getJSONArray
(
"data"
).
getJSONArray
(
r
).
getJSONObject
(
c
).
put
(
"v"
,
replace
);
dbObject
.
getJSONArray
(
"data"
).
getJSONArray
(
r
).
getJSONObject
(
c
).
put
(
"m"
,
replace
);
}
else
{
//集合
JSONObject
jsonObject
=
originalDataDto
.
getData
().
get
(
0
);
String
fieldLabel
=
jsonObject
.
getString
(
dataSet
.
getFieldLabel
());
String
replace
=
v
.
replace
(
"#{"
.
concat
(
dataSet
.
getSetCode
()).
concat
(
"."
).
concat
(
dataSet
.
getFieldLabel
()).
concat
(
"}"
),
fieldLabel
);
dbObject
.
getJSONArray
(
"data"
).
getJSONArray
(
r
).
getJSONObject
(
c
).
put
(
"v"
,
replace
);
dbObject
.
getJSONArray
(
"data"
).
getJSONArray
(
r
).
getJSONObject
(
c
).
put
(
"m"
,
replace
);
}
}
}
}
}
}
System
.
out
.
println
(
"aaaa"
);
}
}
/**
* 解析单sheet celldata
*
* @param dbObject
...
...
Please
register
or
login
to post a comment