|
@@ -1,40 +1,38 @@
|
|
|
-
|
|
|
|
|
/*
|
|
/*
|
|
|
* @Descripttion: 导入通用代码
|
|
* @Descripttion: 导入通用代码
|
|
|
* @Author: vian
|
|
* @Author: vian
|
|
|
* @Date: 2020-09-09 10:45:54
|
|
* @Date: 2020-09-09 10:45:54
|
|
|
*/
|
|
*/
|
|
|
-const XML_RN_STR = '@-@';
|
|
|
|
|
|
|
+const XML_RN_STR = "@-@";
|
|
|
const INTERFACE_EXPORT_BASE = (() => {
|
|
const INTERFACE_EXPORT_BASE = (() => {
|
|
|
-
|
|
|
|
|
// xml字符实体
|
|
// xml字符实体
|
|
|
const XMLEntity = {
|
|
const XMLEntity = {
|
|
|
- ' ': 'escape{space}',
|
|
|
|
|
- ' ': 'escape{simpleSpace}',
|
|
|
|
|
- '	': 'escape{tab}',
|
|
|
|
|
- '	': 'escape{simpleTab}',
|
|
|
|
|
- '
': 'escape{return}',
|
|
|
|
|
- '
': 'escape{simpleReturn}',
|
|
|
|
|
- '�A;': 'escape{newLine}',
|
|
|
|
|
- '
': 'escape{simpleNewLine}',
|
|
|
|
|
- '<': 'escape{less}',
|
|
|
|
|
- '>': 'escape{greater}',
|
|
|
|
|
- '&': 'escape{and}',
|
|
|
|
|
- '"': 'escape{quot}',
|
|
|
|
|
- ''': 'escape{apos}'
|
|
|
|
|
|
|
+ " ": "escape{space}",
|
|
|
|
|
+ " ": "escape{simpleSpace}",
|
|
|
|
|
+ "	": "escape{tab}",
|
|
|
|
|
+ "	": "escape{simpleTab}",
|
|
|
|
|
+ "
": "escape{return}",
|
|
|
|
|
+ "
": "escape{simpleReturn}",
|
|
|
|
|
+ "�A;": "escape{newLine}",
|
|
|
|
|
+ "
": "escape{simpleNewLine}",
|
|
|
|
|
+ "<": "escape{less}",
|
|
|
|
|
+ ">": "escape{greater}",
|
|
|
|
|
+ "&": "escape{and}",
|
|
|
|
|
+ """: "escape{quot}",
|
|
|
|
|
+ "'": "escape{apos}",
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 避免字符实体进行转义。原文本中含有xml字符实体,转换为其他字符。
|
|
// 避免字符实体进行转义。原文本中含有xml字符实体,转换为其他字符。
|
|
|
function escapeXMLEntity(str) {
|
|
function escapeXMLEntity(str) {
|
|
|
for (const [key, value] of Object.entries(XMLEntity)) {
|
|
for (const [key, value] of Object.entries(XMLEntity)) {
|
|
|
- str = str.replace(new RegExp(key, 'g'), value);
|
|
|
|
|
|
|
+ str = str.replace(new RegExp(key, "g"), value);
|
|
|
}
|
|
}
|
|
|
return str;
|
|
return str;
|
|
|
}
|
|
}
|
|
|
// 将文本还原为字符实体
|
|
// 将文本还原为字符实体
|
|
|
function restoreXMLEntity(str) {
|
|
function restoreXMLEntity(str) {
|
|
|
for (const [key, value] of Object.entries(XMLEntity)) {
|
|
for (const [key, value] of Object.entries(XMLEntity)) {
|
|
|
- str = str.replace(new RegExp(value, 'g'), key);
|
|
|
|
|
|
|
+ str = str.replace(new RegExp(value, "g"), key);
|
|
|
}
|
|
}
|
|
|
return str;
|
|
return str;
|
|
|
}
|
|
}
|
|
@@ -52,19 +50,19 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
let cur = source;
|
|
let cur = source;
|
|
|
for (const field of fields) {
|
|
for (const field of fields) {
|
|
|
if (!cur[field]) {
|
|
if (!cur[field]) {
|
|
|
- return '';
|
|
|
|
|
|
|
+ return "";
|
|
|
}
|
|
}
|
|
|
cur = cur[field];
|
|
cur = cur[field];
|
|
|
}
|
|
}
|
|
|
- if (typeof cur === 'string') {
|
|
|
|
|
- cur = cur.replace(new RegExp(XML_RN_STR, 'g'), '\r\n');
|
|
|
|
|
|
|
+ if (typeof cur === "string") {
|
|
|
|
|
+ cur = cur.replace(new RegExp(XML_RN_STR, "g"), "\r\n");
|
|
|
}
|
|
}
|
|
|
- return cur || '';
|
|
|
|
|
|
|
+ return cur || "";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取布尔型的数据
|
|
// 获取布尔型的数据
|
|
|
function getBool(source, fields) {
|
|
function getBool(source, fields) {
|
|
|
- return getValue(source, fields) === 'true' ? true : false;
|
|
|
|
|
|
|
+ return getValue(source, fields) === "true" ? true : false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取数据类型
|
|
// 获取数据类型
|
|
@@ -81,10 +79,10 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
* */
|
|
* */
|
|
|
function arrayValue(source, fields) {
|
|
function arrayValue(source, fields) {
|
|
|
let target = getValue(source, fields);
|
|
let target = getValue(source, fields);
|
|
|
- if (_plainType(target) === 'Object') {
|
|
|
|
|
|
|
+ if (_plainType(target) === "Object") {
|
|
|
target = [target];
|
|
target = [target];
|
|
|
- } else if (_plainType(target) !== 'Array') {
|
|
|
|
|
- target = []
|
|
|
|
|
|
|
+ } else if (_plainType(target) !== "Array") {
|
|
|
|
|
+ target = [];
|
|
|
}
|
|
}
|
|
|
return target;
|
|
return target;
|
|
|
}
|
|
}
|
|
@@ -92,10 +90,10 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
// 获取费用
|
|
// 获取费用
|
|
|
function getFee(fees, fields) {
|
|
function getFee(fees, fields) {
|
|
|
if (!Array.isArray(fees) || !fees.length) {
|
|
if (!Array.isArray(fees) || !fees.length) {
|
|
|
- return '0';
|
|
|
|
|
|
|
+ return "0";
|
|
|
}
|
|
}
|
|
|
- const feeData = fees.find(fee => fee.fieldName === fields[0]);
|
|
|
|
|
- return feeData && feeData[fields[1]] || '0';
|
|
|
|
|
|
|
+ const feeData = fees.find((fee) => fee.fieldName === fields[0]);
|
|
|
|
|
+ return (feeData && feeData[fields[1]]) || "0";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 合并价格
|
|
// 合并价格
|
|
@@ -106,8 +104,8 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
if (!feesB) {
|
|
if (!feesB) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
- feesB.forEach(feeB => {
|
|
|
|
|
- const sameKindFee = feesA.find(feeA => feeA.fieldName === feeB.fieldName);
|
|
|
|
|
|
|
+ feesB.forEach((feeB) => {
|
|
|
|
|
+ const sameKindFee = feesA.find((feeA) => feeA.fieldName === feeB.fieldName);
|
|
|
if (sameKindFee) {
|
|
if (sameKindFee) {
|
|
|
Object.assign(sameKindFee, feeB);
|
|
Object.assign(sameKindFee, feeB);
|
|
|
} else {
|
|
} else {
|
|
@@ -125,26 +123,27 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
const sourceAttrs = attrs || Object.keys(source);
|
|
const sourceAttrs = attrs || Object.keys(source);
|
|
|
for (const attr of sourceAttrs) {
|
|
for (const attr of sourceAttrs) {
|
|
|
// 如果值是undefined,则不进行赋值覆盖处理
|
|
// 如果值是undefined,则不进行赋值覆盖处理
|
|
|
- if (attr === 'children' || source[attr] === undefined) {
|
|
|
|
|
|
|
+ if (attr === "children" || source[attr] === undefined) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
- target[attr] = attr === 'fees'
|
|
|
|
|
- ? mergeFees(target[attr], source[attr]) // 如果是价格,不能简单地覆盖,要合并两个对象的价格
|
|
|
|
|
- : source[attr];
|
|
|
|
|
|
|
+ target[attr] =
|
|
|
|
|
+ attr === "fees"
|
|
|
|
|
+ ? mergeFees(target[attr], source[attr]) // 如果是价格,不能简单地覆盖,要合并两个对象的价格
|
|
|
|
|
+ : source[attr];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取固定ID
|
|
// 获取固定ID
|
|
|
function getFlag(data) {
|
|
function getFlag(data) {
|
|
|
- return data.flags && data.flags[0] && data.flags[0].flag || 0;
|
|
|
|
|
|
|
+ return (data.flags && data.flags[0] && data.flags[0].flag) || 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 设置成树结构数据
|
|
// 设置成树结构数据
|
|
|
function setTreeData(data, parent, next) {
|
|
function setTreeData(data, parent, next) {
|
|
|
const defalutID = -1;
|
|
const defalutID = -1;
|
|
|
data.ID = uuid.v1();
|
|
data.ID = uuid.v1();
|
|
|
- data.ParentID = parent && parent.ID || defalutID;
|
|
|
|
|
- data.NextSiblingID = next && next.ID || defalutID;
|
|
|
|
|
|
|
+ data.ParentID = (parent && parent.ID) || defalutID;
|
|
|
|
|
+ data.NextSiblingID = (next && next.ID) || defalutID;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 递归设置树结构数据,并返回设置好的数据,递归items数组
|
|
// 递归设置树结构数据,并返回设置好的数据,递归items数组
|
|
@@ -175,7 +174,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
return obj;
|
|
return obj;
|
|
|
}); */
|
|
}); */
|
|
|
const items = [];
|
|
const items = [];
|
|
|
- itemsSrc.forEach(itemSrc => {
|
|
|
|
|
|
|
+ itemsSrc.forEach((itemSrc) => {
|
|
|
const obj = extractFuc(itemSrc, field[0]);
|
|
const obj = extractFuc(itemSrc, field[0]);
|
|
|
if (obj) {
|
|
if (obj) {
|
|
|
if (!obj.children || obj.children.length === 0) {
|
|
if (!obj.children || obj.children.length === 0) {
|
|
@@ -183,7 +182,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
}
|
|
}
|
|
|
items.push(obj);
|
|
items.push(obj);
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ });
|
|
|
rst.push(...items);
|
|
rst.push(...items);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -212,7 +211,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
* @return {Array}
|
|
* @return {Array}
|
|
|
*/
|
|
*/
|
|
|
function mergeInfo(source, target) {
|
|
function mergeInfo(source, target) {
|
|
|
- source.forEach(item => mergeChild(item, target));
|
|
|
|
|
|
|
+ source.forEach((item) => mergeChild(item, target));
|
|
|
return target;
|
|
return target;
|
|
|
|
|
|
|
|
function mergeChild(item, target) {
|
|
function mergeChild(item, target) {
|
|
@@ -242,7 +241,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
4: fixedFlag.DAYWORK_LABOR,
|
|
4: fixedFlag.DAYWORK_LABOR,
|
|
|
5: fixedFlag.PROVISIONAL,
|
|
5: fixedFlag.PROVISIONAL,
|
|
|
6: fixedFlag.TOTAL_COST,
|
|
6: fixedFlag.TOTAL_COST,
|
|
|
- }
|
|
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 将提取出来的清单合并进清单模板
|
|
* 将提取出来的清单合并进清单模板
|
|
@@ -258,33 +257,33 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
if (!parent) {
|
|
if (!parent) {
|
|
|
bills.seq = index;
|
|
bills.seq = index;
|
|
|
}
|
|
}
|
|
|
- const simpleName = bills.name ? bills.name.replace(/\s/g, '') : '';
|
|
|
|
|
- const titleType = bills.titleType || '0';
|
|
|
|
|
|
|
+ const simpleName = bills.name ? bills.name.replace(/\s/g, "") : "";
|
|
|
|
|
+ const titleType = bills.titleType || "0";
|
|
|
let matched;
|
|
let matched;
|
|
|
if (!parent) {
|
|
if (!parent) {
|
|
|
if (titleTypeToFlag[titleType] === fixedFlag.ONE_SEVEN_BILLS || /100章.*章|100章.*700章|100章.*900章/.test(simpleName)) {
|
|
if (titleTypeToFlag[titleType] === fixedFlag.ONE_SEVEN_BILLS || /100章.*章|100章.*700章|100章.*900章/.test(simpleName)) {
|
|
|
- matched = target.find(bills => getFlag(bills) === fixedFlag.ONE_SEVEN_BILLS);
|
|
|
|
|
|
|
+ matched = target.find((bills) => getFlag(bills) === fixedFlag.ONE_SEVEN_BILLS);
|
|
|
} else if (titleTypeToFlag[titleType] === fixedFlag.PROVISIONAL_TOTAL || /包含在清单合计中的材料、工程设备、专业工程暂估/.test(simpleName)) {
|
|
} else if (titleTypeToFlag[titleType] === fixedFlag.PROVISIONAL_TOTAL || /包含在清单合计中的材料、工程设备、专业工程暂估/.test(simpleName)) {
|
|
|
- matched = target.find(bills => getFlag(bills) === fixedFlag.PROVISIONAL_TOTAL);
|
|
|
|
|
|
|
+ matched = target.find((bills) => getFlag(bills) === fixedFlag.PROVISIONAL_TOTAL);
|
|
|
} else if (titleTypeToFlag[titleType] === fixedFlag.BILLS_TOTAL_WT_PROV || /清单合计减去材料、工程设备、专业工程暂估价/.test(simpleName)) {
|
|
} else if (titleTypeToFlag[titleType] === fixedFlag.BILLS_TOTAL_WT_PROV || /清单合计减去材料、工程设备、专业工程暂估价/.test(simpleName)) {
|
|
|
- matched = target.find(bills => getFlag(bills) === fixedFlag.BILLS_TOTAL_WT_PROV);
|
|
|
|
|
|
|
+ matched = target.find((bills) => getFlag(bills) === fixedFlag.BILLS_TOTAL_WT_PROV);
|
|
|
} else if (titleTypeToFlag[titleType] === fixedFlag.DAYWORK_LABOR || /计日工合计/.test(simpleName)) {
|
|
} else if (titleTypeToFlag[titleType] === fixedFlag.DAYWORK_LABOR || /计日工合计/.test(simpleName)) {
|
|
|
- matched = target.find(bills => getFlag(bills) === fixedFlag.DAYWORK_LABOR);
|
|
|
|
|
|
|
+ matched = target.find((bills) => getFlag(bills) === fixedFlag.DAYWORK_LABOR);
|
|
|
} else if (titleTypeToFlag[titleType] === fixedFlag.PROVISIONAL || /暂列金额[((]不含/.test(simpleName)) {
|
|
} else if (titleTypeToFlag[titleType] === fixedFlag.PROVISIONAL || /暂列金额[((]不含/.test(simpleName)) {
|
|
|
- matched = target.find(bills => getFlag(bills) === fixedFlag.PROVISIONAL);
|
|
|
|
|
|
|
+ matched = target.find((bills) => getFlag(bills) === fixedFlag.PROVISIONAL);
|
|
|
} else if (titleTypeToFlag[titleType] === fixedFlag.TOTAL_COST || /报价/.test(simpleName)) {
|
|
} else if (titleTypeToFlag[titleType] === fixedFlag.TOTAL_COST || /报价/.test(simpleName)) {
|
|
|
- matched = target.find(bills => getFlag(bills) === fixedFlag.TOTAL_COST);
|
|
|
|
|
|
|
+ matched = target.find((bills) => getFlag(bills) === fixedFlag.TOTAL_COST);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- const parentSimpleName = parent.name ? parent.name.replace(/\s/g, '') : '';
|
|
|
|
|
|
|
+ const parentSimpleName = parent.name ? parent.name.replace(/\s/g, "") : "";
|
|
|
if (/100章.*章|100章.*700章|100章.*900章/.test(parentSimpleName) && /100章总则/.test(simpleName)) {
|
|
if (/100章.*章|100章.*700章|100章.*900章/.test(parentSimpleName) && /100章总则/.test(simpleName)) {
|
|
|
- matched = target.find(bills => getFlag(bills) === fixedFlag.ONE_HUNDRED_BILLS);
|
|
|
|
|
|
|
+ matched = target.find((bills) => getFlag(bills) === fixedFlag.ONE_HUNDRED_BILLS);
|
|
|
} else if (/计日工合计/.test(parentSimpleName) && /劳务/.test(simpleName)) {
|
|
} else if (/计日工合计/.test(parentSimpleName) && /劳务/.test(simpleName)) {
|
|
|
- matched = target.find(bills => getFlag(bills) === fixedFlag.LABOUR_SERVICE);
|
|
|
|
|
|
|
+ matched = target.find((bills) => getFlag(bills) === fixedFlag.LABOUR_SERVICE);
|
|
|
} else if (/计日工合计/.test(parentSimpleName) && /材料/.test(simpleName)) {
|
|
} else if (/计日工合计/.test(parentSimpleName) && /材料/.test(simpleName)) {
|
|
|
- matched = target.find(bills => getFlag(bills) === fixedFlag.MATERIAL);
|
|
|
|
|
|
|
+ matched = target.find((bills) => getFlag(bills) === fixedFlag.MATERIAL);
|
|
|
} else if (/计日工合计/.test(parentSimpleName) && /机械/.test(simpleName)) {
|
|
} else if (/计日工合计/.test(parentSimpleName) && /机械/.test(simpleName)) {
|
|
|
- matched = target.find(bills => getFlag(bills) === fixedFlag.CONSTRUCTION_MACHINE);
|
|
|
|
|
|
|
+ matched = target.find((bills) => getFlag(bills) === fixedFlag.CONSTRUCTION_MACHINE);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (matched) {
|
|
if (matched) {
|
|
@@ -316,7 +315,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
// 如果只导入文件中有的清单,除100-700/900章清单、报价清单外,其他未匹配到的固定清单模板,均不导入
|
|
// 如果只导入文件中有的清单,除100-700/900章清单、报价清单外,其他未匹配到的固定清单模板,均不导入
|
|
|
function removeNotMatchFlagBills(bills) {
|
|
function removeNotMatchFlagBills(bills) {
|
|
|
const rst = [];
|
|
const rst = [];
|
|
|
- bills.forEach(item => {
|
|
|
|
|
|
|
+ bills.forEach((item) => {
|
|
|
const flag = getFlag(item);
|
|
const flag = getFlag(item);
|
|
|
if (!flag || [fixedFlag.ONE_SEVEN_BILLS, fixedFlag.TOTAL_COST].includes(flag) || matchedFlags.includes(flag)) {
|
|
if (!flag || [fixedFlag.ONE_SEVEN_BILLS, fixedFlag.TOTAL_COST].includes(flag) || matchedFlags.includes(flag)) {
|
|
|
rst.push(item);
|
|
rst.push(item);
|
|
@@ -328,7 +327,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
return rst;
|
|
return rst;
|
|
|
}
|
|
}
|
|
|
if (onlyImportMatchBills) {
|
|
if (onlyImportMatchBills) {
|
|
|
- billsTarget = removeNotMatchFlagBills(billsTarget)
|
|
|
|
|
|
|
+ billsTarget = removeNotMatchFlagBills(billsTarget);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 大项费用按照清单标题排序
|
|
// 大项费用按照清单标题排序
|
|
@@ -356,7 +355,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
}
|
|
}
|
|
|
if (child.rowCode) {
|
|
if (child.rowCode) {
|
|
|
const regStr = /{[^{}]+}/.test(child.rowCode) ? child.rowCode : `\\b${child.rowCode}\\b`;
|
|
const regStr = /{[^{}]+}/.test(child.rowCode) ? child.rowCode : `\\b${child.rowCode}\\b`;
|
|
|
- rowCodeData.push({ reg: new RegExp(regStr, 'g'), ID: child.ID, rowCode: child.rowCode });
|
|
|
|
|
|
|
+ rowCodeData.push({ reg: new RegExp(regStr, "g"), ID: child.ID, rowCode: child.rowCode });
|
|
|
}
|
|
}
|
|
|
if (child.tempCalcBase) {
|
|
if (child.tempCalcBase) {
|
|
|
toBeTransformBills.push(child);
|
|
toBeTransformBills.push(child);
|
|
@@ -368,7 +367,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
}
|
|
}
|
|
|
setBills(billsTarget, -1);
|
|
setBills(billsTarget, -1);
|
|
|
// 转换计算基数
|
|
// 转换计算基数
|
|
|
- toBeTransformBills.forEach(bills => {
|
|
|
|
|
|
|
+ toBeTransformBills.forEach((bills) => {
|
|
|
rowCodeData.forEach(({ reg, ID, rowCode }) => {
|
|
rowCodeData.forEach(({ reg, ID, rowCode }) => {
|
|
|
const rowCodeReg = new RegExp(`{${rowCode}}`);
|
|
const rowCodeReg = new RegExp(`{${rowCode}}`);
|
|
|
// 替换行号
|
|
// 替换行号
|
|
@@ -378,26 +377,28 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
bills.tempCalcBase = bills.tempCalcBase.replace(reg, `@${ID}`);
|
|
bills.tempCalcBase = bills.tempCalcBase.replace(reg, `@${ID}`);
|
|
|
}
|
|
}
|
|
|
// 替换基数,防止其他公司的软件导出没有{}
|
|
// 替换基数,防止其他公司的软件导出没有{}
|
|
|
- bills.tempCalcBase = bills.tempCalcBase.replace(/.?专项暂定合计.?/g, '{专项暂定合计}');
|
|
|
|
|
- bills.tempCalcBase = bills.tempCalcBase.replace(/.?各章清单合计.?/g, '{各章清单合计}');
|
|
|
|
|
|
|
+ bills.tempCalcBase = bills.tempCalcBase.replace(/.?专项暂定合计.?/g, "{专项暂定合计}");
|
|
|
|
|
+ bills.tempCalcBase = bills.tempCalcBase.replace(/.?各章清单合计.?/g, "{各章清单合计}");
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
/* 检查基数有效性,无效则使用模板的基数 */
|
|
/* 检查基数有效性,无效则使用模板的基数 */
|
|
|
// 消除ID引用对基数分割的影响
|
|
// 消除ID引用对基数分割的影响
|
|
|
const IDs = bills.tempCalcBase.match(/@[\da-zA-Z-]{36}/g) || [];
|
|
const IDs = bills.tempCalcBase.match(/@[\da-zA-Z-]{36}/g) || [];
|
|
|
const bases = [...IDs];
|
|
const bases = [...IDs];
|
|
|
- const str = bills.tempCalcBase.replace(/@[\da-zA-Z-]{36}/g, '');
|
|
|
|
|
- const otherBases = str.split(/[+-/*]/).filter(item => !!item);
|
|
|
|
|
|
|
+ const str = bills.tempCalcBase.replace(/@[\da-zA-Z-]{36}/g, "");
|
|
|
|
|
+ const otherBases = str.split(/[+-/*]/).filter((item) => !!item);
|
|
|
bases.push(...otherBases);
|
|
bases.push(...otherBases);
|
|
|
// 判定基数有效性
|
|
// 判定基数有效性
|
|
|
- const isValid = bases.every(base => {
|
|
|
|
|
- if (base === '{专项暂定合计}' || base === '{各章清单合计}') {
|
|
|
|
|
|
|
+ const isValid = bases.every((base) => {
|
|
|
|
|
+ if (base === "{专项暂定合计}" || base === "{各章清单合计}") {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
- if (/^(\d+(\.\d+)?)%?$/.test(base)) { // 数值+%(可有可无)
|
|
|
|
|
|
|
+ if (/^(\d+(\.\d+)?)%?$/.test(base)) {
|
|
|
|
|
+ // 数值+%(可有可无)
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
- if (/[\da-zA-Z-]{36}/.test(base)) { // ID引用
|
|
|
|
|
|
|
+ if (/[\da-zA-Z-]{36}/.test(base)) {
|
|
|
|
|
+ // ID引用
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
@@ -406,7 +407,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
bills.calcBase = bills.tempCalcBase;
|
|
bills.calcBase = bills.tempCalcBase;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- rst.forEach(bills => delete bills.children);
|
|
|
|
|
|
|
+ rst.forEach((bills) => delete bills.children);
|
|
|
return rst;
|
|
return rst;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -437,22 +438,22 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
tender.projType = projectType.tender;
|
|
tender.projType = projectType.tender;
|
|
|
const featureTarget = _.cloneDeep(templateData.feature); // 必须拷贝出一份新数据,否则会被下一个单位工程覆盖
|
|
const featureTarget = _.cloneDeep(templateData.feature); // 必须拷贝出一份新数据,否则会被下一个单位工程覆盖
|
|
|
if (!engineeringLib) {
|
|
if (!engineeringLib) {
|
|
|
- throw '不存在可用工程专业。';
|
|
|
|
|
|
|
+ throw "不存在可用工程专业。";
|
|
|
}
|
|
}
|
|
|
const taxData = engineeringLib.lib.tax_group[0];
|
|
const taxData = engineeringLib.lib.tax_group[0];
|
|
|
const featureSource = [
|
|
const featureSource = [
|
|
|
...(tender.feature || []),
|
|
...(tender.feature || []),
|
|
|
- { key: 'valuationType', value: '工程量清单' }, // 导入的时候以下项不一定有数据,但是需要自动生成
|
|
|
|
|
- { key: 'feeStandard', value: engineeringLib.lib.feeName },
|
|
|
|
|
|
|
+ { key: "valuationType", value: "工程量清单" }, // 导入的时候以下项不一定有数据,但是需要自动生成
|
|
|
|
|
+ { key: "feeStandard", value: engineeringLib.lib.feeName },
|
|
|
];
|
|
];
|
|
|
- const needEngineering = featureTarget && featureTarget.find(item => item.key === 'engineering');
|
|
|
|
|
|
|
+ const needEngineering = featureTarget && featureTarget.find((item) => item.key === "engineering");
|
|
|
if (needEngineering) {
|
|
if (needEngineering) {
|
|
|
- featureSource.push({ key: 'engineering', value: engineeringLib.lib.name });
|
|
|
|
|
|
|
+ featureSource.push({ key: "engineering", value: engineeringLib.lib.name });
|
|
|
}
|
|
}
|
|
|
tender.property = {
|
|
tender.property = {
|
|
|
areaKey,
|
|
areaKey,
|
|
|
rootProjectID: tender.ParentID,
|
|
rootProjectID: tender.ParentID,
|
|
|
- region: '全省',
|
|
|
|
|
|
|
+ region: "全省",
|
|
|
engineering_id: engineeringLib.engineering_id,
|
|
engineering_id: engineeringLib.engineering_id,
|
|
|
engineeringName: engineeringLib.lib.name,
|
|
engineeringName: engineeringLib.lib.name,
|
|
|
feeStandardName: engineeringLib.lib.feeName,
|
|
feeStandardName: engineeringLib.lib.feeName,
|
|
@@ -465,21 +466,21 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
boqType: commonConstants.BOQType.BID_SUBMISSION, // 导入后必为投标
|
|
boqType: commonConstants.BOQType.BID_SUBMISSION, // 导入后必为投标
|
|
|
taxType: taxData.taxType,
|
|
taxType: taxData.taxType,
|
|
|
projectFeature: mergeInfo(featureSource, featureTarget),
|
|
projectFeature: mergeInfo(featureSource, featureTarget),
|
|
|
- featureLibID: engineeringLib.lib.feature_lib[0] && engineeringLib.lib.feature_lib[0].id || '',
|
|
|
|
|
|
|
+ featureLibID: (engineeringLib.lib.feature_lib[0] && engineeringLib.lib.feature_lib[0].id) || "",
|
|
|
calcProgram: { name: taxData.program_lib.name, id: taxData.program_lib.id },
|
|
calcProgram: { name: taxData.program_lib.name, id: taxData.program_lib.id },
|
|
|
colLibID: taxData.col_lib.id,
|
|
colLibID: taxData.col_lib.id,
|
|
|
templateLibID: taxData.template_lib.id,
|
|
templateLibID: taxData.template_lib.id,
|
|
|
unitPriceFile: { name: tender.name, id: templateData.unitPriceFileBeginID + index }, // 新建单价文件
|
|
unitPriceFile: { name: tender.name, id: templateData.unitPriceFileBeginID + index }, // 新建单价文件
|
|
|
- feeFile: { name: tender.name, id: `newFeeRate@@${taxData.fee_lib.id}` } // 新建费率文件
|
|
|
|
|
|
|
+ feeFile: { name: tender.name, id: `newFeeRate@@${taxData.fee_lib.id}` }, // 新建费率文件
|
|
|
};
|
|
};
|
|
|
delete tender.feature;
|
|
delete tender.feature;
|
|
|
const tenderDataBills = getTemplateBillsTarget(templateData.bills);
|
|
const tenderDataBills = getTemplateBillsTarget(templateData.bills);
|
|
|
tender.bills = handleBills(tender.bills, tenderDataBills, tender.ID, onlyImportMatchBills); // 必须要拷贝一份,否则多单位工程情况下,前单位工程的清单数据会被后单位工程的覆盖
|
|
tender.bills = handleBills(tender.bills, tenderDataBills, tender.ID, onlyImportMatchBills); // 必须要拷贝一份,否则多单位工程情况下,前单位工程的清单数据会被后单位工程的覆盖
|
|
|
// 给暂估材料和评标材料设置项目数据
|
|
// 给暂估材料和评标材料设置项目数据
|
|
|
- const setGLJRefFunc = glj => {
|
|
|
|
|
|
|
+ const setGLJRefFunc = (glj) => {
|
|
|
glj.ID = uuid.v1();
|
|
glj.ID = uuid.v1();
|
|
|
glj.projectID = tender.ID;
|
|
glj.projectID = tender.ID;
|
|
|
- }
|
|
|
|
|
|
|
+ };
|
|
|
if (tender.evaluationList && tender.evaluationList.length) {
|
|
if (tender.evaluationList && tender.evaluationList.length) {
|
|
|
tender.evaluationList.forEach(setGLJRefFunc);
|
|
tender.evaluationList.forEach(setGLJRefFunc);
|
|
|
}
|
|
}
|
|
@@ -501,27 +502,26 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
async function handleImportData(importData, areaKey, onlyImportMatchBills) {
|
|
async function handleImportData(importData, areaKey, onlyImportMatchBills) {
|
|
|
const valuationID = compilationData.ration_valuation[0].id;
|
|
const valuationID = compilationData.ration_valuation[0].id;
|
|
|
if (!Array.isArray(importData.tenders) && !importData.tenders.length) {
|
|
if (!Array.isArray(importData.tenders) && !importData.tenders.length) {
|
|
|
- throw '导入的文件中不存在有效的标段数据。';
|
|
|
|
|
|
|
+ throw "导入的文件中不存在有效的标段数据。";
|
|
|
}
|
|
}
|
|
|
const projectCount = 1 + importData.tenders.length;
|
|
const projectCount = 1 + importData.tenders.length;
|
|
|
// const feeName = compilationData.name === '安徽养护(2018)' ? '安徽养护' : '公路工程';
|
|
// const feeName = compilationData.name === '安徽养护(2018)' ? '安徽养护' : '公路工程';
|
|
|
// 一些接口需要根据导入文件,匹配工程专业库
|
|
// 一些接口需要根据导入文件,匹配工程专业库
|
|
|
- debugger;
|
|
|
|
|
const rationValuationData = rationValuation && JSON.parse(rationValuation)[0]; // 只有工程量清单才能导入接口
|
|
const rationValuationData = rationValuation && JSON.parse(rationValuation)[0]; // 只有工程量清单才能导入接口
|
|
|
if (!rationValuationData) {
|
|
if (!rationValuationData) {
|
|
|
- throw '无法获取工程量清单计价数据';
|
|
|
|
|
|
|
+ throw "无法获取工程量清单计价数据";
|
|
|
}
|
|
}
|
|
|
- const engineeringList = (rationValuationData.engineering_list || []).filter(item => item.lib.visible);
|
|
|
|
|
|
|
+ const engineeringList = (rationValuationData.engineering_list || []).filter((item) => item.lib.visible);
|
|
|
let engineeringLib = engineeringList[0];
|
|
let engineeringLib = engineeringList[0];
|
|
|
if (importData.engineeringName && importData.feeName) {
|
|
if (importData.engineeringName && importData.feeName) {
|
|
|
- const matchLibs = engineeringList.filter(item => item.lib && item.lib.name === importData.engineeringName);
|
|
|
|
|
- engineeringLib = matchLibs.find(item => item.lib.feeName === importData.feeName) || matchLibs[0] || engineeringList[0];
|
|
|
|
|
|
|
+ const matchLibs = engineeringList.filter((item) => item.lib && item.lib.name === importData.engineeringName);
|
|
|
|
|
+ engineeringLib = matchLibs.find((item) => item.lib.feeName === importData.feeName) || matchLibs[0] || engineeringList[0];
|
|
|
}
|
|
}
|
|
|
const engineeringID = engineeringLib.engineering_id || null;
|
|
const engineeringID = engineeringLib.engineering_id || null;
|
|
|
|
|
|
|
|
- const templateData = await ajaxPost('/pm/api/getImportTemplateData', { user_id: userID, valuationID, engineeringID, projectCount });
|
|
|
|
|
|
|
+ const templateData = await ajaxPost("/pm/api/getImportTemplateData", { user_id: userID, valuationID, engineeringID, projectCount });
|
|
|
if (!templateData) {
|
|
if (!templateData) {
|
|
|
- throw '无法获取有效模板数据。';
|
|
|
|
|
|
|
+ throw "无法获取有效模板数据。";
|
|
|
}
|
|
}
|
|
|
console.log(templateData);
|
|
console.log(templateData);
|
|
|
// 处理建设项目数据
|
|
// 处理建设项目数据
|
|
@@ -543,7 +543,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
importData.property = {
|
|
importData.property = {
|
|
|
valuationType: commonConstants.ValuationType.BOQ, // 必为工程量清单
|
|
valuationType: commonConstants.ValuationType.BOQ, // 必为工程量清单
|
|
|
boqType: commonConstants.BOQType.BID_SUBMISSION, // 导入后必为投标
|
|
boqType: commonConstants.BOQType.BID_SUBMISSION, // 导入后必为投标
|
|
|
- basicInformation: mergeInfo(importData.info, templateData.basicInfo) // 将提取的基本信息数据与标准基本信息数据进行合并(目前只赋值,没有匹配到的不追加)
|
|
|
|
|
|
|
+ basicInformation: mergeInfo(importData.info, templateData.basicInfo), // 将提取的基本信息数据与标准基本信息数据进行合并(目前只赋值,没有匹配到的不追加)
|
|
|
};
|
|
};
|
|
|
delete importData.info;
|
|
delete importData.info;
|
|
|
// 处理单位工程数据
|
|
// 处理单位工程数据
|
|
@@ -552,25 +552,25 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
- * 读取文件转换为utf-8编码的字符串
|
|
|
|
|
- * @param {Blob} file
|
|
|
|
|
- * @return {Promise}
|
|
|
|
|
- * */
|
|
|
|
|
|
|
+ * 读取文件转换为utf-8编码的字符串
|
|
|
|
|
+ * @param {Blob} file
|
|
|
|
|
+ * @return {Promise}
|
|
|
|
|
+ * */
|
|
|
function readAsTextSync(file) {
|
|
function readAsTextSync(file) {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
const fr = new FileReader();
|
|
const fr = new FileReader();
|
|
|
- fr.readAsText(file); // 默认utf-8,如果出现乱码,得看导入文件是什么编码
|
|
|
|
|
|
|
+ fr.readAsText(file); // 默认utf-8,如果出现乱码,得看导入文件是什么编码
|
|
|
fr.onload = function () {
|
|
fr.onload = function () {
|
|
|
resolve(this.result);
|
|
resolve(this.result);
|
|
|
};
|
|
};
|
|
|
fr.onerror = function () {
|
|
fr.onerror = function () {
|
|
|
- reject('读取文件失败,请重试。');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ reject("读取文件失败,请重试。");
|
|
|
|
|
+ };
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @param {Function} entryFunc - 各导入接口提取导入数据方法
|
|
* @param {Function} entryFunc - 各导入接口提取导入数据方法
|
|
|
* @param {File} file - 导入的文件
|
|
* @param {File} file - 导入的文件
|
|
|
* @param {String} areaKey - 地区标识,如:'安徽@马鞍山'
|
|
* @param {String} areaKey - 地区标识,如:'安徽@马鞍山'
|
|
@@ -586,10 +586,10 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
xmlStr = escapeXMLEntity(xmlStr);
|
|
xmlStr = escapeXMLEntity(xmlStr);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let reg1 = new RegExp('>\r\n', 'g');
|
|
|
|
|
- xmlStr = xmlStr.replace(reg1, '>');
|
|
|
|
|
|
|
+ let reg1 = new RegExp(">\r\n", "g");
|
|
|
|
|
+ xmlStr = xmlStr.replace(reg1, ">");
|
|
|
|
|
|
|
|
- let reg2 = new RegExp('\r\n', 'g');
|
|
|
|
|
|
|
+ let reg2 = new RegExp("\r\n", "g");
|
|
|
xmlStr = xmlStr.replace(reg2, XML_RN_STR);
|
|
xmlStr = xmlStr.replace(reg2, XML_RN_STR);
|
|
|
|
|
|
|
|
// reg = /(?<=子目名称).+(?=单位)/g;
|
|
// reg = /(?<=子目名称).+(?=单位)/g;
|
|
@@ -605,7 +605,7 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
xmlObj = JSON.parse(restoreXMLEntity(JSON.stringify(xmlObj)));
|
|
xmlObj = JSON.parse(restoreXMLEntity(JSON.stringify(xmlObj)));
|
|
|
console.log(xmlObj);
|
|
console.log(xmlObj);
|
|
|
if (!xmlObj) {
|
|
if (!xmlObj) {
|
|
|
- throw '无有效数据。';
|
|
|
|
|
|
|
+ throw "无有效数据。";
|
|
|
}
|
|
}
|
|
|
const importData = await entryFunc(areaKey, xmlObj);
|
|
const importData = await entryFunc(areaKey, xmlObj);
|
|
|
console.log(areaKey);
|
|
console.log(areaKey);
|
|
@@ -616,6 +616,5 @@ const INTERFACE_EXPORT_BASE = (() => {
|
|
|
return {
|
|
return {
|
|
|
UTIL,
|
|
UTIL,
|
|
|
extractImportData,
|
|
extractImportData,
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-})();
|
|
|
|
|
|
|
+ };
|
|
|
|
|
+})();
|