Przeglądaj źródła

Merge branch 'master' of http://192.168.1.12:3000/caiaolin/Calculation

laiguoran 6 lat temu
rodzic
commit
ce2f19249a

+ 20 - 0
app.js

@@ -17,6 +17,7 @@ const BaseService = require('./app/base/base_service');
 const BaseController = require('./app/base/base_controller');
 
 const menu = require('./config/menu');
+const JsFiles = require('./config/web');
 
 module.exports = app => {
     app.uuid = uuid;
@@ -62,6 +63,25 @@ module.exports = app => {
     });
 
     //压缩前端js
+    app.jsFiles = { common: JsFiles.commonFiles };
+    for (const c in JsFiles.controller) {
+        const controller = JsFiles.controller[c];
+        app.jsFiles[c] = {};
+        for (const a in controller) {
+            const action = controller[a];
+            if (app.config.min) {
+                const minFileName = JsFiles.webPath + action.mergeFile + '.' + app.config.version + '.min.js';
+                let code = '';
+                for (const f of action.mergeFiles) {
+                    code = code + fs.readFileSync(app.baseDir + '/app' + f, 'utf8');
+                }
+                fs.writeFileSync(app.baseDir + '/app' + minFileName, Uglyfy.minify(code, {mangle: true}).code);
+                app.jsFiles[c][a] = action.files.concat([minFileName]);
+            } else {
+                app.jsFiles[c][a] = action.files.concat(action.mergeFiles);
+            }
+        }
+    }
     if (app.config.min) {
         app.minify = (file) => {
             const files = file instanceof Array ? file : [file];

+ 3 - 2
app/base/base_controller.js

@@ -57,17 +57,18 @@ class BaseController extends Controller {
         this.ctx.session.message = null;
 
         try {
-            data.min = this.app.config.min ? '.min' : '';
+            data.min = this.app.config.min;
             const viewString = await this.ctx.renderView(view, data);
             const modalString = modal === '' ? '' : await this.ctx.renderView(modal, data);
             const renderData = {
-                min: this.app.config.min ? '.min' : '',
+                min: this.app.config.min,
                 content: viewString,
                 message: JSON.stringify(message),
                 modal: modalString,
                 dropDownMenu: data.dropDownMenu === undefined ? [] : data.dropDownMenu,
                 breadCrumb: data.breadCrumb === undefined ? '' : data.breadCrumb,
                 tenderList: data.tenderList === undefined ? [] : data.tenderList,
+                jsFiles: data.jsFiles ? data.jsFiles : this.app.jsFiles.common,
             };
             await this.ctx.render('layout/layout.ejs', renderData);
         } catch(err) {

+ 1 - 0
app/controller/ledger_audit_controller.js

@@ -96,6 +96,7 @@ module.exports = app => {
                 renderData.ledgerSpreadSetting = JSON.stringify(ledgerSpread);
                 renderData.posSpreadSetting = JSON.stringify(posSpread);
                 renderData.readOnly = true;
+                renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.ledger.audit),
                 await this.layout('ledger/audit.ejs', renderData, 'ledger/audit_modal.ejs');
             } catch (err) {
                 console.log(err);

+ 20 - 0
app/controller/ledger_controller.js

@@ -58,8 +58,26 @@ module.exports = app => {
                     return cols.indexOf(c.field) > -1;
                 });
             }
+            function setColFormat(cols, field, formatter) {
+                const col = _.find(cols, function (c) {
+                    return c.field === field;
+                });
+                col.formatter = formatter;
+            }
+            const qtyFormatter = this.ctx.helper.getNumberFormatter(this.ctx.tender.info.decimal.qty);
+            const tpFormatter = this.ctx.helper.getNumberFormatter(this.ctx.tender.info.decimal.tp);
+            const upFormatter = this.ctx.helper.getNumberFormatter(2);
             const ledger = JSON.parse(JSON.stringify(spreadConst.ledgerSpread));
+            setColFormat(ledger.cols, 'quantity', qtyFormatter);
+            setColFormat(ledger.cols, 'dgn_qty1', qtyFormatter);
+            setColFormat(ledger.cols, 'dgn_qty2', qtyFormatter);
+            setColFormat(ledger.cols, 'deal_qty', qtyFormatter);
+            setColFormat(ledger.cols, 'unit_price', upFormatter);
+            setColFormat(ledger.cols, 'total_price', tpFormatter);
+            setColFormat(ledger.cols, 'deal_tp', tpFormatter);
             const pos = JSON.parse(JSON.stringify(spreadConst.ledgerPosSpread));
+            setColFormat(pos.cols, 'quantity', qtyFormatter);
+
             const tender = this.ctx.tender;
             if (this._ledgerReadOnly(tender.data)) {
                 ledger.readOnly = true;
@@ -114,7 +132,9 @@ module.exports = app => {
                     tenderMenu,
                     preUrl: '/tender/' + tender.id,
                     measureType,
+                    jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.ledger.explode),
                 };
+
                 await this.layout('ledger/explode.ejs', renderData, 'ledger/explode_modal.ejs');
             } catch (err) {
                 this.log(err);

+ 19 - 0
app/controller/stage_controller.js

@@ -62,8 +62,26 @@ module.exports = app => {
                     return cols.indexOf(c.field) > -1;
                 });
             }
