修复切换语言时,表头不变化的bug

This commit is contained in:
lzy
2023-09-13 10:04:19 +08:00
parent fc3f329cdd
commit 18e9cf7489
3 changed files with 44 additions and 45 deletions

View File

@ -3,7 +3,10 @@ package ai.chat2db.server.web.api.controller.rdb.doc;
import ai.chat2db.server.domain.api.enums.ExportTypeEnum;
import ai.chat2db.server.domain.api.model.IndexInfo;
import ai.chat2db.server.domain.api.model.TableParameter;
import ai.chat2db.server.tools.common.util.I18nUtils;
import ai.chat2db.server.web.api.controller.rdb.doc.conf.ExportOptions;
import ai.chat2db.server.web.api.controller.rdb.doc.constant.CommonConstant;
import ai.chat2db.server.web.api.controller.rdb.doc.constant.PatternConstant;
import ai.chat2db.server.web.api.controller.rdb.vo.ColumnVO;
import ai.chat2db.server.web.api.controller.rdb.vo.IndexVO;
import ai.chat2db.server.web.api.controller.rdb.vo.TableVO;
@ -55,6 +58,41 @@ public class DatabaseExportService {
public final static String JOINER = "---";
private void init() {
CommonConstant.INDEX_HEAD_NAMES = new String[]{I18nUtils.getMessage("main.indexName"),
I18nUtils.getMessage("main.indexFieldName"),
I18nUtils.getMessage("main.indexType"),
I18nUtils.getMessage("main.indexMethod"),
I18nUtils.getMessage("main.indexNote")};
CommonConstant.COLUMN_HEAD_NAMES = new String[]{I18nUtils.getMessage("main.fieldNo"),
I18nUtils.getMessage("main.fieldName"),
I18nUtils.getMessage("main.fieldType"),
I18nUtils.getMessage("main.fieldLength"),
I18nUtils.getMessage("main.fieldIfEmpty"),
I18nUtils.getMessage("main.fieldDefault"),
I18nUtils.getMessage("main.fieldDecimalPlaces"),
I18nUtils.getMessage("main.fieldNote")};
// index表头
StringBuilder mdIndex = new StringBuilder(PatternConstant.MD_SPLIT);
StringBuilder htmlIndex = new StringBuilder("<tr><th>");
for (int i = 0; i < CommonConstant.INDEX_HEAD_NAMES.length; i++) {
mdIndex.append(CommonConstant.INDEX_HEAD_NAMES[i]).append(i == CommonConstant.INDEX_HEAD_NAMES.length - 1 ? "" : PatternConstant.MD_SPLIT);
htmlIndex.append(CommonConstant.INDEX_HEAD_NAMES[i]).append(i == CommonConstant.INDEX_HEAD_NAMES.length - 1 ? "" : "</th><th>");
}
mdIndex.append(PatternConstant.MD_SPLIT);
htmlIndex.append("</th></tr>");
// column 表头
StringBuilder mdColumn = new StringBuilder(PatternConstant.MD_SPLIT);
StringBuilder htmlColumn = new StringBuilder("<tr><th>");
for (int i = 0; i < CommonConstant.COLUMN_HEAD_NAMES.length; i++) {
mdColumn.append(CommonConstant.COLUMN_HEAD_NAMES[i]).append(i == CommonConstant.COLUMN_HEAD_NAMES.length - 1 ? "" : PatternConstant.MD_SPLIT);
htmlColumn.append(CommonConstant.COLUMN_HEAD_NAMES[i]).append(i == CommonConstant.COLUMN_HEAD_NAMES.length - 1 ? "" : "</th><th>");
}
mdColumn.append(PatternConstant.MD_SPLIT);
htmlColumn.append("</th></tr>");
PatternConstant.ALL_INDEX_TABLE_HEADER = mdIndex.toString();
PatternConstant.HTML_INDEX_TABLE_HEADER = htmlIndex.toString();
PatternConstant.ALL_TABLE_HEADER = mdColumn.toString();
PatternConstant.HTML_TABLE_HEADER = htmlColumn.toString();
listMap.clear();
indexMap.clear();
}

View File

@ -1,6 +1,5 @@
package ai.chat2db.server.web.api.controller.rdb.doc.constant;
import ai.chat2db.server.tools.common.util.I18nUtils;
import lombok.extern.java.Log;
/**
@ -13,19 +12,6 @@ public final class CommonConstant {
/**
* 表head
**/
public static String[] INDEX_HEAD_NAMES =
{I18nUtils.getMessage("main.indexName"),
I18nUtils.getMessage("main.indexFieldName"),
I18nUtils.getMessage("main.indexType"),
I18nUtils.getMessage("main.indexMethod"),
I18nUtils.getMessage("main.indexNote")};
public static String[] COLUMN_HEAD_NAMES =
{I18nUtils.getMessage("main.fieldNo"),
I18nUtils.getMessage("main.fieldName"),
I18nUtils.getMessage("main.fieldType"),
I18nUtils.getMessage("main.fieldLength"),
I18nUtils.getMessage("main.fieldIfEmpty"),
I18nUtils.getMessage("main.fieldDefault"),
I18nUtils.getMessage("main.fieldDecimalPlaces"),
I18nUtils.getMessage("main.fieldNote")};
public static String[] INDEX_HEAD_NAMES = {};
public static String[] COLUMN_HEAD_NAMES = {};
}

