importStandardInterface.js 85 KB

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