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
5d612191
Commit
5d612191
authored
Sep 26, 2023
by
liuzz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
机构查看添加了所属区县字段
模板字段数据类型同步功能bug修复 数据导入添加了数据库字段类型异常判断
parent
c24a569e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
108 additions
and
59 deletions
+108
-59
DataTemplateController.java
...his/web/controller/dataImport/DataTemplateController.java
+0
-10
ExcelDataController.java
...yf/his/web/controller/dataImport/ExcelDataController.java
+15
-5
AreaDict.java
.../java/com/tbyf/his/web/dataImport/domain/vo/AreaDict.java
+4
-0
VerifyVO.java
.../java/com/tbyf/his/web/dataImport/domain/vo/VerifyVO.java
+5
-2
DataTemplateServiceImpl.java
.../web/dataImport/service/impl/DataTemplateServiceImpl.java
+9
-6
ExcelDataServiceImpl.java
...his/web/dataImport/service/impl/ExcelDataServiceImpl.java
+75
-36
No files found.
admin-api/src/main/java/com/tbyf/his/web/controller/dataImport/DataTemplateController.java
View file @
5d612191
...
@@ -4,11 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
...
@@ -4,11 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.tbyf.his.common.annotation.IgnoreWebSecurity
;
import
com.tbyf.his.common.annotation.IgnoreWebSecurity
;
import
com.tbyf.his.common.core.domain.AjaxResult
;
import
com.tbyf.his.common.core.domain.AjaxResult
;
import
com.tbyf.his.common.core.text.StrFormatter
;
import
com.tbyf.his.common.enums.DataSourceType
;
import
com.tbyf.his.common.utils.StringUtils
;
import
com.tbyf.his.common.utils.StringUtils
;
import
com.tbyf.his.common.utils.bean.BeanUtils
;
import
com.tbyf.his.common.utils.bean.BeanUtils
;
import
com.tbyf.his.framework.datasource.DataSourceUtil
;
import
com.tbyf.his.web.dataImport.domain.param.*
;
import
com.tbyf.his.web.dataImport.domain.param.*
;
import
com.tbyf.his.web.dataImport.domain.vo.FieldErrorVo
;
import
com.tbyf.his.web.dataImport.domain.vo.FieldErrorVo
;
import
com.tbyf.his.web.dataImport.entity.*
;
import
com.tbyf.his.web.dataImport.entity.*
;
...
@@ -18,8 +15,6 @@ import io.swagger.annotations.Api;
...
@@ -18,8 +15,6 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -85,14 +80,9 @@ public class DataTemplateController {
...
@@ -85,14 +80,9 @@ public class DataTemplateController {
@PostMapping
(
"/syncFieldError"
)
@PostMapping
(
"/syncFieldError"
)
@ApiOperation
(
"物理表异常字段同步"
)
@ApiOperation
(
"物理表异常字段同步"
)
public
AjaxResult
syncFieldError
(
@RequestBody
List
<
FieldErrorVo
>
fieldErrorVos
)
{
public
AjaxResult
syncFieldError
(
@RequestBody
List
<
FieldErrorVo
>
fieldErrorVos
)
{
try
{
DataSourceUtil
.
switchDs
(
DataSourceType
.
SLAVE
.
name
());
fieldErrorVos
.
forEach
(
item
->
{
fieldErrorVos
.
forEach
(
item
->
{
dataTemplateService
.
syncFieldError
(
item
.
getFieldType
(),
item
.
getFieldName
(),
item
.
getTableName
());
dataTemplateService
.
syncFieldError
(
item
.
getFieldType
(),
item
.
getFieldName
(),
item
.
getTableName
());
});
});
}
finally
{
DataSourceUtil
.
switchDefaultDs
();
}
return
AjaxResult
.
success
();
return
AjaxResult
.
success
();
}
}
...
...
admin-api/src/main/java/com/tbyf/his/web/controller/dataImport/ExcelDataController.java
View file @
5d612191
...
@@ -12,9 +12,7 @@ import com.tbyf.his.web.dataImport.core.DiConfig;
...
@@ -12,9 +12,7 @@ import com.tbyf.his.web.dataImport.core.DiConfig;
import
com.tbyf.his.web.dataImport.domain.param.UploadExcelParam
;
import
com.tbyf.his.web.dataImport.domain.param.UploadExcelParam
;
import
com.tbyf.his.web.dataImport.domain.vo.AreaDict
;
import
com.tbyf.his.web.dataImport.domain.vo.AreaDict
;
import
com.tbyf.his.web.dataImport.domain.vo.VerifyVO
;
import
com.tbyf.his.web.dataImport.domain.vo.VerifyVO
;
import
com.tbyf.his.web.dataImport.entity.DataDict
;
import
com.tbyf.his.web.dataImport.entity.*
;
import
com.tbyf.his.web.dataImport.entity.DataTemplate
;
import
com.tbyf.his.web.dataImport.entity.ExcelData
;
import
com.tbyf.his.web.dataImport.service.*
;
import
com.tbyf.his.web.dataImport.service.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
...
@@ -60,6 +58,9 @@ public class ExcelDataController {
...
@@ -60,6 +58,9 @@ public class ExcelDataController {
@Autowired
@Autowired
private
DataDictService
dataDictService
;
private
DataDictService
dataDictService
;
@Autowired
private
MetaFieldService
metaFieldService
;
@IgnoreWebSecurity
@IgnoreWebSecurity
@GetMapping
(
"/download/template"
)
@GetMapping
(
"/download/template"
)
@ApiOperation
(
"模板下载"
)
@ApiOperation
(
"模板下载"
)
...
@@ -154,10 +155,19 @@ public class ExcelDataController {
...
@@ -154,10 +155,19 @@ public class ExcelDataController {
final
List
<
DataDict
>
areaList
=
dataDictService
.
list
(
Wrappers
.
lambdaQuery
(
DataDict
.
class
)
final
List
<
DataDict
>
areaList
=
dataDictService
.
list
(
Wrappers
.
lambdaQuery
(
DataDict
.
class
)
.
eq
(
DataDict:
:
getType
,
"area"
));
.
eq
(
DataDict:
:
getType
,
"area"
));
DataTemplate
template
=
dataTemplateService
.
getById
(
excelData
.
getTemplateId
());
DataTemplate
template
=
dataTemplateService
.
getById
(
excelData
.
getTemplateId
());
String
sql
=
"SELECT ROWCODE, '{}' AS ORG_TYPE,ORG_NAME,MAILING_ADDRESS,AREA_NUMBER_CODE FROM {} WHERE YEAROOFDATARECORD='{}年'"
;
String
sql
=
"SELECT ROWCODE, '{}' AS ORG_TYPE,ORG_NAME,MAILING_ADDRESS,AREA_NUMBER_CODE
,DWSSQX
FROM {} WHERE YEAROOFDATARECORD='{}年'"
;
if
(
StringUtils
.
equals
(
"中医类医院"
,
template
.
getOrgName
()))
{
if
(
StringUtils
.
equals
(
"中医类医院"
,
template
.
getOrgName
()))
{
sql
=
"SELECT ROWCODE, '{}' AS ORG_TYPE,ORG_NAME, ADDRESS_OF_ORG AS MAILING_ADDRESS,AREA_NUMBER_CODE FROM {} WHERE YEAROOFDATARECORD='{}年'"
;
sql
=
"SELECT ROWCODE, '{}' AS ORG_TYPE,ORG_NAME, ADDRESS_OF_ORG AS MAILING_ADDRESS,AREA_NUMBER_CODE,DWSSQX FROM {} WHERE YEAROOFDATARECORD='{}年'"
;
}
// 需要判断模板有没有字段DWSSQX
MetaField
dwssqx
=
metaFieldService
.
getOne
(
Wrappers
.
lambdaQuery
(
MetaField
.
class
).
eq
(
MetaField:
:
getFieldName
,
"DWSSQX"
),
false
);
if
(
dwssqx
!=
null
){
long
count
=
dataFieldService
.
count
(
Wrappers
.
lambdaQuery
(
DataField
.
class
).
eq
(
DataField:
:
getField
,
dwssqx
.
getId
()).
eq
(
DataField:
:
getTemplateId
,
template
.
getId
()));
if
(
count
==
0
){
sql
=
sql
.
replaceAll
(
",DWSSQX"
,
""
);
}
}
}
try
{
try
{
DataSourceService
.
switchDb
(
template
.
getDataSourceId
());
DataSourceService
.
switchDb
(
template
.
getDataSourceId
());
List
<
AreaDict
>
areaDictList
=
jdbcTemplate
.
query
(
List
<
AreaDict
>
areaDictList
=
jdbcTemplate
.
query
(
...
...
admin-api/src/main/java/com/tbyf/his/web/dataImport/domain/vo/AreaDict.java
View file @
5d612191
...
@@ -40,6 +40,10 @@ public class AreaDict implements Serializable {
...
@@ -40,6 +40,10 @@ public class AreaDict implements Serializable {
@JsonProperty
(
value
=
"AREA_NUMBER_CODE"
)
@JsonProperty
(
value
=
"AREA_NUMBER_CODE"
)
private
String
AREA_NUMBER_CODE
;
private
String
AREA_NUMBER_CODE
;
@ApiModelProperty
(
value
=
"所属区县"
)
@JsonProperty
(
value
=
"DWSSQX"
)
private
String
DWSSQX
;
/* @ApiModelProperty(value = "所属市")
/* @ApiModelProperty(value = "所属市")
@JsonProperty(value = "CITY")
@JsonProperty(value = "CITY")
private String CITY;
private String CITY;
...
...
admin-api/src/main/java/com/tbyf/his/web/dataImport/domain/vo/VerifyVO.java
View file @
5d612191
...
@@ -41,12 +41,15 @@ public class VerifyVO {
...
@@ -41,12 +41,15 @@ public class VerifyVO {
@ApiModelProperty
(
value
=
"元字段ID"
)
@ApiModelProperty
(
value
=
"元字段ID"
)
private
String
metaFieldId
;
private
String
metaFieldId
;
@ApiModelProperty
(
value
=
"
数据库
字段名"
)
@ApiModelProperty
(
value
=
"字段名"
)
private
String
fieldName
;
private
String
fieldName
;
@ApiModelProperty
(
value
=
"
数据库
字段类型"
)
@ApiModelProperty
(
value
=
"
元
字段类型"
)
private
String
fieldType
;
private
String
fieldType
;
@ApiModelProperty
(
value
=
"数据库字段类型"
)
private
String
columnType
;
@ApiModelProperty
(
value
=
"待校验的值列表"
)
@ApiModelProperty
(
value
=
"待校验的值列表"
)
private
List
<
String
>
values
;
private
List
<
String
>
values
;
...
...
admin-api/src/main/java/com/tbyf/his/web/dataImport/service/impl/DataTemplateServiceImpl.java
View file @
5d612191
package
com
.
tbyf
.
his
.
web
.
dataImport
.
service
.
impl
;
package
com
.
tbyf
.
his
.
web
.
dataImport
.
service
.
impl
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.tbyf.his.common.annotation.DataSource
;
import
com.tbyf.his.common.annotation.DataSource
;
...
@@ -19,7 +20,6 @@ import com.tbyf.his.web.dataImport.mapper.MetaFieldMapper;
...
@@ -19,7 +20,6 @@ import com.tbyf.his.web.dataImport.mapper.MetaFieldMapper;
import
com.tbyf.his.web.dataImport.service.DataTemplateService
;
import
com.tbyf.his.web.dataImport.service.DataTemplateService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -84,6 +84,7 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat
...
@@ -84,6 +84,7 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat
DataSourceUtil
.
switchDs
(
DataSourceType
.
SLAVE
.
name
());
DataSourceUtil
.
switchDs
(
DataSourceType
.
SLAVE
.
name
());
if
(
metaFieldMapper
.
selectTableCount
(
tableName
)
>
0
)
{
if
(
metaFieldMapper
.
selectTableCount
(
tableName
)
>
0
)
{
fieldErrorVos
.
forEach
(
item
->
{
fieldErrorVos
.
forEach
(
item
->
{
if
(
StrUtil
.
isAllNotBlank
(
item
.
getFieldType
(),
item
.
getFieldName
())){
String
fieldType
=
item
.
getFieldType
();
String
fieldType
=
item
.
getFieldType
();
String
columnType
;
String
columnType
;
if
(
fieldType
.
contains
(
"NUMBER"
))
{
if
(
fieldType
.
contains
(
"NUMBER"
))
{
...
@@ -97,6 +98,7 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat
...
@@ -97,6 +98,7 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat
BeanUtils
.
copyBeanProp
(
fieldErrorVo
,
item
);
BeanUtils
.
copyBeanProp
(
fieldErrorVo
,
item
);
resultList
.
add
(
fieldErrorVo
.
setColumnType
(
columnType
).
setTableName
(
tableName
));
resultList
.
add
(
fieldErrorVo
.
setColumnType
(
columnType
).
setTableName
(
tableName
));
}
}
}
});
});
}
}
}
finally
{
}
finally
{
...
@@ -105,14 +107,15 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat
...
@@ -105,14 +107,15 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat
return
CompletableFuture
.
completedFuture
(
resultList
);
return
CompletableFuture
.
completedFuture
(
resultList
);
}
}
@Async
public
void
syncFieldError
(
String
fieldType
,
String
fieldName
,
String
tableName
)
{
public
void
syncFieldError
(
String
fieldType
,
String
fieldName
,
String
tableName
)
{
String
sql
=
StrFormatter
.
format
(
alterSql
,
tableName
,
fieldName
,
fieldType
);
try
{
try
{
DataSourceUtil
.
switchDs
(
DataSourceType
.
SLAVE
.
name
());
String
sql
=
StrFormatter
.
format
(
alterSql
,
tableName
,
fieldName
,
fieldType
);
jdbcTemplate
.
execute
(
sql
);
jdbcTemplate
.
execute
(
sql
);
}
catch
(
DataAccessException
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"alter table's fieldType error"
);
log
.
error
(
"修改数据类型失败"
,
e
);
e
.
printStackTrace
();
}
finally
{
DataSourceUtil
.
switchDefaultDs
();
}
}
}
}
...
...
admin-api/src/main/java/com/tbyf/his/web/dataImport/service/impl/ExcelDataServiceImpl.java
View file @
5d612191
package
com
.
tbyf
.
his
.
web
.
dataImport
.
service
.
impl
;
package
com
.
tbyf
.
his
.
web
.
dataImport
.
service
.
impl
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
...
@@ -21,6 +22,7 @@ import com.tbyf.his.web.dataImport.entity.DataRule;
...
@@ -21,6 +22,7 @@ import com.tbyf.his.web.dataImport.entity.DataRule;
import
com.tbyf.his.web.dataImport.entity.DataTemplate
;
import
com.tbyf.his.web.dataImport.entity.DataTemplate
;
import
com.tbyf.his.web.dataImport.entity.ExcelData
;
import
com.tbyf.his.web.dataImport.entity.ExcelData
;
import
com.tbyf.his.web.dataImport.mapper.ExcelDataMapper
;
import
com.tbyf.his.web.dataImport.mapper.ExcelDataMapper
;
import
com.tbyf.his.web.dataImport.mapper.MetaFieldMapper
;
import
com.tbyf.his.web.dataImport.service.DataDictService
;
import
com.tbyf.his.web.dataImport.service.DataDictService
;
import
com.tbyf.his.web.dataImport.service.DataSourceService
;
import
com.tbyf.his.web.dataImport.service.DataSourceService
;
import
com.tbyf.his.web.dataImport.service.DataTemplateService
;
import
com.tbyf.his.web.dataImport.service.DataTemplateService
;
...
@@ -72,6 +74,9 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
...
@@ -72,6 +74,9 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
private
DataDictService
dataDictService
;
private
DataDictService
dataDictService
;
@Autowired
@Autowired
private
MetaFieldMapper
metaFieldMapper
;
@Autowired
@Qualifier
(
"threadPoolTaskExecutor"
)
@Qualifier
(
"threadPoolTaskExecutor"
)
private
Executor
executor
;
private
Executor
executor
;
...
@@ -477,6 +482,25 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
...
@@ -477,6 +482,25 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
final
DataTemplate
template
=
dataTemplateService
.
getById
(
excelData
.
getTemplateId
());
final
DataTemplate
template
=
dataTemplateService
.
getById
(
excelData
.
getTemplateId
());
// 获取元字段与所有校验对象
// 获取元字段与所有校验对象
List
<
VerifyVO
>
verifyList
=
dataTemplateService
.
getVerify
(
template
.
getId
());
List
<
VerifyVO
>
verifyList
=
dataTemplateService
.
getVerify
(
template
.
getId
());
try
{
DataSourceService
.
switchDb
(
template
.
getDataSourceId
());
verifyList
.
forEach
(
item
->{
// 查询数据库字段类型
if
(
StrUtil
.
isNotBlank
(
item
.
getFieldType
())){
String
columnType
;
if
(
StrUtil
.
containsIgnoreCase
(
item
.
getFieldType
(),
"NUMBER"
))
{
columnType
=
metaFieldMapper
.
selectNumberFieldType
(
template
.
getTableName
()+
"_TEMP"
,
item
.
getFieldName
());
}
else
{
columnType
=
metaFieldMapper
.
selectFieldType
(
template
.
getTableName
()+
"_TEMP"
,
item
.
getFieldName
());
}
if
(
StrUtil
.
isNotBlank
(
columnType
)){
item
.
setColumnType
(
columnType
);
}
}
});
}
catch
(
Exception
ignored
){}
finally
{
DataSourceService
.
switchDefault
();
}
try
(
InputStream
is
=
new
ByteArrayInputStream
(
excelData
.
getFile
());
Workbook
workbook
=
WorkbookFactory
.
create
(
is
))
{
try
(
InputStream
is
=
new
ByteArrayInputStream
(
excelData
.
getFile
());
Workbook
workbook
=
WorkbookFactory
.
create
(
is
))
{
final
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
final
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
final
Optional
<
VerifyVO
>
first
=
verifyList
.
stream
()
final
Optional
<
VerifyVO
>
first
=
verifyList
.
stream
()
...
@@ -496,61 +520,76 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
...
@@ -496,61 +520,76 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
}
}
vo
.
setCoordinate
(
s
);
vo
.
setCoordinate
(
s
);
}
}
int
a
=
0
;
// 整数位长度
// 整数长度 小数长度 字段长度
int
b
=
0
;
// 小数位长度
int
a
=
0
,
b
=
0
,
c
=
0
;
int
l
=
0
;
// 字段长度
int
x
=
0
,
y
=
0
,
z
=
0
;
if
(
StringUtils
.
containsIgnoreCase
(
vo
.
getFieldType
(),
"NUMBER"
))
{
if
(
StrUtil
.
containsIgnoreCase
(
vo
.
getFieldType
(),
"number"
)){
final
String
[]
numbers
=
vo
.
getFieldType
().
replaceAll
(
"NUMBER"
,
""
)
String
[]
split
=
StrUtil
.
replaceIgnoreCase
(
vo
.
getFieldType
(),
"number"
,
""
)
.
replaceAll
(
"number"
,
""
)
.
replaceAll
(
"\\("
,
""
)
.
replaceAll
(
"\\)"
,
""
)
.
split
(
","
);
b
=
Convert
.
toInt
(
split
[
1
]);
a
=
Convert
.
toInt
(
split
[
0
])
-
b
;
}
else
if
(
StringUtils
.
containsIgnoreCase
(
vo
.
getFieldType
(),
"char"
)){
c
=
Convert
.
toInt
(
StrUtil
.
replaceIgnoreCase
(
StrUtil
.
replaceIgnoreCase
(
vo
.
getFieldType
(),
"varchar2"
,
""
),
"varchar"
,
""
)
.
replaceAll
(
"\\("
,
""
)
.
replaceAll
(
"\\)"
,
""
));
}
if
(
StrUtil
.
containsIgnoreCase
(
vo
.
getColumnType
(),
"number"
)){
String
[]
split
=
StrUtil
.
replaceIgnoreCase
(
vo
.
getColumnType
(),
"number"
,
""
)
.
replaceAll
(
"\\("
,
""
)
.
replaceAll
(
"\\("
,
""
)
.
replaceAll
(
"\\)"
,
""
)
.
replaceAll
(
"\\)"
,
""
)
.
split
(
","
);
.
split
(
","
);
b
=
Integer
.
parseInt
(
numbers
[
1
]);
y
=
Convert
.
toInt
(
split
[
1
]);
a
=
Integer
.
parseInt
(
numbers
[
0
])
-
b
;
x
=
Convert
.
toInt
(
split
[
0
])
-
b
;
}
else
if
(
StringUtils
.
containsIgnoreCase
(
vo
.
getFieldType
(),
"VARCHAR"
))
{
}
else
if
(
StringUtils
.
containsIgnoreCase
(
vo
.
getColumnType
(),
"char"
)){
l
=
Integer
.
parseInt
(
vo
.
getFieldType
().
replaceAll
(
"VARCHAR2"
,
""
)
z
=
Convert
.
toInt
(
StrUtil
.
replaceIgnoreCase
(
.
replaceAll
(
"varchar2"
,
""
)
StrUtil
.
replaceIgnoreCase
(
vo
.
getColumnType
(),
"varchar2"
,
""
),
"varchar"
,
""
)
.
replaceAll
(
"VARCHAR"
,
""
)
.
replaceAll
(
"varchar"
,
""
)
.
replaceAll
(
"\\("
,
""
)
.
replaceAll
(
"\\("
,
""
)
.
replaceAll
(
"\\)"
,
""
));
.
replaceAll
(
"\\)"
,
""
));
}
}
final
String
[]
coords
=
vo
.
getCoordinate
().
split
(
","
);
final
String
[]
coords
=
vo
.
getCoordinate
().
split
(
","
);
// TODO 这里减1的原因是excel表名的行号1实际上的下标为0
// TODO 这里减1的原因是excel表名的行号1实际上的下标为0
int
rowStart
=
Integer
.
parseInt
(
coords
[
1
])
-
1
;
int
rowStart
=
Integer
.
parseInt
(
coords
[
1
])
-
1
;
final
Row
row
=
sheet
.
getRow
(
rowStart
);
final
Row
row
=
sheet
.
getRow
(
rowStart
);
for
(
Integer
column
:
columnList
)
{
for
(
Integer
column
:
columnList
)
{
final
Cell
cell
=
row
.
getCell
(
column
,
Row
.
MissingCellPolicy
.
RETURN_BLANK_AS_NULL
);
final
Cell
cell
=
row
.
getCell
(
column
,
Row
.
MissingCellPolicy
.
RETURN_BLANK_AS_NULL
);
final
String
cellValue
=
DiConfig
.
getValue
(
cell
);
String
cellValue
=
DiConfig
.
getValue
(
cell
);
if
(
StringUtils
.
containsIgnoreCase
(
vo
.
getFieldType
(),
"NUMBER"
))
{
if
(
StrUtil
.
containsIgnoreCase
(
vo
.
getFieldType
(),
"number"
)){
// i是整数位长度
// 如果是数字
int
i
=
cellValue
.
indexOf
(
"."
);
// 计算整数长度in 小数长度de
if
(
i
==
-
1
)
{
int
in
=
cellValue
.
indexOf
(
"."
);
i
=
cellValue
.
length
();
if
(
in
==
-
1
){
}
in
=
cellValue
.
length
();
int
k
=
cellValue
.
length
()
-
i
-
1
;
}
if
(
i
>
a
||
k
>
b
)
{
int
de
=
cellValue
.
length
()
==
in
?
0
:
cellValue
.
length
()
-
in
-
1
;
errorList
.
add
(
StrFormatter
.
format
(
"字段数据:[{}],字段类型:[{}],字段名称:[{}],数据位置:[{}],数据精度异常"
,
if
(
in
>
a
||
de
>
b
){
errorList
.
add
(
StrFormatter
.
format
(
"字段数据:[{}],字段类型:[{}],字段名称:[{}],数据位置:[{}],数据不符合元字段精度要求"
,
cellValue
,
vo
.
getFieldType
(),
vo
.
getFieldName
(),
new
CellReference
(
cell
.
getRowIndex
(),
cell
.
getColumnIndex
()).
formatAsString
()));
cellValue
,
vo
.
getFieldType
(),
vo
.
getFieldName
(),
new
CellReference
(
cell
.
getRowIndex
(),
cell
.
getColumnIndex
()).
formatAsString
()));
}
}
if
(
in
>
x
||
de
>
y
){
errorList
.
add
(
StrFormatter
.
format
(
"字段数据:[{}],字段类型:[{}],字段名称:[{}],数据位置:[{}],数据不符合数据库精度要求"
,
cellValue
,
vo
.
getColumnType
(),
vo
.
getFieldName
(),
new
CellReference
(
cell
.
getRowIndex
(),
cell
.
getColumnIndex
()).
formatAsString
()));
}
if
(
StringUtils
.
equals
(
""
,
cellValue
)
||
StringUtils
.
equals
(
"-"
,
cellValue
)){
if
(
StringUtils
.
equals
(
""
,
cellValue
)
||
StringUtils
.
equals
(
"-"
,
cellValue
)){
vo
.
addValue
(
"0"
);
cellValue
=
"0"
;
}
else
if
(
NumberUtils
.
isCreatable
(
cellValue
)){
}
else
if
(!
NumberUtils
.
isCreatable
(
cellValue
)){
vo
.
addValue
(
cellValue
);
errorList
.
add
(
StrFormatter
.
format
(
"字段数据:[{}],字段类型:[{}],字段名称:[{}],数据位置:[{}],不是合法的数字"
,
}
else
{
errorList
.
add
(
StrFormatter
.
format
(
"字段数据:[{}],字段类型:[{}],字段名称:[{}],数据位置:[{}],非数字"
,
cellValue
,
vo
.
getFieldType
(),
vo
.
getFieldName
(),
new
CellReference
(
cell
.
getRowIndex
(),
cell
.
getColumnIndex
()).
formatAsString
()));
cellValue
,
vo
.
getFieldType
(),
vo
.
getFieldName
(),
new
CellReference
(
cell
.
getRowIndex
(),
cell
.
getColumnIndex
()).
formatAsString
()));
vo
.
addValue
(
cellValue
);
}
}
}
else
if
(
StringUtils
.
containsIgnoreCase
(
vo
.
getFieldType
(),
"VARCHAR"
))
{
}
else
if
(
StrUtil
.
containsIgnoreCase
(
vo
.
getFieldType
(),
"char"
))
{
if
(
l
<
cellValue
.
length
()
*
3
)
{
if
(
c
<
cellValue
.
length
()
*
3
)
{
errorList
.
add
(
StrFormatter
.
format
(
"字段数据:[{}],字段类型:[{}],字段名称:[{}],数据位置:[{}],数据长度
不足
"
,
errorList
.
add
(
StrFormatter
.
format
(
"字段数据:[{}],字段类型:[{}],字段名称:[{}],数据位置:[{}],数据长度
超过元字段限制
"
,
cellValue
,
vo
.
getFieldType
(),
vo
.
getFieldName
(),
new
CellReference
(
cell
.
getRowIndex
(),
cell
.
getColumnIndex
()).
formatAsString
()));
cellValue
,
vo
.
getFieldType
(),
vo
.
getFieldName
(),
new
CellReference
(
cell
.
getRowIndex
(),
cell
.
getColumnIndex
()).
formatAsString
()));
}
}
vo
.
addValue
(
cellValue
);
if
(
z
<
cellValue
.
length
()
*
3
)
{
}
else
{
errorList
.
add
(
StrFormatter
.
format
(
"字段数据:[{}],字段类型:[{}],字段名称:[{}],数据位置:[{}],数据长度超过数据库字段限制"
,
vo
.
addValue
(
cellValue
);
cellValue
,
vo
.
getColumnType
(),
vo
.
getFieldName
(),
new
CellReference
(
cell
.
getRowIndex
(),
cell
.
getColumnIndex
()).
formatAsString
()));
}
}
}
vo
.
addValue
(
cellValue
);
}
}
}
}
log
.
info
(
"解析Excel数据用时:[{}]"
,
System
.
currentTimeMillis
()
-
startTime
);
log
.
info
(
"解析Excel数据用时:[{}]"
,
System
.
currentTimeMillis
()
-
startTime
);
...
@@ -596,7 +635,7 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
...
@@ -596,7 +635,7 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
log
.
info
(
"导入数据用时:[{}]"
,
System
.
currentTimeMillis
()
-
startTime
);
log
.
info
(
"导入数据用时:[{}]"
,
System
.
currentTimeMillis
()
-
startTime
);
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
log
.
error
(
"数据导入错误"
,
e
);
log
.
error
(
"数据导入错误"
,
e
);
throw
new
BaseException
(
e
.
get
Cause
().
get
Message
());
throw
new
BaseException
(
e
.
getMessage
());
}
finally
{
}
finally
{
DataSourceService
.
switchDefault
();
DataSourceService
.
switchDefault
();
}
}
...
...
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