|
@@ -1,8 +1,6 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
@@ -72,7 +70,6 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
|
|
|
public int batchInsertDragTableStatistic(DragTableVo vo)
|
|
|
{
|
|
|
vo.getDragTableStatisticList().forEach(s -> s.setCreateBy(SecurityUtils.getUserId().toString()));
|
|
|
-
|
|
|
// 拼接sql查询条件
|
|
|
String SQL = "";
|
|
|
switch (SecurityUtils.getDatabaseType().toUpperCase()) {
|
|
@@ -107,15 +104,90 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int updateDragTableStatistic(DragTableVo vo)
|
|
|
+ @Transactional
|
|
|
+ public void updateDragTableStatistic(DragTableVo vo)
|
|
|
{
|
|
|
- return 1;
|
|
|
- }
|
|
|
+ // 拼接sql查询条件
|
|
|
+ String SQL = "";
|
|
|
+ switch (SecurityUtils.getDatabaseType().toUpperCase()) {
|
|
|
+ case "MYSQL":
|
|
|
+ SQL += SQL_START;
|
|
|
+ for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
|
|
|
+ SQL += SQL_MIDDLE.replace("#{VAL}", vo.getSearchFieldList().get(i));
|
|
|
+ SQL += vo.getSearchFieldList().size() - 1 == i ? ")" : ",\n";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "DM":
|
|
|
+ case "SQLSERVER":
|
|
|
+ SQL += SQL_START;
|
|
|
+ for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
|
|
|
+ SQL += SQL_DM_SERVER_MIDDLE.replace("#{VAL}", vo.getSearchFieldList().get(i));
|
|
|
+ SQL += vo.getSearchFieldList().size() - 1 == i ? ",'')" : ",\n";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "ORACLE":
|
|
|
+// SQL_START = "";
|
|
|
+ for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
|
|
|
+ SQL += vo.getSearchFieldList().get(i);
|
|
|
+ SQL += (vo.getSearchFieldList().size() - 1 == i ? " " : "||");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String sql = vo.getDtTableName() + ".del_flag = '0' AND "+ SQL + SQL_END;
|
|
|
+
|
|
|
+ LinkedList<DragTableStatistic> addList = new LinkedList<>();
|
|
|
+ LinkedList<DragTableStatistic> editList = new LinkedList<>();
|
|
|
+ List<Long> numList = new ArrayList<>();
|
|
|
+ vo.getDragTableStatisticList().stream().forEach(s -> {
|
|
|
+ if(s.getId() == null){
|
|
|
+ s.setCreateBy(SecurityUtils.getUserId().toString());
|
|
|
+ s.setCreateTime(DateUtils.getNowDate());
|
|
|
+ addList.add(s);
|
|
|
+ }else {
|
|
|
+ s.setUpdateBy(SecurityUtils.getUserId().toString());
|
|
|
+ s.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ editList.add(s);
|
|
|
+ }
|
|
|
+ numList.add(s.getId());
|
|
|
+ });
|
|
|
+ //select Statistic ids
|
|
|
+ List<Long> allIds = dragTableStatisticMapper.selectIdsByTableKey(vo.getTableKey());
|
|
|
+ allIds.removeAll(numList);
|
|
|
+ //remove Statistic
|
|
|
+ if(allIds.size() > 0){
|
|
|
+ dragTableStatisticMapper.deleteDragTableStatisticByIds(allIds);
|
|
|
+ }
|
|
|
+ //add Statistic
|
|
|
+ if(addList.size() > 0){
|
|
|
+ dragTableStatisticMapper.batchInsertDragTableStatistic(addList);
|
|
|
+ }
|
|
|
+ //update Statistic
|
|
|
+ if(editList.size() > 0){
|
|
|
+ dragTableStatisticMapper.batchUpdateDragTableStatistic(editList);
|
|
|
+
|
|
|
+ }
|
|
|
+ // select Statistic sqlKey
|
|
|
+ List<String> allSqlKey = dragTableStatisticMapper.selectSqlKeyByTableKey(vo.getTableKey());
|
|
|
+
|
|
|
+ if(vo.getTableSqlList().size() > 0){
|
|
|
+ vo.getTableSqlList().stream().forEach(t -> {
|
|
|
+ t.setCreateBy(SecurityUtils.getUserId().toString());
|
|
|
+ t.setCreateTime(DateUtils.getNowDate());
|
|
|
+ t.setTableCondition(sql);
|
|
|
+ });
|
|
|
+ if(allSqlKey.size() > 0){
|
|
|
+ //remove tableSql
|
|
|
+ tableSqlMapper.deleteTableSqlBySqlKeys(allSqlKey);
|
|
|
+ }
|
|
|
+ //add tableSql
|
|
|
+ tableSqlMapper.batchInsertTableSql(vo.getTableSqlList());
|
|
|
+ }else {
|
|
|
+ if(allSqlKey.size() > 0){
|
|
|
+ //remove tableSql
|
|
|
+ tableSqlMapper.deleteTableSqlBySqlKeys(allSqlKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public int deleteDragTableStatisticByIds(Long[] ids)
|
|
|
- {
|
|
|
- return dragTableStatisticMapper.deleteDragTableStatisticByIds(ids);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -124,6 +196,11 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
|
|
|
return dragTableStatisticMapper.deleteDragTableStatisticByTableKey(tableKey);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void deleteDragTableStatisticByTableKeys(List<String> tableKeys) {
|
|
|
+ dragTableStatisticMapper.deleteDragTableStatisticByTableKeys(tableKeys);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, Object> getInfoBySqlKey(String tableKey) {
|
|
|
Map<String,Object> map = new HashMap<>();
|