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. 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. const matched = bills.calcBase.match(new RegExp(`\\b${bills.feeCode}\\b`)); // \b: 匹配前一个字符和后一个字符不全为\w的位置
  1111. return !!(matched && matched[0]);
  1112. }
  1113. // 转换计算基数
  1114. // 1.有子项数据,则清空基数
  1115. // 2.引用的基数造成自身循环,比如分部分项部分引用了QDF
  1116. // 3.费用代号匹配清单基数的代号
  1117. // 4.费用代号匹配不到清单基数的代号,则匹配此费用代号的清单,作为行引用(即ID引用)
  1118. // 5.对应字典里找不到则设置成金额
  1119. function transformCalcBase(billsData) {
  1120. // 费用代号 - 计算基数映射
  1121. const feeCodeFormulaMap = {}
  1122. Object
  1123. .entries(FormulaFeeCodeMap)
  1124. .forEach(([formula, feeCode]) => {
  1125. feeCodeFormulaMap[feeCode] = formula;
  1126. });
  1127. // 费用代号 - ID映射
  1128. const feeCodeIDMap = {};
  1129. billsData.forEach(data => {
  1130. if (data.feeCode) {
  1131. feeCodeIDMap[data.feeCode] = data.ID;
  1132. }
  1133. });
  1134. for (const bills of billsData) {
  1135. if (!bills.calcBase || bills.ignoreValidator) {
  1136. continue;
  1137. }
  1138. const sub = billsData.find(data => data.ParentID === bills.ID);
  1139. // 有子项数据,则清空基数,费率
  1140. if (sub) {
  1141. bills.calcBase = '';
  1142. bills.feeRate = '';
  1143. continue;
  1144. }
  1145. if (typeof bills.calcBase !== 'string') {
  1146. bills.calcBase = String(bills.calcBase);
  1147. }
  1148. // 引用的基数造成自循环,清空基数
  1149. const isCycle = isCalcBaseCycle(bills);
  1150. if (isCycle) {
  1151. bills.calcBase = '';
  1152. continue;
  1153. }
  1154. // 提取基数中的费用代号
  1155. bills.calcBase = bills.calcBase.replace(/\s/g, '');
  1156. const feeCodes = bills.calcBase.split(/[\+\-\*\/]/g);
  1157. // 提取操作符
  1158. const oprs = bills.calcBase.match(/[\+\-\*\/]/g);
  1159. // 转换后的基数
  1160. const newBase = [];
  1161. let illegal = false; //不合法
  1162. for (const feeCode of feeCodes) {
  1163. const formula = feeCodeFormulaMap[feeCode];
  1164. const refID = feeCodeIDMap[feeCode];
  1165. if (formula) { // 匹配到公式
  1166. newBase.push(formula);
  1167. } else if (refID) { // 匹配到行引用
  1168. newBase.push(`@${refID}`) // 转换成ID引用
  1169. } else { // 无法识别
  1170. illegal = true;
  1171. break;
  1172. }
  1173. }
  1174. if (illegal) {
  1175. const fee = getFee(bills.fees, ['common', 'totalFee']);
  1176. const feeRate = bills.feeRate && parseFloat(bills.feeRate) !== 0 ? parseFloat(bills.feeRate) : 0;
  1177. if (fee && parseFloat(fee) !== 0 && feeRate) {
  1178. bills.calcBase = scMathUtil.roundForObj(parseFloat(fee) * 100 / feeRate, Decimal.FEE);
  1179. } else {
  1180. bills.calcBase = fee !== '0' ? fee : '';
  1181. }
  1182. } else {
  1183. let newCalcBase = '';
  1184. for (let i = 0; i < newBase.length; i++) {
  1185. newCalcBase += newBase[i];
  1186. if (oprs && oprs[i]) {
  1187. newCalcBase += oprs[i];
  1188. }
  1189. }
  1190. bills.calcBase = newCalcBase;
  1191. }
  1192. }
  1193. }
  1194. // 转换清单
  1195. function transformBills(tenderData, billsTemplate) {
  1196. const rst = {
  1197. bills: [],
  1198. billsQuantityDetails: []
  1199. };
  1200. const billsData = mergeBills(tenderData, billsTemplate);
  1201. setupFeeCode(billsData);
  1202. transformCalcBase(billsData);
  1203. // 处理综合单价
  1204. // 没有子清单,且没有综合单价,且有综合合价,则综合单价 = 综合合价 / 工程量
  1205. billsData.forEach(bills => {
  1206. const hasChild = billsData.some(data => data.ParentID === bills.ID);
  1207. let unitFee = getFee(bills.fees, ['common', 'unitFee']);
  1208. const totalFee = getFee(bills.fees, ['common', 'totalFee']);
  1209. if (!hasChild && !parseFloat(unitFee) && totalFee && parseFloat(totalFee)) {
  1210. // 不存工程量
  1211. if (!bills.quantity || !parseFloat(bills.quantity)) {
  1212. unitFee = totalFee;
  1213. // 源不存在工程量,没有计算基数、但是却有综合合价,工程量要设置为1
  1214. if (!bills.calcBase) {
  1215. bills.quantity = '1';
  1216. }
  1217. } else {
  1218. // 综合合价的小数位数
  1219. //const totalFeeDecimal = totalFee.match(/\.\d+/);
  1220. //unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, totalFeeDecimal ? totalFeeDecimal[0] : 0);
  1221. unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, Decimal.FEE);
  1222. }
  1223. const commonFee = bills.fees.find(fee => fee.fieldName === 'common');
  1224. if (commonFee) {
  1225. commonFee.unitFee = unitFee;
  1226. }
  1227. }
  1228. bills.projectID = tenderData.ID;
  1229. // 工程量明细
  1230. transformQuantityDetails(tenderData.ID, bills.quantityDetails, bills.ID, 'billID');
  1231. bills.quantityEXP = bills.quantityDetails && bills.quantityDetails.length ? GCLMXHj : bills.quantity;
  1232. if (bills.quantityDetails) {
  1233. rst.billsQuantityDetails.push(...bills.quantityDetails);
  1234. }
  1235. rst.bills.push(bills);
  1236. });
  1237. return rst;
  1238. }
  1239. // 转换工程量明细数据
  1240. function transformQuantityDetails(tenderID, quantityDetails, refID, typeKey) {
  1241. if (quantityDetails) {
  1242. quantityDetails.forEach(item => {
  1243. item.ID = uuid.v1();
  1244. item[typeKey] = refID; // billID、rationID
  1245. item.projectID = tenderID;
  1246. });
  1247. }
  1248. }
  1249. // 转换人材机汇总相关数据(人材机汇总、承包人材料、评标材料、暂估价材料、组成物、单价文件)
  1250. function transformGLJList(tenderData, IDPlaceholder, projectGLJMap) {
  1251. const rst = {
  1252. projectGLJ: [], // 项目人材机
  1253. contractorList: [], // 承包人材料
  1254. bidEvaluationList: [], // 评标材料
  1255. evaluationList: [], // 暂估材料
  1256. unitPrice: [], // 单价文件
  1257. mixRatio: [] // 组成物
  1258. };
  1259. transformGLJSummary();
  1260. transformContractorSummary();
  1261. transformRelatedGLJList(tenderData.bidEvaluationSummary, rst.bidEvaluationList, 'is_eval_material');
  1262. transformEvalSummary();
  1263. return rst;
  1264. // 转换项目人材机、组成物
  1265. function transformGLJSummary() {
  1266. // 项目人材机
  1267. tenderData.gljSummary.forEach(projectGLJ => {
  1268. projectGLJ.project_id = tenderData.ID;
  1269. projectGLJ.id = IDPlaceholder.projectGLJ++;
  1270. projectGLJMap[projectGLJ.code] = projectGLJ;
  1271. });
  1272. tenderData.gljSummary.forEach(projectGLJ => {
  1273. //组成物数据
  1274. projectGLJ.ratios.forEach(ratio => {
  1275. const matched = projectGLJMap[ratio.code];
  1276. ratio.code = matched.code;
  1277. ratio.projectGLJID = projectGLJ.id;
  1278. ratio.id = IDPlaceholder.ratio++;
  1279. ratio.unit_price_file_id = tenderData.property.unitPriceFile.id;
  1280. ratio.unit = matched && matched.unit || '';
  1281. ratio.name = matched && matched.name || '';
  1282. ratio.specs = matched && matched.specs || '';
  1283. ratio.type = matched && matched.type || 1;
  1284. ratio.connect_key = [projectGLJ.code || 'null', projectGLJ.name || 'null', projectGLJ.specs || 'null', projectGLJ.unit || 'null', projectGLJ.type].join('|-|');
  1285. rst.mixRatio.push(ratio);
  1286. });
  1287. rst.projectGLJ.push(projectGLJ);
  1288. // 单价文件数据:
  1289. rst.unitPrice.push(generateUnitPrice(projectGLJ));
  1290. });
  1291. }
  1292. // 转换与项目人材机关联的材料
  1293. function transformRelatedGLJList(list, container, relatedType) {
  1294. list.forEach(glj => {
  1295. glj.ID = uuid.v1();
  1296. glj.projectID = tenderData.ID;
  1297. glj.projectGLJID = -1;
  1298. if (typeof glj.seq === 'undefined') {
  1299. glj.seq = glj.code;
  1300. }
  1301. const projectGLJ = projectGLJMap[glj.code];
  1302. if (projectGLJ) {
  1303. projectGLJ[relatedType] = 1;
  1304. glj.is_related = 1;
  1305. glj.projectGLJID = projectGLJ.id;
  1306. }
  1307. container.push(glj);
  1308. });
  1309. }
  1310. // 转换承包人材料
  1311. function transformContractorSummary() {
  1312. // 由于承包人差额数据和指数数据共用承包人材料表,因此需要合并差额数据和指数数据
  1313. const mergedList = [];
  1314. tenderData.exponentialSummary.forEach(eGLJ => {
  1315. const matched = tenderData.differentiaSummary.find(dGLJ => dGLJ.code === eGLJ.code);
  1316. if (matched) {
  1317. assignAttr(matched, eGLJ, ['varWeight', 'FO', 'FI']);
  1318. } else {
  1319. mergedList.push(eGLJ);
  1320. }
  1321. });
  1322. mergedList.push(...tenderData.differentiaSummary);
  1323. transformRelatedGLJList(mergedList, rst.contractorList, 'is_contractor_material');
  1324. }
  1325. // 转换暂估价材料
  1326. function transformEvalSummary() {
  1327. const evalGLJList = tenderData.gljSummary
  1328. .filter(glj => glj.is_evaluate)
  1329. .map(glj => {
  1330. const evalGLJ = {};
  1331. assignAttr(evalGLJ, glj, [
  1332. 'code', 'name', 'specs', 'unit', 'quantity', 'market_price',
  1333. 'originPlace', 'vender', 'remark'
  1334. ]);
  1335. evalGLJ.seq = evalGLJ.code;
  1336. return evalGLJ;
  1337. });
  1338. transformRelatedGLJList(evalGLJList, rst.evaluationList, 'is_evaluate');
  1339. }
  1340. // 生成单价文件
  1341. function generateUnitPrice(projectGLJ) {
  1342. return {
  1343. projectGLJID: projectGLJ.id, //做个标记,后端查找标准数据后,方便更新组成物数据
  1344. unit_price_file_id: tenderData.property.unitPriceFile.id,
  1345. id: IDPlaceholder.unitPrice++,
  1346. code: projectGLJ.code,
  1347. original_code: projectGLJ.original_code,
  1348. name: projectGLJ.name,
  1349. unit: projectGLJ.unit,
  1350. specs: projectGLJ.specs,
  1351. type: projectGLJ.type,
  1352. short_name: projectGLJ.shortName,
  1353. base_price: projectGLJ.base_price,
  1354. market_price: projectGLJ.market_price
  1355. };
  1356. }
  1357. }
  1358. // 转换定额、定额人材机、定额系数
  1359. // @param {Object} tenderData - 提取的单位工程数据
  1360. // @param {Array} billsData - 转换后的清单数据
  1361. // @param {Object} projectGLJMap - 转换项目人材机时生成的项目人材机编码-数据的映射
  1362. function transformRations(tenderData, billsData, projectGLJMap) {
  1363. const rst = {
  1364. ration: [],
  1365. rationGLJ: [],
  1366. rationCoe: [],
  1367. rationQuantityDetails: []
  1368. };
  1369. billsData
  1370. .filter(bills => bills.rations && bills.rations.length)
  1371. .forEach(bills => {
  1372. bills.rations.forEach(ration => {
  1373. // TODO 取费专业不知如何取,暂时取单位工程取费专业(导出的文件没有可用的取费专业字段,因此需要后端匹配标准定额)
  1374. // 如果标准定额有取费专业,则会替换掉这里设置的取费专业
  1375. ration.programID = tenderData.property.projectEngineering;
  1376. ration.ID = uuid.v1();
  1377. ration.projectID = tenderData.ID;
  1378. ration.billsItemID = bills.ID;
  1379. ration.contain = getContain(bills, ration);
  1380. // 工程量明细
  1381. transformQuantityDetails(tenderData.ID, ration.quantityDetails, ration.ID, 'rationID');
  1382. ration.quantityEXP = getQuantityEXP(bills, ration);
  1383. if (ration.quantityDetails) {
  1384. rst.rationQuantityDetails.push(...ration.quantityDetails);
  1385. }
  1386. rst.ration.push(ration);
  1387. // 定额人材机
  1388. rst.rationGLJ.push(...transformRationGLJs(bills, ration));
  1389. // 定额系数
  1390. rst.rationCoe.push(generateRationCoe(ration));
  1391. });
  1392. });
  1393. return rst;
  1394. // 含量:定额工程量/清单工程量
  1395. function getContain(bills, ration) {
  1396. if (!bills.quantity || !ration.quantity) {
  1397. return '0';
  1398. } else {
  1399. const tempQuantity = ration.quantity / bills.quantity;
  1400. return isFinite(tempQuantity) ? scMathUtil.roundForObj(tempQuantity, Decimal.PROCESS) : '0';
  1401. }
  1402. }
  1403. // 转换定额人材机
  1404. function transformRationGLJs(bills, ration) {
  1405. return ration.rationGLJs.map(rationGLJ => {
  1406. const matched = projectGLJMap[rationGLJ.code];
  1407. if (matched) {
  1408. rationGLJ.projectGLJID = matched.id;
  1409. rationGLJ.code = matched.code;
  1410. rationGLJ.type = matched.type;
  1411. rationGLJ.shortName = matched.shortName;
  1412. rationGLJ.name = matched.name;
  1413. rationGLJ.original_code = matched.original_code;
  1414. rationGLJ.unit = matched.unit;
  1415. rationGLJ.specs = matched.specs;
  1416. }
  1417. rationGLJ.ID = uuid.v1();
  1418. rationGLJ.projectID = tenderData.ID;
  1419. rationGLJ.billsItemID = bills.ID;
  1420. rationGLJ.rationID = ration.ID;
  1421. rationGLJ.rationCode = ration.code; // 暂时跟定额编码关联,后端好匹配标准数据
  1422. rationGLJ.rationItemQuantity = rationGLJ.quantity; // 定额消耗,暂时取消耗量,需要后端匹配标准数据后更新
  1423. return rationGLJ;
  1424. });
  1425. }
  1426. // 生成定额系数(项目数据处理的方法很有可能无法共用,因此不把重庆的方法抽离了)
  1427. function generateRationCoe(ration) {
  1428. return {
  1429. projectID: ration.projectID,
  1430. rationID: ration.ID,
  1431. coeID: -1,
  1432. ID: uuid.v1(),
  1433. seq: 1, // 以前排序有的字段,暂时没什么用,不过还是赋上一个值
  1434. name: '自定义系数',
  1435. content: '人工×1,材料×1,机械×1,主材×1,设备×1',
  1436. coes: [
  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. { amount: 1, operator: '*', gljCode: null, coeType: '设备' },
  1443. ],
  1444. option_list: []
  1445. }
  1446. }
  1447. // 获取定额的工程量表达式
  1448. function getQuantityEXP(bills, ration) {
  1449. if (ration.quantityDetails && ration.quantityDetails.length) {
  1450. return GCLMXHj;
  1451. }
  1452. // 定额根单位与清单根单位相同,则定额工程量表达式为QDL;否则定额工程量表达式为:定额工程量 * 定额单位量词
  1453. // eg: 清单单位:m 定额单位:100m
  1454. const reg = /\d+(\D+.*)/;
  1455. const billsRootUnit = bills.unit && bills.unit.replace(reg, '$1') || '';
  1456. const rationRootUnit = ration.unit && ration.unit.replace(reg, '$1') || '';
  1457. if (billsRootUnit === rationRootUnit) {
  1458. return QDL;
  1459. }
  1460. const numReg = /(\d+)\D+.*/;
  1461. const num = ration.unit && ration.unit.replace(numReg, '$1') || '1';
  1462. return ration.quantity * num;
  1463. }
  1464. }
  1465. // 删除一些无用属性,减少通信数据量
  1466. function clean(detailData) {
  1467. const {
  1468. bills,
  1469. ration,
  1470. projectGLJ
  1471. } = detailData;
  1472. bills.forEach(item => delete item.items && delete item.rations && delete item.feeCode && delete item.quantityDetails);
  1473. ration.forEach(item => delete item.rationGLJs && delete item.quantityDetails);
  1474. projectGLJ.forEach(item => delete item.ratios);
  1475. }
  1476. // 需要给清单、定额价格字段赋上调价数据,不然打开项目后会被重算: project_view.js -> loadProjectData方法内
  1477. function setupTenderFees(detailData) {
  1478. const { bills, ration } = detailData;
  1479. [...bills, ...ration].forEach(item => {
  1480. if (item.fees && item.fees.length) {
  1481. item.fees.forEach(feeItem => {
  1482. if (commonUtil.isDef(feeItem.unitFee)) {
  1483. feeItem.tenderUnitFee = feeItem.unitFee;
  1484. }
  1485. if (commonUtil.isDef(feeItem.totalFee)) {
  1486. feeItem.tenderTotalFee = feeItem.totalFee;
  1487. }
  1488. })
  1489. }
  1490. });
  1491. }
  1492. // 转换详细的项目数据,清单、定额、定额人材机、项目人材机、单价文件等
  1493. function transformDetail(tenderData, IDPlaceholder, billsTemplate) {
  1494. const { bills, billsQuantityDetails } = transformBills(tenderData, billsTemplate);
  1495. // 转换定额的处理依赖转换后的项目人材机数据,因此需要先转换项目人材机相关的数据
  1496. const projectGLJMap = {};
  1497. const relatedljGLJData = transformGLJList(tenderData, IDPlaceholder, projectGLJMap);
  1498. const {
  1499. ration,
  1500. rationGLJ,
  1501. rationCoe,
  1502. rationQuantityDetails
  1503. } = transformRations(tenderData, bills, projectGLJMap);
  1504. const detailData = {
  1505. bills,
  1506. ration,
  1507. rationGLJ,
  1508. rationCoe,
  1509. quantityDetails: [...billsQuantityDetails, ...rationQuantityDetails],
  1510. ...relatedljGLJData
  1511. };
  1512. clean(detailData);
  1513. setupTenderFees(detailData);
  1514. console.log(`detailData`);
  1515. console.log(detailData);
  1516. return detailData;
  1517. }
  1518. function getUnit8Numbers(unit8Array) {
  1519. const numbers = [];
  1520. for (const a of unit8Array) {
  1521. numbers.push(a);
  1522. }
  1523. return numbers;
  1524. }
  1525. /**
  1526. * 解压cos、zip文件
  1527. * @param {File} file - 上传的文件
  1528. * @return {Object} 解压出来的xml文件名称与xml文件文本内容映射
  1529. */
  1530. async function unzipFile(file) {
  1531. const jsZip = new JSZip();
  1532. // 广联达导出的cos文件,内部文件的文件名是gbk编码,如果不处理的话无法导入
  1533. let zip;
  1534. if (typeof TextDecoder === 'undefined') {
  1535. const gbkTextDecoder = new TextDecoder('gbk');
  1536. zip = await jsZip.loadAsync(file, {
  1537. // zip文件中有一个标志,用于说明文件名和注释是否使用UTF-8编码。
  1538. // 如果未设置,则JSZip无法知道所使用的编码(它通常是操作系统的默认编码)
  1539. // 因此若文件名编码非utf-8,则会调用decodeFileName。我们将其认为是gbk编码
  1540. decodeFileName: function (bytes) {
  1541. if (bytes.length) {
  1542. return gbkTextDecoder.decode(bytes);
  1543. } else {
  1544. return '';
  1545. }
  1546. }
  1547. });
  1548. } else {
  1549. const fileNameByteList = [];
  1550. let index = 0;
  1551. zip = await jsZip.loadAsync(file, {
  1552. decodeFileName: function (bytes) {
  1553. if (bytes.length) {
  1554. fileNameByteList.push(getUnit8Numbers(bytes));
  1555. return String(index++);
  1556. } else {
  1557. return '';
  1558. }
  1559. }
  1560. });
  1561. const decodedNames = await util.getDecodedData(fileNameByteList, 'gbk');
  1562. // 将zip里的文件名替换成gbk解码后的名称
  1563. decodedNames.forEach((name, index) => {
  1564. if (zip.files[index]) {
  1565. zip.files[index].name = name;
  1566. zip.files[name] = zip.files[index];
  1567. delete zip.files[index];
  1568. }
  1569. });
  1570. }
  1571. const map = {};
  1572. for (const fileName in zip.files) {
  1573. // 将二进制数据转换成字符串
  1574. map[fileName] = await jsZip.file(fileName).async('string');
  1575. }
  1576. return map;
  1577. }
  1578. //从xml文件中提取数据
  1579. async function extractData(file, escape = false) {
  1580. const fileMap = await unzipFile(file);
  1581. const projectXML = fileMap['Project.xml'];
  1582. if (!projectXML) {
  1583. throw '无有效数据';
  1584. }
  1585. const xmlObjMap = {};
  1586. // 导入易达的文件,经过unzipFile的decodeFileName,xml文件头部变成了<?xml version="1.0" encoding="utf-8"?>,需要将前面的乱码去除,否则DOMParser转换后是null
  1587. const reg = /.*<\?xml version="1.0" encoding="utf-8"\?>/i;
  1588. for (const fileName in fileMap) {
  1589. fileMap[fileName] = fileMap[fileName].replace(reg, '<?xml version="1.0" encoding="utf-8"?>');
  1590. // x2js转换xml使用了DomParser接口,会将一些字符实体进行转义。若不想被自动转义,则需要调用escapeXMLEntity
  1591. const xmlStr = escape ? util.escapeXMLEntity(fileMap[fileName]) : fileMap[fileName];
  1592. console.log(xmlStr);
  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. })();