提交 3d71175a authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 修改几个bug

上级 aefe0153
...@@ -25,7 +25,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -25,7 +25,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2
public class WebMvcConfig extends WebMvcConfigurerAdapter { public class WebMvcConfig implements WebMvcConfigurer {
@Bean @Bean
public WebMvcConfigurer corsConfigurer() { public WebMvcConfigurer corsConfigurer() {
...@@ -53,9 +53,9 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { ...@@ -53,9 +53,9 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
private ApiInfo apiInfo() { private ApiInfo apiInfo() {
return new ApiInfoBuilder() return new ApiInfoBuilder()
.title("swagger") .title("数据模型")
.description("swagger") .description("数据模型")
.version("1.0") .version("1.1")
.build(); .build();
} }
......
...@@ -81,12 +81,7 @@ public class ModelController { ...@@ -81,12 +81,7 @@ public class ModelController {
@ApiOperation("新增数据模型") @ApiOperation("新增数据模型")
@PostMapping(value = "/addModel") @PostMapping(value = "/addModel")
public ResponseEntity addModel(@RequestBody TableVO tableVO) throws Exception { public ResponseEntity addModel(@RequestBody TableVO tableVO) throws Exception {
SearchTableInfoVo searchTableInfoVo = new SearchTableInfoVo();
searchTableInfoVo.setModelName(tableVO.getModelName());
List<TableInfo> tableInfos = modelService.listAllEntities(searchTableInfoVo);
if (tableInfos.size() > 0) {
return ResultUtil.failed("表已经存在!");
}
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
modelService.newTable(tableVO); modelService.newTable(tableVO);
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
......
...@@ -31,6 +31,7 @@ import org.springframework.data.domain.Page; ...@@ -31,6 +31,7 @@ import org.springframework.data.domain.Page;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -102,7 +103,7 @@ public class ModelImpl implements ModelService { ...@@ -102,7 +103,7 @@ public class ModelImpl implements ModelService {
private PredicateBuilder<TableInfo> createPredicateBySearchTableInfoVo(SearchTableInfoVo stv) { private PredicateBuilder<TableInfo> createPredicateBySearchTableInfoVo(SearchTableInfoVo stv) {
PredicateBuilder<TableInfo> and = Specifications.and(); PredicateBuilder<TableInfo> and = Specifications.and();
if (stv != null) { if (stv != null) {
and.like(!isNull(stv.getModelName()) && isNotEmpty(stv.getModelName()), "modelName", "%" + stv.getModelName() + "%"); and.like(!isNull(stv.getModelName().toUpperCase()) && isNotEmpty(stv.getModelName().toUpperCase()), "modelName", "%" + stv.getModelName().toUpperCase() + "%");
and.like(!isNull(stv.getModelTitle()) && isNotEmpty(stv.getModelTitle()), "modelTitle", "%" + stv.getModelTitle() + "%"); and.like(!isNull(stv.getModelTitle()) && isNotEmpty(stv.getModelTitle()), "modelTitle", "%" + stv.getModelTitle() + "%");
and.in(!isNull(stv.getModelType()) && stv.getModelType().length > 0, "modelType", stv.getModelType()); and.in(!isNull(stv.getModelType()) && stv.getModelType().length > 0, "modelType", stv.getModelType());
and.in(!isNull(stv.getIds()) && stv.getIds().length > 0, "id", stv.getIds()); and.in(!isNull(stv.getIds()) && stv.getIds().length > 0, "id", stv.getIds());
...@@ -138,7 +139,7 @@ public class ModelImpl implements ModelService { ...@@ -138,7 +139,7 @@ public class ModelImpl implements ModelService {
public TableInfo newTable(TableVO tableVO) { public TableInfo newTable(TableVO tableVO) {
String xmlMapping = createTable(tableVO); String xmlMapping = createTable(tableVO);
// 表名判重 // 表名判重
modelNameIsExist(tableVO.getModelName()); modelNameIsExist(tableVO.getModelName().toUpperCase());
//向数据库中生成这张表 //向数据库中生成这张表
sessionUtil.addXml(xmlMapping); sessionUtil.addXml(xmlMapping);
List<ColumnVO> dataList = tableVO.getDataList(); List<ColumnVO> dataList = tableVO.getDataList();
...@@ -152,7 +153,7 @@ public class ModelImpl implements ModelService { ...@@ -152,7 +153,7 @@ public class ModelImpl implements ModelService {
tableInfoDao.save(tableInfo); tableInfoDao.save(tableInfo);
//构建字段 //构建字段
//默认存储ID字段 //默认存储ID字段
ColumnInfo cId = new ColumnInfo(0, "id", "主键", "java.lang.Integer", 11, tableInfo.getModelName(), tableInfo.getId(), "主键"); ColumnInfo cId = new ColumnInfo(0, "id", "主键", "java.lang.Integer", 11, tableInfo.getModelName().toUpperCase(), tableInfo.getId(), "主键");
columnInfoDao.save(cId); columnInfoDao.save(cId);
for (ColumnVO columnVO : dataList) { for (ColumnVO columnVO : dataList) {
ColumnInfo columnInfo = new ColumnInfo( ColumnInfo columnInfo = new ColumnInfo(
...@@ -282,8 +283,7 @@ public class ModelImpl implements ModelService { ...@@ -282,8 +283,7 @@ public class ModelImpl implements ModelService {
Type propertyType = propertyTypes[i]; Type propertyType = propertyTypes[i];
//根据目标Type转换 //根据目标Type转换
changeValueToTargetType(map, value, propertyType, propertyNames[i]); changeValueToTargetType(map, value, propertyType, propertyNames[i]);
//todo //验证
// 通过 tableInfo 的 Id + columnName 为查询条件 查出 columnInfo
validationAllRuleAndQuote(tableInfo, value, propertyType, propertyNames[i]); validationAllRuleAndQuote(tableInfo, value, propertyType, propertyNames[i]);
} }
session.saveOrUpdate(tableName, map); session.saveOrUpdate(tableName, map);
...@@ -550,6 +550,8 @@ public class ModelImpl implements ModelService { ...@@ -550,6 +550,8 @@ public class ModelImpl implements ModelService {
String sql = "DROP SEQUENCE " + "SEQUENCE_" + tableInfo.getModelName().toUpperCase() + " CASCADE;"; String sql = "DROP SEQUENCE " + "SEQUENCE_" + tableInfo.getModelName().toUpperCase() + " CASCADE;";
log.info(sql); log.info(sql);
jdbcTemplate.execute(sql); jdbcTemplate.execute(sql);
//重新加载metaSource
sessionUtil.init();
} }
} catch (Exception e) { } catch (Exception e) {
throw new ApiException("删除表时出现错误!"); throw new ApiException("删除表时出现错误!");
...@@ -641,16 +643,19 @@ public class ModelImpl implements ModelService { ...@@ -641,16 +643,19 @@ public class ModelImpl implements ModelService {
void validationAllRuleAndQuote(TableInfo tableInfo, Object value, Type propertyType, String propertyNames) { void validationAllRuleAndQuote(TableInfo tableInfo, Object value, Type propertyType, String propertyNames) {
if (propertyType instanceof StringType) { if (propertyType instanceof StringType) {
// 通过 tableInfo 的 Id + columnName 为查询条件 查出 columnInfo
ColumnInfo columnInfo = columnInfoDao.findByDbIdAndFieldName(tableInfo.getId(), propertyNames); ColumnInfo columnInfo = columnInfoDao.findByDbIdAndFieldName(tableInfo.getId(), propertyNames);
//引用校验 //引用校验
if (!isNull(quoteDao.findAllByColumnId(columnInfo.getId()))){
List<String> quotes = quoteDao.findAllByColumnId(columnInfo.getId()).stream().map(Quote::getValue).collect(Collectors.toList()); List<String> quotes = quoteDao.findAllByColumnId(columnInfo.getId()).stream().map(Quote::getValue).collect(Collectors.toList());
validationQuote(quotes, (String) value); validationQuote(quotes, (String) value);
}
//规则校验 //规则校验
if (!isNull( ruleDao.findByColumnId(columnInfo.getId()))){
String regular = ruleDao.findByColumnId(columnInfo.getId()).getRegular(); String regular = ruleDao.findByColumnId(columnInfo.getId()).getRegular();
validationRule(regular, (String) value); validationRule(regular, (String) value);
} }
}
} }
private Boolean isNotEmpty(String str) { private Boolean isNotEmpty(String str) {
......
...@@ -57,7 +57,7 @@ public class CreateTableUtil { ...@@ -57,7 +57,7 @@ public class CreateTableUtil {
"<hibernate-mapping>\n" + "<hibernate-mapping>\n" +
" <class entity-name=\"" + tableVO.getModelName().toUpperCase() + "\" table=\"" + tableVO.getModelName().toUpperCase() + "\">\n"; " <class entity-name=\"" + tableVO.getModelName().toUpperCase() + "\" table=\"" + tableVO.getModelName().toUpperCase() + "\">\n";
xmlMapping += " <id name=\"id\" type=\"java.lang.Integer\" length=\"11\" unsaved-value=\"null\" >\n" + xmlMapping += " <id name=\"ID\" type=\"java.lang.Integer\" length=\"11\" unsaved-value=\"null\" >\n" +
" <generator class=\"com.tykj.datawarehouse.base.entity.XMQGenerator\" >" + " <generator class=\"com.tykj.datawarehouse.base.entity.XMQGenerator\" >" +
"<param name=\"sequence\">SEQUENCE_"+tableVO.getModelName().toUpperCase()+"</param>"+ "<param name=\"sequence\">SEQUENCE_"+tableVO.getModelName().toUpperCase()+"</param>"+
"</generator>" + "</generator>" +
......
...@@ -40,12 +40,11 @@ public class SessionUtil { ...@@ -40,12 +40,11 @@ public class SessionUtil {
this.tableInfoDao = tableInfoDao; this.tableInfoDao = tableInfoDao;
sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry(); serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry();
metadataSources = new MetadataSources(serviceRegistry);
sessionFactory.getSessionFactoryOptions();
init(); init();
} }
private void init(){ public void init(){
metadataSources = new MetadataSources(serviceRegistry);
//去数据库读取所有的XML 加载到 metasource里 //去数据库读取所有的XML 加载到 metasource里
List<TableInfo> all = tableInfoDao.findAll(); List<TableInfo> all = tableInfoDao.findAll();
for (TableInfo tableInfo : all) { for (TableInfo tableInfo : all) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论