浏览代码

材料替换功能

zhangweicheng 6 年之前
父节点
当前提交
22a0273015

+ 1 - 0
config/gulpConfig.js

@@ -119,6 +119,7 @@ module.exports = {
         'web/building_saas/main/js/main.js',
         'web/building_saas/main/js/controllers/project_controller.js',
         'web/building_saas/main/js/controllers/block_controller.js',
+        'web/building_saas/main/js/controllers/material_controller.js',
         'web/building_saas/main/js/views/side_tools.js',
         'web/building_saas/main/js/views/std_billsGuidance_lib.js',
         'web/building_saas/main/js/views/std_bills_lib.js',

+ 53 - 0
modules/all_models/material_replace_lib.js

@@ -0,0 +1,53 @@
+/**
+ * Created by zhang on 2018/8/22.
+ */
+//材料替换库
+const mongoose = require('mongoose');
+const Schema = mongoose.Schema;
+const oprSchema = require('../all_schemas/opr_schema');
+const material_lib = new Schema({
+        ID:{type:String,index:true},
+        creator: String,
+        createDate: Number,
+        recentOpr: [oprSchema],
+        name: String,
+        compilationId: String,
+        compilationName: String,
+        billsLibId:Number,
+        billsLibName:String,
+        deleted: Boolean
+    }, {versionKey: false}
+);
+
+mongoose.model("std_material_replace_lib", material_lib,"std_material_replace_lib");
+
+
+const std_replace_bills = new Schema({
+        ID: {type:String,index:true},
+        libID:{type:String,index:true},
+        code: {type:String,index:true},
+        name: String,
+        rule:Number//规则类型
+    }, {versionKey: false}
+);
+
+mongoose.model('std_replace_bills', std_replace_bills, 'std_replace_bills');
+
+
+const std_replace_material = new Schema({
+    ID: {type:String,index:true},
+    libID:{type:String,index:true},
+    billsItemID:{type:String,index:true},
+    code: String,
+    name: String,
+    specs: String,
+    type: Number,
+    unit: String
+},{versionKey: false});
+
+mongoose.model('std_replace_material', std_replace_material, 'std_replace_material');
+
+
+
+
+

+ 25 - 0
modules/main/controllers/material_replace_controller.js

@@ -0,0 +1,25 @@
+/**
+ * Created by zhang on 2018/9/12.
+ */
+
+let materialFacade = require('../facade/material_replace_facade');
+let logger = require("../../../logs/log_helper").logger;
+module.exports ={
+    findMaterial:async function(req,res) {
+        let result={
+            error:0
+        }
+        try {
+            let data = req.body.data;
+            console.log(data);
+          //  data = JSON.parse(data);
+
+        }catch (err){
+            logger.err(err);
+            result.error=1;
+            result.message = err.message;
+        }
+        res.json(result);
+    }
+
+};

+ 3 - 1
modules/main/facade/bill_facade.js

@@ -221,10 +221,12 @@ function generateBillTasks(data) {
 
 
 async function insertMany(datas,model) {
+    let tem = [];
     while (datas.length>1000){//因为mongoose限制了批量插入的条数为1000.所以超出限制后需要分批插入
         let newList = datas.splice(0,1000);//一次插入1000条
         await model.insertMany(newList);
+        tem = tem.concat(newList);
     }
     await model.insertMany(datas);
-
+    if(tem.length > 0) datas.push(...tem);//还原数组
 }

+ 3 - 0
modules/main/facade/material_replace_facade.js

@@ -0,0 +1,3 @@
+/**
+ * Created by zhang on 2018/9/12.
+ */

+ 16 - 0
modules/main/routes/material_replace_route.js

@@ -0,0 +1,16 @@
+/**
+ * Created by zhang on 2018/9/12.
+ */
+
+let express = require('express');
+let materialController = require('../controllers/material_replace_controller');
+
+module.exports = function (app) {
+
+    var materialRouter = express.Router();
+
+    materialRouter.post('/getMaterial', materialController.findMaterial);
+
+
+    app.use('/material',materialRouter);
+}

+ 3 - 1
public/web/tree_sheet/tree_sheet_helper.js

@@ -125,7 +125,7 @@ var TREE_SHEET_HELPER = {
                 }
             }
             setting.cols.forEach(function (colSetting, iCol) {
-                var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
+
    /* if(typeof projectObj !== 'undefined'){ 7/28  取消黑体显示
                     let boldFontStyle = projectObj.getBoldFontStyle(node, colSetting);
                     sheet.setStyle(iRow, iCol, boldFontStyle);
@@ -179,6 +179,8 @@ var TREE_SHEET_HELPER = {
 
                 }
 
+                if(colSetting.visible == false) return;//隐藏列不做其它操作
+                var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
                 if (colSetting.data.getText && Object.prototype.toString.apply(colSetting.data.getText) === "[object Function]") {
                     cell.value(colSetting.data.getText(node));
                 } else {

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

@@ -1547,6 +1547,7 @@
     <script type="text/javascript" src="/web/building_saas/main/js/main.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/controllers/project_controller.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/controllers/block_controller.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/controllers/material_controller.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/side_tools.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/std_billsGuidance_lib.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/std_bills_lib.js"></script>

+ 0 - 1
web/building_saas/main/js/controllers/block_controller.js

@@ -331,7 +331,6 @@ let BlockController = {
                 i==0?firstNode = temNode:'';
             }
         }
-
         ProjectController.syncDisplayNewNodes(projectObj.mainController, newNodes);
         let sels = projectObj.mainController.sheet.getSelections();
         //设置选中并更新下方显示

+ 52 - 0
web/building_saas/main/js/controllers/material_controller.js

@@ -0,0 +1,52 @@
+/**
+ * Created by zhang on 2018/9/12.
+ */
+let MaterialController = {
+    rule1:"材质及规格:",
+    replaceMaterial:function(node){
+
+        this.getMaterial([node]);
+        let itemText = node.data.itemCharacterText;
+        let keyWord =  this.getKeyString(itemText,this.rule1);
+        console.log(keyWord);
+
+    },
+
+
+
+
+    getMaterial:function (nodes,callback) {
+        let data = [],materialMap= null;
+        for(let n of nodes){
+            let code = n.data.code;
+            if(code.length >= 9 && n.data.billsLibId){
+                let billCode = code.substr(0,9);
+                data.push({code:billCode,billsLibId:n.data.billsLibId});
+            }
+        }
+        if(data.length>0){
+            //data去重
+
+
+
+
+        }else {
+            callback(null);
+        }
+    },
+
+    getKeyString:function (itemText,matchStr) {//截取关键数据
+        itemText = itemText.replace(/:/g, ":");//中文字符转换为英文字符
+        itemText = itemText.replace(matchStr,"@$@");//用特殊符号取代关键字,方便截取
+        let index = itemText.indexOf("@$@");
+        if(index == -1) return null;
+        let temString = itemText.substr(index+3);
+        let strArray =  temString.split(/\n/);
+        let keyString = this.trim(strArray[0]);
+        return keyString===""?null:keyString;
+    },
+    trim:function (str) {
+        return str.replace(/(^\s*)|(\s*$)/g, "");
+    }
+
+};

+ 7 - 4
web/building_saas/main/js/controllers/project_controller.js

@@ -29,15 +29,18 @@ ProjectController = {
                 }
                 return rst;
             });
+            let lastNode = null;
             for(let newNode of newNodes){
                 sc.sheet.addRows(newNode.serialNo(), 1);
-            }
-            for(let newNode of newNodes){
-                sc.setTreeSelected(newNode);
                 TREE_SHEET_HELPER.refreshTreeNodeData(sc.setting, sc.sheet, [newNode], false);
-                sc.sheet.setSelection(newNode.serialNo(), sels[0].col, 1, 1);
+                lastNode = newNode
                // sc.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
             }
+            if(lastNode){
+                sc.setTreeSelected(lastNode);
+                sc.sheet.setSelection(lastNode.serialNo(), sels[0].col, 1, 1);
+            }
+
             cbTools.refreshFormulaNodes();
         });
     },

