Browse Source

TASK #4627 报表模板显示选择

Tony Kang 1 year ago
parent
commit
95e49b6404

+ 31 - 10
app/controller/report_controller.js

@@ -232,9 +232,12 @@ module.exports = app => {
                 for (const prjAcc of prjAccList) {
                     prjAcc.account_group = accountGroup[prjAcc.account_group];
                 }
-                let rpt_tpl_items = '{ customize: [], common: [] }';
+                const cust_select_keys = JSON.stringify(['common', 'customize']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
+                const rpt_tpl_items = { customize: [], common: [] };
                 if (custTreeNodes.length > 0) {
-                    rpt_tpl_items = custTreeNodes[0].rpt_tpl_items;
+                    const cust_select_item = JSON.parse(custTreeNodes[0].rpt_tpl_items);
+                    if (cust_select_item.common) rpt_tpl_items.common = cust_select_item.common;
+                    if (cust_select_item.customize) rpt_tpl_items.customize = cust_select_item.customize;
                 }
 
                 // 获取所有项目参与者
@@ -264,7 +267,8 @@ module.exports = app => {
                     tender: tender.data,
                     tenderInfo: tender.info,
                     rpt_tpl_data: JSON.stringify(treeNodes),
-                    cust_tpl_data: rpt_tpl_items,
+                    cust_tpl_data: JSON.stringify(rpt_tpl_items),
+                    cust_select_keys,
                     cust_cfg: JSON.stringify(custCfg),
                     project_id: tender.data.project_id,
                     tender_id: tender.id,
@@ -410,6 +414,7 @@ module.exports = app => {
                     prjAcc.account_group = accountGroup[prjAcc.account_group];
                 }
                 // const rpt_tpl_items = '{ customize: [], common: [] }';
+                const cust_select_keys = JSON.stringify(['common_safe', 'customize_safe']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求,安全生产费没有这个,就过了
                 const rpt_tpl_items = { customize: [], common: [] };
                 commonArrs.forEach(item => {
                     rpt_tpl_items.common.push(item.name);
@@ -444,6 +449,7 @@ module.exports = app => {
                     rpt_tpl_data: JSON.stringify(treeNodes),
                     // cust_tpl_data: rpt_tpl_items,
                     cust_tpl_data: JSON.stringify(rpt_tpl_items),
+                    cust_select_keys,
                     cust_cfg: JSON.stringify(custCfg),
                     project_id: tender.pid,
                     tender_id: tenderId,
@@ -496,9 +502,9 @@ module.exports = app => {
             try {
                 await this._getStageAuditViewData(ctx);
                 const pageShow = ctx.session.sessionProject.page_show;
-                pageShow.showArchive = 1;
                 // pageShow.closeWatermark = 1;
                 pageShow.showArchive = 0;
+                pageShow.closeShowAllCustomized = 0;
                 const tenderId = -1;
                 const paymentDetail_id = -1;
                 // const tender = ctx.paymentTender;
@@ -514,6 +520,7 @@ module.exports = app => {
                 });
                 // 加一个dummy的通用报表
                 const dummyCommonRptNode = { id: 1, name: '通用报表', pid: -1, rpt_type: 0, items: JSON.stringify(commonArrs) };
+                // const dummyCommonRptNode = { id: 1, name: '通用报表', pid: -1, rpt_type: 0, items: '[]' };
                 treeNodes.push(dummyCommonRptNode);
                 // const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
                 const custCfg = await ctx.service.rptCustomizeCfg.getCustomizeCfgByUserId('Administrator');
@@ -561,11 +568,23 @@ module.exports = app => {
                 for (const prjAcc of prjAccList) {
                     prjAcc.account_group = accountGroup[prjAcc.account_group];
                 }
-                // const rpt_tpl_items = '{ customize: [], common: [] }';
+                const cust_select_keys = JSON.stringify(['common_dynamic', 'customize_dynamic']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
                 const rpt_tpl_items = { customize: [], common: [] };
-                commonArrs.forEach(item => {
-                    rpt_tpl_items.common.push(item.name);
-                });
+                const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
+                if (custTreeNodes.length > 0) {
+                    const cust_select_item = JSON.parse(custTreeNodes[0].rpt_tpl_items);
+                    if (cust_select_item.common_dynamic) rpt_tpl_items.common = cust_select_item.common_dynamic;
+                    if (cust_select_item.customize_dynamic) rpt_tpl_items.customize = cust_select_item.customize_dynamic;
+                    if (!cust_select_item.hasOwnProperty('common_dynamic') && !cust_select_item.hasOwnProperty('customize_dynamic')) {
+                        commonArrs.forEach(item => {
+                            rpt_tpl_items.common.push(item.name);
+                        });
+                    }
+                } else {
+                    commonArrs.forEach(item => {
+                        rpt_tpl_items.common.push(item.name);
+                    });
+                }
 
                 // 获取所有项目参与者
                 const accountList = await ctx.service.projectAccount.getAllDataByCondition({
@@ -596,6 +615,7 @@ module.exports = app => {
                     rpt_tpl_data: JSON.stringify(treeNodes),
                     // cust_tpl_data: rpt_tpl_items,
                     cust_tpl_data: JSON.stringify(rpt_tpl_items),
+                    cust_select_keys,
                     cust_cfg: JSON.stringify(custCfg),
                     project_id: pid,
                     tender_id: tenderId,
@@ -1204,8 +1224,9 @@ module.exports = app => {
             const params = JSON.parse(ctx.request.body.params);
             // console.log(params);
             const custId = this.ctx.session.sessionUser.accountId;
-            const newNodeItems = JSON.stringify(params.nodeItems);
-            const rst = await ctx.service.rptTreeNodeCust.updateCustNode(custId, newNodeItems);
+            const newNodeItems = params.nodeItems;
+            const custSelectKeys = params.custSelectKeys;
+            const rst = await ctx.service.rptTreeNodeCust.updateCustNode(custId, newNodeItems, custSelectKeys);
             // console.log(rst);
             ctx.body = { data: rst };
             // ctx.body = { data: { msg: 'test the network' } };

+ 12 - 6
app/service/rpt_tree_node_cust.js

@@ -44,7 +44,7 @@ module.exports = app => {
             this.transaction = await this.db.beginTransaction();
             try {
                 const data = {
-                    cust_acc_id: cust_acc_id,
+                    cust_acc_id,
                     rpt_tpl_items: newRptItems,
                 };
                 // console.log('createNode:');
@@ -60,19 +60,25 @@ module.exports = app => {
             }
         }
 
-        async updateCustNode(cust_acc_id, newNodeItems) {
+        async updateCustNode(cust_acc_id, newNodeItems, custSelectKeys) {
             let rst = null;
             try {
                 const custNode = await this.getCustFoldersByUserId(cust_acc_id);
-                // console.log('query Node:');
-                // console.log(custNode);
                 if (custNode.length > 0) {
                     this.transaction = await this.db.beginTransaction();
-                    custNode[0].rpt_tpl_items = newNodeItems;
+                    const orgNodeItems = JSON.parse(custNode[0].rpt_tpl_items);
+                    orgNodeItems[custSelectKeys[0]] = newNodeItems.common;
+                    orgNodeItems[custSelectKeys[1]] = newNodeItems.customize;
+                    // custNode[0].rpt_tpl_items = newNodeItems;
+                    custNode[0].rpt_tpl_items = JSON.stringify(orgNodeItems);
                     rst = await this.transaction.update(this.tableName, custNode[0]);
                     this.transaction.commit();
                 } else {
-                    rst = await this.createCustNode(cust_acc_id, newNodeItems);
+                    const nodeItems = {};
+                    nodeItems[custSelectKeys[0]] = newNodeItems.common;
+                    nodeItems[custSelectKeys[1]] = newNodeItems.customize;
+                    // rst = await this.createCustNode(cust_acc_id, newNodeItems);
+                    rst = await this.createCustNode(cust_acc_id, JSON.stringify(nodeItems));
                 }
             } catch (ex) {
                 console.log(ex);

+ 5 - 0
app/view/report/index.ejs

@@ -24,6 +24,8 @@
                         <div class="dropdown-menu" aria-labelledby="dropdownMenuButton" id="optionSelectableStages"></div>
                     </div>
                 </div>
+                <% } %>
+                <% if ((stg_id === -200) || (stg_id !== -100 && stg_id !== -300)) { %>
                 <div class="d-inline-block">
                     <ul class="nav nav-pills m-0">
                         <li class="nav-item mr-1"><a href="#man-c" data-toggle="modal" data-target="#man-c" class=" btn btn-outline-primary btn-sm"><i class="fa fa-cog"></i> 推荐报表</a></li>
@@ -32,6 +34,8 @@
                         -->
                     </ul>
                 </div>
+                <% } %>
+                <% if (false || (stg_id !== -100 && stg_id !== -200 && stg_id !== -300)) { %>
                 <% if (ctx.session.sessionProject.page_show.isPreset) { %>
                 <div class="d-inline-block">
                     <div class="dropdown">
@@ -388,6 +392,7 @@
 //    PAGE_SHOW['closeWatermark'] = 0; //测试用,check in 前要屏蔽
 
     const CUST_TREE_NODES = <%- cust_tpl_data %>;
+    const CUST_SELECT_KEYS = <%- cust_select_keys %>;
     if (!(CUST_TREE_NODES.customize instanceof Array)) {
         CUST_TREE_NODES.customize = [];
     }

+ 2 - 1
app/view/report/rpt_all_popup.ejs

@@ -746,7 +746,7 @@
     zTreeOprObj.getCustomerCfg();
     zTreeOprObj.iniFontCfgDom(CUST_CFG);
     
-    <% if (false || (stg_id !== -100 && stg_id !== -200 && stg_id !== -300)) { %>
+    <% if (stg_id === -200 || (stg_id !== -100 && stg_id !== -300)) { %>
     buildCustRptCommon('report_cust_group_common', ORG_TOP_TREE_NODES[1], CUST_TREE_NODES.common, 'true');
     buildCustRptCommon('report_cust_group_individual', ORG_TOP_TREE_NODES[0], CUST_TREE_NODES.customize, 'false');
     <% } %>
@@ -1093,6 +1093,7 @@
     function updateCustRptCfg(){
         let params = {};
         params.nodeItems = CUST_TREE_NODES;
+        params.custSelectKeys = CUST_SELECT_KEYS;
         CommonAjax.postXsrfEx("/tender/report_api/updateCustNode", params, 60000, true, getCookie('csrfToken_j'),
             function(result){
                 try {