|
@@ -11,7 +11,7 @@ const priceInfoAreaModel = mongoose.model('std_price_info_areas');
|
|
|
const compilationModel = mongoose.model('compilation');
|
|
|
const importLogsModel = mongoose.model('import_logs');
|
|
|
const priceInfoIndexModel = mongoose.model('std_price_info_index');
|
|
|
-
|
|
|
+const priceInfoSummaryModel = mongoose.model('std_price_info_summary');
|
|
|
|
|
|
|
|
|
async function getLibs(query) {
|
|
@@ -634,6 +634,65 @@ async function exportExcelData(libID, areaName) {
|
|
|
return excelData;
|
|
|
}
|
|
|
|
|
|
+const getMatchSummaryKey = (item) => {
|
|
|
+ const props = ['name', 'specs', 'unit'];
|
|
|
+ return props.map(prop => {
|
|
|
+ const subKey = item[prop] ? item[prop].trim() : '';
|
|
|
+ return subKey;
|
|
|
+ }).join('@');
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+const getSummaryMap = (items) => {
|
|
|
+ const map = {};
|
|
|
+ items.forEach(item => {
|
|
|
+ const key = getMatchSummaryKey(item);
|
|
|
+ map[key] = item;
|
|
|
+ });
|
|
|
+ return map;
|
|
|
+}
|
|
|
+
|
|
|
+// 匹配总表
|
|
|
+// 按规则匹配信息价的编码、别名编码、计算式(只匹配珠海建筑,要单独标记珠海地区);
|
|
|
+// 匹配规则:名称+规格型号+单位,与总表一致则自动填入编码、别名编码、计算式(珠海建筑);
|
|
|
+const matchSummary = async (compilationID, libID) => {
|
|
|
+ const updateBulks = [];
|
|
|
+ const areas = await priceInfoAreaModel.find({ compilationID }, '-_id ID name').lean();
|
|
|
+ const areaNameMap = {};
|
|
|
+ areas.forEach(area => {
|
|
|
+ areaNameMap[area.ID] = area.name;
|
|
|
+ });
|
|
|
+ const priceItems = await priceInfoItemModel.find({ libID }, '-_id ID compilationID name specs unit areaID period').lean();
|
|
|
+ const summaryItems = await priceInfoSummaryModel.find({}, '-_id ID name specs unit code classCode expString').lean();
|
|
|
+ const summaryMap = getSummaryMap(summaryItems);
|
|
|
+ priceItems.forEach(priceItem => {
|
|
|
+ const key = getMatchSummaryKey(priceItem);
|
|
|
+ const matched = summaryMap[key];
|
|
|
+ if (matched) {
|
|
|
+ const updateObj = {
|
|
|
+ code: matched.code,
|
|
|
+ classCode: matched.classCode,
|
|
|
+ }
|
|
|
+ console.log(matched);
|
|
|
+ console.log(updateObj);
|
|
|
+ const areaName = areaNameMap[priceItem.areaID];
|
|
|
+ if (/珠海/.test(areaName)) {
|
|
|
+ updateObj.expString = matched.expString;
|
|
|
+ }
|
|
|
+ updateBulks.push({
|
|
|
+ updateOne: {
|
|
|
+ filter: { ID: priceItem.ID, compilationID: priceItem.compilationID, areaID: priceItem.areaID, period: priceItem.period },
|
|
|
+ update: updateObj
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (updateBulks.length) {
|
|
|
+ console.log(`updateBulks.length`, updateBulks.length);
|
|
|
+ await priceInfoItemModel.bulkWrite(updateBulks);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
module.exports = {
|
|
|
getLibs,
|
|
|
createLib,
|
|
@@ -652,5 +711,6 @@ module.exports = {
|
|
|
getPriceData,
|
|
|
editPriceData,
|
|
|
editClassData,
|
|
|
- exportExcelData
|
|
|
+ exportExcelData,
|
|
|
+ matchSummary,
|
|
|
}
|