Commit 723579fc authored by 刘松's avatar 刘松

update query

parent b7117971
This diff is collapsed.
...@@ -53,7 +53,7 @@ class Main extends React.Component{ ...@@ -53,7 +53,7 @@ class Main extends React.Component{
> >
<SubMenu title={<span>数据统计</span>}> <SubMenu title={<span>数据统计</span>}>
<Menu.Item key="0">口令数据</Menu.Item> <Menu.Item key="0">口令数据</Menu.Item>
<Menu.Item key="1">每日汇总</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>
...@@ -63,7 +63,7 @@ class Main extends React.Component{ ...@@ -63,7 +63,7 @@ class Main extends React.Component{
<Content style={{ padding: '0 50px' }}> <Content style={{ padding: '0 50px' }}>
<Breadcrumb style={{ margin: '12px 0' }}> <Breadcrumb style={{ margin: '12px 0' }}>
<Breadcrumb.Item>{ this.map[ this.props.menu.currentPage ]}</Breadcrumb.Item> <Breadcrumb.Item>{ this.map[ this.props.menu.currentPage ]}</Breadcrumb.Item>
<Breadcrumb.Item>{ this.props.menu.currentPage == '0' ? '数据统计' : (this.props.menu.currentPage == '1' ? '每日汇总' : "配置" )}</Breadcrumb.Item> <Breadcrumb.Item>{ this.props.menu.currentPage == '0' ? '数据统计' : (this.props.menu.currentPage == '1' ? '汇总数据' : "配置" )}</Breadcrumb.Item>
</Breadcrumb> </Breadcrumb>
<div style={{ background: '#fff', padding: 24, minHeight: 280 }}>{ <div style={{ background: '#fff', padding: 24, minHeight: 280 }}>{
this.props.children this.props.children
......
...@@ -14,20 +14,33 @@ class DashBoard extends React.Component{ ...@@ -14,20 +14,33 @@ 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' }; this.state= { logs :[],status:'pending',pagination:{current:1,pageSize:10,total:100} };
} }
componentDidMount(){ componentDidMount(){
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').then((res) => { api('GET', 'logs?'+'skip=0&limit=' + pagination.pageSize).then((res) => {
this.setState({logs: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);
}); });
} }
onChange(date, dateString) { getlogs(pagination){
let data = { start:dateString[0],end:dateString[1]}; this.setState({status:'pending'})
api('GET', 'logs?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize).then((res) => {
this.setState({tbkls:res.result,status:'ready'})
console.dir(res.result);
});
}
onChange(pagination) {
//let data = { start:dateString[0],end:dateString[1]};
this.getlogs(pagination);
//this.props.dispatch(actions.getMainData(data)); //this.props.dispatch(actions.getMainData(data));
} }
onChangeRange(date, dateString){
}
exportData(){ exportData(){
...@@ -58,6 +71,13 @@ class DashBoard extends React.Component{ ...@@ -58,6 +71,13 @@ class DashBoard extends React.Component{
}, },
{ {
title: '推广计划', title: '推广计划',
dataIndex: 'schedule',
key: 'schedule',
width: 100,
render: text => <a href="#">{text}</a>,
},
{
title: '渠道',
dataIndex: 'qd', dataIndex: 'qd',
key: 'qd', key: 'qd',
width: 100, width: 100,
...@@ -88,25 +108,27 @@ class DashBoard extends React.Component{ ...@@ -88,25 +108,27 @@ class DashBoard extends React.Component{
let count = 0; let count = 0;
let logs = this.state.logs; let logs = this.state.logs;
for(let i = 0;i<logs.length;i++){ for(let i = 0;i<logs.length;i++){
console.dir(logs[i]);
data.push({ data.push({
key:i, key:i,
date:logs[i].date, date:logs[i].date,
info:logs[i].key, info:logs[i].key,
times:logs[i].times, times:logs[i].times,
status:logs[i].status == 'disable' ? '已归档' :'--', status:logs[i].status == 'disable' ? '已归档' :'--',
qd:(logs[i].schedule) || '--', schedule:(logs[i].schedule && logs[i].schedule['_id']) || '--',
qd:(logs[i].schedule && logs[i].schedule['qd'] && logs[i].schedule['qd']['user']) || '--',
update:logs[i].updatedAt update:logs[i].updatedAt
}); });
} }
return ( return (
<div> <div>
<RangePicker onChange={ this.onChange.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'}}>
导出数据 导出数据
</Button> </Button>
<Spin spinning= { this.state.status == 'pending' }> <Spin spinning= { this.state.status == 'pending' }>
<Table columns={columns} dataSource = { data } size="middle" bordered/> <Table columns={columns} dataSource = { data } size="middle" pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} bordered/>
</Spin> </Spin>
</div> </div>
) )
......
const React = require('react');
/*const connect = require('react-redux').connect;
const actions = require('../../js/actions');*/
const moment = require('moment');
const api = require('../../js/api');
import json2xlsx from '../../js/json2xlsx';
import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button} from 'antd';
const { RangePicker } = DatePicker;
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' };
}
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'})
console.dir(res.result);
});
}
onChange(date, dateString) {
let data = { start:dateString[0],end:dateString[1]};
//this.props.dispatch(actions.getMainData(data));
}
exportData(){
//json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'});
}
render(){
const columns = [
{
title: '日期',
dataIndex: 'date',
key: 'date',
width: 100,
render: text => <a href="#">{text}</a>,
},
{
title: '计划ID',
dataIndex: 'schedule',
key: 'schedule',
width: 100,
render: text => <a href="#">{text}</a>,
},{
title: '请求数',
dataIndex: 'times',
key: 'times',
width: 100,
render: text => <a href="#">{text}</a>,
},
{
title: '总口令',
dataIndex: 'total',
key: 'total',
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',
width: 100,
render: text => <a href="#">{text}</a>,
}
];
let range = this.range;
var start = range[0];
var end = range[1];
let ranges = [];
ranges.push(moment(start,'YYYYMMDD'));
ranges.push(moment(end,'YYYYMMDD'));
let data = [];
let count = 0;
let logs = this.state.logs;
for(let i = 0;i<logs.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
});
}
return (
<div>
<RangePicker onChange={ this.onChange.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>
<Spin spinning= { this.state.status == 'pending' }>
<Table columns={columns} dataSource = { data } size="middle" bordered/>
</Spin>
</div>
)
}
}
/*
function mapStateToProps (state) {
return state;
}
module.exports = connect(mapStateToProps)(DashBoard);*/
module.exports = Gather;
...@@ -60,20 +60,19 @@ exports.putTbkl = async (req, res, next) => { ...@@ -60,20 +60,19 @@ exports.putTbkl = async (req, res, next) => {
} }
}; };
exports.logs = async (req, res, next) => { exports.logs = async (req, res, next) => {
try{ let {start,end} = req.body;
var options = {limit: 1000, skip: 0, sort: {'updatedAt':-1}}; const condition = {'$and': [{'createdAt': {'$gte': moment(start, 'YYYYMMDD').startOf('day').toDate()}}, {'createdAt': {'$lt': moment(end, 'YYYYMMDD').endOf('day').toDate()}}]};
var logs = await Log.find({},null,options).populate('qd','user role'); 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;}); logs = logs.map(x => { var d = x.toJSON();d['updatedAt'] = dateFormat(d['updatedAt']);return d;});
res.send({ status:'ok',result:logs }); res.send({ status:'ok',result:logs,pagination:{total:total,skip:skip,limit:limit}});
} catch(e){
console.dir(e);
}
} }
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),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');
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,7 +80,7 @@ exports.getTbkls = async (req, res, next) => { ...@@ -81,7 +80,7 @@ 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),sort}; let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort};
let tbkls = await Link.find({},null,options).populate('qd','user role'); let tbkls = await Link.find({},null,options).populate('qd','user role');
let total = await Link.count({},null); let total = await Link.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}});
...@@ -120,7 +119,7 @@ exports.createLink = async (req, res, next) => { ...@@ -120,7 +119,7 @@ exports.createLink = async (req, res, next) => {
exports.getSchedules = async (req, res, next) => { 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),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');
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}});
...@@ -173,7 +172,6 @@ exports.createSchedule = async (req, res, next) => { ...@@ -173,7 +172,6 @@ exports.createSchedule = async (req, res, next) => {
} }
var createTbkl = async (data) => { var createTbkl = async (data) => {
console.dir(data);
let {title,target,pic} = data; let {title,target,pic} = data;
return new Promise(async (r,d) => { return new Promise(async (r,d) => {
try { try {
......
...@@ -7,10 +7,10 @@ const tao = require('./tao'); ...@@ -7,10 +7,10 @@ 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 = 20000; const max = 400000;
var CronJob = cron.CronJob; var CronJob = cron.CronJob;
var job = new CronJob({ var job = new CronJob({
cronTime: '* */1 * * *', cronTime: '0 */2 * * * *',
onTick: function() { onTick: function() {
tbklTask(); tbklTask();
}, },
...@@ -43,7 +43,6 @@ async function sendMail(email,body) { ...@@ -43,7 +43,6 @@ async function sendMail(email,body) {
async function tbklTask () { async function tbklTask () {
console.log('定时更新开始 =====> '); console.log('定时更新开始 =====> ');
try { try {
console.log('=====> ');
//let tkls = await Kouling.find({status:'use'}).populate('link','title target').limit(1000); //let tkls = await Kouling.find({status:'use'}).populate('link','title target').limit(1000);
// 查询进行中计划 // 查询进行中计划
let schedules = await Schedule.find({status:'use'}).limit(500); let schedules = await Schedule.find({status:'use'}).limit(500);
...@@ -53,12 +52,12 @@ async function tbklTask () { ...@@ -53,12 +52,12 @@ async function tbklTask () {
// 查询计划内 超过20000 请求 淘口令 // 查询计划内 超过20000 请求 淘口令
//console.dir({times:{$gte:10},status:'use',schedule:schedule}); //console.dir({times:{$gte:10},status:'use',schedule:schedule});
let logs = await Log.find({times:{$gte:max},schedule:schedule,status:{$ne:'disable'}}).populate('link','title target pic').limit(1000); let logs = await Log.find({times:{$gte:max},schedule:schedule,status:{$ne:'disable'}}).populate('link','title target pic').limit(1000);
//console.dir(logs.length);
var tasks_new = []; var tasks_new = [];
var tasks_old = []; var tasks_old = [];
var tasks_log = []; var tasks_log = [];
logs.forEach( item => { logs.forEach( item => {
item = item.toJSON(); item = item.toJSON();
console.log(item._id);
//console.dir(item); //console.dir(item);
if(item.link && item.link.title && item.link.target && item.times >= max){ if(item.link && item.link.title && item.link.target && item.times >= max){
var data = { var data = {
...@@ -70,23 +69,24 @@ async function tbklTask () { ...@@ -70,23 +69,24 @@ async function tbklTask () {
pic:item.link.pic pic:item.link.pic
} }
tasks_new.push(controller.createTbkl(data)); tasks_new.push(controller.createTbkl(data));
tasks_old.push(Kouling.update({info:item.key},{$set:{status:'disable'}})); tasks_old.push(Kouling.update({info:item.key,status:{$ne:'disable'}},{$set:{status:'disable'}}));
tasks_log.push(Log.update({key:item.key},{$set:{status:'disable'}})); tasks_log.push(Log.update({_id:item._id},{$set:{status:'disable'}}));
} }
}); });
if(tasks_new.length&&tasks_old.length&&tasks_log.length){ if(tasks_new.length&&tasks_old.length&&tasks_log.length){
Promise.all(tasks_new).then(function(arr){
console.log('增加老口令 结束 影响' + arr.length + '条数据');
});
Promise.all(tasks_old).then(function(arr){ Promise.all(tasks_old).then(function(arr){
console.log('删除老口令 结束 影响' + arr.length + '条数据'); console.log('删除老口令 结束 影响' + arr.length + '条数据');
}); });
Promise.all(tasks_log).then(function(arr){ Promise.all(tasks_log).then(function(arr){
console.log('更新log数据 影响' + arr.length + '条数据'); console.log('更新log数据 影响' + arr.length + '条数据');
}); });
Promise.all(tasks_new).then(function(arr){
console.log('增加新口令 结束 影响' + arr.length + '条数据');
});
console.log(' 更新结束 有任务');
} }
else{ else{
console.log('没有任务 影响0条数据'); console.log(' 更新结束 无任务');
} }
}); });
...@@ -96,7 +96,6 @@ async function tbklTask () { ...@@ -96,7 +96,6 @@ async function tbklTask () {
let mailList = 'liusong@goyoo.com'; let mailList = 'liusong@goyoo.com';
sendMail(mailList, err.toString()); sendMail(mailList, err.toString());
} }
console.log(' 更新结束 ');
} }
module.exports.start = function () module.exports.start = function ()
......
...@@ -24,7 +24,6 @@ exports.saveKouling = async (data,cb) => { ...@@ -24,7 +24,6 @@ exports.saveKouling = async (data,cb) => {
exports.saveLink = async (data,cb) => { exports.saveLink = async (data,cb) => {
try { try {
console.dir(data);
var link = new Link(data); var link = new Link(data);
cb(null,await link.save()); cb(null,await link.save());
} catch(e){ } catch(e){
...@@ -83,9 +82,6 @@ exports.getGood = (id) => { ...@@ -83,9 +82,6 @@ exports.getGood = (id) => {
} }
exports.createTbkl = (title,url,pic) => { exports.createTbkl = (title,url,pic) => {
console.dir(title);
console.dir(url)
console.dir(pic)
return new Promise((r,d) => { return new Promise((r,d) => {
client.execute('taobao.tbk.tpwd.create', { client.execute('taobao.tbk.tpwd.create', {
'text':title, 'text':title,
......
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