template_param.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/4/24
  7. * @version
  8. */
  9. const excel = require('node-xlsx');
  10. // 参数可选代号
  11. const paramCodeArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
  12. 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'aa', 'ab', 'ac', 'ad', 'ae', 'af',
  13. 'ag', 'ah', 'ai', 'aj', 'ak', 'al', 'am', 'an', 'ao', 'ap', 'aq', 'ar', 'as', 'at', 'au',
  14. 'av', 'aw', 'ax', 'ay', 'az'];
  15. // 参数绑定类别
  16. const matchType = {
  17. fixed_id: 1,
  18. properties: 2,
  19. node_default: 11,
  20. parent_default: 12,
  21. code: 21,
  22. non_match: -1,
  23. }
  24. const matchTypeStr = [];
  25. matchTypeStr[matchType.fixed_id] = '全局匹配参数';
  26. matchTypeStr[matchType.node_default] = '节点默认参数';
  27. matchTypeStr[matchType.properties] = '属性匹配参数';
  28. matchTypeStr[matchType.code] = '编号匹配参数';
  29. matchTypeStr[matchType.non_match] = '非匹配参数';
  30. const validMatchType = [matchType.properties, matchType.code, matchType.non_match];
  31. const validProperties = {
  32. loadLength: 'loadLength',
  33. loadWidth: 'loadWidth'
  34. }
  35. // 参数取值
  36. const matchNum = {
  37. total_price: 1,
  38. dgn_quantity1: 2,
  39. dgn_quantity2: 3,
  40. quantity: 4,
  41. };
  42. const matchNumStr = [];
  43. matchNumStr[matchNum.total_price] = '合价';
  44. matchNumStr[matchNum.dgn_quantity1] = '设计数量1';
  45. matchNumStr[matchNum.dgn_quantity2] = '设计数量2';
  46. matchNumStr[matchNum.quantity] = '清单数量';
  47. const globalParamNodeId = 0;
  48. const defaultGlobalParamsFile = 'app/const/global_params.xls';
  49. // 默认全局参数
  50. const loadingGlobalParams = function () {
  51. const params = [];
  52. const sheets = excel.parse(defaultGlobalParamsFile);
  53. if (sheets && sheets.length > 0 && sheets[0] !== undefined && sheets[0].data !== undefined) {
  54. for (const row of sheets[0].data) {
  55. if (!row[0] || row[0] === '') { continue; }
  56. const param = {
  57. template_id: 1,
  58. node_id: globalParamNodeId,
  59. param_id: params.length + 1,
  60. name: row[0],
  61. };
  62. param.code = 'g_' + paramCodeArr[param.param_id];
  63. if (row[1] && row[1] === 'fixed') {
  64. param.match_type = matchType.fixed_id;
  65. } else if (row[2] && row[2] !== '') {
  66. param.match_type = matchType.code;
  67. } else {
  68. param.match_type = matchType.non_match;
  69. }
  70. param.match_key = row[2];
  71. if (row[3] && row[3] === '合价') {
  72. param.match_num = matchNum.total_price;
  73. } else if (row[3] === '数量1') {
  74. param.match_num = matchNum.dgn_quantity1;
  75. } else if (row[3] === '数量2') {
  76. param.match_num = matchNum.dgn_quantity2;
  77. } else if (row[3] === '数量') {
  78. param.match_num = matchNum.quantity;
  79. }
  80. params.push(param);
  81. }
  82. }
  83. return params;
  84. };
  85. const defaultGlobalParams = loadingGlobalParams();
  86. // 默认节点参数
  87. const defaultNodeParams = [
  88. {
  89. template_id: 1,
  90. param_id: 1,
  91. code: 'a',
  92. name: '本项合价',
  93. match_type: matchType.node_default,
  94. match_num: matchNum.total_price,
  95. }, {
  96. template_id: 1,
  97. param_id: 2,
  98. code: 'b',
  99. name: '本项数量1',
  100. match_type: matchType.node_default,
  101. match_num: matchNum.dgn_quantity1,
  102. }, {
  103. template_id: 1,
  104. param_id: 3,
  105. code: 'c',
  106. name: '本项数量2',
  107. match_type: matchType.node_default,
  108. match_num: matchNum.dgn_quantity2,
  109. }, {
  110. template_id: 1,
  111. param_id: 4,
  112. code: 'd',
  113. name: '本项清单数量',
  114. match_type: matchType.node_default,
  115. match_num: matchNum.quantity,
  116. }, {
  117. template_id: 1,
  118. param_id: 1,
  119. code: 'e',
  120. name: '父项合价',
  121. match_type: matchType.parent_default,
  122. match_num: matchNum.total_price,
  123. }, {
  124. template_id: 1,
  125. param_id: 2,
  126. code: 'f',
  127. name: '父项数量1',
  128. match_type: matchType.parent_default,
  129. match_num: matchNum.dgn_quantity1,
  130. }, {
  131. template_id: 1,
  132. param_id: 3,
  133. code: 'g',
  134. name: '父项数量2',
  135. match_type: matchType.parent_default,
  136. match_num: matchNum.dgn_quantity2,
  137. },
  138. ];
  139. module.exports = {
  140. paramCodeArr,
  141. matchType,
  142. matchTypeStr,
  143. validMatchType,
  144. validProperties,
  145. matchNum,
  146. matchNumStr,
  147. globalParamNodeId,
  148. defaultGlobalParams,
  149. defaultNodeParams
  150. }