anhui_chizhou.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * @Descripttion: 安徽池州导入接口
  3. * @Author: vian
  4. * @Date: 2020-09-21 17:40:45
  5. */
  6. // INTERFACE_EXPORT =,必须这么写,这样才能在导入时动态加载脚本后,覆盖前端代码
  7. INTERFACE_IMPORT = (() => {
  8. 'use strict';
  9. /**
  10. *
  11. * @param {String} areaKey - 地区标识,如:'安徽@马鞍山',有些地区的接口只是取值上有不同,共有一个接口脚本, 需要通过地区标识确定一些特殊处理
  12. * @param {Object} xmlObj - xml经过x2js转换后的xml对象
  13. * @return {Object} - 返回的格式需要统一,具体参考函数内返回的内容。返回的内容会经过一系列的统一处理形成可入库的数据。
  14. */
  15. async function entry(areaKey, xmlObj) {
  16. const {
  17. UTIL: {
  18. getValue,
  19. arrayValue,
  20. extractItemsRecur,
  21. }
  22. } = INTERFACE_EXPORT_BASE;
  23. const subArea = areaKey.split('@')[1];
  24. const natureConstructionMap = {
  25. '1': '新建',
  26. '2': '改扩建',
  27. };
  28. const roadGradeMap = {
  29. '1': '高速公路',
  30. '2': '一级公路',
  31. '3': '二级公路',
  32. '4': '三级公路',
  33. '5': '四级公路',
  34. '6': '独立桥梁',
  35. '7': '独立隧道',
  36. };
  37. const taxModeMap = {
  38. '1': '一般计税',
  39. '2': '简易计税',
  40. };
  41. // 提取基本信息,xml中提取出来的基本信息,最终会与模板基本信息进行合并处理。(接口内不需要处理合并)
  42. function setupInformation(projectSrc) {
  43. const gcxx = getValue(projectSrc, ['工程信息']);
  44. const zbxx = getValue(projectSrc, ['招投标信息', '招标信息']);
  45. // key:基本信息模板中的key,作为合并时的匹配字段
  46. const info = [
  47. { key: 'projNum', value: getValue(gcxx, ['_项目编号']) },
  48. { key: 'constructingUnits', value: getValue(gcxx, ['_建设单位']) },
  49. { key: 'startChainages', value: getValue(gcxx, ['_起始桩号']) },
  50. { key: 'endChainages', value: getValue(gcxx, ['_终点桩号']) },
  51. { key: 'constructionAddress', value: getValue(gcxx, ['_建设地址']) },
  52. { key: 'projOverview', value: getValue(gcxx, ['_项目概况']) },
  53. { key: 'natureConstruction', value: natureConstructionMap[getValue(gcxx, ['_建设性质'])] || '' },
  54. { key: 'roadGrade', value: roadGradeMap[getValue(gcxx, ['_专业划分'])] || '' },
  55. { key: 'roadDistance', value: getValue(gcxx, ['_道路里程']) },
  56. { key: 'designUnit', value: getValue(gcxx, ['_设计单位']) },
  57. { key: 'taxMode', value: taxModeMap[getValue(gcxx, ['_计税方式'])] },
  58. { key: 'projType', value: getValue(gcxx, ['_文件类型']) },
  59. { key: 'tendereeName', value: getValue(zbxx, ['_招标人']) },
  60. { key: 'tendereeTaxpayerIdentificationNo', value: getValue(zbxx, ['_招标人纳税识别号']) },
  61. { key: 'tenderAuthorizer', value: getValue(zbxx, ['_招标法定代表人或其授权人']) },
  62. { key: 'tenderAuthorizerIDNo', value: getValue(zbxx, ['_招标法人或其授权人身份证号']) },
  63. { key: 'costConsultant', value: getValue(zbxx, ['_造价咨询人']) },
  64. { key: 'costConsultantTaxpayerIdentificationNo', value: getValue(zbxx, ['_造价咨询人纳税识别号']) },
  65. { key: 'consultantAuthorizer', value: getValue(zbxx, ['_造价咨询人法定代表人或其授权人']) },
  66. { key: 'consultantAuthorizerTaxpayerIdentificationNo', value: getValue(zbxx, ['_造价咨询法人或其授权人身份证号']) },
  67. { key: 'compileApprover', value: getValue(zbxx, ['_编制人']) },
  68. { key: 'compileCertNo', value: getValue(zbxx, ['_编制人资格证号']) },
  69. { key: 'compileDate', value: getValue(zbxx, ['_编制日期']) },
  70. { key: 'reviewApprover', value: getValue(zbxx, ['_复核人']) },
  71. { key: 'reviewCertNo', value: getValue(zbxx, ['_复核人资格证号']) },
  72. { key: 'reviewDate', value: getValue(zbxx, ['_复核日期']) },
  73. ];
  74. return info;
  75. }
  76. // 提取清单数据
  77. function setupBills(rootSrc, oneSevenSrc, dayWorkSrc) {
  78. // 章次为空的造价汇总表数据,为大项费用数据
  79. const roots = arrayValue(rootSrc, ['造价汇总明细'])
  80. .filter(item => !getValue(item, ['_章次']))
  81. .map(item => ({
  82. name: getValue(item, ['_名称']),
  83. remark: getValue(item, ['_备注'])
  84. }));
  85. let oneSevenBills;
  86. let dayWorkBills;
  87. roots.forEach(item => {
  88. const simpleName = item.name ? item.name.replace(/\s/g, '') : '';
  89. if (/100章至第700章|100章至700章/.test(simpleName)) {
  90. oneSevenBills = item;
  91. } else if (/计日工合计/.test(simpleName)) {
  92. dayWorkBills = item;
  93. }
  94. });
  95. // 第100-700章的数据
  96. if (oneSevenBills) {
  97. oneSevenBills.children = extractItemsRecur(oneSevenSrc, [['工程量清单明细']], (src) => ({
  98. code: getValue(src, ['_子目号']),
  99. name: getValue(src, ['_子目名称']),
  100. unit: getValue(src, ['_单位']),
  101. quantity: getValue(src, ['_数量']),
  102. remark: getValue(src, ['_备注']),
  103. }));
  104. }
  105. // 计日工数据
  106. if (dayWorkBills) {
  107. const title = '计日工信息标题';
  108. const detail = '计日工信息明细';
  109. dayWorkBills.children = extractItemsRecur(dayWorkSrc, [[title], [detail]], (src, curField) => {
  110. const name = getValue(src, ['_名称']);
  111. const simpleName = name ? name.replace(/\s/g, '') : ''
  112. if (curField === title && /计日工合计/.test(simpleName)) { // 计日工标题在根节点中已经提取了,不重复提取
  113. return null;
  114. }
  115. const item = { name };
  116. if (curField === detail) {
  117. item.code = getValue(src, ['_编号']);
  118. item.unit = getValue(src, ['_单位']);
  119. item.quantity = getValue(src, ['_暂定数量']);
  120. }
  121. return item;
  122. });
  123. }
  124. return roots;
  125. }
  126. // 提取单位工程数据
  127. function setupTender(tenderSrc) {
  128. const oneSevenSrc = getValue(tenderSrc, ['工程量清单表']);
  129. const dayWorkSrc = getValue(tenderSrc, ['计日工信息表']);
  130. const rootSrc = getValue(tenderSrc, ['造价汇总表']);
  131. return {
  132. name: getValue(tenderSrc, ['_标段名称']),
  133. bills: setupBills(rootSrc, oneSevenSrc, dayWorkSrc)
  134. };
  135. }
  136. // 从xml对象提取需要的数据
  137. function setupProject(projectSrc) {
  138. const tenders = arrayValue(projectSrc, ['公路工程数据', '公路标段工程'])
  139. .map(tenderSrc => setupTender(tenderSrc));
  140. return {
  141. name: getValue(projectSrc, ['工程信息', '_项目名称']),
  142. info: setupInformation(projectSrc),
  143. tenders,
  144. };
  145. }
  146. return setupProject(getValue(xmlObj, ['池州公路工程']));
  147. }
  148. return {
  149. entry
  150. };
  151. })();