|
@@ -119,6 +119,127 @@ async function importExcelData(libID, sheetData) {
|
|
|
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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 提取数据
|
|
|
+ const data = [];
|
|
|
+ const classData = [];
|
|
|
+ const areaClassDataMap = {};
|
|
|
+ let curAreaName;
|
|
|
+ let curClassName;
|
|
|
+ let curClassID;
|
|
|
+ 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 (!className && !code && !name && !specs && !noTaxPrice && !taxPrice) { // 认为是空数据
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (areaName && areaName !== curAreaName) {
|
|
|
+ curAreaName = areaName;
|
|
|
+ }
|
|
|
+ const areaID = areaMap[curAreaName];
|
|
|
+ if (!areaID) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (className && className !== curClassName) {
|
|
|
+ curClassName = className;
|
|
|
+ const classItem = {
|
|
|
+ libID,
|
|
|
+ areaID,
|
|
|
+ ID: uuidV1(),
|
|
|
+ ParentID: '-1',
|
|
|
+ NextSiblingID: '-1',
|
|
|
+ name: curClassName
|
|
|
+ };
|
|
|
+ curClassID = classItem.ID;
|
|
|
+ classData.push(classItem);
|
|
|
+ (areaClassDataMap[areaID] || (areaClassDataMap[areaID] = [])).push(classItem);
|
|
|
+ const preClassItem = areaClassDataMap[areaID][areaClassDataMap[areaID].length - 2];
|
|
|
+ if (preClassItem) {
|
|
|
+ preClassItem.NextSiblingID = classItem.ID;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!curClassID) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ data.push({
|
|
|
+ ID: uuidV1(),
|
|
|
+ compilationID,
|
|
|
+ libID,
|
|
|
+ areaID,
|
|
|
+ classID: curClassID,
|
|
|
+ period: libs[0].period,
|
|
|
+ code,
|
|
|
+ name,
|
|
|
+ specs,
|
|
|
+ unit,
|
|
|
+ noTaxPrice,
|
|
|
+ taxPrice
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (classData.length) {
|
|
|
+ await priceInfoClassModel.remove({ libID });
|
|
|
+ await priceInfoClassModel.insertMany(classData);
|
|
|
+ }
|
|
|
+ if (data.length) {
|
|
|
+ await priceInfoItemModel.remove({ libID });
|
|
|
+ await priceInfoItemModel.insertMany(data);
|
|
|
+ } else {
|
|
|
+ throw 'excel没有有效数据。'
|
|
|
+ }
|
|
|
+}
|
|
|
+/* 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 }) => {
|
|
@@ -207,7 +328,7 @@ async function importExcelData(libID, sheetData) {
|
|
|
} else {
|
|
|
throw 'excel没有有效数据。'
|
|
|
}
|
|
|
-}
|
|
|
+} */
|
|
|
|
|
|
// 获取费用定额的地区数据
|
|
|
async function getAreas(compilationID) {
|