Pārlūkot izejas kodu

增加计算式模板选择

TonyKang 6 gadi atpakaļ
vecāks
revīzija
d018297579

+ 12 - 1
modules/all_models/rpt_template.js

@@ -27,6 +27,17 @@ let RptTemplateSchema = new Schema({
     "计算式_集合": Array
 });
 
-let Template = mongoose.model("rpt_templates", RptTemplateSchema, "rpt_templates");
+let RptTplExtCodeSchema = new Schema({
+    "Name": String,
+    "Type": String,
+    "Description": String,
+    "Template": String,
+    "items": Array
+});
+
+mongoose.model("rpt_templates", RptTemplateSchema, "rpt_templates");
+mongoose.model("rpt_ext_code_tpl", RptTplExtCodeSchema, "rpt_ext_code_tpl");
+
+//rpt_ext_code_tpl
 
 // export {Template as default};

+ 12 - 2
modules/reports/controllers/rpt_tpl_controller.js

@@ -9,6 +9,7 @@ import counter from "../../../public/counter/counter";
 
 let RptTplModel = mongoose.model('rpt_templates');
 let TreeNodeModel = mongoose.model('rpt_tpl_tree');
+let rptExtCodeModel = mongoose.model('rpt_ext_code_tpl');
 
 let rptCustCfgFacade = require("../facade/rpt_cust_cfg_facade");
 
@@ -22,7 +23,7 @@ let callback = function(req, res, err, message, data){
 };
 
 let mExport = {
-    getCustomerCfg(req, res) {
+    getCustomerCfg: function(req, res) {
         let params = JSON.parse(req.body.params),
             userId = params.userId,
             me = this;
@@ -82,7 +83,7 @@ let mExport = {
             }
         })
     },
