فهرست منبع

Merge remote-tracking branch 'origin/main' into main

侯茂昌 1 سال پیش
والد
کامیت
c7cbd07a4a

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

@@ -7,6 +7,7 @@ import javax.servlet.http.HttpServletResponse;
 import com.ruoyi.common.annotation.Anonymous;
 import com.ruoyi.system.entity.DragTable;
 import com.ruoyi.system.entity.vo.DragTableVo;
+import com.ruoyi.system.service.IDragTableStatisticService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -30,6 +31,9 @@ public class DragTableController extends BaseController {
     @Autowired
     private IDragTableService dragTableService;
 
+    @Autowired
+    private IDragTableStatisticService dragTableStatisticService;
+
     /**
      * 查询动态表格列表
      */
@@ -119,7 +123,9 @@ public class DragTableController extends BaseController {
     public AjaxResult remove(@RequestBody Map<String,Object> map) {
         List<Long> tIds = (List<Long>) map.get("tIds");
         List<String> sqlKeys = (List<String>) map.get("sqlKeys");
+        List<String> tableKeys = (List<String>)map.get("tableKeys");
         dragTableService.deleteDragTable(tIds,sqlKeys);
+        dragTableStatisticService.deleteDragTableStatisticByTableKeys(tableKeys);
         return AjaxResult.success();
     }
 

+ 2 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableStatisticController.java

@@ -93,7 +93,8 @@ public class DragTableStatisticController extends BaseController
     @ApiOperation(value = "修改动态表格统计")
     public AjaxResult edit(@RequestBody DragTableVo vo)
     {
-        return toAjax(dragTableStatisticService.updateDragTableStatistic(vo));
+        dragTableStatisticService.updateDragTableStatistic(vo);
+        return AjaxResult.success();
     }
 
     /**

+ 20 - 3
ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableStatisticMapper.java

@@ -39,10 +39,10 @@ public interface DragTableStatisticMapper
     /**
      * 修改动态表格统计
      * 
-     * @param dragTableStatistic 动态表格统计
+     * @param dragTableStatisticList 动态表格统计
      * @return 结果
      */
-    int updateDragTableStatistic(DragTableStatistic dragTableStatistic);
+    int batchUpdateDragTableStatistic(List<DragTableStatistic> dragTableStatisticList);
 
     /**
      * 删除动态表格统计
@@ -52,12 +52,29 @@ public interface DragTableStatisticMapper
      */
     int deleteDragTableStatisticByTableKey(String tableKey);
 
+    /**
+     * 批量删除动态表格统计
+     *
+     * @param tableKeys 动态表格统计主键
+     * @return 结果
+     */
+    int deleteDragTableStatisticByTableKeys(List<String> tableKeys);
+
     /**
      * 批量删除动态表格统计
      * 
      * @param ids 需要删除的数据主键集合
      * @return 结果
      */
-    int deleteDragTableStatisticByIds(Long[] ids);
+    int deleteDragTableStatisticByIds(List<Long> ids);
+
+    /**
+     * 根据tableKey查询统计编号
+     */
+    List<Long> selectIdsByTableKey(String tableKey);
 
+    /**
+     * 根据tableKey查询sqlKey
+     */
+    List<String> selectSqlKeyByTableKey(String tableKey);
 }

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

@@ -89,4 +89,5 @@ public interface TableSqlMapper {
      */
     int batchInsertTableSql(List<TableSql> tableSqlList);
 
+
 }

+ 7 - 9
ruoyi-system/src/main/java/com/ruoyi/system/service/IDragTableStatisticService.java

@@ -46,15 +46,7 @@ public interface IDragTableStatisticService
      * @param vo 动态表格统计
      * @return 结果
      */
-    int updateDragTableStatistic(DragTableVo vo);
-
-    /**
-     * 批量删除动态表格统计
-     * 
-     * @param ids 需要删除的动态表格统计主键集合
-     * @return 结果
-     */
-    int deleteDragTableStatisticByIds(Long[] ids);
+    void updateDragTableStatistic(DragTableVo vo);
 
     /**
      * 删除动态表格统计信息
@@ -64,6 +56,12 @@ public interface IDragTableStatisticService
      */
     int deleteDragTableStatisticByTableKey(String tableKey);
 
+    /**
+     * 批量删除动态表格通
+     */
+    void deleteDragTableStatisticByTableKeys(List<String> tableKeys);
+
+
     /**
      * 根据tableKey获取详情
      * @return

+ 88 - 11
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableStatisticServiceImpl.java

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

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

@@ -163,5 +163,4 @@
     </delete>
 
 
-
 </mapper>

+ 30 - 13
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableStatisticMapper.xml

@@ -50,30 +50,47 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
     </insert>
 
-    <update id="updateDragTableStatistic" parameterType="com.ruoyi.system.entity.DragTableStatistic">
+    <update id="batchUpdateDragTableStatistic">
+        <foreach collection="list" item="item" separator=";">
         update drag_table_statistic
         <trim prefix="SET" suffixOverrides=",">
-            <if test="statisticTitle != null">statistic_title = #{statisticTitle},</if>
-            <if test="tableKey != null">table_key = #{tableKey},</if>
-            <if test="statisticDescription != null">statistic_description = #{statisticDescription},</if>
-            <if test="statisticType != null">statistic_type = #{statisticType},</if>
-            <if test="statisticField != null">statistic_field = #{statisticField},</if>
-            <if test="statisticObject != null">statistic_object = #{statisticObject},</if>
-            <if test="sqlKey != null">sql_key = #{sqlKey},</if>
-            <if test="updateBy != null">update_by = #{updateBy},</if>
-            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="item.statisticTitle != null">statistic_title = #{item.statisticTitle},</if>
+            <if test="item.tableKey != null">table_key = #{item.tableKey},</if>
+            <if test="item.statisticDescription != null">statistic_description = #{item.statisticDescription},</if>
+            <if test="item.statisticType != null">statistic_type = #{item.statisticType},</if>
+            <if test="item.statisticField != null">statistic_field = #{item.statisticField},</if>
+            <if test="item.statisticObject != null">statistic_object = #{item.statisticObject},</if>
+            <if test="item.sqlKey != null">sql_key = #{item.sqlKey},</if>
+            <if test="item.updateBy != null">update_by = #{item.updateBy},</if>
+            <if test="item.updateTime != null">update_time = #{item.updateTime},</if>
         </trim>
-        where id = #{id}
+        where id = #{item.id}
+        </foreach>
     </update>
 
     <update id="deleteDragTableStatisticByTableKey" parameterType="String">
         update drag_table_statistic set del_flag = '2' where table_key = #{tableKey}
     </update>
 
-    <delete id="deleteDragTableStatisticByIds" parameterType="String">
+    <update id="deleteDragTableStatisticByTableKeys" parameterType="String">
+        update drag_table_statistic set del_flag = '2' where table_key in
+        <foreach collection="list" item="tableKey" open="(" close=")" separator=",">
+            #{tableKey}
+        </foreach>
+    </update>
+
+    <delete id="deleteDragTableStatisticByIds">
         update drag_table_statistic set del_flag = '2' where id in
-        <foreach item="id" collection="array" open="(" separator="," close=")">
+        <foreach item="id" collection="list" open="(" separator="," close=")">
             #{id}
         </foreach>
     </delete>
+
+    <select id="selectIdsByTableKey" parameterType="String" resultType="Long">
+        select id from drag_table_statistic where del_flag = '0' and table_key = #{tableKey}
+    </select>
+
+    <select id="selectSqlKeyByTableKey" parameterType="String" resultType="String">
+        select sql_key from drag_table_statistic where del_flag = '0' and table_key = #{tableKey}
+    </select>
 </mapper>