Procházet zdrojové kódy

输入定额编号,从定额库中匹配定额

MaiXinRong před 7 roky
rodič
revize
f6f3437be1

+ 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);
 };
 
 

+ 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);
     }
 };

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

@@ -203,7 +203,26 @@ var projectObj = {
         } 
     },
     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;