|
@@ -1,19 +1,11 @@
|
|
|
package com.ruoyi.business.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson2.JSON;
|
|
|
import com.ruoyi.business.entity.*;
|
|
|
-import com.ruoyi.business.entity.vo.DragTableGroupVo;
|
|
|
import com.ruoyi.business.entity.vo.DragTableVo;
|
|
|
import com.ruoyi.business.mapper.*;
|
|
|
import com.ruoyi.business.service.IDragTableService;
|
|
|
-import com.ruoyi.common.utils.DateUtils;
|
|
|
-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 org.springframework.transaction.support.TransactionTemplate;
|
|
|
-
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -27,7 +19,6 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class DragTableServiceImpl implements IDragTableService {
|
|
|
|
|
|
-
|
|
|
@Autowired
|
|
|
private DragTableMapper dragTableMapper;
|
|
|
|
|
@@ -40,9 +31,6 @@ public class DragTableServiceImpl implements IDragTableService {
|
|
|
@Resource
|
|
|
private CommonMapper commonMapper;
|
|
|
|
|
|
- @Resource
|
|
|
- private TransactionTemplate transactionTemplate;
|
|
|
-
|
|
|
@Resource
|
|
|
private DragTableStatisticMapper dragTableStatisticMapper;
|
|
|
|
|
@@ -55,6 +43,7 @@ public class DragTableServiceImpl implements IDragTableService {
|
|
|
@Resource
|
|
|
private DragTableBtnRelevanceMapper dragTableBtnRelevanceMapper;
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 查询动态表格
|
|
|
*
|
|
@@ -78,41 +67,10 @@ public class DragTableServiceImpl implements IDragTableService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 新增动态表格
|
|
|
- *
|
|
|
- * @param dragTable 动态表格
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
- @Override
|
|
|
- public int insertDragTable(DragTable dragTable) {
|
|
|
- dragTable.setCreateTime(DateUtils.getNowDate());
|
|
|
- dragTable.setCreateById(SecurityUtils.getUserId());
|
|
|
- return dragTableMapper.insertDragTable(dragTable);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量删除动态表格
|
|
|
- *
|
|
|
- * @param tIds 需要删除的动态表格主键
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
- @Override
|
|
|
- public int deleteDragTableByTIds(List<Long> tIds) {
|
|
|
- return dragTableMapper.deleteDragTableByTIds(tIds);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除动态表格信息
|
|
|
- *
|
|
|
- * @param tId 动态表格主键
|
|
|
- * @return 结果
|
|
|
+ * 根据tableKey查询动态表格
|
|
|
+ * @param tableKey 唯一标识
|
|
|
+ * @return
|
|
|
*/
|
|
|
- @Override
|
|
|
- public int deleteDragTableByTId(Long tId) {
|
|
|
- return dragTableMapper.deleteDragTableByTId(tId);
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public CommonEntity dragTableInfo(String tableKey) {
|
|
|
//DragTable dragTable = dragTableMapper.selectDragTableBySqlKey(sqlKey);
|
|
@@ -163,148 +121,11 @@ public class DragTableServiceImpl implements IDragTableService {
|
|
|
return commonEntity;
|
|
|
}
|
|
|
|
|
|
- private List<DragTableBtn> getChildrenList(DragTableBtn root, List<DragTableBtn> childNodes) {
|
|
|
- List<DragTableBtn> list = childNodes.stream().filter(dragTableBtn ->
|
|
|
- //筛选出下一节点元素
|
|
|
- Objects.equals(dragTableBtn.getBtnParentId(), root.getId())).map(dragTableBtn -> {
|
|
|
- //递归set子节点
|
|
|
- dragTableBtn.setChildren(this.getChildrenList(dragTableBtn, childNodes));
|
|
|
- return dragTableBtn;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
- // 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}%'";
|
|
|
-
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
- public void addDragTable(DragTableVo 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("0");//表格类型
|
|
|
- //add table_sql
|
|
|
- TableSql tableSql = new TableSql();
|
|
|
- tableSql.setTableSql(dragTableVo.getTableSql());
|
|
|
- dragTableMapper.insertDragTable(dragTable);
|
|
|
- // 拼接sql查询条件
|
|
|
- switch (SecurityUtils.getDatabaseType().toUpperCase()) {
|
|
|
- case "MYSQL":
|
|
|
- SQL += SQL_START;
|
|
|
- for (int i = 0; dragTableVo.getSearchFieldList().size() > i; i++) {
|
|
|
- SQL += SQL_MIDDLE.replace("#{VAL}", dragTableVo.getSearchFieldList().get(i));
|
|
|
- SQL += dragTableVo.getSearchFieldList().size() - 1 == i ? ")" : ",\n";
|
|
|
- }
|
|
|
- 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":
|
|
|
- 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' AND ";
|
|
|
- tableSql.setTableCondition(where + SQL + SQL_END);
|
|
|
- tableSql.setTableAlias(dragTableVo.getDtTableName());
|
|
|
- tableSql.setTableExportField(JSON.toJSONString(dragTableVo.getTableExportField()));
|
|
|
- tableSql.setSqlKey(dragTableVo.getSqlKey());
|
|
|
- tableSql.setOrderByColumn(dragTableVo.getOrderByColumn());
|
|
|
- tableSql.setSortOrder(dragTableVo.getSortOrder());
|
|
|
- tableSqlMapper.insertTableSql(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));
|
|
|
- });
|
|
|
- dragTableConditionList.forEach(e->{
|
|
|
- e.setCreateById(SecurityUtils.getUserId());
|
|
|
- });
|
|
|
- dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
- public void addDragTable(DragTableGroupVo dragTableGroupVo) {
|
|
|
- for (DragTableVo dragTableVo : dragTableGroupVo.getDragTables()) {
|
|
|
- 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.setTableSql(dragTableVo.getTableSql());
|
|
|
- dragTableMapper.insertDragTable(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.insertTableSql(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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 获取动态表格详情
|
|
|
+ * @param tId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public DragTableVo selectDragTableVoByTId(Long tId) {
|
|
|
DragTableVo vo = dragTableMapper.selectDragTableVoByTId(tId);
|
|
@@ -324,76 +145,31 @@ public class DragTableServiceImpl implements IDragTableService {
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ /**
|
|
|
+ * 根据tableKey获取sqlKey
|
|
|
+ * @param tableKey
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void updateDragTable(DragTableVo dragTableVo) {
|
|
|
- String SQL = "";
|
|
|
- //update drag_table
|
|
|
- DragTable dragTable = new DragTable();
|
|
|
- BeanUtils.copyProperties(dragTableVo, dragTable);
|
|
|
- dragTable.setDtColumnName(JSON.toJSONString(dragTableVo.getDtColumnName()));
|
|
|
- dragTableMapper.updateDragTable(dragTable);
|
|
|
- //update table_sql
|
|
|
- TableSql tableSql = new TableSql();
|
|
|
- tableSql.setTableSql(dragTableVo.getTableSql());
|
|
|
- // 拼接sql查询条件
|
|
|
- switch (SecurityUtils.getDatabaseType().toUpperCase()) {
|
|
|
- case "MYSQL":
|
|
|
- SQL += SQL_START;
|
|
|
- for (int i = 0; dragTableVo.getSearchFieldList().size() > i; i++) {
|
|
|
- SQL += SQL_MIDDLE.replace("#{VAL}", dragTableVo.getSearchFieldList().get(i));
|
|
|
- SQL += dragTableVo.getSearchFieldList().size() - 1 == i ? ")" : ",\n";
|
|
|
- }
|
|
|
- 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":
|
|
|
- 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' AND ";
|
|
|
- tableSql.setTableCondition(where + SQL + SQL_END);
|
|
|
- tableSql.setTableAlias(dragTableVo.getDtTableName());
|
|
|
- tableSql.setSqlKey(dragTableVo.getSqlKey());
|
|
|
- tableSql.setTableExportField(JSON.toJSONString(dragTableVo.getTableExportField()));
|
|
|
- tableSql.setOrderByColumn(dragTableVo.getOrderByColumn());
|
|
|
- tableSql.setSortOrder(dragTableVo.getSortOrder());
|
|
|
- tableSqlMapper.updateTableSqlBySqlKey(tableSql);
|
|
|
- //update drag_table_condition
|
|
|
- if (dragTableVo.getSearchFieldList().size() > 0) {
|
|
|
- //delete
|
|
|
- dragTableConditionMapper.deleteDragTableConditionBytIds(Collections.singletonList(dragTableVo.gettId()));
|
|
|
- //insert
|
|
|
- List<DragTableCondition> dragTableConditionList = new ArrayList<>();
|
|
|
- dragTableVo.getSearchFieldList().forEach(item -> {
|
|
|
- dragTableConditionList.add(new DragTableCondition(dragTable.gettId(),item));
|
|
|
- });
|
|
|
- dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
|
|
|
- }
|
|
|
+ public DragTable selectSqlKeyByTableKey(String tableKey) {
|
|
|
+ return dragTableMapper.selectDragTableByTableKey(tableKey);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
- @Override
|
|
|
- public void deleteDragTable(List<Long> tIds, List<String> sqlKeys) {
|
|
|
- // delete drag_table
|
|
|
- dragTableMapper.deleteDragTableByTIds(tIds);
|
|
|
- //delete table_sql
|
|
|
- tableSqlMapper.deleteTableSqlBySqlKeys(sqlKeys);
|
|
|
- //delete drag_table_condition
|
|
|
- dragTableConditionMapper.deleteDragTableConditionBytIds(tIds);
|
|
|
+ /**
|
|
|
+ * 表格按钮过滤子级
|
|
|
+ * @param root
|
|
|
+ * @param childNodes
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<DragTableBtn> getChildrenList(DragTableBtn root, List<DragTableBtn> childNodes) {
|
|
|
+ List<DragTableBtn> list = childNodes.stream().filter(dragTableBtn ->
|
|
|
+ //筛选出下一节点元素
|
|
|
+ Objects.equals(dragTableBtn.getBtnParentId(), root.getId())).map(dragTableBtn -> {
|
|
|
+ //递归set子节点
|
|
|
+ dragTableBtn.setChildren(this.getChildrenList(dragTableBtn, childNodes));
|
|
|
+ return dragTableBtn;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public DragTable selectSqlKeyByTableKey(String tableKey) {
|
|
|
- return dragTableMapper.selectDragTableByTableKey(tableKey);
|
|
|
- }
|
|
|
}
|