importStandardInterface.js 88 KB

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