Quellcode durchsuchen

修改定额库名称后,引用处应自动更新

vian vor 5 Jahren
Ursprung
Commit
f02868ebbb

+ 11 - 0
config/config.js

@@ -40,6 +40,17 @@ module.exports = {
             connectTimeoutMS: 50000,
             useMongoClient: true
         }},
+    uat:{  server: "112.74.42.187",
+    port: "27017",
+    options:{
+        user:'smartcost',
+        pass:'SmartCost3850888',
+        auth: {
+            "authdb": "admin"
+        },
+        connectTimeoutMS: 50000,
+        useMongoClient: true
+    }},
     prod_s:{  server: "112.74.42.187",
         port: "28066",
         options:{

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

@@ -18,9 +18,70 @@ const installationDao = new InstallationDao();
 import GljDao from "../../std_glj_lib/models/gljModel";
 const stdGljDao = new GljDao();
 import stdgljutil  from "../../../public/cache/std_glj_type_util";
-
+const stdGLJItemModel = mongoose.model('std_glj_lib_gljList');
 var rationItemDAO = function(){};
 
+// 处理部颁数据
+rationItemDAO.prototype.handleBBData = async function (rationLibID, gljLibID) {
+    const rations = await rationItemModel.find({ rationRepId: rationLibID }, '-_id code ID rationGljList').lean();
+    const gljs = await stdGLJItemModel.find({ repositoryId: gljLibID, 'component.0': {$exists: true} }, '-_id ID component').lean();
+    const gljIDMap = {};
+    gljs.forEach(glj => gljIDMap[glj.ID] = glj);
+    const updateData = [];
+    const errorRange = 0.004;
+    for (const ration of rations) {
+        if (!ration.rationGljList) {
+            continue;
+        }
+        const componentAmtMap = {};
+        for (const rGLJ of ration.rationGljList) {
+            const stdGLJ = gljIDMap[rGLJ.gljId];
+            if (!stdGLJ) {
+                continue;
+            }
+            for (const c of stdGLJ.component) {
+                const amt = c.consumeAmt * rGLJ.consumeAmt;
+                if (componentAmtMap[c.ID]) {
+                    componentAmtMap[c.ID] += amt;
+                } else {
+                    componentAmtMap[c.ID] = amt;
+                }
+            }
+        }
+        const newRationGljList = [];
+        let isChanged = false;
+        for (let i = 0; i < ration.rationGljList.length; i++) {
+            const rGLJ = ration.rationGljList[i];
+            if (componentAmtMap[rGLJ.gljId]) {
+                isChanged = true;
+                const diff = scMathUtil.roundTo(rGLJ.consumeAmt - componentAmtMap[rGLJ.gljId], -3);
+                if (diff > errorRange || diff < -errorRange) {
+                    // 扣减
+                    rGLJ.consumeAmt = diff;
+                    if (diff < 0) {
+                        console.log(`ration.code`);
+                        console.log(ration.code);
+                    }
+                    newRationGljList.push(rGLJ);    
+                }
+            } else {
+                newRationGljList.push(rGLJ);
+            }
+        }
+        if (isChanged) {
+            updateData.push({
+                updateOne: {
+                    filter: { ID: ration.ID },
+                    update: { rationGljList: newRationGljList }
+                }
+            });
+        }
+    }
+    if (updateData.length) {
+        await rationItemModel.bulkWrite(updateData);
+    }
+};
+
 /* rationItemDAO.prototype.copyLib = async function (sourceLibID, targetLibID) {
     // coe-list
     const coeIDMap = {};

+ 1 - 1
modules/ration_repository/models/repository_map.js

@@ -197,7 +197,7 @@ rationRepositoryDao.prototype.updateName = function(oprtor, renameObj, callback)
                     callback(err, '更新最近操作者失败!');
                 }
                 else{
-                    engLibModel.update({'ration_lib.id': renameObj.ID}, {$set: {'ration_lib.$.name': renameObj.newName}}, {multi: true}, function (err) {
+                    engLibModel.update({'ration_lib.id': {$in: [String(renameObj.ID), +renameObj.ID]}}, {$set: {'ration_lib.$.name': renameObj.newName}}, {multi: true}, function (err) {
                         if(err){
                             callback(err, '更新工程专业引用失败!');
                         }

+ 1 - 0
modules/std_glj_lib/controllers/gljController.js

@@ -208,6 +208,7 @@ class GljController extends BaseController{
             const info = await gljDao.getReference(repositoryId, gljId);
             res.json({error: 0, message: 'success', data: info});
         } catch (err) {
+            console.log(err);
             res.json({error: 1, message: 'fail', data: null});
         }
     }

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

@@ -17,6 +17,42 @@ import counter from "../../../public/counter/counter";
 import async from "async";
 
 class GljDao  extends OprDao{
+    // 自动计算组含有组成物的人材机的定额价
+    async calcPriceForComposition(gljLibID) {
+        const gljs = await gljModel.find({ repositoryId: gljLibID }, '-_id ID component basePrice').lean();
+        const updateData = [];
+        const toCalcGLJs = [];
+        const gljIDMap = {};
+        for (let i = 0; i < gljs.length; i++) {
+            const glj = gljs[i];
+            gljIDMap[glj.ID] = glj;
+            if (glj.component && glj.component.length) {
+                toCalcGLJs.push(glj);
+            }
+        }
+        for (let i = 0; i < toCalcGLJs.length; i++) {
+            const glj = toCalcGLJs[i];
+            let sum = 0;
+            for (let j = 0; j < glj.component.length; j++) {
+                const c = glj.component[j];
+                if (!gljIDMap[c.ID]) {
+                    continue;
+                }
+                sum += c.consumeAmt * gljIDMap[c.ID].basePrice;
+            }
+            sum = scMathUtil.roundTo(sum, -2);
+            updateData.push({
+                updateOne: {
+                    filter: { ID: glj.ID },
+                    update: { basePrice: sum }
+                }
+            });
+        }
+        if (updateData.length) {
+            await gljModel.bulkWrite(updateData);
+        }
+    }
+
     async copyLib(sourceLibID, targetLibID) {
         const task = [
             this.copyClassData(sourceLibID, targetLibID),