|
|
@@ -15,30 +15,20 @@ import EngineeringLibModel from "../../users/models/engineering_lib_model";
|
|
|
|
|
|
module.exports = {
|
|
|
copyTemplateData: async function (property, newProjID, callback) {
|
|
|
- //转换ID引用,原本@ID ID为原ID,需要替换为新的uuid
|
|
|
+ // 原ID引用更新成新ID引用
|
|
|
function parseCalcBase(calcBase, uuidMapping) {
|
|
|
- let rst = '';
|
|
|
- let reg = /@\d+/g,
|
|
|
- numberData = Array.from(new Set(calcBase.match(reg))); //eg: @1
|
|
|
- let regForOpr = /[\+,\-,\*,\/]/g,
|
|
|
- oprData = calcBase.match(regForOpr); //eg: +
|
|
|
- let regForID = /\d+/g;
|
|
|
- let uuidArr = [];
|
|
|
- for (let data of numberData) {
|
|
|
- let orgID = data.match(regForID);
|
|
|
- if (orgID && orgID[0] && uuidMapping[orgID[0]]) {
|
|
|
- uuidArr.push(uuidMapping[orgID[0]]);
|
|
|
+ const orgIDRefs = [...new Set(calcBase.match(/@\d+/g))];
|
|
|
+ orgIDRefs.forEach(orgRef => {
|
|
|
+ const orgID = orgRef.match(/\d+/)[0];
|
|
|
+ const newID = uuidMapping[orgID] || null;
|
|
|
+ // ID匹配不上则不转换这个引用
|
|
|
+ if (!newID) {
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
- for (let i = 0; i < uuidArr.length; i++) {
|
|
|
- let uid = uuidArr[i],
|
|
|
- opr = oprData[i - 1];
|
|
|
- if (opr) {
|
|
|
- rst += opr;
|
|
|
- }
|
|
|
- rst += `@${uid}`;
|
|
|
- }
|
|
|
- return rst;
|
|
|
+ const replaceStr = `@${newID}`;
|
|
|
+ calcBase = calcBase.replace(new RegExp(`${orgRef}\\b`, 'g'), replaceStr);
|
|
|
+ });
|
|
|
+ return calcBase;
|
|
|
}
|
|
|
async.parallel([
|
|
|
async function (cb) {
|
|
|
@@ -52,14 +42,15 @@ module.exports = {
|
|
|
for(let bill of billsDatas){
|
|
|
uuidMaping[bill.ID] = uuidV1();
|
|
|
}
|
|
|
- let needParseReg = /@/g;
|
|
|
+ const reg = /@\d+/;
|
|
|
billsDatas.forEach(function (template) {
|
|
|
template.projectID = newProjID;
|
|
|
template.ID = uuidMaping[template.ID] ? uuidMaping[template.ID] : -1;
|
|
|
template.ParentID = uuidMaping[template.ParentID] ? uuidMaping[template.ParentID] : -1;
|
|
|
template.NextSiblingID = uuidMaping[template.NextSiblingID] ? uuidMaping[template.NextSiblingID] : -1;
|
|
|
- //需要转换ID引用
|
|
|
- if (template.calcBase && needParseReg.test(template.calcBase)) {
|
|
|
+
|
|
|
+ const needToParseCalcBase = template.calcBase && reg.test(template.calcBase);
|
|
|
+ if (needToParseCalcBase) {
|
|
|
template.calcBase = parseCalcBase(template.calcBase, uuidMaping);
|
|
|
}
|
|
|
});
|