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
707050df
Commit
707050df
authored
Dec 04, 2017
by
刘松
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
da77cd5a
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
202 additions
and
86 deletions
+202
-86
app.js
app.js
+2
-2
app.bundle.js
app/built/app.bundle.js
+0
-0
common.bundle.js
app/built/common.bundle.js
+0
-0
api.js
app/js/api.js
+2
-1
manageRoute.js
app/js/routes/manageRoute.js
+1
-1
main.jsx
app/jsx/main.jsx
+10
-3
schedule.jsx
app/jsx/setting/schedule.jsx
+36
-18
taopage.jsx
app/jsx/setting/taopage.jsx
+8
-4
tbk.jsx
app/jsx/setting/tbk.jsx
+8
-4
dashboard.jsx
app/jsx/statistics/dashboard.jsx
+10
-4
gather.jsx
app/jsx/statistics/gather.jsx
+31
-28
tao-data.js
db/mongo/tao-data.js
+5
-4
controller.js
lib/controller.js
+37
-8
cron_gather.js
lib/cron_gather.js
+27
-9
session.js
lib/session.js
+21
-0
index.js
routes/index.js
+4
-0
No files found.
app.js
View file @
707050df
...
...
@@ -52,5 +52,5 @@ app.use(routes);
app
.
listen
(
config
.
port
);
console
.
log
(
'server started on port '
+
config
.
port
);
//
cron.start();
//
cron_gather.start();
cron
.
start
();
cron_gather
.
start
();
app/built/app.bundle.js
View file @
707050df
This diff is collapsed.
Click to expand it.
app/built/common.bundle.js
View file @
707050df
This diff is collapsed.
Click to expand it.
app/js/api.js
View file @
707050df
...
...
@@ -17,7 +17,8 @@ const request = function(method,path,data) {
resolve
(
resp
);
},
error
:(
resp
)
=>
{
console
.
dir
(
'error resp'
,
JSON
.
stringfy
(
resp
));
console
.
dir
(
resp
);
//console.dir('error resp',JSON.stringfy(resp));
resolve
(
resp
);
}
...
...
app/js/routes/manageRoute.js
View file @
707050df
module
.
exports
=
{
path
:
'manage'
,
component
:
require
(
'../../jsx/main.jsx'
),
indexRoute
:{
component
:
require
(
'../../jsx/statistics/
dashboard
.jsx'
)
},
indexRoute
:{
component
:
require
(
'../../jsx/statistics/
gather
.jsx'
)
},
childRoutes
:[
{
path
:
'statistics'
,
...
...
app/jsx/main.jsx
View file @
707050df
const
React
=
require
(
'react'
);
const
connect
=
require
(
'react-redux'
).
connect
;
const
actions
=
require
(
'../js/actions'
);
const
api
=
require
(
'../js/api'
);
import
{
Menu
,
Icon
,
Button
,
Layout
,
Breadcrumb
}
from
'antd'
;
const
SubMenu
=
Menu
.
SubMenu
;
...
...
@@ -15,7 +16,7 @@ class Main extends React.Component{
super
(
props
);
this
.
map
=
[
'数据统计'
,
'数据统计'
,
'配置'
,
'淘口令'
,
'渠道管理'
]
this
.
state
=
{
current
:
'
0
'
,
current
:
'
1
'
,
openKeys
:
[],
theme
:
'dark'
,
username
:
null
...
...
@@ -24,6 +25,12 @@ class Main extends React.Component{
handleClick
(
e
){
//this.props.dispatch(actions.getMenu());
if
(
e
.
key
==
5
){
api
(
'GET'
,
'logout'
,
function
(
res
){
console
.
dir
(
res
);
});
}
else
location
.
href
=
mapLocations
[
e
.
key
];
}
...
...
@@ -56,13 +63,13 @@ class Main extends React.Component{
style=
{
{
lineHeight
:
'64px'
}
}
>
<
SubMenu
title=
{
<
span
>
数据统计
</
span
>
}
>
<
Menu
.
Item
key=
"0"
>
口令数据
</
Menu
.
Item
>
<
Menu
.
Item
key=
"1"
>
汇总数据
</
Menu
.
Item
>
<
Menu
.
Item
key=
"0"
>
口令数据
</
Menu
.
Item
>
</
SubMenu
>
<
Menu
.
Item
key=
"2"
>
推广页管理
</
Menu
.
Item
>
<
Menu
.
Item
key=
"3"
>
淘口令
</
Menu
.
Item
>
<
Menu
.
Item
key=
"4"
>
推广计划
</
Menu
.
Item
>
<
Menu
.
Item
key=
"5"
style
={{
float
:'
right
'}}
><
Icon
type=
"
user
"
/>
{
this
.
state
.
username
}
</
Menu
.
Item
>
<
Menu
.
Item
key=
"5"
style
={{
float
:'
right
'}}
><
Icon
type=
"
logout
"
/>
{
this
.
state
.
username
}
</
Menu
.
Item
>
</
Menu
>
</
Header
>
<
Content
style=
{
{
padding
:
'0 50px'
}
}
>
...
...
app/jsx/setting/schedule.jsx
View file @
707050df
...
...
@@ -4,7 +4,7 @@ const api = require('../../js/api');
import
json2xlsx
from
'../../js/json2xlsx'
;
import
{
Table
,
Icon
,
DatePicker
,
Alert
,
Row
,
Col
,
Spin
,
Button
,
Modal
,
Form
,
Input
}
from
'antd'
;
import
{
Table
,
Icon
,
DatePicker
,
Alert
,
Row
,
Col
,
Spin
,
Button
,
Modal
,
Form
,
Input
,
Switch
}
from
'antd'
;
const
{
RangePicker
}
=
DatePicker
;
const
FormItem
=
Form
.
Item
;
...
...
@@ -17,8 +17,8 @@ class Schedule extends React.Component{
}
componentDidMount
(){
let
pagination
=
this
.
state
.
pagination
;
if
(
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
]
&&
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]
==
'admin'
){
this
.
setState
({
username
:
'admin'
});
if
(
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
]
&&
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]){
this
.
setState
({
username
:
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]
});
}
//let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')};
api
(
'GET'
,
'schedules?'
+
'skip=0&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
...
...
@@ -63,6 +63,12 @@ class Schedule extends React.Component{
}
});
}
checkUpdate
(
schedule
){
console
.
dir
(
schedule
);
var
schedules
=
this
.
state
.
schedules
;
schedules
[
schedule
[
'key'
]][
'status'
]
=
(
schedule
[
'status'
]
==
'use'
?
'disable'
:
'use'
);
this
.
setState
({
schedules
:
schedules
});
}
exportData
(){
//json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'});
...
...
@@ -72,23 +78,23 @@ class Schedule extends React.Component{
const
{
getFieldDecorator
,
getFieldsError
,
getFieldError
,
isFieldTouched
}
=
this
.
props
.
form
;
const
columns
=
[
{
title
:
'
分发
ID'
,
title
:
'
计划
ID'
,
dataIndex
:
'id'
,
key
:
'id'
,
width
:
100
,
render
:
text
=>
<
span
href=
"#"
>
{
text
}
</
span
>,
},
{
title
:
'
推广页名称
'
,
dataIndex
:
'
names
'
,
key
:
'
names
'
,
title
:
'
分发ID/渠道
'
,
dataIndex
:
'
qd
'
,
key
:
'
qd
'
,
width
:
100
,
render
:
text
=>
<
span
href=
"#"
>
{
text
}
</
span
>,
},
{
title
:
'推广
渠道
'
,
dataIndex
:
'
qd
'
,
key
:
'
qd
'
,
title
:
'推广
页名称
'
,
dataIndex
:
'
names
'
,
key
:
'
names
'
,
width
:
100
,
render
:
text
=>
<
span
href=
"#"
>
{
text
}
</
span
>,
},
...
...
@@ -96,21 +102,28 @@ class Schedule extends React.Component{
title
:
'状态'
,
dataIndex
:
'status'
,
key
:
'status'
,
width
:
100
,
width
:
30
,
render
:
(
text
,
schedule
)
=>
<
Switch
checked=
{
text
==
'use'
?
true
:
false
}
onChange=
{
this
.
checkUpdate
.
bind
(
this
,
schedule
)
}
/>,
},
{
title
:
'可用淘口令'
,
dataIndex
:
'tkls'
,
key
:
'tkls'
,
width
:
10
,
render
:
text
=>
<
span
href=
"#"
>
{
text
}
</
span
>,
},
{
title
:
'推广次数'
,
dataIndex
:
'times'
,
key
:
'times'
,
width
:
10
0
,
width
:
5
0
,
render
:
text
=>
<
span
href=
"#"
>
{
text
}
</
span
>,
},
{
title
:
'创建日期'
,
dataIndex
:
'create'
,
key
:
'create'
,
width
:
10
0
,
width
:
7
0
,
render
:
text
=>
<
span
href=
"#"
>
{
text
}
</
span
>,
}
];
...
...
@@ -124,16 +137,17 @@ class Schedule extends React.Component{
});
data
.
push
({
key
:
i
,
id
:(
schedules
[
i
].
qd
&&
schedules
[
i
].
qd
[
'_id'
]
)
||
'--'
,
id
:(
schedules
[
i
].
_id
&&
schedules
[
i
].
_id
)
||
'--'
,
names
:
names
||
'--'
,
status
:
schedules
[
i
].
status
==
'use'
?
'进行中'
:
'已暂停'
,
qd
:(
schedules
[
i
].
qd
&&
schedules
[
i
].
qd
[
'user'
])
||
'--'
,
status
:
schedules
[
i
].
status
,
qd
:((
schedules
[
i
].
qd
&&
schedules
[
i
].
qd
[
'user'
])
||
'--'
)
+
' /'
+
((
schedules
[
i
].
qd
&&
schedules
[
i
].
qd
[
'_id'
])
||
'--'
),
tkls
:(
schedules
[
i
].
count
),
times
:
schedules
[
i
].
times
,
create
:
schedules
[
i
].
createdAt
});
}
return
(
<
div
>
this
.
state
.
username
==
'admin'
?
<
div
>
<
Button
type=
"primary"
icon=
"export"
onClick=
{
this
.
createSchedule
.
bind
(
this
)
}
style=
{
{
margin
:
'10px 0px'
}
}
>
创建
</
Button
>
...
...
@@ -176,7 +190,11 @@ class Schedule extends React.Component{
</
FormItem
>
</
Form
>
</
Modal
>
</
div
>
</
div
>:
<
Alert
message=
"提示"
description=
"您没有权限"
type=
"warning"
/>
)
}
}
...
...
app/jsx/setting/taopage.jsx
View file @
707050df
...
...
@@ -17,8 +17,8 @@ class Agent extends React.Component{
}
componentDidMount
(){
let
pagination
=
this
.
state
.
pagination
;
if
(
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
]
&&
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]
==
'admin'
){
this
.
setState
({
username
:
'admin'
});
if
(
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
]
&&
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]){
this
.
setState
({
username
:
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]
});
}
//let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')};
api
(
'GET'
,
'links?'
+
'skip=0&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
...
...
@@ -150,7 +150,7 @@ class Agent extends React.Component{
});
}
return
(
<
div
>
this
.
state
.
username
==
'admin'
?
<
div
>
<
Button
type=
"primary"
icon=
"export"
onClick=
{
this
.
createLink
.
bind
(
this
)
}
style=
{
{
margin
:
'10px 0px'
}
}
>
创建
</
Button
>
...
...
@@ -200,7 +200,11 @@ class Agent extends React.Component{
</
FormItem
>
</
Form
>
</
Modal
>
</
div
>
</
div
>
:
<
Alert
message=
"提示"
description=
"您没有权限"
type=
"warning"
/>
)
}
}
...
...
app/jsx/setting/tbk.jsx
View file @
707050df
...
...
@@ -16,8 +16,8 @@ class Tbkls extends React.Component{
}
componentDidMount
(){
let
pagination
=
this
.
state
.
pagination
;
if
(
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
]
&&
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]
==
'admin'
){
this
.
setState
({
username
:
'admin'
});
if
(
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
]
&&
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]){
this
.
setState
({
username
:
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]
});
}
//let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')};
api
(
'GET'
,
'tbkls?'
+
'skip=0&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
...
...
@@ -104,7 +104,7 @@ class Tbkls extends React.Component{
});
}
return
(
<
div
>
this
.
state
.
username
==
'admin'
?
<
div
>
<
Alert
message=
"提示"
description=
"淘口令油后台任务自动生成"
...
...
@@ -113,7 +113,11 @@ class Tbkls extends React.Component{
<
Spin
spinning=
{
this
.
state
.
status
==
'pending'
}
>
<
Table
columns=
{
columns
}
dataSource
=
{
data
}
size=
"middle"
pagination=
{
this
.
state
.
pagination
}
onChange
=
{
this
.
onChange
.
bind
(
this
)}
bordered
/>
</
Spin
>
</
div
>
</
div
>:
<
Alert
message=
"提示"
description=
"您没有权限"
type=
"warning"
/>
)
}
}
...
...
app/jsx/statistics/dashboard.jsx
View file @
707050df
...
...
@@ -17,6 +17,9 @@ class DashBoard extends React.Component{
this
.
state
=
{
logs
:[],
status
:
'pending'
,
pagination
:{
current
:
1
,
pageSize
:
100
,
total
:
1
}
};
}
componentDidMount
(){
if
(
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
]
&&
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]){
this
.
setState
({
username
:
document
.
cookie
.
match
(
'username=[a-zA-Z0-9]+'
)[
0
].
split
(
'='
)[
1
]});
}
let
pagination
=
this
.
state
.
pagination
;
let
data
=
{
start
:
moment
().
add
(
-
6
,
'days'
).
format
(
'YYYYMMDD'
),
end
:
moment
().
format
(
'YYYYMMDD'
)};
api
(
'GET'
,
'logs?'
+
'skip=0&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
...
...
@@ -26,8 +29,7 @@ class DashBoard extends React.Component{
}
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
)
=>
{
this
.
setState
({
logs
:
res
.
result
,
status
:
'ready'
,
pagination
:{
current
:
res
.
pagination
.
skip
,
pageSize
:
res
.
pagination
.
limit
,
total
:
res
.
pagination
.
total
}})
console
.
dir
(
res
.
result
);
...
...
@@ -123,7 +125,7 @@ class DashBoard extends React.Component{
}
return
(
<
div
>
this
.
state
.
username
==
'admin'
?
<
div
>
<
RangePicker
onChange=
{
this
.
onChangeRange
.
bind
(
this
)
}
value=
{
ranges
}
format=
{
'YYYYMMDD'
}
style=
{
{
margin
:
'10px 0px'
}
}
/>
<
Button
type=
"primary"
icon=
"export"
onClick=
{
this
.
exportData
.
bind
(
this
)
}
style=
{
{
float
:
'right'
,
margin
:
'10px 0px'
}
}
>
导出数据
...
...
@@ -131,7 +133,11 @@ class DashBoard extends React.Component{
<
Spin
spinning=
{
this
.
state
.
status
==
'pending'
}
>
<
Table
columns=
{
columns
}
dataSource
=
{
data
}
size=
"middle"
pagination=
{
this
.
state
.
pagination
}
onChange
=
{
this
.
onChange
.
bind
(
this
)}
bordered
/>
</
Spin
>
</
div
>
</
div
>:
<
Alert
message=
"提示"
description=
"您没有权限"
type=
"warning"
/>
)
}
}
...
...
app/jsx/statistics/gather.jsx
View file @
707050df
...
...
@@ -14,12 +14,22 @@ class Gather extends React.Component{
constructor
(
props
){
super
(
props
);
this
.
range
=
[
moment
().
subtract
(
6
,
'days'
).
format
(
'YYYYMMDD'
),
moment
().
format
(
'YYYYMMDD'
)];
this
.
state
=
{
logs
:[],
status
:
'pending
'
};
this
.
state
=
{
qdgathers
:[],
status
:
'pending'
,
pagination
:{
current
:
1
,
pageSize
:
10
,
total
:
100
},
username
:
'channel
'
};
}
componentDidMount
(){
let
data
=
{
start
:
moment
().
add
(
-
6
,
'days'
).
format
(
'YYYYMMDD'
),
end
:
moment
().
format
(
'YYYYMMDD'
)};
api
(
'GET'
,
'logs'
).
then
((
res
)
=>
{
this
.
setState
({
logs
:
res
.
result
,
status
:
'ready'
})
api
(
'GET'
,
'gathers/qd'
).
then
((
res
)
=>
{
this
.
setState
({
qdgathers
:
res
.
result
,
status
:
'ready'
})
console
.
dir
(
res
.
result
);
});
}
getQdGatherss
(
pagination
){
console
.
dir
(
pagination
);
this
.
setState
({
status
:
'pending'
})
api
(
'GET'
,
'gathers/qd?'
+
'skip='
+
(
pagination
.
current
-
1
)
+
'&limit='
+
pagination
.
pageSize
).
then
((
res
)
=>
{
this
.
setState
({
qdgathers
:
res
.
result
,
status
:
'ready'
,
pagination
:{
current
:
res
.
pagination
.
skip
,
pageSize
:
res
.
pagination
.
limit
,
total
:
res
.
pagination
.
total
}})
console
.
dir
(
res
.
result
);
});
}
...
...
@@ -44,12 +54,13 @@ class Gather extends React.Component{
render
:
text
=>
<
a
href=
"#"
>
{
text
}
</
a
>,
},
{
title
:
'
计划
ID'
,
dataIndex
:
'
schedule
'
,
key
:
'
schedule
'
,
title
:
'
渠道/分发
ID'
,
dataIndex
:
'
user
'
,
key
:
'
user
'
,
width
:
100
,
render
:
text
=>
<
a
href=
"#"
>
{
text
}
</
a
>,
},{
},
{
title
:
'请求数'
,
dataIndex
:
'times'
,
key
:
'times'
,
...
...
@@ -57,23 +68,16 @@ class Gather extends React.Component{
render
:
text
=>
<
a
href=
"#"
>
{
text
}
</
a
>,
},
{
title
:
'
总口令
'
,
dataIndex
:
'
total
'
,
key
:
'
total
'
,
title
:
'
导出数
'
,
dataIndex
:
'
dc_times
'
,
key
:
'
dc_times
'
,
width
:
100
,
render
:
text
=>
<
a
href=
"#"
>
{
text
}
</
a
>,
},
{
title
:
'可用口令'
,
dataIndex
:
'available'
,
key
:
'available'
,
width
:
100
,
render
:
text
=>
<
a
href=
"#"
>
{
text
}
</
a
>,
},
{
title
:
'渠道'
,
dataIndex
:
'user'
,
key
:
'user'
,
title
:
'导出率'
,
dataIndex
:
'rate'
,
key
:
'rate'
,
width
:
100
,
render
:
text
=>
<
a
href=
"#"
>
{
text
}
</
a
>,
}
...
...
@@ -87,16 +91,15 @@ class Gather extends React.Component{
ranges
.
push
(
moment
(
end
,
'YYYYMMDD'
));
let
data
=
[];
let
count
=
0
;
let
logs
=
this
.
state
.
log
s
;
for
(
let
i
=
0
;
i
<
log
s
.
length
;
i
++
){
let
qdgathers
=
this
.
state
.
qdgather
s
;
for
(
let
i
=
0
;
i
<
qdgather
s
.
length
;
i
++
){
data
.
push
({
key
:
i
,
date
:
logs
[
i
].
date
,
info
:
logs
[
i
].
key
,
times
:
logs
[
i
].
times
,
status
:
logs
[
i
].
status
==
'disable'
?
'已归档'
:
'--'
,
qd
:(
logs
[
i
].
schedule
)
||
'--'
,
update
:
logs
[
i
].
updatedAt
date
:
qdgathers
[
i
].
date
,
user
:(
qdgathers
[
i
].
qd
&&
qdgathers
[
i
].
qd
.
user
)
+
'/ '
+
(
qdgathers
[
i
].
qd
&&
qdgathers
[
i
].
qd
.
_id
),
times
:
qdgathers
[
i
].
times
,
dc_times
:
qdgathers
[
i
].
status
==
'disable'
?
'已归档'
:
'--'
,
rate
:(
qdgathers
[
i
].
schedule
)
||
'--'
});
}
...
...
db/mongo/tao-data.js
View file @
707050df
...
...
@@ -6,11 +6,12 @@ const schema = mongoose.Schema({
type
:
Date
,
required
:
true
},
schedule
:{
qd
:{
type
:
ObjectId
,
required
:
true
,
ref
:
'tao-
schedule'
ref
:
'tao-
agent'
},
schedules
:[],
times
:{
type
:
Number
,
required
:
true
...
...
@@ -20,6 +21,6 @@ const schema = mongoose.Schema({
});
schema
.
index
({
date
:
1
});
schema
.
index
({
schedule
:
1
});
schema
.
index
({
date
:
1
,
schedule
:
1
});
schema
.
index
({
qd
:
1
});
schema
.
index
({
date
:
1
,
qd
:
1
});
module
.
exports
=
mongoose
.
model
(
'tao-data'
,
schema
);
lib/controller.js
View file @
707050df
...
...
@@ -8,9 +8,11 @@ const Link = require('../db/mongo/tao-link');
const
Session
=
require
(
'../db/mongo/session'
);
const
Agent
=
require
(
'../db/mongo/tao-agent'
);
const
Schedule
=
require
(
'../db/mongo/tao-schedule'
);
const
GatherData
=
require
(
'../db/mongo/tao-data'
);
const
url
=
require
(
'url'
);
const
not_full
=
'params not full error'
;
const
not_right
=
'params not right error'
;
const
not_login
=
'please login first'
;
function
dateFormat
(
target
,
format
)
{
return
moment
(
new
Date
(
target
.
getTime
()),
'x'
).
format
(
format
||
'YYYYMMDD HH:mm:ss'
);
...
...
@@ -63,7 +65,6 @@ 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
()}}]};
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'updatedAt'
:
-
1
}}
=
req
.
query
;
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'
}});
let
total
=
await
Log
.
count
({},
null
);
logs
=
logs
.
map
(
x
=>
{
var
d
=
x
.
toJSON
();
d
[
'updatedAt'
]
=
dateFormat
(
d
[
'updatedAt'
]);
return
d
;});
...
...
@@ -71,14 +72,27 @@ exports.logs = async (req, res, next) => {
}
exports
.
getGatherData
=
async
(
req
,
res
,
next
)
=>
{
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'updatedAt'
:
-
1
}}
=
req
.
query
;
exports
.
getQdGatherData
=
async
(
req
,
res
,
next
)
=>
{
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'date'
:
-
1
},
qd
}
=
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
}});
let
sess
=
req
.
cookies
[
'sess'
];
if
(
sess
){
var
session_body
=
await
Session
.
findById
(
sess
);
if
(
session_body
){
var
user
=
session_body
.
toJSON
().
user
;
let
qs
=
(
user
==
'5a1e81f8c86fa7aa4b51b18b'
?
{}
:
{
qd
:
user
});
var
gatherDatas
=
await
GatherData
.
find
(
qs
,
null
,
options
).
populate
(
'qd'
,
'user'
);
let
total
=
await
GatherData
.
count
({},
null
);
gatherDatas
=
gatherDatas
.
map
(
x
=>
{
var
d
=
x
.
toJSON
();
d
[
'date'
]
=
dateFormat
(
d
[
'date'
],
'YYYYMMDD'
);
return
d
;});
res
.
send
({
status
:
'ok'
,
result
:
gatherDatas
,
pagination
:{
total
:
total
,
skip
:
skip
,
limit
:
limit
}});
}
else
{
res
.
status
(
400
).
send
(
not_login
);
}
}
else
{
res
.
status
(
400
).
send
(
not_login
);
}
}
...
...
@@ -135,6 +149,21 @@ exports.getSchedules = async (req, res, next) => {
let
{
limit
=
100
,
skip
=
0
,
sort
=
{
'updatedAt'
:
-
1
}}
=
req
.
query
;
let
options
=
{
limit
:
parseInt
(
limit
),
skip
:
parseInt
(
skip
)
*
limit
,
sort
};
let
schedules
=
await
Schedule
.
find
({},
null
,
options
).
populate
(
'links'
,
'name title target'
).
populate
(
'qd'
,
'user'
);
var
tasks
=
[];
schedules
.
forEach
(
(
item
)
=>
{
tasks
.
push
(
Kouling
.
count
({
schedule
:
item
.
_id
,
status
:
'use'
}));
});
Promise
.
all
(
tasks
).
then
(
async
function
(
arr
){
let
total
=
await
Schedule
.
count
({},
null
);
schedules
=
schedules
.
map
(
(
x
,
i
)
=>
{
var
a
=
x
.
toJSON
();
a
[
'createdAt'
]
=
dateFormat
(
a
[
'createdAt'
]);
a
[
'count'
]
=
arr
[
i
];
return
a
});
res
.
send
({
status
:
'ok'
,
result
:
schedules
,
pagination
:{
total
:
total
,
skip
:
skip
,
limit
:
limit
}});
});
}
exports
.
updateSchedule
=
async
(
req
,
res
,
next
)
=>
{
let
{
schedule
,
status
}
=
req
.
body
;
//let schedules = await Schedule.f
let
total
=
await
Schedule
.
count
({},
null
);
res
.
send
({
status
:
'ok'
,
result
:
schedules
,
pagination
:{
total
:
total
,
skip
:
skip
,
limit
:
limit
}});
}
...
...
lib/cron_gather.js
View file @
707050df
...
...
@@ -6,10 +6,9 @@ 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'
,
cronTime
:
'00
01 00
* * 0-6'
,
onTick
:
function
()
{
tbklTask
();
},
...
...
@@ -42,8 +41,8 @@ async function sendMail(email,body) {
async
function
tbklTask
()
{
console
.
log
(
'定时更新开始 =====> '
);
try
{
var
date
=
moment
().
add
(
-
1
,
'days'
).
format
(
'YYYYMMDD'
);
var
logDate
=
moment
().
add
(
-
1
,
'days'
).
toDate
();
var
date
=
moment
().
add
(
-
3
,
'days'
).
format
(
'YYYYMMDD'
);
var
logDate
=
moment
().
add
(
-
3
,
'days'
).
toDate
();
var
list
=
await
Log
.
aggregate
([
{
$match
:{
...
...
@@ -57,15 +56,34 @@ async function tbklTask () {
}
}
]);
var
qd2schedule
=
{};
var
sum2schedule
=
{};
var
_tasks
=
[]
list
.
forEach
(
async
item
=>
{
//schedule = schedule.toJSON();
var
schedule
=
_tasks
.
push
(
Schedule
.
findById
(
item
.
_id
));
sum2schedule
[
item
.
_id
]
=
item
.
sum
;
});
Promise
.
all
(
_tasks
).
then
(
function
(
arr
){
arr
.
forEach
(
function
(
item
){
var
schedule
=
item
.
toJSON
();
if
(
qd2schedule
[
schedule
.
qd
]
&&
qd2schedule
[
schedule
.
qd
].
length
)
qd2schedule
[
schedule
.
qd
]
=
qd2schedule
[
schedule
.
qd
].
concat
({
schedule
:
item
.
_id
,
times
:
sum2schedule
[
schedule
.
_id
]})
else
qd2schedule
[
schedule
.
qd
]
=
[{
schedule
:
item
.
_id
,
times
:
sum2schedule
[
schedule
.
_id
]}];
});
var
tasks
=
[];
list
.
forEach
(
item
=>
{
var
data
=
new
Data
({
schedule
:
item
.
_id
,
date
:
logDate
,
times
:
item
.
sum
});
for
(
var
k
in
qd2schedule
){
var
qd
=
k
;
var
total
=
qd2schedule
[
k
].
reduce
(
function
(
a
,
b
){
return
a
.
times
+
b
.
times
},{
times
:
0
});
var
data
=
new
Data
({
qd
:
qd
,
schedules
:
qd2schedule
[
k
],
date
:
logDate
,
times
:
total
});
tasks
.
push
(
data
.
save
());
});
}
Promise
.
all
(
tasks
).
then
(
function
(
arr
){
console
.
log
(
'插入'
+
arr
.
length
+
'条数据'
);
console
.
log
(
'插入完成'
);
});
});
}
catch
(
err
)
{
console
.
dir
(
err
);
console
.
dir
(
'更新异常 =====>'
);
...
...
lib/session.js
View file @
707050df
...
...
@@ -21,3 +21,23 @@ exports.login = async (req,res,next) => {
res
.
status
(
500
).
send
({
result
:
'密码不正确'
});
};
exports
.
logout
=
async
(
req
,
res
,
next
)
=>
{
let
sess
=
req
.
cookies
[
'sess'
];
if
(
sess
){
session
.
remove
({
_id
:
sess
},
function
(
err
,
result
)
{
if
(
!
err
){
res
.
clearCookie
(
'sess'
);
res
.
clearCookie
(
'username'
);
res
.
redirect
(
'/'
)
}
else
{
res
.
status
(
500
).
send
(
'错误'
);
}
});
}
else
res
.
status
(
500
).
send
(
'错误'
);
};
\ No newline at end of file
routes/index.js
View file @
707050df
...
...
@@ -10,6 +10,7 @@ router.get('/logs',controller.logs);
router
.
post
(
'/agent'
,
controller
.
putAgent
);
router
.
post
(
'/tbkl'
,
controller
.
putTbkl
);
router
.
post
(
'/session'
,
session
.
login
);
router
.
get
(
'/logout'
,
session
.
logout
);
router
.
post
(
'/to_tbkl'
,
controller
.
createTbkl
);
//系统生成淘口令
router
.
get
(
'/tbkls'
,
controller
.
getTbkls
);
router
.
get
(
'/links'
,
controller
.
getLinks
);
...
...
@@ -20,4 +21,6 @@ router.post('/link',controller.createLink);
router
.
get
(
'/schedules'
,
controller
.
getSchedules
);
router
.
post
(
'/schedule'
,
controller
.
createSchedule
);
router
.
get
(
'/gathers/qd'
,
controller
.
getQdGatherData
);
module
.
exports
=
router
;
\ No newline at end of file
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