+ 18 - 4
web/building_saas/main/js/views/project_view.js

@@ -1383,6 +1383,17 @@ var projectObj = {
                             projectObj.editContent(node,'claimVisa');
                         }
                     }
+                },
+                "replaceMaterial":{
+                    name:'智能材料替换',
+                    icon: 'fa-edit',
+                    visible:function (key,opt) {
+                        let  selected = project.mainTree.selected;
+                        return selected.sourceType==ModuleNames.bills ?project.Bills.isFXorBX(selected)||selected.source.children.length ==0:false//是分项、补项或叶子清单才显示;
+                    },
+                    callback:function(){
+                        MaterialController.replaceMaterial(project.mainTree.selected);
+                    }
                 }
             }
         });
@@ -1405,6 +1416,7 @@ var projectObj = {
         col = parseInt(col);
         const sheet = this.mainSpread.getActiveSheet();
         sheet.setSelection(row, col, 1, 1);
+        row=row<this.mainController.tree.items.length?row:0;
         this.mainController.setTreeSelected(this.mainController.tree.items[row]);//触发树节点选中事件
         sheet.showRow(row, GC.Spread.Sheets.VerticalPosition.center);
     },
@@ -1693,10 +1705,12 @@ var projectObj = {
         });
     },
     ifItemCharHiden:function (setting) {//项目特征及内容列是否隐藏
-        let col = _.find(setting.cols,function (item) {
-            return  item.data.field == "itemCharacterText";
-        })
-        return !col.visible;
+        if(this.itemCol == null||this.itemCol == undefined){
+            this.itemCol = _.find(setting.cols,function (item) {
+                return  item.data.field == "itemCharacterText";
+            })
+        }
+        return !this.itemCol.visible;
     },
     //综合合价cellType
     getCommonTotalFeeCellType:function () {