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
30ada97d
Commit
30ada97d
authored
Feb 10, 2023
by
刘泽志
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
动态解析模板
parent
c8e10b26
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
186 additions
and
2 deletions
+186
-2
DataImportController.java
...f/his/web/controller/dataImport/DataImportController.java
+66
-2
DiConfig.java
.../main/java/com/tbyf/his/web/dataImport/core/DiConfig.java
+85
-0
DataField.java
...in/java/com/tbyf/his/web/dataImport/entity/DataField.java
+30
-0
application.yml
admin-api/src/main/resources/application.yml
+0
-0
pom.xml
admin-service/pom.xml
+5
-0
No files found.
admin-api/src/main/java/com/tbyf/his/web/controller/dataImport/DataImportController.java
View file @
30ada97d
...
...
@@ -26,6 +26,10 @@ 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
;
...
...
@@ -34,6 +38,10 @@ import org.springframework.util.ObjectUtils;
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.Collections
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -110,8 +118,19 @@ public class DataImportController {
@ApiOperation
(
"删除模板"
)
public
AjaxResult
deleteTemplate
(
@RequestParam
String
templateId
)
{
dataImportService
.
removeById
(
templateId
);
//TODO 需要删除字段以及其字段关联的规则与其它数据
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
();
}
...
...
@@ -260,7 +279,7 @@ public class DataImportController {
@ApiOperation
(
"删除字段"
)
public
AjaxResult
deleteField
(
@RequestParam
String
fieldId
)
{
dataFieldService
.
removeById
(
fieldId
);
//TODO 需要删除其字段关联的规则与其它数据
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
eq
(
BindRule:
:
getDataId
,
fieldId
));
return
AjaxResult
.
success
();
}
...
...
@@ -312,6 +331,7 @@ public class DataImportController {
@ApiOperation
(
"删除规则"
)
public
AjaxResult
deleteRule
(
@RequestParam
String
ruleId
)
{
dataRuleService
.
removeById
(
ruleId
);
bindRuleService
.
remove
(
Wrappers
.
lambdaQuery
(
BindRule
.
class
).
eq
(
BindRule:
:
getRuleId
,
ruleId
));
return
AjaxResult
.
success
();
}
...
...
@@ -413,5 +433,49 @@ public class DataImportController {
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
));
String
title
=
DiConfig
.
getValue
(
row
.
getCell
(
2
));
String
unit
=
DiConfig
.
getValue
(
row
.
getCell
(
4
));
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
);
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/dataImport/core/DiConfig.java
View file @
30ada97d
package
com
.
tbyf
.
his
.
web
.
dataImport
.
core
;
import
com.tbyf.his.common.utils.StringUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.CellType
;
import
org.apache.poi.ss.usermodel.DateUtil
;
import
org.apache.poi.ss.usermodel.FormulaEvaluator
;
import
org.apache.poi.ss.util.NumberToTextConverter
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
javax.annotation.PostConstruct
;
import
java.text.SimpleDateFormat
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -13,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @date 2023/2/9 9:22
*/
@Configuration
@Slf4j
public
class
DiConfig
{
@Autowired
...
...
@@ -20,6 +32,10 @@ public class DiConfig {
public
static
final
Map
<
String
,
RuleValidator
>
VALIDATOR_MAP
=
new
ConcurrentHashMap
<>(
8
);
public
static
final
List
<
String
>
WORD
=
Arrays
.
asList
(
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
,
"K"
,
"L"
,
"M"
,
"N"
,
"O"
,
"P"
,
"Q"
,
"R"
,
"S"
,
"T"
,
"U"
,
"V"
,
"W"
,
"X"
,
"Y"
,
"Z"
);
@PostConstruct
public
void
init
()
{
final
Map
<
String
,
RuleValidator
>
validatorMap
=
applicationContext
.
getBeansOfType
(
RuleValidator
.
class
);
...
...
@@ -36,4 +52,73 @@ public class DiConfig {
return
VALIDATOR_MAP
.
get
(
DiConstants
.
SERVICE_PREFIX
+
mode
);
}
public
static
int
getIndex
(
String
word
)
{
for
(
int
i
=
0
;
i
<
WORD
.
size
();
i
++)
{
if
(
StringUtils
.
equals
(
word
,
WORD
.
get
(
i
)))
{
return
i
;
}
}
return
-
1
;
}
public
static
String
getWord
(
int
index
)
{
return
WORD
.
get
(
index
);
}
/**
* 获取单元格的值
*
* @param cell
* @return
*/
public
static
String
getValue
(
Cell
cell
)
{
if
(
cell
==
null
||
""
.
equals
(
cell
.
toString
().
trim
()))
{
return
""
;
}
String
cellString
=
""
;
final
CellType
type
=
cell
.
getCellType
();
switch
(
type
)
{
case
STRING:
cellString
=
trim
(
cell
.
getRichStringCellValue
().
getString
());
break
;
case
BOOLEAN:
cellString
=
String
.
valueOf
(
cell
.
getBooleanCellValue
());
break
;
case
FORMULA:
final
FormulaEvaluator
evaluator
=
cell
.
getSheet
().
getWorkbook
().
getCreationHelper
().
createFormulaEvaluator
();
cellString
=
evaluator
.
evaluate
(
cell
).
getStringValue
().
trim
();
break
;
case
NUMERIC:
final
short
format
=
cell
.
getCellStyle
().
getDataFormat
();
if
(
DateUtil
.
isCellDateFormatted
(
cell
))
{
// 日期格式
SimpleDateFormat
sdf
=
null
;
if
(
format
==
20
||
format
==
32
)
{
sdf
=
new
SimpleDateFormat
(
"HH:mm"
);
cellString
=
sdf
.
format
(
cell
.
getDateCellValue
());
}
else
if
(
format
==
14
||
format
==
31
||
format
==
57
||
format
==
58
)
{
// 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58)
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
double
value
=
cell
.
getNumericCellValue
();
Date
date
=
org
.
apache
.
poi
.
ss
.
usermodel
.
DateUtil
.
getJavaDate
(
value
);
cellString
=
sdf
.
format
(
date
);
}
else
{
// 日期
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
cellString
=
sdf
.
format
(
cell
.
getDateCellValue
());
}
}
else
{
cellString
=
NumberToTextConverter
.
toText
(
cell
.
getNumericCellValue
());
}
break
;
default
:
break
;
}
return
cellString
;
}
public
static
String
trim
(
String
text
)
{
return
text
.
replaceAll
(
"(\\u00A0+| )"
,
""
).
trim
();
}
}
admin-api/src/main/java/com/tbyf/his/web/dataImport/entity/DataField.java
View file @
30ada97d
...
...
@@ -4,10 +4,17 @@ 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
com.tbyf.his.common.utils.StringUtils
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.SneakyThrows
;
import
lombok.experimental.Accessors
;
import
net.sourceforge.pinyin4j.PinyinHelper
;
import
net.sourceforge.pinyin4j.format.HanyuPinyinCaseType
;
import
net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat
;
import
net.sourceforge.pinyin4j.format.HanyuPinyinToneType
;
import
net.sourceforge.pinyin4j.format.HanyuPinyinVCharType
;
import
java.io.Serializable
;
...
...
@@ -55,4 +62,27 @@ public class DataField implements Serializable {
@TableField
(
"field"
)
private
String
field
;
@SneakyThrows
public
void
createField
()
{
if
(
StringUtils
.
equals
(
title
,
"统一社会信用代码"
))
{
field
=
"UNIFIED_CODE"
;
}
else
if
(
StringUtils
.
equals
(
title
,
"组织机构代码"
))
{
field
=
"ORG_CODE"
;
}
else
if
(
StringUtils
.
equals
(
title
,
"机构名称"
))
{
field
=
"ORG_NAME"
;
}
else
{
final
HanyuPinyinOutputFormat
format
=
new
HanyuPinyinOutputFormat
();
format
.
setCaseType
(
HanyuPinyinCaseType
.
UPPERCASE
);
format
.
setVCharType
(
HanyuPinyinVCharType
.
WITH_V
);
format
.
setToneType
(
HanyuPinyinToneType
.
WITHOUT_TONE
);
for
(
int
i
=
0
;
i
<
title
.
length
();
i
++)
{
final
String
[]
array
=
PinyinHelper
.
toHanyuPinyinStringArray
(
title
.
charAt
(
i
),
format
);
if
(
array
!=
null
&&
array
.
length
>
0
)
{
field
=
array
[
0
].
charAt
(
0
)
+
""
+
sort
;
break
;
}
}
}
}
}
admin-api/src/main/resources/application.yml
View file @
30ada97d
admin-service/pom.xml
View file @
30ada97d
...
...
@@ -47,6 +47,11 @@
<artifactId>
mybatis-plus-extension
</artifactId>
<version>
3.5.0
</version>
</dependency>
<dependency>
<groupId>
com.belerweb
</groupId>
<artifactId>
pinyin4j
</artifactId>
<version>
2.5.0
</version>
</dependency>
</dependencies>
</project>
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