server.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import express from 'express'
  2. const app = express();
  3. // 使用中间件解析JSON格式的请求体
  4. app.use(express.json());
  5. import Service from './Service.js';
  6. import {copy} from './utils.js';
  7. import {handleBeizhu} from './editor.js';
  8. app.post('/api/transform', (req, res) => {
  9. let data = copy(req.body);
  10. Service.setQufei([{ "children": [{"children":[{
  11. "key": "1",
  12. "利润(%)": "",
  13. "名称": "",
  14. "备注": "",
  15. "工程类型": "",
  16. "工程类别": "",
  17. "管理费(%)": ""
  18. }]}]}])
  19. Service.setQufeiEntry("1")
  20. Service.processQingdanmingxi([{
  21. "主材费": "",
  22. "人工费": "",
  23. "利润": "",
  24. "单位": data['dw'],
  25. "合价": "",
  26. "名称": data['mc'],
  27. "备注": "",
  28. "序号": "1",
  29. "数量": data['sl'],
  30. "暂估价": "",
  31. "机械费": "",
  32. "清单编码": data['bianma'],
  33. "管理费": "",
  34. "综合人工工日": "",
  35. "综合单价": "",
  36. "计算规则": "",
  37. "设备费": "",
  38. "辅材费": "",
  39. "项目特征": data['tz'],
  40. "操作": "",
  41. "材料费": ""
  42. }])
  43. let result = copy(data['result'])
  44. delete data.result
  45. if (data['bianma'].startsWith('031301017')){
  46. console.log('安装脚手架');
  47. let de04=result.filter(x=>x['清单编码'].startsWith('0304'));
  48. let json_ = "{\"reverse\": \"2076\", \"DEBH\": {\"111\": \"4-F1\"}, \"GCLMC\": {\"111\": \"第四册\"}, \"DW\": {\"111\": \"项\"}, \"rgde\": [], \"jxde\": [], \"clde\": [], \"actual_zhuanye\": 30, \"bz_selected\": {\"BZBH\": {}}, \"bz_selected2\": {\"BZBH\": {}}}"
  49. Service.azfy_mock("1", json_, de04)
  50. let de05=result.filter(x=>x['清单编码'].startsWith('0305'));
  51. json_ = "{\"reverse\": \"2076\", \"DEBH\": {\"111\": \"5-F1\"}, \"GCLMC\": {\"111\": \"第五册\"}, \"DW\": {\"111\": \"项\"}, \"rgde\": [], \"jxde\": [], \"clde\": [], \"actual_zhuanye\": 30, \"bz_selected\": {\"BZBH\": {}}, \"bz_selected2\": {\"BZBH\": {}}}"
  52. Service.azfy_mock("1", json_, de05)
  53. let de06=result.filter(x=>x['清单编码'].startsWith('0306'));
  54. json_ = "{\"reverse\": \"2076\", \"DEBH\": {\"111\": \"6-F1\"}, \"GCLMC\": {\"111\": \"第六册\"}, \"DW\": {\"111\": \"项\"}, \"rgde\": [], \"jxde\": [], \"clde\": [], \"actual_zhuanye\": 30, \"bz_selected\": {\"BZBH\": {}}, \"bz_selected2\": {\"BZBH\": {}}}"
  55. Service.azfy_mock("1", json_, de06)
  56. let de07=result.filter(x=>x['清单编码'].startsWith('0307'));
  57. json_ = "{\"reverse\": \"2076\", \"DEBH\": {\"111\": \"7-F1\"}, \"GCLMC\": {\"111\": \"第七册\"}, \"DW\": {\"111\": \"项\"}, \"rgde\": [], \"jxde\": [], \"clde\": [], \"actual_zhuanye\": 30, \"bz_selected\": {\"BZBH\": {}}, \"bz_selected2\": {\"BZBH\": {}}}"
  58. Service.azfy_mock("1", json_, de07)
  59. let de08=result.filter(x=>x['清单编码'].startsWith('0308'));
  60. json_ = "{\"reverse\": \"2076\", \"DEBH\": {\"111\": \"8-F1\"}, \"GCLMC\": {\"111\": \"第八册\"}, \"DW\": {\"111\": \"项\"}, \"rgde\": [], \"jxde\": [], \"clde\": [], \"actual_zhuanye\": 30, \"bz_selected\": {\"BZBH\": {}}, \"bz_selected2\": {\"BZBH\": {}}}"
  61. Service.azfy_mock("1", json_, de08)
  62. let de09=result.filter(x=>x['清单编码'].startsWith('0309'));
  63. json_ = "{\"reverse\": \"2076\", \"DEBH\": {\"111\": \"9-F1\"}, \"GCLMC\": {\"111\": \"第九册\"}, \"DW\": {\"111\": \"项\"}, \"rgde\": [], \"jxde\": [], \"clde\": [], \"actual_zhuanye\": 30, \"bz_selected\": {\"BZBH\": {}}, \"bz_selected2\": {\"BZBH\": {}}}"
  64. Service.azfy_mock("1", json_, de09)
  65. let de10=result.filter(x=>x['清单编码'].startsWith('0310'));
  66. json_ = "{\"reverse\": \"2076\", \"DEBH\": {\"111\": \"10-F1\"}, \"GCLMC\": {\"111\": \"第十册\"}, \"DW\": {\"111\": \"项\"}, \"rgde\": [], \"jxde\": [], \"clde\": [], \"actual_zhuanye\": 30, \"bz_selected\": {\"BZBH\": {}}, \"bz_selected2\": {\"BZBH\": {}}}"
  67. Service.azfy_mock("1", json_, de10)
  68. let de111=result.filter(x=>x['清单编码'].startsWith('031201'));
  69. json_ = "{\"reverse\": \"2076\", \"DEBH\": {\"111\": \"11-F1\"}, \"GCLMC\": {\"111\": \"第十一册刷油工程(定额11-51~11-329)\"}, \"DW\": {\"111\": \"项\"}, \"rgde\": [], \"jxde\": [], \"clde\": [], \"actual_zhuanye\": 30, \"bz_selected\": {\"BZBH\": {}}, \"bz_selected2\": {\"BZBH\": {}}}"
  70. Service.azfy_mock("1", json_, de111)
  71. let de112=result.filter(x=>x['清单编码'].startsWith('031202') || x['清单编码'].startsWith('031203') || x['清单编码'].startsWith('031204') || x['清单编码'].startsWith('031205') || x['清单编码'].startsWith('031206') || x['清单编码'].startsWith('031207'));
  72. json_ = "{\"reverse\": \"2076\", \"DEBH\": {\"111\": \"11-F1\"}, \"GCLMC\": {\"111\": \"第十一册防腐蚀工程(定额11-330~11-1689)\"}, \"DW\": {\"111\": \"项\"}, \"rgde\": [], \"jxde\": [], \"clde\": [], \"actual_zhuanye\": 30, \"bz_selected\": {\"BZBH\": {}}, \"bz_selected2\": {\"BZBH\": {}}}"
  73. Service.azfy_mock("1", json_, de112)
  74. let de113=result.filter(x=>x['清单编码'].startsWith('031208'));
  75. json_ = "{\"reverse\": \"2076\", \"DEBH\": {\"111\": \"11-F1\"}, \"GCLMC\": {\"111\": \"第十一册绝热工程(定额11-1690~11-2327)\"}, \"DW\": {\"111\": \"项\"}, \"rgde\": [], \"jxde\": [], \"clde\": [], \"actual_zhuanye\": 30, \"bz_selected\": {\"BZBH\": {}}, \"bz_selected2\": {\"BZBH\": {}}}"
  76. Service.azfy_mock("1", json_, de113)
  77. }
  78. else{
  79. for (let i = 0; i < result.length; i++) {
  80. console.log(result[i][0])
  81. console.log(result[i][1])
  82. console.log((result[i][2]))
  83. let selected = data['fuzhu'][i][0]
  84. let selected2=[]
  85. for(let j = 0; j < selected.length; j++){
  86. selected2.push(selected[j].charCodeAt(0) - 64)
  87. }
  88. let fk = data['fuzhu'][i][1]
  89. let zk = data['fuzhu'][i][2]
  90. let zk2 = []
  91. for(let j = 0;j<zk.length;j++){
  92. zk2.push({
  93. 'id': j+1,
  94. 'key': j+1,
  95. '序号':j+1,
  96. '数量':1,
  97. '编号':zk[j][1],
  98. '说明':zk[j][2]
  99. })
  100. }
  101. let r = Service.changguidinge(JSON.parse(result[i][2]), "1")
  102. if (selected2.length>0){
  103. let detail = handleBeizhu(fk,r[2],selected2,zk2)
  104. Service.updateBeizhu(r[2],detail,selected2.map(x=>x.toString().concat('*1')))
  105. }
  106. let current = Service.current()[0]
  107. current = current['_children'].filter(x=>x['key']==r[2])[0]
  108. current = current['dercj']
  109. let shajiang = false
  110. for(let j=1;j<current.length;j++){
  111. if(current[j][2].includes('灰浆搅拌机'))shajiang=true;
  112. }
  113. if (shajiang){
  114. Service.handleYuban(r[2], ['2']);
  115. }
  116. let r_ = Service.updateShuliang(result[i][1], r[2])
  117. let hit = r_[1][0]['_children'].filter(x=>x['key']==r[2])[0]
  118. let dercj = copy(hit['dercj'])
  119. for(let j = 1; j < dercj.length; j++){
  120. let bianma = dercj[j][1]
  121. if (data['replace'].hasOwnProperty(bianma)){
  122. dercj[j][2] = data['replace'][bianma]
  123. }
  124. for(let k = 0; k < result[i][3].length;k++){
  125. let old_bianma = result[i][3][k]['bianma']
  126. let new_bianma = result[i][3][k]['new_bianma']
  127. let new_mc = result[i][3][k]['mc']
  128. let new_jg = result[i][3][k]['jg']
  129. if (old_bianma == bianma){
  130. dercj[j][1] = new_bianma
  131. dercj[j][2] = new_mc
  132. dercj[j][5] = new_jg
  133. }
  134. }
  135. }
  136. Service.updateDercj(r[2], dercj)
  137. }
  138. console.log(data['extra']);
  139. if (data['extra'].length >= 4) {
  140. Service.danxiangdinge("1", data['n'], data['extra'])
  141. }
  142. if (data['fy']=='{}'){}
  143. else Service.changguidinge(JSON.parse(data['fy']), "1")
  144. }
  145. res.status(200).send(Service.cache);
  146. });
  147. app.listen(3000, () => {
  148. console.log('Server is running on port 3000');
  149. });