Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
马玮
/
carspider
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
856ddd7e
authored
Aug 29, 2017
by
马玮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add latest fetch point
parent
cb218239
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
190 additions
and
174 deletions
+190
-174
lib/helpers/Dealer.js
+76
-77
lib/spider/Base.js
+11
-0
lib/spider/dealer/Autohome.js
+11
-8
lib/spider/dealer/Easypass.js
+90
-89
sql/history.sql
+2
-0
No files found.
lib/helpers/Dealer.js
View file @
856ddd7e
...
@@ -258,60 +258,61 @@ class DealerHelper {
...
@@ -258,60 +258,61 @@ class DealerHelper {
// 保存线索
// 保存线索
static
async
saveClues
(
params
)
{
static
async
saveClues
(
params
)
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
const
dealerID
=
params
.
dealerID
||
0
;
try
{
const
website
=
params
.
website
||
''
;
const
dealerID
=
params
.
dealerID
||
0
;
let
clues
=
params
.
clues
||
[];
const
website
=
params
.
website
||
''
;
if
(
!
dealerID
||
!
clues
.
length
||
!
website
)
{
let
clues
=
params
.
clues
||
[];
throw
errors
.
AppError
(
'Params missing'
);
if
(
!
dealerID
||
!
clues
.
length
||
!
website
)
{
}
throw
new
errors
.
AppError
(
'Params missing'
);
}
clues
=
await
this
.
mapClues
(
params
).
catch
((
e
)
=>
{
clues
=
await
this
.
mapClues
(
params
).
catch
((
e
)
=>
{
console
.
log
(
e
);
logger
.
error
(
`accountID:
${
params
.
accountID
}
, 线索信息匹配失败:
${
e
}
}`
);
});
});
const
connection
=
await
DI
.
getConnection
(
'MASTER_CRM'
);
const
connection
=
await
DI
.
getConnection
(
'MASTER_CRM'
);
const
valuesSql
=
[];
const
valuesSql
=
[];
const
_clue
=
{
const
_clue
=
{
customerID
:
0
,
customerID
:
0
,
customerName
:
''
,
customerName
:
''
,
customerPhone
:
''
,
customerPhone
:
''
,
customerArea
:
''
,
customerArea
:
''
,
licenseArea
:
''
,
licenseArea
:
''
,
intentionDes
:
''
,
intentionDes
:
''
,
intentionID
:
0
,
intentionID
:
0
,
salesmanName
:
''
,
salesmanName
:
''
,
salesPhone
:
''
,
salesPhone
:
''
,
createdAt
:
0
,
createdAt
:
0
,
};
};
for
(
let
clue
of
clues
)
{
for
(
let
clue
of
clues
)
{
clue
=
Object
.
assign
(
_clue
,
clue
);
clue
=
Object
.
assign
(
_clue
,
clue
);
try
{
try
{
clue
.
customerID
=
await
this
.
saveCustomer
({
clue
.
customerID
=
await
this
.
saveCustomer
({
phone
:
clue
.
customerPhone
,
phone
:
clue
.
customerPhone
,
name
:
clue
.
customerName
,
name
:
clue
.
customerName
,
area
:
clue
.
customerAreaID
,
area
:
clue
.
customerAreaID
,
createTime
:
clue
.
createdAt
createTime
:
clue
.
createdAt
});
});
logger
.
debug
(
`accountID:
${
params
.
accountID
}
, 客户信息保存成功, customerID:
${
clue
.
customerID
}
`
);
logger
.
debug
(
`accountID:
${
params
.
accountID
}
, 客户信息保存成功, customerID:
${
clue
.
customerID
}
`
);
}
catch
(
e
)
{
}
catch
(
e
)
{
// 如果没有customerID则跳过这条线索
// 如果没有customerID则跳过这条线索
logger
.
error
(
`accountID:
${
params
.
accountID
}
, 客户信息保存失败:
${
e
}
}`
);
logger
.
error
(
`accountID:
${
params
.
accountID
}
, 客户信息保存失败:
${
e
}
}`
);
continue
;
continue
;
}
}
let
valueSql
=
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
;
let
valueSql
=
'(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
;
// customer_id, shop_name, salesman_id需要映射
// customer_id, shop_name, salesman_id需要映射
let
replacements
=
[
let
replacements
=
[
clue
.
customerID
,
clue
.
customerName
,
clue
.
customerPhone
,
clue
.
intentionDes
,
clue
.
intentionID
,
''
,
dealerID
,
clue
.
salesmanName
,
0
,
clue
.
customerID
,
clue
.
customerName
,
clue
.
customerPhone
,
clue
.
intentionDes
,
clue
.
intentionID
,
''
,
dealerID
,
clue
.
salesmanName
,
0
,
config
.
get
(
'CLUE_INPUT_TYPE'
)[
params
.
website
],
4
,
clue
.
createdAt
config
.
get
(
'CLUE_INPUT_TYPE'
)[
params
.
website
],
4
,
clue
.
createdAt
];
];
valueSql
=
connection
.
format
(
valueSql
,
replacements
);
valueSql
=
connection
.
format
(
valueSql
,
replacements
);
valuesSql
.
push
(
valueSql
);
valuesSql
.
push
(
valueSql
);
}
}
const
sql
=
`INSERT INTO crm_clue (
const
sql
=
`INSERT INTO crm_clue (
customer_id, customer_name, customer_phone, intention_des, intention_id, shop_name, shop_id,
customer_id, customer_name, customer_phone, intention_des, intention_id, shop_name, shop_id,
salesman_name, salesman_id, clue_input_type, create_type, create_time
salesman_name, salesman_id, clue_input_type, create_type, create_time
) VALUES
${
valuesSql
.
join
(
','
)}
ON DUPLICATE KEY UPDATE
) VALUES
${
valuesSql
.
join
(
','
)}
ON DUPLICATE KEY UPDATE
...
@@ -321,38 +322,35 @@ class DealerHelper {
...
@@ -321,38 +322,35 @@ class DealerHelper {
intention_des = VALUES(intention_des),
intention_des = VALUES(intention_des),
create_type = VALUES(create_type)`
;
create_type = VALUES(create_type)`
;
connection
.
query
(
connection
.
query
(
sql
,
sql
,
async
(
err
,
results
,
fields
)
=>
{
async
(
err
,
results
,
fields
)
=>
{
connection
.
release
();
connection
.
release
();
if
(
err
)
{
if
(
err
)
{
reject
(
new
errors
.
AppError
(
err
));
reject
(
new
errors
.
AppError
(
err
));
}
}
if
(
results
.
affectedRows
)
{
if
(
results
.
affectedRows
)
{
// console.log(results.insertId, results);
// console.log(results.insertId, results);
logger
.
info
(
`accountID:
${
params
.
accountID
}
, 线索信息保存成功, 总计:
${
results
.
affectedRows
}
`
);
logger
.
info
(
`accountID:
${
params
.
accountID
}
, 线索信息保存成功, 总计:
${
results
.
affectedRows
}
`
);
try
{
try
{
await
this
.
saveSummary
(
params
);
await
this
.
saveSummary
(
params
);
logger
.
info
(
`accountID:
${
params
.
accountID
}
, 线索统计保存成功`
);
logger
.
info
(
`accountID:
${
params
.
accountID
}
, 线索统计保存成功`
);
}
catch
(
e
)
{
}
catch
(
e
)
{
logger
.
info
(
`accountID:
${
params
.
accountID
}
, 线索统计保存失败`
);
logger
.
info
(
`accountID:
${
params
.
accountID
}
, 线索统计保存失败,
${
e
}
`
);
}
}
try
{
await
this
.
updateLatestFetch
(
params
);
logger
.
info
(
`accountID:
${
params
.
accountID
}
, 抓取时间更新成功`
);
}
catch
(
e
)
{
logger
.
info
(
`accountID:
${
params
.
accountID
}
, 抓取时间更新失败`
);
}
resolve
(
true
);
resolve
(
true
);
}
else
{
}
else
{
reject
(
new
errors
.
AppError
(
'线索保存失败'
));
reject
(
new
errors
.
AppError
(
'线索保存失败'
));
}
}
}
}
);
);
}
catch
(
e
)
{
reject
(
e
);
}
});
});
}
}
...
@@ -386,8 +384,9 @@ class DealerHelper {
...
@@ -386,8 +384,9 @@ class DealerHelper {
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
try
{
try
{
const
sql
=
`UPDATE crm_dealer_thirdparty_account SET
const
sql
=
`UPDATE crm_dealer_thirdparty_account SET
latestClueAt = (SELECT MAX(create_time) FROM crm_clue WHERE clue_input_type = ? AND dealerID = ?),
latestFetchAt = UNIX_TIMESTAMP() WHERE id = ?`
;
latestFetchAt = UNIX_TIMESTAMP() WHERE id = ?`
;
const
replacements
=
[
params
.
accountID
];
const
replacements
=
[
config
.
get
(
'CLUE_INPUT_TYPE'
)[
params
.
website
],
params
.
dealerID
,
params
.
accountID
];
const
connection
=
await
DI
.
getConnection
(
'MASTER_CRM'
);
const
connection
=
await
DI
.
getConnection
(
'MASTER_CRM'
);
connection
.
query
(
connection
.
query
(
sql
,
sql
,
...
...
lib/spider/Base.js
View file @
856ddd7e
...
@@ -49,6 +49,16 @@ class Base {
...
@@ -49,6 +49,16 @@ class Base {
throw
new
errors
.
LoginError
(
'登录失败'
);
throw
new
errors
.
LoginError
(
'登录失败'
);
}
}
}
}
// 更新抓取时间
async
updateLatestFetch
()
{
try
{
await
DealerHelper
.
updateLatestFetch
(
this
.
params
);
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 抓取时间更新成功`
);
}
catch
(
e
)
{
logger
.
error
(
`accountID:
${
this
.
params
.
accountID
}
, 抓取时间更新失败,
${
e
}
`
);
}
}
}
}
module
.
exports
=
Base
;
module
.
exports
=
Base
;
\ No newline at end of file
lib/spider/dealer/Autohome.js
View file @
856ddd7e
...
@@ -198,11 +198,11 @@ class Autohome extends Base {
...
@@ -198,11 +198,11 @@ class Autohome extends Base {
let
startTime
;
let
startTime
;
let
customerIndex
=
0
;
let
customerIndex
=
0
;
//
读取上次抓取时间点
//
最新线索时间点作为抓取开始时间
if
(
this
.
params
.
latest
Fetch
At
)
{
if
(
this
.
params
.
latest
Clue
At
)
{
startTime
=
moment
.
unix
(
this
.
params
.
latest
Fetch
At
).
format
(
'YYYY.MM.DD'
);
startTime
=
moment
.
unix
(
this
.
params
.
latest
Clue
At
).
format
(
'YYYY.MM.DD'
);
}
else
{
}
else
{
startTime
=
moment
().
subtract
(
3
0
,
'days'
).
format
(
'YYYY.MM.DD'
);
startTime
=
moment
().
subtract
(
3
,
'days'
).
format
(
'YYYY.MM.DD'
);
}
}
const
params
=
{};
const
params
=
{};
...
@@ -276,17 +276,19 @@ class Autohome extends Base {
...
@@ -276,17 +276,19 @@ class Autohome extends Base {
// logger.debug('线索类型:', clue.orderType);
// logger.debug('线索类型:', clue.orderType);
// logger.debug('线索状态:', clue.orderState);
// logger.debug('线索状态:', clue.orderState);
logger
.
debug
(
`accountID:
${
this
.
params
.
accountID
}
, 线索:
${
JSON
.
stringify
(
clue
)}
`
);
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 线索:
${
JSON
.
stringify
(
clue
)}
`
);
logger
.
debug
(
'==============================================================================='
);
logger
.
info
(
'==============================================================================='
);
}
}
if
(
this
.
params
.
dealerID
)
{
if
(
clues
.
length
>
0
)
{
await
DealerHelper
.
saveClues
({
await
DealerHelper
.
saveClues
({
clues
:
clues
,
clues
:
clues
,
dealerID
:
this
.
params
.
dealerID
,
dealerID
:
this
.
params
.
dealerID
,
website
:
this
.
params
.
website
,
website
:
this
.
params
.
website
,
accountID
:
this
.
params
.
accountID
,
accountID
:
this
.
params
.
accountID
,
});
});
}
else
{
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 时间段(
${
params
.
startTime
}
-
${
params
.
endtime
}
)没有线索`
);
}
}
// 判断是否抓取完全
// 判断是否抓取完全
...
@@ -301,8 +303,9 @@ class Autohome extends Base {
...
@@ -301,8 +303,9 @@ class Autohome extends Base {
});
});
}
}
await
fetchByPage
();
await
fetchByPage
();
await
this
.
updateLatestFetch
();
}
catch
(
e
)
{
}
catch
(
e
)
{
logger
.
error
(
e
);
logger
.
error
(
`accountID:
${
this
.
params
.
accountID
}
,
${
e
}
`
);
}
}
}
}
}
}
...
...
lib/spider/dealer/Easypass.js
View file @
856ddd7e
...
@@ -194,107 +194,108 @@ class Easypass extends Base {
...
@@ -194,107 +194,108 @@ class Easypass extends Base {
logger
.
debug
(
e
);
logger
.
debug
(
e
);
}
}
if
(
cookies
)
{
if
(
!
cookies
)
throw
new
errors
.
AppError
(
'抓取线索cookies读取失败'
);
const
horseman
=
new
Horseman
({
ignoreSSLErrors
:
true
});
// 上次抓取时间点
const
horseman
=
new
Horseman
({
let
txtBeginTime
;
ignoreSSLErrors
:
true
if
(
this
.
params
.
latestFetchAt
)
{
});
txtBeginTime
=
moment
.
unix
(
this
.
params
.
latestFetchAt
).
format
(
'YYYY-MM-DD'
);
}
else
{
txtBeginTime
=
moment
().
subtract
(
3
,
'days'
).
format
(
'YYYY-MM-DD'
);
}
const
txtEndTime
=
moment
().
format
(
'YYYY-MM-DD'
);
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 线索抓取范围:
${
txtBeginTime
}
-
${
txtEndTime
}
`
);
// 最新线索时间点作为抓取开始时间
let
txtBeginTime
;
if
(
this
.
params
.
latestClueAt
)
{
txtBeginTime
=
moment
.
unix
(
this
.
params
.
latestClueAt
).
format
(
'YYYY-MM-DD'
);
}
else
{
txtBeginTime
=
moment
().
subtract
(
3
,
'days'
).
format
(
'YYYY-MM-DD'
);
}
const
txtEndTime
=
moment
().
format
(
'YYYY-MM-DD'
);
await
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 线索抓取范围:
${
txtBeginTime
}
-
${
txtEndTime
}
`
);
horseman
.
userAgent
(
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0'
)
.
viewport
(
1920
,
1080
)
.
cookies
(
cookies
)
.
open
(
'http://app.Easypass.cn/lmsnew/OutmodedDefault.aspx'
)
.
waitForSelector
(
'#UpdatePanel1'
)
.
waitForSelector
(
'#pager1'
)
.
type
(
'input[id="txtBeginTime"]'
,
txtBeginTime
)
.
click
(
'input[id="btnSearch"]'
)
.
wait
(
1000
);
// TODO: if waitfor failed need some error check
if
(
process
.
env
.
LOG_LEVEL
===
'debug'
)
{
await
horseman
.
screenshot
(
`
${
__basedir
}
/tmp/workflow/
${
this
.
params
.
website
}
/clues.png`
);
}
const
fetchByPage
=
async
()
=>
{
await
const
html
=
await
horseman
.
html
(
'#UpdatePanel1'
);
horseman
const
$
=
cheerio
.
load
(
html
);
.
userAgent
(
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0'
)
.
viewport
(
1920
,
1080
)
const
clues
=
[];
.
cookies
(
cookies
)
const
params
=
this
.
params
;
.
open
(
'http://app.Easypass.cn/lmsnew/OutmodedDefault.aspx'
)
$
(
'#dataTable #grvNewCarOpportunity tr'
).
not
(
'.th'
).
each
(
function
(
i
,
elem
)
{
.
waitForSelector
(
'#UpdatePanel1'
)
const
clue
=
{};
.
waitForSelector
(
'#pager1'
)
// 主体信息样本:赵永亮[河南新乡],电话15249705814,订购大迈X5升级版 1.5T 手动 精英型2017款
.
type
(
'input[id="txtBeginTime"]'
,
txtBeginTime
)
const
ptitleStr
=
(
$
(
this
).
find
(
'.msg p'
).
attr
(
'title'
)
||
''
).
trim
();
.
click
(
'input[id="btnSearch"]'
)
const
ptitlePieces
=
ptitleStr
.
split
(
','
)
||
[];
.
wait
(
1000
);
const
customerNameAreaStr
=
(
ptitlePieces
[
0
]
||
''
).
trim
();
// TODO: if waitfor failed need some error check
const
nameAreaMatch
=
customerNameAreaStr
.
match
(
/
(
.*
?)\[(
.*
?)\]
/
);
if
(
process
.
env
.
LOG_LEVEL
===
'debug'
)
{
clue
.
customerName
=
(
nameAreaMatch
[
1
]
||
''
).
trim
();
await
horseman
.
screenshot
(
`
${
__basedir
}
/tmp/workflow/
${
this
.
params
.
website
}
/clues.png`
);
clue
.
licenseArea
=
(
nameAreaMatch
[
2
]
||
''
).
replace
(
/
\s
+/g
,
''
);
}
clue
.
customerArea
=
clue
.
licenseArea
;
clue
.
customerPhone
=
(
ptitlePieces
[
1
]
||
''
).
replace
(
'电话'
,
''
).
trim
();
const
fetchByPage
=
async
()
=>
{
clue
.
intentionDes
=
(
ptitlePieces
[
2
]
||
''
).
replace
(
'订购'
,
''
).
trim
();
const
html
=
await
horseman
.
html
(
'#UpdatePanel1'
);
const
$
=
cheerio
.
load
(
html
);
// 提交时间样本:提交时间:2017-08-10 08:31
const
customerCreatedAtStr
=
$
(
this
).
find
(
'.msg p a span:contains(提交时间)'
).
text
()
||
''
;
const
clues
=
[];
clue
.
createdAt
=
customerCreatedAtStr
.
replace
(
'提交时间:'
,
''
).
trim
();
const
params
=
this
.
params
;
clue
.
salesmanName
=
$
(
this
).
find
(
'td span[title]'
).
text
().
trim
();
$
(
'#dataTable #grvNewCarOpportunity tr'
).
not
(
'.th'
).
each
(
function
(
i
,
elem
)
{
clues
.
push
(
clue
);
const
clue
=
{};
// 主体信息样本:赵永亮[河南新乡],电话15249705814,订购大迈X5升级版 1.5T 手动 精英型2017款
logger
.
debug
(
`accountID:
${
params
.
accountID
}
, 线索:
${
JSON
.
stringify
(
clue
)}
`
);
const
ptitleStr
=
(
$
(
this
).
find
(
'.msg p'
).
attr
(
'title'
)
||
''
).
trim
();
logger
.
debug
(
'==============================================================================='
);
const
ptitlePieces
=
ptitleStr
.
split
(
','
)
||
[];
const
customerNameAreaStr
=
(
ptitlePieces
[
0
]
||
''
).
trim
();
const
nameAreaMatch
=
customerNameAreaStr
.
match
(
/
(
.*
?)\[(
.*
?)\]
/
);
clue
.
customerName
=
(
nameAreaMatch
[
1
]
||
''
).
trim
();
clue
.
licenseArea
=
(
nameAreaMatch
[
2
]
||
''
).
replace
(
/
\s
+/g
,
''
);
clue
.
customerArea
=
clue
.
licenseArea
;
clue
.
customerPhone
=
(
ptitlePieces
[
1
]
||
''
).
replace
(
'电话'
,
''
).
trim
();
clue
.
intentionDes
=
(
ptitlePieces
[
2
]
||
''
).
replace
(
'订购'
,
''
).
trim
();
// 提交时间样本:提交时间:2017-08-10 08:31
const
customerCreatedAtStr
=
$
(
this
).
find
(
'.msg p a span:contains(提交时间)'
).
text
()
||
''
;
clue
.
createdAt
=
customerCreatedAtStr
.
replace
(
'提交时间:'
,
''
).
trim
();
clue
.
salesmanName
=
$
(
this
).
find
(
'td span[title]'
).
text
().
trim
();
clues
.
push
(
clue
);
logger
.
info
(
`accountID:
${
params
.
accountID
}
, 线索:
${
JSON
.
stringify
(
clue
)}
`
);
logger
.
info
(
'==============================================================================='
);
});
if
(
clues
.
length
>
0
)
{
await
DealerHelper
.
saveClues
({
clues
:
clues
,
dealerID
:
this
.
params
.
dealerID
,
website
:
this
.
params
.
website
,
accountID
:
this
.
params
.
accountID
,
});
});
}
else
{
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 时间段(
${
txtBeginTime
}
-
${
txtEndTime
}
)没有线索`
);
}
if
(
this
.
params
.
dealerID
)
{
// 判断是否最后一页有两种情况:1.只有一页时分页按钮不存在 2.末页按钮置灰
await
DealerHelper
.
saveClues
({
const
isLastPage
=
!
$
(
'#pager1'
).
length
||
$
(
'#pager1 a:contains(末页)'
).
prop
(
'disabled'
);
clues
:
clues
,
if
(
!
isLastPage
)
{
dealerID
:
this
.
params
.
dealerID
,
if
(
process
.
env
.
LOG_LEVEL
===
'debug'
)
{
website
:
this
.
params
.
website
,
await
horseman
.
screenshot
(
`
${
__basedir
}
/tmp/workflow/
${
this
.
params
.
website
}
/beforeNextPage.png`
);
accountID
:
this
.
params
.
accountID
,
});
}
}
await
horseman
.
click
(
'a.paginator:contains(下一页)'
)
.
wait
(
1000
)
.
waitForSelector
(
'#UpdatePanel1'
);
// 判断是否最后一页有两种情况:1.只有一页时分页按钮不存在 2.末页按钮置灰
if
(
process
.
env
.
LOG_LEVEL
===
'debug'
)
{
const
isLastPage
=
!
$
(
'#pager1'
).
length
||
$
(
'#pager1 a:contains(末页)'
).
prop
(
'disabled'
);
await
horseman
.
screenshot
(
`
${
__basedir
}
/tmp/workflow/
${
this
.
params
.
website
}
/nextPage.png`
);
if
(
!
isLastPage
)
{
if
(
process
.
env
.
LOG_LEVEL
===
'debug'
)
{
await
horseman
.
screenshot
(
`
${
__basedir
}
/tmp/workflow/
${
this
.
params
.
website
}
/beforeNextPage.png`
);
}
await
horseman
.
click
(
'a.paginator:contains(下一页)'
)
.
wait
(
1000
)
.
waitForSelector
(
'#UpdatePanel1'
);
if
(
process
.
env
.
LOG_LEVEL
===
'debug'
)
{
await
horseman
.
screenshot
(
`
${
__basedir
}
/tmp/workflow/
${
this
.
params
.
website
}
/nextPage.png`
);
}
let
randomSecs
=
randomInt
(
1
,
5
);
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 随机等待
${
randomSecs
}
秒`
);
await
Promise
.
delay
(
randomSecs
*
1000
).
then
(
async
function
()
{
await
fetchByPage
();
});
}
}
let
randomSecs
=
randomInt
(
1
,
5
);
logger
.
info
(
`accountID:
${
this
.
params
.
accountID
}
, 随机等待
${
randomSecs
}
秒`
);
await
Promise
.
delay
(
randomSecs
*
1000
).
then
(
async
function
()
{
await
fetchByPage
();
});
}
}
await
fetchByPage
();
await
horseman
.
close
();
}
else
{
logger
.
error
(
`accountID:
${
this
.
params
.
accountID
}
,
${
new
errors
.
AppError
(
'cookies读取失败'
)}
`
);
}
}
await
fetchByPage
();
await
horseman
.
close
();
await
this
.
updateLatestFetch
();
}
catch
(
e
)
{
}
catch
(
e
)
{
logger
.
error
(
e
);
logger
.
error
(
`accountID:
${
this
.
params
.
accountID
}
,
${
e
}
`
);
}
}
}
}
}
}
...
...
sql/history.sql
View file @
856ddd7e
...
@@ -16,6 +16,8 @@ CREATE TABLE `crm_dealer_thirdparty_account` (
...
@@ -16,6 +16,8 @@ CREATE TABLE `crm_dealer_thirdparty_account` (
`cookies`
text
COMMENT
'第三方账号cookies'
,
`cookies`
text
COMMENT
'第三方账号cookies'
,
`error`
text
COMMENT
'爬取第三方过程中产生的错误'
,
`error`
text
COMMENT
'爬取第三方过程中产生的错误'
,
`status`
tinyint
(
255
)
DEFAULT
'0'
COMMENT
'第三方账号状态: -1: 同步失败, 0: 未同步, 1: 同步成功'
,
`status`
tinyint
(
255
)
DEFAULT
'0'
COMMENT
'第三方账号状态: -1: 同步失败, 0: 未同步, 1: 同步成功'
,
`latestClueAt`
bigint
(
255
)
DEFAULT
NULL
COMMENT
'最新线索时间'
,
`latestFetchAt`
bigint
(
255
)
DEFAULT
NULL
COMMENT
'最近抓取时间'
,
`createdAt`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'第三方账号创建时间'
,
`createdAt`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'第三方账号创建时间'
,
`updatedAt`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'第三方账号更新时间'
,
`updatedAt`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'第三方账号更新时间'
,
PRIMARY
KEY
(
`id`
),
PRIMARY
KEY
(
`id`
),
...
...
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