+            function setColFormat(cols, field, formatter) {
+                const filterCols = cols.filter(function (c) {
+                    return c.field.search(field) !== -1;
+                });
+                for (const col of filterCols) {
+                    col.formatter = formatter;
+                }
+            }
+            const qtyFormatter = this.ctx.helper.getNumberFormatter(this.ctx.tender.info.decimal.qty);
+            const tpFormatter = this.ctx.helper.getNumberFormatter(this.ctx.tender.info.decimal.tp);
+            const upFormatter = this.ctx.helper.getNumberFormatter(2);
             const ledger = JSON.parse(JSON.stringify(spreadConst.stage.ledger));
+            setColFormat(ledger.cols, 'quantity', qtyFormatter);
+            setColFormat(ledger.cols, 'qty', qtyFormatter);
+            setColFormat(ledger.cols, 'unit_price', upFormatter);
+            setColFormat(ledger.cols, 'total_price', tpFormatter);
+            setColFormat(ledger.cols, 'tp', tpFormatter);
             const pos = JSON.parse(JSON.stringify(spreadConst.stage.pos));
+            setColFormat(pos.cols, 'quantity', qtyFormatter);
+            setColFormat(pos.cols, 'qty', qtyFormatter);
             const tender = this.ctx.tender, stage = this.ctx.stage;
             if (this._stageReadOnly(stage)) {
                 ledger.readOnly = true;
@@ -105,6 +123,7 @@ module.exports = app => {
                 [renderData.ledgerSpread, renderData.posSpread] = this._getSpreadSetting();
                 renderData.ledgerData = await ctx.service.ledger.getDataByTenderId(ctx.tender.id, -1);
                 renderData.curStageData = await ctx.service.stageBills.getAuditorStageData(ctx.tender.id, ctx.stage.id, ctx.stage.times, 0);
+                renderData.jsFiles = this.app.jsFiles.common.concat(this.app.jsFiles.stage.index);
                 // 查询截止上期数据
                 //if (ctx.stage.order > 0) {
                     //renderData.preStageData

+ 1 - 0
app/controller/tender_controller.js

@@ -41,6 +41,7 @@ module.exports = app => {
                     categoryData,
                     tableColSetting: setting,
                     measureType: tenderConst.measureType,
+                    jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.tender.list),
                 };
                 await this.layout(view, renderData, modal);
             } catch (err) {

+ 11 - 0
app/extend/helper.js

@@ -358,4 +358,15 @@ module.exports = {
         const reg2 = /([a-z0-9]+$)/i;
         return reg1.test(code) && reg2.test(code);
     },
+
+    getNumberFormatter(decimal) {
+        if (decimal <= 0) {
+            return "0";
+        }
+        let pre = "0.";
+        for (let i = 0; i < decimal; i++) {
+            pre += "#"
+        }
+        return pre;
+    }
 };

