浏览代码

Merge remote-tracking branch 'origin/master'

Administrator 4 年之前
父节点
当前提交
b7e82265f8

+ 3 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/domain/GenTableColumn.java

@@ -17,6 +17,9 @@ public class GenTableColumn extends BaseEntity
     /** 是查询字段 */
     public static final String IS_QUERY = "1";
 
+    /** 是列表展示字段 */
+    public static final String IS_LIST = "1";
+
     /** 编号 */
     private Long columnId;
 

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

@@ -89,6 +89,15 @@ public class FormDataConstant {
     /**  根据表名查询表单时,返回给前台的按钮 (其实不是list而是 "AMDQSUE"的字符串 */
     public static final String BUTTON_LIST = "buttonList";
 
+    /**  根据表名查询表单时,返回给前台列表展示的列*/
+    public static final String TABLE_HEAD_LIST = "tableHeadList";
+
+    /**  分页  总条数*/
+    public static final String PAGE_TOTAL = "total";
+
+    /**  分页 总记录*/
+    public static final String PAGE_ROWS = "rows";
+
 
 
 }

+ 19 - 2
boman-modules/boman-system/src/main/java/com/boman/system/common/TableServiceCmdService.java

@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
 import static com.boman.common.core.utils.obj.ObjectUtils.requiredNonNull;
