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

tax 城市配置接口更新

parent e17f0c0e
...@@ -185,10 +185,12 @@ class TaskController extends Controller { ...@@ -185,10 +185,12 @@ class TaskController extends Controller {
const {ctx, service} = this; const {ctx, service} = this;
// ctx.validate(this.cityConfigRule); // ctx.validate(this.cityConfigRule);
// await service.signature.signatureCheck(ctx.request.body); // await service.signature.signatureCheck(ctx.request.body);
const result = await service.task.getCityList();
console.log('Type'+JSON.stringify(ctx.app.cityTypeLists[0]))
ctx.success({ ctx.success({
code: 0, code: 0,
data: ctx.app.cityLists data: result
}) });
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module.exports = { module.exports = {
schedule: { schedule: {
interval: '24*60m', // 5分钟间隔 interval: '1440m', // 5分钟间隔
type: 'all', // 所有woker type: 'all', // 所有woker
immediate: true, immediate: true,
}, },
...@@ -32,4 +32,4 @@ module.exports = { ...@@ -32,4 +32,4 @@ module.exports = {
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 \ No newline at end of file
...@@ -5,20 +5,21 @@ const Service = require('egg').Service; ...@@ -5,20 +5,21 @@ const Service = require('egg').Service;
class TaskService extends Service { class TaskService extends Service {
constructor(ctx) { constructor(ctx) {
super(ctx); super(ctx);
const { config } = this; const {config} = this;
const { taskAPI, LOCK_KEY } = config; const {taskAPI, LOCK_KEY} = config;
this.baseURL = taskAPI.host; this.baseURL = taskAPI.host;
this.newbaseURL = taskAPI.newhost; this.newbaseURL = taskAPI.newhost;
this.createTaskUrl = taskAPI.createTaskUrl; this.createTaskUrl = taskAPI.createTaskUrl;
this.submitTaskUrl = taskAPI.submitTaskUrl; this.submitTaskUrl = taskAPI.submitTaskUrl;
this.fetchCodeUrl = taskAPI.fetchCodeUrl; this.fetchCodeUrl = taskAPI.fetchCodeUrl;
this.fetchTaskUrl = taskAPI.fetchTaskUrl; this.fetchTaskUrl = taskAPI.fetchTaskUrl;
this.cityConfigUrl = taskAPI.cityConfigUrl;
this.LOCK_KEY = LOCK_KEY; this.LOCK_KEY = LOCK_KEY;
} }
_request(url, type, opts) { _request(url, type, opts) {
const { ctx, baseURL, newbaseURL } = this; const {ctx, baseURL, newbaseURL} = this;
url = (type === 'gsgj') ? `${newbaseURL}${url}` : `${baseURL}${url}`; url = (type === 'gsgj') ? `${newbaseURL}${url}` : `${baseURL}${url}`;
opts = { opts = {
charset: 'utf-8', charset: 'utf-8',
...@@ -27,7 +28,7 @@ class TaskService extends Service { ...@@ -27,7 +28,7 @@ class TaskService extends Service {
contentType: 'json', contentType: 'json',
...opts, ...opts,
}; };
ctx.logger.info('_request', type, JSON.stringify(opts)); // ctx.logger.info('_request', type, JSON.stringify(opts));
return ctx.curl(url, opts); return ctx.curl(url, opts);
} }
...@@ -37,15 +38,15 @@ class TaskService extends Service { ...@@ -37,15 +38,15 @@ class TaskService extends Service {
this.ctx.throw(result.status, errorMsg); this.ctx.throw(result.status, errorMsg);
} }
if (result.data.code !== 0) { if (result.data.code !== 0) {
this.ctx.throw(400, { message: result.data.msg, code: result.data.code }); this.ctx.throw(400, {message: result.data.msg, code: result.data.code});
} }
} }
async create(data) { async create(data) {
const { createTaskUrl, ctx } = this; const {createTaskUrl, ctx} = this;
const result = await this._request(createTaskUrl, ctx.app.channelType, { const result = await this._request(createTaskUrl, ctx.app.channelType, {
method: 'post', method: 'post',
data: { cityId: data }, data: {cityId: data},
}); });
ctx.logger.info(`【Task】create ${createTaskUrl} cityId: ${data} result:`, JSON.stringify(result.data)); ctx.logger.info(`【Task】create ${createTaskUrl} cityId: ${data} result:`, JSON.stringify(result.data));
ctx.logger.info('channelType', ctx.app.channelType); ctx.logger.info('channelType', ctx.app.channelType);
...@@ -53,8 +54,8 @@ class TaskService extends Service { ...@@ -53,8 +54,8 @@ class TaskService extends Service {
return result.data.data.taskId; return result.data.data.taskId;
} }
async fetchCapture({ taskId, type }) { async fetchCapture({taskId, type}) {
const { fetchCodeUrl, ctx } = this; const {fetchCodeUrl, ctx} = this;
let channelType = taskId.length > 20 ? 'gsgj' : '51gs'; let channelType = taskId.length > 20 ? 'gsgj' : '51gs';
const result = await this._request(fetchCodeUrl, channelType, { const result = await this._request(fetchCodeUrl, channelType, {
method: 'post', method: 'post',
...@@ -72,7 +73,7 @@ class TaskService extends Service { ...@@ -72,7 +73,7 @@ class TaskService extends Service {
} }
async submit(data) { async submit(data) {
const { submitTaskUrl, ctx } = this; const {submitTaskUrl, ctx} = this;
let channelType = data.taskId.length > 20 ? 'gsgj' : '51gs'; let channelType = data.taskId.length > 20 ? 'gsgj' : '51gs';
const result = await this._request(submitTaskUrl, channelType, { const result = await this._request(submitTaskUrl, channelType, {
method: 'post', method: 'post',
...@@ -84,7 +85,7 @@ class TaskService extends Service { ...@@ -84,7 +85,7 @@ class TaskService extends Service {
} }
async fetchTask(data) { async fetchTask(data) {
const { fetchTaskUrl, ctx } = this; const {fetchTaskUrl, ctx} = this;
let channelType = data.taskId.length > 20 ? 'gsgj' : '51gs'; let channelType = data.taskId.length > 20 ? 'gsgj' : '51gs';
const result = await this._request(fetchTaskUrl, channelType, { const result = await this._request(fetchTaskUrl, channelType, {
method: 'post', method: 'post',
...@@ -93,6 +94,57 @@ class TaskService extends Service { ...@@ -93,6 +94,57 @@ class TaskService extends Service {
ctx.logger.info(`【Task】fetchTask ${fetchTaskUrl} params`, JSON.stringify(data), JSON.stringify(result.data)); ctx.logger.info(`【Task】fetchTask ${fetchTaskUrl} params`, JSON.stringify(data), JSON.stringify(result.data));
return result.data; return result.data;
} }
async getCityList() {
const {cityConfigUrl, ctx} = this;
let cityLists = [];//对外城市列表
let cityTypeLists = [];//不对外城市列表,含渠道(51/管家)
let newCityMap = new Map();
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; 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