|
@@ -765,6 +765,7 @@ async function exportInfoPriceByCompilation(compilationID) {
|
|
|
|
|
|
// 批量修改同省份下所有相同材料(编号、名称、规格、单位)
|
|
|
async function batchUpdate(priceItem, prop, val) {
|
|
|
+ const date1 = Date.now();
|
|
|
const areas = await priceInfoAreaModel.find({ compilationID: priceItem.compilationID }, '-_id ID name').lean();
|
|
|
const area = areas.find(item => item.ID === priceItem.areaID);
|
|
|
if (!area || !area.name) {
|
|
@@ -778,24 +779,31 @@ async function batchUpdate(priceItem, prop, val) {
|
|
|
if (!sameProvinceAreas.length) {
|
|
|
return;
|
|
|
}
|
|
|
+ console.log('1', date1);
|
|
|
+ const date2 = Date.now();
|
|
|
const areaIDs = sameProvinceAreas.map(item => item.ID);
|
|
|
// 根据编号初筛
|
|
|
const priceItems = await priceInfoItemModel.find({ libID: priceItem.libID, code: priceItem.code || '' }, '-_id ID areaID code name specs unit').lean();
|
|
|
+ const date3 = Date.now();
|
|
|
+ console.log('2', date3 - date2);
|
|
|
// 批量修改相同材料
|
|
|
- const bulks = [];
|
|
|
+ // const bulks = [];
|
|
|
const getKey = (item) => {
|
|
|
return `${item.code || ''}@${item.name || ''}@${item.specs || ''}@${item.unit || ''}`;
|
|
|
}
|
|
|
const key = getKey(priceItem);
|
|
|
+ const updateIDs = [];
|
|
|
priceItems.forEach(item => {
|
|
|
if (areaIDs.includes(item.areaID) && getKey(item) === key) {
|
|
|
- bulks.push({ updateOne: { filter: { ID: item.ID }, update: { $set: { [prop]: val } } } });
|
|
|
+ updateIDs.push(item.ID);
|
|
|
+ // bulks.push({ updateOne: { filter: { ID: item.ID }, update: { $set: { [prop]: val } } } });
|
|
|
}
|
|
|
});
|
|
|
- if (bulks.length) {
|
|
|
- await priceInfoItemModel.bulkWrite(bulks);
|
|
|
+ if (updateIDs.length) {
|
|
|
+ await priceInfoItemModel.updateMany({ ID: { $in: updateIDs } }, { $set: { [prop]: val } });
|
|
|
}
|
|
|
-
|
|
|
+ const date4 = Date.now();
|
|
|
+ console.log('3', date4 - date3);
|
|
|
|
|
|
|
|
|
}
|