Browse Source

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost

zhangweicheng 7 years ago
parent
commit
410bb54091

+ 6 - 0
modules/bills_lib/controllers/bills_lib_controllers.js

@@ -239,6 +239,12 @@ module.exports = {
         billsLibDao.edUpdateItem(data, function(err, message, id){
             callback(req, res, err, message, id);
         })
+    },
+    getStdBillsByCode: function (req, res) {
+        let data = JSON.parse(req.body.data);
+        billsLibDao.getStdBillsByCode(data, function (err, message, data) {
+            callback(req, res, err, message, data)
+        });
     }
 }
 

+ 3 - 0
modules/bills_lib/controllers/bills_permissionController.js

@@ -53,6 +53,9 @@ class billsPermContr extends baseController{
     deleteBills(req, res){
         billsController.deleteBills(req, res);
     }
+    getStdBillsByCode(req, res) {
+        billsController.getStdBillsByCode(req, res);
+    }
 
 }
 

+ 88 - 0
modules/bills_lib/models/bills_lib_interfaces.js

@@ -3031,5 +3031,93 @@ billsLibDao.prototype.edUpdateItem = function(data, callback){
 };
 //
 
+billsLibDao.prototype.getStdBillsByCode = function (data, callback) {
+    let findData = function (value, field, Array) {
+        let i = 0;
+        for (i = 0; i < Array.length; i++) {
+            if (value[field] === Array[i][field]) {
+                return Array[i];
+            }
+        }
+        return null;
+    };
+    let MergeData = function (arr) {
+        let result = "", count = 0;
+        for(let i = 0; i < arr.length; i++){
+            if(arr[i].isChecked === true){
+                count += 1;
+                if (count === 1) {
+                    result += count + ". " + arr[i].content;
+                } else {
+                    result += "\n" + count + ". " + arr[i].content;
+                }
+            }
+        }
+        return result;
+    }
+    async.waterfall([
+        function (callback) {
+            Bills.findOne({'billsLibId': data.billsLibId, 'code': data.code, 'deleted': false}, "-_id", function (err, result) {
+                callback(err, JSON.parse(JSON.stringify(result)));
+            });
+        },
+        function (bills, callback) {
+            if (bills) {
+                ItemCharacter.find({'billsLibId': data.billsLibId, 'deleted': false}, '-_id', function (err, result) {
+                    if (err) {
+                        callback(err, bills);
+                    } else {
+                        bills.itemCharacter = [];
+                        if (result && bills && bills.items) {
+                            for (let item of bills.items) {
+                                let itemData = findData(item, 'id', result);
+                                if (itemData) {
+                                    bills.itemCharacter.push(JSON.parse(JSON.stringify(itemData)));
+                                }
+                            }
+                        }
+                        bills.itemCharacterText = MergeData(bills.itemCharacter);
+                        callback(err, bills);
+                    }
+                });
+            } else {
+                callback(null, bills);
+            }
+            
+        },
+        function (bills, callback) {
+            if (bills) {
+                JobContent.find({'billsLibId': data.billsLibId, 'deleted': false}, '-_id', function (err, result) {
+                    if (err) {
+                        callback(err, bills);
+                    } else {
+                        bills.jobContent = [];
+                        if (result && bills && bills.jobs) {
+                            for (let job of bills.jobs) {
+                                let jobData = findData(job, 'id', result);;
+                                if (jobData) {
+                                    jobData = JSON.parse(JSON.stringify(jobData));
+                                    jobData.isChecked = true;
+                                    bills.jobContent.push(jobData);
+                                }
+                            }
+                        }
+                        bills.jobContentText = MergeData(bills.jobContent);
+                        callback(err, bills);
+                    }
+                });
+            } else {
+                callback(null, bills);
+            }
+        }
+    ], function (err, result) {
+        if (err) {
+            callback(1, err, null);
+        } else {
+            callback(0, err, result);
+        }
+    });
+};
+
 
 module.exports = new billsLibDao();

+ 2 - 0
modules/bills_lib/routes/bills_lib_routes.js