+ 49 - 9
app/lib/analysis_excel.js

@@ -172,6 +172,39 @@ class ImportBaseTree {
             return pos;
         }
     }
+
+    /**
+     * 第一部分的子节点,顺序重排
+     */
+    resortFirstPartChildren () {
+        const splitChar = this.splitChar;
+        const firstPart = this.roots[0];
+        firstPart.children.sort(function (a, b) {
+            if (a.code === '') {
+                return 1;
+            } else if (b.code === '') {
+                return -1;
+            }
+            const codeA = a.code.split(splitChar);
+            const numA = _.toNumber(codeA[codeA.length -1]);
+            const codeB = b.code.split(splitChar);
+            const numB = _.toNumber(codeB[codeB.length -1]);
+            return numA - numB;
+        });
+    }
+
+    calculateLeafWithPos () {
+        for (const node of this.items) {
+            if (node.children && node.children.length > 0) { continue; }
+            if (!node.pos || node.pos.length === 0) { continue; }
+            node.quantity = _.round(_.sum(_.map(node.pos, 'quantity')), 6);
+            if (node.quantity && node.unit_price) {
+                node.total_price = _.round(node.quantity * node.unit_price, 6);
+            } else {
+                node.total_price = null;
+            }
+        }
+    }
 }
 
 class AnalysisExcelTree {
@@ -195,6 +228,11 @@ class AnalysisExcelTree {
         };
     }
 
