Built motion from commit 14588770.|2.5.38
[motion2.git] / server / components / export / csv.js
index 9a7f5c7..60b8252 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x38b3=['length','existsSync','join','%s%d.%s','csv','%s.%s','writeFileSync','zip','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','CSV','catch','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','inspect','Failed','finally','exit','util','path','lodash','to-csv','bluebird','zip-dir','rimraf','../../mysqldb','../../config/logger','analytics','argv','AnalyticExtractedReport','info','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','Setting','split','splitSizeCsv','then','query','QueryTypes','num','range','forEach','push','sequelize','%s\x20limit\x20%d\x20OFFSET\x20%d','SELECT','dirname','basename','.csv'];(function(_0x47571e,_0x4bc822){var _0x1ce20f=function(_0x35e0a8){while(--_0x35e0a8){_0x47571e['push'](_0x47571e['shift']());}};_0x1ce20f(++_0x4bc822);}(_0x38b3,0xfb));var _0x338b=function(_0x590759,_0x2139af){_0x590759=_0x590759-0x0;var _0x1a6bf4=_0x38b3[_0x590759];return _0x1a6bf4;};'use strict';var util=require(_0x338b('0x0'));var path=require(_0x338b('0x1'));var _=require(_0x338b('0x2'));var csv=require(_0x338b('0x3'));var fs=require('fs');var BPromise=require(_0x338b('0x4'));var zipdir=require(_0x338b('0x5'));var rimraf=require(_0x338b('0x6'));var db=require(_0x338b('0x7'))['db'];var dbH=require('../../mysqldb')['dbH'];var logger=require(_0x338b('0x8'))(_0x338b('0x9'));var EXTRACTED_REPORT_ID=Number(process[_0x338b('0xa')][0x2]);var QUERY=process[_0x338b('0xa')][0x3];var PATH=process[_0x338b('0xa')][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0x13da7f,_0xeadfa){var _0x213796={'status':_0x13da7f};var _0x53ba5e={'where':{'id':EXTRACTED_REPORT_ID}};if(_0xeadfa){_0x213796['savename']=_0xeadfa;}return db[_0x338b('0xb')]['update'](_0x213796,_0x53ba5e);}function main(){var _0x41d608=0x1388;var _0x9eec0a;logger[_0x338b('0xc')](util[_0x338b('0xd')](_0x338b('0xe'),EXTRACTED_REPORT_ID,'CSV'));return db[_0x338b('0xf')]['find']({'where':{'id':0x1},'raw':!![],'attributes':['id',_0x338b('0x10'),_0x338b('0x11')]})[_0x338b('0x12')](function(_0x539e61){if(_0x539e61){_0x9eec0a=_0x539e61;_0x41d608=_0x9eec0a[_0x338b('0x11')]||0x1388;}})[_0x338b('0x12')](function(){return dbH['sequelize'][_0x338b('0x13')](util['format']('SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t',QUERY),{'type':dbH['sequelize'][_0x338b('0x14')]['SELECT']});})['then'](function(_0x2f5772){if(!_0x2f5772[0x0][_0x338b('0x15')]){return analyticExtractedReport('Empty');}var _0x2163a0=[];var _0x2cca38=0x0;if(_0x9eec0a[_0x338b('0x10')]){if(_0x2f5772&&_0x2f5772['length']){var _0x83818e=_[_0x338b('0x16')](_0x2f5772[0x0]['num']/_0x41d608);var _0x45970d=Number['isInteger'](_0x2f5772[0x0][_0x338b('0x15')]/_0x41d608)?_0x2f5772[0x0]['num']%_0x41d608:0x0;_0x83818e[_0x338b('0x17')](function(_0x5d6bfb){if(_0x5d6bfb>0x0){_0x2cca38+=_0x41d608;}_0x2163a0[_0x338b('0x18')](dbH[_0x338b('0x19')]['query'](util[_0x338b('0xd')](_0x338b('0x1a'),QUERY,_0x41d608,_0x2cca38),{'type':dbH['sequelize'][_0x338b('0x14')]['SELECT']}));});if(_0x45970d>0x0){_0x2cca38+=_0x41d608;_0x2163a0['push'](dbH[_0x338b('0x19')][_0x338b('0x13')](util[_0x338b('0xd')](_0x338b('0x1a'),QUERY,_0x45970d,_0x2cca38),{'type':dbH[_0x338b('0x19')][_0x338b('0x14')][_0x338b('0x1b')]}));}}}else{_0x2163a0[_0x338b('0x18')](dbH[_0x338b('0x19')][_0x338b('0x13')](QUERY,{'type':dbH['sequelize'][_0x338b('0x14')]['SELECT']}));}var _0x3c60fe=path[_0x338b('0x1c')](PATH);var _0x5eb5f1=path[_0x338b('0x1d')](PATH,_0x338b('0x1e'));var _0x3551da=_0x9eec0a[_0x338b('0x10')]&&_0x2163a0[_0x338b('0x1f')]>0x1;var _0xc7a18c=[];if(!fs[_0x338b('0x20')](path['join'](_0x3c60fe,_0x5eb5f1))&&_0x3551da){fs['mkdirSync'](path[_0x338b('0x21')](_0x3c60fe,_0x5eb5f1));}return BPromise['each'](_0x2163a0,function(_0x1095a5){_0xc7a18c['push'](_0x1095a5);})['then'](function(){for(var _0x48ab2b=0x0;_0x48ab2b<_0xc7a18c[_0x338b('0x1f')];_0x48ab2b+=0x1){var _0x9841a9;var _0x1487bb=_0xc7a18c[_0x48ab2b];if(_0x3551da){_0x9841a9=path['join'](_0x3c60fe,_0x5eb5f1,util[_0x338b('0xd')](_0x338b('0x22'),_0x5eb5f1,_0x48ab2b,_0x338b('0x23')));}else{_0x9841a9=path[_0x338b('0x21')](_0x3c60fe,util[_0x338b('0xd')](_0x338b('0x24'),_0x5eb5f1,'csv'));}fs[_0x338b('0x25')](_0x9841a9,csv(_0x1487bb));}})['then'](function(){if(_0x3551da){return new Promise(function(_0x54f977){zipdir(path['join'](_0x3c60fe,_0x5eb5f1),{'saveTo':path[_0x338b('0x21')](_0x3c60fe,util[_0x338b('0xd')]('%s.%s',_0x5eb5f1,_0x338b('0x26')))},function(_0x5baab9,_0x15c92a){rimraf(path[_0x338b('0x21')](_0x3c60fe,_0x5eb5f1),function(){});_0x54f977('zip\x20finished');});});}})[_0x338b('0x12')](function(){logger['info'](util[_0x338b('0xd')](_0x338b('0x27'),EXTRACTED_REPORT_ID,_0x338b('0x28')));return analyticExtractedReport('Completed',_0x3551da?util[_0x338b('0xd')](_0x338b('0x24'),_0x5eb5f1,_0x3551da?_0x338b('0x26'):_0x338b('0x23')):null);});})[_0x338b('0x29')](function(_0x1fa830){logger[_0x338b('0xc')](util[_0x338b('0xd')](_0x338b('0x2a'),EXTRACTED_REPORT_ID,_0x338b('0x28')),util[_0x338b('0x2b')](_0x1fa830,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport(_0x338b('0x2c'));})[_0x338b('0x2d')](function(){process[_0x338b('0x2e')](EXIT_CODE);});}main();
\ No newline at end of file
+var _0x6f80=['lodash','to-csv','zip-dir','rimraf','../../mysqldb','dbH','../../config/logger','analytics','argv','savename','AnalyticExtractedReport','info','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','CSV','Setting','find','then','splitSizeCsv','sequelize','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','QueryTypes','SELECT','num','Empty','length','range','forEach','push','%s\x20limit\x20%d\x20OFFSET\x20%d','dirname','basename','.csv','split','existsSync','join','mkdirSync','each','%s%d.%s','csv','writeFileSync','%s.%s','zip','zip\x20finished','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','Completed','catch','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','Failed','exit','path'];(function(_0x361ac8,_0x5bd80b){var _0x54dd46=function(_0x1a2dbe){while(--_0x1a2dbe){_0x361ac8['push'](_0x361ac8['shift']());}};_0x54dd46(++_0x5bd80b);}(_0x6f80,0x103));var _0x06f8=function(_0x2b94b3,_0x46dea3){_0x2b94b3=_0x2b94b3-0x0;var _0x4356d4=_0x6f80[_0x2b94b3];return _0x4356d4;};'use strict';var util=require('util');var path=require(_0x06f8('0x0'));var _=require(_0x06f8('0x1'));var csv=require(_0x06f8('0x2'));var fs=require('fs');var BPromise=require('bluebird');var zipdir=require(_0x06f8('0x3'));var rimraf=require(_0x06f8('0x4'));var db=require(_0x06f8('0x5'))['db'];var dbH=require(_0x06f8('0x5'))[_0x06f8('0x6')];var logger=require(_0x06f8('0x7'))(_0x06f8('0x8'));var EXTRACTED_REPORT_ID=Number(process[_0x06f8('0x9')][0x2]);var QUERY=process['argv'][0x3];var PATH=process[_0x06f8('0x9')][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0x32b419,_0x245cc9){var _0x5be33d={'status':_0x32b419};var _0x399f48={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x245cc9){_0x5be33d[_0x06f8('0xa')]=_0x245cc9;}return db[_0x06f8('0xb')]['update'](_0x5be33d,_0x399f48);}function main(){var _0x57c104=0x1388;var _0x4bfaf9;logger[_0x06f8('0xc')](util[_0x06f8('0xd')](_0x06f8('0xe'),EXTRACTED_REPORT_ID,_0x06f8('0xf')));return db[_0x06f8('0x10')][_0x06f8('0x11')]({'where':{'id':0x1},'raw':!![],'attributes':['id','split','splitSizeCsv']})[_0x06f8('0x12')](function(_0xad739d){if(_0xad739d){_0x4bfaf9=_0xad739d;_0x57c104=_0x4bfaf9[_0x06f8('0x13')]||0x1388;}})[_0x06f8('0x12')](function(){return dbH[_0x06f8('0x14')][_0x06f8('0x15')](util[_0x06f8('0xd')](_0x06f8('0x16'),QUERY),{'type':dbH['sequelize'][_0x06f8('0x17')][_0x06f8('0x18')]});})[_0x06f8('0x12')](function(_0x5a1375){if(!_0x5a1375[0x0][_0x06f8('0x19')]){return analyticExtractedReport(_0x06f8('0x1a'));}var _0x42806f=[];var _0x500063=0x0;if(_0x4bfaf9['split']){if(_0x5a1375&&_0x5a1375[_0x06f8('0x1b')]){var _0x5130c7=_[_0x06f8('0x1c')](_0x5a1375[0x0][_0x06f8('0x19')]/_0x57c104);var _0x121dd3=Number['isInteger'](_0x5a1375[0x0][_0x06f8('0x19')]/_0x57c104)?_0x5a1375[0x0][_0x06f8('0x19')]%_0x57c104:0x0;_0x5130c7[_0x06f8('0x1d')](function(_0x20b8e9){if(_0x20b8e9>0x0){_0x500063+=_0x57c104;}_0x42806f[_0x06f8('0x1e')](dbH[_0x06f8('0x14')][_0x06f8('0x15')](util[_0x06f8('0xd')](_0x06f8('0x1f'),QUERY,_0x57c104,_0x500063),{'type':dbH[_0x06f8('0x14')]['QueryTypes'][_0x06f8('0x18')]}));});if(_0x121dd3>0x0){_0x500063+=_0x57c104;_0x42806f['push'](dbH[_0x06f8('0x14')]['query'](util[_0x06f8('0xd')](_0x06f8('0x1f'),QUERY,_0x121dd3,_0x500063),{'type':dbH[_0x06f8('0x14')][_0x06f8('0x17')][_0x06f8('0x18')]}));}}}else{_0x42806f[_0x06f8('0x1e')](dbH[_0x06f8('0x14')][_0x06f8('0x15')](QUERY,{'type':dbH['sequelize'][_0x06f8('0x17')][_0x06f8('0x18')]}));}var _0x98b4b=path[_0x06f8('0x20')](PATH);var _0x3b0f43=path[_0x06f8('0x21')](PATH,_0x06f8('0x22'));var _0x8acf93=_0x4bfaf9[_0x06f8('0x23')]&&_0x42806f[_0x06f8('0x1b')]>0x1;var _0x9e394e=[];if(!fs[_0x06f8('0x24')](path[_0x06f8('0x25')](_0x98b4b,_0x3b0f43))&&_0x8acf93){fs[_0x06f8('0x26')](path[_0x06f8('0x25')](_0x98b4b,_0x3b0f43));}return BPromise[_0x06f8('0x27')](_0x42806f,function(_0x24ca80){_0x9e394e[_0x06f8('0x1e')](_0x24ca80);})[_0x06f8('0x12')](function(){for(var _0x182481=0x0;_0x182481<_0x9e394e['length'];_0x182481+=0x1){var _0x1fc78c;var _0x584cd0=_0x9e394e[_0x182481];if(_0x8acf93){_0x1fc78c=path[_0x06f8('0x25')](_0x98b4b,_0x3b0f43,util[_0x06f8('0xd')](_0x06f8('0x28'),_0x3b0f43,_0x182481,'csv'));}else{_0x1fc78c=path['join'](_0x98b4b,util[_0x06f8('0xd')]('%s.%s',_0x3b0f43,_0x06f8('0x29')));}fs[_0x06f8('0x2a')](_0x1fc78c,csv(_0x584cd0));}})[_0x06f8('0x12')](function(){if(_0x8acf93){return new Promise(function(_0x14e299){zipdir(path[_0x06f8('0x25')](_0x98b4b,_0x3b0f43),{'saveTo':path['join'](_0x98b4b,util['format'](_0x06f8('0x2b'),_0x3b0f43,_0x06f8('0x2c')))},function(_0x3d36c6,_0xfdf2c4){rimraf(path[_0x06f8('0x25')](_0x98b4b,_0x3b0f43),function(){});_0x14e299(_0x06f8('0x2d'));});});}})['then'](function(){logger['info'](util['format'](_0x06f8('0x2e'),EXTRACTED_REPORT_ID,'CSV'));return analyticExtractedReport(_0x06f8('0x2f'),_0x8acf93?util['format']('%s.%s',_0x3b0f43,_0x8acf93?'zip':_0x06f8('0x29')):null);});})[_0x06f8('0x30')](function(_0x21ac2f){logger['info'](util[_0x06f8('0xd')](_0x06f8('0x31'),EXTRACTED_REPORT_ID,_0x06f8('0xf')),util['inspect'](_0x21ac2f,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport(_0x06f8('0x32'));})['finally'](function(){process[_0x06f8('0x33')](EXIT_CODE);});}main();
\ No newline at end of file