guangdong_2018_import.js 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545
  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. assignAttr,
  20. mergeDataRecur,
  21. getFlag,
  22. getBool,
  23. getItemsRecur,
  24. extractItemsRecur,
  25. } = util;
  26. //导入的文件类型,界面选的文件类型是生成项目的文件类型,这里的文件类型指的是,要导入文件的类型,
  27. //导入文件类型不同,导入数据不同
  28. let importFileKind = '';
  29. //文件类型
  30. const FileKind = {
  31. '6': 1, // 投标
  32. 'tender': 1,
  33. '4': 2, // 招标
  34. 'bid': 2,
  35. '5': 3, // 控制价
  36. 'control': 3,
  37. };
  38. // 一些数据是需要从后端获取自增数字后赋值的,这里是记录,用完会在extractProject清空
  39. const countData = {
  40. projectCount: 0, //项目数量
  41. projectGLJCount: 0, //项目人材机数量
  42. ratioCount: 0, //组成物数量
  43. unitPriceCount: 0, //单价数量
  44. unitPriceFileCount: 0, //单价文件数量
  45. };
  46. // 精度
  47. const Decimal = {
  48. // 工料机消耗量、含量、用量类小数精度
  49. GLJ: 4,
  50. // 工程量、数量类小数精度
  51. QUANTITY: 3,
  52. // 金额、合价、费用类小数精度
  53. FEE: 2,
  54. // 费率、指数、比例(%)类小数精度
  55. RATE: 3,
  56. };
  57. // 根据上方精度要求得到的项目属性,小数位数的值
  58. const tenderPropertyDecimal = {
  59. bills: { unitPrice: Decimal.FEE, totalPrice: Decimal.FEE },
  60. ration: { quantity: Decimal.QUANTITY, unitPrice: Decimal.FEE, totalPrice: Decimal.FEE },
  61. glj: { quantity: Decimal.GLJ, unitPriceHasMix: Decimal.FEE, unitPrice: Decimal.FEE },
  62. feeRate: Decimal.RATE,
  63. quantity_detail: 4,
  64. material: 5,//三材系数
  65. process: 6
  66. };
  67. const tenderPropertyBillsQuantityDecimal = Decimal.QUANTITY;
  68. // 工程量表达式相关
  69. const GCLMXHj = 'GCLMXHJ';
  70. const QDL = 'QDL';
  71. // 工程量表达式累加映射
  72. const summationMap = {
  73. '1': 1, // 累加
  74. '2': 0 // 不累加
  75. };
  76. /*
  77. * 从导入的xml文件中提取有用的数据
  78. *
  79. */
  80. // 建设项目
  81. function extractProject(xmlObjMap) {
  82. Object.keys(countData).forEach(key => countData[key] = 0); // 清缓存
  83. countData.projectCount++;
  84. const projectXMLObj = xmlObjMap['Project.xml'];
  85. const projectSrc = getValue(projectXMLObj, ['ConstructionProject']);
  86. importFileKind = FileKind[getValue(projectSrc, ['_FileKind'])]; // 标记当前导入的文件类型
  87. const rst = {
  88. projType: projectType.Project,
  89. name: getValue(projectSrc, ['_Name']),
  90. engs: extractEngs(projectSrc, xmlObjMap),
  91. property: {
  92. compilationIllustration: getValue(projectSrc, ['_Explains'])
  93. },
  94. basicInformation: extractBasicInfo(projectSrc)
  95. };
  96. countData.unitPriceCount = countData.projectGLJCount;
  97. if (importFileKind !== FileKind.tender) {
  98. countData = {
  99. projectCount: countData.projectCount,
  100. unitPriceFileCount: countData.unitPriceFileCount
  101. };
  102. }
  103. return rst;
  104. }
  105. // 从xml对象中提取基本信息相关
  106. function extractBasicInfo(projectSrc) {
  107. const projectInfo = getValue(projectSrc, ['ProjectInfo']); // 估概预算信息
  108. const tendereeInfo = getValue(projectSrc, ['TendereeInfo']); // 招标信息
  109. const bidderInfo = getValue(projectSrc, ['BidderInfo']); // 投标信息
  110. return [
  111. { key: 'projNum', value: getValue(projectSrc, ['_Number']) }, // 编码
  112. { key: 'projectCategory', value: getValue(projectSrc, ['_ProjectCategory']) }, // 工程类别
  113. { key: 'constructionType', value: getValue(projectSrc, ['_ConstructionType']) }, // 建设性质
  114. { key: 'regionalCategories', value: getValue(projectSrc, ['_AreaKind']) }, // 地区类被
  115. { key: 'projLocation', value: getValue(projectSrc, ['_ProjectSite']) }, // 工程地点
  116. { key: 'constructingUnits', value: getValue(projectSrc, ['_BulidUnit']) }, // 建设单位
  117. { key: 'constructingUnitsPerson', value: getValue(projectSrc, ['_BulidAuthorizer']) }, // 建设单位法定代表人或其授权人
  118. { key: 'rangeOfCompilation', value: getValue(projectSrc, ['_RangeOfCompilation']) }, // 建设(编制)范围
  119. { key: 'scale', value: getValue(projectSrc, ['_Scale']) }, // 建设规模
  120. { key: 'unit', value: getValue(projectSrc, ['_Unit']) }, // 建设规模单位
  121. { key: 'designUnits', value: getValue(projectInfo, ['_Designer']) }, // 设计单位
  122. { key: 'constructionUnits', value: getValue(projectInfo, ['_Contractor']) }, // 承包单位
  123. { key: 'establishUnit', value: getValue(projectInfo, ['_CompileCompany']) }, // 编制单位
  124. { key: importFileKind === FileKind.tender ? 'bidCompileDate' : 'tenderCompileDate', value: getValue(projectInfo, ['_CompileDate']) }, // 编制时间
  125. { key: 'authorizer', value: getValue(projectInfo, ['_Authorizer']) }, // 编制单位法定代表人或其授权人
  126. { key: 'tendereeName', value: getValue(tendereeInfo, ['_TendereeName']) }, // 招标人
  127. { key: 'tenderAuthorizer', value: getValue(tendereeInfo, ['_TenderAuthorizer']) }, // 招标单位法定代表人或其授权人
  128. { key: 'tenderCompiler', value: getValue(tendereeInfo, ['_TenderCompiler']) }, // 招标单位编制人
  129. { key: 'tenderCompilerCertNo', value: getValue(tendereeInfo, ['_TenderCompilerCertNo']) }, // 招标单位编制人资格证书编号
  130. { key: 'tenderCompileDate', value: getValue(tendereeInfo, ['_TenderCompileDate']) }, // 招标单位编制时间
  131. { key: 'tenderExaminer', value: getValue(tendereeInfo, ['_TenderExaminer']) }, // 招标单位审核人
  132. { key: 'tenderExaminerCertNo', value: getValue(tendereeInfo, ['_TenderExaminerCertNo']) }, // 招标单位审核人资格证书编号
  133. { key: 'tenderExamineDate', value: getValue(tendereeInfo, ['_TenderExamineDate']) }, // 招标单位审核时间
  134. { key: 'tenderApprover', value: getValue(tendereeInfo, ['_TenderApprover']) }, // 招标单位审定人
  135. { key: 'tenderApproverCertNo', value: getValue(tendereeInfo, ['_TenderApproverCertNo']) }, // 招标单位审定人资格证书编号
  136. { key: 'proxy', value: getValue(tendereeInfo, ['_Proxy']) }, // 招标代理
  137. { key: 'proxyCertNo', value: getValue(tendereeInfo, ['_ProxyCertNo']) }, // 招标代理资质证书编号
  138. { key: 'proxyAuthorizer', value: getValue(tendereeInfo, ['_ProxyAuthorizer']) }, // 招标代理法定代表人或其授权人
  139. { key: 'proxyCompiler', value: getValue(tendereeInfo, ['_ProxyCompiler']) }, // 招标代理编制人员
  140. { key: 'proxyCompilerCertNo', value: getValue(tendereeInfo, ['_ProxyCompilerCertNo']) }, // 招标代理编制人员资格证书编号
  141. { key: 'proxyCompileDate', value: getValue(tendereeInfo, ['_ProxyCompileDate']) }, // 招标代理编制时间
  142. { key: 'proxyExaminer', value: getValue(tendereeInfo, ['_ProxyExaminer']) }, // 招标代理审核人
  143. { key: 'proxyExaminerCertNo', value: getValue(tendereeInfo, ['_ProxyExaminerCertNo']) }, // 招标代理审核人资格证书编号
  144. { key: 'proxyExamineDate', value: getValue(tendereeInfo, ['_ProxyExamineDate']) }, // 招标代理审核时间
  145. { key: 'proxyApprover', value: getValue(tendereeInfo, ['_ProxyApprover']) }, // 招标代理审定人
  146. { key: 'proxyApproverCertNo', value: getValue(tendereeInfo, ['_ProxyApproverCertNo']) }, // 招标代理审定人资格证书编号
  147. { key: 'proxyApproveDate', value: getValue(tendereeInfo, ['_ProxyApproveDate']) }, // 招标代理审定时间
  148. { key: 'consultant', value: getValue(tendereeInfo, ['_Consultant']) }, // 造价咨询
  149. { key: 'consultantCertNo', value: getValue(tendereeInfo, ['_ConsultantCertNo']) }, // 造价咨询资质证书编号
  150. { key: 'consultantCompiler', value: getValue(tendereeInfo, ['_ConsultantCompiler']) }, // 造价咨询编制人
  151. { key: 'consultantCompilerCertNo', value: getValue(tendereeInfo, ['_ConsultantCompilerCertNo']) }, // 造价咨询编制人资格证书
  152. { key: 'consultantCompileDate', value: getValue(tendereeInfo, ['_ConsultantCompileDate']) }, // 造价咨询编制时间
  153. { key: 'consultantExaminer', value: getValue(tendereeInfo, ['_ConsultantExaminer']) }, // 造价咨询审核人
  154. { key: 'consultantExaminerCertNo', value: getValue(tendereeInfo, ['_ConsultantExaminerCertNo']) }, // 造价咨询审核人资格证书编号
  155. { key: 'consultantExamineDate', value: getValue(tendereeInfo, ['_ConsultantExamineDate']) }, // 造价咨询审核时间
  156. { key: 'consultantApprover', value: getValue(tendereeInfo, ['_ConsultantApprover']) }, // 造价咨询审定人
  157. { key: 'consultantApproverCertNo', value: getValue(tendereeInfo, ['_ConsultantApproverCertNo']) }, // 造价咨询审定人资格证书编号
  158. { key: 'consultantApproveDate', value: getValue(tendereeInfo, ['_ConsultantApproveDate']) }, // 造价咨询审定时间
  159. { key: 'bidName', value: getValue(bidderInfo, ['_BidName']) }, // 投标人
  160. { key: 'bidAuthorizer', value: getValue(bidderInfo, ['_BidAuthorizer']) }, // 投标单位法定代表人或其授权人
  161. { key: 'bidCompiler', value: getValue(bidderInfo, ['_BidCompiler']) }, // 投标单位编制人
  162. { key: 'bidCompilerCertNo', value: getValue(bidderInfo, ['_BidCompilerCertNo']) }, // 投标单位编制人资格证书编号
  163. { key: 'bidCompileDate', value: getValue(bidderInfo, ['_BidCompileDate']) }, // 投标单位编制时间
  164. { key: 'bidExaminer', value: getValue(bidderInfo, ['_BidExaminer']) }, // 投标单位审核人
  165. { key: 'bidExaminerCertNo', value: getValue(bidderInfo, ['_BidExaminerCertNo']) }, // 投标单位审核人资格证书编号
  166. { key: 'bidExamineDate', value: getValue(bidderInfo, ['_BidExamineDate']) }, // 投标单位审核时间
  167. { key: 'bidApprover', value: getValue(bidderInfo, ['_BidApprover']) }, // 投标单位审定人
  168. { key: 'bidApproverCertNo', value: getValue(bidderInfo, ['_BidApproverCertNo']) }, // 投标单位审定人资格证书
  169. { key: 'bidApproveDate', value: getValue(bidderInfo, ['_BidApproveDate']) }, // 投标单位审定时间
  170. ];
  171. }
  172. // 从xml对象中提取单项工程数据
  173. function extractEngs(projectSrc, xmlObjMap) {
  174. const sectionWorks = arrayValue(projectSrc, ['ProjectInstallationWorkCost', 'SectionalWorks']);
  175. return sectionWorks.map(src => {
  176. countData.projectCount++;
  177. return {
  178. projType: projectType.Engineering,
  179. name: getValue(src, ['_Name']),
  180. code: getValue(src, ['_Number']),
  181. tenders: extractTenders(src, xmlObjMap)
  182. }
  183. });
  184. }
  185. // 从xml对象中提取单位工程数据
  186. function extractTenders(sectionWorkSrc, xmlObjMap) {
  187. const unitWorks = arrayValue(sectionWorkSrc, ['UnitWorks']);
  188. return unitWorks.map(unitWorckSrc => {
  189. countData.projectCount++;
  190. countData.unitPriceFileCount++;
  191. const fileName = getValue(unitWorckSrc, ['_FileName']);
  192. const tenderXMLObj = xmlObjMap[fileName];
  193. const src = getValue(tenderXMLObj, ['UnitWorks']); // 单位工程文件的数据
  194. return {
  195. projType: projectType.Tender,
  196. name: getValue(src, ['_Name']),
  197. code: getValue(src, ['_Number']),
  198. compilationIllustration: getValue(src, ['_Explains']),
  199. engineering: getValue(src, ['_ProjectType']),
  200. projectFeature: extractProjectFeature(src),
  201. workSummary: extractWorkSummary(src),
  202. fbfx: extractFBFX(src),
  203. csxm: extractCSXM(src),
  204. other: extractOther(src),
  205. tax: extractTax(src),
  206. ...extractGLJSummary(src),
  207. bidEvaluationSummary: extractBidEvaluationSummary(src)
  208. };
  209. });
  210. }
  211. // 提取工程特征数据
  212. function extractProjectFeature(tenderSrc) {
  213. // 支持嵌套子项
  214. const attrInfoSrc = getValue(tenderSrc, ['AttrInfo']);
  215. const featureData = extractItemsRecur(attrInfoSrc, [['AttrInfoItem']], (src) => ({
  216. dispName: getValue(src, ['_Name']),
  217. value: getValue(src, ['_Value'])
  218. }));
  219. clearEmptyItems(featureData);
  220. return featureData;
  221. function clearEmptyItems(items) {
  222. items.forEach(item => {
  223. if (!item.items) {
  224. return;
  225. }
  226. if (!item.items.length) {
  227. delete item.items;
  228. } else {
  229. clearEmptyItems(item.items);
  230. }
  231. })
  232. }
  233. }
  234. // 提取大项费用
  235. function extractWorkSummary(tenderSrc) {
  236. const summarySrc = getValue(tenderSrc, ['UnitWorksSummary']);
  237. const fields = [['UnitWorksSummaryGroup'], ['UnitWorksSummaryItem']];
  238. return extractItemsRecur(summarySrc, fields, (src, curField) => {
  239. const item = {
  240. code: getValue(src, ['_Number']),
  241. name: getValue(src, ['_Name']),
  242. quantity: getValue(src, ['_Quantity']),
  243. remark: getValue(src, ['_Remark']),
  244. feeCode: getValue(src, ['_Code']), //费用字典
  245. fees: [{
  246. fieldName: 'common', totalFee: getValue(src, ['_Total']) || '0',
  247. unitFee: getValue(src, ['_TechnicalAndEconomicIndex']) || '0'
  248. }]
  249. };
  250. if (curField[0] === fields[1][0]) {
  251. item.calcBase = getValue(src, ['_QtyFormula']);
  252. item.feeRate = getValue(src, ['_Rate']);
  253. }
  254. if (importFileKind !== FileKind.tender) {
  255. delete item.feeRate
  256. delete item.fees;
  257. }
  258. return item;
  259. });
  260. }
  261. // 从src子项的SummaryOfBasicCost中获取一部分费用
  262. function getFeesFromBasicCost(src) {
  263. const summaryCost = getValue(src, ['SummaryOfBasicCost']);
  264. if (!summaryCost) {
  265. return [];
  266. }
  267. // SummaryOfBasicCost中有用的价格只有:人工费、材料费、主材费、机械费、管理费、利润
  268. return [
  269. { fieldName: 'labour', totalFee: getValue(summaryCost, ['_Labor']) || '0' },
  270. { fieldName: 'material', totalFee: getValue(summaryCost, ['_Material']) || '0' },
  271. { fieldName: 'mainMaterial', totalFee: getValue(summaryCost, ['_MainMaterial']) || '0' },
  272. { fieldName: 'machine', totalFee: getValue(summaryCost, ['_Machine']) || '0' },
  273. { fieldName: 'manage', totalFee: getValue(summaryCost, ['_Overhead']) || '0' },
  274. { fieldName: 'profit', totalFee: getValue(summaryCost, ['_Profit']) || '0' },
  275. ];
  276. }
  277. // 提取分部分项
  278. function extractFBFX(tenderSrc) {
  279. const fbfxSrc = getValue(tenderSrc, ['DivisionalAndElementalWorks']);
  280. const fields = [['DivisionalWorks'], ['WorkElement']];
  281. const fees = getFeesFromBasicCost(fbfxSrc); // 分部分项的汇总价
  282. const items = getItemsRecur(fbfxSrc, fields, (itemSrc, curField) => {
  283. if (curField[0] === fields[0][0]) { // 分部
  284. return extractDivisionalWorks(itemSrc, billType.FB);
  285. } else {
  286. return extractWorkElement(itemSrc, billType.FX);
  287. }
  288. });
  289. return {
  290. fees,
  291. items
  292. };
  293. }
  294. // 提取分部
  295. function extractDivisionalWorks(divisionalSrc, type) {
  296. // 分部不需要基数,因此不用把基数导入
  297. const item = {
  298. type,
  299. code: getValue(divisionalSrc, ['_Number']),
  300. name: getValue(divisionalSrc, ['_Name']),
  301. unit: getValue(divisionalSrc, ['_Unit']),
  302. quantity: getValue(divisionalSrc, ['_Quantity']),
  303. feeCode: getValue(divisionalSrc, ['_Code']),
  304. remark: getValue(divisionalSrc, ['_Remark']),
  305. };
  306. if (importFileKind === FileKind.tender) {
  307. const summaryFees = getFeesFromBasicCost(divisionalSrc);
  308. const fees = [{ fieldName: 'common', totalFee: getValue(divisionalSrc, ['_Total']), unitFee: getValue(divisionalSrc, ['_TechnicalAndEconomicIndex']) }];
  309. item.fees = mergeFees(fees, summaryFees);
  310. }
  311. return item;
  312. }
  313. // 提取分项清单数据(包含定额、定额人材机)
  314. function extractWorkElement(workElementSrc, type) {
  315. const itemCharacterText = getItemCharacterText(getValue(workElementSrc, ['_Attr']));
  316. const bills = {
  317. type: type, // 清单类型
  318. code: getValue(workElementSrc, ['_Number']),
  319. name: getValue(workElementSrc, ['_Name']),
  320. itemCharacterText,
  321. itemCharacter: getItemCharacter(itemCharacterText),
  322. jocContentText: getValue(workElementSrc, ['_WorkContent']),
  323. jobContent: getJobContent(workElementSrc),
  324. unit: getValue(workElementSrc, ['_Unit']),
  325. quantity: getValue(workElementSrc, ['_Quantity']),
  326. mainBills: getBool(getValue(workElementSrc, ['_Major'])),
  327. feeCode: getValue(workElementSrc, ['_Code']),
  328. remark: getValue(workElementSrc, ['_Remark']),
  329. quantityDetails: extractQuantityDetails(workElementSrc),
  330. rations: extractRations(workElementSrc)
  331. };
  332. if (type === billType.BILL) {
  333. // 分项不需要基数、费率
  334. bills.calcBase = getValue(workElementSrc, ['_QtyFormula']);
  335. const feeRate = getValue(workElementSrc, ['_Rate']);
  336. if (+feeRate) {
  337. bills.feeRate = feeRate;
  338. }
  339. }
  340. // 投标和控制价,需要导入最高限价
  341. if ([FileKind.tender, FileKind.control].includes(importFileKind)) {
  342. const maxPrice = getValue(workElementSrc, ['_PriceHigh']);
  343. //不为0才输出
  344. if (maxPrice && maxPrice !== '0') {
  345. bills.outPutMaxPrice = true;
  346. bills.maxPrice = maxPrice;
  347. }
  348. if (importFileKind === FileKind.tender) {
  349. const summaryFees = getFeesFromBasicCost(workElementSrc);
  350. const fees = [
  351. { fieldName: 'common', unitFee: getValue(workElementSrc, ['_Price']), totalFee: getValue(workElementSrc, ['_Total']) },
  352. { fieldName: 'equipment', unitFee: getValue(workElementSrc, ['_EquipmentPrice']) },
  353. ];
  354. bills.fees = mergeFees(fees, summaryFees);
  355. }
  356. }
  357. return bills;
  358. // 获取项目特征文本
  359. function getItemCharacterText(attr) {
  360. // 去掉除换行符以外的空白符
  361. const newLine = '{newLine}';
  362. attr = attr
  363. .replace(/[\r\n]/g, newLine)
  364. .replace(/\s/g, '')
  365. .replace(new RegExp(newLine, 'g'), '\n');
  366. const matchStrs = ['
', ';'];
  367. const matchStr = matchStrs.find(str => attr.includes(str));
  368. if (matchStr) {
  369. attr = attr.replace(new RegExp(matchStr, 'g'), '\n');
  370. }
  371. return attr;
  372. }
  373. // 获取清单项目特征窗口数据
  374. function getItemCharacter(itemText) {
  375. const itemsList = itemText.split('\n');
  376. const reg = /\d+\.([^:]+)[::](.*)?/;
  377. const itemCharacter = [];
  378. let idx = 1;
  379. itemsList.forEach(str => {
  380. str = str.replace(/\s/g, '');
  381. const result = reg.exec(str);
  382. if (!result) {
  383. return;
  384. }
  385. const name = result[1];
  386. const value = result[2] || '';
  387. const eigenvalue = value ? [{ value, isSelected: true }] : [];
  388. itemCharacter.push({
  389. character: name,
  390. isChecked: true,
  391. serialNo: idx++,
  392. eigenvalue
  393. });
  394. });
  395. return itemCharacter;
  396. }
  397. // 获取清单工作内容窗口数据
  398. function getJobContent(workElementSrc) {
  399. return arrayValue(workElementSrc, ['WorkContent']).map((workContent, idx) => ({
  400. content: getValue(workContent, ['_Name']),
  401. serialNo: idx + 1,
  402. isChecked: true
  403. }));
  404. }
  405. }
  406. // 提取工程量明细(清单、定额底下都可能会有)
  407. function extractQuantityDetails(src) {
  408. return arrayValue(src, ['ExpressElement']).map(itemSrc => ({
  409. seq: getValue(itemSrc, ['_OrderNumber']),
  410. regex: getValue(itemSrc, ['_Express']),
  411. result: getValue(itemSrc, ['_Quantity']),
  412. isSummation: summationMap[getValue(itemSrc, ['_Kind'])]
  413. }));
  414. }
  415. // 提取定额
  416. function extractRations(workElementSrc) {
  417. if (importFileKind !== FileKind.tender) {
  418. return [];
  419. }
  420. // 正常情况下定额肯定是在WorkContent内的,但是也做定额不在WorkContent内的处理(外层定额)
  421. const rations = [];
  422. let serialNo = 1;
  423. const workContents = arrayValue(workElementSrc, ['WorkContent']);
  424. workContents.forEach(workContent => {
  425. const innerRationsSrc = arrayValue(workContent, ['Norm']);
  426. const jobContentText = getValue(workContent, ['_Name']);
  427. const innerRations = innerRationsSrc.map(rationSrc => extractRation(rationSrc, jobContentText));
  428. rations.push(...innerRations);
  429. });
  430. const outerRationsSrc = arrayValue(workElementSrc, ['Norm']);
  431. const outerRations = outerRationsSrc.map(rationSrc => extractRation(rationSrc, ''));
  432. rations.push(...outerRations);
  433. return rations;
  434. // 获取类型
  435. function getType(rationSrc) {
  436. const overHeightMap = {
  437. '1': true,
  438. '2': false
  439. };
  440. const isOverHeight = overHeightMap[getValue(rationSrc, ['EfficiencyKind'])];
  441. if (isOverHeight) {
  442. return rationType.overHeight;
  443. }
  444. const itemIncreaseMap = {
  445. '1': true,
  446. '2': false
  447. };
  448. const isItemIncrease = itemIncreaseMap[getValue(rationSrc, ['IncFeeKind'])];
  449. if (isItemIncrease) {
  450. return rationType.itemIncrease;
  451. }
  452. return rationType.ration;
  453. }
  454. // 从定额的计算程序提取价格
  455. function getFeesFromCalculationOfItem(rationSrc) {
  456. const calculationOfItems = arrayValue(rationSrc, ['UnitPriceCalculationOfItem']);
  457. const fees = [];
  458. const codeFiedNameMap = {
  459. 'ZJF': 'direct',
  460. 'RGF': 'labour',
  461. 'CLF': 'material',
  462. 'JXF': 'machine',
  463. 'ZCF': 'mainMaterial',
  464. 'SBF': 'equipment',
  465. 'LR': 'profit',
  466. //'DJ': 'common',定额本身已经有单价这个字段,不需要从这读取
  467. };
  468. calculationOfItems.forEach(item => {
  469. const totalFee = +getValue(item, ['_Total']);
  470. const fieldName = codeFiedNameMap[getValue(item, ['_Code'])];
  471. if (totalFee && fieldName) {
  472. fees.push({ fieldName, totalFee });
  473. }
  474. });
  475. return fees;
  476. }
  477. // 提取定额人材机
  478. function extractRationGLJs(rationSrc) {
  479. const rationGLJsSrc = arrayValue(rationSrc, ['LabourMaterialsEquipmentsMachinesElement']);
  480. return rationGLJsSrc.map(src => ({
  481. code: getValue(src, ['_Number']),
  482. quantity: getValue(src, ['_Quantity'])
  483. }));
  484. }
  485. // TODO 目前无法确定定额的取费专业programID,暂时用专业类别Specialty
  486. function extractRation(rationSrc, jobContentText) {
  487. const ration = {
  488. serialNo: serialNo++,
  489. code: getValue(rationSrc, ['_Number']),
  490. name: getValue(rationSrc, ['_Name']),
  491. unit: getValue(rationSrc, ['_Unit']),
  492. quantity: getValue(rationSrc, ['_Quantity']),
  493. type: getType(rationSrc),
  494. programID: getValue(rationSrc, ['_Specialty']),
  495. libCode: getValue(rationSrc, ['_NormIdentity']),
  496. jobContentText,
  497. remark: getValue(rationSrc, ['_Remark'])
  498. };
  499. const fees = [{ fieldName: 'common', unitFee: getValue(rationSrc, ['_Price']), totalFee: getValue(rationSrc, ['_Total']) }]
  500. const feesFromCalcItem = getFeesFromCalculationOfItem(rationSrc);
  501. ration.fees = mergeFees(fees, feesFromCalcItem);
  502. ration.rationGLJs = extractRationGLJs(rationSrc);
  503. ration.quantityDetails = extractQuantityDetails(rationSrc);
  504. return ration;
  505. }
  506. }
  507. // 提取措施项目
  508. function extractCSXM(tenderSrc) {
  509. const csxmSrc = getValue(tenderSrc, ['Preliminaries']);
  510. const fields = [['DivisionalWorks'], ['WorkElement']];
  511. const fees = getFeesFromBasicCost(csxmSrc); // 措施项目的汇总价
  512. const items = getItemsRecur(csxmSrc, fields, (itemSrc, curField) => {
  513. if (curField[0] === fields[0][0]) {
  514. return extractDivisionalWorks(itemSrc, billType.BILL);
  515. } else {
  516. return extractWorkElement(itemSrc, billType.BILL);
  517. }
  518. });
  519. return {
  520. fees,
  521. items
  522. };
  523. }
  524. // 提取其他项目
  525. function extractOther(tenderSrc) {
  526. const sundry = getValue(tenderSrc, ['Sundry']);
  527. // SundryCosts 其他项目 ,对于我们软件是其他项目下完整数据,但是广联达的并不是,因此需要Sundry的其他节点来补充这份数据
  528. const sundryCosts = getValue(sundry, ['SundryCosts']);
  529. // 其他项目汇总费用
  530. const sundryFees = [{ fieldName: 'common', totalFee: getValue(sundryCosts, ['_Total']) }];
  531. const provisionalMaterialEquipment = getValue(sundry, ['ProvisionalMaterialEquipment']);
  532. return {
  533. fees: importFileKind === FileKind.tender ? sundryFees : [],
  534. sundryCosts: extractData(sundry, 'SundryCosts', [['SundryCostsGroup'], ['SundryCostsItem']]),
  535. provisional: extractData(sundry, 'ProvisionalSums', [['ProvisionalSumsGroup'], ['ProvisionalSumsItem']]),
  536. ProvisionalMaterialEquipment: {
  537. name: getValue(provisionalMaterialEquipment, ['_Name']),
  538. feeCode: getValue(provisionalMaterialEquipment, ['_Code']),
  539. remark: getValue(provisionalMaterialEquipment, ['_Remark']),
  540. fees: [{ fieldName: 'common', totalFee: getValue(provisionalMaterialEquipment, ['_Total']) }],
  541. },
  542. specialty: extractData(sundry, 'SpecialtyProvisionalPrice', [['SpecialtyProvisionalPriceGroup'], ['SpecialtyProvisionalPriceItem']],
  543. { engineeringContent: ['_Content'] }, { engineeringContent: ['_Content'] }),
  544. dayWork: extractData(sundry, 'DayWorkRate', [['DayWorkRateGroup'], ['DayWorkRateItem']]),
  545. mainContractor: extractData(sundry, 'MainContractorAttendance', [['MainContractorAttendanceGroup'], ['MainContractorAttendanceItem']], { serviceContent: ['_Content'] }),
  546. claim: extractData(sundry, 'ClaimsCost', [['ClaimsCostGroup'], ['ClaimsCostItem']]),
  547. visa: extractData(sundry, 'SiteInstructionCost', [['SiteInstructionCostGroup'], ['SiteInstructionCostItem']]),
  548. };
  549. // 提取标题和明细
  550. function extractGroupOrItem(itemSrc, isGroup = true, extendAttrs = null, field) {
  551. let source;
  552. if (isGroup) {
  553. source = {
  554. name: getValue(itemSrc, ['_Name']),
  555. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(itemSrc, ['_Total']) }] : [],
  556. feeCode: getValue(itemSrc, ['_Code']),
  557. remark: getValue(itemSrc, ['_Remark'])
  558. };
  559. } else {
  560. source = {
  561. name: getValue(itemSrc, ['_Name']),
  562. unit: getValue(itemSrc, ['_Unit']),
  563. calcBase: getValue(itemSrc, ['_QtyFormula']),
  564. feeRate: getValue(itemSrc, ['_Rate']),
  565. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', unitFee: getValue(itemSrc, ['_Price']), totalFee: getValue(itemSrc, ['_Total']) }] : [],
  566. feeCode: getValue(itemSrc, ['_Code']),
  567. remark: getValue(itemSrc, ['_Remark'])
  568. };
  569. if (field !== 'MainContractorAttendanceItem') { // MainContractorAttendanceItem的quantity比较特殊,是清单基数计算后的值而不是工程量,不需要导入
  570. source.quantity = getValue(itemSrc, ['_Quantity']);
  571. }
  572. }
  573. return extendAttrs ? Object.assign(source, extendAttrs) : source;
  574. }
  575. // 提取数据
  576. function extractData(sundry, srcName, fields, groupExtendMap, itemExtendMap) {
  577. const src = getValue(sundry, [srcName]);
  578. return {
  579. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(src, ['_Total']) }] : [],
  580. feeCode: getValue(src, ['_Code']),
  581. items: extractItemsRecur(src, fields, (itemSrc, curField) => {
  582. const groupExtend = groupExtendMap
  583. ? Object.keys(groupExtendMap).reduce((acc, key) => {
  584. acc[key] = getValue(itemSrc, groupExtendMap[key]);
  585. return acc;
  586. }, {})
  587. : null;
  588. const itemExtend = itemExtendMap
  589. ? Object.keys(itemExtendMap).reduce((acc, key) => {
  590. acc[key] = getValue(itemSrc, itemExtendMap[key]);
  591. return acc;
  592. }, {})
  593. : null;
  594. return curField[0] === fields[0][0]
  595. ? extractGroupOrItem(itemSrc, true, groupExtend, curField[0])
  596. : extractGroupOrItem(itemSrc, false, itemExtend, curField[0]);
  597. })
  598. };
  599. }
  600. }
  601. // 提取税金
  602. function extractTax(tenderSrc) {
  603. const taxSrc = getValue(tenderSrc, ['Tax']);
  604. const itemsSrc = arrayValue(taxSrc, ['TaxItem']);
  605. return {
  606. ...extractTaxItem(taxSrc),
  607. items: itemsSrc.map(extractTaxItem)
  608. };
  609. function extractTaxItem(src) {
  610. return {
  611. name: getValue(src, ['_Name']),
  612. calcBase: getValue(src, ['_QtyFormula']),
  613. feeRate: getValue(src, ['_Rate']),
  614. fees: importFileKind === FileKind.tender ? [{ fieldName: 'common', totalFee: getValue(src, ['_Total']) }] : [],
  615. feeCode: getValue(src, ['_Code']),
  616. remark: getValue(src, ['_Remark'])
  617. };
  618. }
  619. }
  620. // 供料方式
  621. const Provider = {
  622. '1': commonConstants.supplyType.ZXCG,
  623. '2': commonConstants.supplyType.BFJG,
  624. '3': commonConstants.supplyType.WQJG
  625. };
  626. // 提取人材机汇总相关(人材机汇总表、承包材料表)
  627. function extractGLJSummary(tenderSrc) {
  628. const initData = { gljSummary: [], differentiaSummary: [], exponentialSummary: [] };
  629. if (importFileKind !== FileKind.tender) {
  630. return initData;
  631. }
  632. const taxType = getValue(tenderSrc, ['_TaxModel']); // 计税方式
  633. const gljListSrc = arrayValue(tenderSrc, ['LabourMaterialsEquipmentsMachinesSummary']);
  634. return gljListSrc.reduce((acc, gljSrc) => {
  635. acc.gljSummary.push(extractGLJ(gljSrc));
  636. const differentiaGLJ = extractDifferentiaGLJ(gljSrc);
  637. if (differentiaGLJ) {
  638. acc.differentiaSummary.push(differentiaGLJ);
  639. }
  640. const exponentialGLJ = extractExponentialGLJ(gljSrc);
  641. if (exponentialGLJ) {
  642. acc.exponentialSummary.push(exponentialGLJ);
  643. }
  644. return acc;
  645. }, initData);
  646. // 获取原始编码
  647. function getOriginalCode(code) {
  648. //编码后面有-\d+的形式,去掉-\d+取前面的字符串作为原始代码
  649. return code.replace(/(.*)-\d+$/, '$1');
  650. }
  651. // TODO (不靠谱) 获取人材机类型数据
  652. // 导入的源文件没有细化区分人材机类型,这里只是暂时大概给个值。后续会在后端与标准人材机进行配对。也因此无法准确处理补充人材机
  653. function getTypeData(gljSrc) {
  654. const concrete = getBool(getValue(gljSrc, ['_Concrete']));
  655. if (concrete) {
  656. return { type: 205, shorName: '商砼' };
  657. }
  658. const type = getValue(gljSrc, ['_Kind']);
  659. switch (type) {
  660. case '6':
  661. return { type: 202, shorName: '砼' };
  662. case '7':
  663. return { type: 301, shorName: '机' };
  664. case '15':
  665. return { type: 6, shortName: '管' };
  666. default:
  667. return { type: 201, shortName: '材' };
  668. }
  669. }
  670. // 根据计税方式获取价格,一般计税对应不含税,简易对应含税
  671. function getPriceByTaxType(gljSrc, taxType) {
  672. return taxType === TaxType.NORMAL
  673. ? {
  674. base_price: getValue(gljSrc, ['_NoTaxOrgPrice']),
  675. market_price: getValue(gljSrc, ['_NoTaxPrice'])
  676. }
  677. : {
  678. base_price: getValue(gljSrc, ['_TaxOrgPrice']),
  679. market_price: getValue(gljSrc, ['_TaxPrice'])
  680. };
  681. }
  682. // 提取组成物
  683. function extractRatios(gljSrc) {
  684. const ratiosSrc = arrayValue(gljSrc, ['LabourMaterialsEquipmentsMachinesElement']);
  685. countData.ratioCount += ratiosSrc.length;
  686. return ratiosSrc.map(src => ({
  687. code: getValue(src, ['_Number']),
  688. consumption: getValue(src, ['_Quantity'])
  689. }));
  690. }
  691. // 提取项目人材机
  692. function extractGLJ(gljSrc) {
  693. countData.projectGLJCount++;
  694. const code = getValue(gljSrc, ['_Number']);
  695. return {
  696. code,
  697. original_code: getOriginalCode(code),
  698. name: getValue(gljSrc, ['_Name']),
  699. specs: getValue(gljSrc, ['_Specification']),
  700. unit: getValue(gljSrc, ['_Unit']),
  701. ...getTypeData(gljSrc),
  702. ...getPriceByTaxType(gljSrc, taxType), // 软件中项目人材机是没有价格的,只是为了后续处理单价文件
  703. is_main_material: getBool(getValue(gljSrc, ['_MainMaterial'])),
  704. is_evaluate: getBool(getValue(gljSrc, ['_ProvisionalMaterial'])),
  705. supply: Provider[getValue(gljSrc, ['_Provider'])],
  706. delivery: getValue(gljSrc, ['_Delivery']),
  707. delivery_address: getValue(gljSrc, ['_Location']),
  708. originPlace: getValue(gljSrc, ['_ProducingArea']),
  709. vender: getValue(gljSrc, ['_Supplier']),
  710. qualityGrace: getValue(gljSrc, ['_Character']),
  711. remark: getValue(gljSrc, ['_Remark']),
  712. ratios: extractRatios(gljSrc)
  713. };
  714. }
  715. // 提取造价信息差额调整法
  716. function extractDifferentiaGLJ(gljSrc) {
  717. // 风险系数或者基准单价有值,才算一条差额数据
  718. const riskCoe = getValue(gljSrc, ['_ProviderRate']);
  719. const standardPrice = getValue(gljSrc, ['_ProviderBase']);
  720. if ((riskCoe && riskCoe !== '0') || (standardPrice && standardPrice !== '0')) {
  721. return {
  722. code: getValue(gljSrc, ['_Number']),
  723. name: getValue(gljSrc, ['_Name']),
  724. specs: getValue(gljSrc, ['_Specification']),
  725. unit: getValue(gljSrc, ['_Unit']),
  726. quantity: getValue(gljSrc, ['_Quantity']),
  727. riskCoe,
  728. standardPrice,
  729. market_price: getPriceByTaxType(gljSrc, taxType).market_price,
  730. remark: getValue(gljSrc, ['_Remark']),
  731. };
  732. }
  733. return null;
  734. }
  735. // 提取价格指数调整法
  736. function extractExponentialGLJ(gljSrc) {
  737. // 变值权重或基本、现行价格指数有值,才算一条指数数据
  738. const varWeight = getValue(gljSrc, ['_Weight']);
  739. const FO = getValue(gljSrc, ['_BasicPrice']);
  740. const FI = getValue(gljSrc, ['_CurrentPrice']);
  741. if ((varWeight && varWeight !== '0') || (FO && FO !== '0') || (FI && FI !== '0')) {
  742. return {
  743. code: getValue(gljSrc, ['_Number']),
  744. name: getValue(gljSrc, ['_Name']),
  745. specs: getValue(gljSrc, ['_Specification']),
  746. varWeight: varWeight,
  747. FO: FO,
  748. FI: FI,
  749. remark: getValue(gljSrc, ['_Remark'])
  750. };
  751. }
  752. return null;
  753. }
  754. }
  755. // 提取评标材料
  756. function extractBidEvaluationSummary(tenderSrc) {
  757. if (importFileKind !== FileKind.tender) {
  758. return [];
  759. }
  760. const srcList = arrayValue(tenderSrc, ['BidEvaluationMainMaterial']);
  761. return srcList.map(gljSrc => ({
  762. seq: getValue(gljSrc, ['_Code']),
  763. code: getValue(gljSrc, ['_Number']),
  764. name: getValue(gljSrc, ['_Name']),
  765. specs: getValue(gljSrc, ['_Specification']),
  766. unit: getValue(gljSrc, ['_Unit']),
  767. quantity: getValue(gljSrc, ['_Quantity']),
  768. market_price: getValue(gljSrc, ['_Price']),
  769. originPlace: getValue(gljSrc, ['_ProducingArea']),
  770. vender: getValue(gljSrc, ['_Supplier']),
  771. remark: getValue(gljSrc, ['_Remark'])
  772. }));
  773. }
  774. /*
  775. * 转换从xml提取的数据,转换成软件所需的数据结构
  776. *
  777. */
  778. async function transformData(extractedData) {
  779. const IDPlaceholder = await ajaxPost('/pm/import/getProjectPlaceholder', countData);
  780. extractedData.ID = IDPlaceholder.project++;
  781. // 最终上传到服务器的转换后的数据
  782. const transformedData = {
  783. ID: extractedData.ID,
  784. ParentID: extractedData.ParentID,
  785. NextSiblingID: extractedData.NextSiblingID,
  786. preID: extractedData.preID,
  787. name: extractedData.name,
  788. basicInformation: extractedData.basicInformation,
  789. projType: extractedData.projType,
  790. property: extractedData.property,
  791. shareInfo: [],
  792. engs: []
  793. };
  794. // 所有的清单模板库ID
  795. const allTemplateLibIDs = [];
  796. extractedData.engs.forEach(eng => {
  797. eng.tenders.forEach(tender => {
  798. let templateLibID = tender.property.templateLibID;
  799. if (!allTemplateLibIDs.includes(templateLibID)) {
  800. allTemplateLibIDs.push(templateLibID);
  801. }
  802. });
  803. });
  804. // 模板映射:{[templateLibID]: data}
  805. const templateMapping = await ajaxPost('/template/bills/api/getNeedfulTemplate', { allTemplateLibIDs });
  806. for (let i = 0; i < extractedData.engs.length; i++) {
  807. const curEng = extractedData.engs[i];
  808. const preEng = transformedData.engs[i - 1];
  809. curEng.ID = IDPlaceholder.project++;
  810. curEng.ParentID = extractedData.ID;
  811. curEng.NextSiblingID = -1;
  812. if (preEng) {
  813. preEng.NextSiblingID = curEng.ID;
  814. }
  815. const engData = {
  816. ID: curEng.ID,
  817. ParentID: curEng.ParentID,
  818. NextSiblingID: curEng.NextSiblingID,
  819. code: curEng.code,
  820. name: curEng.name,
  821. projType: curEng.projType,
  822. shareInfo: [],
  823. tenders: []
  824. };
  825. transformedData.engs.push(engData);
  826. for (let j = 0; j < curEng.tenders.length; j++) {
  827. const curTender = curEng.tenders[j];
  828. const preTender = engData.tenders[j - 1];
  829. curTender.ID = IDPlaceholder.project++;
  830. curTender.ParentID = curEng.ID;
  831. curTender.NextSiblingID = -1;
  832. curTender.property.unitPriceFile.id = IDPlaceholder.unitPriceFile++;
  833. if (preTender) {
  834. preTender.tender.NextSiblingID = curTender.ID;
  835. }
  836. // 项目清单模板(后台清单模板中提取含有固定类别的数据)
  837. const billsTemplate = _.cloneDeep(templateMapping[curTender.property.templateLibID]);
  838. // 重设模板树结构数据
  839. BILLS_UTIL.resetTreeData(billsTemplate, uuid.v1);
  840. console.log(billsTemplate);
  841. const tenderData = transformTender(curTender, IDPlaceholder, billsTemplate);
  842. tenderData.tender.property.rootProjectID = transformedData.ID;
  843. engData.tenders.push(tenderData);
  844. }
  845. }
  846. console.log(`transformedData`);
  847. console.log(transformedData);
  848. return transformedData;
  849. }
  850. // 获取承包人材料类型
  851. function getAdjustType(tenderData) {
  852. if (tenderData.differentiaSummary.length) {
  853. return AdjustType.info;
  854. } else if (tenderData.exponentialSummary.length) {
  855. return AdjustType.coe;
  856. } else {
  857. return AdjustType.info;
  858. }
  859. }
  860. // 获取当前文件
  861. // 转换单位工程的数据(直接可插入数据库的数据),返回{tender: {}, bills: [], ration: [], rationGLJ: [], projectGLJ: [], unitPrice: [], mixRatio: []}
  862. function transformTender(tenderData, IDPlaceholder, billsTemplate) {
  863. const detailData = transformDetail(tenderData, IDPlaceholder, billsTemplate);
  864. // 提取需要插入的单位工程数据
  865. const transformedTender = {
  866. ID: tenderData.ID,
  867. ParentID: tenderData.ParentID,
  868. NextSiblingID: tenderData.NextSiblingID,
  869. code: tenderData.code,
  870. name: tenderData.name,
  871. projType: tenderData.projType,
  872. property: tenderData.property,
  873. projectFeature: tenderData.projectFeature,
  874. engineering: tenderData.engineering,
  875. defaultRationLib: tenderData.defaultRationLib,
  876. rationLibIDs: tenderData.rationLibIDs,
  877. gljLibIDs: tenderData.gljLibIDs,
  878. shareInfo: []
  879. };
  880. transformedTender.property.compilationIllustration = tenderData.compilationIllustration;
  881. transformedTender.property.gljAdjustType = getAdjustType(tenderData);
  882. transformedTender.property.decimal = tenderPropertyDecimal;
  883. transformedTender.property.billsQuantityDecimalValue = tenderPropertyBillsQuantityDecimal;
  884. detailData.tender = transformedTender;
  885. return detailData;
  886. }
  887. // 过滤掉相关费用代号的数据(递归地)
  888. // 返回被过滤掉的数据
  889. function filterDataByFeeCodes(billsData, feeCodes) {
  890. const filterd = [];
  891. billsData.forEach(bills => {
  892. if (bills.items && bills.items.length) {
  893. const newItems = [];
  894. bills.items.forEach(subBills => {
  895. if (!feeCodes.includes(subBills.feeCode)) {
  896. newItems.push(subBills);
  897. } else {
  898. filterd.push(subBills);
  899. }
  900. });
  901. bills.items = newItems;
  902. // bills.items = bills.items.filter(subBills => !feeCodes.includes(subBills.feeCode));
  903. const subFilterd = filterDataByFeeCodes(bills.items, feeCodes);
  904. filterd.push(...subFilterd);
  905. }
  906. });
  907. return filterd;
  908. }
  909. // 合并清单,将提取出来的清单相关数据,合并进项目清单(模板)
  910. function mergeBills(tenderData, billsTemplate) {
  911. const mergedBills = [...billsTemplate];
  912. const roots = billsTemplate.filter(bills => bills.ParentID === -1);
  913. let lastRoot = roots.find(root => root.NextSiblingID === -1);
  914. mergeWorkSummary(tenderData.workSummary);
  915. mergeFBFX(tenderData.fbfx);
  916. mergeCSXM(tenderData.csxm);
  917. mergeOther(tenderData.other);
  918. mergeTax(tenderData.tax);
  919. return mergedBills;
  920. // 合并清单数据
  921. function mergeitems(fixedBills, items) {
  922. const daryWorkMap = {
  923. '人工': fixedFlag.LABOUR,
  924. '材料': fixedFlag.MATERIAL,
  925. '机械': fixedFlag.MACHINE,
  926. '施工机械': fixedFlag.MACHINE,
  927. '施工机具': fixedFlag.MACHINE
  928. };
  929. const fixedBillsFlag = getFlag(fixedBills);
  930. let preBills = billsTemplate.find(bills => bills.ParentID === fixedBills.ID && bills.NextSiblingID === -1);
  931. items.forEach(bills => {
  932. // 计日工需要特殊处理,兼容广联达的数据,广联达的计日工下的人工、材料、机械的费用字典不对,因此用名称匹配
  933. let matched;
  934. if (fixedBillsFlag === fixedFlag.DAYWORK) {
  935. const dayWorkSubFlag = daryWorkMap[bills.name];
  936. matched = dayWorkSubFlag
  937. ? billsTemplate.find(templateBills => getFlag(templateBills) === dayWorkSubFlag)
  938. : null;
  939. } else {
  940. matched = billsTemplate.find(templateBills => FlagFeeCodeMap[getFlag(templateBills)] === bills.feeCode);
  941. }
  942. if (matched) {
  943. assignAttr(matched, bills, ['items'], true);
  944. if (bills.items && bills.items.length) {
  945. mergeitems(matched, bills.items);
  946. //mergedBills.push(...mergeDataRecur(fixedBills, [bills]))
  947. }
  948. preBills = matched;
  949. } else {
  950. const nextID = preBills && preBills.NextSiblingID || -1;
  951. mergedBills.push(...mergeDataRecur(fixedBills, [bills]));
  952. bills.NextSiblingID = nextID;
  953. if (preBills) {
  954. preBills.NextSiblingID = bills.ID;
  955. }
  956. preBills = bills;
  957. }
  958. });
  959. }
  960. // 简单地合并: 设置某清单的金额,数据递归插入到某清单的子项
  961. function simpleMerge(flag, src) {
  962. const fixedBills = billsTemplate.find(bills => getFlag(bills) === flag);
  963. if (fixedBills) {
  964. assignAttr(fixedBills, src, ['fees', 'feeCode']);
  965. mergedBills.push(...mergeDataRecur(fixedBills, src.items));
  966. }
  967. }
  968. // 合并大项费用
  969. function mergeWorkSummary(workSummary) {
  970. // 首层数据与清单模板根据费用字典进行匹配,匹配到的则赋值一些属性,匹配不到则将其及其所有子数据插入到模板最末大项费用
  971. debugger;
  972. workSummary.forEach(summaryBills => {
  973. const matched = roots.find(root => FlagFeeCodeMap[getFlag(root)] === summaryBills.feeCode);
  974. if (matched) {
  975. if (!summaryBills.calcBase) {
  976. summaryBills.calcBase = matched.calcBase;
  977. matched.ignoreValidator = true; // 用了模板的基数,基数无视基数验证
  978. }
  979. assignAttr(matched, summaryBills, ['items'], true);
  980. } else {
  981. mergedBills.push(...mergeDataRecur(null, [summaryBills]));
  982. if (lastRoot) {
  983. lastRoot.NextSiblingID = summaryBills.ID;
  984. lastRoot = summaryBills;
  985. }
  986. }
  987. });
  988. }
  989. // 合并分部分项
  990. function mergeFBFX(fbfxSrc) {
  991. simpleMerge(fixedFlag.SUB_ENGINERRING, fbfxSrc);
  992. }
  993. // 合并措施项目
  994. function mergeCSXM(csxmSrc) {
  995. const fixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.MEASURE);
  996. fixedBills.fees = mergeFees(fixedBills.fees, csxmSrc.fees);
  997. mergeitems(fixedBills, csxmSrc.items);
  998. }
  999. // 合并其他项目
  1000. function mergeOther(otherSrc) {
  1001. const fixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.OTHER);
  1002. fixedBills.fees = mergeFees(fixedBills.fees, otherSrc.fees);
  1003. // 合并其他项目费
  1004. // SundryCosts其他项目费会包含暂列金额等后续会再次出现的数据,因此合并SundryCosts的数据时,过滤掉一部分数据
  1005. const feeCodeFilter = [
  1006. FlagFeeCodeMap[fixedFlag.PROVISIONAL], // 暂列金额
  1007. FlagFeeCodeMap[fixedFlag.MATERIAL_PROVISIONAL], // 材料暂估
  1008. FlagFeeCodeMap[fixedFlag.ENGINEERING_ESITIMATE], // 专业工程暂估
  1009. FlagFeeCodeMap[fixedFlag.DAYWORK], // 计日工
  1010. FlagFeeCodeMap[fixedFlag.TURN_KEY_CONTRACT], // 总承包服务费
  1011. FlagFeeCodeMap[fixedFlag.CLAIM], // 索赔
  1012. FlagFeeCodeMap[fixedFlag.VISA], // 现场签证
  1013. ];
  1014. const filterdBills = filterDataByFeeCodes([otherSrc.sundryCosts], feeCodeFilter);
  1015. /**
  1016. * 有些源xml文件中,被过滤掉SundryCosts中的子项,相对于Sundry的子项会多一些属性
  1017. * 比如:Sundry->SunryCosts->SundryCostsGroup->SundryCostsItem中的材料暂估价,含有QtyFormula属性,但是Sundry->ProvisionalMaterialEquipment中不含有QtyFormula
  1018. * 因此,即使后续Sundry的子项会赋值给模板,也要将被过滤掉的子项的属性先赋给模板
  1019. */
  1020. filterdBills.forEach(filterdItem => {
  1021. const matched = billsTemplate.find(templateBills => FlagFeeCodeMap[getFlag(templateBills)] === filterdItem.feeCode);
  1022. if (matched) {
  1023. assignAttr(matched, filterdItem, ['items'], true); // 不拷贝item属性
  1024. matched.ignoreA
  1025. }
  1026. });
  1027. const sundryCostsBills = otherSrc.sundryCosts.items;
  1028. mergeitems(fixedBills, sundryCostsBills);
  1029. // 合并暂列金额
  1030. simpleMerge(fixedFlag.PROVISIONAL, otherSrc.provisional);
  1031. // 合并材料暂估,由于材料暂估的子元素是暂估人材机,因此对清单来说,只需处理材料暂估根元素的属性
  1032. const zgcFixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.MATERIAL_PROVISIONAL);
  1033. assignAttr(zgcFixedBills, otherSrc.ProvisionalMaterialEquipment);
  1034. // 合并专业工程暂估价
  1035. simpleMerge(fixedFlag.ENGINEERING_ESITIMATE, otherSrc.specialty);
  1036. // 合并计日工
  1037. const dayWorkFixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.DAYWORK);
  1038. assignAttr(dayWorkFixedBills, otherSrc.dayWork, ['fees', 'feeCode']);
  1039. mergeitems(dayWorkFixedBills, otherSrc.dayWork.items);
  1040. // 合并总承包服务费
  1041. simpleMerge(fixedFlag.TURN_KEY_CONTRACT, otherSrc.mainContractor);
  1042. // 合并索赔
  1043. simpleMerge(fixedFlag.CLAIM, otherSrc.claim);
  1044. // 合并现场签证
  1045. simpleMerge(fixedFlag.VISA, otherSrc.visa);
  1046. }
  1047. // 合并税金
  1048. function mergeTax(taxSrc) {
  1049. const taxFixedBills = billsTemplate.find(bills => getFlag(bills) === fixedFlag.TAX);
  1050. if (!taxSrc.calcBase) {
  1051. taxSrc.calcBase = taxFixedBills.calcBase;
  1052. taxFixedBills.ignoreValidator = true; // 用了模板的基数,基数无视基数验证
  1053. } else {
  1054. taxFixedBills.ignoreValidator = false;
  1055. }
  1056. assignAttr(taxFixedBills, taxSrc);
  1057. }
  1058. }
  1059. // 给固定清单设置上费用字典,因为在合并清单的时候,清单模板中可能有一些数据应该有规定的费用字典,但是没有被设置上费用字典。
  1060. function setupFeeCode(billsData) {
  1061. billsData.forEach(bills => {
  1062. if (bills.feeCode) {
  1063. return;
  1064. }
  1065. bills.feeCode = FlagFeeCodeMap[getFlag(bills)] || '';
  1066. })
  1067. }
  1068. // 检查清单是否引用了自身,比如广联达导出文件中 材料保管费基数为CLBGF
  1069. function isCalcBaseCycle(bills) {
  1070. return bills.calcBase.match(new RegExp(`\\b${bills.feeCode}\\b`)); // \b: 匹配前一个字符和后一个字符不全为\w的位置
  1071. }
  1072. // 转换计算基数
  1073. // 1.有子项数据,则清空基数
  1074. // 2.引用的基数造成自身循环,比如分部分项部分引用了QDF
  1075. // 3.费用代号匹配清单基数的代号
  1076. // 4.费用代号匹配不到清单基数的代号,则匹配此费用代号的清单,作为行引用(即ID引用)
  1077. // 5.对应字典里找不到则设置成金额
  1078. function transformCalcBase(billsData) {
  1079. // 费用代号 - 计算基数映射
  1080. const feeCodeFormulaMap = {}
  1081. Object
  1082. .entries(FormulaFeeCodeMap)
  1083. .forEach(([formula, feeCode]) => {
  1084. feeCodeFormulaMap[feeCode] = formula;
  1085. });
  1086. // 费用代号 - ID映射
  1087. const feeCodeIDMap = {};
  1088. billsData.forEach(data => {
  1089. if (data.feeCode) {
  1090. feeCodeIDMap[data.feeCode] = data.ID;
  1091. }
  1092. });
  1093. for (const bills of billsData) {
  1094. if (!bills.calcBase || bills.ignoreValidator) {
  1095. continue;
  1096. }
  1097. const sub = billsData.find(data => data.ParentID === bills.ID);
  1098. // 有子项数据,则清空基数,费率
  1099. if (sub) {
  1100. bills.calcBase = '';
  1101. bills.feeRate = '';
  1102. continue;
  1103. }
  1104. if (typeof bills.calcBase !== 'string') {
  1105. bills.calcBase = String(bills.calcBase);
  1106. }
  1107. // 引用的基数造成自循环,清空基数
  1108. const isCycle = isCalcBaseCycle(bills);
  1109. if (isCycle) {
  1110. bills.calcBase = '';
  1111. continue;
  1112. }
  1113. // 提取基数中的费用代号
  1114. bills.calcBase = bills.calcBase.replace(/\s/g, '');
  1115. const feeCodes = bills.calcBase.split(/[\+\-\*\/]/g);
  1116. // 提取操作符
  1117. const oprs = bills.calcBase.match(/[\+\-\*\/]/g);
  1118. // 转换后的基数
  1119. const newBase = [];
  1120. let illegal = false; //不合法
  1121. for (const feeCode of feeCodes) {
  1122. const formula = feeCodeFormulaMap[feeCode];
  1123. const refID = feeCodeIDMap[feeCode];
  1124. if (formula) { // 匹配到公式
  1125. newBase.push(formula);
  1126. } else if (refID) { // 匹配到行引用
  1127. newBase.push(`@${refID}`) // 转换成ID引用
  1128. } else { // 无法识别
  1129. illegal = true;
  1130. break;
  1131. }
  1132. }
  1133. if (illegal) {
  1134. const fee = getFee(bills.fees, ['common', 'totalFee']);
  1135. const feeRate = bills.feeRate && parseFloat(bills.feeRate) !== 0 ? parseFloat(bills.feeRate) : 0;
  1136. if (fee && parseFloat(fee) !== 0 && feeRate) {
  1137. bills.calcBase = scMathUtil.roundForObj(parseFloat(fee) * 100 / feeRate, Decimal.FEE);
  1138. } else {
  1139. bills.calcBase = fee !== '0' ? fee : '';
  1140. }
  1141. } else {
  1142. let newCalcBase = '';
  1143. for (let i = 0; i < newBase.length; i++) {
  1144. newCalcBase += newBase[i];
  1145. if (oprs && oprs[i]) {
  1146. newCalcBase += oprs[i];
  1147. }
  1148. }
  1149. bills.calcBase = newCalcBase;
  1150. }
  1151. }
  1152. }
  1153. // 转换清单
  1154. function transformBills(tenderData, billsTemplate) {
  1155. const rst = {
  1156. bills: [],
  1157. billsQuantityDetails: []
  1158. };
  1159. const billsData = mergeBills(tenderData, billsTemplate);
  1160. setupFeeCode(billsData);
  1161. transformCalcBase(billsData);
  1162. // 处理综合单价
  1163. // 没有子清单,且没有综合单价,且有综合合价,则综合单价 = 综合合价 / 工程量
  1164. billsData.forEach(bills => {
  1165. const hasChild = billsData.some(data => data.ParentID === bills.ID);
  1166. let unitFee = getFee(bills.fees, ['common', 'unitFee']);
  1167. const totalFee = getFee(bills.fees, ['common', 'totalFee']);
  1168. if (!hasChild && !parseFloat(unitFee) && totalFee && parseFloat(totalFee)) {
  1169. // 不存工程量
  1170. if (!bills.quantity || !parseFloat(bills.quantity)) {
  1171. unitFee = totalFee;
  1172. // 源不存在工程量,没有计算基数、但是却有综合合价,工程量要设置为1
  1173. if (!bills.calcBase) {
  1174. bills.quantity = '1';
  1175. }
  1176. } else {
  1177. // 综合合价的小数位数
  1178. //const totalFeeDecimal = totalFee.match(/\.\d+/);
  1179. //unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, totalFeeDecimal ? totalFeeDecimal[0] : 0);
  1180. unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, Decimal.FEE);
  1181. }
  1182. const commonFee = bills.fees.find(fee => fee.fieldName === 'common');
  1183. if (commonFee) {
  1184. commonFee.unitFee = unitFee;
  1185. }
  1186. }
  1187. bills.projectID = tenderData.ID;
  1188. // 工程量明细
  1189. transformQuantityDetails(tenderData.ID, bills.quantityDetails, bills.ID, 'billID');
  1190. bills.quantityEXP = bills.quantityDetails && bills.quantityDetails.length ? GCLMXHj : bills.quantity;
  1191. if (bills.quantityDetails) {
  1192. rst.billsQuantityDetails.push(...bills.quantityDetails);
  1193. }
  1194. rst.bills.push(bills);
  1195. });
  1196. return rst;
  1197. }
  1198. // 转换工程量明细数据
  1199. function transformQuantityDetails(tenderID, quantityDetails, refID, typeKey) {
  1200. if (quantityDetails) {
  1201. quantityDetails.forEach(item => {
  1202. item.ID = uuid.v1();
  1203. item[typeKey] = refID; // billID、rationID
  1204. item.projectID = tenderID;
  1205. });
  1206. }
  1207. }
  1208. // 转换人材机汇总相关数据(人材机汇总、承包人材料、评标材料、暂估价材料、组成物、单价文件)
  1209. function transformGLJList(tenderData, IDPlaceholder, projectGLJMap) {
  1210. const rst = {
  1211. projectGLJ: [], // 项目人材机
  1212. contractorList: [], // 承包人材料
  1213. bidEvaluationList: [], // 评标材料
  1214. evaluationList: [], // 暂估材料
  1215. unitPrice: [], // 单价文件
  1216. mixRatio: [] // 组成物
  1217. };
  1218. transformGLJSummary();
  1219. transformContractorSummary();
  1220. transformRelatedGLJList(tenderData.bidEvaluationSummary, rst.bidEvaluationList, 'is_eval_material');
  1221. transformEvalSummary();
  1222. return rst;
  1223. // 转换项目人材机、组成物
  1224. function transformGLJSummary() {
  1225. // 项目人材机
  1226. tenderData.gljSummary.forEach(projectGLJ => {
  1227. projectGLJ.project_id = tenderData.ID;
  1228. projectGLJ.id = IDPlaceholder.projectGLJ++;
  1229. projectGLJMap[projectGLJ.code] = projectGLJ;
  1230. });
  1231. tenderData.gljSummary.forEach(projectGLJ => {
  1232. //组成物数据
  1233. projectGLJ.ratios.forEach(ratio => {
  1234. const matched = projectGLJMap[ratio.code];
  1235. ratio.code = matched.code;
  1236. ratio.projectGLJID = projectGLJ.id;
  1237. ratio.id = IDPlaceholder.ratio++;
  1238. ratio.unit_price_file_id = tenderData.property.unitPriceFile.id;
  1239. ratio.unit = matched && matched.unit || '';
  1240. ratio.name = matched && matched.name || '';
  1241. ratio.specs = matched && matched.specs || '';
  1242. ratio.type = matched && matched.type || 1;
  1243. ratio.connect_key = [projectGLJ.code || 'null', projectGLJ.name || 'null', projectGLJ.specs || 'null', projectGLJ.unit || 'null', projectGLJ.type].join('|-|');
  1244. rst.mixRatio.push(ratio);
  1245. });
  1246. rst.projectGLJ.push(projectGLJ);
  1247. // 单价文件数据:
  1248. rst.unitPrice.push(generateUnitPrice(projectGLJ));
  1249. });
  1250. }
  1251. // 转换与项目人材机关联的材料
  1252. function transformRelatedGLJList(list, container, relatedType) {
  1253. list.forEach(glj => {
  1254. glj.ID = uuid.v1();
  1255. glj.projectID = tenderData.ID;
  1256. glj.projectGLJID = -1;
  1257. if (typeof glj.seq === 'undefined') {
  1258. glj.seq = glj.code;
  1259. }
  1260. const projectGLJ = projectGLJMap[glj.code];
  1261. if (projectGLJ) {
  1262. projectGLJ[relatedType] = 1;
  1263. glj.is_related = 1;
  1264. glj.projectGLJID = projectGLJ.id;
  1265. }
  1266. container.push(glj);
  1267. });
  1268. }
  1269. // 转换承包人材料
  1270. function transformContractorSummary() {
  1271. // 由于承包人差额数据和指数数据共用承包人材料表,因此需要合并差额数据和指数数据
  1272. const mergedList = [];
  1273. tenderData.exponentialSummary.forEach(eGLJ => {
  1274. const matched = tenderData.differentiaSummary.find(dGLJ => dGLJ.code === eGLJ.code);
  1275. if (matched) {
  1276. assignAttr(matched, eGLJ, ['varWeight', 'FO', 'FI']);
  1277. } else {
  1278. mergedList.push(eGLJ);
  1279. }
  1280. });
  1281. mergedList.push(...tenderData.differentiaSummary);
  1282. transformRelatedGLJList(mergedList, rst.contractorList, 'is_contractor_material');
  1283. }
  1284. // 转换暂估价材料
  1285. function transformEvalSummary() {
  1286. const evalGLJList = tenderData.gljSummary
  1287. .filter(glj => glj.is_evaluate)
  1288. .map(glj => {
  1289. const evalGLJ = {};
  1290. assignAttr(evalGLJ, glj, [
  1291. 'code', 'name', 'specs', 'unit', 'quantity', 'market_price',
  1292. 'originPlace', 'vender', 'remark'
  1293. ]);
  1294. evalGLJ.seq = evalGLJ.code;
  1295. return evalGLJ;
  1296. });
  1297. transformRelatedGLJList(evalGLJList, rst.evaluationList, 'is_evaluate');
  1298. }
  1299. // 生成单价文件
  1300. function generateUnitPrice(projectGLJ) {
  1301. return {
  1302. projectGLJID: projectGLJ.id, //做个标记,后端查找标准数据后,方便更新组成物数据
  1303. unit_price_file_id: tenderData.property.unitPriceFile.id,
  1304. id: IDPlaceholder.unitPrice++,
  1305. code: projectGLJ.code,
  1306. original_code: projectGLJ.original_code,
  1307. name: projectGLJ.name,
  1308. unit: projectGLJ.unit,
  1309. specs: projectGLJ.specs,
  1310. type: projectGLJ.type,
  1311. short_name: projectGLJ.shortName,
  1312. base_price: projectGLJ.base_price,
  1313. market_price: projectGLJ.market_price
  1314. };
  1315. }
  1316. }
  1317. // 转换定额、定额人材机、定额系数
  1318. // @param {Object} tenderData - 提取的单位工程数据
  1319. // @param {Array} billsData - 转换后的清单数据
  1320. // @param {Object} projectGLJMap - 转换项目人材机时生成的项目人材机编码-数据的映射
  1321. function transformRations(tenderData, billsData, projectGLJMap) {
  1322. const rst = {
  1323. ration: [],
  1324. rationGLJ: [],
  1325. rationCoe: [],
  1326. rationQuantityDetails: []
  1327. };
  1328. billsData
  1329. .filter(bills => bills.rations && bills.rations.length)
  1330. .forEach(bills => {
  1331. bills.rations.forEach(ration => {
  1332. // TODO 取费专业不知如何取,暂时取单位工程取费专业(导出的文件没有可用的取费专业字段,因此需要后端匹配标准定额)
  1333. // 如果标准定额有取费专业,则会替换掉这里设置的取费专业
  1334. ration.programID = tenderData.property.projectEngineering;
  1335. ration.ID = uuid.v1();
  1336. ration.projectID = tenderData.ID;
  1337. ration.billsItemID = bills.ID;
  1338. ration.contain = getContain(bills, ration);
  1339. // 工程量明细
  1340. transformQuantityDetails(tenderData.ID, ration.quantityDetails, ration.ID, 'rationID');
  1341. ration.quantityEXP = getQuantityEXP(bills, ration);
  1342. if (ration.quantityDetails) {
  1343. rst.rationQuantityDetails.push(...ration.quantityDetails);
  1344. }
  1345. rst.ration.push(ration);
  1346. // 定额人材机
  1347. rst.rationGLJ.push(...transformRationGLJs(bills, ration));
  1348. // 定额系数
  1349. rst.rationCoe.push(generateRationCoe(ration));
  1350. });
  1351. });
  1352. return rst;
  1353. // 含量:定额工程量/清单工程量
  1354. function getContain(bills, ration) {
  1355. if (!bills.quantity || !ration.quantity) {
  1356. return '0';
  1357. } else {
  1358. const tempQuantity = ration.quantity / bills.quantity;
  1359. return isFinite(tempQuantity) ? scMathUtil.roundForObj(tempQuantity, Decimal.QUANTITY) : '0';
  1360. }
  1361. }
  1362. // 转换定额人材机
  1363. function transformRationGLJs(bills, ration) {
  1364. return ration.rationGLJs.map(rationGLJ => {
  1365. const matched = projectGLJMap[rationGLJ.code];
  1366. if (matched) {
  1367. rationGLJ.projectGLJID = matched.id;
  1368. rationGLJ.code = matched.code;
  1369. rationGLJ.type = matched.type;
  1370. rationGLJ.shortName = matched.shortName;
  1371. rationGLJ.name = matched.name;
  1372. rationGLJ.original_code = matched.original_code;
  1373. rationGLJ.unit = matched.unit;
  1374. rationGLJ.specs = matched.specs;
  1375. }
  1376. rationGLJ.ID = uuid.v1();
  1377. rationGLJ.projectID = tenderData.ID;
  1378. rationGLJ.billsItemID = bills.ID;
  1379. rationGLJ.rationID = ration.ID;
  1380. rationGLJ.rationCode = ration.code; // 暂时跟定额编码关联,后端好匹配标准数据
  1381. rationGLJ.rationItemQuantity = rationGLJ.quantity; // 定额消耗,暂时取消耗量,需要后端匹配标准数据后更新
  1382. return rationGLJ;
  1383. });
  1384. }
  1385. // 生成定额系数(项目数据处理的方法很有可能无法共用,因此不把重庆的方法抽离了)
  1386. function generateRationCoe(ration) {
  1387. return {
  1388. projectID: ration.projectID,
  1389. rationID: ration.ID,
  1390. coeID: -1,
  1391. ID: uuid.v1(),
  1392. seq: 1, // 以前排序有的字段,暂时没什么用,不过还是赋上一个值
  1393. name: '自定义系数',
  1394. content: '人工×1,材料×1,机械×1,主材×1,设备×1',
  1395. coes: [
  1396. { amount: 1, operator: '*', gljCode: null, coeType: '定额' },
  1397. { amount: 1, operator: '*', gljCode: null, coeType: '人工' },
  1398. { amount: 1, operator: '*', gljCode: null, coeType: '材料' },
  1399. { amount: 1, operator: '*', gljCode: null, coeType: '机械' },
  1400. { amount: 1, operator: '*', gljCode: null, coeType: '主材' },
  1401. { amount: 1, operator: '*', gljCode: null, coeType: '设备' },
  1402. ],
  1403. option_list: []
  1404. }
  1405. }
  1406. // 获取定额的工程量表达式
  1407. function getQuantityEXP(bills, ration) {
  1408. if (ration.quantityDetails && ration.quantityDetails.length) {
  1409. return GCLMXHj;
  1410. }
  1411. // 定额根单位与清单根单位相同,则定额工程量表达式为QDL;否则定额工程量表达式为:定额工程量 * 定额单位量词
  1412. // eg: 清单单位:m 定额单位:100m
  1413. const reg = /\d+(\D+.*)/;
  1414. const billsRootUnit = bills.unit && bills.unit.replace(reg, '$1') || '';
  1415. const rationRootUnit = ration.unit && ration.unit.replace(reg, '$1') || '';
  1416. if (billsRootUnit === rationRootUnit) {
  1417. return QDL;
  1418. }
  1419. const numReg = /(\d+)\D+.*/;
  1420. const num = ration.unit && ration.unit.replace(numReg, '$1') || '1';
  1421. return ration.quantity * num;
  1422. }
  1423. }
  1424. // 删除一些无用属性,减少通信数据量
  1425. function clean(detailData) {
  1426. const {
  1427. bills,
  1428. ration,
  1429. projectGLJ
  1430. } = detailData;
  1431. bills.forEach(item => delete item.items && delete item.rations && delete item.feeCode && delete item.quantityDetails);
  1432. ration.forEach(item => delete item.rationGLJs && delete item.quantityDetails);
  1433. projectGLJ.forEach(item => delete item.ratios);
  1434. }
  1435. // 需要给清单、定额价格字段赋上调价数据,不然打开项目后会被重算: project_view.js -> loadProjectData方法内
  1436. function setupTenderFees(detailData) {
  1437. const { bills, ration } = detailData;
  1438. [...bills, ...ration].forEach(item => {
  1439. if (item.fees && item.fees.length) {
  1440. item.fees.forEach(feeItem => {
  1441. if (commonUtil.isDef(feeItem.unitFee)) {
  1442. feeItem.tenderUnitFee = feeItem.unitFee;
  1443. }
  1444. if (commonUtil.isDef(feeItem.totalFee)) {
  1445. feeItem.tenderTotalFee = feeItem.totalFee;
  1446. }
  1447. })
  1448. }
  1449. });
  1450. }
  1451. // 转换详细的项目数据,清单、定额、定额人材机、项目人材机、单价文件等
  1452. function transformDetail(tenderData, IDPlaceholder, billsTemplate) {
  1453. const { bills, billsQuantityDetails } = transformBills(tenderData, billsTemplate);
  1454. // 转换定额的处理依赖转换后的项目人材机数据,因此需要先转换项目人材机相关的数据
  1455. const projectGLJMap = {};
  1456. const relatedljGLJData = transformGLJList(tenderData, IDPlaceholder, projectGLJMap);
  1457. const {
  1458. ration,
  1459. rationGLJ,
  1460. rationCoe,
  1461. rationQuantityDetails
  1462. } = transformRations(tenderData, bills, projectGLJMap);
  1463. const detailData = {
  1464. bills,
  1465. ration,
  1466. rationGLJ,
  1467. rationCoe,
  1468. quantityDetails: [...billsQuantityDetails, ...rationQuantityDetails],
  1469. ...relatedljGLJData
  1470. };
  1471. clean(detailData);
  1472. setupTenderFees(detailData);
  1473. console.log(`detailData`);
  1474. console.log(detailData);
  1475. return detailData;
  1476. }
  1477. /**
  1478. * 解压cos、zip文件
  1479. * @param {File} file - 上传的文件
  1480. * @return {Object} 解压出来的xml文件名称与xml文件文本内容映射
  1481. */
  1482. async function unzipFile(file) {
  1483. const jsZip = new JSZip();
  1484. const zip = await jsZip.loadAsync(file);
  1485. const map = {};
  1486. for (const fileName in zip.files) {
  1487. // 将二进制数据转换成字符串
  1488. map[fileName] = await jsZip.file(fileName).async('string');
  1489. }
  1490. return map;
  1491. }
  1492. //从xml文件中提取数据
  1493. async function extractData(file, escape = false) {
  1494. const fileMap = await unzipFile(file);
  1495. const projectXML = fileMap['Project.xml'];
  1496. if (!projectXML) {
  1497. throw '无有效数据';
  1498. }
  1499. const xmlObjMap = {};
  1500. for (const fileName in fileMap) {
  1501. // x2js转换xml使用了DomParser接口,会将一些字符实体进行转义。若不想被自动转义,则需要调用escapeXMLEntity
  1502. const xmlStr = escape ? util.escapeXMLEntity(fileMap[fileName]) : fileMap[fileName];
  1503. //将xml格式良好的字符串转换成对象
  1504. const x2js = new X2JS();
  1505. let xmlObj = x2js.xml_str2json(xmlStr);
  1506. xmlObj = JSON.parse(util.restoreXMLEntity(JSON.stringify(xmlObj)));
  1507. if (!xmlObj) {
  1508. throw '无有效数据。';
  1509. }
  1510. xmlObjMap[fileName] = xmlObj;
  1511. }
  1512. //提取数据
  1513. return extractProject(xmlObjMap);
  1514. };
  1515. // 接受上传的文件类型(不同的省份可以上传的文件不同)
  1516. const accept = ['.zip', '.cos'];
  1517. return {
  1518. accept,
  1519. extractData,
  1520. transformData,
  1521. }
  1522. })();