|
@@ -242,7 +242,7 @@ async function importExcelData(libID, sheetData) {
|
|
主表:主从对应码 别名编码 材料名称 规格 单位 含税价(元) 除税价(元) 月份备注 计算式
|
|
主表:主从对应码 别名编码 材料名称 规格 单位 含税价(元) 除税价(元) 月份备注 计算式
|
|
副表:主从对应码 关键字 单位 关键字效果 组别 选项号
|
|
副表:主从对应码 关键字 单位 关键字效果 组别 选项号
|
|
*/
|
|
*/
|
|
-async function importKeyData(libID, areaID, mainData, subData) {
|
|
|
|
|
|
+async function importMainSubData(libID, areaID, mainData, subData) {
|
|
const lib = await priceInfoLibModel.findOne({ ID: libID }).lean();
|
|
const lib = await priceInfoLibModel.findOne({ ID: libID }).lean();
|
|
if (!lib) {
|
|
if (!lib) {
|
|
throw new Error('库不存在');
|
|
throw new Error('库不存在');
|
|
@@ -326,106 +326,51 @@ async function importKeyData(libID, areaID, mainData, subData) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-/* async function importExcelData(libID, sheetData) {
|
|
|
|
- const libs = await getLibs({ ID: libID });
|
|
|
|
- const compilationID = libs[0].compilationID;
|
|
|
|
- // 建立区映射表:名称-ID映射、ID-名称映射
|
|
|
|
- const areaList = await getAreas(compilationID);
|
|
|
|
- const areaMap = {};
|
|
|
|
- areaList.forEach(({ ID, name }) => {
|
|
|
|
- areaMap[name] = ID;
|
|
|
|
- areaMap[ID] = name;
|
|
|
|
- });
|
|
|
|
- // 建立分类映射表:地区名称@分类名称:ID映射
|
|
|
|
- const classMap = {};
|
|
|
|
- const classList = await getClassData(libID);
|
|
|
|
- classList.forEach(({ ID, areaID, name }) => {
|
|
|
|
- const areaName = areaMap[areaID] || '';
|
|
|
|
- classMap[`${areaName}@${name}`] = ID;
|
|
|
|
- });
|
|
|
|
- // 第一行获取行映射
|
|
|
|
- const colMap = {};
|
|
|
|
- for (let col = 0; col < sheetData[0].length; col++) {
|
|
|
|
- const cellText = sheetData[0][col];
|
|
|
|
- switch (cellText) {
|
|
|
|
- case '地区':
|
|
|
|
- colMap.area = col;
|
|
|
|
- break;
|
|
|
|
- case '分类':
|
|
|
|
- colMap.class = col;
|
|
|
|
- break;
|
|
|
|
- case '编码':
|
|
|
|
- colMap.code = col;
|
|
|
|
- break;
|
|
|
|
- case '名称':
|
|
|
|
- colMap.name = col;
|
|
|
|
- break;
|
|
|
|
- case '规格型号':
|
|
|
|
- colMap.specs = col;
|
|
|
|
- break;
|
|
|
|
- case '单位':
|
|
|
|
- colMap.unit = col;
|
|
|
|
- break;
|
|
|
|
- case '不含税价':
|
|
|
|
- colMap.noTaxPrice = col;
|
|
|
|
- break;
|
|
|
|
- case '含税价':
|
|
|
|
- colMap.taxPrice = col;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+// 仅导入关键字excel
|
|
|
|
+async function importKeyData(libID, areaID, subData) {
|
|
|
|
+ const lib = await priceInfoLibModel.findOne({ ID: libID }).lean();
|
|
|
|
+ if (!lib) {
|
|
|
|
+ throw new Error('库不存在');
|
|
}
|
|
}
|
|
- // 提取数据
|
|
|
|
- const data = [];
|
|
|
|
- let curAreaName;
|
|
|
|
- let curClassName;
|
|
|
|
- for (let row = 1; row < sheetData.length; row++) {
|
|
|
|
- const areaName = sheetData[row][colMap.area] || '';
|
|
|
|
- const className = sheetData[row][colMap.class] || '';
|
|
|
|
- const code = sheetData[row][colMap.code] || '';
|
|
|
|
- const name = sheetData[row][colMap.name] || '';
|
|
|
|
- const specs = sheetData[row][colMap.specs] || '';
|
|
|
|
- const unit = sheetData[row][colMap.unit] || '';
|
|
|
|
- const noTaxPrice = sheetData[row][colMap.noTaxPrice] || '';
|
|
|
|
- const taxPrice = sheetData[row][colMap.taxPrice] || '';
|
|
|
|
- if (!code && !name && !specs && !noTaxPrice && !taxPrice) { // 认为是空数据
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if (areaName && areaName !== curAreaName) {
|
|
|
|
- curAreaName = areaName;
|
|
|
|
- }
|
|
|
|
- if (className && className !== curClassName) {
|
|
|
|
- curClassName = className;
|
|
|
|
- }
|
|
|
|
- const areaID = areaMap[curAreaName];
|
|
|
|
- if (!areaID) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- const classID = classMap[`${curAreaName}@${curClassName}`];
|
|
|
|
- if (!classID) {
|
|
|
|
|
|
+ /* const zh = await priceInfoAreaModel.findOne({ name: { $regex: '珠海' } }).lean();
|
|
|
|
+ if (!zh) {
|
|
|
|
+ throw new Error('该库不存在珠海地区');
|
|
|
|
+ } */
|
|
|
|
+ const area = await priceInfoAreaModel.findOne({ ID: areaID }).lean();
|
|
|
|
+ if (!area) {
|
|
|
|
+ throw new Error('不存在该地区');
|
|
|
|
+ }
|
|
|
|
+ // 主从对应码 - 关键字数组映射
|
|
|
|
+ const keywordMap = {};
|
|
|
|
+ for (let row = 1; row < subData.length; row++) {
|
|
|
|
+ const rowData = subData[row];
|
|
|
|
+ const keywordItem = {
|
|
|
|
+ code: rowData[0] ? String(rowData[0]) : '',
|
|
|
|
+ keyword: rowData[1] || '',
|
|
|
|
+ unit: rowData[2] || '',
|
|
|
|
+ coe: rowData[3] || '',
|
|
|
|
+ group: rowData[4] || '',
|
|
|
|
+ optionCode: rowData[5] || '',
|
|
|
|
+ };
|
|
|
|
+ if (!keywordItem.code) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- data.push({
|
|
|
|
- ID: uuidV1(),
|
|
|
|
- compilationID,
|
|
|
|
- libID,
|
|
|
|
- areaID,
|
|
|
|
- classID,
|
|
|
|
- period: libs[0].period,
|
|
|
|
- code,
|
|
|
|
- name,
|
|
|
|
- specs,
|
|
|
|
- unit,
|
|
|
|
- noTaxPrice,
|
|
|
|
- taxPrice
|
|
|
|
- });
|
|
|
|
|
|
+ (keywordMap[keywordItem.code] || (keywordMap[keywordItem.code] = [])).push(keywordItem);
|
|
}
|
|
}
|
|
- if (data.length) {
|
|
|
|
- await priceInfoItemModel.remove({ libID });
|
|
|
|
- await priceInfoItemModel.insertMany(data);
|
|
|
|
- } else {
|
|
|
|
- throw 'excel没有有效数据。'
|
|
|
|
|
|
+
|
|
|
|
+ const priceItems = await priceInfoItemModel.find({ libID: lib.ID, areaID, period: lib.period, compilationID: lib.compilationID }).lean();
|
|
|
|
+
|
|
|
|
+ const bulks = [];
|
|
|
|
+ priceItems.forEach(item => {
|
|
|
|
+ if (item.code && keywordMap[item.code]) {
|
|
|
|
+ bulks.push({ updateOne: { filter: { ID: item.ID }, update: { $set: { keywordList: keywordMap[item.code] || [] } } } });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (bulks.length) {
|
|
|
|
+ await priceInfoItemModel.bulkWrite(bulks);
|
|
}
|
|
}
|
|
-} */
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
// 获取费用定额的地区数据
|
|
// 获取费用定额的地区数据
|
|
async function getAreas(compilationID) {
|
|
async function getAreas(compilationID) {
|
|
@@ -788,6 +733,7 @@ module.exports = {
|
|
processChecking,
|
|
processChecking,
|
|
crawlDataByCompilation,
|
|
crawlDataByCompilation,
|
|
importExcelData,
|
|
importExcelData,
|
|
|
|
+ importMainSubData,
|
|
importKeyData,
|
|
importKeyData,
|
|
getAreas,
|
|
getAreas,
|
|
updateAres,
|
|
updateAres,
|