Built motion from commit 52c8a02d.|2.6.29
[motion2.git] / server / components / export / xlsx.js
index 397ab55..8884e31 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x97ac=['info','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','find','split','splitSizeXlsx','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','sequelize','QueryTypes','then','Empty','length','num','push','SELECT','dirname','.xlsx','existsSync','mkdirSync','each','join','xlsx','%s.%s','writeFileSync','binary','zip','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','XLSX','Completed','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','Failed','util','path','lodash','bluebird','zip-dir','../../mysqldb','dbH','analytics','argv','savename','update'];(function(_0x3582eb,_0x442738){var _0x35378c=function(_0x1361b9){while(--_0x1361b9){_0x3582eb['push'](_0x3582eb['shift']());}};_0x35378c(++_0x442738);}(_0x97ac,0xa1));var _0xc97a=function(_0x241b27,_0x755b3b){_0x241b27=_0x241b27-0x0;var _0x17e5de=_0x97ac[_0x241b27];return _0x17e5de;};'use strict';var util=require(_0xc97a('0x0'));var path=require(_0xc97a('0x1'));var _=require(_0xc97a('0x2'));var fs=require('fs');var json2xls=require('json2xls');var BPromise=require(_0xc97a('0x3'));var zipdir=require(_0xc97a('0x4'));var rimraf=require('rimraf');var db=require(_0xc97a('0x5'))['db'];var dbH=require(_0xc97a('0x5'))[_0xc97a('0x6')];var logger=require('../../config/logger')(_0xc97a('0x7'));var EXTRACTED_REPORT_ID=Number(process[_0xc97a('0x8')][0x2]);var QUERY=process[_0xc97a('0x8')][0x3];var PATH=process[_0xc97a('0x8')][0x4];function analyticExtractedReport(_0x169911,_0x439215){var _0x4e9d9c={'status':_0x169911};var _0x48ea80={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x439215){_0x4e9d9c[_0xc97a('0x9')]=_0x439215;}return db['AnalyticExtractedReport'][_0xc97a('0xa')](_0x4e9d9c,_0x48ea80);}function main(){var _0x32264b=0x1388;var _0x59c3d0;logger[_0xc97a('0xb')](util[_0xc97a('0xc')](_0xc97a('0xd'),EXTRACTED_REPORT_ID,'XLSX'));return db['Setting'][_0xc97a('0xe')]({'where':{'id':0x1},'raw':!![],'attributes':['id',_0xc97a('0xf'),_0xc97a('0x10')]})['then'](function(_0x515fe6){if(_0x515fe6){_0x59c3d0=_0x515fe6;_0x32264b=_0x59c3d0[_0xc97a('0x10')]||0x1388;}})['then'](function(){return dbH['sequelize'][_0xc97a('0x11')](util['format'](_0xc97a('0x12'),QUERY),{'type':dbH[_0xc97a('0x13')][_0xc97a('0x14')]['SELECT']});})[_0xc97a('0x15')](function(_0x2a0209){if(!_0x2a0209[0x0]['num']){return analyticExtractedReport(_0xc97a('0x16'));}var _0xdb8af3=[];var _0x2682b5=0x0;var _0x295ac6=!![];if(_0x59c3d0[_0xc97a('0xf')]){if(_0x2a0209&&_0x2a0209[_0xc97a('0x17')]){var _0x545c05=_0x2a0209[0x0][_0xc97a('0x18')]%(_0x2682b5+_0x32264b);for(;_0x295ac6;_0x2682b5+=_0x32264b,_0x545c05=_0x2a0209[0x0]['num']%(_0x2682b5+_0x32264b)){if(_0x545c05==0x0||_0x545c05==_0x2a0209[0x0][_0xc97a('0x18')]){_0x295ac6=![];}_0xdb8af3[_0xc97a('0x19')](dbH['sequelize'][_0xc97a('0x11')](util[_0xc97a('0xc')]('%s\x20limit\x20%d\x20OFFSET\x20%d',QUERY,_0x32264b,_0x2682b5),{'type':dbH[_0xc97a('0x13')][_0xc97a('0x14')][_0xc97a('0x1a')]}));}}}else{_0xdb8af3['push'](dbH['sequelize']['query'](QUERY,{'type':dbH[_0xc97a('0x13')][_0xc97a('0x14')][_0xc97a('0x1a')]}));}var _0x259e9a=path[_0xc97a('0x1b')](PATH);var _0x965b79=path['basename'](PATH,_0xc97a('0x1c'));var _0x16152b=_0x59c3d0[_0xc97a('0xf')]&&_0xdb8af3['length']>0x1;var _0x508fe4=[];if(!fs[_0xc97a('0x1d')](path['join'](_0x259e9a,_0x965b79))&&_0x16152b){fs[_0xc97a('0x1e')](path['join'](_0x259e9a,_0x965b79));}return BPromise[_0xc97a('0x1f')](_0xdb8af3,function(_0x2916ad){_0x508fe4[_0xc97a('0x19')](_0x2916ad);})['then'](function(){for(var _0x49a526=0x0;_0x49a526<_0x508fe4[_0xc97a('0x17')];_0x49a526+=0x1){var _0x44d60a;var _0x408245=_0x508fe4[_0x49a526];if(_0x16152b){_0x44d60a=path[_0xc97a('0x20')](_0x259e9a,_0x965b79,util[_0xc97a('0xc')]('%s%d.%s',_0x965b79,_0x49a526,_0xc97a('0x21')));}else{_0x44d60a=path[_0xc97a('0x20')](_0x259e9a,util[_0xc97a('0xc')](_0xc97a('0x22'),_0x965b79,_0xc97a('0x21')));}fs[_0xc97a('0x23')](_0x44d60a,json2xls(_0x408245),_0xc97a('0x24'));}})['then'](function(){if(_0x16152b){zipdir(path[_0xc97a('0x20')](_0x259e9a,_0x965b79),{'saveTo':path[_0xc97a('0x20')](_0x259e9a,util[_0xc97a('0xc')](_0xc97a('0x22'),_0x965b79,_0xc97a('0x25')))},function(_0x3ba76f,_0x52ed6f){});rimraf(path[_0xc97a('0x20')](_0x259e9a,_0x965b79),function(){});}})['then'](function(){logger[_0xc97a('0xb')](util[_0xc97a('0xc')](_0xc97a('0x26'),EXTRACTED_REPORT_ID,_0xc97a('0x27')));return analyticExtractedReport(_0xc97a('0x28'),_0x16152b?util['format'](_0xc97a('0x22'),_0x965b79,_0x16152b?_0xc97a('0x25'):_0xc97a('0x21')):null);});})['catch'](function(_0x25973c){logger[_0xc97a('0xb')](util[_0xc97a('0xc')](_0xc97a('0x29'),EXTRACTED_REPORT_ID,'XLSX'),util['inspect'](_0x25973c,{'showHidden':![],'depth':null}));return analyticExtractedReport(_0xc97a('0x2a'));});}main();
\ No newline at end of file
+var _0x359c=['push','%s\x20limit\x20%d\x20OFFSET\x20%d','QueryTypes','SELECT','dirname','basename','.xlsx','existsSync','join','mkdirSync','%s%d.%s','xlsx','%s.%s','zip','zip\x20finished','info','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','inspect','Failed','finally','exit','util','path','lodash','json2xls','bluebird','zip-dir','rimraf','dbH','../../config/logger','analytics','argv','savename','AnalyticExtractedReport','update','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','XLSX','Setting','find','then','sequelize','query','Empty','length','isInteger','num','forEach'];(function(_0x5b54ce,_0x50a38c){var _0x5e9502=function(_0x18d11a){while(--_0x18d11a){_0x5b54ce['push'](_0x5b54ce['shift']());}};_0x5e9502(++_0x50a38c);}(_0x359c,0xa5));var _0xc359=function(_0x1f7fcc,_0x5a1912){_0x1f7fcc=_0x1f7fcc-0x0;var _0x12eeb0=_0x359c[_0x1f7fcc];return _0x12eeb0;};'use strict';var util=require(_0xc359('0x0'));var path=require(_0xc359('0x1'));var _=require(_0xc359('0x2'));var fs=require('fs');var json2xls=require(_0xc359('0x3'));var BPromise=require(_0xc359('0x4'));var zipdir=require(_0xc359('0x5'));var rimraf=require(_0xc359('0x6'));var db=require('../../mysqldb')['db'];var dbH=require('../../mysqldb')[_0xc359('0x7')];var logger=require(_0xc359('0x8'))(_0xc359('0x9'));var EXTRACTED_REPORT_ID=Number(process[_0xc359('0xa')][0x2]);var QUERY=process[_0xc359('0xa')][0x3];var PATH=process[_0xc359('0xa')][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0x1f612f,_0x306d9d){var _0x44a306={'status':_0x1f612f};var _0x332dd2={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x306d9d){_0x44a306[_0xc359('0xb')]=_0x306d9d;}return db[_0xc359('0xc')][_0xc359('0xd')](_0x44a306,_0x332dd2);}function main(){var _0x6dafab=0x1388;var _0x45de4b;logger['info'](util[_0xc359('0xe')](_0xc359('0xf'),EXTRACTED_REPORT_ID,_0xc359('0x10')));return db[_0xc359('0x11')][_0xc359('0x12')]({'where':{'id':0x1},'raw':!![],'attributes':['id','split','splitSizeXlsx']})['then'](function(_0xc52332){if(_0xc52332){_0x45de4b=_0xc52332;_0x6dafab=_0x45de4b['splitSizeXlsx']||0x1388;}})[_0xc359('0x13')](function(){return dbH[_0xc359('0x14')][_0xc359('0x15')](util[_0xc359('0xe')]('SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t',QUERY),{'type':dbH['sequelize']['QueryTypes']['SELECT']});})[_0xc359('0x13')](function(_0x2c628f){if(!_0x2c628f[0x0]['num']){return analyticExtractedReport(_0xc359('0x16'));}var _0x5b5008=[];var _0x1ec62c=0x0;if(_0x45de4b['split']){if(_0x2c628f&&_0x2c628f[_0xc359('0x17')]){var _0x5b41ce=_['range'](_0x2c628f[0x0]['num']/_0x6dafab);var _0xbd523b=Number[_0xc359('0x18')](_0x2c628f[0x0][_0xc359('0x19')]/_0x6dafab)?_0x2c628f[0x0]['num']%_0x6dafab:0x0;_0x5b41ce[_0xc359('0x1a')](function(_0x781589){if(_0x781589>0x0){_0x1ec62c+=_0x6dafab;}_0x5b5008[_0xc359('0x1b')](dbH[_0xc359('0x14')]['query'](util[_0xc359('0xe')](_0xc359('0x1c'),QUERY,_0x6dafab,_0x1ec62c),{'type':dbH[_0xc359('0x14')][_0xc359('0x1d')][_0xc359('0x1e')]}));});if(_0xbd523b>0x0){_0x1ec62c+=_0x6dafab;_0x5b5008[_0xc359('0x1b')](dbH[_0xc359('0x14')][_0xc359('0x15')](util[_0xc359('0xe')](_0xc359('0x1c'),QUERY,_0xbd523b,_0x1ec62c),{'type':dbH[_0xc359('0x14')]['QueryTypes'][_0xc359('0x1e')]}));}}}else{_0x5b5008[_0xc359('0x1b')](dbH[_0xc359('0x14')]['query'](QUERY,{'type':dbH['sequelize'][_0xc359('0x1d')]['SELECT']}));}var _0x1dcd75=path[_0xc359('0x1f')](PATH);var _0x3107d0=path[_0xc359('0x20')](PATH,_0xc359('0x21'));var _0x22c9b9=_0x45de4b['split']&&_0x5b5008[_0xc359('0x17')]>0x1;var _0x2b48fe=[];if(!fs[_0xc359('0x22')](path[_0xc359('0x23')](_0x1dcd75,_0x3107d0))&&_0x22c9b9){fs[_0xc359('0x24')](path[_0xc359('0x23')](_0x1dcd75,_0x3107d0));}return BPromise['each'](_0x5b5008,function(_0x7960f3){_0x2b48fe['push'](_0x7960f3);})['then'](function(){for(var _0x1e0137=0x0;_0x1e0137<_0x2b48fe[_0xc359('0x17')];_0x1e0137+=0x1){var _0x842276;var _0x7bd9a8=_0x2b48fe[_0x1e0137];if(_0x22c9b9){_0x842276=path[_0xc359('0x23')](_0x1dcd75,_0x3107d0,util['format'](_0xc359('0x25'),_0x3107d0,_0x1e0137,_0xc359('0x26')));}else{_0x842276=path['join'](_0x1dcd75,util[_0xc359('0xe')](_0xc359('0x27'),_0x3107d0,'xlsx'));}fs['writeFileSync'](_0x842276,json2xls(_0x7bd9a8),'binary');}})['then'](function(){if(_0x22c9b9){return new Promise(function(_0x4051fd){zipdir(path[_0xc359('0x23')](_0x1dcd75,_0x3107d0),{'saveTo':path[_0xc359('0x23')](_0x1dcd75,util[_0xc359('0xe')](_0xc359('0x27'),_0x3107d0,_0xc359('0x28')))},function(_0x80ecee,_0x2b748e){rimraf(path[_0xc359('0x23')](_0x1dcd75,_0x3107d0),function(){});_0x4051fd(_0xc359('0x29'));});});}})['then'](function(){logger[_0xc359('0x2a')](util[_0xc359('0xe')](_0xc359('0x2b'),EXTRACTED_REPORT_ID,_0xc359('0x10')));return analyticExtractedReport('Completed',_0x22c9b9?util[_0xc359('0xe')](_0xc359('0x27'),_0x3107d0,_0x22c9b9?'zip':_0xc359('0x26')):null);});})['catch'](function(_0x27e20e){logger[_0xc359('0x2a')](util[_0xc359('0xe')]('Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format',EXTRACTED_REPORT_ID,'XLSX'),util[_0xc359('0x2c')](_0x27e20e,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport(_0xc359('0x2d'));})[_0xc359('0x2e')](function(){process[_0xc359('0x2f')](EXIT_CODE);});}main();
\ No newline at end of file