Browse Source

修改动态表格接口

xuezizhuo 1 năm trước cách đây
mục cha
commit
5165ae5815

+ 6 - 8
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableController.java

@@ -91,10 +91,8 @@ public class DragTableController extends BaseController {
      */
     @PostMapping("/addDragTable")
     public AjaxResult addDragTable(@RequestBody DragTableVo dragTableVo){
-        AjaxResult ajax = AjaxResult.success();
-        String sqlKey = dragTableService.addDragTable(dragTableVo);
-        ajax.put("sqlKey",sqlKey);
-        return ajax;
+        dragTableService.addDragTable(dragTableVo);
+        return AjaxResult.success();
     }
 
     /**
@@ -110,7 +108,8 @@ public class DragTableController extends BaseController {
      */
     @PutMapping("/edit")
     public AjaxResult edit(@RequestBody DragTableVo dragTableVo) {
-        return toAjax(dragTableService.updateDragTable(dragTableVo));
+        dragTableService.updateDragTable(dragTableVo);
+        return AjaxResult.success();
     }
 
 
@@ -119,9 +118,8 @@ public class DragTableController extends BaseController {
      */
     @DeleteMapping("/remove")
     public AjaxResult remove(@RequestParam("tIds") List<Long> tIds,@RequestParam("sqlKeys") List<String> sqlKeys) {
-        return toAjax(dragTableService.deleteDragTable(tIds,sqlKeys));
+        dragTableService.deleteDragTable(tIds,sqlKeys);
+        return AjaxResult.success();
     }
 
-
-
 }

+ 3 - 3
ruoyi-system/src/main/java/com/ruoyi/system/service/IDragTableService.java

@@ -73,7 +73,7 @@ public interface IDragTableService
     /**
      * 新增动态表格
      */
-    String addDragTable(DragTableVo dragTableVo);
+    void addDragTable(DragTableVo dragTableVo);
 
     /**
      * 获取动态表格详情详情
@@ -83,10 +83,10 @@ public interface IDragTableService
     /**
      * 修改动态格
      */
-    int updateDragTable(DragTableVo dragTableVo);
+    void updateDragTable(DragTableVo dragTableVo);
 
     /**
      * 删除动态格信息
      */
-    int deleteDragTable(List<Long> tIds,List<String> sqlKeys);
+    void deleteDragTable(List<Long> tIds,List<String> sqlKeys);
 }

+ 30 - 21
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableServiceImpl.java

@@ -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);
     }
 }

+ 2 - 6
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableMapper.xml

@@ -77,10 +77,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="spare1 != null">spare1,</if>
             <if test="delFlag != null">del_flag,</if>
             <if test="createBy != null">create_by,</if>
-            <if test="createTime != null">create_time,</if>
-            <if test="updateBy != null">update_by,</if>
-            <if test="updateTime != null">update_time,</if>
             <if test="isSelection != null">is_selection,</if>
+            create_time
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="dtName != null">#{dtName},</if>
@@ -95,10 +93,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="spare1 != null">#{spare1},</if>
             <if test="delFlag != null">#{delFlag},</if>
             <if test="createBy != null">#{createBy},</if>
-            <if test="createTime != null">#{createTime},</if>
-            <if test="updateBy != null">#{updateBy},</if>
-            <if test="updateTime != null">#{updateTime},</if>
             <if test="isSelection != null">#{isSelection},</if>
+            now()
          </trim>
     </insert>