|
@@ -231,6 +231,85 @@ async function importExcelData(libID, sheetData) {
|
|
|
throw 'excel没有有效数据。'
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// 导入excel关键字数据(主表+副表),目前只针对珠海,根据列号导入
|
|
|
+/*
|
|
|
+主表:主从对应码 别名编码 材料名称 规格 单位 含税价(元) 除税价(元) 月份备注 计算式
|
|
|
+副表:主从对应码 关键字 单位 关键字效果 组别 选项号
|
|
|
+ */
|
|
|
+async function importKeyData(libID, mainData, subData) {
|
|
|
+ const lib = await priceInfoLibModel.findOne({ ID: libID }).lean();
|
|
|
+ if (!lib) {
|
|
|
+ throw new Error('库不存在');
|
|
|
+ }
|
|
|
+ const zh = await priceInfoAreaModel.findOne({ name: { $regex: '珠海' } }).lean();
|
|
|
+ if (!zh) {
|
|
|
+ throw new Error('该库不存在珠海地区');
|
|
|
+ }
|
|
|
+ // 删除珠海地区所有材料
|
|
|
+ await priceInfoItemModel.deleteMany({ libID, areaID: zh.ID });
|
|
|
+
|
|
|
+ const classItems = await priceInfoClassModel.find({ libID, areaID: zh.ID }).lean();
|
|
|
+ // 分类树前四位编码 - 分类节点ID映射表
|
|
|
+ let otherClassID = '';
|
|
|
+ const classMap = {};
|
|
|
+ classItems.forEach(item => {
|
|
|
+ if (item.name) {
|
|
|
+ if (!otherClassID && /其他/.test(item.name)) {
|
|
|
+ otherClassID = item.ID;
|
|
|
+ }
|
|
|
+ const code = item.name.substr(0, 4);
|
|
|
+ if (/\d{4}/.test(code)) {
|
|
|
+ classMap[code] = item.ID;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 主从对应码 - 关键字数组映射
|
|
|
+ const keywordMap = {};
|
|
|
+ for (let row = 1; row < subData.length; row++) {
|
|
|
+ const rowData = subData[row];
|
|
|
+ const keywordItem = {
|
|
|
+ code: rowData[0] || '',
|
|
|
+ keyword: rowData[1] || '',
|
|
|
+ coe: rowData[3] || '',
|
|
|
+ group: rowData[4] || '',
|
|
|
+ optionCode: rowData[5] || '',
|
|
|
+ };
|
|
|
+ (keywordMap[keywordItem.code] || (keywordMap[keywordItem.code] = [])).push(keywordItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ const priceItems = [];
|
|
|
+ for (let row = 1; row < mainData.length; row++) {
|
|
|
+ const rowData = mainData[row];
|
|
|
+ const code = rowData[0] || '';
|
|
|
+ const matchCode = code.substr(0, 4);
|
|
|
+ const classID = classMap[matchCode] || otherClassID;
|
|
|
+ const priceItem = {
|
|
|
+ code,
|
|
|
+ libID,
|
|
|
+ classID,
|
|
|
+ ID: uuidV1(),
|
|
|
+ compilationID: lib.compilationID,
|
|
|
+ areaID: zh.ID,
|
|
|
+ period: lib.period,
|
|
|
+ classCode: rowData[1] || '',
|
|
|
+ name: rowData[2] || '',
|
|
|
+ specs: rowData[3] || '',
|
|
|
+ unit: rowData[4] || '',
|
|
|
+ taxPrice: rowData[5] || '',
|
|
|
+ noTaxPrice: rowData[6] || '',
|
|
|
+ dateRemark: rowData[7] || '',
|
|
|
+ expString: rowData[8] || '',
|
|
|
+ keywordList: keywordMap[code] || [],
|
|
|
+ }
|
|
|
+ priceItems.push(priceItem);
|
|
|
+ }
|
|
|
+ if (priceItems.length) {
|
|
|
+ await priceInfoItemModel.insertMany(priceItems);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/* async function importExcelData(libID, sheetData) {
|
|
|
const libs = await getLibs({ ID: libID });
|
|
|
const compilationID = libs[0].compilationID;
|
|
@@ -454,6 +533,7 @@ module.exports = {
|
|
|
processChecking,
|
|
|
crawlDataByCompilation,
|
|
|
importExcelData,
|
|
|
+ importKeyData,
|
|
|
getAreas,
|
|
|
updateAres,
|
|
|
insertAreas,
|