Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / components / export / xlsx.js
index 42b477f..5aef32c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8d02=['analytics','argv','AnalyticExtractedReport','info','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','Setting','find','split','splitSizeXlsx','then','sequelize','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','QueryTypes','SELECT','length','num','isInteger','forEach','push','%s\x20limit\x20%d\x20OFFSET\x20%d','existsSync','mkdirSync','each','join','%s%d.%s','%s.%s','binary','zip','zip\x20finished','Completed','xlsx','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','XLSX','inspect','Failed','exit','util','path','json2xls','bluebird','zip-dir','rimraf','../../mysqldb'];(function(_0x14add3,_0x13ce8d){var _0x4a174f=function(_0x2b3ed7){while(--_0x2b3ed7){_0x14add3['push'](_0x14add3['shift']());}};_0x4a174f(++_0x13ce8d);}(_0x8d02,0x134));var _0x28d0=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x8d02[_0x3dd15e];return _0x231fd0;};'use strict';var util=require(_0x28d0('0x0'));var path=require(_0x28d0('0x1'));var _=require('lodash');var fs=require('fs');var json2xls=require(_0x28d0('0x2'));var BPromise=require(_0x28d0('0x3'));var zipdir=require(_0x28d0('0x4'));var rimraf=require(_0x28d0('0x5'));var db=require(_0x28d0('0x6'))['db'];var dbH=require('../../mysqldb')['dbH'];var logger=require('../../config/logger')(_0x28d0('0x7'));var EXTRACTED_REPORT_ID=Number(process['argv'][0x2]);var QUERY=process[_0x28d0('0x8')][0x3];var PATH=process['argv'][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0x4bc63e,_0x58f343){var _0x3ef5fb={'status':_0x4bc63e};var _0x58d8d2={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x58f343){_0x3ef5fb['savename']=_0x58f343;}return db[_0x28d0('0x9')]['update'](_0x3ef5fb,_0x58d8d2);}function main(){var _0x57f8ac=0x1388;var _0xee9c43;logger[_0x28d0('0xa')](util[_0x28d0('0xb')](_0x28d0('0xc'),EXTRACTED_REPORT_ID,'XLSX'));return db[_0x28d0('0xd')][_0x28d0('0xe')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0x28d0('0xf'),_0x28d0('0x10')]})['then'](function(_0x2aa7ac){if(_0x2aa7ac){_0xee9c43=_0x2aa7ac;_0x57f8ac=_0xee9c43[_0x28d0('0x10')]||0x1388;}})[_0x28d0('0x11')](function(){return dbH[_0x28d0('0x12')][_0x28d0('0x13')](util[_0x28d0('0xb')](_0x28d0('0x14'),QUERY),{'type':dbH['sequelize'][_0x28d0('0x15')][_0x28d0('0x16')]});})[_0x28d0('0x11')](function(_0x29532a){if(!_0x29532a[0x0]['num']){return analyticExtractedReport('Empty');}var _0x121527=[];var _0x37342d=0x0;if(_0xee9c43[_0x28d0('0xf')]){if(_0x29532a&&_0x29532a[_0x28d0('0x17')]){var _0x56fd84=_['range'](_0x29532a[0x0][_0x28d0('0x18')]/_0x57f8ac);var _0x3ac280=Number[_0x28d0('0x19')](_0x29532a[0x0][_0x28d0('0x18')]/_0x57f8ac)?_0x29532a[0x0][_0x28d0('0x18')]%_0x57f8ac:0x0;_0x56fd84[_0x28d0('0x1a')](function(_0x87b79f){if(_0x87b79f>0x0){_0x37342d+=_0x57f8ac;}_0x121527[_0x28d0('0x1b')](dbH[_0x28d0('0x12')][_0x28d0('0x13')](util[_0x28d0('0xb')]('%s\x20limit\x20%d\x20OFFSET\x20%d',QUERY,_0x57f8ac,_0x37342d),{'type':dbH[_0x28d0('0x12')][_0x28d0('0x15')][_0x28d0('0x16')]}));});if(_0x3ac280>0x0){_0x37342d+=_0x57f8ac;_0x121527[_0x28d0('0x1b')](dbH[_0x28d0('0x12')][_0x28d0('0x13')](util['format'](_0x28d0('0x1c'),QUERY,_0x3ac280,_0x37342d),{'type':dbH[_0x28d0('0x12')][_0x28d0('0x15')][_0x28d0('0x16')]}));}}}else{_0x121527[_0x28d0('0x1b')](dbH[_0x28d0('0x12')][_0x28d0('0x13')](QUERY,{'type':dbH[_0x28d0('0x12')]['QueryTypes'][_0x28d0('0x16')]}));}var _0x355bfd=path['dirname'](PATH);var _0x3e71d3=path['basename'](PATH,'.xlsx');var _0x857290=_0xee9c43[_0x28d0('0xf')]&&_0x121527[_0x28d0('0x17')]>0x1;var _0x431278=[];if(!fs[_0x28d0('0x1d')](path['join'](_0x355bfd,_0x3e71d3))&&_0x857290){fs[_0x28d0('0x1e')](path['join'](_0x355bfd,_0x3e71d3));}return BPromise[_0x28d0('0x1f')](_0x121527,function(_0x5e1801){_0x431278[_0x28d0('0x1b')](_0x5e1801);})[_0x28d0('0x11')](function(){for(var _0x48e4bc=0x0;_0x48e4bc<_0x431278[_0x28d0('0x17')];_0x48e4bc+=0x1){var _0x35a250;var _0x44f50b=_0x431278[_0x48e4bc];if(_0x857290){_0x35a250=path[_0x28d0('0x20')](_0x355bfd,_0x3e71d3,util[_0x28d0('0xb')](_0x28d0('0x21'),_0x3e71d3,_0x48e4bc,'xlsx'));}else{_0x35a250=path[_0x28d0('0x20')](_0x355bfd,util[_0x28d0('0xb')](_0x28d0('0x22'),_0x3e71d3,'xlsx'));}fs['writeFileSync'](_0x35a250,json2xls(_0x44f50b),_0x28d0('0x23'));}})['then'](function(){if(_0x857290){return new Promise(function(_0x1c948d){zipdir(path[_0x28d0('0x20')](_0x355bfd,_0x3e71d3),{'saveTo':path[_0x28d0('0x20')](_0x355bfd,util[_0x28d0('0xb')](_0x28d0('0x22'),_0x3e71d3,_0x28d0('0x24')))},function(_0x4e4557,_0x4157ef){rimraf(path['join'](_0x355bfd,_0x3e71d3),function(){});_0x1c948d(_0x28d0('0x25'));});});}})[_0x28d0('0x11')](function(){logger[_0x28d0('0xa')](util[_0x28d0('0xb')]('Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed',EXTRACTED_REPORT_ID,'XLSX'));return analyticExtractedReport(_0x28d0('0x26'),_0x857290?util[_0x28d0('0xb')]('%s.%s',_0x3e71d3,_0x857290?_0x28d0('0x24'):_0x28d0('0x27')):null);});})['catch'](function(_0x5800b8){logger[_0x28d0('0xa')](util[_0x28d0('0xb')](_0x28d0('0x28'),EXTRACTED_REPORT_ID,_0x28d0('0x29')),util[_0x28d0('0x2a')](_0x5800b8,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport(_0x28d0('0x2b'));})['finally'](function(){process[_0x28d0('0x2c')](EXIT_CODE);});}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