Forráskód Böngészése

动态表格接口

xuezizhuo 1 éve
szülő
commit
2d5d6007d0

+ 11 - 4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonController.java

@@ -104,7 +104,6 @@ public class CommonController extends BaseController {
      *
      * @param response
      * @param tableName
-     * @param sqlKey
      * @throws Exception
      */
     @PostMapping("/exportTemplate")
@@ -114,13 +113,21 @@ public class CommonController extends BaseController {
 
     /**
      * 通用动态表单详情
-     *
-     * @param sqlKey
-     * @return
      */
     @GetMapping("/dragTableInfo")
     public AjaxResult dragTableInfo(CommonEntity commonEntity) {
         return AjaxResult.success(dragTableService.dragTableInfo(commonEntity.getQueryMap().get("sqlkey").toString()));
     }
 
+    /**
+     * 动态表单预览接口
+     */
+    @GetMapping("/dragTablePreview")
+    public TableDataInfo DragTablePreview(CommonEntity commonEntity){
+        startPage();
+        return getDataTable(commonService.dragTablePreview(commonEntity));
+    }
+
+
+
 }

+ 22 - 17
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableController.java

@@ -8,14 +8,7 @@ import com.ruoyi.system.entity.DragTable;
 import com.ruoyi.system.entity.vo.DragTableVo;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -84,21 +77,24 @@ public class DragTableController extends BaseController {
 //        return toAjax(dragTableService.updateDragTable(dragTable));
 //    }
 
-    /**
-     * 删除动态格
-     */
-    @Log(title = "动态格", businessType = BusinessType.DELETE)
-    @DeleteMapping("/{tIds}")
-    public AjaxResult remove(@PathVariable Long[] tIds) {
-        return toAjax(dragTableService.deleteDragTableByTIds(tIds));
-    }
+//    /**
+//     * 删除动态格
+//     */
+//    @Log(title = "动态格", businessType = BusinessType.DELETE)
+//    @DeleteMapping("/{tIds}")
+//    public AjaxResult remove(@PathVariable Long[] tIds) {
+//        return toAjax(dragTableService.deleteDragTableByTIds(tIds));
+//    }
 
     /**
      * 新增动态表格模版数据
      */
     @PostMapping("/addDragTable")
     public AjaxResult addDragTable(@RequestBody DragTableVo dragTableVo){
-        return toAjax(dragTableService.addDragTable(dragTableVo));
+        AjaxResult ajax = AjaxResult.success();
+        String sqlKey = dragTableService.addDragTable(dragTableVo);
+        ajax.put("sqlKey",sqlKey);
+        return ajax;
     }
 
     /**
@@ -118,5 +114,14 @@ 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));
+    }
+
+
 
 }

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableConditionMapper.java

@@ -57,4 +57,11 @@ public interface DragTableConditionMapper
      */
     List<String> selectDragTableSearchField(Long tId);
 
+    /**
+     * 删除动态格条件
+     * @param tIds 动态表格编号
+     * @return
+     */
+    int deleteDragTableConditionBytIds(List<Long> tIds);
+
 }

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableMapper.java

@@ -59,7 +59,7 @@ public interface DragTableMapper
      * @param tIds 需要删除的数据主键集合
      * @return 结果
      */
-    int deleteDragTableByTIds(Long[] tIds);
+    int deleteDragTableByTIds(List<Long> tIds);
 
     /**
      * 查询动态格

+ 14 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/TableSqlMapper.java

@@ -67,4 +67,18 @@ public interface TableSqlMapper {
      * @return 结果
      */
     public int deleteTableSqlByTIds(Long[] tIds);
+
+    /**
+     * 修改table 联合查询sql存储
+     *
+     * @param tableSql table 联合查询sql存储
+     * @return 结果
+     */
+    int updateTableSqlBySqlKey(TableSql tableSql);
+
+    /**
+     * 批量删除
+     */
+    int deleteTableSqlBySqlKeys(List<String> sqlKeys);
+
 }

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ICommonService.java

@@ -45,4 +45,9 @@ public interface ICommonService {
      */
     void exportTemplate(HttpServletResponse response, String tableName, String sqlKey) throws Exception;
 
+    /**
+     * 动态表单预览接口
+     */
+    List<CommonEntity> dragTablePreview(CommonEntity commonEntity);
+
 }

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

@@ -52,7 +52,7 @@ public interface IDragTableService
      * @param tIds 需要删除的动态格主键集合
      * @return 结果
      */
