浏览代码

导出excel(all in one book)的边框控制 + 多张报表的横向纵向控制调整 + cron job的代码移动

TonyKang 6 年之前
父节点
当前提交
97528ff1a6

+ 2 - 3
modules/reports/controllers/rpt_controller.js

@@ -225,7 +225,7 @@ function getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, custo
                     let printCom = JpcEx.createNew();
                     if (pageSize) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE] = pageSize;
                     //console.log("orientation: " + (orientation === 'null'));
-                    if (orientation !== null && orientation !== 'null') rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = orientation;
+                    if (orientation && (orientation !== 'null')) rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] = orientation;
                     let defProperties = rptUtil.getReportDefaultCache();
                     if (customizeCfg) setupCustomizeCfg(customizeCfg, rptTpl, defProperties);
                     let dftOption = option||JV.PAGING_OPTION_NORMAL;
@@ -374,8 +374,7 @@ module.exports = {
                     getAllPagesCommon(user_id, prj_id, rpt_id, pageSize, orientation, customizeCfg, dftOption, function (err, pageRst) {
                         if(err){
                             cb(err);
-                        }
-                        else{
+                        } else {
                             rpt_xl_util.exportExcel(pageRst, pageSize, rpt_name, isOneSheet, null, null, function(uuidName){
                                 let fileRst = {uuid: uuidName, reportName: rpt_name};
                                 cb(err, fileRst);

+ 12 - 2
modules/reports/util/rpt_excel_util.js

@@ -346,7 +346,8 @@ function writeSheets(pageData, paperSize, sharedStrList, stylesObj, isSinglePage
     return rst;
 }
 function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, appointedMergeBand){
-    let rst = [], xPos = [], yPos = [], yMultiPos = [], headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+    let rst = [], xPos = [], yPos = [], yMultiPos = [], currentMergeBorder = null,
+        headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     let currentPageMergePos = null; //在 JV.PAGING_OPTION_INFINITY 场合应用
     let private_pre_analyze_pos = function(){
         let cell, pos;
@@ -508,7 +509,8 @@ function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, ap
     };
     let private_chkAndGetMergeLine = function(cell, sheetBorder, borderStr, needFurtherChk) {
         let rst = 0,
-            mergeBorder = (sheetData)?sheetData[JV.PROP_PAGE_MERGE_BORDER]:pageData[JV.BAND_PROP_MERGE_BAND],
+            // mergeBorder = (sheetData)?sheetData[JV.PROP_PAGE_MERGE_BORDER]:pageData[JV.BAND_PROP_MERGE_BAND],
+            mergeBorder = currentMergeBorder,
             mergeBand = pageData[JV.BAND_PROP_MERGE_BAND]
         ;
         if (appointedMergeBand !== null) {
@@ -758,6 +760,7 @@ function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, ap
         if (sheetData) {
             //current sheet data
             currentPageMergePos = sheetData[JV.PAGE_SPECIAL_MERGE_POS];
+            currentMergeBorder = sheetData[JV.PROP_PAGE_MERGE_BORDER];
             self_setDataEx(sheetData, yPos, 0);
         } else {
             //total data in one sheet
@@ -765,6 +768,7 @@ function writeSheet(pageData, sheetData, paperSize, sharedStrList, stylesObj, ap
             for (let i = 0; i < pageData.items.length; i++) {
                 let shtItemData = pageData.items[i];
                 currentPageMergePos = shtItemData[JV.PAGE_SPECIAL_MERGE_POS];
+                currentMergeBorder = shtItemData[JV.PROP_PAGE_MERGE_BORDER];
                 let tmpPos = yMultiPos[i];
                 cellIdx = 0;
                 self_setDataEx(shtItemData, tmpPos, cnt);
@@ -939,6 +943,7 @@ module.exports = {
                 let offsetY = 0;
                 let mergeBand = {};
                 custMergeBands.push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND]);
+                //备注:不同的报表有可能有不同的边框,如封面表就是无边框的
                 mergeBand[JV.PROP_LEFT] = [];
                 mergeBand[JV.PROP_RIGHT] = [];
                 mergeBand[JV.PROP_TOP] = [];
@@ -955,6 +960,11 @@ module.exports = {
                         mergeBand[JV.PROP_TOP].push(pos);
                         pos = pageDataArray[i].items[j][JV.PAGE_SPECIAL_MERGE_POS][JV.PROP_BOTTOM][0] + offsetY;
                         mergeBand[JV.PROP_BOTTOM].push(pos);
+                    } else if (pageDataArray[i].items[j][JV.PROP_PAGE_MERGE_BORDER]) {
+                        let pos = pageDataArray[i].items[j][JV.PROP_PAGE_MERGE_BORDER][JV.PROP_TOP] + offsetY;
+                        mergeBand[JV.PROP_TOP].push(pos);
+                        pos = pageDataArray[i].items[j][JV.PROP_PAGE_MERGE_BORDER][JV.PROP_BOTTOM] + offsetY;
+                        mergeBand[JV.PROP_BOTTOM].push(pos);
                     } else {
                         mergeBand[JV.PROP_TOP].push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND][JV.PROP_TOP] + offsetY);
                         mergeBand[JV.PROP_BOTTOM].push(pageDataArray[i][JV.BAND_PROP_MERGE_BAND][JV.PROP_BOTTOM] + offsetY);

+ 53 - 0
modules/reports/util/rpt_tmp_file_sweep.js

@@ -0,0 +1,53 @@
+/**
+ * Created by Tony on 2018/7/27.
+ */
+
+let fs = require('fs');
+let cron = require('node-schedule');
+let remove_file_types = [".xlsx", ".pdf", ".jsp"];
+function chkIsRemoveType(file) {
+    let rst = false;
+    for (let fType of remove_file_types) {
+        if (file.indexOf(fType) === (file.length - fType.length)) {
+            rst = true;
+            break;
+        }
+    }
+    return rst;
+}
+let jobObj = {
+    createJob: function (rule, rootPath) {
+        let localRule = rule;
+        if (!localRule) {
+            // setup schedule rule
+            localRule = new cron.RecurrenceRule();
+            // 3:15AM, everyday
+            localRule.dayOfWeek = [1,2,3,4,5,6,0];
+            localRule.hour = 3;
+            localRule.minute = 15;
+        }
+        cron.scheduleJob(localRule, function(){
+            let path = rootPath;
+            fs.exists(path, function (exists) {
+                if (exists) {
+                    fs.readdir(path, function (err, files) {
+                        let currentTime = (new Date()).valueOf();
+                        let timeGap = currentTime - (1000 * 60 * 60 * 24 * 0.5); //half day before
+                        files.forEach(function(file,index){
+                            if (chkIsRemoveType(file)) {
+                                let curPath = path + "/" + file;
+                                fs.stat(curPath,function(err,data){
+                                    if (timeGap > data.mtime) {
+                                        fs.unlink(curPath);
+                                    }
+                                });
+                            }
+                        });
+                    })
+                }
+            })
+        });
+    }
+};
+
+export default jobObj;

+ 5 - 33
server.js

@@ -13,7 +13,7 @@ let DBStore = require('connect-mongo')(session);
 let fs = require('fs');
 
 let URL = require('url');
-let cron = require('node-schedule');
+import rptCronJob from "./modules/reports/util/rpt_tmp_file_sweep";
 
 dbm.connect(process.env.NODE_ENV);
 //这里现在只引入了定额工料机里的models,当其它模块的models修改后使用:./modules/**/models/*.js引入所有的模块
@@ -103,13 +103,9 @@ app.use(function(err, req, res, next) {
     res.status(500).send('500 Error');
 });
 
-//设置Date Format函数
+//设置外增的Date对象Format函数
 fs.readFile(__dirname + '/public/web/date_util.js', 'utf8', 'r', function (err, data) {
     eval(data);
-    // let dt = new Date();
-    // console.log(dt.Format('yyyy-M-dd'));
-    // console.log(dt.Format('yyyy 年 M 月 dd 日'));
-    // console.log(dt.Format('yyyy 年 M 月 20 日'));
 });
 
 app.listen(6060, function(){
@@ -117,30 +113,6 @@ app.listen(6060, function(){
 });
 
 //设置schedule job
-let rule = new cron.RecurrenceRule();
-//1. 每天凌晨3点一刻,删除临时文件
-rule.dayOfWeek = [1,2,3,4,5,6,0];
-rule.hour = 3;
-rule.minute = 15;
-cron.scheduleJob(rule, function(){
-    let path = __dirname + "/tmp";
-    fs.exists(path, function (exists) {
-        if (exists) {
-            fs.readdir(path, function (err, files) {
-                let currentTime = (new Date()).valueOf();
-                let timeGap = currentTime - (1000 * 60 * 60 * 24 * 0.5);
-                files.forEach(function(file,index){
-                    if (file.indexOf(".xlsx") === (file.length - 5) ||
-                        file.indexOf(".pdf") === (file.length - 4)) {
-                        let curPath = path + "/" + file;
-                        fs.stat(curPath,function(err,data){
-                            if (timeGap > data.mtime) {
-                                fs.unlink(curPath);
-                            }
-                        });
-                    }
-                });
-            })
-        }
-    })
-});
+//1. 报表临时文件
+rptCronJob.createJob(null, __dirname + "/tmp");
+//2. 其他(待补充)...

+ 6 - 2
test/unit/reports/test_rpt_test_template.js

@@ -28,10 +28,10 @@ let fsUtil = require("../../../public/fsUtil");
 let demoPrjId = - 1;
 // let demoRptId = 279;
 // let demoRptId = 275; //测试模板-流水式
-// let demoRptId = 337; //19表
+let demoRptId = 337; //19表
 // let demoRptId = 361; //封1
 // let demoRptId = 279; //表04
-let demoRptId = 261; //封3
+// let demoRptId = 261; //封3
 let pagesize = "A4";
 //288: 11-2表(新)
 //279: 04
@@ -51,6 +51,7 @@ let rptTplFacade = require("../../../modules/reports/facade/rpt_template_facade"
 let rptTplDataFacade = require("../../../modules/reports/facade/rpt_tpl_data_facade");
 
 import rptDataExtractor from "../../../modules/reports/util/rpt_construct_data_util";
+import rpt_xl_util from "../../../modules/reports/util/rpt_excel_util";
 
 let fs = require('fs');
 //设置Date Format函数
@@ -83,6 +84,9 @@ test('测试 - 测试模板啦: ', function (t) {
                     let pageRst = printCom.outputAsSimpleJSONPageArray(rptTpl, tplData, 1, maxPages, defProperties);
                     if (pageRst) {
                         fsUtil.writeObjToFile(pageRst, "D:/GitHome/ConstructionCost/tmp/testBuiltPageResult_测试模板.jsp");
+                        rpt_xl_util.exportExcel(pageRst, pagesize, "local_test_rpt_excel", true, null, null, function(uuidName){
+                            console.log("excel uuid: " + uuidName);
+                        });
                     } else {
                         console.log("oh! no pages were created!");
                     }

+ 1 - 1
web/building_saas/report/html/rpt_content_format.html

@@ -39,8 +39,8 @@
             <div class="modal-footer">
                 <button type="button" class="btn btn-link float-left" onclick="rptControlObj.restoreCustCFG()">恢复默认值</button>
                 <button type="button" class="btn btn-link float-left" onclick="rptControlObj.saveCustCfg()">存为默认值</button>
-                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                 <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="rptControlObj.confirmCfgChange()">确定</button>
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
             </div>
         </div>
     </div>

+ 4 - 10
web/building_saas/report/html/rpt_main.html

@@ -4,7 +4,9 @@
         <div class="col-lg-2 p-0">
             <div class="print-list">
                 <div class="list-tools d-flex justify-content-center">
-                    <button class="btn btn-outline-primary btn-sm" data-toggle="modal" data-target="#editForm"><i class="fa fa-cog"></i> 管理报表</button>
+                    <!--
+                        <button class="btn btn-outline-primary btn-sm" data-toggle="modal" data-target="#editForm"><i class="fa fa-cog"></i> 管理报表</button>
+                    -->
                 </div>
                 <div class="form-list">
                     <ul id="rptTplTree" class="ztree"></ul>
@@ -19,11 +21,6 @@
                             <button class="btn btn-outline-primary btn-sm" type="button" onclick="rptPrintHelper.preview()">
                                 <i class="fa fa-print"></i><br>打印<span class="badge badge-secondary">0</span>
                             </button>
-                            <!--
-                            <button class="btn btn-outline-primary btn-sm" type="button"  href="#export" data-toggle="modal" data-target="#export">
-                                <i class="fa fa-share-square-o"></i><br>导出
-                            </button>
-                            -->
                         </div>
                     </div>
                     <div class="panel">
@@ -63,10 +60,7 @@
                         <div class="panel-body">
                             <div class="btn-group" role="group" aria-label="Button group with nested dropdown">
                                 <button type="button" class="btn btn-outline-primary btn-sm" data-toggle="modal" data-target="#paper_margins"><i class="fa fa-file-o"></i> 页边距</button>
-                                <button type="button" class="btn btn-outline-primary btn-sm" data-toggle="modal" data-target="#content_format"><i class="fa fa-file-text-o"></i> 页面</button>
-                                <!--
-                                <button type="button" class="btn btn-outline-primary btn-sm" data-toggle="modal" data-target="#format"><i class="fa fa-bold"></i> 格式</button>
-                                -->
+                                <button type="button" class="btn btn-outline-primary btn-sm" data-toggle="modal" data-target="#content_format"><i class="fa fa-bold"></i> 页面</button>
                             </div>
                         </div>
                         <div class="panel-foot text-muted">

+ 1 - 1
web/building_saas/report/html/rpt_margins.html

@@ -29,8 +29,8 @@
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-link float-left" data-dismiss="modal" onclick="rptControlObj.saveCustCfg()">存为默认值</button>
-                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                 <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="rptControlObj.confirmCfgChange()">确定</button>
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
             </div>
         </div>
     </div>