Commit 5d612191 by liuzz

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

模板字段数据类型同步功能bug修复
数据导入添加了数据库字段类型异常判断
parent c24a569e
......@@ -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();
}
......
......@@ -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(
......
......@@ -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;
......
......@@ -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;
......
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();
}
}
......
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