|
@@ -1,5 +1,6 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
+import java.sql.SQLSyntaxErrorException;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -19,7 +20,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.system.mapper.DragTableMapper;
|
|
|
import com.ruoyi.system.service.IDragTableService;
|
|
|
+import org.springframework.transaction.TransactionStatus;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
|
|
+import org.springframework.transaction.support.TransactionTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
@@ -43,6 +48,9 @@ public class DragTableServiceImpl implements IDragTableService {
|
|
|
@Resource
|
|
|
private CommonMapper commonMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private TransactionTemplate transactionTemplate;
|
|
|
+
|
|
|
/**
|
|
|
* 查询动态格
|
|
|
*
|
|
@@ -141,7 +149,7 @@ public class DragTableServiceImpl implements IDragTableService {
|
|
|
|
|
|
@Transactional
|
|
|
@Override
|
|
|
- public String addDragTable(DragTableVo dragTableVo) {
|
|
|
+ public void addDragTable(DragTableVo dragTableVo) {
|
|
|
//生成dtNickname表格别名
|
|
|
String dtNickname = IdUtils.fastSimpleUUID();
|
|
|
//生成sqlKey唯一标识
|
|
@@ -178,20 +186,20 @@ public class DragTableServiceImpl implements IDragTableService {
|
|
|
SQL_START += dragTableVo.getSearchFieldList().size() - 1 == i ? " " : "||";
|
|
|
}
|
|
|
break;
|
|
|
- }
|
|
|
+ }
|
|
|
tableSql.setTableCondition(SQL_START + SQL_END);
|
|
|
tableSql.setTableAlias(dragTableVo.getDtTableName());
|
|
|
tableSql.setSqlKey(sqlKey);
|
|
|
tableSql.setTableExportField(JSON.toJSONString(dragTableVo.getTableExportField()));
|
|
|
tableSqlMapper.insertTableSql(tableSql);
|
|
|
//add drag_table_condition
|
|
|
- List<DragTableCondition> dragTableConditionList = new ArrayList<>();
|
|
|
- dragTableVo.getSearchFieldList().forEach(item -> {
|
|
|
- dragTableConditionList.add(new DragTableCondition(dragTable.gettId(), item));
|
|
|
- });
|
|
|
- dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
|
|
|
-
|
|
|
- return sqlKey;
|
|
|
+ if(dragTableVo.getSearchFieldList().size() > 0 ){
|
|
|
+ List<DragTableCondition> dragTableConditionList = new ArrayList<>();
|
|
|
+ dragTableVo.getSearchFieldList().forEach(item -> {
|
|
|
+ dragTableConditionList.add(new DragTableCondition(dragTable.gettId(), item));
|
|
|
+ });
|
|
|
+ dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -203,7 +211,7 @@ public class DragTableServiceImpl implements IDragTableService {
|
|
|
|
|
|
@Transactional
|
|
|
@Override
|
|
|
- public int updateDragTable(DragTableVo dragTableVo) {
|
|
|
+ public void updateDragTable(DragTableVo dragTableVo) {
|
|
|
//update drag_table
|
|
|
DragTable dragTable = new DragTable();
|
|
|
BeanUtils.copyProperties(dragTableVo, dragTable);
|
|
@@ -243,25 +251,26 @@ public class DragTableServiceImpl implements IDragTableService {
|
|
|
tableSqlMapper.updateTableSqlBySqlKey(tableSql);
|
|
|
|
|
|
//update drag_table_condition
|
|
|
- //delete
|
|
|
- dragTableConditionMapper.deleteDragTableConditionBytIds(Collections.singletonList(dragTableVo.gettId()));
|
|
|
-
|
|
|
- //insert
|
|
|
- List<DragTableCondition> dragTableConditionList = new ArrayList<>();
|
|
|
- dragTableVo.getSearchFieldList().forEach(item -> {
|
|
|
- dragTableConditionList.add(new DragTableCondition(dragTableVo.gettId(), item));
|
|
|
- });
|
|
|
- return dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
|
|
|
+ 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(dragTableVo.gettId(), item));
|
|
|
+ });
|
|
|
+ dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
@Override
|
|
|
- public int deleteDragTable(List<Long> tIds, List<String> sqlKeys) {
|
|
|
+ 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
|
|
|
- return dragTableConditionMapper.deleteDragTableConditionBytIds(tIds);
|
|
|
+ dragTableConditionMapper.deleteDragTableConditionBytIds(tIds);
|
|
|
}
|
|
|
}
|