123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date 2018/4/24
- * @version
- */
- const excel = require('node-xlsx');
- // 参数可选代号
- const paramCodeArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'aa', 'ab', 'ac', 'ad', 'ae', 'af',
- 'ag', 'ah', 'ai', 'aj', 'ak', 'al', 'am', 'an', 'ao', 'ap', 'aq', 'ar', 'as', 'at', 'au',
- 'av', 'aw', 'ax', 'ay', 'az'];
- // 参数绑定类别
- const matchType = {
- fixed_id: 1,
- properties: 2,
- node_default: 11,
- parent_default: 12,
- child_gather: 13,
- code: 21,
- non_match: -1,
- }
- const matchTypeStr = [];
- matchTypeStr[matchType.fixed_id] = '全局匹配参数';
- matchTypeStr[matchType.properties] = '属性匹配参数';
- matchTypeStr[matchType.node_default] = '节点默认参数';
- matchTypeStr[matchType.parent_default] = '父项默认参数';
- matchTypeStr[matchType.child_gather] = '子项合计参数';
- matchTypeStr[matchType.code] = '编号匹配参数';
- matchTypeStr[matchType.non_match] = '非匹配参数';
- const validMatchType = [matchType.properties, matchType.code, matchType.non_match];
- const validProperties = {
- loadLength: 'loadLength',
- loadWidth: 'loadWidth'
- };
- // 参数取值
- const matchNum = {
- total_price: 1,
- dgn_quantity1: 2,
- dgn_quantity2: 3,
- quantity: 4,
- };
- const matchNumStr = [];
- matchNumStr[matchNum.total_price] = '合价';
- matchNumStr[matchNum.dgn_quantity1] = '设计数量1';
- matchNumStr[matchNum.dgn_quantity2] = '设计数量2';
- matchNumStr[matchNum.quantity] = '清单数量';
- const globalParamNodeId = 0;
- const defaultGlobalParamsFile = 'app/const/global_params.xls';
- // 默认全局参数
- const loadingGlobalParams = function () {
- const params = [];
- const sheets = excel.parse(defaultGlobalParamsFile);
- if (sheets && sheets.length > 0 && sheets[0] !== undefined && sheets[0].data !== undefined) {
- for (const row of sheets[0].data) {
- if (!row[0] || row[0] === '') { continue; }
- const param = {
- template_id: 1,
- node_id: globalParamNodeId,
- param_id: params.length + 1,
- name: row[0],
- };
- param.code = 'g_' + paramCodeArr[param.param_id - 1];
- if (row[1] && row[1] === 'fixed') {
- param.match_type = matchType.fixed_id;
- } else if (row[2] && row[2] !== '') {
- param.match_type = matchType.code;
- } else {
- param.match_type = matchType.non_match;
- }
- param.match_key = row[2];
- if (row[3] && row[3] === '合价') {
- param.match_num = matchNum.total_price;
- } else if (row[3] === '数量1') {
- param.match_num = matchNum.dgn_quantity1;
- } else if (row[3] === '数量2') {
- param.match_num = matchNum.dgn_quantity2;
- } else if (row[3] === '数量') {
- param.match_num = matchNum.quantity;
- }
- params.push(param);
- }
- }
- return params;
- };
- const defaultGlobalParams = loadingGlobalParams();
- // 默认节点参数
- const defaultNodeParams = [
- {
- template_id: 1,
- param_id: 1,
- code: 'a',
- name: '本项合价',
- match_type: matchType.node_default,
- match_num: matchNum.total_price,
- }, {
- template_id: 1,
- param_id: 2,
- code: 'b',
- name: '本项数量1',
- match_type: matchType.node_default,
- match_num: matchNum.dgn_quantity1,
- }, {
- template_id: 1,
- param_id: 3,
- code: 'c',
- name: '本项数量2',
- match_type: matchType.node_default,
- match_num: matchNum.dgn_quantity2,
- }, {
- template_id: 1,
- param_id: 4,
- code: 'd',
- name: '本项清单数量',
- match_type: matchType.node_default,
- match_num: matchNum.quantity,
- }, {
- template_id: 1,
- param_id: 1,
- code: 'e',
- name: '父项合价',
- match_type: matchType.parent_default,
- match_num: matchNum.total_price,
- }, {
- template_id: 1,
- param_id: 2,
- code: 'f',
- name: '父项数量1',
- match_type: matchType.parent_default,
- match_num: matchNum.dgn_quantity1,
- }, {
- template_id: 1,
- param_id: 3,
- code: 'g',
- name: '父项数量2',
- match_type: matchType.parent_default,
- match_num: matchNum.dgn_quantity2,
- }, {
- template_id: 1,
- param_id: 2,
- code: 'b',
- name: '子项数量1合计',
- match_type: matchType.child_gather,
- match_num: matchNum.dgn_quantity1,
- }, {
- template_id: 1,
- param_id: 3,
- code: 'c',
- name: '子项数量2合计',
- match_type: matchType.child_gather,
- match_num: matchNum.dgn_quantity2,
- },
- ];
- module.exports = {
- paramCodeArr,
- matchType,
- matchTypeStr,
- validMatchType,
- validProperties,
- matchNum,
- matchNumStr,
- globalParamNodeId,
- defaultGlobalParams,
- defaultNodeParams,
- };
|