View File

@ -1,8 +1,6 @@
package ai.chat2db.server.web.api.controller.rdb.doc.constant;
import ai.chat2db.server.tools.common.util.I18nUtils;
/**
* PatternConstant
*
@ -20,21 +18,10 @@ public final class PatternConstant {
*/
public static final String TITLE = "# %s";
public static final String CATALOG = "## %s";
public static final String ALL_TABLE_HEADER = MD_SPLIT + I18nUtils.getMessage("main.fieldNo") + MD_SPLIT +
I18nUtils.getMessage("main.fieldName") + MD_SPLIT +
I18nUtils.getMessage("main.fieldType") + MD_SPLIT +
I18nUtils.getMessage("main.fieldLength") + MD_SPLIT +
I18nUtils.getMessage("main.fieldIfEmpty") + MD_SPLIT +
I18nUtils.getMessage("main.fieldDefault") + MD_SPLIT +
I18nUtils.getMessage("main.fieldDecimalPlaces") + MD_SPLIT +
I18nUtils.getMessage("main.fieldNote") + MD_SPLIT;
public static String ALL_TABLE_HEADER = "";
public static String TABLE_BODY = "|%s|%s|%s|%s|%s|%s|%s|%s|";
public static String TABLE_SEPARATOR = "|:----:|----|----|----|----|----|----|----|";
public static final String ALL_INDEX_TABLE_HEADER = MD_SPLIT + I18nUtils.getMessage("main.indexName") + MD_SPLIT +
I18nUtils.getMessage("main.indexFieldName") + MD_SPLIT +
I18nUtils.getMessage("main.indexType") + MD_SPLIT +
I18nUtils.getMessage("main.indexMethod") + MD_SPLIT +
I18nUtils.getMessage("main.indexNote") + MD_SPLIT;
public static String ALL_INDEX_TABLE_HEADER = "";
public static String INDEX_TABLE_BODY = "|%s|%s|%s|%s|";
public static String INDEX_TABLE_SEPARATOR = "|:----:|----|----|----|";
@ -44,20 +31,8 @@ public final class PatternConstant {
public static final String HTML_TITLE = "<h1 id=\"{0}\">{0}</h1>";
public static final String HTML_CATALOG = "<h2 id=\"{0}\">{1}</h2>";
public static final String HTML_INDEX_ITEM = "<a href=\"#{0}\" title=\"{0}\">{1}</a>";
public static String HTML_TABLE_HEADER = "<tr><th>" + I18nUtils.getMessage("main.fieldNo")
+ "</th><th>" + I18nUtils.getMessage("main.fieldName")
+ "</th><th>"+ I18nUtils.getMessage("main.fieldType")
+ "</th><th>" + I18nUtils.getMessage("main.fieldLength")
+ "</th><th>" + I18nUtils.getMessage("main.fieldIfEmpty")
+ "</th><th>" + I18nUtils.getMessage("main.fieldDefault")
+ "</th><th>" + I18nUtils.getMessage("main.fieldDecimalPlaces")
+ "</th><th>" + I18nUtils.getMessage("main.fieldNote")
+ "</th></tr>";
public static String HTML_TABLE_HEADER = "";
public static String HTML_TABLE_BODY = "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>";
public static String HTML_INDEX_TABLE_HEADER = "<tr><th>" + I18nUtils.getMessage("main.indexName")
+ "</th><th>" + I18nUtils.getMessage("main.indexFieldName")
+ "</th><th>" + I18nUtils.getMessage("main.indexType")
+ "</th><th>" + I18nUtils.getMessage("main.indexMethod")
+ "</th><th>" + I18nUtils.getMessage("main.indexNote") + "</th></tr>";
public static String HTML_INDEX_TABLE_HEADER = "";
public static String HTML_INDEX_TABLE_BODY = "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>";
}