Browse Source

信息价语义匹配

zhangweicheng 4 năm trước cách đây
mục cha
commit
22dead8d41

+ 87 - 1
modules/main/facade/info_price_facade.js

@@ -15,6 +15,14 @@ let unitPriceModel = mongoose.model("unit_price");
 let _ = require("lodash");
 let gljUtil = require('../../../public/web/gljUtil');
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
+// 载入模块
+var Segment = require('segment');
+// 创建实例
+var segment = new Segment();
+// 使用默认的识别模块及字典,载入字典文件需要1秒,仅初始化时执行一次即可
+segment.useDefault();
+
+
 async function getOptions(data,compilation){//data 是预留对象,暂时不用
   let compilationID = compilation._id;
   let areaMap={};
@@ -42,7 +50,20 @@ async function getOptions(data,compilation){//data 是预留对象,暂时不
 async function getDataByCondition(data,compilation){
   let result = {};
   data.condition["compilationID"] = compilation._id;
-  if(data.keyWord) data.condition.name = {"$regex":new RegExp(data.keyWord, "i")};
+  //根据地区+期数+材料编号的前4位与信息价材料的分类编号匹配,如果有数据,则显示数据出来。
+  //先按编号匹配
+  if (data.code) { 
+    result = await getDataByCode(data.code, data);
+    if (result.totalSize > 0) return result;
+  }
+
+  //编号匹配不上的情况:
+  //有关键字的情况
+  if (data.keyWord) { 
+    return await getDataByKeyWord(data.keyWord,data);
+  } 
+
+  //查询所有的情况
   if(data.lastID){ //有最后一行说明是查询下一页
     data.condition["_id"] = {$gt:mongoose.Types.ObjectId(data.lastID)};
   }else{
@@ -52,6 +73,71 @@ async function getDataByCondition(data,compilation){
   return result;
 }
 
+
+async function getDataByCode(code, data) { 
+  let condition = { ...data.condition };
+  condition.code = code;
+  let totalSize = await infoItemsModel.find(condition).count();
+  if (data.lastID) { //有最后一行说明是查询下一页
+    condition["_id"] = {$gt:mongoose.Types.ObjectId(data.lastID)};
+  }
+  let items = [];
+  if (totalSize > 0) { 
+    items = await infoItemsModel.find(condition).lean().sort({"_id":1}).limit(50);
+  }
+   
+  return {totalSize,items}
+}
+
+
+async function getDataByKeyWord(keyword, data) {
+  let items = [];
+  let nameArray = [];
+  //混凝土 和 砼 认成一个
+ // keyword = keyword.replace(/混凝土/g, "砼");
+  if (keyword.length < 3) {
+    nameArray.push(keyword)
+  } else { 
+    nameArray = segment.doSegment(keyword, {
+      simple: true, //不返回词性
+      stripPunctuation: true //去除标点符号
+    });
+  }
+  let temArr = [];
+  for (let a of nameArray) { 
+    if (a == "混凝土") a = '砼';
+    if (a == '砼' || a.length > 1) temArr.push(a);
+  }
+  nameArray = temArr;
+  console.log(nameArray);
+
+  let allInfoPrice = await infoItemsModel.find(data.condition).lean().sort({"_id":1});
+
+  let maxNum = 0;//最大匹配数
+  let matchMap = {};//匹配储存
+
+  for (let info of allInfoPrice) { 
+    //specs
+    let mstring = info.name + info.spec;
+    mstring = mstring.replace(/混凝土/g, "砼");
+    let matchCount = 0;
+    for (let na of nameArray) { 
+      if (mstring.indexOf(na) != -1) { 
+        matchCount++;
+      }
+    }  
+    if (matchCount > 0) { 
+      matchMap[matchCount] ? matchMap[matchCount].push(info) : matchMap[matchCount] = [info];
+      if (matchCount > maxNum) maxNum = matchCount;
+    }
+  }
+  
+  if (maxNum > 0) items = matchMap[maxNum];
+  totalSize = items.length
+  return {totalSize,items}
+}
+
+
 async function mutiApplyInfoPrice(data,compilation){
   data.condition["compilationID"] = compilation._id;
   let infoPrices = await infoItemsModel.find(data.condition).lean();

+ 85 - 80
package-lock.json

@@ -4566,8 +4566,8 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "delegates": "1.0.0",
-            "readable-stream": "2.3.7"
+            "delegates": "^1.0.0",
+            "readable-stream": "^2.0.6"
           }
         },
         "balanced-match": {
@@ -4580,7 +4580,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "balanced-match": "1.0.0",
+            "balanced-match": "^1.0.0",
             "concat-map": "0.0.1"
           }
         },
@@ -4614,7 +4614,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "ms": "2.1.2"
+            "ms": "^2.1.1"
           }
         },
         "deep-extend": {
@@ -4637,7 +4637,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "minipass": "2.9.0"
+            "minipass": "^2.6.0"
           }
         },
         "fs.realpath": {
@@ -4650,14 +4650,14 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "aproba": "1.2.0",
-            "console-control-strings": "1.1.0",
-            "has-unicode": "2.0.1",
-            "object-assign": "4.1.1",
-            "signal-exit": "3.0.2",
-            "string-width": "1.0.2",
-            "strip-ansi": "3.0.1",
-            "wide-align": "1.1.3"
+            "aproba": "^1.0.3",
+            "console-control-strings": "^1.0.0",
+            "has-unicode": "^2.0.0",
+            "object-assign": "^4.1.0",
+            "signal-exit": "^3.0.0",
+            "string-width": "^1.0.1",
+            "strip-ansi": "^3.0.1",
+            "wide-align": "^1.1.0"
           }
         },
         "glob": {
@@ -4665,12 +4665,12 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "fs.realpath": "1.0.0",
-            "inflight": "1.0.6",
-            "inherits": "2.0.4",
-            "minimatch": "3.0.4",
-            "once": "1.4.0",
-            "path-is-absolute": "1.0.1"
+            "fs.realpath": "^1.0.0",
+            "inflight": "^1.0.4",
+            "inherits": "2",
+            "minimatch": "^3.0.4",
+            "once": "^1.3.0",
+            "path-is-absolute": "^1.0.0"
           }
         },
         "has-unicode": {
@@ -4683,7 +4683,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "safer-buffer": "2.1.2"
+            "safer-buffer": ">= 2.1.2 < 3"
           }
         },
         "ignore-walk": {
@@ -4691,7 +4691,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "minimatch": "3.0.4"
+            "minimatch": "^3.0.4"
           }
         },
         "inflight": {
@@ -4699,8 +4699,8 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "once": "1.4.0",
-            "wrappy": "1.0.2"
+            "once": "^1.3.0",
+            "wrappy": "1"
           }
         },
         "inherits": {
@@ -4718,7 +4718,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "number-is-nan": "1.0.1"
+            "number-is-nan": "^1.0.0"
           }
         },
         "isarray": {
@@ -4731,7 +4731,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "brace-expansion": "1.1.11"
+            "brace-expansion": "^1.1.7"
           }
         },
         "minimist": {
@@ -4744,8 +4744,8 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "safe-buffer": "5.1.2",
-            "yallist": "3.1.1"
+            "safe-buffer": "^5.1.2",
+            "yallist": "^3.0.0"
           }
         },
         "minizlib": {
@@ -4753,7 +4753,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "minipass": "2.9.0"
+            "minipass": "^2.9.0"
           }
         },
         "mkdirp": {
@@ -4761,7 +4761,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "minimist": "1.2.5"
+            "minimist": "^1.2.5"
           }
         },
         "ms": {
@@ -4774,9 +4774,9 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "debug": "3.2.6",
-            "iconv-lite": "0.4.24",
-            "sax": "1.2.4"
+            "debug": "^3.2.6",
+            "iconv-lite": "^0.4.4",
+            "sax": "^1.2.4"
           }
         },
         "node-pre-gyp": {
@@ -4784,16 +4784,16 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "detect-libc": "1.0.3",
-            "mkdirp": "0.5.3",
-            "needle": "2.3.3",
-            "nopt": "4.0.3",
-            "npm-packlist": "1.4.8",
-            "npmlog": "4.1.2",
-            "rc": "1.2.8",
-            "rimraf": "2.7.1",
-            "semver": "5.7.1",
-            "tar": "4.4.13"
+            "detect-libc": "^1.0.2",
+            "mkdirp": "^0.5.1",
+            "needle": "^2.2.1",
+            "nopt": "^4.0.1",
+            "npm-packlist": "^1.1.6",
+            "npmlog": "^4.0.2",
+            "rc": "^1.2.7",
+            "rimraf": "^2.6.1",
+            "semver": "^5.3.0",
+            "tar": "^4.4.2"
           }
         },
         "nopt": {
@@ -4801,8 +4801,8 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "abbrev": "1.1.1",
-            "osenv": "0.1.5"
+            "abbrev": "1",
+            "osenv": "^0.1.4"
           }
         },
         "npm-bundled": {
@@ -4810,7 +4810,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "npm-normalize-package-bin": "1.0.1"
+            "npm-normalize-package-bin": "^1.0.1"
           }
         },
         "npm-normalize-package-bin": {
@@ -4823,9 +4823,9 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "ignore-walk": "3.0.3",
-            "npm-bundled": "1.1.1",
-            "npm-normalize-package-bin": "1.0.1"
+            "ignore-walk": "^3.0.1",
+            "npm-bundled": "^1.0.1",
+            "npm-normalize-package-bin": "^1.0.1"
           }
         },
         "npmlog": {
@@ -4833,10 +4833,10 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "are-we-there-yet": "1.1.5",
-            "console-control-strings": "1.1.0",
-            "gauge": "2.7.4",
-            "set-blocking": "2.0.0"
+            "are-we-there-yet": "~1.1.2",
+            "console-control-strings": "~1.1.0",
+            "gauge": "~2.7.3",
+            "set-blocking": "~2.0.0"
           }
         },
         "number-is-nan": {
@@ -4854,7 +4854,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "wrappy": "1.0.2"
+            "wrappy": "1"
           }
         },
         "os-homedir": {
@@ -4872,8 +4872,8 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "os-homedir": "1.0.2",
-            "os-tmpdir": "1.0.2"
+            "os-homedir": "^1.0.0",
+            "os-tmpdir": "^1.0.0"
           }
         },
         "path-is-absolute": {
@@ -4891,10 +4891,10 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "deep-extend": "0.6.0",
-            "ini": "1.3.5",
-            "minimist": "1.2.5",
-            "strip-json-comments": "2.0.1"
+            "deep-extend": "^0.6.0",
+            "ini": "~1.3.0",
+            "minimist": "^1.2.0",
+            "strip-json-comments": "~2.0.1"
           }
         },
         "readable-stream": {
@@ -4902,13 +4902,13 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "core-util-is": "1.0.2",
-            "inherits": "2.0.4",
-            "isarray": "1.0.0",
-            "process-nextick-args": "2.0.1",
-            "safe-buffer": "5.1.2",
-            "string_decoder": "1.1.1",
-            "util-deprecate": "1.0.2"
+            "core-util-is": "~1.0.0",
+            "inherits": "~2.0.3",
+            "isarray": "~1.0.0",
+            "process-nextick-args": "~2.0.0",
+            "safe-buffer": "~5.1.1",
+            "string_decoder": "~1.1.1",
+            "util-deprecate": "~1.0.1"
           }
         },
         "rimraf": {
@@ -4916,7 +4916,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "glob": "7.1.6"
+            "glob": "^7.1.3"
           }
         },
         "safe-buffer": {
@@ -4954,9 +4954,9 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "code-point-at": "1.1.0",
-            "is-fullwidth-code-point": "1.0.0",
-            "strip-ansi": "3.0.1"
+            "code-point-at": "^1.0.0",
+            "is-fullwidth-code-point": "^1.0.0",
+            "strip-ansi": "^3.0.0"
           }
         },
         "string_decoder": {
@@ -4964,7 +4964,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "safe-buffer": "5.1.2"
+            "safe-buffer": "~5.1.0"
           }
         },
         "strip-ansi": {
@@ -4972,7 +4972,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "ansi-regex": "2.1.1"
+            "ansi-regex": "^2.0.0"
           }
         },
         "strip-json-comments": {
@@ -4985,13 +4985,13 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "chownr": "1.1.4",
-            "fs-minipass": "1.2.7",
-            "minipass": "2.9.0",
-            "minizlib": "1.3.3",
-            "mkdirp": "0.5.3",
-            "safe-buffer": "5.1.2",
-            "yallist": "3.1.1"
+            "chownr": "^1.1.1",
+            "fs-minipass": "^1.2.5",
+            "minipass": "^2.8.6",
+            "minizlib": "^1.2.1",
+            "mkdirp": "^0.5.0",
+            "safe-buffer": "^5.1.2",
+            "yallist": "^3.0.3"
           }
         },
         "util-deprecate": {
@@ -5004,7 +5004,7 @@
           "bundled": true,
           "optional": true,
           "requires": {
-            "string-width": "1.0.2"
+            "string-width": "^1.0.2 || 2"
           }
         },
         "wrappy": {
@@ -11196,6 +11196,11 @@
         }
       }
     },
+    "segment": {
+      "version": "0.1.3",
+      "resolved": "https://registry.npmjs.org/segment/-/segment-0.1.3.tgz",
+      "integrity": "sha1-YF+A/WxxMcRuOBA6F7Fojwnvr6c="
+    },
     "semver": {
       "version": "4.3.6",
       "resolved": "https://registry.npmjs.org/semver/-/semver-4.3.6.tgz",

+ 1 - 0
package.json

@@ -50,6 +50,7 @@
     "pdfkit": "^0.8.2",
     "qiniu": "^7.1.1",
     "request-promise": "^4.2.5",
+    "segment": "^0.1.3",
     "socket.io": "2.0.3",
     "ua-parser-js": "^0.7.14",
     "uuid": "^3.1.0",

+ 4 - 1
web/building_saas/glj/html/project_glj.html

@@ -147,8 +147,11 @@
               </select>
               &nbsp;
               <input type="text" class="form-control form-control-sm" id="info_search_name">
-              <button type="button" class="btn btn-outline-primary btn-sm mr-auto" id="info_search_btn"><i
+              <button type="button" class="btn btn-outline-primary btn-sm" id="info_search_btn"><i
                   class="fa fa-search" aria-hidden="true"></i></button>
+              <label class="mr-auto" id = "info-warning"></label>    
+              <input type="hidden" class="form-control form-control-sm" id="info_glj_name">
+              <input type="hidden" class="form-control form-control-sm" id="info_glj_code">       
               <button type="button" class="btn btn-primary  btn-sm" id="muti_apply_info">批量套用</button>
             </div>
             <div class="main-data-bottom" id="info_price_sheet"> </div>

+ 0 - 1
web/building_saas/main/js/views/billsElf.js

@@ -315,7 +315,6 @@ const BillsSub = (function() {
     //建表
     //@param {Object}module @return {void}
     function buildSheet(cmodule) {
-        console.log(cmodule);
         if(!cmodule.workBook){
             cmodule.workBook = new GC.Spread.Sheets.Workbook(cmodule.dom[0], {sheetCount: 1});
             sheetCommonObj.spreadDefaultStyle(cmodule.workBook);

+ 28 - 6
web/building_saas/main/js/views/project_glj_view.js

@@ -221,7 +221,7 @@ let projectGljObject = {
     sheetCommonObj.spreadDefaultStyle(this.infoPriceSpread);
     this.infoPriceSheet = this.infoPriceSpread.getSheet(0);
     this.initSheet(this.infoPriceSheet, this.infoPriceSetting);
-    this.infoPriceSheet.bind(GC.Spread.Sheets.Events.TopRowChanged, _.debounce(this.onInfoTopRowChanged, 100));
+    this.infoPriceSheet.bind(GC.Spread.Sheets.Events.TopRowChanged, _.debounce(this.onInfoTopRowChanged, 100)); 
     this.infoPriceSheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, this.onInfoPriceDoubleClick);
     this.infoPriceSheet.name('infoPriceSheet');
     this.infoPriceSheet.setRowCount(0);
@@ -534,6 +534,15 @@ let projectGljObject = {
     sheetCommonObj.showData(me.infoPriceSheet, me.infoPriceSetting, datas);
     me.infoPriceSheet.setRowCount(datas.length);
   },
+  autoShowInfoPriceData: function () { 
+    if (!$('#info-nav').hasClass('active')) return;
+    let projectGLJData = this.getProjectGLJSelected();
+    $('#info_search_name').val(projectGLJData.name);
+    let code = projectGLJData.code.substr(0, 4);
+    $('#info_glj_name').val(projectGLJData.name);
+    $('#info_glj_code').val(code);
+    this.searchInfoPrice(null);
+  },
   getMixRatioSheetData: function (glj) {
     let data = {
       id: glj.id,
@@ -647,6 +656,7 @@ let projectGljObject = {
     sel.colCount = 1;
     me.showMixRatioData();
     me.showRelatedRationDatas();
+    me.autoShowInfoPriceData();
   },
   rightClickCallback: function (row) {
     let me = projectGljObject;
@@ -1642,16 +1652,17 @@ let projectGljObject = {
       }
       console.log(bottomRow);
       me.infoPriceLastLoadingRow = me.infoPriceData.length;
-      me.searchInfoPrice(me.infoPriceData[me.infoPriceData.length - 1]._id)
+      //只有在空的搜索条件下才执行分页查询,其它情况无法分页
+      if ($('#info_search_name').val() == "") me.searchInfoPrice(me.infoPriceData[me.infoPriceData.length - 1]._id)
     }
-
-
   },
   searchInfoPrice: async function (objectID) {
     let year = $('#info_year').val();
     let month = $('#info_month').val();
     let areaID = $('#info_area').val();
     let keyWord = $('#info_search_name').val();
+    let name =  $('#info_glj_name').val();
+    let code =  $('#info_glj_code').val();
     let me = projectGljObject;
     try {
       if (year != "" && month != "" && areaID != "") {
@@ -1663,7 +1674,9 @@ let projectGljObject = {
           condition: condition
         };
         if (keyWord != "") data.keyWord = keyWord;
+        if (name !="") data.keyWord = name;
         if (objectID) data.lastID = objectID;
+        if (code !="" ) data.code = code;
         let result = await ajaxPost("/infoPrice/getDataByCondition", data);
         if (objectID) { //分页查询
           sheetCommonObj.appendData(me.infoPriceSheet, me.infoPriceData.length, 0, me.infoPriceSetting, result.items);
@@ -1672,6 +1685,11 @@ let projectGljObject = {
           me.infoPriceTotalSize = result.totalSize;
           me.infoPriceLastLoadingRow = 0;
           me.showInforPriceData(result.items);
+          if (result.totalSize == 0) {
+            $("#info-warning").text("当前材料没有信息价! ");
+          } else { 
+            $("#info-warning").text("");
+          }
         }
       } else { //当有任意一个为空时,都清空表格
         me.infoPriceTotalSize = 0;
@@ -2111,8 +2129,7 @@ $(function () {
   $("#info-nav").on('shown.bs.tab', function () {
     $('#info_price_sheet').height($("#mix_ratio_sheet").height() - $("#infoToolDiv").height());
     projectGljObject.initInfoPriceSpread();
-    /*  
-     projectGljObject.showRelatedRationDatas(); */
+    projectGljObject.autoShowInfoPriceData(); 
   });
   $('#info_year').change(function () {
     let periodMap = projectGljObject.infoPriceOptions.periodMap;
@@ -2135,12 +2152,17 @@ $(function () {
     projectGljObject.searchInfoPrice();
   });
   $('#info_search_name').on('keypress', function (e) {
+    $("#info-warning").text("");
     if (e.keyCode === 13) {
+      $('#info_glj_name').val("");
+      $('#info_glj_code').val("");
       projectGljObject.searchInfoPrice();
     }
   });
 
   $('#info_search_btn').on('click', function (e) {
+    $('#info_glj_name').val("");
+    $('#info_glj_code').val("");
     projectGljObject.searchInfoPrice();
   });