+    toNumber (value) {
+        let num = _.toNumber(value);
+        return _.isNaN(num) ? null : num;
+    }
+
     /**
      * 读取项目节节点
      * @param {Array} row - excel行数据
@@ -206,14 +244,14 @@ class AnalysisExcelTree {
         node.code = row[this.colsDef.code];
         node.name = row[this.colsDef.name];
         node.unit = row[this.colsDef.unit];
-        node.quantity = row[this.colsDef.quantity];
-        node.dgn_qty1 = row[this.colsDef.dgn_qty1];
-        node.dgn_qty2 = row[this.colsDef.dgn_qty2];
-        node.unit_price = row[this.colsDef.unit_price];
+        node.quantity = this.toNumber(row[this.colsDef.quantity]);
+        node.dgn_qty1 = this.toNumber(row[this.colsDef.dgn_qty1]);
+        node.dgn_qty2 = this.toNumber(row[this.colsDef.dgn_qty2]);
+        node.unit_price = this.toNumber(row[this.colsDef.unit_price]);
         node.drawing_code = row[this.colsDef.drawing_code];
         node.memo = row[this.colsDef.memo];
         if (node.quantity && node.unit_price) {
-            node.total_price = node.quantity * node.unit_price;
+            node.total_price = _.round(node.quantity * node.unit_price, 6);
         } else {
             node.total_price = null;
         }
@@ -230,12 +268,12 @@ class AnalysisExcelTree {
         node.b_code = row[this.colsDef.b_code];
         node.name = row[this.colsDef.name];
         node.unit = row[this.colsDef.unit];
-        node.quantity = row[this.colsDef.quantity];
-        node.unit_price = row[this.colsDef.unit_price];
+        node.quantity = this.toNumber(row[this.colsDef.quantity]);
+        node.unit_price = this.toNumber(row[this.colsDef.unit_price]);
         node.drawing_code = row[this.colsDef.drawing_code];
         node.memo = row[this.colsDef.memo];
         if (node.quantity && node.unit_price) {
-            node.total_price = node.quantity * node.unit_price;
+            node.total_price = _.round(node.quantity * node.unit_price, 6);
         } else {
             node.total_price = null;
         }
@@ -250,7 +288,7 @@ class AnalysisExcelTree {
     _loadPos(row) {
         const pos = {};
         pos.name = row[this.colsDef.name];
-        pos.quantity = row[this.colsDef.quantity];
+        pos.quantity = this.toNumber(row[this.colsDef.quantity]);
         pos.drawing_code = row[this.colsDef.drawing_code];
         return this.cacheTree.addPos(pos);
     }
@@ -324,6 +362,8 @@ class AnalysisExcelTree {
                 this.checkColHeader(row);
             }
         }
+        this.cacheTree.resortFirstPartChildren();
+        this.cacheTree.calculateLeafWithPos();
         return this.cacheTree;
     }
 }

BIN
app/public/files/template/ledger/渭武12标.xls


+ 1 - 1
app/public/js/global.js

@@ -159,7 +159,7 @@ const postDataCompress = function (url, data, successCallback, errorCallBack) {
         data: {'data': LZString.compressToUTF16(JSON.stringify(data))},
         dataType: 'json',
         cache: false,
-        timeout: 5000,
+        timeout: 60000, // 导入清单Excel(10w行)预计需要时间
         beforeSend: function(xhr) {
             let csrfToken = Cookies.get('csrfToken');
             xhr.setRequestHeader('x-csrf-token', csrfToken);

+ 5 - 2
app/public/js/ledger.js

@@ -34,7 +34,7 @@ $(document).ready(function() {
     }
     treeSetting.calcFun = function (node) {
         if (checkZero(node.dgn_qty1)) {
-            node.dgn_price = _.round(node.total_price/node.dgn_qty1, 2);
+            node.dgn_price = _.round(node.total_price/node.dgn_qty1, 6);
         } else {
             node.dgn_price = null;
         }
@@ -1242,7 +1242,6 @@ $(document).ready(function() {
         }$('#upload-ledger-sheets').hide();
         try {
             xlsxUtils.import(this.files[0], (excelData) => {
-                console.log(excelData);
                 if (excelData.SheetNames.length > 0) {
                     const html = [];
                     html.push('<label for="exampleFormControlFile1">勾选要导入的工作簿</label>');
@@ -1284,5 +1283,9 @@ $(document).ready(function() {
             });
         }
     });
+    $('#upload-ledger').bind('hidden.bs.modal', function () {
+        $('#upload-ledger-file').val('');
+        $('#upload-ledger-sheets').html('');
+    });
 });
 

+ 1 - 1
app/public/js/path_tree.js

@@ -880,7 +880,7 @@ const treeCalc = {
                 const result = {};
                 const fieldCalc = function (field) {
                     if (rst[field]) {
-                        result[field] = x[field] ? rst[field] + x[field] : rst[field];
+                        result[field] = x[field] ? _.round(rst[field] + x[field], 6) : rst[field];
                     } else {
                         result[field] = x[field] ? x[field] : undefined;
                     }

+ 0 - 21
app/public/js/spreadjs_rela/import_excel.js

@@ -1,21 +0,0 @@
-/**
- * 导入Excel相关js
- *
- * @author Mai
- * @date 2019/01/04
- * @version
- */
-'use strict';
-
-class ImportExcel {
-    constructor (setting) {
-        this.setting = setting;
-    }
-
-    analysisExcel(file) {
-        const excelIo = new GC.Spread.Excel.IO();
-        excelIo.open(file, function () {
-
-        });
-    }
-}

