koishi-plugin-jscn-aaaquery 1.0.0 → 1.0.2
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.
- package/lib/index.js +347 -181
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -35,6 +35,97 @@ var Config = import_koishi.Schema.object({
|
|
|
35
35
|
function apply(ctx, config) {
|
|
36
36
|
let currentToken = null;
|
|
37
37
|
let tokenExpireTime = 0;
|
|
38
|
+
const requestQueue = {};
|
|
39
|
+
const cache = {};
|
|
40
|
+
const CACHE_EXPIRE_TIME = 5 * 60 * 1e3;
|
|
41
|
+
const CACHE_CLEAN_INTERVAL = 60 * 1e3;
|
|
42
|
+
const QUEUE_EXPIRE_TIME = 10 * 60 * 1e3;
|
|
43
|
+
const QUEUE_CLEAN_INTERVAL = 5 * 60 * 1e3;
|
|
44
|
+
const MAX_CONCURRENT_REQUESTS = 10;
|
|
45
|
+
let currentConcurrentRequests = 0;
|
|
46
|
+
const requestWaitQueue = [];
|
|
47
|
+
function getCacheKey(type, params) {
|
|
48
|
+
return `${type}:${JSON.stringify(params)}`;
|
|
49
|
+
}
|
|
50
|
+
__name(getCacheKey, "getCacheKey");
|
|
51
|
+
function getFromCache(type, params) {
|
|
52
|
+
const key = getCacheKey(type, params);
|
|
53
|
+
const item = cache[key];
|
|
54
|
+
if (item && Date.now() - item.timestamp <= CACHE_EXPIRE_TIME) {
|
|
55
|
+
return item.data;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
__name(getFromCache, "getFromCache");
|
|
60
|
+
function setCache(type, params, data) {
|
|
61
|
+
const key = getCacheKey(type, params);
|
|
62
|
+
cache[key] = {
|
|
63
|
+
data,
|
|
64
|
+
timestamp: Date.now()
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
__name(setCache, "setCache");
|
|
68
|
+
setInterval(() => {
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
for (const key in cache) {
|
|
71
|
+
if (now - cache[key].timestamp > CACHE_EXPIRE_TIME) {
|
|
72
|
+
delete cache[key];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}, CACHE_CLEAN_INTERVAL);
|
|
76
|
+
setInterval(() => {
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
for (const key in requestQueue) {
|
|
79
|
+
if (now - requestQueue[key].timestamp > QUEUE_EXPIRE_TIME) {
|
|
80
|
+
delete requestQueue[key];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}, QUEUE_CLEAN_INTERVAL);
|
|
84
|
+
function getQueueKey(type, params) {
|
|
85
|
+
return `${type}:${JSON.stringify(params)}`;
|
|
86
|
+
}
|
|
87
|
+
__name(getQueueKey, "getQueueKey");
|
|
88
|
+
async function waitForRequestSlot() {
|
|
89
|
+
if (currentConcurrentRequests < MAX_CONCURRENT_REQUESTS) {
|
|
90
|
+
currentConcurrentRequests++;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
return new Promise((resolve) => {
|
|
94
|
+
requestWaitQueue.push(() => {
|
|
95
|
+
currentConcurrentRequests++;
|
|
96
|
+
resolve();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
__name(waitForRequestSlot, "waitForRequestSlot");
|
|
101
|
+
function releaseRequestSlot() {
|
|
102
|
+
currentConcurrentRequests--;
|
|
103
|
+
if (requestWaitQueue.length > 0) {
|
|
104
|
+
const nextRequest = requestWaitQueue.shift();
|
|
105
|
+
if (nextRequest) {
|
|
106
|
+
nextRequest();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
__name(releaseRequestSlot, "releaseRequestSlot");
|
|
111
|
+
async function addToQueue(type, params, fn) {
|
|
112
|
+
const key = getQueueKey(type, params);
|
|
113
|
+
if (requestQueue[key]) {
|
|
114
|
+
return requestQueue[key].promise;
|
|
115
|
+
}
|
|
116
|
+
await waitForRequestSlot();
|
|
117
|
+
const promise = fn();
|
|
118
|
+
requestQueue[key] = {
|
|
119
|
+
promise,
|
|
120
|
+
timestamp: Date.now()
|
|
121
|
+
};
|
|
122
|
+
promise.finally(() => {
|
|
123
|
+
delete requestQueue[key];
|
|
124
|
+
releaseRequestSlot();
|
|
125
|
+
});
|
|
126
|
+
return promise;
|
|
127
|
+
}
|
|
128
|
+
__name(addToQueue, "addToQueue");
|
|
38
129
|
function formatMacAddress(mac) {
|
|
39
130
|
return mac.replace(/[:-\s.]/g, "").toLowerCase();
|
|
40
131
|
}
|
|
@@ -44,6 +135,14 @@ function apply(ctx, config) {
|
|
|
44
135
|
return /^[0-9a-f]{12}$/i.test(cleanMac);
|
|
45
136
|
}
|
|
46
137
|
__name(isValidMacAddress, "isValidMacAddress");
|
|
138
|
+
function formatAccount(account) {
|
|
139
|
+
return account.toUpperCase();
|
|
140
|
+
}
|
|
141
|
+
__name(formatAccount, "formatAccount");
|
|
142
|
+
function isAccountResponseComplete(data) {
|
|
143
|
+
return !!(data.accessUserName && data.onlineStatus && data.isPass && data.userIp && data.mac && data.maxUpSpeed !== void 0 && data.maxDownSpeed !== void 0 && data.accessDomain && data.startTime && data.startTimeSum !== void 0 && data.nickName);
|
|
144
|
+
}
|
|
145
|
+
__name(isAccountResponseComplete, "isAccountResponseComplete");
|
|
47
146
|
async function getToken() {
|
|
48
147
|
const now = Date.now();
|
|
49
148
|
if (currentToken && now < tokenExpireTime) {
|
|
@@ -52,10 +151,7 @@ function apply(ctx, config) {
|
|
|
52
151
|
}
|
|
53
152
|
try {
|
|
54
153
|
console.log("开始登录请求...");
|
|
55
|
-
|
|
56
|
-
loginName: config.loginName,
|
|
57
|
-
pwd: config.password
|
|
58
|
-
});
|
|
154
|
+
await waitForRequestSlot();
|
|
59
155
|
const response = await ctx.http.post(
|
|
60
156
|
`${config.baseUrl}/admin/login`,
|
|
61
157
|
`loginName=${encodeURIComponent(config.loginName)}&pwd=${encodeURIComponent(config.password)}`,
|
|
@@ -80,41 +176,56 @@ function apply(ctx, config) {
|
|
|
80
176
|
console.error("错误响应:", error.response.data);
|
|
81
177
|
}
|
|
82
178
|
throw error;
|
|
179
|
+
} finally {
|
|
180
|
+
releaseRequestSlot();
|
|
83
181
|
}
|
|
84
182
|
}
|
|
85
183
|
__name(getToken, "getToken");
|
|
86
184
|
async function queryAccount(account) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
185
|
+
const formattedAccount = formatAccount(account);
|
|
186
|
+
const cachedData = getFromCache("account", { account: formattedAccount });
|
|
187
|
+
if (cachedData) {
|
|
188
|
+
console.log("使用缓存的账号信息");
|
|
189
|
+
return cachedData;
|
|
190
|
+
}
|
|
191
|
+
return addToQueue("account", { account: formattedAccount }, async () => {
|
|
192
|
+
try {
|
|
193
|
+
console.log("开始查询账号信息...");
|
|
194
|
+
const token = await getToken();
|
|
195
|
+
const response = await ctx.http.get(`${config.baseUrl}/fttx/aaa/aaaCertification`, {
|
|
196
|
+
params: { accessUserName: formattedAccount },
|
|
197
|
+
headers: {
|
|
198
|
+
"Authorization": token,
|
|
199
|
+
"Accept": "application/json",
|
|
200
|
+
"Content-Type": "application/json"
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
204
|
+
if (response.status === 200 && response.data) {
|
|
205
|
+
if (!isAccountResponseComplete(response.data)) {
|
|
206
|
+
throw new Error("账号信息不完整,请检查账号是否正确");
|
|
207
|
+
}
|
|
208
|
+
setCache("account", { account: formattedAccount }, response.data);
|
|
209
|
+
return response.data;
|
|
96
210
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
console.error("查询错误详情:", error);
|
|
105
|
-
if (error.response) {
|
|
106
|
-
console.error("错误响应:", error.response.data);
|
|
211
|
+
throw new Error(`查询失败:${response.message || "未知错误"}`);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
console.error("查询错误详情:", error);
|
|
214
|
+
if (error.response) {
|
|
215
|
+
console.error("错误响应:", error.response.data);
|
|
216
|
+
}
|
|
217
|
+
throw error;
|
|
107
218
|
}
|
|
108
|
-
|
|
109
|
-
}
|
|
219
|
+
});
|
|
110
220
|
}
|
|
111
221
|
__name(queryAccount, "queryAccount");
|
|
112
222
|
async function queryAccountDetail(account) {
|
|
223
|
+
const formattedAccount = formatAccount(account);
|
|
113
224
|
try {
|
|
114
225
|
console.log("开始查询账号详情记录...");
|
|
115
226
|
const token = await getToken();
|
|
116
227
|
const response = await ctx.http.get(`${config.baseUrl}/fttx/aaa/getMoreRecord`, {
|
|
117
|
-
params: { accessUserName:
|
|
228
|
+
params: { accessUserName: formattedAccount },
|
|
118
229
|
headers: {
|
|
119
230
|
"Authorization": token,
|
|
120
231
|
"Accept": "application/json",
|
|
@@ -136,188 +247,243 @@ function apply(ctx, config) {
|
|
|
136
247
|
}
|
|
137
248
|
__name(queryAccountDetail, "queryAccountDetail");
|
|
138
249
|
async function queryOnuList(mac) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
250
|
+
const cachedData = getFromCache("onuList", { mac });
|
|
251
|
+
if (cachedData) {
|
|
252
|
+
console.log("使用缓存的设备信息");
|
|
253
|
+
return cachedData;
|
|
254
|
+
}
|
|
255
|
+
return addToQueue("onuList", { mac }, async () => {
|
|
256
|
+
try {
|
|
257
|
+
console.log("开始查询MAC设备信息...");
|
|
258
|
+
const token = await getToken();
|
|
259
|
+
const response = await ctx.http.get(`${config.baseUrl}/fttx/onu/searchOnuList`, {
|
|
260
|
+
params: { mac, limit: 10, page: 1 },
|
|
261
|
+
headers: {
|
|
262
|
+
"Authorization": token,
|
|
263
|
+
"Accept": "application/json",
|
|
264
|
+
"Content-Type": "application/json"
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
268
|
+
if (response.status === 200 && response.data && response.data.rows && response.data.rows.length > 0) {
|
|
269
|
+
const activeOnu = response.data.rows.find((row) => row.status === 1);
|
|
270
|
+
if (activeOnu) {
|
|
271
|
+
console.log("找到在线设备:", activeOnu);
|
|
272
|
+
setCache("onuList", { mac }, activeOnu);
|
|
273
|
+
return activeOnu;
|
|
274
|
+
}
|
|
275
|
+
const lastOnu = response.data.rows[response.data.rows.length - 1];
|
|
276
|
+
console.log("没有在线设备,返回最后一条记录:", lastOnu);
|
|
277
|
+
setCache("onuList", { mac }, lastOnu);
|
|
278
|
+
return lastOnu;
|
|
149
279
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
console.log("找到在线设备:", activeOnu);
|
|
156
|
-
return activeOnu;
|
|
280
|
+
throw new Error(`查询失败:${response.message || "未找到设备信息"}`);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
console.error("查询错误详情:", error);
|
|
283
|
+
if (error.response) {
|
|
284
|
+
console.error("错误响应:", error.response.data);
|
|
157
285
|
}
|
|
158
|
-
|
|
159
|
-
console.log("没有在线设备,返回最后一条记录:", lastOnu);
|
|
160
|
-
return lastOnu;
|
|
286
|
+
throw error;
|
|
161
287
|
}
|
|
162
|
-
|
|
163
|
-
} catch (error) {
|
|
164
|
-
console.error("查询错误详情:", error);
|
|
165
|
-
if (error.response) {
|
|
166
|
-
console.error("错误响应:", error.response.data);
|
|
167
|
-
}
|
|
168
|
-
throw error;
|
|
169
|
-
}
|
|
288
|
+
});
|
|
170
289
|
}
|
|
171
290
|
__name(queryOnuList, "queryOnuList");
|
|
172
291
|
async function queryOnuDetailInfo(onuId) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
292
|
+
const cachedData = getFromCache("onuDetail", { onuId });
|
|
293
|
+
if (cachedData) {
|
|
294
|
+
console.log("使用缓存的设备详细信息");
|
|
295
|
+
return cachedData;
|
|
296
|
+
}
|
|
297
|
+
return addToQueue("onuDetail", { onuId }, async () => {
|
|
298
|
+
try {
|
|
299
|
+
console.log("开始查询MAC详细信息...");
|
|
300
|
+
const token = await getToken();
|
|
301
|
+
const response = await ctx.http.get(`${config.baseUrl}/fttx/onu/onuDetailInfo`, {
|
|
302
|
+
params: { onuId },
|
|
303
|
+
headers: {
|
|
304
|
+
"Authorization": token,
|
|
305
|
+
"Accept": "application/json",
|
|
306
|
+
"Content-Type": "application/json"
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
310
|
+
if (response.status === 200 && response.data) {
|
|
311
|
+
if (response.data.status === 1 && (response.data.onuReceivePower === "0" || response.data.onuSendPower === "0")) {
|
|
312
|
+
console.log("设备在线但光功率为0,尝试刷新光功率...");
|
|
313
|
+
try {
|
|
314
|
+
const powerResponse = await ctx.http.get(
|
|
315
|
+
`${config.baseUrl}/fttx/onu/refreshOnuPower`,
|
|
316
|
+
{
|
|
317
|
+
params: {
|
|
318
|
+
cid: response.data.cid,
|
|
319
|
+
gponIndex: response.data.gponIndex,
|
|
320
|
+
onuIndex: response.data.onuIndex
|
|
321
|
+
},
|
|
322
|
+
headers: {
|
|
323
|
+
"Authorization": token,
|
|
324
|
+
"Accept": "application/json",
|
|
325
|
+
"Content-Type": "application/json"
|
|
326
|
+
}
|
|
201
327
|
}
|
|
328
|
+
);
|
|
329
|
+
if (powerResponse.status === 200 && powerResponse.data) {
|
|
330
|
+
console.log("光功率刷新成功:", powerResponse.data);
|
|
331
|
+
response.data.onuReceivePower = powerResponse.data.onuReceivePower;
|
|
332
|
+
response.data.onuSendPower = powerResponse.data.onuSendPower;
|
|
333
|
+
response.data.statusHealth = powerResponse.data.statusHealth;
|
|
202
334
|
}
|
|
203
|
-
)
|
|
204
|
-
|
|
205
|
-
console.log("光功率刷新成功:", powerResponse.data);
|
|
206
|
-
response.data.onuReceivePower = powerResponse.data.onuReceivePower;
|
|
207
|
-
response.data.onuSendPower = powerResponse.data.onuSendPower;
|
|
208
|
-
response.data.statusHealth = powerResponse.data.statusHealth;
|
|
335
|
+
} catch (error) {
|
|
336
|
+
console.error("刷新光功率失败:", error);
|
|
209
337
|
}
|
|
210
|
-
} catch (error) {
|
|
211
|
-
console.error("刷新光功率失败:", error);
|
|
212
338
|
}
|
|
339
|
+
setCache("onuDetail", { onuId }, response.data);
|
|
340
|
+
return response.data;
|
|
213
341
|
}
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
342
|
+
throw new Error(`查询失败:${response.message || "未知错误"}`);
|
|
343
|
+
} catch (error) {
|
|
344
|
+
console.error("查询错误详情:", error);
|
|
345
|
+
if (error.response) {
|
|
346
|
+
console.error("错误响应:", error.response.data);
|
|
347
|
+
}
|
|
348
|
+
throw error;
|
|
221
349
|
}
|
|
222
|
-
|
|
223
|
-
}
|
|
350
|
+
});
|
|
224
351
|
}
|
|
225
352
|
__name(queryOnuDetailInfo, "queryOnuDetailInfo");
|
|
226
353
|
async function queryCCName(mac) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
354
|
+
const cachedData = getFromCache("ccname", { mac });
|
|
355
|
+
if (cachedData) {
|
|
356
|
+
console.log("使用缓存的CCNAME");
|
|
357
|
+
return cachedData;
|
|
358
|
+
}
|
|
359
|
+
return addToQueue("ccname", { mac }, async () => {
|
|
360
|
+
try {
|
|
361
|
+
console.log("开始查询CCNAME...");
|
|
362
|
+
const token = await getToken();
|
|
363
|
+
const response = await ctx.http.get(`${config.baseUrl}/fttx/onu/getCCname`, {
|
|
364
|
+
params: { mac },
|
|
365
|
+
headers: {
|
|
366
|
+
"Authorization": token,
|
|
367
|
+
"Accept": "application/json",
|
|
368
|
+
"Content-Type": "application/json"
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
372
|
+
if (response.status === 200 && response.data && response.data.ccname) {
|
|
373
|
+
setCache("ccname", { mac }, response.data.ccname);
|
|
374
|
+
return response.data.ccname;
|
|
236
375
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return
|
|
376
|
+
return "无CCName";
|
|
377
|
+
} catch (error) {
|
|
378
|
+
console.error("查询错误详情:", error);
|
|
379
|
+
return "无CCName";
|
|
241
380
|
}
|
|
242
|
-
|
|
243
|
-
} catch (error) {
|
|
244
|
-
console.error("查询错误详情:", error);
|
|
245
|
-
return "无CCName";
|
|
246
|
-
}
|
|
381
|
+
});
|
|
247
382
|
}
|
|
248
383
|
__name(queryCCName, "queryCCName");
|
|
249
384
|
async function queryOnuOrder(onuDetail) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
385
|
+
const cacheKey = {
|
|
386
|
+
cid: onuDetail.cid,
|
|
387
|
+
gponIndex: onuDetail.gponIndex,
|
|
388
|
+
onuIndex: onuDetail.onuIndex,
|
|
389
|
+
serial: onuDetail.serial
|
|
390
|
+
};
|
|
391
|
+
const cachedData = getFromCache("onuOrder", cacheKey);
|
|
392
|
+
if (cachedData) {
|
|
393
|
+
console.log("使用缓存的工单信息");
|
|
394
|
+
return cachedData;
|
|
395
|
+
}
|
|
396
|
+
return addToQueue("onuOrder", cacheKey, async () => {
|
|
397
|
+
try {
|
|
398
|
+
console.log("开始查询工单信息...");
|
|
399
|
+
const token = await getToken();
|
|
400
|
+
const response = await ctx.http.get(`${config.baseUrl}/fttx/onu/onuOrderList`, {
|
|
401
|
+
params: {
|
|
402
|
+
cid: onuDetail.cid,
|
|
403
|
+
gponIndex: onuDetail.gponIndex,
|
|
404
|
+
onuIndex: onuDetail.onuIndex,
|
|
405
|
+
serial: onuDetail.serial
|
|
406
|
+
},
|
|
407
|
+
headers: {
|
|
408
|
+
"Authorization": token,
|
|
409
|
+
"Accept": "application/json",
|
|
410
|
+
"Content-Type": "application/json"
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
414
|
+
if (response.status === 200 && response.data && response.data.length > 0) {
|
|
415
|
+
setCache("onuOrder", cacheKey, response.data[0]);
|
|
416
|
+
return response.data[0];
|
|
264
417
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return
|
|
418
|
+
return null;
|
|
419
|
+
} catch (error) {
|
|
420
|
+
console.error("查询错误详情:", error);
|
|
421
|
+
return null;
|
|
269
422
|
}
|
|
270
|
-
|
|
271
|
-
} catch (error) {
|
|
272
|
-
console.error("查询错误详情:", error);
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
423
|
+
});
|
|
275
424
|
}
|
|
276
425
|
__name(queryOnuOrder, "queryOnuOrder");
|
|
277
426
|
async function queryOnuDetailVlanInfo(onuId) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
params: { onuId },
|
|
283
|
-
headers: {
|
|
284
|
-
"Authorization": token,
|
|
285
|
-
"Accept": "application/json",
|
|
286
|
-
"Content-Type": "application/json"
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
290
|
-
return response;
|
|
291
|
-
} catch (error) {
|
|
292
|
-
console.error("查询错误详情:", error);
|
|
293
|
-
return [];
|
|
427
|
+
const cachedData = getFromCache("onuVlan", { onuId });
|
|
428
|
+
if (cachedData) {
|
|
429
|
+
console.log("使用缓存的业务配置信息");
|
|
430
|
+
return cachedData;
|
|
294
431
|
}
|
|
432
|
+
return addToQueue("onuVlan", { onuId }, async () => {
|
|
433
|
+
try {
|
|
434
|
+
console.log("开始查询业务配置信息...");
|
|
435
|
+
const token = await getToken();
|
|
436
|
+
const response = await ctx.http.get(`${config.baseUrl}/fttx/onu/onuDetailVlanInfo`, {
|
|
437
|
+
params: { onuId },
|
|
438
|
+
headers: {
|
|
439
|
+
"Authorization": token,
|
|
440
|
+
"Accept": "application/json",
|
|
441
|
+
"Content-Type": "application/json"
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
445
|
+
setCache("onuVlan", { onuId }, response);
|
|
446
|
+
return response;
|
|
447
|
+
} catch (error) {
|
|
448
|
+
console.error("查询错误详情:", error);
|
|
449
|
+
return [];
|
|
450
|
+
}
|
|
451
|
+
});
|
|
295
452
|
}
|
|
296
453
|
__name(queryOnuDetailVlanInfo, "queryOnuDetailVlanInfo");
|
|
297
454
|
async function queryOrderLog(mac, startTime, endTime) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const response = await ctx.http.get(`${config.baseUrl}/fttx/orderAnalyBlock/selectorderAnalyBlockOneList`, {
|
|
304
|
-
params: {
|
|
305
|
-
mac: formattedMac,
|
|
306
|
-
startTime,
|
|
307
|
-
endTime
|
|
308
|
-
},
|
|
309
|
-
headers: {
|
|
310
|
-
"Authorization": token,
|
|
311
|
-
"Accept": "application/json",
|
|
312
|
-
"Content-Type": "application/json"
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
316
|
-
return response;
|
|
317
|
-
} catch (error) {
|
|
318
|
-
console.error("查询错误详情:", error);
|
|
319
|
-
return [];
|
|
455
|
+
const cacheKey = { mac, startTime, endTime };
|
|
456
|
+
const cachedData = getFromCache("orderLog", cacheKey);
|
|
457
|
+
if (cachedData) {
|
|
458
|
+
console.log("使用缓存的工单日志");
|
|
459
|
+
return cachedData;
|
|
320
460
|
}
|
|
461
|
+
return addToQueue("orderLog", cacheKey, async () => {
|
|
462
|
+
try {
|
|
463
|
+
console.log("开始查询工单日志...");
|
|
464
|
+
const token = await getToken();
|
|
465
|
+
const formattedMac = formatMacAddress(mac);
|
|
466
|
+
console.log("处理后的MAC地址:", formattedMac);
|
|
467
|
+
const response = await ctx.http.get(`${config.baseUrl}/fttx/orderAnalyBlock/selectorderAnalyBlockOneList`, {
|
|
468
|
+
params: {
|
|
469
|
+
mac: formattedMac,
|
|
470
|
+
startTime,
|
|
471
|
+
endTime
|
|
472
|
+
},
|
|
473
|
+
headers: {
|
|
474
|
+
"Authorization": token,
|
|
475
|
+
"Accept": "application/json",
|
|
476
|
+
"Content-Type": "application/json"
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
console.log("查询响应:", JSON.stringify(response, null, 2));
|
|
480
|
+
setCache("orderLog", cacheKey, response);
|
|
481
|
+
return response;
|
|
482
|
+
} catch (error) {
|
|
483
|
+
console.error("查询错误详情:", error);
|
|
484
|
+
return [];
|
|
485
|
+
}
|
|
486
|
+
});
|
|
321
487
|
}
|
|
322
488
|
__name(queryOrderLog, "queryOrderLog");
|
|
323
489
|
ctx.middleware(async (session, next) => {
|
|
@@ -394,7 +560,7 @@ function apply(ctx, config) {
|
|
|
394
560
|
return message;
|
|
395
561
|
} catch (error) {
|
|
396
562
|
console.error("查询过程出错:", error);
|
|
397
|
-
return "
|
|
563
|
+
return error.message || "查询失败,请检查账号是否正确";
|
|
398
564
|
}
|
|
399
565
|
}
|
|
400
566
|
});
|
|
@@ -420,7 +586,7 @@ function apply(ctx, config) {
|
|
|
420
586
|
return message;
|
|
421
587
|
} catch (error) {
|
|
422
588
|
console.error("查询过程出错:", error);
|
|
423
|
-
return "
|
|
589
|
+
return error.message || "查询失败,请检查账号是否正确";
|
|
424
590
|
}
|
|
425
591
|
});
|
|
426
592
|
ctx.command("账号详情 <account:string>", "查询宽带账号详细记录").action(async (_, account) => {
|
|
@@ -445,7 +611,7 @@ function apply(ctx, config) {
|
|
|
445
611
|
return messages.join("\n\n");
|
|
446
612
|
} catch (error) {
|
|
447
613
|
console.error("查询过程出错:", error);
|
|
448
|
-
return "查询失败,请稍后重试";
|
|
614
|
+
return error.message || "查询失败,请稍后重试";
|
|
449
615
|
}
|
|
450
616
|
});
|
|
451
617
|
ctx.command("终端查询 <mac:string>", "查询终端基本信息").action(async (_, mac) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-jscn-aaaquery",
|
|
3
3
|
"description": "江苏有线无锡分公司宽带信息查询插件",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@koishijs/plugin-http": "^0.6.3",
|
|
26
26
|
"koishi": "^4.18.7"
|
|
27
27
|
},
|
|
28
|
-
"contributors": [
|
|
29
|
-
"chenluziyang <wxjscnjsb@163.com>"
|
|
28
|
+
"contributors": [
|
|
29
|
+
"chenluziyang <wxjscnjsb@163.com>"
|
|
30
30
|
]
|
|
31
31
|
}
|