importStandardInterface.js 89 KB

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