const db = require('../db');
const xlsx = require('node-xlsx').default;
const fs = require('fs');
const _ = require('lodash');
const moment = require('moment');
async function task(argument) {
	
  const dspCallTask = await db.getCollection('dspCallTask');
  const callTask = await db.getCollection('callTask');

  let data = [['被叫用户','账户ID','z']];
  let _count = 0;
  let arrs = await dspCallTask.find({ "date" : { $gte: "20180801", $lte: "20180831" }}).limit(1000000000000).toArray();
  console.dir(arrs);
  arrs.forEach( async ({ tags, _id, groupID }) => {
  /*  let areas =  provincelist.concat(citylist)
    data.push([dspgroup,areas.join(","),interestlist.join(",")]);
    console.dir(_count + '====>');*/
    let group = await dspCallGroups.findOne({_id:  db.ObjectID(groupID) });
     data.push([_id+'',(group ? group.dspgroup : ''), tags]);
    _count ++;
    if(_count === arrs.length) {
       //console.dir(JSON.stringify(data));
       var buffer = xlsx.build([{name: "mySheetName", data: data}]);
       fs.writeFile('./data2.xlsx', buffer, function(err) {
            if (err) {
                throw err;
            }
            console.log('Hello.');
        });
    }

  });
 
}



task();


