Commit d07e239d authored by 何娜's avatar 何娜

taxapi 限制appKey查询次数

parent ea5f3f25
Pipeline #7259 passed with stage
in 9 seconds
......@@ -49,15 +49,16 @@ class OrderController extends Controller {
//拉取数据接口
async partnerShow() {
const { ctx, service } = this;
const {ctx, service} = this;
try {
ctx.validate(this.showRule);
const { appKey, orderSn } = ctx.request.body.params;
const {appKey, orderSn} = ctx.request.body.params;
await service.signature.signatureCheck(ctx.request.body);
let data = await service.cache.get({ key: orderSn });
let data = await service.cache.get({key: orderSn});
let result = '任务还在执行或未输入';
if (data) {
if (data.status === 'success') {
await service.partner.appKeyLimit(appKey);
const result = await service.storage.read(orderSn, appKey);
ctx.body = {
code: 0,
......@@ -74,18 +75,18 @@ class OrderController extends Controller {
ctx.logger.error('partnerShow', err);
ctx.status = 200;
if (err.code == 'invalid_param') {
return ctx.body = { code: -1, msg: err.message || '' };
return ctx.body = {code: -1, msg: err.message || ''};
}
return ctx.body = { code: err.code || -1, msg: err.message || '' };
return ctx.body = {code: err.code || -1, msg: err.message || ''};
}
}
//创建订单号接口
async fetchOrderId() {
const { ctx, service } = this;
const {ctx, service} = this;
try {
ctx.validate(this.fetchOrderIdRule, ctx.query);
const { appKey, cityId } = ctx.query;
const {appKey, cityId} = ctx.query;
// const appKeyInfo = await service.partner.fetchInfo(appKey);
// ctx.logger.info(appKey, ',appKeyInfo,', appKeyInfo);
// if (!(appKeyInfo && appKeyInfo.valid === true && appKeyInfo.enableIt === true)) {
......@@ -112,21 +113,21 @@ class OrderController extends Controller {
ctx.logger.error('fetchOrderId', err);
ctx.status = 200;
if (err.code == 'invalid_param') {
return ctx.body = { code: -1, msg: err.message || '' };
return ctx.body = {code: -1, msg: err.message || ''};
}
return ctx.body = { code: err.code || -1, msg: err.message || '' };
return ctx.body = {code: err.code || -1, msg: err.message || ''};
}
}
//获取帮助配置接口
async help(){
const { ctx, service } = this;
const { cityId } = ctx.query;
async help() {
const {ctx, service} = this;
const {cityId} = ctx.query;
const cityName = await await service.scripts.fetchScriptName(cityId);
const helpData = await service.scripts.fetchHelp(cityId);
if(helpData && helpData.length > 0){
if (helpData && helpData.length > 0) {
let helpInfo = [];
for(let item of helpData[0].help_list){
for (let item of helpData[0].help_list) {
helpInfo.push({
desc: item.content,
link: {
......@@ -143,7 +144,7 @@ class OrderController extends Controller {
help: helpInfo
}
});
}else{
} else {
return ctx.body = {
code: "-1",
msg: "未查询到此地区帮助信息"
......
'use strict';
module.exports = app => {
const { DataTypes } = app.Sequelize;
const nodeLimit = app.model.define('nodeLimit', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
autoIncrement: true,
primaryKey: true,
field: 'id',
},
companyName: {
type: DataTypes.STRING(255),
allowNull: true,
field: 'companyName',
},
appKey: {
type: DataTypes.STRING(255),
allowNull: false,
field: 'appKey',
},
type: {
type: DataTypes.STRING(255),
allowNull: true,
field: 'type',
},
currentCount: {
type: DataTypes.INTEGER(20),
allowNull: true,
defaultValue: 0,
field: 'currentCount',
},
limitCount: {
type: DataTypes.INTEGER(20),
allowNull: true,
defaultValue: 0,
field: 'limitCount',
},
createTime: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'createTime',
},
updateTime: {
type: DataTypes.DATE,
allowNull: true,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
field: 'updateTime',
},
text: {
type: DataTypes.STRING(255),
allowNull: true,
field: 'text1',
},
text2: {
type: DataTypes.STRING(255),
allowNull: true,
field: 'text2',
},
},
{
tableName: 'node_limit',
timestamps: false,
});
return nodeLimit;
};
......@@ -25,8 +25,8 @@ module.exports = {
notifyMap.set(customer.appKey, { notifyUrl: customer.callBackUrl });
}
});
ctx.app.notifyMap = notifyMap;
}
ctx.app.notifyMap = notifyMap;
} catch (e) {
ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e));
}
......
......@@ -61,6 +61,50 @@ class PartnerService extends Service {
}
return;
}
async appKeyLimit(appKey) {
const { ctx, partnerAPI: { redisappKeyLimitPrefix } } = this;
let data = await this.app.redis.get(redisappKeyLimitPrefix);
if (data) {
data = JSON.parse(data);
if (data.includes(appKey)) {
let limit = await this.app.redis.get(redisappKeyLimitPrefix + appKey);
if (limit) {
limit = JSON.parse(limit);
if (limit.currentCount >= limit.limitCount) {
ctx.throw(422, { message: 'appKey查询数量超过限制,请联系技术人员' });
} else {
// limit.currentCount++;
// await this.app.redis.set(redisappKeyLimitPrefix + appKey, JSON.stringify({ currentCount: limit.currentCount, limitCount: limit.limitCount }), 'EX', 300);
await ctx.model.query('UPDATE node_limit set currentCount = currentCount + 1 where appKey = ?', {
type: 'UPDATE',
replacements: [appKey],
});
}
}
}
} else {
const dbRes = await ctx.model.NodeLimit.findAll({
attributes: ['appKey', 'currentCount', 'limitCount'],
where: { type: 'tax' },
});
if (dbRes) {
const appKeyArray = [];
for (const item of dbRes) {
const { appKey, currentCount, limitCount } = item;
appKeyArray.push(appKey);
await this.app.redis.set(redisappKeyLimitPrefix + appKey, JSON.stringify({ currentCount, limitCount }), 'EX', 300);
}
await this.app.redis.set(redisappKeyLimitPrefix, JSON.stringify(appKeyArray), 'EX', 300);
if (appKeyArray.includes(appKey)) {
await ctx.model.query('UPDATE node_limit set currentCount = currentCount + 1 where appKey = ?', {
type: 'UPDATE',
replacements: [appKey],
});
}
}
}
}
}
module.exports = PartnerService;
......@@ -34,6 +34,7 @@ module.exports = () => {
redisScriptsPrefix: 'URANUS.IT.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.IT.PARNTERS.Agreements',
redisInfoPrefix: 'URANUS.IT.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.IT.PARNTERS.Limit',
};
config.scriptsAPI = {
......
......@@ -37,6 +37,7 @@ module.exports = () => {
redisScriptsPrefix: 'URANUS.IT.PARNTERS.SCRIPTS',
redisAgreementsPrefix: 'URANUS.IT.PARNTERS.Agreements',
redisInfoPrefix: 'URANUS.IT.PARNTERS.Info',
redisappKeyLimitPrefix: 'URANUS.IT.PARNTERS.Limit',
};
config.scriptsAPI = {
......
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