importStandardInterface.js 91 KB

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