|
|
@@ -22,6 +22,8 @@ const installationDao = new InstallationDao();
|
|
|
import GljDao from "../../std_glj_lib/models/gljModel";
|
|
|
const stdGljDao = new GljDao();
|
|
|
import stdgljutil from "../../../public/cache/std_glj_type_util";
|
|
|
+const lossRateModel = mongoose.model('std_ration_lib_loss_rate_list');
|
|
|
+const uuidV1 = require('uuid/v1');
|
|
|
//add
|
|
|
const stdGLJItemModel = mongoose.model('std_glj_lib_gljList');
|
|
|
const stdGLJItemModelBackup = mongoose.model('std_glj_lib_gljList_backup');
|
|
|
@@ -72,6 +74,25 @@ async function copyCoeData(sourceLibID, targetLibID) {
|
|
|
return IDMapping;
|
|
|
}
|
|
|
|
|
|
+// 拷贝损耗率
|
|
|
+async function copyLossRateData(sourceLibID, targetLibID) {
|
|
|
+ const sourceLossData = await lossRateModel.find({ libID: sourceLibID }, '-_id').lean();
|
|
|
+ const IDMapping = {};
|
|
|
+ sourceLossData.forEach(item => {
|
|
|
+ IDMapping[item.ID] = uuidV1();
|
|
|
+ });
|
|
|
+
|
|
|
+ const insertData = sourceLossData.map(item => ({
|
|
|
+ ...item,
|
|
|
+ libID: targetLibID,
|
|
|
+ ID: IDMapping[item.ID],
|
|
|
+ }));
|
|
|
+ if (insertData.length) {
|
|
|
+ await lossRateModel.insertMany(insertData);
|
|
|
+ }
|
|
|
+ return IDMapping;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
// 拷贝定额库
|
|
|
rationItemDAO.prototype.copyLib = async function (sourceLibID, targetLibID, sourceGLJLibID, targetGLJLibID) {
|
|
|
@@ -79,6 +100,7 @@ rationItemDAO.prototype.copyLib = async function (sourceLibID, targetLibID, sour
|
|
|
const rationIDMapping = await getIDMapping(counter.moduleName.rations, sourceRationData);
|
|
|
const classIDMapping = await copyClassData(sourceLibID, targetLibID);
|
|
|
const coeIDMapping = await copyCoeData(sourceLibID, targetLibID);
|
|
|
+ const lossRateIDMapping = await copyLossRateData(sourceLibID, targetLibID);
|
|
|
const sourceGLJData = await stdGLJItemModel.find({ repositoryId: sourceGLJLibID }, '-_id code ID').lean();
|
|
|
const sourceGLJCodeMapping = {};
|
|
|
sourceGLJData.forEach(glj => sourceGLJCodeMapping[glj.code] = glj.ID);
|
|
|
@@ -100,6 +122,9 @@ rationItemDAO.prototype.copyLib = async function (sourceLibID, targetLibID, sour
|
|
|
});
|
|
|
const rationGLJList = [];
|
|
|
ration.rationGljList.forEach(rGLJ => {
|
|
|
+ if (rGLJ.lossRateID) {
|
|
|
+ rGLJ.lossRateID = lossRateIDMapping[rGLJ.lossRateID];
|
|
|
+ }
|
|
|
const newGLJID = gljIDMapping[rGLJ.gljId];
|
|
|
if (newGLJID) {
|
|
|
rGLJ.gljId = newGLJID;
|