guangdong_2018_import.js 73 KB

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