guangdong_2018_import.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. 'use strict';
  2. const importXML = (() => {
  3. // 通用设置和工具
  4. const config = importXMLBase.CONFIG;
  5. const util = importXMLBase.UTIL;
  6. const {
  7. fixedFlag,
  8. billType,
  9. rationType,
  10. projectType
  11. } = commonConstants;
  12. const { AdjustType } = config;
  13. const {
  14. getValue,
  15. arrayValue,
  16. getFee,
  17. getFlag,
  18. getItemsRecur,
  19. } = util;
  20. //导入的文件类型,界面选的文件类型是生成项目的文件类型,这里的文件类型指的是,要导入文件的类型,
  21. //导入文件类型不同,导入数据不同
  22. let importFileKind = '';
  23. //文件类型
  24. const FileKind = {
  25. '6': 1, // 投标
  26. 'tender': 1,
  27. '4': 2, // 招标
  28. 'bid': 2,
  29. '5': 3, // 控制价
  30. 'control': 3,
  31. };
  32. const countData = {
  33. projectCount: 0, //项目数量
  34. projectGLJCount: 0, //项目人材机数量
  35. ratioCount: 0, //组成物数量
  36. unitPriceCount: 0, //单价数量
  37. unitPriceFileCount: 0, //单价文件数量
  38. };
  39. // 建设项目
  40. function extractProject(xmlObjMap) {
  41. Object.keys(countData).forEach(key => countData[key] = 0); // 清缓存
  42. countData.projectCount++;
  43. const projectXMLObj = xmlObjMap['Project.xml'];
  44. const projectSrc = getValue(projectXMLObj, ['ConstructionProject']);
  45. importFileKind = FileKind[getValue(source, ['_FileKind'])]; // 标记当前导入的文件类型
  46. const rst = {
  47. projectType: projectType.Project,
  48. name: getValue(projectSrc, ['_Name']),
  49. engs: extractEngs(projectSrc),
  50. property: {
  51. compilationIllustrationProject: getValue(projectSrc, ['_Explains'])
  52. },
  53. basicInformation: extractBasicInfo(projectSrc)
  54. }
  55. }
  56. // 从xml对象中提取基本信息相关
  57. function extractBasicInfo(projectSrc) {
  58. const projectInfo = getValue(projectSrc, ['ProjectInfo']); // 估概预算信息
  59. const tendereeInfo = getValue(projectSrc, ['TendereeInfo']); // 招标信息
  60. const bidderInfo = getValue(projectSrc, ['BidderInfo']); // 投标信息
  61. return [
  62. { key: 'projNum', value: getValue(projectSrc, ['_Number']) }, // 编码
  63. { key: 'projectCategory', value: getValue(projectSrc, ['_ProjectCategory']) }, // 工程类别
  64. { key: 'constructionType', value: getValue(projectSrc, ['_ConstructionType']) }, // 建设性质
  65. { key: 'regionalCategories', value: getValue(projectSrc, ['_AreaKind']) }, // 地区类被
  66. { key: 'projLocation', value: getValue(projectSrc, ['_ProjectSite']) }, // 工程地点
  67. { key: 'constructingUnits', value: getValue(projectSrc, ['_BulidUnit']) }, // 建设单位
  68. { key: 'constructingUnitsPerson', value: getValue(projectSrc, ['_BulidAuthorizer']) }, // 建设单位法定代表人或其授权人
  69. { key: 'rangeOfCompilation', value: getValue(projectSrc, ['_RangeOfCompilation']) }, // 建设(编制)范围
  70. { key: 'scale', value: getValue(projectSrc, ['_Scale']) }, // 建设规模
  71. { key: 'unit', value: getValue(projectSrc, ['_Unit']) }, // 建设规模单位
  72. { key: 'designUnits', value: getValue(projectInfo, ['_Designer']) }, // 设计单位
  73. { key: 'constructionUnits', value: getValue(projectInfo, ['_Contractor']) }, // 承包单位
  74. { key: 'establishUnit', value: getValue(projectInfo, ['_CompileCompany']) }, // 编制单位
  75. { key: importFileKind === FileKind.tender ? 'bidCompileDate' : 'tenderCompileDate', value: getValue(projectInfo, ['_CompileDate']) }, // 编制时间
  76. { key: 'authorizer', value: getValue(projectInfo, ['_Authorizer']) }, // 编制单位法定代表人或其授权人
  77. { key: 'tendereeName', value: getValue(tendereeInfo, ['_TendereeName']) }, // 招标人
  78. { key: 'tenderAuthorizer', value: getValue(tendereeInfo, ['_TenderAuthorizer']) }, // 招标单位法定代表人或其授权人
  79. { key: 'tenderCompiler', value: getValue(tendereeInfo, ['_TenderCompiler']) }, // 招标单位编制人
  80. { key: 'tenderCompilerCertNo', value: getValue(tendereeInfo, ['_TenderCompilerCertNo']) }, // 招标单位编制人资格证书编号
  81. { key: 'tenderCompileDate', value: getValue(tendereeInfo, ['_TenderCompileDate']) }, // 招标单位编制时间
  82. { key: 'tenderExaminer', value: getValue(tendereeInfo, ['_TenderExaminer']) }, // 招标单位审核人
  83. { key: 'tenderExaminerCertNo', value: getValue(tendereeInfo, ['_TenderExaminerCertNo']) }, // 招标单位审核人资格证书编号
  84. { key: 'tenderExamineDate', value: getValue(tendereeInfo, ['_TenderExamineDate']) }, // 招标单位审核时间
  85. { key: 'tenderApprover', value: getValue(tendereeInfo, ['_TenderApprover']) }, // 招标单位审定人
  86. { key: 'tenderApproverCertNo', value: getValue(tendereeInfo, ['_TenderApproverCertNo']) }, // 招标单位审定人资格证书编号
  87. { key: 'proxy', value: getValue(tendereeInfo, ['_Proxy']) }, // 招标代理
  88. { key: 'proxyCertNo', value: getValue(tendereeInfo, ['_ProxyCertNo']) }, // 招标代理资质证书编号
  89. { key: 'proxyAuthorizer', value: getValue(tendereeInfo, ['_ProxyAuthorizer']) }, // 招标代理法定代表人或其授权人
  90. { key: 'proxyCompiler', value: getValue(tendereeInfo, ['_ProxyCompiler']) }, // 招标代理编制人员
  91. { key: 'proxyCompilerCertNo', value: getValue(tendereeInfo, ['_ProxyCompilerCertNo']) }, // 招标代理编制人员资格证书编号
  92. { key: 'proxyCompileDate', value: getValue(tendereeInfo, ['_ProxyCompileDate']) }, // 招标代理编制时间
  93. { key: 'proxyExaminer', value: getValue(tendereeInfo, ['_ProxyExaminer']) }, // 招标代理审核人
  94. { key: 'proxyExaminerCertNo', value: getValue(tendereeInfo, ['_ProxyExaminerCertNo']) }, // 招标代理审核人资格证书编号
  95. { key: 'proxyExamineDate', value: getValue(tendereeInfo, ['_ProxyExamineDate']) }, // 招标代理审核时间
  96. { key: 'proxyApprover', value: getValue(tendereeInfo, ['_ProxyApprover']) }, // 招标代理审定人
  97. { key: 'proxyApproverCertNo', value: getValue(tendereeInfo, ['_ProxyApproverCertNo']) }, // 招标代理审定人资格证书编号
  98. { key: 'proxyApproveDate', value: getValue(tendereeInfo, ['_ProxyApproveDate']) }, // 招标代理审定时间
  99. { key: 'consultant', value: getValue(tendereeInfo, ['_Consultant']) }, // 造价咨询
  100. { key: 'consultantCertNo', value: getValue(tendereeInfo, ['_ConsultantCertNo']) }, // 造价咨询资质证书编号
  101. { key: 'consultantCompiler', value: getValue(tendereeInfo, ['_ConsultantCompiler']) }, // 造价咨询编制人
  102. { key: 'consultantCompilerCertNo', value: getValue(tendereeInfo, ['_ConsultantCompilerCertNo']) }, // 造价咨询编制人资格证书
  103. { key: 'consultantCompileDate', value: getValue(tendereeInfo, ['_ConsultantCompileDate']) }, // 造价咨询编制时间
  104. { key: 'consultantExaminer', value: getValue(tendereeInfo, ['_ConsultantExaminer']) }, // 造价咨询审核人
  105. { key: 'consultantExaminerCertNo', value: getValue(tendereeInfo, ['_ConsultantExaminerCertNo']) }, // 造价咨询审核人资格证书编号
  106. { key: 'consultantExamineDate', value: getValue(tendereeInfo, ['_ConsultantExamineDate']) }, // 造价咨询审核时间
  107. { key: 'consultantApprover', value: getValue(tendereeInfo, ['_ConsultantApprover']) }, // 造价咨询审定人
  108. { key: 'consultantApproverCertNo', value: getValue(tendereeInfo, ['_ConsultantApproverCertNo']) }, // 造价咨询审定人资格证书编号
  109. { key: 'consultantApproveDate', value: getValue(tendereeInfo, ['_ConsultantApproveDate']) }, // 造价咨询审定时间
  110. { key: 'bidName', value: getValue(bidderInfo, ['_BidName']) }, // 投标人
  111. { key: 'bidAuthorizer', value: getValue(bidderInfo, ['_BidAuthorizer']) }, // 投标单位法定代表人或其授权人
  112. { key: 'bidCompiler', value: getValue(bidderInfo, ['_BidCompiler']) }, // 投标单位编制人
  113. { key: 'bidCompilerCertNo', value: getValue(bidderInfo, ['_BidCompilerCertNo']) }, // 投标单位编制人资格证书编号
  114. { key: 'bidCompileDate', value: getValue(bidderInfo, ['_BidCompileDate']) }, // 投标单位编制时间
  115. { key: 'bidExaminer', value: getValue(bidderInfo, ['_BidExaminer']) }, // 投标单位审核人
  116. { key: 'bidExaminerCertNo', value: getValue(bidderInfo, ['_BidExaminerCertNo']) }, // 投标单位审核人资格证书编号
  117. { key: 'bidExamineDate', value: getValue(bidderInfo, ['_BidExamineDate']) }, // 投标单位审核时间
  118. { key: 'bidApprover', value: getValue(bidderInfo, ['_BidApprover']) }, // 投标单位审定人
  119. { key: 'bidApproverCertNo', value: getValue(bidderInfo, ['_BidApproverCertNo']) }, // 投标单位审定人资格证书
  120. { key: 'bidApproveDate', value: getValue(bidderInfo, ['_BidApproveDate']) }, // 投标单位审定时间
  121. ];
  122. }
  123. // 从xml对象中提取单项工程数据
  124. function extractEngs(projectSrc) {
  125. const sectionWorks = arrayValue(projectSrc, ['ProjectInstallationWorkCost', 'SectionalWorks']);
  126. return sectionWorks.map(src => {
  127. countData.projectCount++;
  128. return {
  129. projType: projectType.Engineering,
  130. name: getValue(src, ['_Name']),
  131. code: getValue(src, ['_Number']),
  132. tenders: extractTenders(src)
  133. }
  134. });
  135. }
  136. // 从xml对象中提取单位工程数据
  137. function extractTenders(sectionWorkSrc) {
  138. const unitWorks = arrayValue(sectionWorkSrc, ['UnitWorks']);
  139. return unitWorks.map(src => {
  140. countData.projectCount++;
  141. countData.unitPriceFileCount++;
  142. return {
  143. projType: projectType.Tender,
  144. name: getValue(src, ['_Name']),
  145. code: getValue(src, ['_Number']),
  146. }
  147. });
  148. }
  149. /**
  150. * 解压cos、zip文件
  151. * @param {File} file - 上传的文件
  152. * @return {Object} 解压出来的xml文件名称与xml文件文本内容映射
  153. */
  154. async function unzipFile(file) {
  155. const jsZip = new JSZip();
  156. const zip = await jsZip.loadAsync(file);
  157. const map = {};
  158. for (const fileName in zip.files) {
  159. // 将二进制数据转换成字符串
  160. map[fileName] = await jsZip.file(fileName).async('string');
  161. }
  162. return map;
  163. }
  164. //从xml文件中提取数据
  165. async function extractData(file, escape = false) {
  166. const fileMap = await unzipFile(file);
  167. const projectXML = fileMap['Project.xml'];
  168. if (!projectXML) {
  169. throw '无有效数据';
  170. }
  171. const xmlObjMap = {};
  172. for (const fileName in fileMap) {
  173. const xmlStr = escape ? util.escapeXMLEntity(fileMap[fileName]) : fileMap[fileName];
  174. //将xml格式良好的字符串转换成对象
  175. const x2js = new X2JS();
  176. let xmlObj = x2js.xml_str2json(xmlStr);
  177. xmlObj = JSON.parse(util.restoreXMLEntity(JSON.stringify(xmlObj)));
  178. if (!xmlObj) {
  179. throw '无有效数据。';
  180. }
  181. xmlObjMap[fileName] = xmlObj;
  182. }
  183. //提取数据
  184. return loadData(xmlObjMap);
  185. };
  186. // 接受上传的文件类型(不同的省份可以上传的文件不同)
  187. const accept = ['.zip', '.cos'];
  188. return {
  189. accept,
  190. extractData,
  191. }
  192. })();