@@ -141,9 +142,18 @@ public class TableServiceCmdService {
         JSONObject packCondition =  packColCondition(columns, condition);
         // 需要返回到前台的列
         JSONArray showData = fixedData.getJSONArray(SHOW_DATA);
+        JSONObject rows = new JSONObject();
+        int total = selectService.countByCondition(genTable.getTableName(), condition, packCondition);
+        rows.put(FormDataConstant.PAGE_TOTAL, total);
+        if (total <= 0) {
+            rows.put(FormDataConstant.PAGE_ROWS, null);
+            return AjaxResult.success(rows);
+        }
+
         List<JSONObject> result = selectService.selectByCondition(genTable.getTableName(), condition, packCondition
                 , showData, dto.getOrderBy(), dto.getLimit(), dto.getOffset());
-        return AjaxResult.success(result);
+        rows.put(FormDataConstant.PAGE_ROWS, result);
+        return AjaxResult.success(rows);
     }
 
  /**
@@ -198,7 +208,7 @@ public class TableServiceCmdService {
     }
 
     /**
-     * 功能描述: 获取表单查询字段和按钮
+     * 功能描述: 获取表单查询字段、按钮、表头
      * 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
      * 刷新的入口为 {@link MyController#loadTable(com.boman.gen.domain.GenTable)}
      *
@@ -214,6 +224,7 @@ public class TableServiceCmdService {
 
         List<GenTableColumn> columns = genTable.getColumns();
         JSONObject jsonObject = new JSONObject();
+        // 查询字段
         ArrayList<GenTableColumn> queryList = Lists.newArrayListWithCapacity(16);
         for (GenTableColumn column : columns) {
             if (GenTableColumn.IS_QUERY.equalsIgnoreCase(column.getIsQuery())) {
@@ -224,6 +235,12 @@ public class TableServiceCmdService {
         jsonObject.put(FormDataConstant.QUERY_LIST, queryList);
         // genTable.getMenuRole() 暂时数据库没有数据,
         jsonObject.put(FormDataConstant.BUTTON_LIST, genTable.getMenuRole());
+
+        // 表头
+        List<GenTableColumn> tableHeadList = columns.stream()
+                .filter(genTableColumn -> GenTableColumn.IS_LIST.equals(genTableColumn.getIsList()))
+                .collect(Collectors.toList());
+        jsonObject.put(FormDataConstant.TABLE_HEAD_LIST, tableHeadList);
         return AjaxResult.success(jsonObject);
     }
 

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

@@ -135,12 +135,12 @@ public class ObjController {
     }
 
     /**
-     * 功能描述: 获取表单查询字段和按钮
+     * 功能描述: 获取表单查询字段、按钮、表头
      * 注意: 都是从redis中拿的,如果数据库和redis不一致,则需刷新一下redis
      * 刷新的入口为 {@link MyController#loadTable(com.boman.gen.domain.GenTable)}
      *
      *                    eg:{
-     *                          "table": "sys_config",
+     *                          "table": "sys_config"
      *                        }
      *
      * @param condition condition

+ 45 - 0
boman-modules/boman-system/src/main/java/com/boman/system/mapper/StandardlyMapper.java

@@ -127,6 +127,21 @@ public interface StandardlyMapper {
             , @Param("offset") int offset);
 
 
+    /**
+     * 功能描述: 自定义查询,需要查询的字段和value都在condition中
+     * {@link StandardlyMapper.SqlProvider#countByCondition(java.util.Map)}
+     *
+     * @param tableName     tableName
+     * @param condition     condition
+     * @param packCondition 封装好的查询条件
+     * @return int
+     */
+    @SelectProvider(type = StandardlyMapper.SqlProvider.class, method = "countByCondition")
+    int countByCondition(@Param("tableName") String tableName
+            , @Param("condition") JSONObject condition
+            , @Param("packCondition") JSONObject packCondition);
+
+
 
 
     public static class SqlProvider {
@@ -474,6 +489,36 @@ public interface StandardlyMapper {
             return result;
         }
 
+        public String countByCondition(Map<String, Object> para) {
+            JSONObject condition = (JSONObject) para.get("condition");
+            LOGGER.info("前台传过来的查询条件: {}", condition.toJSONString());
+            JSONObject packCondition = (JSONObject) para.get("packCondition");
+            String tableName = (String) para.get("tableName");
+
+            StringBuilder wholeSql = new StringBuilder();
+            wholeSql.append("select count(1)");
+            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);
+                // {@link com.boman.system.common.TableServiceCmdService.packValue} 这里是拼参数的地方
+                String[] split = valueStr.split("_");
+                String value = split[0];
+                String queryType = split[1];
+                String columnType = split[2];
+                conditionSql.append(key).append(covert(queryType, columnType, key, value)).append(" and ");
+            }
+
+            wholeSql.append(StringUtils.substringBeforeLast(conditionSql.toString(), " and"));
+            String result = wholeSql.toString();
+            LOGGER.info("查询count拼出的sql语句为:{}", result);
+            return result;
+        }
+
         private String covert(String queryType, String columnType, String key, String value) {
             // false 不需要转义
             boolean needEscape = columnType.contains(VARCHAR) || columnType.contains(CHAR)

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

@@ -26,6 +26,16 @@ public interface IBaseSelectService {
     List<JSONObject> selectByCondition(String tableName, JSONObject condition, JSONObject packCondition
             , JSONArray showData, String orderBy, Integer limit, Integer offset);
 
+    /**
+     * 功能描述: 根据条件查询
+     *
+     * @param tableName     tableName
+     * @param condition     原始查询条件
+     * @param packCondition 封装的查询条件
+     * @return int
+     */
+    int countByCondition(String tableName, JSONObject condition, JSONObject packCondition);
+
     /**
      * 功能描述: 根据id查所有,不支持自定义查询列
      *

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

@@ -40,6 +40,7 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
      */
     @Override
     public List<JSONObject> selectByCondition(String tableName, JSONObject condition, JSONObject packCondition, JSONArray showData, String orderBy, Integer limit, Integer offset) {
+        requireNonNull(tableName);
         requireNonNull(condition);
         requireNonNull(packCondition);
         requireNonNull(showData);
@@ -48,6 +49,22 @@ public class BaseSelectServiceImpl implements IBaseSelectService {
         return mapper.selectByCondition(tableName, condition, packCondition, showData, orderBy, limit, offset);
     }
 
+    /**
+     * 功能描述: 根据条件查询
+     *
+     * @param tableName     tableName
+     * @param condition     原始查询条件
+     * @param packCondition 封装的查询条件
+     * @return int
+     */
+    @Override
+    public int countByCondition(String tableName, JSONObject condition, JSONObject packCondition) {
+        requireNonNull(tableName);
+        requireNonNull(condition);
+        requireNonNull(packCondition);
+        return mapper.countByCondition(tableName, condition, packCondition);
+    }
+
     /**
      * 功能描述: 根据id查所有,不支持自定义查询列
      *