Эх сурвалжийг харах

新增多表联合查询接口

韩帛霖 2 жил өмнө
parent
commit
0bdd87c712

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

@@ -5,7 +5,9 @@ import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.system.entity.CommonEntity;
+import com.ruoyi.system.entity.TableSql;
 import com.ruoyi.system.service.ICommonService;
+import com.ruoyi.system.service.ITableSqlService;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -19,11 +21,14 @@ public class CommonController extends BaseController {
     @Resource
     private ICommonService commonService;
 
+    @Resource
+    private ITableSqlService iTableSqlService;
+
     /**
      * 查询
      */
     @GetMapping("/selectList")
-    public TableDataInfo selectList( CommonEntity commonEntity) {
+    public TableDataInfo selectList(CommonEntity commonEntity) {
         startPage();
         return getDataTable(commonService.selectList(commonEntity.getFormMap()));
     }
@@ -53,9 +58,10 @@ public class CommonController extends BaseController {
     }
 
     @GetMapping("/getTableList")
-    public AjaxResult queryTableList(String sqlkey) {
-
-        return AjaxResult.success();
+    public TableDataInfo queryTableList(CommonEntity commonEntity) {
+        TableSql tableSql = iTableSqlService.selectTableSqlByTSqlKey(commonEntity.getFormMap().get("SQLKEY").toString());
+        startPage();
+        return getDataTable(commonService.queryTableList(commonEntity, tableSql));
     }
 
 }

+ 1 - 1
ruoyi-common/src/main/java/com/ruoyi/common/config/datasource/config/DynamicDataSource.java

@@ -6,7 +6,7 @@ package com.ruoyi.common.config.datasource.config;
 import com.alibaba.druid.pool.DruidDataSource;
 import com.ruoyi.common.config.datasource.constant.DataSourceType;
 import com.ruoyi.common.config.datasource.constant.UrlSuffix;
-import com.ruoyi.common.config.datasource.utils.StringUtils;
+import com.ruoyi.common.utils.StringUtils;
 import org.apache.ibatis.mapping.Environment;
 import org.apache.ibatis.session.Configuration;
 import org.apache.ibatis.session.SqlSessionFactory;

+ 1 - 0
ruoyi-common/src/main/java/com/ruoyi/common/config/datasource/utils/AjaxResult.java

@@ -2,6 +2,7 @@ package com.ruoyi.common.config.datasource.utils;
 
 
 import com.ruoyi.common.constant.HttpStatus;
+import com.ruoyi.common.utils.StringUtils;
 
 import java.util.HashMap;
 

+ 0 - 576
ruoyi-common/src/main/java/com/ruoyi/common/config/datasource/utils/StringUtils.java

@@ -1,576 +0,0 @@
-package com.ruoyi.common.config.datasource.utils;
-
-import org.springframework.util.AntPathMatcher;
-
-import java.util.*;
-
-/**
- * 字符串工具类
- * 
- * @author ruoyi
- */
-public class StringUtils extends org.apache.commons.lang3.StringUtils
-{
-    /** 空字符串 */
-    private static final String NULLSTR = "";
-
-    /** 下划线 */
-    private static final char SEPARATOR = '_';
-
-    /**
-     * 获取参数不为空值
-     * 
-     * @param value defaultValue 要判断的value
-     * @return value 返回值
-     */
-    public static <T> T nvl(T value, T defaultValue)
-    {
-        return value != null ? value : defaultValue;
-    }
-
-    /**
-     * * 判断一个Collection是否为空, 包含List,Set,Queue
-     * 
-     * @param coll 要判断的Collection
-     * @return true:为空 false:非空
-     */
-    public static boolean isEmpty(Collection<?> coll)
-    {
-        return isNull(coll) || coll.isEmpty();
-    }
-
-    /**
-     * * 判断一个Collection是否非空,包含List,Set,Queue
-     * 
-     * @param coll 要判断的Collection
-     * @return true:非空 false:空
-     */
-    public static boolean isNotEmpty(Collection<?> coll)
-    {
-        return !isEmpty(coll);
-    }
-
-    /**
-     * * 判断一个对象数组是否为空
-     * 
-     * @param objects 要判断的对象数组
-     ** @return true:为空 false:非空
-     */
-    public static boolean isEmpty(Object[] objects)
-    {
-        return isNull(objects) || (objects.length == 0);
-    }
-
-    /**
-     * * 判断一个对象数组是否非空
-     * 
-     * @param objects 要判断的对象数组
-     * @return true:非空 false:空
-     */
-    public static boolean isNotEmpty(Object[] objects)
-    {
-        return !isEmpty(objects);
-    }
-
-    /**
-     * * 判断一个Map是否为空
-     * 
-     * @param map 要判断的Map
-     * @return true:为空 false:非空
-     */
-    public static boolean isEmpty(Map<?, ?> map)
-    {
-        return isNull(map) || map.isEmpty();
-    }
-
-    /**
-     * * 判断一个Map是否为空
-     * 
-     * @param map 要判断的Map
-     * @return true:非空 false:空
-     */
-    public static boolean isNotEmpty(Map<?, ?> map)
-    {
-        return !isEmpty(map);
-    }
-
-    /**
-     * * 判断一个字符串是否为空串
-     * 
-     * @param str String
-     * @return true:为空 false:非空
-     */
-    public static boolean isEmpty(String str)
-    {
-        return isNull(str) || NULLSTR.equals(str.trim());
-    }
-
-    /**
-     * * 判断一个字符串是否为非空串
-     * 
-     * @param str String
-     * @return true:非空串 false:空串
-     */
-    public static boolean isNotEmpty(String str)
-    {
-        return !isEmpty(str);
-    }
-
-    /**
-     * * 判断一个对象是否为空
-     * 
-     * @param object Object
-     * @return true:为空 false:非空
-     */
-    public static boolean isNull(Object object)
-    {
-        return object == null;
-    }
-
-    /**
-     * * 判断一个对象是否非空
-     * 
-     * @param object Object
-     * @return true:非空 false:空
-     */
-    public static boolean isNotNull(Object object)
-    {
-        return !isNull(object);
-    }
-
-    /**
-     * * 判断一个对象是否是数组类型(Java基本型别的数组)
-     * 
-     * @param object 对象
-     * @return true:是数组 false:不是数组
-     */
-    public static boolean isArray(Object object)
-    {
-        return isNotNull(object) && object.getClass().isArray();
-    }
-
-    /**
-     * 去空格
-     */
-    public static String trim(String str)
-    {
-        return (str == null ? "" : str.trim());
-    }
-
-    /**
-     * 截取字符串
-     * 
-     * @param str 字符串
-     * @param start 开始
-     * @return 结果
-     */
-    public static String substring(final String str, int start)
-    {
-        if (str == null)
-        {
-            return NULLSTR;
-        }
-
-        if (start < 0)
-        {
-            start = str.length() + start;
-        }
-
-        if (start < 0)
-        {
-            start = 0;
-        }
-        if (start > str.length())
-        {
-            return NULLSTR;
-        }
-
-        return str.substring(start);
-    }
-
-    /**
-     * 截取字符串
-     * 
-     * @param str 字符串
-     * @param start 开始
-     * @param end 结束
-     * @return 结果
-     */
-    public static String substring(final String str, int start, int end)
-    {
-        if (str == null)
-        {
-            return NULLSTR;
-        }
-
-        if (end < 0)
-        {
-            end = str.length() + end;
-        }
-        if (start < 0)
-        {
-            start = str.length() + start;
-        }
-
-        if (end > str.length())
-        {
-            end = str.length();
-        }
-
-        if (start > end)
-        {
-            return NULLSTR;
-        }
-
-        if (start < 0)
-        {
-            start = 0;
-        }
-        if (end < 0)
-        {
-            end = 0;
-        }
-
-        return str.substring(start, end);
-    }
-
-
-    /**
-     * 字符串转set
-     * 
-     * @param str 字符串
-     * @param sep 分隔符
-     * @return set集合
-     */
-    public static final Set<String> str2Set(String str, String sep)
-    {
-        return new HashSet<String>(str2List(str, sep, true, false));
-    }
-
-    /**
-     * 字符串转list
-     * 
-     * @param str 字符串
-     * @param sep 分隔符
-     * @param filterBlank 过滤纯空白
-     * @param trim 去掉首尾空白
-     * @return list集合
-     */
-    public static final List<String> str2List(String str, String sep, boolean filterBlank, boolean trim)
-    {
-        List<String> list = new ArrayList<String>();
-        if (StringUtils.isEmpty(str))
-        {
-            return list;
-        }
-
-        // 过滤空白字符串
-        if (filterBlank && StringUtils.isBlank(str))
-        {
-            return list;
-        }
-        String[] split = str.split(sep);
-        for (String string : split)
-        {
-            if (filterBlank && StringUtils.isBlank(string))
-            {
-                continue;
-            }
-            if (trim)
-            {
-                string = string.trim();
-            }
-            list.add(string);
-        }
-
-        return list;
-    }
-
-    /**
-     * 判断给定的collection列表中是否包含数组array 判断给定的数组array中是否包含给定的元素value
-     *
-     * @param collection 给定的集合
-     * @param array 给定的数组
-     * @return boolean 结果
-     */
-    public static boolean containsAny(Collection<String> collection, String... array)
-    {
-        if (isEmpty(collection) || isEmpty(array))
-        {
-            return false;
-        }
-        else
-        {
-            for (String str : array)
-            {
-                if (collection.contains(str))
-                {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-    /**
-     * 查找指定字符串是否包含指定字符串列表中的任意一个字符串同时串忽略大小写
-     *
-     * @param cs 指定字符串
-     * @param searchCharSequences 需要检查的字符串数组
-     * @return 是否包含任意一个字符串
-     */
-    public static boolean containsAnyIgnoreCase(CharSequence cs, CharSequence... searchCharSequences)
-    {
-        if (isEmpty(cs) || isEmpty(searchCharSequences))
-        {
-            return false;
-        }
-        for (CharSequence testStr : searchCharSequences)
-        {
-            if (containsIgnoreCase(cs, testStr))
-            {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * 驼峰转下划线命名
-     */
-    public static String toUnderScoreCase(String str)
-    {
-        if (str == null)
-        {
-            return null;
-        }
-        StringBuilder sb = new StringBuilder();
-        // 前置字符是否大写
-        boolean preCharIsUpperCase = true;
-        // 当前字符是否大写
-        boolean curreCharIsUpperCase = true;
-        // 下一字符是否大写
-        boolean nexteCharIsUpperCase = true;
-        for (int i = 0; i < str.length(); i++)
-        {
-            char c = str.charAt(i);
-            if (i > 0)
-            {
-                preCharIsUpperCase = Character.isUpperCase(str.charAt(i - 1));
-            }
-            else
-            {
-                preCharIsUpperCase = false;
-            }
-
-            curreCharIsUpperCase = Character.isUpperCase(c);
-
-            if (i < (str.length() - 1))
-            {
-                nexteCharIsUpperCase = Character.isUpperCase(str.charAt(i + 1));
-            }
-
-            if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase)
-            {
-                sb.append(SEPARATOR);
-            }
-            else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase)
-            {
-                sb.append(SEPARATOR);
-            }
-            sb.append(Character.toLowerCase(c));
-        }
-
-        return sb.toString();
-    }
-
-    /**
-     * 是否包含字符串
-     * 
-     * @param str 验证字符串
-     * @param strs 字符串组
-     * @return 包含返回true
-     */
-    public static boolean inStringIgnoreCase(String str, String... strs)
-    {
-        if (str != null && strs != null)
-        {
-            for (String s : strs)
-            {
-                if (str.equalsIgnoreCase(trim(s)))
-                {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    /**
-     * 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。 例如:HELLO_WORLD->HelloWorld
-     * 
-     * @param name 转换前的下划线大写方式命名的字符串
-     * @return 转换后的驼峰式命名的字符串
-     */
-    public static String convertToCamelCase(String name)
-    {
-        StringBuilder result = new StringBuilder();
-        // 快速检查
-        if (name == null || name.isEmpty())
-        {
-            // 没必要转换
-            return "";
-        }
-        else if (!name.contains("_"))
-        {
-            // 不含下划线,仅将首字母大写
-            return name.substring(0, 1).toUpperCase() + name.substring(1);
-        }
-        // 用下划线将原始字符串分割
-        String[] camels = name.split("_");
-        for (String camel : camels)
-        {
-            // 跳过原始字符串中开头、结尾的下换线或双重下划线
-            if (camel.isEmpty())
-            {
-                continue;
-            }
-            // 首字母大写
-            result.append(camel.substring(0, 1).toUpperCase());
-            result.append(camel.substring(1).toLowerCase());
-        }
-        return result.toString();
-    }
-
-    /**
-     * 驼峰式命名法
-     * 例如:user_name->userName
-     */
-    public static String toCamelCase(String s)
-    {
-        if (s == null)
-        {
-            return null;
-        }
-        if (s.indexOf(SEPARATOR) == -1)
-        {
-            return s;
-        }
-        s = s.toLowerCase();
-        StringBuilder sb = new StringBuilder(s.length());
-        boolean upperCase = false;
-        for (int i = 0; i < s.length(); i++)
-        {
-            char c = s.charAt(i);
-
-            if (c == SEPARATOR)
-            {
-                upperCase = true;
-            }
-            else if (upperCase)
-            {
-                sb.append(Character.toUpperCase(c));
-                upperCase = false;
-            }
-            else
-            {
-                sb.append(c);
-            }
-        }
-        return sb.toString();
-    }
-
-    /**
-     * 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
-     * 
-     * @param str 指定字符串
-     * @param strs 需要检查的字符串数组
-     * @return 是否匹配
-     */
-    public static boolean matches(String str, List<String> strs)
-    {
-        if (isEmpty(str) || isEmpty(strs))
-        {
-            return false;
-        }
-        for (String pattern : strs)
-        {
-            if (isMatch(pattern, str))
-            {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * 判断url是否与规则配置: 
-     * ? 表示单个字符; 
-     * * 表示一层路径内的任意字符串,不可跨层级; 
-     * ** 表示任意层路径;
-     * 
-     * @param pattern 匹配规则
-     * @param url 需要匹配的url
-     * @return
-     */
-    public static boolean isMatch(String pattern, String url)
-    {
-        AntPathMatcher matcher = new AntPathMatcher();
-        return matcher.match(pattern, url);
-    }
-
-    @SuppressWarnings("unchecked")
-    public static <T> T cast(Object obj)
-    {
-        return (T) obj;
-    }
-
-    /**
-     * 数字左边补齐0,使之达到指定长度。注意,如果数字转换为字符串后,长度大于size,则只保留 最后size个字符。
-     * 
-     * @param num 数字对象
-     * @param size 字符串指定长度
-     * @return 返回数字的字符串格式,该字符串为指定长度。
-     */
-    public static final String padl(final Number num, final int size)
-    {
-        return padl(num.toString(), size, '0');
-    }
-
-    /**
-     * 字符串左补齐。如果原始字符串s长度大于size,则只保留最后size个字符。
-     * 
-     * @param s 原始字符串
-     * @param size 字符串指定长度
-     * @param c 用于补齐的字符
-     * @return 返回指定长度的字符串,由原字符串左补齐或截取得到。
-     */
-    public static final String padl(final String s, final int size, final char c)
-    {
-        final StringBuilder sb = new StringBuilder(size);
-        if (s != null)
-        {
-            final int len = s.length();
-            if (s.length() <= size)
-            {
-                for (int i = size - len; i > 0; i--)
-                {
-                    sb.append(c);
-                }
-                sb.append(s);
-            }
-            else
-            {
-                return s.substring(len - size, len);
-            }
-        }
-        else
-        {
-            for (int i = size; i > 0; i--)
-            {
-                sb.append(c);
-            }
-        }
-        return sb.toString();
-    }
-}

+ 33 - 2
ruoyi-system/src/main/java/com/ruoyi/system/entity/CommonEntity.java

@@ -10,12 +10,23 @@ import java.util.TreeMap;
  * @date 2023/7/19 4:05 PM
  */
 public class CommonEntity extends BaseEntity {
+    private static final long serialVersionUID = 1L;
 
     /**
-     * map
+     * 基本参数map
      */
     private Map<String, Object> formMap;
 
+    /**
+     * 主表参数map
+     */
+    private Map<String, Object> condition;
+
+    /**
+     * 返回前端map
+     */
+    private Map<String, Object> retMap;
+
     public CommonEntity() {
     }
 
@@ -23,6 +34,8 @@ public class CommonEntity extends BaseEntity {
     public String toString() {
         return "CommonEntity{" +
                 "formMap=" + formMap +
+                ", condition=" + condition +
+                ", retMap=" + retMap +
                 '}';
     }
 
@@ -34,7 +47,25 @@ public class CommonEntity extends BaseEntity {
         this.formMap = formMap;
     }
 
-    public CommonEntity(Map<String, Object> formMap) {
+    public Map<String, Object> getCondition() {
+        return condition;
+    }
+
+    public void setCondition(Map<String, Object> condition) {
+        this.condition = condition;
+    }
+
+    public Map<String, Object> getRetMap() {
+        return retMap;
+    }
+
+    public void setRetMap(Map<String, Object> retMap) {
+        this.retMap = retMap;
+    }
+
+    public CommonEntity(Map<String, Object> formMap, Map<String, Object> condition, Map<String, Object> retMap) {
         this.formMap = formMap;
+        this.condition = condition;
+        this.retMap = retMap;
     }
 }

+ 12 - 4
ruoyi-system/src/main/java/com/ruoyi/system/mapper/CommonMapper.java

@@ -14,20 +14,28 @@ public interface CommonMapper {
     /**
      * 查询列表
      */
-    List<CommonEntity> selectList(@Param("tableName") String tableName, @Param("conditions")Map<String,Object> conditions);
+    List<CommonEntity> selectList(@Param("tableName") String tableName, @Param("conditions") Map<String, Object> conditions);
 
     /**
      * 批量新增
      */
-    int batchInsert(@Param("fieldNames") Set<String> fieldNames, @Param("tableName") String tableName, @Param("fieldValues") List<Map<String,Object>> fieldValues);
+    int batchInsert(@Param("fieldNames") Set<String> fieldNames, @Param("tableName") String tableName, @Param("fieldValues") List<Map<String, Object>> fieldValues);
 
     /**
      * 批量删除
      */
-    int batchDelete(@Param("tableName") String tableName,@Param("conditions")Map<String,Object> conditions);
+    int batchDelete(@Param("tableName") String tableName, @Param("conditions") Map<String, Object> conditions);
 
     /**
      * 修改
      */
-    int edit(@Param("fields")Map<String,Object> fields,@Param("tableName") String tableName,@Param("conditions")Map<String,Object> conditions);
+    int edit(@Param("fields") Map<String, Object> fields, @Param("tableName") String tableName, @Param("conditions") Map<String, Object> conditions);
+
+    /**
+     * 执行动态sql
+     *
+     * @param Sql
+     * @return
+     */
+    List<CommonEntity> queryTableList(String Sql);
 }

+ 2 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/ICommonService.java

@@ -1,6 +1,7 @@
 package com.ruoyi.system.service;
 
 import com.ruoyi.system.entity.CommonEntity;
+import com.ruoyi.system.entity.TableSql;
 
 import java.util.List;
 import java.util.Map;
@@ -31,6 +32,6 @@ public interface ICommonService {
     /**
      * 根据sqlkey 执行sql并返回结果
      */
-    List<Map<String, Object>> queryTableList(Map<String, Object> map);
+    List<CommonEntity> queryTableList(CommonEntity commonEntity, TableSql tableSql);
 
 }

+ 42 - 15
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java

@@ -2,27 +2,25 @@ package com.ruoyi.system.service.impl;
 
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
-import com.ruoyi.common.utils.CollectionUtil;
 import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.TableSql;
 import com.ruoyi.system.mapper.CommonMapper;
 import com.ruoyi.system.service.ICommonService;
-import com.ruoyi.system.service.ITableSqlService;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.util.*;
 
+import static com.ruoyi.common.utils.StringUtils.convertToCamelCase;
+import static com.ruoyi.common.utils.StringUtils.toUnderScoreCase;
+
 
 @Service
 public class CommonServiceImpl implements ICommonService {
 
     @Resource
     private CommonMapper commonMapper;
-    @Resource
-    private ITableSqlService iTableSqlService;
+
 
     @Override
     public List<CommonEntity> selectList(Map<String, Object> map) {
@@ -65,18 +63,47 @@ public class CommonServiceImpl implements ICommonService {
     }
 
     @Override
-    public List<Map<String, Object>> queryTableList(Map<String, Object> map) {
+    public List<CommonEntity> queryTableList(CommonEntity commonEntity, TableSql tableSql) {
         // 根据sqlkey查询得到当前表单对应的sql
-        TableSql tableSql = iTableSqlService.selectTableSqlByTSqlKey(map.get("SQLKEY").toString());
-        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(map.get("condition")));
-
-
+        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getCondition()));
+        // sql当中拼接好条件格式 后台使用AND分割 拼接条件
+        //  and 。。。。 and 。。。。 and。。。。
         StringBuilder endSQL = new StringBuilder();
-        endSQL.append("" + tableSql.getTableSql() + "where 1=1");
-
+        endSQL.append("" + tableSql.getTableSql() + " where 1=1 ");
+        String[] whereTerm = tableSql.getTableCondition().split("AND");
+        List<String> test = Arrays.asList(whereTerm);
+        // 拼接条件
         conditions.forEach((key, val) -> {
-            endSQL.append(" and " + tableSql.getTableAlias() + " " + key + " = " + val);
+            String sqlWhere = test.stream().filter(item -> item.contains(toUnderScoreCase(key))).findAny().get();
+            if (sqlWhere.indexOf("#{timeframe}") != -1) {  // 时间范围查询拼接
+                endSQL.append(" AND " + sqlWhere.replace("#{timeframe}", "'" + val.toString().split(",")[0] + "'" + " and " + "'" + val.toString().split(",")[1] + "'"));
+            } else if (sqlWhere.indexOf("#{val}") != -1) { // 寻常条件拼接
+                endSQL.append(" AND " + sqlWhere.replace("#{val}", val.toString()));
+            }
         });
-        return null;
+        //for (String w : whereTerm) {
+        //extractSubstring(w, tableSql.getTableAlias()); // 得到当前筛选条件的字段名称
+        //w.replace("#{val}", extractSubstring(w, tableSql.getTableAlias()));
+        //}
+        //conditions.forEach((key, val) -> {
+        //endSQL.append(" and " + tableSql.getTableAlias() + " " + key + " = " + val);
+        //});
+        return commonMapper.queryTableList(endSQL.toString());
+    }
+
+
+    public static String extractSubstring(String input, String identifier) {
+        int startIndex = input.indexOf(identifier);
+        if (startIndex == -1) {
+            return null; // 如果找不到指定的标识符,则返回空
+        }
+
+        int endIndex = input.indexOf(" ", startIndex);
+        if (endIndex == -1) {
+            endIndex = input.length(); // 如果找不到空格,则截取到字符串末尾
+        }
+        String sqlColumn = input.substring(startIndex + identifier.length() + 1, endIndex);
+        return convertToCamelCase(sqlColumn);
+
     }
 }

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TableSqlServiceImpl.java

@@ -33,7 +33,7 @@ public class TableSqlServiceImpl implements ITableSqlService {
 
     @Override
     public TableSql selectTableSqlByTSqlKey(String SQLKEY) {
-        return selectTableSqlByTSqlKey(SQLKEY);
+        return tableSqlMapper.selectTableSqlByTSqlKey(SQLKEY);
     }
 
     /**

+ 56 - 0
ruoyi-system/src/main/java/com/ruoyi/system/test/ljj.java

@@ -0,0 +1,56 @@
+package com.ruoyi.system.test;
+
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+import static com.ruoyi.common.utils.StringUtils.convertToCamelCase;
+import static com.ruoyi.common.utils.StringUtils.toUnderScoreCase;
+import static org.apache.commons.lang3.StringUtils.lowerCase;
+
+/**
+ * @author hanzihang
+ * @date 2023/7/20 2:34 PM
+ */
+public class ljj {
+
+
+    public static String extractSubstring(String input, String identifier) {
+        int startIndex = input.indexOf(identifier);
+        if (startIndex == -1) {
+            return null; // 如果找不到指定的标识符,则返回空
+        }
+
+        int endIndex = input.indexOf(" ", startIndex);
+        if (endIndex == -1) {
+            endIndex = input.length(); // 如果找不到空格,则截取到字符串末尾
+        }
+        String sqlColumn = input.substring(startIndex + identifier.length() + 1, endIndex);
+        System.out.println(sqlColumn);
+
+        return convertToCamelCase(sqlColumn);
+
+    }
+
+    private static final Pattern TPATTERN = Pattern.compile("[A-Z0-9]");
+
+    private static String teseDemo(String str) {
+        Matcher matcher = TPATTERN.matcher(str);
+        StringBuffer sb = new StringBuffer();
+        while (matcher.find()) {
+            matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
+        }
+        matcher.appendTail(sb);
+        return sb.toString();
+    }
+
+    public static void main(String[] args) {
+        String input = "AND dragform.df_name like concat('%', #{val}, '%')";
+        String identifier = "dragForm";
+//        String extractedSubstring = extractSubstring(input, identifier);
+        String extractedSubstring = toUnderScoreCase(identifier);
+        System.out.println(extractedSubstring);
+    }
+
+}

+ 8 - 4
ruoyi-system/src/main/resources/mapper/common/CommonMapper.xml

@@ -5,12 +5,12 @@
 <mapper namespace="com.ruoyi.system.mapper.CommonMapper">
 
 
-    <resultMap id="testMap" type="map" autoMapping="true">
-        <collection property="formMap" ofType="com.ruoyi.system.entity.CommonEntity" autoMapping="true" javaType="map">
-        </collection>
+    <resultMap id="retMap" type="map" autoMapping="true">
+        <collection property="retMap" ofType="com.ruoyi.system.entity.CommonEntity" autoMapping="true"
+                    javaType="map"></collection>
     </resultMap>
 
-    <select id="selectList" resultMap="testMap">
+    <select id="selectList" resultMap="retMap">
         select * from ${tableName}
         <where>
             <if test="conditions != null">
@@ -21,6 +21,10 @@
         </where>
     </select>
 
+    <select id="queryTableList" resultMap="retMap">
+        ${Sql}
+    </select>
+
     <insert id="batchInsert">
         insert into ${tableName}
         <foreach collection="fieldNames" item="fieldName" open="(" close=")" separator=",">