guangdong_2018_import.js 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  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. TaxType,
  12. } = commonConstants;
  13. const { AdjustType } = config;
  14. const {
  15. getValue,
  16. arrayValue,
  17. getFee,
  18. mergeFees,
  19. assignAttr,
  20. mergeDataRecur,
  21. getFlag,
  22. getBool,
  23. getItemsRecur,
  24. extractItemsRecur,
  25. } = util;
  26. //导入的文件类型,界面选的文件类型是生成项目的文件类型,这里的文件类型指的是,要导入文件的类型,
  27. //导入文件类型不同,导入数据不同
  28. let importFileKind = '';
  29. //文件类型
  30. const FileKind = {
  31. '6': 1, // 投标
  32. 'tender': 1,
  33. '4': 2, // 招标
  34. 'bid': 2,
  35. '5': 3, // 控制价
  36. 'control': 3,
  37. };
  38. // 一些数据是需要从后端获取自增数字后赋值的,这里是记录,用完会在extractProject清空
  39. const countData = {
  40. projectCount: 0, //项目数量
  41. projectGLJCount: 0, //项目人材机数量
  42. ratioCount: 0, //组成物数量
  43. unitPriceCount: 0, //单价数量
  44. unitPriceFileCount: 0, //单价文件数量
  45. };
  46. // 精度
  47. const Decimal = {
  48. // 工料机消耗量、含量、用量类小数精度
  49. GLJ: 4,
  50. // 工程量、数量类小数精度
  51. QUANTITY: 3,
  52. // 金额、合价、费用类小数精度
  53. FEE: 2,
  54. // 费率、指数、比例(%)类小数精度
  55. RATE: 3,
  56. };
  57. /*
  58. * 从导入的xml文件中提取有用的数据
  59. *
  60. */
  61. // 建设项目
  62. function extractProject(xmlObjMap) {
  63. Object.keys(countData).forEach(key => countData[key] = 0); // 清缓存
  64. countData.projectCount++;
  65. const projectXMLObj = xmlObjMap['Project.xml'];
  66. const projectSrc = getValue(projectXMLObj, ['ConstructionProject']);
  67. importFileKind = FileKind[getValue(projectSrc, ['_FileKind'])]; // 标记当前导入的文件类型
  68. const rst = {
  69. projType: projectType.Project,
  70. name: getValue(projectSrc, ['_Name']),
  71. engs: extractEngs(projectSrc, xmlObjMap),
  72. property: {
  73. compilationIllustrationProject: getValue(projectSrc, ['_Explains'])
  74. },
  75. basicInformation: extractBasicInfo(projectSrc)
  76. };
  77. countData.unitPriceCount = countData.projectGLJCount;
  78. if (importFileKind !== FileKind.tender) {
  79. countData = {
  80. projectCount: countData.projectCount,
  81. unitPriceFileCount: countData.unitPriceFileCount
  82. };
  83. }
  84. return rst;
  85. }
  86. // 从xml对象中提取基本信息相关
  87. function extractBasicInfo(projectSrc) {
  88. const projectInfo = getValue(projectSrc, ['ProjectInfo']); // 估概预算信息
  89. const tendereeInfo = getValue(projectSrc, ['TendereeInfo']); // 招标信息
  90. const bidderInfo = getValue(projectSrc, ['BidderInfo']); // 投标信息
  91. return [
  92. { key: 'projNum', value: getValue(projectSrc, ['_Number']) }, // 编码
  93. { key: 'projectCategory', value: getValue(projectSrc, ['_ProjectCategory']) }, // 工程类别
  94. { key: 'constructionType', value: getValue(projectSrc, ['_ConstructionType']) }, // 建设性质
  95. { key: 'regionalCategories', value: getValue(projectSrc, ['_AreaKind']) }, // 地区类被
  96. { key: 'projLocation', value: getValue(projectSrc, ['_ProjectSite']) }, // 工程地点
  97. { key: 'constructingUnits', value: getValue(projectSrc, ['_BulidUnit']) }, // 建设单位
  98. { key: 'constructingUnitsPerson', value: getValue(projectSrc, ['_BulidAuthorizer']) }, // 建设单位法定代表人或其授权人
  99. { key: 'rangeOfCompilation', value: getValue(projectSrc, ['_RangeOfCompilation']) }, // 建设(编制)范围
  100. { key: 'scale', value: getValue(projectSrc, ['_Scale']) }, // 建设规模
  101. { key: 'unit', value: getValue(projectSrc, ['_Unit']) }, // 建设规模单位
  102. { key: 'designUnits', value: getValue(projectInfo, ['_Designer']) }, // 设计单位
  103. { key: 'constructionUnits', value: getValue(projectInfo, ['_Contractor']) }, // 承包单位
  104. { key: 'establishUnit', value: getValue(projectInfo, ['_CompileCompany']) }, // 编制单位
  105. { key: importFileKind === FileKind.tender ? 'bidCompileDate' : 'tenderCompileDate', value: getValue(projectInfo, ['_CompileDate']) }, // 编制时间
  106. { key: 'authorizer', value: getValue(projectInfo, ['_Authorizer']) }, // 编制单位法定代表人或其授权人
  107. { key: 'tendereeName', value: getValue(tendereeInfo, ['_TendereeName']) }, // 招标人
  108. { key: 'tenderAuthorizer', value: getValue(tendereeInfo, ['_TenderAuthorizer']) }, // 招标单位法定代表人或其授权人
  109. { key: 'tenderCompiler', value: getValue(tendereeInfo, ['_TenderCompiler']) }, // 招标单位编制人
  110. { key: 'tenderCompilerCertNo', value: getValue(tendereeInfo, ['_TenderCompilerCertNo']) }, // 招标单位编制人资格证书编号
  111. { key: 'tenderCompileDate', value: getValue(tendereeInfo, ['_TenderCompileDate']) }, // 招标单位编制时间
  112. { key: 'tenderExaminer', value: getValue(tendereeInfo, ['_TenderExaminer']) }, // 招标单位审核人
  113. { key: 'tenderExaminerCertNo', value: getValue(tendereeInfo, ['_TenderExaminerCertNo']) }, // 招标单位审核人资格证书编号
  114. { key: 'tenderExamineDate', value: getValue(tendereeInfo, ['_TenderExamineDate']) }, // 招标单位审核时间
  115. { key: 'tenderApprover', value: getValue(tendereeInfo, ['_TenderApprover']) }, // 招标单位审定人
  116. { key: 'tenderApproverCertNo', value: getValue(tendereeInfo, ['_TenderApproverCertNo']) }, // 招标单位审定人资格证书编号
  117. { key: 'proxy', value: getValue(tendereeInfo, ['_Proxy']) }, // 招标代理
  118. { key: 'proxyCertNo', value: getValue(tendereeInfo, ['_ProxyCertNo']) }, // 招标代理资质证书编号
  119. { key: 'proxyAuthorizer', value: getValue(tendereeInfo, ['_ProxyAuthorizer']) }, // 招标代理法定代表人或其授权人
  120. { key: 'proxyCompiler', value: getValue(tendereeInfo, ['_ProxyCompiler']) }, // 招标代理编制人员
  121. { key: 'proxyCompilerCertNo', value: getValue(tendereeInfo, ['_ProxyCompilerCertNo']) }, // 招标代理编制人员资格证书编号
  122. { key: 'proxyCompileDate', value: getValue(tendereeInfo, ['_ProxyCompileDate']) }, // 招标代理编制时间
  123. { key: 'proxyExaminer', value: getValue(tendereeInfo, ['_ProxyExaminer']) }, // 招标代理审核人
  124. { key: 'proxyExaminerCertNo', value: getValue(tendereeInfo, ['_ProxyExaminerCertNo']) }, // 招标代理审核人资格证书编号
  125. { key: 'proxyExamineDate', value: getValue(tendereeInfo, ['_ProxyExamineDate']) }, // 招标代理审核时间
  126. { key: 'proxyApprover', value: getValue(tendereeInfo, ['_ProxyApprover']) }, // 招标代理审定人
  127. { key: 'proxyApproverCertNo', value: getValue(tendereeInfo, ['_ProxyApproverCertNo']) }, // 招标代理审定人资格证书编号
  128. { key: 'proxyApproveDate', value: getValue(tendereeInfo, ['_ProxyApproveDate']) }, // 招标代理审定时间
  129. { key: 'consultant', value: getValue(tendereeInfo, ['_Consultant']) }, // 造价咨询
  130. { key: 'consultantCertNo', value: getValue(tendereeInfo, ['_ConsultantCertNo']) }, // 造价咨询资质证书编号
  131. { key: 'consultantCompiler', value: getValue(tendereeInfo, ['_ConsultantCompiler']) }, // 造价咨询编制人
  132. { key: 'consultantCompilerCertNo', value: getValue(tendereeInfo, ['_ConsultantCompilerCertNo']) }, // 造价咨询编制人资格证书
  133. { key: 'consultantCompileDate', value: getValue(tendereeInfo, ['_ConsultantCompileDate']) }, // 造价咨询编制时间
  134. { key: 'consultantExaminer', value: getValue(tendereeInfo, ['_ConsultantExaminer']) }, // 造价咨询审核人
  135. { key: 'consultantExaminerCertNo', value: getValue(tendereeInfo, ['_ConsultantExaminerCertNo']) }, // 造价咨询审核人资格证书编号
  136. { key: 'consultantExamineDate', value: getValue(tendereeInfo, ['_ConsultantExamineDate']) }, // 造价咨询审核时间
  137. { key: 'consultantApprover', value: getValue(tendereeInfo, ['_ConsultantApprover']) }, // 造价咨询审定人
  138. { key: 'consultantApproverCertNo', value: getValue(tendereeInfo, ['_ConsultantApproverCertNo']) }, // 造价咨询审定人资格证书编号
  139. { key: 'consultantApproveDate', value: getValue(tendereeInfo, ['_ConsultantApproveDate']) }, // 造价咨询审定时间
  140. { key: 'bidName', value: getValue(bidderInfo, ['_BidName']) }, // 投标人
  141. { key: 'bidAuthorizer', value: getValue(bidderInfo, ['_BidAuthorizer']) }, // 投标单位法定代表人或其授权人
  142. { key: 'bidCompiler', value: getValue(bidderInfo, ['_BidCompiler']) }, // 投标单位编制人
  143. { key: 'bidCompilerCertNo', value: getValue(bidderInfo, ['_BidCompilerCertNo']) }, // 投标单位编制人资格证书编号
  144. { key: 'bidCompileDate', value: getValue(bidderInfo, ['_BidCompileDate']) }, // 投标单位编制时间
  145. { key: 'bidExaminer', value: getValue(bidderInfo, ['_BidExaminer']) }, // 投标单位审核人
  146. { key: 'bidExaminerCertNo', value: getValue(bidderInfo, ['_BidExaminerCertNo']) }, // 投标单位审核人资格证书编号
  147. { key: 'bidExamineDate', value: getValue(bidderInfo, ['_BidExamineDate']) }, // 投标单位审核时间
  148. { key: 'bidApprover', value: getValue(bidderInfo, ['_BidApprover']) }, // 投标单位审定人
  149. { key: 'bidApproverCertNo', value: getValue(bidderInfo, ['_BidApproverCertNo']) }, // 投标单位审定人资格证书
  150. { key: 'bidApproveDate', value: getValue(bidderInfo, ['_BidApproveDate']) }, // 投标单位审定时间
  151. ];
  152. }
  153. // 从xml对象中提取单项工程数据
  154. function extractEngs(projectSrc, xmlObjMap) {
  155. const sectionWorks = arrayValue(projectSrc, ['ProjectInstallationWorkCost', 'SectionalWorks']);
  156. return sectionWorks.map(src => {
  157. countData.projectCount++;
  158. return {
  159. projType: projectType.Engineering,
  160. name: getValue(src, ['_Name']),
  161. code: getValue(src, ['_Number']),
  162. tenders: extractTenders(src, xmlObjMap)
  163. }
  164. });
  165. }
  166. // 从xml对象中提取单位工程数据
  167. function extractTenders(sectionWorkSrc, xmlObjMap) {
  168. const unitWorks = arrayValue(sectionWorkSrc, ['UnitWorks']);
  169. return unitWorks.map(unitWorckSrc => {
  170. countData.projectCount++;
  171. countData.unitPriceFileCount++;
  172. const fileName = getValue(unitWorckSrc, ['_FileName']);
  173. const tenderXMLObj = xmlObjMap[fileName];
  174. const src = getValue(tenderXMLObj, ['UnitWorks']); // 单位工程文件的数据
  175. return {
  176. projType: projectType.Tender,
  177. name: getValue(src, ['_Name']),
  178. code: getValue(src, ['_Number']),
  179. engineering: getValue(src, ['_ProjectType']),
  180. projectFeature: extractProjectFeature(src),
  181. workSummary: extractWorkSummary(src),
  182. fbfx: extractFBFX(src),
  183. csxm: extractCSXM(src),
  184. other: extractOther(src),
  185. tax: extractTax(src),
  186. ...extractGLJSummary(src),
  187. bidEvaluationSummary: extractBidEvaluationSummary(src)
  188. };
  189. });
  190. }
  191. // 提取工程特征数据
  192. function extractProjectFeature(tenderSrc) {
  193. // TODO 支持嵌套子项
  194. const attrInfoItems = arrayValue(tenderSrc, ['AttrInfo', 'AttrInfoItem']);
  195. return attrInfoItems.map(item => {
  196. return { name: getValue(item, ['_Name']), value: getValue(item, ['_Value']) };
  197. });
  198. }
  199. // 提取大项费用
  200. function extractWorkSummary(tenderSrc) {
  201. const summarySrc = getValue(tenderSrc, ['UnitWorksSummary']);
  202. const fields = [['UnitWorksSummaryGroup'], ['UnitWorksSummaryItem']];
  203. return extractItemsRecur(summarySrc, fields, (src, curField) => {
  204. const item = {
  205. code: getValue(src, ['_Number']),
  206. name: getValue(src, ['_Name']),
  207. quantity: getValue(src, ['_Quantity']),
  208. remark: getValue(src, ['_Remark']),
  209. feeCode: getValue(src, ['_Code']), //费用字典
  210. fees: [{
  211. fieldName: 'common', totalFee: getValue(src, ['_Total']) || '0',
  212. unitFee: getValue(src, ['_TechnicalAndEconomicIndex']) || '0'
  213. }]
  214. };
  215. if (curField[0] === fields[1][0]) {
  216. item.calcBase = getValue(src, ['_QtyFormula']);
  217. item.feeRate = getValue(src, ['_Rate']);
  218. }
  219. if (importFileKind !== FileKind.tender) {
  220. delete item.feeRate
  221. delete item.fees;
  222. }
  223. return item;
  224. });
  225. }
  226. // 从src子项的SummaryOfBasicCost中获取一部分费用
  227. function getFeesFromBasicCost(src) {
  228. const summaryCost = getValue(src, ['SummaryOfBasicCost']);
  229. if (!summaryCost) {
  230. return [];
  231. }
  232. // SummaryOfBasicCost中有用的价格只有:人工费、材料费、主材费、机械费、管理费、利润
  233. return [
  234. { fieldName: 'labour', totalFee: getValue(summaryCost, ['_Labor']) || '0' },
  235. { fieldName: 'material', totalFee: getValue(summaryCost, ['_Material']) || '0' },
  236. { fieldName: 'mainMaterial', totalFee: getValue(summaryCost, ['_MainMaterial']) || '0' },
  237. { fieldName: 'machine', totalFee: getValue(summaryCost, ['_Machine']) || '0' },
  238. { fieldName: 'manage', totalFee: getValue(summaryCost, ['_Overhead']) || '0' },
  239. { fieldName: 'profit', totalFee: getValue(summaryCost, ['_Profit']) || '0' },
  240. ];
  241. }
  242. // 提取分部分项
  243. function extractFBFX(tenderSrc) {
  244. const fbfxSrc = getValue(tenderSrc, ['DivisionalAndElementalWorks']);
  245. const fields = [['DivisionalWorks'], ['WorkElement']];
  246. const fees = getFeesFromBasicCost(fbfxSrc); // 分部分项的汇总价
  247. const items = getItemsRecur(fbfxSrc, fields, (itemSrc, curField) => {
  248. if (curField[0] === fields[0][0]) { // 分部
  249. return extractDivisionalWorks(itemSrc, billType.FB);
  250. } else {
  251. return extractWorkElement(itemSrc, billType.FX);
  252. }
  253. });
  254. return {
  255. fees,
  256. items
  257. };
  258. }
  259. // 提取分部
  260. function extractDivisionalWorks(divisionalSrc, type) {
  261. // 分部不需要基数,因此不用把基数导入
  262. const item = {
  263. type,
  264. code: getValue(divisionalSrc, ['_Number']),
  265. name: getValue(divisionalSrc, ['_Name']),
  266. unit: getValue(divisionalSrc, ['_Unit']),
  267. quantity: getValue(divisionalSrc, ['_Quantity']),
  268. feeCode: getValue(divisionalSrc, ['_Code']),
  269. remark: getValue(divisionalSrc, ['_Remark']),
  270. };
  271. if (importFileKind === FileKind.tender) {
  272. const summaryFees = getFeesFromBasicCost(divisionalSrc);
  273. const fees = [{ fieldName: 'common', totalFee: getValue(divisionalSrc, ['_Total']), unitFee: getValue(divisionalSrc, ['_TechnicalAndEconomicIndex']) }];
  274. item.fees = mergeFees(fees, summaryFees);
  275. }
  276. return item;
  277. }
  278. // 提取分项清单数据(包含定额、定额人材机)
  279. function extractWorkElement(workElementSrc, type) {
  280. const itemCharacterText = getItemCharacterText(getValue(workElementSrc, ['_Attr']));
  281. const bills = {
  282. type: type, // 清单类型
  283. code: getValue(workElementSrc, ['_Number']),
  284. name: getValue(workElementSrc, ['_Name']),
  285. itemCharacterText,
  286. itemCharacter: getItemCharacter(itemCharacterText),
  287. jocContentText: getValue(workElementSrc, ['_WorkContent']),
  288. jobContent: getJobContent(workElementSrc),
  289. unit: getValue(workElementSrc, ['_Unit']),
  290. quantity: getValue(workElementSrc, ['_Quantity']),
  291. feeRate: getValue(workElementSrc, ['_Rate']),
  292. mainBills: getBool(getValue(workElementSrc, ['_Major'])),
  293. feeCode: getValue(workElementSrc, ['_Code']),
  294. remark: getValue(workElementSrc, ['_Remark']),
  295. rations: extractRations(workElementSrc)
  296. };
  297. if (type === billType.BILL) {
  298. // 分项不需要基数
  299. bills.calcBase = getValue(workElementSrc, ['_QtyFormula']);
  300. }
  301. // 投标和控制价,需要导入最高限价
  302. if ([FileKind.tender, FileKind.control].includes(importFileKind)) {
  303. const maxPrice = getValue(workElementSrc, ['_PriceHigh']);
  304. //不为0才输出
  305. if (maxPrice && maxPrice !== '0') {
  306. bills.outPutMaxPrice = true;
  307. bills.maxPrice = maxPrice;
  308. }
  309. if (importFileKind === FileKind.tender) {
  310. const summaryFees = getFeesFromBasicCost(workElementSrc);
  311. const fees = [
  312. { fieldName: 'common', unitFee: getValue(workElementSrc, ['_Price']), totalFee: getValue(workElementSrc, ['_Total']) },
  313. { fieldName: 'equipment', unitFee: getValue(workElementSrc, ['_EquipmentPrice']) },
  314. ];
  315. bills.fees = mergeFees(fees, summaryFees);
  316. }
  317. }
  318. return bills;
  319. // 获取项目特征文本
  320. function getItemCharacterText(attr) {
  321. // 去掉除换行符以外的空白符
  322. const newLine = '{newLine}';
  323. attr = attr
  324. .replace(/[\r\n]/g, newLine)
  325. .replace(/\s/g, '')
  326. .replace(new RegExp(newLine, 'g'), '\n');
  327. const matchStrs = ['
', ';'];
  328. const matchStr = matchStrs.find(str => attr.includes(str));
  329. if (matchStr) {
  330. attr = attr.replace(new RegExp(matchStr, 'g'), '\n');
  331. }
  332. return attr;
  333. }
  334. // 获取清单项目特征窗口数据
  335. function getItemCharacter(itemText) {
  336. const itemsList = itemText.split('\n');
  337. const reg = /\d+\.([^:]+)[::](.*)?/;
  338. const itemCharacter = [];
  339. let idx = 1;
  340. itemsList.forEach(str => {
  341. str = str.replace(/\s/g, '');
  342. const result = reg.exec(str);
  343. if (!result) {
  344. return;
  345. }
  346. const name = result[1];
  347. const value = result[2] || '';
  348. const eigenvalue = value ? [{ value, isSelected: true }] : [];
  349. itemCharacter.push({
  350. character: name,
  351. isChecked: true,
  352. serialNo: idx++,
  353. eigenvalue
  354. });
  355. });
  356. return itemCharacter;
  357. }
  358. // 获取清单工作内容窗口数据
  359. function getJobContent(workElementSrc) {
  360. return arrayValue(workElementSrc, ['WorkContent']).map((workContent, idx) => ({
  361. content: getValue(workContent, ['_Name']),
  362. serialNo: idx + 1,
  363. isChecked: true
  364. }));
  365. }
  366. }
  367. // 提取定额
  368. function extractRations(workElementSrc) {
  369. if (importFileKind !== FileKind.tender) {
  370. return [];
  371. }
  372. // 正常情况下定额肯定是在WorkContent内的,但是也做定额不在WorkContent内的处理(外层定额)
  373. const rations = [];
  374. let serialNo = 1;
  375. const workContents = arrayValue(workElementSrc, ['WorkContent']);
  376. workContents.forEach(workContent => {
  377. const innerRationsSrc = arrayValue(workContent, ['Norm']);
  378. const jobContentText = getValue(workContent, ['_Name']);
  379. const innerRations = innerRationsSrc.map(rationSrc => extractRation(rationSrc, jobContentText));
  380. rations.push(...innerRations);
  381. });
  382. const outerRationsSrc = arrayValue(workElementSrc, ['Norm']);
  383. const outerRations = outerRationsSrc.map(rationSrc => extractRation(rationSrc, ''));
  384. rations.push(...outerRations);
  385. return rations;
  386. // 获取类型
  387. function getType(rationSrc) {
  388. const overHeightMap = {
  389. '1': true,
  390. '2': false
  391. };
  392. const isOverHeight = overHeightMap[getValue(rationSrc, ['EfficiencyKind'])];
  393. if (isOverHeight) {
  394. return rationType.overHeight;
  395. }
  396. const itemIncreaseMap = {
  397. '1': true,
  398. '2': false
  399. };
  400. const isItemIncrease = itemIncreaseMap[getValue(rationSrc, ['IncFeeKind'])];
  401. if (isItemIncrease) {
  402. return rationType.itemIncrease;
  403. }
  404. return rationType.ration;
  405. }
  406. // 从定额的计算程序提取价格
  407. function getFeesFromCalculationOfItem(rationSrc) {
  408. const calculationOfItems = arrayValue(rationSrc, ['UnitPriceCalculationOfItem']);
  409. const fees = [];
  410. const codeFiedNameMap = {
  411. 'DEZJF': 'direct',
  412. 'RGF': 'labour',
  413. 'CLF': 'material',
  414. 'JXF': 'machine',
  415. 'ZCF': 'mainMaterial',
  416. 'SBF': 'equipment',
  417. 'LR': 'profit',
  418. 'DJ': 'common',
  419. };
  420. calculationOfItems.forEach(item => {
  421. const totalFee = +getValue(item, ['_Total']);
  422. const fieldName = codeFiedNameMap[getValue(item, ['_Code'])];
  423. if (totalFee && fieldName) {
  424. fees.push({ fieldName, totalFee });
  425. }
  426. });
  427. return fees;
  428. }
  429. // 提取定额人材机
  430. function extractRationGLJs(rationSrc) {
  431. const rationGLJsSrc = arrayValue(rationSrc, ['LabourMaterialsEquipmentsMachinesElement']);
  432. return rationGLJsSrc.map(src => ({
  433. code: getValue(src, ['_Number']),
  434. quantity: getValue(src, ['_Quantity'])
  435. }));
  436. }
  437. // TODO 目前无法确定定额的取费专业programID,暂时用专业类别Specialty
  438. function extractRation(rationSrc, jobContentText) {
  439. const ration = {
  440. serialNo: serialNo++,
  441. code: getValue(rationSrc, ['_Number']),
  442. name: getValue(rationSrc, ['_Name']),
  443. unit: getValue(rationSrc, ['_Unit']),
  444. quantity: getValue(rationSrc, ['_Quantity']),
  445. type: getType(rationSrc),
  446. programID: getValue(rationSrc, ['_Specialty']),
  447. libCode: getValue(rationSrc, ['_NormIdentity']),
  448. jobContentText,
  449. remark: getValue(rationSrc, ['_Remark'])
  450. };
  451. const fees = [{ fieldName: 'common', unitFee: getValue(rationSrc, ['_Price']), totalFee: getValue(rationSrc, ['_Total']) }]
  452. const feesFromCalcItem = getFeesFromCalculationOfItem(rationSrc);
  453. ration.fees = mergeFees(fees, feesFromCalcItem);
  454. ration.rationGLJs = extractRationGLJs(rationSrc);
  455. return ration;
  456. }
  457. }
  458. // 提取措施项目
  459. function extractCSXM(tenderSrc) {
  460. const csxmSrc = getValue(tenderSrc, ['Preliminaries']);
  461. const fields = [['DivisionalWorks'], ['WorkElement']];
  462. const fees = getFeesFromBasicCost(csxmSrc); // 措施项目的汇总价
  463. const items = getItemsRecur(csxmSrc, fields, (itemSrc, curField) => {
  464. if (curField[0] === fields[0][0]) {
  465. return extractDivisionalWorks(itemSrc, billType.BILL);
  466. } else {
  467. return extractWorkElement(itemSrc, billType.BILL);
  468. }
  469. });
  470. return {
  471. fees,
  472. items
  473. };
  474. }
  475. // 提取其他项目
  476. function extractOther(tenderSrc) {
  477. const sundry = getValue(tenderSrc, ['Sundry']);
  478. // SundryCosts 其他项目 ,对于我们软件是其他项目下完整数据,但是广联达的并不是,因此需要Sundry的其他节点来补充这份数据
  479. const sundryCosts = getValue(sundry, ['SundryCosts']);
  480. // 其他项目汇总费用
  481. const sundryFees = [{ fieldName: 'common', totalFee: getValue(sundryCosts, ['_Total']) }];
  482. const provisionalMaterialEquipment = getValue(sundry, ['ProvisionalMaterialEquipment']);
  483. return {
  484. fees: importFileKind === FileKind.tender ? sundryFees : [],
  485. sundryCosts: extractData(sundry, 'SundryCosts', [['SundryCostsGroup'], ['SundryCostsItem']]),
  486. provisional: extractData(sundry, 'ProvisionalSums', [['ProvisionalSumsGroup'], ['ProvisionalSumsItem']]),
  487. ProvisionalMaterialEquipment: {
  488. name: getValue(provisionalMaterialEquipment, ['_Name']),
  489. feeCode: getValue(provisionalMaterialEquipment, ['_Code']),
  490. remark: getValue(provisionalMaterialEquipment, ['_Remark']),
  491. fees: [{ fieldName: 'common', totalFee: getValue(provisionalMaterialEquipment, ['_Total']) }],
  492. },
  493. specialty: extractData(sundry, 'SpecialtyProvisionalPrice', [['SpecialtyProvisionalPriceGroup'], ['SpecialtyProvisionalPriceItem']],
  494. { engineeringContent: ['_Content'] }, { engineeringContent: ['_Content'] }),
  495. dayWork: extractData(sundry, 'DayWorkRate', [['DayWorkRateGroup'], ['DayWorkRateItem']]),
  496. mainContractor: extractData(sundry, 'MainContractorAttendance', [['MainContractorAttendanceGroup'], ['MainContractorAttendanceItem']], { serviceContent: ['_Content'] }),
  497. claim: extractData(sundry, 'ClaimsCost', [['ClaimsCostGroup'], ['ClaimsCostItem']]),
  498. visa: extractData(sundry, 'SiteInstructionCost', [['SiteInstructionCostGroup'], ['SiteInstructionCostItem']]),
  499. };
  500. // 提取标题和明细
  501. function extractGroupOrItem(itemSrc, isGroup = true, extendAttrs = null) {
  502. const source = isGroup
  503. ? {
  504. name: getValue(itemSrc, ['_Name']),
  505. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(itemSrc, ['_Total']) }] : [],
  506. feeCode: getValue(itemSrc, ['_Code']),
  507. remark: getValue(itemSrc, ['_Remark'])
  508. }
  509. : {
  510. name: getValue(itemSrc, ['_Name']),
  511. unit: getValue(itemSrc, ['_Unit']),
  512. quantity: getValue(itemSrc, ['_Quantity']),
  513. calcBase: getValue(itemSrc, ['_QtyFormula']),
  514. feeRate: getValue(itemSrc, ['_Rate']),
  515. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', unitFee: getValue(itemSrc, ['_Price']), totalFee: getValue(itemSrc, ['_Total']) }] : [],
  516. feeCode: getValue(itemSrc, ['_Code']),
  517. remark: getValue(itemSrc, ['_Remark'])
  518. };
  519. return extendAttrs ? Object.assign(source, extendAttrs) : source;
  520. }
  521. // 提取数据
  522. function extractData(sundry, srcName, fields, groupExtendMap, itemExtendMap) {
  523. const src = getValue(sundry, [srcName]);
  524. return {
  525. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(src, ['_Total']) }] : [],
  526. feeCode: getValue(src, ['_Code']),
  527. items: extractItemsRecur(src, fields, (itemSrc, curField) => {
  528. const groupExtend = groupExtendMap
  529. ? Object.keys(groupExtendMap).reduce((acc, key) => {
  530. acc[key] = getValue(itemSrc, groupExtendMap[key]);
  531. return acc;
  532. }, {})
  533. : null;
  534. const itemExtend = itemExtendMap
  535. ? Object.keys(itemExtendMap).reduce((acc, key) => {
  536. acc[key] = getValue(itemSrc, itemExtendMap[key]);
  537. return acc;
  538. }, {})
  539. : null;
  540. return curField[0] === fields[0][0]
  541. ? extractGroupOrItem(itemSrc, true, groupExtend)
  542. : extractGroupOrItem(itemSrc, false, itemExtend);
  543. })
  544. };
  545. }
  546. }
  547. // 提取税金
  548. function extractTax(tenderSrc) {
  549. const taxSrc = getValue(tenderSrc, ['Tax']);
  550. const itemsSrc = arrayValue(taxSrc, ['TaxItem']);
  551. return {
  552. ...extractTaxItem(taxSrc),
  553. items: itemsSrc.map(extractTaxItem)
  554. };
  555. function extractTaxItem(src) {
  556. return {
  557. name: getValue(src, ['_Name']),
  558. calcBase: getValue(src, ['_QtyFormula']),
  559. feeRate: getValue(src, ['_Rate']),
  560. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(src, ['_Total']) }] : [],
  561. feeCode: getValue(src, ['_Code']),
  562. remark: getValue(src, ['_Remark'])
  563. };
  564. }
  565. }
  566. // 供料方式
  567. const Provider = {
  568. '1': commonConstants.supplyType.ZXCG,
  569. '2': commonConstants.supplyType.BFJG,
  570. '3': commonConstants.supplyType.WQJG
  571. };
  572. // 提取人材机汇总相关(人材机汇总表、承包材料表)
  573. function extractGLJSummary(tenderSrc) {
  574. const initData = { gljSummary: [], differentiaSummary: [], exponentialSummary: [] };
  575. if (importFileKind !== FileKind.tender) {
  576. return initData;
  577. }
  578. const taxType = getValue(tenderSrc, ['_TaxModel']); // 计税方式
  579. const gljListSrc = arrayValue(tenderSrc, ['LabourMaterialsEquipmentsMachinesSummary']);
  580. return gljListSrc.reduce((acc, gljSrc) => {
  581. acc.gljSummary.push(extractGLJ(gljSrc));
  582. const differentiaGLJ = extractDifferentiaGLJ(gljSrc);
  583. if (differentiaGLJ) {
  584. acc.differentiaSummary.push(differentiaGLJ);
  585. }
  586. const exponentialGLJ = extractExponentialGLJ(gljSrc);
  587. if (exponentialGLJ) {
  588. acc.exponentialSummary.push(exponentialGLJ);
  589. }
  590. return acc;
  591. }, initData);
  592. // 获取原始编码
  593. function getOriginalCode(code) {
  594. //编码后面有-\d+的形式,去掉-\d+取前面的字符串作为原始代码
  595. return code.replace(/(.*)-\d+$/, '$1');
  596. }
  597. // TODO (不靠谱) 获取人材机类型数据
  598. // 导入的源文件没有细化区分人材机类型,这里只是暂时大概给个值。后续会在后端与标准人材机进行配对。也因此无法准确处理补充人材机
  599. function getTypeData(gljSrc) {
  600. const concrete = getBool(getValue(gljSrc, ['_Concrete']));
  601. if (concrete) {
  602. return { type: 205, shorName: '商砼' };
  603. }
  604. const type = getValue(gljSrc, ['_Kind']);
  605. switch (type) {
  606. case '6':
  607. return { type: 202, shorName: '砼' };
  608. case '7':
  609. return { type: 301, shorName: '机' };
  610. case '15':
  611. return { type: 6, shortName: '管' };
  612. default:
  613. return { type: 201, shortName: '材' };
  614. }
  615. }
  616. // 根据计税方式获取价格,一般计税对应不含税,简易对应含税
  617. function getPriceByTaxType(gljSrc, taxType) {
  618. return taxType === TaxType.NORMAL
  619. ? {
  620. base_price: getValue(gljSrc, ['_NoTaxOrgPrice']),
  621. market_price: getValue(gljSrc, ['_NoTaxPrice'])
  622. }
  623. : {
  624. base_price: getValue(gljSrc, ['_TaxOrgPrice']),
  625. market_price: getValue(gljSrc, ['_TaxPrice'])
  626. };
  627. }
  628. // 提取组成物
  629. function extractRatios(gljSrc) {
  630. const ratiosSrc = arrayValue(gljSrc, ['LabourMaterialsEquipmentsMachinesElement']);
  631. countData.ratioCount += ratiosSrc.length;
  632. return ratiosSrc.map(src => ({
  633. code: getValue(src, ['_Number']),
  634. consumption: getValue(src, ['_Quantity'])
  635. }));
  636. }
  637. // 提取项目人材机
  638. function extractGLJ(gljSrc) {
  639. countData.projectGLJCount++;
  640. const code = getValue(gljSrc, ['_Number']);
  641. return {
  642. code,
  643. original_code: getOriginalCode(code),
  644. name: getValue(gljSrc, ['_Name']),
  645. specs: getValue(gljSrc, ['_Specification']),
  646. unit: getValue(gljSrc, ['_Unit']),
  647. ...getTypeData(gljSrc),
  648. ...getPriceByTaxType(gljSrc, taxType), // 软件中项目人材机是没有价格的,只是为了后续处理单价文件
  649. is_main_material: getBool(getValue(gljSrc, ['_MainMaterial'])),
  650. is_evaluate: getBool(getValue(gljSrc, ['_ProvisionalMaterial'])),
  651. supply: Provider[getValue(gljSrc, ['_Provider'])],
  652. delivery: getValue(gljSrc, ['_Delivery']),
  653. delivery_address: getValue(gljSrc, ['_Location']),
  654. originPlace: getValue(gljSrc, ['_ProducingArea']),
  655. vender: getValue(gljSrc, ['_Supplier']),
  656. qualityGrace: getValue(gljSrc, ['_Character']),
  657. remark: getValue(gljSrc, ['_Remark']),
  658. ratios: extractRatios(gljSrc)
  659. };
  660. }
  661. // 提取造价信息差额调整法
  662. function extractDifferentiaGLJ(gljSrc) {
  663. // 风险系数或者基准单价有值,才算一条差额数据
  664. const riskCoe = getValue(gljSrc, ['_ProviderExp']);
  665. const standardPrice = getValue(gljSrc, ['_ProviderBase']);
  666. if ((riskCoe && riskCoe !== '0') || (standardPrice && standardPrice !== '0')) {
  667. return {
  668. code: getValue(gljSrc, ['_Number']),
  669. name: getValue(gljSrc, ['_Name']),
  670. specs: getValue(gljSrc, ['_Specification']),
  671. unit: getValue(gljSrc, ['_Unit']),
  672. quantity: getValue(gljSrc, ['_Quantity']),
  673. riskCoe,
  674. standardPrice,
  675. market_price: getPriceByTaxType(gljSrc, taxType).market_price,
  676. remark: getValue(gljSrc, ['_Remark']),
  677. };
  678. }
  679. return null;
  680. }
  681. // 提取价格指数调整法
  682. function extractExponentialGLJ(gljSrc) {
  683. // 变值权重或基本、现行价格指数有值,才算一条指数数据
  684. const varWeight = getValue(gljSrc, ['_Weight']);
  685. const FO = getValue(gljSrc, ['_BasicPrice']);
  686. const FI = getValue(gljSrc, ['_CurrentPrice']);
  687. if ((varWeight && varWeight !== '0') || (FO && FO !== '0') || (FI && FI !== '0')) {
  688. return {
  689. code: getValue(gljSrc, ['_Number']),
  690. name: getValue(gljSrc, ['_Name']),
  691. specs: getValue(gljSrc, ['_Specification']),
  692. varWeight: varWeight,
  693. FO: FO,
  694. FI: FI,
  695. remark: getValue(gljSrc, ['_Remark'])
  696. };
  697. }
  698. return null;
  699. }
  700. }
  701. // 提取评标材料
  702. function extractBidEvaluationSummary(tenderSrc) {
  703. if (importFileKind !== FileKind.tender) {
  704. return [];
  705. }
  706. const srcList = arrayValue(tenderSrc, ['BidEvaluationMainMaterial']);
  707. return srcList.map(gljSrc => ({
  708. seq: getValue(gljSrc, ['_Code']),
  709. code: getValue(gljSrc, ['_Number']),
  710. name: getValue(gljSrc, ['_Name']),
  711. specs: getValue(gljSrc, ['_Specification']),
  712. unit: getValue(gljSrc, ['_Unit']),
  713. quantity: getValue(gljSrc, ['_Quantity']),
  714. market_price: getValue(gljSrc, ['_Price']),
  715. originPlace: getValue(gljSrc, ['_ProducingArea']),
  716. vender: getValue(gljSrc, ['_Supplier']),
  717. remark: getValue(gljSrc, ['_Remark'])
  718. }));
  719. }
  720. /*
  721. * 转换从xml提取的数据,转换成软件所需的数据结构
  722. *
  723. */
  724. async function transformData(extractedData) {
  725. const IDPlaceholder = await ajaxPost('/pm/import/getProjectPlaceholder', countData);
  726. extractedData.ID = IDPlaceholder.project++;
  727. // 最终上传到服务器的转换后的数据
  728. const transformedData = {
  729. ID: extractedData.ID,
  730. ParentID: extractedData.ParentID,
  731. NextSiblingID: extractedData.NextSiblingID,
  732. preID: extractedData.preID,
  733. name: extractedData.name,
  734. basicInformation: extractedData.basicInformation,
  735. projType: extractedData.projType,
  736. property: extractedData.property,
  737. shareInfo: [],
  738. engs: []
  739. };
  740. // 所有的清单模板库ID
  741. const allTemplateLibIDs = [];
  742. extractedData.engs.forEach(eng => {
  743. eng.tenders.forEach(tender => {
  744. let templateLibID = tender.property.templateLibID;
  745. if (!allTemplateLibIDs.includes(templateLibID)) {
  746. allTemplateLibIDs.push(templateLibID);
  747. }
  748. });
  749. });
  750. // 模板映射:{[templateLibID]: data}
  751. const templateMapping = await ajaxPost('/template/bills/api/getNeedfulTemplate', { allTemplateLibIDs });
  752. for (let i = 0; i < extractedData.engs.length; i++) {
  753. const curEng = extractedData.engs[i];
  754. const preEng = transformedData.engs[i - 1];
  755. curEng.ID = IDPlaceholder.project++;
  756. curEng.ParentID = extractedData.ID;
  757. curEng.NextSiblingID = -1;
  758. if (preEng) {
  759. preEng.NextSiblingID = curEng.ID;
  760. }
  761. const engData = {
  762. ID: curEng.ID,
  763. ParentID: curEng.ParentID,
  764. NextSiblingID: curEng.NextSiblingID,
  765. code: curEng.code,
  766. name: curEng.name,
  767. projType: curEng.projType,
  768. shareInfo: [],
  769. tenders: []
  770. };
  771. transformedData.engs.push(engData);
  772. for (let j = 0; j < curEng.tenders.length; j++) {
  773. const curTender = curEng.tenders[j];
  774. const preTender = engData.tenders[j - 1];
  775. curTender.ID = IDPlaceholder.project++;
  776. curTender.ParentID = curEng.ID;
  777. curTender.NextSiblingID = -1;
  778. curTender.property.unitPriceFile.id = IDPlaceholder.unitPriceFile++;
  779. if (preTender) {
  780. preTender.tender.NextSiblingID = curTender.ID;
  781. }
  782. // 项目清单模板(后台清单模板中提取含有固定类别的数据)
  783. const billsTemplate = _.cloneDeep(templateMapping[curTender.property.templateLibID]);
  784. // 重设模板树结构数据
  785. BILLS_UTIL.resetTreeData(billsTemplate, uuid.v1);
  786. console.log(billsTemplate);
  787. const tenderData = transformTender(curTender, IDPlaceholder, billsTemplate);
  788. tenderData.tender.property.rootProjectID = transformedData.ID;
  789. engData.tenders.push(tenderData);
  790. }
  791. }
  792. console.log(`transformedData`);
  793. console.log(transformedData);
  794. return transformedData;
  795. }
  796. // 获取承包人材料类型
  797. function getAdjustType(tenderData) {
  798. if (tenderData.differentiaSummary.length) {
  799. return AdjustType.info;
  800. } else if (tenderData.exponentialSummary.length) {
  801. return AdjustType.coe;
  802. } else {
  803. return AdjustType.info;
  804. }
  805. }
  806. // 获取当前文件
  807. // 转换单位工程的数据(直接可插入数据库的数据),返回{tender: {}, bills: [], ration: [], rationGLJ: [], projectGLJ: [], unitPrice: [], mixRatio: []}
  808. function transformTender(tenderData, IDPlaceholder, billsTemplate) {
  809. const detailData = transformDetail(tenderData, IDPlaceholder, billsTemplate);
  810. // 提取需要插入的单位工程数据
  811. const transformedTender = {
  812. ID: tenderData.ID,
  813. ParentID: tenderData.ParentID,
  814. NextSiblingID: tenderData.NextSiblingID,
  815. code: tenderData.code,
  816. name: tenderData.name,
  817. projType: tenderData.projType,
  818. property: tenderData.property,
  819. projectFeature: tenderData.projectFeature,
  820. engineering: tenderData.engineering,
  821. defaultRationLib: tenderData.defaultRationLib,
  822. rationLibIDs: tenderData.rationLibIDs,
  823. gljLibIDs: tenderData.gljLibIDs,
  824. shareInfo: []
  825. };
  826. transformedTender.property.gljAdjustType = getAdjustType(tenderData)
  827. detailData.tender = transformedTender;
  828. return detailData;
  829. }
  830. // 过滤掉相关费用代号的数据(递归地)
  831. // 返回被过滤掉的数据
  832. function filterDataByFeeCodes(billsData, feeCodes) {
  833. const filterd = [];
  834. billsData.forEach(bills => {
  835. if (bills.items && bills.items.length) {
  836. const newItems = [];
  837. bills.items.forEach(subBills => {
  838. if (!feeCodes.includes(subBills.feeCode)) {
  839. newItems.push(subBills);
  840. } else {
  841. filterd.push(subBills);
  842. }
  843. });
  844. bills.items = newItems;
  845. // bills.items = bills.items.filter(subBills => !feeCodes.includes(subBills.feeCode));
  846. const subFilterd = filterDataByFeeCodes(bills.items, feeCodes);
  847. filterd.push(...subFilterd);
  848. }
  849. });
  850. return filterd;
  851. }
  852. // 合并清单,将提取出来的清单相关数据,合并进项目清单(模板)
  853. function mergeBills(tenderData, billsTemplate) {
  854. debugger;
  855. const mergedBills = [...billsTemplate];
  856. const roots = billsTemplate.filter(bills => bills.ParentID === -1);
  857. let lastRoot = roots.find(root => root.NextSiblingID === -1);
  858. mergeWorkSummary(tenderData.workSummary);
  859. mergeFBFX(tenderData.fbfx);
  860. mergeCSXM(tenderData.csxm);
  861. mergeOther(tenderData.other);
  862. mergeTax(tenderData.tax);
  863. return mergedBills;
  864. // 合并清单数据
  865. function mergeitems(fixedBills, items) {
  866. const daryWorkMap = {
  867. '人工': fixedFlag.LABOUR,
  868. '材料': fixedFlag.MATERIAL,
  869. '机械': fixedFlag.MACHINE,
  870. '施工机械': fixedFlag.MACHINE,
  871. '施工机具': fixedFlag.MACHINE
  872. };
  873. const fixedBillsFlag = getFlag(fixedBills);
  874. let preBills = billsTemplate.find(bills => bills.ParentID === fixedBills.ID && bills.NextSiblingID === -1);
  875. items.forEach(bills => {
  876. // 计日工需要特殊处理,兼容广联达的数据,广联达的计日工下的人工、材料、机械的费用字典不对,因此用名称匹配
  877. let matched;
  878. if (fixedBillsFlag === fixedFlag.DAYWORK) {
  879. const dayWorkSubFlag = daryWorkMap[bills.name];
  880. matched = dayWorkSubFlag
  881. ? billsTemplate.find(templateBills => getFlag(templateBills) === dayWorkSubFlag)
  882. : null;
  883. } else {
  884. matched = billsTemplate.find(templateBills => FlagFeeCodeMap[getFlag(templateBills)] === bills.feeCode);
  885. }
  886. if (matched) {
  887. assignAttr(matched, bills, ['items'], true);
  888. if (bills.items && bills.items.length) {
  889. mergeitems(matched, bills.items);
  890. //mergedBills.push(...mergeDataRecur(fixedBills, [bills]))
  891. }
  892. preBills = matched;
  893. } else {
  894. const nextID = preBills && preBills.NextSiblingID || -1;
  895. mergedBills.push(...mergeDataRecur(fixedBills, [bills]));
  896. bills.NextSiblingID = nextID;
  897. if (preBills) {
  898. preBills.NextSiblingID = bills.ID;
  899. }
  900. preBills = bills;
  901. }
  902. });
  903. }
  904. // 简单地合并: 设置某清单的金额,数据递归插入到某清单的子项
  905. function simpleMerge(flag, src) {
  906. const fixedBills = billsTemplate.find(bills => getFlag(bills) === flag);
  907. if (fixedBills) {
  908. assignAttr(fixedBills, src, ['fees', 'feeCode']);
  909. mergedBills.push(...mergeDataRecur(fixedBills, src.items));
  910. }
  911. }
  912. // 合并大项费用
  913. function mergeWorkSummary(workSummary) {
  914. // 首层数据与清单模板根据费用字典进行匹配,匹配到的则赋值一些属性,匹配不到则将其及其所有子数据插入到模板最末大项费用
  915. workSummary.forEach(summaryBills => {
  916. const matched = roots.find(root => FlagFeeCodeMap[getFlag(root)] === summaryBills.feeCode);
  917. if (matched) {
  918. if (!summaryBills.calcBase) {
  919. summaryBills.calcBase = matched.calcBase;
  920. matched.ignoreValidator = true; // 用了模板的基数,基数无视基数验证
  921. }
  922. assignAttr(matched, summaryBills, ['items'], true);
  923. } else {
  924. mergedBills.push(...mergeDataRecur(null, [summaryBills]));
  925. if (lastRoot) {
  926. lastRoot.NextSiblingID = summaryBills.ID;
  927. lastRoot = summaryBills;
  928. }
  929. }
  930. });
  931. }
  932. // 合并分部分项
  933. function mergeFBFX(fbfxSrc) {
  934. simpleMerge(fixedFlag.SUB_ENGINERRING, fbfxSrc);
  935. }
  936. // 合并措施项目
  937. function mergeCSXM(csxmSrc) {
  938. const fixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.MEASURE);
  939. fixedBills.fees = csxmSrc.fees;
  940. mergeitems(fixedBills, csxmSrc.items);
  941. }
  942. // 合并其他项目
  943. function mergeOther(otherSrc) {
  944. const fixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.OTHER);
  945. fixedBills.fees = otherSrc.fees;
  946. // 合并其他项目费
  947. // SundryCosts其他项目费会包含暂列金额等后续会再次出现的数据,因此合并SundryCosts的数据时,过滤掉一部分数据
  948. const feeCodeFilter = [
  949. FlagFeeCodeMap[fixedFlag.PROVISIONAL], // 暂列金额
  950. FlagFeeCodeMap[fixedFlag.MATERIAL_PROVISIONAL], // 材料暂估
  951. FlagFeeCodeMap[fixedFlag.ENGINEERING_ESITIMATE], // 专业工程暂估
  952. FlagFeeCodeMap[fixedFlag.DAYWORK], // 计日工
  953. FlagFeeCodeMap[fixedFlag.TURN_KEY_CONTRACT], // 总承包服务费
  954. FlagFeeCodeMap[fixedFlag.CLAIM], // 索赔
  955. FlagFeeCodeMap[fixedFlag.VISA], // 现场签证
  956. ];
  957. const filterdBills = filterDataByFeeCodes([otherSrc.sundryCosts], feeCodeFilter);
  958. /**
  959. * 有些源xml文件中,被过滤掉SundryCosts中的子项,相对于Sundry的子项会多一些属性
  960. * 比如:Sundry->SunryCosts->SundryCostsGroup->SundryCostsItem中的材料暂估价,含有QtyFormula属性,但是Sundry->ProvisionalMaterialEquipment中不含有QtyFormula
  961. * 因此,即使后续Sundry的子项会赋值给模板,也要将被过滤掉的子项的属性先赋给模板
  962. */
  963. filterdBills.forEach(filterdItem => {
  964. const matched = billsTemplate.find(templateBills => FlagFeeCodeMap[getFlag(templateBills)] === filterdItem.feeCode);
  965. if (matched) {
  966. assignAttr(matched, filterdItem, ['items'], true); // 不拷贝item属性
  967. matched.ignoreA
  968. }
  969. });
  970. const sundryCostsBills = otherSrc.sundryCosts.items;
  971. mergeitems(fixedBills, sundryCostsBills);
  972. // 合并暂列金额
  973. simpleMerge(fixedFlag.PROVISIONAL, otherSrc.provisional);
  974. // 合并材料暂估,由于材料暂估的子元素是暂估人材机,因此对清单来说,只需处理材料暂估根元素的属性
  975. const zgcFixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.MATERIAL_PROVISIONAL);
  976. assignAttr(zgcFixedBills, otherSrc.ProvisionalMaterialEquipment);
  977. // 合并专业工程暂估价
  978. simpleMerge(fixedFlag.ENGINEERING_ESITIMATE, otherSrc.specialty);
  979. // 合并计日工
  980. const dayWorkFixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.DAYWORK);
  981. assignAttr(dayWorkFixedBills, otherSrc.dayWork, ['fees', 'feeCode']);
  982. mergeitems(dayWorkFixedBills, otherSrc.dayWork.items);
  983. // 合并总承包服务费
  984. simpleMerge(fixedFlag.TURN_KEY_CONTRACT, otherSrc.mainContractor);
  985. // 合并索赔
  986. simpleMerge(fixedFlag.CLAIM, otherSrc.claim);
  987. // 合并现场签证
  988. simpleMerge(fixedFlag.VISA, otherSrc.visa);
  989. }
  990. // 合并税金
  991. function mergeTax(taxSrc) {
  992. const taxFixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.TAX);
  993. if (!taxSrc.calcBase) {
  994. taxSrc.calcBase = taxFixedBills.calcBase;
  995. taxFixedBills.ignoreValidator = true; // 用了模板的基数,基数无视基数验证
  996. } else {
  997. taxFixedBills.ignoreValidator = false;
  998. }
  999. assignAttr(taxFixedBills, taxSrc);
  1000. }
  1001. }
  1002. // 给固定清单设置上费用字典,因为在合并清单的时候,清单模板中可能有一些数据应该有规定的费用字典,但是没有被设置上费用字典。
  1003. function setupFeeCode(billsData) {
  1004. billsData.forEach(bills => {
  1005. if (bills.feeCode) {
  1006. return;
  1007. }
  1008. bills.feeCode = FlagFeeCodeMap[getFlag(bills)] || '';
  1009. })
  1010. }
  1011. // 检查清单是否引用了自身,比如广联达导出文件中 材料保管费基数为CLBGF
  1012. function isCalcBaseCycle(bills) {
  1013. return bills.calcBase.match(new RegExp(`\\b${bills.feeCode}\\b`)); // \b: 匹配前一个字符和后一个字符不全为\w的位置
  1014. }
  1015. // 转换计算基数
  1016. // 1.有子项数据,则清空基数
  1017. // 2.引用的基数造成自身循环,比如分部分项部分引用了QDF
  1018. // 3.费用代号匹配清单基数的代号
  1019. // 4.费用代号匹配不到清单基数的代号,则匹配此费用代号的清单,作为行引用(即ID引用)
  1020. // 5.对应字典里找不到则设置成金额
  1021. function transformCalcBase(billsData) {
  1022. // 费用代号 - 计算基数映射
  1023. const feeCodeFormulaMap = {}
  1024. Object
  1025. .entries(FormulaFeeCodeMap)
  1026. .forEach(([formula, feeCode]) => {
  1027. feeCodeFormulaMap[feeCode] = formula;
  1028. });
  1029. // 费用代号 - ID映射
  1030. const feeCodeIDMap = {};
  1031. billsData.forEach(data => {
  1032. if (data.feeCode) {
  1033. feeCodeIDMap[data.feeCode] = data.ID;
  1034. }
  1035. });
  1036. for (const bills of billsData) {
  1037. if (!bills.calcBase || bills.ignoreValidator) {
  1038. continue;
  1039. }
  1040. const sub = billsData.find(data => data.ParentID === bills.ID);
  1041. // 有子项数据,则清空基数,费率
  1042. if (sub) {
  1043. bills.calcBase = '';
  1044. bills.feeRate = '';
  1045. continue;
  1046. }
  1047. if (typeof bills.calcBase !== 'string') {
  1048. bills.calcBase = String(bills.calcBase);
  1049. }
  1050. // 引用的基数造成自循环,清空基数
  1051. const isCycle = isCalcBaseCycle(bills);
  1052. if (isCycle) {
  1053. bills.calcBase = '';
  1054. continue;
  1055. }
  1056. // 提取基数中的费用代号
  1057. bills.calcBase = bills.calcBase.replace(/\s/g, '');
  1058. const feeCodes = bills.calcBase.split(/[\+\-\*\/]/g);
  1059. // 提取操作符
  1060. const oprs = bills.calcBase.match(/[\+\-\*\/]/g);
  1061. // 转换后的基数
  1062. const newBase = [];
  1063. let illegal = false; //不合法
  1064. for (const feeCode of feeCodes) {
  1065. const formula = feeCodeFormulaMap[feeCode];
  1066. const refID = feeCodeIDMap[feeCode];
  1067. if (formula) { // 匹配到公式
  1068. newBase.push(formula);
  1069. } else if (refID) { // 匹配到行引用
  1070. newBase.push(`@${refID}`) // 转换成ID引用
  1071. } else { // 无法识别
  1072. illegal = true;
  1073. break;
  1074. }
  1075. }
  1076. if (illegal) {
  1077. const fee = getFee(bills.fees, ['common', 'totalFee']);
  1078. const feeRate = bills.feeRate && parseFloat(bills.feeRate) !== 0 ? parseFloat(bills.feeRate) : 0;
  1079. if (fee && parseFloat(fee) !== 0 && feeRate) {
  1080. bills.calcBase = scMathUtil.roundForObj(parseFloat(fee) * 100 / feeRate, 2);
  1081. } else {
  1082. bills.calcBase = fee !== '0' ? fee : '';
  1083. }
  1084. } else {
  1085. let newCalcBase = '';
  1086. for (let i = 0; i < newBase.length; i++) {
  1087. newCalcBase += newBase[i];
  1088. if (oprs && oprs[i]) {
  1089. newCalcBase += oprs[i];
  1090. }
  1091. }
  1092. bills.calcBase = newCalcBase;
  1093. }
  1094. }
  1095. }
  1096. // 转换清单
  1097. function transformBills(tenderData, billsTemplate) {
  1098. const billsData = mergeBills(tenderData, billsTemplate);
  1099. setupFeeCode(billsData);
  1100. transformCalcBase(billsData);
  1101. // 处理综合单价
  1102. // 没有子清单,且没有综合单价,且有综合合价,则综合单价 = 综合合价 / 工程量
  1103. billsData.forEach(bills => {
  1104. const hasChild = billsData.some(data => data.ParentID === bills.ID);
  1105. let unitFee = getFee(bills.fees, ['common', 'unitFee']);
  1106. const totalFee = getFee(bills.fees, ['common', 'totalFee']);
  1107. if (!hasChild && !parseFloat(unitFee) && totalFee && parseFloat(totalFee)) {
  1108. // 不存工程量
  1109. if (!bills.quantity || !parseFloat(bills.quantity)) {
  1110. unitFee = totalFee;
  1111. // 源不存在工程量,没有计算基数、但是却有综合合价,工程量要设置为1
  1112. if (!bills.calcBase) {
  1113. bills.quantity = '1';
  1114. }
  1115. } else {
  1116. // 综合合价的小数位数
  1117. const totalFeeDecimal = totalFee.match(/\.\d+/);
  1118. unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, totalFeeDecimal ? totalFeeDecimal[0] : 0);
  1119. }
  1120. const commonFee = bills.fees.find(fee => fee.fieldName === 'common');
  1121. if (commonFee) {
  1122. commonFee.unitFee = unitFee;
  1123. }
  1124. }
  1125. bills.projectID = tenderData.ID;
  1126. bills.quantityEXP = bills.quantity;
  1127. // TODO 删除items rations feeCode
  1128. });
  1129. return billsData;
  1130. }
  1131. // 转换人材机汇总相关数据(人材机汇总、承包人材料、评标材料、暂估价材料、组成物、单价文件)
  1132. function transformGLJList(tenderData, IDPlaceholder, projectGLJMap) {
  1133. const rst = {
  1134. projectGLJ: [], // 项目人材机
  1135. contractorList: [], // 承包人材料
  1136. bidEvaluationList: [], // 评标材料
  1137. evaluationList: [], // 暂估材料
  1138. unitPrice: [], // 单价文件
  1139. mixRatio: [] // 组成物
  1140. };
  1141. transformGLJSummary();
  1142. transformContractorSummary();
  1143. transformRelatedGLJList(tenderData.bidEvaluationSummary, rst.bidEvaluationList, 'is_eval_material');
  1144. transformEvalSummary();
  1145. return rst;
  1146. // 转换项目人材机、组成物
  1147. function transformGLJSummary() {
  1148. // 项目人材机
  1149. tenderData.gljSummary.forEach(projectGLJ => {
  1150. projectGLJ.project_id = tenderData.ID;
  1151. projectGLJ.id = IDPlaceholder.projectGLJ++;
  1152. projectGLJMap[projectGLJ.code] = projectGLJ;
  1153. });
  1154. tenderData.gljSummary.forEach(projectGLJ => {
  1155. //组成物数据
  1156. projectGLJ.ratios.forEach(ratio => {
  1157. const matched = projectGLJMap[ratio.code];
  1158. ratio.code = matched.code;
  1159. ratio.projectGLJID = projectGLJ.id;
  1160. ratio.id = IDPlaceholder.ratio++;
  1161. ratio.unit_price_file_id = tenderData.property.unitPriceFile.id;
  1162. ratio.unit = matched && matched.unit || '';
  1163. ratio.name = matched && matched.name || '';
  1164. ratio.specs = matched && matched.specs || '';
  1165. ratio.type = matched && matched.type || 1;
  1166. ratio.connect_key = [projectGLJ.code || 'null', projectGLJ.name || 'null', projectGLJ.specs || 'null', projectGLJ.unit || 'null', projectGLJ.type].join('|-|');
  1167. rst.mixRatio.push(ratio);
  1168. });
  1169. rst.projectGLJ.push(projectGLJ);
  1170. // 单价文件数据:
  1171. rst.unitPrice.push(generateUnitPrice(projectGLJ));
  1172. // TODO 删除ratios
  1173. });
  1174. }
  1175. // 转换与项目人材机关联的材料
  1176. function transformRelatedGLJList(list, container, relatedType) {
  1177. list.forEach(glj => {
  1178. glj.ID = uuid.v1();
  1179. glj.projectID = tenderData.ID;
  1180. glj.projectGLJID = -1;
  1181. if (typeof glj.seq === 'undefined') {
  1182. glj.seq = glj.code;
  1183. }
  1184. const projectGLJ = projectGLJMap[glj.code];
  1185. if (projectGLJ) {
  1186. projectGLJ[relatedType] = 1;
  1187. glj.is_related = 1;
  1188. glj.projectGLJID = projectGLJ.id;
  1189. }
  1190. container.push(glj);
  1191. });
  1192. }
  1193. // 转换承包人材料
  1194. function transformContractorSummary() {
  1195. // 由于承包人差额数据和指数数据共用承包人材料表,因此需要合并差额数据和指数数据
  1196. const mergedList = [];
  1197. tenderData.exponentialSummary.forEach(eGLJ => {
  1198. const matched = tenderData.differentiaSummary.find(dGLJ => dGLJ.code === eGLJ.code);
  1199. if (matched) {
  1200. assignAttr(matched, eGLJ, ['varWeight', 'FO', 'FI']);
  1201. } else {
  1202. mergedList.push(eGLJ);
  1203. }
  1204. });
  1205. mergedList.push(...tenderData.differentiaSummary);
  1206. transformRelatedGLJList(mergedList, rst.contractorList, 'is_contractor_material');
  1207. }
  1208. // 转换暂估价材料
  1209. function transformEvalSummary() {
  1210. const evalGLJList = tenderData.gljSummary
  1211. .filter(glj => glj.is_evaluate)
  1212. .map(glj => {
  1213. const evalGLJ = {};
  1214. assignAttr(evalGLJ, glj, [
  1215. 'code', 'name', 'specs', 'unit', 'quantity', 'market_price',
  1216. 'originPlace', 'vender', 'remark'
  1217. ]);
  1218. evalGLJ.seq = evalGLJ.code;
  1219. return evalGLJ;
  1220. });
  1221. transformRelatedGLJList(evalGLJList, rst.evaluationList, 'is_evaluate');
  1222. }
  1223. // 生成单价文件
  1224. function generateUnitPrice(projectGLJ) {
  1225. return {
  1226. projectGLJID: projectGLJ.id, //做个标记,后端查找标准数据后,方便更新组成物数据
  1227. unit_price_file_id: tenderData.property.unitPriceFile.id,
  1228. id: IDPlaceholder.unitPrice++,
  1229. code: projectGLJ.code,
  1230. original_code: projectGLJ.original_code,
  1231. name: projectGLJ.name,
  1232. unit: projectGLJ.unit,
  1233. specs: projectGLJ.specs,
  1234. type: projectGLJ.type,
  1235. short_name: projectGLJ.shortName,
  1236. base_price: projectGLJ.base_price,
  1237. market_price: projectGLJ.market_price
  1238. };
  1239. }
  1240. }
  1241. // 转换定额、定额人材机、定额系数
  1242. // @param {Object} tenderData - 提取的单位工程数据
  1243. // @param {Array} billsData - 转换后的清单数据
  1244. // @param {Object} projectGLJMap - 转换项目人材机时生成的项目人材机编码-数据的映射
  1245. function transformRations(tenderData, billsData, projectGLJMap) {
  1246. const rst = {
  1247. ration: [],
  1248. rationGLJ: [],
  1249. rationCoe: []
  1250. };
  1251. billsData
  1252. .filter(bills => bills.rations && bills.rations.length)
  1253. .forEach(bills => {
  1254. bills.rations.forEach(ration => {
  1255. // TODO 取费专业不知如何取,暂时取单位工程取费专业
  1256. ration.programID = tenderData.property.projectEngineering;
  1257. ration.ID = uuid.v1();
  1258. ration.projectID = tenderData.ID;
  1259. ration.billsItemID = bills.ID;
  1260. ration.contain = getContain(bills, ration);
  1261. rst.ration.push(ration);
  1262. // 定额人材机
  1263. rst.rationGLJ.push(...transformRationGLJs(bills, ration));
  1264. // 定额系数
  1265. rst.rationCoe.push(generateRationCoe(ration));
  1266. // TODO 删除rationGljs
  1267. });
  1268. });
  1269. return rst;
  1270. // 含量:定额工程量/清单工程量
  1271. function getContain(bills, ration) {
  1272. if (!bills.quantity || !ration.quantity) {
  1273. return '0';
  1274. } else {
  1275. const tempQuantity = ration.quantity / bills.quantity;
  1276. return isFinite(tempQuantity) ? scMathUtil.roundForObj(tempQuantity, Decimal.QUANTITY) : '0';
  1277. }
  1278. }
  1279. // 转换定额人材机
  1280. function transformRationGLJs(bills, ration) {
  1281. return ration.rationGLJs.map(rationGLJ => {
  1282. const matched = projectGLJMap[rationGLJ.code];
  1283. if (matched) {
  1284. rationGLJ.projectGLJID = matched.id;
  1285. rationGLJ.code = matched.code;
  1286. rationGLJ.type = matched.type;
  1287. rationGLJ.shortName = matched.shortName;
  1288. rationGLJ.name = matched.name;
  1289. rationGLJ.original_code = matched.original_code;
  1290. rationGLJ.unit = matched.unit;
  1291. rationGLJ.specs = matched.specs;
  1292. }
  1293. rationGLJ.ID = uuid.v1();
  1294. rationGLJ.projectID = tenderData.ID;
  1295. rationGLJ.billsItemID = bills.ID;
  1296. rationGLJ.rationID = ration.ID;
  1297. rationGLJ.rationCode = ration.code; // 暂时跟定额编码关联,后端好匹配标准数据
  1298. rationGLJ.rationItemQuantity = rationGLJ.quantity; // 定额消耗,暂时取消耗量,需要后端匹配标准数据后更新
  1299. return rationGLJ;
  1300. });
  1301. }
  1302. // 生成定额系数(项目数据处理的方法很有可能无法共用,因此不把重庆的方法抽离了)
  1303. function generateRationCoe(ration) {
  1304. return {
  1305. projectID: ration.projectID,
  1306. rationID: ration.ID,
  1307. coeID: -1,
  1308. ID: uuid.v1(),
  1309. seq: 1, // 以前排序有的字段,暂时没什么用,不过还是赋上一个值
  1310. name: '自定义系数',
  1311. content: '人工×1,材料×1,机械×1,主材×1,设备×1',
  1312. coes: [
  1313. { amount: 1, operator: '*', gljCode: null, coeType: '定额' },
  1314. { amount: 1, operator: '*', gljCode: null, coeType: '人工' },
  1315. { amount: 1, operator: '*', gljCode: null, coeType: '材料' },
  1316. { amount: 1, operator: '*', gljCode: null, coeType: '机械' },
  1317. { amount: 1, operator: '*', gljCode: null, coeType: '主材' },
  1318. { amount: 1, operator: '*', gljCode: null, coeType: '设备' },
  1319. ],
  1320. option_list: []
  1321. }
  1322. }
  1323. }
  1324. // 删除一些无用属性,减少通信数据量
  1325. function clean(detailData) {
  1326. const {
  1327. bills,
  1328. ration,
  1329. projectGLJ
  1330. } = detailData;
  1331. bills.forEach(item => delete item.items && delete item.rations && delete item.feeCode);
  1332. ration.forEach(item => delete item.rationGLJs);
  1333. projectGLJ.forEach(item => delete item.ratios);
  1334. }
  1335. // 需要给清单、定额价格字段赋上调价数据,不然打开项目后会被重算: project_view.js -> loadProjectData方法内
  1336. function setupTenderFees(detailData) {
  1337. const { bills, ration } = detailData;
  1338. [...bills, ...ration].forEach(item => {
  1339. if (item.fees && item.fees.length) {
  1340. item.fees.forEach(feeItem => {
  1341. if (commonUtil.isDef(feeItem.unitFee)) {
  1342. feeItem.tenderUnitFee = feeItem.unitFee;
  1343. }
  1344. if (commonUtil.isDef(feeItem.totalFee)) {
  1345. feeItem.tenderTotalFee = feeItem.totalFee;
  1346. }
  1347. })
  1348. }
  1349. });
  1350. }
  1351. // 转换详细的项目数据,清单、定额、定额人材机、项目人材机、单价文件等
  1352. function transformDetail(tenderData, IDPlaceholder, billsTemplate) {
  1353. const bills = transformBills(tenderData, billsTemplate);
  1354. // 转换定额的处理依赖转换后的项目人材机数据,因此需要先转换项目人材机相关的数据
  1355. const projectGLJMap = {};
  1356. const relatedljGLJData = transformGLJList(tenderData, IDPlaceholder, projectGLJMap);
  1357. const relatedRationData = transformRations(tenderData, bills, projectGLJMap);
  1358. const detailData = {
  1359. bills,
  1360. ...relatedRationData,
  1361. ...relatedljGLJData
  1362. };
  1363. clean(detailData);
  1364. setupTenderFees(detailData);
  1365. console.log(`detailData`);
  1366. console.log(detailData);
  1367. return detailData;
  1368. }
  1369. /**
  1370. * 解压cos、zip文件
  1371. * @param {File} file - 上传的文件
  1372. * @return {Object} 解压出来的xml文件名称与xml文件文本内容映射
  1373. */
  1374. async function unzipFile(file) {
  1375. const jsZip = new JSZip();
  1376. const zip = await jsZip.loadAsync(file);
  1377. const map = {};
  1378. for (const fileName in zip.files) {
  1379. // 将二进制数据转换成字符串
  1380. map[fileName] = await jsZip.file(fileName).async('string');
  1381. }
  1382. return map;
  1383. }
  1384. //从xml文件中提取数据
  1385. async function extractData(file, escape = false) {
  1386. const fileMap = await unzipFile(file);
  1387. const projectXML = fileMap['Project.xml'];
  1388. if (!projectXML) {
  1389. throw '无有效数据';
  1390. }
  1391. const xmlObjMap = {};
  1392. for (const fileName in fileMap) {
  1393. // x2js转换xml使用了DomParser接口,会将一些字符实体进行转义。若不想被自动转义,则需要调用escapeXMLEntity
  1394. const xmlStr = escape ? util.escapeXMLEntity(fileMap[fileName]) : fileMap[fileName];
  1395. //将xml格式良好的字符串转换成对象
  1396. const x2js = new X2JS();
  1397. let xmlObj = x2js.xml_str2json(xmlStr);
  1398. xmlObj = JSON.parse(util.restoreXMLEntity(JSON.stringify(xmlObj)));
  1399. if (!xmlObj) {
  1400. throw '无有效数据。';
  1401. }
  1402. xmlObjMap[fileName] = xmlObj;
  1403. }
  1404. //提取数据
  1405. return extractProject(xmlObjMap);
  1406. };
  1407. // 接受上传的文件类型(不同的省份可以上传的文件不同)
  1408. const accept = ['.zip', '.cos'];
  1409. return {
  1410. accept,
  1411. extractData,
  1412. transformData,
  1413. }
  1414. })();