Commit d7eb204f authored by 何娜's avatar 何娜

tax fix

parent 75360ca2
Pipeline #4562 passed with stage
in 7 seconds
......@@ -54,14 +54,10 @@ class TaskController extends Controller {
const {ctx, service} = this;
ctx.validate(this.createRule);
const {scriptId, orderId, userId} = ctx.request.body;
ctx.logger.info(typeof (ctx.app.cityTypeLists), 'cityTypeLists', ctx.app.cityTypeLists)
for(let item of ctx.app.cityTypeLists){
if(item.id === scriptId){
ctx.app.channelType = item.type;
}
}
const taskId = await service.task.create(scriptId);
await service.order.update({orderId, cityId: scriptId, taskId, userId, text1: ctx.app.channelType});
const channelType = await ctx.app.redis.get(scriptId);
ctx.app.redis.set(scriptId, channelType, "EX", 3600);
const taskId = await service.task.create({scriptId, channelType});
await service.order.update({orderId, cityId: scriptId, taskId, userId, text1: channelType});
await service.cache.set({
key: taskId,
value: {status: 'init', note: {message: 'init'}},
......@@ -186,7 +182,6 @@ class TaskController extends Controller {
// ctx.validate(this.cityConfigRule);
// await service.signature.signatureCheck(ctx.request.body);
const result = await service.task.getCityList();
console.log('Type'+JSON.stringify(ctx.app.cityTypeLists[0]))
ctx.success({
code: 0,
data: result
......
'use strict';
const REDIS_CACHE = Symbol('Context#RedisCache');
const NODE_CACHE = Symbol('Context#NodeCache');
const NodeCache = require('node-cache');
......@@ -10,7 +12,7 @@ class Cache {
this.name = 'unknown-cache';
}
async val(key, next, ttl) {
async val(key, next, ttl) { // key存在取值,不存在存值
let data = await this.get(key);
if (data) {
return data;
......@@ -36,13 +38,85 @@ class Cache {
}
}
this.app.logger.info(`[cache](${+new Date() - startTime}ms) ${this.name}.${key}: ${jsonText}`);
// this.cacheLog(startTime, key, jsonText);
return ret;
}
async set(key, value, ttl = 60) {
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);
}
}
}
......@@ -65,13 +139,15 @@ class NodeCacheWrap extends Cache {
cache.set(key, value);
}
}
async _del(key){
const { cache } = this;
cache.del(key);
}
}
module.exports = {
get memcache() {
if (!this[REDIS_CACHE]) {
this[REDIS_CACHE] = new RedisCacheWrap(this, this.redis);
}
return this[REDIS_CACHE];
},
get cache() {
if (!this[NODE_CACHE]) {
this[NODE_CACHE] = new NodeCacheWrap(this);
......@@ -79,4 +155,3 @@ module.exports = {
return this[NODE_CACHE];
},
};
\ No newline at end of file
......@@ -110,7 +110,7 @@ module.exports = app => {
field: 'text3',
},
}, {
tableName: 'iith5_status',
tableName: 'tax_status',
// timestamps: false,
});
......
......@@ -33,23 +33,22 @@ class TaskService extends Service {
}
_checkSuccess(result) {
// if (result.status !== 200) {
// const errorMsg = result.data && result.data.error_msg ? result.data.error_msg : 'unknown error';
// this.ctx.throw(result.status, errorMsg);
// }
if (result.status !== 200) {
const errorMsg = result.data && result.data.error_msg ? result.data.error_msg : 'unknown error';
this.ctx.throw(result.status, errorMsg);
}
if (result.data.code !== 0) {
this.ctx.throw(400, {message: result.data.msg, code: result.data.code});
}
}
async create(data) {
async create({scriptId, channelType}) {
const {createTaskUrl, ctx} = this;
const result = await this._request(createTaskUrl, ctx.app.channelType, {
const result = await this._request(createTaskUrl, channelType, {
method: 'post',
data: {cityId: data},
data: {cityId: scriptId},
});
ctx.logger.info(`【Task】create ${createTaskUrl} cityId: ${data} result:`, JSON.stringify(result.data));
ctx.logger.info('channelType', ctx.app.channelType);
ctx.logger.info(`【Task】create ${createTaskUrl} cityId: ${scriptId} channelType: ${channelType} result:`, JSON.stringify(result.data));
this._checkSuccess(result);
return result.data.data.taskId;
}
......@@ -132,18 +131,26 @@ class TaskService extends Service {
state: city.state,
queryParam: city.queryParam
});
cityTypeLists.push({
// cityTypeLists.push({
// province: city.province,
// name: city.name,
// id: city.id,
// state: city.state,
// type: city.type,
// });
let obj = {
province: city.province,
name: city.name,
id: city.id,
state: city.state,
type: city.type,
});
type: city.type
}
ctx.app.redis.set(city.id, city.type, "EX", 3600)
});
cityLists.push(newProv);
});
ctx.app.cityTypeLists = cityTypeLists;
ctx.logger.info('-------------', JSON.stringify(ctx.app.cityTypeLists))
// await ctx.app.redis.set('cityTypeLists', cityTypeLists, "EX", 3600);
// ctx.logger.info(ctx.app.redis.get(1))
return cityLists;
}
}
......
......@@ -30,7 +30,7 @@ module.exports = () => {
config.partnerAPI = {
host: process.env.PARTNERAPI_HOST,
fetchTheme: '/chaos/theme',
fetchTheme: '/chaos/partners/theme',
fetchScripts: '/chaos/partners/scripts',
fetchAgreements: '/chaos/agreements',
redisThemePrefix: 'URANUS.HF.PARNTERS.THEME',
......@@ -42,17 +42,17 @@ module.exports = () => {
config.scriptsAPI = {
host: 'https://dev-nginx.jianbing.com/zeus-api/v1',
fetchScriptsUrl: '/chaos/hf/two_dimension_array/queries',
fetchOneScriptUrl: '/chaos/hf/two_dimension_array/info',
fetchParamsInfoUrl: '/chaos/hf/login_param_map',
fetchQueryButtonUrl: '/chaos/hf/query_button',
fetchHelpUrl: '/chaos/hf/help',
fetchNoticeUrl: '/chaos/hf/notice',
fetchHubSeriptsUrl: '/chaos/hf/hubs',
fetchScriptByCityNameUrl: '/chaos/hf/city_scripts',
redisScriptsKey: 'DATA_SERVER_SHEBAO.SCRIPTS',
redisParamsKey: 'DATA_SERVER_SHEBAO.PARAMS',
redisScriptListKey: 'DATA_SERVER_SHEBAO.SCRIPTLIST',
fetchScriptsUrl: '/chaos/it/two_dimension_array/queries',
fetchOneScriptUrl: '/chaos/it/two_dimension_array/info',
fetchParamsInfoUrl: '/chaos/it/login_param_map',
fetchQueryButtonUrl: '/chaos/it/query_button',
fetchHelpUrl: '/chaos/it/help',
fetchNoticeUrl: '/chaos/it/notice',
fetchHubSeriptsUrl: '/chaos/it/hubs',
fetchScriptByCityNameUrl: '/chaos/it/city_scripts',
redisScriptsKey: 'URANUS.IT.SCRIPTS',
redisParamsKey: 'URANUS.IT.PARAMS',
redisScriptListKey: 'URANUS.IT.SCRIPTLIST',
};
config.storageAPI = {
......@@ -79,11 +79,11 @@ module.exports = () => {
};
config.lockKeys = {
fecthHub: 'NEWSB.HF.HUBS.LOCK',
fecteToken: 'NEWSB.HF.TOKEN.LOCK',
token: 'NEWSB.HF.TOKEN',
fecthParnters: 'NEWSB.PARNTERS.LOCK',
taskPrefix: 'NEWSB.TASK',
fecthHub: 'URANUS.IT.HUBS.LOCK',
fecteToken: 'URANUS.IT.TOKEN.LOCK',
token: 'URANUS.IT.TOKEN',
fecthParnters: 'URANUS.PARNTERS.LOCK',
taskPrefix: 'URANUS.TASK',
};
config.sequelize = {
......
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