Commit 3a3f3fef authored by 何娜's avatar 何娜

tax 城市配置接口更新

parent e17f0c0e
......@@ -185,10 +185,12 @@ class TaskController extends Controller {
const {ctx, service} = this;
// 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: ctx.app.cityLists
})
data: result
});
}
}
......
......@@ -2,7 +2,7 @@
module.exports = {
schedule: {
interval: '24*60m', // 5分钟间隔
interval: '1440m', // 5分钟间隔
type: 'all', // 所有woker
immediate: true,
},
......@@ -32,4 +32,4 @@ module.exports = {
ctx.logger.error('【schedule/notifyUrlTask】catch error:', JSON.stringify(e));
}
}
}
\ No newline at end of file
};
\ No newline at end of file
......@@ -3,96 +3,148 @@
const Service = require('egg').Service;
class TaskService extends Service {
constructor(ctx) {
super(ctx);
const { config } = this;
const { taskAPI, LOCK_KEY } = config;
this.baseURL = taskAPI.host;
this.newbaseURL = taskAPI.newhost;
this.createTaskUrl = taskAPI.createTaskUrl;
this.submitTaskUrl = taskAPI.submitTaskUrl;
this.fetchCodeUrl = taskAPI.fetchCodeUrl;
this.fetchTaskUrl = taskAPI.fetchTaskUrl;
this.LOCK_KEY = LOCK_KEY;
}
constructor(ctx) {
super(ctx);
const {config} = this;
const {taskAPI, LOCK_KEY} = config;
this.baseURL = taskAPI.host;
this.newbaseURL = taskAPI.newhost;
this.createTaskUrl = taskAPI.createTaskUrl;
this.submitTaskUrl = taskAPI.submitTaskUrl;
this.fetchCodeUrl = taskAPI.fetchCodeUrl;
this.fetchTaskUrl = taskAPI.fetchTaskUrl;
this.cityConfigUrl = taskAPI.cityConfigUrl;
this.LOCK_KEY = LOCK_KEY;
}
_request(url, type, opts) {
const { ctx, baseURL, newbaseURL } = this;
url = (type === 'gsgj') ? `${newbaseURL}${url}` : `${baseURL}${url}`;
opts = {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
contentType: 'json',
...opts,
};
ctx.logger.info('_request', type, JSON.stringify(opts));
return ctx.curl(url, opts);
}
_request(url, type, opts) {
const {ctx, baseURL, newbaseURL} = this;
url = (type === 'gsgj') ? `${newbaseURL}${url}` : `${baseURL}${url}`;
opts = {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
contentType: 'json',
...opts,
};
// ctx.logger.info('_request', type, JSON.stringify(opts));
return ctx.curl(url, opts);
}
_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);
_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.data.code !== 0) {
this.ctx.throw(400, {message: result.data.msg, code: result.data.code});
}
}
if (result.data.code !== 0) {
this.ctx.throw(400, { message: result.data.msg, code: result.data.code });
async create(data) {
const {createTaskUrl, ctx} = this;
const result = await this._request(createTaskUrl, ctx.app.channelType, {
method: 'post',
data: {cityId: data},
});
ctx.logger.info(`【Task】create ${createTaskUrl} cityId: ${data} result:`, JSON.stringify(result.data));
ctx.logger.info('channelType', ctx.app.channelType);
this._checkSuccess(result);
return result.data.data.taskId;
}
}
async create(data) {
const { createTaskUrl, ctx } = this;
const result = await this._request(createTaskUrl, ctx.app.channelType, {
method: 'post',
data: { cityId: data },
});
ctx.logger.info(`【Task】create ${createTaskUrl} cityId: ${data} result:`, JSON.stringify(result.data));
ctx.logger.info('channelType', ctx.app.channelType);
this._checkSuccess(result);
return result.data.data.taskId;
}
async fetchCapture({taskId, type}) {
const {fetchCodeUrl, ctx} = this;
let channelType = taskId.length > 20 ? 'gsgj' : '51gs';
const result = await this._request(fetchCodeUrl, channelType, {
method: 'post',
data: {
taskId,
type,
},
});
ctx.logger.info(`【Task】fetchCapture ${fetchCodeUrl} params`, JSON.stringify({
taskId,
type,
}), result.data.code);
this._checkSuccess(result);
return result.data.data;
}
async fetchCapture({ taskId, type }) {
const { fetchCodeUrl, ctx } = this;
let channelType = taskId.length > 20 ? 'gsgj' : '51gs';
const result = await this._request(fetchCodeUrl, channelType, {
method: 'post',
data: {
taskId,
type,
},
});
ctx.logger.info(`【Task】fetchCapture ${fetchCodeUrl} params`, JSON.stringify({
taskId,
type,
}), result.data.code);
this._checkSuccess(result);
return result.data.data;
}
async submit(data) {
const {submitTaskUrl, ctx} = this;
let channelType = data.taskId.length > 20 ? 'gsgj' : '51gs';
const result = await this._request(submitTaskUrl, channelType, {
method: 'post',
data,
});
ctx.logger.info(`【Task】submit ${submitTaskUrl} params`, JSON.stringify(data), JSON.stringify(result.data));
this._checkSuccess(result);
return result;
}
async submit(data) {
const { submitTaskUrl, ctx } = this;
let channelType = data.taskId.length > 20 ? 'gsgj' : '51gs';
const result = await this._request(submitTaskUrl, channelType, {
method: 'post',
data,
});
ctx.logger.info(`【Task】submit ${submitTaskUrl} params`, JSON.stringify(data), JSON.stringify(result.data));
this._checkSuccess(result);
return result;
}
async fetchTask(data) {
const {fetchTaskUrl, ctx} = this;
let channelType = data.taskId.length > 20 ? 'gsgj' : '51gs';
const result = await this._request(fetchTaskUrl, channelType, {
method: 'post',
data,
});
ctx.logger.info(`【Task】fetchTask ${fetchTaskUrl} params`, JSON.stringify(data), JSON.stringify(result.data));
return result.data;
}
async getCityList() {
const {cityConfigUrl, ctx} = this;
let cityLists = [];//对外城市列表
let cityTypeLists = [];//不对外城市列表,含渠道(51/管家)
let newCityMap = new Map();
async fetchTask(data) {
const { fetchTaskUrl, ctx } = this;
let channelType = data.taskId.length > 20 ? 'gsgj' : '51gs';
const result = await this._request(fetchTaskUrl, channelType, {
method: 'post',
data,
});
ctx.logger.info(`【Task】fetchTask ${fetchTaskUrl} params`, JSON.stringify(data), JSON.stringify(result.data));
return result.data;
}
const newret = await this._request(cityConfigUrl, 'gsgj', {method: 'get'});
ctx.logger.info(`【Task】getCityList ${cityConfigUrl} params gsgj`, JSON.stringify(newret.data.code));
this._checkSuccess(newret);
newret.data.data.map(Prov => {
Prov.citys.map(city => {
newCityMap.set(String(city.id), city)
})
});
const ret = await this._request(cityConfigUrl, '51gs', {method: 'get'});
ctx.logger.info(`【Task】getCityList ${cityConfigUrl} params 51gs`, JSON.stringify(newret.data.code));
this._checkSuccess(ret);
ret.data.data.map(Prov => {
let newProv = {provinceName: Prov.provinceName, citys: []};
Prov.citys.map(city => {
city.type = "51gs";
if (city.state === -1 && newCityMap.get(String(city.id)) && newCityMap.get(String(city.id)).state === 1) {
city = newCityMap.get(String(city.id));
city.type = "gsgj";
ctx.logger.info('city', city)
}
if (city.state != 1) {
city.state = -1;
}
newProv.citys.push({
province: city.province,
name: city.name,
id: city.id,
state: city.state,
queryParam: city.queryParam
});
cityTypeLists.push({
province: city.province,
name: city.name,
id: city.id,
state: city.state,
type: city.type,
});
});
cityLists.push(newProv);
});
ctx.app.cityTypeLists = cityTypeLists;
return cityLists;
}
}
module.exports = TaskService;
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