class MessageClass { async action() { } } const soap = require('soap'); const MESSAGE_CLASS = Symbol('Application#Message'); module.exports = { async wsdl(methodName, args) { try { const wsdlUrl = "http://ye4s.com/webservice/ws?wsdl"; const obj = {}; args.forEach((value, index) => { obj['arg' + index] = value; }); const client = await soap.createClientAsync(wsdlUrl); const result = await client[methodName + 'Async'](obj); return result[0]; } catch (error) { console.error('Error calling SOAP service:', error); throw error; } }, async setCacheAsync(cacheKey, data, expireSeconds = 300) { const cacheRedis = this.redis && this.redis.get ? this.redis.get('cache') : null; if (!cacheRedis) { this.logger.warn('[RedisNotAvailable] Cannot set cache, Redis client is not available'); return; } try { await cacheRedis.setex(cacheKey, expireSeconds, JSON.stringify(data)); this.logger.debug('[CacheSet] Successfully set cache', cacheKey); } catch (error) { this.logger.error('[CacheSetError] Failed to set cache', error.message, cacheKey); } }, async getCacheAsync(cacheKey) { const cacheRedis = this.redis && this.redis.get ? this.redis.get('cache') : null; if (!cacheRedis) { this.logger.warn('[RedisNotAvailable] Cannot get cache, Redis client is not available'); return null; } try { const data = await cacheRedis.get(cacheKey); if (data) { return JSON.parse(data); } return null; } catch (error) { this.logger.error('[CacheGetError] Failed to get cache', error.message, cacheKey); return null; } }, get Message() { if (!this[MESSAGE_CLASS]) { // 返回类本身,不是实例 this[MESSAGE_CLASS] = MessageClass; } return this[MESSAGE_CLASS]; }, };