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

Merge branch 'master' of http://192.168.101.10:13000/boman/boman-framwork

sr 4 жил өмнө
parent
commit
85fcad8efb

+ 41 - 0
boman-common/boman-common-core/src/main/java/com/boman/common/core/utils/obj/ObjectUtils.java

@@ -2,9 +2,12 @@ package com.boman.common.core.utils.obj;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
 
 import java.util.Collection;
+import java.util.Objects;
 
 /**
  * @author shiqian
@@ -46,6 +49,21 @@ public class ObjectUtils {
         return input;
     }
 
+    public static Integer requireNonNull(Integer input) {
+        if (input == null || input < 0) {
+            throw new IllegalArgumentException("所传参数为空");
+        }
+        return input;
+    }
+
+    public static boolean isEmpty(Integer input) {
+        return input == null || input < 0;
+    }
+
+    public static boolean isNotEmpty(Integer input) {
+        return !isEmpty(input);
+    }
+
 
     public static String requireNonNull(String input) {
         if (input == null || input.isEmpty() || NULL.equalsIgnoreCase(input) || UNDEFINED.equalsIgnoreCase(input)) {
@@ -69,6 +87,25 @@ public class ObjectUtils {
         return input;
     }
 
+    /**
+     * 功能描述: 暂且只做 string collection long 三种类型的校验
+     *
+     * @param input input
+     * @return boolean
+     */
+    public static boolean isEmpty(Object input) {
+        if (input instanceof String) {
+            return StringUtils.isEmpty((String) input);
+        } else if (input instanceof Collection) {
+            return CollectionUtils.isEmpty(((Collection<?>) input));
+        } else {
+            return Objects.isNull(input);
+        }
+    }
+
+    public static boolean isNotEmpty(Object input) {
+        return !isEmpty(input);
+    }
 
     public static JSONArray requireNonNull(JSONArray input) {
         if (input == null || input.isEmpty()) {
@@ -77,6 +114,10 @@ public class ObjectUtils {
         return input;
     }
 
+    public static String escapeStr(String input) {
+        return "'" + input + "'";
+    }
+
 
 
 }

+ 18 - 0
boman-modules/boman-system/src/main/java/com/boman/system/common/BaseTableSaveDTO.java

@@ -46,4 +46,22 @@ public class BaseTableSaveDTO implements Serializable {
      */
     @JSONField(name = "idList")
     private List<Long> idList;
+
+    /**
+     * orderBy eg: order_by columnName desc
+     */
+    @JSONField(name = "orderBy")
+    private String orderBy;
+
+    /**
+     * 分页
+     */
+    @JSONField(name = "limit")
+    private Integer limit;
+
+    /**
+     * 分页
+     */
+    @JSONField(name = "offset")
+    private Integer offset;
 }

+ 5 - 0
boman-modules/boman-system/src/main/java/com/boman/system/common/FormDataConstant.java

@@ -20,4 +20,9 @@ public class FormDataConstant {
      * 查询后需要返回到前台的字段
      */
     public static final String SHOW_DATA = "showData";
+
+
+    public static final String EQ = "EQ";
+
+    public static final String LIKE = "LIKE";
 }

+ 47 - 6
boman-modules/boman-system/src/main/java/com/boman/system/common/TableServiceCmdService.java

@@ -5,13 +5,16 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.StringUtils;
 import com.boman.common.core.utils.collection.CollectionUtils;
+import com.boman.common.core.utils.obj.ObjectUtils;
 import com.boman.common.redis.RedisKey;
 import com.boman.common.redis.service.RedisService;
 import com.boman.gen.domain.GenTable;
 import com.boman.gen.domain.GenTableColumn;
+import com.boman.system.service.IBaseSelectService;
 import com.boman.system.service.impl.BaseDeleteService;
 import com.boman.system.service.impl.BaseSaveService;
 import com.boman.system.utils.IdUtils;
+import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,10 +22,12 @@ import org.springframework.stereotype.Component;
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
 import static com.boman.common.core.utils.obj.ObjectUtils.requiredNonNull;
-import static com.boman.system.common.FormDataConstant.*;
+import static com.boman.system.common.FormDataConstant.CONDITION;
+import static com.boman.system.common.FormDataConstant.SHOW_DATA;
 
 /**
  * @author shiqian
@@ -38,6 +43,8 @@ public class TableServiceCmdService {
     private BaseSaveService saveService;
     @Autowired
     private RedisService redisService;
+    @Autowired
+    private IBaseSelectService selectService;
 
     private static final Logger LOGGER = LoggerFactory.getLogger(TableServiceCmdService.class);
 
@@ -116,25 +123,59 @@ public class TableServiceCmdService {
     /**
      * 功能描述: 获取单表单数据
      *
-     * @param condition condition
+     * @param dto condition
      * @return com.boman.system.common.ValueHolder
      */
-    public ValueHolder<RowResult> getObject(BaseTableSaveDTO dto) {
+    public ValueHolder<List<JSONObject>> getObject(BaseTableSaveDTO dto) {
         requireNonNull(dto.getTable());
 
-        // 拿到每个字段对应的查询类型,是 = 或者 like 或者 > 或者 <
+        // 拿到每个字段对应的查询类型,=、 like、 >、 <
         GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + requireNonNull(dto.getTable()));
         requireNonNull(genTable);
         JSONObject fixedData = dto.getFixedData();
         requireNonNull(fixedData);
         // 查询条件
         JSONObject condition = fixedData.getJSONObject(CONDITION);
+        List<GenTableColumn> columns = genTable.getColumns();
+        // 封装好以后的查询条件
+        JSONObject packCondition =  packColCondition(columns, condition);
         // 需要返回到前台的列
         JSONArray showData = fixedData.getJSONArray(SHOW_DATA);
+        List<JSONObject> result = selectService.selectByCondition(genTable.getTableName(), condition, packCondition
+                , showData, dto.getOrderBy(), dto.getLimit(), dto.getOffset());
+        return ValueHolder.ok(result);
+    }
 
+    /**
+     * 功能描述: 封装成查询条件 key: 列名,  value:查询条件_查询类别
+     *              eg: {“columnName”: config_name, "value": "系统配置_like"}
+     *              eg: [{"config_name":"系统配置_like"}, {"config_name":"_like"}]
+     *
+     * @param columns columns
+     * @return com.alibaba.fastjson.JSONObject
+     */
+    private JSONObject packColCondition(List<GenTableColumn> columns, JSONObject condition) {
+        requireNonNull(columns);
+
+        JSONObject result = new JSONObject(columns.size());
+        for (Map.Entry<String, Object> entry : condition.entrySet()) {
+            String key = entry.getKey();
+            Object value = entry.getValue();
+            for (GenTableColumn column : columns) {
+                // long string collection 暂时只作此三种类型判断
+                if (column.getColumnName().equalsIgnoreCase(key) && ObjectUtils.isNotEmpty(value)) {
+                    result.put(key, packValue(String.valueOf(value), column.getQueryType()));
+                    break;
+                }
+            }
+        }
 
+        return result;
+    }
 
-
-        return ValueHolder.ok("");
+    private String packValue(String value, String type){
+        requireNonNull(value);
+        requireNonNull(type);
+        return value + "_" + type;
     }
 }

