Commit 03f367ef authored by 何娜's avatar 何娜

fix

parent 4eb9bc1f
Pipeline #4724 passed with stage
in 45 seconds
...@@ -82,15 +82,18 @@ class OrderController extends Controller { ...@@ -82,15 +82,18 @@ class OrderController extends Controller {
ctx.validate(this.fetchRule); ctx.validate(this.fetchRule);
const { appKey } = ctx.request.body.signParams.params; const { appKey } = ctx.request.body.signParams.params;
const { cityId } = ctx.request.body; const { cityId } = ctx.request.body;
const channelType = await ctx.app.redis.get(cityId);
ctx.app.redis.set(cityId, channelType, "EX", 3600);
const orderId = await service.signature.createOrderId(ctx.request.body.signParams); const orderId = await service.signature.createOrderId(ctx.request.body.signParams);
const taskId = await service.task.create(cityId); const taskId = await service.task.create({cityId, channelType});
await service.order.create({ await service.order.create({
orderId, orderId,
taskId, taskId,
cityId: cityId, cityId,
notifyUrl: ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl || '', // notifyUrl: ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl || '',
appKey: appKey, appkey: appKey,
status: 'init', status: 'init',
text1: channelType,
}); });
ctx.body = { ctx.body = {
code: 0, code: 0,
...@@ -105,9 +108,6 @@ class OrderController extends Controller { ...@@ -105,9 +108,6 @@ class OrderController extends Controller {
if (err.code == 'invalid_param') { if (err.code == 'invalid_param') {
return ctx.body = { code: -1, msg: err.message || '' }; return ctx.body = { code: -1, msg: err.message || '' };
} }
if (/[a-zA-Z]+/.test(err.message)) {
return ctx.body = { code: err.code || -1, msg: '系统错误, 请稍后再试' };
}
return ctx.body = { code: err.code || -1, msg: err.message || '' }; return ctx.body = { code: err.code || -1, msg: err.message || '' };
} }
} }
......
'use strict'; 'use strict';
const REDIS_CACHE = Symbol('Context#RedisCache');
const NODE_CACHE = Symbol('Context#NodeCache'); const NODE_CACHE = Symbol('Context#NodeCache');
const NodeCache = require('node-cache'); const NodeCache = require('node-cache');
...@@ -10,7 +12,7 @@ class Cache { ...@@ -10,7 +12,7 @@ class Cache {
this.name = 'unknown-cache'; this.name = 'unknown-cache';
} }
async val(key, next, ttl) { async val(key, next, ttl) { // key存在取值,不存在存值
let data = await this.get(key); let data = await this.get(key);
if (data) { if (data) {
return data; return data;
...@@ -35,15 +37,86 @@ class Cache { ...@@ -35,15 +37,86 @@ class Cache {
jsonText = jsonText.substr(0, 125) + '...'; jsonText = jsonText.substr(0, 125) + '...';
} }
} }
this.app.logger.info(`[cache] get (${+new Date() - startTime}ms) ${this.name}.${key}: ${jsonText}`); this.app.logger.info(`[cache](${+new Date() - startTime}ms) ${this.name}.${key}: ${jsonText}`);
// this.cacheLog(startTime, key, jsonText);
return ret; return ret;
} }
async set(key, value, ttl = 60) { async set(key, value, ttl = 60) {
this.app.logger.info(`[cache] set (ms)${this.name}.${key}: ${value}`);
return await this._set(key, value, ttl); return await this._set(key, value, ttl);
} }
async del(key){
return await this._del(key) async hget(key) {
const startTime = +new Date();
let ret;
if (!this.hasOwnProperty('_hget') && this.hasOwnProperty('_get')) {
ret = await this._get(key);
return ret;
}
ret = await this._hget(key);
this.chcheLog(startTime, key, ret);
return ret;
}
async hset(key, obj, ttl = 60) {
if (!this.hasOwnProperty('_hset') && this.hasOwnProperty('_set')) {
return await this._set(key, obj, ttl);
}
return await this._hset(key, obj, ttl);
}
chcheLog(startTime, key, value) {
if (typeof value === 'object') {
value = JSON.stringify(value);
}
this.app.logger.info(`[cache](${+new Date() - startTime}ms) ${this.name}.${key}: ${value}`);
}
}
class RedisCacheWrap extends Cache {
constructor(app, redis) {
super(app);
this.redis = redis;
this.name = 'redis-cache';
}
async _get(key) {
const { redis } = this;
let value = await redis.get(key);
if (value === null) {
value = undefined;
}
if (value) {
value = JSON.parse(value);
}
return value;
}
async _set(key, value, ttl) {
const { redis } = this;
value = JSON.stringify(value);
if (ttl > 0) {
await redis.set(key, value, 'EX', ttl);
} else {
await redis.set(key, value);
}
}
async _hget(key) {
const { redis } = this;
let value = await redis.hgetall(key);
if (value === null) {
value = undefined;
}
return value;
}
async _hset(key, obj, ttl) {
const { redis } = this;
if (typeof obj !== 'object') {
obj = JSON.parse(obj);
}
if (ttl > 0) {
await redis.hmset(key, obj);
} else {
await redis.hmset(key, obj);
}
} }
} }
...@@ -66,13 +139,15 @@ class NodeCacheWrap extends Cache { ...@@ -66,13 +139,15 @@ class NodeCacheWrap extends Cache {
cache.set(key, value); cache.set(key, value);
} }
} }
async _del(key){
const { cache } = this;
cache.del(key);
}
} }
module.exports = { module.exports = {
get memcache() {
if (!this[REDIS_CACHE]) {
this[REDIS_CACHE] = new RedisCacheWrap(this, this.redis);
}
return this[REDIS_CACHE];
},
get cache() { get cache() {
if (!this[NODE_CACHE]) { if (!this[NODE_CACHE]) {
this[NODE_CACHE] = new NodeCacheWrap(this); this[NODE_CACHE] = new NodeCacheWrap(this);
...@@ -80,4 +155,3 @@ module.exports = { ...@@ -80,4 +155,3 @@ module.exports = {
return this[NODE_CACHE]; return this[NODE_CACHE];
}, },
}; };
\ No newline at end of file
...@@ -110,7 +110,7 @@ module.exports = app => { ...@@ -110,7 +110,7 @@ module.exports = app => {
field: 'text3', field: 'text3',
}, },
}, { }, {
tableName: 'taxh5_status', tableName: 'tax_status',
// timestamps: false, // timestamps: false,
}); });
......
...@@ -10,10 +10,10 @@ module.exports = app => { ...@@ -10,10 +10,10 @@ module.exports = app => {
taxRouter.post('/getToken', controller.token.partnerCreate);// 合作方创建token taxRouter.post('/getToken', controller.token.partnerCreate);// 合作方创建token
taxRouter.post('/getorderSn', controller.order.fetchOrderId);// 合作方获取订单号
taxRouter.get('/getCity', controller.task.cityConfigs);// 获取城市基础配置项 taxRouter.get('/getCity', controller.task.cityConfigs);// 获取城市基础配置项
taxRouter.post('/getorderSn', controller.order.fetchOrderId);// 合作方获取订单号
taxRouter.post('/getCode', controller.task.fetchCapture);// 获取验证码 taxRouter.post('/getCode', controller.task.fetchCapture);// 获取验证码
taxRouter.post('/query', controller.task.submit);// 提交任务查询参数 taxRouter.post('/query', controller.task.submit);// 提交任务查询参数
...@@ -22,5 +22,5 @@ module.exports = app => { ...@@ -22,5 +22,5 @@ module.exports = app => {
taxRouter.post('/callback', controller.task.handleCallback); // 处理回调结果,不对外 taxRouter.post('/callback', controller.task.handleCallback); // 处理回调结果,不对外
taxRouter.get('/helpInfo', controller.task.fetchCapture);// 获取帮助信息 // taxRouter.get('/helpInfo', controller.task.help);// 获取帮助信息
}; };
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module.exports = { module.exports = {
schedule: { schedule: {
interval: '5m', // 5分钟间隔 interval: '3m', // 5分钟间隔
type: 'all', // 所有woker type: 'all', // 所有woker
immediate: true, immediate: true,
}, },
...@@ -11,14 +11,16 @@ module.exports = { ...@@ -11,14 +11,16 @@ module.exports = {
try { try {
const { host, customerUrl } = ctx.app.config.signatureAPI; const { host, customerUrl } = ctx.app.config.signatureAPI;
const notifyMap = new Map(); const notifyMap = new Map();
ctx.logger.info('host',host, 'customerUrl', customerUrl)
const ret = await ctx.curl(host + customerUrl, { const ret = await ctx.curl(host + customerUrl, {
charset: 'utf-8', charset: 'utf-8',
timeout: ['30s', '30s'], timeout: ['30s', '30s'],
dataType: 'json', dataType: 'json',
contentType: 'json', contentType: 'json',
gzip: true
}); });
// ctx.logger.info(JSON.stringify(ret.data)); ctx.logger.info('notifyUrlCode', JSON.stringify(ret.data.code));
if (ret.data.code == '0') { if (ret.data.code === '0') {
ret.data.data.customerList.map(customer => { ret.data.data.customerList.map(customer => {
if ('callBackUrl' in customer) { if ('callBackUrl' in customer) {
notifyMap.set(customer.appKey, { notifyUrl: customer.callBackUrl }); notifyMap.set(customer.appKey, { notifyUrl: customer.callBackUrl });
...@@ -30,4 +32,4 @@ module.exports = { ...@@ -30,4 +32,4 @@ module.exports = {
ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e)); ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e));
} }
} }
} };
\ No newline at end of file \ No newline at end of file
...@@ -27,7 +27,7 @@ class SignatureService extends Service { ...@@ -27,7 +27,7 @@ class SignatureService extends Service {
dataType: 'json', dataType: 'json',
...opts, ...opts,
}; };
ctx.logger.info('signnature', url, opts); // ctx.logger.info('signnature', url, opts);
return ctx.curl(url, opts); return ctx.curl(url, opts);
} }
......
...@@ -42,14 +42,13 @@ class TaskService extends Service { ...@@ -42,14 +42,13 @@ class TaskService extends Service {
} }
} }
async create(data) { async create({cityId, channelType}) {
const {createTaskUrl, ctx} = this; const {createTaskUrl, ctx} = this;
const result = await this._request(createTaskUrl, ctx.app.channelType, { const result = await this._request(createTaskUrl, channelType, {
method: 'post', method: 'post',
data: {cityId: data}, data: {cityId},
}); });
ctx.logger.info(`【Task】create ${createTaskUrl} cityId: ${data} result:`, JSON.stringify(result.data)); ctx.logger.info(`【Task】create ${createTaskUrl} cityId: ${cityId} channelType: ${channelType} result:`, JSON.stringify(result.data));
ctx.logger.info('channelType', ctx.app.channelType);
this._checkSuccess(result); this._checkSuccess(result);
return result.data.data.taskId; return result.data.data.taskId;
} }
...@@ -98,7 +97,6 @@ class TaskService extends Service { ...@@ -98,7 +97,6 @@ class TaskService extends Service {
async getCityList() { async getCityList() {
const {cityConfigUrl, ctx} = this; const {cityConfigUrl, ctx} = this;
let cityLists = [];//对外城市列表 let cityLists = [];//对外城市列表
let cityTypeLists = [];//不对外城市列表,含渠道(51/管家)
let newCityMap = new Map(); let newCityMap = new Map();
const newret = await this._request(cityConfigUrl, 'gsgj', {method: 'get'}); const newret = await this._request(cityConfigUrl, 'gsgj', {method: 'get'});
...@@ -132,18 +130,10 @@ class TaskService extends Service { ...@@ -132,18 +130,10 @@ class TaskService extends Service {
state: city.state, state: city.state,
queryParam: city.queryParam queryParam: city.queryParam
}); });
cityTypeLists.push({ ctx.app.redis.set(city.id, city.type, "EX", 3600)
province: city.province,
name: city.name,
id: city.id,
state: city.state,
type: city.type,
});
}); });
cityLists.push(newProv); cityLists.push(newProv);
}); });
ctx.app.cityTypeLists = cityTypeLists;
// ctx.logger.info('-------------', JSON.stringify(ctx.app.cityTypeLists))
return cityLists; return cityLists;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment