guangdong_2018_import.js 75 KB

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