importStandardInterface.js 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475
  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, ['_原始定额编号']).replace('换', ''),
  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. customCode: code, //处理自定义的代码 (有的公司定额人材机代码、人材机代码是用自动生成的代码)
  761. code: orgCode,
  762. original_code: orgCode,
  763. name: getValue(gljSrc, ['_名称']),
  764. specs: getValue(gljSrc, ['_规格']),
  765. unit: getValue(gljSrc, ['_单位']),
  766. supply: getValue(gljSrc, ['_供应方式']) == '2' ? 2 : 0, //不是完全甲供就取自行采购
  767. is_evaluate: getValue(gljSrc, ['_暂估材料标志']) === 'true' ? true : false,
  768. no_tax_eqp: getValue(gljSrc, ['_不计税设备标志']) === 'true' ? true : false,
  769. base_price: getValue(gljSrc, ['_定额价']),
  770. market_price: getValue(gljSrc, ['_市场价']),
  771. originPlace: getValue(gljSrc, ['_产地']),
  772. vender: getValue(gljSrc, ['_厂家']),
  773. qualityGrace: getValue(gljSrc, ['_质量等级']),
  774. brand: getValue(gljSrc, ['_品牌']),
  775. remark: getValue(gljSrc, ['_备注'])
  776. };
  777. if (MaterialMap[getValue(gljSrc, ['_主要材料类别'])]) {
  778. gljData.materialType = MaterialMap[getValue(gljSrc, ['_主要材料类别'])];
  779. gljData.materialCoe = getValue(gljSrc, ['_主要材料单位系数']);
  780. }
  781. let typeData = getGljTypeData(getValue(gljSrc, ['_费用类别']), getValue(gljSrc, ['_配比类别']));
  782. if (typeData) {
  783. gljData.type = typeData.type;
  784. gljData.shortName = typeData.shortName;
  785. }
  786. //人材机配比
  787. let ratioSrc = arrayValue(gljSrc, ['人材机配比']);
  788. gljData.ratios = ratioSrc.map(rSrc => {
  789. countData.ratioCount++;
  790. return {
  791. code: getValue(rSrc, ['_明细材料代码']),
  792. consumption: getValue(rSrc, ['_数量'])
  793. }
  794. });
  795. return gljData;
  796. });
  797. }
  798. //-------------------------提取数据后的数据处理
  799. function getFlag(data) {
  800. return data.flags && data.flags[0] && data.flags[0].flag || 0;
  801. }
  802. let toMatches = [
  803. {reg: /分部分项/, flag: fixedFlag.SUB_ENGINERRING},
  804. {reg: /^措施项目/, flag: fixedFlag.MEASURE},
  805. {reg: /技术措施/, flag: fixedFlag.CONSTRUCTION_TECH},
  806. {reg: /组织措施/, flag: fixedFlag.CONSTRUCTION_ORGANIZATION},
  807. {reg: /组织措施/, flag: fixedFlag.CONSTRUCTION_ORGANIZATION},
  808. {reg: /安全文明/, flag: fixedFlag.SAFETY_CONSTRUCTION},
  809. {reg: /其他项目/, flag: fixedFlag.OTHER},
  810. {reg: /暂列金额/, flag: fixedFlag.PROVISIONAL},
  811. {reg: /暂估价/, flag: fixedFlag.ESTIMATE},
  812. {reg: /计日工/, flag: fixedFlag.DAYWORK},
  813. {reg: /总承包服务/, flag: fixedFlag.TURN_KEY_CONTRACT},
  814. {reg: /索赔(?:及|与|和)现场签证/, flag: fixedFlag.TURN_KEY_CONTRACT},
  815. {reg: /规费/, flag: fixedFlag.CHARGE},
  816. {reg: /税金/, flag: fixedFlag.TAX},
  817. {reg: /增值税/, flag: fixedFlag.ADDED_VALUE_TAX},
  818. {reg: /^附加税/, flag: fixedFlag.ADDITIONAL_TAX},
  819. {reg: /环境保护税/, flag: fixedFlag.ENVIRONMENTAL_PROTECTION_TAX},
  820. {reg: /(?:合\s*价)|(?:工程造价)/, flag: fixedFlag.ENGINEERINGCOST},
  821. ];
  822. //处理单位工程费用汇总的清单,这一部分没有靠谱的规则,特殊处理并添加相关清单
  823. function setupFeeSummary(feeSummary, needfulTemplate) {
  824. let preDXFY = null, //记录上一条添加的大项费用
  825. preSubTax = null; //记录上一条添加的附加税子项(特殊处理城市xx、教育xx附加...名称的清单)
  826. let addtionalTax = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.ADDITIONAL_TAX), //附加税
  827. engineeringCost = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.ENGINEERINGCOST); //工程造价
  828. for (let feeBills of feeSummary) {
  829. //匹配固定的附加税子项
  830. if (addtionalTax &&
  831. (/城市维护建设/.test(feeBills.name) ||
  832. /教育费附加/.test(feeBills.name) ||
  833. /地方教育附加/.test(feeBills.name))
  834. ) {
  835. let subTaxData ={
  836. ID: uuid.v1(),
  837. ParentID: addtionalTax.ID,
  838. NextSiblingID: -1,
  839. name: feeBills.name,
  840. feeRate: feeBills.feeRate,
  841. };
  842. if (importFileKind === FileKind.tender) {
  843. subTaxData.rowCode = feeBills.rowCode;
  844. subTaxData.fees = feeBills.fees;
  845. }
  846. if (preSubTax) {
  847. preSubTax.NextSiblingID = subTaxData.ID;
  848. }
  849. needfulTemplate.push(subTaxData);
  850. preSubTax = subTaxData;
  851. } else { //匹配固定项
  852. let isMatched = false;
  853. //匹配固定项
  854. for (let match of toMatches) {
  855. if (!match.reg.test(feeBills.name)) {
  856. continue;
  857. }
  858. let findBills = needfulTemplate.find(nData => getFlag(nData) === match.flag);
  859. if (!findBills) {
  860. //如果模板中没有安全文明施工费,计价汇总行中安全文明施工费,将其设置为组织清单子项
  861. if (/安全文明施工/.test(feeBills.name)) {
  862. let fixedCSXM = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.CONSTRUCTION_ORGANIZATION);
  863. if (fixedCSXM) {
  864. needfulTemplate.push({
  865. ID: uuid.v1(),
  866. ParentID: fixedCSXM.ID,
  867. NextSiblingID: -1,
  868. name: feeBills.name,
  869. calcBase: feeBills.calcBase,
  870. feeRate: feeBills.feeRate,
  871. });
  872. isMatched = true;
  873. break; //不添加到大项费用
  874. }
  875. }
  876. continue;
  877. }
  878. isMatched = true;
  879. findBills.calcBase = feeBills.calcBase;
  880. findBills.feeRate = feeBills.feeRate;
  881. //后台配置的feeRateID优先级比feeRate高,导入数据有费率值时,需要清空这个配置
  882. if (findBills.feeRate && parseFloat(findBills.feeRate) !== 0) {
  883. findBills.feeRateID = null;
  884. }
  885. if (importFileKind === FileKind.tender) {
  886. findBills.rowCode = feeBills.rowCode;
  887. findBills.fees = feeBills.fees;
  888. }
  889. break;
  890. }
  891. //匹配不到固定项,认为是大项费用
  892. if (!isMatched) {
  893. let dxfyData = {
  894. ID: uuid.v1(),
  895. ParentID: -1,
  896. NextSiblingID: -1,
  897. name: feeBills.name,
  898. calcBase: feeBills.calcBase,
  899. feeRate: feeBills.feeRate,
  900. };
  901. if (importFileKind === FileKind.tender) {
  902. dxfyData.rowCode = feeBills.rowCode;
  903. dxfyData.fees = feeBills.fees;
  904. }
  905. if (!preDXFY) {
  906. preDXFY = engineeringCost;
  907. }
  908. preDXFY.NextSiblingID = dxfyData.ID;
  909. needfulTemplate.push(dxfyData);
  910. preDXFY = dxfyData;
  911. }
  912. }
  913. }
  914. }
  915. //处理、添加清单
  916. function setupBills(tenderData, billsTarget) {
  917. //规费和税金 这个地方不靠谱,先特殊处理(无法兼容所有情况)
  918. //1.如果在清单中出现(匹配名称相关关键字),则更新数据
  919. //2.否则新增(在税金出现前,全作为规费的子清单,否则作为税金子清单)
  920. let charge = null,
  921. tax = null,
  922. additionalTax = null;
  923. for (let i = 0; i < tenderData.chargeTax.length; i++) {
  924. let curBills = tenderData.chargeTax[i];
  925. let matchBills = billsTarget.find(d => (d.rowCode && d.rowCode === curBills.rowCode) || d.name === curBills.name);
  926. //匹配到,更新
  927. if (matchBills) {
  928. if (getFlag(matchBills) === fixedFlag.CHARGE) {
  929. charge = matchBills;
  930. } else if (getFlag(matchBills) === fixedFlag.TAX) {
  931. tax = matchBills;
  932. } else if (getFlag(matchBills) === fixedFlag.ADDITIONAL_TAX) {
  933. additionalTax = matchBills;
  934. }
  935. matchBills.calcBase = curBills.calcBase;
  936. matchBills.feeRate = curBills.feeRate;
  937. matchBills.fees = curBills.fees || [];
  938. } else { //新增
  939. if (!charge && !tax) {
  940. continue;
  941. }
  942. //存在规费,还未找到税金,后面数据作为规费的子项 已找到税金,后面数据作为税金子项
  943. let curParent = !tax ? charge : tax;
  944. //特殊处理"城市维护建设税" "教育费附加" "地方教育附加",这三项固定设为税金下附加税的子项
  945. if (additionalTax &&
  946. (/城市维护建设/.test(curBills.name) ||
  947. /教育费附加/.test(curBills.name) ||
  948. /地方教育附加/.test(curBills.name))) {
  949. curParent = additionalTax;
  950. }
  951. curBills.ID = uuid.v1();
  952. curBills.NextSiblingID = -1;
  953. curBills.ParentID = curParent.ID;
  954. let pre = billsTarget.find(d => d.ParentID === curParent.ID && d.NextSiblingID === -1);
  955. if (pre) {
  956. pre.NextSiblingID = curBills.ID;
  957. }
  958. billsTarget.push(curBills);
  959. if (!additionalTax && /^附加税/.test(curBills.name)) {
  960. additionalTax = curBills;
  961. }
  962. }
  963. }
  964. //分部分项
  965. addFixedBlock(fixedFlag.SUB_ENGINERRING, tenderData.fbfx);
  966. //措施项目
  967. addFixedBlock(fixedFlag.MEASURE, null, tenderData.csxm.fees);
  968. //组织措施 //特殊处理子项
  969. //需要添加的组织措施子项
  970. function updateZZCSItem(org, tar) {
  971. for(let [k, v] of Object.entries(tar)) {
  972. org[k] = v;
  973. }
  974. }
  975. let zzcsSubs = [];
  976. let fixedOrganization = billsTarget.find(data => /组织措施费/.test(data.name)),
  977. fixedSafe = billsTarget.find(data => /安全文明/.test(data.name)),
  978. fixedProjectComplete = billsTarget.find(data => /建设工程竣工档案编制/.test(data.name)),
  979. fixedHouseQuality = billsTarget.find(data => /住宅工程质量分户验收/.test(data.name)),
  980. fixedZZCS = billsTarget.find(data => getFlag(data) === fixedFlag.CONSTRUCTION_ORGANIZATION),
  981. lastItem = billsTarget.find(data => data.ParentID === fixedZZCS.ID && data.NextSiblingID === -1);
  982. for (let item of tenderData.csxm.zzcs.items) {
  983. if (/组织措施费/.test(item.name) && fixedOrganization) {
  984. updateZZCSItem(fixedOrganization, item);
  985. } else if (/安全文明/.test(item.name) && fixedSafe) {
  986. updateZZCSItem(fixedSafe, item);
  987. } else if (/建设工程竣工档案/.test(item.name) && fixedProjectComplete) {
  988. updateZZCSItem(fixedProjectComplete, item);
  989. } else if (/住宅工程质量分户验收/.test(item.name) && fixedHouseQuality) {
  990. updateZZCSItem(fixedHouseQuality, item);
  991. } else {
  992. zzcsSubs.push(item);
  993. }
  994. }
  995. if (zzcsSubs.length && lastItem) {
  996. zzcsSubs[0].NextSiblingID = lastItem.ID;
  997. }
  998. addFixedBlock(fixedFlag.CONSTRUCTION_ORGANIZATION, zzcsSubs, tenderData.csxm.zzcs.fees);
  999. //技术措施
  1000. addFixedBlock(fixedFlag.CONSTRUCTION_TECH, tenderData.csxm.jscs.items, tenderData.csxm.jscs.fees);
  1001. //暂列金额
  1002. addFixedBlock(fixedFlag.PROVISIONAL, tenderData.other.provisional.items, tenderData.other.provisional.fees);
  1003. //专业工程暂估价
  1004. addFixedBlock(fixedFlag.ENGINEERING_ESITIMATE, tenderData.other.engineeringPro.items, tenderData.other.engineeringPro.fees);
  1005. //计日工
  1006. addFixedBlock(fixedFlag.DAYWORK, null, tenderData.other.dayWork.fees);
  1007. //人工
  1008. addFixedBlock(fixedFlag.LABOUR, tenderData.other.dayWork.labour);
  1009. //材料
  1010. addFixedBlock(fixedFlag.MATERIAL,tenderData.other.dayWork.material);
  1011. //机械
  1012. addFixedBlock(fixedFlag.MACHINE, tenderData.other.dayWork.machine);
  1013. //总承包服务费
  1014. addFixedBlock(fixedFlag.TURN_KEY_CONTRACT, tenderData.other.service.items, tenderData.other.service.fees);
  1015. //索赔
  1016. addFixedBlock(fixedFlag.CLAIM, tenderData.other.claim.items, tenderData.other.claim.fees);
  1017. //签证
  1018. addFixedBlock(fixedFlag.VISA, tenderData.other.visa.items, tenderData.other.visa.fees);
  1019. //其他
  1020. if (tenderData.other.others.items.length) {
  1021. //特殊处理材料(工程设备暂估价)
  1022. let materialProIdx = tenderData.other.others.items.findIndex(item => item.name === '材料(工程设备)暂估价');
  1023. if (~materialProIdx) {
  1024. let materialPro = tenderData.other.others.items.splice(materialProIdx, 1)[0];
  1025. let fixedMaterialPro = billsTarget.find(data => getFlag(data) === fixedFlag.MATERIAL_PROVISIONAL);
  1026. if (fixedMaterialPro) {
  1027. fixedMaterialPro.fees = materialPro.fees;
  1028. fixedMaterialPro.feeRate = materialPro.feeRate;
  1029. fixedMaterialPro.calcBase = materialPro.calcBase;
  1030. }
  1031. }
  1032. if (tenderData.other.others.items.length) {
  1033. let othersParent = {
  1034. ID: uuid.v1(),
  1035. NextSiblingID: -1,
  1036. name: '其他',
  1037. fees: tenderData.other.others.fees || []
  1038. };
  1039. addFixedBlock(fixedFlag.OTHER, [othersParent]);
  1040. addFixedBlock(othersParent, tenderData.other.others.items);
  1041. }
  1042. }
  1043. //删掉有feeRate的feeRateID
  1044. billsTarget.forEach(data => {
  1045. if (data.feeRate) {
  1046. data.feeRateID = null;
  1047. }
  1048. });
  1049. function addFixedBlock(flag, items, fees = null) {
  1050. let fixedBills = flag;
  1051. if (typeof flag === 'number') {
  1052. fixedBills = billsTarget.find(d => getFlag(d) === flag);
  1053. }
  1054. if (fixedBills) {
  1055. if (fees) {
  1056. fixedBills.fees = fees || [];
  1057. }
  1058. if (Array.isArray(items) && items.length) {
  1059. addBills(fixedBills.ID, items);
  1060. }
  1061. }
  1062. }
  1063. //设置清单的ID数据并添加清单到目标数组
  1064. function addBills(parentID, items) {
  1065. for (let i = 0; i < items.length; i++) {
  1066. let curBills = items[i],
  1067. preBills = items[i - 1];
  1068. curBills.ID = uuid.v1();
  1069. curBills.ParentID = parentID;
  1070. curBills.NextSiblingID = -1;
  1071. if (preBills) {
  1072. preBills.NextSiblingID = curBills.ID;
  1073. }
  1074. billsTarget.push(curBills);
  1075. if (curBills.items && curBills.items.length) {
  1076. addBills(curBills.ID, curBills.items);
  1077. }
  1078. }
  1079. }
  1080. }
  1081. //计算基数字典
  1082. const CalcBaseMap = {
  1083. FBFXHJ: '{分部分项工程费}',
  1084. RGF: '{分部分项定额人工费}',
  1085. CLF: '{分部分项定额材料费}',
  1086. JXF: '{分部分项定额施工机具使用费}',
  1087. ZCF: '{分部分项主材费}',
  1088. GR: '{分部分项人工工日}',
  1089. CSXMHJ: '{措施项目费}',
  1090. ZZCSF: '{组织措施项目费}',
  1091. JSCSF: '{技术措施项目费}',
  1092. JSCS_RGF: '{技术措施项目定额人工费}',
  1093. JSCS_CLF: '{技术措施项目定额材料费}',
  1094. JSCS_JXF: '{技术措施项目定额施工机具使用费}',
  1095. JSCS_ZCF: '{技术措施项目主材费}',
  1096. JSCS_GR: '{技术措施项目人工工日}',
  1097. JZMZ: '{建筑面积}',
  1098. RCJJC: '{人材机价差}',
  1099. RGJC: '{人工价差}',
  1100. CLJC: '{材料价差}',
  1101. JXJC: '{机械价差}',
  1102. JRGLF: '{甲供人工费}',
  1103. JGCLF: '{甲供材料费}',
  1104. JGJXF: '{甲供施工机具使用费}',
  1105. JGZCF: '{甲供主材费}',
  1106. FBF: '{分包费}',
  1107. FBRGF: '{分包定额人工费}',
  1108. FBCLF: '{分包定额材料费}',
  1109. FBJXF: '{分包定额机械费}',
  1110. FBZCF: '{分包主材费}',
  1111. FBSBF: '{分包设备费}',
  1112. FBGR: '{分包人工工日}',
  1113. QTXMHJ: '{其他项目费}',
  1114. GF: '{规费}',
  1115. SJ: '{税金}',
  1116. SJHJ: '{税金}',
  1117. };
  1118. //转换计算基数
  1119. //1.有子项数据,则清空基数
  1120. //2.行代号引用转换为ID引用
  1121. //3.对应字典代号转换,对应字典里找不到则设置成金额
  1122. function transformCalcBase(billsData) {
  1123. //行代号 - ID映射
  1124. let rowCodeMap = {};
  1125. billsData.forEach(data => {
  1126. if (data.rowCode) {
  1127. rowCodeMap[data.rowCode] = data.ID;
  1128. }
  1129. });
  1130. for (let bills of billsData) {
  1131. if (!bills.calcBase) {
  1132. continue;
  1133. }
  1134. let sub = billsData.find(data => data.ParentID === bills.ID);
  1135. //有子项数据,则清空基数,费率
  1136. if (sub) {
  1137. bills.calcBase = '';
  1138. bills.feeRate = '';
  1139. continue;
  1140. }
  1141. //提取基数
  1142. bills.calcBase = bills.calcBase.replace(/\s/g, '');
  1143. let bases = bills.calcBase.split(/[\+\-\*\/]/g);
  1144. //提取操作符
  1145. let oprs = bills.calcBase.match(/[\+\-\*\/]/g);
  1146. //转换后的基数
  1147. let newBase = [];
  1148. let illegal = false; //不合法
  1149. for (let base of bases) {
  1150. if (rowCodeMap[base]) { //行引用
  1151. newBase.push(`@${rowCodeMap[base]}`);
  1152. } else if (CalcBaseMap[base]) { //基数字典
  1153. /*illegal = true;
  1154. break;*/
  1155. newBase.push(CalcBaseMap[base]);
  1156. } else { //都没匹配到,说明软件无法识别此基数
  1157. illegal = true;
  1158. break;
  1159. }
  1160. };
  1161. if (illegal) {
  1162. let fee = getFee(bills.fees, ['common', 'totalFee']);
  1163. let feeRate = bills.feeRate && parseFloat(bills.feeRate) !== 0 ? parseFloat(bills.feeRate) : 0;
  1164. if (fee && parseFloat(fee) !== 0 && feeRate) {
  1165. bills.calcBase = scMathUtil.roundForObj(parseFloat(fee) * 100 / feeRate, 2);
  1166. } else {
  1167. bills.calcBase = fee !== '0' ? fee : '';
  1168. }
  1169. } else {
  1170. let newCalcBase = '';
  1171. for (let i = 0; i < newBase.length; i++) {
  1172. newCalcBase += newBase[i];
  1173. if (oprs && oprs[i]) {
  1174. newCalcBase += oprs[i];
  1175. }
  1176. }
  1177. bills.calcBase = newCalcBase;
  1178. }
  1179. }
  1180. }
  1181. //从xml文件中提取数据
  1182. this.extractData = async (file) => {
  1183. //将二进制文件转换成字符串
  1184. let xmlStr = await readAsTextSync(file);
  1185. //将xml格式良好的字符串转换成对象
  1186. let x2js = new X2JS();
  1187. let xmlObj = x2js.xml_str2json(xmlStr);
  1188. if (!xmlObj) {
  1189. throw '无有效数据。';
  1190. }
  1191. //console.log(xmlObj);
  1192. //提取数据
  1193. return loadProject(xmlObj);
  1194. };
  1195. //把数据转换成适应项目的数据
  1196. this.transformData = async (xmlObj) => {
  1197. //获取占位ID数据
  1198. countData.unitPriceCount = countData.projectGLJCount;
  1199. if (importFileKind !== FileKind.tender) {
  1200. countData = {
  1201. projectCount: countData.projectCount,
  1202. unitPriceFileCount: countData.unitPriceFileCount
  1203. };
  1204. }
  1205. let IDPlaceholder = await ajaxPost('/pm/import/getProjectPlaceholder', countData);
  1206. xmlObj.ID = IDPlaceholder.project++;
  1207. //获取到的转换后的最终上传数据
  1208. let postConstructData = {
  1209. ID: xmlObj.ID,
  1210. ParentID: xmlObj.ParentID,
  1211. NextSiblingID: xmlObj.NextSiblingID,
  1212. preID: xmlObj.preID,
  1213. name: xmlObj.name,
  1214. basicInformation: xmlObj.basicInformation,
  1215. projType: xmlObj.projType,
  1216. property: xmlObj.property,
  1217. shareInfo: [],
  1218. engs: []
  1219. };
  1220. for (let i = 0; i < xmlObj.engs.length; i++) {
  1221. let curEng = xmlObj.engs[i],
  1222. preEng = xmlObj.engs[i - 1];
  1223. curEng.ID = IDPlaceholder.project++;
  1224. curEng.ParentID = xmlObj.ID;
  1225. curEng.NextSiblingID = -1;
  1226. if (preEng) {
  1227. preEng.NextSiblingID = curEng.ID;
  1228. }
  1229. let postEngData = {
  1230. ID: curEng.ID,
  1231. ParentID: curEng.ParentID,
  1232. NextSiblingID: curEng.NextSiblingID,
  1233. name: curEng.name,
  1234. projType: curEng.projType,
  1235. shareInfo: [],
  1236. tenders: []
  1237. };
  1238. postConstructData.engs.push(postEngData);
  1239. for (let j = 0; j < curEng.tenders.length; j++) {
  1240. let curTender = curEng.tenders[j],
  1241. preTender = postEngData.tenders[j - 1];
  1242. curTender.ID = IDPlaceholder.project++;
  1243. curTender.ParentID = curEng.ID;
  1244. curTender.NextSiblingID = -1;
  1245. curTender.property.unitPriceFile.id = IDPlaceholder.unitPriceFile++;
  1246. if (preTender) {
  1247. preTender.tender.NextSiblingID = curTender.ID;
  1248. }
  1249. //提取详细数据
  1250. let postTenderData = await transformTender(curTender, IDPlaceholder);
  1251. postTenderData.tender.property.rootProjectID = postConstructData.ID;
  1252. postEngData.tenders.push(postTenderData);
  1253. }
  1254. }
  1255. console.log(postConstructData);
  1256. return postConstructData;
  1257. };
  1258. //转换单位工程的数据(直接可插入数据库的数据),返回{tender: {}, bills: [], ration: [], rationGLJ: [], projectGLJ: [], unitPrice: [], mixRatio: []}
  1259. async function transformTender(tenderData, IDPlaceholder) {
  1260. let detailData = await transformBills(tenderData, IDPlaceholder);
  1261. //提取需要插入的单位工程数据
  1262. let tender = {
  1263. ID: tenderData.ID,
  1264. ParentID: tenderData.ParentID,
  1265. NextSiblingID: tenderData.NextSiblingID,
  1266. name: tenderData.name,
  1267. projType: tenderData.projType,
  1268. property: tenderData.property,
  1269. projectFeature: tenderData.projectFeature,
  1270. engineering: tenderData.engineering,
  1271. defaultRationLib: tenderData.defaultRationLib,
  1272. rationLibIDs: tenderData.rationLibIDs,
  1273. gljLibIDs: tenderData.gljLibIDs,
  1274. shareInfo: []
  1275. };
  1276. detailData.tender = tender;
  1277. return detailData;
  1278. }
  1279. //转换清单数据
  1280. async function transformBills(tenderData, IDPlaceholder) {
  1281. //获取清单模板数据
  1282. let needfulTemplate = await ajaxPost('/template/bills/api/getNeedfulTemplate',
  1283. {templateLibID: tenderData.property.templateLibID});
  1284. //处理单位工程费用汇总的清单,这一部分没有靠谱的规则,特殊处理。
  1285. setupFeeSummary(tenderData.feeSummary, needfulTemplate);
  1286. //处理添加清单数据
  1287. setupBills(tenderData, needfulTemplate);
  1288. //转换清单基数表达式
  1289. transformCalcBase(needfulTemplate);
  1290. //转换提取需要插入的详细数据
  1291. let detailData = transformDetail(tenderData, needfulTemplate, IDPlaceholder);
  1292. //console.log(detailData);
  1293. return detailData;
  1294. }
  1295. //提取转换后的定额、定额人材机、人材机汇总、单价文件、组成物数据
  1296. function transformDetail(tenderData, billsData, IDPlaceholder) {
  1297. let rst = {
  1298. bills: [], //清单
  1299. ration: [], //定额
  1300. rationGLJ: [], //定额人材机
  1301. rationCoe: [], //定额系数,全为默认
  1302. projectGLJ: [], //项目人材机
  1303. unitPrice: [], //单价文件
  1304. mixRatio: [] //组成物
  1305. };
  1306. //工料机汇总code-数据映射
  1307. //let gljCodeMap = {};
  1308. //项目人材机customCode-原始代码数据映射
  1309. let projectGLJMap = {};
  1310. //投标文件才需要导入定额等数据
  1311. if (importFileKind === FileKind.tender) {
  1312. tenderData.gljSummary.forEach(pGLJ => {
  1313. pGLJ.project_id = tenderData.ID;
  1314. pGLJ.id = IDPlaceholder.projectGLJ++;
  1315. //gljCodeMap[pGLJ.code] = pGLJ;
  1316. projectGLJMap[pGLJ.customCode] = pGLJ;
  1317. });
  1318. //处理项目人材机数据
  1319. tenderData.gljSummary.forEach(pGLJ => {
  1320. //组成物数据
  1321. pGLJ.ratios.forEach(ratio => {
  1322. let matchData = projectGLJMap[ratio.code];
  1323. ratio.code = matchData.original_code;
  1324. ratio.projectGLJID = pGLJ.id; //后端查找标准数据后,方便更新组成物数据
  1325. ratio.id = IDPlaceholder.ratio++;
  1326. ratio.unit_price_file_id = tenderData.property.unitPriceFile.id;
  1327. ratio.unit = matchData ? matchData.unit : '';
  1328. ratio.name = matchData ? matchData.name : '';
  1329. ratio.specs = matchData ? matchData.specs : '';
  1330. ratio.type = matchData ? matchData.type : 1;
  1331. ratio.connect_key = [pGLJ.original_code || 'null', pGLJ.name || 'null', pGLJ.specs || 'null', pGLJ.unit || 'null', pGLJ.type].join('|-|');
  1332. rst.mixRatio.push(ratio);
  1333. });
  1334. delete pGLJ.ratios;
  1335. rst.projectGLJ.push(pGLJ);
  1336. //单价文件数据
  1337. rst.unitPrice.push(getUnitPrice(pGLJ));
  1338. });
  1339. //处理定额数据
  1340. //获取含有定额数据的清单
  1341. handleRation(billsData);
  1342. }
  1343. //处理清单 设置必要数据 设置无用属性
  1344. billsData.forEach(bills => {
  1345. //处理综合单价
  1346. //1.没有子清单,且没有综合单价,则综合单价=综合合价/工程量
  1347. let children = billsData.find(data => data.ParentID === bills.ID),
  1348. unitFee = getFee(bills.fees, ['common', 'unitFee']),
  1349. totalFee = getFee(bills.fees, ['common', 'totalFee']);
  1350. if (!children && !parseFloat(unitFee) && totalFee && parseFloat(totalFee)) {
  1351. //不存工程量
  1352. if (!bills.quantity || !parseFloat(bills.quantity)) {
  1353. unitFee = totalFee;
  1354. //源不存在工程量,没有计算基数、但是却有综合合价,工程量要设置为1
  1355. if (!bills.calcBase) {
  1356. bills.quantity = '1';
  1357. }
  1358. } else {
  1359. //综合合价的小数位数
  1360. let totalFeeDecimal = totalFee.match(/\.\d+/);
  1361. unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, totalFeeDecimal
  1362. ? totalFeeDecimal[0] : 0);
  1363. }
  1364. let commonFee = bills.fees.find(fee => fee.fieldName === 'common');
  1365. if (commonFee) {
  1366. commonFee.unitFee = unitFee;
  1367. }
  1368. }
  1369. bills.projectID = tenderData.ID;
  1370. bills.quantityEXP = bills.quantity;
  1371. delete bills.items;
  1372. delete bills.rations;
  1373. rst.bills.push(bills);
  1374. });
  1375. return rst;
  1376. function handleRation(billsData) {
  1377. let billsHasRations = billsData.filter(bills => Array.isArray(bills.rations) && bills.rations.length);
  1378. billsHasRations.forEach(bills => {
  1379. //处理定额
  1380. bills.rations.forEach(ration => {
  1381. ration.ID = uuid.v1();
  1382. ration.projectID = tenderData.ID;
  1383. ration.billsItemID = bills.ID;
  1384. //含量:定额工程量/清单工程量
  1385. if (!bills.quantity || !ration.quantity){
  1386. ration.contain = '0';
  1387. } else {
  1388. ration.contain = scMathUtil.roundForObj(ration.quantity / bills.quantity, 6);
  1389. }
  1390. //工程量表达式:工程量 * 单位前的量
  1391. if (!ration.unit) {
  1392. ration.quantityEXP = ration.quantity;
  1393. } else {
  1394. let unitNum = ration.unit.match(/^\d+/);
  1395. //工程量小数位数
  1396. let qDecimal = ration.quantity.match(/\.\d+/);
  1397. ration.quantityEXP = unitNum
  1398. ? scMathUtil.roundForObj(ration.quantity * unitNum[0], qDecimal ? qDecimal[0] - 1 : 0)
  1399. : ration.quantity;
  1400. }
  1401. //处理定额人材机,添加需要的数据
  1402. ration.rationGljs.forEach(rGLJ => {
  1403. let matchGLJ = projectGLJMap[rGLJ.code];
  1404. if (matchGLJ) {
  1405. rGLJ.projectGLJID = matchGLJ.id;
  1406. rGLJ.code = matchGLJ.original_code;
  1407. rGLJ.type = matchGLJ.type;
  1408. rGLJ.shortName = matchGLJ.shortName;
  1409. rGLJ.name = matchGLJ.name;
  1410. rGLJ.original_code = matchGLJ.original_code;
  1411. rGLJ.unit = matchGLJ.unit;
  1412. rGLJ.specs = matchGLJ.specs;
  1413. }
  1414. rGLJ.ID = uuid.v1();
  1415. rGLJ.projectID = tenderData.ID;
  1416. rGLJ.billsItemID = bills.ID;
  1417. rGLJ.rationID = ration.ID;
  1418. rGLJ.rationCode = ration.code; //暂时跟定额编码关联,后端好匹配标准数据
  1419. rGLJ.rationItemQuantity = rGLJ.quantity; //定额消耗,暂时取消耗量,需要后端匹配标准数据后更新
  1420. rst.rationGLJ.push(rGLJ);
  1421. });
  1422. delete ration.rationGljs;
  1423. rst.ration.push(ration);
  1424. rst.rationCoe.push(getRationCoe(ration));
  1425. });
  1426. });
  1427. }
  1428. function getRationCoe(ration) {
  1429. return {
  1430. projectID: ration.projectID,
  1431. rationID: ration.ID,
  1432. coeID: -1,
  1433. ID: uuid.v1(),
  1434. seq: 1, //以前排序有的字段,暂时没什么用,不过还是赋上一个值
  1435. name: '自定义系数',
  1436. content: '人工×1,材料×1,机械×1,主材×1,设备×1',
  1437. coes: [
  1438. {amount: 1, operator: '*', gljCode: null, coeType: '定额'},
  1439. {amount: 1, operator: '*', gljCode: null, coeType: '人工'},
  1440. {amount: 1, operator: '*', gljCode: null, coeType: '材料'},
  1441. {amount: 1, operator: '*', gljCode: null, coeType: '机械'},
  1442. {amount: 1, operator: '*', gljCode: null, coeType: '主材'},
  1443. {amount: 1, operator: '*', gljCode: null, coeType: '设备'},
  1444. ],
  1445. option_list: []
  1446. }
  1447. }
  1448. function getUnitPrice(projectGLJ) {
  1449. return {
  1450. projectGLJID: projectGLJ.id, //做个标记,后端查找标准数据后,方便更新组成物数据
  1451. unit_price_file_id: tenderData.property.unitPriceFile.id,
  1452. id: IDPlaceholder.unitPrice++,
  1453. code: projectGLJ.code,
  1454. original_code: projectGLJ.original_code,
  1455. name: projectGLJ.name,
  1456. unit: projectGLJ.unit,
  1457. specs: projectGLJ.specs,
  1458. type: projectGLJ.type,
  1459. short_name: projectGLJ.shortName,
  1460. base_price: projectGLJ.base_price,
  1461. market_price: projectGLJ.market_price
  1462. };
  1463. }
  1464. }
  1465. };
  1466. })();