|
@@ -213,6 +213,54 @@ class UnitPriceModel extends BaseModel {
|
|
|
return result.ok !== undefined && result.ok === 1;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 复制单价文件数据
|
|
|
+ *
|
|
|
+ * @param {Number} currentUnitPriceId
|
|
|
+ * @param {Number} changeUnitPriceId
|
|
|
+ * @return {Promise}
|
|
|
+ */
|
|
|
+ async copyNotExist(currentUnitPriceId, changeUnitPriceId) {
|
|
|
+ let result = false;
|
|
|
+ // 首先查找原单价文件id下的数据
|
|
|
+ let currentUnitList = await this.findDataByCondition({unit_price_file_id: currentUnitPriceId}, null, false);
|
|
|
+ if (currentUnitList === null) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 过滤mongoose格式
|
|
|
+ currentUnitList = JSON.stringify(currentUnitList);
|
|
|
+ currentUnitList = JSON.parse(currentUnitList);
|
|
|
+
|
|
|
+ let codeList = [];
|
|
|
+ for (let tmp of currentUnitList) {
|
|
|
+ if (codeList.indexOf(tmp.code) >= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ codeList.push(tmp.code);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找即将更替的单价文件是否存在对应的工料机数据
|
|
|
+ let condition = {unit_price_file_id: changeUnitPriceId, code: {"$in": codeList}};
|
|
|
+ let targetUnitList = await this.findDataByCondition(condition, null, false, 'code');
|
|
|
+
|
|
|
+ // 如果没有重叠的数据则原有的数据都复制一份
|
|
|
+ let insertData = [];
|
|
|
+ for (let tmp of currentUnitList) {
|
|
|
+ if (targetUnitList !== null && targetUnitList[tmp.code] !== undefined) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 删除原有id信息
|
|
|
+ delete tmp._id;
|
|
|
+ delete tmp.id;
|
|
|
+ tmp.unit_price_file_id = changeUnitPriceId;
|
|
|
+ insertData.push(tmp);
|
|
|
+ }
|
|
|
+
|
|
|
+ return insertData.length > 0 ? this.add(currentUnitList) : true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
export default UnitPriceModel;
|