| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475 |
- 'use strict';
- /**
- *
- *
- * @author Zhong
- * @date 2019/5/14
- * @version
- */
- /*
- * 尽可能减少服务器压力,前端提取后端所需数据,提取成更符合我们程序数据结构的数据
- * 源数据中,含有前缀"_"的数据,为原xml节点中的属性,不含前缀的数据为原xml节点的节点名
- * */
- const ImportXML = (() => {
- const fixedFlag = {
- // 分部分项工程
- SUB_ENGINERRING: 1,
- // 措施项目
- MEASURE: 2,
- // 施工技术措施项目
- CONSTRUCTION_TECH: 3,
- // 安全文明施工按实计算费用
- SAFETY_CONSTRUCTION_ACTUAL: 4,
- // 施工组织措施专项费用
- CONSTRUCTION_ORGANIZATION: 5,
- // 安全文明施工专项费用
- SAFETY_CONSTRUCTION: 6,
- // 其他项目
- OTHER: 7,
- // 暂列金额
- PROVISIONAL: 8,
- // 暂估价
- ESTIMATE: 9,
- // 材料(工程设备)暂估价
- MATERIAL_PROVISIONAL: 10,
- // 专业工程暂估价
- ENGINEERING_ESITIMATE: 11,
- // 计日工
- DAYWORK: 12,
- // 总承包服务费
- TURN_KEY_CONTRACT: 13,
- // 索赔与现场签证
- CLAIM_VISA: 14,
- // 规费
- CHARGE: 15,
- // 社会保险费及住房公积金 Social insurance fee and housing accumulation fund
- SOCIAL_INSURANCE_HOUSING_FUND: 16,
- // 工程排污费 charges for disposing pollutants
- POLLUTANTS: 17,
- // 税金
- TAX: 18,
- //工程造价
- ENGINEERINGCOST: 19,
- //增值税
- ADDED_VALUE_TAX: 20,
- //专项技术措施暂估价
- SPECIAL_TECH_PROVISIONAL: 21,
- //专业发包工程管理费
- LET_CONTRACT_MANAGEMENT: 22,
- //人工
- LABOUR: 23,
- //材料
- MATERIAL: 24,
- //施工机械
- MACHINE: 25,
- //索赔
- CLAIM: 26,
- //现场签证
- VISA: 27,
- ADDITIONAL_TAX: 28,
- //环境保护税
- ENVIRONMENTAL_PROTECTION_TAX: 29,
- //建设工程竣工档案编制费
- PROJECT_COMPLETE_ARCH_FEE:30,
- //住宅工程质量分户验收费
- HOUSE_QUALITY_ACCEPT_FEE:31,
- //组织措施费
- ORGANIZATION:32
- };
- //导入的文件类型,界面选的文件类型是生成项目的文件类型,这里的文件类型指的是,要导入文件的类型,
- //导入文件类型不同,导入数据不同
- let importFileKind = '';
- //文件类型
- const FileKind = {
- '投标': 1,
- 'tender': 1,
- '招标': 2,
- 'bid': 2,
- '控制价': 3,
- 'control': 3
- };
- //计税方法
- const TaxTypeMap = {
- '一般计税法': 1,
- '一般计税': 1,
- '简易计税法': 2,
- '简易计税': 2,
- '': 1 //默认
- };
- //清单类型
- const BillsType ={
- DXFY: 1, //大项费用
- FB: 2, //分部
- FX: 3, //分项
- BILLS: 4, //清单
- BX: 5 //补项
- };
- //项目类型
- const ProjectType = {
- Project: 'Project',
- Engineering: 'Engineering',
- Tender: 'Tender'
- };
- //读取文件转换为utf-8编码的字符串
- function readAsTextSync(file) {
- return new Promise((resolve, reject) => {
- let fr = new FileReader();
- fr.readAsText(file); //默认utf-8,如果出现乱码,得看导入文件是什么编码
- fr.onload = function () {
- resolve(this.result);
- };
- fr.onerror = function () {
- reject('读取文件失败,请重试。');
- }
- });
- }
- /*
- * 根据字段数组获得所要字段的值 eg: 要获取标段下的单项工程: ['标段', '单项工程'];
- * @param {Object}source源数据 {Array}fields字段数组
- * */
- function getValue(source, fields) {
- let cur = source;
- for (let field of fields) {
- if (!cur[field]) {
- return '';
- }
- cur = cur[field];
- }
- return cur || '';
- }
- /*
- * 获取某字段的值,强制返回数组
- * */
- function arrayValue(source, fields) {
- let target = getValue(source, fields);
- if (plainType(target) === 'Object') {
- target = [target];
- } else if (plainType(target) !== 'Array') {
- target = []
- }
- return target;
- }
- function plainType(v) {
- return Object.prototype.toString.call(v).slice(8, -1);
- }
- return function () {
- let countData = {
- projectCount: 0, //项目数量
- projectGLJCount: 0, //项目人材机数量
- ratioCount: 0, //组成物数量
- unitPriceCount: 0, //单价数量
- unitPriceFileCount: 0, //单价文件数量
- };
- //获取费用
- function getFee(fees, fields) {
- if (!Array.isArray(fees) || !fees.length) {
- return '0';
- }
- let feeData = fees.find(fee => fee.fieldName === fields[0]);
- return feeData[fields[1]] || '0';
- }
- //标段
- function loadProject(source) {
- countData.projectCount++;
- importFileKind = FileKind[getValue(source, ['标段', '_文件类型'])];
- let obj = {
- projType: ProjectType.Project,
- name: getValue(source, ['标段', '_项目名称']),
- engs: loadEng(source),
- property: {
- compilationIllustration: getValue(source, ['标段', '编制说明', '_内容'])
- },
- basicInformation: loadBasicInfo(source),
- };
- //统计项目数量
- let count = 1 + obj.engs.length;
- obj.engs.forEach(eng => {
- count += eng.tenders.length;
- });
- obj.projectCount = count;
- return obj;
- }
- //基本信息相关
- function loadBasicInfo(source) {
- let info = [];
- info.push({key: 'projNum', value: getValue(source, ['标段', '_项目编号'])});
- info.push({key: 'constructionUnit', value: getValue(source, ['标段', '_建设单位'])});
- //项目信息
- let projInfoSrc = getValue(source, ['标段', '项目信息']);
- if (projInfoSrc) {
- info.push({key: 'projectScale', value: getValue(projInfoSrc, ['_工程规模'])});
- info.push({key: 'projLocation', value: getValue(projInfoSrc, ['_工程所在地'])});
- info.push({key: 'projAddress', value: getValue(projInfoSrc, ['_工程地址'])});
- info.push({key: 'buildingUnit', value: getValue(projInfoSrc, ['_施工单位'])});
- info.push({key: 'establishmentUnit', value: getValue(projInfoSrc, ['_编制单位'])});
- info.push({key: 'auditUnit', value: getValue(projInfoSrc, ['_审核单位'])});
- info.push({key: 'buildingUnitAuthor', value: getValue(projInfoSrc, ['_编制人'])});
- info.push({key: 'auditUnitAuditor', value: getValue(projInfoSrc, ['_审核人'])});
- info.push({key: 'commencementDate', value: getValue(projInfoSrc, ['_开工日期'])});
- info.push({key: 'completionDate', value: getValue(projInfoSrc, ['_竣工日期'])});
- info.push({key: 'establishDate', value: getValue(projInfoSrc, ['_编制日期'])});
- info.push({key: 'auditDate', value: getValue(projInfoSrc, ['_审核日期'])});
- info.push({key: 'materialPricePeriod', value: getValue(projInfoSrc, ['_材料价格期'])});
- info.push({key: 'contractPriceType', value: getValue(projInfoSrc, ['_合同价类型'])});
- //招标信息
- info.push({key: 'tenderingAgency', value: getValue(projInfoSrc, ['招标信息', '_招标代理机构'])});
- info.push({key: 'tenderCostEngineer', value: getValue(projInfoSrc, ['招标信息', '_造价工程师'])});
- info.push({key: 'tenderCostEngineerNo', value: getValue(projInfoSrc, ['招标信息', '_造价工程师注册证号'])});
- info.push({key: 'tenderPeriod', value: getValue(projInfoSrc, ['招标信息', '_招标工期'])});
- info.push({key: 'engineeringCost', value: getValue(projInfoSrc, ['招标信息', '_控制总价'])});
- let firstEng = arrayValue(source, ['标段', '单项工程'])[0];
- if (firstEng) {
- let firstTender = arrayValue(firstEng, ['单位工程'])[0];
- if (firstTender) {
- info.push({key: 'projectCategory', value: getValue(firstTender, ['工程特征', '_工程类别'])});
- }
- }
- }
- return info;
- }
- //单项工程
- function loadEng(source) {
- return arrayValue(source, ['标段', '单项工程']).map(src => {
- countData.projectCount++;
- return {
- projType: ProjectType.Engineering,
- name: getValue(src, ['_名称']),
- tenders: loadTender(src)
- };
- });
- }
- //单位工程
- function loadTender(engSrc) {
- return arrayValue(engSrc, ['单位工程']).map(src => {
- countData.projectCount++;
- countData.unitPriceFileCount++;
- return {
- projType: ProjectType.Tender,
- name: getValue(src, ['_名称']),
- engineering: getValue(src, ['_专业']),
- projectFeature: loadProjectFeature(src),
- feeSummary: loadFeeSummary(src), //单位工程费汇总
- fbfx: loadFBFX(src),
- csxm: loadCSXM(src),
- other: loadOther(src),
- chargeTax: loadChargeTax(src),
- gljSummary: loadGljSummary(src)
- };
- });
- }
- //工程特征相关,特征项没有固定的项,不清楚导入的项无法用已有key对应,而且工程特征名称不会有重复,因此用名称与我们软件的工程特征对应
- function loadProjectFeature(tenderSrc) {
- let feature = [];
- feature.push({name: '建筑分类', value: getValue(tenderSrc, ['工程特征', '_建筑分类'])});
- feature.push({name: '工程分类', value: getValue(tenderSrc, ['工程特征', '_工程分类'])});
- feature.push({name: '建设规模', value: getValue(tenderSrc, ['工程特征', '_建设规模'])});
- let items = arrayValue(tenderSrc, ['工程特征', '特征项']);
- feature.push(...items.map(item => {
- return {name: getValue(item, ['_名称']), value: getValue(item, ['_内容'])};
- }));
- return feature;
- }
- /*
- * 递归获取相关数据,eg:获取组织措施清单下的所有子清单,该子清单们可能由分类及公式措施项各种组合组成。(参考调用处)
- * @param {Object}src(数据源) {Array}fields(二维数组,数组里的成员由需要取的字段组成)
- * eg: ['组织措施分类'], ['公式计算措施项'],该层数据可能由组织措施分类 或 公式计算措施项组成 (同层不可同时存在)
- * {Function} 获得源数据后,需要提取的数据方法
- * @return {Array}
- * */
- function getItemsRecur(src, fields, extractFuc) {
- let itemsSrc = [],
- curField = [''];
- for (let field of fields) {
- itemsSrc = arrayValue(src, field);
- if (itemsSrc.length) {
- curField = field;
- break;
- }
- }
- return itemsSrc.map(itemSrc => {
- let obj = extractFuc(itemSrc, curField);
- obj.items = getItemsRecur(itemSrc, fields, extractFuc);
- return obj;
- });
- }
- //单位工程费汇总-计价程序费用行
- function loadFeeSummary(tenderSrc) {
- let feeItems = arrayValue(tenderSrc, ['单位工程费汇总', '计价程序费用行']);
- return feeItems.map(itemSrc => {
- let obj = {
- rowCode: getValue(itemSrc, ['_行代号']),
- name: getValue(itemSrc, ['_项目名称']),
- };
- if (importFileKind === FileKind.tender) {
- obj.calcBase = getValue(itemSrc, ['_计算基础表达式']);
- obj.feeRate = getValue(itemSrc, ['_费率']);
- obj.fees = [{fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0'}];
- }
- return obj;
- });
- }
- //分部分项,两种情况 分部分项-清单分部-清单项目、分部分项-清单项目
- //return {Array}
- function loadFBFX(tenderSrc) {
- let fbfxSrc = getValue(tenderSrc, ['分部分项清单']),
- fields = [['清单分部'], ['清单项目']];
- return getItemsRecur(fbfxSrc, fields, (itemSrc, curField) => {
- if (curField[0] === fields[0][0]) { //提取分部所需数据
- let obj = {
- type: BillsType.FB,
- code: getValue(itemSrc, ['_编号']),
- name: getValue(itemSrc, ['_名称']),
- remark: getValue(itemSrc, ['_备注']),
- };
- if (importFileKind === FileKind.tender) {
- obj.fees = [
- {fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0'},
- {fieldName: 'estimate', totalFee: getValue(itemSrc, ['_其中暂估价']) || '0'},
- ];
- }
- return obj;
- } else { //提取清单项目所需数据
- return extractBills(itemSrc, BillsType.FX);
- }
- });
- }
- //提取清单项目数据
- function extractBills(billsSrc, type) {
- let obj = {
- type: type, //清单类型
- code: getValue(billsSrc, ['_项目编码']),
- name: getValue(billsSrc, ['_项目名称']),
- unit: getValue(billsSrc, ['_单位']),
- isEstimate: getValue(billsSrc, ['_暂估清单标志']) === 'true' ? true : false,
- mainBills: getValue(billsSrc, ['_主要清单标志']) === 'true' ? true : false,
- quantity: getValue(billsSrc, ['_工程量']) || '0' ,
- remark: getValue(billsSrc, ['_备注']),
- itemCharacterText: itemCharacterText(billsSrc)
- };
- //投标和控制价,需要导入最高限价
- if ([FileKind.tender ,FileKind.control].includes(importFileKind)) {
- let maxPrice = getValue(billsSrc, ['_最高限价']);
- //不为0才输出
- if (maxPrice && maxPrice !== '0') {
- obj.outPutMaxPrice = true;
- obj.maxPrice = maxPrice;
- }
- }
- if (importFileKind === FileKind.tender) { //投标
- obj.fees = [
- {fieldName: 'common', unitFee: getValue(billsSrc, ['_综合单价']), totalFee: getValue(billsSrc, ['_综合合价'])},
- {fieldName: 'estimate', totalFee: getValue(billsSrc, ['_其中暂估价'])},
- ];
- //费用组成
- obj.fees.push(...extractFeeContent(getValue(billsSrc, ['费用组成'])));
- //组价内容
- obj.rations = extractRation(billsSrc);
- }
- return obj;
- //特征及内容文本(默认显示在项目特征列)
- function itemCharacterText(fxSrc) {
- let textArr = [];
- //项目特征
- let itemCharacter = getValue(fxSrc, ['项目特征']);
- if (itemCharacter) {
- textArr.push('[项目特征]');
- let features = arrayValue(itemCharacter, ['特征']);
- textArr.push(...features.map(feature => {
- let fName = getValue(feature, ['_特征名称']),
- fDesr = getValue(feature, ['_特征描述']);
- //若不存在特征描述,同时特征名称中含有“:”,则直接返回特征名称 (广联达招标文件中,特征名称包含了特征名:值)
- if (!fDesr && /[\:,:]/.test(fName)) {
- return fName;
- } else {
- return `${fName}: ${fDesr}`;
- }
- }));
- }
- //工作内容
- if (textArr.length) {
- textArr.push('[工作内容]');
- }
- let jobContent = getValue(fxSrc, ['工程内容']);
- if (jobContent) {
- let jobs = arrayValue(jobContent, ['内容']);
- textArr.push(...jobs.map(job => getValue(job, ['_内容'])));
- }
- return textArr.join('\n');
- }
- }
- //提取定额子目
- function extractRation(billsSrc) {
- let rationSrcs = arrayValue(billsSrc, ['组价内容', '定额子目']),
- serialNo = 1;
- return rationSrcs.map(rationSrc => {
- let rationData = {
- serialNo: serialNo++,
- code: getValue(rationSrc, ['_原始定额编号']).replace('换', ''),
- name: getValue(rationSrc, ['_项目名称']),
- caption: getValue(rationSrc, ['_项目名称']),
- unit: getValue(rationSrc, ['_单位']),
- libCode: getValue(rationSrc, ['_定额库编码']),
- quantity: getValue(rationSrc, ['_工程量']) || '0',
- adjustState: getValue(rationSrc, ['_子目类型']) == '2' ? '1' : '', //子目类型2为换算定额,标记一下我们软件才能显示
- isSubcontract: getValue(rationSrc, ['_分包标志']) === 'false' ? false : true,
- remark: getValue(rationSrc, ['_备注']),
- programID: parseInt(getValue(rationSrc, ['_单价构成文件ID'])),
- };
- //'6'认为量材,其他都认为是定额
- let type = getValue(rationSrc, ['_子目类型']);
- if (type == '6') {
- rationData.type = 2;
- rationData.subType = 201;
- } else {
- rationData.type = 1;
- }
- rationData.fees = [
- {fieldName: 'rationUnitPrice', unitFee: getValue(rationSrc, ['_定额单价']) || '0',
- totalFee: getValue(rationSrc, ['_定额合价']) || '0'},
- {fieldName: 'common', unitFee: getValue(rationSrc, ['_综合单价']) || '0',
- totalFee: getValue(rationSrc, ['_综合合价']) || '0'},
- ];
- rationData.fees.push(...extractFeeContent(getValue(rationSrc, ['费用组成'])));
- //定额人材机
- let rationGljSrc = arrayValue(rationSrc, ['工料分析', '人材机含量']);
- rationData.rationGljs = rationGljSrc.map(rjSrc => {
- return {
- code: getValue(rjSrc, ['_人材机代码']),
- quantity: getValue(rjSrc, ['_消耗量']) || '0',
- }
- });
- return rationData;
- });
- }
- //获取费用组成
- function extractFeeContent(src) {
- let rst = [];
- //减少数据量
- function addFee(feeData) {
- //有不为空的价格,才会插入
- let match = Object.entries(feeData).find(data => {
- let [k, v] = data;
- return k !== 'fieldName' && v && v !== '0' && v !== '0.00';
- });
- if (match) {
- rst.push(feeData);
- }
- }
- addFee({
- fieldName: 'labour',
- unitFee: getValue(src, ['_基价人工费单价']),
- totalFee: getValue(src, ['_基价人工费合价']),
- });
- addFee({
- fieldName: 'material',
- unitFee: getValue(src, ['_基价材料费单价']),
- totalFee: getValue(src, ['_基价材料费合价']),
- });
- addFee( {
- fieldName: 'machine',
- unitFee: getValue(src, ['_基价机械费单价']),
- totalFee: getValue(src, ['_基价机械费合价']),
- });
- addFee({
- fieldName: 'unratedMaterial',
- unitFee: getValue(src, ['_未计材料单价']),
- totalFee: getValue(src, ['_未计材料合价']),
- });
- addFee({
- fieldName: 'gljDiff',
- unitFee: getValue(src, ['_人材机价差单价']),
- totalFee: getValue(src, ['_人材机价差合价']),
- });
- addFee({
- fieldName: 'estimate',
- unitFee: getValue(src, ['_暂估材料单价']),
- totalFee: getValue(src, ['_暂估材料合价']),
- });
- addFee({
- fieldName: 'manage',
- unitFee: getValue(src, ['_管理费单价']),
- totalFee: getValue(src, ['_管理费合价']),
- });
- addFee({
- fieldName: 'profit',
- unitFee: getValue(src, ['_利润单价']),
- totalFee: getValue(src, ['_利润合价']),
- });
- addFee({
- fieldName: 'risk',
- unitFee: getValue(src, ['_一般风险单价']),
- totalFee: getValue(src, ['_一般风险合价']),
- });
- addFee({
- fieldName: 'otherRisk',
- unitFee: getValue(src, ['_其他风险单价']),
- totalFee: getValue(src, ['_其他风险合价']),
- });
- return rst;
- }
- //措施项目
- function loadCSXM(tenderSrc) {
- let target = {};
- let zzcsxmSrc = getValue(tenderSrc, ['措施项目清单', '组织措施清单']);
- target.zzcs = {items: loadZZCS(zzcsxmSrc)};
- let jscsxmSrc = getValue(tenderSrc, ['措施项目清单', '技术措施清单']);
- target.jscs = {items: loadJSCS(jscsxmSrc)};
- if (importFileKind === FileKind.tender) { //投标
- target.fees = [
- {fieldName: 'common', totalFee: getValue(tenderSrc, ['措施项目清单', '_金额']) || '0'},
- {fieldName: 'estimate', totalFee: getValue(tenderSrc, ['措施项目清单', '_其中暂估价']) || '0'},
- ];
- target.zzcs.fees = [{fieldName: 'common', totalFee: getValue(tenderSrc, ['措施项目清单', '组织措施清单', '_金额']) || '0'}];
- target.jscs.fees = [
- {fieldName: 'common', totalFee: getValue(tenderSrc, ['措施项目清单', '技术措施清单', '_金额']) || '0'},
- {fieldName: 'estimate', totalFee: getValue(tenderSrc, ['措施项目清单', '技术措施清单', '_其中暂估价']) || '0'},
- ];
- }
- return target;
- //组织措施清单
- function loadZZCS(zzcsSrc) {
- let fields = [['组织措施分类'], ['公式计算措施项']];
- return getItemsRecur(zzcsSrc, fields, (itemSrc, curField) => {
- let rstObj;
- if (curField[0] === fields[0][0]) { //组织措施分类
- rstObj = {
- type: BillsType.BILLS,
- code: getValue(itemSrc, ['_编码']),
- name: getValue(itemSrc, ['_名称']),
- remark: getValue(itemSrc, ['_备注'])
- }
- } else {
- rstObj = { //公式计算措施项
- type: BillsType.BILLS,
- code:getValue(itemSrc, ['_序号']),
- name: getValue(itemSrc, ['_名称']),
- calcBase: getValue(itemSrc, ['_计算基础表达式']),
- feeRate: getValue(itemSrc, ['_费率']),
- isEstimate: getValue(itemSrc, ['_暂估价标志']) === 'true' ? true : false,
- remark: getValue(itemSrc, ['_备注'])
- };
- }
- if (importFileKind === FileKind.tender) {
- rstObj.fees = [{fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0'}];
- }
- return rstObj;
- });
- }
- //技术措施清单
- function loadJSCS(jscsSrc) {
- let fields = [['技术措施分类'], ['清单项目']];
- return getItemsRecur(jscsSrc, fields, (itemSrc, curField) => {
- if (curField[0] === fields[0][0]) { //技术措施分类
- let obj = {
- type: BillsType.BILLS,
- code: getValue(itemSrc, ['_编号']),
- name: getValue(itemSrc, ['_名称'])
- };
- if (importFileKind === FileKind.tender) {
- obj.fees = [
- {fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0'},
- {fieldName: 'estimate', totalFee: getValue(itemSrc, ['_其中暂估价']) || '0'},
- ];
- }
- return obj;
- } else { //清单项目
- return extractBills(itemSrc, BillsType.BILLS);
- }
- });
- }
- }
- //其他项目
- function loadOther(tenderSrc) {
- let otherSrc = getValue(tenderSrc, ['其他项目清单']);
- //暂列金额
- let provisional = {items: arrayValue(otherSrc, ['暂列金额', '暂列金额明细']).map(src => {
- let obj = {
- type: BillsType.BILLS,
- code: getValue(src, ['_编号']),
- name: getValue(src, ['_项目名称']),
- unit: getValue(src, ['_计量单位']),
- remark: getValue(src, ['_备注'])
- };
- if (importFileKind === FileKind.tender) {
- obj.fees = [{fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0'},];
- }
- return obj;
- })};
- //专业工程暂估价
- let engineeringPro = {items: arrayValue(otherSrc, ['专业工程暂估价', '专业工程暂估明细']).map(src => {
- let obj = {
- type: BillsType.BILLS,
- code: getValue(src, ['_编号']),
- name: getValue(src, ['_工程名称']),
- engineeringContent: getValue(src, ['_工程内容']),
- remark: getValue(src, ['_备注'])
- };
- if (importFileKind === FileKind.tender) {
- obj.fees = [{fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0'},];
- }
- return obj;
- })};
- //计日工
- function extractDayWorkItem(src) {
- let obj = {
- type: BillsType.BILLS,
- code: getValue(src, ['_编号']),
- name: getValue(src, ['_名称']),
- unit: getValue(src, ['_单位']),
- quantity: getValue(src, ['_数量']),
- remark: getValue(src, ['_备注'])
- };
- if (importFileKind === FileKind.tender) {
- obj.fees = [
- {fieldName: 'common', unitFee: getValue(src, ['_综合单价']) || '0', totalFee: getValue(src, ['_综合合价']) || '0'}
- ];
- }
- return obj;
- }
- let labour = arrayValue(otherSrc, ['计日工', '人工', '计日工项目']).map(extractDayWorkItem),
- material = arrayValue(otherSrc, ['计日工', '材料', '计日工项目']).map(extractDayWorkItem),
- machine = arrayValue(otherSrc, ['计日工', '施工机械', '计日工项目']).map(extractDayWorkItem);
- let dayWork = {labour, material, machine};
- //总承包服务费
- let fields = [['总承包服务费分类'], ['总承包服务费费用项']],
- serviceSrc = getValue(otherSrc, ['总承包服务费']);
- let service = {items: getItemsRecur(serviceSrc, fields, (src, curField) => {
- if (curField[0] === fields[0][0]) {
- return { //总承包服务费分类
- type: BillsType.BILLS,
- code: getValue(src, ['_编号']),
- name: getValue(src, ['_名称']),
- remark: getValue(src, ['_备注'])
- }
- } else {
- let obj = { //总承包服务费费用项
- type: BillsType.BILLS,
- code:getValue(src, ['_编号']),
- name: getValue(src, ['_工程名称']),
- calcBase: getValue(src, ['_计算基础']),
- serviceContent: getValue(src, ['_服务内容']),
- feeRate: getValue(src, ['_费率']),
- remark: getValue(src, ['_备注'])
- };
- if (importFileKind === FileKind.tender) {
- obj.fees = [
- {fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0'}
- ];
- }
- return obj;
- }
- })};
- //索赔、签证
- function extractClaimVisa(src) {
- let obj = {
- type: BillsType.BILLS,
- code: getValue(src, ['_编号']),
- name: getValue(src, ['_项目名称']),
- unit: getValue(src, ['_计量单位']),
- quantity: getValue(src, ['_数量']),
- claimVisa: getValue(src, ['_依据'])
- };
- if (importFileKind === FileKind.tender) {
- obj.fees = [
- {fieldName: 'common', unitFee: getValue(src, ['_单价']) || '0', totalFee: getValue(src, ['_合价']) || '0'}
- ];
- }
- return obj;
- }
- let claim = {items: arrayValue(otherSrc, ['索赔计价汇总', '签证索赔计价汇总费用项']).map(extractClaimVisa)},
- visa = {items: arrayValue(otherSrc, ['现场签证计价汇总', '签证索赔计价汇总费用项']).map(extractClaimVisa)};
- //其他
- let others = {items: arrayValue(otherSrc, ['其他', '其他列项']).map(src => {
- let obj = {
- type: BillsType.BILLS,
- code: getValue(src, ['_序号']),
- name: getValue(src, ['_名称']),
- calcBase: getValue(src, ['_计算基础']),
- feeRate: getValue(src, ['_费率']),
- remark: getValue(src, ['_备注'])
- };
- if (importFileKind === FileKind.tender) {
- obj.fees = [{fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0'}];
- }
- return obj;
- })};
- if (importFileKind === FileKind.tender) {
- provisional.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['暂列金额', '_金额']) || '0'}];
- engineeringPro.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['专业工程暂估价', '_金额']) || '0'}];
- dayWork.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['计日工', '_金额']) || '0'}];
- service.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['总承包服务费', '_金额']) || '0'}];
- claim.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['索赔计价汇总', '_金额']) || '0'}];
- visa.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['现场签证计价汇总', '_金额']) || '0'}];
- others.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['其他', '_金额']) || '0'}];
- }
- return {provisional, engineeringPro, dayWork, service, claim, visa, others};
- }
- //规费和税金清单
- function loadChargeTax(tenderSrc) {
- return arrayValue(tenderSrc, ['规费和税金清单', '费用项']).map(src => {
- let obj = {
- type: BillsType.BILLS,
- rowCode: getValue(src, ['_行代号']),
- code: getValue(src, ['_序号']),
- name: getValue(src, ['_名称']),
- calcBase: getValue(src, ['_计算基础表达式']),
- feeRate: getValue(src, ['_费率']),
- remark: getValue(src, ['_备注'])
- };
- if (importFileKind === FileKind.tender) {
- obj.fees = [{fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0'}];
- }
- return obj;
- });
- }
- //根据费用类别、配比类比获取人材机类别(后端匹配不到标准人材机的时候用)
- function getGljTypeData(feeType, ratioType) {
- let map = {
- '-': {type: 201, shortName: '材'},
- '1-': {type: 1, shortName: '人'},
- '2-': {type: 201, shortName: '材'},
- '2-1': {type: 202, shortName: '砼'},
- '2-2': {type: 205, shortName: '商砼'},
- '2-3': {type: 203, shortName: '浆'},
- '2-4': {type: 206, shortName: '商浆'},
- '2-5': {type: 204, shortName: '配比'},
- '3-': {type: 301, shortName: '机'},
- '4-': {type: 4, shortName: '主'},
- };
- return map[`${feeType}-${ratioType}`] || '';
- }
- //主要材料类别-三材类别映射
- const MaterialMap = {
- '100': 1, //钢材钢筋认为钢材,因为文件没细分
- '200': 4, //水泥
- '300': 3, //木材
- '400': 5 //商品砼
- };
- //人材机汇总
- function loadGljSummary(tenderSrc) {
- let gljsSrc = arrayValue(tenderSrc, ['人材机汇总', '人材机']);
- return gljsSrc.map(gljSrc => {
- countData.projectGLJCount++;
- //编码都取原始编码,如果原始编码为空,都取编码
- let orgCode = getValue(gljSrc, ['_原始代码']),
- code = getValue(gljSrc, ['_代码']);
- if (!orgCode) {
- orgCode = code;
- }
- let gljData = {
- customCode: code, //处理自定义的代码 (有的公司定额人材机代码、人材机代码是用自动生成的代码)
- code: orgCode,
- original_code: orgCode,
- name: getValue(gljSrc, ['_名称']),
- specs: getValue(gljSrc, ['_规格']),
- unit: getValue(gljSrc, ['_单位']),
- supply: getValue(gljSrc, ['_供应方式']) == '2' ? 2 : 0, //不是完全甲供就取自行采购
- is_evaluate: getValue(gljSrc, ['_暂估材料标志']) === 'true' ? true : false,
- no_tax_eqp: getValue(gljSrc, ['_不计税设备标志']) === 'true' ? true : false,
- base_price: getValue(gljSrc, ['_定额价']),
- market_price: getValue(gljSrc, ['_市场价']),
- originPlace: getValue(gljSrc, ['_产地']),
- vender: getValue(gljSrc, ['_厂家']),
- qualityGrace: getValue(gljSrc, ['_质量等级']),
- brand: getValue(gljSrc, ['_品牌']),
- remark: getValue(gljSrc, ['_备注'])
- };
- if (MaterialMap[getValue(gljSrc, ['_主要材料类别'])]) {
- gljData.materialType = MaterialMap[getValue(gljSrc, ['_主要材料类别'])];
- gljData.materialCoe = getValue(gljSrc, ['_主要材料单位系数']);
- }
- let typeData = getGljTypeData(getValue(gljSrc, ['_费用类别']), getValue(gljSrc, ['_配比类别']));
- if (typeData) {
- gljData.type = typeData.type;
- gljData.shortName = typeData.shortName;
- }
- //人材机配比
- let ratioSrc = arrayValue(gljSrc, ['人材机配比']);
- gljData.ratios = ratioSrc.map(rSrc => {
- countData.ratioCount++;
- return {
- code: getValue(rSrc, ['_明细材料代码']),
- consumption: getValue(rSrc, ['_数量'])
- }
- });
- return gljData;
- });
- }
- //-------------------------提取数据后的数据处理
- function getFlag(data) {
- return data.flags && data.flags[0] && data.flags[0].flag || 0;
- }
- let toMatches = [
- {reg: /分部分项/, flag: fixedFlag.SUB_ENGINERRING},
- {reg: /^措施项目/, flag: fixedFlag.MEASURE},
- {reg: /技术措施/, flag: fixedFlag.CONSTRUCTION_TECH},
- {reg: /组织措施/, flag: fixedFlag.CONSTRUCTION_ORGANIZATION},
- {reg: /组织措施/, flag: fixedFlag.CONSTRUCTION_ORGANIZATION},
- {reg: /安全文明/, flag: fixedFlag.SAFETY_CONSTRUCTION},
- {reg: /其他项目/, flag: fixedFlag.OTHER},
- {reg: /暂列金额/, flag: fixedFlag.PROVISIONAL},
- {reg: /暂估价/, flag: fixedFlag.ESTIMATE},
- {reg: /计日工/, flag: fixedFlag.DAYWORK},
- {reg: /总承包服务/, flag: fixedFlag.TURN_KEY_CONTRACT},
- {reg: /索赔(?:及|与|和)现场签证/, flag: fixedFlag.TURN_KEY_CONTRACT},
- {reg: /规费/, flag: fixedFlag.CHARGE},
- {reg: /税金/, flag: fixedFlag.TAX},
- {reg: /增值税/, flag: fixedFlag.ADDED_VALUE_TAX},
- {reg: /^附加税/, flag: fixedFlag.ADDITIONAL_TAX},
- {reg: /环境保护税/, flag: fixedFlag.ENVIRONMENTAL_PROTECTION_TAX},
- {reg: /(?:合\s*价)|(?:工程造价)/, flag: fixedFlag.ENGINEERINGCOST},
- ];
- //处理单位工程费用汇总的清单,这一部分没有靠谱的规则,特殊处理并添加相关清单
- function setupFeeSummary(feeSummary, needfulTemplate) {
- let preDXFY = null, //记录上一条添加的大项费用
- preSubTax = null; //记录上一条添加的附加税子项(特殊处理城市xx、教育xx附加...名称的清单)
- let addtionalTax = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.ADDITIONAL_TAX), //附加税
- engineeringCost = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.ENGINEERINGCOST); //工程造价
- for (let feeBills of feeSummary) {
- //匹配固定的附加税子项
- if (addtionalTax &&
- (/城市维护建设/.test(feeBills.name) ||
- /教育费附加/.test(feeBills.name) ||
- /地方教育附加/.test(feeBills.name))
- ) {
- let subTaxData ={
- ID: uuid.v1(),
- ParentID: addtionalTax.ID,
- NextSiblingID: -1,
- name: feeBills.name,
- feeRate: feeBills.feeRate,
- };
- if (importFileKind === FileKind.tender) {
- subTaxData.rowCode = feeBills.rowCode;
- subTaxData.fees = feeBills.fees;
- }
- if (preSubTax) {
- preSubTax.NextSiblingID = subTaxData.ID;
- }
- needfulTemplate.push(subTaxData);
- preSubTax = subTaxData;
- } else { //匹配固定项
- let isMatched = false;
- //匹配固定项
- for (let match of toMatches) {
- if (!match.reg.test(feeBills.name)) {
- continue;
- }
- let findBills = needfulTemplate.find(nData => getFlag(nData) === match.flag);
- if (!findBills) {
- //如果模板中没有安全文明施工费,计价汇总行中安全文明施工费,将其设置为组织清单子项
- if (/安全文明施工/.test(feeBills.name)) {
- let fixedCSXM = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.CONSTRUCTION_ORGANIZATION);
- if (fixedCSXM) {
- needfulTemplate.push({
- ID: uuid.v1(),
- ParentID: fixedCSXM.ID,
- NextSiblingID: -1,
- name: feeBills.name,
- calcBase: feeBills.calcBase,
- feeRate: feeBills.feeRate,
- });
- isMatched = true;
- break; //不添加到大项费用
- }
- }
- continue;
- }
- isMatched = true;
- findBills.calcBase = feeBills.calcBase;
- findBills.feeRate = feeBills.feeRate;
- //后台配置的feeRateID优先级比feeRate高,导入数据有费率值时,需要清空这个配置
- if (findBills.feeRate && parseFloat(findBills.feeRate) !== 0) {
- findBills.feeRateID = null;
- }
- if (importFileKind === FileKind.tender) {
- findBills.rowCode = feeBills.rowCode;
- findBills.fees = feeBills.fees;
- }
- break;
- }
- //匹配不到固定项,认为是大项费用
- if (!isMatched) {
- let dxfyData = {
- ID: uuid.v1(),
- ParentID: -1,
- NextSiblingID: -1,
- name: feeBills.name,
- calcBase: feeBills.calcBase,
- feeRate: feeBills.feeRate,
- };
- if (importFileKind === FileKind.tender) {
- dxfyData.rowCode = feeBills.rowCode;
- dxfyData.fees = feeBills.fees;
- }
- if (!preDXFY) {
- preDXFY = engineeringCost;
- }
- preDXFY.NextSiblingID = dxfyData.ID;
- needfulTemplate.push(dxfyData);
- preDXFY = dxfyData;
- }
- }
- }
- }
- //处理、添加清单
- function setupBills(tenderData, billsTarget) {
- //规费和税金 这个地方不靠谱,先特殊处理(无法兼容所有情况)
- //1.如果在清单中出现(匹配名称相关关键字),则更新数据
- //2.否则新增(在税金出现前,全作为规费的子清单,否则作为税金子清单)
- let charge = null,
- tax = null,
- additionalTax = null;
- for (let i = 0; i < tenderData.chargeTax.length; i++) {
- let curBills = tenderData.chargeTax[i];
- let matchBills = billsTarget.find(d => (d.rowCode && d.rowCode === curBills.rowCode) || d.name === curBills.name);
- //匹配到,更新
- if (matchBills) {
- if (getFlag(matchBills) === fixedFlag.CHARGE) {
- charge = matchBills;
- } else if (getFlag(matchBills) === fixedFlag.TAX) {
- tax = matchBills;
- } else if (getFlag(matchBills) === fixedFlag.ADDITIONAL_TAX) {
- additionalTax = matchBills;
- }
- matchBills.calcBase = curBills.calcBase;
- matchBills.feeRate = curBills.feeRate;
- matchBills.fees = curBills.fees || [];
- } else { //新增
- if (!charge && !tax) {
- continue;
- }
- //存在规费,还未找到税金,后面数据作为规费的子项 已找到税金,后面数据作为税金子项
- let curParent = !tax ? charge : tax;
- //特殊处理"城市维护建设税" "教育费附加" "地方教育附加",这三项固定设为税金下附加税的子项
- if (additionalTax &&
- (/城市维护建设/.test(curBills.name) ||
- /教育费附加/.test(curBills.name) ||
- /地方教育附加/.test(curBills.name))) {
- curParent = additionalTax;
- }
- curBills.ID = uuid.v1();
- curBills.NextSiblingID = -1;
- curBills.ParentID = curParent.ID;
- let pre = billsTarget.find(d => d.ParentID === curParent.ID && d.NextSiblingID === -1);
- if (pre) {
- pre.NextSiblingID = curBills.ID;
- }
- billsTarget.push(curBills);
- if (!additionalTax && /^附加税/.test(curBills.name)) {
- additionalTax = curBills;
- }
- }
- }
- //分部分项
- addFixedBlock(fixedFlag.SUB_ENGINERRING, tenderData.fbfx);
- //措施项目
- addFixedBlock(fixedFlag.MEASURE, null, tenderData.csxm.fees);
- //组织措施 //特殊处理子项
- //需要添加的组织措施子项
- function updateZZCSItem(org, tar) {
- for(let [k, v] of Object.entries(tar)) {
- org[k] = v;
- }
- }
- let zzcsSubs = [];
- let fixedOrganization = billsTarget.find(data => /组织措施费/.test(data.name)),
- fixedSafe = billsTarget.find(data => /安全文明/.test(data.name)),
- fixedProjectComplete = billsTarget.find(data => /建设工程竣工档案编制/.test(data.name)),
- fixedHouseQuality = billsTarget.find(data => /住宅工程质量分户验收/.test(data.name)),
- fixedZZCS = billsTarget.find(data => getFlag(data) === fixedFlag.CONSTRUCTION_ORGANIZATION),
- lastItem = billsTarget.find(data => data.ParentID === fixedZZCS.ID && data.NextSiblingID === -1);
- for (let item of tenderData.csxm.zzcs.items) {
- if (/组织措施费/.test(item.name) && fixedOrganization) {
- updateZZCSItem(fixedOrganization, item);
- } else if (/安全文明/.test(item.name) && fixedSafe) {
- updateZZCSItem(fixedSafe, item);
- } else if (/建设工程竣工档案/.test(item.name) && fixedProjectComplete) {
- updateZZCSItem(fixedProjectComplete, item);
- } else if (/住宅工程质量分户验收/.test(item.name) && fixedHouseQuality) {
- updateZZCSItem(fixedHouseQuality, item);
- } else {
- zzcsSubs.push(item);
- }
- }
- if (zzcsSubs.length && lastItem) {
- zzcsSubs[0].NextSiblingID = lastItem.ID;
- }
- addFixedBlock(fixedFlag.CONSTRUCTION_ORGANIZATION, zzcsSubs, tenderData.csxm.zzcs.fees);
- //技术措施
- addFixedBlock(fixedFlag.CONSTRUCTION_TECH, tenderData.csxm.jscs.items, tenderData.csxm.jscs.fees);
- //暂列金额
- addFixedBlock(fixedFlag.PROVISIONAL, tenderData.other.provisional.items, tenderData.other.provisional.fees);
- //专业工程暂估价
- addFixedBlock(fixedFlag.ENGINEERING_ESITIMATE, tenderData.other.engineeringPro.items, tenderData.other.engineeringPro.fees);
- //计日工
- addFixedBlock(fixedFlag.DAYWORK, null, tenderData.other.dayWork.fees);
- //人工
- addFixedBlock(fixedFlag.LABOUR, tenderData.other.dayWork.labour);
- //材料
- addFixedBlock(fixedFlag.MATERIAL,tenderData.other.dayWork.material);
- //机械
- addFixedBlock(fixedFlag.MACHINE, tenderData.other.dayWork.machine);
- //总承包服务费
- addFixedBlock(fixedFlag.TURN_KEY_CONTRACT, tenderData.other.service.items, tenderData.other.service.fees);
- //索赔
- addFixedBlock(fixedFlag.CLAIM, tenderData.other.claim.items, tenderData.other.claim.fees);
- //签证
- addFixedBlock(fixedFlag.VISA, tenderData.other.visa.items, tenderData.other.visa.fees);
- //其他
- if (tenderData.other.others.items.length) {
- //特殊处理材料(工程设备暂估价)
- let materialProIdx = tenderData.other.others.items.findIndex(item => item.name === '材料(工程设备)暂估价');
- if (~materialProIdx) {
- let materialPro = tenderData.other.others.items.splice(materialProIdx, 1)[0];
- let fixedMaterialPro = billsTarget.find(data => getFlag(data) === fixedFlag.MATERIAL_PROVISIONAL);
- if (fixedMaterialPro) {
- fixedMaterialPro.fees = materialPro.fees;
- fixedMaterialPro.feeRate = materialPro.feeRate;
- fixedMaterialPro.calcBase = materialPro.calcBase;
- }
- }
- if (tenderData.other.others.items.length) {
- let othersParent = {
- ID: uuid.v1(),
- NextSiblingID: -1,
- name: '其他',
- fees: tenderData.other.others.fees || []
- };
- addFixedBlock(fixedFlag.OTHER, [othersParent]);
- addFixedBlock(othersParent, tenderData.other.others.items);
- }
- }
- //删掉有feeRate的feeRateID
- billsTarget.forEach(data => {
- if (data.feeRate) {
- data.feeRateID = null;
- }
- });
- function addFixedBlock(flag, items, fees = null) {
- let fixedBills = flag;
- if (typeof flag === 'number') {
- fixedBills = billsTarget.find(d => getFlag(d) === flag);
- }
- if (fixedBills) {
- if (fees) {
- fixedBills.fees = fees || [];
- }
- if (Array.isArray(items) && items.length) {
- addBills(fixedBills.ID, items);
- }
- }
- }
- //设置清单的ID数据并添加清单到目标数组
- function addBills(parentID, items) {
- for (let i = 0; i < items.length; i++) {
- let curBills = items[i],
- preBills = items[i - 1];
- curBills.ID = uuid.v1();
- curBills.ParentID = parentID;
- curBills.NextSiblingID = -1;
- if (preBills) {
- preBills.NextSiblingID = curBills.ID;
- }
- billsTarget.push(curBills);
- if (curBills.items && curBills.items.length) {
- addBills(curBills.ID, curBills.items);
- }
- }
- }
- }
- //计算基数字典
- const CalcBaseMap = {
- FBFXHJ: '{分部分项工程费}',
- RGF: '{分部分项定额人工费}',
- CLF: '{分部分项定额材料费}',
- JXF: '{分部分项定额施工机具使用费}',
- ZCF: '{分部分项主材费}',
- GR: '{分部分项人工工日}',
- CSXMHJ: '{措施项目费}',
- ZZCSF: '{组织措施项目费}',
- JSCSF: '{技术措施项目费}',
- JSCS_RGF: '{技术措施项目定额人工费}',
- JSCS_CLF: '{技术措施项目定额材料费}',
- JSCS_JXF: '{技术措施项目定额施工机具使用费}',
- JSCS_ZCF: '{技术措施项目主材费}',
- JSCS_GR: '{技术措施项目人工工日}',
- JZMZ: '{建筑面积}',
- RCJJC: '{人材机价差}',
- RGJC: '{人工价差}',
- CLJC: '{材料价差}',
- JXJC: '{机械价差}',
- JRGLF: '{甲供人工费}',
- JGCLF: '{甲供材料费}',
- JGJXF: '{甲供施工机具使用费}',
- JGZCF: '{甲供主材费}',
- FBF: '{分包费}',
- FBRGF: '{分包定额人工费}',
- FBCLF: '{分包定额材料费}',
- FBJXF: '{分包定额机械费}',
- FBZCF: '{分包主材费}',
- FBSBF: '{分包设备费}',
- FBGR: '{分包人工工日}',
- QTXMHJ: '{其他项目费}',
- GF: '{规费}',
- SJ: '{税金}',
- SJHJ: '{税金}',
- };
- //转换计算基数
- //1.有子项数据,则清空基数
- //2.行代号引用转换为ID引用
- //3.对应字典代号转换,对应字典里找不到则设置成金额
- function transformCalcBase(billsData) {
- //行代号 - ID映射
- let rowCodeMap = {};
- billsData.forEach(data => {
- if (data.rowCode) {
- rowCodeMap[data.rowCode] = data.ID;
- }
- });
- for (let bills of billsData) {
- if (!bills.calcBase) {
- continue;
- }
- let sub = billsData.find(data => data.ParentID === bills.ID);
- //有子项数据,则清空基数,费率
- if (sub) {
- bills.calcBase = '';
- bills.feeRate = '';
- continue;
- }
- //提取基数
- bills.calcBase = bills.calcBase.replace(/\s/g, '');
- let bases = bills.calcBase.split(/[\+\-\*\/]/g);
- //提取操作符
- let oprs = bills.calcBase.match(/[\+\-\*\/]/g);
- //转换后的基数
- let newBase = [];
- let illegal = false; //不合法
- for (let base of bases) {
- if (rowCodeMap[base]) { //行引用
- newBase.push(`@${rowCodeMap[base]}`);
- } else if (CalcBaseMap[base]) { //基数字典
- /*illegal = true;
- break;*/
- newBase.push(CalcBaseMap[base]);
- } else { //都没匹配到,说明软件无法识别此基数
- illegal = true;
- break;
- }
- };
- if (illegal) {
- let fee = getFee(bills.fees, ['common', 'totalFee']);
- let feeRate = bills.feeRate && parseFloat(bills.feeRate) !== 0 ? parseFloat(bills.feeRate) : 0;
- if (fee && parseFloat(fee) !== 0 && feeRate) {
- bills.calcBase = scMathUtil.roundForObj(parseFloat(fee) * 100 / feeRate, 2);
- } else {
- bills.calcBase = fee !== '0' ? fee : '';
- }
- } else {
- let newCalcBase = '';
- for (let i = 0; i < newBase.length; i++) {
- newCalcBase += newBase[i];
- if (oprs && oprs[i]) {
- newCalcBase += oprs[i];
- }
- }
- bills.calcBase = newCalcBase;
- }
- }
- }
- //从xml文件中提取数据
- this.extractData = async (file) => {
- //将二进制文件转换成字符串
- let xmlStr = await readAsTextSync(file);
- //将xml格式良好的字符串转换成对象
- let x2js = new X2JS();
- let xmlObj = x2js.xml_str2json(xmlStr);
- if (!xmlObj) {
- throw '无有效数据。';
- }
- //console.log(xmlObj);
- //提取数据
- return loadProject(xmlObj);
- };
- //把数据转换成适应项目的数据
- this.transformData = async (xmlObj) => {
- //获取占位ID数据
- countData.unitPriceCount = countData.projectGLJCount;
- if (importFileKind !== FileKind.tender) {
- countData = {
- projectCount: countData.projectCount,
- unitPriceFileCount: countData.unitPriceFileCount
- };
- }
- let IDPlaceholder = await ajaxPost('/pm/import/getProjectPlaceholder', countData);
- xmlObj.ID = IDPlaceholder.project++;
- //获取到的转换后的最终上传数据
- let postConstructData = {
- ID: xmlObj.ID,
- ParentID: xmlObj.ParentID,
- NextSiblingID: xmlObj.NextSiblingID,
- preID: xmlObj.preID,
- name: xmlObj.name,
- basicInformation: xmlObj.basicInformation,
- projType: xmlObj.projType,
- property: xmlObj.property,
- shareInfo: [],
- engs: []
- };
- for (let i = 0; i < xmlObj.engs.length; i++) {
- let curEng = xmlObj.engs[i],
- preEng = xmlObj.engs[i - 1];
- curEng.ID = IDPlaceholder.project++;
- curEng.ParentID = xmlObj.ID;
- curEng.NextSiblingID = -1;
- if (preEng) {
- preEng.NextSiblingID = curEng.ID;
- }
- let postEngData = {
- ID: curEng.ID,
- ParentID: curEng.ParentID,
- NextSiblingID: curEng.NextSiblingID,
- name: curEng.name,
- projType: curEng.projType,
- shareInfo: [],
- tenders: []
- };
- postConstructData.engs.push(postEngData);
- for (let j = 0; j < curEng.tenders.length; j++) {
- let curTender = curEng.tenders[j],
- preTender = postEngData.tenders[j - 1];
- curTender.ID = IDPlaceholder.project++;
- curTender.ParentID = curEng.ID;
- curTender.NextSiblingID = -1;
- curTender.property.unitPriceFile.id = IDPlaceholder.unitPriceFile++;
- if (preTender) {
- preTender.tender.NextSiblingID = curTender.ID;
- }
- //提取详细数据
- let postTenderData = await transformTender(curTender, IDPlaceholder);
- postTenderData.tender.property.rootProjectID = postConstructData.ID;
- postEngData.tenders.push(postTenderData);
- }
- }
- console.log(postConstructData);
- return postConstructData;
- };
- //转换单位工程的数据(直接可插入数据库的数据),返回{tender: {}, bills: [], ration: [], rationGLJ: [], projectGLJ: [], unitPrice: [], mixRatio: []}
- async function transformTender(tenderData, IDPlaceholder) {
- let detailData = await transformBills(tenderData, IDPlaceholder);
- //提取需要插入的单位工程数据
- let tender = {
- ID: tenderData.ID,
- ParentID: tenderData.ParentID,
- NextSiblingID: tenderData.NextSiblingID,
- name: tenderData.name,
- projType: tenderData.projType,
- property: tenderData.property,
- projectFeature: tenderData.projectFeature,
- engineering: tenderData.engineering,
- defaultRationLib: tenderData.defaultRationLib,
- rationLibIDs: tenderData.rationLibIDs,
- gljLibIDs: tenderData.gljLibIDs,
- shareInfo: []
- };
- detailData.tender = tender;
- return detailData;
- }
- //转换清单数据
- async function transformBills(tenderData, IDPlaceholder) {
- //获取清单模板数据
- let needfulTemplate = await ajaxPost('/template/bills/api/getNeedfulTemplate',
- {templateLibID: tenderData.property.templateLibID});
- //处理单位工程费用汇总的清单,这一部分没有靠谱的规则,特殊处理。
- setupFeeSummary(tenderData.feeSummary, needfulTemplate);
- //处理添加清单数据
- setupBills(tenderData, needfulTemplate);
- //转换清单基数表达式
- transformCalcBase(needfulTemplate);
- //转换提取需要插入的详细数据
- let detailData = transformDetail(tenderData, needfulTemplate, IDPlaceholder);
- //console.log(detailData);
- return detailData;
- }
- //提取转换后的定额、定额人材机、人材机汇总、单价文件、组成物数据
- function transformDetail(tenderData, billsData, IDPlaceholder) {
- let rst = {
- bills: [], //清单
- ration: [], //定额
- rationGLJ: [], //定额人材机
- rationCoe: [], //定额系数,全为默认
- projectGLJ: [], //项目人材机
- unitPrice: [], //单价文件
- mixRatio: [] //组成物
- };
- //工料机汇总code-数据映射
- //let gljCodeMap = {};
- //项目人材机customCode-原始代码数据映射
- let projectGLJMap = {};
- //投标文件才需要导入定额等数据
- if (importFileKind === FileKind.tender) {
- tenderData.gljSummary.forEach(pGLJ => {
- pGLJ.project_id = tenderData.ID;
- pGLJ.id = IDPlaceholder.projectGLJ++;
- //gljCodeMap[pGLJ.code] = pGLJ;
- projectGLJMap[pGLJ.customCode] = pGLJ;
- });
- //处理项目人材机数据
- tenderData.gljSummary.forEach(pGLJ => {
- //组成物数据
- pGLJ.ratios.forEach(ratio => {
- let matchData = projectGLJMap[ratio.code];
- ratio.code = matchData.original_code;
- ratio.projectGLJID = pGLJ.id; //后端查找标准数据后,方便更新组成物数据
- ratio.id = IDPlaceholder.ratio++;
- ratio.unit_price_file_id = tenderData.property.unitPriceFile.id;
- ratio.unit = matchData ? matchData.unit : '';
- ratio.name = matchData ? matchData.name : '';
- ratio.specs = matchData ? matchData.specs : '';
- ratio.type = matchData ? matchData.type : 1;
- ratio.connect_key = [pGLJ.original_code || 'null', pGLJ.name || 'null', pGLJ.specs || 'null', pGLJ.unit || 'null', pGLJ.type].join('|-|');
- rst.mixRatio.push(ratio);
- });
- delete pGLJ.ratios;
- rst.projectGLJ.push(pGLJ);
- //单价文件数据
- rst.unitPrice.push(getUnitPrice(pGLJ));
- });
- //处理定额数据
- //获取含有定额数据的清单
- handleRation(billsData);
- }
- //处理清单 设置必要数据 设置无用属性
- billsData.forEach(bills => {
- //处理综合单价
- //1.没有子清单,且没有综合单价,则综合单价=综合合价/工程量
- let children = billsData.find(data => data.ParentID === bills.ID),
- unitFee = getFee(bills.fees, ['common', 'unitFee']),
- totalFee = getFee(bills.fees, ['common', 'totalFee']);
- if (!children && !parseFloat(unitFee) && totalFee && parseFloat(totalFee)) {
- //不存工程量
- if (!bills.quantity || !parseFloat(bills.quantity)) {
- unitFee = totalFee;
- //源不存在工程量,没有计算基数、但是却有综合合价,工程量要设置为1
- if (!bills.calcBase) {
- bills.quantity = '1';
- }
- } else {
- //综合合价的小数位数
- let totalFeeDecimal = totalFee.match(/\.\d+/);
- unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, totalFeeDecimal
- ? totalFeeDecimal[0] : 0);
- }
- let commonFee = bills.fees.find(fee => fee.fieldName === 'common');
- if (commonFee) {
- commonFee.unitFee = unitFee;
- }
- }
- bills.projectID = tenderData.ID;
- bills.quantityEXP = bills.quantity;
- delete bills.items;
- delete bills.rations;
- rst.bills.push(bills);
- });
- return rst;
- function handleRation(billsData) {
- let billsHasRations = billsData.filter(bills => Array.isArray(bills.rations) && bills.rations.length);
- billsHasRations.forEach(bills => {
- //处理定额
- bills.rations.forEach(ration => {
- ration.ID = uuid.v1();
- ration.projectID = tenderData.ID;
- ration.billsItemID = bills.ID;
- //含量:定额工程量/清单工程量
- if (!bills.quantity || !ration.quantity){
- ration.contain = '0';
- } else {
- ration.contain = scMathUtil.roundForObj(ration.quantity / bills.quantity, 6);
- }
- //工程量表达式:工程量 * 单位前的量
- if (!ration.unit) {
- ration.quantityEXP = ration.quantity;
- } else {
- let unitNum = ration.unit.match(/^\d+/);
- //工程量小数位数
- let qDecimal = ration.quantity.match(/\.\d+/);
- ration.quantityEXP = unitNum
- ? scMathUtil.roundForObj(ration.quantity * unitNum[0], qDecimal ? qDecimal[0] - 1 : 0)
- : ration.quantity;
- }
- //处理定额人材机,添加需要的数据
- ration.rationGljs.forEach(rGLJ => {
- let matchGLJ = projectGLJMap[rGLJ.code];
- if (matchGLJ) {
- rGLJ.projectGLJID = matchGLJ.id;
- rGLJ.code = matchGLJ.original_code;
- rGLJ.type = matchGLJ.type;
- rGLJ.shortName = matchGLJ.shortName;
- rGLJ.name = matchGLJ.name;
- rGLJ.original_code = matchGLJ.original_code;
- rGLJ.unit = matchGLJ.unit;
- rGLJ.specs = matchGLJ.specs;
- }
- rGLJ.ID = uuid.v1();
- rGLJ.projectID = tenderData.ID;
- rGLJ.billsItemID = bills.ID;
- rGLJ.rationID = ration.ID;
- rGLJ.rationCode = ration.code; //暂时跟定额编码关联,后端好匹配标准数据
- rGLJ.rationItemQuantity = rGLJ.quantity; //定额消耗,暂时取消耗量,需要后端匹配标准数据后更新
- rst.rationGLJ.push(rGLJ);
- });
- delete ration.rationGljs;
- rst.ration.push(ration);
- rst.rationCoe.push(getRationCoe(ration));
- });
- });
- }
- function getRationCoe(ration) {
- return {
- projectID: ration.projectID,
- rationID: ration.ID,
- coeID: -1,
- ID: uuid.v1(),
- seq: 1, //以前排序有的字段,暂时没什么用,不过还是赋上一个值
- name: '自定义系数',
- content: '人工×1,材料×1,机械×1,主材×1,设备×1',
- coes: [
- {amount: 1, operator: '*', gljCode: null, coeType: '定额'},
- {amount: 1, operator: '*', gljCode: null, coeType: '人工'},
- {amount: 1, operator: '*', gljCode: null, coeType: '材料'},
- {amount: 1, operator: '*', gljCode: null, coeType: '机械'},
- {amount: 1, operator: '*', gljCode: null, coeType: '主材'},
- {amount: 1, operator: '*', gljCode: null, coeType: '设备'},
- ],
- option_list: []
- }
- }
- function getUnitPrice(projectGLJ) {
- return {
- projectGLJID: projectGLJ.id, //做个标记,后端查找标准数据后,方便更新组成物数据
- unit_price_file_id: tenderData.property.unitPriceFile.id,
- id: IDPlaceholder.unitPrice++,
- code: projectGLJ.code,
- original_code: projectGLJ.original_code,
- name: projectGLJ.name,
- unit: projectGLJ.unit,
- specs: projectGLJ.specs,
- type: projectGLJ.type,
- short_name: projectGLJ.shortName,
- base_price: projectGLJ.base_price,
- market_price: projectGLJ.market_price
- };
- }
- }
- };
- })();
|