guangdong_2018_import.js 74 KB

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