|
@@ -16,7 +16,7 @@ const { getWordArray, alias } = require('../../../public/cut_word/segmentit');
|
|
|
|
|
|
|
|
|
async function getLibs(query) {
|
|
|
- return await priceInfoLibModel.find(query).lean();
|
|
|
+ return await priceInfoLibModel.find(query).sort({ period: 1 }).lean();
|
|
|
}
|
|
|
|
|
|
async function createLib(name, period, compilationID) {
|
|
@@ -323,107 +323,6 @@ async function importKeyData(libID, 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;
|
|
|
- }
|
|
|
- }
|
|
|
- // 提取数据
|
|
|
- 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) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- data.push({
|
|
|
- ID: uuidV1(),
|
|
|
- compilationID,
|
|
|
- libID,
|
|
|
- areaID,
|
|
|
- classID,
|
|
|
- period: libs[0].period,
|
|
|
- code,
|
|
|
- name,
|
|
|
- specs,
|
|
|
- unit,
|
|
|
- noTaxPrice,
|
|
|
- taxPrice
|
|
|
- });
|
|
|
- }
|
|
|
- if (data.length) {
|
|
|
- await priceInfoItemModel.remove({ libID });
|
|
|
- await priceInfoItemModel.insertMany(data);
|
|
|
- } else {
|
|
|
- throw 'excel没有有效数据。'
|
|
|
- }
|
|
|
-} */
|
|
|
-
|
|
|
// 获取费用定额的地区数据
|
|
|
async function getAreas(compilationID) {
|
|
|
return await priceInfoAreaModel.find({ compilationID }, '-_id ID name serialNo').lean();
|
|
@@ -765,6 +664,55 @@ const getRecommendPriceSummaryData = async (keyword) => {
|
|
|
return items;
|
|
|
}
|
|
|
|
|
|
+// 处理价格¥符号
|
|
|
+/* const handlePriceText = async () => {
|
|
|
+ const libs = await priceInfoLibModel.find({}).lean();
|
|
|
+ for (const lib of libs) {
|
|
|
+ const libID = lib.ID;
|
|
|
+ const bulks = [];
|
|
|
+ const items = await priceInfoItemModel.find({ libID }, '-_id ID noTaxPrice areaID period').lean();
|
|
|
+ items.forEach(item => {
|
|
|
+ if (item.noTaxPrice && /¥/.test(item.noTaxPrice)) {
|
|
|
+ const noTaxPrice = item.noTaxPrice.replace('¥', '').replace(',', '');
|
|
|
+ bulks.push({ updateOne: { filter: { ID: item.ID, areaID: item.areaID, period: item.period }, update: { $set: { noTaxPrice } } } });
|
|
|
+ // bulks.push({ deleteOne: { filter: { ID: item.ID, areaID: item.areaID, period: item.period } } });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (bulks.length) {
|
|
|
+ const chunks = _.chunk(bulks, Math.floor(bulks.length / 500) + 1);
|
|
|
+ for (const chunk of chunks) {
|
|
|
+
|
|
|
+ if (chunk.length) {
|
|
|
+ await priceInfoItemModel.bulkWrite(chunk);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+} */
|
|
|
+
|
|
|
+// 删除价格为空的
|
|
|
+const handlePriceText = async () => {
|
|
|
+ const libs = await priceInfoLibModel.find({}).lean();
|
|
|
+ for (const lib of libs) {
|
|
|
+ const libID = lib.ID;
|
|
|
+ const bulks = [];
|
|
|
+ const items = await priceInfoItemModel.find({ libID }, '-_id ID noTaxPrice areaID period').lean();
|
|
|
+ items.forEach(item => {
|
|
|
+ if (!item.noTaxPrice) {
|
|
|
+ bulks.push({ deleteOne: { filter: { ID: item.ID, areaID: item.areaID, period: item.period } } });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (bulks.length) {
|
|
|
+ const chunks = _.chunk(bulks, Math.floor(bulks.length / 500) + 1);
|
|
|
+ for (const chunk of chunks) {
|
|
|
+ if (chunk.length) {
|
|
|
+ await priceInfoItemModel.bulkWrite(chunk);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
module.exports = {
|
|
|
getLibs,
|
|
|
createLib,
|
|
@@ -786,4 +734,5 @@ module.exports = {
|
|
|
matchSummary,
|
|
|
getPriceEmptyData,
|
|
|
getRecommendPriceSummaryData,
|
|
|
+ handlePriceText,
|
|
|
}
|