importStandardInterface.js 70 KB

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