|
@@ -186,26 +186,30 @@ async function importExcelData(libID, sheetData) {
|
|
|
let curAreaName;
|
|
|
let curClassName;
|
|
|
let curClassID;
|
|
|
+ const areaIDSet = new Set();
|
|
|
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] ? sheetData[row][colMap.code].trim() : '';
|
|
|
- const name = sheetData[row][colMap.name] ? sheetData[row][colMap.name].trim() : '';
|
|
|
- const specs = sheetData[row][colMap.specs] ? sheetData[row][colMap.specs].trim() : '';
|
|
|
- const unit = sheetData[row][colMap.unit] ? sheetData[row][colMap.unit].trim() : '';
|
|
|
- const noTaxPrice = sheetData[row][colMap.noTaxPrice] ? sheetData[row][colMap.noTaxPrice].trim() : '';
|
|
|
- const taxPrice = sheetData[row][colMap.taxPrice] ? sheetData[row][colMap.taxPrice].trim() : '';
|
|
|
+ const areaName = sheetData[row][colMap.area] ? String(sheetData[row][colMap.area]).trim() : '';
|
|
|
+ const className = sheetData[row][colMap.class] ? String(sheetData[row][colMap.class]).trim() : '';
|
|
|
+ const code = sheetData[row][colMap.code] ? String(sheetData[row][colMap.code]).trim() : '';
|
|
|
+ const name = sheetData[row][colMap.name] ? String(sheetData[row][colMap.name]).trim() : '';
|
|
|
+ const specs = sheetData[row][colMap.specs] ? String(sheetData[row][colMap.specs]).trim() : '';
|
|
|
+ const unit = sheetData[row][colMap.unit] ? String(sheetData[row][colMap.unit]).trim() : '';
|
|
|
+ const noTaxPrice = sheetData[row][colMap.noTaxPrice] ? String(sheetData[row][colMap.noTaxPrice]).trim() : '';
|
|
|
+ const taxPrice = sheetData[row][colMap.taxPrice] ? String(sheetData[row][colMap.taxPrice]).trim() : '';
|
|
|
if (!className && !code && !name && !specs && !noTaxPrice && !taxPrice) { // 认为是空数据
|
|
|
continue;
|
|
|
}
|
|
|
+ let areaChange = false;
|
|
|
if (areaName && areaName !== curAreaName) {
|
|
|
curAreaName = areaName;
|
|
|
+ areaChange = true;
|
|
|
}
|
|
|
const areaID = areaMap[curAreaName];
|
|
|
if (!areaID) {
|
|
|
continue;
|
|
|
}
|
|
|
- if (className && className !== curClassName) {
|
|
|
+ areaIDSet.add(areaID);
|
|
|
+ if ((className && className !== curClassName) || areaChange) {
|
|
|
curClassName = className;
|
|
|
const classItem = {
|
|
|
libID,
|
|
@@ -241,12 +245,13 @@ async function importExcelData(libID, sheetData) {
|
|
|
taxPrice
|
|
|
});
|
|
|
}
|
|
|
+ const areaIDs = [...areaIDSet]
|
|
|
if (classData.length) {
|
|
|
- await priceInfoClassModel.remove({ libID });
|
|
|
+ await priceInfoClassModel.remove({ libID, areaID: { $in: areaIDs } });
|
|
|
await priceInfoClassModel.insertMany(classData);
|
|
|
}
|
|
|
if (data.length) {
|
|
|
- await priceInfoItemModel.remove({ libID });
|
|
|
+ await priceInfoItemModel.remove({ libID, areaID: { $in: areaIDs } });
|
|
|
await priceInfoItemModel.insertMany(data);
|
|
|
} else {
|
|
|
throw 'excel没有有效数据。'
|