Browse Source

导入消耗量为负数的处理

vian 5 years ago
parent
commit
e85f50bdfa

+ 30 - 1
modules/ration_repository/models/ration_item.js

@@ -21,6 +21,35 @@ import stdgljutil  from "../../../public/cache/std_glj_type_util";
 
 var rationItemDAO = function(){};
 
+// 由于导入excel时,excel数据存在负的工程量,所以导入后一些定额人材机的消耗量可能为负,需要处理
+rationItemDAO.prototype.handleMinusQuantity = async function() {
+    const updateTask = [];
+    const repIDs = new Set();
+    const rations = await rationItemModel.find({'rationGljList.consumeAmt': {$lt: 0}}).lean();
+    for (const ration of rations) {
+        repIDs.add(ration.rationRepId);
+        const rationGLJList = [];
+        for (const rGLJ of ration.rationGljList) {
+            rationGLJList.push({
+                gljId: rGLJ.gljId,
+                consumeAmt: Math.abs(rGLJ.consumeAmt),
+                proportion: rGLJ.proportion
+            });
+        }
+        updateTask.push({
+            updateOne: {
+                filter: { ID: ration.ID },
+                update: { $set: { rationGljList: rationGLJList } }
+            }
+        });
+    }
+    if (updateTask.length) {
+        await rationItemModel.bulkWrite(updateTask);
+    }
+    console.log(`repIDs`);
+    console.log(repIDs);
+};
+
 rationItemDAO.prototype.prepareInitData = async function (rationRepId) {
     // 定额库
     const libTask = stdRationLibModel.findOne({ID: rationRepId}, '-_id ID dispName gljLib');
@@ -878,7 +907,7 @@ rationItemDAO.prototype.batchAddFromExcel = async function(rationRepId, data) {
             }
             const tmpRationGlj = {
                 gljId: stdGLJList[tmp[1]],
-                consumeAmt: tmp[4],
+                consumeAmt: Math.abs(tmp[4]),
                 proportion: 0,
             };
             lastData.rationGljList.push(tmpRationGlj);

+ 28 - 0
modules/std_glj_lib/models/gljModel.js

@@ -810,6 +810,34 @@ class GljDao  extends OprDao{
         }
     }
 
+    // 批量修改人材机类型
+    async batchUpdateGLJType(gljLibId, sheetData) {
+        // 将所有人材机进行编码映射
+        const allGLJs = await gljModel.find({repositoryId: gljLibId}, {ID: true, code: true, gljType: true, shortName: true}).lean();
+        const codeMapping = {};
+        allGLJs.forEach(glj => codeMapping[glj.code] = glj);
+        const updateTask = [];
+        for (let row = 1; row < sheetData.length; row++) {
+            const rowData = sheetData[row];
+            const code = rowData[0];
+            const gljType = rowData[1];
+            const shortName = rowData[2];
+            const glj = codeMapping[code];
+            if (!glj) {
+                continue;
+            }
+            updateTask.push({
+                updateOne: {
+                    filter: { ID: glj.ID },
+                    update: { gljType, shortName }
+                }
+            });
+        }
+        if (updateTask.length) {
+            gljModel.bulkWrite(updateTask);
+        }
+    }
+
     // 导入组成物(替换原本的数据)
     // excel第一行应为:人材机、组成物、消耗量(或者:消耗-一般、消耗-简易等)
     async importComponents(gljLibId, sheetData) {