소스 검색

新建表格无数据时,查询表信息

shiqian 3 년 전
부모
커밋
b6d03c15c3

+ 26 - 0
boman-report/src/main/java/com/boman/report/mapper/MysqlTableMapper.java

@@ -0,0 +1,26 @@
+package com.boman.report.mapper;
+
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author shiqian
+ * @date 2021年08月31日 14:27
+ **/
+@Repository
+public interface MysqlTableMapper {
+
+    /**
+     * 功能描述: 查询表的字段
+     *
+     * @param tableName tableName
+     * @param dbName    数据库名称
+     * @return java.util.List<com.google.gson.JsonObject>
+     */
+    List<JSONObject> getColumnNames(@Param("tableName") String tableName, @Param("dbName") String dbName);
+}

+ 15 - 0
boman-report/src/main/java/com/boman/report/service/MysqlTableService.java

@@ -0,0 +1,15 @@
+package com.boman.report.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author shiqian
+ * @date 2021年08月31日 14:29
+ **/
+public interface MysqlTableService {
+
+    List<JSONObject> getColumnNames(String tableName, String dbName);
+}

+ 27 - 0
boman-report/src/main/java/com/boman/report/service/MysqlTableServiceImpl.java

@@ -0,0 +1,27 @@
+package com.boman.report.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.boman.report.mapper.MysqlTableMapper;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author shiqian
+ * @date 2021年08月31日 14:29
+ **/
+@Service
+public class MysqlTableServiceImpl implements MysqlTableService {
+
+    @Resource
+    private MysqlTableMapper mysqlTableMapper;
+
+
+    @Override
+    public List<JSONObject> getColumnNames(String tableName, String dbName) {
+
+        return mysqlTableMapper.getColumnNames(tableName, dbName);
+    }
+}

+ 8 - 6
boman-report/src/main/java/org/jeecg/modules/jmreport/desreport/a/service/a/JmReportDbService.java

@@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
 
 import com.boman.domain.GenTableColumn;
 import com.boman.gen.api.RemoteGenTableColumnService;
+import com.boman.report.service.MysqlTableService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.jeecg.modules.jmreport.common.expetion.JimuReportException;
@@ -91,6 +92,8 @@ public class JmReportDbService implements IJmReportDbService {
     private String apiBasePath;
     @Autowired
     private RemoteGenTableColumnService remoteGenTableColumnService;
+    @Autowired
+    private MysqlTableService mysqlTableService;
 
     @Override
     @Transactional
@@ -682,20 +685,19 @@ public class JmReportDbService implements IJmReportDbService {
         if (CollectionUtils.isEmpty(columns)) {
             return var5;
         }
-
+        List<JSONObject> jiaoyuju = mysqlTableService.getColumnNames(tableName, "jiaoyuju");
         List<LinkedHashMap<String, Object>> var19 = new ArrayList<>();
-        Map<String, Object> limitOne = var6.get(0);
 
         int cnt = 1;
-        for (Entry<String, Object> entry : limitOne.entrySet()) {
-            String limitOneColumnName = entry.getKey().toLowerCase();
+        for (JSONObject jsonObject : jiaoyuju) {
+            String columnName = jsonObject.getString("column_name");
             for (GenTableColumn column : columns) {
-                if (!column.getColumnName().equals(limitOneColumnName)) {
+                if (!column.getColumnName().equals(columnName)) {
                     continue;
                 }
 
                 LinkedHashMap<String, Object> temp = new LinkedHashMap<>();
-                temp.put("fieldName", limitOneColumnName);
+                temp.put("fieldName", columnName);
                 temp.put("fieldText", column.getColumnComment());
                 temp.put("widgetType", "String");
                 temp.put("orderNum", cnt++);

+ 19 - 0
boman-report/src/main/resources/mapper/MysqlTableMapper.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.boman.report.mapper.MysqlTableMapper">
+
+
+
+    <select id="getColumnNames" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT
+            column_name
+        FROM
+            information_schema.COLUMNS
+        WHERE
+            table_name = #{tableName}
+          AND table_schema =  #{dbName}
+    </select>
+
+</mapper>

+ 5 - 5
boman-report/src/main/resources/templates/jmreport/desreport/template/components/data_source_setting.ftl

@@ -91,10 +91,10 @@
 <#--                                        </i-input>-->
 <#--                                    </form-item>-->
 <#--                                </i-col>-->
-                                <i-col span="4" style="margin-left: 20px;">
-                                    <form-item prop="tableComment" label="名称">
-                                        <i-input type="text" style="width: 200px" @on-change="initTables" v-model="sqlForm.tableComment" placeholder="请输入名称">
-                                        </i-input>
+                                <i-col span="4" style="margin-left: 20px; display: inline">
+                                    <form-item prop="tableComment" label="名称" style="display: inline">
+                                        <i-input type="text" style="width: 200px; display: inline" @on-change="initTables" v-model="sqlForm.tableComment" placeholder="请输入名称"></i-input>
+                                        <i-button style="display: inline" @click="handleSQLAnalyze" v-if="sqlForm.dbType == 0" type="primary">SQL解析</i-button>
                                     </form-item>
                                 </i-col>
 <#--                                <i-col span="3">-->
@@ -128,7 +128,7 @@
                             </Row>
                             <Row style="margin-top: 2%;">
                                 <i-col span="24">
-                                    <i-button @click="handleSQLAnalyze" v-if="sqlForm.dbType == 0" type="primary">SQL解析</i-button>
+<#--                                    <i-button @click="handleSQLAnalyze" v-if="sqlForm.dbType == 0" type="primary">SQL解析</i-button>-->
                                     <form-item prop="dbDynSql" label="报表选择" v-if="sqlForm.dbType == 0">
                                        <#-- <i-input v-model="sqlForm.dbDynSql"  @on-blur="dbDynSqlBlur"  type="textarea" :rows="4"  placeholder="请输入查询SQL" style="min-height: 120px;max-height: 620px;width:950px">
                                         </i-input>-->