-    getDftTemplates(req, res) {
+    getDftTemplates: function(req, res) {
         let filter = {"userId": "-100", "$or": [{"isDeleted": null}, {"isDeleted": false} ]};
         TreeNodeModel.find(filter, '-_id', function(err, data){
             if (err) {
@@ -92,6 +93,15 @@ let mExport = {
             }
         });
     },
+    getExtCodeTpl: function(req, res) {
+        rptExtCodeModel.find({}).exec().then(function(rstCodeTpl) {
+            if (rstCodeTpl) {
+                callback(req,res, false, "", rstCodeTpl);
+            } else {
+                callback(req, res, 'The report template was not found!', null);
+            }
+        })
+    },
     getCompilationList(req, res) {
         let compilationModel = new CompilationModel();
         let compilationList = compilationModel.getCompilationList();

+ 7 - 1
modules/reports/facade/rpt_template_facade.js

@@ -3,12 +3,18 @@
  */
 import mongoose from "mongoose";
 let rpt_tpl_mdl = mongoose.model("rpt_templates");
+let rpt_tpl_ext_code_mdl = mongoose.model("rpt_ext_code_tpl");
 
 module.exports = {
-    getRptTemplate: getRptTemplate
+    getRptTemplate: getRptTemplate,
+    getExtCodeTpl: getExtCodeTpl
 };
 
 async function getRptTemplate(tplId) {
     //console.log('templateId: ' + parseInt(tplId));
     return await  rpt_tpl_mdl.findOne({"ID": parseInt(tplId)}, '-_id');
 }
+
+async function getExtCodeTpl() {
+    return await  rpt_tpl_ext_code_mdl.find({});
+}

+ 1 - 0
modules/reports/routes/rpt_tpl_router.js

@@ -36,6 +36,7 @@ module.exports = function (app) {
     rptTplRouter.post('/getCompilationList', reportTplController.getCompilationList);
     rptTplRouter.post('/getCustomizeCfg', reportTplController.getCustomerCfg);
     rptTplRouter.post('/saveCustomerCfg', reportTplController.saveCustomerCfg);
+    rptTplRouter.post('/getExtCodeTpl', reportTplController.getExtCodeTpl);
 
     rptTplRouter.post('/getUserRptCfg', reportCfgController.getReportUserCfg);
     rptTplRouter.post('/getMappingFields', reportCfgController.getAllMappingFields);

+ 3 - 0
modules/reports/rpt_component/helper/jpc_helper_field.js

@@ -29,6 +29,7 @@ let JpcFieldHelper = {
         return rst;
     },
     resetFormat: function (tab_field, map_field, customizeCfg) {
+        let rst = false;
         if (map_field && map_field[JV.PROP_PRECISION] && map_field[JV.PROP_PRECISION].type === "fixed") {
             let formatStrs = ["#."], ffStr = (customizeCfg && customizeCfg.fillZero)?"0":"#";
             for (let idx = 0; idx < parseInt(map_field[JV.PROP_FIXED_PRECISION_AMT]); idx++) {
@@ -40,7 +41,9 @@ let JpcFieldHelper = {
                 tab_field[JV.PROP_FORMAT] = formatStrs.join("");
             }
             map_field[JV.PROP_FORMAT] = tab_field[JV.PROP_FORMAT]; //这里顺手把format也赋给map_field,后期统计用得着
+            rst = true;
         }
+        return rst;
     },
     resetFlexibleFormat: function (tab_field, ref_field_data, flexiblePrecisionRefObj, valueIdx, customizeCfg) {
         let precisionAmt = 2;

+ 13 - 9
modules/reports/rpt_component/jpc_flow_tab.js

@@ -749,9 +749,9 @@ JpcFlowTabSrv.prototype.createNew = function(){
             // 2.2 Column tab
             tabRstLst.push(me.outputColumn(rptTpl, dataObj, page, segIdx, bands, unitFactor, 0));
             // 2.3 Sum Seg
-            tabRstLst.push(me.outputSegSum(rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT));
+            tabRstLst.push(me.outputSegSum(rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg));
             // 2.4 Sum Page
-            tabRstLst.push(me.outputPageSum(rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT));
+            tabRstLst.push(me.outputPageSum(rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg));
             // 2.5 Group
             // 2.6 Discrete
             tabRstLst.push(JpcDiscreteHelper.outputDiscreteInfo(rptTpl[FLOW_NODE_STR][JV.NODE_DISCRETE_INFO], bands, dataObj, unitFactor, me.pageStatusLst[page - 1], segIdx, 1, 0, $CURRENT_RPT, customizeCfg));
@@ -783,9 +783,9 @@ JpcFlowTabSrv.prototype.createNew = function(){
                 // 2.2 Column tab
                 tabRstLst.push(me.outputColumn(rptTpl, dataObj, actualPage, segIdx, bands, unitFactor, pi));
                 // 2.3 Sum Seg
-                tabRstLst.push(me.outputSegSum(rptTpl, dataObj, actualPage, segIdx, bands, unitFactor, controls, $CURRENT_RPT));
+                tabRstLst.push(me.outputSegSum(rptTpl, dataObj, actualPage, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg));
                 // 2.4 Sum Page
-                tabRstLst.push(me.outputPageSum(rptTpl, dataObj, actualPage, segIdx, bands, unitFactor, controls, $CURRENT_RPT));
+                tabRstLst.push(me.outputPageSum(rptTpl, dataObj, actualPage, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg));
                 // 2.5 Group
                 // 2.6 Discrete
                 if (pi === 0) {
@@ -1023,7 +1023,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
         }
         return rst;
     };
-    JpcFlowTabResult.outputSegSum = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT) {
+    JpcFlowTabResult.outputSegSum = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg) {
         let me = this, rst = [];
         let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
         let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_SEG_SUM];
@@ -1040,7 +1040,8 @@ JpcFlowTabSrv.prototype.createNew = function(){
                     if (!JpcFieldHelper.resetSumFormat(ref_tab_fields, tab_fields[i])) {
                         if (!JpcFieldHelper.resetSumFormat(ref_tab_fields_ex, tab_fields[i])) {
                             let map_data_field = JE.F(tab_fields[i][JV.PROP_FIELD_ID], $CURRENT_RPT);
-                            tab_fields[i][JV.PROP_FORMAT] = map_data_field[JV.PROP_FORMAT];
+                            JpcFieldHelper.resetFormat(tab_fields[i], map_data_field, customizeCfg)
+                            //如果都找不到,就得靠自己的Format属性了
                         }
                     }
                     let sumVal = 0;
@@ -1057,7 +1058,7 @@ JpcFlowTabSrv.prototype.createNew = function(){
         }
         return rst;
     };
-    JpcFlowTabResult.outputPageSum = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT) {
+    JpcFlowTabResult.outputPageSum = function (rptTpl, dataObj, page, segIdx, bands, unitFactor, controls, $CURRENT_RPT, customizeCfg) {
         let me = this, rst = [];
         let FLOW_NODE_STR = me.isEx?JV.NODE_FLOW_INFO_EX:JV.NODE_FLOW_INFO;
         let tab = rptTpl[FLOW_NODE_STR][JV.NODE_FLOW_PAGE_SUM];
@@ -1072,8 +1073,11 @@ JpcFlowTabSrv.prototype.createNew = function(){
                 let tab_fields = me.page_sum_tab_fields;
                 for (let i = 0; i < tab_fields.length; i++) {
                     if (!JpcFieldHelper.resetSumFormat(ref_tab_fields, tab_fields[i])) {
-                        JpcFieldHelper.resetSumFormat(ref_tab_fields_ex, tab_fields[i]);
-                        //如果都找不到,说明是离散的指标,那么就得靠tab_fields[i]本身的Format来处理格式了
+                        if (!JpcFieldHelper.resetSumFormat(ref_tab_fields_ex, tab_fields[i])) {
+                            let map_data_field = JE.F(tab_fields[i][JV.PROP_FIELD_ID], $CURRENT_RPT);
+                            JpcFieldHelper.resetFormat(tab_fields[i], map_data_field, customizeCfg)
+                            //如果都找不到,就得靠自己的Format属性了
+                        }
                     }
                     let cellItem = JpcCommonOutputHelper.createCommonOutput(tab_fields[i], me.pageSumValLst[page - 1][i], controls);
                     cellItem[JV.PROP_AREA] = JpcAreaHelper.outputArea(tab_fields[i][JV.PROP_AREA], band, unitFactor, 1, 0, 1, 0, me.multiCols, 0, true, false);

+ 15 - 36
web/maintain/report/html/rpt_tpl_dtl_calc.html

@@ -1,44 +1,11 @@
 <div class="tab-pane" id="rpttplformula" role="tabpanel">
     <!--
-    <div class="main-data">
-        <div class="p-3">
-            <label>计算式</label>
-            <div class="tab-content">
-                <ul id="rpt_tpl_formulas" class="ztree"></ul>
-            </div>
-        </div>
-        <div class="p-3" id="exprDetail">
-            <div class="row">
-                <div class="form-group col-md-5">
-                    <select class="form-control" id="exprTemplatesSelect"></select>
-                </div>
-                <div class="form-group col-md-1">
-                    <button class="btn btn-primary" id="expr_tpl_select_btn" onclick="calculationTreeOprObj.setTemplateExpression(this)">套用</button>
-                </div>
-            </div>
-            <div class="row">
-                <div class="form-group col-md-3">
-                    <label>计算式执行点</label>
-                    <select class="form-control" id="exprRunType" onchange="calculationTreeOprObj.changeRunType(this)"></select>
-                </div>
-                <div class="form-group col-md-4">
-                    <label>格式串(format)</label>
-                    <input class="form-control" id="exprFormat" value="" onkeyup="calculationTreeOprObj.changeFormat(this)">
-                </div>
-            </div>
-            <div class="form-group">
-                <textarea rows="20" cols="50" style="width: 100%; height: 100%; overflow: auto; work-break: break-all;" id="exprContent" onkeyup="calculationTreeOprObj.changeExpression(this)"></textarea>
-            </div>
-        </div>
-    </div>
-    -->
-    <!--
     -->
     <div class="main">
         <div class="content">
             <div class="container-fluid">
                 <div class="row">
-                    <div class="main-side col-lg-6 p-3">
+                    <div class="main-side col-lg-5 p-3">
                         <div class="row">
                             <div class="form-group col-md-12">
                                 <label>计算式</label>
@@ -47,7 +14,7 @@
                                 </div>
                             </div>
                         </div>
-                        <div class="row">
+                        <div class="row" style="display:none;">
                             <div class="form-group col-md-5">
                                 <select class="form-control" id="exprTemplatesSelect"></select>
                             </div>
@@ -55,8 +22,20 @@
                                 <button class="btn btn-primary" id="expr_tpl_select_btn" onclick="calculationTreeOprObj.setTemplateExpression(this)">套用</button>
                             </div>
                         </div>
+                        <div class="row">
+                            <div class="sub-button p-0">
+                                <button class="btn btn-primary" id="ext_code_tpl_select_btn" onclick="calculationTreeOprObj.setExtCodeTemplate(this)">套用</button>
+                                <button class="btn btn-primary" id="ext_code_tpl_add_btn" onclick="calculationTreeOprObj.addExtCodeTemplate(this)">Copy</button>
+                            </div>
+                        </div>
+                        <div style="height: 10px"></div>
+                        <div class="main-content">
+                            <div>
+                                <ul id="rpt_ext_code_tpl" class="ztree"></ul>
+                            </div>
+                        </div>
                     </div>
-                    <div class="main-content col-lg-6 p-0">
+                    <div class="main-content col-lg-7 p-0">
                         <div class="p-3" id="exprDetail">
                             <div class="row">
                                 <div class="form-group col-md-3">

+ 30 - 0
web/maintain/report/js/cfg_const.js

@@ -228,6 +228,36 @@ let caculationSetting = {
     }
 };
 
+let extCodeSetting = {
+    view: {
+        showIcon: true,
+        expandSpeed: "",
+        selectedMulti: false
+    },
+    edit: {
+        enable: false,
+        showRemoveBtn: false,
+        showRenameBtn: false
+    },
+    data: {
+        keep: {
+            parent:true,
+            leaf:true
+        },
+        key: {
+            children: 'items',
+            name: "Name",
+            title: "Description"
+        },
+        simpleData: {
+            enable: true
+        }
+    },
+    callback:{
+        onClick: calculationTreeOprObj.onExtCodeTreeClick
+    }
+};
+
 let rptDataInfoSetting = {
     view: {
         showIcon: true,

+ 30 - 2
web/maintain/report/js/rpt_tpl_calculation.js

@@ -12,15 +12,27 @@ let expr_templates = [
 
 let calculationTreeOprObj = {
     treeObj : null,
+    extCodeTreeObj: null,
     currentNode: null,
+    currentExtCodeNode: null,
     iniTree: function(rptTpl) {
         var me = this;
         let fieldMapList = me.buildTreeData(rptTpl);
         me.treeObj = $.fn.zTree.init($("#rpt_tpl_formulas"), caculationSetting, fieldMapList);
         me.treeObj.expandAll(true);
         $("#exprDetail")[0].style.display = "none";
-        // $("#exprFormat").get(0).value = "";
-        // $("#exprContent").get(0).value = "";
+    },
+    iniExtCodeTpl: function () {
+        let me = this, params = {};
+        CommonAjax.postEx("report_tpl_api/getExtCodeTpl", params, 10000, true, function(result){
+            me.extCodeTreeObj = $.fn.zTree.init($("#rpt_ext_code_tpl"), extCodeSetting, result);
+            let nodes = me.extCodeTreeObj.getNodes();
+            for (let node of nodes) {
+                me.extCodeTreeObj.expandNode(node, true, false);
+            }
+            // me.extCodeTreeObj.expandAll(true);
+            }, null, null
+        );
     },
     buildExprTemplates: function () {
         let et = $("#exprTemplatesSelect");
@@ -64,6 +76,18 @@ let calculationTreeOprObj = {
         let selIdx = $("#exprTemplatesSelect")[0].selectedIndex;
         $("#exprContent")[0].value = expr_templates[selIdx].Expression;
     },
+    setExtCodeTemplate: function (dom) {
+        let me = calculationTreeOprObj;
+        if (me.currentExtCodeNode && me.currentExtCodeNode["Template"] !== '') {
+            $("#exprContent")[0].value = me.currentExtCodeNode["Template"];
+        }
+    },
+    addExtCodeTemplate: function (dom) {
+        let me = calculationTreeOprObj;
+        if (me.currentExtCodeNode && me.currentExtCodeNode["Template"] !== '') {
+            $("#exprContent")[0].value += me.currentExtCodeNode["Template"];
+        }
+    },
     changeFormat: function (dom) {
         let me = calculationTreeOprObj;
         if (me.currentNode) {
@@ -93,6 +117,10 @@ let calculationTreeOprObj = {
             //
         }
     },
+    onExtCodeTreeClick: function (event, treeId, treeNode) {
+        let me = calculationTreeOprObj;
+        me.currentExtCodeNode = treeNode;
+    },
     onBeforeRemove: function(treeId, treeNode){
         let rst = false;
         if (treeNode.level > 0) {

+ 1 - 0
web/maintain/report/js/rpt_tpl_main.js

@@ -24,6 +24,7 @@ let rptTplObj = {
         calculationTreeOprObj.buildRunType();
         calculationTreeOprObj.buildExprTemplates();
         preHandleObj.buildTypeData();
+        calculationTreeOprObj.iniExtCodeTpl();
     }
 };