+ 2 - 2
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -225,7 +225,7 @@ const SpreadJsObj = {
             });
             // 设置列单元格格式
             sheet.zh_setting.cols.forEach(function (col, j) {
-                if (!col.cellType) { return; }
+                //if (!col.cellType) { return; }
 
                 if (col.cellType === 'tree') {
                     if (!sheet.extendCellType.tree) {
@@ -239,7 +239,7 @@ const SpreadJsObj = {
                     sheet.getRange(-1, j, -1, 1).cellType(sheet.extendCellType.tip);
                 }
                 if (col.formatter) {
-                    sheet.getRange(-1, j, -1, 1).format(col.formatter);
+                    sheet.getRange(-1, j, -1, 1).formatter(col.formatter);
                 }
             });
             this.endMassOperation(sheet);

+ 5 - 3
app/public/js/tender_list.js

@@ -154,9 +154,10 @@ function getCategoryHtml() {
         html.push('<div class="form-group" cate-id="' + cate.id + '">');
         html.push('<lable>', cate.name, '</lable>');
         html.push('<div>');
-        for (const v of cate.value) {
+        for (const iV in cate.value) {
+            const v = cate.value[iV];
             html.push('<div class="form-check-inline">');
-            html.push('<input class="form-check-input" type="radio"', 'value="' , v.id,  '">');
+            html.push('<input class="form-check-input" type="radio"', 'name="' + cate.name + '" ', 'value="' , v.id, (iV == 0 ? '" checked="' : ''),  '">');
             html.push('<label class="form-check-label">', v.value, '</label>');
             html.push('</div>');
         }
@@ -303,7 +304,6 @@ $(document).ready(() => {
     $('.modal-body', '#add-bd').append(getCategoryHtml());
     // 初始化标段树结构
     initTenderTree();
-    console.log(tenderTree);
     $('.c-body').html(getTenderTreeHtml());
     bindTenderUrl();
     // 分类
@@ -358,6 +358,8 @@ $(document).ready(() => {
             initTenderTree();
             $('.c-body').html(getTenderTreeHtml());
             bindTenderUrl();
+            $('#add-bd').modal('hide');
+            $('[name=name]', '#add-bd').val('');
         });
     });
 });

+ 3 - 13
app/view/layout/layout.ejs

@@ -15,19 +15,9 @@
     <link rel="stylesheet" href="/public/css/ztree/zTreeStyle.css" type="text/css">
     <link rel="stylesheet" href="/public/css/datepicker/datepicker.min.css" rel="stylesheet" type="text/css">
     <!-- JS. -->
-    <script src="/public/js/jquery/jquery-3.2.1.min.js"></script>
-    <script src="/public/js/jquery/jquery.validate.js"></script>
-    <script src="/public/js/messages_zh.js"></script>
-    <script src="/public/js/popper/popper.min.js"></script>
-    <script src="/public/js/bootstrap/bootstrap.min.js"></script>
-    <script src="/public/js/global.js"></script>
-    <script src="/public/js/vue/vue.js"></script>
-    <script src="/public/js/component/input.js"></script>
-    <script src="/public/js/cookies.js"></script>
-    <script src="/public/js/jquery-contextmenu/jquery.ui.position.min.js"></script>
-    <script src="/public/js/jquery-contextmenu/jquery.contextMenu.min.js"></script>
-    <script src="/public/js/lodash.js"></script>
-    <script src="/public/js/lz-string/lz-string.js"></script>
+    <% for (const file of jsFiles) { %>
+    <script type="text/javascript" src="<%- file %>"></script>
+    <% } %>
 </head>
 
 <body>

+ 1 - 5
app/view/ledger/audit.ejs

@@ -73,10 +73,6 @@
     ledgerSpreadSetting = JSON.parse(ledgerSpreadSetting);
     let posSpreadSetting = JSON.parse('<%- posSpreadSetting %>');
 </script>
-<script src="/public/js/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js"></script>
 <script>
     GC.Spread.Sheets.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";
-</script>
-<script src="/public/js/spreadjs_rela/spreadjs_zh<%= min %>.js"></script>
-<script src="/public/js/path_tree<%= min %>.js"></script>
-<script src="/public/js/ledger_audit.js"></script>
+</script>

+ 1 - 8
app/view/ledger/explode.ejs

@@ -137,13 +137,6 @@
     ledgerSpreadSetting = JSON.parse(ledgerSpreadSetting);
     let posSpreadSetting = JSON.parse('<%- posSpreadSetting %>');
 </script>
-<script src="/public/js/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js"></script>
-<script src="/public/js/js-xlsx/xlsx.full.min.js"></script>
-<script src="/public/js/js-xlsx/xlsx.utils.js"></script>
 <script>
     GC.Spread.Sheets.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";
-</script>
-<script src="/public/js/spreadjs_rela/spreadjs_zh<%= min %>.js"></script>
-<script src="/public/js/spreadjs_rela/extend_celltype.js"></script>
-<script src="/public/js/path_tree<%= min %>.js"></script>
-<script src="/public/js/ledger.js"></script>
+</script>

+ 1 - 5
app/view/stage/index.ejs

@@ -273,12 +273,9 @@
         </div>
     </div>
 </div>
-<script src="/public/js/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js"></script>
 <script>
     GC.Spread.Sheets.LicenseKey = "559432293813965#A0y3iTOzEDOzkjMyMDN9UTNiojIklkI1pjIEJCLi4TPB9mM5AFNTd4cvZ7SaJUVy3CWKtWYXx4VVhjMpp7dYNGdx2ia9sEVlZGOTh7NRlTUwkWR9wEV4gmbjBDZ4ElR8N7cGdHVvEWVBtCOwIGW0ZmeYVWVr3mI0IyUiwCMzETN8kzNzYTM0IicfJye&Qf35VfiEzRwEkI0IyQiwiIwEjL6ByUKBCZhVmcwNlI0IiTis7W0ICZyBlIsIyNyMzM5ADI5ADNwcTMwIjI0ICdyNkIsIibj9SbvNmL4N7bjRnch56ciojIz5GRiwiI8+Y9sWY9QmZ0Jyp96uL9v6L0wap9biY9qiq95q197Wr9g+89iojIh94Wiqi";
 </script>
-<script src="/public/js/spreadjs_rela/spreadjs_zh<%= min %>.js"></script>
-<script src="/public/js/path_tree<%= min %>.js"></script>
 <script>
     const ledgerSpreadSetting = JSON.parse('<%- JSON.stringify(ledgerSpread) %>');
     const posSpreadSetting = JSON.parse('<%- JSON.stringify(posSpread) %>');
@@ -287,5 +284,4 @@
     const stage = JSON.parse('<%- JSON.stringify(ctx.stage) %>');
     const ledgerData = JSON.parse('<%- JSON.stringify(ledgerData) %>');
     const curStageData = JSON.parse('<%- JSON.stringify(curStageData) %>');
-</script>
-<script type="text/javascript" src="/public/js/stage.js"></script>
+</script>

+ 1 - 2
app/view/tender/index.ejs

@@ -10,5 +10,4 @@
     const categoryType = JSON.parse('<%- JSON.stringify(settingConst.cType) %>');
     const category = JSON.parse('<%- JSON.stringify(categoryData) %>');
     const TenderTableCol = JSON.parse('<%- JSON.stringify(tableColSetting) %>');
-</script>
-<script src="/public/js/tender_list.js"></script>
+</script>

+ 1 - 2
app/view/tender/manage.ejs

@@ -10,5 +10,4 @@
     const categoryType = JSON.parse('<%- JSON.stringify(settingConst.cType) %>');
     const category = JSON.parse('<%- JSON.stringify(categoryData) %>');
     const TenderTableCol = JSON.parse('<%- JSON.stringify(tableColSetting) %>');
-</script>
-<script src="/public/js/tender_list.js"></script>
+</script>

+ 2 - 1
app/view/tender/manage_modal.ejs

@@ -154,4 +154,5 @@
                 <button type="button" class="btn btn-primary">确定添加</button>
             </div>
         </div>
-    </div>
+    </div>
+</div>

+ 1 - 2
app/view/tender/progress.ejs

@@ -10,5 +10,4 @@
     const categoryType = JSON.parse('<%- JSON.stringify(settingConst.cType) %>');
     const category = JSON.parse('<%- JSON.stringify(categoryData) %>');
     const TenderTableCol = JSON.parse('<%- JSON.stringify(tableColSetting) %>');
-</script>
-<script src="/public/js/tender_list.js"></script>
+</script>

+ 7 - 0
config/config.default.js

@@ -108,6 +108,8 @@ module.exports = appInfo => {
     // 是否压缩替换前端js
     config.min = true;
 
+    config.version = '1.0.0';
+
     // 压缩设置
     config.gzip = {
         threshold: 1024,
@@ -130,5 +132,10 @@ module.exports = appInfo => {
         }
     };
 
+    config.bodyParser = {
+        jsonLimit: '10mb',
+        formLimit: '10mb',
+    };
+
     return config;
 };

+ 79 - 0
config/web.js

@@ -0,0 +1,79 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date 2019/1/10
+ * @version
+ */
+const JsFiles = {
+    webPath: "/public/js/web/",
+    commonFiles: [
+        "/public/js/jquery/jquery-3.2.1.min.js",
+        "/public/js/jquery/jquery.validate.js",
+        "/public/js/messages_zh.js",
+        "/public/js/popper/popper.min.js",
+        "/public/js/bootstrap/bootstrap.min.js",
+        "/public/js/global.js",
+        "/public/js/vue/vue.js",
+        "/public/js/component/input.js",
+        "/public/js/cookies.js",
+        "/public/js/jquery-contextmenu/jquery.ui.position.min.js",
+        "/public/js/jquery-contextmenu/jquery.contextMenu.min.js",
+        "/public/js/lodash.js",
+        "/public/js/lz-string/lz-string.js",
+    ],
+    controller: {
+        tender: {
+            list: {
+                files: [],
+                mergeFiles: ["/public/js/tender_list.js"],
+                mergeFile: 'tender_list',
+            }
+        },
+        ledger: {
+            explode: {
+                files: [
+                    "/public/js/js-xlsx/xlsx.full.min.js",
+                    "/public/js/js-xlsx/xlsx.utils.js",
+                    "/public/js/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js",
+                ],
+                mergeFiles: [
+                    "/public/js/spreadjs_rela/spreadjs_zh.js",
+                    "/public/js/path_tree.js",
+                    "/public/js/ledger.js",
+                ],
+                mergeFile: 'explode',
+            },
+            audit: {
+                files: [
+                    "/public/js/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js",
+                ],
+                mergeFiles: [
+                    "/public/js/spreadjs_rela/spreadjs_zh.js",
+                    "/public/js/path_tree.js",
+                    "/public/js/ledger_audit.js",
+                ],
+                mergeFile: 'ledger_audit',
+            }
+        },
+        stage: {
+            // 本期计量台账
+            index: {
+                files: [
+                    "/public/js/spreadjs/sheets/gc.spread.sheets.all.10.0.1.min.js",
+                ],
+                mergeFiles: [
+                    "/public/js/spreadjs_rela/spreadjs_zh.js",
+                    "/public/js/path_tree.js",
+                    "/public/js/stage.js",
+                ],
+                mergeFile: 'stage',
+            }
+        }
+    }
+
+};
+
+module.exports = JsFiles;

+ 2 - 0
package.json

@@ -14,6 +14,8 @@
     "egg-view": "^1.1.2",
     "egg-view-ejs": "^1.1.0",
     "gt3-sdk": "^2.0.0",
+    "gulp": "^4.0.0",
+    "js-xlsx": "^0.8.22",
     "koa-is-json": "^1.0.0",
     "lodash": "^4.17.11",
     "lz-string": "^1.4.4",

+ 60 - 3
test/app/lib/analysis_excel.test.js

@@ -10,6 +10,8 @@
 
 const { app, assert } = require('egg-mock/bootstrap');
 const AnalysisExcel = require('../../../app/lib/analysis_excel');
+const Xlsx = require('js-xlsx');
+const _ = require('lodash');
 
 describe('test/app/lib/analysis_excel.test.js', () => {
     it('analysis Test Data', function* () {
@@ -34,7 +36,7 @@ describe('test/app/lib/analysis_excel.test.js', () => {
                 [ '1-2-2', null, null, '挖方', 'm3' ],
                 [ '1-2-2-1', null, null, '挖土方', 'm3' ],
                 [ '1-2-2-1-1', null, null, '挖路基土方', 'm3' ],
-                [ null, '203-1-a', null, ' ', 'm3', 92954.75, null, null, 7.53 ],
+                [ null, '203-1-a', null, ' ', 'm3', null, null, null, 7.53 ],
                 [ null, null, 1, 'K0+000-K1+000', null, 11619.34375, null, null, null, null, '第二册S-2-1' ],
                 [ null, null, 2, 'K1+000-K1+800', null, 11619.34375, null, null, null, null, '第二册S-2-1' ],
                 [ null, null, 3, 'K2+800-K3+004', null, 11619.34375, null, null, null, null, '第二册S-2-1' ],
@@ -46,14 +48,69 @@ describe('test/app/lib/analysis_excel.test.js', () => {
                 [ '1-2-2-2', null, null, '挖石方', 'm3' ],
                 [ '1-2-2-2-1', null, null, '挖软石', 'm3' ],
                 [ null, '203-1-b', null, '挖石方', 'm3', 105.36, null, null, 16.11 ],
+                [ '1-3', null, null, '路面工程', 'km' ],
+                [ '1-4', null, null, '桥梁涵洞工程', 'km' ],
+                [ '1-6', null, null, '隧道工程', 'km' ],
             ],
             range: 'A1:L29',
         };
         const ctx = app.mockContext();
         const templateData = yield ctx.service.tenderNodeTemplate.getData(true);
         const result = analysisExcel.analysisData(testData, templateData);
-        assert(result.items.length === 21);
-        assert(result.roots.length === 1);
+        // 检查插入总量
+        assert(result.items.length === 72);
+        assert(result.roots.length === 6);
         assert(result.pos.length === 8);
+        // 检查第一部分子节点排序
+        const nodes = result.roots[0].children;
+        assert(nodes[nodes.length - 2].code === '1-6');
+        assert(nodes[nodes.length - 1].code === '1-10');
+        // 检查第203-1-a的数量
+        const xmj = result.codeNodes['1-2-2-1-1'];
+        const gcl = xmj.children[0];
+        assert(gcl.quantity === 92954.75);
+    });
+    it('Analysis Excel Test Data And Import', function* () {
+        const excelFile = app.baseDir  + '/app/public/files/template/ledger/导入分项清单Excel格式.xls';
+        const wb = Xlsx.readFile(excelFile);
+        const name = wb.SheetNames[0];
+        const sheetData = {
+            rows: Xlsx.utils.sheet_to_json(wb.Sheets[name], {header: 1}),
+            merge: wb.Sheets[name]["!merges"],
+        };
+        const ctx = app.mockContext();
+        const analysisExcel = new AnalysisExcel();
+        const templateData = yield ctx.service.tenderNodeTemplate.getData(true);
+        const result = analysisExcel.analysisData(sheetData, templateData);
+        assert(result.items.length === 216);
+        const xmj = result.codeNodes['1-2-3-1-2'];
+        const gcl = xmj.children[0];
+        assert(gcl.quantity === 0);
+        ctx.tender = { id: 2 };
+        // pos需要记录createUserId
+        ctx.session = {
+            sessionUser: {
+                accountId: 2,
+            },
+        };
+        yield ctx.service.ledger.importExcel(sheetData);
+    });
+    it('analysis 渭武12标 Excel', function* () {
+        const excelFile = app.baseDir  + '/app/public/files/template/ledger/渭武12标.xls';
+        const wb = Xlsx.readFile(excelFile);
+        const name = wb.SheetNames[0];
+        const sheetData = {
+            rows: Xlsx.utils.sheet_to_json(wb.Sheets[name], {header: 1}),
+            merge: wb.Sheets[name]["!merges"],
+        };
+        const ctx = app.mockContext();
+        ctx.tender = { id: 2 };
+        // pos需要记录createUserId
+        ctx.session = {
+            sessionUser: {
+                accountId: 2,
+            },
+        };
+        yield ctx.service.ledger.importExcel(sheetData);
     });
 });