chongqing_2018_import.js 80 KB

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