chongqing_2018_import.js 80 KB

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