|
@@ -3,8 +3,11 @@ package com.ruoyi.system.service.impl;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.ruoyi.system.entity.DragTable;
|
|
|
import com.ruoyi.system.entity.DragTableCondition;
|
|
|
import com.ruoyi.system.entity.DragTableGroup;
|
|
|
+import com.ruoyi.system.entity.TableSql;
|
|
|
import com.ruoyi.system.entity.vo.DragTableGroupVo;
|
|
|
import com.ruoyi.system.entity.vo.DragTableVo;
|
|
|
import com.ruoyi.system.mapper.DragTableConditionMapper;
|
|
@@ -69,6 +72,7 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
return dragTableGroupMapper.selectDragTableGroupList(dragTableGroup);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 新增拖拽格组
|
|
|
*
|
|
@@ -86,6 +90,19 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
dragTableService.addDragTable(dragTableGroupVo);
|
|
|
return dragTableGroupMapper.insertDragTableGroup(dragTableGroup);
|
|
|
}
|
|
|
+
|
|
|
+ // SQL 条件的开始
|
|
|
+ public static final String SQL_START = "CONCAT(";
|
|
|
+
|
|
|
+ // SQL 超级查询常量
|
|
|
+ public static final String SQL_MIDDLE = "IFNULL( #{VAL}, '' )";
|
|
|
+
|
|
|
+ // sqlserver || DM 数据类型的超级查询常量
|
|
|
+ public static final String SQL_DM_SERVER_MIDDLE = "COALESCE( #{VAL}, '' )";
|
|
|
+
|
|
|
+ // SQL 条件的结束
|
|
|
+ public static final String SQL_END = "LIKE '%#{val}%'";
|
|
|
+
|
|
|
/**
|
|
|
* 修改拖拽格组
|
|
|
*
|
|
@@ -93,8 +110,8 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateDragTableGroup(DragTableGroupVo dragTableGroupVo)
|
|
|
- {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int updateDragTableGroup(DragTableGroupVo dragTableGroupVo) {
|
|
|
//根据id查询表格组信息
|
|
|
DragTableGroup dragTableGroupOne = dragTableGroupMapper.selectDragTableGroupById(dragTableGroupVo.getId());
|
|
|
//得到group_table_info
|
|
@@ -104,22 +121,81 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
//收集tableKey
|
|
|
List<String> tableKeys = jsonArray.stream().map(item -> JSONObject.parseObject(item.toString()).get("tableKey").toString()
|
|
|
).collect(Collectors.toList());
|
|
|
- //删除表格数据
|
|
|
- dragTableMapper.deleteDragTableByTableKeys(tableKeys);
|
|
|
//删除条件数据
|
|
|
List<Long> dragTableIds = dragTableMapper.selectDragTableTableKeys(tableKeys)
|
|
|
.stream().map(item -> item.gettId()).collect(Collectors.toList());
|
|
|
dragTableConditionMapper.deleteDragTableConditionBytIds(dragTableIds);
|
|
|
//删除sql数据
|
|
|
- Long[] dragTableIds1 = dragTableIds.toArray(new Long[0]);
|
|
|
- tableSqlMapper.deleteTableSqlByTIds(dragTableIds1);
|
|
|
+ //Long[] dragTableIds1 = dragTableIds.toArray(new Long[0]);
|
|
|
+ //tableSqlMapper.deleteTableSqlByTIds(dragTableIds1);
|
|
|
+ //删除表格数据
|
|
|
+ //dragTableMapper.deleteDragTableByTableKeys(tableKeys);
|
|
|
+
|
|
|
+ //优化逻辑 1、表格组信息 2、表格信息、条件信息、sql信息
|
|
|
+ List<DragTableVo> dragTables = dragTableGroupVo.getDragTables();
|
|
|
+ if (dragTables.size()>0) {
|
|
|
+ dragTables.stream().forEach(dragTableVo->{
|
|
|
+ String SQL="";
|
|
|
+ //add drag_table
|
|
|
+ DragTable dragTable = new DragTable();
|
|
|
+ BeanUtils.copyProperties(dragTableVo, dragTable);
|
|
|
+ dragTable.setDtColumnName(JSON.toJSONString(dragTableVo.getDtColumnName()));
|
|
|
+ dragTable.setPrimaryKey(dragTableVo.getPrimaryKey());
|
|
|
+ dragTable.setMenuId(dragTableVo.getMenuId());
|
|
|
+ dragTable.setDtType("1");
|
|
|
+ //add table_sql
|
|
|
+ TableSql tableSql = new TableSql();
|
|
|
+ tableSql.settId(dragTable.gettId());
|
|
|
+ tableSql.setTableSql(dragTableVo.getTableSql());
|
|
|
+ dragTableMapper.updateDragTable(dragTable);
|
|
|
+ //拼接sql查询条件
|
|
|
+ switch (SecurityUtils.getDatabaseType().toUpperCase()) {
|
|
|
+ case "MYSQL":
|
|
|
+ for (int i = 0; dragTableVo.getSearchFieldList().size() > i; i++) {
|
|
|
+ SQL += " AND "+dragTableVo.getSearchFieldList().get(i)+"="+dragTableVo.getConditionDefaultValueMap().get(dragTableVo.getSearchFieldList().get(i));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "DM":
|
|
|
+ case "SQLSERVER":
|
|
|
+ SQL += SQL_START;
|
|
|
+ for (int i = 0; dragTableVo.getSearchFieldList().size() > i; i++) {
|
|
|
+ SQL += SQL_DM_SERVER_MIDDLE.replace("#{VAL}", dragTableVo.getSearchFieldList().get(i));
|
|
|
+ SQL += dragTableVo.getSearchFieldList().size() - 1 == i ? ",'')" : ",\n";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "ORACLE":
|
|
|
+ //SQL_START = "";
|
|
|
+ for (int i = 0; dragTableVo.getSearchFieldList().size() > i; i++) {
|
|
|
+ SQL += dragTableVo.getSearchFieldList().get(i);
|
|
|
+ SQL += (dragTableVo.getSearchFieldList().size() - 1 == i ? " " : "||");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String where = dragTableVo.getDtTableName() + ".del_flag = '0'";
|
|
|
+ tableSql.setTableCondition(where + SQL);
|
|
|
+ tableSql.setTableAlias(dragTableVo.getDtTableName());
|
|
|
+ tableSql.setTableExportField(JSON.toJSONString(dragTableVo.getTableExportField()));
|
|
|
+ tableSql.setSqlKey(dragTableVo.getSqlKey());
|
|
|
+ tableSql.setOrderByColumn(dragTableVo.getOrderByColumn());
|
|
|
+ tableSql.setSortOrder(dragTableVo.getSortOrder());
|
|
|
+ tableSqlMapper.updateTableSql(tableSql);
|
|
|
+ //add drag_table_condition
|
|
|
+ if (dragTableVo.getSearchFieldList().size() > 0) {
|
|
|
+ List<DragTableCondition> dragTableConditionList = new ArrayList<>();
|
|
|
+ dragTableVo.getSearchFieldList().forEach(item -> {
|
|
|
+ dragTableConditionList.add(new DragTableCondition(dragTable.gettId(), item,dragTableVo.getConditionDefaultValueMap().get(item).toString()));
|
|
|
+ });
|
|
|
+ dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
//修改表格组列表信息
|
|
|
- DragTableGroup dragTableGroup=new DragTableGroup();
|
|
|
- BeanUtils.copyProperties(dragTableGroupVo,dragTableGroup );
|
|
|
- dragTableGroupMapper.updateDragTableGroup(dragTableGroup);
|
|
|
+ DragTableGroup dragTableGroup = new DragTableGroup();
|
|
|
+ BeanUtils.copyProperties(dragTableGroupVo, dragTableGroup);
|
|
|
+ int i = dragTableGroupMapper.updateDragTableGroup(dragTableGroup);
|
|
|
//从新插入数据
|
|
|
- int insertRow = this.insertDragTableGroup(dragTableGroupVo);
|
|
|
- return insertRow;
|
|
|
+ //dragTableService.addDragTable(dragTableGroupVo);
|
|
|
+ return i;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -233,4 +309,6 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|