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

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

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