|
@@ -40,6 +40,52 @@ class GljDao extends OprDao {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 处理消耗量,将多消耗量的第一个消耗量字段,设置成消耗量
|
|
|
+ async setConsumeAmt(sourceLibID, targetLibID) {
|
|
|
+ const sourceGljs = await gljModelBackup.find({ repositoryId: sourceLibID }).lean();
|
|
|
+ const targetGljs = await gljModel.find({ repositoryId: targetLibID }).lean();
|
|
|
+ const sourceMap = {};
|
|
|
+ const sourceIDMap = {};
|
|
|
+ sourceGljs.forEach(glj => {
|
|
|
+ sourceMap[glj.code] = glj;
|
|
|
+ sourceIDMap[glj.ID] = glj.code;
|
|
|
+
|
|
|
+ });
|
|
|
+ const targetMap = {};
|
|
|
+ targetGljs.forEach(glj => {
|
|
|
+ targetMap[glj.code] = glj;
|
|
|
+ });
|
|
|
+ const bulks = [];
|
|
|
+ targetGljs.forEach(glj => {
|
|
|
+ const source = sourceMap[glj.code];
|
|
|
+ if (source && source.component && source.component.length) {
|
|
|
+ const component = [];
|
|
|
+ source.component.forEach(c => {
|
|
|
+ const cCode = sourceIDMap[c.ID];
|
|
|
+ if (!cCode) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const target = targetMap[cCode];
|
|
|
+ if (!target) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const newID = target.ID;
|
|
|
+ const consumeAmt = c.consumeAmtProperty ? c.consumeAmtProperty.consumeAmt1 : undefined;
|
|
|
+ component.push({ ID: newID, consumeAmt });
|
|
|
+ })
|
|
|
+ bulks.push({ updateOne: { filter: { ID: glj.ID }, update: { $set: { component } } } })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (bulks.length) {
|
|
|
+ const chunks = _.chunk(bulks, 1000);
|
|
|
+ for (const chunk of chunks) {
|
|
|
+ if (chunk.length) {
|
|
|
+ await gljModel.bulkWrite(chunk);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async copyLib(sourceLibID, targetLibID) {
|
|
|
const task = [
|
|
|
this.copyClassData(sourceLibID, targetLibID),
|
|
@@ -49,7 +95,7 @@ class GljDao extends OprDao {
|
|
|
}
|
|
|
|
|
|
async copyClassData(sourceLibID, targetLibID) {
|
|
|
- const sourceClassData = await gljClassModel.find({ repositoryId: sourceLibID }, '-_id').lean();
|
|
|
+ const sourceClassData = await gljClassModelBackup.find({ repositoryId: sourceLibID }, '-_id').lean();
|
|
|
const insertData = sourceClassData.map(item => ({
|
|
|
...item,
|
|
|
repositoryId: targetLibID
|
|
@@ -60,7 +106,7 @@ class GljDao extends OprDao {
|
|
|
}
|
|
|
|
|
|
async copyGLJData(sourceLibID, targetLibID) {
|
|
|
- const sourceGLJData = await gljModel.find({ repositoryId: sourceLibID }, '-_id').lean();
|
|
|
+ const sourceGLJData = await gljModelBackup.find({ repositoryId: sourceLibID }, '-_id').lean();
|
|
|
const IDMapping = {};
|
|
|
const countData = await counter.counterDAO.getIDAfterCount(counter.moduleName.GLJ, sourceGLJData.length);
|
|
|
const countIdx = countData.sequence_value - (sourceGLJData.length - 1);
|