importStandardInterface.js 70 KB

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