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

[数据模型] 修改几个bug

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