Commit 5d612191 by liuzz

机构查看添加了所属区县字段

模板字段数据类型同步功能bug修复
数据导入添加了数据库字段类型异常判断
parent c24a569e
...@@ -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 { fieldErrorVos.forEach(item -> {
DataSourceUtil.switchDs(DataSourceType.SLAVE.name()); dataTemplateService.syncFieldError(item.getFieldType(), item.getFieldName(), item.getTableName());
fieldErrorVos.forEach(item -> { });
dataTemplateService.syncFieldError(item.getFieldType(), item.getFieldName(), item.getTableName());
});
} finally {
DataSourceUtil.switchDefaultDs();
}
return AjaxResult.success(); return AjaxResult.success();
} }
......
...@@ -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(
......
...@@ -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;
......
...@@ -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;
......
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,18 +84,20 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat ...@@ -84,18 +84,20 @@ 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 -> {
String fieldType = item.getFieldType(); if (StrUtil.isAllNotBlank(item.getFieldType(),item.getFieldName())){
String columnType; String fieldType = item.getFieldType();
if (fieldType.contains("NUMBER")) { String columnType;
columnType = metaFieldMapper.selectNumberFieldType(tableName, item.getFieldName()); if (fieldType.contains("NUMBER")) {
} else { columnType = metaFieldMapper.selectNumberFieldType(tableName, item.getFieldName());
columnType = metaFieldMapper.selectFieldType(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(); if (StringUtils.isNotBlank(columnType) && !StringUtils.equals(fieldType, columnType) && !isVarcharLengthEqual(fieldType, columnType)) {
BeanUtils.copyBeanProp(fieldErrorVo, item); FieldErrorVo fieldErrorVo = new FieldErrorVo();
resultList.add(fieldErrorVo.setColumnType(columnType).setTableName(tableName)); BeanUtils.copyBeanProp(fieldErrorVo, item);
resultList.add(fieldErrorVo.setColumnType(columnType).setTableName(tableName));
}
} }
}); });
} }
...@@ -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();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment