|
@@ -3,20 +3,27 @@ package com.ruoyi.business.service.impl;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.ruoyi.business.entity.DragTable;
|
|
|
import com.ruoyi.business.entity.DragTableCondition;
|
|
|
import com.ruoyi.business.entity.DragTableGroup;
|
|
|
+import com.ruoyi.business.entity.TableSql;
|
|
|
import com.ruoyi.business.entity.vo.DragTableGroupVo;
|
|
|
import com.ruoyi.business.entity.vo.DragTableVo;
|
|
|
import com.ruoyi.business.mapper.DragTableConditionMapper;
|
|
|
import com.ruoyi.business.mapper.DragTableGroupMapper;
|
|
|
import com.ruoyi.business.mapper.DragTableMapper;
|
|
|
import com.ruoyi.business.mapper.TableSqlMapper;
|
|
|
+import com.ruoyi.business.service.IDragTableBtnRelevanceService;
|
|
|
import com.ruoyi.business.service.IDragTableGroupService;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -45,6 +52,8 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
@Autowired
|
|
|
private TableSqlMapper tableSqlMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IDragTableBtnRelevanceService dragTableBtnRelevanceService;
|
|
|
/**
|
|
|
* 查询拖拽格组
|
|
|
*
|
|
@@ -69,6 +78,7 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
return dragTableGroupMapper.selectDragTableGroupList(dragTableGroup);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 新增拖拽格组
|
|
|
*
|
|
@@ -84,8 +94,38 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
BeanUtils.copyProperties(dragTableGroupVo,dragTableGroup);
|
|
|
//添加动态表格列表
|
|
|
dragTableService.addDragTable(dragTableGroupVo);
|
|
|
+ //默认添加的是联动表格
|
|
|
+ dragTableGroup.setGroupType("0");
|
|
|
return dragTableGroupMapper.insertDragTableGroup(dragTableGroup);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int insertDragTableConfigurationGroup(DragTableGroupVo dragTableGroupVo)
|
|
|
+ {
|
|
|
+ //表格组实体类拷贝数据
|
|
|
+ DragTableGroup dragTableGroup=new DragTableGroup();
|
|
|
+ BeanUtils.copyProperties(dragTableGroupVo,dragTableGroup);
|
|
|
+ //添加动态表格列表
|
|
|
+ dragTableService.addDragTable(dragTableGroupVo);
|
|
|
+ dragTableGroup.setGroupType("1");
|
|
|
+ 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 +133,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 +144,158 @@ 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="";
|
|
|
+ //update drag_table
|
|
|
+ DragTable dragTable = new DragTable();
|
|
|
+ BeanUtils.copyProperties(dragTableVo, dragTable);
|
|
|
+ dragTable.setDtColumnName(dragTableVo.getDtColumnName().toString());
|
|
|
+ dragTable.setPrimaryKey(dragTableVo.getPrimaryKey());
|
|
|
+ dragTable.setMenuId(dragTableVo.getMenuId());
|
|
|
+ dragTable.setDtType("1");
|
|
|
+ dragTableMapper.updateDragTable(dragTable);
|
|
|
+ //update table_sql
|
|
|
+ TableSql tableSql = new TableSql();
|
|
|
+ //拼接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.setOrderByColumn(dragTableVo.getOrderByColumn());
|
|
|
+ tableSql.setSortOrder(dragTableVo.getSortOrder());
|
|
|
+ tableSql.setSqlKey(dragTableVo.getSqlKey());
|
|
|
+ int i = tableSqlMapper.updateTableSqlBySqlKey(tableSql);
|
|
|
+ System.out.println(i);
|
|
|
+ //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);
|
|
|
- //从新插入数据
|
|
|
- int insertRow = this.insertDragTableGroup(dragTableGroupVo);
|
|
|
- return insertRow;
|
|
|
+ DragTableGroup dragTableGroup = new DragTableGroup();
|
|
|
+ BeanUtils.copyProperties(dragTableGroupVo, dragTableGroup);
|
|
|
+ int i = dragTableGroupMapper.updateDragTableGroup(dragTableGroup);
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int editConfigurationGroup(DragTableGroupVo dragTableGroupVo) {
|
|
|
+ //根据id查询表格组信息
|
|
|
+ DragTableGroup dragTableGroupOne = dragTableGroupMapper.selectDragTableGroupById(dragTableGroupVo.getId());
|
|
|
+ //得到group_table_info
|
|
|
+ String groupTableInfo = dragTableGroupOne.getGroupTableInfo();
|
|
|
+ //把他转换成Map对象
|
|
|
+ JSONArray jsonArray = JSON.parseArray(groupTableInfo);
|
|
|
+ //收集tableKey
|
|
|
+ List<String> tableKeys = jsonArray.stream().map(item -> JSONObject.parseObject(item.toString()).get("tableKey").toString()
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ //删除条件数据
|
|
|
+ List<Long> dragTableIds = dragTableMapper.selectDragTableTableKeys(tableKeys)
|
|
|
+ .stream().map(item -> item.gettId()).collect(Collectors.toList());
|
|
|
+ dragTableConditionMapper.deleteDragTableConditionBytIds(dragTableIds);
|
|
|
+ //优化逻辑 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(dragTableVo.getDtColumnName().toString());
|
|
|
+ dragTable.setPrimaryKey(dragTableVo.getPrimaryKey());
|
|
|
+ dragTable.setMenuId(dragTableVo.getMenuId());
|
|
|
+ dragTable.setDtType("1");
|
|
|
+ //add table_sql
|
|
|
+ TableSql tableSql = new TableSql();
|
|
|
+ tableSql.setSqlKey(dragTableVo.getSqlKey());
|
|
|
+ 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.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);
|
|
|
+ }
|
|
|
+ //修改按钮信息
|
|
|
+ dragTableBtnRelevanceService.updateDragTableBtnRelevance(dragTableVo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //修改表格组列表信息
|
|
|
+ DragTableGroup dragTableGroup = new DragTableGroup();
|
|
|
+ BeanUtils.copyProperties(dragTableGroupVo, dragTableGroup);
|
|
|
+ int i = dragTableGroupMapper.updateDragTableGroup(dragTableGroup);
|
|
|
+ return i;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -129,8 +305,35 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public int deleteDragTableGroupByIds(Long[] ids)
|
|
|
{
|
|
|
+ //表格数据
|
|
|
+ List<String> tableKeys = new ArrayList<>();
|
|
|
+ //删除条件数据
|
|
|
+ List<Long> dragTableIds =new ArrayList<>();
|
|
|
+ for (Long id : ids) {
|
|
|
+ //根据id查询表格组信息
|
|
|
+ DragTableGroup dragTableGroupOne = dragTableGroupMapper.selectDragTableGroupById(id);
|
|
|
+ //得到group_table_info
|
|
|
+ String groupTableInfo = dragTableGroupOne.getGroupTableInfo();
|
|
|
+ //把他转换成Map对象
|
|
|
+ JSONArray jsonArray = JSON.parseArray(groupTableInfo);
|
|
|
+ //收集tableKey
|
|
|
+ jsonArray.stream().forEach(item->
|
|
|
+ tableKeys.add(JSONObject.parseObject(item.toString()).get("tableKey").toString()));
|
|
|
+ //删除条件数据
|
|
|
+ dragTableMapper.selectDragTableTableKeys(tableKeys)
|
|
|
+ .stream().forEach(item ->dragTableIds.add(item.gettId()));
|
|
|
+ }
|
|
|
+ //删除表格数据
|
|
|
+ dragTableMapper.deleteDragTableByTableKeys(tableKeys);
|
|
|
+ //删除条件数据
|
|
|
+ dragTableConditionMapper.deleteDragTableConditionBytIds(dragTableIds);
|
|
|
+ //删除sql数据
|
|
|
+ Long[] dragTableIds1 = dragTableIds.toArray(new Long[0]);
|
|
|
+ tableSqlMapper.deleteTableSqlByTIds(dragTableIds1);
|
|
|
+ //删除组数据
|
|
|
return dragTableGroupMapper.deleteDragTableGroupByIds(ids);
|
|
|
}
|
|
|
|
|
@@ -154,15 +357,25 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
String groupTableInfo = dragTableGroupOne.getGroupTableInfo();
|
|
|
//把他转换成Map对象
|
|
|
JSONArray jsonArray = JSON.parseArray(groupTableInfo);
|
|
|
- List<String> stringList=new ArrayList<>();
|
|
|
- //收集下tableKey
|
|
|
- jsonArray.forEach(e->{
|
|
|
+ //排序确保表格的顺序
|
|
|
+ JSONArray sortArray = jsonArray.stream().sorted(
|
|
|
+ Comparator.comparingLong(
|
|
|
+ // 根据对象中的ID进行排序
|
|
|
+ e -> JSONObject.parseObject(e.toString()).getIntValue("sort")
|
|
|
+ )
|
|
|
+ ).collect(Collectors.toCollection(JSONArray::new));
|
|
|
+ //把查询出来的动态表格数据放到一个集合里边
|
|
|
+ List<DragTableVo> dragTableList=new ArrayList<>();
|
|
|
+ sortArray.forEach(e->{
|
|
|
JSONObject jsonObject = JSON.parseObject(e.toString());
|
|
|
String str = jsonObject.get("tableKey").toString();
|
|
|
- stringList.add(str);
|
|
|
+ DragTable dragTable = dragTableMapper.selectDragTableByTableKey(str);
|
|
|
+ DragTableVo dragTableVo=new DragTableVo();
|
|
|
+ BeanUtils.copyProperties(dragTable, dragTableVo);
|
|
|
+ dragTableList.add( dragTableVo);
|
|
|
});
|
|
|
- //根据tableKey批量查询表格数据
|
|
|
- List<DragTableVo> dragTables = dragTableMapper.selectDragTableTableKeys(stringList).stream().map(item -> {
|
|
|
+ //查询这个动态表格的 1.条件 2.sql信息
|
|
|
+ dragTableList.stream().map(item -> {
|
|
|
//拿到这个表格的所有条件数据
|
|
|
List<DragTableCondition> dragTableConditions = dragTableConditionMapper.selectDragTableConditionByTid(item.gettId());
|
|
|
//条件
|
|
@@ -177,11 +390,16 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
item.setConditionDefaultValueMap(conditionDefaultValueMap);
|
|
|
}
|
|
|
});
|
|
|
+ //排序字段
|
|
|
+ TableSql tableSql = tableSqlMapper.selectTableSqlByTSqlKey(item.getSqlKey());
|
|
|
+ if(tableSql!=null){
|
|
|
+ item.setOrderByColumn(tableSql.getOrderByColumn());
|
|
|
+ }
|
|
|
return item;
|
|
|
}).collect(Collectors.toList());
|
|
|
DragTableGroupVo dragTableGroupVo=new DragTableGroupVo();
|
|
|
BeanUtils.copyProperties(dragTableGroupOne, dragTableGroupVo);
|
|
|
- dragTableGroupVo.setDragTables(dragTables);
|
|
|
+ dragTableGroupVo.setDragTables(dragTableList);
|
|
|
//查询表格的关联数据
|
|
|
return dragTableGroupVo;
|
|
|
}
|
|
@@ -206,4 +424,6 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|