Commit e505b7b6 authored by 姜登's avatar 姜登

gjj

parent 58c79848
......@@ -16,7 +16,7 @@ class OrderController extends Controller {
required: false,
format: /^(\w{8})-(\w{4})-(\w{4})-(\w{4})-(\w{12})$/,
message: '订单号格式错误',
}
},
};
this.showRule = {
......@@ -55,7 +55,7 @@ class OrderController extends Controller {
async create() {
const { ctx, service } = this;
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);
if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableHf === true)) {
return ctx.fail('未开通此服务');
......@@ -67,9 +67,9 @@ class OrderController extends Controller {
cityId: '',
notifyUrl: notifyUrl || (ctx.app.notifyMap && ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl) || '',
backUrl: backUrl || '',
appKey: appKey,
appKey,
status: 'init',
}
};
if (orderId) {
await service.order.update(object);
} else {
......@@ -116,22 +116,27 @@ class OrderController extends Controller {
const result = await service.storage.read(orderId, appKey);
ctx.body = {
code: 0,
data: result
data: result,
};
return;
}
}
ctx.body = {
code: -1,
msg: '无此订单号'
msg: '无此订单号',
};
} catch (err) {
ctx.logger.error('partnerShow', JSON.stringify(err));
ctx.status = 200;
if (err.code == 'invalid_param') {
return ctx.body = { code: -1, msg: err.message || '' };
if (err.code === 'invalid_param') {
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 {
taskId: '',
cityId: '',
notifyUrl: ctx.app.notifyMap.get(appKey) && ctx.app.notifyMap.get(appKey).notifyUrl || '',
appKey: appKey,
appKey,
status: 'init',
});
ctx.body = {
code: 0,
data: {
orderSn: orderId
orderSn: orderId,
},
msg: ''
}
msg: '',
};
} catch (err) {
ctx.logger.error('fetchOrderId', JSON.stringify(err));
ctx.status = 200;
if (err.code == 'invalid_param') {
return ctx.body = { code: -1, msg: err.message || '' };
if (err.code === 'invalid_param') {
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 {
}
module.exports = PartnerController;
......@@ -96,68 +96,68 @@ class TaskController extends Controller {
note: { message: 'init' },
};
switch (result.code) {
case -1:
case 106:
case 102:
case 204:
taskNote = {
status: 'failure',
note: { message: result.msg },
case -1:
case 106:
case 102:
case 204:
taskNote = {
status: 'failure',
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:
if (result.data.data) {
result.data = {
data: JSON.parse(JSON.parse(result.data.data).post_data.strForNextStep),
loginParam: result.data.loginParam
}
}
taskNote = {
status: 'next',
note: { message: 'waiting', nextStep: result.data },
};
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 = {
status: 'next',
note: { message: 'waiting', nextStep: result.data },
};
break;
case 110:
taskNote = {
status: 'query',
note: { message: 'login success' },
};
break;
case 0:
taskNote = {
status: 'success',
note: { message: 'task success' },
status: 'failure',
note: { message: err.message },
};
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 = {
status: 'failure',
note: { message: err.message },
};
}
break;
default:
ctx.logger.warn('handleCallback', JSON.stringify(result));
break;
}
break;
default:
ctx.logger.warn('handleCallback', JSON.stringify(result));
break;
}
await service.cache.set({
key: taskId,
......@@ -175,10 +175,15 @@ class TaskController extends Controller {
return;
} catch (err) {
ctx.status = 200;
if (err.code == 'invalid_param') {
return ctx.body = { code: -1, message: err.message || '' };
if (err.code === 'invalid_param') {
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 {
try {
ctx.validate(this.createRule);
const token = await service.signature.createToken(ctx.request.body);
return ctx.body = {
ctx.body = {
code: 0,
data: { token },
msg: ''
}
msg: '',
};
} catch (err) {
ctx.logger.error('partnerCreate', JSON.stringify(err));
ctx.status = 200;
if (err.code == 'invalid_param') {
return ctx.body = { code: -1, msg: err.message || '' };
if (err.code === 'invalid_param') {
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 {
this.app.logger.info(`[cache] set (ms)${this.name}.${key}: ${value}`);
return await this._set(key, value, ttl);
}
async del(key){
return await this._del(key)
async del(key) {
return await this._del(key);
}
}
......@@ -66,7 +66,7 @@ class NodeCacheWrap extends Cache {
cache.set(key, value);
}
}
async _del(key){
async _del(key) {
const { cache } = this;
cache.del(key);
}
......
......@@ -3,7 +3,7 @@
module.exports = (options, app) => {
return async function errorHandler(ctx, next) {
try {
if(ctx.request.method == 'POST'){
if (ctx.request.method === 'POST') {
app.logger.info(JSON.stringify(ctx.request.body));
}
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';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const { DataTypes } = app.Sequelize;
const cusDatas = app.model.define('cusDatas', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
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',
},
const cusDatas = app.model.define('cusDatas', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
field: 'id',
},
{
tableName: 'cus_data',
timestamps: false,
});
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',
},
},
{
tableName: 'cus_data',
timestamps: false,
});
return cusDatas;
}
\ No newline at end of file
return cusDatas;
};
......@@ -109,10 +109,10 @@ module.exports = app => {
field: 'notice',
},
},
{
tableName: 'gjj_status',
timestamps: false,
});
{
tableName: 'gjj_status',
timestamps: false,
});
return taskStatsu;
};
......@@ -30,17 +30,17 @@ module.exports = app => {
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('/getorderSn',controller.order.fetchOrderId);//合作方获取订单号
gjjRouter.post('/getorderSn',controller.order.fetchOrderId);// 合作方获取订单号
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';
module.exports = {
schedule: {
interval: '5m', // 5分钟间隔
type: 'all', // 所有woker
immediate: true,
},
schedule: {
interval: '5m', // 5分钟间隔
type: 'all', // 所有woker
immediate: true,
},
async task(ctx) {
try {
const { host, customerUrl } = ctx.app.config.signatureAPI;
const notifyMap = new Map();
const ret = await ctx.curl(host + customerUrl, {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
contentType: 'json',
});
// ctx.logger.info(JSON.stringify(ret.data));
if (ret.data.code == '0') {
ret.data.data.customerList.map(customer => {
if ('callBackUrl' in customer) {
notifyMap.set(customer.appKey, { notifyUrl: customer.callBackUrl });
}
});
ctx.app.notifyMap = notifyMap;
}
} catch (e) {
ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e));
}
async task(ctx) {
try {
const { host, customerUrl } = ctx.app.config.signatureAPI;
const notifyMap = new Map();
const ret = await ctx.curl(host + customerUrl, {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
contentType: 'json',
});
// ctx.logger.info(JSON.stringify(ret.data));
if (ret.data.code === 0) {
ret.data.data.customerList.map(customer => {
if ('callBackUrl' in customer) {
notifyMap.set(customer.appKey, { notifyUrl: customer.callBackUrl });
}
});
ctx.app.notifyMap = notifyMap;
}
} catch (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 {
method: 'GET',
data: {
appKey,
subject: 'hf'
}
subject: 'hf',
},
});
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) {
......@@ -39,7 +39,7 @@ class PartnerService extends Service {
return ret.data[0];
}
async fetchInfo(appKey){
async fetchInfo(appKey) {
const { ctx, partnerAPI: { fetchInfo, host, redisInfoPrefix } } = this;
if (appKey) {
const data = await this.app.redis.get(redisInfoPrefix + appKey);
......@@ -58,8 +58,8 @@ class PartnerService extends Service {
dataType: 'json',
method: 'GET',
data: {
appKey
}
appKey,
},
});
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) {
......@@ -132,12 +132,12 @@ class PartnerService extends Service {
data: {
orderId,
userId,
status: 'success'
status: 'success',
},
}
)
);
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' });
}
}
......
......@@ -181,7 +181,7 @@ class ScriptsService extends Service {
}
}
async getCityList(){
async getCityList() {
}
}
......
......@@ -57,8 +57,8 @@ class StorageService extends Service {
await ctx.model.Cusdata.create({
appKey,
orderId,
type: 'gjj'
})
type: 'gjj',
});
return result.data.data[readDataKey];
}
}
......
......@@ -51,16 +51,16 @@ class WashDataService extends Service {
dealData(data, passID = false) {
const { clearGjj, clearLoan } = this;
delete data.data.general_analyzed_data;
for (let gjjItem of data.data.gjj_data) {
for (let text of clearGjj) {
if (!(passID && text == 'ID')) {
for (const gjjItem of data.data.gjj_data) {
for (const text of clearGjj) {
if (!(passID && text === 'ID')) {
delete gjjItem.gjj_brief[text];
}
}
delete gjjItem.gjj_account_analyzed_data;
}
for (let loanItem of data.data.loan_data) {
for (let text of clearLoan) {
for (const loanItem of data.data.loan_data) {
for (const text of clearLoan) {
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