86 lines
2.5 KiB
JavaScript
86 lines
2.5 KiB
JavaScript
class MessageClass {
|
|
async action() {
|
|
|
|
}
|
|
}
|
|
const soap = require('soap');
|
|
const businessDict = require('../dict/businessDict');
|
|
const MESSAGE_CLASS = Symbol('Application#Message');
|
|
module.exports = {
|
|
get businessDict() {
|
|
return businessDict;
|
|
},
|
|
getBusinessTypeName(code) {
|
|
const dict = this.businessDict.BUSINESS_TYPE || {};
|
|
for (const key in dict) {
|
|
if (dict[key].code === code) {
|
|
return dict[key].name;
|
|
}
|
|
}
|
|
return code;
|
|
},
|
|
getOperationCodeName(code) {
|
|
return this.businessDict.OPERATION_CODE?.[code] || code;
|
|
},
|
|
getPlatformName(code) {
|
|
return this.businessDict.PLATFORM_CODE?.[code] || code;
|
|
},
|
|
getExternalLogTypeName(type) {
|
|
return this.businessDict.EXTERNAL_LOG_TYPE?.[type] || type;
|
|
},
|
|
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];
|
|
},
|
|
};
|