@@ -65,6 +65,8 @@ module.exports =function (app) {
     billsRouter.post("/edCreateItem", itemsContr.init, itemsContr.edCreateItem);
     billsRouter.post("/edUpdateItem", itemsContr.init, itemsContr.edUpdateItem);
 
+    billsRouter.post('/getStdBillsByCode', billsContr.init, billsContr.getStdBillsByCode);
+
     app.use("/stdBillsEditor", billsRouter);
 
 }

+ 2 - 2
modules/main/controllers/labour_coe_controller.js

@@ -26,10 +26,10 @@ async function getProjectLabourCoe(req, res) {
 };
 
 async function getStdLabourCoe(req, res) {
-    let result={error: 0};
+    let result = {error: 0, message: '', data: null};
 
     try {
-        let stdLC = await labourCoeFacade.getStdLabourCoe(req.body.data.libID);
+        let stdLC = await labourCoeFacade.getStdLabourCoe(req.body.ID);
         result.data= stdLC;
     }catch (err){
         console.log(err);

+ 21 - 5
modules/main/facade/labour_coe_facade.js

@@ -54,13 +54,29 @@ async function getStdLabourCoe(libID) {
 };
 
 // 统一的 getData() 方法供project调用
-function getData (projectID, callback) {
-    projectLabourCoesModel.findOne({projectID: projectID}, '-_id', function(err, datas) {
-            if (!err) {
-                callback(0, projectConsts.LABOUR_COE, datas);
+function getData(projectID, callback) {
+    projectLabourCoesModel.findOne({projectID: projectID}, '-_id', function (err, datas) {
+        if (!err) {
+            // 旧项目没有人工系数文件,默认给它生成一个。
+            if (!datas) {
+                getStdLabourCoe(1).then(function (stdLC) {
+                    let doc = {
+                        ID: uuidV1(),
+                        projectID: projectID,
+                        name: '[旧项目补人工系数文件]',
+                        libID: stdLC.ID,
+                        libName: stdLC.libName,
+                        coes: stdLC.coes
+                    };
+                    projectLabourCoesModel.create(doc);
+                    callback(0, projectConsts.LABOUR_COE, stdLC);
+                });
             } else {
-                callback(1, projectConsts.LABOUR_COE, null);
+                callback(0, projectConsts.LABOUR_COE, datas);
             };
+        } else {
+            callback(1, projectConsts.LABOUR_COE, null);
+        };
     });
 };
 

+ 31 - 0
modules/ration_repository/controllers/search_controller.js

@@ -3,6 +3,7 @@
  */
 var rationItem = require('../models/ration_item');
 let rationChapter = require('../models/ration_section_tree');
+let asyncTool = require('async');
 var callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
 };
@@ -32,5 +33,35 @@ module.exports = {
                 callback(req, res, 0, '', rst);
             }
         });
+    },
+    matchRation: function (req, res) {
+        let rId = req.body.rationLibId, code = req.body.code;
+        asyncTool.waterfall([
+            function (callback) {
+                rationItem.matchRation(rId, code, callback);
+            },
+            function (ration, callback) {
+                if (ration) {
+                    rationChapter.getRationChapter(rId, ration.sectionId).then(function(result, err) {
+                        if (!err) {
+                            ration.chapter = JSON.parse(JSON.stringify(result));
+                            callback(err, ration);
+                        } else {
+                            callback(err, ration);
+                        }
+                    }).catch(
+
+                    );
+                } else {
+                    callback(null, ration);
+                }
+            }
+        ], function (err, result) {
+            if (err) {
+                callback(req, res, 1, err, null);
+            } else {
+                callback(req, res, 0, err, result);
+            }
+        });
     }
 };

+ 13 - 2
modules/ration_repository/models/ration_item.js

@@ -113,8 +113,19 @@ rationItemDAO.prototype.findRation = function (repId, keyword, callback) {
         } else {
             callback(false, '', data);
         }
-    })
-}
+    });
+};
+
+rationItemDAO.prototype.matchRation = function (repId, keyword, callback) {
+    let filter = {
+        'rationRepId': repId,
+        'code': keyword,
+        '$or': [{'isDeleted': {"$exists":false}}, {'isDeleted': null}, {'isDeleted': false}]
+    };
+    rationItemModel.findOne(filter, function (err, data) {
+        callback(err, JSON.parse(JSON.stringify(data)));
+    });
+};
 
 rationItemDAO.prototype.getRationItem = function (repId, code, callback) {
     if (callback) {

+ 1 - 0
modules/ration_repository/routes/ration_front_end_routes.js

@@ -31,6 +31,7 @@ module.exports = function (app) {
 
     apiRouter.post('/getRationItem', searchController.getRationItem);
     apiRouter.post('/findRation', searchController.findRation);
+    apiRouter.post('/matchRation', searchController.matchRation);
 
     app.use("/rationRepository/api", apiRouter);
 };

+ 1 - 2
modules/ration_repository/routes/ration_rep_routes.js

@@ -42,8 +42,7 @@ module.exports = function (app) {
 
     apiRouter.post('/getRationItem', searchController.getRationItem);
     apiRouter.post('/findRation', searchController.findRation);
-
-
+    apiRouter.post('/matchRation', searchController.matchRation);
 };
 
 

+ 1 - 1
web/building_saas/main/html/main.html

@@ -478,7 +478,7 @@
                                 <!--人工单价调整-->
                                 <div class="tab-pane fade" id="poj-settings-6" role="tabpanel">
                                     <div class="row px-3">
-                                        <select class="col-4 form-control form-control-sm"><option>渝建[2016]71号</option><option>渝建[2017]78号</option></select>
+                                        <select class="col-4 form-control form-control-sm" id="std_labour_coe_files"><option>渝建[2016]71号</option><option>渝建[2017]78号</option></select>
                                     </div>
                                     <div style="height:8px;"></div>
                                     <div class="modal-auto-height" id="labourCoeSpread"></div>

+ 51 - 1
web/building_saas/main/js/models/bills.js

@@ -164,7 +164,7 @@ var Bills = {
             var newData = null, that = this;
             insertData.forEach(function (data) {
                 if (data.type === idTree.updateType.new) {
-                    data.data.code = stdBillsData.code;
+                    data.data.code = that.newFormatCode(stdBillsData.code);
                     data.data.name = stdBillsData.name;
                     data.data.unit = stdBillsData.unit;
                     // 工程量计算规则
@@ -285,6 +285,56 @@ var Bills = {
             }
         };
 
+        bills.prototype.sameStdCode = function (stdCode, filterCode) {
+            let reg = new RegExp('^' + stdCode), matchs= [];
+            for (let data of this.datas) {
+                if (data.code && data.code.length === 12 && reg.test(data.code) && data.code !== filterCode) {
+                    matchs.push(data.code);
+                }
+            }
+            return matchs;
+        }
+
+        bills.prototype.newFormatCode = function (stdCode, filterCode) {
+            let matchs = this.sameStdCode(stdCode, filterCode);
+            let format = function (Number) {
+                let s = Number + '';
+                while (s.length < 3) {
+                    s = '0' + s;
+                }
+                return s;
+            }
+            for (i = 0; i <= matchs.length; i++) {
+                let formatCode = stdCode + format(i+1);
+                if (matchs.indexOf(formatCode) === -1) {
+                    return formatCode;
+                }
+            }
+        };
+
+        bills.prototype.replaceBills = function (node, stdBillsData, code) {
+            let updateData = [];
+            node.data.code = code;
+            if (stdBillsData) {
+                node.data.name = stdBillsData.name;
+                node.data.unit = stdBillsData.unit;
+                // 工程量计算规则
+                node.data.ruleText = stdBillsData.ruleText;
+                // 说明(补注)
+                node.data.comments = stdBillsData.recharge;
+                // 工作内容
+                node.data.jobContent = stdBillsData.jobContent;
+                node.data.jobContentText = stdBillsData.jobContentText;
+                // 特征
+                node.data.itemCharacter = stdBillsData.itemCharacter;
+                node.data.itemCharacterText = stdBillsData.itemCharacterText;
+            }
+            updateData.push({'updateType': 'ut_update', 'updateData': tools.formatBillsUpdateData(node.data)});
+
+            this.project.pushNow('replaceBills', this.getSourceType(), updateData);
+            return node;            
+        }
+
         return new bills(project);
     }
 };

+ 3 - 2
web/building_saas/main/js/models/calc_program.js

@@ -3463,7 +3463,7 @@ let calcTemplates = [
     }
 ];*/
 
-let calcLabourCoes = [
+/*let calcLabourCoes = [
     {
         "ID" : 1,
         "ParentID" : null,
@@ -3590,7 +3590,7 @@ let calcLabourCoes = [
         "name" : "盾构用工",
         "coe" :1.49
     }
-];
+];*/
 
 class CalcProgram {
     constructor(project){
@@ -3600,6 +3600,7 @@ class CalcProgram {
 
     compileAllTemps(){
         let calcFeeRates = this.project.FeeRate.datas.rates;
+        let calcLabourCoes = this.project.LabourCoe.datas.coes;
         this.calc.compilePublics(calcFeeRates, calcLabourCoes, feeType, rationCalcBase);
         for (let calcTemplate of calcTemplates){
             this.calc.compileTemplate(calcTemplate);

+ 31 - 1
web/building_saas/main/js/models/ration.js

@@ -280,8 +280,38 @@ var Ration = {
             } else {
                 this.project.push(this.getSourceType(), updateData);
             }
-        }
+        };
+
+        ration.prototype.replaceRation = function (ration, std) {
+            this.project.beginUpdate('replaceRation');
+            
+            // delete
+            let ration_glj =projectObj.project.ration_glj;
+            this.project.push(this.project.ration_glj.getSourceType(), this.project.ration_glj.getDeleteDataByRation(ration));
+
+            this.project.ration_glj.deleteByRation(ration);
+            this.project.ration_coe.deleteByRation(ration);
+            this.project.quantity_detail.deleteByRation(ration);
 
+            // insertNewRation
+            let updateData = [];
+            ration.code = std.code;
+            ration.name = std.name;
+            ration.caption = std.caption;
+            ration.unit = std.unit;
+            ration.libID = std.rationRepId;
+            ration.content = std.jobContent;
+            if (std.chapter) {
+                ration.comments = std.chapter.explanation;
+                ration.ruleText = std.chapter.ruleText;
+            }
+            ration.rationAssList = projectObj.project.ration_ass.CreateNewAss(std);
+            updateData.push({updateType: 'ut_update', updateData: ration});
+            this.project.push(this.getSourceType(), updateData);
+
+            this.project.endUpdate();
+        };
+        
         return new ration(project);
     }
 };

+ 3 - 2
web/building_saas/main/js/views/character_content_view.js

@@ -661,8 +661,9 @@ let pageCCOprObj = {
         node.data.itemCharacter = itemCharacter;
         node.data.jobContentText = contentTxt ? contentTxt : '';
         node.data.itemCharacterText = characterTxt ? characterTxt : '';
-
-
+    },
+    safeItemCharater: function (itemCharater) {
+        return characterOprObj.buildItemCharactet(itemCharater);
     },
     //设置特征及内容currentCache
     setCacheAndShow: function (node) {

+ 55 - 5
web/building_saas/main/js/views/project_property_labour_coe_view.js

@@ -7,10 +7,27 @@ let labourCoeView = {
     spread: null,
     sheet: null,
 
-    buildSheet: function (){
+    init(){
         let me = this;
-        me.datas = calcLabourCoes;
 
+        function getStdLabourCoeFilesHtml(stdLabourCoeLibs) {
+            let result = '<option value="">请选择人工系数标准库</option>';
+            if (stdLabourCoeLibs.length <= 0) {
+                return result;
+            };
+
+            for (let lib of stdLabourCoeLibs){
+                result += '<option value="'+ lib.id +'">'+ lib.name +'</option>';
+            };
+            return result;
+        };
+
+        let stdLCHtml = getStdLabourCoeFilesHtml(projectInfoObj.projectInfo.engineeringInfo.artificial_lib);
+        $("#std_labour_coe_files").html(stdLCHtml);
+    },
+
+    buildSheet: function (){
+        let me = this;
         if (me.spread) {
             me.spread.destroy();
             me.spread = null;
@@ -35,8 +52,9 @@ let labourCoeView = {
         sheet.resumePaint();
     },
 
-    loadData(){          // 树结构转换二维表显示,行列转换
+    loadData(datas){          // 树结构转换二维表显示,行列转换
         let me = this;
+        me.datas = datas;
         let libArr = [];
         for (let v of me.datas) {if (!v.ParentID) libArr.push(v);};
 
@@ -53,7 +71,7 @@ let labourCoeView = {
         me.sheet.setRowCount(row, GC.Spread.Sheets.SheetArea.viewport);
         me.sheet.setText(0, 0, "定额工种", GC.Spread.Sheets.SheetArea.colHeader);
         me.sheet.options.isProtected = true;
-        me.sheet.getRange(-1, 1, -1, libArr.length + 1, GC.Spread.Sheets.SheetArea.viewport).locked(false); 
+        me.sheet.getRange(-1, 1, -1, libArr.length + 1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
 
         // 列名称
         for (let c = 0; c <= libArr.length - 1; c++) {
@@ -75,8 +93,10 @@ let labourCoeView = {
 
     showData(){
         let me = this;
+        let datas = projectObj.project.LabourCoe.datas !== null ? projectObj.project.LabourCoe.datas.coes : [];
+        me.init();
         me.buildSheet();
-        me.loadData();
+        me.loadData(datas);
     }
 };
 
@@ -84,4 +104,34 @@ $(document).ready(function(){
     $("#tab_poj-settings-6").on('shown.bs.tab', function (e) {
         labourCoeView.showData();
     });
+
+    $("#std_labour_coe_files").change(function() {
+        // 取标准库数据过来显示。
+        let libID = $(this).val();
+        if (libID == ''){
+            labourCoeView.loadData([]);
+            return false;
+        };
+
+        $.ajax({
+            type:"POST",
+            url: '/labourCoe/getStdLabourCoe',
+            data: {"ID": libID},
+            dataType: 'json',
+            cache: false,
+            timeout: 50000,
+            success: function(result){
+                if (result.error === 0) {
+                    labourCoeView.buildSheet();
+                    labourCoeView.loadData(result.data.coes);
+
+                } else {
+                    alert('error: ' + result.message);
+                }
+            },
+            error: function(jqXHR, textStatus, errorThrown){
+                alert('error ' + textStatus + " " + errorThrown);
+            }
+        });
+    });
 });

+ 73 - 1
web/building_saas/main/js/views/project_view.js

@@ -163,6 +163,75 @@ var projectObj = {
         this.mainController.refreshTreeNode(nodes, false);
         calc = null;
     },
+    updateBillsCode: function (node, value) {
+        let project = projectObj.project;
+        let stdMatchCode, formatCode, matchs;
+        let searchStdBillsAndUpdate = function (stdCode, formatCode) {
+            let orgCode = node.data.code.substr(0, 9);
+            if (stdCode === orgCode || projectInfoObj.projectInfo.engineeringInfo.bill_lib.length === 0) {
+                project.Bills.updateField(node.source, 'code', formatCode, true);
+                projectObj.mainController.refreshTreeNode([node], false);
+            } else if (projectInfoObj.projectInfo.engineeringInfo.bill_lib.length > 0) {
+                let libId = projectInfoObj.projectInfo.engineeringInfo.bill_lib[0].id;
+                CommonAjax.post('/stdBillsEditor/getStdBillsByCode', {userId: userID, billsLibId: libId, code: stdCode}, function (data) {
+                    if (data) {
+                        data.itemCharacter = pageCCOprObj.safeItemCharater(data.itemCharacter);
+                        project.Bills.replaceBills(node.source, data, formatCode);
+                    } else {
+                        project.Bills.updateField(node.source, 'code', formatCode, true);
+                    }
+                    projectObj.mainController.refreshTreeNode([node], false);
+                });
+            }
+        }
+        if (value.length === 9 && /^[\d]+$/.test(value)) {
+            stdMatchCode = value;
+            formatCode = project.Bills.newFormatCode(stdMatchCode);
+            searchStdBillsAndUpdate(stdMatchCode, formatCode);
+        } else if (value.length === 12 && /^[\d]+$/.test(value)) {
+            stdMatchCode = value.substr(0, 9);
+            matchs = project.Bills.sameStdCode(stdMatchCode, node.data.code);
+            if (matchs.indexOf(value) === -1) {
+                searchStdBillsAndUpdate(stdMatchCode, value);
+            } else if (confirm('已存在该编码的清单,是否继续?')) {
+                formatCode = project.Bills.newFormatCode(stdMatchCode, node.data.code);
+                searchStdBillsAndUpdate(stdMatchCode, formatCode);
+            }
+        } else {
+            project.Bills.updateField(node.source, 'code', value, true);
+            this.mainController.refreshTreeNode([node], false);
+        } 
+    },
+    updateRationCode: function (node, value) {
+        if (/[\w]{2}[\d]{4}/.test(value)) {
+            if (projectInfoObj.projectInfo.engineeringInfo.ration_lib.length === 0) {
+                alert('当前项目无定额库,请添加定额库。');
+                this.mainController.refreshTreeNode([node], false);
+            } else {
+                let libId = projectInfoObj.projectInfo.engineeringInfo.ration_lib[0].id;
+                CommonAjax.postRationLib('/rationRepository/api/matchRation', {user_id: userID, rationLibId: libId, code: value}, function (data) {
+                    if (data) {
+                        projectObj.project.Ration.replaceRation(node.source, data);
+                        projectObj.project.ration_glj.addRationGLJ(node.source, data);
+                    } else {
+                        alert('当前库中找不到定额"' + value + '"');
+                    }
+                    projectObj.mainController.refreshTreeNode([node], false);
+                });
+            }
+        } else {
+            alert('输入的定额编码有误,请检查。');
+            this.mainController.refreshTreeNode([node], false);
+        }
+    },
+    updateCode: function (node, value) {
+        let project = projectObj.project;
+        if (node.sourceType === project.Bills.getSourceType()) {
+            this.updateBillsCode(node, value);
+        } else if (node.sourceType === project.Ration.getSourceType()) {
+            this.updateRationCode(node, value);
+        }
+    },
     mainSpreadEditEnded: function (sender, info) {
         let project = projectObj.project;
         let node = project.mainTree.items[info.row];
@@ -173,7 +242,7 @@ var projectObj = {
 
         if (value && value !== calcFees.getFee(node.data, fieldName)) {
             if (fieldName === 'code') {
-
+                projectObj.updateCode(node, value);
             } else if (fieldName === 'quantity' && project.quantity_detail.quantityEditChecking(value,node,fieldName)) {
                 projectObj.updateAndReCalculate(node, fieldName, value);
             } else if (fieldName === 'feesIndex.common.unitFee') {
@@ -232,6 +301,9 @@ var projectObj = {
                         col.data.decimal = that.project.getDecimal(col.data.digit);
                         col.data.formatter = MainTreeCol.getNumberFormatter(col.data.decimal);
                     }
+                    if (col.data.field === 'code') {
+                        col.data.formatter = '@';
+                    }
                 });
 
                 that.project.calcProgram = new CalcProgram(that.project);

+ 1 - 1
web/building_saas/main/js/views/std_bills_lib.js

@@ -66,7 +66,7 @@ var billsLibObj = {
         var stdBillsTreeController = TREE_SHEET_CONTROLLER.createNew(stdBillsTree, billsLibObj.stdBillsSpread.getActiveSheet(), billsLibObj.stdBillsTreeSetting);
         var findData = function (value, field, Array) {
             var i = 0;
-            for (i = 0; i < Array.length - 1; i++) {
+            for (i = 0; i < Array.length; i++) {
                 if (value[field] === Array[i][field]) {
                     return Array[i];
                 }