Forráskód Böngészése

feat: 表2-1数据接口,增加分部、设备购置数据

vian 4 éve
szülő
commit
06f140448c

+ 12 - 1
modules/equipment_purchase/facade/equipment_purchase_facade.js

@@ -5,7 +5,8 @@ module.exports={
     deleteEquipment:deleteEquipment,
     updateEquipments:updateEquipments,
     getEquipmentTotalCost:getEquipmentTotalCost,
-    getEquipmentSummary:getEquipmentSummary
+    getEquipmentSummary:getEquipmentSummary,
+    getSortedEquipmentData,
 };
 
 let mongoose = require('mongoose');
@@ -57,6 +58,16 @@ function sortEquipments(equipments) {
     }
 }
 
+// 获取单位工程设备购置数据(按树结构排好序的)
+async function getSortedEquipmentData(unitID) {
+    const equipment = await equipmentPurchaseModel.findOne({ projectID: unitID }).lean();
+    if (!equipment) {
+        return [];
+    }
+    const items = sortEquipments(equipment.equipments || []);
+    items.forEach(item => item.feeType = 'equipment');
+    return items;
+}
 
 async function getEquipmentSummary(user_id, projectIDs) {
      let data = [];

+ 47 - 9
modules/main/facade/bill_facade.js

@@ -19,7 +19,7 @@ let ration_template_Model = mongoose.model('ration_template');
 let bill_Model = require('../models/bills').model;
 let billsLibDao = require("../../bills_lib/models/bills_lib_interfaces");
 const pmFacade = require('../../pm/facade/pm_facade');
-const { getSortedTreeData, getEngineeringFeeType } = require('../../../public/common_util');
+const { getSortedTreeData, getSortedSeqTreeData, getEngineeringFeeType } = require('../../../public/common_util');
 const { billType, constructionFeeNodeID, constructionEquipmentFeeNodeID, BudgetArea, fixedFlag, BudgetType } = require('../../../public/common_constants');
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
 const uuidV1 = require('uuid/v1');
@@ -183,20 +183,58 @@ module.exports={
         });
         return map;
     },
-    // 获取概算汇总单项工程级别数据(拍好序的,报表接口用)
+    // 获取单位工程分部数据(按树结构排好序的)
+    getFBData: async function (unitID) {
+        const bills = await bill_Model.find({ projectID: unitID }).lean();
+        const sortedData = getSortedTreeData('-1', bills);
+        return sortedData.filter(item => item.type === billType.FB);
+    },
+    // 获取概算汇总单项工程级别数据(排好序的,报表接口用)
     getSinglesBudgetSummary: async function (constructionID) {
         const items = await this.getBudgetSummary(constructionID, true);
         // 去除建设项目层级
         items.shift();
-        items.forEach(item => {
+        const [budgetTotalItem] = items.splice(items.length - 1, 1);
+        const budgetTotalFeeItem = budgetTotalItem.fees && budgetTotalItem.fees.find(f => f.fieldName === 'common');
+        const budgetTotalFee = budgetTotalFeeItem ? +budgetTotalFeeItem.totalFee : 0;
+        const rst = [];
+        for (const project of items) {
+            rst.push(project);
             // 方便报表取值处理
-            if (item.projType === 'Engineering') {
-                item.engineeringName = item.name || '';
-            } else if (item.projType === 'Tender') {
-                item.tenderName = item.name || '';
+            if (project.projType === 'Engineering') {
+                project.engineeringName = project.name || '';
+            } else if (project.projType === 'Tender') {
+                project.tenderName = project.name || '';
+                // 追加分部和设备购置数据
+                const feeType = getEngineeringFeeType(project.property && project.property.engineeringName || '');
+                const fbs = await this.getFBData(project.orgProjectID);
+                const equipments = await equipmentFacade.getSortedEquipmentData(project.orgProjectID);
+                const detailData = [...fbs, ...equipments].map(item => {
+                    let totalFee = 0;
+                    if (item.feeType === 'equipment') {
+                        totalFee = item.totalPrice || 0;
+                    } else {
+                        const totalFeeItem = item.fees && item.fees.find(f => f.fieldName === 'common');
+                        totalFee = totalFeeItem ? +totalFeeItem.totalFee : 0;
+                    }
+                    // 计算占总投资比例
+                    const rate = (budgetTotalFee ?  scMathUtil.roundForObj(totalFee / budgetTotalFee, 4) : 0) * 100;
+                    return {
+                        code: item.code || '',
+                        name: item.name || '',
+                        buildingFee: item.feeType !== 'equipment' && feeType === 'building' ? totalFee : 0,
+                        installationFee: item.feeType !== 'equipment' && feeType === 'installation' ? totalFee : 0,
+                        equipmentFee: item.feeType === 'equipment' ? totalFee : 0,
+                        otherFee: 0,
+                        totalFee,
+                        rate,
+                    }
+                });
+                rst.push(...detailData);
+                
             }
-        });
-        return items;
+        }
+        return rst;
     },
 
     // 获取概算汇总数据(拍好序的)

+ 25 - 2
public/common_util.js

@@ -72,13 +72,13 @@ function deleteEmptyObject(arr) {
         return sortSameDedth(rootID, items).reverse();
 
         function sortSameDedth(parentID, items) {
-            const sameDepthItems = items.filter(item => item.ParentID === parentID);
+            const sameDepthItems = items.filter(item => item.ParentID == parentID);
             if (!sameDepthItems.length) {
                 return [];
             }
             const NextIDMapping = {};
             sameDepthItems.forEach(item => NextIDMapping[item.NextSiblingID] = item);
-            let curItem = sameDepthItems.length > 1 ? sameDepthItems.find(item => +item.NextSiblingID === -1) : sameDepthItems[0];
+            let curItem = sameDepthItems.length > 1 ? sameDepthItems.find(item => +item.NextSiblingID == -1) : sameDepthItems[0];
             const sorted = [];
             while (curItem) {
                 sorted.push(...sortSameDedth(curItem.ID, items));
@@ -89,6 +89,29 @@ function deleteEmptyObject(arr) {
         }
     }
 
+    function getSortedSeqTreeData(rootID, items) {
+        const parentMap = {};
+        items.forEach(item => {
+            (parentMap[item.ParentID] || (parentMap[item.ParentID] = [])).push(item);
+        });
+        Object.values(parentMap).forEach(data => data.sort((a, b) => a.seq - b.seq));
+        const rst = [];
+        function extractItems(data) {
+            if (data && data.length) {
+                for (const item of data) {
+                    rst.push(item);
+                    const children = parentMap[item.ID];
+                    if (children && children.length) {
+                        extractItems(children);
+                    }
+                }
+            }
+            
+        }
+        extractItems(parentMap[rootID]);
+        return rst;
+    }
+
     // 控制全屏(浏览器有限制)
     // Element.requestFullscreen的全屏和“F11”的全屏是不一样的。前者是将相关Element变成全屏显示。后者是将浏览器导航、标签等隐藏。
     // Fullscreen API对于全屏的判断和监听都是基于Element.requestFullscreen的,比如Document.fullscreenElement。通过F11触发的全屏Document.fullscreenElement返回null,无法正确返回全屏状态。