Commit 707050df authored by 刘松's avatar 刘松

update

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