template_param.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. child_gather: 13,
  22. code: 21,
  23. non_match: -1,
  24. }
  25. const matchTypeStr = [];
  26. matchTypeStr[matchType.fixed_id] = '全局匹配参数';
  27. matchTypeStr[matchType.properties] = '属性匹配参数';
  28. matchTypeStr[matchType.node_default] = '节点默认参数';
  29. matchTypeStr[matchType.parent_default] = '父项默认参数';
  30. matchTypeStr[matchType.child_gather] = '子项合计参数';
  31. matchTypeStr[matchType.code] = '编号匹配参数';
  32. matchTypeStr[matchType.non_match] = '非匹配参数';
  33. const validMatchType = [matchType.properties, matchType.code, matchType.non_match];
  34. const validProperties = {
  35. loadLength: 'loadLength',
  36. loadWidth: 'loadWidth'
  37. };
  38. // 参数取值
  39. const matchNum = {
  40. total_price: 1,
  41. dgn_quantity1: 2,
  42. dgn_quantity2: 3,
  43. quantity: 4,
  44. };
  45. const matchNumStr = [];
  46. matchNumStr[matchNum.total_price] = '合价';
  47. matchNumStr[matchNum.dgn_quantity1] = '设计数量1';
  48. matchNumStr[matchNum.dgn_quantity2] = '设计数量2';
  49. matchNumStr[matchNum.quantity] = '清单数量';
  50. const globalParamNodeId = 0;
  51. const defaultGlobalParamsFile = 'app/const/global_params.xls';
  52. // 默认全局参数
  53. const loadingGlobalParams = function () {
  54. const params = [];
  55. const sheets = excel.parse(defaultGlobalParamsFile);
  56. if (sheets && sheets.length > 0 && sheets[0] !== undefined && sheets[0].data !== undefined) {
  57. for (const row of sheets[0].data) {
  58. if (!row[0] || row[0] === '') { continue; }
  59. const param = {
  60. template_id: 1,
  61. node_id: globalParamNodeId,
  62. param_id: params.length + 1,
  63. name: row[0],
  64. };
  65. param.code = 'g_' + paramCodeArr[param.param_id - 1];
  66. if (row[1] && row[1] === 'fixed') {
  67. param.match_type = matchType.fixed_id;
  68. } else if (row[2] && row[2] !== '') {
  69. param.match_type = matchType.code;
  70. } else {
  71. param.match_type = matchType.non_match;
  72. }
  73. param.match_key = row[2];
  74. if (row[3] && row[3] === '合价') {
  75. param.match_num = matchNum.total_price;
  76. } else if (row[3] === '数量1') {
  77. param.match_num = matchNum.dgn_quantity1;
  78. } else if (row[3] === '数量2') {
  79. param.match_num = matchNum.dgn_quantity2;
  80. } else if (row[3] === '数量') {
  81. param.match_num = matchNum.quantity;
  82. }
  83. params.push(param);
  84. }
  85. }
  86. return params;
  87. };
  88. const defaultGlobalParams = loadingGlobalParams();
  89. // 默认节点参数
  90. const defaultNodeParams = [
  91. {
  92. template_id: 1,
  93. param_id: 1,
  94. code: 'a',
  95. name: '本项合价',
  96. match_type: matchType.node_default,
  97. match_num: matchNum.total_price,
  98. }, {
  99. template_id: 1,
  100. param_id: 2,
  101. code: 'b',
  102. name: '本项数量1',
  103. match_type: matchType.node_default,
  104. match_num: matchNum.dgn_quantity1,
  105. }, {
  106. template_id: 1,
  107. param_id: 3,
  108. code: 'c',
  109. name: '本项数量2',
  110. match_type: matchType.node_default,
  111. match_num: matchNum.dgn_quantity2,
  112. }, {
  113. template_id: 1,
  114. param_id: 4,
  115. code: 'd',
  116. name: '本项清单数量',
  117. match_type: matchType.node_default,
  118. match_num: matchNum.quantity,
  119. }, {
  120. template_id: 1,
  121. param_id: 1,
  122. code: 'e',
  123. name: '父项合价',
  124. match_type: matchType.parent_default,
  125. match_num: matchNum.total_price,
  126. }, {
  127. template_id: 1,
  128. param_id: 2,
  129. code: 'f',
  130. name: '父项数量1',
  131. match_type: matchType.parent_default,
  132. match_num: matchNum.dgn_quantity1,
  133. }, {
  134. template_id: 1,
  135. param_id: 3,
  136. code: 'g',
  137. name: '父项数量2',
  138. match_type: matchType.parent_default,
  139. match_num: matchNum.dgn_quantity2,
  140. }, {
  141. template_id: 1,
  142. param_id: 2,
  143. code: 'b',
  144. name: '子项数量1合计',
  145. match_type: matchType.child_gather,
  146. match_num: matchNum.dgn_quantity1,
  147. }, {
  148. template_id: 1,
  149. param_id: 3,
  150. code: 'c',
  151. name: '子项数量2合计',
  152. match_type: matchType.child_gather,
  153. match_num: matchNum.dgn_quantity2,
  154. },
  155. ];
  156. module.exports = {
  157. paramCodeArr,
  158. matchType,
  159. matchTypeStr,
  160. validMatchType,
  161. validProperties,
  162. matchNum,
  163. matchNumStr,
  164. globalParamNodeId,
  165. defaultGlobalParams,
  166. defaultNodeParams,
  167. };