提交 9b13f021 authored 作者: ww1xhqc's avatar ww1xhqc

[数据模型] 修改模型修改xml的bug,复杂查询的简单测试

上级 d1cc9af4
...@@ -22,7 +22,7 @@ import java.io.Serializable; ...@@ -22,7 +22,7 @@ import java.io.Serializable;
*/ */
@WorkFlowCoreNoScan @WorkFlowCoreNoScan
@Entity @Entity
@Table(name = "workflow_table_info") //@Table(name = "workflow_table_info")
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
@Data @Data
@SQLDelete(sql = "update table_info set deleted = 1 where id = ?") @SQLDelete(sql = "update table_info set deleted = 1 where id = ?")
......
...@@ -22,6 +22,7 @@ import org.hibernate.Session; ...@@ -22,6 +22,7 @@ import org.hibernate.Session;
import org.hibernate.internal.SessionImpl; import org.hibernate.internal.SessionImpl;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.Query;
import org.hibernate.type.IntegerType; import org.hibernate.type.IntegerType;
import org.hibernate.type.StringType; import org.hibernate.type.StringType;
import org.hibernate.type.TimestampType; import org.hibernate.type.TimestampType;
...@@ -428,7 +429,11 @@ public class ModelImpl implements ModelService { ...@@ -428,7 +429,11 @@ public class ModelImpl implements ModelService {
if (!"".equals(tableName)) { if (!"".equals(tableName)) {
String query = createQuery(tableName, queryConditions); String query = createQuery(tableName, queryConditions);
return jdbcTemplate.queryForList(query); Session session = sessionUtil.getSession();
Query query1 = session.createQuery(query);
List<Map<String, Object>> list = query1.list();
return list;
} }
return null; return null;
} }
...@@ -463,13 +468,15 @@ public class ModelImpl implements ModelService { ...@@ -463,13 +468,15 @@ public class ModelImpl implements ModelService {
.map(columnVO -> columnInfo(tableInfo.getId(), tableInfo.getModelName(), columnVO)) .map(columnVO -> columnInfo(tableInfo.getId(), tableInfo.getModelName(), columnVO))
.collect(Collectors.toList()); .collect(Collectors.toList());
//根据ColumnInfo集合得出表实际改动的sql语句集合
List<String> sqls = getTableSqls(tableInfo.getModelName(), originalColumnInfos, currentColumnInfos); //根据ColumnInfo集合得出表实际改动的sql语句集合
//执行sql语句 List<String> sqls = getTableSqls(tableInfo.getModelName(), originalColumnInfos, currentColumnInfos);
for (String sql : sqls) { //执行sql语句
System.out.println(sql); for (String sql : sqls) {
jdbcTemplate.execute(sql); System.out.println(sql);
} jdbcTemplate.execute(sql);
}
//重新保存字段信息 //重新保存字段信息
List<ColumnInfo> columnsForAdd = getColumnsForAdd(originalColumnInfos, currentColumnInfos); List<ColumnInfo> columnsForAdd = getColumnsForAdd(originalColumnInfos, currentColumnInfos);
...@@ -486,6 +493,13 @@ public class ModelImpl implements ModelService { ...@@ -486,6 +493,13 @@ public class ModelImpl implements ModelService {
} }
} }
if(modelType.equals(ModelType.BASICS_EXTENSION)){
columnInfoDao.deleteAllByDbId(updateTableInfoVO.getDbId());
List<ColumnInfo> dataList = updateTableInfoVO.getTableVO().getDataList().stream()
.map(columnVO -> columnInfo(tableInfo.getId(), tableInfo.getModelName(), columnVO))
.collect(Collectors.toList());
columnInfoDao.saveAll(dataList);
}
return 1; return 1;
} }
...@@ -586,7 +600,7 @@ public class ModelImpl implements ModelService { ...@@ -586,7 +600,7 @@ public class ModelImpl implements ModelService {
TableInfo tableInfo = byId.get(); TableInfo tableInfo = byId.get();
Integer modelType = tableInfo.getModelType(); Integer modelType = tableInfo.getModelType();
if (modelType.equals(ModelType.BUSINESS)||modelType.equals(ModelType.BASICS_EXTENSION)) { if (modelType.equals(ModelType.BUSINESS)||modelType.equals(ModelType.BASICS_EXTENSION)) {
tableInfoDao.delete(tableInfo); tableInfoDao.deleteById(delTableVO.getId());
List<ColumnInfo> allByDbId = columnInfoDao.findAllByDbId(delTableVO.getId()); List<ColumnInfo> allByDbId = columnInfoDao.findAllByDbId(delTableVO.getId());
columnInfoDao.deleteInBatch(allByDbId); columnInfoDao.deleteInBatch(allByDbId);
// jdbcTemplate.execute("drop table " + tableInfo.getModelName()); // jdbcTemplate.execute("drop table " + tableInfo.getModelName());
...@@ -619,7 +633,7 @@ public class ModelImpl implements ModelService { ...@@ -619,7 +633,7 @@ public class ModelImpl implements ModelService {
List<TableInfo> tableInfoList = tableInfoDao.findAllByModelType(ModelType.BASICS); List<TableInfo> tableInfoList = tableInfoDao.findAllByModelType(ModelType.BASICS);
for (TableInfo tableInfo : tableInfoList) { for (TableInfo tableInfo : tableInfoList) {
/*删除columnInfo*/ /*删除columnInfo*/
columnInfoDao.deleteAllByDbId(tableInfo.getId()); // columnInfoDao.deleteAllByDbId(tableInfo.getId());
} }
} }
} }
...@@ -58,7 +58,7 @@ public class CreateTableUtil { ...@@ -58,7 +58,7 @@ public class CreateTableUtil {
"<hibernate-mapping>\n" + "<hibernate-mapping>\n" +
" <class entity-name=\"" + tableVO.getModelName() + "\" table=\"" + tableVO.getModelName() + "\">\n"; " <class entity-name=\"" + tableVO.getModelName() + "\" table=\"" + tableVO.getModelName() + "\">\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=\"identity\" />\n" + " <generator class=\"identity\" />\n" +
" </id>"; " </id>";
for (ColumnVO columnVO : dataList) { for (ColumnVO columnVO : dataList) {
......
...@@ -8,6 +8,7 @@ import com.tykj.workflowcore.model_layer.dao.TableInfoDao; ...@@ -8,6 +8,7 @@ import com.tykj.workflowcore.model_layer.dao.TableInfoDao;
import com.tykj.workflowcore.model_layer.entity.ColumnInfo; import com.tykj.workflowcore.model_layer.entity.ColumnInfo;
import com.tykj.workflowcore.model_layer.entity.TableInfo; import com.tykj.workflowcore.model_layer.entity.TableInfo;
import com.tykj.workflowcore.model_layer.entity.vo.QueryCondition;
import com.tykj.workflowcore.model_layer.entity.vo.TableAndColumnInfoVO; import com.tykj.workflowcore.model_layer.entity.vo.TableAndColumnInfoVO;
import com.tykj.workflowcore.model_layer.myEnum.ModelType; import com.tykj.workflowcore.model_layer.myEnum.ModelType;
import com.tykj.workflowcore.model_layer.service.ModelService; import com.tykj.workflowcore.model_layer.service.ModelService;
...@@ -16,6 +17,7 @@ import com.tykj.workflowcore.model_layer.utils.AggregationUtil; ...@@ -16,6 +17,7 @@ import com.tykj.workflowcore.model_layer.utils.AggregationUtil;
import com.tykj.workflowcore.model_layer.utils.CreateTableUtil; import com.tykj.workflowcore.model_layer.utils.CreateTableUtil;
import com.tykj.workflowcore.model_layer.utils.SessionUtil; import com.tykj.workflowcore.model_layer.utils.SessionUtil;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.assertj.core.util.Lists;
import org.dom4j.*; import org.dom4j.*;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import org.hibernate.Session; import org.hibernate.Session;
...@@ -494,8 +496,9 @@ class WorkflowCoreApplicationTests { ...@@ -494,8 +496,9 @@ class WorkflowCoreApplicationTests {
// System.out.println(jsonExample); // System.out.println(jsonExample);
StringUtils.hasLength(xml); StringUtils.hasLength(xml);
} }
@Test @Test
public void testDelete(){ public void testDelete() {
List<TableInfo> tableInfos = tableInfoDao.deleteAllByModelType(0); List<TableInfo> tableInfos = tableInfoDao.deleteAllByModelType(0);
for (TableInfo tableInfo : tableInfos) { for (TableInfo tableInfo : tableInfos) {
System.out.println(tableInfo.getId()); System.out.println(tableInfo.getId());
...@@ -503,12 +506,28 @@ class WorkflowCoreApplicationTests { ...@@ -503,12 +506,28 @@ class WorkflowCoreApplicationTests {
} }
} }
@Test @Test
public void testType(){ public void testType() {
// System.out.println(getTypeName(Integer.class.toString())); // System.out.println(getTypeName(Integer.class.toString()));
// String exJsonExample = modelHelper.getExJsonExample(5); // String exJsonExample = modelHelper.getExJsonExample(5);
// System.out.println(exJsonExample); // System.out.println(exJsonExample);
} }
@Test
public void complex() {
ArrayList<QueryCondition> queryConditions = Lists.newArrayList(
new QueryCondition("id", "=", "1")
// new QueryCondition("type", "=", "'1'")
);
List<Map<String, Object>> list = modelService.complexQuery("nw_history", queryConditions);
for (Map<String, Object> map : list) {
System.out.println(map);
}
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论