+ 4 - 1
boman-modules/boman-system/src/main/java/com/boman/system/controller/ObjController.java

@@ -1,5 +1,6 @@
 package com.boman.system.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.boman.system.common.BaseTableSaveDTO;
 import com.boman.system.common.RowResult;
 import com.boman.system.common.TableServiceCmdService;
@@ -11,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 
 /**
  * @author shiqian
@@ -68,7 +71,7 @@ public class ObjController {
      */
     @ApiOperation(value = "获取单表单数据")
     @PostMapping("/getObject")
-    public ValueHolder<RowResult> getObject(@RequestBody BaseTableSaveDTO condition) {
+    public ValueHolder<List<JSONObject>> getObject(@RequestBody BaseTableSaveDTO condition) {
         return tableServiceCmdService.getObject(condition);
     }
 

+ 59 - 15
boman-modules/boman-system/src/main/java/com/boman/system/mapper/StandardlyMapper.java

@@ -1,7 +1,9 @@
 package com.boman.system.mapper;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.boman.common.core.utils.obj.ObjectUtils;
+import com.boman.system.common.FormDataConstant;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.*;
 import org.apache.ibatis.annotations.Param;
@@ -89,16 +91,21 @@ public interface StandardlyMapper {
     /**
      * 功能描述: 自定义查询,需要查询的字段和value都在condition中
      *
-     * @param tableName tableName
-     * @param condition condition
-     * @param limit     分页
-     * @param offset    分页
+     * @param tableName     tableName
+     * @param condition     condition
+     * @param packCondition 封装好的查询条件
+     * @param showData      需要查询的列
+     * @param orderBy       orderBy
+     * @param limit         分页
+     * @param offset        分页, 可以为null
      * @return java.util.List<com.alibaba.fastjson.JSONObject>
      */
     @SelectProvider(type = StandardlyMapper.SqlProvider.class, method = "selectByCondition")
     List<JSONObject> selectByCondition(@Param("tableName") String tableName
             , @Param("condition") JSONObject condition
-            , @Param("showData") JSONObject showData
+            , @Param("packCondition") JSONObject packCondition
+            , @Param("showData") JSONArray showData
+            , @Param("orderBy") String orderBy
             , @Param("limit") int limit
             , @Param("offset") int offset);
 
@@ -404,24 +411,61 @@ public interface StandardlyMapper {
             }
         }
 
-//        @Param("tableName") String tableName, @Param("condition") JSONObject condition, @Param("limit") int limit, @Param("offset") int offset
         public String selectByCondition(Map<String, Object> para) {
-            JSONObject condition = (JSONObject) para.get("condition");
-            ObjectUtils.requireNonNull(condition);
+//            JSONObject condition = (JSONObject) para.get("condition");
+            JSONObject packCondition = (JSONObject) para.get("packCondition");
             String tableName = (String) para.get("tableName");
-            ObjectUtils.requireNonNull(tableName);
+            String orderBy = (String) para.get("orderBy");
             int limit = (int) para.get("limit");
-            ObjectUtils.requireNonNull(limit);
             int offset = (int) para.get("offset");
-            ObjectUtils.requireNonNull(offset);
-
-            StringBuilder sql = new StringBuilder();
-            sql.append("select ");
+            JSONArray showData = (JSONArray) para.get("showData");
+
+            StringBuilder wholeSql = new StringBuilder();
+            wholeSql.append("select ");
+            // showData
+            StringBuilder showDataSql = new StringBuilder();
+            for (Object columnObj : showData) {
+                String columnName = (String) columnObj;
+                showDataSql.append(columnName).append(", ");
+            }
 
+            wholeSql.append(StringUtils.substringBeforeLast(showDataSql.toString(), ","));
+            wholeSql.append(" from ").append(tableName);
+            wholeSql.append(" where ");
+            // 条件
+            StringBuilder conditionSql = new StringBuilder();
+            for (Map.Entry<String, Object> entry : packCondition.entrySet()) {
+                String key = entry.getKey();
+                Object valueObj = entry.getValue();
+                String valueStr = ((String) valueObj);
+                String[] split = valueStr.split("_");
+                String value = split[0];
+                String type = split[1];
+                conditionSql.append(key).append(covert(type, key, value)).append(" and ");
+            }
 
+            wholeSql.append(StringUtils.substringBeforeLast(conditionSql.toString(), " and"));
+            wholeSql.append(" order by ").append(orderBy).append(" limit ").append(limit);
+            if (ObjectUtils.isNotEmpty(offset)) {
+                wholeSql.append(", ").append(offset);
+            }
 
+            String result = wholeSql.toString();
+            LOGGER.info("查询拼出的sql语句为:{}", result);
+            return result;
+        }
 
-            return "";
+        private String covert(String type, String key, String value) {
+            switch (type) {
+                case FormDataConstant.EQ:
+                    return " = " + ObjectUtils.escapeStr(value);
+                case FormDataConstant.LIKE:
+                    return " like " + "concat('%', #{condition." + key + "}, '%')";
+                default:
+                    throw new IllegalArgumentException("参数非法");
+            }
         }
+
+
     }
 }

