From 3c31130cbe89704d93cb8cd25e4841d05adebe6a Mon Sep 17 00:00:00 2001 From: liushuang Date: Mon, 29 Sep 2025 11:49:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(table):=20=E6=96=B0=E5=A2=9E=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E9=80=89=E9=A1=B9=E9=85=8D=E7=BD=AE=E6=96=B9=E6=B3=95?= =?UTF-8?q?-=20=E6=96=B0=E5=A2=9E=20setTableOptions=E9=87=8D=E8=BD=BD?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=B1=9E=E6=80=A7=E5=92=8C=E5=8C=85=E5=90=AB=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=88=97=E8=A1=A8=20-=E4=BC=98=E5=8C=96=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=98=A0=E5=B0=84=E8=BF=87=E6=BB=A4=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E6=8C=89=E5=8C=85=E5=90=AB=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=88=97=E8=A1=A8=E8=BF=87=E6=BB=A4-=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E5=86=97=E4=BD=99=E7=9A=84=E8=A1=A8=E5=A4=B4=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=96=B9=E6=B3=95=E5=92=8C=E6=B3=A8=E9=87=8A=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=20-=20=E8=B0=83=E6=95=B4=E6=96=B9=E6=B3=95=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=A1=BA=E5=BA=8F=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7-=20=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E9=85=8D=E7=BD=AE=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=90=AF=E7=94=A8=E6=8F=8F=E8=BF=B0=E4=BF=A1?= =?UTF-8?q?=E6=81=AF-=20=E9=87=8D=E6=9E=84=E5=AD=97=E6=AE=B5=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=A4=84=E7=90=86=E6=B5=81=E7=A8=8B=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E9=AB=98=E4=BB=A3=E7=A0=81=E5=A4=8D=E7=94=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/isliu/core/utils/FsTableUtil.java | 79 +++++++------------ 1 file changed, 28 insertions(+), 51 deletions(-) diff --git a/src/main/java/cn/isliu/core/utils/FsTableUtil.java b/src/main/java/cn/isliu/core/utils/FsTableUtil.java index 1cc401a..e11bc8f 100644 --- a/src/main/java/cn/isliu/core/utils/FsTableUtil.java +++ b/src/main/java/cn/isliu/core/utils/FsTableUtil.java @@ -307,6 +307,34 @@ public class FsTableUtil { return resultMap; } + public static void setTableOptions(String spreadsheetToken, String sheetId, Class clazz) { + setTableOptions(spreadsheetToken, sheetId, clazz, null, null); + } + + public static void setTableOptions(String spreadsheetToken, String sheetId, Class clazz, + Map customProperties, List includeFields) { + Map fieldsMap = PropertyUtil.getTablePropertyFieldsMap(clazz); + Map currFieldsMap; + if (includeFields != null && !includeFields.isEmpty()) { + currFieldsMap = fieldsMap.entrySet().stream() + .filter(entry -> { + String field = entry.getValue().getField(); + field = field.substring(field.lastIndexOf(".") + 1); + if (field.isEmpty()) { + return false; + } + return includeFields.contains(StringUtil.toUnderscoreCase(field)); + }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } else { + currFieldsMap = fieldsMap; + } + + List headers = PropertyUtil.getHeaders(currFieldsMap, includeFields); + + TableConf tableConf = PropertyUtil.getTableConf(clazz); + setTableOptions(spreadsheetToken, headers, currFieldsMap, sheetId, tableConf.enableDesc(), customProperties); + } + public static void setTableOptions(String spreadsheetToken, List headers, Map fieldsMap, String sheetId, boolean enableDesc, Map customProperties) { @@ -357,11 +385,6 @@ public class FsTableUtil { setTableOptions(spreadsheetToken, headers, fieldsMap, sheetId, enableDesc, null); } -// public static CustomValueService.ValueRequest getHeadTemplateBuilder(String sheetId, List headers, -// Map fieldsMap, TableConf tableConf) { -// return getHeadTemplateBuilder(sheetId, headers, fieldsMap, null, tableConf); -// } - public static CustomValueService.ValueRequest getHeadTemplateBuilder(String sheetId, List headers, Map fieldsMap, TableConf tableConf) { return getHeadTemplateBuilder(sheetId, headers, fieldsMap, tableConf, null); @@ -424,52 +447,6 @@ public class FsTableUtil { return batchPutValuesBuilder.build(); } - @NotNull - private static List getIncludeFieldHeaders(List headers, Map fieldsMap, List includeFields) { - return includeFields.stream() - .map(includeField -> { - // 查找匹配的fieldsMap key - for (Map.Entry entry : fieldsMap.entrySet()) { - FieldProperty fieldProperty = entry.getValue(); - if (fieldProperty != null && fieldProperty.getTableProperty() != null) { - String field = fieldProperty.getField(); - if (field != null) { - // 获取最后一个属性并转换为下划线格式 - String[] split = field.split("\\."); - String lastValue = split[split.length - 1]; - String underscoreFormat = StringUtil.toUnderscoreCase(lastValue); - // 如果匹配,返回fieldsMap的key - if (underscoreFormat.equals(includeField)) { - return entry.getKey(); - } - - if (lastValue.equals(includeField)) { - return entry.getKey(); - } - } - } - } - // 如果没有匹配到,返回原始值 - return includeField; - }) - .sorted(Comparator.comparingInt(includeFields::indexOf)) - .collect(Collectors.toList()); - } - - /** - * 获取按order排序的表头列表 - * - * @param fieldsMap 字段属性映射 - * @return 按order排序的表头列表 - */ - private static List getSortedHeaders(Map fieldsMap) { - return fieldsMap.entrySet().stream() - .filter(entry -> entry.getValue() != null && entry.getValue().getTableProperty() != null) - .sorted(Comparator.comparingInt(entry -> entry.getValue().getTableProperty().order())) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); - } - private static int getMaxLevel(Map fieldsMap) { AtomicInteger maxLevel = new AtomicInteger(1); fieldsMap.forEach((field, fieldProperty) -> {