Commit e505b7b6 authored by 姜登's avatar 姜登

gjj

parent 58c79848
...@@ -16,7 +16,7 @@ class OrderController extends Controller { ...@@ -16,7 +16,7 @@ class OrderController extends Controller {
required: false, required: false,
format: /^(\w{8})-(\w{4})-(\w{4})-(\w{4})-(\w{12})$/, format: /^(\w{8})-(\w{4})-(\w{4})-(\w{4})-(\w{12})$/,
message: '订单号格式错误', message: '订单号格式错误',
} },
}; };
this.showRule = { this.showRule = {
...@@ -55,7 +55,7 @@ class OrderController extends Controller { ...@@ -55,7 +55,7 @@ class OrderController extends Controller {
async create() { async create() {
const { ctx, service } = this; const { ctx, service } = this;
ctx.validate(this.createRule); ctx.validate(this.createRule);
let { appKey, userId, notifyUrl, backUrl, orderId } = ctx.request.body; const { appKey, userId, notifyUrl, backUrl, orderId } = ctx.request.body;
const appKeyInfo = await service.partner.fetchInfo(appKey); const appKeyInfo = await service.partner.fetchInfo(appKey);
if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableHf === true)) { if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableHf === true)) {
return ctx.fail('未开通此服务'); return ctx.fail('未开通此服务');
...@@ -67,9 +67,9 @@ class OrderController extends Controller { ...@@ -67,9 +67,9 @@ class OrderController extends Controller {
cityId: '', cityId: '',
notifyUrl: notifyUrl || (ctx.app.notifyMap && ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl) || '', notifyUrl: notifyUrl || (ctx.app.notifyMap && ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl) || '',
backUrl: backUrl || '', backUrl: backUrl || '',
appKey: appKey, appKey,
status: 'init', status: 'init',
} };
if (orderId) { if (orderId) {
await service.order.update(object); await service.order.update(object);
} else { } else {
...@@ -116,22 +116,27 @@ class OrderController extends Controller { ...@@ -116,22 +116,27 @@ class OrderController extends Controller {
const result = await service.storage.read(orderId, appKey); const result = await service.storage.read(orderId, appKey);
ctx.body = { ctx.body = {
code: 0, code: 0,
data: result data: result,
}; };
return; return;
} }
} }
ctx.body = { ctx.body = {
code: -1, code: -1,
msg: '无此订单号' msg: '无此订单号',
}; };
} catch (err) { } catch (err) {
ctx.logger.error('partnerShow', JSON.stringify(err)); ctx.logger.error('partnerShow', JSON.stringify(err));
ctx.status = 200; ctx.status = 200;
if (err.code == 'invalid_param') { if (err.code === 'invalid_param') {
return ctx.body = { code: -1, msg: err.message || '' }; ctx.body = { code: -1, msg: '请求参数有误' };
return;
}
if (/[a-zA-Z]+/.test(err.message)) {
ctx.body = { code: err.code || -1, msg: '系统错误, 请稍后再试' };
return;
} }
return ctx.body = { code: err.code || -1, msg: err.message || '' }; ctx.body = { code: err.code || -1, msg: err.message || '' };
} }
} }
...@@ -165,23 +170,28 @@ class OrderController extends Controller { ...@@ -165,23 +170,28 @@ class OrderController extends Controller {
taskId: '', taskId: '',
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,
status: 'init', status: 'init',
}); });
ctx.body = { ctx.body = {
code: 0, code: 0,
data: { data: {
orderSn: orderId orderSn: orderId,
}, },
msg: '' msg: '',
} };
} catch (err) { } catch (err) {
ctx.logger.error('fetchOrderId', JSON.stringify(err)); ctx.logger.error('fetchOrderId', JSON.stringify(err));
ctx.status = 200; ctx.status = 200;
if (err.code == 'invalid_param') { if (err.code === 'invalid_param') {
return ctx.body = { code: -1, msg: err.message || '' }; ctx.body = { code: -1, msg: '请求参数有误' };
return;
}
if (/[a-zA-Z]+/.test(err.message)) {
ctx.body = { code: err.code || -1, msg: '系统错误, 请稍后再试' };
return;
} }
return ctx.body = { code: err.code || -1, msg: err.message || '' }; ctx.body = { code: err.code || -1, msg: err.message || '' };
} }
} }
} }
......
...@@ -32,5 +32,4 @@ class PartnerController extends Controller { ...@@ -32,5 +32,4 @@ class PartnerController extends Controller {
} }
module.exports = PartnerController; module.exports = PartnerController;
...@@ -96,68 +96,68 @@ class TaskController extends Controller { ...@@ -96,68 +96,68 @@ class TaskController extends Controller {
note: { message: 'init' }, note: { message: 'init' },
}; };
switch (result.code) { switch (result.code) {
case -1: case -1:
case 106: case 106:
case 102: case 102:
case 204: case 204:
taskNote = { taskNote = {
status: 'failure', status: 'failure',
note: { message: result.msg }, note: { message: result.msg },
};
break;
case 1:
if (result.data.data) {
result.data = {
data: JSON.parse(JSON.parse(result.data.data).post_data.strForNextStep),
loginParam: result.data.loginParam,
}; };
break; }
case 1: taskNote = {
if (result.data.data) { status: 'next',
result.data = { note: { message: 'waiting', nextStep: result.data },
data: JSON.parse(JSON.parse(result.data.data).post_data.strForNextStep), };
loginParam: result.data.loginParam break;
} case 110:
taskNote = {
status: 'query',
note: { message: 'login success' },
};
break;
case 0:
taskNote = {
status: 'success',
note: { message: 'task success' },
};
try {
const insertData = await service.washData.wash(result);
const order = await service.order.getOneByTaskId(taskId);
if (!order) {
throw new Error('任务已经结束了');
} }
const { orderId, appKey } = order;
insertData.orderId = orderId;
insertData.cityName = await service.scripts.fetchScriptName(insertData.cid);
insertData.taskId = taskId;
insertData.appKey = appKey;
delete insertData.code;
await service.storage.write(insertData);
await service.cache.set({
key: taskId,
value: taskNote,
});
await service.partner.notice(order);
return;
} catch (err) {
ctx.logger.error('handleCallback', JSON.stringify(err), JSON.stringify(result));
taskNote = { taskNote = {
status: 'next', status: 'failure',
note: { message: 'waiting', nextStep: result.data }, note: { message: err.message },
};
break;
case 110:
taskNote = {
status: 'query',
note: { message: 'login success' },
};
break;
case 0:
taskNote = {
status: 'success',
note: { message: 'task success' },
}; };
try { }
const insertData = await service.washData.wash(result); break;
const order = await service.order.getOneByTaskId(taskId); default:
if (!order) { ctx.logger.warn('handleCallback', JSON.stringify(result));
throw new Error('任务已经结束了'); break;
}
const { orderId, appKey } = order;
insertData.orderId = orderId;
insertData.cityName = await service.scripts.fetchScriptName(insertData.cid);
insertData.taskId = taskId;
insertData.appKey = appKey;
delete insertData.code;
await service.storage.write(insertData);
await service.cache.set({
key: taskId,
value: taskNote,
});
await service.partner.notice(order);
return;
} catch (err) {
ctx.logger.error('handleCallback', JSON.stringify(err), JSON.stringify(result));
taskNote = {
status: 'failure',
note: { message: err.message },
};
}
break;
default:
ctx.logger.warn('handleCallback', JSON.stringify(result));
break;
} }
await service.cache.set({ await service.cache.set({
key: taskId, key: taskId,
...@@ -175,10 +175,15 @@ class TaskController extends Controller { ...@@ -175,10 +175,15 @@ class TaskController extends Controller {
return; return;
} catch (err) { } catch (err) {
ctx.status = 200; ctx.status = 200;
if (err.code == 'invalid_param') { if (err.code === 'invalid_param') {
return ctx.body = { code: -1, message: err.message || '' }; ctx.body = { code: -1, msg: '请求参数有误' };
return;
}
if (/[a-zA-Z]+/.test(err.message)) {
ctx.body = { code: err.code || -1, msg: '系统错误, 请稍后再试' };
return;
} }
return ctx.body = { code: err.code || -1, message: err.message || '' }; ctx.body = { code: err.code || -1, msg: err.message || '' };
} }
} }
} }
......
...@@ -28,18 +28,23 @@ class TokenController extends Controller { ...@@ -28,18 +28,23 @@ class TokenController extends Controller {
try { try {
ctx.validate(this.createRule); ctx.validate(this.createRule);
const token = await service.signature.createToken(ctx.request.body); const token = await service.signature.createToken(ctx.request.body);
return ctx.body = { ctx.body = {
code: 0, code: 0,
data: { token }, data: { token },
msg: '' msg: '',
} };
} catch (err) { } catch (err) {
ctx.logger.error('partnerCreate', JSON.stringify(err)); ctx.logger.error('partnerCreate', JSON.stringify(err));
ctx.status = 200; ctx.status = 200;
if (err.code == 'invalid_param') { if (err.code === 'invalid_param') {
return ctx.body = { code: -1, msg: err.message || '' }; ctx.body = { code: -1, msg: '请求参数有误' };
return;
}
if (/[a-zA-Z]+/.test(err.message)) {
ctx.body = { code: err.code || -1, msg: '系统错误, 请稍后再试' };
return;
} }
return ctx.body = { code: err.code || -1, msg: err.message || '' }; ctx.body = { code: err.code || -1, msg: err.message || '' };
} }
} }
} }
......
...@@ -42,8 +42,8 @@ class Cache { ...@@ -42,8 +42,8 @@ class Cache {
this.app.logger.info(`[cache] set (ms)${this.name}.${key}: ${value}`); 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){ async del(key) {
return await this._del(key) return await this._del(key);
} }
} }
...@@ -66,7 +66,7 @@ class NodeCacheWrap extends Cache { ...@@ -66,7 +66,7 @@ class NodeCacheWrap extends Cache {
cache.set(key, value); cache.set(key, value);
} }
} }
async _del(key){ async _del(key) {
const { cache } = this; const { cache } = this;
cache.del(key); cache.del(key);
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module.exports = (options, app) => { module.exports = (options, app) => {
return async function errorHandler(ctx, next) { return async function errorHandler(ctx, next) {
try { try {
if(ctx.request.method == 'POST'){ if (ctx.request.method === 'POST') {
app.logger.info(JSON.stringify(ctx.request.body)); app.logger.info(JSON.stringify(ctx.request.body));
} }
await next(); await next();
......
'use strict';
module.exports = (options, app) => {
return async function(ctx, next) {
const { appKey } = ctx.request.body;
// 可以在这里增加验签的功能;
if (appKey && ctx.app.appKeyArr.includes(appKey)) {
await next();
} else {
ctx.throw(400, '无效的appKey');
}
};
};
'use strict'; 'use strict';
module.exports = app => { module.exports = app => {
const { DataTypes } = app.Sequelize; const { DataTypes } = app.Sequelize;
const cusDatas = app.model.define('cusDatas', { const cusDatas = app.model.define('cusDatas', {
id: { id: {
type: DataTypes.INTEGER, type: DataTypes.INTEGER,
allowNull: false, allowNull: false,
autoIncrement: true, autoIncrement: true,
primaryKey: true, primaryKey: true,
field: 'id', field: 'id',
},
orderId: {
type: DataTypes.STRING(255),
allowNull: false,
defaultValue: '',
primaryKey: true,
field: 'orderId',
},
appKey: {
type: DataTypes.STRING(255),
allowNull: false,
field: 'appKey',
},
type: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'type',
},
date: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'date',
},
text1: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text1',
},
text2: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text2',
},
text3: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text3',
},
text4: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text4',
},
date1: {
type: DataTypes.DATE,
allowNull: true,
field: 'date1',
},
date2: {
type: DataTypes.DATE,
allowNull: true,
field: 'date2',
},
}, },
{ orderId: {
tableName: 'cus_data', type: DataTypes.STRING(255),
timestamps: false, allowNull: false,
}); defaultValue: '',
primaryKey: true,
field: 'orderId',
},
appKey: {
type: DataTypes.STRING(255),
allowNull: false,
field: 'appKey',
},
type: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'type',
},
date: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'date',
},
text1: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text1',
},
text2: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text2',
},
text3: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text3',
},
text4: {
type: DataTypes.STRING(255),
allowNull: true,
defaultValue: '',
field: 'text4',
},
date1: {
type: DataTypes.DATE,
allowNull: true,
field: 'date1',
},
date2: {
type: DataTypes.DATE,
allowNull: true,
field: 'date2',
},
},
{
tableName: 'cus_data',
timestamps: false,
});
return cusDatas; return cusDatas;
} };
\ No newline at end of file
...@@ -109,10 +109,10 @@ module.exports = app => { ...@@ -109,10 +109,10 @@ module.exports = app => {
field: 'notice', field: 'notice',
}, },
}, },
{ {
tableName: 'gjj_status', tableName: 'gjj_status',
timestamps: false, timestamps: false,
}); });
return taskStatsu; return taskStatsu;
}; };
...@@ -30,17 +30,17 @@ module.exports = app => { ...@@ -30,17 +30,17 @@ module.exports = app => {
gjjRouter.get('/theme/:appKey', controller.partner.show);// 根据appkey查询合作方主题 gjjRouter.get('/theme/:appKey', controller.partner.show);// 根据appkey查询合作方主题
gjjRouter.get('/agreements/:id', controller.partner.fetchAgreements);//查询协议 gjjRouter.get('/agreements/:id', controller.partner.fetchAgreements);// 查询协议
gjjRouter.post('/getToken', controller.token.partnerCreate);// 合作方创建token gjjRouter.post('/getToken', controller.token.partnerCreate);// 合作方创建token
gjjRouter.post('/getorderSn',controller.order.fetchOrderId);//合作方获取订单号 gjjRouter.post('/getorderSn',controller.order.fetchOrderId);// 合作方获取订单号
gjjRouter.post('/getData', controller.order.partnerShow);// 合作方获取订单数据 gjjRouter.post('/getData', controller.order.partnerShow);// 合作方获取订单数据
gjjRouter.post('/getCityConfig', controller.task.fetchCityConfig)//获取城市配置 gjjRouter.post('/getCityConfig', controller.task.fetchCityConfig);// 获取城市配置
gjjRouter.get('/orderData/:appKey/:orderId', controller.order.orderShow);//获取展示页面数据 gjjRouter.get('/orderData/:appKey/:orderId', controller.order.orderShow);// 获取展示页面数据
}; };
'use strict'; 'use strict';
module.exports = { module.exports = {
schedule: { schedule: {
interval: '5m', // 5分钟间隔 interval: '5m', // 5分钟间隔
type: 'all', // 所有woker type: 'all', // 所有woker
immediate: true, immediate: true,
}, },
async task(ctx) { async task(ctx) {
try { try {
const { host, customerUrl } = ctx.app.config.signatureAPI; const { host, customerUrl } = ctx.app.config.signatureAPI;
const notifyMap = new Map(); const notifyMap = new Map();
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',
}); });
// ctx.logger.info(JSON.stringify(ret.data)); // ctx.logger.info(JSON.stringify(ret.data));
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 });
} }
}); });
ctx.app.notifyMap = notifyMap; ctx.app.notifyMap = notifyMap;
} }
} catch (e) { } catch (e) {
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 };
...@@ -29,8 +29,8 @@ class PartnerService extends Service { ...@@ -29,8 +29,8 @@ class PartnerService extends Service {
method: 'GET', method: 'GET',
data: { data: {
appKey, appKey,
subject: 'hf' subject: 'hf',
} },
}); });
ctx.logger.info(`【Partner】 fetchTheme ${host + fetchTheme}/${appKey}`, ret.data); ctx.logger.info(`【Partner】 fetchTheme ${host + fetchTheme}/${appKey}`, ret.data);
if (ret.status === 200 && ret.data && ret.data.length > 0 && ret.data[0].appKey === appKey) { if (ret.status === 200 && ret.data && ret.data.length > 0 && ret.data[0].appKey === appKey) {
...@@ -39,7 +39,7 @@ class PartnerService extends Service { ...@@ -39,7 +39,7 @@ class PartnerService extends Service {
return ret.data[0]; return ret.data[0];
} }
async fetchInfo(appKey){ async fetchInfo(appKey) {
const { ctx, partnerAPI: { fetchInfo, host, redisInfoPrefix } } = this; const { ctx, partnerAPI: { fetchInfo, host, redisInfoPrefix } } = this;
if (appKey) { if (appKey) {
const data = await this.app.redis.get(redisInfoPrefix + appKey); const data = await this.app.redis.get(redisInfoPrefix + appKey);
...@@ -58,8 +58,8 @@ class PartnerService extends Service { ...@@ -58,8 +58,8 @@ class PartnerService extends Service {
dataType: 'json', dataType: 'json',
method: 'GET', method: 'GET',
data: { data: {
appKey appKey,
} },
}); });
ctx.logger.info(`【Partner】 fetchTheme ${host + fetchInfo}?appKey=${appKey}`, ret.data); ctx.logger.info(`【Partner】 fetchTheme ${host + fetchInfo}?appKey=${appKey}`, ret.data);
if (ret.status === 200 && ret.data && ret.data.length > 0 && ret.data[0].appKey === appKey) { if (ret.status === 200 && ret.data && ret.data.length > 0 && ret.data[0].appKey === appKey) {
...@@ -132,12 +132,12 @@ class PartnerService extends Service { ...@@ -132,12 +132,12 @@ class PartnerService extends Service {
data: { data: {
orderId, orderId,
userId, userId,
status: 'success' status: 'success',
}, },
} }
) );
ctx.logger.info(`【Partner】 notice ${notifyUrl}`, 'orderId:', orderId, 'result:', ret.status, JSON.stringify(ret.data)); ctx.logger.info(`【Partner】 notice ${notifyUrl}`, 'orderId:', orderId, 'result:', ret.status, JSON.stringify(ret.data));
if (ret.status == 200) { if (ret.status === 200) {
await order.update({ notice: '1' }); await order.update({ notice: '1' });
} }
} }
......
...@@ -181,7 +181,7 @@ class ScriptsService extends Service { ...@@ -181,7 +181,7 @@ class ScriptsService extends Service {
} }
} }
async getCityList(){ async getCityList() {
} }
} }
......
...@@ -57,8 +57,8 @@ class StorageService extends Service { ...@@ -57,8 +57,8 @@ class StorageService extends Service {
await ctx.model.Cusdata.create({ await ctx.model.Cusdata.create({
appKey, appKey,
orderId, orderId,
type: 'gjj' type: 'gjj',
}) });
return result.data.data[readDataKey]; return result.data.data[readDataKey];
} }
} }
......
...@@ -51,16 +51,16 @@ class WashDataService extends Service { ...@@ -51,16 +51,16 @@ class WashDataService extends Service {
dealData(data, passID = false) { dealData(data, passID = false) {
const { clearGjj, clearLoan } = this; const { clearGjj, clearLoan } = this;
delete data.data.general_analyzed_data; delete data.data.general_analyzed_data;
for (let gjjItem of data.data.gjj_data) { for (const gjjItem of data.data.gjj_data) {
for (let text of clearGjj) { for (const text of clearGjj) {
if (!(passID && text == 'ID')) { if (!(passID && text === 'ID')) {
delete gjjItem.gjj_brief[text]; delete gjjItem.gjj_brief[text];
} }
} }
delete gjjItem.gjj_account_analyzed_data; delete gjjItem.gjj_account_analyzed_data;
} }
for (let loanItem of data.data.loan_data) { for (const loanItem of data.data.loan_data) {
for (let text of clearLoan) { for (const text of clearLoan) {
delete loanItem.loan_brief[text]; delete loanItem.loan_brief[text];
} }
} }
......
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