Bläddra i källkod

变更令调整及优化

Tony Kang 1 år sedan
förälder
incheckning
b296093b1a
2 ändrade filer med 58 tillägg och 118 borttagningar
  1. 3 2
      app/const/source_type.js
  2. 55 116
      app/controller/report_controller.js

+ 3 - 2
app/const/source_type.js

@@ -14,15 +14,16 @@ const sourceTypeData = [
 ];
 
 // sourceType = { tender: 1, advance: 10, ... };
-const sourceType = (function (data){
+const sourceType = (function(data) {
     const result = {};
     for (const d of data) {
         result[d.key] = d.id;
     }
+    return result;
 })(sourceTypeData);
 
 module.exports = {
     sourceType,
     sourceTypeData,
     defaultSourceType: sourceTypeData[0].id,
-};
+};

+ 55 - 116
app/controller/report_controller.js

@@ -59,6 +59,47 @@ module.exports = app => {
             // throw
         }
 
+        async _createNodes(ctx, source_type, pid) {
+            const treeNodes = await ctx.service.rptTreeNode.getNodesBySourceType([pid], source_type); // 这个查定制的
+            const commonTreeNodes = await ctx.service.rptTreeNode.getNodesByProjectId([-1]); // 这个查通用的
+            const nodeItems = JSON.parse(commonTreeNodes[0].items);
+            const commonArrs = [];
+            nodeItems.forEach(nodeItem => {
+                const srcType = nodeItem.source_type ? nodeItem.source_type : 1;
+                if (srcType === source_type) {
+                    commonArrs.push(nodeItem);
+                }
+            });
+            // 加一个dummy的通用报表
+            const dummyCommonRptNode = { id: 1, name: '通用报表', pid: -1, rpt_type: 0, items: JSON.stringify(commonArrs) };
+            treeNodes.push(dummyCommonRptNode);
+            const custCfg = await ctx.service.rptCustomizeCfg.getCustomizeCfgByUserId('Administrator');
+            return { treeNodes, commonArrs, custCfg };
+        }
+
+        async _getInvolveAcc(ctx, tId) {
+            // 获取所有项目参与者
+            const accountList = await ctx.service.projectAccount.getAllDataByCondition({
+                where: { project_id: ctx.session.sessionProject.id, enable: 1 },
+                columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
+            });
+            const newAccountGroup = accountGroup.map((item, idx) => {
+                const groupList = accountList.filter(item => item.account_group === idx);
+                return { groupName: item, groupList };
+            });
+            const where = { tid: tId };
+            const advance = await ctx.service.advance.getAllDataByCondition({
+                columns: ['id', 'order', 'status', 'selected', 'type'],
+                where,
+                orders: [['type', 'asc'], ['create_time', 'desc']],
+            });
+            advance.forEach(x => {
+                x.statusStr = auditConst.advance.statusString[x.status];
+                x.typeStr = advanceConst.typeColMap[x.type].text;
+            });
+            return { accountList, newAccountGroup, advance };
+        }
+
         /**
          * 报表显示页面
          *
@@ -78,26 +119,9 @@ module.exports = app => {
                 let sorder = -1;
                 let stage_times = -1;
                 let stage_status = -1;
-                const treeNodes = await ctx.service.rptTreeNode.getNodesByProjectId([-1, tender.data.project_id]);
-                const filterNames = ['01.支付审批报表'],
-                    filterSourceTypes = [100, 101, 200];
-                if (treeNodes && treeNodes.length > 0) {
-                    for (let tIdx = treeNodes.length - 1; tIdx >= 0; tIdx--) {
-                        if (filterNames.includes(treeNodes[tIdx].name)) {
-                            treeNodes.splice(tIdx, 1);
-                        } else if (treeNodes[tIdx].name === '通用报表') {
-                            const items = JSON.parse(treeNodes[tIdx].items);
-                            for (let itemIdx = items.length - 1; itemIdx >= 0; itemIdx--) {
-                                if (filterSourceTypes.includes(items[itemIdx].source_type)) {
-                                    items.splice(itemIdx, 1);
-                                }
-                            }
-                            treeNodes[tIdx].items = JSON.stringify(items);
-                        }
-                    }
-                }
+
+                const { treeNodes, custCfg } = await this._createNodes(ctx, sourceTypeConst.sourceType.tender, tender.data.project_id);
                 const custTreeNodes = await ctx.service.rptTreeNodeCust.getCustFoldersByUserId(this.ctx.session.sessionUser.accountId);
-                const custCfg = await ctx.service.rptCustomizeCfg.getCustomizeCfgByUserId('Administrator');
                 const stageList = await ctx.service.stage.getValidStagesShort(tender.id);
                 const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: tender.data.project_id } }); // 找公司章用的
                 const isAdmin = ctx.session.sessionUser.is_admin;
@@ -241,24 +265,7 @@ module.exports = app => {
                 }
 
                 // 获取所有项目参与者
-                const accountList = await ctx.service.projectAccount.getAllDataByCondition({
-                    where: { project_id: ctx.session.sessionProject.id, enable: 1 },
-                    columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
-                });
-                const newAccountGroup = accountGroup.map((item, idx) => {
-                    const groupList = accountList.filter(item => item.account_group === idx);
-                    return { groupName: item, groupList };
-                });
-                const where = { tid: this.ctx.tender.id };
-                const advance = await ctx.service.advance.getAllDataByCondition({
-                    columns: ['id', 'order', 'status', 'selected', 'type'],
-                    where,
-                    orders: [['type', 'asc'], ['create_time', 'desc']],
-                });
-                advance.forEach(x => {
-                    x.statusStr = auditConst.advance.statusString[x.status];
-                    x.typeStr = advanceConst.typeColMap[x.type].text;
-                });
+                const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, this.ctx.tender.id);
 
                 const renderData = {
                     accountGroup: newAccountGroup,
@@ -348,7 +355,7 @@ module.exports = app => {
                 //          没有计量期的概念!!!
                 const paymentAuditorList = await ctx.service.paymentDetailAudit.getAuditors(paymentDetail_id);
                 const tender = ctx.paymentTender;
-                const { treeNodes, commonArrs, custCfg } = await this._createNodes(ctx, 101, tender.pid);
+                const { treeNodes, commonArrs, custCfg } = await this._createNodes(ctx, sourceTypeConst.sourceType.payment_safe, tender.pid);
                 const stageList = [];
                 const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid: tender.pid } }); // 找公司章用的
                 const isAdmin = ctx.session.sessionUser.is_admin;
@@ -410,24 +417,7 @@ module.exports = app => {
                 });
 
                 // 获取所有项目参与者
-                const accountList = await ctx.service.projectAccount.getAllDataByCondition({
-                    where: { project_id: ctx.session.sessionProject.id, enable: 1 },
-                    columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
-                });
-                const newAccountGroup = accountGroup.map((item, idx) => {
-                    const groupList = accountList.filter(item => item.account_group === idx);
-                    return { groupName: item, groupList };
-                });
-                const where = { tid: tenderId };
-                const advance = await ctx.service.advance.getAllDataByCondition({
-                    columns: ['id', 'order', 'status', 'selected', 'type'],
-                    where,
-                    orders: [['type', 'asc'], ['create_time', 'desc']],
-                });
-                advance.forEach(x => {
-                    x.statusStr = auditConst.advance.statusString[x.status];
-                    x.typeStr = advanceConst.typeColMap[x.type].text;
-                });
+                const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, tenderId);
 
                 const renderData = {
                     accountGroup: newAccountGroup,
@@ -505,7 +495,7 @@ module.exports = app => {
                 const budget_id = ctx.budget.id;
                 const subProj = await ctx.service.subProject.getDataByCondition({ budget_id });
                 const sp_id = subProj.id;
-                const { treeNodes, commonArrs, custCfg } = await this._createNodes(ctx, 200, pid);
+                const { treeNodes, commonArrs, custCfg } = await this._createNodes(ctx, sourceTypeConst.sourceType.budget, pid);
                 const stageList = [];
                 const unitList = await ctx.service.constructionUnit.getAllDataByCondition({ where: { pid } }); // 找公司章用的
                 const isAdmin = ctx.session.sessionUser.is_admin;
@@ -569,24 +559,7 @@ module.exports = app => {
                 }
 
                 // 获取所有项目参与者
-                const accountList = await ctx.service.projectAccount.getAllDataByCondition({
-                    where: { project_id: ctx.session.sessionProject.id, enable: 1 },
-                    columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
-                });
-                const newAccountGroup = accountGroup.map((item, idx) => {
-                    const groupList = accountList.filter(item => item.account_group === idx);
-                    return { groupName: item, groupList };
-                });
-                const where = { tid: tenderId };
-                const advance = await ctx.service.advance.getAllDataByCondition({
-                    columns: ['id', 'order', 'status', 'selected', 'type'],
-                    where,
-                    orders: [['type', 'asc'], ['create_time', 'desc']],
-                });
-                advance.forEach(x => {
-                    x.statusStr = auditConst.advance.statusString[x.status];
-                    x.typeStr = advanceConst.typeColMap[x.type].text;
-                });
+                const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, tenderId);
 
                 const renderData = {
                     accountGroup: newAccountGroup,
@@ -647,23 +620,6 @@ module.exports = app => {
             }
         }
 
-        async _createNodes(ctx, source_type, pid) {
-            const treeNodes = await ctx.service.rptTreeNode.getNodesBySourceType([pid], source_type); // 这个查定制的
-            const commonTreeNodes = await ctx.service.rptTreeNode.getNodesByProjectId([-1]); // 这个查通用的
-            const nodeItems = JSON.parse(commonTreeNodes[0].items);
-            const commonArrs = [];
-            nodeItems.forEach(nodeItem => {
-                if (nodeItem.source_type === source_type) {
-                    commonArrs.push(nodeItem);
-                }
-            });
-            // 加一个dummy的通用报表
-            const dummyCommonRptNode = { id: 1, name: '通用报表', pid: -1, rpt_type: 0, items: JSON.stringify(commonArrs) };
-            treeNodes.push(dummyCommonRptNode);
-            const custCfg = await ctx.service.rptCustomizeCfg.getCustomizeCfgByUserId('Administrator');
-            return { treeNodes, commonArrs, custCfg };
-        }
-
         async _indexForBGL(ctx, source_type) {
             // 变更令、变更方案、变更立项、变更申请 报表入口
             try {
@@ -678,7 +634,7 @@ module.exports = app => {
                 const pid = ctx.session.sessionProject.id;
                 const budget_id = -1;
                 const sp_id = -1;
-                const { treeNodes, commonArrs, custCfg } = await this._createNodes(ctx, source_type, tenderId);
+                const { treeNodes, custCfg } = await this._createNodes(ctx, source_type, tenderId);
                 const sorts = ctx.query.sort ? ctx.query.sort : 0;
                 const orders = ctx.query.order ? ctx.query.order : 0;
                 const state = ctx.session.sessionProject.page_show.openChangeState && ctx.query.state ? parseInt(ctx.query.state) : 0;
@@ -727,7 +683,7 @@ module.exports = app => {
                 for (const prjAcc of prjAccList) {
                     prjAcc.account_group = accountGroup[prjAcc.account_group];
                 }
-                const cust_select_keys = JSON.stringify(['common_dynamic', 'customize_dynamic']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
+                const cust_select_keys = JSON.stringify(['common', 'customize']); // 因其他地方也有可能保存用户报表的显示选择项,因当初设计问题,不好改数据库结构了,但可以调节内部json来满足需求
                 const rpt_tpl_items = { customize: [], common: [] };
                 if (treeNodes && treeNodes.length > 0) {
                     for (let tIdx = treeNodes.length - 1; tIdx >= 0; tIdx--) {
@@ -743,24 +699,7 @@ module.exports = app => {
                 }
 
                 // 获取所有项目参与者
-                const accountList = await ctx.service.projectAccount.getAllDataByCondition({
-                    where: { project_id: ctx.session.sessionProject.id, enable: 1 },
-                    columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
-                });
-                const newAccountGroup = accountGroup.map((item, idx) => {
-                    const groupList = accountList.filter(item => item.account_group === idx);
-                    return { groupName: item, groupList };
-                });
-                const where = { tid: tenderId };
-                const advance = await ctx.service.advance.getAllDataByCondition({
-                    columns: ['id', 'order', 'status', 'selected', 'type'],
-                    where,
-                    orders: [['type', 'asc'], ['create_time', 'desc']],
-                });
-                advance.forEach(x => {
-                    x.statusStr = auditConst.advance.statusString[x.status];
-                    x.typeStr = advanceConst.typeColMap[x.type].text;
-                });
+                const { accountList, newAccountGroup, advance } = await this._getInvolveAcc(ctx, tenderId);
 
                 const renderData = {
                     accountGroup: newAccountGroup,
@@ -822,22 +761,22 @@ module.exports = app => {
 
         async indexForChange(ctx) {
             // 变更令报表入口
-            await this._indexForBGL(ctx, 20);
+            await this._indexForBGL(ctx, sourceTypeConst.sourceType.change);
         }
 
         async indexForChangePlan(ctx) {
             // 变更方案报表入口
-            await this._indexForBGL(ctx, 21);
+            await this._indexForBGL(ctx, sourceTypeConst.sourceType.change_plan);
         }
 
         async indexForChangeProject(ctx) {
             // 变更立项报表入口
-            await this._indexForBGL(ctx, 22);
+            await this._indexForBGL(ctx, sourceTypeConst.sourceType.change_project);
         }
 
         async indexForChangeApply(ctx) {
             // 变更申请报表入口
-            await this._indexForBGL(ctx, 23);
+            await this._indexForBGL(ctx, sourceTypeConst.sourceType.change_apply);
         }
 
         /**