|
@@ -21,6 +21,51 @@ import async from "async";
|
|
|
let _ = require("lodash");
|
|
|
|
|
|
class GljDao extends OprDao{
|
|
|
+
|
|
|
+ async copyLib(sourceLibID, targetLibID) {
|
|
|
+ const task = [
|
|
|
+ this.copyClassData(sourceLibID, targetLibID),
|
|
|
+ this.copyGLJData(sourceLibID, targetLibID)
|
|
|
+ ];
|
|
|
+ await Promise.all(task);
|
|
|
+ }
|
|
|
+
|
|
|
+ async copyClassData(sourceLibID, targetLibID) {
|
|
|
+ const sourceClassData = await gljClassModel.find({ repositoryId: sourceLibID }, '-_id').lean();
|
|
|
+ const insertData = sourceClassData.map(item => ({
|
|
|
+ ... item,
|
|
|
+ repositoryId: targetLibID
|
|
|
+ }));
|
|
|
+ if (insertData.length) {
|
|
|
+ await gljClassModel.insertMany(insertData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async copyGLJData(sourceLibID, targetLibID) {
|
|
|
+ const sourceGLJData = await gljModel.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);
|
|
|
+ sourceGLJData.forEach((glj, index) => {
|
|
|
+ IDMapping[glj.ID] = countIdx + index;
|
|
|
+ });
|
|
|
+ const insertData = sourceGLJData.map(glj => {
|
|
|
+ const newComponent = (glj.component || []).map(c => ({
|
|
|
+ ID: IDMapping[c.ID],
|
|
|
+ consumeAmt: c.consumeAmt
|
|
|
+ }));
|
|
|
+ return {
|
|
|
+ ...glj,
|
|
|
+ repositoryId: targetLibID,
|
|
|
+ ID: IDMapping[glj.ID],
|
|
|
+ component: newComponent
|
|
|
+ };
|
|
|
+ });
|
|
|
+ if (insertData.length) {
|
|
|
+ await gljModel.insertMany(insertData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async getReference(repositoryId, gljId) {
|
|
|
const gljLib = await gljMapModel.findOne({ID: repositoryId});
|
|
|
const rationLibIds = gljLib.rationLibs.map(lib => lib.ID);
|