chongqing_2018_import.js 83 KB

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