importStandardInterface.js 85 KB

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