Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tagManager
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
lanmw
tagManager
Commits
d6597727
Commit
d6597727
authored
Jan 14, 2020
by
zhangkb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
标签管理excel导入代码
parent
fa633f6d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
6 deletions
+140
-6
TagFileCtrl.java
src/main/java/com/keymobile/tagmanager/api/TagFileCtrl.java
+12
-5
RepoServiceClient.java
...va/com/keymobile/tagmanager/remote/RepoServiceClient.java
+10
-0
TagFileService.java
...java/com/keymobile/tagmanager/service/TagFileService.java
+118
-1
No files found.
src/main/java/com/keymobile/tagmanager/api/TagFileCtrl.java
View file @
d6597727
package
com
.
keymobile
.
tagmanager
.
api
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -15,8 +12,6 @@ import org.springframework.web.bind.annotation.RestController;
import
org.springframework.web.multipart.MultipartFile
;
import
com.keymobile.auth.common.security.GrantedAuthHelper
;
import
com.keymobile.tagmanager.model.ExtTag
;
import
com.keymobile.tagmanager.model.ImportLog
;
import
com.keymobile.tagmanager.model.Page
;
import
com.keymobile.tagmanager.service.TagFileService
;
import
com.keymobile.tagmanager.util.UserInfoUtils
;
...
...
@@ -31,6 +26,18 @@ public class TagFileCtrl {
@Autowired
private
TagFileService
tagExportService
;
@ApiOperation
(
value
=
"导入标签元数据"
,
notes
=
"导入标签元数据"
)
@GetMapping
(
"/importTagMeta"
)
public
String
importTagMeta
(
@RequestParam
(
"idPath"
)
String
idPath
,
@RequestParam
(
"dimensionType"
)
String
dimensionType
,
@RequestParam
(
"tagType"
)
String
tagType
,
MultipartFile
file
,
HttpServletResponse
response
)
throws
Exception
{
String
userName
=
UserInfoUtils
.
getUserName
();
String
userId
=
UserInfoUtils
.
getUserId
();
String
deptIdPath
=
/**UserInfoUtils.getDataRoleOrg()*/
String
.
valueOf
(
GrantedAuthHelper
.
getUserOrg
());
return
tagExportService
.
importTagMetadataExcel
(
userName
,
userId
,
deptIdPath
,
idPath
,
dimensionType
,
tagType
,
file
);
}
@ApiOperation
(
value
=
"导出标签元数据excel文件"
,
notes
=
"导出标签元数据excel文件"
)
@GetMapping
(
"/exportTagMeta"
)
public
int
exportTagMeta
(
@RequestParam
(
"idPath"
)
String
idPath
,
...
...
src/main/java/com/keymobile/tagmanager/remote/RepoServiceClient.java
View file @
d6597727
package
com
.
keymobile
.
tagmanager
.
remote
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestParam
;
@FeignClient
(
name
=
"MetadataRepo"
)
...
...
@@ -15,4 +17,12 @@ public interface RepoServiceClient {
@RequestParam
(
required
=
false
)
int
pageNum
,
@RequestParam
(
required
=
false
)
int
pageSize
,
@RequestParam
String
tagType
);
@PostMapping
(
value
=
"/rest/metadata/getByNamePathAndClass"
)
public
Map
<
String
,
Object
>
getMetaByNamePathAndClass
(
@RequestParam
String
namePath
,
@RequestParam
String
claz
);
@PostMapping
(
value
=
"/rest/tag/addTag"
)
public
void
addTag
(
@RequestParam
String
dimensionType
,
@RequestParam
String
idPath
,
@RequestBody
List
<
String
>
metadataIds
,
@RequestParam
String
tagType
);
}
src/main/java/com/keymobile/tagmanager/service/TagFileService.java
View file @
d6597727
...
...
@@ -54,8 +54,19 @@ public class TagFileService {
@Autowired
private
RepoServiceClient
repoService
;
//标签管理导入
public
String
importTagMetadataExcel
(
String
userName
,
String
userId
,
String
dept
,
String
idPath
,
String
dimensionType
,
String
tagType
,
MultipartFile
file
)
throws
Exception
{
ImportLog
importLog
=
new
ImportLog
(
UUID
.
randomUUID
().
toString
());
importLog
.
setCreator
(
userName
);
importLog
.
setDept
(
dept
);
mongoOperations
.
save
(
importLog
);
return
"ok"
;
}
/**
* author:zhangkb time:2020-1-14 desc:
元数据
管理导出
* author:zhangkb time:2020-1-14 desc:
标签
管理导出
*/
@SuppressWarnings
(
"unchecked"
)
public
int
exportTagMetadataExcel
(
String
idPath
,
String
dimensionType
,
...
...
@@ -200,6 +211,112 @@ public class TagFileService {
}
}
/**
*author:zhangkb time:2020-1-14 desc:标签管理导入
*/
class
TagMetadataImportExecutor
implements
Runnable
{
private
String
dept
;
private
MultipartFile
file
;
private
ImportLog
importLog
;
private
String
userName
;
private
String
userId
;
private
String
idPath
;
private
String
dimensionType
;
private
String
tagType
;
public
TagMetadataImportExecutor
(
String
userName
,
String
userId
,
String
dept
,
String
idPath
,
String
dimensionType
,
String
tagType
,
MultipartFile
file
,
ImportLog
importLog
)
{
this
.
userName
=
userName
;
this
.
userId
=
userId
;
this
.
dept
=
dept
;
this
.
file
=
file
;
this
.
importLog
=
importLog
;
this
.
idPath
=
idPath
;
this
.
dimensionType
=
dimensionType
;
this
.
tagType
=
tagType
;
}
@Override
public
void
run
()
{
try
{
boolean
hasOtherFail
=
false
;
ImportParams
params
=
new
ImportParams
();
params
.
setTitleRows
(
0
);
params
.
setHeadRows
(
1
);
params
.
setNeedVerify
(
true
);
params
.
setVerifyHandler
(
new
TagMetadataVerifyHandler
());
ExcelImportResult
<
TagMetadata
>
excelImportResult
=
ExcelImportUtil
.
importExcelMore
(
file
.
getInputStream
(),
TagMetadata
.
class
,
params
);
List
<
String
>
successIds
=
new
ArrayList
<>();
List
<
TagMetadata
>
tagMetadatas
=
excelImportResult
.
getList
();
for
(
TagMetadata
tagMetadata
:
tagMetadatas
)
{
//判断元数据名称是否在repo存在
String
claz
=
null
;
if
(
"TABLE"
.
equals
(
tagMetadata
.
getMetaModel
().
toUpperCase
()))
{
claz
=
"Catalog,Database,Schema,Table"
;
}
if
(
"HANAVIEW"
.
equals
(
tagMetadata
.
getMetaModel
().
toUpperCase
()))
{
claz
=
"Catalog,Database,Schema,HanaView"
;
}
Map
<
String
,
Object
>
meta
=
repoService
.
getMetaByNamePathAndClass
(
tagMetadata
.
getMetaName
(),
claz
);
if
(
meta
.
isEmpty
())
{
importLog
.
appendErrorMsg
(
String
.
format
(
"第%s行, 元数据名为[%s]的元数据不存在"
,
tagMetadata
.
getRowNum
(),
tagMetadata
.
getMetaName
()));
hasOtherFail
=
true
;
continue
;
}
else
{
successIds
.
add
(
meta
.
get
(
"_id"
).
toString
());
}
}
if
(!
successIds
.
isEmpty
())
{
//调用repo接口批量打元数据标签
repoService
.
addTag
(
dimensionType
,
idPath
,
successIds
,
tagType
);
}
importLog
.
setHasFailNum
(!
excelImportResult
.
getFailList
().
isEmpty
()
||
hasOtherFail
);
importLog
.
setTotalNum
(
excelImportResult
.
getList
().
size
()
+
excelImportResult
.
getFailList
().
size
());
importLog
.
setSuccessIds
(
successIds
);
importLog
.
setReport
(
importLog
.
generateReport
());
}
catch
(
Exception
e
)
{
importLog
.
appendErrorMsg
(
e
.
getCause
().
getMessage
());
}
finally
{
importLog
.
setEndTime
(
DateUtils
.
formatDate
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
));
importLog
.
setHasFinish
(
true
);
mongoOperations
.
save
(
importLog
);
}
}
}
class
TagMetadataVerifyHandler
implements
IExcelVerifyHandler
<
TagMetadata
>{
@Override
public
ExcelVerifyHandlerResult
verifyHandler
(
TagMetadata
obj
)
{
ExcelVerifyHandlerResult
result
=
new
ExcelVerifyHandlerResult
(
true
);
//判断导入模型是不是table或者hanaView
if
(!
"TABLE"
.
equals
(
obj
.
getMetaModel
().
toUpperCase
())
||
!
"HANAVIEW"
.
equals
(
obj
.
getMetaModel
().
toUpperCase
()))
{
result
.
setSuccess
(
false
);
result
.
setMsg
(
String
.
format
(
"模型类型错误,不能为[%s]"
,
obj
.
getMetaModel
()));
return
result
;
}
//判断元数据名称是否在repo存在
String
claz
=
null
;
if
(
"TABLE"
.
equals
(
obj
.
getMetaModel
().
toUpperCase
()))
{
claz
=
"Catalog,Database,Schema,Table"
;
}
if
(
"HANAVIEW"
.
equals
(
obj
.
getMetaModel
().
toUpperCase
()))
{
claz
=
"Catalog,Database,Schema,HanaView"
;
}
Map
<
String
,
Object
>
meta
=
repoService
.
getMetaByNamePathAndClass
(
obj
.
getMetaName
(),
claz
);
if
(
meta
.
isEmpty
())
{
result
.
setSuccess
(
false
);
result
.
setMsg
(
String
.
format
(
"元数据不存在namePath为[%s]的[%s]数据"
,
obj
.
getMetaName
(),
obj
.
getMetaModel
()));
}
return
result
;
}
}
class
ExcelImportExecutor
implements
Runnable
{
private
String
dept
;
private
MultipartFile
file
;
...
...
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