-    public int deleteDragTableByTIds(Long[] tIds);
+    public int deleteDragTableByTIds(List<Long> tIds);
 
     /**
      * 删除动态格信息
@@ -73,7 +73,7 @@ public interface IDragTableService
     /**
      * 新增动态表格
      */
-    int addDragTable(DragTableVo dragTableVo);
+    String addDragTable(DragTableVo dragTableVo);
 
     /**
      * 获取动态表格详情详情
@@ -84,4 +84,9 @@ public interface IDragTableService
      * 修改动态格
      */
     int updateDragTable(DragTableVo dragTableVo);
+
+    /**
+     * 删除动态格信息
+     */
+    int deleteDragTable(List<Long> tIds,List<String> sqlKeys);
 }

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java

@@ -192,6 +192,12 @@ public class CommonServiceImpl implements ICommonService {
         outputStream.close();
     }
 
+    @Override
+    public List<CommonEntity> dragTablePreview(CommonEntity commonEntity) {
+        String sql = commonEntity.getBasicMap().get("sql").toString();
+        return commonMapper.queryTableList(sql);
+    }
+
     public static String extractSubstring(String input, String identifier) {
         int startIndex = input.indexOf(identifier);
         if (startIndex == -1) {

+ 20 - 11
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableServiceImpl.java

@@ -1,9 +1,6 @@
 package com.ruoyi.system.service.impl;
 
-import java.util.ArrayList;
-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;
@@ -99,7 +96,7 @@ public class DragTableServiceImpl implements IDragTableService {
      * @return 结果
      */
     @Override
-    public int deleteDragTableByTIds(Long[] tIds) {
+    public int deleteDragTableByTIds(List<Long> tIds) {
         return dragTableMapper.deleteDragTableByTIds(tIds);
     }
 
@@ -144,7 +141,7 @@ public class DragTableServiceImpl implements IDragTableService {
 
     @Transactional
     @Override
-    public int addDragTable(DragTableVo dragTableVo) {
+    public String addDragTable(DragTableVo dragTableVo) {
         //生成dtNickname表格别名
         String dtNickname = IdUtils.fastSimpleUUID();
         //生成sqlKey唯一标识
@@ -194,7 +191,7 @@ public class DragTableServiceImpl implements IDragTableService {
         });
         dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
 
-        return 1;
+        return sqlKey;
     }
 
     @Override
@@ -241,18 +238,30 @@ public class DragTableServiceImpl implements IDragTableService {
         }
         tableSql.setTableCondition(SQL_START + SQL_END);
         tableSql.setTableAlias(dragTableVo.getDtTableName());
+        tableSql.setSqlKey(dragTableVo.getSqlKey());
         tableSql.setTableExportField(JSON.toJSONString(dragTableVo.getTableExportField()));
-
+        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));
         });
-        dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
-
+        return dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
+    }
 
-        return 0;
+    @Transactional
+    @Override
+    public int 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);
     }
 }

+ 24 - 0
ruoyi-system/src/main/resources/mapper/common/TableSqlMapper.xml

@@ -100,4 +100,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{tId}
         </foreach>
     </delete>
+
+    <update id="updateTableSqlBySqlKey">
+        update table_sql
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="tableSql != null">table_sql = #{tableSql},</if>
+            <if test="tableCondition != null">table_condition = #{tableCondition},</if>
+            <if test="tableAlias != null">table_alias = #{tableAlias},</if>
+            <if test="tableExportField != null">table_export_field = #{tableExportField},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="delFlag != null">del_flag = #{delFlag},</if>
+        </trim>
+        where sql_key = #{sqlKey}
+    </update>
+
+    <delete id="deleteTableSqlBySqlKeys" parameterType="String">
+        delete from table_sql where sql_key in
+        <foreach item="sqlKey" collection="list" open="(" separator="," close=")">
+            #{sqlKey}
+        </foreach>
+    </delete>
+
 </mapper>

+ 8 - 0
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableConditionMapper.xml

@@ -109,5 +109,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         select condition_field from drag_table_condition where t_id = #{tId}
     </select>
 
+    <delete id="deleteDragTableConditionBytIds">
+        delete from drag_table_condition where t_id in
+        <foreach item="ids" collection="list" open="(" separator="," close=")">
+            #{ids}
+        </foreach>
+    </delete>
+
+
 
 </mapper>

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

@@ -131,7 +131,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <delete id="deleteDragTableByTIds" parameterType="String">
         delete from drag_table where t_id in 
-        <foreach item="tId" collection="array" open="(" separator="," close=")">
+        <foreach item="tId" collection="list" open="(" separator="," close=")">
             #{tId}
         </foreach>
     </delete>