+ 28 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/IBaseSelectService.java

@@ -0,0 +1,28 @@
+package com.boman.system.service;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.List;
+
+/**
+ * @author shiqian
+ * @date 2021年03月29日 10:22
+ **/
+public interface IBaseSelectService {
+
+    /**
+     * 功能描述: 根据条件查询
+     *
+     * @param tableName     tableName
+     * @param condition     原始查询条件
+     * @param packCondition 封装的查询条件
+     * @param showData      前台需要查询的列
+     * @param orderBy       orderBy
+     * @param limit         分页
+     * @param offset        分页
+     * @return java.util.List<com.alibaba.fastjson.JSONObject>
+     */
+    List<JSONObject> selectByCondition(String tableName, JSONObject condition, JSONObject packCondition
+            , JSONArray showData, String orderBy, Integer limit, Integer offset);
+}

+ 50 - 0
boman-modules/boman-system/src/main/java/com/boman/system/service/impl/BaseSelectServiceImpl.java

@@ -0,0 +1,50 @@
+package com.boman.system.service.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.boman.system.mapper.StandardlyMapper;
+import com.boman.system.service.IBaseSelectService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
+
+/**
+ * @author shiqian
+ * @date 2021年03月29日 10:22
+ **/
+@Service
+public class BaseSelectServiceImpl implements IBaseSelectService {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(BaseSelectServiceImpl.class);
+
+    @Autowired
+    private StandardlyMapper mapper;
+
+
+    /**
+     * 功能描述: 根据条件查询
+     *
+     * @param tableName     tableName
+     * @param condition     原始查询条件
+     * @param packCondition 封装的查询条件
+     * @param showData      前台需要查询的列
+     * @param orderBy       orderBy
+     * @param limit         分页
+     * @param offset        分页
+     * @return java.util.List<com.alibaba.fastjson.JSONObject>
+     */
+    @Override
+    public List<JSONObject> selectByCondition(String tableName, JSONObject condition, JSONObject packCondition, JSONArray showData, String orderBy, Integer limit, Integer offset) {
+        requireNonNull(condition);
+        requireNonNull(packCondition);
+        requireNonNull(showData);
+        requireNonNull(limit);
+        requireNonNull(orderBy);
+        return mapper.selectByCondition(tableName, condition, packCondition, showData, orderBy, limit, offset);
+    }
+}

BIN
ruoyi-ui/src/assets/images/icon_list_sj.png


BIN
ruoyi-ui/src/assets/images/icon_more.png


BIN
ruoyi-ui/src/assets/images/icon_tjbj.png


BIN
ruoyi-ui/src/assets/images/pic_kpbg.png


+ 40 - 0
ruoyi-ui/src/views/system/table/index.vue

@@ -0,0 +1,40 @@
+<template>
+ <div class="table_total">
+   <div class="table_header">
+     <p>单表</p>
+     <el-divider></el-divider>
+   </div>
+   <!-- 内容 -->
+   <div class="table_nav">
+     
+   </div>
+
+ </div>
+
+</template>
+
+<script>
+</script>
+
+
+<style  lang="scss">
+
+</style>
+
+
+
+<style scoped lang="scss">
+  .table_total{
+     background-color: #eef0ff;
+     padding: 20px;
+     // 头部
+     .table_header{
+        background-color: #fff;
+
+     }
+  }
+  p{
+    margin: 0;
+
+  }
+</style>