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
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
38 deletions
+48
-38
DataTemplateController.java
...his/web/controller/dataImport/DataTemplateController.java
+3
-13
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
+21
-18
ExcelDataServiceImpl.java
...his/web/dataImport/service/impl/ExcelDataServiceImpl.java
+0
-0
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;
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.core.text.StrFormatter
;
import
com.tbyf.his.common.enums.DataSourceType
;
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.web.dataImport.domain.param.*
;
import
com.tbyf.his.web.dataImport.domain.vo.FieldErrorVo
;
import
com.tbyf.his.web.dataImport.entity.*
;
...
...
@@ -18,8 +15,6 @@ 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.dao.DataAccessException
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
...
...
@@ -85,14 +80,9 @@ public class DataTemplateController {
@PostMapping
(
"/syncFieldError"
)
@ApiOperation
(
"物理表异常字段同步"
)
public
AjaxResult
syncFieldError
(
@RequestBody
List
<
FieldErrorVo
>
fieldErrorVos
)
{
try
{
DataSourceUtil
.
switchDs
(
DataSourceType
.
SLAVE
.
name
());
fieldErrorVos
.
forEach
(
item
->
{
dataTemplateService
.
syncFieldError
(
item
.
getFieldType
(),
item
.
getFieldName
(),
item
.
getTableName
());
});
}
finally
{
DataSourceUtil
.
switchDefaultDs
();
}
fieldErrorVos
.
forEach
(
item
->
{
dataTemplateService
.
syncFieldError
(
item
.
getFieldType
(),
item
.
getFieldName
(),
item
.
getTableName
());
});
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;
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.VerifyVO
;
import
com.tbyf.his.web.dataImport.entity.DataDict
;
import
com.tbyf.his.web.dataImport.entity.DataTemplate
;
import
com.tbyf.his.web.dataImport.entity.ExcelData
;
import
com.tbyf.his.web.dataImport.entity.*
;
import
com.tbyf.his.web.dataImport.service.*
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
...
...
@@ -60,6 +58,9 @@ public class ExcelDataController {
@Autowired
private
DataDictService
dataDictService
;
@Autowired
private
MetaFieldService
metaFieldService
;
@IgnoreWebSecurity
@GetMapping
(
"/download/template"
)
@ApiOperation
(
"模板下载"
)
...
...
@@ -154,10 +155,19 @@ public class ExcelDataController {
final
List
<
DataDict
>
areaList
=
dataDictService
.
list
(
Wrappers
.
lambdaQuery
(
DataDict
.
class
)
.
eq
(
DataDict:
:
getType
,
"area"
));
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
()))
{
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
{
DataSourceService
.
switchDb
(
template
.
getDataSourceId
());
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 {
@JsonProperty
(
value
=
"AREA_NUMBER_CODE"
)
private
String
AREA_NUMBER_CODE
;
@ApiModelProperty
(
value
=
"所属区县"
)
@JsonProperty
(
value
=
"DWSSQX"
)
private
String
DWSSQX
;
/* @ApiModelProperty(value = "所属市")
@JsonProperty(value = "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 {
@ApiModelProperty
(
value
=
"元字段ID"
)
private
String
metaFieldId
;
@ApiModelProperty
(
value
=
"
数据库
字段名"
)
@ApiModelProperty
(
value
=
"字段名"
)
private
String
fieldName
;
@ApiModelProperty
(
value
=
"
数据库
字段类型"
)
@ApiModelProperty
(
value
=
"
元
字段类型"
)
private
String
fieldType
;
@ApiModelProperty
(
value
=
"数据库字段类型"
)
private
String
columnType
;
@ApiModelProperty
(
value
=
"待校验的值列表"
)
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
;
import
cn.hutool.core.util.StrUtil
;
import
com.baomidou.mybatisplus.annotation.DbType
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.tbyf.his.common.annotation.DataSource
;
...
...
@@ -19,7 +20,6 @@ import com.tbyf.his.web.dataImport.mapper.MetaFieldMapper;
import
com.tbyf.his.web.dataImport.service.DataTemplateService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.DataAccessException
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
...
...
@@ -84,18 +84,20 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat
DataSourceUtil
.
switchDs
(
DataSourceType
.
SLAVE
.
name
());
if
(
metaFieldMapper
.
selectTableCount
(
tableName
)
>
0
)
{
fieldErrorVos
.
forEach
(
item
->
{
String
fieldType
=
item
.
getFieldType
();
String
columnType
;
if
(
fieldType
.
contains
(
"NUMBER"
))
{
columnType
=
metaFieldMapper
.
selectNumberFieldType
(
tableName
,
item
.
getFieldName
());
}
else
{
columnType
=
metaFieldMapper
.
selectFieldType
(
tableName
,
item
.
getFieldName
());
}
//元字段存在、物理表字段可能不存在
if
(
StringUtils
.
isNotBlank
(
columnType
)
&&
!
StringUtils
.
equals
(
fieldType
,
columnType
)
&&
!
isVarcharLengthEqual
(
fieldType
,
columnType
))
{
FieldErrorVo
fieldErrorVo
=
new
FieldErrorVo
();
BeanUtils
.
copyBeanProp
(
fieldErrorVo
,
item
);
resultList
.
add
(
fieldErrorVo
.
setColumnType
(
columnType
).
setTableName
(
tableName
));
if
(
StrUtil
.
isAllNotBlank
(
item
.
getFieldType
(),
item
.
getFieldName
())){
String
fieldType
=
item
.
getFieldType
();
String
columnType
;
if
(
fieldType
.
contains
(
"NUMBER"
))
{
columnType
=
metaFieldMapper
.
selectNumberFieldType
(
tableName
,
item
.
getFieldName
());
}
else
{
columnType
=
metaFieldMapper
.
selectFieldType
(
tableName
,
item
.
getFieldName
());
}
//元字段存在、物理表字段可能不存在
if
(
StringUtils
.
isNotBlank
(
columnType
)
&&
!
StringUtils
.
equals
(
fieldType
,
columnType
)
&&
!
isVarcharLengthEqual
(
fieldType
,
columnType
))
{
FieldErrorVo
fieldErrorVo
=
new
FieldErrorVo
();
BeanUtils
.
copyBeanProp
(
fieldErrorVo
,
item
);
resultList
.
add
(
fieldErrorVo
.
setColumnType
(
columnType
).
setTableName
(
tableName
));
}
}
});
}
...
...
@@ -105,14 +107,15 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat
return
CompletableFuture
.
completedFuture
(
resultList
);
}
@Async
public
void
syncFieldError
(
String
fieldType
,
String
fieldName
,
String
tableName
)
{
String
sql
=
StrFormatter
.
format
(
alterSql
,
tableName
,
fieldName
,
fieldType
);
try
{
DataSourceUtil
.
switchDs
(
DataSourceType
.
SLAVE
.
name
());
String
sql
=
StrFormatter
.
format
(
alterSql
,
tableName
,
fieldName
,
fieldType
);
jdbcTemplate
.
execute
(
sql
);
}
catch
(
DataAccessException
e
)
{
log
.
error
(
"alter table's fieldType error"
);
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
log
.
error
(
"修改数据类型失败"
,
e
);
}
finally
{
DataSourceUtil
.
switchDefaultDs
();
}
}
...
...
admin-api/src/main/java/com/tbyf/his/web/dataImport/service/impl/ExcelDataServiceImpl.java
View file @
5d612191
This diff is collapsed.
Click to expand it.
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