guangdong_2018_import.js 73 KB

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