guangdong_2018_import.js 85 KB

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