guangdong_2018_import.js 85 KB

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