Built motion from commit da24aabd.|2.6.20
[motion2.git] / server / components / export / xlsx.js
index 75eaf69..02b0b5a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4fdb=['XLSX','Setting','find','splitSizeXlsx','then','sequelize','query','SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t','QueryTypes','SELECT','num','length','push','dirname','basename','.xlsx','existsSync','join','xlsx','%s.%s','binary','zip','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','inspect','Failed','util','path','lodash','json2xls','zip-dir','rimraf','../../mysqldb','dbH','../../config/logger','analytics','argv','savename','AnalyticExtractedReport','update','info','format','Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format'];(function(_0x31cb5f,_0x2df766){var _0x586042=function(_0x53c807){while(--_0x53c807){_0x31cb5f['push'](_0x31cb5f['shift']());}};_0x586042(++_0x2df766);}(_0x4fdb,0xa3));var _0xb4fd=function(_0x197f36,_0x1e2e51){_0x197f36=_0x197f36-0x0;var _0x5c4079=_0x4fdb[_0x197f36];return _0x5c4079;};'use strict';var util=require(_0xb4fd('0x0'));var path=require(_0xb4fd('0x1'));var _=require(_0xb4fd('0x2'));var fs=require('fs');var json2xls=require(_0xb4fd('0x3'));var BPromise=require('bluebird');var zipdir=require(_0xb4fd('0x4'));var rimraf=require(_0xb4fd('0x5'));var db=require(_0xb4fd('0x6'))['db'];var dbH=require('../../mysqldb')[_0xb4fd('0x7')];var logger=require(_0xb4fd('0x8'))(_0xb4fd('0x9'));var EXTRACTED_REPORT_ID=Number(process[_0xb4fd('0xa')][0x2]);var QUERY=process[_0xb4fd('0xa')][0x3];var PATH=process[_0xb4fd('0xa')][0x4];function analyticExtractedReport(_0x3e295a,_0x538085){var _0x53f71e={'status':_0x3e295a};var _0x25809e={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x538085){_0x53f71e[_0xb4fd('0xb')]=_0x538085;}return db[_0xb4fd('0xc')][_0xb4fd('0xd')](_0x53f71e,_0x25809e);}function main(){var _0x350a7c=0x1388;var _0x1b01b8;logger[_0xb4fd('0xe')](util[_0xb4fd('0xf')](_0xb4fd('0x10'),EXTRACTED_REPORT_ID,_0xb4fd('0x11')));return db[_0xb4fd('0x12')][_0xb4fd('0x13')]({'where':{'id':0x1},'raw':!![],'attributes':['id','split',_0xb4fd('0x14')]})['then'](function(_0x2188a7){if(_0x2188a7){_0x1b01b8=_0x2188a7;_0x350a7c=_0x1b01b8[_0xb4fd('0x14')]||0x1388;}})[_0xb4fd('0x15')](function(){return dbH[_0xb4fd('0x16')][_0xb4fd('0x17')](util[_0xb4fd('0xf')](_0xb4fd('0x18'),QUERY),{'type':dbH[_0xb4fd('0x16')][_0xb4fd('0x19')][_0xb4fd('0x1a')]});})[_0xb4fd('0x15')](function(_0x2ff205){if(!_0x2ff205[0x0][_0xb4fd('0x1b')]){return analyticExtractedReport('Empty');}var _0x2a1ff6=[];var _0x38b46f=0x0;var _0x27abbd=!![];if(_0x1b01b8['split']){if(_0x2ff205&&_0x2ff205[_0xb4fd('0x1c')]){var _0x4aaba8=_0x2ff205[0x0][_0xb4fd('0x1b')]%(_0x38b46f+_0x350a7c);for(;_0x27abbd;_0x38b46f+=_0x350a7c,_0x4aaba8=_0x2ff205[0x0]['num']%(_0x38b46f+_0x350a7c)){if(_0x4aaba8==0x0||_0x4aaba8==_0x2ff205[0x0][_0xb4fd('0x1b')]){_0x27abbd=![];}_0x2a1ff6[_0xb4fd('0x1d')](dbH[_0xb4fd('0x16')]['query'](util['format']('%s\x20limit\x20%d\x20OFFSET\x20%d',QUERY,_0x350a7c,_0x38b46f),{'type':dbH[_0xb4fd('0x16')]['QueryTypes']['SELECT']}));}}}else{_0x2a1ff6['push'](dbH[_0xb4fd('0x16')][_0xb4fd('0x17')](QUERY,{'type':dbH[_0xb4fd('0x16')][_0xb4fd('0x19')][_0xb4fd('0x1a')]}));}var _0x9e9b09=path[_0xb4fd('0x1e')](PATH);var _0xc535b3=path[_0xb4fd('0x1f')](PATH,_0xb4fd('0x20'));var _0x54385c=_0x1b01b8['split']&&_0x2a1ff6[_0xb4fd('0x1c')]>0x1;var _0x3dfa25=[];if(!fs[_0xb4fd('0x21')](path[_0xb4fd('0x22')](_0x9e9b09,_0xc535b3))&&_0x54385c){fs['mkdirSync'](path[_0xb4fd('0x22')](_0x9e9b09,_0xc535b3));}return BPromise['each'](_0x2a1ff6,function(_0x205a89){_0x3dfa25[_0xb4fd('0x1d')](_0x205a89);})[_0xb4fd('0x15')](function(){for(var _0x22fc27=0x0;_0x22fc27<_0x3dfa25[_0xb4fd('0x1c')];_0x22fc27+=0x1){var _0x2e9e2c;var _0x2ccca9=_0x3dfa25[_0x22fc27];if(_0x54385c){_0x2e9e2c=path[_0xb4fd('0x22')](_0x9e9b09,_0xc535b3,util[_0xb4fd('0xf')]('%s%d.%s',_0xc535b3,_0x22fc27,_0xb4fd('0x23')));}else{_0x2e9e2c=path[_0xb4fd('0x22')](_0x9e9b09,util[_0xb4fd('0xf')](_0xb4fd('0x24'),_0xc535b3,_0xb4fd('0x23')));}fs['writeFileSync'](_0x2e9e2c,json2xls(_0x2ccca9),_0xb4fd('0x25'));}})[_0xb4fd('0x15')](function(){if(_0x54385c){zipdir(path[_0xb4fd('0x22')](_0x9e9b09,_0xc535b3),{'saveTo':path['join'](_0x9e9b09,util['format']('%s.%s',_0xc535b3,_0xb4fd('0x26')))},function(_0x587ba1,_0x1f8e5e){});rimraf(path[_0xb4fd('0x22')](_0x9e9b09,_0xc535b3),function(){});}})[_0xb4fd('0x15')](function(){logger['info'](util[_0xb4fd('0xf')](_0xb4fd('0x27'),EXTRACTED_REPORT_ID,_0xb4fd('0x11')));return analyticExtractedReport(_0xb4fd('0x28'),_0x54385c?util[_0xb4fd('0xf')](_0xb4fd('0x24'),_0xc535b3,_0x54385c?_0xb4fd('0x26'):_0xb4fd('0x23')):null);});})[_0xb4fd('0x29')](function(_0x4f5921){logger[_0xb4fd('0xe')](util[_0xb4fd('0xf')](_0xb4fd('0x2a'),EXTRACTED_REPORT_ID,'XLSX'),util[_0xb4fd('0x2b')](_0x4f5921,{'showHidden':![],'depth':null}));return analyticExtractedReport(_0xb4fd('0x2c'));});}main();
\ No newline at end of file
+var _0x61c0=['query','format','sequelize','QueryTypes','SELECT','num','length','isInteger','forEach','push','%s\x20limit\x20%d\x20OFFSET\x20%d','dirname','.xlsx','each','join','%s%d.%s','xlsx','writeFileSync','binary','%s.%s','zip','zip\x20finished','Extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format\x20completed','XLSX','catch','Error\x20during\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format','finally','exit','util','lodash','json2xls','bluebird','zip-dir','rimraf','../../mysqldb','dbH','analytics','argv','savename','update','info','Setting','split','splitSizeXlsx','then'];(function(_0xea343d,_0x311197){var _0x2c6e9c=function(_0x454bd6){while(--_0x454bd6){_0xea343d['push'](_0xea343d['shift']());}};_0x2c6e9c(++_0x311197);}(_0x61c0,0x1b1));var _0x061c=function(_0x1a550a,_0x238578){_0x1a550a=_0x1a550a-0x0;var _0xee8d93=_0x61c0[_0x1a550a];return _0xee8d93;};'use strict';var util=require(_0x061c('0x0'));var path=require('path');var _=require(_0x061c('0x1'));var fs=require('fs');var json2xls=require(_0x061c('0x2'));var BPromise=require(_0x061c('0x3'));var zipdir=require(_0x061c('0x4'));var rimraf=require(_0x061c('0x5'));var db=require(_0x061c('0x6'))['db'];var dbH=require(_0x061c('0x6'))[_0x061c('0x7')];var logger=require('../../config/logger')(_0x061c('0x8'));var EXTRACTED_REPORT_ID=Number(process['argv'][0x2]);var QUERY=process[_0x061c('0x9')][0x3];var PATH=process[_0x061c('0x9')][0x4];var EXIT_CODE=0x0;function analyticExtractedReport(_0x4c2c49,_0x5a12bc){var _0x331246={'status':_0x4c2c49};var _0x366e51={'where':{'id':EXTRACTED_REPORT_ID}};if(_0x5a12bc){_0x331246[_0x061c('0xa')]=_0x5a12bc;}return db['AnalyticExtractedReport'][_0x061c('0xb')](_0x331246,_0x366e51);}function main(){var _0x275825=0x1388;var _0x562d74;logger[_0x061c('0xc')](util['format']('Start\x20extraction\x20report\x20with\x20id\x20%d\x20in\x20%s\x20format',EXTRACTED_REPORT_ID,'XLSX'));return db[_0x061c('0xd')]['find']({'where':{'id':0x1},'raw':!![],'attributes':['id',_0x061c('0xe'),_0x061c('0xf')]})[_0x061c('0x10')](function(_0xe3b2be){if(_0xe3b2be){_0x562d74=_0xe3b2be;_0x275825=_0x562d74[_0x061c('0xf')]||0x1388;}})[_0x061c('0x10')](function(){return dbH['sequelize'][_0x061c('0x11')](util[_0x061c('0x12')]('SELECT\x20count(*)\x20as\x20num\x20FROM\x20(%s)\x20t',QUERY),{'type':dbH[_0x061c('0x13')][_0x061c('0x14')][_0x061c('0x15')]});})['then'](function(_0x2f601e){if(!_0x2f601e[0x0][_0x061c('0x16')]){return analyticExtractedReport('Empty');}var _0x4d9cc0=[];var _0x57daf5=0x0;if(_0x562d74['split']){if(_0x2f601e&&_0x2f601e[_0x061c('0x17')]){var _0x12551c=_['range'](_0x2f601e[0x0][_0x061c('0x16')]/_0x275825);var _0x26e192=Number[_0x061c('0x18')](_0x2f601e[0x0]['num']/_0x275825)?_0x2f601e[0x0][_0x061c('0x16')]%_0x275825:0x0;_0x12551c[_0x061c('0x19')](function(_0x3d608e){if(_0x3d608e>0x0){_0x57daf5+=_0x275825;}_0x4d9cc0['push'](dbH['sequelize'][_0x061c('0x11')](util[_0x061c('0x12')]('%s\x20limit\x20%d\x20OFFSET\x20%d',QUERY,_0x275825,_0x57daf5),{'type':dbH[_0x061c('0x13')][_0x061c('0x14')]['SELECT']}));});if(_0x26e192>0x0){_0x57daf5+=_0x275825;_0x4d9cc0[_0x061c('0x1a')](dbH[_0x061c('0x13')][_0x061c('0x11')](util['format'](_0x061c('0x1b'),QUERY,_0x26e192,_0x57daf5),{'type':dbH['sequelize'][_0x061c('0x14')]['SELECT']}));}}}else{_0x4d9cc0[_0x061c('0x1a')](dbH[_0x061c('0x13')][_0x061c('0x11')](QUERY,{'type':dbH[_0x061c('0x13')][_0x061c('0x14')]['SELECT']}));}var _0x39aaf1=path[_0x061c('0x1c')](PATH);var _0xfc1378=path['basename'](PATH,_0x061c('0x1d'));var _0x42871f=_0x562d74[_0x061c('0xe')]&&_0x4d9cc0[_0x061c('0x17')]>0x1;var _0x325a15=[];if(!fs['existsSync'](path['join'](_0x39aaf1,_0xfc1378))&&_0x42871f){fs['mkdirSync'](path['join'](_0x39aaf1,_0xfc1378));}return BPromise[_0x061c('0x1e')](_0x4d9cc0,function(_0x389e5e){_0x325a15[_0x061c('0x1a')](_0x389e5e);})[_0x061c('0x10')](function(){for(var _0x51a0a3=0x0;_0x51a0a3<_0x325a15['length'];_0x51a0a3+=0x1){var _0x4938bd;var _0x530e1f=_0x325a15[_0x51a0a3];if(_0x42871f){_0x4938bd=path[_0x061c('0x1f')](_0x39aaf1,_0xfc1378,util['format'](_0x061c('0x20'),_0xfc1378,_0x51a0a3,_0x061c('0x21')));}else{_0x4938bd=path['join'](_0x39aaf1,util[_0x061c('0x12')]('%s.%s',_0xfc1378,_0x061c('0x21')));}fs[_0x061c('0x22')](_0x4938bd,json2xls(_0x530e1f),_0x061c('0x23'));}})['then'](function(){if(_0x42871f){return new Promise(function(_0x58eb6f){zipdir(path['join'](_0x39aaf1,_0xfc1378),{'saveTo':path[_0x061c('0x1f')](_0x39aaf1,util[_0x061c('0x12')](_0x061c('0x24'),_0xfc1378,_0x061c('0x25')))},function(_0xaa6847,_0x16e8e9){rimraf(path[_0x061c('0x1f')](_0x39aaf1,_0xfc1378),function(){});_0x58eb6f(_0x061c('0x26'));});});}})[_0x061c('0x10')](function(){logger[_0x061c('0xc')](util[_0x061c('0x12')](_0x061c('0x27'),EXTRACTED_REPORT_ID,_0x061c('0x28')));return analyticExtractedReport('Completed',_0x42871f?util[_0x061c('0x12')](_0x061c('0x24'),_0xfc1378,_0x42871f?_0x061c('0x25'):_0x061c('0x21')):null);});})[_0x061c('0x29')](function(_0x534bda){logger[_0x061c('0xc')](util[_0x061c('0x12')](_0x061c('0x2a'),EXTRACTED_REPORT_ID,'XLSX'),util['inspect'](_0x534bda,{'showHidden':![],'depth':null}));EXIT_CODE=0x1;return analyticExtractedReport('Failed');})[_0x061c('0x2b')](function(){process[_0x061c('0x2c')](EXIT_CODE);});}main();
\ No newline at end of file