Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
emport-api
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
刘泽志
emport-api
Commits
619cf8e1
Commit
619cf8e1
authored
Feb 16, 2023
by
刘泽志
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api等接口分类
parent
ab35a02c
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
897 additions
and
516 deletions
+897
-516
DataFieldController.java
...yf/his/web/controller/dataImport/DataFieldController.java
+148
-0
DataImportController.java
...f/his/web/controller/dataImport/DataImportController.java
+27
-490
DataRuleController.java
...byf/his/web/controller/dataImport/DataRuleController.java
+177
-0
DataTemplateController.java
...his/web/controller/dataImport/DataTemplateController.java
+157
-0
DictDataController.java
...byf/his/web/controller/dataImport/DictDataController.java
+91
-0
ExcelDataController.java
...yf/his/web/controller/dataImport/ExcelDataController.java
+108
-0
DataTemplate.java
...java/com/tbyf/his/web/dataImport/entity/DataTemplate.java
+2
-2
MetaField.java
...in/java/com/tbyf/his/web/dataImport/entity/MetaField.java
+49
-0
DataTemplateMapper.java
...om/tbyf/his/web/dataImport/mapper/DataTemplateMapper.java
+2
-2
DataSourceService.java
...om/tbyf/his/web/dataImport/service/DataSourceService.java
+54
-0
DataTemplateService.java
.../tbyf/his/web/dataImport/service/DataTemplateService.java
+2
-2
DataSourceServiceImpl.java
...is/web/dataImport/service/impl/DataSourceServiceImpl.java
+33
-0
DataTemplateServiceImpl.java
.../web/dataImport/service/impl/DataTemplateServiceImpl.java
+9
-9
ExcelDataServiceImpl.java
...his/web/dataImport/service/impl/ExcelDataServiceImpl.java
+6
-6
DataTemplateMapper.xml
admin-api/src/main/resources/mapper/DataTemplateMapper.xml
+3
-3
SysDatasourceMapper.java
.../java/com/tbyf/his/system/mapper/SysDatasourceMapper.java
+5
-1
ISysDatasourceService.java
...va/com/tbyf/his/system/service/ISysDatasourceService.java
+2
-0
SysDatasourceServiceImpl.java
...byf/his/system/service/impl/SysDatasourceServiceImpl.java
+5
-0
SysDatasourceMapper.xml
.../src/main/resources/mapper/system/SysDatasourceMapper.xml
+8
-1
dataImport.sql
scripts/dataImport.sql
+9
-0
No files found.
admin-api/src/main/java/com/tbyf/his/web/controller/dataImport/DataFieldController.java
0 → 100644
View file @
619cf8e1
package
com
.
tbyf
.
his
.
web
.
controller
.
dataImport
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.tbyf.his.common.annotation.IgnoreWebSecurity
;
import
com.tbyf.his.common.core.domain.AjaxResult
;
import
com.tbyf.his.common.core.page.TableDataInfo
;
import
com.tbyf.his.common.utils.StringUtils
;
import
com.tbyf.his.common.utils.bean.BeanUtils
;
import
com.tbyf.his.web.dataImport.core.DiConfig
;
import
com.tbyf.his.web.dataImport.domain.param.AddFieldParam
;
import
com.tbyf.his.web.dataImport.domain.param.QueryFieldParam
;
import
com.tbyf.his.web.dataImport.domain.param.UpdateFieldParam
;
import
com.tbyf.his.web.dataImport.entity.BindRule
;
import
com.tbyf.his.web.dataImport.entity.DataField
;
import
com.tbyf.his.web.dataImport.entity.ExcelData
;
import
com.tbyf.his.web.dataImport.service.BindRuleService
;
import
com.tbyf.his.web.dataImport.service.DataFieldService
;
import
com.tbyf.his.web.dataImport.service.ExcelDataService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.ss.usermodel.WorkbookFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* @author lzz
* @date 2023/2/16 15:29
*/
@RestController
@Api
(
tags
=
"数据字段接口"
)
@RequestMapping
(
"/data/field"
)
@Slf4j
public
class
DataFieldController
{
@Autowired
private
DataFieldService
dataFieldService
;
@Autowired
private
BindRuleService
bindRuleService
;
@Autowired
private
ExcelDataService
excelDataService
;
@IgnoreWebSecurity
@GetMapping
(
""
)
@ApiOperation
(
"字段查询"
)
public
TableDataInfo
queryField
(
@Validated
QueryFieldParam
param
)
{
final
Page
<
DataField
>
page
=
Page
.
of
(
param
.
getPageNum
(),
param
.
getPageSize
());
final
LambdaQueryWrapper
<
DataField
>
queryWrapper
=
Wrappers
.
lambdaQuery
(
DataField
.
class
);
queryWrapper
.
eq
(
StringUtils
.
isNotBlank
(
param
.
getTemplateId
()),
DataField:
:
getTemplateId
,
param
.
getTemplateId
())
.
like
(
StringUtils
.
isNotBlank
(
param
.
getCode
()),
DataField:
:
getCode
,
param
.
getCode
())
.
like
(
StringUtils
.
isNotBlank
(
param
.
getTitle
()),
DataField:
:
getTitle
,
param
.
getTitle
())
.
like
(
StringUtils
.
isNotBlank
(
param
.
getCoordinate
()),
DataField:
:
getCoordinate
,
param
.
getCoordinate
())
.
like
(
StringUtils
.
isNotBlank
(
param
.
getField
()),
DataField:
:
getField
,
param
.
getField
());
final
Page
<
DataField
>
templatePage
=
dataFieldService
.
page
(
page
,
queryWrapper
);
return
param
.
convert
(
templatePage
);
}
@IgnoreWebSecurity
@PostMapping
(
""
)
@ApiOperation
(
"字段新增"
)
public
AjaxResult
addField
(
@RequestBody
@Validated
AddFieldParam
param
)
{
DataField
field
=
new
DataField
();
BeanUtils
.
copyProperties
(
param
,
field
);
dataFieldService
.
save
(
field
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/update"
)
@ApiOperation
(
"修改字段"
)
public
AjaxResult
updateField
(
@RequestBody
@Validated
UpdateFieldParam
param
)
{
DataField
field
=
new
DataField
();
BeanUtils
.
copyProperties
(
param
,
field
);
dataFieldService
.
updateById
(
field
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/delete"
)
@ApiOperation
(
"删除字段"
)
public
AjaxResult
deleteField
(
@RequestParam
String
fieldId
)
{
dataFieldService
.
removeById
(
fieldId
);
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
eq
(
BindRule:
:
getDataId
,
fieldId
));
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/reset"
)
@ApiOperation
(
"根据基础模板重置字段"
)
public
AjaxResult
resetField
(
@RequestParam
String
excelId
)
{
final
ExcelData
excelData
=
excelDataService
.
getById
(
excelId
);
final
LambdaQueryWrapper
<
DataField
>
wrapper
=
Wrappers
.
lambdaQuery
(
DataField
.
class
).
eq
(
DataField:
:
getTemplateId
,
excelData
.
getTemplateId
());
final
List
<
DataField
>
list
=
dataFieldService
.
list
(
wrapper
);
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
final
List
<
String
>
fieldIdList
=
list
.
stream
().
map
(
DataField:
:
getId
).
collect
(
Collectors
.
toList
());
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
in
(
BindRule:
:
getDataId
,
fieldIdList
));
}
dataFieldService
.
remove
(
Wrappers
.
lambdaQuery
(
DataField
.
class
).
eq
(
DataField:
:
getTemplateId
,
excelData
.
getTemplateId
()));
try
(
InputStream
is
=
new
ByteArrayInputStream
(
excelData
.
getFile
());
Workbook
workbook
=
WorkbookFactory
.
create
(
is
))
{
final
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
final
int
rows
=
sheet
.
getLastRowNum
()
+
1
;
List
<
DataField
>
fieldList
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<
rows
;
i
++)
{
final
Row
row
=
sheet
.
getRow
(
i
);
String
code
=
DiConfig
.
getValue
(
row
.
getCell
(
1
,
Row
.
MissingCellPolicy
.
RETURN_BLANK_AS_NULL
));
String
title
=
DiConfig
.
getValue
(
row
.
getCell
(
2
,
Row
.
MissingCellPolicy
.
RETURN_BLANK_AS_NULL
));
String
unit
=
DiConfig
.
getValue
(
row
.
getCell
(
4
,
Row
.
MissingCellPolicy
.
RETURN_BLANK_AS_NULL
));
if
(
StringUtils
.
isAllBlank
(
code
,
title
,
unit
))
{
continue
;
}
if
(
StringUtils
.
equals
(
code
,
"代码"
)
||
StringUtils
.
equals
(
title
,
"指标名称"
)
||
StringUtils
.
equals
(
unit
,
"计量单位"
))
{
continue
;
}
final
DataField
dataField
=
new
DataField
();
dataField
.
setTemplateId
(
excelData
.
getTemplateId
());
dataField
.
setCode
(
code
);
dataField
.
setTitle
(
title
);
dataField
.
setUnit
(
unit
);
// TODO 这里坐标修改为i+1是因为excel文件中展示的第一行号是1,符合直觉
dataField
.
setCoordinate
(
"F,"
+
(
i
+
1
));
dataField
.
setSort
(
i
+
1
);
dataField
.
createField
();
fieldList
.
add
(
dataField
);
}
dataFieldService
.
saveBatch
(
fieldList
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
return
AjaxResult
.
success
();
}
}
admin-api/src/main/java/com/tbyf/his/web/controller/dataImport/DataImportController.java
View file @
619cf8e1
...
...
@@ -2,51 +2,40 @@ package com.tbyf.his.web.controller.dataImport;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.tbyf.his.common.annotation.IgnoreWebSecurity
;
import
com.tbyf.his.common.core.domain.AjaxResult
;
import
com.tbyf.his.common.core.page.TableDataInfo
;
import
com.tbyf.his.common.core.text.StrFormatter
;
import
com.tbyf.his.common.exception.base.BaseException
;
import
com.tbyf.his.common.utils.StringUtils
;
import
com.tbyf.his.common.utils.bean.BeanUtils
;
import
com.tbyf.his.framework.datasource.DataSourceUtil
;
import
com.tbyf.his.framework.datasource.DynamicDataSourceContextHolder
;
import
com.tbyf.his.system.domain.SysDatasource
;
import
com.tbyf.his.system.service.ISysDatasourceService
;
import
com.tbyf.his.web.dataImport.core.DiConfig
;
import
com.tbyf.his.web.dataImport.core.RuleVO
;
import
com.tbyf.his.web.dataImport.core.RuleValidator
;
import
com.tbyf.his.web.dataImport.domain.param.*
;
import
com.tbyf.his.system.vo.SqlHandler
;
import
com.tbyf.his.web.dataImport.domain.vo.TemplateVO
;
import
com.tbyf.his.web.dataImport.entity.*
;
import
com.tbyf.his.web.dataImport.service.*
;
import
com.tbyf.his.web.dataImport.entity.DataField
;
import
com.tbyf.his.web.dataImport.entity.DataTemplate
;
import
com.tbyf.his.web.dataImport.entity.ExcelData
;
import
com.tbyf.his.web.dataImport.service.DataFieldService
;
import
com.tbyf.his.web.dataImport.service.DataSourceService
;
import
com.tbyf.his.web.dataImport.service.DataTemplateService
;
import
com.tbyf.his.web.dataImport.service.ExcelDataService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.ss.usermodel.WorkbookFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.function.Function
;
import
java.util.function.Predicate
;
...
...
@@ -58,16 +47,12 @@ import java.util.stream.Collectors;
*/
@RestController
@Api
(
tags
=
"数据导入接口"
)
@RequestMapping
(
"/data
I
mport"
)
@RequestMapping
(
"/data
/i
mport"
)
@Slf4j
public
class
DataImportController
{
@Autowired
private
DataImportTemplateService
dataImportService
;
@Autowired
private
DataDictService
dictService
;
private
DataTemplateService
dataImportService
;
@Autowired
private
ISysDatasourceService
sysDatasourceService
;
...
...
@@ -78,139 +63,9 @@ public class DataImportController {
private
DataFieldService
dataFieldService
;
@Autowired
private
DataRuleService
dataRuleService
;
@Autowired
private
BindRuleService
bindRuleService
;
@Autowired
private
ExcelDataService
excelDataService
;
@IgnoreWebSecurity
@GetMapping
(
"/template"
)
@ApiOperation
(
"模板查询"
)
public
AjaxResult
queryTemplate
(
@Validated
QueryTemplateParam
param
)
{
return
AjaxResult
.
success
(
dataImportService
.
queryTemplate
(
param
));
}
@IgnoreWebSecurity
@GetMapping
(
"/template/allField"
)
@ApiOperation
(
"查询模板的所有字段数据"
)
public
AjaxResult
getAllTemplateField
(
@RequestParam
String
templateId
)
{
return
AjaxResult
.
success
(
dataFieldService
.
list
(
Wrappers
.
lambdaQuery
(
DataField
.
class
)
.
eq
(
DataField:
:
getTemplateId
,
templateId
)));
}
@IgnoreWebSecurity
@GetMapping
(
"/template/allRule"
)
@ApiOperation
(
"查询模板的所有规则数据"
)
public
AjaxResult
getAllTemplateRule
(
@RequestParam
String
templateId
)
{
final
List
<
BindRule
>
bindRules
=
bindRuleService
.
list
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
)
.
eq
(
BindRule:
:
getDataId
,
templateId
));
if
(
CollectionUtils
.
isEmpty
(
bindRules
))
{
return
AjaxResult
.
success
(
Collections
.
emptyList
());
}
return
AjaxResult
.
success
(
dataRuleService
.
list
(
Wrappers
.
lambdaQuery
(
DataRule
.
class
)
.
eq
(
DataRule:
:
getType
,
"模板规则"
)
.
in
(
DataRule:
:
getId
,
bindRules
.
stream
().
map
(
BindRule:
:
getRuleId
).
collect
(
Collectors
.
toList
()))));
}
@IgnoreWebSecurity
@PostMapping
(
"/template"
)
@ApiOperation
(
"模板新增"
)
public
AjaxResult
addTemplate
(
@RequestBody
@Validated
AddTemplateParam
param
)
{
DataImportTemplate
template
=
new
DataImportTemplate
();
BeanUtils
.
copyProperties
(
param
,
template
);
template
.
initAdd
();
dataImportService
.
save
(
template
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/template/update"
)
@ApiOperation
(
"修改模板"
)
public
AjaxResult
updateTemplate
(
@RequestBody
@Validated
UpdateTemplateParam
param
)
{
DataImportTemplate
template
=
new
DataImportTemplate
();
BeanUtils
.
copyProperties
(
param
,
template
);
template
.
initAdd
();
dataImportService
.
updateById
(
template
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/template/delete"
)
@ApiOperation
(
"删除模板"
)
public
AjaxResult
deleteTemplate
(
@RequestParam
String
templateId
)
{
dataImportService
.
removeById
(
templateId
);
excelDataService
.
remove
(
Wrappers
.
lambdaQuery
(
ExcelData
.
class
).
eq
(
ExcelData:
:
getTemplateId
,
templateId
));
final
LambdaQueryWrapper
<
DataField
>
wrapper
=
Wrappers
.
lambdaQuery
(
DataField
.
class
).
eq
(
DataField:
:
getTemplateId
,
templateId
);
final
List
<
DataField
>
list
=
dataFieldService
.
list
(
wrapper
);
final
List
<
String
>
idList
=
new
ArrayList
<>();
idList
.
add
(
templateId
);
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
final
List
<
String
>
fieldIdList
=
list
.
stream
().
map
(
DataField:
:
getId
).
collect
(
Collectors
.
toList
());
dataFieldService
.
remove
(
Wrappers
.
lambdaQuery
(
DataField
.
class
).
eq
(
DataField:
:
getTemplateId
,
templateId
));
idList
.
addAll
(
fieldIdList
);
}
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
in
(
BindRule:
:
getDataId
,
idList
));
//TODO 已经删除:模板,字段,模板与字段关联的规则信息,模板文件表 未删除: 模板规则信息
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/dict"
)
@ApiOperation
(
"字典查询"
)
public
AjaxResult
queryDict
(
@RequestParam
String
type
)
{
final
LambdaQueryWrapper
<
DataDict
>
wrapper
=
Wrappers
.
lambdaQuery
(
DataDict
.
class
)
.
eq
(
DataDict:
:
getType
,
type
);
final
List
<
Map
<
String
,
String
>>
list
=
dictService
.
list
(
wrapper
).
stream
().
map
(
item
->
{
String
json
=
item
.
getRemarks
();
item
.
setRemarks
(
null
);
final
Map
<
String
,
String
>
map
=
BeanUtils
.
getFieldValueMap
(
item
);
if
(
StringUtils
.
isNotBlank
(
json
))
{
try
{
final
JSONObject
object
=
JSON
.
parseObject
(
json
);
object
.
forEach
((
key
,
value
)
->
{
map
.
put
(
key
,
(
String
)
value
);
});
}
catch
(
Exception
ignore
)
{
}
}
return
map
;
}).
collect
(
Collectors
.
toList
());
return
AjaxResult
.
success
(
list
);
}
@IgnoreWebSecurity
@PostMapping
(
"/dict"
)
@ApiOperation
(
"新增字典"
)
public
AjaxResult
addDict
(
@RequestBody
AddDictParam
param
)
{
DataDict
dict
=
new
DataDict
();
BeanUtils
.
copyProperties
(
param
,
dict
);
dictService
.
save
(
dict
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/dict/update"
)
@ApiOperation
(
"修改字典"
)
public
AjaxResult
updateDict
(
@RequestBody
@Validated
UpdateDictParam
param
)
{
DataDict
template
=
new
DataDict
();
BeanUtils
.
copyProperties
(
param
,
template
);
dictService
.
updateById
(
template
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/dict/delete"
)
@ApiOperation
(
"删除字典"
)
public
AjaxResult
deleteDict
(
@RequestParam
String
dictId
)
{
dictService
.
removeById
(
dictId
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/datasource"
)
@ApiOperation
(
"查询所有数据源"
)
public
AjaxResult
queryDatasource
()
{
...
...
@@ -223,18 +78,20 @@ public class DataImportController {
@ApiOperation
(
"获取指定数据源中的表"
)
public
AjaxResult
getDbTable
(
@RequestParam
String
dataSourceId
)
{
try
{
DataSource
Util
.
switchDs
(
dataSourceId
);
DataSource
Service
.
switchDb
(
dataSourceId
);
final
DruidDataSource
dataSource
=
(
DruidDataSource
)
DynamicDataSourceContextHolder
.
dataSourcesMap
.
get
(
dataSourceId
);
String
sql
=
"select TABLE_NAME AS VALUE,COMMENTS AS LABEL from user_tab_comments WHERE TABLE_TYPE = 'TABLE'"
;
if
(
dataSource
.
getDriverClassName
().
toLowerCase
().
contains
(
"mysql"
))
{
sql
=
"select TABLE_NAME AS VALUE ,table_comment AS LABEL from information_schema.tables where table_type='BASE TABLE'"
;
String
sql
;
if
(
SqlHandler
.
isOracle
(
dataSource
.
getDriverClassName
()))
{
sql
=
"SELECT TABLE_NAME AS VALUE,COMMENTS AS LABEL FROM USER_TAB_COMMENTS WHERE TABLE_TYPE = 'TABLE'"
;
}
else
{
sql
=
"select TABLE_NAME AS VALUE,TABLE_COMMENT AS LABEL from information_schema.tables where table_type='BASE TABLE'"
;
}
final
List
<
Map
<
String
,
Object
>>
maps
=
jdbcTemplate
.
queryForList
(
sql
);
return
AjaxResult
.
success
(
maps
.
stream
().
filter
(
distinctByKey
(
b
->
b
.
get
(
"VALUE"
))
).
distinct
().
collect
(
Collectors
.
toList
()));
}
finally
{
DataSource
Util
.
switchDefaultDs
();
DataSource
Service
.
switchDefault
();
}
}
...
...
@@ -264,297 +121,13 @@ public class DataImportController {
@IgnoreWebSecurity
@GetMapping
(
"/field"
)
@ApiOperation
(
"字段查询"
)
public
TableDataInfo
queryField
(
@Validated
QueryFieldParam
param
)
{
final
Page
<
DataField
>
page
=
Page
.
of
(
param
.
getPageNum
(),
param
.
getPageSize
());
final
LambdaQueryWrapper
<
DataField
>
queryWrapper
=
Wrappers
.
lambdaQuery
(
DataField
.
class
);
queryWrapper
.
eq
(
StringUtils
.
isNotBlank
(
param
.
getTemplateId
()),
DataField:
:
getTemplateId
,
param
.
getTemplateId
())
.
like
(
StringUtils
.
isNotBlank
(
param
.
getCode
()),
DataField:
:
getCode
,
param
.
getCode
())
.
like
(
StringUtils
.
isNotBlank
(
param
.
getTitle
()),
DataField:
:
getTitle
,
param
.
getTitle
())
.
like
(
StringUtils
.
isNotBlank
(
param
.
getCoordinate
()),
DataField:
:
getCoordinate
,
param
.
getCoordinate
())
.
like
(
StringUtils
.
isNotBlank
(
param
.
getField
()),
DataField:
:
getField
,
param
.
getField
());
final
Page
<
DataField
>
templatePage
=
dataFieldService
.
page
(
page
,
queryWrapper
);
return
param
.
convert
(
templatePage
);
}
@IgnoreWebSecurity
@PostMapping
(
"/field"
)
@ApiOperation
(
"字段新增"
)
public
AjaxResult
addField
(
@RequestBody
@Validated
AddFieldParam
param
)
{
DataField
field
=
new
DataField
();
BeanUtils
.
copyProperties
(
param
,
field
);
dataFieldService
.
save
(
field
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/field/update"
)
@ApiOperation
(
"修改字段"
)
public
AjaxResult
updateField
(
@RequestBody
@Validated
UpdateFieldParam
param
)
{
DataField
field
=
new
DataField
();
BeanUtils
.
copyProperties
(
param
,
field
);
dataFieldService
.
updateById
(
field
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/field/delete"
)
@ApiOperation
(
"删除字段"
)
public
AjaxResult
deleteField
(
@RequestParam
String
fieldId
)
{
dataFieldService
.
removeById
(
fieldId
);
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
eq
(
BindRule:
:
getDataId
,
fieldId
));
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/rule"
)
@ApiOperation
(
"规则查询"
)
public
TableDataInfo
queryRule
(
@Validated
QueryRuleParam
param
)
{
final
Page
<
DataRule
>
page
=
Page
.
of
(
param
.
getPageNum
(),
param
.
getPageSize
());
final
LambdaQueryWrapper
<
DataRule
>
queryWrapper
=
Wrappers
.
lambdaQuery
(
DataRule
.
class
);
queryWrapper
.
like
(
StringUtils
.
isNotBlank
(
param
.
getName
()),
DataRule:
:
getName
,
param
.
getName
())
.
eq
(
StringUtils
.
isNotBlank
(
param
.
getType
()),
DataRule:
:
getType
,
param
.
getType
())
.
in
(
DataRule:
:
getType
,
"基础规则"
,
"组合规则"
);
final
Page
<
DataRule
>
templatePage
=
dataRuleService
.
page
(
page
,
queryWrapper
);
return
param
.
convert
(
templatePage
);
}
@IgnoreWebSecurity
@GetMapping
(
"/rule/dict"
)
@ApiOperation
(
"规则字典"
)
public
AjaxResult
queryRuleDict
()
{
final
LambdaQueryWrapper
<
DataRule
>
queryWrapper
=
Wrappers
.
lambdaQuery
(
DataRule
.
class
);
queryWrapper
.
in
(
DataRule:
:
getType
,
"基础规则"
,
"组合规则"
)
.
select
(
DataRule:
:
getId
,
DataRule:
:
getName
);
return
AjaxResult
.
success
(
dataRuleService
.
list
(
queryWrapper
));
}
@IgnoreWebSecurity
@PostMapping
(
"/rule"
)
@ApiOperation
(
"规则新增"
)
public
AjaxResult
addRule
(
@RequestBody
@Validated
AddRuleParam
param
)
{
DataRule
rule
=
new
DataRule
();
BeanUtils
.
copyProperties
(
param
,
rule
);
dataRuleService
.
save
(
rule
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/rule/update"
)
@ApiOperation
(
"修改规则"
)
public
AjaxResult
updateRule
(
@RequestBody
@Validated
UpdateRuleParam
param
)
{
DataRule
rule
=
new
DataRule
();
BeanUtils
.
copyProperties
(
param
,
rule
);
dataRuleService
.
updateById
(
rule
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/rule/delete"
)
@ApiOperation
(
"删除规则"
)
public
AjaxResult
deleteRule
(
@RequestParam
String
ruleId
)
{
dataRuleService
.
removeById
(
ruleId
);
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
eq
(
BindRule:
:
getRuleId
,
ruleId
));
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/rule/test"
)
@ApiOperation
(
"规则测试"
)
public
AjaxResult
testRule
(
@RequestBody
@Validated
RuleVO
test
)
{
final
RuleValidator
validator
=
DiConfig
.
getValidator
(
test
.
getMode
());
validator
.
validate
(
test
);
if
(
StringUtils
.
isNotBlank
(
test
.
getResult
()))
{
return
AjaxResult
.
error
(
test
.
getResult
());
}
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/bind/quick"
)
@ApiOperation
(
"快速绑定"
)
public
AjaxResult
quickBind
(
@RequestParam
String
templateId
,
@RequestParam
String
ruleId
)
{
final
LambdaQueryWrapper
<
DataField
>
queryWrapper
=
Wrappers
.
lambdaQuery
(
DataField
.
class
)
.
select
(
DataField:
:
getId
)
.
eq
(
DataField:
:
getTemplateId
,
templateId
);
final
List
<
String
>
fieldIdList
=
dataFieldService
.
list
(
queryWrapper
).
stream
()
.
map
(
DataField:
:
getId
)
.
collect
(
Collectors
.
toList
());
final
LambdaQueryWrapper
<
BindRule
>
removeWrapper
=
Wrappers
.
lambdaQuery
(
BindRule
.
class
)
.
in
(
BindRule:
:
getDataId
,
fieldIdList
)
.
eq
(
BindRule:
:
getRuleId
,
ruleId
);
bindRuleService
.
remove
(
removeWrapper
);
final
List
<
BindRule
>
bindRuleList
=
fieldIdList
.
stream
().
map
(
item
->
{
BindRule
bind
=
new
BindRule
();
bind
.
setDataId
(
item
);
bind
.
setRuleId
(
ruleId
);
return
bind
;
}).
collect
(
Collectors
.
toList
());
bindRuleService
.
saveBatch
(
bindRuleList
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/bind"
)
@ApiOperation
(
"查询绑定的规则"
)
public
AjaxResult
queryBindRule
(
@RequestParam
String
fieldId
)
{
final
List
<
BindRule
>
list
=
bindRuleService
.
list
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
)
.
eq
(
BindRule:
:
getDataId
,
fieldId
));
if
(
CollectionUtils
.
isEmpty
(
list
))
{
return
AjaxResult
.
success
(
Collections
.
emptyList
());
}
final
List
<
String
>
idList
=
list
.
stream
().
map
(
BindRule:
:
getRuleId
).
collect
(
Collectors
.
toList
());
return
AjaxResult
.
success
(
dataRuleService
.
list
(
Wrappers
.
lambdaQuery
(
DataRule
.
class
)
.
in
(
DataRule:
:
getId
,
idList
)));
}
@IgnoreWebSecurity
@PostMapping
(
"/bind"
)
@ApiOperation
(
"配置字段规则绑定"
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
AjaxResult
bindRule
(
@RequestBody
BindRuleParam
param
)
{
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
eq
(
BindRule:
:
getDataId
,
param
.
getFieldId
()));
if
(!
CollectionUtils
.
isEmpty
(
param
.
getRuleIdList
()))
{
final
List
<
BindRule
>
bindRuleList
=
param
.
getRuleIdList
().
stream
().
map
(
item
->
{
BindRule
bd
=
new
BindRule
();
bd
.
setRuleId
(
item
);
bd
.
setDataId
(
param
.
getFieldId
());
return
bd
;
}).
collect
(
Collectors
.
toList
());
bindRuleService
.
saveBatch
(
bindRuleList
);
}
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/template/download"
)
@ApiOperation
(
"模板下载"
)
public
void
downloadTemplate
(
HttpServletResponse
response
,
@RequestParam
String
excelId
)
{
final
ExcelData
excel
=
excelDataService
.
getById
(
excelId
);
if
(
excel
!=
null
)
{
try
(
OutputStream
os
=
response
.
getOutputStream
())
{
os
.
write
(
excel
.
getFile
());
os
.
flush
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
@IgnoreWebSecurity
@GetMapping
(
"/template/download/filename"
)
@ApiOperation
(
"获取模板文件名"
)
public
AjaxResult
getTemplateFileName
(
@RequestParam
String
excelId
)
{
final
ExcelData
excel
=
excelDataService
.
getOne
(
Wrappers
.
lambdaQuery
(
ExcelData
.
class
)
.
select
(
ExcelData:
:
getFileName
)
.
eq
(
ExcelData:
:
getId
,
excelId
)
);
if
(
excel
!=
null
)
{
return
AjaxResult
.
success
(
excel
);
}
else
{
return
AjaxResult
.
error
(
"未查询到指定的模板文件"
);
}
}
@SneakyThrows
@IgnoreWebSecurity
@PostMapping
(
"/upload"
)
@ApiOperation
(
"文件导入"
)
public
AjaxResult
bindRule
(
UploadExcelParam
param
)
{
if
(
StringUtils
.
equals
(
param
.
getType
(),
"1"
))
{
ExcelData
excelData
=
excelDataService
.
getOne
(
Wrappers
.
lambdaQuery
(
ExcelData
.
class
)
.
eq
(
ExcelData:
:
getTemplateId
,
param
.
getTemplateId
())
.
eq
(
ExcelData:
:
getType
,
"1"
),
false
);
if
(
excelData
==
null
)
{
excelData
=
new
ExcelData
();
excelData
.
setType
(
"1"
);
excelData
.
setTemplateId
(
param
.
getTemplateId
());
excelData
.
setYear
(
param
.
getYear
());
excelData
.
setOrgName
(
param
.
getOrgName
());
}
excelData
.
setFile
(
param
.
getFile
().
getBytes
());
excelData
.
setFileName
(
param
.
getFile
().
getOriginalFilename
());
excelDataService
.
saveOrUpdate
(
excelData
);
}
else
if
(
StringUtils
.
equals
(
param
.
getType
(),
"2"
))
{
ExcelData
excelData
=
excelDataService
.
getOne
(
Wrappers
.
lambdaQuery
(
ExcelData
.
class
)
.
eq
(
ExcelData:
:
getTemplateId
,
param
.
getTemplateId
())
.
eq
(
ExcelData:
:
getType
,
"2"
),
false
);
if
(
ObjectUtils
.
isEmpty
(
excelData
))
{
excelData
=
new
ExcelData
();
excelData
.
setFile
(
param
.
getFile
().
getBytes
());
excelData
.
setFileName
(
param
.
getFile
().
getOriginalFilename
());
excelData
.
setType
(
"2"
);
excelData
.
setTemplateId
(
param
.
getTemplateId
());
excelData
.
setYear
(
param
.
getYear
());
excelData
.
setOrgName
(
param
.
getOrgName
());
excelDataService
.
save
(
excelData
);
}
else
{
excelData
.
setFile
(
param
.
getFile
().
getBytes
());
excelData
.
setFileName
(
param
.
getFile
().
getOriginalFilename
());
excelDataService
.
updateById
(
excelData
);
}
}
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/field/reset"
)
@ApiOperation
(
"根据基础模板重置字段"
)
public
AjaxResult
resetField
(
@RequestParam
String
excelId
)
{
final
ExcelData
excelData
=
excelDataService
.
getById
(
excelId
);
final
LambdaQueryWrapper
<
DataField
>
wrapper
=
Wrappers
.
lambdaQuery
(
DataField
.
class
).
eq
(
DataField:
:
getTemplateId
,
excelData
.
getTemplateId
());
final
List
<
DataField
>
list
=
dataFieldService
.
list
(
wrapper
);
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
final
List
<
String
>
fieldIdList
=
list
.
stream
().
map
(
DataField:
:
getId
).
collect
(
Collectors
.
toList
());
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
in
(
BindRule:
:
getDataId
,
fieldIdList
));
}
dataFieldService
.
remove
(
Wrappers
.
lambdaQuery
(
DataField
.
class
).
eq
(
DataField:
:
getTemplateId
,
excelData
.
getTemplateId
()));
try
(
InputStream
is
=
new
ByteArrayInputStream
(
excelData
.
getFile
());
Workbook
workbook
=
WorkbookFactory
.
create
(
is
))
{
final
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
final
int
rows
=
sheet
.
getLastRowNum
()
+
1
;
List
<
DataField
>
fieldList
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<
rows
;
i
++)
{
final
Row
row
=
sheet
.
getRow
(
i
);
String
code
=
DiConfig
.
getValue
(
row
.
getCell
(
1
,
Row
.
MissingCellPolicy
.
RETURN_BLANK_AS_NULL
));
String
title
=
DiConfig
.
getValue
(
row
.
getCell
(
2
,
Row
.
MissingCellPolicy
.
RETURN_BLANK_AS_NULL
));
String
unit
=
DiConfig
.
getValue
(
row
.
getCell
(
4
,
Row
.
MissingCellPolicy
.
RETURN_BLANK_AS_NULL
));
if
(
StringUtils
.
isAllBlank
(
code
,
title
,
unit
))
{
continue
;
}
if
(
StringUtils
.
equals
(
code
,
"代码"
)
||
StringUtils
.
equals
(
title
,
"指标名称"
)
||
StringUtils
.
equals
(
unit
,
"计量单位"
))
{
continue
;
}
final
DataField
dataField
=
new
DataField
();
dataField
.
setTemplateId
(
excelData
.
getTemplateId
());
dataField
.
setCode
(
code
);
dataField
.
setTitle
(
title
);
dataField
.
setUnit
(
unit
);
// TODO 这里坐标修改为i+1是因为excel文件中展示的第一行号是1,符合直觉
dataField
.
setCoordinate
(
"F,"
+
(
i
+
1
));
dataField
.
setSort
(
i
+
1
);
dataField
.
createField
();
fieldList
.
add
(
dataField
);
}
dataFieldService
.
saveBatch
(
fieldList
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/table/create"
)
@ApiOperation
(
"物理表生成"
)
public
AjaxResult
createTable
(
@RequestParam
String
tableName
,
@RequestParam
String
templateId
)
{
// 默认表名全大写
tableName
=
tableName
.
toUpperCase
();
final
Data
Import
Template
template
=
dataImportService
.
getById
(
templateId
);
final
DataTemplate
template
=
dataImportService
.
getById
(
templateId
);
if
(
StringUtils
.
isBlank
(
template
.
getDataSourceId
()))
{
return
AjaxResult
.
error
(
"请在模板编辑界面选择对应的数据源"
);
}
...
...
@@ -587,7 +160,7 @@ public class DataImportController {
jdbcTemplate
.
execute
(
StrFormatter
.
format
(
sb
.
toString
(),
tableName
));
jdbcTemplate
.
execute
(
StrFormatter
.
format
(
sb
.
toString
(),
tableName
+
"_TEMP"
));
// 修改模板表绑定的表名
final
Data
ImportTemplate
updateTemplate
=
new
DataImport
Template
();
final
Data
Template
updateTemplate
=
new
Data
Template
();
updateTemplate
.
setId
(
template
.
getId
());
updateTemplate
.
setTableName
(
tableName
);
DataSourceUtil
.
switchDefaultDs
();
...
...
@@ -632,7 +205,7 @@ public class DataImportController {
jdbcTemplate
.
batchUpdate
(
prod
);
jdbcTemplate
.
batchUpdate
(
temp
);
// 修改模板表绑定的表名
final
Data
ImportTemplate
updateTemplate
=
new
DataImport
Template
();
final
Data
Template
updateTemplate
=
new
Data
Template
();
updateTemplate
.
setId
(
template
.
getId
());
updateTemplate
.
setTableName
(
finalTableName
);
DataSourceUtil
.
switchDefaultDs
();
...
...
@@ -673,7 +246,7 @@ public class DataImportController {
@PostMapping
(
"/clearTemp"
)
@ApiOperation
(
"清空临时表数据"
)
public
AjaxResult
clearTemp
(
@RequestBody
TemplateVO
vo
)
{
final
Data
Import
Template
template
=
dataImportService
.
getById
(
vo
.
getId
());
final
DataTemplate
template
=
dataImportService
.
getById
(
vo
.
getId
());
try
{
DataSourceUtil
.
switchDs
(
template
.
getDataSourceId
());
String
sql
=
"DELETE FROM "
+
template
.
getTableName
()
+
"_TEMP"
;
...
...
@@ -695,7 +268,7 @@ public class DataImportController {
@PostMapping
(
"/syncDb"
)
@ApiOperation
(
"一键导入正式库"
)
public
AjaxResult
syncDb
(
@RequestBody
TemplateVO
vo
)
{
final
Data
Import
Template
template
=
dataImportService
.
getById
(
vo
.
getId
());
final
DataTemplate
template
=
dataImportService
.
getById
(
vo
.
getId
());
final
List
<
DataField
>
fieldList
=
dataFieldService
.
list
(
Wrappers
.
lambdaQuery
(
DataField
.
class
)
.
eq
(
DataField:
:
getTemplateId
,
template
.
getId
())
.
isNotNull
(
DataField:
:
getField
)
...
...
@@ -736,7 +309,7 @@ public class DataImportController {
}
finally
{
DataSourceUtil
.
switchDefaultDs
();
}
Data
ImportTemplate
updateTemplate
=
new
DataImport
Template
();
Data
Template
updateTemplate
=
new
Data
Template
();
updateTemplate
.
setId
(
template
.
getId
());
updateTemplate
.
setImportStatus
(
"1"
);
updateTemplate
.
setImportTime
(
new
Date
());
...
...
@@ -744,41 +317,5 @@ public class DataImportController {
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/rule/template"
)
@ApiOperation
(
"规则新增By Template"
)
public
AjaxResult
addRuleByTemplate
(
@RequestBody
@Validated
AddTemplateRuleParam
param
)
{
DataRule
rule
=
new
DataRule
();
BeanUtils
.
copyProperties
(
param
,
rule
);
dataRuleService
.
save
(
rule
);
final
BindRule
bindRule
=
new
BindRule
();
bindRule
.
setDataId
(
param
.
getTid
())
.
setRuleId
(
rule
.
getId
());
bindRuleService
.
save
(
bindRule
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/rule/template/update"
)
@ApiOperation
(
"修改规则By Template"
)
public
AjaxResult
updateRuleByTemplate
(
@RequestBody
@Validated
UpdateRuleParam
param
)
{
DataRule
rule
=
new
DataRule
();
BeanUtils
.
copyProperties
(
param
,
rule
);
dataRuleService
.
updateById
(
rule
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/rule/template/delete"
)
@ApiOperation
(
"删除规则By Template"
)
public
AjaxResult
deleteRuleByTemplate
(
@RequestParam
String
ruleId
,
@RequestParam
String
templateId
)
{
dataRuleService
.
removeById
(
ruleId
);
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
)
.
eq
(
BindRule:
:
getRuleId
,
ruleId
)
.
eq
(
BindRule:
:
getDataId
,
templateId
));
return
AjaxResult
.
success
();
}
}
admin-api/src/main/java/com/tbyf/his/web/controller/dataImport/DataRuleController.java
0 → 100644
View file @
619cf8e1
package
com
.
tbyf
.
his
.
web
.
controller
.
dataImport
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.tbyf.his.common.annotation.IgnoreWebSecurity
;
import
com.tbyf.his.common.core.domain.AjaxResult
;
import
com.tbyf.his.common.core.page.TableDataInfo
;
import
com.tbyf.his.common.utils.StringUtils
;
import
com.tbyf.his.common.utils.bean.BeanUtils
;
import
com.tbyf.his.web.dataImport.core.DiConfig
;
import
com.tbyf.his.web.dataImport.core.RuleVO
;
import
com.tbyf.his.web.dataImport.core.RuleValidator
;
import
com.tbyf.his.web.dataImport.domain.param.AddRuleParam
;
import
com.tbyf.his.web.dataImport.domain.param.BindRuleParam
;
import
com.tbyf.his.web.dataImport.domain.param.QueryRuleParam
;
import
com.tbyf.his.web.dataImport.domain.param.UpdateRuleParam
;
import
com.tbyf.his.web.dataImport.entity.BindRule
;
import
com.tbyf.his.web.dataImport.entity.DataField
;
import
com.tbyf.his.web.dataImport.entity.DataRule
;
import
com.tbyf.his.web.dataImport.service.BindRuleService
;
import
com.tbyf.his.web.dataImport.service.DataFieldService
;
import
com.tbyf.his.web.dataImport.service.DataRuleService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* @author lzz
* @date 2023/2/16 15:29
*/
@RestController
@Api
(
tags
=
"数据字段接口"
)
@RequestMapping
(
"/data/rule"
)
@Slf4j
public
class
DataRuleController
{
@Autowired
private
DataRuleService
dataRuleService
;
@Autowired
private
BindRuleService
bindRuleService
;
@Autowired
private
DataFieldService
dataFieldService
;
@IgnoreWebSecurity
@GetMapping
(
""
)
@ApiOperation
(
"规则查询"
)
public
TableDataInfo
queryRule
(
@Validated
QueryRuleParam
param
)
{
final
Page
<
DataRule
>
page
=
Page
.
of
(
param
.
getPageNum
(),
param
.
getPageSize
());
final
LambdaQueryWrapper
<
DataRule
>
queryWrapper
=
Wrappers
.
lambdaQuery
(
DataRule
.
class
);
queryWrapper
.
like
(
StringUtils
.
isNotBlank
(
param
.
getName
()),
DataRule:
:
getName
,
param
.
getName
())
.
eq
(
StringUtils
.
isNotBlank
(
param
.
getType
()),
DataRule:
:
getType
,
param
.
getType
())
.
in
(
DataRule:
:
getType
,
"基础规则"
,
"组合规则"
);
final
Page
<
DataRule
>
templatePage
=
dataRuleService
.
page
(
page
,
queryWrapper
);
return
param
.
convert
(
templatePage
);
}
@IgnoreWebSecurity
@GetMapping
(
"/dict"
)
@ApiOperation
(
"规则字典"
)
public
AjaxResult
queryRuleDict
()
{
final
LambdaQueryWrapper
<
DataRule
>
queryWrapper
=
Wrappers
.
lambdaQuery
(
DataRule
.
class
);
queryWrapper
.
in
(
DataRule:
:
getType
,
"基础规则"
,
"组合规则"
)
.
select
(
DataRule:
:
getId
,
DataRule:
:
getName
);
return
AjaxResult
.
success
(
dataRuleService
.
list
(
queryWrapper
));
}
@IgnoreWebSecurity
@PostMapping
(
""
)
@ApiOperation
(
"规则新增"
)
public
AjaxResult
addRule
(
@RequestBody
@Validated
AddRuleParam
param
)
{
DataRule
rule
=
new
DataRule
();
BeanUtils
.
copyProperties
(
param
,
rule
);
dataRuleService
.
save
(
rule
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/update"
)
@ApiOperation
(
"修改规则"
)
public
AjaxResult
updateRule
(
@RequestBody
@Validated
UpdateRuleParam
param
)
{
DataRule
rule
=
new
DataRule
();
BeanUtils
.
copyProperties
(
param
,
rule
);
dataRuleService
.
updateById
(
rule
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/delete"
)
@ApiOperation
(
"删除规则"
)
public
AjaxResult
deleteRule
(
@RequestParam
String
ruleId
)
{
dataRuleService
.
removeById
(
ruleId
);
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
eq
(
BindRule:
:
getRuleId
,
ruleId
));
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/test"
)
@ApiOperation
(
"规则测试"
)
public
AjaxResult
testRule
(
@RequestBody
@Validated
RuleVO
test
)
{
final
RuleValidator
validator
=
DiConfig
.
getValidator
(
test
.
getMode
());
validator
.
validate
(
test
);
if
(
StringUtils
.
isNotBlank
(
test
.
getResult
()))
{
return
AjaxResult
.
error
(
test
.
getResult
());
}
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/bind/quick"
)
@ApiOperation
(
"快速绑定"
)
public
AjaxResult
quickBind
(
@RequestParam
String
templateId
,
@RequestParam
String
ruleId
)
{
final
LambdaQueryWrapper
<
DataField
>
queryWrapper
=
Wrappers
.
lambdaQuery
(
DataField
.
class
)
.
select
(
DataField:
:
getId
)
.
eq
(
DataField:
:
getTemplateId
,
templateId
);
final
List
<
String
>
fieldIdList
=
dataFieldService
.
list
(
queryWrapper
).
stream
()
.
map
(
DataField:
:
getId
)
.
collect
(
Collectors
.
toList
());
final
LambdaQueryWrapper
<
BindRule
>
removeWrapper
=
Wrappers
.
lambdaQuery
(
BindRule
.
class
)
.
in
(
BindRule:
:
getDataId
,
fieldIdList
)
.
eq
(
BindRule:
:
getRuleId
,
ruleId
);
bindRuleService
.
remove
(
removeWrapper
);
final
List
<
BindRule
>
bindRuleList
=
fieldIdList
.
stream
().
map
(
item
->
{
BindRule
bind
=
new
BindRule
();
bind
.
setDataId
(
item
);
bind
.
setRuleId
(
ruleId
);
return
bind
;
}).
collect
(
Collectors
.
toList
());
bindRuleService
.
saveBatch
(
bindRuleList
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/bind"
)
@ApiOperation
(
"查询绑定的规则"
)
public
AjaxResult
queryBindRule
(
@RequestParam
String
fieldId
)
{
final
List
<
BindRule
>
list
=
bindRuleService
.
list
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
)
.
eq
(
BindRule:
:
getDataId
,
fieldId
));
if
(
CollectionUtils
.
isEmpty
(
list
))
{
return
AjaxResult
.
success
(
Collections
.
emptyList
());
}
final
List
<
String
>
idList
=
list
.
stream
().
map
(
BindRule:
:
getRuleId
).
collect
(
Collectors
.
toList
());
return
AjaxResult
.
success
(
dataRuleService
.
list
(
Wrappers
.
lambdaQuery
(
DataRule
.
class
)
.
in
(
DataRule:
:
getId
,
idList
)));
}
@IgnoreWebSecurity
@PostMapping
(
"/bind"
)
@ApiOperation
(
"配置字段规则绑定"
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
AjaxResult
bindRule
(
@RequestBody
BindRuleParam
param
)
{
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
eq
(
BindRule:
:
getDataId
,
param
.
getFieldId
()));
if
(!
CollectionUtils
.
isEmpty
(
param
.
getRuleIdList
()))
{
final
List
<
BindRule
>
bindRuleList
=
param
.
getRuleIdList
().
stream
().
map
(
item
->
{
BindRule
bd
=
new
BindRule
();
bd
.
setRuleId
(
item
);
bd
.
setDataId
(
param
.
getFieldId
());
return
bd
;
}).
collect
(
Collectors
.
toList
());
bindRuleService
.
saveBatch
(
bindRuleList
);
}
return
AjaxResult
.
success
();
}
}
admin-api/src/main/java/com/tbyf/his/web/controller/dataImport/DataTemplateController.java
0 → 100644
View file @
619cf8e1
package
com
.
tbyf
.
his
.
web
.
controller
.
dataImport
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.tbyf.his.common.annotation.IgnoreWebSecurity
;
import
com.tbyf.his.common.core.domain.AjaxResult
;
import
com.tbyf.his.common.utils.bean.BeanUtils
;
import
com.tbyf.his.web.dataImport.domain.param.*
;
import
com.tbyf.his.web.dataImport.entity.*
;
import
com.tbyf.his.web.dataImport.service.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* @author lzz
* @date 2023/2/7 10:42
*/
@RestController
@Api
(
tags
=
"数据模板接口"
)
@RequestMapping
(
"/data/template"
)
@Slf4j
public
class
DataTemplateController
{
@Autowired
private
DataTemplateService
dataImportService
;
@Autowired
private
DataFieldService
dataFieldService
;
@Autowired
private
DataRuleService
dataRuleService
;
@Autowired
private
BindRuleService
bindRuleService
;
@Autowired
private
ExcelDataService
excelDataService
;
@IgnoreWebSecurity
@GetMapping
()
@ApiOperation
(
"模板查询"
)
public
AjaxResult
queryTemplate
(
@Validated
QueryTemplateParam
param
)
{
return
AjaxResult
.
success
(
dataImportService
.
queryTemplate
(
param
));
}
@IgnoreWebSecurity
@GetMapping
(
"/allField"
)
@ApiOperation
(
"查询模板的所有字段数据"
)
public
AjaxResult
getAllTemplateField
(
@RequestParam
String
templateId
)
{
return
AjaxResult
.
success
(
dataFieldService
.
list
(
Wrappers
.
lambdaQuery
(
DataField
.
class
)
.
eq
(
DataField:
:
getTemplateId
,
templateId
)));
}
@IgnoreWebSecurity
@GetMapping
(
"/allRule"
)
@ApiOperation
(
"查询模板的所有规则数据"
)
public
AjaxResult
getAllTemplateRule
(
@RequestParam
String
templateId
)
{
final
List
<
BindRule
>
bindRules
=
bindRuleService
.
list
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
)
.
eq
(
BindRule:
:
getDataId
,
templateId
));
if
(
CollectionUtils
.
isEmpty
(
bindRules
))
{
return
AjaxResult
.
success
(
Collections
.
emptyList
());
}
return
AjaxResult
.
success
(
dataRuleService
.
list
(
Wrappers
.
lambdaQuery
(
DataRule
.
class
)
.
eq
(
DataRule:
:
getType
,
"模板规则"
)
.
in
(
DataRule:
:
getId
,
bindRules
.
stream
().
map
(
BindRule:
:
getRuleId
).
collect
(
Collectors
.
toList
()))));
}
@IgnoreWebSecurity
@PostMapping
(
""
)
@ApiOperation
(
"模板新增"
)
public
AjaxResult
addTemplate
(
@RequestBody
@Validated
AddTemplateParam
param
)
{
DataTemplate
template
=
new
DataTemplate
();
BeanUtils
.
copyProperties
(
param
,
template
);
template
.
initAdd
();
dataImportService
.
save
(
template
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/template/update"
)
@ApiOperation
(
"修改模板"
)
public
AjaxResult
updateTemplate
(
@RequestBody
@Validated
UpdateTemplateParam
param
)
{
DataTemplate
template
=
new
DataTemplate
();
BeanUtils
.
copyProperties
(
param
,
template
);
template
.
initAdd
();
dataImportService
.
updateById
(
template
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/template/delete"
)
@ApiOperation
(
"删除模板"
)
public
AjaxResult
deleteTemplate
(
@RequestParam
String
templateId
)
{
dataImportService
.
removeById
(
templateId
);
excelDataService
.
remove
(
Wrappers
.
lambdaQuery
(
ExcelData
.
class
).
eq
(
ExcelData:
:
getTemplateId
,
templateId
));
final
LambdaQueryWrapper
<
DataField
>
wrapper
=
Wrappers
.
lambdaQuery
(
DataField
.
class
).
eq
(
DataField:
:
getTemplateId
,
templateId
);
final
List
<
DataField
>
list
=
dataFieldService
.
list
(
wrapper
);
final
List
<
String
>
idList
=
new
ArrayList
<>();
idList
.
add
(
templateId
);
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
final
List
<
String
>
fieldIdList
=
list
.
stream
().
map
(
DataField:
:
getId
).
collect
(
Collectors
.
toList
());
dataFieldService
.
remove
(
Wrappers
.
lambdaQuery
(
DataField
.
class
).
eq
(
DataField:
:
getTemplateId
,
templateId
));
idList
.
addAll
(
fieldIdList
);
}
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
in
(
BindRule:
:
getDataId
,
idList
));
//TODO 已经删除:模板,字段,模板与字段关联的规则信息,模板文件表 未删除: 模板规则信息
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/rule"
)
@ApiOperation
(
"规则新增By Template"
)
public
AjaxResult
addRuleByTemplate
(
@RequestBody
@Validated
AddTemplateRuleParam
param
)
{
DataRule
rule
=
new
DataRule
();
BeanUtils
.
copyProperties
(
param
,
rule
);
dataRuleService
.
save
(
rule
);
final
BindRule
bindRule
=
new
BindRule
();
bindRule
.
setDataId
(
param
.
getTid
())
.
setRuleId
(
rule
.
getId
());
bindRuleService
.
save
(
bindRule
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/rule/update"
)
@ApiOperation
(
"修改规则By Template"
)
public
AjaxResult
updateRuleByTemplate
(
@RequestBody
@Validated
UpdateRuleParam
param
)
{
DataRule
rule
=
new
DataRule
();
BeanUtils
.
copyProperties
(
param
,
rule
);
dataRuleService
.
updateById
(
rule
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/rule/delete"
)
@ApiOperation
(
"删除规则By Template"
)
public
AjaxResult
deleteRuleByTemplate
(
@RequestParam
String
ruleId
,
@RequestParam
String
templateId
)
{
dataRuleService
.
removeById
(
ruleId
);
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
)
.
eq
(
BindRule:
:
getRuleId
,
ruleId
)
.
eq
(
BindRule:
:
getDataId
,
templateId
));
return
AjaxResult
.
success
();
}
}
admin-api/src/main/java/com/tbyf/his/web/controller/dataImport/DictDataController.java
0 → 100644
View file @
619cf8e1
package
com
.
tbyf
.
his
.
web
.
controller
.
dataImport
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.tbyf.his.common.annotation.IgnoreWebSecurity
;
import
com.tbyf.his.common.core.domain.AjaxResult
;
import
com.tbyf.his.common.utils.StringUtils
;
import
com.tbyf.his.common.utils.bean.BeanUtils
;
import
com.tbyf.his.web.dataImport.domain.param.AddDictParam
;
import
com.tbyf.his.web.dataImport.domain.param.UpdateDictParam
;
import
com.tbyf.his.web.dataImport.entity.DataDict
;
import
com.tbyf.his.web.dataImport.service.DataDictService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* @author lzz
* @date 2023/2/16 15:30
*/
@RestController
@Api
(
tags
=
"字典接口"
)
@RequestMapping
(
"/data/dict"
)
@Slf4j
public
class
DictDataController
{
@Autowired
private
DataDictService
dictService
;
@IgnoreWebSecurity
@GetMapping
(
""
)
@ApiOperation
(
"字典查询"
)
public
AjaxResult
queryDict
(
@RequestParam
String
type
)
{
final
LambdaQueryWrapper
<
DataDict
>
wrapper
=
Wrappers
.
lambdaQuery
(
DataDict
.
class
)
.
eq
(
DataDict:
:
getType
,
type
);
final
List
<
Map
<
String
,
String
>>
list
=
dictService
.
list
(
wrapper
).
stream
().
map
(
item
->
{
String
json
=
item
.
getRemarks
();
item
.
setRemarks
(
null
);
final
Map
<
String
,
String
>
map
=
BeanUtils
.
getFieldValueMap
(
item
);
if
(
StringUtils
.
isNotBlank
(
json
))
{
try
{
final
JSONObject
object
=
JSON
.
parseObject
(
json
);
object
.
forEach
((
key
,
value
)
->
{
map
.
put
(
key
,
(
String
)
value
);
});
}
catch
(
Exception
ignore
)
{
}
}
return
map
;
}).
collect
(
Collectors
.
toList
());
return
AjaxResult
.
success
(
list
);
}
@IgnoreWebSecurity
@PostMapping
(
""
)
@ApiOperation
(
"新增字典"
)
public
AjaxResult
addDict
(
@RequestBody
AddDictParam
param
)
{
DataDict
dict
=
new
DataDict
();
BeanUtils
.
copyProperties
(
param
,
dict
);
dictService
.
save
(
dict
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@PostMapping
(
"/update"
)
@ApiOperation
(
"修改字典"
)
public
AjaxResult
updateDict
(
@RequestBody
@Validated
UpdateDictParam
param
)
{
DataDict
template
=
new
DataDict
();
BeanUtils
.
copyProperties
(
param
,
template
);
dictService
.
updateById
(
template
);
return
AjaxResult
.
success
();
}
@IgnoreWebSecurity
@GetMapping
(
"/delete"
)
@ApiOperation
(
"删除字典"
)
public
AjaxResult
deleteDict
(
@RequestParam
String
dictId
)
{
dictService
.
removeById
(
dictId
);
return
AjaxResult
.
success
();
}
}
admin-api/src/main/java/com/tbyf/his/web/controller/dataImport/ExcelDataController.java
0 → 100644
View file @
619cf8e1
package
com
.
tbyf
.
his
.
web
.
controller
.
dataImport
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.tbyf.his.common.annotation.IgnoreWebSecurity
;
import
com.tbyf.his.common.core.domain.AjaxResult
;
import
com.tbyf.his.common.utils.StringUtils
;
import
com.tbyf.his.web.dataImport.domain.param.UploadExcelParam
;
import
com.tbyf.his.web.dataImport.entity.ExcelData
;
import
com.tbyf.his.web.dataImport.service.ExcelDataService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.SneakyThrows
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.OutputStream
;
/**
* @author lzz
* @date 2023/2/16 15:30
*/
@RestController
@Api
(
tags
=
"excel文件接口"
)
@RequestMapping
(
"/data/excel"
)
@Slf4j
public
class
ExcelDataController
{
@Autowired
private
ExcelDataService
excelDataService
;
@IgnoreWebSecurity
@GetMapping
(
"/download/template"
)
@ApiOperation
(
"模板下载"
)
public
void
downloadTemplate
(
HttpServletResponse
response
,
@RequestParam
String
excelId
)
{
final
ExcelData
excel
=
excelDataService
.
getById
(
excelId
);
if
(
excel
!=
null
)
{
try
(
OutputStream
os
=
response
.
getOutputStream
())
{
os
.
write
(
excel
.
getFile
());
os
.
flush
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
@IgnoreWebSecurity
@GetMapping
(
"/download/template/filename"
)
@ApiOperation
(
"获取模板文件名"
)
public
AjaxResult
getTemplateFileName
(
@RequestParam
String
excelId
)
{
final
ExcelData
excel
=
excelDataService
.
getOne
(
Wrappers
.
lambdaQuery
(
ExcelData
.
class
)
.
select
(
ExcelData:
:
getFileName
)
.
eq
(
ExcelData:
:
getId
,
excelId
)
);
if
(
excel
!=
null
)
{
return
AjaxResult
.
success
(
excel
);
}
else
{
return
AjaxResult
.
error
(
"未查询到指定的模板文件"
);
}
}
@SneakyThrows
@IgnoreWebSecurity
@PostMapping
(
"/upload"
)
@ApiOperation
(
"文件导入"
)
public
AjaxResult
bindRule
(
UploadExcelParam
param
)
{
if
(
StringUtils
.
equals
(
param
.
getType
(),
"1"
))
{
ExcelData
excelData
=
excelDataService
.
getOne
(
Wrappers
.
lambdaQuery
(
ExcelData
.
class
)
.
eq
(
ExcelData:
:
getTemplateId
,
param
.
getTemplateId
())
.
eq
(
ExcelData:
:
getType
,
"1"
),
false
);
if
(
excelData
==
null
)
{
excelData
=
new
ExcelData
();
excelData
.
setType
(
"1"
);
excelData
.
setTemplateId
(
param
.
getTemplateId
());
excelData
.
setYear
(
param
.
getYear
());
excelData
.
setOrgName
(
param
.
getOrgName
());
}
excelData
.
setFile
(
param
.
getFile
().
getBytes
());
excelData
.
setFileName
(
param
.
getFile
().
getOriginalFilename
());
excelDataService
.
saveOrUpdate
(
excelData
);
}
else
if
(
StringUtils
.
equals
(
param
.
getType
(),
"2"
))
{
ExcelData
excelData
=
excelDataService
.
getOne
(
Wrappers
.
lambdaQuery
(
ExcelData
.
class
)
.
eq
(
ExcelData:
:
getTemplateId
,
param
.
getTemplateId
())
.
eq
(
ExcelData:
:
getType
,
"2"
),
false
);
if
(
ObjectUtils
.
isEmpty
(
excelData
))
{
excelData
=
new
ExcelData
();
excelData
.
setFile
(
param
.
getFile
().
getBytes
());
excelData
.
setFileName
(
param
.
getFile
().
getOriginalFilename
());
excelData
.
setType
(
"2"
);
excelData
.
setTemplateId
(
param
.
getTemplateId
());
excelData
.
setYear
(
param
.
getYear
());
excelData
.
setOrgName
(
param
.
getOrgName
());
excelDataService
.
save
(
excelData
);
}
else
{
excelData
.
setFile
(
param
.
getFile
().
getBytes
());
excelData
.
setFileName
(
param
.
getFile
().
getOriginalFilename
());
excelDataService
.
updateById
(
excelData
);
}
}
return
AjaxResult
.
success
();
}
}
admin-api/src/main/java/com/tbyf/his/web/dataImport/entity/Data
Import
Template.java
→
admin-api/src/main/java/com/tbyf/his/web/dataImport/entity/DataTemplate.java
View file @
619cf8e1
...
...
@@ -26,9 +26,9 @@ import java.util.stream.Stream;
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@Accessors
(
chain
=
true
)
@TableName
(
value
=
"data_
import_
template"
,
autoResultMap
=
true
)
@TableName
(
value
=
"data_template"
,
autoResultMap
=
true
)
@ApiModel
(
value
=
"数据导入模板表"
,
description
=
"数据导入模板表"
)
public
class
Data
Import
Template
extends
BaseMp
implements
Serializable
{
public
class
DataTemplate
extends
BaseMp
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"模板ID"
)
...
...
admin-api/src/main/java/com/tbyf/his/web/dataImport/entity/MetaField.java
0 → 100644
View file @
619cf8e1
package
com
.
tbyf
.
his
.
web
.
dataImport
.
entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
/**
* 原字段跟模板字段绑定结合,使字段信息公用
*
* @author lzz
* @date 2023/1/10 15:36
*/
@Data
@Accessors
(
chain
=
true
)
@TableName
(
value
=
"meta_data"
,
autoResultMap
=
true
)
@ApiModel
(
value
=
"元字段信息"
,
description
=
"元字段信息"
)
public
class
MetaField
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"字段元ID"
)
@TableId
(
value
=
"id"
,
type
=
IdType
.
ASSIGN_ID
)
private
String
id
;
@ApiModelProperty
(
value
=
"字段名 ORG_CODE"
)
@TableField
(
"field_name"
)
private
String
fieldName
;
@ApiModelProperty
(
value
=
"字段类型 VARCHAR(32) NUMBER"
)
@TableField
(
"field_type"
)
private
String
fieldType
;
@ApiModelProperty
(
value
=
"字段注释/指标名称"
)
@TableField
(
"field_comment"
)
private
String
fieldComment
;
@ApiModelProperty
(
value
=
"备注"
)
@TableField
(
"remarks"
)
private
String
remarks
;
}
admin-api/src/main/java/com/tbyf/his/web/dataImport/mapper/Data
Import
TemplateMapper.java
→
admin-api/src/main/java/com/tbyf/his/web/dataImport/mapper/DataTemplateMapper.java
View file @
619cf8e1
...
...
@@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import
com.tbyf.his.web.dataImport.domain.param.QueryTemplateParam
;
import
com.tbyf.his.web.dataImport.domain.vo.TemplateVO
;
import
com.tbyf.his.web.dataImport.domain.vo.VerifyVO
;
import
com.tbyf.his.web.dataImport.entity.DataImportTemplate
;
import
com.tbyf.his.web.dataImport.entity.DataRule
;
import
com.tbyf.his.web.dataImport.entity.DataTemplate
;
import
java.util.List
;
...
...
@@ -14,7 +14,7 @@ import java.util.List;
* @date 2023/2/7 11:22
*/
public
interface
Data
ImportTemplateMapper
extends
BaseMapper
<
DataImport
Template
>
{
public
interface
Data
TemplateMapper
extends
BaseMapper
<
Data
Template
>
{
/**
* 查询模板数据
...
...
admin-api/src/main/java/com/tbyf/his/web/dataImport/service/DataSourceService.java
0 → 100644
View file @
619cf8e1
package
com
.
tbyf
.
his
.
web
.
dataImport
.
service
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.tbyf.his.common.utils.spring.SpringUtils
;
import
com.tbyf.his.framework.datasource.DynamicDataSource
;
import
com.tbyf.his.framework.datasource.DynamicDataSourceContextHolder
;
import
com.tbyf.his.framework.utils.AesUtils
;
import
com.tbyf.his.system.domain.SysDatasource
;
import
com.tbyf.his.system.service.ISysDatasourceService
;
import
java.util.List
;
import
java.util.Map
;
import
static
com
.
tbyf
.
his
.
framework
.
datasource
.
DataSourceUtil
.
getDataSource
;
/**
* @author lzz
* @date 2023/2/16 16:05
*/
public
interface
DataSourceService
{
static
void
switchDb
(
String
dsName
)
{
if
(!
DynamicDataSourceContextHolder
.
dataSourcesMap
.
containsKey
(
dsName
))
{
final
SysDatasource
datasource
=
SpringUtils
.
getBean
(
ISysDatasourceService
.
class
).
selectSysDatasourceByDsName
(
dsName
);
String
password
;
try
{
password
=
AesUtils
.
decrypt
(
datasource
.
getPassword
());
}
catch
(
Exception
e
)
{
password
=
datasource
.
getPassword
();
}
DruidDataSource
druidDataSource
=
getDataSource
(
datasource
.
getUrl
(),
datasource
.
getDatasourceName
(),
datasource
.
getUsername
(),
password
);
DynamicDataSourceContextHolder
.
dataSourcesMap
.
put
(
dsName
,
druidDataSource
);
DynamicDataSource
dynamicDataSource
=
SpringUtils
.
getBean
(
"dynamicDataSource"
);
dynamicDataSource
.
afterPropertiesSet
();
}
DynamicDataSourceContextHolder
.
setDataSourceType
(
dsName
);
}
static
void
switchDefault
()
{
DynamicDataSourceContextHolder
.
clearDataSourceType
();
}
/**
* 执行单条查询sql返回
*
* @param dsName
* @param sql
* @return
*/
List
<
Map
<
String
,
Object
>>
executeList
(
String
dsName
,
String
sql
);
}
admin-api/src/main/java/com/tbyf/his/web/dataImport/service/Data
Import
TemplateService.java
→
admin-api/src/main/java/com/tbyf/his/web/dataImport/service/DataTemplateService.java
View file @
619cf8e1
...
...
@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import
com.tbyf.his.web.dataImport.domain.param.QueryTemplateParam
;
import
com.tbyf.his.web.dataImport.domain.vo.TemplateVO
;
import
com.tbyf.his.web.dataImport.domain.vo.VerifyVO
;
import
com.tbyf.his.web.dataImport.entity.DataImportTemplate
;
import
com.tbyf.his.web.dataImport.entity.DataRule
;
import
com.tbyf.his.web.dataImport.entity.DataTemplate
;
import
java.util.List
;
...
...
@@ -15,7 +15,7 @@ import java.util.List;
* @date 2023/2/7 11:23
*/
public
interface
Data
ImportTemplateService
extends
IService
<
DataImport
Template
>
{
public
interface
Data
TemplateService
extends
IService
<
Data
Template
>
{
/**
* 查询模板信息
...
...
admin-api/src/main/java/com/tbyf/his/web/dataImport/service/impl/DataSourceServiceImpl.java
0 → 100644
View file @
619cf8e1
package
com
.
tbyf
.
his
.
web
.
dataImport
.
service
.
impl
;
import
com.tbyf.his.web.dataImport.service.DataSourceService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author lzz
* @date 2023/2/16 16:05
*/
@Slf4j
@Service
public
class
DataSourceServiceImpl
implements
DataSourceService
{
@Resource
public
JdbcTemplate
jdbcTemplate
;
@Override
public
List
<
Map
<
String
,
Object
>>
executeList
(
String
dsName
,
String
sql
)
{
try
{
DataSourceService
.
switchDb
(
dsName
);
return
jdbcTemplate
.
queryForList
(
sql
);
}
finally
{
DataSourceService
.
switchDefault
();
}
}
}
admin-api/src/main/java/com/tbyf/his/web/dataImport/service/impl/Data
Import
TemplateServiceImpl.java
→
admin-api/src/main/java/com/tbyf/his/web/dataImport/service/impl/DataTemplateServiceImpl.java
View file @
619cf8e1
...
...
@@ -8,10 +8,10 @@ import com.tbyf.his.common.utils.StringUtils;
import
com.tbyf.his.web.dataImport.domain.param.QueryTemplateParam
;
import
com.tbyf.his.web.dataImport.domain.vo.TemplateVO
;
import
com.tbyf.his.web.dataImport.domain.vo.VerifyVO
;
import
com.tbyf.his.web.dataImport.entity.DataImportTemplate
;
import
com.tbyf.his.web.dataImport.entity.DataRule
;
import
com.tbyf.his.web.dataImport.mapper.DataImportTemplateMapper
;
import
com.tbyf.his.web.dataImport.service.DataImportTemplateService
;
import
com.tbyf.his.web.dataImport.entity.DataTemplate
;
import
com.tbyf.his.web.dataImport.mapper.DataTemplateMapper
;
import
com.tbyf.his.web.dataImport.service.DataTemplateService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -25,19 +25,19 @@ import java.util.List;
@Slf4j
@Service
@DataSource
(
DataSourceType
.
MASTER
)
public
class
Data
ImportTemplateServiceImpl
extends
ServiceImpl
<
DataImportTemplateMapper
,
DataImportTemplate
>
implements
DataImport
TemplateService
{
public
class
Data
TemplateServiceImpl
extends
ServiceImpl
<
DataTemplateMapper
,
DataTemplate
>
implements
Data
TemplateService
{
@Autowired
private
Data
ImportTemplateMapper
dataImport
TemplateMapper
;
private
Data
TemplateMapper
data
TemplateMapper
;
@Override
public
List
<
TemplateVO
>
queryTemplate
(
QueryTemplateParam
param
)
{
return
data
Import
TemplateMapper
.
queryTemplate
(
param
);
return
dataTemplateMapper
.
queryTemplate
(
param
);
}
@Override
public
DbType
getDbType
(
String
dataSourceId
)
{
final
String
dbType
=
data
Import
TemplateMapper
.
queryDbType
(
dataSourceId
);
final
String
dbType
=
dataTemplateMapper
.
queryDbType
(
dataSourceId
);
if
(
StringUtils
.
isBlank
(
dbType
))
{
return
DbType
.
MYSQL
;
}
...
...
@@ -50,11 +50,11 @@ public class DataImportTemplateServiceImpl extends ServiceImpl<DataImportTemplat
@Override
public
List
<
VerifyVO
>
getVerify
(
String
id
)
{
return
data
Import
TemplateMapper
.
getVerify
(
id
);
return
dataTemplateMapper
.
getVerify
(
id
);
}
@Override
public
List
<
DataRule
>
getAllRule
(
String
templateId
)
{
return
data
Import
TemplateMapper
.
getAllRule
(
templateId
);
return
dataTemplateMapper
.
getAllRule
(
templateId
);
}
}
admin-api/src/main/java/com/tbyf/his/web/dataImport/service/impl/ExcelDataServiceImpl.java
View file @
619cf8e1
...
...
@@ -13,11 +13,11 @@ import com.tbyf.his.web.dataImport.core.RuleVO;
import
com.tbyf.his.web.dataImport.core.RuleValidator
;
import
com.tbyf.his.web.dataImport.domain.vo.ExcelVO
;
import
com.tbyf.his.web.dataImport.domain.vo.VerifyVO
;
import
com.tbyf.his.web.dataImport.entity.DataImportTemplate
;
import
com.tbyf.his.web.dataImport.entity.DataRule
;
import
com.tbyf.his.web.dataImport.entity.DataTemplate
;
import
com.tbyf.his.web.dataImport.entity.ExcelData
;
import
com.tbyf.his.web.dataImport.mapper.ExcelDataMapper
;
import
com.tbyf.his.web.dataImport.service.Data
Import
TemplateService
;
import
com.tbyf.his.web.dataImport.service.DataTemplateService
;
import
com.tbyf.his.web.dataImport.service.ExcelDataService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.ss.usermodel.*
;
...
...
@@ -48,7 +48,7 @@ import java.util.stream.Collectors;
public
class
ExcelDataServiceImpl
extends
ServiceImpl
<
ExcelDataMapper
,
ExcelData
>
implements
ExcelDataService
{
@Autowired
private
Data
ImportTemplateService
dataImport
TemplateService
;
private
Data
TemplateService
data
TemplateService
;
@Autowired
private
JdbcTemplate
jdbcTemplate
;
...
...
@@ -56,8 +56,8 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
@Override
public
void
analyzeExport
(
ExcelData
excelData
,
HttpServletResponse
response
)
{
final
Data
ImportTemplate
template
=
dataImport
TemplateService
.
getById
(
excelData
.
getTemplateId
());
List
<
VerifyVO
>
verifyList
=
data
Import
TemplateService
.
getVerify
(
template
.
getId
());
final
Data
Template
template
=
data
TemplateService
.
getById
(
excelData
.
getTemplateId
());
List
<
VerifyVO
>
verifyList
=
dataTemplateService
.
getVerify
(
template
.
getId
());
try
(
InputStream
is
=
new
ByteArrayInputStream
(
excelData
.
getFile
());
Workbook
workbook
=
WorkbookFactory
.
create
(
is
))
{
final
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
//final int rows = sheet.getLastRowNum() + 1;
...
...
@@ -145,7 +145,7 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
}
});
// 模板规则的数据校验
final
List
<
DataRule
>
allRule
=
data
Import
TemplateService
.
getAllRule
(
template
.
getId
());
final
List
<
DataRule
>
allRule
=
dataTemplateService
.
getAllRule
(
template
.
getId
());
for
(
DataRule
rule
:
allRule
)
{
if
(
StringUtils
.
isNotBlank
(
rule
.
getContent
()))
{
if
(
StringUtils
.
equals
(
rule
.
getMode
(),
"逻辑相加"
))
{
...
...
admin-api/src/main/resources/mapper/Data
Import
TemplateMapper.xml
→
admin-api/src/main/resources/mapper/DataTemplateMapper.xml
View file @
619cf8e1
...
...
@@ -2,7 +2,7 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.tbyf.his.web.dataImport.mapper.Data
Import
TemplateMapper"
>
<mapper
namespace=
"com.tbyf.his.web.dataImport.mapper.DataTemplateMapper"
>
<select
id=
"queryTemplate"
resultType=
"com.tbyf.his.web.dataImport.domain.vo.TemplateVO"
>
SELECT id,
name,
...
...
@@ -18,10 +18,10 @@
remarks,
(select id
from excel_data
where template_id = data_
import_
template.id
where template_id = data_template.id
and type = '2'
limit 1) as excelId
FROM data_
import_
template
FROM data_template
<where>
<if
test=
"year != null and year != ''"
>
year = #{year}
...
...
admin-service/src/main/java/com/tbyf/his/system/mapper/SysDatasourceMapper.java
View file @
619cf8e1
package
com
.
tbyf
.
his
.
system
.
mapper
;
import
com.tbyf.his.common.core.domain.model.MyKeyValue
;
import
com.tbyf.his.system.domain.SysDatasource
;
;
import
com.tbyf.his.system.domain.SysDatasource
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.Map
;
;
/**
* 数据源配置Mapper接口
*
...
...
@@ -78,4 +80,6 @@ public interface SysDatasourceMapper {
@Param
(
value
=
"keyName"
)
String
keyName
,
@Param
(
value
=
"keyValue"
)
Long
keyValue
);
SysDatasource
selectSysDatasourceByDsName
(
String
dsName
);
}
admin-service/src/main/java/com/tbyf/his/system/service/ISysDatasourceService.java
View file @
619cf8e1
...
...
@@ -25,6 +25,8 @@ public interface ISysDatasourceService {
*/
public
SysDatasource
selectSysDatasourceByDatasourceId
(
Long
datasourceId
);
SysDatasource
selectSysDatasourceByDsName
(
String
dsName
);
/**
* 查询数据源配置列表
*
...
...
admin-service/src/main/java/com/tbyf/his/system/service/impl/SysDatasourceServiceImpl.java
View file @
619cf8e1
...
...
@@ -60,6 +60,11 @@ public class SysDatasourceServiceImpl implements ISysDatasourceService {
return
sysDatasourceMapper
.
selectSysDatasourceByDatasourceId
(
datasourceId
);
}
@Override
public
SysDatasource
selectSysDatasourceByDsName
(
String
dsName
)
{
return
sysDatasourceMapper
.
selectSysDatasourceByDsName
(
dsName
);
}
/**
* 查询数据源配置列表
*
...
...
admin-service/src/main/resources/mapper/system/SysDatasourceMapper.xml
View file @
619cf8e1
...
...
@@ -47,7 +47,9 @@
</select>
<select
id=
"selectSysDatasource"
resultMap=
"MyKeyValueResult"
>
select datasource_id, datasource_name from sys_datasource where adapter_flag = '0'
select datasource_id, datasource_name
from sys_datasource
where adapter_flag = '0'
</select>
<select
id=
"selectSysDatasourceByDatasourceId"
parameterType=
"Long"
resultMap=
"SysDatasourceResult"
>
...
...
@@ -55,6 +57,11 @@
where datasource_id = #{datasourceId}
</select>
<select
id=
"selectSysDatasourceByDsName"
resultMap=
"SysDatasourceResult"
>
<include
refid=
"selectSysDatasourceVo"
/>
where datasource_name = #{dsName}
</select>
<select
id=
"executeSql"
resultType=
"java.util.Map"
>
${sqlStr}
</select>
...
...
scripts/dataImport.sql
View file @
619cf8e1
...
...
@@ -65,3 +65,11 @@ create table excel_data
org_name
varchar
(
64
)
null
comment
'机构类型'
)
comment
'excel存储表'
;
create
table
meta_field
(
id
varchar
(
32
)
not
null
primary
key
,
field_name
varchar
(
64
)
null
comment
'字段名'
,
field_type
varchar
(
64
)
null
comment
'字段类型'
,
field_comment
varchar
(
64
)
null
comment
'字段注释'
,
remarks
varchar
(
256
)
null
comment
'备注'
)
comment
'元字段信息表'
;
\ No newline at end of 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