Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
taxh5
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data_server
taxh5
Commits
3a3f3fef
Commit
3a3f3fef
authored
Mar 14, 2019
by
何娜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tax 城市配置接口更新
parent
e17f0c0e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
86 deletions
+140
-86
task.js
app/controller/task.js
+4
-2
notifyUrl.js
app/schedule/notifyUrl.js
+3
-3
task.js
app/service/task.js
+133
-81
No files found.
app/controller/task.js
View file @
3a3f3fef
...
@@ -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
})
})
;
}
}
}
}
...
...
app/schedule/notifyUrl.js
View file @
3a3f3fef
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
module
.
exports
=
{
module
.
exports
=
{
schedule
:
{
schedule
:
{
interval
:
'
24*6
0m'
,
// 5分钟间隔
interval
:
'
144
0m'
,
// 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
app/service/task.js
View file @
3a3f3fef
...
@@ -3,96 +3,148 @@
...
@@ -3,96 +3,148 @@
const
Service
=
require
(
'egg'
).
Service
;
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
.
LOCK_KEY
=
LOCK_KEY
;
this
.
cityConfigUrl
=
taskAPI
.
cityConfigUrl
;
}
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'
,
timeout
:
[
'30s'
,
'30s'
],
timeout
:
[
'30s'
,
'30s'
],
dataType
:
'json'
,
dataType
:
'json'
,
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
);
}
}
_checkSuccess
(
result
)
{
_checkSuccess
(
result
)
{
if
(
result
.
status
!==
200
)
{
if
(
result
.
status
!==
200
)
{
const
errorMsg
=
result
.
data
&&
result
.
data
.
error_msg
?
result
.
data
.
error_msg
:
'unknown error'
;
const
errorMsg
=
result
.
data
&&
result
.
data
.
error_msg
?
result
.
data
.
error_msg
:
'unknown error'
;
this
.
ctx
.
throw
(
result
.
status
,
errorMsg
);
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
)
{
async
fetchCapture
({
taskId
,
type
})
{
const
{
createTaskUrl
,
ctx
}
=
this
;
const
{
fetchCodeUrl
,
ctx
}
=
this
;
const
result
=
await
this
.
_request
(
createTaskUrl
,
ctx
.
app
.
channelType
,
{
let
channelType
=
taskId
.
length
>
20
?
'gsgj'
:
'51gs'
;
method
:
'post'
,
const
result
=
await
this
.
_request
(
fetchCodeUrl
,
channelType
,
{
data
:
{
cityId
:
data
},
method
:
'post'
,
});
data
:
{
ctx
.
logger
.
info
(
`【Task】create
${
createTaskUrl
}
cityId:
${
data
}
result:`
,
JSON
.
stringify
(
result
.
data
));
taskId
,
ctx
.
logger
.
info
(
'channelType'
,
ctx
.
app
.
channelType
);
type
,
this
.
_checkSuccess
(
result
);
},
return
result
.
data
.
data
.
taskId
;
});
}
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
})
{
async
submit
(
data
)
{
const
{
fetchCodeUrl
,
ctx
}
=
this
;
const
{
submitTaskUrl
,
ctx
}
=
this
;
let
channelType
=
taskId
.
length
>
20
?
'gsgj'
:
'51gs'
;
let
channelType
=
data
.
taskId
.
length
>
20
?
'gsgj'
:
'51gs'
;
const
result
=
await
this
.
_request
(
fetchCodeUrl
,
channelType
,
{
const
result
=
await
this
.
_request
(
submitTaskUrl
,
channelType
,
{
method
:
'post'
,
method
:
'post'
,
data
:
{
data
,
taskId
,
});
type
,
ctx
.
logger
.
info
(
`【Task】submit
${
submitTaskUrl
}
params`
,
JSON
.
stringify
(
data
),
JSON
.
stringify
(
result
.
data
));
},
this
.
_checkSuccess
(
result
);
});
return
result
;
ctx
.
logger
.
info
(
`【Task】fetchCapture
${
fetchCodeUrl
}
params`
,
JSON
.
stringify
({
}
taskId
,
type
,
}),
result
.
data
.
code
);
this
.
_checkSuccess
(
result
);
return
result
.
data
.
data
;
}
async
submit
(
data
)
{
async
fetchTask
(
data
)
{
const
{
submitTaskUrl
,
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
(
submitTaskUrl
,
channelType
,
{
const
result
=
await
this
.
_request
(
fetchTaskUrl
,
channelType
,
{
method
:
'post'
,
method
:
'post'
,
data
,
data
,
});
});
ctx
.
logger
.
info
(
`【Task】submit
${
submitTaskUrl
}
params`
,
JSON
.
stringify
(
data
),
JSON
.
stringify
(
result
.
data
));
ctx
.
logger
.
info
(
`【Task】fetchTask
${
fetchTaskUrl
}
params`
,
JSON
.
stringify
(
data
),
JSON
.
stringify
(
result
.
data
));
this
.
_checkSuccess
(
result
);
return
result
.
data
;
return
result
;
}
}
async
getCityList
()
{
const
{
cityConfigUrl
,
ctx
}
=
this
;
let
cityLists
=
[];
//对外城市列表
let
cityTypeLists
=
[];
//不对外城市列表,含渠道(51/管家)
let
newCityMap
=
new
Map
();
async
fetchTask
(
data
)
{
const
newret
=
await
this
.
_request
(
cityConfigUrl
,
'gsgj'
,
{
method
:
'get'
});
const
{
fetchTaskUrl
,
ctx
}
=
this
;
ctx
.
logger
.
info
(
`【Task】getCityList
${
cityConfigUrl
}
params gsgj`
,
JSON
.
stringify
(
newret
.
data
.
code
));
let
channelType
=
data
.
taskId
.
length
>
20
?
'gsgj'
:
'51gs'
;
this
.
_checkSuccess
(
newret
);
const
result
=
await
this
.
_request
(
fetchTaskUrl
,
channelType
,
{
newret
.
data
.
data
.
map
(
Prov
=>
{
method
:
'post'
,
Prov
.
citys
.
map
(
city
=>
{
data
,
newCityMap
.
set
(
String
(
city
.
id
),
city
)
});
})
ctx
.
logger
.
info
(
`【Task】fetchTask
${
fetchTaskUrl
}
params`
,
JSON
.
stringify
(
data
),
JSON
.
stringify
(
result
.
data
));
});
return
result
.
data
;
}
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
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment