소스 검색

1. 导入指标模板,识别指标分类
2. 指标对比,可根据指标分类查询

MaiXinRong 6 년 전
부모
커밋
145d3ecb4e
8개의 변경된 파일143개의 추가작업 그리고 12개의 파일을 삭제
  1. 14 2
      app/const/template_node.js
  2. 42 5
      app/controller/compare_controller.js
  3. 32 4
      app/public/js/compare.js
  4. 1 0
      app/router.js
  5. 3 1
      app/service/match.js
  6. 19 0
      app/service/template_node.js
  7. 16 0
      app/service/tender_node.js
  8. 16 0
      app/view/compare/index.ejs

+ 14 - 2
app/const/template_node.js

@@ -12,12 +12,24 @@
 const matchType = {
     code: 1,
     name: 2,
-}
+};
 const matchTypeStr = [];
 matchTypeStr[matchType.code] = '匹配分项编号';
 matchTypeStr[matchType.name] = '匹配分项名称';
 
+const indexClass = {
+    zh: 1,
+    fx: 2,
+    dy: 3,
+};
+const indexClassStr = [];
+indexClassStr[indexClass.zh] = '综合指标';
+indexClassStr[indexClass.fx] = '分项指标';
+indexClassStr[indexClass.dy] = '单元指标';
+
 module.exports = {
     matchType,
-    matchTypeStr
+    matchTypeStr,
+    indexClass,
+    indexClassStr,
 };

+ 42 - 5
app/controller/compare_controller.js

@@ -19,13 +19,15 @@ module.exports = app => {
          */
         async index (ctx) {
             const libList = await ctx.service.quotaLib.getList(libConst.status.enter);
+            const dyNames = await ctx.service.templateNode.getDanYuanNames();
             const renderData = {
-                libList
+                libList,
+                nodeConst: this.app.nodeConst,
+                dyNames,
             };
             await this.layout('compare/index.ejs', renderData, 'compare/modal.ejs');
         }
         async search (ctx) {
-            //console.log('start' + new Date());
             const responseData = {
                 err: 0,
                 msg: '',
@@ -46,7 +48,7 @@ module.exports = app => {
                         const condition = {
                             lib_id: tender.lib_id,
                             node_id: n.node_id,
-                        }
+                        };
                         n.children = await ctx.service.tenderIndex.getAllDataByCondition({where: condition});
                     }
                 }
@@ -56,10 +58,45 @@ module.exports = app => {
                 responseData.msg = err.toString();
                 console.log(err);
             }
-
-            //console.log('end' + new Date());
             ctx.body = responseData;
         }
+
+        async searchClass(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                const tenders = data.tenders;
+                const indexClass = this.app.nodeConst.indexClass;
+                if (!data.indexClass) {
+                    throw '查询的指标分类不存在';
+                } else {
+                    if (data.indexClass === indexClass.dy) {
+                        if (!data.className) {
+                            throw '查询的单元指标分类不存在';
+                        }
+                    } else if (data.indexClass !== indexClass.zh && data.indexClass !== indexClass.fx) {
+                        throw '查询的指标分类不存在';
+                    }
+                }
+                for (const tender of tenders) {
+                    if (!tender.lib_id) {
+                        throw '查询的标段有误或不存在';
+                    }
+                    tender.data = await ctx.service.tenderNode.searchClass(tender.lib_id, data.indexClass, data.className);
+                    for (const n of tender.data) {
+                        const condition = {
+                            lib_id: tender.lib_id,
+                            node_id: n.node_id,
+                        };
+                        n.children = await ctx.service.tenderIndex.getAllDataByCondition({where: condition});
+                    }
+                }
+                console.log(tenders);
+                ctx.body = {err: 0, msg: '', data: tenders};
+            } catch (err) {
+                ctx.body = {err: 1, msg: err.toString(), data: []};
+                console.log(err);
+            }
+        }
     }
 
     return CompareController;

+ 32 - 4
app/public/js/compare.js

@@ -193,11 +193,11 @@ $(document).ready(function () {
             let iRow = 2;
             SpreadJsObj.massOperationSheet(this.sheet, function () {
                 self.sheet.setRowCount(2);
-                for (const node of self.showData) {
+                for (const sd of self.showData) {
                     self.sheet.addRows(iRow, 1);
-                    loadNode(node, iRow);
+                    loadNode(sd, iRow);
                     iRow += 1;
-                    for (const index of node.indexes) {
+                    for (const index of sd.indexes) {
                         self.sheet.addRows(iRow, 1);
                         loadIndex(index, iRow);
                         iRow += 1;
@@ -216,6 +216,13 @@ $(document).ready(function () {
                 self.loadData(datas);
             });
         }
+        searchClass (data) {
+            const self = this;
+            data.tenders = this.tenders;
+            postData('/compare/searchClass', data, function (datas) {
+                self.loadData(datas);
+            })
+        }
     }
     const compareObj = new CompareObj($('#compare-spread')[0]);
 
@@ -235,6 +242,27 @@ $(document).ready(function () {
 
     $('#search').click(function () {
         compareObj.searchIndex($('#keyword').val());
+        $('.btn-secondary').removeClass('btn-secondary').addClass('btn-primary');
+    });
+
+    $('#index-zh').click(function () {
+        $('.btn-secondary').removeClass('btn-secondary').addClass('btn-primary');
+        $(this).removeClass('btn-primary').addClass('btn-secondary');
+        $('#index-dy').text('单元指标');
+        compareObj.searchClass(JSON.parse($(this).attr('data')));
+    });
+
+    $('#index-fx').click(function () {
+        $('.btn-secondary').removeClass('btn-secondary').addClass('btn-primary');
+        $(this).removeClass('btn-primary').addClass('btn-secondary');
+        $('#index-dy').text('单元指标');
+        compareObj.searchClass(JSON.parse($(this).attr('data')));
+    });
+
+    $('a[data]').click(function () {
+        $('.btn-secondary').removeClass('btn-secondary').addClass('btn-primary');
+        $('#index-dy').removeClass('btn-primary').addClass('btn-secondary').text($(this).text());
+        compareObj.searchClass(JSON.parse($(this).attr('data')));
     });
 
     $('#export-excel').click(function () {
@@ -245,7 +273,7 @@ $(document).ready(function () {
         excelIo.save(sJson, function(blob) {
             saveAs(blob, fileName);
         });
-    })
+    });
 
     // $.contextMenu({
     //     selector: '#compare-spread',

+ 1 - 0
app/router.js

@@ -35,4 +35,5 @@ module.exports = app => {
     // 指标对比
     app.get('/compare', sessionAuth, 'compareController.index');
     app.post('/compare/search', sessionAuth, 'compareController.search');
+    app.post('/compare/searchClass', sessionAuth, 'compareController.searchClass');
 };

+ 3 - 1
app/service/match.js

@@ -247,7 +247,9 @@ module.exports = app => {
                     match_type: node.match_type,
                     match_key: node.match_key,
                     bills_id: mb.n_id,
-                }
+                    index_class: node.index_class,
+                    class_name: node.class_name,
+                };
                 this.nodes.push(newNode);
                 this._syncNodeParam(newNode.source_id, newNode.node_id, mb);
                 this._syncNodeIndex(newNode);

+ 19 - 0
app/service/template_node.js

@@ -7,6 +7,8 @@
  * @date 2018/4/19
  * @version
  */
+const _ = require('lodash');
+
 module.exports = app => {
 
     const paramConst = app.paramConst;
@@ -151,6 +153,12 @@ module.exports = app => {
          * @private
          */
         _parseSheetData(excelSheet, nodes, indexes, params, templateId = 1) {
+            let indexClass = nodeConst.indexClass.dy;
+            if (excelSheet.name.indexOf(nodeConst.indexClassStr[nodeConst.indexClass.zh]) > -1) {
+                indexClass = nodeConst.indexClass.zh;
+            } else if (excelSheet.name.indexOf(nodeConst.indexClassStr[nodeConst.indexClass.fx]) > -1) {
+                indexClass = nodeConst.indexClass.fx;
+            }
             for (const row of excelSheet.data) {
                 if (!row[0]) { continue; }
                 if (this.ctx.helper.ValidTemplateNodeCode(row[0])) {
@@ -164,6 +172,8 @@ module.exports = app => {
                             name: row[1],
                             match_type: isMatchCode ? nodeConst.matchType.code : nodeConst.matchType.name,
                             match_key: isMatchCode ? row[11] : row[1],
+                            index_class: indexClass,
+                            class_name: excelSheet.name,
                         };
                         nodes.push(node);
                     }
@@ -256,6 +266,15 @@ module.exports = app => {
             return await this.getDataByCondition(condition);
         }
 
+        async getDanYuanNames() {
+            const sql = 'SELECT `class_name` As name FROM ' + this.tableName +
+                '  WHERE index_class = ?' +
+                '  GROUP By `class_name`';
+            const sqlParam = [nodeConst.indexClass.dy];
+            const names = await this.db.query(sql, sqlParam);
+            return names;
+        }
+
     }
 
     return TemplateNode;

+ 16 - 0
app/service/tender_node.js

@@ -28,6 +28,22 @@ module.exports = app => {
             const sqlParam = [this.tableName, searchKey, searchKey];
             return await this.db.query(sql, sqlParam);
         }
+
+        async searchClass (tenderId, indexClass, className) {
+            if (indexClass === this.app.nodeConst.indexClass.dy) {
+                const sql = 'Select * From ' + this.tableName +
+                    '  Where `lib_id` = ? and `index_class` = ? and `class_name` = ?';
+                const sqlParam = [tenderId, indexClass, className];
+                console.log(this.db.format(sql, sqlParam));
+                return await this.db.query(sql, sqlParam);
+            } else {
+                const sql = 'Select * From ' + this.tableName +
+                    '  Where `lib_id` = ? and `index_class` = ?';
+                const sqlParam = [tenderId, indexClass];
+                console.log(this.db.format(sql, sqlParam));
+                return await this.db.query(sql, sqlParam);
+            }
+        }
     };
 
     return TenderNode;

+ 16 - 0
app/view/compare/index.ejs

@@ -11,6 +11,22 @@
                 <div class="d-inline-flex">
                     <button class="btn btn-sm btn-primary " type="button" id="search">搜索</button>
                 </div>
+                <div class="d-inline-flex">
+                    <div class="btn-group btn-group-sm" role="group" aria-label="Basic example">
+                        <button id="index-zh" type="button" class="btn btn-primary" data='<%- JSON.stringify({indexClass: nodeConst.indexClass.zh}) %>'>综合指标</button>
+                        <button id="index-fx" type="button" class="btn btn-primary" data='<%- JSON.stringify({indexClass: nodeConst.indexClass.fx}) %>'>分项指标</button><!--选中状态 btn-secondary-->
+                        <div class="btn-group btn-group-sm" role="group">
+                            <button id="index-dy" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+                                单元指标
+                            </button>
+                            <div class="dropdown-menu" aria-labelledby="index-dy">
+                                <% for (const dy of dyNames) { %>
+                                <a class="dropdown-item" data='<%- JSON.stringify({indexClass: nodeConst.indexClass.dy, className: dy.name }) %>'><%- dy.name %></a>
+                                <% } %>
+                            </div>
+                        </div>
+                    </div>
+                </div>
             </div>
             <div>
                 <a href="javascript: void(0)" class="btn btn-primary btn-sm pull-right" target="_blank" id="export-excel"><i class="fa fa-file-excel-o"></i> 导出Excel</a>