Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
kouling-admin
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
刘松
kouling-admin
Commits
c23a91d3
Commit
c23a91d3
authored
Dec 04, 2017
by
刘松
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
723579fc
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
142 additions
and
16 deletions
+142
-16
app.js
app.js
+2
-0
app.bundle.js
app/built/app.bundle.js
+0
-0
schedule.jsx
app/jsx/setting/schedule.jsx
+4
-4
taopage.jsx
app/jsx/setting/taopage.jsx
+2
-2
tbk.jsx
app/jsx/setting/tbk.jsx
+1
-1
dashboard.jsx
app/jsx/statistics/dashboard.jsx
+3
-2
config.default.js
config/config.default.js
+1
-0
tao-data.js
db/mongo/tao-data.js
+25
-0
tao-schedule.js
db/mongo/tao-schedule.js
+1
-1
controller.js
lib/controller.js
+20
-5
cron.js
lib/cron.js
+3
-1
cron_gather.js
lib/cron_gather.js
+80
-0
No files found.
app.js
View file @
c23a91d3
...
@@ -13,6 +13,7 @@ const session = require('cookie-session');
...
@@ -13,6 +13,7 @@ const session = require('cookie-session');
const
mongoose
=
require
(
'mongoose'
);
const
mongoose
=
require
(
'mongoose'
);
const
sessions
=
require
(
'./db/mongo/session'
);
const
sessions
=
require
(
'./db/mongo/session'
);
const
cron
=
require
(
'./lib/cron'
);
const
cron
=
require
(
'./lib/cron'
);
const
cron_gather
=
require
(
'./lib/cron_gather'
);
const
options
=
{
const
options
=
{
useMongoClient
:
true
useMongoClient
:
true
...
@@ -52,3 +53,4 @@ app.listen(config.port);
...
@@ -52,3 +53,4 @@ app.listen(config.port);
console
.
log
(
'server started on port '
+
config
.
port
);
console
.
log
(
'server started on port '
+
config
.
port
);
cron
.
start
();
cron
.
start
();
//cron_gather.start();
app/built/app.bundle.js
View file @
c23a91d3
This diff is collapsed.
Click to expand it.
app/jsx/setting/schedule.jsx
View file @
c23a91d3
...
@@ -13,7 +13,7 @@ class Schedule extends React.Component{
...
@@ -13,7 +13,7 @@ class Schedule extends React.Component{
constructor
(
props
){
constructor
(
props
){
super
(
props
);
super
(
props
);
console
.
dir
(
this
.
props
);
console
.
dir
(
this
.
props
);
this
.
state
=
{
schedules
:[],
status
:
'pending'
,
pagination
:{
current
:
1
,
pageSize
:
10
,
total
:
1
00
},
modalVisible
:
false
,
username
:
'channel'
};
this
.
state
=
{
schedules
:[],
status
:
'pending'
,
pagination
:{
current
:
1
,
pageSize
:
10
,
total
:
1
},
modalVisible
:
false
,
username
:
'channel'
};
}
}
componentDidMount
(){
componentDidMount
(){
let
pagination
=
this
.
state
.
pagination
;
let
pagination
=
this
.
state
.
pagination
;
...
@@ -31,7 +31,7 @@ class Schedule extends React.Component{
...
@@ -31,7 +31,7 @@ class Schedule extends React.Component{
console
.
dir
(
pagination
);
console
.
dir
(
pagination
);
this
.
setState
({
status
:
'pending'
})
this
.
setState
({
status
:
'pending'
})
api
(
'GET'
,
'schedules?'
+
'skip='
+
(
pagination
.
current
-
1
)
+
'&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
api
(
'GET'
,
'schedules?'
+
'skip='
+
(
pagination
.
current
-
1
)
+
'&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
this
.
setState
({
schedules
:
res
.
result
,
status
:
'ready'
})
this
.
setState
({
schedules
:
res
.
result
,
status
:
'ready'
,
pagination
:{
current
:
res
.
pagination
.
skip
,
pageSize
:
res
.
pagination
.
limit
,
total
:
res
.
pagination
.
total
}
})
console
.
dir
(
res
.
result
);
console
.
dir
(
res
.
result
);
});
});
}
}
...
@@ -124,10 +124,10 @@ class Schedule extends React.Component{
...
@@ -124,10 +124,10 @@ class Schedule extends React.Component{
});
});
data
.
push
({
data
.
push
({
key
:
i
,
key
:
i
,
id
:
schedules
[
i
].
_id
,
id
:
(
schedules
[
i
].
qd
&&
schedules
[
i
].
qd
[
'_id'
])
||
'--'
,
names
:
names
||
'--'
,
names
:
names
||
'--'
,
status
:
schedules
[
i
].
status
==
'use'
?
'进行中'
:
'已暂停'
,
status
:
schedules
[
i
].
status
==
'use'
?
'进行中'
:
'已暂停'
,
qd
:
schedules
[
i
].
qd
&&
schedules
[
i
].
qd
[
'user'
]
||
'--'
,
qd
:
(
schedules
[
i
].
qd
&&
schedules
[
i
].
qd
[
'user'
])
||
'--'
,
times
:
schedules
[
i
].
times
,
times
:
schedules
[
i
].
times
,
create
:
schedules
[
i
].
createdAt
create
:
schedules
[
i
].
createdAt
});
});
...
...
app/jsx/setting/taopage.jsx
View file @
c23a91d3
...
@@ -13,7 +13,7 @@ class Agent extends React.Component{
...
@@ -13,7 +13,7 @@ class Agent extends React.Component{
constructor
(
props
){
constructor
(
props
){
super
(
props
);
super
(
props
);
console
.
dir
(
this
.
props
);
console
.
dir
(
this
.
props
);
this
.
state
=
{
links
:[],
status
:
'pending'
,
pagination
:{
current
:
1
,
pageSize
:
10
,
total
:
1
00
},
modalVisible
:
false
,
username
:
'channel'
};
this
.
state
=
{
links
:[],
status
:
'pending'
,
pagination
:{
current
:
1
,
pageSize
:
10
,
total
:
1
},
modalVisible
:
false
,
username
:
'channel'
};
}
}
componentDidMount
(){
componentDidMount
(){
let
pagination
=
this
.
state
.
pagination
;
let
pagination
=
this
.
state
.
pagination
;
...
@@ -31,7 +31,7 @@ class Agent extends React.Component{
...
@@ -31,7 +31,7 @@ class Agent extends React.Component{
console
.
dir
(
pagination
);
console
.
dir
(
pagination
);
this
.
setState
({
status
:
'pending'
})
this
.
setState
({
status
:
'pending'
})
api
(
'GET'
,
'links?'
+
'skip='
+
(
pagination
.
current
-
1
)
+
'&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
api
(
'GET'
,
'links?'
+
'skip='
+
(
pagination
.
current
-
1
)
+
'&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
this
.
setState
({
links
:
res
.
result
,
status
:
'ready'
})
this
.
setState
({
links
:
res
.
result
,
status
:
'ready'
,
pagination
:{
current
:
res
.
pagination
.
skip
,
pageSize
:
res
.
pagination
.
limit
,
total
:
res
.
pagination
.
total
}
})
console
.
dir
(
res
.
result
);
console
.
dir
(
res
.
result
);
});
});
}
}
...
...
app/jsx/setting/tbk.jsx
View file @
c23a91d3
...
@@ -30,7 +30,7 @@ class Tbkls extends React.Component{
...
@@ -30,7 +30,7 @@ class Tbkls extends React.Component{
console
.
dir
(
pagination
);
console
.
dir
(
pagination
);
this
.
setState
({
status
:
'pending'
})
this
.
setState
({
status
:
'pending'
})
api
(
'GET'
,
'tbkls?'
+
'skip='
+
(
pagination
.
current
-
1
)
+
'&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
api
(
'GET'
,
'tbkls?'
+
'skip='
+
(
pagination
.
current
-
1
)
+
'&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
this
.
setState
({
tbkls
:
res
.
result
,
status
:
'ready'
})
this
.
setState
({
tbkls
:
res
.
result
,
status
:
'ready'
,
pagination
:{
current
:
res
.
pagination
.
skip
,
pageSize
:
res
.
pagination
.
limit
,
total
:
res
.
pagination
.
total
}
})
console
.
dir
(
res
.
result
);
console
.
dir
(
res
.
result
);
});
});
}
}
...
...
app/jsx/statistics/dashboard.jsx
View file @
c23a91d3
...
@@ -14,7 +14,7 @@ class DashBoard extends React.Component{
...
@@ -14,7 +14,7 @@ class DashBoard extends React.Component{
constructor
(
props
){
constructor
(
props
){
super
(
props
);
super
(
props
);
this
.
range
=
[
moment
().
subtract
(
6
,
'days'
).
format
(
'YYYYMMDD'
),
moment
().
format
(
'YYYYMMDD'
)];
this
.
range
=
[
moment
().
subtract
(
6
,
'days'
).
format
(
'YYYYMMDD'
),
moment
().
format
(
'YYYYMMDD'
)];
this
.
state
=
{
logs
:[],
status
:
'pending'
,
pagination
:{
current
:
1
,
pageSize
:
10
,
total
:
100
}
};
this
.
state
=
{
logs
:[],
status
:
'pending'
,
pagination
:{
current
:
1
,
pageSize
:
10
0
,
total
:
1
}
};
}
}
componentDidMount
(){
componentDidMount
(){
let
pagination
=
this
.
state
.
pagination
;
let
pagination
=
this
.
state
.
pagination
;
...
@@ -26,9 +26,10 @@ class DashBoard extends React.Component{
...
@@ -26,9 +26,10 @@ class DashBoard extends React.Component{
}
}
getlogs
(
pagination
){
getlogs
(
pagination
){
this
.
setState
({
status
:
'pending'
})
this
.
setState
({
status
:
'pending'
})
this
.
setState
({
status
:
'pending'
})
api
(
'GET'
,
'logs?'
+
'skip='
+
(
pagination
.
current
-
1
)
+
'&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
api
(
'GET'
,
'logs?'
+
'skip='
+
(
pagination
.
current
-
1
)
+
'&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
this
.
setState
({
tbkls
:
res
.
result
,
status
:
'ready'
})
this
.
setState
({
logs
:
res
.
result
,
status
:
'ready'
,
pagination
:{
current
:
res
.
pagination
.
skip
,
pageSize
:
res
.
pagination
.
limit
,
total
:
res
.
pagination
.
total
}
})
console
.
dir
(
res
.
result
);
console
.
dir
(
res
.
result
);
});
});
}
}
...
...
config/config.default.js
View file @
c23a91d3
module
.
exports
=
{
module
.
exports
=
{
host
:
'0.0.0.0'
,
host
:
'0.0.0.0'
,
port
:
process
.
env
.
PORT
?
process
.
env
.
PORT
:
9401
,
port
:
process
.
env
.
PORT
?
process
.
env
.
PORT
:
9401
,
//mongo:'mongodb://user:password@10.11.3.100:1302/taoarticle',
mongo
:
'mongodb://127.0.0.1:27017/taoarticle'
,
mongo
:
'mongodb://127.0.0.1:27017/taoarticle'
,
taobao
:
{
taobao
:
{
host
:
"http://gw.api.taobao.com/router/rest"
,
host
:
"http://gw.api.taobao.com/router/rest"
,
...
...
db/mongo/tao-data.js
0 → 100644
View file @
c23a91d3
const
mongoose
=
require
(
'mongoose'
);
const
{
ObjectId
}
=
mongoose
.
SchemaTypes
;
const
schema
=
mongoose
.
Schema
({
date
:
{
type
:
Date
,
required
:
true
},
schedule
:{
type
:
ObjectId
,
required
:
true
,
ref
:
'tao-schedule'
},
times
:{
type
:
Number
,
required
:
true
}
},
{
timestamps
:
true
});
schema
.
index
({
date
:
1
});
schema
.
index
({
schedule
:
1
});
schema
.
index
({
date
:
1
,
schedule
:
1
});
module
.
exports
=
mongoose
.
model
(
'tao-data'
,
schema
);
db/mongo/tao-schedule.js
View file @
c23a91d3
...
@@ -20,5 +20,5 @@ const schema = mongoose.Schema({
...
@@ -20,5 +20,5 @@ const schema = mongoose.Schema({
timestamps
:
true
timestamps
:
true
});
});
schema
.
index
({
info
:
1
});
schema
.
index
({
qd
:
1
});
module
.
exports
=
mongoose
.
model
(
'tao-schedule'
,
schema
);
module
.
exports
=
mongoose
.
model
(
'tao-schedule'
,
schema
);
lib/controller.js
View file @
c23a91d3
...
@@ -13,7 +13,6 @@ const not_full = 'params not full error';
...
@@ -13,7 +13,6 @@ const not_full = 'params not full error';
const
not_right
=
'params not right error'
;
const
not_right
=
'params not right error'
;
function
dateFormat
(
target
,
format
)
{
function
dateFormat
(
target
,
format
)
{
console
.
dir
(
target
.
getTime
());
return
moment
(
new
Date
(
target
.
getTime
()),
'x'
).
format
(
format
||
'YYYYMMDD HH:mm:ss'
);
return
moment
(
new
Date
(
target
.
getTime
()),
'x'
).
format
(
format
||
'YYYYMMDD HH:mm:ss'
);
};
};
...
@@ -64,16 +63,30 @@ exports.logs = async (req, res, next) => {
...
@@ -64,16 +63,30 @@ exports.logs = async (req, res, next) => {
const
condition
=
{
'$and'
:
[{
'createdAt'
:
{
'$gte'
:
moment
(
start
,
'YYYYMMDD'
).
startOf
(
'day'
).
toDate
()}},
{
'createdAt'
:
{
'$lt'
:
moment
(
end
,
'YYYYMMDD'
).
endOf
(
'day'
).
toDate
()}}]};
const
condition
=
{
'$and'
:
[{
'createdAt'
:
{
'$gte'
:
moment
(
start
,
'YYYYMMDD'
).
startOf
(
'day'
).
toDate
()}},
{
'createdAt'
:
{
'$lt'
:
moment
(
end
,
'YYYYMMDD'
).
endOf
(
'day'
).
toDate
()}}]};
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'updatedAt'
:
-
1
}}
=
req
.
query
;
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'updatedAt'
:
-
1
}}
=
req
.
query
;
let
options
=
{
limit
:
parseInt
(
limit
),
skip
:
parseInt
(
skip
)
*
limit
,
sort
};
let
options
=
{
limit
:
parseInt
(
limit
),
skip
:
parseInt
(
skip
)
*
limit
,
sort
};
console
.
dir
(
options
);
var
logs
=
await
Log
.
find
({},
null
,
options
).
populate
({
path
:
"schedule"
,
select
:
"links qd"
,
populate
:{
path
:
'qd'
,
select
:
'user'
}});
var
logs
=
await
Log
.
find
({},
null
,
options
).
populate
({
path
:
"schedule"
,
select
:
"links qd"
,
populate
:{
path
:
'qd'
,
select
:
'user'
}});
let
total
=
await
Log
.
count
({},
null
);
let
total
=
await
Log
.
count
({},
null
);
logs
=
logs
.
map
(
x
=>
{
var
d
=
x
.
toJSON
();
d
[
'updatedAt'
]
=
dateFormat
(
d
[
'updatedAt'
]);
return
d
;});
logs
=
logs
.
map
(
x
=>
{
var
d
=
x
.
toJSON
();
d
[
'updatedAt'
]
=
dateFormat
(
d
[
'updatedAt'
]);
return
d
;});
res
.
send
({
status
:
'ok'
,
result
:
logs
,
pagination
:{
total
:
total
,
skip
:
skip
,
limit
:
limit
}});
res
.
send
({
status
:
'ok'
,
result
:
logs
,
pagination
:{
total
:
total
,
skip
:
skip
,
limit
:
limit
}});
}
}
exports
.
getGatherData
=
async
(
req
,
res
,
next
)
=>
{
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'updatedAt'
:
-
1
}}
=
req
.
query
;
let
options
=
{
limit
:
parseInt
(
limit
),
skip
:
parseInt
(
skip
)
*
limit
,
sort
};
var
logs
=
await
Log
.
find
({},
null
,
options
).
populate
({
path
:
"schedule"
,
select
:
"links qd"
,
populate
:{
path
:
'qd'
,
select
:
'user'
}});
let
total
=
await
Log
.
count
({},
null
);
logs
=
logs
.
map
(
x
=>
{
var
d
=
x
.
toJSON
();
d
[
'updatedAt'
]
=
dateFormat
(
d
[
'updatedAt'
]);
return
d
;});
res
.
send
({
status
:
'ok'
,
result
:
logs
,
pagination
:{
total
:
total
,
skip
:
skip
,
limit
:
limit
}});
}
exports
.
getTbkls
=
async
(
req
,
res
,
next
)
=>
{
exports
.
getTbkls
=
async
(
req
,
res
,
next
)
=>
{
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'updatedAt'
:
-
1
}}
=
req
.
query
;
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'updatedAt'
:
-
1
}}
=
req
.
query
;
let
options
=
{
limit
:
parseInt
(
limit
),
skip
:
parseInt
(
skip
)
*
limit
,
sort
};
let
options
=
{
limit
:
parseInt
(
limit
),
skip
:
parseInt
(
skip
)
*
limit
,
sort
};
let
tbkls
=
await
Kouling
.
find
({},
null
,
options
).
populate
(
'link'
,
'title target'
);
let
tbkls
=
await
Kouling
.
find
({},
null
,
options
).
populate
(
'link'
,
'title target'
);
tbkls
=
tbkls
.
map
(
x
=>
{
var
d
=
x
.
toJSON
();
d
[
'createdAt'
]
=
dateFormat
(
d
[
'createdAt'
]);
return
d
;});
let
total
=
await
Kouling
.
count
({},
null
);
let
total
=
await
Kouling
.
count
({},
null
);
res
.
send
({
status
:
'ok'
,
result
:
tbkls
,
pagination
:{
total
:
total
,
skip
:
skip
,
limit
:
limit
}});
res
.
send
({
status
:
'ok'
,
result
:
tbkls
,
pagination
:{
total
:
total
,
skip
:
skip
,
limit
:
limit
}});
}
}
...
@@ -81,9 +94,10 @@ exports.getTbkls = async (req, res, next) => {
...
@@ -81,9 +94,10 @@ exports.getTbkls = async (req, res, next) => {
exports
.
getLinks
=
async
(
req
,
res
,
next
)
=>
{
exports
.
getLinks
=
async
(
req
,
res
,
next
)
=>
{
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'updatedAt'
:
-
1
}}
=
req
.
query
;
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'updatedAt'
:
-
1
}}
=
req
.
query
;
let
options
=
{
limit
:
parseInt
(
limit
),
skip
:
parseInt
(
skip
)
*
limit
,
sort
};
let
options
=
{
limit
:
parseInt
(
limit
),
skip
:
parseInt
(
skip
)
*
limit
,
sort
};
let
tbkls
=
await
Link
.
find
({},
null
,
options
).
populate
(
'qd'
,
'user role'
);
let
links
=
await
Link
.
find
({},
null
,
options
).
populate
(
'qd'
,
'user role'
);
links
=
links
.
map
(
x
=>
{
var
d
=
x
.
toJSON
();
d
[
'createdAt'
]
=
dateFormat
(
d
[
'createdAt'
]);
return
d
;})
let
total
=
await
Link
.
count
({},
null
);
let
total
=
await
Link
.
count
({},
null
);
res
.
send
({
status
:
'ok'
,
result
:
tbkl
s
,
pagination
:{
total
:
total
,
skip
:
skip
,
limit
:
limit
}});
res
.
send
({
status
:
'ok'
,
result
:
link
s
,
pagination
:{
total
:
total
,
skip
:
skip
,
limit
:
limit
}});
}
}
exports
.
createLink
=
async
(
req
,
res
,
next
)
=>
{
exports
.
createLink
=
async
(
req
,
res
,
next
)
=>
{
...
@@ -150,6 +164,7 @@ exports.createSchedule = async (req, res, next) => {
...
@@ -150,6 +164,7 @@ exports.createSchedule = async (req, res, next) => {
arr
.
forEach
(
async
item
=>
{
arr
.
forEach
(
async
item
=>
{
item
[
'link'
]
=
item
.
_id
;
item
[
'link'
]
=
item
.
_id
;
item
[
'schedule'
]
=
schedule
;
item
[
'schedule'
]
=
schedule
;
item
[
'qd'
]
=
item
.
qd
;
for
(
let
i
=
0
;
i
<
5
;
i
++
){
for
(
let
i
=
0
;
i
<
5
;
i
++
){
tkl_Tasks
.
push
(
createTbkl
(
item
));
tkl_Tasks
.
push
(
createTbkl
(
item
));
}
}
...
@@ -172,12 +187,12 @@ exports.createSchedule = async (req, res, next) => {
...
@@ -172,12 +187,12 @@ exports.createSchedule = async (req, res, next) => {
}
}
var
createTbkl
=
async
(
data
)
=>
{
var
createTbkl
=
async
(
data
)
=>
{
let
{
title
,
target
,
pic
}
=
data
;
let
{
title
,
target
,
pic
,
qd
}
=
data
;
return
new
Promise
(
async
(
r
,
d
)
=>
{
return
new
Promise
(
async
(
r
,
d
)
=>
{
try
{
try
{
let
tbklInfo
=
await
tao
.
createTbkl
(
title
,
target
,
pic
);
let
tbklInfo
=
await
tao
.
createTbkl
(
title
,
target
,
pic
);
let
model
=
tbklInfo
.
model
;
let
model
=
tbklInfo
.
model
;
let
_data
=
{
info
:
model
,
schedule
:
data
.
schedule
,
link
:
data
.
link
,
status
:
'use'
};
let
_data
=
{
info
:
model
,
schedule
:
data
.
schedule
,
link
:
data
.
link
,
creater
:
qd
,
status
:
'use'
};
tao
.
saveKouling
(
_data
,
function
(
e
,
result
){
tao
.
saveKouling
(
_data
,
function
(
e
,
result
){
if
(
e
)
d
(
e
);
if
(
e
)
d
(
e
);
else
r
(
result
);
else
r
(
result
);
...
...
lib/cron.js
View file @
c23a91d3
...
@@ -7,7 +7,7 @@ const tao = require('./tao');
...
@@ -7,7 +7,7 @@ const tao = require('./tao');
const
_
=
require
(
'lodash'
);
const
_
=
require
(
'lodash'
);
const
moment
=
require
(
'moment'
);
const
moment
=
require
(
'moment'
);
const
controller
=
require
(
'./controller'
);
const
controller
=
require
(
'./controller'
);
const
max
=
4
00000
;
const
max
=
1
00000
;
var
CronJob
=
cron
.
CronJob
;
var
CronJob
=
cron
.
CronJob
;
var
job
=
new
CronJob
({
var
job
=
new
CronJob
({
cronTime
:
'0 */2 * * * *'
,
cronTime
:
'0 */2 * * * *'
,
...
@@ -48,6 +48,7 @@ async function tbklTask () {
...
@@ -48,6 +48,7 @@ async function tbklTask () {
let
schedules
=
await
Schedule
.
find
({
status
:
'use'
}).
limit
(
500
);
let
schedules
=
await
Schedule
.
find
({
status
:
'use'
}).
limit
(
500
);
schedules
.
forEach
(
async
item
=>
{
schedules
.
forEach
(
async
item
=>
{
let
schedule
=
item
.
toJSON
().
_id
;
let
schedule
=
item
.
toJSON
().
_id
;
var
qd
=
item
.
toJSON
().
qd
;
// console.dir(schedule);
// console.dir(schedule);
// 查询计划内 超过20000 请求 淘口令
// 查询计划内 超过20000 请求 淘口令
//console.dir({times:{$gte:10},status:'use',schedule:schedule});
//console.dir({times:{$gte:10},status:'use',schedule:schedule});
...
@@ -66,6 +67,7 @@ async function tbklTask () {
...
@@ -66,6 +67,7 @@ async function tbklTask () {
schedule
:
item
.
schedule
,
schedule
:
item
.
schedule
,
link
:
item
.
link
,
link
:
item
.
link
,
status
:
'use'
,
status
:
'use'
,
creater
:
qd
,
pic
:
item
.
link
.
pic
pic
:
item
.
link
.
pic
}
}
tasks_new
.
push
(
controller
.
createTbkl
(
data
));
tasks_new
.
push
(
controller
.
createTbkl
(
data
));
...
...
lib/cron_gather.js
0 → 100644
View file @
c23a91d3
const
cron
=
require
(
'cron'
);
const
nodemailer
=
require
(
'nodemailer'
);
const
Schedule
=
require
(
'../db/mongo/tao-schedule'
);
const
Data
=
require
(
'../db/mongo/tao-data'
);
const
Log
=
require
(
'../db/mongo/tao-log'
);
const
_
=
require
(
'lodash'
);
const
moment
=
require
(
'moment'
);
const
controller
=
require
(
'./controller'
);
const
max
=
400000
;
var
CronJob
=
cron
.
CronJob
;
var
job
=
new
CronJob
({
cronTime
:
'00 26 15 * * 0-6'
,
onTick
:
function
()
{
tbklTask
();
},
start
:
false
,
});
async
function
sendMail
(
email
,
body
)
{
var
smtpTransport
=
nodemailer
.
createTransport
({
auth
:
{
user
:
"liusong@goyoo.com"
,
pass
:
"323609zhang"
},
host
:
'smtp.exmail.qq.com'
,
port
:
465
});
var
mailOptions
=
{
from
:
"liusong@goyoo.com"
,
to
:
email
,
//发给谁
subject
:
'淘口令后台定时任务错误'
,
//主题
text
:
body
};
smtpTransport
.
sendMail
(
mailOptions
,
function
(
err
,
response
)
{
if
(
!
err
)
{
console
.
log
(
'发送邮件成功'
);
}
else
{
console
.
log
(
'发送邮件失败,请重试'
);
}
});
}
async
function
tbklTask
()
{
console
.
log
(
'定时更新开始 =====> '
);
try
{
var
date
=
moment
().
add
(
-
1
,
'days'
).
format
(
'YYYYMMDD'
);
var
logDate
=
moment
().
add
(
-
1
,
'days'
).
toDate
();
var
list
=
await
Log
.
aggregate
([
{
$match
:{
"date"
:
date
}
},
{
$group
:{
_id
:
"$schedule"
,
sum
:{
$sum
:
"$times"
}
}
}
]);
var
tasks
=
[];
list
.
forEach
(
item
=>
{
var
data
=
new
Data
({
schedule
:
item
.
_id
,
date
:
logDate
,
times
:
item
.
sum
});
tasks
.
push
(
data
.
save
());
});
Promise
.
all
(
tasks
).
then
(
function
(
arr
){
console
.
log
(
'插入'
+
arr
.
length
+
'条数据'
);
});
}
catch
(
err
)
{
console
.
dir
(
err
);
console
.
dir
(
'更新异常 =====>'
);
let
mailList
=
'liusong@goyoo.com'
;
sendMail
(
mailList
,
err
.
toString
());
}
}
module
.
exports
.
start
=
function
()
{
job
.
start
();
};
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