Browse Source

feat:动态表格统计新增、回显、删除接口

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

+ 131 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableStatisticController.java

@@ -0,0 +1,131 @@
+package com.ruoyi.web.controller.dragForm;
+
+import java.util.List;
+import java.util.Map;
+import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.system.entity.CommonEntity;
+import com.ruoyi.system.entity.DragTableStatistic;
+import com.ruoyi.system.entity.vo.DragTableVo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
+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;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.system.service.IDragTableStatisticService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+
+/**
+ * 动态表格统计Controller
+ *
+ * @author ruoyi
+ * @date 2023-10-27
+ */
+@RestController
+@RequestMapping("/system/statistic")
+@Api(value = "/system/statistic", description = "动态表格统计-接口")
+public class DragTableStatisticController extends BaseController
+{
+    @Autowired
+    private IDragTableStatisticService dragTableStatisticService;
+
+/**
+ * 查询动态表格统计列表
+ */
+@PreAuthorize("@ss.hasPermi('system:statistic:list')")
+@GetMapping("/list")
+@ApiOperation(value = "查询动态表格统计列表")
+    public TableDataInfo list(DragTableStatistic dragTableStatistic)
+    {
+        startPage();
+        List<DragTableStatistic> list = dragTableStatisticService.selectDragTableStatisticList(dragTableStatistic);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出动态表格统计列表
+     */
+    @PreAuthorize("@ss.hasPermi('system:statistic:export')")
+    @Log(title = "动态表格统计", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    @ApiOperation(value = "导出动态表格统计列表")
+    public void export(HttpServletResponse response, DragTableStatistic dragTableStatistic)
+    {
+        List<DragTableStatistic> list = dragTableStatisticService.selectDragTableStatisticList(dragTableStatistic);
+        ExcelUtil<DragTableStatistic> util = new ExcelUtil<DragTableStatistic>(DragTableStatistic.class);
+        util.exportExcel(response, list, "动态表格统计数据");
+    }
+
+    /**
+     * 获取动态表格统计详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('system:statistic:query')")
+    @GetMapping(value = "/{id}")
+    @ApiOperation(value = "获取动态表格统计详细信息")
+    public AjaxResult getInfo(@PathVariable("id") Long id)
+    {
+        return success(dragTableStatisticService.selectDragTableStatisticById(id));
+    }
+
+    /**
+     * 新增动态表格统计
+     */
+    @PreAuthorize("@ss.hasPermi('system:statistic:add')")
+    @Log(title = "动态表格统计", businessType = BusinessType.INSERT)
+    @PostMapping
+    @ApiOperation(value = "新增动态表格统计")
+    public AjaxResult add(@RequestBody DragTableVo vo)
+    {
+        return toAjax(dragTableStatisticService.batchInsertDragTableStatistic(vo));
+    }
+
+    /**
+     * 修改动态表格统计
+     */
+    @PreAuthorize("@ss.hasPermi('system:statistic:edit')")
+    @Log(title = "动态表格统计", businessType = BusinessType.UPDATE)
+    @PutMapping
+    @ApiOperation(value = "修改动态表格统计")
+    public AjaxResult edit(@RequestBody DragTableVo vo)
+    {
+        return toAjax(dragTableStatisticService.updateDragTableStatistic(vo));
+    }
+
+    /**
+     * 删除动态表格统计
+     */
+    @PreAuthorize("@ss.hasPermi('system:statistic:remove')")
+    @Log(title = "动态表格统计", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{tableKey}")
+    @ApiOperation(value = "删除动态表格统计")
+    public AjaxResult remove(@PathVariable String tableKey)
+    {
+        return toAjax(dragTableStatisticService.deleteDragTableStatisticByTableKey(tableKey));
+    }
+
+    /**
+     * 获取动态表格统计详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('system:statistic:query')")
+    @GetMapping("/getInfoBySqlKey")
+    @ApiOperation(value = "获取动态表格统计详细信息")
+    public AjaxResult getInfoBySqlKey(@RequestParam("sqlKey") String sqlKey)
+    {
+        return success(dragTableStatisticService.getInfoBySqlKey(sqlKey));
+    }
+
+    /**
+     * 获取列表统计信息
+     */
+    @GetMapping("/getStatisticList")
+    public AjaxResult getStatisticList(CommonEntity commonEntity){
+        return AjaxResult.success(dragTableStatisticService.getStatisticList(commonEntity));
+    }
+
+
+}

+ 51 - 50
ruoyi-system/src/main/java/com/ruoyi/system/entity/DragTableStatistic.java

@@ -6,7 +6,7 @@ import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.BaseEntity;
 
 /**
- * 动态格统计对象 drag_table_statistic
+ * 动态格统计对象 drag_table_statistic
  * 
  * @author ruoyi
  * @date 2023-10-27
@@ -32,7 +32,7 @@ public class DragTableStatistic extends BaseEntity
 
     /** 统计类型 */
     @Excel(name = "统计类型")
-    private Long statisticType;
+    private String statisticType;
 
     /** 统计字段 */
     @Excel(name = "统计字段")
@@ -44,91 +44,92 @@ public class DragTableStatistic extends BaseEntity
 
     /** 执行sql */
     @Excel(name = "执行sql")
-    private String executeSql;
+    private String sqlKey;
 
     /** 删除标志(0:否;2:是) */
     private String delFlag;
 
-    public void setId(Long id) 
-    {
+    //执行sql返回结果
+    private Object result;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
         this.id = id;
     }
 
-    public Long getId() 
-    {
-        return id;
+    public String getStatisticTitle() {
+        return statisticTitle;
     }
-    public void setStatisticTitle(String statisticTitle) 
-    {
+
+    public void setStatisticTitle(String statisticTitle) {
         this.statisticTitle = statisticTitle;
     }
 
-    public String getStatisticTitle() 
-    {
-        return statisticTitle;
+    public String getTableKey() {
+        return tableKey;
     }
-    public void setTableKey(String tableKey) 
-    {
+
+    public void setTableKey(String tableKey) {
         this.tableKey = tableKey;
     }
 
-    public String getTableKey() 
-    {
-        return tableKey;
+    public String getStatisticDescription() {
+        return statisticDescription;
     }
-    public void setStatisticDescription(String statisticDescription) 
-    {
+
+    public void setStatisticDescription(String statisticDescription) {
         this.statisticDescription = statisticDescription;
     }
 
-    public String getStatisticDescription() 
-    {
-        return statisticDescription;
+    public String getStatisticType() {
+        return statisticType;
     }
-    public void setStatisticType(Long statisticType) 
-    {
+
+    public void setStatisticType(String statisticType) {
         this.statisticType = statisticType;
     }
 
-    public Long getStatisticType() 
-    {
-        return statisticType;
+    public String getStatisticField() {
+        return statisticField;
     }
-    public void setStatisticField(String statisticField) 
-    {
+
+    public void setStatisticField(String statisticField) {
         this.statisticField = statisticField;
     }
 
-    public String getStatisticField() 
-    {
-        return statisticField;
+    public String getStatisticObject() {
+        return statisticObject;
     }
-    public void setStatisticObject(String statisticObject) 
-    {
+
+    public void setStatisticObject(String statisticObject) {
         this.statisticObject = statisticObject;
     }
 
-    public String getStatisticObject() 
-    {
-        return statisticObject;
+    public String getSqlKey() {
+        return sqlKey;
     }
-    public void setExecuteSql(String executeSql) 
-    {
-        this.executeSql = executeSql;
+
+    public void setSqlKey(String sqlKey) {
+        this.sqlKey = sqlKey;
     }
 
-    public String getExecuteSql() 
-    {
-        return executeSql;
+    public String getDelFlag() {
+        return delFlag;
     }
-    public void setDelFlag(String delFlag) 
-    {
+
+    public void setDelFlag(String delFlag) {
         this.delFlag = delFlag;
     }
 
-    public String getDelFlag() 
-    {
-        return delFlag;
+    public Object getResult() {
+        return result;
+    }
+
+    public void setResult(Object result) {
+        this.result = result;
     }
 
     @Override
@@ -141,7 +142,7 @@ public class DragTableStatistic extends BaseEntity
             .append("statisticType", getStatisticType())
             .append("statisticField", getStatisticField())
             .append("statisticObject", getStatisticObject())
-            .append("executeSql", getExecuteSql())
+            .append("sqlKey", getSqlKey())
             .append("delFlag", getDelFlag())
             .append("createBy", getCreateBy())
             .append("createTime", getCreateTime())

+ 15 - 1
ruoyi-system/src/main/java/com/ruoyi/system/entity/vo/DragTableVo.java

@@ -3,6 +3,7 @@ package com.ruoyi.system.entity.vo;
 import com.ruoyi.common.annotation.Excel;
 import com.ruoyi.common.core.domain.BaseEntity;
 import com.ruoyi.system.entity.DragTableStatistic;
+import com.ruoyi.system.entity.TableSql;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 
@@ -113,6 +114,9 @@ public class DragTableVo {
     /** 表格统计 */
     private List<DragTableStatistic> dragTableStatisticList;
 
+    /** tableList */
+    private List<TableSql> tableSqlList;
+
     public Long gettId() {
         return tId;
     }
@@ -273,10 +277,18 @@ public class DragTableVo {
         this.dragTableStatisticList = dragTableStatisticList;
     }
 
+    public List<TableSql> getTableSqlList() {
+        return tableSqlList;
+    }
+
+    public void setTableSqlList(List<TableSql> tableSqlList) {
+        this.tableSqlList = tableSqlList;
+    }
+
     public DragTableVo() {
     }
 
-    public DragTableVo(Long tId, String dtName, String dtNickname, String tableKey, String sqlKey, String dtTableName, Object dtColumnName, String dtColumnNameEcho, String timeFormat, String isSelection, List<String> searchFieldList, String tableSql, Object tableExportField, String tableExportFieldEcho, String echoData, Long menuId, String primaryKey, String orderByColumn, String sortOrder, List<DragTableStatistic> dragTableStatisticList) {
+    public DragTableVo(Long tId, String dtName, String dtNickname, String tableKey, String sqlKey, String dtTableName, Object dtColumnName, String dtColumnNameEcho, String timeFormat, String isSelection, List<String> searchFieldList, String tableSql, Object tableExportField, String tableExportFieldEcho, String echoData, Long menuId, String primaryKey, String orderByColumn, String sortOrder, List<DragTableStatistic> dragTableStatisticList, List<TableSql> tableSqlList) {
         this.tId = tId;
         this.dtName = dtName;
         this.dtNickname = dtNickname;
@@ -297,6 +309,7 @@ public class DragTableVo {
         this.orderByColumn = orderByColumn;
         this.sortOrder = sortOrder;
         this.dragTableStatisticList = dragTableStatisticList;
+        this.tableSqlList = tableSqlList;
     }
 
     @Override
@@ -322,6 +335,7 @@ public class DragTableVo {
                 ", orderByColumn='" + orderByColumn + '\'' +
                 ", sortOrder='" + sortOrder + '\'' +
                 ", dragTableStatisticList=" + dragTableStatisticList +
+                ", tableSqlList=" + tableSqlList +
                 '}';
     }
 }

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

@@ -5,7 +5,7 @@ import com.ruoyi.system.entity.DragTableStatistic;
 import java.util.List;
 
 /**
- * 动态格统计Mapper接口
+ * 动态格统计Mapper接口
  * 
  * @author ruoyi
  * @date 2023-10-27
@@ -13,47 +13,47 @@ import java.util.List;
 public interface DragTableStatisticMapper 
 {
     /**
-     * 查询动态格统计
+     * 查询动态格统计
      * 
-     * @param id 动态格统计主键
-     * @return 动态格统计
+     * @param id 动态格统计主键
+     * @return 动态格统计
      */
     DragTableStatistic selectDragTableStatisticById(Long id);
 
     /**
-     * 查询动态格统计列表
+     * 查询动态格统计列表
      * 
-     * @param dragTableStatistic 动态格统计
-     * @return 动态格统计集合
+     * @param dragTableStatistic 动态格统计
+     * @return 动态格统计集合
      */
     List<DragTableStatistic> selectDragTableStatisticList(DragTableStatistic dragTableStatistic);
 
     /**
-     * 新增动态格统计
+     * 新增动态格统计
      * 
-     * @param dragTableStatisticList 动态格统计
+     * @param dragTableStatisticList 动态格统计
      * @return 结果
      */
     int batchInsertDragTableStatistic(List<DragTableStatistic> dragTableStatisticList);
 
     /**
-     * 修改动态格统计
+     * 修改动态格统计
      * 
-     * @param dragTableStatistic 动态格统计
+     * @param dragTableStatistic 动态格统计
      * @return 结果
      */
     int updateDragTableStatistic(DragTableStatistic dragTableStatistic);
 
     /**
-     * 删除动态格统计
+     * 删除动态格统计
      * 
-     * @param id 动态格统计主键
+     * @param tableKey 动态表格统计主键
      * @return 结果
      */
-    int deleteDragTableStatisticById(Long id);
+    int deleteDragTableStatisticByTableKey(String tableKey);
 
     /**
-     * 批量删除动态格统计
+     * 批量删除动态格统计
      * 
      * @param ids 需要删除的数据主键集合
      * @return 结果

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

@@ -81,4 +81,12 @@ public interface TableSqlMapper {
      */
     int deleteTableSqlBySqlKeys(List<String> sqlKeys);
 
+    /**
+     * 新增table 联合查询sql存储
+     *
+     * @param tableSqlList table 联合查询sql存储
+     * @return 结果
+     */
+    int batchInsertTableSql(List<TableSql> tableSqlList);
+
 }

+ 77 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IDragTableStatisticService.java

@@ -0,0 +1,77 @@
+package com.ruoyi.system.service;
+
+import com.ruoyi.system.entity.CommonEntity;
+import com.ruoyi.system.entity.DragTableStatistic;
+import com.ruoyi.system.entity.vo.DragTableVo;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 动态表格统计Service接口
+ * 
+ * @author ruoyi
+ * @date 2023-10-27
+ */
+public interface IDragTableStatisticService 
+{
+    /**
+     * 查询动态表格统计
+     * 
+     * @param id 动态表格统计主键
+     * @return 动态表格统计
+     */
+    DragTableStatistic selectDragTableStatisticById(Long id);
+
+    /**
+     * 查询动态表格统计列表
+     * 
+     * @param dragTableStatistic 动态表格统计
+     * @return 动态表格统计集合
+     */
+    List<DragTableStatistic> selectDragTableStatisticList(DragTableStatistic dragTableStatistic);
+
+    /**
+     * 新增动态表格统计
+     * 
+     * @param vo 动态表格统计
+     * @return 结果
+     */
+    int batchInsertDragTableStatistic(DragTableVo vo);
+
+    /**
+     * 修改动态表格统计
+     * 
+     * @param vo 动态表格统计
+     * @return 结果
+     */
+    int updateDragTableStatistic(DragTableVo vo);
+
+    /**
+     * 批量删除动态表格统计
+     * 
+     * @param ids 需要删除的动态表格统计主键集合
+     * @return 结果
+     */
+    int deleteDragTableStatisticByIds(Long[] ids);
+
+    /**
+     * 删除动态表格统计信息
+     * 
+     * @param tableKey 动态表格统计主键
+     * @return 结果
+     */
+    int deleteDragTableStatisticByTableKey(String tableKey);
+
+    /**
+     * 根据tableKey获取详情
+     * @return
+     */
+    Map<String,Object> getInfoBySqlKey(String tableKey);
+
+    /**
+     * 根据tableKey获取统计列表
+     */
+    List<DragTableStatistic> getStatisticList(CommonEntity commonEntity);
+}

+ 5 - 9
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableServiceImpl.java

@@ -11,10 +11,7 @@ import com.alibaba.fastjson2.JSON;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.uuid.IdUtils;
-import com.ruoyi.system.entity.CommonEntity;
-import com.ruoyi.system.entity.DragTable;
-import com.ruoyi.system.entity.DragTableCondition;
-import com.ruoyi.system.entity.TableSql;
+import com.ruoyi.system.entity.*;
 import com.ruoyi.system.entity.vo.DragTableVo;
 import com.ruoyi.system.mapper.*;
 import org.apache.ibatis.jdbc.SQL;
@@ -214,17 +211,16 @@ public class DragTableServiceImpl implements IDragTableService {
             });
             dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
         }
-        //add drag_table_statistic
-//        if(dragTableVo.getDragTableStatisticList().size() > 0){
-//            dragTableStatisticMapper.batchInsertDragTableStatistic(dragTableVo.getDragTableStatisticList());
-//        }
-
     }
 
     @Override
     public DragTableVo selectDragTableVoByTId(Long tId) {
         DragTableVo vo = dragTableMapper.selectDragTableVoByTId(tId);
         vo.setSearchFieldList(dragTableConditionMapper.selectDragTableSearchField(tId));
+        //查询数据统计
+        DragTableStatistic dragTableStatistic = new DragTableStatistic();
+        dragTableStatistic.setTableKey(vo.getTableKey());
+        vo.setDragTableStatisticList(dragTableStatisticMapper.selectDragTableStatisticList(dragTableStatistic));
         return vo;
     }
 

+ 165 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableStatisticServiceImpl.java

@@ -0,0 +1,165 @@
+package com.ruoyi.system.service.impl;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.system.entity.CommonEntity;
+import com.ruoyi.system.entity.DragTableStatistic;
+import com.ruoyi.system.entity.TableSql;
+import com.ruoyi.system.entity.vo.DragTableVo;
+import com.ruoyi.system.mapper.CommonMapper;
+import com.ruoyi.system.mapper.TableSqlMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.system.mapper.DragTableStatisticMapper;
+import com.ruoyi.system.service.IDragTableStatisticService;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import javax.annotation.Resource;
+
+/**
+ * 动态表格统计Service业务层处理
+ * 
+ * @author ruoyi
+ * @date 2023-10-27
+ */
+@Service
+public class DragTableStatisticServiceImpl implements IDragTableStatisticService 
+{
+    @Autowired
+    private DragTableStatisticMapper dragTableStatisticMapper;
+
+    @Resource
+    private TableSqlMapper tableSqlMapper;
+
+    @Resource
+    private CommonMapper commonMapper;
+
+    @Override
+    public DragTableStatistic selectDragTableStatisticById(Long id)
+    {
+        return dragTableStatisticMapper.selectDragTableStatisticById(id);
+    }
+
+    @Override
+    public List<DragTableStatistic> selectDragTableStatisticList(DragTableStatistic dragTableStatistic)
+    {
+        return dragTableStatisticMapper.selectDragTableStatisticList(dragTableStatistic);
+    }
+
+    // SQL 条件的开始
+    public static final String SQL_START = "CONCAT(";
+
+    // SQL 超级查询常量
+    public static final String SQL_MIDDLE = "IFNULL( #{VAL}, '' )";
+
+    // sqlserver || DM 数据类型的超级查询常量
+    public static final String SQL_DM_SERVER_MIDDLE = "COALESCE( #{VAL}, '' )";
+
+    // SQL 条件的结束
+    public static final String SQL_END = "LIKE '%#{val}%'";
+
+    @Override
+    @Transactional
+    public int batchInsertDragTableStatistic(DragTableVo vo)
+    {
+        vo.getDragTableStatisticList().forEach(s -> s.setCreateBy(SecurityUtils.getUserId().toString()));
+
+        // 拼接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 where = vo.getDtTableName() + ".del_flag = '0' AND "+ SQL + SQL_END;
+        vo.getTableSqlList().stream().forEach(t -> t.setTableCondition(where));
+
+        tableSqlMapper.batchInsertTableSql(vo.getTableSqlList());
+        return dragTableStatisticMapper.batchInsertDragTableStatistic(vo.getDragTableStatisticList());
+    }
+
+    @Override
+    public int updateDragTableStatistic(DragTableVo vo)
+    {
+        return 1;
+    }
+
+    @Override
+    public int deleteDragTableStatisticByIds(Long[] ids)
+    {
+        return dragTableStatisticMapper.deleteDragTableStatisticByIds(ids);
+    }
+
+    @Override
+    public int deleteDragTableStatisticByTableKey(String tableKey)
+    {
+        return dragTableStatisticMapper.deleteDragTableStatisticByTableKey(tableKey);
+    }
+
+    @Override
+    public Map<String, Object> getInfoBySqlKey(String tableKey) {
+        Map<String,Object> map = new HashMap<>();
+        DragTableStatistic dragTableStatistic = new DragTableStatistic();
+        dragTableStatistic.setTableKey(tableKey);
+        List<DragTableStatistic> dragTableStatisticList = dragTableStatisticMapper.selectDragTableStatisticList(dragTableStatistic);
+        map.put("dragTableStatisticList",dragTableStatisticList);
+        return null;
+    }
+
+    @Override
+    public List<DragTableStatistic> getStatisticList(CommonEntity commonEntity) {
+        // 根据sqlkey查询得到当前表单对应的sql
+        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getQueryMap()));
+        // 得到查询条件的值
+        String queryCriteriaValue =
+                conditions.containsKey("queryCriteriaValue") == true
+                        ? conditions.get("queryCriteriaValue").toString() : "";
+        DragTableStatistic dragTableStatistic = new DragTableStatistic();
+        dragTableStatistic.setTableKey(conditions.get("tableKey").toString());
+        List<DragTableStatistic> dragTableStatisticList = dragTableStatisticMapper.selectDragTableStatisticList(dragTableStatistic);
+        return dragTableStatisticList.stream().map(d -> {
+            TableSql tableSql = tableSqlMapper.selectTableSqlByTSqlKey(d.getSqlKey());
+            // 得到需要执行的sql条件语句
+            String endSQL = tableSql.getTableCondition().replace("#{val}", queryCriteriaValue);
+            String sql = "";
+            if(StringUtils.hasLength(d.getStatisticObject())){
+                sql = tableSql.getTableSql() + " where " + endSQL + " and " + d.getStatisticField() + " like'"+d.getStatisticObject()+"'";
+            }else {
+                sql = tableSql.getTableSql() + " where " + endSQL;
+            }
+            List<CommonEntity> commonEntities = commonMapper.queryTableList(sql);
+            d.setResult(commonEntities.get(0) == null ? 0 : commonEntities.get(0).getResultMap().get("result") );
+            return d;
+        }).collect(Collectors.toList());
+
+
+    }
+}

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

@@ -91,6 +91,15 @@
         </trim>
     </insert>
 
+    <insert id="batchInsertTableSql" useGeneratedKeys="true" keyProperty="tId">
+        insert into table_sql (table_sql,table_condition,table_alias,sql_key,table_export_field,create_by,create_time,del_flag,order_by_column,is_asc)
+        values
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.tableSql},#{item.tableCondition},#{item.tableAlias},#{item.sqlKey},#{item.tableExportField},#{item.createBy},#{item.createTime},
+             #{item.delFlag},#{item.orderByColumn},#{item.sortOrder})
+        </foreach>
+    </insert>
+
     <update id="updateTableSql" parameterType="com.ruoyi.system.entity.TableSql">
         update table_sql
         <trim prefix="SET" suffixOverrides=",">
@@ -148,4 +157,6 @@
         </foreach>
     </delete>
 
+
+
 </mapper>

+ 11 - 9
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableStatisticMapper.xml

@@ -12,7 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="statisticType"    column="statistic_type"    />
         <result property="statisticField"    column="statistic_field"    />
         <result property="statisticObject"    column="statistic_object"    />
-        <result property="executeSql"    column="execute_sql"    />
+        <result property="sqlKey"    column="sql_key"    />
         <result property="delFlag"    column="del_flag"    />
         <result property="createBy"    column="create_by"    />
         <result property="createTime"    column="create_time"    />
@@ -21,7 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectDragTableStatisticVo">
-        select id, statistic_title, table_key, statistic_description, statistic_type, statistic_field, statistic_object, execute_sql, del_flag, create_by, create_time, update_by, update_time from drag_table_statistic
+        select id, statistic_title, table_key, statistic_description, statistic_type, statistic_field, statistic_object, sql_key, del_flag, create_by, create_time, update_by, update_time from drag_table_statistic
     </sql>
 
     <select id="selectDragTableStatisticList" parameterType="com.ruoyi.system.entity.DragTableStatistic" resultMap="DragTableStatisticResult">
@@ -33,7 +33,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="statisticType != null "> and statistic_type = #{statisticType}</if>
             <if test="statisticField != null  and statisticField != ''"> and statistic_field = #{statisticField}</if>
             <if test="statisticObject != null  and statisticObject != ''"> and statistic_object = #{statisticObject}</if>
-            <if test="executeSql != null  and executeSql != ''"> and execute_sql = #{executeSql}</if>
     </select>
 
     <select id="selectDragTableStatisticById" parameterType="Long" resultMap="DragTableStatisticResult">
@@ -41,11 +40,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where id = #{id}
     </select>
         
-    <insert id="batchInsertDragTableStatistic" parameterType="com.ruoyi.system.entity.DragTableStatistic" useGeneratedKeys="true" keyProperty="id">
+    <insert id="batchInsertDragTableStatistic" useGeneratedKeys="true" keyProperty="id">
         insert into drag_table_statistic
-            (statistic_title,table_key,statistic_description,statistic_type,statistic_field,statistic_object,execute_sql,create_by,create_time,del_flag)
+            (statistic_title,table_key,statistic_description,statistic_type,statistic_field,statistic_object,sql_key,create_by,create_time,del_flag)
             values
-            (#{statisticTitle},#{tableKey},#{statisticDescription},#{statisticType},#{statisticField},#{statisticObject},#{executeSql},#{createBy},#{createTime},'0')
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.statisticTitle},#{item.tableKey},#{item.statisticDescription},#{item.statisticType},#{item.statisticField},#{item.statisticObject},
+             #{item.sqlKey},#{item.createBy},#{item.createTime},'0')
+        </foreach>
     </insert>
 
     <update id="updateDragTableStatistic" parameterType="com.ruoyi.system.entity.DragTableStatistic">
@@ -57,15 +59,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <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="executeSql != null">execute_sql = #{executeSql},</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>
         </trim>
         where id = #{id}
     </update>
 
-    <update id="deleteDragTableStatisticById" parameterType="Long">
-        update drag_table_statistic set del_flag = '2' where id = #{id}
+    <update id="deleteDragTableStatisticByTableKey" parameterType="String">
+        update drag_table_statistic set del_flag = '2' where table_key = #{tableKey}
     </update>
 
     <delete id="deleteDragTableStatisticByIds" parameterType="String">