guangdong_2018_import.js 83 KB

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