koishi-plugin-jscn-aaaquery 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/index.js +127 -68
  2. package/package.json +1 -1
  3. package/readme.md +10 -18
package/lib/index.js CHANGED
@@ -797,6 +797,98 @@ function apply(ctx, config) {
797
797
  console.log(`清理了 ${expiredCount} 个超时的消息任务`);
798
798
  }
799
799
  }, MESSAGE_CLEAN_INTERVAL);
800
+ async function queryTerminalInfo(mac, needDetailedInfo = false) {
801
+ const formattedMac = formatMacAddress(mac);
802
+ try {
803
+ const onuList = await queryOnuList(formattedMac);
804
+ if (!onuList) {
805
+ throw new Error("未找到该MAC地址的设备信息");
806
+ }
807
+ const [onuDetail, vlanInfo] = await Promise.all([
808
+ queryOnuDetailInfo(onuList.id),
809
+ queryOnuDetailVlanInfo(onuList.id)
810
+ ]);
811
+ if (needDetailedInfo) {
812
+ const [ccname, order] = await Promise.all([
813
+ queryCCName(formattedMac),
814
+ queryOnuOrder(onuDetail)
815
+ ]);
816
+ return {
817
+ onuList,
818
+ onuDetail,
819
+ ccname,
820
+ order,
821
+ vlanInfo
822
+ };
823
+ }
824
+ return {
825
+ onuList,
826
+ onuDetail,
827
+ vlanInfo
828
+ };
829
+ } catch (error) {
830
+ console.error("终端查询过程出错:", error);
831
+ throw error;
832
+ }
833
+ }
834
+ __name(queryTerminalInfo, "queryTerminalInfo");
835
+ async function smartQueryMacAddress(cleanInput) {
836
+ try {
837
+ const { onuDetail, ccname, order, vlanInfo } = await queryTerminalInfo(cleanInput, true);
838
+ const messages = [
839
+ "🖥️ 终端基本信息",
840
+ "--------------------------------",
841
+ `MAC地址: ${cleanInput}`,
842
+ `状态:${onuDetail.status === 1 ? "在线 ✅" : "不在线 ❌"}`,
843
+ `机房: ${onuDetail.roomName}`,
844
+ `设备名称: `,
845
+ `${onuDetail.deviceName}`,
846
+ `OLT IP: ${onuDetail.oltIp}`,
847
+ `PON端口: ${onuDetail.portName}`,
848
+ `端口逻辑号: ${onuDetail.logicId}`,
849
+ `发射光功率: ${onuDetail.onuSendPower === "设备不在线" ? "设备不在线" : onuDetail.onuSendPower + "dBm"}`,
850
+ `接收光功率: ${onuDetail.onuReceivePower === "设备不在线" ? "设备不在线" : onuDetail.onuReceivePower + "dBm"}${onuDetail.onuReceivePower !== "设备不在线" ? " " + evaluateOpticalPower(onuDetail.onuReceivePower) : ""}`,
851
+ `CCName: ${ccname}`,
852
+ "",
853
+ "📃 工单信息",
854
+ "--------------------------------",
855
+ order ? [
856
+ `工单编号: ${order.orderId}`,
857
+ `创建时间: ${order.createDate}`,
858
+ `更新时间: ${order.updateDate}`
859
+ ].join("\n") : "无工单信息",
860
+ "",
861
+ "⚙️ 业务配置信息",
862
+ "--------------------------------"
863
+ ];
864
+ const vlanGroups = {};
865
+ vlanInfo.forEach((info) => {
866
+ const key = `${info.VLAN !== void 0 && info.VLAN !== null && info.VLAN !== "-" ? info.VLAN : "未配置"}-${info.actualVlan !== void 0 && info.actualVlan !== null ? info.actualVlan : "未配置"}`;
867
+ if (!vlanGroups[key]) {
868
+ vlanGroups[key] = {
869
+ VLAN: info.VLAN !== void 0 && info.VLAN !== null && info.VLAN !== "-" ? info.VLAN : "未配置",
870
+ actualVlan: info.actualVlan !== void 0 && info.actualVlan !== null ? info.actualVlan : "未配置",
871
+ ports: []
872
+ };
873
+ }
874
+ vlanGroups[key].ports.push(info.LAN);
875
+ });
876
+ Object.values(vlanGroups).forEach((group) => {
877
+ const portsText = group.ports.join(",");
878
+ messages.push(
879
+ `端口 ${portsText}:`,
880
+ ` 端口VLAN: ${group.VLAN}`,
881
+ ` 工单VLAN: ${group.actualVlan}`
882
+ );
883
+ });
884
+ messages.push("--------------------------------");
885
+ return messages.join("\n");
886
+ } catch (error) {
887
+ console.error("查询MAC地址过程出错:", error);
888
+ return "查询失败,请稍后重试";
889
+ }
890
+ }
891
+ __name(smartQueryMacAddress, "smartQueryMacAddress");
800
892
  ctx.middleware(async (session, next) => {
801
893
  console.log("原始消息:", session.content);
802
894
  const originalInput = session.stripped.content.trim();
@@ -817,54 +909,7 @@ function apply(ctx, config) {
817
909
  console.log("处理后的内容:", cleanInput);
818
910
  if (isValidMacAddress(cleanInput)) {
819
911
  console.log("内容是合法的MAC地址,开始查询");
820
- try {
821
- const onuList = await queryOnuList(cleanInput);
822
- if (!onuList) {
823
- return "未找到该MAC地址的设备信息";
824
- }
825
- const onuDetail = await queryOnuDetailInfo(onuList.id);
826
- const ccname = await queryCCName(cleanInput);
827
- const order = await queryOnuOrder(onuDetail);
828
- const vlanInfo = await queryOnuDetailVlanInfo(onuList.id);
829
- const messages = [
830
- "🖥️ 终端基本信息",
831
- "--------------------------------",
832
- `MAC地址: ${cleanInput}`,
833
- `状态:${onuDetail.status === 1 ? "在线 ✅" : "不在线 ❌"}`,
834
- `机房: ${onuDetail.roomName}`,
835
- `设备名称: `,
836
- `${onuDetail.deviceName}`,
837
- `OLT IP: ${onuDetail.oltIp}`,
838
- `PON端口: ${onuDetail.portName}`,
839
- `端口逻辑号: ${onuDetail.logicId}`,
840
- `发射光功率: ${onuDetail.onuSendPower === "设备不在线" ? "设备不在线" : onuDetail.onuSendPower + "dBm"}`,
841
- `接收光功率: ${onuDetail.onuReceivePower === "设备不在线" ? "设备不在线" : onuDetail.onuReceivePower + "dBm"}${onuDetail.onuReceivePower !== "设备不在线" ? " " + evaluateOpticalPower(onuDetail.onuReceivePower) : ""}`,
842
- `CCName: ${ccname}`,
843
- "",
844
- "📃 工单信息",
845
- "--------------------------------",
846
- order ? [
847
- `工单编号: ${order.orderId}`,
848
- `创建时间: ${order.createDate}`,
849
- `更新时间: ${order.updateDate}`
850
- ].join("\n") : "无工单信息",
851
- "",
852
- "⚙️ 业务配置信息",
853
- "--------------------------------"
854
- ];
855
- vlanInfo.forEach((info) => {
856
- messages.push(
857
- `端口 ${info.LAN}:`,
858
- ` 端口VLAN: ${info.VLAN || "未配置"}`,
859
- ` 工单VLAN: ${info.actualVlan || "未配置"}`
860
- );
861
- });
862
- messages.push("--------------------------------");
863
- return messages.join("\n");
864
- } catch (error) {
865
- console.error("查询MAC地址过程出错:", error);
866
- return "查询失败,请稍后重试";
867
- }
912
+ return await smartQueryMacAddress(cleanInput);
868
913
  } else {
869
914
  console.log("内容不是MAC地址,尝试作为账号查询");
870
915
  try {
@@ -1077,12 +1122,7 @@ function apply(ctx, config) {
1077
1122
  addToMessageQueue(session, async () => {
1078
1123
  try {
1079
1124
  const formattedMac = formatMacAddress(mac);
1080
- const onuList = await queryOnuList(formattedMac);
1081
- if (!onuList) {
1082
- return "未找到该MAC地址的设备信息";
1083
- }
1084
- const onuDetail = await queryOnuDetailInfo(onuList.id);
1085
- const vlanInfo = await queryOnuDetailVlanInfo(onuList.id);
1125
+ const { onuDetail, vlanInfo } = await queryTerminalInfo(formattedMac, false);
1086
1126
  const messages = [
1087
1127
  "🖥️ 终端基本信息",
1088
1128
  "--------------------------------",
@@ -1096,11 +1136,24 @@ function apply(ctx, config) {
1096
1136
  "⚙️ 业务配置信息",
1097
1137
  "--------------------------------"
1098
1138
  ];
1139
+ const vlanGroups = {};
1099
1140
  vlanInfo.forEach((info) => {
1141
+ const key = `${info.VLAN !== void 0 && info.VLAN !== null && info.VLAN !== "-" ? info.VLAN : "未配置"}-${info.actualVlan !== void 0 && info.actualVlan !== null ? info.actualVlan : "未配置"}`;
1142
+ if (!vlanGroups[key]) {
1143
+ vlanGroups[key] = {
1144
+ VLAN: info.VLAN !== void 0 && info.VLAN !== null && info.VLAN !== "-" ? info.VLAN : "未配置",
1145
+ actualVlan: info.actualVlan !== void 0 && info.actualVlan !== null ? info.actualVlan : "未配置",
1146
+ ports: []
1147
+ };
1148
+ }
1149
+ vlanGroups[key].ports.push(info.LAN);
1150
+ });
1151
+ Object.values(vlanGroups).forEach((group) => {
1152
+ const portsText = group.ports.join(",");
1100
1153
  messages.push(
1101
- `端口 ${info.LAN}:`,
1102
- ` 端口VLAN: ${info.VLAN || "未配置"}`,
1103
- ` 工单VLAN: ${info.actualVlan || "未配置"}`
1154
+ `端口 ${portsText}:`,
1155
+ ` 端口VLAN: ${group.VLAN}`,
1156
+ ` 工单VLAN: ${group.actualVlan}`
1104
1157
  );
1105
1158
  });
1106
1159
  messages.push("--------------------------------");
@@ -1119,14 +1172,7 @@ function apply(ctx, config) {
1119
1172
  addToMessageQueue(session, async () => {
1120
1173
  try {
1121
1174
  const formattedMac = formatMacAddress(mac);
1122
- const onuList = await queryOnuList(formattedMac);
1123
- if (!onuList) {
1124
- return "未找到该MAC地址的设备信息";
1125
- }
1126
- const onuDetail = await queryOnuDetailInfo(onuList.id);
1127
- const ccname = await queryCCName(formattedMac);
1128
- const order = await queryOnuOrder(onuDetail);
1129
- const vlanInfo = await queryOnuDetailVlanInfo(onuList.id);
1175
+ const { onuDetail, ccname, order, vlanInfo } = await queryTerminalInfo(formattedMac, true);
1130
1176
  const messages = [
1131
1177
  "🖥️ 终端基本信息",
1132
1178
  "--------------------------------",
@@ -1153,11 +1199,24 @@ function apply(ctx, config) {
1153
1199
  "⚙️ 业务配置信息",
1154
1200
  "--------------------------------"
1155
1201
  ];
1202
+ const vlanGroups = {};
1156
1203
  vlanInfo.forEach((info) => {
1204
+ const key = `${info.VLAN !== void 0 && info.VLAN !== null && info.VLAN !== "-" ? info.VLAN : "未配置"}-${info.actualVlan !== void 0 && info.actualVlan !== null ? info.actualVlan : "未配置"}`;
1205
+ if (!vlanGroups[key]) {
1206
+ vlanGroups[key] = {
1207
+ VLAN: info.VLAN !== void 0 && info.VLAN !== null && info.VLAN !== "-" ? info.VLAN : "未配置",
1208
+ actualVlan: info.actualVlan !== void 0 && info.actualVlan !== null ? info.actualVlan : "未配置",
1209
+ ports: []
1210
+ };
1211
+ }
1212
+ vlanGroups[key].ports.push(info.LAN);
1213
+ });
1214
+ Object.values(vlanGroups).forEach((group) => {
1215
+ const portsText = group.ports.join(",");
1157
1216
  messages.push(
1158
- `端口 ${info.LAN}:`,
1159
- ` 端口VLAN: ${info.VLAN || "未配置"}`,
1160
- ` 工单VLAN: ${info.actualVlan || "未配置"}`
1217
+ `端口 ${portsText}:`,
1218
+ ` 端口VLAN: ${group.VLAN}`,
1219
+ ` 工单VLAN: ${group.actualVlan}`
1161
1220
  );
1162
1221
  });
1163
1222
  messages.push("--------------------------------");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-jscn-aaaquery",
3
3
  "description": "江苏有线无锡分公司宽带信息查询插件",
4
- "version": "1.0.6",
4
+ "version": "1.0.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -104,6 +104,8 @@
104
104
  7. **超时处理**:设置请求超时,自动处理长时间未响应的请求
105
105
  8. **格式优化**:优化消息显示格式,使用直观的图标显示状态信息
106
106
  9. **错误处理**:完善的错误处理机制,确保查询失败时有清晰的提示
107
+ 10. **并行查询**:终端查询采用并行请求策略,在保持接口依赖关系的同时大幅提升查询速度
108
+ 11. **智能合并**:具有相同VLAN配置的多个LAN端口会自动合并显示,提高信息的可读性
107
109
 
108
110
  ## 显示优化
109
111
 
@@ -126,6 +128,11 @@
126
128
  - 内容丰富的查询结果使用新行显示
127
129
  - 简短提示直接显示在同一行
128
130
 
131
+ 5. **VLAN显示**:
132
+ - 端口VLAN值为"-"时显示为"未配置"
133
+ - 工单VLAN值为0时正确显示为"0"
134
+ - 相同VLAN配置的多个LAN端口合并显示,如"LAN2,LAN3,LAN4"
135
+
129
136
  ## 注意事项
130
137
  1. 所有查询都需要正确的权限和配置。
131
138
  2. MAC地址不区分大小写,支持多种分隔符格式,包括中文符号。
@@ -138,27 +145,12 @@
138
145
  9. 针对上线失败或离线状态的账号,系统也能提供有用的信息,不会简单报错。
139
146
  10. 所有命令支持带斜杠(如`/账号查询`)和不带斜杠(如`账号查询`)两种触发方式,提高命令输入的灵活性。
140
147
 
141
- ## 开发相关
142
-
143
- 为了支持开发过程中的热重载功能,需要确保:
144
- 1. 在`koishi.yml`中正确配置hmr插件
145
- 2. 安装并启用loader服务
146
- 3. 在开发环境下运行Koishi时设置`NODE_ENV=development`
147
-
148
- ```yaml
149
- # 开发相关配置示例
150
- group:develop:
151
- $if: env.NODE_ENV === 'development'
152
- hmr:
153
- root:
154
- - .
155
- loader:
156
- watch: true
157
- ```
158
-
159
148
  ## 更新日志
160
149
 
161
150
  ### 最新更新
151
+ - 优化终端查询性能,实现并行请求,大幅减少查询响应时间
152
+ - 智能合并显示具有相同VLAN配置的LAN端口,使得信息展示更加清晰
153
+ - 优化VLAN值显示:端口VLAN为"-"时显示为"未配置",工单VLAN为0时正确显示为"0"
162
154
  - 增加了对双触发词的支持,同时兼容带斜杠(如`/账号查询`)和不带斜杠(如`账号查询`)的命令格式
163
155
  - 增加了离线状态和上线失败状态的特殊处理,提供更多有用信息
164
156
  - 修复了状态图标显示问题,确保"不在线"状态正确显示❌图标