Commit 955dede3 by guoxw

物理表异常字段查询和同步 增加_TEMP表

parent 0fadb312
...@@ -57,9 +57,6 @@ public class DataTemplateController { ...@@ -57,9 +57,6 @@ public class DataTemplateController {
private ExcelDataService excelDataService; private ExcelDataService excelDataService;
@Autowired @Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private MetaFieldMapper metaFieldMapper; private MetaFieldMapper metaFieldMapper;
@IgnoreWebSecurity @IgnoreWebSecurity
...@@ -87,21 +84,11 @@ public class DataTemplateController { ...@@ -87,21 +84,11 @@ public class DataTemplateController {
@IgnoreWebSecurity @IgnoreWebSecurity
@PostMapping("/syncFieldError") @PostMapping("/syncFieldError")
@ApiOperation("物理表异常字段同步") @ApiOperation("物理表异常字段同步")
public AjaxResult fieldErrorUpdate(@RequestBody List<FieldErrorVo> fieldErrorVos) { public AjaxResult syncFieldError(@RequestBody List<FieldErrorVo> fieldErrorVos) {
final String alterSql = "ALTER TABLE {} MODIFY ( {} {} )";
try { try {
DataSourceUtil.switchDs(DataSourceType.SLAVE.name()); DataSourceUtil.switchDs(DataSourceType.SLAVE.name());
fieldErrorVos.forEach(item -> { fieldErrorVos.forEach(item -> {
String fieldType = item.getFieldType(); dataTemplateService.syncFieldError(item.getFieldType(), item.getFieldName(), item.getTableName());
String fieldName = item.getFieldName();
String tableName = item.getTableName();
String sql = StrFormatter.format(alterSql, tableName, fieldName, fieldType);
try {
jdbcTemplate.execute(sql);
} catch (DataAccessException e) {
log.error("alter table's fieldType error");
e.printStackTrace();
}
}); });
} finally { } finally {
DataSourceUtil.switchDefaultDs(); DataSourceUtil.switchDefaultDs();
......
...@@ -52,4 +52,12 @@ public interface DataTemplateService extends IService<DataTemplate> { ...@@ -52,4 +52,12 @@ public interface DataTemplateService extends IService<DataTemplate> {
* @return * @return
*/ */
public CompletableFuture<List<FieldErrorVo>> getTableFieldError(List<FieldErrorVo> fieldErrorVos, String tableName); public CompletableFuture<List<FieldErrorVo>> getTableFieldError(List<FieldErrorVo> fieldErrorVos, String tableName);
/**
* 同步异常字段
* @param fieldType
* @param fieldName
* @param tableName
*/
public void syncFieldError(String fieldType, String fieldName, String tableName);
} }
...@@ -3,6 +3,7 @@ package com.tbyf.his.web.dataImport.service.impl; ...@@ -3,6 +3,7 @@ package com.tbyf.his.web.dataImport.service.impl;
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;
import com.tbyf.his.common.core.text.StrFormatter;
import com.tbyf.his.common.enums.DataSourceType; 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;
...@@ -18,6 +19,8 @@ import com.tbyf.his.web.dataImport.mapper.MetaFieldMapper; ...@@ -18,6 +19,8 @@ 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.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -40,6 +43,11 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat ...@@ -40,6 +43,11 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat
@Autowired @Autowired
private MetaFieldMapper metaFieldMapper; private MetaFieldMapper metaFieldMapper;
@Autowired
private JdbcTemplate jdbcTemplate;
private static final String alterSql = "ALTER TABLE {} MODIFY ( {} {} )";
@Override @Override
public List<TemplateVO> queryTemplate(QueryTemplateParam param) { public List<TemplateVO> queryTemplate(QueryTemplateParam param) {
return dataTemplateMapper.queryTemplate(param); return dataTemplateMapper.queryTemplate(param);
...@@ -97,6 +105,17 @@ public class DataTemplateServiceImpl extends ServiceImpl<DataTemplateMapper, Dat ...@@ -97,6 +105,17 @@ 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) {
String sql = StrFormatter.format(alterSql, tableName, fieldName, fieldType);
try {
jdbcTemplate.execute(sql);
} catch (DataAccessException e) {
log.error("alter table's fieldType error");
e.printStackTrace();
}
}
protected boolean isVarcharLengthEqual(String fieldType, String columnType) { protected boolean isVarcharLengthEqual(String fieldType, String columnType) {
return fieldType.contains("VARCHAR") && columnType.contains("VARCHAR") && return fieldType.contains("VARCHAR") && columnType.contains("VARCHAR") &&
fieldType.substring(fieldType.indexOf("(") + 1, fieldType.indexOf(")")).equals(columnType.substring(columnType.indexOf("(") + 1, columnType.indexOf(")"))); fieldType.substring(fieldType.indexOf("(") + 1, fieldType.indexOf(")")).equals(columnType.substring(columnType.indexOf("(") + 1, columnType.indexOf(")")));
......
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