Commit 0c7a5ca6 authored by 何娜's avatar 何娜

fix

parent 8ff64eac
Pipeline #4990 passed with stage
in 2 seconds
......@@ -32,6 +32,7 @@ class ScriptController extends Controller {
const data = await service.scripts.fetchOneScripts(scriptId);
ctx.success(data);
}
async fetchParamsInfo() {
const { ctx, service } = this;
const { refresh = false } = ctx.query;
......
......@@ -5,8 +5,8 @@ const Service = require('egg').Service;
class ScriptsService extends Service {
constructor(ctx) {
super(ctx);
const { config } = this;
const { scriptsAPI } = config;
const {config} = this;
const {scriptsAPI, taskAPI} = config;
this.scriptsAPI = scriptsAPI;
this.baseURL = scriptsAPI.host;
this.fetchScriptsUrl = scriptsAPI.fetchScriptsUrl;
......@@ -16,10 +16,12 @@ class ScriptsService extends Service {
this.redisScriptsKey = scriptsAPI.redisScriptsKey;
this.redisParamsKey = scriptsAPI.redisParamsKey;
this.redisScriptListKey = scriptsAPI.redisScriptListKey;
this.newhost = taskAPI.newhost;
this.cityConfigUrl = taskAPI.cityConfigUrl;
}
async fetchScripts() {
const { baseURL, fetchScriptsUrl, redisScriptsKey, ctx } = this;
const {baseURL, fetchScriptsUrl, redisScriptsKey, newhost, cityConfigUrl, ctx} = this;
const data = await this.app.redis.get(redisScriptsKey);
if (data) {
try {
......@@ -29,22 +31,60 @@ class ScriptsService extends Service {
await this.app.redis.del(redisScriptsKey);
}
}
let cityLists = [];
let newCityMap = new Map();
//个税管家
const gsgjRet = await ctx.curl(newhost + cityConfigUrl, {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
contentType: 'json',
});
ctx.logger.info(`【Scripts】fetchScripts,gsgjRet,${baseURL + fetchScriptsUrl}`, 'result:', gsgjRet.data[1]);
if (gsgjRet.data && gsgjRet.data.code === 0) {
gsgjRet.data.data.map(Prov => {
Prov.citys.map(city => {
let state = city.state === 1 ? 'online' : 'offline';
let obj = {
id: city.id,
state: state,
hub_name: city.name,
hub_id: city.id,
province_name: Prov.provinceName,
province_id: city.province,
};
newCityMap.set(String(city.id), obj)
})
});
}
//爬虫
const result = await ctx.curl(baseURL + fetchScriptsUrl, {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
contentType: 'json',
});
ctx.logger.info(`【Scripts】fetchScripts,${baseURL + fetchScriptsUrl}`, 'result:', result.data[1]);
ctx.logger.info(`【Scripts】fetchScripts,result,${baseURL + fetchScriptsUrl}`, 'result:', result.data[1]);
if (result.data && result.data.length > 0) {
await this.app.redis.set(redisScriptsKey, JSON.stringify(result.data), 'EX', 300);
result.data.map(city => {
if (city.state === 'offline' && newCityMap.get(String(city.id)) && newCityMap.get(String(city.id)).state === 'online') {
city = newCityMap.get(String(city.id));
city.channelType = "gsgj";
ctx.logger.info(city.id, city.hub_name)
} else {
city.channelType = "51gs";
}
return result.data;
cityLists.push(city)
});
await this.app.redis.set(redisScriptsKey, JSON.stringify(cityLists), 'EX', 300);
}
return cityLists;
}
async fetchOneScripts(scriptId) {
const { baseURL, fetchOneScriptUrl, redisScriptListKey, ctx } = this;
const {baseURL, fetchOneScriptUrl, redisScriptListKey, newhost, cityConfigUrl, ctx} = this;
const data = await this.app.redis.get(redisScriptListKey + scriptId);
if (data) {
try {
......@@ -54,20 +94,76 @@ class ScriptsService extends Service {
await this.app.redis.del(redisScriptListKey + scriptId);
}
}
let scriptData;
const result = await ctx.curl(baseURL + fetchOneScriptUrl + '/' + scriptId, {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
contentType: 'json',
});
if (result.data && (String(result.data.id) === scriptId)) {
await this.app.redis.set(redisScriptListKey + scriptId, JSON.stringify(result.data), 'EX', 60);
if (result.data) {
if (result.data.state != 'online') {
//个税管家
// let newCityMap = new Map();
const gsgjRet = await ctx.curl(newhost + cityConfigUrl, {
charset: 'utf-8',
timeout: ['30s', '30s'],
dataType: 'json',
contentType: 'json',
});
if (gsgjRet.data && gsgjRet.data.code === 0) {
gsgjRet.data.data.map(Prov => {
Prov.citys.map(city => {
if (city.state === 1) {
result.data.params = [];
for (let item of queryParam) {
let objs = {
login_type_id: '',
name: '',
login_step_detail: [{
current_step: '',
login_param: [],
next_step: '',
step_name: '',
pre_step: ''
}],
};
for (let gjParams of item.loginParam) {
let gjObj = {};
if (gjParams.type === 'radio') {
gjObj = {
name: gjParams.name,
note: '',
placeholder: gjParams.note,
type: 'radio',
}
} else {
gjObj = {
name: gjParams.name,
note: gjParams.note,
placeholder: '',
type: gjParams.type,
}
}
objs.login_step_detail.login_param.push(gjObj)
}
result.data.params.push(objs)
}
return result.data;
}
})
});
}
} else {
scriptData = result.data;
}
await this.app.redis.set(redisScriptListKey + scriptId, JSON.stringify(scriptData), 'EX', 60);
}
return scriptData;
}
async fetchParams(refresh = false) {
const { baseURL, fetchParamsInfoUrl, redisParamsKey, ctx } = this;
const {baseURL, fetchParamsInfoUrl, redisParamsKey, ctx} = this;
if (!refresh) {
const data = await this.app.redis.get(redisParamsKey);
if (data) {
......@@ -94,7 +190,7 @@ class ScriptsService extends Service {
}
async fetchHelp(scriptId) {
const { baseURL, scriptsAPI: { fetchHelpUrl }, ctx } = this;
const {baseURL, scriptsAPI: {fetchHelpUrl}, ctx} = this;
const result = await ctx.curl(baseURL + fetchHelpUrl + '/' + scriptId, {
charset: 'utf-8',
timeout: ['30s', '30s'],
......@@ -105,7 +201,7 @@ class ScriptsService extends Service {
}
async fetchQueryButton(scriptId) {
const { baseURL, scriptsAPI: { fetchQueryButtonUrl }, ctx } = this;
const {baseURL, scriptsAPI: {fetchQueryButtonUrl}, ctx} = this;
const result = await ctx.curl(baseURL + fetchQueryButtonUrl + '/' + scriptId, {
charset: 'utf-8',
timeout: ['30s', '30s'],
......@@ -116,7 +212,7 @@ class ScriptsService extends Service {
}
async fetchNotice(scriptId) {
const { baseURL, scriptsAPI: { fetchNoticeUrl }, ctx } = this;
const {baseURL, scriptsAPI: {fetchNoticeUrl}, ctx} = this;
const result = await ctx.curl(baseURL + fetchNoticeUrl + '/' + scriptId, {
charset: 'utf-8',
timeout: ['30s', '30s'],
......@@ -127,7 +223,7 @@ class ScriptsService extends Service {
}
async fetchHubSeripts(hubId) {
const { baseURL, scriptsAPI: { fetchHubSeriptsUrl }, ctx } = this;
const {baseURL, scriptsAPI: {fetchHubSeriptsUrl}, ctx} = this;
const result = await ctx.curl(baseURL + fetchHubSeriptsUrl + '/' + hubId + '/scripts', {
charset: 'utf-8',
timeout: ['30s', '30s'],
......@@ -136,9 +232,10 @@ class ScriptsService extends Service {
});
return result.data;
}
async fetchCityFormIp() {
const { ctx } = this;
const { ip } = ctx.request;
const {ctx} = this;
const {ip} = ctx.request;
ctx.logger.info(ctx.request);
const url = `https://api.map.baidu.com/location/ip?ak=3TBenWOhPygtFFazaR5kSibU&ip=${ip}`;
const result = await ctx.curl(url, {
......@@ -155,7 +252,7 @@ class ScriptsService extends Service {
}
async fetchScriptByCityName(name) {
const { baseURL, scriptsAPI: { fetchScriptByCityNameUrl }, ctx } = this;
const {baseURL, scriptsAPI: {fetchScriptByCityNameUrl}, ctx} = this;
const result = await ctx.curl(baseURL + fetchScriptByCityNameUrl + '?name=' + encodeURIComponent(name) + '&type=query', {
charset: 'utf-8',
timeout: ['30s', '30s'],
......
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