guangdong_2018_import.js 73 KB

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