guangdong_2018_import.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. 'use strict';
  2. const importXML = (() => {
  3. // 通用设置和工具
  4. const config = importXMLBase.CONFIG;
  5. const util = importXMLBase.UTIL;
  6. const {
  7. fixedFlag,
  8. billType,
  9. rationType,
  10. projectType,
  11. TaxType,
  12. } = commonConstants;
  13. const { AdjustType } = config;
  14. const {
  15. getValue,
  16. arrayValue,
  17. getFee,
  18. mergeFees,
  19. getFlag,
  20. getBool,
  21. getItemsRecur,
  22. extractItemsRecur,
  23. } = util;
  24. //导入的文件类型,界面选的文件类型是生成项目的文件类型,这里的文件类型指的是,要导入文件的类型,
  25. //导入文件类型不同,导入数据不同
  26. let importFileKind = '';
  27. //文件类型
  28. const FileKind = {
  29. '6': 1, // 投标
  30. 'tender': 1,
  31. '4': 2, // 招标
  32. 'bid': 2,
  33. '5': 3, // 控制价
  34. 'control': 3,
  35. };
  36. const countData = {
  37. projectCount: 0, //项目数量
  38. projectGLJCount: 0, //项目人材机数量
  39. ratioCount: 0, //组成物数量
  40. unitPriceCount: 0, //单价数量
  41. unitPriceFileCount: 0, //单价文件数量
  42. };
  43. /*
  44. * 从导入的xml文件中提取有用的数据
  45. *
  46. */
  47. // 建设项目
  48. function extractProject(xmlObjMap) {
  49. Object.keys(countData).forEach(key => countData[key] = 0); // 清缓存
  50. countData.projectCount++;
  51. const projectXMLObj = xmlObjMap['Project.xml'];
  52. const projectSrc = getValue(projectXMLObj, ['ConstructionProject']);
  53. importFileKind = FileKind[getValue(projectSrc, ['_FileKind'])]; // 标记当前导入的文件类型
  54. const rst = {
  55. projectType: projectType.Project,
  56. name: getValue(projectSrc, ['_Name']),
  57. engs: extractEngs(projectSrc, xmlObjMap),
  58. property: {
  59. compilationIllustrationProject: getValue(projectSrc, ['_Explains'])
  60. },
  61. basicInformation: extractBasicInfo(projectSrc)
  62. };
  63. countData.unitPriceCount = countData.projectGLJCount;
  64. if (importFileKind !== FileKind.tender) {
  65. countData = {
  66. projectCount: countData.projectCount,
  67. unitPriceFileCount: countData.unitPriceFileCount
  68. };
  69. }
  70. return rst;
  71. }
  72. // 从xml对象中提取基本信息相关
  73. function extractBasicInfo(projectSrc) {
  74. const projectInfo = getValue(projectSrc, ['ProjectInfo']); // 估概预算信息
  75. const tendereeInfo = getValue(projectSrc, ['TendereeInfo']); // 招标信息
  76. const bidderInfo = getValue(projectSrc, ['BidderInfo']); // 投标信息
  77. return [
  78. { key: 'projNum', value: getValue(projectSrc, ['_Number']) }, // 编码
  79. { key: 'projectCategory', value: getValue(projectSrc, ['_ProjectCategory']) }, // 工程类别
  80. { key: 'constructionType', value: getValue(projectSrc, ['_ConstructionType']) }, // 建设性质
  81. { key: 'regionalCategories', value: getValue(projectSrc, ['_AreaKind']) }, // 地区类被
  82. { key: 'projLocation', value: getValue(projectSrc, ['_ProjectSite']) }, // 工程地点
  83. { key: 'constructingUnits', value: getValue(projectSrc, ['_BulidUnit']) }, // 建设单位
  84. { key: 'constructingUnitsPerson', value: getValue(projectSrc, ['_BulidAuthorizer']) }, // 建设单位法定代表人或其授权人
  85. { key: 'rangeOfCompilation', value: getValue(projectSrc, ['_RangeOfCompilation']) }, // 建设(编制)范围
  86. { key: 'scale', value: getValue(projectSrc, ['_Scale']) }, // 建设规模
  87. { key: 'unit', value: getValue(projectSrc, ['_Unit']) }, // 建设规模单位
  88. { key: 'designUnits', value: getValue(projectInfo, ['_Designer']) }, // 设计单位
  89. { key: 'constructionUnits', value: getValue(projectInfo, ['_Contractor']) }, // 承包单位
  90. { key: 'establishUnit', value: getValue(projectInfo, ['_CompileCompany']) }, // 编制单位
  91. { key: importFileKind === FileKind.tender ? 'bidCompileDate' : 'tenderCompileDate', value: getValue(projectInfo, ['_CompileDate']) }, // 编制时间
  92. { key: 'authorizer', value: getValue(projectInfo, ['_Authorizer']) }, // 编制单位法定代表人或其授权人
  93. { key: 'tendereeName', value: getValue(tendereeInfo, ['_TendereeName']) }, // 招标人
  94. { key: 'tenderAuthorizer', value: getValue(tendereeInfo, ['_TenderAuthorizer']) }, // 招标单位法定代表人或其授权人
  95. { key: 'tenderCompiler', value: getValue(tendereeInfo, ['_TenderCompiler']) }, // 招标单位编制人
  96. { key: 'tenderCompilerCertNo', value: getValue(tendereeInfo, ['_TenderCompilerCertNo']) }, // 招标单位编制人资格证书编号
  97. { key: 'tenderCompileDate', value: getValue(tendereeInfo, ['_TenderCompileDate']) }, // 招标单位编制时间
  98. { key: 'tenderExaminer', value: getValue(tendereeInfo, ['_TenderExaminer']) }, // 招标单位审核人
  99. { key: 'tenderExaminerCertNo', value: getValue(tendereeInfo, ['_TenderExaminerCertNo']) }, // 招标单位审核人资格证书编号
  100. { key: 'tenderExamineDate', value: getValue(tendereeInfo, ['_TenderExamineDate']) }, // 招标单位审核时间
  101. { key: 'tenderApprover', value: getValue(tendereeInfo, ['_TenderApprover']) }, // 招标单位审定人
  102. { key: 'tenderApproverCertNo', value: getValue(tendereeInfo, ['_TenderApproverCertNo']) }, // 招标单位审定人资格证书编号
  103. { key: 'proxy', value: getValue(tendereeInfo, ['_Proxy']) }, // 招标代理
  104. { key: 'proxyCertNo', value: getValue(tendereeInfo, ['_ProxyCertNo']) }, // 招标代理资质证书编号
  105. { key: 'proxyAuthorizer', value: getValue(tendereeInfo, ['_ProxyAuthorizer']) }, // 招标代理法定代表人或其授权人
  106. { key: 'proxyCompiler', value: getValue(tendereeInfo, ['_ProxyCompiler']) }, // 招标代理编制人员
  107. { key: 'proxyCompilerCertNo', value: getValue(tendereeInfo, ['_ProxyCompilerCertNo']) }, // 招标代理编制人员资格证书编号
  108. { key: 'proxyCompileDate', value: getValue(tendereeInfo, ['_ProxyCompileDate']) }, // 招标代理编制时间
  109. { key: 'proxyExaminer', value: getValue(tendereeInfo, ['_ProxyExaminer']) }, // 招标代理审核人
  110. { key: 'proxyExaminerCertNo', value: getValue(tendereeInfo, ['_ProxyExaminerCertNo']) }, // 招标代理审核人资格证书编号
  111. { key: 'proxyExamineDate', value: getValue(tendereeInfo, ['_ProxyExamineDate']) }, // 招标代理审核时间
  112. { key: 'proxyApprover', value: getValue(tendereeInfo, ['_ProxyApprover']) }, // 招标代理审定人
  113. { key: 'proxyApproverCertNo', value: getValue(tendereeInfo, ['_ProxyApproverCertNo']) }, // 招标代理审定人资格证书编号
  114. { key: 'proxyApproveDate', value: getValue(tendereeInfo, ['_ProxyApproveDate']) }, // 招标代理审定时间
  115. { key: 'consultant', value: getValue(tendereeInfo, ['_Consultant']) }, // 造价咨询
  116. { key: 'consultantCertNo', value: getValue(tendereeInfo, ['_ConsultantCertNo']) }, // 造价咨询资质证书编号
  117. { key: 'consultantCompiler', value: getValue(tendereeInfo, ['_ConsultantCompiler']) }, // 造价咨询编制人
  118. { key: 'consultantCompilerCertNo', value: getValue(tendereeInfo, ['_ConsultantCompilerCertNo']) }, // 造价咨询编制人资格证书
  119. { key: 'consultantCompileDate', value: getValue(tendereeInfo, ['_ConsultantCompileDate']) }, // 造价咨询编制时间
  120. { key: 'consultantExaminer', value: getValue(tendereeInfo, ['_ConsultantExaminer']) }, // 造价咨询审核人
  121. { key: 'consultantExaminerCertNo', value: getValue(tendereeInfo, ['_ConsultantExaminerCertNo']) }, // 造价咨询审核人资格证书编号
  122. { key: 'consultantExamineDate', value: getValue(tendereeInfo, ['_ConsultantExamineDate']) }, // 造价咨询审核时间
  123. { key: 'consultantApprover', value: getValue(tendereeInfo, ['_ConsultantApprover']) }, // 造价咨询审定人
  124. { key: 'consultantApproverCertNo', value: getValue(tendereeInfo, ['_ConsultantApproverCertNo']) }, // 造价咨询审定人资格证书编号
  125. { key: 'consultantApproveDate', value: getValue(tendereeInfo, ['_ConsultantApproveDate']) }, // 造价咨询审定时间
  126. { key: 'bidName', value: getValue(bidderInfo, ['_BidName']) }, // 投标人
  127. { key: 'bidAuthorizer', value: getValue(bidderInfo, ['_BidAuthorizer']) }, // 投标单位法定代表人或其授权人
  128. { key: 'bidCompiler', value: getValue(bidderInfo, ['_BidCompiler']) }, // 投标单位编制人
  129. { key: 'bidCompilerCertNo', value: getValue(bidderInfo, ['_BidCompilerCertNo']) }, // 投标单位编制人资格证书编号
  130. { key: 'bidCompileDate', value: getValue(bidderInfo, ['_BidCompileDate']) }, // 投标单位编制时间
  131. { key: 'bidExaminer', value: getValue(bidderInfo, ['_BidExaminer']) }, // 投标单位审核人
  132. { key: 'bidExaminerCertNo', value: getValue(bidderInfo, ['_BidExaminerCertNo']) }, // 投标单位审核人资格证书编号
  133. { key: 'bidExamineDate', value: getValue(bidderInfo, ['_BidExamineDate']) }, // 投标单位审核时间
  134. { key: 'bidApprover', value: getValue(bidderInfo, ['_BidApprover']) }, // 投标单位审定人
  135. { key: 'bidApproverCertNo', value: getValue(bidderInfo, ['_BidApproverCertNo']) }, // 投标单位审定人资格证书
  136. { key: 'bidApproveDate', value: getValue(bidderInfo, ['_BidApproveDate']) }, // 投标单位审定时间
  137. ];
  138. }
  139. // 从xml对象中提取单项工程数据
  140. function extractEngs(projectSrc, xmlObjMap) {
  141. const sectionWorks = arrayValue(projectSrc, ['ProjectInstallationWorkCost', 'SectionalWorks']);
  142. return sectionWorks.map(src => {
  143. countData.projectCount++;
  144. return {
  145. projType: projectType.Engineering,
  146. name: getValue(src, ['_Name']),
  147. code: getValue(src, ['_Number']),
  148. tenders: extractTenders(src, xmlObjMap)
  149. }
  150. });
  151. }
  152. // 从xml对象中提取单位工程数据
  153. function extractTenders(sectionWorkSrc, xmlObjMap) {
  154. const unitWorks = arrayValue(sectionWorkSrc, ['UnitWorks']);
  155. return unitWorks.map(unitWorckSrc => {
  156. countData.projectCount++;
  157. countData.unitPriceFileCount++;
  158. const fileName = getValue(unitWorckSrc, ['_FileName']);
  159. const tenderXMLObj = xmlObjMap[fileName];
  160. const src = getValue(tenderXMLObj, ['UnitWorks']); // 单位工程文件的数据
  161. return {
  162. projType: projectType.Tender,
  163. name: getValue(src, ['_Name']),
  164. code: getValue(src, ['_Number']),
  165. engineering: getValue(src, ['_ProjectType']),
  166. projectFeature: extractProjectFeature(src),
  167. workSummary: extractWorkSummary(src),
  168. fbfx: extractFBFX(src),
  169. csxm: extractCSXM(src),
  170. other: extractOther(src),
  171. tax: extractTax(src),
  172. ...extractGLJSummary(src),
  173. bidEvaluationSummary: extractBidEvaluationSummary(src)
  174. };
  175. });
  176. }
  177. // 提取工程特征数据
  178. function extractProjectFeature(tenderSrc) {
  179. // TODO 支持嵌套子项
  180. const attrInfoItems = arrayValue(tenderSrc, ['AttrInfo', 'AttrInfoItem']);
  181. return attrInfoItems.map(item => {
  182. return { name: getValue(item, ['_Name']), value: getValue(item, ['_Value']) };
  183. });
  184. }
  185. // 提取大项费用
  186. function extractWorkSummary(tenderSrc) {
  187. const summarySrc = getValue(tenderSrc, ['UnitWorksSummary']);
  188. const fields = [['UnitWorksSummaryGroup'], ['UnitWorksSummaryItem']];
  189. return extractItemsRecur(summarySrc, fields, (src, curField) => {
  190. const item = {
  191. code: getValue(src, ['_Number']),
  192. name: getValue(src, ['_Name']),
  193. quantity: getValue(src, ['_Quantity']),
  194. remark: getValue(src, ['_Remark']),
  195. feeCode: getValue(src, ['_Code']), //费用字典
  196. fees: [{
  197. fieldName: 'common', totalFee: getValue(src, ['_Total']) || '0',
  198. unitFee: getValue(src, ['_TechnicalAndEconomicIndex']) || '0'
  199. }]
  200. };
  201. if (curField[0] === fields[1][0]) {
  202. item.calcBase = getValue(src, ['_QtyFormula']);
  203. item.feeRate = getValue(src, ['_Rate']);
  204. }
  205. if (importFileKind !== FileKind.tender) {
  206. delete item.feeRate
  207. delete item.fees;
  208. }
  209. return item;
  210. });
  211. }
  212. // 从src子项的SummaryOfBasicCost中获取一部分费用
  213. function getFeesFromBasicCost(src) {
  214. const summaryCost = getValue(src, ['SummaryOfBasicCost']);
  215. if (!summaryCost) {
  216. return [];
  217. }
  218. // SummaryOfBasicCost中有用的价格只有:人工费、材料费、主材费、机械费、管理费、利润
  219. return [
  220. { fieldName: 'labour', totalFee: getValue(summaryCost, ['_Labor']) || '0' },
  221. { fieldName: 'material', totalFee: getValue(summaryCost, ['_Material']) || '0' },
  222. { fieldName: 'mainMaterial', totalFee: getValue(summaryCost, ['_MainMaterial']) || '0' },
  223. { fieldName: 'machine', totalFee: getValue(summaryCost, ['_Machine']) || '0' },
  224. { fieldName: 'manage', totalFee: getValue(summaryCost, ['_Overhead']) || '0' },
  225. { fieldName: 'profit', totalFee: getValue(summaryCost, ['_Profit']) || '0' },
  226. ];
  227. }
  228. // 提取分部分项
  229. function extractFBFX(tenderSrc) {
  230. const fbfxSrc = getValue(tenderSrc, ['DivisionalAndElementalWorks']);
  231. const fields = [['DivisionalWorks'], ['WorkElement']];
  232. const fees = getFeesFromBasicCost(fbfxSrc); // 分部分项的汇总价
  233. const items = getItemsRecur(fbfxSrc, fields, (itemSrc, curField) => {
  234. if (curField[0] === fields[0][0]) { // 分部
  235. return extractDivisionalWorks(itemSrc, billType.FB);
  236. } else {
  237. return extractWorkElement(itemSrc, billType.FX);
  238. }
  239. });
  240. return {
  241. fees,
  242. items
  243. };
  244. }
  245. // 提取分部
  246. function extractDivisionalWorks(divisionalSrc, type) {
  247. // 分部不需要基数,因此不用把基数导入
  248. const item = {
  249. type,
  250. code: getValue(divisionalSrc, ['_Number']),
  251. name: getValue(divisionalSrc, ['_Name']),
  252. unit: getValue(divisionalSrc, ['_Unit']),
  253. quantity: getValue(divisionalSrc, ['_Quantity']),
  254. feeCode: getValue(divisionalSrc, ['_Code']),
  255. remark: getValue(divisionalSrc, ['_Remark']),
  256. };
  257. if (importFileKind === FileKind.tender) {
  258. const summaryFees = getFeesFromBasicCost(divisionalSrc);
  259. const fees = [{ fieldName: 'common', totalFee: getValue(divisionalSrc, ['_Total']), unitFee: getValue(divisionalSrc, ['_TechnicalAndEconomicIndex']) }];
  260. item.fees = mergeFees(fees, summaryFees);
  261. }
  262. return item;
  263. }
  264. // 提取分项清单数据(包含定额、定额人材机)
  265. function extractWorkElement(workElementSrc, type) {
  266. const itemCharacterText = getItemCharacterText(getValue(workElementSrc, ['_Attr']));
  267. const bills = {
  268. type: type, // 清单类型
  269. code: getValue(workElementSrc, ['_Number']),
  270. name: getValue(workElementSrc, ['_Name']),
  271. itemCharacterText,
  272. itemCharacter: getItemCharacter(itemCharacterText),
  273. jocContentText: getValue(workElementSrc, ['_WorkContent']),
  274. jobContent: getJobContent(workElementSrc),
  275. unit: getValue(workElementSrc, ['_Unit']),
  276. quantity: getValue(workElementSrc, ['_Quantity']),
  277. calcBase: getValue(workElementSrc, ['_QtyFormula']),
  278. feeRate: getValue(workElementSrc, ['_Rate']),
  279. mainBills: getBool(getValue(workElementSrc, ['_Major'])),
  280. feeCode: getValue(workElementSrc, ['_Code']),
  281. remark: getValue(workElementSrc, ['_Remark']),
  282. rations: extractRations(workElementSrc)
  283. };
  284. // 投标和控制价,需要导入最高限价
  285. if ([FileKind.tender, FileKind.control].includes(importFileKind)) {
  286. const maxPrice = getValue(workElementSrc, ['_PriceHigh']);
  287. //不为0才输出
  288. if (maxPrice && maxPrice !== '0') {
  289. bills.outPutMaxPrice = true;
  290. bills.maxPrice = maxPrice;
  291. }
  292. if (importFileKind === FileKind.tender) {
  293. const summaryFees = getFeesFromBasicCost(workElementSrc);
  294. const fees = [
  295. { fieldName: 'common', unitFee: getValue(workElementSrc, ['_Price']), totalFee: getValue(workElementSrc, ['_Total']) },
  296. { fieldName: 'equipment', unitFee: getValue(workElementSrc, ['_EquipmentPrice']) },
  297. ];
  298. bills.fees = mergeFees(fees, summaryFees);
  299. }
  300. }
  301. return bills;
  302. // 获取项目特征文本
  303. function getItemCharacterText(attr) {
  304. // 去掉除换行符以外的空白符
  305. const newLine = '{newLine}';
  306. attr = attr
  307. .replace(/[\r\n]/g, newLine)
  308. .replace(/\s/g, '')
  309. .replace(new RegExp(newLine, 'g'), '\n');
  310. const matchStrs = ['
', ';'];
  311. const matchStr = matchStrs.find(str => attr.includes(str));
  312. if (matchStr) {
  313. attr = attr.replace(new RegExp(matchStr, 'g'), '\n');
  314. }
  315. return attr;
  316. }
  317. // 获取清单项目特征窗口数据
  318. function getItemCharacter(itemText) {
  319. const itemsList = itemText.split('\n');
  320. const reg = /\d+\.([^:]+)[::](.*)?/;
  321. const itemCharacter = [];
  322. let idx = 1;
  323. itemsList.forEach(str => {
  324. str = str.replace(/\s/g, '');
  325. const result = reg.exec(str);
  326. if (!result) {
  327. return;
  328. }
  329. const name = result[1];
  330. const value = result[2] || '';
  331. const eigenvalue = value ? [{ value, isSelected: true }] : [];
  332. itemCharacter.push({
  333. character: name,
  334. isChecked: true,
  335. serialNo: idx++,
  336. eigenvalue
  337. });
  338. });
  339. return itemCharacter;
  340. }
  341. // 获取清单工作内容窗口数据
  342. function getJobContent(workElementSrc) {
  343. return arrayValue(workElementSrc, ['WorkContent']).map((workContent, idx) => ({
  344. content: getValue(workContent, ['_Name']),
  345. serialNo: idx + 1,
  346. isChecked: true
  347. }));
  348. }
  349. }
  350. // 提取定额
  351. function extractRations(workElementSrc) {
  352. if (importFileKind !== FileKind.tender) {
  353. return [];
  354. }
  355. // 正常情况下定额肯定是在WorkContent内的,但是也做定额不在WorkContent内的处理(外层定额)
  356. const rations = [];
  357. let serialNo = 1;
  358. const workContents = arrayValue(workElementSrc, ['WorkContent']);
  359. workContents.forEach(workContent => {
  360. const innerRationsSrc = arrayValue(workContent, ['Norm']);
  361. const jobContentText = getValue(workContent, ['_Name']);
  362. const innerRations = innerRationsSrc.map(rationSrc => extractRation(rationSrc, jobContentText));
  363. rations.push(...innerRations);
  364. });
  365. const outerRationsSrc = arrayValue(workElementSrc, ['Norm']);
  366. const outerRations = outerRationsSrc.map(rationSrc => extractRation(rationSrc, ''));
  367. rations.push(...outerRations);
  368. return rations;
  369. // 获取类型
  370. function getType(rationSrc) {
  371. const overHeightMap = {
  372. '1': true,
  373. '2': false
  374. };
  375. const isOverHeight = overHeightMap[getValue(rationSrc, ['EfficiencyKind'])];
  376. if (isOverHeight) {
  377. return rationType.overHeight;
  378. }
  379. const itemIncreaseMap = {
  380. '1': true,
  381. '2': false
  382. };
  383. const isItemIncrease = itemIncreaseMap[getValue(rationSrc, ['IncFeeKind'])];
  384. if (isItemIncrease) {
  385. return rationType.itemIncrease;
  386. }
  387. return rationType.ration;
  388. }
  389. // 从定额的计算程序提取价格
  390. function getFeesFromCalculationOfItem(rationSrc) {
  391. const calculationOfItems = arrayValue(rationSrc, ['UnitPriceCalculationOfItem']);
  392. const fees = [];
  393. const codeFiedNameMap = {
  394. 'DEZJF': 'direct',
  395. 'RGF': 'labour',
  396. 'CLF': 'material',
  397. 'JXF': 'machine',
  398. 'ZCF': 'mainMaterial',
  399. 'SBF': 'equipment',
  400. 'LR': 'profit',
  401. 'DJ': 'common',
  402. };
  403. calculationOfItems.forEach(item => {
  404. const totalFee = +getValue(item, ['_Total']);
  405. const fieldName = codeFiedNameMap[getValue(item, ['_Code'])];
  406. if (totalFee && fieldName) {
  407. fees.push({ fieldName, totalFee });
  408. }
  409. });
  410. return fees;
  411. }
  412. // 提取定额人材机
  413. function extractRationGLJs(rationSrc) {
  414. const rationGLJsSrc = arrayValue(rationSrc, ['LabourMaterialsEquipmentsMachinesElement']);
  415. return rationGLJsSrc.map(src => ({
  416. code: getValue(src, ['_Number']),
  417. quantity: getValue(src, ['_Quantity'])
  418. }));
  419. }
  420. // TODO 目前无法确定定额的取费专业programID,暂时用专业类别Specialty
  421. function extractRation(rationSrc, jobContentText) {
  422. const ration = {
  423. serialNo: serialNo++,
  424. code: getValue(rationSrc, ['_Number']),
  425. name: getValue(rationSrc, ['_Name']),
  426. unit: getValue(rationSrc, ['_Unit']),
  427. quantity: getValue(rationSrc, ['_Quantity']),
  428. type: getType(rationSrc),
  429. programID: getValue(rationSrc, ['_Specialty']),
  430. libCode: getValue(rationSrc, ['_NormIdentity']),
  431. jobContentText,
  432. remark: getValue(rationSrc, ['_Remark'])
  433. };
  434. const fees = [{ fieldName: 'common', unitFee: getValue(rationSrc, ['_Price']), totalFee: getValue(rationSrc, ['_Total']) }]
  435. const feesFromCalcItem = getFeesFromCalculationOfItem(rationSrc);
  436. ration.fees = mergeFees(fees, feesFromCalcItem);
  437. ration.rationGLJs = extractRationGLJs(rationSrc);
  438. return ration;
  439. }
  440. }
  441. // 提取措施项目
  442. function extractCSXM(tenderSrc) {
  443. const csxmSrc = getValue(tenderSrc, ['Preliminaries']);
  444. const fields = [['DivisionalWorks'], ['WorkElement']];
  445. const fees = getFeesFromBasicCost(csxmSrc); // 措施项目的汇总价
  446. const items = getItemsRecur(csxmSrc, fields, (itemSrc, curField) => {
  447. if (curField[0] === fields[0][0]) {
  448. return extractDivisionalWorks(itemSrc, billType.BILL);
  449. } else {
  450. return extractWorkElement(itemSrc, billType.BILL);
  451. }
  452. });
  453. return {
  454. fees,
  455. items
  456. };
  457. }
  458. // 提取其他项目
  459. function extractOther(tenderSrc) {
  460. const sundry = getValue(tenderSrc, ['Sundry']);
  461. // SundryCosts 其他项目 ,对于我们软件是其他项目下完整数据,但是广联达的并不是,因此需要Sundry的其他节点来补充这份数据
  462. const sundryCosts = getValue(sundry, ['SundryCosts']);
  463. // 其他项目汇总费用
  464. const sundryFees = [{ fieldName: 'common', totalFee: getValue(sundryCosts, ['_Total']) }];
  465. debugger;
  466. return {
  467. fees: importFileKind === FileKind.tender ? sundryFees : [],
  468. sundryCosts: extractData(sundry, 'SundryCosts', [['SundryCostsGroup'], ['SundryCostsItem']]),
  469. provisional: extractData(sundry, 'ProvisionalSums', [['ProvisionalSumsGroup'], ['ProvisionalSumsItem']]),
  470. specialty: extractData(sundry, 'SpecialtyProvisionalPrice', [['SpecialtyProvisionalPriceGroup'], ['SpecialtyProvisionalPriceItem']],
  471. { engineeringContent: ['_Content'] }, { engineeringContent: ['_Content'] }),
  472. dayWork: extractData(sundry, 'DayWorkRate', [['DayWorkRateGroup'], ['DayWorkRateItem']]),
  473. mainContractor: extractData(sundry, 'MainContractorAttendance', [['MainContractorAttendanceGroup'], ['MainContractorAttendanceItem']], { serviceContent: ['_Content'] }),
  474. claim: extractData(sundry, 'ClaimsCost', [['ClaimsCostGroup'], ['ClaimsCostItem']]),
  475. visa: extractData(sundry, 'SiteInstructionCost', [['SiteInstructionCostGroup'], ['SiteInstructionCostItem']]),
  476. };
  477. // 提取标题和明细
  478. function extractGroupOrItem(itemSrc, isGroup = true, extendAttrs = null) {
  479. const source = isGroup
  480. ? {
  481. name: getValue(itemSrc, ['_Name']),
  482. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(itemSrc, ['_Total']) }] : [],
  483. feeCode: getValue(itemSrc, ['_Code']),
  484. remark: getValue(itemSrc, ['_Remark'])
  485. }
  486. : {
  487. name: getValue(itemSrc, ['_Name']),
  488. unit: getValue(itemSrc, ['_Unit']),
  489. quantity: getValue(itemSrc, ['_Quantity']),
  490. calcBase: getValue(itemSrc, ['_QtyFormula']),
  491. feeRate: getValue(itemSrc, ['_Rate']),
  492. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', unitFee: getValue(itemSrc, ['_Price']), totalFee: getValue(itemSrc, ['_Total']) }] : [],
  493. feeCode: getValue(itemSrc, ['_Code']),
  494. remark: getValue(itemSrc, ['_Remark'])
  495. };
  496. return extendAttrs ? Object.assign(source, extendAttrs) : source;
  497. }
  498. // 提取数据
  499. function extractData(sundry, srcName, fields, groupExtendMap, itemExtendMap) {
  500. const src = getValue(sundry, [srcName]);
  501. return extractItemsRecur(src, fields, (itemSrc, curField) => {
  502. const groupExtend = groupExtendMap
  503. ? Object.keys(groupExtendMap).reduce((acc, key) => {
  504. acc[key] = getValue(itemSrc, groupExtendMap[key]);
  505. return acc;
  506. }, {})
  507. : null;
  508. const itemExtend = itemExtendMap
  509. ? Object.keys(itemExtendMap).reduce((acc, key) => {
  510. acc[key] = getValue(itemSrc, itemExtendMap[key]);
  511. return acc;
  512. }, {})
  513. : null;
  514. return curField[0] === fields[0][0]
  515. ? extractGroupOrItem(itemSrc, true, groupExtend)
  516. : extractGroupOrItem(itemSrc, false, itemExtend);
  517. });
  518. }
  519. // TODO 材料设备暂估价明细
  520. }
  521. // 提取税金
  522. function extractTax(tenderSrc) {
  523. const taxSrc = getValue(tenderSrc, ['Tax']);
  524. const itemsSrc = arrayValue(taxSrc, ['TaxItem']);
  525. return {
  526. ...extractTaxItem(taxSrc),
  527. items: itemsSrc.map(extractTaxItem)
  528. };
  529. function extractTaxItem(src) {
  530. return {
  531. name: getValue(src, ['_Name']),
  532. calcBase: getValue(src, ['_QtyFormula']),
  533. feeRate: getValue(src, ['_Rate']),
  534. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(src, ['_Total']) }] : [],
  535. feeCode: getValue(src, ['_Code']),
  536. remark: getValue(src, ['_Remark'])
  537. };
  538. }
  539. }
  540. // 供料方式
  541. const Provider = {
  542. '1': [commonConstants.supplyType.ZXCG],
  543. '2': [commonConstants.supplyType.BFJG],
  544. '3': [commonConstants.supplyType.WQJG]
  545. };
  546. // 提取人材机汇总相关(人材机汇总表、承包材料表)
  547. function extractGLJSummary(tenderSrc) {
  548. const initData = { gljSummary: [], differentiaSummary: [], exponentialSummary: [] };
  549. if (importFileKind !== FileKind.tender) {
  550. return initData;
  551. }
  552. const taxType = getValue(tenderSrc, ['_TaxModel']); // 计税方式
  553. const gljListSrc = arrayValue(tenderSrc, ['LabourMaterialsEquipmentsMachinesSummary']);
  554. return gljListSrc.reduce((acc, gljSrc) => {
  555. acc.gljSummary.push(extractGLJ(gljSrc));
  556. acc.differentiaSummary.push(extractDifferentiaGLJ(gljSrc));
  557. acc.exponentialSummary.push(extractExponentialGLJ(gljSrc));
  558. return acc;
  559. }, initData);
  560. // 获取原始编码
  561. function getOriginalCode(code) {
  562. //编码后面有-\d+的形式,去掉-\d+取前面的字符串作为原始代码
  563. return code.replace(/(.*)-\d+$/, '$1');
  564. }
  565. // TODO (不靠谱) 获取人材机类型数据
  566. // 导入的源文件没有细化区分人材机类型,这里只是暂时大概给个值。后续会在后端与标准人材机进行配对。也因此无法准确处理补充人材机
  567. function getTypeData(gljSrc) {
  568. const concrete = getBool(getValue(gljSrc, ['_Concrete']));
  569. if (concrete) {
  570. return { type: 205, shorName: '商砼' };
  571. }
  572. const type = getValue(gljSrc, ['_Kind']);
  573. switch (type) {
  574. case '6':
  575. return { type: 202, shorName: '砼' };
  576. case '7':
  577. return { type: 301, shorName: '机' };
  578. case '15':
  579. return { type: 6, shortName: '管' };
  580. default:
  581. return { type: 201, shortName: '材' };
  582. }
  583. }
  584. // 根据计税方式获取价格,一般计税对应不含税,简易对应含税
  585. function getPriceByTaxType(gljSrc, taxType) {
  586. return taxType === TaxType.NORMAL
  587. ? {
  588. base_price: getValue(gljSrc, ['_NoTaxOrgPrice']),
  589. market_price: getValue(gljSrc, ['_NoTaxPrice'])
  590. }
  591. : {
  592. base_price: getValue(gljSrc, ['_TaxOrgPrice']),
  593. market_price: getValue(gljSrc, ['_TaxPrice'])
  594. };
  595. }
  596. // 提取组成物
  597. function extractRatios(gljSrc) {
  598. const ratiosSrc = arrayValue(gljSrc, ['LabourMaterialsEquipmentsMachinesElement']);
  599. countData.ratioCount += ratiosSrc.length;
  600. return ratiosSrc.map(src => ({
  601. code: getValue(src, ['_Number']),
  602. consumption: getValue(src, ['_Quantity'])
  603. }));
  604. }
  605. // 提取项目人材机
  606. function extractGLJ(gljSrc) {
  607. countData.projectGLJCount++;
  608. const code = getValue(gljSrc, ['_Number']);
  609. return {
  610. code,
  611. original_code: getOriginalCode(code),
  612. name: getValue(gljSrc, ['_Name']),
  613. specs: getValue(gljSrc, ['_Specification']),
  614. unit: getValue(gljSrc, ['_Unit']),
  615. ...getTypeData(gljSrc),
  616. ...getPriceByTaxType(gljSrc, taxType), // 软件中项目人材机是没有价格的,只是为了后续处理单价文件
  617. is_main_material: getBool(getValue(gljSrc, ['_MainMaterial'])),
  618. is_evaluate: getBool(getValue(gljSrc, ['_ProvisionalMaterial'])),
  619. supply: Provider[getValue(gljSrc, ['_Provider'])],
  620. delivery: getValue(gljSrc, ['_Delivery']),
  621. delivery_address: getValue(gljSrc, ['_Location']),
  622. originPlace: getValue(gljSrc, ['_ProducingArea']),
  623. vender: getValue(gljSrc, ['_Supplier']),
  624. qualityGrace: getValue(gljSrc, ['_Character']),
  625. remark: getValue(gljSrc, ['_Remark']),
  626. ratios: extractRatios(gljSrc)
  627. };
  628. }
  629. // 提取造价信息差额调整法
  630. function extractDifferentiaGLJ(gljSrc) {
  631. return {
  632. code: getValue(gljSrc, ['_Number']),
  633. name: getValue(gljSrc, ['_Name']),
  634. specs: getValue(gljSrc, ['_Specification']),
  635. unit: getValue(gljSrc, ['_Unit']),
  636. quantity: getValue(gljSrc, ['_Quantity']),
  637. riskCoe: getValue(gljSrc, ['_ProviderExp']),
  638. standardPrice: getValue(gljSrc, ['_ProviderBase']),
  639. market_price: getPriceByTaxType(gljSrc, taxType).market_price,
  640. remark: getValue(gljSrc, ['_Remark']),
  641. };
  642. }
  643. // 提取价格指数调整法
  644. function extractExponentialGLJ(gljSrc) {
  645. return {
  646. code: getValue(gljSrc, ['_Number']),
  647. name: getValue(gljSrc, ['_Name']),
  648. specs: getValue(gljSrc, ['_Specification']),
  649. varWeight: getValue(gljSrc, ['_Weight']),
  650. FO: getValue(gljSrc, ['_BasicPrice']),
  651. FI: getValue(gljSrc, ['_CurrentPrice']),
  652. remark: getValue(gljSrc, ['_Remark'])
  653. };
  654. }
  655. }
  656. // 提取评标材料
  657. function extractBidEvaluationSummary(tenderSrc) {
  658. if (importFileKind !== FileKind.tender) {
  659. return [];
  660. }
  661. const srcList = arrayValue(tenderSrc, ['BidEvaluationMainMaterial']);
  662. return srcList.map(src => ({
  663. seq: getValue(gljSrc, ['_Code']),
  664. code: getValue(gljSrc, ['_Number']),
  665. name: getValue(gljSrc, ['_Name']),
  666. specs: getValue(gljSrc, ['_Specification']),
  667. unit: getValue(gljSrc, ['_Unit']),
  668. quantity: getValue(gljSrc, ['_Quantity']),
  669. market_price: getValue(gljSrc, ['_Price']),
  670. originPlace: getValue(gljSrc, ['_ProducingArea']),
  671. vender: getValue(gljSrc, ['_Supplier']),
  672. remark: getValue(gljSrc, ['_Remark'])
  673. }));
  674. }
  675. /*
  676. * 转换从xml提取的数据,转换成软件所需的数据结构
  677. *
  678. */
  679. async function transformData(extractedData) {
  680. const IDPlaceholder = await ajaxPost('/pm/import/getProjectPlaceholder', countData);
  681. extractedData.ID = IDPlaceholder.project++;
  682. // 最终上传到服务器的转换后的数据
  683. const transformedData = {
  684. ID: extractedData.ID,
  685. ParentID: extractedData.ParentID,
  686. NextSiblingID: extractedData.NextSiblingID,
  687. preID: extractedData.preID,
  688. name: extractedData.name,
  689. basicInformation: extractedData.basicInformation,
  690. projType: extractedData.projType,
  691. property: extractedData.property,
  692. shareInfo: [],
  693. engs: []
  694. };
  695. // 所有的清单模板库ID
  696. const allTemplateLibIDs = [];
  697. extractedData.engs.forEach(eng => {
  698. eng.tenders.forEach(tender => {
  699. let templateLibID = tender.property.templateLibID;
  700. if (!allTemplateLibIDs.includes(templateLibID)) {
  701. allTemplateLibIDs.push(templateLibID);
  702. }
  703. });
  704. });
  705. // 模板映射:{[templateLibID]: data}
  706. const templateMapping = await ajaxPost('/template/bills/api/getNeedfulTemplate', { allTemplateLibIDs });
  707. for (let i = 0; i < extractedData.engs.length; i++) {
  708. const curEng = extractedData.engs[i];
  709. const preEng = transformedData.engs[i - 1];
  710. curEng.ID = IDPlaceholder.project++;
  711. curEng.ParentID = extractedData.ID;
  712. curEng.NextSiblingID = -1;
  713. if (preEng) {
  714. preEng.NextSiblingID = curEng.ID;
  715. }
  716. const engData = {
  717. ID: curEng.ID,
  718. ParentID: curEng.ParentID,
  719. NextSiblingID: curEng.NextSiblingID,
  720. code: curEng.code,
  721. name: curEng.name,
  722. projType: curEng.projType,
  723. shareInfo: [],
  724. tenders: []
  725. };
  726. transformedData.engs.push(engData);
  727. for (let j = 0; j < curEng.tenders.length; j++) {
  728. const curTender = curEng.tenders[j];
  729. const preTender = engData.tenders[j - 1];
  730. curTender.ID = IDPlaceholder.project++;
  731. curTender.ParentID = curEng.ID;
  732. curTender.NextSiblingID = -1;
  733. curTender.property.unitPriceFile.id = IDPlaceholder.unitPriceFile++;
  734. if (preTender) {
  735. preTender.tender.NextSiblingID = curTender.ID;
  736. }
  737. // 项目清单模板(后台清单模板中提取含有固定类别的数据)
  738. const projectBills = _.cloneDeep(templateMapping[curTender.property.templateLibID]);
  739. debugger;
  740. // 重设模板树结构数据
  741. BILLS_UTIL.resetTreeData(projectBills, uuid.v1);
  742. console.log(projectBills);
  743. const tenderData = transformTender(curTender, IDPlaceholder, projectBills);
  744. tenderData.tender.property.rootProjectID = transformedData.ID;
  745. engData.tenders.push(tenderData);
  746. }
  747. }
  748. return transformedData;
  749. }
  750. // 转换单位工程的数据(直接可插入数据库的数据),返回{tender: {}, bills: [], ration: [], rationGLJ: [], projectGLJ: [], unitPrice: [], mixRatio: []}
  751. function transformTender(tenderData, IDPlaceholder, projectBills) {
  752. const detailData = transformDetail(tenderData, IDPlaceholder, projectBills);
  753. // 提取需要插入的单位工程数据
  754. const transformedTender = {
  755. ID: tenderData.ID,
  756. ParentID: tenderData.ParentID,
  757. NextSiblingID: tenderData.NextSiblingID,
  758. code: tenderData.code,
  759. name: tenderData.name,
  760. projType: tenderData.projType,
  761. property: tenderData.property,
  762. projectFeature: tenderData.projectFeature,
  763. engineering: tenderData.engineering,
  764. defaultRationLib: tenderData.defaultRationLib,
  765. rationLibIDs: tenderData.rationLibIDs,
  766. gljLibIDs: tenderData.gljLibIDs,
  767. shareInfo: []
  768. };
  769. transformedTender.property.gljAdjustType = AdjustType.info;
  770. detailData.tender = transformedTender;
  771. return detailData;
  772. }
  773. // 转换清单
  774. function transformBills(tenderData, IDPlaceholder, projectBills) {
  775. }
  776. // 转换详细的项目数据,清单、定额、定额人材机、项目人材机、单价文件等
  777. function transformDetail() {
  778. }
  779. /**
  780. * 解压cos、zip文件
  781. * @param {File} file - 上传的文件
  782. * @return {Object} 解压出来的xml文件名称与xml文件文本内容映射
  783. */
  784. async function unzipFile(file) {
  785. const jsZip = new JSZip();
  786. const zip = await jsZip.loadAsync(file);
  787. const map = {};
  788. for (const fileName in zip.files) {
  789. // 将二进制数据转换成字符串
  790. map[fileName] = await jsZip.file(fileName).async('string');
  791. }
  792. return map;
  793. }
  794. //从xml文件中提取数据
  795. async function extractData(file, escape = false) {
  796. const fileMap = await unzipFile(file);
  797. const projectXML = fileMap['Project.xml'];
  798. if (!projectXML) {
  799. throw '无有效数据';
  800. }
  801. const xmlObjMap = {};
  802. for (const fileName in fileMap) {
  803. // x2js转换xml使用了DomParser接口,会将一些字符实体进行转义。若不想被自动转义,则需要调用escapeXMLEntity
  804. const xmlStr = escape ? util.escapeXMLEntity(fileMap[fileName]) : fileMap[fileName];
  805. //将xml格式良好的字符串转换成对象
  806. const x2js = new X2JS();
  807. let xmlObj = x2js.xml_str2json(xmlStr);
  808. xmlObj = JSON.parse(util.restoreXMLEntity(JSON.stringify(xmlObj)));
  809. if (!xmlObj) {
  810. throw '无有效数据。';
  811. }
  812. xmlObjMap[fileName] = xmlObj;
  813. }
  814. //提取数据
  815. return extractProject(xmlObjMap);
  816. };
  817. // 接受上传的文件类型(不同的省份可以上传的文件不同)
  818. const accept = ['.zip', '.cos'];
  819. return {
  820. accept,
  821. extractData,
  822. transformData,
  823. }
  824. })();