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
3 years ago
Commit
2aa46d2ba45ea59c90605d1a1ea4f310ae6c27f2
1 parent
67e02ffc
导入导出
1.【无】导入导出联调
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
86 additions
and
23 deletions
report-core/src/main/java/com/anjiplus/template/gaea/business/filter/TokenFilter.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dataset/service/impl/DataSetServiceImpl.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasource/service/impl/DataSourceServiceImpl.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/export/controller/ExportController.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/export/service/ExportService.java
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/export/service/impl/ExportServiceImpl.java
report-core/src/main/java/com/anjiplus/template/gaea/business/filter/TokenFilter.java
View file @
2aa46d2
...
...
@@ -102,6 +102,9 @@ public class TokenFilter implements Filter {
//获取token
String
token
=
request
.
getHeader
(
"Authorization"
);
if
(
token
==
null
){
token
=
request
.
getParameter
(
"Authorization"
);
}
if
(
StringUtils
.
isBlank
(
token
))
{
error
(
response
);
return
;
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/dataset/service/impl/DataSetServiceImpl.java
View file @
2aa46d2
...
...
@@ -257,7 +257,7 @@ public class DataSetServiceImpl implements DataSetService {
}
else
{
dataSource
=
dataSourceService
.
selectOne
(
"source_code"
,
dataSetDto
.
getSourceCode
());
}
dataSource
.
setSourceCode
(
dataSetDto
.
getSourceCode
());
log
.
info
(
"数据源详情:{}"
,
dataSource
);
//3.参数替换
...
...
@@ -303,6 +303,7 @@ public class DataSetServiceImpl implements DataSetService {
dataSource
=
new
DataSource
();
dataSource
.
setSourceConfig
(
dynSentence
);
dataSource
.
setSourceType
(
JdbcConstants
.
HTTP
);
dataSource
.
setSourceCode
(
dto
.
getSourceCode
());
String
body
=
JSONObject
.
parseObject
(
dynSentence
).
getString
(
"body"
);
if
(
StringUtils
.
isNotBlank
(
body
))
{
dynSentence
=
body
;
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/datasource/service/impl/DataSourceServiceImpl.java
View file @
2aa46d2
...
...
@@ -37,8 +37,8 @@ import org.springframework.web.client.RestTemplate;
import
javax.annotation.Resource
;
import
java.sql.*
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.Date
;
import
java.util.*
;
/**
* @author Raod
...
...
@@ -304,6 +304,20 @@ public class DataSourceServiceImpl implements DataSourceService {
public
List
<
JSONObject
>
executeHttp
(
DataSourceDto
dto
)
{
analysisHttpConfig
(
dto
);
String
apiUrl
=
dto
.
getApiUrl
();
String
sourceCode
=
dto
.
getSourceCode
();
DataSource
dataSource
=
dataSourceMapper
.
selectOne
(
new
LambdaQueryWrapper
<
DataSource
>()
.
eq
(
DataSource:
:
getSourceCode
,
sourceCode
));
String
sourceConfig
=
dataSource
.
getSourceConfig
();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
sourceConfig
);
String
gateway
=
jsonObject
.
getString
(
"apiUrl"
);
if
(
apiUrl
.
indexOf
(
"/"
)
==
0
)
{
apiUrl
=
apiUrl
.
substring
(
1
);
}
if
(
gateway
.
lastIndexOf
(
"/"
)
!=
gateway
.
length
()
-
1
)
{
gateway
=
gateway
+
"/"
;
}
apiUrl
=
gateway
+
apiUrl
;
HttpMethod
httpMethod
=
HttpMethod
.
valueOf
(
dto
.
getMethod
());
if
(
Objects
.
equals
(
HttpMethod
.
GET
,
httpMethod
))
{
Map
<
String
,
Object
>
contextData
=
dto
.
getContextData
();
...
...
@@ -323,12 +337,12 @@ public class DataSourceServiceImpl implements DataSourceService {
ResponseEntity
<
Object
>
exchange
;
List
<
JSONObject
>
result
=
new
ArrayList
<>();
try
{
log
.
info
(
"== 发送请求:\n\t\t apiUrl:{}\n\t\t httpMethod:{}\n\t\t entity:{}\n\t\t "
,
apiUrl
,
httpMethod
,
dto
.
getDynSentence
());
log
.
info
(
"== 发送请求:\n\t\t apiUrl:{}\n\t\t httpMethod:{}\n\t\t entity:{}\n\t\t "
,
apiUrl
,
httpMethod
,
dto
.
getDynSentence
());
exchange
=
restTemplate
.
exchange
(
apiUrl
,
httpMethod
,
entity
,
Object
.
class
);
}
catch
(
HttpClientErrorException
error
)
{
int
rawStatusCode
=
error
.
getRawStatusCode
();
// 401 接口请求无权限
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"code"
,
rawStatusCode
);
jsonObject
.
put
(
"data"
,
error
.
getMessage
());
result
.
add
(
jsonObject
);
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/export/controller/ExportController.java
View file @
2aa46d2
package
com
.
anjiplus
.
template
.
gaea
.
business
.
modules
.
export
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.anji.plus.gaea.bean.ResponseBean
;
import
com.anjiplus.template.gaea.business.modules.export.service.impl.ExportServiceImpl
;
import
com.anjiplus.template.gaea.business.modules.report.dao.entity.Report
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.List
;
...
...
@@ -35,9 +33,17 @@ public class ExportController {
}
@GetMapping
(
"/export"
)
public
void
export
(
HttpServletResponse
response
,
@RequestParam
List
<
String
>
reportCodeList
)
{
public
void
export
(
HttpServletResponse
response
,
@RequestParam
List
<
String
>
reportIdList
,
@RequestParam
String
type
)
{
if
(
reportIdList
==
null
||
reportIdList
.
size
()
==
0
)
{
return
;
}
List
<
String
>
reportCodeList
=
exportService
.
getReportCodeList
(
reportIdList
);
if
(
reportCodeList
==
null
||
reportCodeList
.
size
()
==
0
)
{
return
;
}
List
<
Report
>
export
=
exportService
.
export
(
reportCodeList
);
exportJson
(
response
,
export
,
"
AJ
大屏报表"
);
exportJson
(
response
,
export
,
"大屏报表"
);
}
private
void
exportJson
(
HttpServletResponse
response
,
List
<
Report
>
export
,
String
fileName
)
{
...
...
@@ -46,7 +52,10 @@ public class ExportController {
SerializerFeature
.
PrettyFormat
,
SerializerFeature
.
WriteMapNullValue
,
SerializerFeature
.
WriteDateUseDateFormat
);
response
.
setContentType
(
"application/octet-stream"
);
fileName
=
URLEncoder
.
encode
(
fileName
,
StandardCharsets
.
UTF_8
.
toString
());
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setHeader
(
"Content-disposition"
,
"attachment;filename="
+
fileName
+
".json"
);
response
.
getOutputStream
().
write
(
jsonString
.
getBytes
(
StandardCharsets
.
UTF_8
));
}
catch
(
Exception
e
)
{
...
...
@@ -54,11 +63,24 @@ public class ExportController {
}
}
@RequestMapping
(
"/import"
)
public
void
importE
(
MultipartFile
file
)
throws
IOException
{
@PostMapping
(
"/import"
)
public
ResponseBean
importE
(
@RequestBody
JSONArray
jsonArray
)
throws
IOException
{
if
(
jsonArray
==
null
||
jsonArray
.
size
()
==
0
)
{
return
ResponseBean
.
builder
().
build
();
}
String
s
=
JSONObject
.
toJSONString
(
jsonArray
);
List
<
Report
>
reportList
=
JSONObject
.
parseArray
(
s
,
Report
.
class
);
exportService
.
importE
(
reportList
);
return
ResponseBean
.
builder
().
build
();
}
@PostMapping
(
"/read"
)
public
ResponseBean
read
(
MultipartFile
file
)
throws
IOException
{
if
(
file
==
null
)
{
return
null
;
}
byte
[]
bytes
=
file
.
getBytes
();
Object
parse
=
JSONObject
.
parse
(
bytes
);
List
<
Report
>
reportList
=
JSONObject
.
parseArray
(
JSONObject
.
toJSONString
(
parse
),
Report
.
class
);
exportService
.
importE
(
reportList
);
return
ResponseBean
.
builder
().
data
(
JSONObject
.
parseArray
(
JSONObject
.
toJSONString
(
parse
),
Report
.
class
)).
build
();
}
}
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/export/service/ExportService.java
View file @
2aa46d2
...
...
@@ -10,6 +10,9 @@ import java.util.List;
* @date 2022-06-21 11:03
*/
public
interface
ExportService
{
List
<
String
>
getReportCodeList
(
List
<
String
>
reportIdList
);
List
<
Report
>
export
(
List
<
String
>
reportCodeList
);
void
importE
(
List
<
Report
>
reportList
);
...
...
report-core/src/main/java/com/anjiplus/template/gaea/business/modules/export/service/impl/ExportServiceImpl.java
View file @
2aa46d2
...
...
@@ -18,6 +18,7 @@ import com.anjiplus.template.gaea.business.modules.report.service.ReportService;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -51,6 +52,12 @@ public class ExportServiceImpl implements ExportService {
}
@Override
public
List
<
String
>
getReportCodeList
(
List
<
String
>
reportIdList
)
{
List
<
Report
>
reportList
=
reportService
.
getMapper
().
selectBatchIds
(
reportIdList
);
return
reportList
.
stream
().
map
(
Report:
:
getReportCode
).
collect
(
Collectors
.
toList
());
}
@Override
public
List
<
Report
>
export
(
List
<
String
>
reportCodeList
)
{
//大屏
List
<
Report
>
reportList
=
reportService
.
list
(
new
LambdaQueryWrapper
<
Report
>()
...
...
@@ -70,10 +77,19 @@ public class ExportServiceImpl implements ExportService {
reportDashboardWidgetList
.
stream
().
filter
(
item
->
item
.
getData
().
contains
(
"setCode"
)).
forEach
(
item
->
{
String
data
=
item
.
getData
();
int
startIndex
=
data
.
indexOf
(
"setCode"
);
while
(
startIndex
!=
-
1
)
{
int
endIndex
=
data
.
indexOf
(
","
,
startIndex
);
String
setCode
=
data
.
substring
(
startIndex
+
10
,
endIndex
-
1
);
setCodeList
.
add
(
setCode
);
item
.
setSetCode
(
setCode
);
if
(
endIndex
+
2
<=
data
.
length
())
{
data
=
data
.
substring
(
endIndex
+
2
);
}
else
{
data
=
""
;
}
startIndex
=
data
.
indexOf
(
"setCode"
);
}
;
});
if
(
setCodeList
.
size
()
==
0
)
{
return
reportList
;
...
...
@@ -109,8 +125,11 @@ public class ExportServiceImpl implements ExportService {
//组合组件接口
Map
<
String
,
List
<
DataSet
>>
dataSetMap
=
dataSetList
.
stream
().
collect
(
Collectors
.
groupingBy
(
DataSet:
:
getSetCode
));
reportDashboardWidgetList
.
stream
().
filter
(
item
->
item
.
getData
().
contains
(
"setCode"
)).
forEach
(
reportDashboardWidget
->
{
if
(
dataSetMap
.
get
(
reportDashboardWidget
.
getSetCode
())
!=
null
)
{
reportDashboardWidget
.
getDataSetList
().
addAll
(
dataSetMap
.
get
(
reportDashboardWidget
.
getSetCode
()));
String
data
=
reportDashboardWidget
.
getData
();
for
(
Map
.
Entry
<
String
,
List
<
DataSet
>>
map
:
dataSetMap
.
entrySet
())
{
if
(
data
.
contains
(
"\"setCode\":\""
+
map
.
getKey
()
+
"\""
))
{
reportDashboardWidget
.
getDataSetList
().
addAll
(
dataSetMap
.
get
(
map
.
getKey
()));
}
}
});
//组合接口参数转换数据源
...
...
@@ -132,6 +151,7 @@ public class ExportServiceImpl implements ExportService {
}
@Override
@Transactional
public
void
importE
(
List
<
Report
>
reportList
)
{
//新增大屏
...
...
@@ -144,7 +164,7 @@ public class ExportServiceImpl implements ExportService {
//新增大屏配置
List
<
ReportDashboard
>
reportDashboardList
=
new
ArrayList
<>();
reportList
.
stream
().
map
(
Report:
:
getReportDashboardList
).
forEach
(
reportDashboardList:
:
addAll
);
reportList
.
stream
().
map
(
Report:
:
getReportDashboardList
).
distinct
().
forEach
(
reportDashboardList:
:
addAll
);
if
(
reportDashboardList
.
size
()
!=
0
)
{
reportDashboardService
.
delete
(
new
LambdaQueryWrapper
<
ReportDashboard
>().
in
(
ReportDashboard:
:
getReportCode
,
reportCodeList
));
reportDashboardService
.
insertBatch
(
reportDashboardList
);
...
...
@@ -152,7 +172,7 @@ public class ExportServiceImpl implements ExportService {
//新增大屏组件
List
<
ReportDashboardWidget
>
reportDashboardWidgetList
=
new
ArrayList
<>();
reportList
.
stream
().
map
(
Report:
:
getReportDashboardWidgetList
).
forEach
(
reportDashboardWidgetList:
:
addAll
);
reportList
.
stream
().
map
(
Report:
:
getReportDashboardWidgetList
).
distinct
().
forEach
(
reportDashboardWidgetList:
:
addAll
);
if
(
reportDashboardWidgetList
.
size
()
==
0
)
{
return
;
}
...
...
@@ -162,7 +182,7 @@ public class ExportServiceImpl implements ExportService {
//新增数据集
List
<
String
>
setCodeList
=
reportDashboardWidgetList
.
stream
().
map
(
ReportDashboardWidget:
:
getSetCode
).
distinct
().
collect
(
Collectors
.
toList
());
List
<
DataSet
>
dataSetList
=
new
ArrayList
<>();
reportDashboardWidgetList
.
stream
().
map
(
ReportDashboardWidget:
:
getDataSetList
).
forEach
(
dataSetList:
:
addAll
);
reportDashboardWidgetList
.
stream
().
map
(
ReportDashboardWidget:
:
getDataSetList
).
distinct
().
forEach
(
dataSetList:
:
addAll
);
if
(
dataSetList
.
size
()
!=
0
)
{
dataSetService
.
delete
(
new
LambdaQueryWrapper
<
DataSet
>().
in
(
DataSet:
:
getSetCode
,
setCodeList
));
for
(
DataSet
dataSet
:
dataSetList
)
{
...
...
@@ -175,7 +195,7 @@ public class ExportServiceImpl implements ExportService {
//新增数据集参数
List
<
DataSetParam
>
dataSetParamList
=
new
ArrayList
<>();
dataSetList
.
stream
().
map
(
DataSet:
:
getDataSetParamList
).
forEach
(
dataSetParamList:
:
addAll
);
dataSetList
.
stream
().
map
(
DataSet:
:
getDataSetParamList
).
distinct
().
forEach
(
dataSetParamList:
:
addAll
);
if
(
dataSetParamList
.
size
()
!=
0
)
{
dataSetParamService
.
delete
(
new
LambdaQueryWrapper
<
DataSetParam
>().
in
(
DataSetParam:
:
getSetCode
,
setCodeList
));
dataSetParamService
.
insertBatch
(
dataSetParamList
);
...
...
@@ -183,7 +203,7 @@ public class ExportServiceImpl implements ExportService {
//新增数据源转换
List
<
DataSetTransform
>
dataSetTransformList
=
new
ArrayList
<>();
dataSetList
.
stream
().
map
(
DataSet:
:
getDataSetTransformList
).
forEach
(
dataSetTransformList:
:
addAll
);
dataSetList
.
stream
().
map
(
DataSet:
:
getDataSetTransformList
).
distinct
().
forEach
(
dataSetTransformList:
:
addAll
);
if
(
dataSetTransformList
.
size
()
!=
0
)
{
dataSetTransformService
.
delete
(
new
LambdaQueryWrapper
<
DataSetTransform
>().
in
(
DataSetTransform:
:
getSetCode
,
setCodeList
));
dataSetTransformService
.
insertBatch
(
dataSetTransformList
);
...
...
Please
register
or
login
to post a comment