importStandardInterface.js 80 KB

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