From 4adfe94961b8afd6886a4b4d4f787203e3ff115e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=94=E6=B0=91=E5=B0=8F=E9=95=87?= <262610965@qq.com> Date: Sat, 2 Nov 2024 22:02:48 +0800 Subject: [PATCH] :whale: perf(i18n): #376 TextDocumentGenerate --- .../core/ActionParserListenerAbout.java | 1 - .../core/doc/ActionMemberCmdDocument.java | 7 ++- .../skeleton/core/doc/BroadcastDocument.java | 2 + .../core/doc/BroadcastDocumentBuilder.java | 1 + .../skeleton/core/doc/DocumentAnalyseKit.java | 11 +++-- .../core/doc/IoGameDocumentHelper.java | 7 +++ .../core/doc/TextDocumentGenerate.java | 44 +++++++++++++------ .../game/action/skeleton/i18n/MessageKey.java | 7 +++ .../src/main/resources/iohao.properties | 7 ++- .../src/main/resources/iohao_zh_CN.properties | 6 +++ .../com/iohao/game/common/kit/StrKit.java | 13 ++++++ 11 files changed, 85 insertions(+), 21 deletions(-) diff --git a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/ActionParserListenerAbout.java b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/ActionParserListenerAbout.java index 3a47fa0e2..555271f41 100644 --- a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/ActionParserListenerAbout.java +++ b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/ActionParserListenerAbout.java @@ -104,7 +104,6 @@ public void onAfter(BarSkeleton barSkeleton) { } } - /** * proto 协议类型添检测 * diff --git a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/ActionMemberCmdDocument.java b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/ActionMemberCmdDocument.java index 2273000a2..8d7b98f5b 100644 --- a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/ActionMemberCmdDocument.java +++ b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/ActionMemberCmdDocument.java @@ -18,6 +18,7 @@ */ package com.iohao.game.action.skeleton.core.doc; +import com.iohao.game.action.skeleton.core.CmdKit; import lombok.Getter; import lombok.Setter; @@ -31,14 +32,16 @@ @Getter @Setter public final class ActionMemberCmdDocument { - int cmd; - int subCmd; + final int cmd; + final int subCmd; + final int cmdMerge; String comment; String memberName; ActionMemberCmdDocument(int cmd, int subCmd, String memberName, String comment) { this.cmd = cmd; this.subCmd = subCmd; + this.cmdMerge = CmdKit.merge(cmd, subCmd); this.comment = comment; this.memberName = memberName; } diff --git a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/BroadcastDocument.java b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/BroadcastDocument.java index 808a685bb..a40a206ff 100644 --- a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/BroadcastDocument.java +++ b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/BroadcastDocument.java @@ -42,6 +42,7 @@ public final class BroadcastDocument { String methodDescription; /** 方法名 */ String methodName; + String cmdMethodName; /** 业务类型 */ Class dataClass; @@ -67,6 +68,7 @@ public final class BroadcastDocument { String dataActualTypeNameSimple; String exampleCode; + String exampleCodeAction; public int getCmdMerge() { return this.cmdInfo.getCmdMerge(); diff --git a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/BroadcastDocumentBuilder.java b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/BroadcastDocumentBuilder.java index 23e5dc3ea..b315f1e76 100644 --- a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/BroadcastDocumentBuilder.java +++ b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/BroadcastDocumentBuilder.java @@ -144,6 +144,7 @@ public BroadcastDocument build() { // 方法相关 .setMethodDescription(this.methodDescription) .setMethodName(theMethodName) + .setCmdMethodName(StrKit.firstCharToLowerCase(theMethodName)) // 业务参数相关 .setDataClass(this.dataClass) .setDataClassName(this.dataClassName) diff --git a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/DocumentAnalyseKit.java b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/DocumentAnalyseKit.java index e117eb588..54f587540 100644 --- a/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/DocumentAnalyseKit.java +++ b/common/common-core/src/main/java/com/iohao/game/action/skeleton/core/doc/DocumentAnalyseKit.java @@ -29,10 +29,7 @@ import java.io.File; import java.net.URL; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.function.Function; /** @@ -78,6 +75,12 @@ private List analyseActionErrorEnumDocument(Class broadcastDocu return; } - this.docContentJoiner.add("==================== 其它广播推送 ===================="); + String title = Bundle.getMessage(MessageKey.textDocumentBroadcastTitle); + this.docContentJoiner.add("==================== %s ====================".formatted(title)); + for (BroadcastDocument broadcastDocument : broadcastDocumentList) { - String template = "路由: {cmd} - {subCmd} --- 广播推送: {dataClass} {dataDescription}"; + String template = "{textDocumentCmd}: {cmd} - {subCmd} --- {textDocumentBroadcast}: {dataClass} {dataDescription}"; if (StrKit.isNotEmpty(broadcastDocument.getMethodDescription())) { - template = "路由: {cmd} - {subCmd} --- 广播推送: {dataClass} {dataDescription},({description})"; + template = "{textDocumentCmd}: {cmd} - {subCmd} --- {textDocumentBroadcast}: {dataClass} {dataDescription},({description})"; } - var stringObjectMap = new HashMap<>(); - stringObjectMap.put("cmd", broadcastDocument.getCmd()); - stringObjectMap.put("subCmd", broadcastDocument.getSubCmd()); - stringObjectMap.put("dataClass", broadcastDocument.getDataClassName()); - stringObjectMap.put("description", broadcastDocument.getMethodDescription()); - stringObjectMap.put("dataDescription", broadcastDocument.getDataDescription()); + var paramMap = toMap(broadcastDocument); - String format = StrKit.format(template, stringObjectMap); + String format = StrKit.format(template, paramMap); this.docContentJoiner.add(format); } this.docContentJoiner.add(""); } + private HashMap toMap(BroadcastDocument broadcastDocument) { + String textDocumentCmd = Bundle.getMessage(MessageKey.textDocumentCmd); + String textDocumentBroadcast = Bundle.getMessage(MessageKey.textDocumentBroadcast); + + var map = new HashMap<>(); + map.put("cmd", broadcastDocument.getCmd()); + map.put("subCmd", broadcastDocument.getSubCmd()); + map.put("dataClass", broadcastDocument.getDataClassName()); + map.put("description", broadcastDocument.getMethodDescription()); + map.put("dataDescription", broadcastDocument.getDataDescription()); + map.put("textDocumentCmd", textDocumentCmd); + map.put("textDocumentBroadcast", textDocumentBroadcast); + + return map; + } + private void extractedErrorCode(IoGameDocument ioGameDocument) { + String title = Bundle.getMessage(MessageKey.textDocumentErrorCodeTitle); - this.docContentJoiner.add("==================== 错误码 ===================="); + this.docContentJoiner.add("==================== %s ====================".formatted(title)); for (ErrorCodeDocument errorCodeDocument : ioGameDocument.getErrorCodeDocumentList()) { String format = "%s : %s : %s".formatted(errorCodeDocument.getValue(), diff --git a/common/common-core/src/main/java/com/iohao/game/action/skeleton/i18n/MessageKey.java b/common/common-core/src/main/java/com/iohao/game/action/skeleton/i18n/MessageKey.java index 764a01279..4825b19e7 100644 --- a/common/common-core/src/main/java/com/iohao/game/action/skeleton/i18n/MessageKey.java +++ b/common/common-core/src/main/java/com/iohao/game/action/skeleton/i18n/MessageKey.java @@ -70,4 +70,11 @@ public interface MessageKey { String cmdMergeLimit = "cmdMergeLimit"; /* see ProtobufCheckActionParserListener.java */ String protobufAnnotationCheck = "protobufAnnotationCheck"; + + /* see TextDocumentGenerate.java */ + String textDocumentTitle = "textDocumentTitle"; + String textDocumentBroadcastTitle = "textDocumentBroadcastTitle"; + String textDocumentCmd = "textDocumentCmd"; + String textDocumentBroadcast = "textDocumentBroadcast"; + String textDocumentErrorCodeTitle = "textDocumentErrorCodeTitle"; } diff --git a/common/common-core/src/main/resources/iohao.properties b/common/common-core/src/main/resources/iohao.properties index c055c0b4a..587a4ec8e 100644 --- a/common/common-core/src/main/resources/iohao.properties +++ b/common/common-core/src/main/resources/iohao.properties @@ -39,4 +39,9 @@ timeRangeInOutMinuteTitle=[%d~%d minutes, execute:%d] cmdMergeLimit=%s exceeds the maximum default value. Please set the capacity manually if necessary. Default maximum capacity %d, current capacity %d # see ProtobufCheckActionParserListener protobufAnnotationCheck=Note that the protocol class does not have the ProtobufClass annotation added - +# see TextDocumentGenerate +textDocumentTitle=Game Document Format Description +textDocumentBroadcastTitle=Other broadcast interfaces +textDocumentCmd=Routing +textDocumentBroadcast=Broadcast +textDocumentErrorCodeTitle=Error Code diff --git a/common/common-core/src/main/resources/iohao_zh_CN.properties b/common/common-core/src/main/resources/iohao_zh_CN.properties index cea8f66b0..7293e8090 100644 --- a/common/common-core/src/main/resources/iohao_zh_CN.properties +++ b/common/common-core/src/main/resources/iohao_zh_CN.properties @@ -39,3 +39,9 @@ timeRangeInOutMinuteTitle=[%d~%d分钟,%d 次] cmdMergeLimit=%s 超过最大默认值,如有需要请手动设置容量。默认最大容量 %d. 当前容量 %d # see ProtobufCheckActionParserListener protobufAnnotationCheck=注意,协议类没有添加 ProtobufClass 注解 +# see TextDocumentGenerate +textDocumentTitle=游戏文档格式说明 +textDocumentBroadcastTitle=其它广播推送 +textDocumentCmd=路由 +textDocumentBroadcast=广播 +textDocumentErrorCodeTitle=错误码 diff --git a/common/common-micro-kit/src/main/java/com/iohao/game/common/kit/StrKit.java b/common/common-micro-kit/src/main/java/com/iohao/game/common/kit/StrKit.java index 69298f4b3..eb5ea5520 100644 --- a/common/common-micro-kit/src/main/java/com/iohao/game/common/kit/StrKit.java +++ b/common/common-micro-kit/src/main/java/com/iohao/game/common/kit/StrKit.java @@ -22,6 +22,8 @@ import lombok.NonNull; import lombok.experimental.UtilityClass; +import java.sql.SQLOutput; +import java.util.Arrays; import java.util.Map; /** @@ -48,6 +50,17 @@ public String firstCharToUpperCase(String value) { return value; } + public String firstCharToLowerCase(String value) { + char firstChar = value.charAt(0); + if (firstChar >= 'A' && firstChar <= 'Z') { + char[] arr = value.toCharArray(); + arr[0] += 32; + return String.valueOf(arr); + } + + return value; + } + public String format(@NonNull CharSequence template, @NonNull Map map) { return AdapterHuUtils.format(template, map); }