提交 27034f8e authored 作者: 黄承天's avatar 黄承天

[模型模块]分类复杂查询改动

上级 b51c53a2
...@@ -47,8 +47,6 @@ public class ModelController { ...@@ -47,8 +47,6 @@ public class ModelController {
private VersionService versionService; private VersionService versionService;
/** /**
* @param * @param
* @return java.util.List<com.tykj.workflowcore.model_layer.model.TableInfo> * @return java.util.List<com.tykj.workflowcore.model_layer.model.TableInfo>
...@@ -183,7 +181,7 @@ public class ModelController { ...@@ -183,7 +181,7 @@ public class ModelController {
@ApiOperation("复杂查询(分类)") @ApiOperation("复杂查询(分类)")
@PostMapping("/complexQuery/group") @PostMapping("/complexQuery/group")
public ResponseEntity complexQueryWithGroup(@RequestBody complexQueryVo complexQueryVo) { public ResponseEntity complexQueryWithGroup(@RequestBody complexQueryVo complexQueryVo) {
Map<Object, List<Map<String, Object>>> list = modelService.complexQueryWithGroup(complexQueryVo.getTableName(), complexQueryVo.getColumnNames(), complexQueryVo.getQueryConditions(), complexQueryVo.getGroupByColumn()); Map<Object, List<Map<String, Object>>> list = modelService.complexQueryWithGroup(complexQueryVo.getTableName(), complexQueryVo.getGroupConditions(), complexQueryVo.getColumnNames(), complexQueryVo.getQueryConditions(), complexQueryVo.getGroupByColumn());
if (list != null) { if (list != null) {
return ResultUtil.success(list, "查询成功!"); return ResultUtil.success(list, "查询成功!");
} }
......
package com.tykj.model_layer.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class GroupCondition {
private String name;
private String value;
}
...@@ -27,6 +27,9 @@ public class complexQueryVo { ...@@ -27,6 +27,9 @@ public class complexQueryVo {
@ApiModelProperty("筛选字段") @ApiModelProperty("筛选字段")
List<String> columnNames; List<String> columnNames;
@ApiModelProperty("分类条件信息")
List<GroupCondition> groupConditions;
@ApiModelProperty("查询条件") @ApiModelProperty("查询条件")
List<QueryCondition> queryConditions; List<QueryCondition> queryConditions;
......
...@@ -22,32 +22,33 @@ public interface ModelService { ...@@ -22,32 +22,33 @@ public interface ModelService {
/** /**
* 分页查询 * 分页查询
*
* @param searchTableInfoVo * @param searchTableInfoVo
* @return * @return
*/ */
Page<TableInfo> pageAllEntities(SearchTableInfoVo searchTableInfoVo); Page<TableInfo> pageAllEntities(SearchTableInfoVo searchTableInfoVo);
/** /**
* 方法重载不分页查询 * 方法重载不分页查询
*
* @return * @return
*/ */
List<TableInfo> listAllEntities(SearchTableInfoVo searchTableInfoVo) ; List<TableInfo> listAllEntities(SearchTableInfoVo searchTableInfoVo);
/** /**
* 根据表名查询所有字段信息 * 根据表名查询所有字段信息
*
* @param searchColumnInfoVo * @param searchColumnInfoVo
* @return * @return
*/ */
List<ColumnInfo> showModelFields(SearchColumnInfoVo searchColumnInfoVo); List<ColumnInfo> showModelFields(SearchColumnInfoVo searchColumnInfoVo);
/** /**
* 新建模型 * 新建模型
*
* @param tableVO * @param tableVO
* @return * @return
*/ */
...@@ -56,6 +57,7 @@ public interface ModelService { ...@@ -56,6 +57,7 @@ public interface ModelService {
/** /**
* 根据表名插入数据 * 根据表名插入数据
*
* @param map * @param map
* @return * @return
*/ */
...@@ -63,6 +65,7 @@ public interface ModelService { ...@@ -63,6 +65,7 @@ public interface ModelService {
/** /**
* 插入一组数据 * 插入一组数据
*
* @param mapList * @param mapList
* @return * @return
*/ */
...@@ -70,6 +73,7 @@ public interface ModelService { ...@@ -70,6 +73,7 @@ public interface ModelService {
/** /**
* 根据表名查询所有 * 根据表名查询所有
*
* @param name * @param name
* @return * @return
* @throws SQLException * @throws SQLException
...@@ -79,23 +83,26 @@ public interface ModelService { ...@@ -79,23 +83,26 @@ public interface ModelService {
/** /**
* 复杂查询 * 复杂查询
*
* @param tableName * @param tableName
* @param queryConditions * @param queryConditions
* @return * @return
*/ */
List<Map<String, Object>> complexQuery(String tableName,List<String> columnNames, List<QueryCondition> queryConditions); List<Map<String, Object>> complexQuery(String tableName, List<String> columnNames, List<QueryCondition> queryConditions);
/** /**
* 复杂查询(带分类) * 复杂查询(带分类)
*
* @param tableName * @param tableName
* @param queryConditions * @param queryConditions
* @return * @return
*/ */
Map<Object,List<Map<String, Object>>> complexQueryWithGroup(String tableName,List<String> columnNames, List<QueryCondition> queryConditions,String groupByColumn); Map<Object, List<Map<String, Object>>> complexQueryWithGroup(String tableName, List<GroupCondition> groupConditions, List<String>columnNames, List<QueryCondition> queryConditions, String groupByColumn);
/** /**
* 修改表 * 修改表
*
* @param updateTableInfoVO * @param updateTableInfoVO
* @return * @return
*/ */
...@@ -104,6 +111,7 @@ public interface ModelService { ...@@ -104,6 +111,7 @@ public interface ModelService {
/** /**
* 删除表 * 删除表
*
* @param delTableVO * @param delTableVO
* @return * @return
*/ */
...@@ -112,6 +120,7 @@ public interface ModelService { ...@@ -112,6 +120,7 @@ public interface ModelService {
/** /**
* 根据id批量查询所有tableInfo和ColumnInfo * 根据id批量查询所有tableInfo和ColumnInfo
*
* @param ids * @param ids
* @return * @return
*/ */
......
...@@ -11,6 +11,7 @@ import com.tykj.model_layer.dao.TableInfoDao; ...@@ -11,6 +11,7 @@ import com.tykj.model_layer.dao.TableInfoDao;
import com.tykj.model_layer.entity.ColumnInfo; import com.tykj.model_layer.entity.ColumnInfo;
import com.tykj.model_layer.entity.Quote; import com.tykj.model_layer.entity.Quote;
import com.tykj.model_layer.entity.TableInfo; import com.tykj.model_layer.entity.TableInfo;
import com.tykj.model_layer.entity.customEnums.ConnectionType;
import com.tykj.model_layer.entity.vo.*; import com.tykj.model_layer.entity.vo.*;
import com.tykj.model_layer.myEnum.ModelType; import com.tykj.model_layer.myEnum.ModelType;
import com.tykj.model_layer.service.ModelService; import com.tykj.model_layer.service.ModelService;
...@@ -157,7 +158,7 @@ public class ModelImpl implements ModelService { ...@@ -157,7 +158,7 @@ public class ModelImpl implements ModelService {
tableInfo.setModelName(tableVO.getModelName()); tableInfo.setModelName(tableVO.getModelName());
tableInfo.setModelTitle(tableVO.getModelTitle()); tableInfo.setModelTitle(tableVO.getModelTitle());
tableInfo.setXml(xmlMapping); tableInfo.setXml(xmlMapping);
tableInfo.setBackName(tableVO.getModelName()+"_back"); tableInfo.setBackName(tableVO.getModelName() + "_back");
tableInfo.setBackXml(xmlBack); tableInfo.setBackXml(xmlBack);
tableInfo.setModelType(tableVO.getModelType()); tableInfo.setModelType(tableVO.getModelType());
tableInfo.setDescription(tableVO.getDescription()); tableInfo.setDescription(tableVO.getDescription());
...@@ -179,9 +180,9 @@ public class ModelImpl implements ModelService { ...@@ -179,9 +180,9 @@ public class ModelImpl implements ModelService {
columnInfo.setPrimaryKey(columnVO.getPrimaryKey()); columnInfo.setPrimaryKey(columnVO.getPrimaryKey());
ColumnInfo save = columnInfoDao.save(columnInfo); ColumnInfo save = columnInfoDao.save(columnInfo);
List<Quote> quoteList = columnVO.getQuoteList(); List<Quote> quoteList = columnVO.getQuoteList();
if (quoteList!=null){ if (quoteList != null) {
for (Quote quote : quoteList) { for (Quote quote : quoteList) {
if (StringUtils.isNotEmpty(quote.getValue())){ if (StringUtils.isNotEmpty(quote.getValue())) {
quote.setColumnId(save.getId()); quote.setColumnId(save.getId());
quoteDao.save(quote); quoteDao.save(quote);
} }
...@@ -218,18 +219,18 @@ public class ModelImpl implements ModelService { ...@@ -218,18 +219,18 @@ public class ModelImpl implements ModelService {
} }
Integer modelType = tableInfo.getModelType(); Integer modelType = tableInfo.getModelType();
SessionImpl session = (SessionImpl)sessionUtil.getSession(); SessionImpl session = (SessionImpl) sessionUtil.getSession();
session.getTransaction().begin(); session.getTransaction().begin();
Object values = map.get(tableName); Object values = map.get(tableName);
if (values instanceof Map) { if (values instanceof Map) {
//插入数据 //插入数据
insertValue(tableInfo.getModelName(), (Map) values,session,true,false); insertValue(tableInfo.getModelName(), (Map) values, session, true, false);
} else { } else {
//循环插入数据 //循环插入数据
List valuesList = (List) values; List valuesList = (List) values;
for (int i = 0; i < valuesList.size(); i++) { for (int i = 0; i < valuesList.size(); i++) {
insertValue(tableInfo.getModelName(), (Map) valuesList.get(i),session,true,false); insertValue(tableInfo.getModelName(), (Map) valuesList.get(i), session, true, false);
} }
} }
session.getTransaction().commit(); session.getTransaction().commit();
...@@ -249,7 +250,7 @@ public class ModelImpl implements ModelService { ...@@ -249,7 +250,7 @@ public class ModelImpl implements ModelService {
**/ **/
@Override @Override
public int putValueByEntityNameList(List<Map<String, Object>> mapList) { public int putValueByEntityNameList(List<Map<String, Object>> mapList) {
SessionImpl session = (SessionImpl)sessionUtil.getSession(); SessionImpl session = (SessionImpl) sessionUtil.getSession();
session.getTransaction().begin(); session.getTransaction().begin();
for (Map<String, Object> map : mapList) { for (Map<String, Object> map : mapList) {
for (String tableName : for (String tableName :
...@@ -270,12 +271,12 @@ public class ModelImpl implements ModelService { ...@@ -270,12 +271,12 @@ public class ModelImpl implements ModelService {
Object values = map.get(tableName); Object values = map.get(tableName);
if (values instanceof Map) { if (values instanceof Map) {
//插入数据 //插入数据
insertValue(tableInfo.getModelName(), (Map) values,session,true,false); insertValue(tableInfo.getModelName(), (Map) values, session, true, false);
} else { } else {
//循环插入数据 //循环插入数据
List valuesList = (List) values; List valuesList = (List) values;
for (int i = 0; i < valuesList.size(); i++) { for (int i = 0; i < valuesList.size(); i++) {
insertValue(tableInfo.getModelName(), (Map) valuesList.get(i),session,true,false); insertValue(tableInfo.getModelName(), (Map) valuesList.get(i), session, true, false);
} }
} }
...@@ -295,7 +296,7 @@ public class ModelImpl implements ModelService { ...@@ -295,7 +296,7 @@ public class ModelImpl implements ModelService {
* @Description 新增参数的方法 * @Description 新增参数的方法
* @Date 16:17 2021/3/5 * @Date 16:17 2021/3/5
**/ **/
public void insertValue(String tableName, Map map,SessionImpl session,boolean back,boolean saveOrSaveAndUpdate) { public void insertValue(String tableName, Map map, SessionImpl session, boolean back, boolean saveOrSaveAndUpdate) {
EntityPersister entityPersister = session.getEntityPersister(tableName, map); EntityPersister entityPersister = session.getEntityPersister(tableName, map);
Type[] propertyTypes = entityPersister.getPropertyTypes(); Type[] propertyTypes = entityPersister.getPropertyTypes();
String[] propertyNames = entityPersister.getEntityPersister().getPropertyNames(); String[] propertyNames = entityPersister.getEntityPersister().getPropertyNames();
...@@ -306,8 +307,8 @@ public class ModelImpl implements ModelService { ...@@ -306,8 +307,8 @@ public class ModelImpl implements ModelService {
//先将Type转为java类 //先将Type转为java类
if (propertyType instanceof TimestampType) { if (propertyType instanceof TimestampType) {
try { try {
if (value instanceof String){ if (value instanceof String) {
if (StringUtils.isNotEmpty((String)value)){ if (StringUtils.isNotEmpty((String) value)) {
Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) value); Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse((String) value);
map.put(propertyNames[i], parse); map.put(propertyNames[i], parse);
} }
...@@ -329,17 +330,17 @@ public class ModelImpl implements ModelService { ...@@ -329,17 +330,17 @@ public class ModelImpl implements ModelService {
} }
HashMap hashMap = new HashMap(); HashMap hashMap = new HashMap();
hashMap.putAll(map); hashMap.putAll(map);
if (saveOrSaveAndUpdate){ if (saveOrSaveAndUpdate) {
session.save(tableName, map); session.save(tableName, map);
}else { } else {
session.saveOrUpdate(tableName, map); session.saveOrUpdate(tableName, map);
} }
if (back){ if (back) {
if (saveOrSaveAndUpdate){ if (saveOrSaveAndUpdate) {
session.save(tableName+"_back", map); session.save(tableName + "_back", map);
}else { } else {
session.saveOrUpdate(tableName+"_back", map); session.saveOrUpdate(tableName + "_back", map);
} }
} }
} }
...@@ -395,27 +396,36 @@ public class ModelImpl implements ModelService { ...@@ -395,27 +396,36 @@ public class ModelImpl implements ModelService {
} }
@Override @Override
public Map<Object, List<Map<String, Object>>> complexQueryWithGroup(String tableName, List<String> columnNames, List<QueryCondition> queryConditions, String groupByColumn) { public Map<Object, List<Map<String, Object>>> complexQueryWithGroup(String tableName, List<GroupCondition> groupConditions, List<String> columnNames, List<QueryCondition> queryConditions, String groupByColumn) {
Map<Object, List<Map<String, Object>>> result = new HashMap<>(); Map<Object, List<Map<String, Object>>> result = new HashMap<>();
if (Strings.isNotEmpty(tableName)) { if (Strings.isNotEmpty(tableName) && Strings.isNotEmpty(groupByColumn) && !groupConditions.isEmpty()) {
String query = createQuery(tableName, new ArrayList<>(), queryConditions, Strings.EMPTY); for (GroupCondition groupCondition : groupConditions) {
queryConditions.add(new QueryCondition(
groupByColumn,
"like",
groupCondition.getValue(),
ConnectionType.AND
));
String query = createQuery(tableName, columnNames, queryConditions, Strings.EMPTY);
Session session = sessionUtil.getSession(); Session session = sessionUtil.getSession();
Query query1 = session.createQuery(query); Query query1 = session.createQuery(query);
List<Map<String, Object>> list = query1.list(); List<Map<String, Object>> list = query1.list();
if (Strings.isNotEmpty(groupByColumn)) { result.put(groupCondition.getName(), list);
Set<Object> groupValues = list.stream().map(obj -> obj.get(groupByColumn)).collect(Collectors.toSet());
for (Object groupValue : groupValues) {
List<Map<String, Object>> entityList = list.stream().filter(obj -> Objects.equals(obj.get(groupByColumn), groupValue)).collect(Collectors.toList());
result.put(groupValue, entityList);
}
} else {
result.put("all", list);
} }
return result; return result;
} }
return null; return null;
} }
private QueryCondition queryCondition(String groupByColumn, GroupCondition groupCondition) {
return new QueryCondition(
groupByColumn,
"like",
groupCondition.getValue(),
ConnectionType.AND
);
}
@Override @Override
public int updateTable(UpdateTableInfoVO updateTableInfoVO) { public int updateTable(UpdateTableInfoVO updateTableInfoVO) {
//tableInfo和columnInfo变化 //tableInfo和columnInfo变化
...@@ -525,7 +535,7 @@ public class ModelImpl implements ModelService { ...@@ -525,7 +535,7 @@ public class ModelImpl implements ModelService {
} }
} }
for (ColumnInfo originColumnInfo : origin) { for (ColumnInfo originColumnInfo : origin) {
if (!originColumnInfo.getFieldName().equals("id")){ if (!originColumnInfo.getFieldName().equals("id")) {
boolean noneMatch = current.stream() boolean noneMatch = current.stream()
.noneMatch(columnInfo1 -> Objects.equals(originColumnInfo.getId(), columnInfo1.getId())); .noneMatch(columnInfo1 -> Objects.equals(originColumnInfo.getId(), columnInfo1.getId()));
if (noneMatch) { if (noneMatch) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论