chongqing_2018_import.js 81 KB

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