guangdong_2018_import.js 78 KB

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