chongqing_2018_import.js 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2019/5/14
  7. * @version
  8. */
  9. /*
  10. * 尽可能减少服务器压力,前端提取后端所需数据,提取成更符合我们程序数据结构的数据
  11. * 源数据中,含有前缀"_"的数据,为原xml节点中的属性,不含前缀的数据为原xml节点的节点名
  12. * */
  13. const importXML = (() => {
  14. // 通用设置和工具
  15. const config = importXMLBase.CONFIG;
  16. const util = importXMLBase.UTIL;
  17. const {
  18. fixedFlag,
  19. billType,
  20. rationType,
  21. projectType
  22. } = commonConstants;
  23. const { AdjustType } = config;
  24. const {
  25. getValue,
  26. arrayValue,
  27. getFee,
  28. getFlag,
  29. getItemsRecur,
  30. } = util;
  31. // 限定取值的取费类别与固定ID对应
  32. const FEE_TYPE_FLAG = {
  33. '120201': fixedFlag.CONSTRUCTION_ORGANIZATION,
  34. '1204': fixedFlag.SAFETY_CONSTRUCTION,
  35. '10041': fixedFlag.PROJECT_COMPLETE_ARCH_FEE,
  36. '1206': fixedFlag.HOUSE_QUALITY_ACCEPT_FEE,
  37. '800': fixedFlag.CHARGE,
  38. '900': fixedFlag.TAX,
  39. '9001': fixedFlag.ADDED_VALUE_TAX,
  40. '9002': fixedFlag.ADDITIONAL_TAX,
  41. '9003': fixedFlag.ENVIRONMENTAL_PROTECTION_TAX
  42. };
  43. // 根据费用类别给清单数据设置flags字段
  44. function initFlags(feeType) {
  45. let flag = FEE_TYPE_FLAG[feeType];
  46. return flag
  47. ? [{ fieldName: 'fixed', flag: flag }]
  48. : [];
  49. }
  50. //导入的文件类型,界面选的文件类型是生成项目的文件类型,这里的文件类型指的是,要导入文件的类型,
  51. //导入文件类型不同,导入数据不同
  52. let importFileKind = '';
  53. //文件类型
  54. const FileKind = {
  55. '投标': 1,
  56. 'tender': 1,
  57. '招标': 2,
  58. 'bid': 2,
  59. '控制价': 3,
  60. 'control': 3
  61. };
  62. // 第x册定额名称包含字符与计算程序ID的匹配映射
  63. const NameProgramMapping = {
  64. '机械设备': 25,
  65. '热力设备': 26,
  66. '静置设备与工艺金属结构制作': 27,
  67. '电气设备': 28,
  68. '建筑智能化': 29,
  69. '自动化控制仪表': 30,
  70. '通风空调': 31,
  71. '工业管道': 32,
  72. '消防': 33,
  73. '给排水、采暖、燃气': 34,
  74. '刷油、防腐蚀、绝热': 35
  75. };
  76. // 获取定额取费专业,根据名称匹配有无固定映射,若没有则取单位工程取费专业(后台配置)
  77. function getProgramID(name, mapping, projectEngineering) {
  78. for (let mapName in mapping) {
  79. const reg = new RegExp(`第.{1,2}册\\s*${mapName}(安装)?工程`);
  80. if (name.match(reg)) {
  81. return mapping[mapName];
  82. }
  83. }
  84. return projectEngineering;
  85. }
  86. let countData = {
  87. projectCount: 0, //项目数量
  88. projectGLJCount: 0, //项目人材机数量
  89. ratioCount: 0, //组成物数量
  90. unitPriceCount: 0, //单价数量
  91. unitPriceFileCount: 0, //单价文件数量
  92. };
  93. //标段
  94. function loadProject(source) {
  95. Object.keys(countData).forEach(key => countData[key] = 0); // 清缓存
  96. countData.projectCount++;
  97. importFileKind = FileKind[getValue(source, ['标段', '_文件类型'])];
  98. let obj = {
  99. projType: projectType.Project,
  100. name: getValue(source, ['标段', '_项目名称']),
  101. engs: loadEng(source),
  102. property: {
  103. compilationIllustration: getValue(source, ['标段', '编制说明', '_内容'])
  104. },
  105. basicInformation: loadBasicInfo(source),
  106. };
  107. //统计项目数量
  108. let count = 1 + obj.engs.length;
  109. obj.engs.forEach(eng => {
  110. count += eng.tenders.length;
  111. });
  112. obj.projectCount = count;
  113. if (source.isTwoLevel) {
  114. obj.isTwoLevel = true;
  115. }
  116. return obj;
  117. }
  118. //基本信息相关
  119. function loadBasicInfo(source) {
  120. let info = [];
  121. info.push({ key: 'projNum', value: getValue(source, ['标段', '_项目编号']) });
  122. info.push({ key: 'constructionUnit', value: getValue(source, ['标段', '_建设单位']) });
  123. //项目信息
  124. let projInfoSrc = getValue(source, ['标段', '项目信息']);
  125. if (projInfoSrc) {
  126. info.push({ key: 'projectScale', value: getValue(projInfoSrc, ['_工程规模']) });
  127. info.push({ key: 'projLocation', value: getValue(projInfoSrc, ['_工程所在地']) });
  128. info.push({ key: 'projAddress', value: getValue(projInfoSrc, ['_工程地址']) });
  129. info.push({ key: 'buildingUnit', value: getValue(projInfoSrc, ['_施工单位']) });
  130. info.push({ key: 'establishUnit', value: getValue(projInfoSrc, ['_编制单位']) });
  131. info.push({ key: 'auditUnit', value: getValue(projInfoSrc, ['_审核单位']) });
  132. info.push({ key: 'establishUnitAuthor', value: getValue(projInfoSrc, ['_编制人']) });
  133. info.push({ key: 'auditUnitAuditor', value: getValue(projInfoSrc, ['_审核人']) });
  134. info.push({ key: 'commencementDate', value: getValue(projInfoSrc, ['_开工日期']) });
  135. info.push({ key: 'completionDate', value: getValue(projInfoSrc, ['_竣工日期']) });
  136. info.push({ key: 'establishDate', value: getValue(projInfoSrc, ['_编制日期']) });
  137. info.push({ key: 'auditDate', value: getValue(projInfoSrc, ['_审核日期']) });
  138. info.push({ key: 'materialPricePeriod', value: getValue(projInfoSrc, ['_材料价格期']) });
  139. info.push({ key: 'contractPriceType', value: getValue(projInfoSrc, ['_合同价类型']) });
  140. //招标信息
  141. info.push({ key: 'agency', value: getValue(projInfoSrc, ['招标信息', '_招标代理机构']) });
  142. info.push({ key: 'tenderCostEngineer', value: getValue(projInfoSrc, ['招标信息', '_造价工程师']) });
  143. info.push({ key: 'tenderingRegistrationCertificateNumber', value: getValue(projInfoSrc, ['招标信息', '_造价工程师注册证号']) });
  144. info.push({ key: 'tenderingPeriod', value: getValue(projInfoSrc, ['招标信息', '_招标工期']) });
  145. info.push({ key: 'engineeringCost', value: getValue(projInfoSrc, ['招标信息', '_控制总价']) });
  146. //投标信息
  147. info.push({ key: 'bidder', value: getValue(projInfoSrc, ['投标信息', '_投标人']) });
  148. info.push({ key: 'bidCostEngineer', value: getValue(projInfoSrc, ['投标信息', '_造价工程师']) });
  149. info.push({ key: 'bidRegistrationCertificateNumber', value: getValue(projInfoSrc, ['投标信息', '_造价工程师注册证号']) });
  150. info.push({ key: 'projectManager', value: getValue(projInfoSrc, ['投标信息', '_项目经理']) });
  151. info.push({ key: 'bidPeriod', value: getValue(projInfoSrc, ['投标信息', '_投标工期']) });
  152. info.push({ key: 'biddingMargin', value: getValue(projInfoSrc, ['投标信息', '_投标保证金']) });
  153. info.push({ key: 'qualityCommitment', value: getValue(projInfoSrc, ['投标信息', '_质量承诺']) });
  154. info.push({ key: 'guaranteeType', value: getValue(projInfoSrc, ['投标信息', '_担保类型']) });
  155. info.push({ key: 'engineeringCost', value: getValue(projInfoSrc, ['投标信息', '_投标总价']) });
  156. let firstEng = arrayValue(source, ['标段', '单项工程'])[0];
  157. if (firstEng) {
  158. let firstTender = arrayValue(firstEng, ['单位工程'])[0];
  159. if (firstTender) {
  160. info.push({ key: 'projectCategory', value: getValue(firstTender, ['工程特征', '_工程类别']) });
  161. }
  162. }
  163. }
  164. return info;
  165. }
  166. //单项工程
  167. function loadEng(source) {
  168. const engs = arrayValue(source, ['标段', '单项工程']);
  169. // 支持导入无单项工程数据,如果只有没有单项工程,自动生成一个单项工程数据
  170. if (!engs.length) {
  171. countData.projectCount++;
  172. const eng = {
  173. code: '1',
  174. name: '单项工程',
  175. projType: 'Engineering',
  176. tenders: loadTender(source, ['标段', '单位工程']),
  177. }
  178. // 标记为两层结构,导出需要用到(虽然自动生成了三层,但是导出的时候需要只导出两层)
  179. source.isTwoLevel = true;
  180. return [eng];
  181. }
  182. return arrayValue(source, ['标段', '单项工程']).map(src => {
  183. countData.projectCount++;
  184. return {
  185. projType: projectType.Engineering,
  186. name: getValue(src, ['_名称']),
  187. code: getValue(src, ['_编号']),
  188. tenders: loadTender(src)
  189. };
  190. });
  191. }
  192. //单位工程
  193. function loadTender(engSrc, path = ['单位工程']) {
  194. return arrayValue(engSrc, path).map(src => {
  195. countData.projectCount++;
  196. countData.unitPriceFileCount++;
  197. return {
  198. projType: projectType.Tender,
  199. name: getValue(src, ['_名称']),
  200. code: getValue(src, ['_编号']),
  201. engineering: getValue(src, ['_专业']), //可能跟我们软件里的工程专业对应不上
  202. projectFeature: loadProjectFeature(src),
  203. feeSummary: loadFeeSummary(src), //单位工程费汇总
  204. fbfx: loadFBFX(src),
  205. csxm: loadCSXM(src),
  206. other: loadOther(src),
  207. chargeTax: loadChargeTax(src),
  208. gljSummary: loadGljSummary(src),
  209. differentiaSummary: loadDifferentiaSummary(src),//承包人材料差额法表
  210. exponentialSummary: loadExponentialSummary(src),//承包人材料指数法表
  211. evalBidSummary: loadEvalBidSummary(src), //评标材料表
  212. evalSummary: loadEvalSummary(src) // 暂估价材料表
  213. };
  214. });
  215. }
  216. //工程特征相关,特征项没有固定的项,不清楚导入的项无法用已有key对应,而且工程特征名称不会有重复,因此用名称与我们软件的工程特征对应
  217. function loadProjectFeature(tenderSrc) {
  218. let feature = [];
  219. feature.push({ dispName: '建筑分类', value: getValue(tenderSrc, ['工程特征', '_建筑分类']) });
  220. feature.push({ dispName: '工程分类', value: getValue(tenderSrc, ['工程特征', '_工程分类']) });
  221. feature.push({ dispName: '建设规模', value: getValue(tenderSrc, ['工程特征', '_建设规模']) });
  222. let items = arrayValue(tenderSrc, ['工程特征', '特征项']);
  223. feature.push(...items.map(item => {
  224. return { dispName: getValue(item, ['_名称']), value: getValue(item, ['_内容']) };
  225. }));
  226. return feature;
  227. }
  228. //单位工程费汇总-计价程序费用行
  229. function loadFeeSummary(tenderSrc) {
  230. let feeItems = arrayValue(tenderSrc, ['单位工程费汇总', '计价程序费用行']);
  231. return feeItems.map(itemSrc => {
  232. let obj = {
  233. rowCode: getValue(itemSrc, ['_行代号']),
  234. name: getValue(itemSrc, ['_项目名称']),
  235. calcBase: getValue(itemSrc, ['_计算基础表达式']),
  236. feeType: getValue(itemSrc, ['_费用类别'])
  237. };
  238. if (importFileKind === FileKind.tender) {
  239. // obj.calcBase = getValue(itemSrc, ['_计算基础表达式']);
  240. obj.feeRate = getValue(itemSrc, ['_费率']);
  241. obj.fees = [{ fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0' }];
  242. }
  243. return obj;
  244. });
  245. }
  246. //分部分项,两种情况 分部分项-清单分部-清单项目、分部分项-清单项目
  247. //return {Array}
  248. function loadFBFX(tenderSrc) {
  249. let fbfxSrc = getValue(tenderSrc, ['分部分项清单']),
  250. fields = [['清单分部'], ['清单项目']];
  251. return getItemsRecur(fbfxSrc, fields, (itemSrc, curField) => {
  252. if (curField[0] === fields[0][0]) { //提取分部所需数据
  253. let obj = {
  254. type: billType.FB,
  255. code: getValue(itemSrc, ['_编号']),
  256. name: getValue(itemSrc, ['_名称']),
  257. remark: getValue(itemSrc, ['_备注']),
  258. };
  259. if (importFileKind === FileKind.tender) {
  260. obj.fees = [
  261. { fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0' },
  262. { fieldName: 'estimate', totalFee: getValue(itemSrc, ['_其中暂估价']) || '0' },
  263. ];
  264. }
  265. return obj;
  266. } else { //提取清单项目所需数据
  267. return extractBills(itemSrc, billType.FX);
  268. }
  269. });
  270. }
  271. //提取清单项目数据
  272. function extractBills(billsSrc, type) {
  273. let { features, contents } = getFeaturesAndContents(billsSrc);
  274. // 特征及内容窗口
  275. let { itemCharacter, jobContent } = featureAndContent(features, contents);
  276. let obj = {
  277. type: type, //清单类型
  278. code: getValue(billsSrc, ['_项目编码']),
  279. name: getValue(billsSrc, ['_项目名称']),
  280. unit: getValue(billsSrc, ['_单位']),
  281. isEstimate: getValue(billsSrc, ['_暂估清单标志']) === 'true' ? true : false,
  282. mainBills: getValue(billsSrc, ['_主要清单标志']) === 'true' ? true : false,
  283. quantity: getValue(billsSrc, ['_工程量']) || '0',
  284. remark: getValue(billsSrc, ['_备注']),
  285. itemCharacterText: featureAndContentText(features, contents),
  286. itemCharacter: itemCharacter, // 不导入到清单下方的特征及内容窗口
  287. jobContent: jobContent
  288. };
  289. //投标和控制价,需要导入最高限价
  290. if ([FileKind.tender, FileKind.control].includes(importFileKind)) {
  291. let maxPrice = getValue(billsSrc, ['_最高限价']);
  292. //不为0才输出
  293. if (maxPrice && maxPrice !== '0') {
  294. obj.outPutMaxPrice = true;
  295. obj.outPutLimitPrice = true;
  296. obj.maxPrice = maxPrice;
  297. }
  298. }
  299. if (importFileKind === FileKind.tender) { //投标
  300. obj.fees = [
  301. { fieldName: 'common', unitFee: getValue(billsSrc, ['_综合单价']), totalFee: getValue(billsSrc, ['_综合合价']) },
  302. { fieldName: 'estimate', totalFee: getValue(billsSrc, ['_其中暂估价']) },
  303. ];
  304. //费用组成
  305. obj.fees.push(...extractFeeContent(getValue(billsSrc, ['费用组成'])));
  306. //组价内容
  307. obj.rations = extractRation(billsSrc);
  308. }
  309. return obj;
  310. // 获取特征及内容源数据
  311. function getFeaturesAndContents(billsSrc) {
  312. let features = arrayValue(billsSrc, ['项目特征', '特征']).map(fSrc => {
  313. return {
  314. name: getValue(fSrc, ['_特征名称']),
  315. eigenvalue: getValue(fSrc, ['_特征描述'])
  316. };
  317. });
  318. let contents = arrayValue(billsSrc, ['工程内容', '内容']).map(cSrc => {
  319. return {
  320. name: getValue(cSrc, ['_内容'])
  321. }
  322. });
  323. return { features, contents };
  324. }
  325. // 特征及内容窗口
  326. function featureAndContent(features, contents) {
  327. // 项目特征
  328. let itemCharacter = features.map((feature, idx) => {
  329. let obj = {
  330. character: feature.name,
  331. isChecked: true,
  332. serialNo: idx + 1,
  333. eigenvalue: []
  334. };
  335. if (feature.eigenvalue) {
  336. obj.eigenvalue.push({ value: feature.eigenvalue, isSelected: true });
  337. }
  338. return obj;
  339. });
  340. // 工作内容
  341. let jobContent = contents.map((content, idx) => {
  342. return {
  343. content: content.name,
  344. serialNo: idx + 1,
  345. isChecked: true
  346. };
  347. });
  348. return { itemCharacter, jobContent };
  349. }
  350. // 特征及内容文本(默认显示在项目特征列)
  351. function featureAndContentText(features, contents) {
  352. let textArr = [];
  353. // 项目特征
  354. textArr.push('[项目特征]');
  355. if (features.length) {
  356. textArr.push(...features.map(feature => {
  357. //若不存在特征描述,同时特征名称中含有“:”,则直接返回特征名称 (广联达招标文件中,特征名称包含了特征名:值)
  358. if (!feature.eigenvalue && /[\:,:]/.test(feature.name)) {
  359. return feature.name;
  360. } else {
  361. return `${feature.name}: ${feature.eigenvalue}`;
  362. }
  363. }));
  364. }
  365. // 工作内容
  366. textArr.push('[工作内容]');
  367. if (textArr.length) {
  368. textArr.push(...contents.map(content => content.name));
  369. }
  370. return textArr.join('\n');
  371. }
  372. }
  373. //提取定额子目
  374. function extractRation(billsSrc) {
  375. let rationSrcs = arrayValue(billsSrc, ['组价内容', '定额子目']),
  376. serialNo = 1;
  377. return rationSrcs.map(rationSrc => {
  378. let rationData = {
  379. serialNo: serialNo++,
  380. code: getValue(rationSrc, ['_原始定额编号']).replace('换', ''),
  381. name: getValue(rationSrc, ['_项目名称']),
  382. caption: getValue(rationSrc, ['_项目名称']),
  383. unit: getValue(rationSrc, ['_单位']),
  384. libCode: getValue(rationSrc, ['_定额库编码']),
  385. quantity: getValue(rationSrc, ['_工程量']) || '0',
  386. quantityEXP: getValue(rationSrc, ['_工程量计算式']),
  387. adjustState: getValue(rationSrc, ['_子目类型']) == '2' ? '1' : '', //子目类型2为换算定额,标记一下我们软件才能显示
  388. isSubcontract: getValue(rationSrc, ['_分包标志']) === 'false' ? false : true,
  389. remark: getValue(rationSrc, ['_备注']),
  390. programID: parseInt(getValue(rationSrc, ['_单价构成文件ID'])),
  391. };
  392. //'6'认为量材,其他都认为是定额
  393. let type = getValue(rationSrc, ['_子目类型']);
  394. if (type == '6') {
  395. rationData.type = rationType.volumePrice;
  396. rationData.subType = rationType.volumePriceMaterial;
  397. } else {
  398. rationData.type = rationType.ration;
  399. }
  400. rationData.fees = [
  401. {
  402. fieldName: 'rationUnitPrice', unitFee: getValue(rationSrc, ['_定额单价']) || '0',
  403. totalFee: getValue(rationSrc, ['_定额合价']) || '0'
  404. },
  405. {
  406. fieldName: 'common', unitFee: getValue(rationSrc, ['_综合单价']) || '0',
  407. totalFee: getValue(rationSrc, ['_综合合价']) || '0'
  408. },
  409. ];
  410. rationData.fees.push(...extractFeeContent(getValue(rationSrc, ['费用组成'])));
  411. //定额人材机
  412. let rationGljSrc = arrayValue(rationSrc, ['工料分析', '人材机含量']);
  413. rationData.rationGljs = rationGljSrc.map(rjSrc => {
  414. return {
  415. code: getValue(rjSrc, ['_人材机代码']),
  416. quantity: getValue(rjSrc, ['_消耗量']) || '0',
  417. }
  418. });
  419. return rationData;
  420. });
  421. }
  422. //获取费用组成
  423. function extractFeeContent(src) {
  424. let rst = [];
  425. //减少数据量
  426. function addFee(feeData) {
  427. //有不为空的价格,才会插入
  428. let match = Object.entries(feeData).find(data => {
  429. let [k, v] = data;
  430. return k !== 'fieldName' && v && v !== '0' && v !== '0.00';
  431. });
  432. if (match) {
  433. rst.push(feeData);
  434. }
  435. }
  436. addFee({
  437. fieldName: 'labour',
  438. unitFee: getValue(src, ['_基价人工费单价']),
  439. totalFee: getValue(src, ['_基价人工费合价']),
  440. });
  441. addFee({
  442. fieldName: 'material',
  443. unitFee: getValue(src, ['_基价材料费单价']),
  444. totalFee: getValue(src, ['_基价材料费合价']),
  445. });
  446. addFee({
  447. fieldName: 'machine',
  448. unitFee: getValue(src, ['_基价机械费单价']),
  449. totalFee: getValue(src, ['_基价机械费合价']),
  450. });
  451. addFee({
  452. fieldName: 'unratedMaterial',
  453. unitFee: getValue(src, ['_未计材料单价']),
  454. totalFee: getValue(src, ['_未计材料合价']),
  455. });
  456. addFee({
  457. fieldName: 'gljDiff',
  458. unitFee: getValue(src, ['_人材机价差单价']),
  459. totalFee: getValue(src, ['_人材机价差合价']),
  460. });
  461. addFee({
  462. fieldName: 'estimate',
  463. unitFee: getValue(src, ['_暂估材料单价']),
  464. totalFee: getValue(src, ['_暂估材料合价']),
  465. });
  466. addFee({
  467. fieldName: 'manage',
  468. unitFee: getValue(src, ['_管理费单价']),
  469. totalFee: getValue(src, ['_管理费合价']),
  470. });
  471. addFee({
  472. fieldName: 'profit',
  473. unitFee: getValue(src, ['_利润单价']),
  474. totalFee: getValue(src, ['_利润合价']),
  475. });
  476. addFee({
  477. fieldName: 'risk',
  478. unitFee: getValue(src, ['_一般风险单价']),
  479. totalFee: getValue(src, ['_一般风险合价']),
  480. });
  481. addFee({
  482. fieldName: 'otherRisk',
  483. unitFee: getValue(src, ['_其他风险单价']),
  484. totalFee: getValue(src, ['_其他风险合价']),
  485. });
  486. return rst;
  487. }
  488. //措施项目
  489. function loadCSXM(tenderSrc) {
  490. let target = {};
  491. let zzcsxmSrc = getValue(tenderSrc, ['措施项目清单', '组织措施清单']);
  492. target.zzcs = { items: loadZZCS(zzcsxmSrc) };
  493. let jscsxmSrc = getValue(tenderSrc, ['措施项目清单', '技术措施清单']);
  494. target.jscs = { items: loadJSCS(jscsxmSrc) };
  495. if (importFileKind === FileKind.tender) { //投标
  496. target.fees = [
  497. { fieldName: 'common', totalFee: getValue(tenderSrc, ['措施项目清单', '_金额']) || '0' },
  498. { fieldName: 'estimate', totalFee: getValue(tenderSrc, ['措施项目清单', '_其中暂估价']) || '0' },
  499. ];
  500. target.zzcs.fees = [{ fieldName: 'common', totalFee: getValue(tenderSrc, ['措施项目清单', '组织措施清单', '_金额']) || '0' }];
  501. target.jscs.fees = [
  502. { fieldName: 'common', totalFee: getValue(tenderSrc, ['措施项目清单', '技术措施清单', '_金额']) || '0' },
  503. { fieldName: 'estimate', totalFee: getValue(tenderSrc, ['措施项目清单', '技术措施清单', '_其中暂估价']) || '0' },
  504. ];
  505. }
  506. return target;
  507. //组织措施清单
  508. function loadZZCS(zzcsSrc) {
  509. let fields = [['组织措施分类'], ['公式计算措施项']];
  510. return getItemsRecur(zzcsSrc, fields, (itemSrc, curField) => {
  511. let rstObj;
  512. if (curField[0] === fields[0][0]) { //组织措施分类
  513. rstObj = {
  514. type: billType.BILLS,
  515. code: getValue(itemSrc, ['_编码']),
  516. name: getValue(itemSrc, ['_名称']),
  517. remark: getValue(itemSrc, ['_备注'])
  518. }
  519. } else {
  520. rstObj = { //公式计算措施项
  521. type: billType.BILLS,
  522. code: getValue(itemSrc, ['_序号']),
  523. name: getValue(itemSrc, ['_名称']),
  524. calcBase: getValue(itemSrc, ['_计算基础表达式']),
  525. feeRate: getValue(itemSrc, ['_费率']),
  526. isEstimate: getValue(itemSrc, ['_暂估价标志']) === 'true' ? true : false,
  527. remark: getValue(itemSrc, ['_备注']),
  528. flags: initFlags(getValue(itemSrc, ['_费用类别']))
  529. };
  530. }
  531. if (importFileKind === FileKind.tender) {
  532. rstObj.fees = [{ fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0' }];
  533. }
  534. return rstObj;
  535. });
  536. }
  537. //技术措施清单
  538. function loadJSCS(jscsSrc) {
  539. let fields = [['技术措施分类'], ['清单项目']];
  540. return getItemsRecur(jscsSrc, fields, (itemSrc, curField) => {
  541. if (curField[0] === fields[0][0]) { //技术措施分类
  542. let obj = {
  543. type: billType.BILLS,
  544. code: getValue(itemSrc, ['_编号']),
  545. name: getValue(itemSrc, ['_名称'])
  546. };
  547. if (importFileKind === FileKind.tender) {
  548. obj.fees = [
  549. { fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0' },
  550. { fieldName: 'estimate', totalFee: getValue(itemSrc, ['_其中暂估价']) || '0' },
  551. ];
  552. }
  553. return obj;
  554. } else { //清单项目
  555. return extractBills(itemSrc, billType.BILLS);
  556. }
  557. });
  558. }
  559. }
  560. //其他项目
  561. function loadOther(tenderSrc) {
  562. let otherSrc = getValue(tenderSrc, ['其他项目清单']);
  563. //暂列金额
  564. let provisional = {
  565. items: arrayValue(otherSrc, ['暂列金额', '暂列金额明细']).map(src => {
  566. let obj = {
  567. type: billType.BILLS,
  568. code: getValue(src, ['_编号']),
  569. name: getValue(src, ['_项目名称']),
  570. unit: getValue(src, ['_计量单位']),
  571. remark: getValue(src, ['_备注'])
  572. };
  573. //if (importFileKind === FileKind.tender) {
  574. obj.fees = [{ fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0' },];
  575. //}
  576. return obj;
  577. })
  578. };
  579. //专业工程暂估价
  580. let engineeringPro = {
  581. items: arrayValue(otherSrc, ['专业工程暂估价', '专业工程暂估明细']).map(src => {
  582. let obj = {
  583. type: billType.BILLS,
  584. code: getValue(src, ['_编号']),
  585. name: getValue(src, ['_工程名称']),
  586. engineeringContent: getValue(src, ['_工程内容']),
  587. remark: getValue(src, ['_备注'])
  588. };
  589. //if (importFileKind === FileKind.tender) {
  590. obj.fees = [{ fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0' },];
  591. //}
  592. return obj;
  593. })
  594. };
  595. //计日工
  596. function extractDayWorkItem(src) {
  597. let obj = {
  598. type: billType.BILLS,
  599. code: getValue(src, ['_编号']),
  600. name: getValue(src, ['_名称']),
  601. unit: getValue(src, ['_单位']),
  602. quantity: getValue(src, ['_数量']),
  603. remark: getValue(src, ['_备注'])
  604. };
  605. if (importFileKind === FileKind.tender) {
  606. obj.fees = [
  607. { fieldName: 'common', unitFee: getValue(src, ['_综合单价']) || '0', totalFee: getValue(src, ['_综合合价']) || '0' }
  608. ];
  609. }
  610. return obj;
  611. }
  612. let labour = arrayValue(otherSrc, ['计日工', '人工', '计日工项目']).map(extractDayWorkItem),
  613. material = arrayValue(otherSrc, ['计日工', '材料', '计日工项目']).map(extractDayWorkItem),
  614. machine = arrayValue(otherSrc, ['计日工', '施工机械', '计日工项目']).map(extractDayWorkItem);
  615. let dayWork = { labour, material, machine };
  616. //总承包服务费
  617. let fields = [['总承包服务费分类'], ['总承包服务费费用项']],
  618. serviceSrc = getValue(otherSrc, ['总承包服务费']);
  619. let service = {
  620. items: getItemsRecur(serviceSrc, fields, (src, curField) => {
  621. if (curField[0] === fields[0][0]) {
  622. return { //总承包服务费分类
  623. type: billType.BILLS,
  624. code: getValue(src, ['_编号']),
  625. name: getValue(src, ['_名称']),
  626. remark: getValue(src, ['_备注'])
  627. }
  628. } else {
  629. let obj = { //总承包服务费费用项
  630. type: billType.BILLS,
  631. code: getValue(src, ['_编号']),
  632. name: getValue(src, ['_工程名称']),
  633. calcBase: getValue(src, ['_计算基础']),
  634. serviceContent: getValue(src, ['_服务内容']),
  635. feeRate: getValue(src, ['_费率']),
  636. remark: getValue(src, ['_备注'])
  637. };
  638. if (importFileKind === FileKind.tender) {
  639. obj.fees = [
  640. { fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0' }
  641. ];
  642. }
  643. return obj;
  644. }
  645. })
  646. };
  647. //索赔、签证
  648. function extractClaimVisa(src) {
  649. let obj = {
  650. type: billType.BILLS,
  651. code: getValue(src, ['_编号']),
  652. name: getValue(src, ['_项目名称']),
  653. unit: getValue(src, ['_计量单位']),
  654. quantity: getValue(src, ['_数量']),
  655. claimVisa: getValue(src, ['_依据'])
  656. };
  657. //if (importFileKind === FileKind.tender) {
  658. obj.fees = [
  659. { fieldName: 'common', unitFee: getValue(src, ['_单价']) || '0', totalFee: getValue(src, ['_合价']) || '0' }
  660. ];
  661. //}
  662. return obj;
  663. }
  664. let claim = { items: arrayValue(otherSrc, ['索赔计价汇总', '签证索赔计价汇总费用项']).map(extractClaimVisa) },
  665. visa = { items: arrayValue(otherSrc, ['现场签证计价汇总', '签证索赔计价汇总费用项']).map(extractClaimVisa) };
  666. //其他
  667. let others = {
  668. items: arrayValue(otherSrc, ['其他', '其他列项']).map(src => {
  669. let obj = {
  670. type: billType.BILLS,
  671. code: getValue(src, ['_序号']),
  672. name: getValue(src, ['_名称']),
  673. calcBase: getValue(src, ['_计算基础']),
  674. feeRate: getValue(src, ['_费率']),
  675. remark: getValue(src, ['_备注'])
  676. };
  677. if (importFileKind === FileKind.tender) {
  678. obj.fees = [{ fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0' }];
  679. }
  680. return obj;
  681. })
  682. };
  683. provisional.fees = [{ fieldName: 'common', totalFee: getValue(otherSrc, ['暂列金额', '_金额']) || '0' }];
  684. engineeringPro.fees = [{ fieldName: 'common', totalFee: getValue(otherSrc, ['专业工程暂估价', '_金额']) || '0' }];
  685. claim.fees = [{ fieldName: 'common', totalFee: getValue(otherSrc, ['索赔计价汇总', '_金额']) || '0' }];
  686. visa.fees = [{ fieldName: 'common', totalFee: getValue(otherSrc, ['现场签证计价汇总', '_金额']) || '0' }];
  687. if (importFileKind === FileKind.tender) {
  688. dayWork.fees = [{ fieldName: 'common', totalFee: getValue(otherSrc, ['计日工', '_金额']) || '0' }];
  689. service.fees = [{ fieldName: 'common', totalFee: getValue(otherSrc, ['总承包服务费', '_金额']) || '0' }];
  690. others.fees = [{ fieldName: 'common', totalFee: getValue(otherSrc, ['其他', '_金额']) || '0' }];
  691. }
  692. return { provisional, engineeringPro, dayWork, service, claim, visa, others };
  693. }
  694. //规费和税金清单
  695. function loadChargeTax(tenderSrc) {
  696. // 由于规费和规费子项的费用类别都是800,因此要处理(重复出现的费用类别不设置固定ID,保证没有相同的固定清单);
  697. // 记录出现过的费用类别
  698. let occurs = [];
  699. return arrayValue(tenderSrc, ['规费和税金清单', '费用项']).map(src => {
  700. let feeType = getValue(src, ['_费用类别']);
  701. let obj = {
  702. type: billType.BILLS,
  703. rowCode: getValue(src, ['_行代号']),
  704. code: getValue(src, ['_序号']),
  705. name: getValue(src, ['_名称']),
  706. calcBase: getValue(src, ['_计算基础表达式']),
  707. feeRate: getValue(src, ['_费率']),
  708. remark: getValue(src, ['_备注']),
  709. flags: occurs.includes(feeType) ? [] : initFlags(feeType)
  710. };
  711. occurs.push(feeType);
  712. if (importFileKind === FileKind.tender) {
  713. obj.fees = [{ fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0' }];
  714. }
  715. return obj;
  716. });
  717. }
  718. //根据费用类别、配比类比获取人材机类别(后端匹配不到标准人材机的时候用)
  719. function getGljTypeData(feeType, ratioType, name) {
  720. // 因为这份文件不太标准,各家也不统一,没有一个靠谱的方法能准备获取人材机类型,所以有些地方需要特殊处理
  721. // 有的人材机类型根据人材机名称特殊获取
  722. const specialMap = {
  723. '定额管理费': { type: 6, shortName: '管' }
  724. };
  725. if (specialMap[name]) {
  726. return specialMap[name];
  727. }
  728. // 一些需要特殊处理的动力材料
  729. const powerNameMap = {
  730. '柴油': { type: 305, shortName: '动' },
  731. '柴油(机械用)': { type: 305, shortName: '动' },
  732. '柴油(机械用)': { type: 305, shortName: '动' },
  733. '汽油': { type: 305, shortName: '动' },
  734. '汽油(机械用)': { type: 305, shortName: '动' },
  735. '汽油(机械用)': { type: 305, shortName: '动' },
  736. '电': { type: 305, shortName: '动' },
  737. '电(机械用)': { type: 305, shortName: '动' },
  738. '电(机械用)': { type: 305, shortName: '动' },
  739. '机上人工': { type: 303, shortName: '机人' },
  740. };
  741. // 特殊处理机上人工(鹏业有的机上人工输出的feeType是1)
  742. if (/机上人工/.test(name)) {
  743. return { type: 303, shortName: '机人' };
  744. }
  745. // 人、机不需要匹配配比类别
  746. if (feeType === '1') {
  747. return { type: 1, shortName: '人' };
  748. } else if (feeType === '3') {
  749. // 特殊处理动力材料
  750. return powerNameMap[name] || { type: 301, shortName: '机' };
  751. }
  752. const map = {
  753. '-': { type: 201, shortName: '材' },
  754. '2-': { type: 201, shortName: '材' },
  755. '2-1': { type: 202, shortName: '砼' },
  756. '2-2': { type: 205, shortName: '商砼' },
  757. '2-3': { type: 203, shortName: '浆' },
  758. '2-4': { type: 206, shortName: '商浆' },
  759. '2-5': { type: 204, shortName: '配比' },
  760. '4-': { type: 4, shortName: '主' },
  761. };
  762. return map[`${feeType}-${ratioType}`] || null;
  763. }
  764. //主要材料类别-三材类别映射
  765. const MaterialMap = {
  766. '100': 1, //钢材钢筋认为钢材,因为文件没细分
  767. '200': 4, //水泥
  768. '300': 3, //木材
  769. '400': 5 //商品砼
  770. };
  771. //人材机汇总
  772. function loadGljSummary(tenderSrc) {
  773. let gljsSrc = arrayValue(tenderSrc, ['人材机汇总', '人材机']);
  774. return gljsSrc.map(gljSrc => {
  775. countData.projectGLJCount++;
  776. //编码都取原始编码,如果原始编码为空,都取编码
  777. let sourceCode = getValue(gljSrc, ['_原始代码']),
  778. code = getValue(gljSrc, ['_代码']);
  779. if (!sourceCode) {
  780. sourceCode = code;
  781. }
  782. // 人材机的真正原始编号应按规矩处理,不能直接读取编码。
  783. // 应取sourceCode,qtf文件中原始代码的最后一个“-”前面的文本;如果没有“-”则直接取原始代码
  784. const orgCodeReg = /.*(?=-\d+$)/;
  785. const match = sourceCode.match(orgCodeReg);
  786. const orgCode = match ? match[0] : sourceCode;
  787. let gljData = {
  788. customCode: code, //处理自定义的代码 (有的公司定额人材机代码、人材机代码是用自动生成的代码)
  789. code: code.includes(sourceCode) ? code : sourceCode, // 如果自定义代码里包含了原始编码,则编码取自定义编码
  790. original_code: orgCode,
  791. name: getValue(gljSrc, ['_名称']),
  792. specs: getValue(gljSrc, ['_规格']),
  793. unit: getValue(gljSrc, ['_单位']),
  794. supply: getValue(gljSrc, ['_供应方式']) == '2' ? 2 : 0, //不是完全甲供就取自行采购
  795. is_evaluate: getValue(gljSrc, ['_暂估材料标志']) === 'true' ? true : false,
  796. no_tax_eqp: getValue(gljSrc, ['_不计税设备标志']) === 'true' ? true : false,
  797. base_price: getValue(gljSrc, ['_定额价']),
  798. market_price: getValue(gljSrc, ['_市场价']),
  799. originPlace: getValue(gljSrc, ['_产地']),
  800. vender: getValue(gljSrc, ['_厂家']),
  801. qualityGrace: getValue(gljSrc, ['_质量等级']),
  802. brand: getValue(gljSrc, ['_品牌']),
  803. remark: getValue(gljSrc, ['_备注'])
  804. };
  805. if (MaterialMap[getValue(gljSrc, ['_主要材料类别'])]) {
  806. gljData.materialType = MaterialMap[getValue(gljSrc, ['_主要材料类别'])];
  807. gljData.materialCoe = getValue(gljSrc, ['_主要材料单位系数']);
  808. }
  809. let typeData = getGljTypeData(getValue(gljSrc, ['_费用类别']), getValue(gljSrc, ['_配比类别']), gljData.name);
  810. if (typeData) {
  811. gljData.type = typeData.type;
  812. gljData.shortName = typeData.shortName;
  813. }
  814. //人材机配比
  815. let ratioSrc = arrayValue(gljSrc, ['人材机配比']);
  816. gljData.ratios = ratioSrc.map(rSrc => {
  817. countData.ratioCount++;
  818. return {
  819. code: getValue(rSrc, ['_明细材料代码']),
  820. consumption: getValue(rSrc, ['_数量'])
  821. }
  822. });
  823. return gljData;
  824. });
  825. }
  826. //承包人材料差额法表
  827. function loadDifferentiaSummary(tenderSrc) {
  828. let gljsSrc = arrayValue(tenderSrc, ['承包人材料差额法表', '承包人材料差额法明细']);
  829. return gljsSrc.map(gljSrc => {
  830. return {
  831. code: getValue(gljSrc, ['_关联材料号']),
  832. name: getValue(gljSrc, ['_名称']),
  833. specs: getValue(gljSrc, ['_规格']),
  834. unit: getValue(gljSrc, ['_单位']),
  835. quantity: getValue(gljSrc, ['_数量']),
  836. riskCoe: getValue(gljSrc, ['_风险系数']),
  837. standardPrice: getValue(gljSrc, ['_基准单价']),
  838. market_price: getValue(gljSrc, ['_投标单价']),
  839. remark: getValue(gljSrc, ['_备注']),
  840. };
  841. });
  842. }
  843. //承包人材料指数法表
  844. function loadExponentialSummary(tenderSrc) {
  845. let gljsSrc = arrayValue(tenderSrc, ['承包人材料指数法表', '承包人材料指数法明细']);
  846. return gljsSrc.map(gljSrc => {
  847. return {
  848. code: getValue(gljSrc, ['_关联材料号']),
  849. name: getValue(gljSrc, ['_名称']),
  850. specs: getValue(gljSrc, ['_规格']),
  851. varWeight: getValue(gljSrc, ['_变值权重B']),
  852. FO: getValue(gljSrc, ['_基本价格指数']),
  853. FI: getValue(gljSrc, ['_现行价格指数']),
  854. remark: getValue(gljSrc, ['_备注']),
  855. };
  856. });
  857. }
  858. //评标材料
  859. function loadEvalBidSummary(tenderSrc) {
  860. let gljsSrc = arrayValue(tenderSrc, ['评标材料表', '材料明细']);
  861. return gljsSrc.map(gljSrc => {
  862. return {
  863. seq: getValue(gljSrc, ['_序号']),
  864. code: getValue(gljSrc, ['_关联材料号']),
  865. name: getValue(gljSrc, ['_材料名称']),
  866. specs: getValue(gljSrc, ['_规格型号']),
  867. unit: getValue(gljSrc, ['_计量单位']),
  868. quantity: getValue(gljSrc, ['_数量']),
  869. market_price: getValue(gljSrc, ['_单价']),
  870. // 由于数据库有这两个字段,暂时也导入(前端隐藏了,目前实际上应该是没用的,以防万一)
  871. originPlace: getValue(gljSrc, ['_产地']),
  872. vender: getValue(gljSrc, ['_厂家']),
  873. remark: getValue(gljSrc, ['_备注'])
  874. };
  875. });
  876. }
  877. // 暂估价材料
  878. function loadEvalSummary(tenderSrc) {
  879. const gljsSrc = arrayValue(tenderSrc, ['暂估价材料表', '材料明细']);
  880. return gljsSrc.map(gljSrc => {
  881. return {
  882. seq: getValue(gljSrc, ['_序号']),
  883. code: getValue(gljSrc, ['_关联材料号']),
  884. name: getValue(gljSrc, ['_材料名称']),
  885. specs: getValue(gljSrc, ['_规格型号']),
  886. unit: getValue(gljSrc, ['_计量单位']),
  887. quantity: getValue(gljSrc, ['_数量']),
  888. market_price: getValue(gljSrc, ['_单价']),
  889. // 由于数据库有这两个字段,暂时也导入(前端隐藏了,目前实际上应该是没用的,以防万一)
  890. originPlace: getValue(gljSrc, ['_产地']),
  891. vender: getValue(gljSrc, ['_厂家']),
  892. remark: getValue(gljSrc, ['_备注'])
  893. }
  894. });
  895. }
  896. //-------------------------提取数据后的数据处理
  897. //获取人材机调整法(差额法还是指数法)
  898. function getAdjustType(tenderData) {
  899. //如果承包人材料指数法里,所有数据的,变值权重B、基本价额指数,现行价格指数全为0,则为指数法,否则为差额法
  900. let isCoe = tenderData.exponentialSummary.length && tenderData.exponentialSummary.every(data =>
  901. !(data.varWeight === '0' && data.FO === '0' && data.FI === '0')
  902. );
  903. return isCoe ? AdjustType.coe : AdjustType.info;
  904. }
  905. // 个软件公司确定了对应关系的其他项目、税金,使用费用类别进行匹配,其他按照名称关键字匹配
  906. const matchRegs = [
  907. { field: 'feeType', reg: /^1300$/, flag: fixedFlag.OTHER },
  908. { field: 'feeType', reg: /^900$/, flag: fixedFlag.TAX },
  909. { field: 'name', reg: /分部分项/, flag: fixedFlag.SUB_ENGINERRING },
  910. { field: 'name', reg: /^措施项目/, flag: fixedFlag.MEASURE },
  911. { field: 'name', reg: /技术措施/, flag: fixedFlag.CONSTRUCTION_TECH },
  912. { field: 'name', reg: /组织措施/, flag: fixedFlag.CONSTRUCTION_ORGANIZATION },
  913. { field: 'name', reg: /组织措施/, flag: fixedFlag.CONSTRUCTION_ORGANIZATION },
  914. { field: 'name', reg: /安全文明/, flag: fixedFlag.SAFETY_CONSTRUCTION },
  915. // {reg: /其他项目/, flag: fixedFlag.OTHER},
  916. { field: 'name', reg: /暂列金额/, flag: fixedFlag.PROVISIONAL },
  917. { field: 'name', reg: /暂估价/, flag: fixedFlag.ESTIMATE },
  918. { field: 'name', reg: /计日工/, flag: fixedFlag.DAYWORK },
  919. { field: 'name', reg: /总承包服务/, flag: fixedFlag.TURN_KEY_CONTRACT },
  920. { field: 'name', reg: /索赔(?:及|与|和)现场签证/, flag: fixedFlag.TURN_KEY_CONTRACT },
  921. { field: 'name', reg: /规费/, flag: fixedFlag.CHARGE },
  922. // {reg: /税金/, flag: fixedFlag.TAX},
  923. { field: 'name', reg: /增值税/, flag: fixedFlag.ADDED_VALUE_TAX },
  924. { field: 'name', reg: /^附加税/, flag: fixedFlag.ADDITIONAL_TAX },
  925. { field: 'name', reg: /环境保护税/, flag: fixedFlag.ENVIRONMENTAL_PROTECTION_TAX },
  926. { field: 'name', reg: /(?:合\s*价)|(?:工程造价)/, flag: fixedFlag.ENGINEERINGCOST }
  927. ];
  928. //处理单位工程费用汇总的清单,这一部分没有靠谱的规则,特殊处理并添加相关清单
  929. function setupFeeSummary(feeSummary, needfulTemplate) {
  930. let preDXFY = null, //记录上一条添加的大项费用
  931. preSubTax = null; //记录上一条添加的附加税子项(特殊处理城市xx、教育xx附加...名称的清单)
  932. let addtionalTax = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.ADDITIONAL_TAX), //附加税
  933. engineeringCost = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.ENGINEERINGCOST); //工程造价
  934. for (let feeBills of feeSummary) {
  935. //匹配固定的附加税子项
  936. if (addtionalTax &&
  937. (/城市维护建设/.test(feeBills.name) ||
  938. /教育费附加/.test(feeBills.name) ||
  939. /地方教育附加/.test(feeBills.name))
  940. ) {
  941. let subTaxData = {
  942. ID: uuid.v1(),
  943. ParentID: addtionalTax.ID,
  944. NextSiblingID: -1,
  945. name: feeBills.name,
  946. rowCode: feeBills.rowCode,
  947. feeRate: feeBills.feeRate,
  948. calcBase: feeBills.calcBase,
  949. };
  950. if (importFileKind === FileKind.tender) {
  951. //subTaxData.rowCode = feeBills.rowCode;
  952. subTaxData.fees = feeBills.fees;
  953. }
  954. if (preSubTax) {
  955. preSubTax.NextSiblingID = subTaxData.ID;
  956. }
  957. needfulTemplate.push(subTaxData);
  958. preSubTax = subTaxData;
  959. } else {
  960. let isMatched = false;
  961. //匹配固定项
  962. for (let match of matchRegs) {
  963. if (!match.reg.test(feeBills[match.field])) {
  964. continue;
  965. }
  966. let findBills = needfulTemplate.find(nData => getFlag(nData) === match.flag);
  967. if (!findBills) {
  968. //如果模板中没有安全文明施工费,计价汇总行中安全文明施工费,将其设置为组织清单子项
  969. if (/安全文明施工/.test(feeBills.name)) {
  970. let fixedCSXM = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.CONSTRUCTION_ORGANIZATION);
  971. if (fixedCSXM) {
  972. needfulTemplate.push({
  973. ID: uuid.v1(),
  974. ParentID: fixedCSXM.ID,
  975. NextSiblingID: -1,
  976. name: feeBills.name,
  977. calcBase: feeBills.calcBase,
  978. feeRate: feeBills.feeRate,
  979. });
  980. isMatched = true;
  981. break; //不添加到大项费用
  982. }
  983. }
  984. continue;
  985. }
  986. isMatched = true;
  987. // 文件有基数则导入基数,没有则用模板的基数
  988. if (feeBills.calcBase) {
  989. findBills.calcBase = feeBills.calcBase;
  990. } else {
  991. // 用了模板的基数,基数无视基数验证
  992. findBills.ignoreValidator = true;
  993. }
  994. findBills.feeRate = feeBills.feeRate;
  995. findBills.rowCode = feeBills.rowCode;
  996. //后台配置的feeRateID优先级比feeRate高,导入数据有费率值时,需要清空这个配置
  997. if (findBills.feeRate && parseFloat(findBills.feeRate) !== 0) {
  998. findBills.feeRateID = null;
  999. }
  1000. if (importFileKind === FileKind.tender) {
  1001. //findBills.rowCode = feeBills.rowCode;
  1002. findBills.fees = feeBills.fees;
  1003. }
  1004. break;
  1005. }
  1006. //匹配不到固定项,认为是大项费用
  1007. if (!isMatched) {
  1008. let dxfyData = {
  1009. ID: uuid.v1(),
  1010. ParentID: -1,
  1011. NextSiblingID: -1,
  1012. name: feeBills.name,
  1013. rowCode: feeBills.rowCode,
  1014. calcBase: feeBills.calcBase,
  1015. feeRate: feeBills.feeRate,
  1016. };
  1017. if (importFileKind === FileKind.tender) {
  1018. //dxfyData.rowCode = feeBills.rowCode;
  1019. dxfyData.fees = feeBills.fees;
  1020. }
  1021. if (!preDXFY) {
  1022. preDXFY = engineeringCost;
  1023. }
  1024. preDXFY.NextSiblingID = dxfyData.ID;
  1025. needfulTemplate.push(dxfyData);
  1026. preDXFY = dxfyData;
  1027. }
  1028. }
  1029. }
  1030. }
  1031. //处理、添加清单
  1032. function setupBills(tenderData, billsTarget) {
  1033. //规费和税金 这个地方不靠谱,先特殊处理(无法兼容所有情况)
  1034. //1.如果在清单中出现(匹配名称相关关键字),则更新数据
  1035. //2.否则新增(在税金出现前,全作为规费的子清单,否则作为税金子清单)
  1036. let charge = null,
  1037. tax = null,
  1038. additionalTax = null;
  1039. for (let i = 0; i < tenderData.chargeTax.length; i++) {
  1040. let curBills = tenderData.chargeTax[i];
  1041. let matchBills = billsTarget.find(d => (d.rowCode && d.rowCode === curBills.rowCode) || d.name === curBills.name);
  1042. //匹配到,更新
  1043. if (matchBills) {
  1044. if (getFlag(matchBills) === fixedFlag.CHARGE) {
  1045. charge = matchBills;
  1046. } else if (getFlag(matchBills) === fixedFlag.TAX) {
  1047. tax = matchBills;
  1048. } else if (getFlag(matchBills) === fixedFlag.ADDITIONAL_TAX) {
  1049. additionalTax = matchBills;
  1050. }
  1051. matchBills.calcBase = curBills.calcBase;
  1052. matchBills.feeRate = curBills.feeRate;
  1053. matchBills.fees = curBills.fees || [];
  1054. matchBills.rowCode = curBills.rowCode;
  1055. if (curBills.flags && curBills.flags.length) {
  1056. matchBills.flags = curBills.flags;
  1057. }
  1058. } else { //新增
  1059. if (!charge && !tax) {
  1060. continue;
  1061. }
  1062. //存在规费,还未找到税金,后面数据作为规费的子项 已找到税金,后面数据作为税金子项
  1063. let curParent = !tax ? charge : tax;
  1064. //特殊处理"城市维护建设税" "教育费附加" "地方教育附加",这三项固定设为税金下附加税的子项
  1065. if (additionalTax &&
  1066. (/城市维护建设/.test(curBills.name) ||
  1067. /教育费附加/.test(curBills.name) ||
  1068. /地方教育附加/.test(curBills.name))) {
  1069. curParent = additionalTax;
  1070. }
  1071. curBills.ID = uuid.v1();
  1072. curBills.NextSiblingID = -1;
  1073. curBills.ParentID = curParent.ID;
  1074. let pre = billsTarget.find(d => d.ParentID === curParent.ID && d.NextSiblingID === -1);
  1075. if (pre) {
  1076. pre.NextSiblingID = curBills.ID;
  1077. }
  1078. billsTarget.push(curBills);
  1079. if (!additionalTax && /^附加税/.test(curBills.name)) {
  1080. additionalTax = curBills;
  1081. }
  1082. }
  1083. }
  1084. //分部分项
  1085. addFixedBlock(fixedFlag.SUB_ENGINERRING, tenderData.fbfx);
  1086. //措施项目
  1087. addFixedBlock(fixedFlag.MEASURE, null, tenderData.csxm.fees);
  1088. //组织措施 //特殊处理子项
  1089. //需要添加的组织措施子项
  1090. function updateZZCSItem(org, tar) {
  1091. for (let [k, v] of Object.entries(tar)) {
  1092. // 如果匹配到的清单自身已有固定ID,不更新固定ID
  1093. // 如果目标清单没有基数,模板清单基数不更新
  1094. if ((k === 'flags' && Array.isArray(tar.flags) && tar.flags.length) ||
  1095. (k === 'calcBase' && !tar.calcBase)) {
  1096. continue;
  1097. }
  1098. org[k] = v;
  1099. }
  1100. }
  1101. let zzcsSubs = [];
  1102. let fixedOrganization = billsTarget.find(data => /组织措施费/.test(data.name)),
  1103. fixedSafe = billsTarget.find(data => /安全文明/.test(data.name)),
  1104. fixedProjectComplete = billsTarget.find(data => /建设工程竣工档案编制/.test(data.name)),
  1105. fixedHouseQuality = billsTarget.find(data => /住宅工程质量分户验收/.test(data.name)),
  1106. fixedZZCS = billsTarget.find(data => getFlag(data) === fixedFlag.CONSTRUCTION_ORGANIZATION),
  1107. lastItem = billsTarget.find(data => data.ParentID === fixedZZCS.ID && data.NextSiblingID === -1);
  1108. for (let item of tenderData.csxm.zzcs.items) {
  1109. if (/组织措施费/.test(item.name) && fixedOrganization) {
  1110. updateZZCSItem(fixedOrganization, item);
  1111. } else if (/安全文明/.test(item.name) && fixedSafe) {
  1112. updateZZCSItem(fixedSafe, item);
  1113. } else if (/建设工程竣工档案/.test(item.name) && fixedProjectComplete) {
  1114. updateZZCSItem(fixedProjectComplete, item);
  1115. } else if (/住宅工程质量分户验收/.test(item.name) && fixedHouseQuality) {
  1116. updateZZCSItem(fixedHouseQuality, item);
  1117. } else {
  1118. zzcsSubs.push(item);
  1119. }
  1120. }
  1121. addFixedBlock(fixedFlag.CONSTRUCTION_ORGANIZATION, zzcsSubs, tenderData.csxm.zzcs.fees);
  1122. //更新原本的最后一个节点
  1123. if (zzcsSubs.length && lastItem) {
  1124. lastItem.NextSiblingID = zzcsSubs[0].ID;
  1125. }
  1126. //技术措施
  1127. addFixedBlock(fixedFlag.CONSTRUCTION_TECH, tenderData.csxm.jscs.items, tenderData.csxm.jscs.fees);
  1128. //暂列金额
  1129. addFixedBlock(fixedFlag.PROVISIONAL, tenderData.other.provisional.items, tenderData.other.provisional.fees);
  1130. //专业工程暂估价
  1131. addFixedBlock(fixedFlag.ENGINEERING_ESITIMATE, tenderData.other.engineeringPro.items, tenderData.other.engineeringPro.fees);
  1132. // 专业工程暂估价汇总金额设置为暂估价清单金额
  1133. let estimateFixedBills = billsTarget.find(d => getFlag(d) === fixedFlag.ESTIMATE);
  1134. if (estimateFixedBills) {
  1135. estimateFixedBills.fees = tenderData.other.engineeringPro.fees;
  1136. }
  1137. //计日工
  1138. addFixedBlock(fixedFlag.DAYWORK, null, tenderData.other.dayWork.fees);
  1139. //人工
  1140. addFixedBlock(fixedFlag.LABOUR, tenderData.other.dayWork.labour);
  1141. //材料
  1142. addFixedBlock(fixedFlag.MATERIAL, tenderData.other.dayWork.material);
  1143. //机械
  1144. addFixedBlock(fixedFlag.MACHINE, tenderData.other.dayWork.machine);
  1145. //总承包服务费
  1146. addFixedBlock(fixedFlag.TURN_KEY_CONTRACT, tenderData.other.service.items, tenderData.other.service.fees);
  1147. //索赔
  1148. addFixedBlock(fixedFlag.CLAIM, tenderData.other.claim.items, tenderData.other.claim.fees);
  1149. //签证
  1150. addFixedBlock(fixedFlag.VISA, tenderData.other.visa.items, tenderData.other.visa.fees);
  1151. //其他
  1152. if (tenderData.other.others.items.length) {
  1153. //特殊处理材料(工程设备暂估价)
  1154. let materialProIdx = tenderData.other.others.items.findIndex(item => item.name === '材料(工程设备)暂估价');
  1155. if (~materialProIdx) {
  1156. let materialPro = tenderData.other.others.items.splice(materialProIdx, 1)[0];
  1157. let fixedMaterialPro = billsTarget.find(data => getFlag(data) === fixedFlag.MATERIAL_PROVISIONAL);
  1158. if (fixedMaterialPro) {
  1159. fixedMaterialPro.fees = materialPro.fees;
  1160. fixedMaterialPro.feeRate = materialPro.feeRate;
  1161. fixedMaterialPro.calcBase = materialPro.calcBase;
  1162. }
  1163. }
  1164. if (tenderData.other.others.items.length) {
  1165. let othersParent = {
  1166. ID: uuid.v1(),
  1167. NextSiblingID: -1,
  1168. name: '其他',
  1169. fees: tenderData.other.others.fees || []
  1170. };
  1171. addFixedBlock(fixedFlag.OTHER, [othersParent]);
  1172. addFixedBlock(othersParent, tenderData.other.others.items);
  1173. }
  1174. }
  1175. //删掉有feeRate的feeRateID
  1176. billsTarget.forEach(data => {
  1177. if (data.feeRate) {
  1178. data.feeRateID = null;
  1179. }
  1180. });
  1181. function addFixedBlock(flag, items, fees = null) {
  1182. let fixedBills = flag;
  1183. if (typeof flag === 'number') {
  1184. fixedBills = billsTarget.find(d => getFlag(d) === flag);
  1185. }
  1186. if (fixedBills) {
  1187. if (fees) {
  1188. fixedBills.fees = fees || [];
  1189. }
  1190. if (Array.isArray(items) && items.length) {
  1191. addBills(fixedBills.ID, items);
  1192. }
  1193. }
  1194. }
  1195. //设置清单的ID数据并添加清单到目标数组
  1196. function addBills(parentID, items) {
  1197. for (let i = 0; i < items.length; i++) {
  1198. let curBills = items[i],
  1199. preBills = items[i - 1];
  1200. curBills.ID = uuid.v1();
  1201. curBills.ParentID = parentID;
  1202. curBills.NextSiblingID = -1;
  1203. if (preBills) {
  1204. preBills.NextSiblingID = curBills.ID;
  1205. }
  1206. billsTarget.push(curBills);
  1207. if (curBills.items && curBills.items.length) {
  1208. addBills(curBills.ID, curBills.items);
  1209. }
  1210. }
  1211. }
  1212. }
  1213. //计算基数字典
  1214. const CalcBaseMap = {
  1215. FBFXHJ: '{分部分项工程费}',
  1216. RGF: '{分部分项定额人工费}',
  1217. CLF: '{分部分项定额材料费}',
  1218. JXF: '{分部分项定额施工机具使用费}',
  1219. ZCF: '{分部分项主材费}',
  1220. GR: '{分部分项人工工日}',
  1221. CSXMHJ: '{措施项目费}',
  1222. ZZCSF: '{组织措施项目费}',
  1223. JSCSF: '{技术措施项目费}',
  1224. JSCS_RGF: '{技术措施项目定额人工费}',
  1225. JSCS_CLF: '{技术措施项目定额材料费}',
  1226. JSCS_JXF: '{技术措施项目定额施工机具使用费}',
  1227. JSCS_ZCF: '{技术措施项目主材费}',
  1228. JSCS_GR: '{技术措施项目人工工日}',
  1229. //JZMJ: '{建筑面积}',
  1230. RCJJC: '{人材机价差}',
  1231. RGJC: '{人工价差}',
  1232. CLJC: '{材料价差}',
  1233. JXJC: '{机械价差}',
  1234. JRGLF: '{甲供人工费}',
  1235. JGCLF: '{甲供材料费}',
  1236. JGJXF: '{甲供施工机具使用费}',
  1237. JGZCF: '{甲供主材费}',
  1238. FBF: '{分包费}',
  1239. FBRGF: '{分包定额人工费}',
  1240. FBCLF: '{分包定额材料费}',
  1241. FBJXF: '{分包定额机械费}',
  1242. FBZCF: '{分包主材费}',
  1243. FBSBF: '{分包设备费}',
  1244. FBGR: '{分包人工工日}',
  1245. QTXMHJ: '{其他项目费}',
  1246. GF: '{规费}',
  1247. SJ: '{税金}',
  1248. SJHJ: '{税金}',
  1249. SQGCZJ: '{税前工程造价}'
  1250. };
  1251. // 检查固定清单引用的基数造成自身循环,比如分部分项部分引用了FBFXHJ
  1252. // 有文件的单位工程费汇总中,含有技术措施项目费清单,含有基数,且无子项。
  1253. function isCalcBaseCycle(bills) {
  1254. const flag = getFlag(bills);
  1255. if (!flag) {
  1256. return false;
  1257. }
  1258. // 跟固定清单直接相关联的基数,若相关固定清单引用了其下的基数,则造成自身循环
  1259. const CycleMap = {
  1260. [fixedFlag.SUB_ENGINERRING]: ['FBFXHJ', 'RGF', 'CLF', 'JXF', 'ZCF', 'GR'],
  1261. [fixedFlag.MEASURE]: ['CSXMHJ'],
  1262. [fixedFlag.CONSTRUCTION_ORGANIZATION]: ['ZZCSF'],
  1263. [fixedFlag.CONSTRUCTION_TECH]: ['JSCSF', 'JSCS_RGF', 'JSCS_CLF', 'JSCS_JXF', 'JSCS_ZCF', 'JSCS_GR'],
  1264. [fixedFlag.CHARGE]: ['GF'],
  1265. [fixedFlag.TAX]: ['SJ', 'SJHJ']
  1266. };
  1267. const match = CycleMap[flag];
  1268. if (!match) {
  1269. return false;
  1270. }
  1271. return match.some(item => bills.calcBase.match(new RegExp(`\\b${item}\\b`)));
  1272. }
  1273. //转换计算基数
  1274. //1.有子项数据,则清空基数
  1275. //2.引用的基数造成自身循环,比如分部分项部分引用了FBFXHJ
  1276. //3.行代号引用转换为ID引用
  1277. //4.对应字典代号转换,对应字典里找不到则设置成金额
  1278. function transformCalcBase(billsData) {
  1279. //行代号 - ID映射
  1280. let rowCodeMap = {};
  1281. billsData.forEach(data => {
  1282. if (data.rowCode) {
  1283. rowCodeMap[data.rowCode] = data.ID;
  1284. }
  1285. });
  1286. for (let bills of billsData) {
  1287. if (!bills.calcBase || bills.ignoreValidator) {
  1288. continue;
  1289. }
  1290. let sub = billsData.find(data => data.ParentID === bills.ID);
  1291. //有子项数据,则清空基数,费率
  1292. if (sub) {
  1293. bills.calcBase = '';
  1294. bills.feeRate = '';
  1295. continue;
  1296. }
  1297. if (typeof bills.calcBase !== 'string') {
  1298. bills.calcBase = String(bills.calcBase);
  1299. }
  1300. // 引用的基数造成自循环,清空基数
  1301. const isCycle = isCalcBaseCycle(bills);
  1302. if (isCycle) {
  1303. bills.calcBase = '';
  1304. continue;
  1305. }
  1306. //提取基数
  1307. bills.calcBase = bills.calcBase.replace(/\s/g, '');
  1308. let bases = bills.calcBase.split(/[\+\-\*\/]/g);
  1309. //提取操作符
  1310. let oprs = bills.calcBase.match(/[\+\-\*\/]/g);
  1311. //转换后的基数
  1312. let newBase = [];
  1313. let illegal = false; //不合法
  1314. for (let base of bases) {
  1315. if (rowCodeMap[base]) { //行引用
  1316. newBase.push(`@${rowCodeMap[base]}`);
  1317. } else if (CalcBaseMap[base]) { //基数字典
  1318. newBase.push(CalcBaseMap[base]);
  1319. } else if (!isNaN(base)) {
  1320. newBase.push(base);
  1321. } else { //都没匹配到,说明软件无法识别此基数
  1322. illegal = true;
  1323. break;
  1324. }
  1325. };
  1326. if (illegal) {
  1327. let fee = getFee(bills.fees, ['common', 'totalFee']);
  1328. let feeRate = bills.feeRate && parseFloat(bills.feeRate) !== 0 ? parseFloat(bills.feeRate) : 0;
  1329. if (fee && parseFloat(fee) !== 0 && feeRate) {
  1330. bills.calcBase = scMathUtil.roundForObj(parseFloat(fee) * 100 / feeRate, 2);
  1331. } else {
  1332. bills.calcBase = fee !== '0' ? fee : '';
  1333. }
  1334. } else {
  1335. let newCalcBase = '';
  1336. for (let i = 0; i < newBase.length; i++) {
  1337. newCalcBase += newBase[i];
  1338. if (oprs && oprs[i]) {
  1339. newCalcBase += oprs[i];
  1340. }
  1341. }
  1342. bills.calcBase = newCalcBase;
  1343. }
  1344. }
  1345. }
  1346. //转换单位工程的数据(直接可插入数据库的数据),返回{tender: {}, bills: [], ration: [], rationGLJ: [], projectGLJ: [], unitPrice: [], mixRatio: []}
  1347. async function transformTender(tenderData, IDPlaceholder, needfulTemplate) {
  1348. let detailData = await transformBills(tenderData, IDPlaceholder, needfulTemplate);
  1349. //提取需要插入的单位工程数据
  1350. let tender = {
  1351. ID: tenderData.ID,
  1352. ParentID: tenderData.ParentID,
  1353. NextSiblingID: tenderData.NextSiblingID,
  1354. code: tenderData.code,
  1355. name: tenderData.name,
  1356. projType: tenderData.projType,
  1357. property: tenderData.property,
  1358. projectFeature: tenderData.projectFeature,
  1359. engineering: tenderData.engineering,
  1360. defaultRationLib: tenderData.defaultRationLib,
  1361. rationLibIDs: tenderData.rationLibIDs,
  1362. gljLibIDs: tenderData.gljLibIDs,
  1363. shareInfo: []
  1364. };
  1365. tender.property.gljAdjustType = getAdjustType(tenderData);
  1366. detailData.tender = tender;
  1367. return detailData;
  1368. }
  1369. //转换清单数据
  1370. async function transformBills(tenderData, IDPlaceholder, needfulTemplate) {
  1371. //处理单位工程费用汇总的清单,这一部分没有靠谱的规则,特殊处理。
  1372. setupFeeSummary(tenderData.feeSummary, needfulTemplate);
  1373. //处理添加清单数据
  1374. setupBills(tenderData, needfulTemplate);
  1375. //转换清单基数表达式
  1376. transformCalcBase(needfulTemplate);
  1377. //转换提取需要插入的详细数据
  1378. let detailData = transformDetail(tenderData, needfulTemplate, IDPlaceholder);
  1379. //console.log(detailData);
  1380. return detailData;
  1381. }
  1382. //提取转换后的定额、定额人材机、人材机汇总、单价文件、组成物数据
  1383. function transformDetail(tenderData, billsData, IDPlaceholder) {
  1384. let rst = {
  1385. bills: [], //清单
  1386. ration: [], //定额
  1387. rationGLJ: [], //定额人材机
  1388. rationCoe: [], //定额系数,全为默认
  1389. projectGLJ: [], //项目人材机
  1390. contractorList: [], //承包人材料
  1391. bidEvaluationList: [], //评标材料
  1392. evaluationList: [], //暂估材料
  1393. unitPrice: [], //单价文件
  1394. mixRatio: [] //组成物
  1395. };
  1396. //工料机汇总code-数据映射
  1397. // 项目人材机customCode、code-原始数据映射,有的导入数据中,有一部分关联自生成材料号CX,有的关联代码...
  1398. // 因此customCode、code都需要跟原始数据映射,通过customCode取不到数据的时候,通过orgCode获取
  1399. let projectGLJMap = {};
  1400. // 代码映射
  1401. let customCodeMap = {};
  1402. // 原始代码映射
  1403. let originCodeMap = {};
  1404. function getGLJByMap(code) {
  1405. return customCodeMap[code] || originCodeMap[code] || null;
  1406. }
  1407. //投标文件才需要导入定额等数据
  1408. if (importFileKind === FileKind.tender) {
  1409. tenderData.gljSummary.forEach(pGLJ => {
  1410. pGLJ.project_id = tenderData.ID;
  1411. pGLJ.id = IDPlaceholder.projectGLJ++;
  1412. // 如果人材机数据的类型为空,默认设置成201先,具体需要后台匹配
  1413. pGLJ.type = pGLJ.type || 201;
  1414. pGLJ.shortName = pGLJ.shortName || '材';
  1415. //gljCodeMap[pGLJ.code] = pGLJ;
  1416. //projectGLJMap[pGLJ.customCode] = pGLJ;
  1417. //projectGLJMap[pGLJ.code] = pGLJ;
  1418. customCodeMap[pGLJ.customCode] = pGLJ;
  1419. originCodeMap[pGLJ.code] = pGLJ;
  1420. });
  1421. //处理项目人材机数据
  1422. tenderData.gljSummary.forEach(pGLJ => {
  1423. //组成物数据
  1424. pGLJ.ratios.forEach(ratio => {
  1425. //let matchData = projectGLJMap[ratio.code];
  1426. let matchData = getGLJByMap(ratio.code);
  1427. ratio.code = matchData.code;
  1428. ratio.projectGLJID = pGLJ.id; //后端查找标准数据后,方便更新组成物数据
  1429. ratio.id = IDPlaceholder.ratio++;
  1430. ratio.unit_price_file_id = tenderData.property.unitPriceFile.id;
  1431. ratio.unit = matchData ? matchData.unit : '';
  1432. ratio.name = matchData ? matchData.name : '';
  1433. ratio.specs = matchData ? matchData.specs : '';
  1434. ratio.type = matchData ? matchData.type : 1;
  1435. ratio.connect_key = [pGLJ.code || 'null', pGLJ.name || 'null', pGLJ.specs || 'null', pGLJ.unit || 'null', pGLJ.type].join('|-|');
  1436. rst.mixRatio.push(ratio);
  1437. });
  1438. delete pGLJ.ratios;
  1439. rst.projectGLJ.push(pGLJ);
  1440. //单价文件数据
  1441. rst.unitPrice.push(getUnitPrice(pGLJ));
  1442. });
  1443. // 处理承包人材料(差额/指数)法表
  1444. handleContractorList();
  1445. // 处理评标材料
  1446. handleGLJRelatedList(tenderData.evalBidSummary, rst.bidEvaluationList, 'is_eval_material');
  1447. //处理定额数据
  1448. //获取含有定额数据的清单
  1449. handleRation(billsData);
  1450. }
  1451. // 处理暂估价材料:变更 :导入招标
  1452. handleGLJRelatedList(tenderData.evalSummary, rst.evaluationList, 'is_evaluate');
  1453. // 处理与项目人材机关联的承包人材料
  1454. function handleContractorList() {
  1455. const contractorType = getAdjustType(tenderData);
  1456. const contractorData = contractorType === AdjustType.info ? tenderData.differentiaSummary : tenderData.exponentialSummary;
  1457. handleGLJRelatedList(contractorData, rst.contractorList, 'is_contractor_material');
  1458. }
  1459. // 处理与项目人材机关联的承包人材料、评标材料、暂估材料
  1460. function handleGLJRelatedList(list, container, relatedType) {
  1461. list.forEach(data => {
  1462. data.ID = uuid.v1();
  1463. data.projectID = tenderData.ID;
  1464. data.projectGLJID = -1;
  1465. if (typeof data.seq === 'undefined') {
  1466. data.seq = data.code;
  1467. }
  1468. //const projectGLJ = projectGLJMap[data.code];
  1469. const projectGLJ = getGLJByMap(data.code);
  1470. if (projectGLJ) {
  1471. projectGLJ[relatedType] = 1;
  1472. data.is_related = 1;
  1473. data.projectGLJID = projectGLJ.id;
  1474. }
  1475. container.push(data);
  1476. });
  1477. }
  1478. //处理清单 设置必要数据 删除无用属性
  1479. billsData.forEach(bills => {
  1480. //处理综合单价
  1481. //1.没有子清单,且没有综合单价,则综合单价=综合合价/工程量
  1482. let children = billsData.find(data => data.ParentID === bills.ID),
  1483. unitFee = getFee(bills.fees, ['common', 'unitFee']),
  1484. totalFee = getFee(bills.fees, ['common', 'totalFee']);
  1485. if (!children && !parseFloat(unitFee) && totalFee && parseFloat(totalFee)) {
  1486. //不存工程量
  1487. if (!bills.quantity || !parseFloat(bills.quantity)) {
  1488. unitFee = totalFee;
  1489. //源不存在工程量,没有计算基数、但是却有综合合价,工程量要设置为1
  1490. if (!bills.calcBase) {
  1491. bills.quantity = '1';
  1492. }
  1493. } else {
  1494. //综合合价的小数位数
  1495. let totalFeeDecimal = totalFee.match(/\.\d+/);
  1496. unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, totalFeeDecimal
  1497. ? totalFeeDecimal[0] : 0);
  1498. }
  1499. let commonFee = bills.fees.find(fee => fee.fieldName === 'common');
  1500. if (commonFee) {
  1501. commonFee.unitFee = unitFee;
  1502. }
  1503. }
  1504. bills.projectID = tenderData.ID;
  1505. bills.quantityEXP = bills.quantity;
  1506. delete bills.items;
  1507. delete bills.rations;
  1508. rst.bills.push(bills);
  1509. // 如果导入招标、控制价文件、每个分项底下自动生成一条空定额
  1510. if (importFileKind !== FileKind.tender && bills.type === billType.FX) {
  1511. const emptyRation = {
  1512. projectID: tenderData.ID,
  1513. ID: uuid.v1(),
  1514. billsItemID: bills.ID,
  1515. serialNo: 1,
  1516. type: rationType.ration,
  1517. };
  1518. rst.ration.push(emptyRation);
  1519. }
  1520. });
  1521. return rst;
  1522. function handleRation(billsData) {
  1523. let billsHasRations = billsData.filter(bills => Array.isArray(bills.rations) && bills.rations.length);
  1524. billsHasRations.forEach(bills => {
  1525. //处理定额
  1526. bills.rations.forEach(ration => {
  1527. ration.programID = getProgramID(ration.name, NameProgramMapping, tenderData.property.projectEngineering);
  1528. ration.ID = uuid.v1();
  1529. ration.projectID = tenderData.ID;
  1530. ration.billsItemID = bills.ID;
  1531. //含量:定额工程量/清单工程量
  1532. if (!bills.quantity || !ration.quantity) {
  1533. ration.contain = '0';
  1534. } else {
  1535. let tempV = ration.quantity / bills.quantity;
  1536. ration.contain = isFinite(tempV) ? scMathUtil.roundForObj(tempV, 6) : '0';
  1537. }
  1538. //处理定额人材机,添加需要的数据
  1539. ration.rationGljs.forEach(rGLJ => {
  1540. //let matchGLJ = projectGLJMap[rGLJ.code];
  1541. let matchGLJ = getGLJByMap(rGLJ.code);
  1542. if (matchGLJ) {
  1543. rGLJ.projectGLJID = matchGLJ.id;
  1544. rGLJ.code = matchGLJ.code;
  1545. rGLJ.type = matchGLJ.type;
  1546. rGLJ.shortName = matchGLJ.shortName;
  1547. rGLJ.name = matchGLJ.name;
  1548. rGLJ.original_code = matchGLJ.original_code;
  1549. rGLJ.unit = matchGLJ.unit;
  1550. rGLJ.specs = matchGLJ.specs;
  1551. }
  1552. rGLJ.ID = uuid.v1();
  1553. rGLJ.projectID = tenderData.ID;
  1554. rGLJ.billsItemID = bills.ID;
  1555. rGLJ.rationID = ration.ID;
  1556. rGLJ.rationCode = ration.code; //暂时跟定额编码关联,后端好匹配标准数据
  1557. rGLJ.rationItemQuantity = rGLJ.quantity; //定额消耗,暂时取消耗量,需要后端匹配标准数据后更新
  1558. rst.rationGLJ.push(rGLJ);
  1559. });
  1560. delete ration.rationGljs;
  1561. rst.ration.push(ration);
  1562. rst.rationCoe.push(getRationCoe(ration));
  1563. });
  1564. });
  1565. }
  1566. function getRationCoe(ration) {
  1567. return {
  1568. projectID: ration.projectID,
  1569. rationID: ration.ID,
  1570. coeID: -1,
  1571. ID: uuid.v1(),
  1572. seq: 1, //以前排序有的字段,暂时没什么用,不过还是赋上一个值
  1573. name: '自定义系数',
  1574. content: '人工×1,材料×1,机械×1,主材×1,设备×1',
  1575. coes: [
  1576. { amount: 1, operator: '*', gljCode: null, coeType: '定额' },
  1577. { amount: 1, operator: '*', gljCode: null, coeType: '人工' },
  1578. { amount: 1, operator: '*', gljCode: null, coeType: '材料' },
  1579. { amount: 1, operator: '*', gljCode: null, coeType: '机械' },
  1580. { amount: 1, operator: '*', gljCode: null, coeType: '主材' },
  1581. { amount: 1, operator: '*', gljCode: null, coeType: '设备' },
  1582. ],
  1583. option_list: []
  1584. }
  1585. }
  1586. function getUnitPrice(projectGLJ) {
  1587. return {
  1588. projectGLJID: projectGLJ.id, //做个标记,后端查找标准数据后,方便更新组成物数据
  1589. unit_price_file_id: tenderData.property.unitPriceFile.id,
  1590. id: IDPlaceholder.unitPrice++,
  1591. code: projectGLJ.code,
  1592. original_code: projectGLJ.original_code,
  1593. name: projectGLJ.name,
  1594. unit: projectGLJ.unit,
  1595. specs: projectGLJ.specs,
  1596. type: projectGLJ.type,
  1597. short_name: projectGLJ.shortName,
  1598. base_price: projectGLJ.base_price,
  1599. market_price: projectGLJ.market_price
  1600. };
  1601. }
  1602. }
  1603. //从xml文件中提取数据
  1604. async function extractData(file, escape = false) {
  1605. //将二进制文件转换成字符串
  1606. let xmlStr = await util.readAsTextSync(file);
  1607. if (escape) {
  1608. xmlStr = util.escapeXMLEntity(xmlStr);
  1609. }
  1610. //将xml格式良好的字符串转换成对象
  1611. let x2js = new X2JS();
  1612. let xmlObj = x2js.xml_str2json(xmlStr);
  1613. xmlObj = JSON.parse(util.restoreXMLEntity(JSON.stringify(xmlObj)));
  1614. if (!xmlObj) {
  1615. throw '无有效数据。';
  1616. }
  1617. //console.log(xmlObj);
  1618. //提取数据
  1619. return loadProject(xmlObj);
  1620. };
  1621. //把数据转换成适应项目的数据
  1622. async function transformData(xmlObj) {
  1623. //获取占位ID数据
  1624. countData.unitPriceCount = countData.projectGLJCount;
  1625. if (importFileKind !== FileKind.tender) {
  1626. countData = {
  1627. projectCount: countData.projectCount,
  1628. unitPriceFileCount: countData.unitPriceFileCount
  1629. };
  1630. }
  1631. let IDPlaceholder = await ajaxPost('/pm/import/getProjectPlaceholder', countData);
  1632. xmlObj.ID = IDPlaceholder.project++;
  1633. //获取到的转换后的最终上传数据
  1634. let postConstructData = {
  1635. isTwoLevel: !!xmlObj.isTwoLevel,
  1636. ID: xmlObj.ID,
  1637. ParentID: xmlObj.ParentID,
  1638. NextSiblingID: xmlObj.NextSiblingID,
  1639. preID: xmlObj.preID,
  1640. name: xmlObj.name,
  1641. basicInformation: xmlObj.basicInformation,
  1642. projType: xmlObj.projType,
  1643. property: xmlObj.property,
  1644. shareInfo: [],
  1645. engs: []
  1646. };
  1647. // 所有的清单模板库ID
  1648. let allTemplateLibIDs = [];
  1649. xmlObj.engs.forEach(eng => {
  1650. eng.tenders.forEach(tender => {
  1651. let templateLibID = tender.property.templateLibID;
  1652. if (!allTemplateLibIDs.includes(templateLibID)) {
  1653. allTemplateLibIDs.push(templateLibID);
  1654. }
  1655. });
  1656. });
  1657. // 模板映射:{[templateLibID]: data}
  1658. let templateMapping = await ajaxPost('/template/bills/api/getNeedfulTemplate', { allTemplateLibIDs });
  1659. for (let i = 0; i < xmlObj.engs.length; i++) {
  1660. let curEng = xmlObj.engs[i],
  1661. preEng = postConstructData.engs[i - 1];
  1662. curEng.ID = IDPlaceholder.project++;
  1663. curEng.ParentID = xmlObj.ID;
  1664. curEng.NextSiblingID = -1;
  1665. if (preEng) {
  1666. preEng.NextSiblingID = curEng.ID;
  1667. }
  1668. let postEngData = {
  1669. ID: curEng.ID,
  1670. ParentID: curEng.ParentID,
  1671. NextSiblingID: curEng.NextSiblingID,
  1672. code: curEng.code,
  1673. name: curEng.name,
  1674. projType: curEng.projType,
  1675. shareInfo: [],
  1676. tenders: []
  1677. };
  1678. postConstructData.engs.push(postEngData);
  1679. for (let j = 0; j < curEng.tenders.length; j++) {
  1680. let curTender = curEng.tenders[j],
  1681. preTender = postEngData.tenders[j - 1];
  1682. curTender.ID = IDPlaceholder.project++;
  1683. curTender.ParentID = curEng.ID;
  1684. curTender.NextSiblingID = -1;
  1685. curTender.property.unitPriceFile.id = IDPlaceholder.unitPriceFile++;
  1686. if (preTender) {
  1687. preTender.tender.NextSiblingID = curTender.ID;
  1688. }
  1689. //提取详细数据
  1690. let needfulTemplate = _.cloneDeep(templateMapping[curTender.property.templateLibID]);
  1691. // 重设模板树结构数据
  1692. BILLS_UTIL.resetTreeData(needfulTemplate, uuid.v1);
  1693. let postTenderData = await transformTender(curTender, IDPlaceholder, needfulTemplate);
  1694. postTenderData.tender.property.rootProjectID = postConstructData.ID;
  1695. postEngData.tenders.push(postTenderData);
  1696. }
  1697. }
  1698. //console.log(postConstructData);
  1699. return postConstructData;
  1700. };
  1701. // 接受上传的文件类型(不同的省份可以上传的文件不同)
  1702. const accept = ['.xml', '.qtf'];
  1703. return {
  1704. accept,
  1705. extractData,
  1706. transformData
  1707. };
  1708. })();