Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / components / export / xlsx.js
index 96ebc67..5aef32c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x43d6=['AnalyticExtractedReport','info','XLSX','Setting','find','splitSizeXlsx','then','sequelize','query','QueryTypes','SELECT','num','Empty','format','push','dirname','basename','.xlsx','split','length','existsSync','join','each','%s%d.%s','%s.%s','xlsx','writeFileSync','binary','Completed','zip','catch','inspect','util','path','lodash','json2xls','bluebird','zip-dir','../../mysqldb','dbH','../../config/logger','analytics','argv','savename'];(function(_0x57b54c,_0x54ce0d){var _0x59cc19=function(_0xa33bc6){while(--_0xa33bc6){_0x57b54c['push'](_0x57b54c['shift']());}};_0x59cc19(++_0x54ce0d);}(_0x43d6,0xfc));var _0x643d=function(_0x593d62,_0x3d52fe){_0x593d62=_0x593d62-0x0;var _0x47ee6b=_0x43d6[_0x593d62];return _0x47ee6b;};'use strict';var util=require(_0x643d('0x0'));var path=require(_0x643d('0x1'));var _=require(_0x643d('0x2'));var fs=require('fs');var json2xls=require(_0x643d('0x3'));var BPromise=require(_0x643d('0x4'));var zipdir=require(_0x643d('0x5'));var rimraf=require('rimraf');var db=require(_0x643d('0x6'))['db'];var dbH=require(_0x643d('0x6'))[_0x643d('0x7')];var logger=require(_0x643d('0x8'))(_0x643d('0x9'));var EXTRACTED_REPORT_ID=Number(process[_0x643d('0xa')][0x2]);var QUERY=process['argv'][0x3];var PATH=process[_0x643d('0xa')][0x4];function analyticExtractedReport(_0x26a8c1,_0x5b1feb){var _0x349e3e={'status':_0x26a8c1};var _0x1787da={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x5b1feb){_0x349e3e[_0x643d('0xb')]=_0x5b1feb;}return db[_0x643d('0xc')]['update'](_0x349e3e,_0x1787da);}function main(){var _0x3f079c=0x1388;var _0x3334dc;logger[_0x643d('0xd')](util['format']('Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format',EXTRACTED_REPORT_ID,_0x643d('0xe')));return db[_0x643d('0xf')][_0x643d('0x10')]({'where':{'id':0x1},'raw':!![],'attributes':['id','split',_0x643d('0x11')]})[_0x643d('0x12')](function(_0x5ba4ee){if(_0x5ba4ee){_0x3334dc=_0x5ba4ee;_0x3f079c=_0x3334dc[_0x643d('0x11')]||0x1388;}})['then'](function(){return dbH[_0x643d('0x13')][_0x643d('0x14')](util['format']('SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t',QUERY),{'type':dbH[_0x643d('0x13')][_0x643d('0x15')][_0x643d('0x16')]});})['then'](function(_0x1fee1d){if(!_0x1fee1d[0x0][_0x643d('0x17')]){return analyticExtractedReport(_0x643d('0x18'));}var _0x4336d0=[];var _0x3ab47d=0x0;var _0x4bedf4=!![];if(_0x3334dc['split']){if(_0x1fee1d&&_0x1fee1d['length']){var _0x24b4c2=_0x1fee1d[0x0][_0x643d('0x17')]%(_0x3ab47d+_0x3f079c);for(;_0x4bedf4;_0x3ab47d+=_0x3f079c,_0x24b4c2=_0x1fee1d[0x0]['num']%(_0x3ab47d+_0x3f079c)){if(_0x24b4c2==0x0||_0x24b4c2==_0x1fee1d[0x0]['num']){_0x4bedf4=![];}_0x4336d0['push'](dbH[_0x643d('0x13')][_0x643d('0x14')](util[_0x643d('0x19')]('%s\x20limit\x20%d\x20OFFSET\x20%d',QUERY,_0x3f079c,_0x3ab47d),{'type':dbH[_0x643d('0x13')][_0x643d('0x15')][_0x643d('0x16')]}));}}}else{_0x4336d0[_0x643d('0x1a')](dbH[_0x643d('0x13')][_0x643d('0x14')](QUERY,{'type':dbH[_0x643d('0x13')][_0x643d('0x15')][_0x643d('0x16')]}));}var _0x94f683=path[_0x643d('0x1b')](PATH);var _0x942cb7=path[_0x643d('0x1c')](PATH,_0x643d('0x1d'));var _0x3306a7=_0x3334dc[_0x643d('0x1e')]&&_0x4336d0[_0x643d('0x1f')]>0x1;var _0x168930=[];if(!fs[_0x643d('0x20')](path['join'](_0x94f683,_0x942cb7))&&_0x3306a7){fs['mkdirSync'](path[_0x643d('0x21')](_0x94f683,_0x942cb7));}return BPromise[_0x643d('0x22')](_0x4336d0,function(_0x46b4ff){_0x168930[_0x643d('0x1a')](_0x46b4ff);})[_0x643d('0x12')](function(){for(var _0x5d52c8=0x0;_0x5d52c8<_0x168930[_0x643d('0x1f')];_0x5d52c8+=0x1){var _0x3eaada;var _0x40f62c=_0x168930[_0x5d52c8];if(_0x3306a7){_0x3eaada=path[_0x643d('0x21')](_0x94f683,_0x942cb7,util[_0x643d('0x19')](_0x643d('0x23'),_0x942cb7,_0x5d52c8,'xlsx'));}else{_0x3eaada=path[_0x643d('0x21')](_0x94f683,util[_0x643d('0x19')](_0x643d('0x24'),_0x942cb7,_0x643d('0x25')));}fs[_0x643d('0x26')](_0x3eaada,json2xls(_0x40f62c),_0x643d('0x27'));}})[_0x643d('0x12')](function(){if(_0x3306a7){zipdir(path[_0x643d('0x21')](_0x94f683,_0x942cb7),{'saveTo':path[_0x643d('0x21')](_0x94f683,util[_0x643d('0x19')](_0x643d('0x24'),_0x942cb7,'zip'))},function(_0x16ad24,_0x511e13){});rimraf(path[_0x643d('0x21')](_0x94f683,_0x942cb7),function(){});}})[_0x643d('0x12')](function(){logger[_0x643d('0xd')](util[_0x643d('0x19')]('Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed',EXTRACTED_REPORT_ID,'XLSX'));return analyticExtractedReport(_0x643d('0x28'),_0x3306a7?util[_0x643d('0x19')](_0x643d('0x24'),_0x942cb7,_0x3306a7?_0x643d('0x29'):_0x643d('0x25')):null);});})[_0x643d('0x2a')](function(_0x41284c){logger[_0x643d('0xd')](util[_0x643d('0x19')]('Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format',EXTRACTED_REPORT_ID,_0x643d('0xe')),util[_0x643d('0x2b')](_0x41284c,{'showHidden':![],'depth':null}));return analyticExtractedReport('Failed');});}main();
\ No newline at end of file
+var _0x0e16=['zip-dir','rimraf','../../mysqldb','dbH','../../config/logger','analytics','argv','savename','info','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','XLSX','Setting','find','split','splitSizeXlsx','then','sequelize','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','QueryTypes','num','Empty','length','range','isInteger','forEach','%s\x20limit\x20%d\x20OFFSET\x20%d','SELECT','push','dirname','basename','.xlsx','existsSync','join','mkdirSync','each','%s%d.%s','xlsx','writeFileSync','binary','%s.%s','zip','zip\x20finished','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','catch','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','inspect','Failed','finally','exit','util','path','lodash','json2xls','bluebird'];(function(_0x8af54b,_0x280be5){var _0x27d8f0=function(_0x559734){while(--_0x559734){_0x8af54b['push'](_0x8af54b['shift']());}};_0x27d8f0(++_0x280be5);}(_0x0e16,0x183));var _0x60e1=function(_0x4b7b62,_0x4920a9){_0x4b7b62=_0x4b7b62-0x0;var _0x2280df=_0x0e16[_0x4b7b62];return _0x2280df;};'use strict';var util=require(_0x60e1('0x0'));var path=require(_0x60e1('0x1'));var _=require(_0x60e1('0x2'));var fs=require('fs');var json2xls=require(_0x60e1('0x3'));var BPromise=require(_0x60e1('0x4'));var zipdir=require(_0x60e1('0x5'));var rimraf=require(_0x60e1('0x6'));var db=require(_0x60e1('0x7'))['db'];var dbH=require(_0x60e1('0x7'))[_0x60e1('0x8')];var logger=require(_0x60e1('0x9'))(_0x60e1('0xa'));var EXTRACTED_REPORT_ID=Number(process['argv'][0x2]);var QUERY=process[_0x60e1('0xb')][0x3];var PATH=process['argv'][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0x40d4a7,_0x17dc35){var _0xd750d2={'status':_0x40d4a7};var _0x16fc29={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x17dc35){_0xd750d2[_0x60e1('0xc')]=_0x17dc35;}return db['AnalyticExtractedReport']['update'](_0xd750d2,_0x16fc29);}function main(){var _0x15898a=0x1388;var _0x1535e9;logger[_0x60e1('0xd')](util[_0x60e1('0xe')](_0x60e1('0xf'),EXTRACTED_REPORT_ID,_0x60e1('0x10')));return db[_0x60e1('0x11')][_0x60e1('0x12')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0x60e1('0x13'),_0x60e1('0x14')]})[_0x60e1('0x15')](function(_0x28bcb0){if(_0x28bcb0){_0x1535e9=_0x28bcb0;_0x15898a=_0x1535e9['splitSizeXlsx']||0x1388;}})[_0x60e1('0x15')](function(){return dbH[_0x60e1('0x16')][_0x60e1('0x17')](util[_0x60e1('0xe')](_0x60e1('0x18'),QUERY),{'type':dbH['sequelize'][_0x60e1('0x19')]['SELECT']});})[_0x60e1('0x15')](function(_0x5979cc){if(!_0x5979cc[0x0][_0x60e1('0x1a')]){return analyticExtractedReport(_0x60e1('0x1b'));}var _0x4813e1=[];var _0x192f38=0x0;if(_0x1535e9[_0x60e1('0x13')]){if(_0x5979cc&&_0x5979cc[_0x60e1('0x1c')]){var _0x3fd27=_[_0x60e1('0x1d')](_0x5979cc[0x0]['num']/_0x15898a);var _0x47cfc2=Number[_0x60e1('0x1e')](_0x5979cc[0x0]['num']/_0x15898a)?_0x5979cc[0x0]['num']%_0x15898a:0x0;_0x3fd27[_0x60e1('0x1f')](function(_0x4c377a){if(_0x4c377a>0x0){_0x192f38+=_0x15898a;}_0x4813e1['push'](dbH[_0x60e1('0x16')]['query'](util[_0x60e1('0xe')](_0x60e1('0x20'),QUERY,_0x15898a,_0x192f38),{'type':dbH['sequelize'][_0x60e1('0x19')][_0x60e1('0x21')]}));});if(_0x47cfc2>0x0){_0x192f38+=_0x15898a;_0x4813e1[_0x60e1('0x22')](dbH[_0x60e1('0x16')][_0x60e1('0x17')](util['format'](_0x60e1('0x20'),QUERY,_0x47cfc2,_0x192f38),{'type':dbH['sequelize']['QueryTypes'][_0x60e1('0x21')]}));}}}else{_0x4813e1[_0x60e1('0x22')](dbH[_0x60e1('0x16')][_0x60e1('0x17')](QUERY,{'type':dbH[_0x60e1('0x16')][_0x60e1('0x19')][_0x60e1('0x21')]}));}var _0x2848ff=path[_0x60e1('0x23')](PATH);var _0x3b1d86=path[_0x60e1('0x24')](PATH,_0x60e1('0x25'));var _0x5ea803=_0x1535e9[_0x60e1('0x13')]&&_0x4813e1[_0x60e1('0x1c')]>0x1;var _0x58a907=[];if(!fs[_0x60e1('0x26')](path[_0x60e1('0x27')](_0x2848ff,_0x3b1d86))&&_0x5ea803){fs[_0x60e1('0x28')](path[_0x60e1('0x27')](_0x2848ff,_0x3b1d86));}return BPromise[_0x60e1('0x29')](_0x4813e1,function(_0x1be296){_0x58a907['push'](_0x1be296);})['then'](function(){for(var _0x17defe=0x0;_0x17defe<_0x58a907[_0x60e1('0x1c')];_0x17defe+=0x1){var _0x3ce477;var _0x217a83=_0x58a907[_0x17defe];if(_0x5ea803){_0x3ce477=path['join'](_0x2848ff,_0x3b1d86,util[_0x60e1('0xe')](_0x60e1('0x2a'),_0x3b1d86,_0x17defe,_0x60e1('0x2b')));}else{_0x3ce477=path[_0x60e1('0x27')](_0x2848ff,util['format']('%s.%s',_0x3b1d86,_0x60e1('0x2b')));}fs[_0x60e1('0x2c')](_0x3ce477,json2xls(_0x217a83),_0x60e1('0x2d'));}})[_0x60e1('0x15')](function(){if(_0x5ea803){return new Promise(function(_0x14a906){zipdir(path['join'](_0x2848ff,_0x3b1d86),{'saveTo':path[_0x60e1('0x27')](_0x2848ff,util[_0x60e1('0xe')](_0x60e1('0x2e'),_0x3b1d86,_0x60e1('0x2f')))},function(_0x37875a,_0x6c7e){rimraf(path[_0x60e1('0x27')](_0x2848ff,_0x3b1d86),function(){});_0x14a906(_0x60e1('0x30'));});});}})[_0x60e1('0x15')](function(){logger['info'](util[_0x60e1('0xe')](_0x60e1('0x31'),EXTRACTED_REPORT_ID,'XLSX'));return analyticExtractedReport('Completed',_0x5ea803?util[_0x60e1('0xe')](_0x60e1('0x2e'),_0x3b1d86,_0x5ea803?_0x60e1('0x2f'):'xlsx'):null);});})[_0x60e1('0x32')](function(_0x24ae74){logger[_0x60e1('0xd')](util[_0x60e1('0xe')](_0x60e1('0x33'),EXTRACTED_REPORT_ID,_0x60e1('0x10')),util[_0x60e1('0x34')](_0x24ae74,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport(_0x60e1('0x35'));})[_0x60e1('0x36')](function(){process[_0x60e1('0x37')](EXIT_CODE);});}main();
\ No newline at end of file