|
@@ -8,6 +8,8 @@
|
|
|
import mongoose from "mongoose";
|
|
|
import BaseModel from "../../common/base/base_model";
|
|
|
import uuidV1 from 'uuid/v1';
|
|
|
+const engineeringModel = mongoose.model('engineering_lib');
|
|
|
+const compilationModel = mongoose.model('compilation');
|
|
|
|
|
|
class CompilationModel extends BaseModel {
|
|
|
|
|
@@ -457,6 +459,35 @@ class CompilationModel extends BaseModel {
|
|
|
return await this.updateById(compilationId, {categoryID: category});
|
|
|
}
|
|
|
|
|
|
+ // 拷贝计价规则
|
|
|
+ async copyValuation(compilationID, valuationType, orgValuationID, newName) {
|
|
|
+ const objectId = mongoose.Types.ObjectId(compilationID);
|
|
|
+ const compilationData = await compilationModel.findOne({_id: objectId }).lean();
|
|
|
+ const orgValuation = compilationData[valuationType].find(item => item.id === orgValuationID);
|
|
|
+ if (!orgValuation) {
|
|
|
+ throw '不存在对应计价规则';
|
|
|
+ }
|
|
|
+ const newValuation = {
|
|
|
+ ...orgValuation,
|
|
|
+ id: uuidV1(),
|
|
|
+ enable: false,
|
|
|
+ name: newName
|
|
|
+ };
|
|
|
+ await compilationModel.update({ _id: objectId }, { $push: { [valuationType]: newValuation } });
|
|
|
+ await this.copyEngineeringList(orgValuationID, newValuation.id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 拷贝工程专业
|
|
|
+ async copyEngineeringList(orgValuationID, newValuationID) {
|
|
|
+ const engineeringList = await engineeringModel.find({ valuationID: orgValuationID }, '-_id').lean();
|
|
|
+ console.log(engineeringList);
|
|
|
+ const newEngineeringList = engineeringList.map(item => ({ ...item, valuationID: newValuationID }));
|
|
|
+ if (newEngineeringList.length) {
|
|
|
+ await engineeringModel.insertMany(newEngineeringList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
export default CompilationModel;
|