exportRationCoe.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /**
  2. * Created by Tony on 2021/10/8.
  3. */
  4. let fs = require('fs');
  5. let data1 = fs.readFileSync('D:/GitHome/ConstructionOperation/tmp/testRationData_1633514079281.js');
  6. let data2 = fs.readFileSync('D:/GitHome/ConstructionOperation/tmp/testRationCoeData.js');
  7. let data3 = fs.readFileSync('D:/GitHome/ConstructionOperation/tmp/testGLJData.js');
  8. //----------------------------------------
  9. let rationItemArr = JSON.parse(data1);
  10. let coeItemArr = JSON.parse(data2);
  11. let gljItemArr = JSON.parse(data3);
  12. let gljCache = {};
  13. let coeCache = {};
  14. const prefix = '_'
  15. for (let gljItem of gljItemArr) {
  16. gljCache[prefix + gljItem.code] = gljItem;
  17. }
  18. for (let gljItem of coeItemArr) {
  19. coeCache[prefix + gljItem.ID] = gljItem;
  20. }
  21. let newData = [];
  22. // 先测量最多有多少coes
  23. let maxCoes = 0;
  24. let fixedCoes = [];
  25. for (let idx = 0; idx < coeItemArr.length; idx++) {
  26. let item = coeItemArr[idx];
  27. let dtlMax = 0;
  28. let dtlFixedCoes = [];
  29. for (let coe of item.coes) {
  30. if (coe.coeType !== '人工' && coe.coeType !== '机械' && coe.coeType !== '材料' && coe.coeType !== '定额') {
  31. dtlMax++;
  32. } else {
  33. dtlFixedCoes.push(coe);
  34. }
  35. }
  36. fixedCoes.push(dtlFixedCoes);
  37. maxCoes = Math.max(dtlMax, maxCoes);
  38. }
  39. let firstStr = 'ID|Name|Type|Content|G|L|J';
  40. //for (let idx = 0; idx < maxCoes - 1; idx++) {
  41. for (let idx = 1; idx <= 10; idx++) {
  42. let str = '';
  43. str = `|GLJ${idx}|Count${idx}|Type${idx}`;
  44. firstStr += str;
  45. };
  46. newData.push(firstStr);
  47. function _getAmountByCoeType(coeObjs, coeItem) {
  48. let rst = [];
  49. let coeG = 0, coeL = 0, coeJ = 0;
  50. for (let coeObj of coeObjs) {
  51. switch (coeObj.coeType) {
  52. case '定额':
  53. coeG = coeObj.amount;
  54. coeL = coeObj.amount;
  55. coeJ = coeObj.amount;
  56. break;
  57. case '人工' :
  58. coeG = coeObj.amount;
  59. break;
  60. case '单个工料机' :
  61. let gcKey = prefix + coeObj.gljCode;
  62. if (!gljCache.hasOwnProperty(gcKey)) {
  63. console.log('code1: ' + ' - ' + coeItem.ID + ' - ' + coeObj.coeType);
  64. } else {
  65. if (gljCache[gcKey].gljType > 200 && gljCache[gcKey].gljType < 300) {
  66. coeL = coeObj.amount;
  67. } else if (gljCache[gcKey].gljType > 300 && gljCache[gcKey].gljType < 400) {
  68. coeJ = coeObj.amount;
  69. } else if (gljCache[gcKey].gljType <= 2) {
  70. coeG = coeObj.amount;
  71. } else {
  72. console.log('不明材料1: ' + ' - ' + gcKey + ' - ' + gljCache[gcKey].gljType);
  73. }
  74. }
  75. break;
  76. case '机械' :
  77. coeJ = coeObj.amount;
  78. break;
  79. case '材料' :
  80. coeL = coeObj.amount;
  81. break;
  82. default :
  83. console.log('不明coeType1: ' + ' - ' + coeObj.coeType);
  84. break;
  85. }
  86. }
  87. rst.push(coeG);
  88. rst.push(coeL);
  89. rst.push(coeJ);
  90. return rst;
  91. }
  92. // 先输出coe list
  93. for (let idx = 0; idx < coeItemArr.length; idx++) {
  94. let coeItem = coeItemArr[idx];
  95. // coeCache[prefix + gljItem.ID] = gljItem;
  96. let firstCoe = coeItem.coes[0];
  97. let firstCoeType = firstCoe.operator;
  98. let cRst =_getAmountByCoeType(fixedCoes[idx], coeItem);
  99. let firstCoeG = cRst[0];
  100. let firstCoeL = cRst[1];
  101. let firstCoeJ = cRst[2];
  102. let str = `${coeItem.ID}|${coeItem.name}|${firstCoeType}|${coeItem.content}|${firstCoeG}|${firstCoeL}|${firstCoeJ}`;
  103. /*
  104. for (let idx = 0; idx < maxCoes - 1; idx++) {
  105. if (idx < coeItem.coes.length - 1) {
  106. // 判断coeItem.coes[idx+1].gljCode,有一下几种情况:udefined, 空串, 其他正常值
  107. let dtlRst =_getAmountByCoeType(coeItem.coes[idx+1], coeItem);
  108. if (coeItem.coes[idx+1].gljCode === undefined || coeItem.coes[idx+1].gljCode === '') {
  109. // str += `,${gljCache[gcKey].ID},${coeItem.coes[idx+1].amount},${coeItem.coes[idx+1].operator}`;
  110. console.log('不明额外coeType2: ' + ' - ' + coeItem.ID + coeItem.coes[idx+1].coeType);
  111. str += `,-1,${coeItem.coes[idx+1].amount},${coeItem.coes[idx+1].operator}`;
  112. } else {
  113. //正常值
  114. let gcKey = prefix + coeItem.coes[idx+1].gljCode;
  115. if (!gljCache.hasOwnProperty(gcKey)) {
  116. console.log('code2: ' + coeItem.ID + ' - ' + gcKey);
  117. }
  118. str += `,${gljCache[gcKey].ID},${coeItem.coes[idx+1].amount},${coeItem.coes[idx+1].operator}`;
  119. }
  120. } else {
  121. str += ',,,';
  122. }
  123. }
  124. */
  125. for (let idx = 1; idx <= 10; idx++) {
  126. str += '|||';
  127. }
  128. newData.push(str);
  129. }
  130. let ttlStr = newData.join('\n');
  131. let regExp = new RegExp('"', "gm");
  132. ttlStr = ttlStr.replace(regExp, '');
  133. // fs.writeFile(`D:/GitHome/ConstructionOperation/tmp/子目换算List文件_${(new Date()).getTime()}.txt`, ttlStr, { 'flag': 'a', 'encoding': 'utf-8' }, function(err){
  134. // if(err) throw err;
  135. // });
  136. // 再输出ration - coe
  137. firstStr = 'SectionID|RationID|CoeID|Order|GroupIdx|Param';
  138. newData = [];
  139. newData.push(firstStr);
  140. for (let item of rationItemArr) {
  141. for (let coeItem of item.rationCoeList) {
  142. let str = `${item.sectionId}|${item.ID}|${coeItem.ID}|${coeItem.no}||`;
  143. newData.push(str);
  144. }
  145. }
  146. ttlStr = newData.join('\n');
  147. ttlStr = ttlStr.replace(regExp, '');
  148. fs.writeFile(`D:/GitHome/ConstructionOperation/tmp/定额_子目换算Data文件_${(new Date()).getTime()}.txt`, ttlStr, { 'flag': 'a', 'encoding': 'utf-8' }, function(err){
  149. if(err) throw err;
  150. });