Преглед изворни кода

Merge branch 'master' of http://192.168.1.41:3000/SmartCost/YangHuOperation

zhangweicheng пре 5 година
родитељ
комит
a920f5df1f

+ 57 - 0
modules/ration_repository/models/ration_item.js

@@ -18,9 +18,66 @@ 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";
+//add
+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 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] = gljs);
+    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 (const rGLJ of ration.rationGljList) {
+            if (componentAmtMap[rGLJ.gljId]) {
+                const diff = Math.abs(componentAmtMap[rGLJ.gljId] - rGLJ.consumeAmt);
+                if (diff <= errorRange) {
+                    isChanged = true;
+                } else {
+                    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);
+    }
+};
+
 // 由于导入excel时,excel数据存在负的工程量,所以导入后一些定额人材机的消耗量可能为负,需要处理
 rationItemDAO.prototype.handleMinusQuantity = async function() {
     const updateTask = [];

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

@@ -192,7 +192,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, '更新工程专业引用失败!');
                         }

+ 12 - 0
modules/users/controllers/compilation_controller.js

@@ -663,6 +663,18 @@ class CompilationController extends BaseController {
         }
     }
 
+    async copyRationLibs(req, res) {
+        const { valuationID, engineeringID } = JSON.parse(req.body.data);
+        try {
+            const engineeringLibModel = new EngineeringLibModel();
+            await engineeringLibModel.copyRationLibsToOthers(valuationID, engineeringID);
+            res.json({ error: 0, message: '复制成功', data: null });
+        } catch (err) {
+            res.json({ error: 1, message: String(err), data: null });
+        }
+
+    }
+
     async addEngineer(request,response){
         let engineeringLibModel = new EngineeringLibModel();
         try {

+ 18 - 0
modules/users/models/engineering_lib_model.js

@@ -273,6 +273,24 @@ class EngineeringLibModel extends BaseModel {
         return result;
     }
 
+    async copyRationLibsToOthers(valuationID, engineeringID) {
+        const compilationModel = new CompilationModel();
+        const compilation = await compilationModel.model.findOne({ $or: [{ 'bill_valuation.id': valuationID }, { 'ration_valuation.id': valuationID }]});
+        if (!compilation) {
+            return;
+        }
+        const valuationIDList = [];
+        const allValuation = compilation.ration_valuation.concat(compilation.bill_valuation);
+        for (const valuation of allValuation) {
+            valuationIDList.push(valuation.id);
+        }
+        const engineering = await this.findDataByCondition({ _id: engineeringID });
+        if (!engineering) {
+            return;
+        }
+        await this.model.updateMany({ valuationID: { $in: valuationIDList } }, {$set: { ration_lib: engineering.ration_lib }});
+    }
+
 }
 
 export default EngineeringLibModel;

+ 1 - 0
modules/users/routes/compilation_route.js

@@ -31,6 +31,7 @@ module.exports = function (app) {
     router.post('/valuation/:section/enable', compilationController.auth, compilationController.init, compilationController.enableSwitch);
     router.post('/template/:section/:id/:engineering/update', compilationController.auth, compilationController.init, compilationController.updateBillsTemplate);
     router.post('/addEngineer', compilationController.auth, compilationController.init, compilationController.addEngineer);
+    router.post('/copyRationLibs', compilationController.auth, compilationController.init, compilationController.copyRationLibs);
 
     router.post('/changeCategory', compilationController.auth, compilationController.init, compilationController.changeCategory);
 

+ 4 - 0
web/users/css/custom.css

@@ -38,4 +38,8 @@
 }
 [draggable=true] span{
   pointer-events: none;
+}
+select.multiple {
+  min-height: 150px;
+  max-height: 300px;
 }

+ 35 - 14
web/users/js/compilation.js

@@ -135,19 +135,26 @@ $(document).ready(function() {
 
     //新增定额库
     $("#add-ration").click(function () {
-        let rationLib = $("select[name='ration_lib']").children("option:selected").val();
-        let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
-        if (rationLib == undefined || rationLib == '') {
-            alert("请选择定额库");
-            return;
-        }
-        if ($("input:hidden[name=ration_lib][data-id = " + rationLib + "]").length <= 0) {
-            let tem = {
+        const options = $("select[name='ration_lib']").children("option:selected");
+        let alertArr = [];
+        let htmlString = '';
+        for (const option of options) {
+            const rationLib = $(option).val();
+            const rationLibString = $(option).text();
+            if (!rationLib) {
+                alertString.push(`“${rationLibString}”为无效定额库`);
+                continue;
+            }
+            if ($("input:hidden[name=ration_lib][data-id = " + rationLib + "]").length > 0) {
+                alertArr.push(`“${rationLibString}”已存在`);
+                continue;
+            }
+            const tem = {
                 id: rationLib,
                 name: rationLibString,
                 isDefault: false
             };
-            let htmlString = ` 
+            htmlString += ` 
                 <tr class='ration_tr' draggable="true">
                     <td><span class="cursor-default">${tem.name}</span></td>
                     <td><label class="form-check-label"> <input class="form-check-input" name="ration_isDefault"  value="${tem.id}" type="radio"></td>  
@@ -155,14 +162,28 @@ $(document).ready(function() {
                         <a class='btn btn-link btn-sm ' style="padding: 0px" onclick='deleteTableTr(this,"ration_tr")'>删除</a>
                         <input type="hidden" name="ration_lib" data-id="${tem.id}" value='${JSON.stringify(tem)}'>
                     </td>
-                </tr>`
-            $("#ration_tbody").append(htmlString);
+                </tr>`;
+        }
+        if (alertArr.length) {
+            alert(alertArr.join('\n'));
         } else {
-            alert('已存在相同的定额库')
+            $("#ration_tbody").append(htmlString);
+            $("#addRation").modal('hide');
         }
-        $("#addRation").modal('hide');
     });
 
+    // 复制定额库
+    $('#copy-lib-confirm').click(async function () {
+        try {
+            $.bootstrapLoading.start();
+            const [valuationID, engineeringID] = window.location.pathname.split('/').slice(-2);
+            await ajaxPost('/compilation/copyRationLibs', { valuationID, engineeringID });
+        } catch (err) {
+            console.log(err);
+        } finally {
+            $.bootstrapLoading.end();
+        }
+    });
     // 拖动排序
     const dragSelector = '.ration_tr[draggable=true]';
     const rationBodySelector = '#ration_tbody';
@@ -550,7 +571,7 @@ function initCompilation() {
         let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
         html += tmpHtml;
     }
-    $("select[name='ration_lib']").children("option").first().after(html);
+    $("select[name='ration_lib']").html(html);
 
     // 工料机库
     html = '';

+ 2 - 0
web/users/views/compilation/engineering.html

@@ -209,6 +209,8 @@
                     <div class="col-md-12" style="padding-top:20px">
                             <legend>定额库</legend>
                             <a data-toggle="modal" data-target="#addRation" class="btn btn-link btn-sm " id="addRatioBtn" style="margin-right:5px">添加</a>
+                            <a data-toggle="modal" data-target="#copy-lib" class="btn btn-link btn-sm " style="margin-right:5px">复制到</a>
+
                             <table class="table engineer_table">
                                 <thead>
                                 <tr>

+ 25 - 1
web/users/views/compilation/modal.html

@@ -334,7 +334,7 @@
                     <label>定额库</label>
                     <div class="row">
                         <div class="col-xs-12">
-                            <select class="form-control" name="ration_lib">
+                            <select class="form-control multiple" name="ration_lib" multiple="multiple">
                                 <option value="">请选择定额库</option>
                             </select>
                         </div>
@@ -349,6 +349,30 @@
     </div>
 </div>
 
+<div class="modal fade in" id="copy-lib" data-backdrop="static">
+    <div class="modal-dialog" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title">复制确认</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">×</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <div class="form-group">
+                    <div>
+                        <label>确认要复制定额库配置到当前费用定额下所有工程专业中?</label>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer" style="justify-content: center">
+                <button type="button" class="btn btn-primary" data-dismiss="modal" id="copy-lib-confirm">是</button>
+                <button type="button" class="btn btn-primary" data-dismiss="modal">否</button>
+            </div>
+        </div>
+    </div>
+</div>
+
 
 
 <script type="text/javascript" src="/web/users/js/col_setting.js"></script>