guangdong_2018_import.js 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  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. let 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. // 特殊处理措施项目的费用代号(广联达这两条数据没有导出费用代号,跟我们的清单模板不匹配,从而导致从合并变成了新增),详看mergeBills中的mergeitems放啊
  317. if (type === billType.BILL) {
  318. if (item.code === 'AQFHWMSG') {
  319. item.feeCode = FlagFeeCodeMap[fixedFlag.SAFETY_CONSTRUCTION];
  320. } else if (item.code === 'QTCSF') {
  321. item.feeCode = FlagFeeCodeMap[fixedFlag.OTHER_MEASURE_FEE];
  322. }
  323. }
  324. if (importFileKind === FileKind.tender) {
  325. const summaryFees = getFeesFromBasicCost(divisionalSrc);
  326. const fees = [{ fieldName: 'common', totalFee: getValue(divisionalSrc, ['_Total']), unitFee: getValue(divisionalSrc, ['_TechnicalAndEconomicIndex']) }];
  327. item.fees = mergeFees(fees, summaryFees);
  328. }
  329. return item;
  330. }
  331. // 提取分项清单数据(包含定额、定额人材机)
  332. function extractWorkElement(workElementSrc, type) {
  333. const itemCharacterText = getItemCharacterText(getValue(workElementSrc, ['_Attr']));
  334. const bills = {
  335. type: type, // 清单类型
  336. code: getValue(workElementSrc, ['_Number']),
  337. name: getValue(workElementSrc, ['_Name']),
  338. itemCharacterText,
  339. itemCharacter: getItemCharacter(itemCharacterText),
  340. jocContentText: getValue(workElementSrc, ['_WorkContent']),
  341. jobContent: getJobContent(workElementSrc),
  342. unit: getValue(workElementSrc, ['_Unit']),
  343. quantity: getValue(workElementSrc, ['_Quantity']),
  344. mainBills: getBool(getValue(workElementSrc, ['_Major'])),
  345. feeCode: getValue(workElementSrc, ['_Code']),
  346. remark: getValue(workElementSrc, ['_Remark']),
  347. quantityDetails: extractQuantityDetails(workElementSrc),
  348. rations: extractRations(workElementSrc)
  349. };
  350. if (type === billType.BILL) {
  351. // 分项不需要基数、费率
  352. bills.calcBase = getValue(workElementSrc, ['_QtyFormula']);
  353. const feeRate = getValue(workElementSrc, ['_Rate']);
  354. bills.feeRate = +feeRate !== 100 && feeRate || undefined;
  355. }
  356. // 投标和控制价,需要导入最高限价
  357. if ([FileKind.tender, FileKind.control].includes(importFileKind)) {
  358. const maxPrice = getValue(workElementSrc, ['_PriceHigh']);
  359. //不为0才输出
  360. if (maxPrice && maxPrice !== '0') {
  361. bills.outPutMaxPrice = true;
  362. bills.maxPrice = maxPrice;
  363. }
  364. if (importFileKind === FileKind.tender) {
  365. const summaryFees = getFeesFromBasicCost(workElementSrc);
  366. const fees = [
  367. { fieldName: 'common', unitFee: getValue(workElementSrc, ['_Price']), totalFee: getValue(workElementSrc, ['_Total']) },
  368. { fieldName: 'equipment', unitFee: getValue(workElementSrc, ['_EquipmentPrice']) },
  369. ];
  370. bills.fees = mergeFees(fees, summaryFees);
  371. }
  372. }
  373. return bills;
  374. // 获取项目特征文本
  375. function getItemCharacterText(attr) {
  376. // 去掉除换行符以外的空白符
  377. const newLine = '{newLine}';
  378. attr = attr
  379. .replace(/[\r\n]/g, newLine)
  380. .replace(/\s/g, '')
  381. .replace(new RegExp(newLine, 'g'), '\n');
  382. const matchStrs = ['
', ';'];
  383. const matchStr = matchStrs.find(str => attr.includes(str));
  384. if (matchStr) {
  385. attr = attr.replace(new RegExp(matchStr, 'g'), '\n');
  386. }
  387. return attr;
  388. }
  389. // 获取清单项目特征窗口数据
  390. function getItemCharacter(itemText) {
  391. const itemsList = itemText.split('\n');
  392. const reg = /\d+\.([^:]+)[::](.*)?/;
  393. const itemCharacter = [];
  394. let idx = 1;
  395. itemsList.forEach(str => {
  396. str = str.replace(/\s/g, '');
  397. const result = reg.exec(str);
  398. if (!result) {
  399. return;
  400. }
  401. const name = result[1];
  402. const value = result[2] || '';
  403. const eigenvalue = value ? [{ value, isSelected: true }] : [];
  404. itemCharacter.push({
  405. character: name,
  406. isChecked: true,
  407. serialNo: idx++,
  408. eigenvalue
  409. });
  410. });
  411. return itemCharacter;
  412. }
  413. // 获取清单工作内容窗口数据
  414. function getJobContent(workElementSrc) {
  415. return arrayValue(workElementSrc, ['WorkContent']).map((workContent, idx) => ({
  416. content: getValue(workContent, ['_Name']),
  417. serialNo: idx + 1,
  418. isChecked: true
  419. }));
  420. }
  421. }
  422. // 提取工程量明细(清单、定额底下都可能会有)
  423. function extractQuantityDetails(src) {
  424. return arrayValue(src, ['ExpressElement']).map(itemSrc => ({
  425. seq: getValue(itemSrc, ['_OrderNumber']),
  426. regex: getValue(itemSrc, ['_Express']),
  427. result: getValue(itemSrc, ['_Quantity']),
  428. isSummation: summationMap[getValue(itemSrc, ['_Kind'])]
  429. }));
  430. }
  431. // 提取定额
  432. function extractRations(workElementSrc) {
  433. if (importFileKind !== FileKind.tender) {
  434. return [];
  435. }
  436. // 正常情况下定额肯定是在WorkContent内的,但是也做定额不在WorkContent内的处理(外层定额)
  437. const rations = [];
  438. let serialNo = 1;
  439. const workContents = arrayValue(workElementSrc, ['WorkContent']);
  440. workContents.forEach(workContent => {
  441. const innerRationsSrc = arrayValue(workContent, ['Norm']);
  442. const jobContentText = getValue(workContent, ['_Name']);
  443. const innerRations = innerRationsSrc.map(rationSrc => extractRation(rationSrc, jobContentText));
  444. rations.push(...innerRations);
  445. });
  446. const outerRationsSrc = arrayValue(workElementSrc, ['Norm']);
  447. const outerRations = outerRationsSrc.map(rationSrc => extractRation(rationSrc, ''));
  448. rations.push(...outerRations);
  449. return rations;
  450. // 获取类型
  451. function getType(rationSrc) {
  452. const overHeightMap = {
  453. '1': true,
  454. '2': false
  455. };
  456. const isOverHeight = overHeightMap[getValue(rationSrc, ['EfficiencyKind'])];
  457. if (isOverHeight) {
  458. return rationType.overHeight;
  459. }
  460. const itemIncreaseMap = {
  461. '1': true,
  462. '2': false
  463. };
  464. const isItemIncrease = itemIncreaseMap[getValue(rationSrc, ['IncFeeKind'])];
  465. if (isItemIncrease) {
  466. return rationType.itemIncrease;
  467. }
  468. return rationType.ration;
  469. }
  470. // 从定额的计算程序提取价格
  471. function getFeesFromCalculationOfItem(rationSrc) {
  472. const calculationOfItems = arrayValue(rationSrc, ['UnitPriceCalculationOfItem']);
  473. const fees = [];
  474. const codeFiedNameMap = {
  475. 'ZJF': 'direct',
  476. 'RGF': 'labour',
  477. 'CLF': 'material',
  478. 'JXF': 'machine',
  479. 'ZCF': 'mainMaterial',
  480. 'SBF': 'equipment',
  481. 'LR': 'profit',
  482. //'DJ': 'common',定额本身已经有单价这个字段,不需要从这读取
  483. };
  484. calculationOfItems.forEach(item => {
  485. const totalFee = +getValue(item, ['_Total']);
  486. const fieldName = codeFiedNameMap[getValue(item, ['_Code'])];
  487. if (totalFee && fieldName) {
  488. fees.push({ fieldName, totalFee });
  489. }
  490. });
  491. return fees;
  492. }
  493. // 提取定额人材机
  494. function extractRationGLJs(rationSrc) {
  495. const rationGLJsSrc = arrayValue(rationSrc, ['LabourMaterialsEquipmentsMachinesElement']);
  496. return rationGLJsSrc.map(src => ({
  497. code: getValue(src, ['_Number']),
  498. quantity: getValue(src, ['_Quantity'])
  499. }));
  500. }
  501. // TODO 目前无法确定定额的取费专业programID,暂时用专业类别Specialty
  502. function extractRation(rationSrc, jobContentText) {
  503. const ration = {
  504. serialNo: serialNo++,
  505. code: getValue(rationSrc, ['_Number']),
  506. name: getValue(rationSrc, ['_Name']),
  507. unit: getValue(rationSrc, ['_Unit']),
  508. quantity: getValue(rationSrc, ['_Quantity']),
  509. type: getType(rationSrc),
  510. programID: getValue(rationSrc, ['_Specialty']),
  511. libCode: getValue(rationSrc, ['_NormIdentity']),
  512. jobContentText,
  513. remark: getValue(rationSrc, ['_Remark'])
  514. };
  515. const fees = [{ fieldName: 'common', unitFee: getValue(rationSrc, ['_Price']), totalFee: getValue(rationSrc, ['_Total']) }]
  516. const feesFromCalcItem = getFeesFromCalculationOfItem(rationSrc);
  517. ration.fees = mergeFees(fees, feesFromCalcItem);
  518. ration.rationGLJs = extractRationGLJs(rationSrc);
  519. ration.quantityDetails = extractQuantityDetails(rationSrc);
  520. return ration;
  521. }
  522. }
  523. // 提取措施项目
  524. /* function extractCSXM(tenderSrc) {
  525. const csxmSrc = getValue(tenderSrc, ['Preliminaries']);
  526. const fields = [['DivisionalWorks'], ['WorkElement']];
  527. const fees = getFeesFromBasicCost(csxmSrc); // 措施项目的汇总价
  528. const items = getItemsRecur(csxmSrc, fields, (itemSrc, curField) => {
  529. if (curField[0] === fields[0][0]) {
  530. return extractDivisionalWorks(itemSrc, billType.BILL);
  531. } else {
  532. return extractWorkElement(itemSrc, billType.BILL);
  533. }
  534. });
  535. return {
  536. fees,
  537. items
  538. };
  539. } */
  540. function extractCSXM(tenderSrc) {
  541. const csxmSrc = getValue(tenderSrc, ['Preliminaries']);
  542. const fields = [['DivisionalWorks'], ['WorkElement']];
  543. const fees = getFeesFromBasicCost(csxmSrc); // 措施项目的汇总价
  544. const items = extractItemsRecur(csxmSrc, fields, (itemSrc, curField) => {
  545. if (curField[0] === fields[0][0]) {
  546. return extractDivisionalWorks(itemSrc, billType.BILL);
  547. } else {
  548. return extractWorkElement(itemSrc, billType.BILL);
  549. }
  550. });
  551. return {
  552. fees,
  553. items
  554. };
  555. }
  556. // 提取其他项目
  557. function extractOther(tenderSrc) {
  558. const sundry = getValue(tenderSrc, ['Sundry']);
  559. // SundryCosts 其他项目 ,对于我们软件是其他项目下完整数据,但是广联达的并不是,因此需要Sundry的其他节点来补充这份数据
  560. const sundryCosts = getValue(sundry, ['SundryCosts']);
  561. // 其他项目汇总费用
  562. const sundryFees = [{ fieldName: 'common', totalFee: getValue(sundryCosts, ['_Total']) }];
  563. const provisionalMaterialEquipment = getValue(sundry, ['ProvisionalMaterialEquipment']);
  564. return {
  565. fees: importFileKind === FileKind.tender ? sundryFees : [],
  566. sundryCosts: extractData(sundry, 'SundryCosts', [['SundryCostsGroup'], ['SundryCostsItem']]),
  567. provisional: extractData(sundry, 'ProvisionalSums', [['ProvisionalSumsGroup'], ['ProvisionalSumsItem']]),
  568. ProvisionalMaterialEquipment: {
  569. name: getValue(provisionalMaterialEquipment, ['_Name']),
  570. feeCode: getValue(provisionalMaterialEquipment, ['_Code']),
  571. remark: getValue(provisionalMaterialEquipment, ['_Remark']),
  572. fees: [{ fieldName: 'common', totalFee: getValue(provisionalMaterialEquipment, ['_Total']) }],
  573. },
  574. specialty: extractData(sundry, 'SpecialtyProvisionalPrice', [['SpecialtyProvisionalPriceGroup'], ['SpecialtyProvisionalPriceItem']],
  575. { engineeringContent: ['_Content'] }, { engineeringContent: ['_Content'] }),
  576. dayWork: extractData(sundry, 'DayWorkRate', [['DayWorkRateGroup'], ['DayWorkRateItem']]),
  577. mainContractor: extractData(sundry, 'MainContractorAttendance', [['MainContractorAttendanceGroup'], ['MainContractorAttendanceItem']], { serviceContent: ['_Content'] }, { serviceContent: ['_Content'] }),
  578. claim: extractData(sundry, 'ClaimsCost', [['ClaimsCostGroup'], ['ClaimsCostItem']], { claimVisa: ['_Reason'] }, { claimVisa: ['_Reason'] }),
  579. visa: extractData(sundry, 'SiteInstructionCost', [['SiteInstructionCostGroup'], ['SiteInstructionCostItem']], { claimVisa: ['_Reason'] }, { claimVisa: ['_Reason'] }),
  580. };
  581. // 提取标题和明细
  582. function extractGroupOrItem(itemSrc, isGroup = true, extendAttrs = null, field) {
  583. let source;
  584. if (isGroup) {
  585. source = {
  586. name: getValue(itemSrc, ['_Name']),
  587. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(itemSrc, ['_Total']) }] : [],
  588. feeCode: getValue(itemSrc, ['_Code']),
  589. remark: getValue(itemSrc, ['_Remark'])
  590. };
  591. } else {
  592. const feeRate = getValue(itemSrc, ['_Rate']);
  593. source = {
  594. name: getValue(itemSrc, ['_Name']),
  595. unit: getValue(itemSrc, ['_Unit']),
  596. calcBase: getValue(itemSrc, ['_QtyFormula']),
  597. feeRate: +feeRate !== 100 && feeRate || undefined,
  598. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', unitFee: getValue(itemSrc, ['_Price']), totalFee: getValue(itemSrc, ['_Total']) }] : [],
  599. feeCode: getValue(itemSrc, ['_Code']),
  600. remark: getValue(itemSrc, ['_Remark'])
  601. };
  602. if (field !== 'MainContractorAttendanceItem') { // MainContractorAttendanceItem的quantity比较特殊,是清单基数计算后的值而不是工程量,不需要导入
  603. source.quantity = getValue(itemSrc, ['_Quantity']);
  604. }
  605. }
  606. return extendAttrs ? Object.assign(source, extendAttrs) : source;
  607. }
  608. // 提取数据
  609. function extractData(sundry, srcName, fields, groupExtendMap, itemExtendMap) {
  610. const src = getValue(sundry, [srcName]);
  611. return {
  612. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(src, ['_Total']) }] : [],
  613. feeCode: getValue(src, ['_Code']),
  614. items: extractItemsRecur(src, fields, (itemSrc, curField) => {
  615. const groupExtend = groupExtendMap
  616. ? Object.keys(groupExtendMap).reduce((acc, key) => {
  617. acc[key] = getValue(itemSrc, groupExtendMap[key]);
  618. return acc;
  619. }, {})
  620. : null;
  621. const itemExtend = itemExtendMap
  622. ? Object.keys(itemExtendMap).reduce((acc, key) => {
  623. acc[key] = getValue(itemSrc, itemExtendMap[key]);
  624. return acc;
  625. }, {})
  626. : null;
  627. return curField[0] === fields[0][0]
  628. ? extractGroupOrItem(itemSrc, true, groupExtend, curField[0])
  629. : extractGroupOrItem(itemSrc, false, itemExtend, curField[0]);
  630. })
  631. };
  632. }
  633. }
  634. // 提取税金
  635. function extractTax(tenderSrc) {
  636. const taxSrc = getValue(tenderSrc, ['Tax']);
  637. const itemsSrc = arrayValue(taxSrc, ['TaxItem']);
  638. return {
  639. ...extractTaxItem(taxSrc),
  640. items: itemsSrc.map(extractTaxItem)
  641. };
  642. function extractTaxItem(src) {
  643. const feeRate = getValue(src, ['_Rate']);
  644. return {
  645. name: getValue(src, ['_Name']),
  646. calcBase: getValue(src, ['_QtyFormula']),
  647. feeRate: +feeRate !== 100 && feeRate || undefined,
  648. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(src, ['_Total']) }] : [],
  649. feeCode: getValue(src, ['_Code']),
  650. remark: getValue(src, ['_Remark'])
  651. };
  652. }
  653. }
  654. // 供料方式
  655. const Provider = {
  656. '1': commonConstants.supplyType.ZXCG,
  657. '2': commonConstants.supplyType.BFJG,
  658. '3': commonConstants.supplyType.WQJG
  659. };
  660. // 提取人材机汇总相关(人材机汇总表、承包材料表)
  661. function extractGLJSummary(tenderSrc) {
  662. const initData = { gljSummary: [], differentiaSummary: [], exponentialSummary: [] };
  663. if (importFileKind !== FileKind.tender) {
  664. return initData;
  665. }
  666. const taxType = getValue(tenderSrc, ['_TaxModel']); // 计税方式
  667. const gljListSrc = arrayValue(tenderSrc, ['LabourMaterialsEquipmentsMachinesSummary']);
  668. return gljListSrc.reduce((acc, gljSrc) => {
  669. acc.gljSummary.push(extractGLJ(gljSrc));
  670. const differentiaGLJ = extractDifferentiaGLJ(gljSrc);
  671. if (differentiaGLJ) {
  672. acc.differentiaSummary.push(differentiaGLJ);
  673. }
  674. const exponentialGLJ = extractExponentialGLJ(gljSrc);
  675. if (exponentialGLJ) {
  676. acc.exponentialSummary.push(exponentialGLJ);
  677. }
  678. return acc;
  679. }, initData);
  680. // 获取原始编码
  681. function getOriginalCode(code) {
  682. //编码后面有-\d+的形式,去掉-\d+取前面的字符串作为原始代码
  683. return code.replace(/(.*)-\d+$/, '$1');
  684. }
  685. // TODO (不靠谱) 获取人材机类型数据
  686. // 导入的源文件没有细化区分人材机类型,这里只是暂时大概给个值。后续会在后端与标准人材机进行配对。也因此无法准确处理补充人材机
  687. function getTypeData(gljSrc) {
  688. const concrete = getBool(getValue(gljSrc, ['_Concrete']));
  689. if (concrete) {
  690. return { type: 205, shorName: '商砼' };
  691. }
  692. const type = getValue(gljSrc, ['_Kind']);
  693. switch (type) {
  694. case '1':
  695. return { type: 1, shorName: '人' };
  696. case '4':
  697. return { type: 4, shortName: '主' };
  698. case '5':
  699. return { type: 5, shortName: '设' }
  700. case '6':
  701. return { type: 202, shorName: '砼' };
  702. case '3':
  703. case '7':
  704. return { type: 301, shorName: '机' };
  705. case '15':
  706. return { type: 6, shortName: '管' };
  707. default:
  708. return { type: 201, shortName: '材' };
  709. }
  710. }
  711. // 根据计税方式获取价格,一般计税对应不含税,简易对应含税
  712. function getPriceByTaxType(gljSrc, taxType) {
  713. return +taxType === TaxType.NORMAL
  714. ? {
  715. base_price: getValue(gljSrc, ['_NoTaxOrgPrice']),
  716. market_price: getValue(gljSrc, ['_NoTaxPrice'])
  717. }
  718. : {
  719. base_price: getValue(gljSrc, ['_TaxOrgPrice']),
  720. market_price: getValue(gljSrc, ['_TaxPrice'])
  721. };
  722. }
  723. // 提取组成物
  724. function extractRatios(gljSrc) {
  725. const ratiosSrc = arrayValue(gljSrc, ['LabourMaterialsEquipmentsMachinesElement']);
  726. countData.ratioCount += ratiosSrc.length;
  727. return ratiosSrc.map(src => ({
  728. code: getValue(src, ['_Number']),
  729. consumption: getValue(src, ['_Quantity'])
  730. }));
  731. }
  732. // 提取项目人材机
  733. function extractGLJ(gljSrc) {
  734. countData.projectGLJCount++;
  735. const code = getValue(gljSrc, ['_Number']);
  736. return {
  737. code,
  738. original_code: getOriginalCode(code),
  739. name: getValue(gljSrc, ['_Name']),
  740. specs: getValue(gljSrc, ['_Specification']),
  741. unit: getValue(gljSrc, ['_Unit']),
  742. ...getTypeData(gljSrc),
  743. ...getPriceByTaxType(gljSrc, taxType), // 软件中项目人材机是没有价格的,只是为了后续处理单价文件
  744. is_main_material: getBool(getValue(gljSrc, ['_MainMaterial'])),
  745. is_evaluate: getBool(getValue(gljSrc, ['_ProvisionalMaterial'])),
  746. supply: Provider[getValue(gljSrc, ['_Provider'])],
  747. delivery: getValue(gljSrc, ['_Delivery']),
  748. delivery_address: getValue(gljSrc, ['_Location']),
  749. originPlace: getValue(gljSrc, ['_ProducingArea']),
  750. vender: getValue(gljSrc, ['_Supplier']),
  751. qualityGrace: getValue(gljSrc, ['_Character']),
  752. remark: getValue(gljSrc, ['_Remark']),
  753. ratios: extractRatios(gljSrc)
  754. };
  755. }
  756. // 提取造价信息差额调整法
  757. function extractDifferentiaGLJ(gljSrc) {
  758. // 风险系数或者基准单价有值,才算一条差额数据
  759. const riskCoe = getValue(gljSrc, ['_ProviderRate']);
  760. const standardPrice = getValue(gljSrc, ['_ProviderBase']);
  761. if ((riskCoe && riskCoe !== '0') || (standardPrice && standardPrice !== '0')) {
  762. return {
  763. code: getValue(gljSrc, ['_Number']),
  764. name: getValue(gljSrc, ['_Name']),
  765. specs: getValue(gljSrc, ['_Specification']),
  766. unit: getValue(gljSrc, ['_Unit']),
  767. quantity: getValue(gljSrc, ['_Quantity']),
  768. riskCoe,
  769. standardPrice,
  770. market_price: getPriceByTaxType(gljSrc, taxType).market_price,
  771. remark: getValue(gljSrc, ['_Remark']),
  772. };
  773. }
  774. return null;
  775. }
  776. // 提取价格指数调整法
  777. function extractExponentialGLJ(gljSrc) {
  778. // 变值权重或基本、现行价格指数有值,才算一条指数数据
  779. const varWeight = getValue(gljSrc, ['_Weight']);
  780. const FO = getValue(gljSrc, ['_BasicPrice']);
  781. const FI = getValue(gljSrc, ['_CurrentPrice']);
  782. if ((varWeight && varWeight !== '0') || (FO && FO !== '0') || (FI && FI !== '0')) {
  783. return {
  784. code: getValue(gljSrc, ['_Number']),
  785. name: getValue(gljSrc, ['_Name']),
  786. specs: getValue(gljSrc, ['_Specification']),
  787. varWeight: varWeight,
  788. FO: FO,
  789. FI: FI,
  790. remark: getValue(gljSrc, ['_Remark'])
  791. };
  792. }
  793. return null;
  794. }
  795. }
  796. // 提取评标材料
  797. function extractBidEvaluationSummary(tenderSrc) {
  798. if (importFileKind !== FileKind.tender) {
  799. return [];
  800. }
  801. const srcList = arrayValue(tenderSrc, ['BidEvaluationMainMaterial']);
  802. return srcList.map(gljSrc => ({
  803. seq: getValue(gljSrc, ['_Code']),
  804. code: getValue(gljSrc, ['_Number']),
  805. name: getValue(gljSrc, ['_Name']),
  806. specs: getValue(gljSrc, ['_Specification']),
  807. unit: getValue(gljSrc, ['_Unit']),
  808. quantity: getValue(gljSrc, ['_Quantity']),
  809. market_price: getValue(gljSrc, ['_Price']),
  810. originPlace: getValue(gljSrc, ['_ProducingArea']),
  811. vender: getValue(gljSrc, ['_Supplier']),
  812. remark: getValue(gljSrc, ['_Remark'])
  813. }));
  814. }
  815. /*
  816. * 转换从xml提取的数据,转换成软件所需的数据结构
  817. *
  818. */
  819. async function transformData(extractedData) {
  820. const IDPlaceholder = await ajaxPost('/pm/import/getProjectPlaceholder', countData);
  821. extractedData.ID = IDPlaceholder.project++;
  822. // 最终上传到服务器的转换后的数据
  823. const transformedData = {
  824. ID: extractedData.ID,
  825. ParentID: extractedData.ParentID,
  826. NextSiblingID: extractedData.NextSiblingID,
  827. preID: extractedData.preID,
  828. name: extractedData.name,
  829. basicInformation: extractedData.basicInformation,
  830. projType: extractedData.projType,
  831. property: extractedData.property,
  832. shareInfo: [],
  833. engs: []
  834. };
  835. // 所有的清单模板库ID
  836. const allTemplateLibIDs = [];
  837. extractedData.engs.forEach(eng => {
  838. eng.tenders.forEach(tender => {
  839. let templateLibID = tender.property.templateLibID;
  840. if (!allTemplateLibIDs.includes(templateLibID)) {
  841. allTemplateLibIDs.push(templateLibID);
  842. }
  843. });
  844. });
  845. // 模板映射:{[templateLibID]: data}
  846. const templateMapping = await ajaxPost('/template/bills/api/getNeedfulTemplate', { allTemplateLibIDs });
  847. for (let i = 0; i < extractedData.engs.length; i++) {
  848. const curEng = extractedData.engs[i];
  849. const preEng = transformedData.engs[i - 1];
  850. curEng.ID = IDPlaceholder.project++;
  851. curEng.ParentID = extractedData.ID;
  852. curEng.NextSiblingID = -1;
  853. if (preEng) {
  854. preEng.NextSiblingID = curEng.ID;
  855. }
  856. const engData = {
  857. ID: curEng.ID,
  858. ParentID: curEng.ParentID,
  859. NextSiblingID: curEng.NextSiblingID,
  860. code: curEng.code,
  861. name: curEng.name,
  862. projType: curEng.projType,
  863. shareInfo: [],
  864. tenders: []
  865. };
  866. transformedData.engs.push(engData);
  867. for (let j = 0; j < curEng.tenders.length; j++) {
  868. const curTender = curEng.tenders[j];
  869. const preTender = engData.tenders[j - 1];
  870. curTender.ID = IDPlaceholder.project++;
  871. curTender.ParentID = curEng.ID;
  872. curTender.NextSiblingID = -1;
  873. curTender.property.unitPriceFile.id = IDPlaceholder.unitPriceFile++;
  874. if (preTender) {
  875. preTender.tender.NextSiblingID = curTender.ID;
  876. }
  877. // 项目清单模板(后台清单模板中提取含有固定类别的数据)
  878. const billsTemplate = _.cloneDeep(templateMapping[curTender.property.templateLibID]);
  879. // 重设模板树结构数据
  880. BILLS_UTIL.resetTreeData(billsTemplate, uuid.v1);
  881. console.log(billsTemplate);
  882. const tenderData = transformTender(curTender, IDPlaceholder, billsTemplate);
  883. tenderData.tender.property.rootProjectID = transformedData.ID;
  884. engData.tenders.push(tenderData);
  885. }
  886. }
  887. console.log(`transformedData`);
  888. console.log(transformedData);
  889. return transformedData;
  890. }
  891. // 获取承包人材料类型
  892. function getAdjustType(tenderData) {
  893. if (tenderData.differentiaSummary.length) {
  894. return AdjustType.info;
  895. } else if (tenderData.exponentialSummary.length) {
  896. return AdjustType.coe;
  897. } else {
  898. return AdjustType.info;
  899. }
  900. }
  901. // 获取当前文件
  902. // 转换单位工程的数据(直接可插入数据库的数据),返回{tender: {}, bills: [], ration: [], rationGLJ: [], projectGLJ: [], unitPrice: [], mixRatio: []}
  903. function transformTender(tenderData, IDPlaceholder, billsTemplate) {
  904. const detailData = transformDetail(tenderData, IDPlaceholder, billsTemplate);
  905. // 提取需要插入的单位工程数据
  906. const transformedTender = {
  907. ID: tenderData.ID,
  908. ParentID: tenderData.ParentID,
  909. NextSiblingID: tenderData.NextSiblingID,
  910. code: tenderData.code,
  911. name: tenderData.name,
  912. projType: tenderData.projType,
  913. property: tenderData.property,
  914. projectFeature: tenderData.projectFeature,
  915. engineering: tenderData.engineering,
  916. defaultRationLib: tenderData.defaultRationLib,
  917. rationLibIDs: tenderData.rationLibIDs,
  918. gljLibIDs: tenderData.gljLibIDs,
  919. shareInfo: []
  920. };
  921. transformedTender.property.compilationIllustration = tenderData.compilationIllustration;
  922. transformedTender.property.gljAdjustType = getAdjustType(tenderData);
  923. transformedTender.property.decimal = tenderPropertyDecimal;
  924. transformedTender.property.billsQuantityDecimalValue = tenderPropertyBillsQuantityDecimal;
  925. detailData.tender = transformedTender;
  926. return detailData;
  927. }
  928. // 过滤掉相关费用代号的数据(递归地)
  929. // 返回被过滤掉的数据
  930. function filterDataByFeeCodes(billsData, feeCodes) {
  931. const filterd = [];
  932. billsData.forEach(bills => {
  933. if (bills.items && bills.items.length) {
  934. const newItems = [];
  935. bills.items.forEach(subBills => {
  936. if (!feeCodes.includes(subBills.feeCode)) {
  937. newItems.push(subBills);
  938. } else {
  939. filterd.push(subBills);
  940. }
  941. });
  942. bills.items = newItems;
  943. // bills.items = bills.items.filter(subBills => !feeCodes.includes(subBills.feeCode));
  944. const subFilterd = filterDataByFeeCodes(bills.items, feeCodes);
  945. filterd.push(...subFilterd);
  946. }
  947. });
  948. return filterd;
  949. }
  950. // 合并清单,将提取出来的清单相关数据,合并进项目清单(模板)
  951. function mergeBills(tenderData, billsTemplate) {
  952. const mergedBills = [...billsTemplate];
  953. const roots = billsTemplate.filter(bills => bills.ParentID === -1);
  954. let lastRoot = roots.find(root => root.NextSiblingID === -1);
  955. mergeWorkSummary(tenderData.workSummary);
  956. mergeFBFX(tenderData.fbfx);
  957. mergeCSXM(tenderData.csxm);
  958. mergeOther(tenderData.other);
  959. mergeTax(tenderData.tax);
  960. return mergedBills;
  961. // 合并清单数据
  962. function mergeitems(fixedBills, items) {
  963. const daryWorkMap = {
  964. '人工': fixedFlag.LABOUR,
  965. '材料': fixedFlag.MATERIAL,
  966. '机械': fixedFlag.MACHINE,
  967. '施工机械': fixedFlag.MACHINE,
  968. '施工机具': fixedFlag.MACHINE
  969. };
  970. const fixedBillsFlag = getFlag(fixedBills);
  971. let preBills = billsTemplate.find(bills => bills.ParentID === fixedBills.ID && bills.NextSiblingID === -1);
  972. items.forEach(bills => {
  973. // 计日工需要特殊处理,兼容广联达的数据,广联达的计日工下的人工、材料、机械的费用字典不对,因此用名称匹配
  974. let matched;
  975. if (fixedBillsFlag === fixedFlag.DAYWORK) {
  976. const dayWorkSubFlag = daryWorkMap[bills.name];
  977. matched = dayWorkSubFlag
  978. ? billsTemplate.find(templateBills => getFlag(templateBills) === dayWorkSubFlag)
  979. : null;
  980. } else {
  981. matched = billsTemplate.find(templateBills => FlagFeeCodeMap[getFlag(templateBills)] === bills.feeCode);
  982. }
  983. if (matched) {
  984. assignAttr(matched, bills, ['items'], true);
  985. if (bills.items && bills.items.length) {
  986. mergeitems(matched, bills.items);
  987. //mergedBills.push(...mergeDataRecur(fixedBills, [bills]))
  988. }
  989. preBills = matched;
  990. } else {
  991. const nextID = preBills && preBills.NextSiblingID || -1;
  992. mergedBills.push(...mergeDataRecur(fixedBills, [bills]));
  993. bills.NextSiblingID = nextID;
  994. if (preBills) {
  995. preBills.NextSiblingID = bills.ID;
  996. }
  997. preBills = bills;
  998. }
  999. });
  1000. }
  1001. // 简单地合并: 设置某清单的金额,数据递归插入到某清单的子项
  1002. function simpleMerge(flag, src) {
  1003. const fixedBills = billsTemplate.find(bills => getFlag(bills) === flag);
  1004. if (fixedBills) {
  1005. assignAttr(fixedBills, src, ['fees', 'feeCode']);
  1006. mergedBills.push(...mergeDataRecur(fixedBills, src.items));
  1007. }
  1008. }
  1009. // 合并大项费用
  1010. function mergeWorkSummary(workSummary) {
  1011. // 首层数据与清单模板根据费用字典进行匹配,匹配到的则赋值一些属性,匹配不到则将其及其所有子数据插入到模板最末大项费用
  1012. workSummary.forEach(summaryBills => {
  1013. const matched = roots.find(root => FlagFeeCodeMap[getFlag(root)] === summaryBills.feeCode);
  1014. if (matched) {
  1015. if (!summaryBills.calcBase) {
  1016. summaryBills.calcBase = matched.calcBase;
  1017. matched.ignoreValidator = true; // 用了模板的基数,基数无视基数验证
  1018. }
  1019. assignAttr(matched, summaryBills, ['items'], true);
  1020. } else {
  1021. mergedBills.push(...mergeDataRecur(null, [summaryBills]));
  1022. if (lastRoot) {
  1023. lastRoot.NextSiblingID = summaryBills.ID;
  1024. lastRoot = summaryBills;
  1025. }
  1026. }
  1027. });
  1028. }
  1029. // 合并分部分项
  1030. function mergeFBFX(fbfxSrc) {
  1031. simpleMerge(fixedFlag.SUB_ENGINERRING, fbfxSrc);
  1032. }
  1033. // 合并措施项目
  1034. function mergeCSXM(csxmSrc) {
  1035. const fixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.MEASURE);
  1036. fixedBills.fees = mergeFees(fixedBills.fees, csxmSrc.fees);
  1037. mergeitems(fixedBills, csxmSrc.items);
  1038. }
  1039. // 合并其他项目
  1040. function mergeOther(otherSrc) {
  1041. const fixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.OTHER);
  1042. fixedBills.fees = mergeFees(fixedBills.fees, otherSrc.fees);
  1043. // 合并其他项目费
  1044. // SundryCosts其他项目费会包含暂列金额等后续会再次出现的数据,因此合并SundryCosts的数据时,过滤掉一部分数据
  1045. const feeCodeFilter = [
  1046. FlagFeeCodeMap[fixedFlag.PROVISIONAL], // 暂列金额
  1047. FlagFeeCodeMap[fixedFlag.MATERIAL_PROVISIONAL], // 材料暂估
  1048. FlagFeeCodeMap[fixedFlag.ENGINEERING_ESITIMATE], // 专业工程暂估
  1049. FlagFeeCodeMap[fixedFlag.DAYWORK], // 计日工
  1050. FlagFeeCodeMap[fixedFlag.TURN_KEY_CONTRACT], // 总承包服务费
  1051. FlagFeeCodeMap[fixedFlag.CLAIM], // 索赔
  1052. FlagFeeCodeMap[fixedFlag.VISA], // 现场签证
  1053. ];
  1054. const filterdBills = filterDataByFeeCodes([otherSrc.sundryCosts], feeCodeFilter);
  1055. /**
  1056. * 有些源xml文件中,被过滤掉SundryCosts中的子项,相对于Sundry的子项会多一些属性
  1057. * 比如:Sundry->SunryCosts->SundryCostsGroup->SundryCostsItem中的材料暂估价,含有QtyFormula属性,但是Sundry->ProvisionalMaterialEquipment中不含有QtyFormula
  1058. * 因此,即使后续Sundry的子项会赋值给模板,也要将被过滤掉的子项的属性先赋给模板
  1059. */
  1060. filterdBills.forEach(filterdItem => {
  1061. const matched = billsTemplate.find(templateBills => FlagFeeCodeMap[getFlag(templateBills)] === filterdItem.feeCode);
  1062. if (matched) {
  1063. assignAttr(matched, filterdItem, ['items'], true); // 不拷贝item属性
  1064. matched.ignoreA
  1065. }
  1066. });
  1067. const sundryCostsBills = otherSrc.sundryCosts.items;
  1068. mergeitems(fixedBills, sundryCostsBills);
  1069. // 合并暂列金额
  1070. simpleMerge(fixedFlag.PROVISIONAL, otherSrc.provisional);
  1071. // 合并材料暂估,由于材料暂估的子元素是暂估人材机,因此对清单来说,只需处理材料暂估根元素的属性
  1072. const zgcFixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.MATERIAL_PROVISIONAL);
  1073. assignAttr(zgcFixedBills, otherSrc.ProvisionalMaterialEquipment);
  1074. // 合并专业工程暂估价
  1075. simpleMerge(fixedFlag.ENGINEERING_ESITIMATE, otherSrc.specialty);
  1076. // 合并计日工
  1077. const dayWorkFixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.DAYWORK);
  1078. assignAttr(dayWorkFixedBills, otherSrc.dayWork, ['fees', 'feeCode']);
  1079. mergeitems(dayWorkFixedBills, otherSrc.dayWork.items);
  1080. // 合并总承包服务费
  1081. simpleMerge(fixedFlag.TURN_KEY_CONTRACT, otherSrc.mainContractor);
  1082. // 合并索赔
  1083. simpleMerge(fixedFlag.CLAIM, otherSrc.claim);
  1084. // 合并现场签证
  1085. simpleMerge(fixedFlag.VISA, otherSrc.visa);
  1086. }
  1087. // 合并税金
  1088. function mergeTax(taxSrc) {
  1089. const taxFixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.TAX);
  1090. if (!taxSrc.calcBase) {
  1091. taxSrc.calcBase = taxFixedBills.calcBase;
  1092. taxFixedBills.ignoreValidator = true; // 用了模板的基数,基数无视基数验证
  1093. } else {
  1094. taxFixedBills.ignoreValidator = false;
  1095. }
  1096. assignAttr(taxFixedBills, taxSrc);
  1097. }
  1098. }
  1099. // 给固定清单设置上费用字典,因为在合并清单的时候,清单模板中可能有一些数据应该有规定的费用字典,但是没有被设置上费用字典。
  1100. function setupFeeCode(billsData) {
  1101. billsData.forEach(bills => {
  1102. if (bills.feeCode) {
  1103. return;
  1104. }
  1105. bills.feeCode = FlagFeeCodeMap[getFlag(bills)] || '';
  1106. })
  1107. }
  1108. // 检查清单是否引用了自身,比如广联达导出文件中 材料保管费基数为CLBGF
  1109. function isCalcBaseCycle(bills) {
  1110. return bills.calcBase.match(new RegExp(`\\b${bills.feeCode}\\b`)); // \b: 匹配前一个字符和后一个字符不全为\w的位置
  1111. }
  1112. // 转换计算基数
  1113. // 1.有子项数据,则清空基数
  1114. // 2.引用的基数造成自身循环,比如分部分项部分引用了QDF
  1115. // 3.费用代号匹配清单基数的代号
  1116. // 4.费用代号匹配不到清单基数的代号,则匹配此费用代号的清单,作为行引用(即ID引用)
  1117. // 5.对应字典里找不到则设置成金额
  1118. function transformCalcBase(billsData) {
  1119. // 费用代号 - 计算基数映射
  1120. const feeCodeFormulaMap = {}
  1121. Object
  1122. .entries(FormulaFeeCodeMap)
  1123. .forEach(([formula, feeCode]) => {
  1124. feeCodeFormulaMap[feeCode] = formula;
  1125. });
  1126. // 费用代号 - ID映射
  1127. const feeCodeIDMap = {};
  1128. billsData.forEach(data => {
  1129. if (data.feeCode) {
  1130. feeCodeIDMap[data.feeCode] = data.ID;
  1131. }
  1132. });
  1133. for (const bills of billsData) {
  1134. if (!bills.calcBase || bills.ignoreValidator) {
  1135. continue;
  1136. }
  1137. const sub = billsData.find(data => data.ParentID === bills.ID);
  1138. // 有子项数据,则清空基数,费率
  1139. if (sub) {
  1140. bills.calcBase = '';
  1141. bills.feeRate = '';
  1142. continue;
  1143. }
  1144. if (typeof bills.calcBase !== 'string') {
  1145. bills.calcBase = String(bills.calcBase);
  1146. }
  1147. // 引用的基数造成自循环,清空基数
  1148. const isCycle = isCalcBaseCycle(bills);
  1149. if (isCycle) {
  1150. bills.calcBase = '';
  1151. continue;
  1152. }
  1153. // 提取基数中的费用代号
  1154. bills.calcBase = bills.calcBase.replace(/\s/g, '');
  1155. const feeCodes = bills.calcBase.split(/[\+\-\*\/]/g);
  1156. // 提取操作符
  1157. const oprs = bills.calcBase.match(/[\+\-\*\/]/g);
  1158. // 转换后的基数
  1159. const newBase = [];
  1160. let illegal = false; //不合法
  1161. for (const feeCode of feeCodes) {
  1162. const formula = feeCodeFormulaMap[feeCode];
  1163. const refID = feeCodeIDMap[feeCode];
  1164. if (formula) { // 匹配到公式
  1165. newBase.push(formula);
  1166. } else if (refID) { // 匹配到行引用
  1167. newBase.push(`@${refID}`) // 转换成ID引用
  1168. } else { // 无法识别
  1169. illegal = true;
  1170. break;
  1171. }
  1172. }
  1173. if (illegal) {
  1174. const fee = getFee(bills.fees, ['common', 'totalFee']);
  1175. const feeRate = bills.feeRate && parseFloat(bills.feeRate) !== 0 ? parseFloat(bills.feeRate) : 0;
  1176. if (fee && parseFloat(fee) !== 0 && feeRate) {
  1177. bills.calcBase = scMathUtil.roundForObj(parseFloat(fee) * 100 / feeRate, Decimal.FEE);
  1178. } else {
  1179. bills.calcBase = fee !== '0' ? fee : '';
  1180. }
  1181. } else {
  1182. let newCalcBase = '';
  1183. for (let i = 0; i < newBase.length; i++) {
  1184. newCalcBase += newBase[i];
  1185. if (oprs && oprs[i]) {
  1186. newCalcBase += oprs[i];
  1187. }
  1188. }
  1189. bills.calcBase = newCalcBase;
  1190. }
  1191. }
  1192. }
  1193. // 转换清单
  1194. function transformBills(tenderData, billsTemplate) {
  1195. const rst = {
  1196. bills: [],
  1197. billsQuantityDetails: []
  1198. };
  1199. const billsData = mergeBills(tenderData, billsTemplate);
  1200. setupFeeCode(billsData);
  1201. transformCalcBase(billsData);
  1202. // 处理综合单价
  1203. // 没有子清单,且没有综合单价,且有综合合价,则综合单价 = 综合合价 / 工程量
  1204. billsData.forEach(bills => {
  1205. const hasChild = billsData.some(data => data.ParentID === bills.ID);
  1206. let unitFee = getFee(bills.fees, ['common', 'unitFee']);
  1207. const totalFee = getFee(bills.fees, ['common', 'totalFee']);
  1208. if (!hasChild && !parseFloat(unitFee) && totalFee && parseFloat(totalFee)) {
  1209. // 不存工程量
  1210. if (!bills.quantity || !parseFloat(bills.quantity)) {
  1211. unitFee = totalFee;
  1212. // 源不存在工程量,没有计算基数、但是却有综合合价,工程量要设置为1
  1213. if (!bills.calcBase) {
  1214. bills.quantity = '1';
  1215. }
  1216. } else {
  1217. // 综合合价的小数位数
  1218. //const totalFeeDecimal = totalFee.match(/\.\d+/);
  1219. //unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, totalFeeDecimal ? totalFeeDecimal[0] : 0);
  1220. unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, Decimal.FEE);
  1221. }
  1222. const commonFee = bills.fees.find(fee => fee.fieldName === 'common');
  1223. if (commonFee) {
  1224. commonFee.unitFee = unitFee;
  1225. }
  1226. }
  1227. bills.projectID = tenderData.ID;
  1228. // 工程量明细
  1229. transformQuantityDetails(tenderData.ID, bills.quantityDetails, bills.ID, 'billID');
  1230. bills.quantityEXP = bills.quantityDetails && bills.quantityDetails.length ? GCLMXHj : bills.quantity;
  1231. if (bills.quantityDetails) {
  1232. rst.billsQuantityDetails.push(...bills.quantityDetails);
  1233. }
  1234. rst.bills.push(bills);
  1235. });
  1236. return rst;
  1237. }
  1238. // 转换工程量明细数据
  1239. function transformQuantityDetails(tenderID, quantityDetails, refID, typeKey) {
  1240. if (quantityDetails) {
  1241. quantityDetails.forEach(item => {
  1242. item.ID = uuid.v1();
  1243. item[typeKey] = refID; // billID、rationID
  1244. item.projectID = tenderID;
  1245. });
  1246. }
  1247. }
  1248. // 转换人材机汇总相关数据(人材机汇总、承包人材料、评标材料、暂估价材料、组成物、单价文件)
  1249. function transformGLJList(tenderData, IDPlaceholder, projectGLJMap) {
  1250. const rst = {
  1251. projectGLJ: [], // 项目人材机
  1252. contractorList: [], // 承包人材料
  1253. bidEvaluationList: [], // 评标材料
  1254. evaluationList: [], // 暂估材料
  1255. unitPrice: [], // 单价文件
  1256. mixRatio: [] // 组成物
  1257. };
  1258. transformGLJSummary();
  1259. transformContractorSummary();
  1260. transformRelatedGLJList(tenderData.bidEvaluationSummary, rst.bidEvaluationList, 'is_eval_material');
  1261. transformEvalSummary();
  1262. return rst;
  1263. // 转换项目人材机、组成物
  1264. function transformGLJSummary() {
  1265. // 项目人材机
  1266. tenderData.gljSummary.forEach(projectGLJ => {
  1267. projectGLJ.project_id = tenderData.ID;
  1268. projectGLJ.id = IDPlaceholder.projectGLJ++;
  1269. projectGLJMap[projectGLJ.code] = projectGLJ;
  1270. });
  1271. tenderData.gljSummary.forEach(projectGLJ => {
  1272. //组成物数据
  1273. projectGLJ.ratios.forEach(ratio => {
  1274. const matched = projectGLJMap[ratio.code];
  1275. ratio.code = matched.code;
  1276. ratio.projectGLJID = projectGLJ.id;
  1277. ratio.id = IDPlaceholder.ratio++;
  1278. ratio.unit_price_file_id = tenderData.property.unitPriceFile.id;
  1279. ratio.unit = matched && matched.unit || '';
  1280. ratio.name = matched && matched.name || '';
  1281. ratio.specs = matched && matched.specs || '';
  1282. ratio.type = matched && matched.type || 1;
  1283. ratio.connect_key = [projectGLJ.code || 'null', projectGLJ.name || 'null', projectGLJ.specs || 'null', projectGLJ.unit || 'null', projectGLJ.type].join('|-|');
  1284. rst.mixRatio.push(ratio);
  1285. });
  1286. rst.projectGLJ.push(projectGLJ);
  1287. // 单价文件数据:
  1288. rst.unitPrice.push(generateUnitPrice(projectGLJ));
  1289. });
  1290. }
  1291. // 转换与项目人材机关联的材料
  1292. function transformRelatedGLJList(list, container, relatedType) {
  1293. list.forEach(glj => {
  1294. glj.ID = uuid.v1();
  1295. glj.projectID = tenderData.ID;
  1296. glj.projectGLJID = -1;
  1297. if (typeof glj.seq === 'undefined') {
  1298. glj.seq = glj.code;
  1299. }
  1300. const projectGLJ = projectGLJMap[glj.code];
  1301. if (projectGLJ) {
  1302. projectGLJ[relatedType] = 1;
  1303. glj.is_related = 1;
  1304. glj.projectGLJID = projectGLJ.id;
  1305. }
  1306. container.push(glj);
  1307. });
  1308. }
  1309. // 转换承包人材料
  1310. function transformContractorSummary() {
  1311. // 由于承包人差额数据和指数数据共用承包人材料表,因此需要合并差额数据和指数数据
  1312. const mergedList = [];
  1313. tenderData.exponentialSummary.forEach(eGLJ => {
  1314. const matched = tenderData.differentiaSummary.find(dGLJ => dGLJ.code === eGLJ.code);
  1315. if (matched) {
  1316. assignAttr(matched, eGLJ, ['varWeight', 'FO', 'FI']);
  1317. } else {
  1318. mergedList.push(eGLJ);
  1319. }
  1320. });
  1321. mergedList.push(...tenderData.differentiaSummary);
  1322. transformRelatedGLJList(mergedList, rst.contractorList, 'is_contractor_material');
  1323. }
  1324. // 转换暂估价材料
  1325. function transformEvalSummary() {
  1326. const evalGLJList = tenderData.gljSummary
  1327. .filter(glj => glj.is_evaluate)
  1328. .map(glj => {
  1329. const evalGLJ = {};
  1330. assignAttr(evalGLJ, glj, [
  1331. 'code', 'name', 'specs', 'unit', 'quantity', 'market_price',
  1332. 'originPlace', 'vender', 'remark'
  1333. ]);
  1334. evalGLJ.seq = evalGLJ.code;
  1335. return evalGLJ;
  1336. });
  1337. transformRelatedGLJList(evalGLJList, rst.evaluationList, 'is_evaluate');
  1338. }
  1339. // 生成单价文件
  1340. function generateUnitPrice(projectGLJ) {
  1341. return {
  1342. projectGLJID: projectGLJ.id, //做个标记,后端查找标准数据后,方便更新组成物数据
  1343. unit_price_file_id: tenderData.property.unitPriceFile.id,
  1344. id: IDPlaceholder.unitPrice++,
  1345. code: projectGLJ.code,
  1346. original_code: projectGLJ.original_code,
  1347. name: projectGLJ.name,
  1348. unit: projectGLJ.unit,
  1349. specs: projectGLJ.specs,
  1350. type: projectGLJ.type,
  1351. short_name: projectGLJ.shortName,
  1352. base_price: projectGLJ.base_price,
  1353. market_price: projectGLJ.market_price
  1354. };
  1355. }
  1356. }
  1357. // 转换定额、定额人材机、定额系数
  1358. // @param {Object} tenderData - 提取的单位工程数据
  1359. // @param {Array} billsData - 转换后的清单数据
  1360. // @param {Object} projectGLJMap - 转换项目人材机时生成的项目人材机编码-数据的映射
  1361. function transformRations(tenderData, billsData, projectGLJMap) {
  1362. const rst = {
  1363. ration: [],
  1364. rationGLJ: [],
  1365. rationCoe: [],
  1366. rationQuantityDetails: []
  1367. };
  1368. billsData
  1369. .filter(bills => bills.rations && bills.rations.length)
  1370. .forEach(bills => {
  1371. bills.rations.forEach(ration => {
  1372. // TODO 取费专业不知如何取,暂时取单位工程取费专业(导出的文件没有可用的取费专业字段,因此需要后端匹配标准定额)
  1373. // 如果标准定额有取费专业,则会替换掉这里设置的取费专业
  1374. ration.programID = tenderData.property.projectEngineering;
  1375. ration.ID = uuid.v1();
  1376. ration.projectID = tenderData.ID;
  1377. ration.billsItemID = bills.ID;
  1378. ration.contain = getContain(bills, ration);
  1379. // 工程量明细
  1380. transformQuantityDetails(tenderData.ID, ration.quantityDetails, ration.ID, 'rationID');
  1381. ration.quantityEXP = getQuantityEXP(bills, ration);
  1382. if (ration.quantityDetails) {
  1383. rst.rationQuantityDetails.push(...ration.quantityDetails);
  1384. }
  1385. rst.ration.push(ration);
  1386. // 定额人材机
  1387. rst.rationGLJ.push(...transformRationGLJs(bills, ration));
  1388. // 定额系数
  1389. rst.rationCoe.push(generateRationCoe(ration));
  1390. });
  1391. });
  1392. return rst;
  1393. // 含量:定额工程量/清单工程量
  1394. function getContain(bills, ration) {
  1395. if (!bills.quantity || !ration.quantity) {
  1396. return '0';
  1397. } else {
  1398. const tempQuantity = ration.quantity / bills.quantity;
  1399. return isFinite(tempQuantity) ? scMathUtil.roundForObj(tempQuantity, Decimal.PROCESS) : '0';
  1400. }
  1401. }
  1402. // 转换定额人材机
  1403. function transformRationGLJs(bills, ration) {
  1404. return ration.rationGLJs.map(rationGLJ => {
  1405. const matched = projectGLJMap[rationGLJ.code];
  1406. if (matched) {
  1407. rationGLJ.projectGLJID = matched.id;
  1408. rationGLJ.code = matched.code;
  1409. rationGLJ.type = matched.type;
  1410. rationGLJ.shortName = matched.shortName;
  1411. rationGLJ.name = matched.name;
  1412. rationGLJ.original_code = matched.original_code;
  1413. rationGLJ.unit = matched.unit;
  1414. rationGLJ.specs = matched.specs;
  1415. }
  1416. rationGLJ.ID = uuid.v1();
  1417. rationGLJ.projectID = tenderData.ID;
  1418. rationGLJ.billsItemID = bills.ID;
  1419. rationGLJ.rationID = ration.ID;
  1420. rationGLJ.rationCode = ration.code; // 暂时跟定额编码关联,后端好匹配标准数据
  1421. rationGLJ.rationItemQuantity = rationGLJ.quantity; // 定额消耗,暂时取消耗量,需要后端匹配标准数据后更新
  1422. return rationGLJ;
  1423. });
  1424. }
  1425. // 生成定额系数(项目数据处理的方法很有可能无法共用,因此不把重庆的方法抽离了)
  1426. function generateRationCoe(ration) {
  1427. return {
  1428. projectID: ration.projectID,
  1429. rationID: ration.ID,
  1430. coeID: -1,
  1431. ID: uuid.v1(),
  1432. seq: 1, // 以前排序有的字段,暂时没什么用,不过还是赋上一个值
  1433. name: '自定义系数',
  1434. content: '人工×1,材料×1,机械×1,主材×1,设备×1',
  1435. coes: [
  1436. { amount: 1, operator: '*', gljCode: null, coeType: '定额' },
  1437. { amount: 1, operator: '*', gljCode: null, coeType: '人工' },
  1438. { amount: 1, operator: '*', gljCode: null, coeType: '材料' },
  1439. { amount: 1, operator: '*', gljCode: null, coeType: '机械' },
  1440. { amount: 1, operator: '*', gljCode: null, coeType: '主材' },
  1441. { amount: 1, operator: '*', gljCode: null, coeType: '设备' },
  1442. ],
  1443. option_list: []
  1444. }
  1445. }
  1446. // 获取定额的工程量表达式
  1447. function getQuantityEXP(bills, ration) {
  1448. if (ration.quantityDetails && ration.quantityDetails.length) {
  1449. return GCLMXHj;
  1450. }
  1451. // 定额根单位与清单根单位相同,则定额工程量表达式为QDL;否则定额工程量表达式为:定额工程量 * 定额单位量词
  1452. // eg: 清单单位:m 定额单位:100m
  1453. const reg = /\d+(\D+.*)/;
  1454. const billsRootUnit = bills.unit && bills.unit.replace(reg, '$1') || '';
  1455. const rationRootUnit = ration.unit && ration.unit.replace(reg, '$1') || '';
  1456. if (billsRootUnit === rationRootUnit) {
  1457. return QDL;
  1458. }
  1459. const numReg = /(\d+)\D+.*/;
  1460. const num = ration.unit && ration.unit.replace(numReg, '$1') || '1';
  1461. return ration.quantity * num;
  1462. }
  1463. }
  1464. // 删除一些无用属性,减少通信数据量
  1465. function clean(detailData) {
  1466. const {
  1467. bills,
  1468. ration,
  1469. projectGLJ
  1470. } = detailData;
  1471. bills.forEach(item => delete item.items && delete item.rations && delete item.feeCode && delete item.quantityDetails);
  1472. ration.forEach(item => delete item.rationGLJs && delete item.quantityDetails);
  1473. projectGLJ.forEach(item => delete item.ratios);
  1474. }
  1475. // 需要给清单、定额价格字段赋上调价数据,不然打开项目后会被重算: project_view.js -> loadProjectData方法内
  1476. function setupTenderFees(detailData) {
  1477. const { bills, ration } = detailData;
  1478. [...bills, ...ration].forEach(item => {
  1479. if (item.fees && item.fees.length) {
  1480. item.fees.forEach(feeItem => {
  1481. if (commonUtil.isDef(feeItem.unitFee)) {
  1482. feeItem.tenderUnitFee = feeItem.unitFee;
  1483. }
  1484. if (commonUtil.isDef(feeItem.totalFee)) {
  1485. feeItem.tenderTotalFee = feeItem.totalFee;
  1486. }
  1487. })
  1488. }
  1489. });
  1490. }
  1491. // 转换详细的项目数据,清单、定额、定额人材机、项目人材机、单价文件等
  1492. function transformDetail(tenderData, IDPlaceholder, billsTemplate) {
  1493. const { bills, billsQuantityDetails } = transformBills(tenderData, billsTemplate);
  1494. // 转换定额的处理依赖转换后的项目人材机数据,因此需要先转换项目人材机相关的数据
  1495. const projectGLJMap = {};
  1496. const relatedljGLJData = transformGLJList(tenderData, IDPlaceholder, projectGLJMap);
  1497. const {
  1498. ration,
  1499. rationGLJ,
  1500. rationCoe,
  1501. rationQuantityDetails
  1502. } = transformRations(tenderData, bills, projectGLJMap);
  1503. const detailData = {
  1504. bills,
  1505. ration,
  1506. rationGLJ,
  1507. rationCoe,
  1508. quantityDetails: [...billsQuantityDetails, ...rationQuantityDetails],
  1509. ...relatedljGLJData
  1510. };
  1511. clean(detailData);
  1512. setupTenderFees(detailData);
  1513. console.log(`detailData`);
  1514. console.log(detailData);
  1515. return detailData;
  1516. }
  1517. function getUnit8Numbers(unit8Array) {
  1518. const numbers = [];
  1519. for (const a of unit8Array) {
  1520. numbers.push(a);
  1521. }
  1522. return numbers;
  1523. }
  1524. /**
  1525. * 解压cos、zip文件
  1526. * @param {File} file - 上传的文件
  1527. * @return {Object} 解压出来的xml文件名称与xml文件文本内容映射
  1528. */
  1529. async function unzipFile(file) {
  1530. const jsZip = new JSZip();
  1531. // 广联达导出的cos文件,内部文件的文件名是gbk编码,如果不处理的话无法导入
  1532. let zip;
  1533. if (typeof TextDecoder === 'undefined') {
  1534. const gbkTextDecoder = new TextDecoder('gbk');
  1535. zip = await jsZip.loadAsync(file, {
  1536. // zip文件中有一个标志,用于说明文件名和注释是否使用UTF-8编码。
  1537. // 如果未设置,则JSZip无法知道所使用的编码(它通常是操作系统的默认编码)
  1538. // 因此若文件名编码非utf-8,则会调用decodeFileName。我们将其认为是gbk编码
  1539. decodeFileName: function (bytes) {
  1540. if (bytes.length) {
  1541. return gbkTextDecoder.decode(bytes);
  1542. } else {
  1543. return '';
  1544. }
  1545. }
  1546. });
  1547. } else {
  1548. const fileNameByteList = [];
  1549. let index = 0;
  1550. zip = await jsZip.loadAsync(file, {
  1551. decodeFileName: function (bytes) {
  1552. if (bytes.length) {
  1553. fileNameByteList.push(getUnit8Numbers(bytes));
  1554. return String(index++);
  1555. } else {
  1556. return '';
  1557. }
  1558. }
  1559. });
  1560. const decodedNames = await util.getDecodedData(fileNameByteList, 'gbk');
  1561. // 将zip里的文件名替换成gbk解码后的名称
  1562. decodedNames.forEach((name, index) => {
  1563. if (zip.files[index]) {
  1564. zip.files[index].name = name;
  1565. zip.files[name] = zip.files[index];
  1566. delete zip.files[index];
  1567. }
  1568. });
  1569. }
  1570. const map = {};
  1571. for (const fileName in zip.files) {
  1572. // 将二进制数据转换成字符串
  1573. map[fileName] = await jsZip.file(fileName).async('string');
  1574. }
  1575. return map;
  1576. }
  1577. //从xml文件中提取数据
  1578. async function extractData(file, escape = false) {
  1579. const fileMap = await unzipFile(file);
  1580. const projectXML = fileMap['Project.xml'];
  1581. if (!projectXML) {
  1582. throw '无有效数据';
  1583. }
  1584. const xmlObjMap = {};
  1585. for (const fileName in fileMap) {
  1586. // x2js转换xml使用了DomParser接口,会将一些字符实体进行转义。若不想被自动转义,则需要调用escapeXMLEntity
  1587. const xmlStr = escape ? util.escapeXMLEntity(fileMap[fileName]) : fileMap[fileName];
  1588. //将xml格式良好的字符串转换成对象
  1589. const x2js = new X2JS();
  1590. let xmlObj = x2js.xml_str2json(xmlStr);
  1591. xmlObj = JSON.parse(util.restoreXMLEntity(JSON.stringify(xmlObj)));
  1592. if (!xmlObj) {
  1593. throw '无有效数据。';
  1594. }
  1595. xmlObjMap[fileName] = xmlObj;
  1596. }
  1597. //提取数据
  1598. return extractProject(xmlObjMap);
  1599. };
  1600. // 接受上传的文件类型(不同的省份可以上传的文件不同)
  1601. const accept = ['.zip', '.cos'];
  1602. return {
  1603. accept,
  1604. extractData,
  1605. transformData,
  1606. }
  1607. })();