Browse Source

fix: 广东信息价、重庆信息价地区排序

vian 4 years ago
parent
commit
5cb132f3f1

+ 1 - 0
modules/all_models/std_price_info_areas.js

@@ -3,6 +3,7 @@ const mongoose = require('mongoose');
 
 const Schema = mongoose.Schema;
 const priceInfoArea = new Schema({
+    serialNo: Number,
     ID: String,
     compilationID: String,
     name: String

+ 1 - 1
modules/price_info_lib/facade/index.js

@@ -333,7 +333,7 @@ async function importExcelData(libID, sheetData) {
 
 // 获取费用定额的地区数据
 async function getAreas(compilationID) {
-    return await priceInfoAreaModel.find({ compilationID }, '-_id ID name').lean();
+    return await priceInfoAreaModel.find({ compilationID }, '-_id ID name serialNo').lean();
 }
 
 async function updateAres(updateData) {

+ 3 - 0
web/maintain/price_info_lib/js/index.js

@@ -69,6 +69,9 @@ const AREA_BOOK = (() => {
     workBook.options.allowUserDragFill = true;
     const sheet = workBook.getSheet(0);
 
+    // 排序显示
+    cache.sort((a, b) => a.serialNo - b.serialNo);
+
     // 显示数据
     showData(sheet, cache, setting.header);
 

+ 91 - 2
web/over_write/crawler/chongqing_2018_price_crawler.js

@@ -30,6 +30,70 @@ function debugConsole(str, type = 'log') {
     }
 }
 
+const areas = [
+    '主城区',
+    '渝中区',
+    '江北区',
+    '沙坪坝区',
+    '南岸区',
+    '九龙坡区',
+    '大渡口区',
+    '北碚区',
+    '渝北区',
+    '巴南区',
+    '万州区',
+    '涪陵区',
+    '万盛区',
+    '双桥区',
+    '黔江区',
+    '长寿区',
+    '江津区',
+    '合川区',
+    '永川区',
+    '南川区',
+    '綦江县',
+    '潼南县',
+    '铜梁县',
+    '大足县',
+    '荣昌县',
+    '璧山县',
+    '梁平区',
+    '城口县',
+    '丰都县',
+    '垫江县',
+    '忠县',
+    '开州区',
+    '云阳县',
+    '奉节县',
+    '巫山县',
+    '巫溪县',
+    '石柱县',
+    '秀山县',
+    '酉阳县',
+    '彭水县',
+    '大足区',
+    '綦江区',
+    '万盛经开区',
+    '双桥经开区',
+    '铜梁区',
+    '璧山区',
+    '荣昌县1',
+    '荣昌县2',
+    '彭水县1',
+    '彭水县2',
+    '彭水县3',
+    '潼南区',
+    '荣昌区1',
+    '荣昌区2',
+    '武隆区',
+    '武隆区1',
+    '武隆区2',
+    '武隆区3',
+    '武隆区4',
+    '武隆区5',
+    '武隆区6',
+];
+
 // 页面类型
 const PageType = {
     GENERAL: '/Index.aspx',
@@ -710,6 +774,10 @@ async function transfromGeneralData(period, compilationID, generalData) {
     const area = '通用';
     // 爬取数据的时候,地区数据先匹配名称,如果费用定额已有此地区,不新增
     const matchedArea = await priceInfoAreaModel.findOne({ compilationID, name: area }).lean();
+    // 地区需要serialNo字段,打补丁
+    if (matchedArea && !matchedArea.serialNo) {
+        await priceInfoAreaModel.update({ ID: matchedArea.ID }, { $set: { serialNo: 1 } });
+    }
     const areaID = matchedArea && matchedArea.ID || uuidV1();
     const compilationAreas = [];
     const libData = {
@@ -831,9 +899,14 @@ async function transformAreaData(period, compilationID, libData, areaData, mixed
     const priceData = [];
     for (const { area, subData } of data) {
         const matchedArea = await priceInfoAreaModel.findOne({ compilationID, name: area }).lean();
+        // 地区需要serialNo字段,打补丁
+        const serialNo = areas.indexOf(area) + 1;
+        if (matchedArea && !matchedArea.serialNo) {
+            await priceInfoAreaModel.update({ ID: matchedArea.ID }, { $set: { serialNo } });
+        }
         const areaID = matchedArea && matchedArea.ID || uuidV1();
         if (!matchedArea) {
-            compilationAreas.push({ compilationID, ID: areaID, name: area });
+            compilationAreas.push({ compilationID, serialNo, ID: areaID, name: area });
         }
         let preClass;
         subData.forEach(subItem => {
@@ -914,9 +987,10 @@ async function save(period, generalData, areaData, mixedData) {
  * 爬取数据
  * @param {String} from - 从哪一期开始 eg: 2020-01
  * @param {String} to - 从哪一期结束 eg: 2020-05
+ * @param {String} compilationID - 费用定额ID
  * @return {Object}
  */
-async function crawlData(from, to) {
+async function crawlData(from, to, compilationID) {
     let curPeriod;
     try {
         const $index = await loadPage(PageType.GENERAL);
@@ -924,6 +998,21 @@ async function crawlData(from, to) {
         if (!periodData) {
             throw '无效的期数区间。';
         }
+        // 地区补丁
+        const areaData = await priceInfoAreaModel.find({ compilationID, serialNo: null }).lean();
+        const bulks = [];
+        areaData.forEach(areaItem => {
+            const serialNo = areas.indexOf(areaItem.name) + 1;
+            bulks.push({
+                updateOne: {
+                    filter: { ID: areaItem.ID },
+                    update: { serialNo }
+                }
+            });
+        });
+        if (bulks.length) {
+            await priceInfoAreaModel.bulkWrite(bulks);
+        }
         // 一期一期爬取数据
         debugConsole('allTime', 'time');
         for (const periodItem of periodData) {

+ 15 - 9
web/over_write/crawler/guangdong_2018_price_crawler.js

@@ -278,17 +278,12 @@ async function getClassNameMap(compilationID) {
  * 将信息价源数据转换入库
  * @param {String} compilationID - 费用定额ID
  * @param {String} period - 期数 eg: 2020年-09月
- * @param {String} area - 地区 eg: 广州市-广州市
+ * @param {String} areaID - 地区ID
  * @param {Array} sourceData - 造价通源数据
  * @param {Object} classNameMap - 从标准人材机分类树获取的编号-名称映射表
  * @return {Void}
  */
-async function saveData(compilationID, period, area, sourceData, classNameMap) {
-  let areaItem = await priceInfoAreaModel.findOne({ compilationID, name: area }).lean();
-  if (!areaItem) {
-    areaItem = { compilationID, ID: uuidV1(), name: area };
-    await priceInfoAreaModel.insertMany([areaItem]);
-  }
+async function saveData(compilationID, period, areaID, sourceData, classNameMap) {
   let lib = await priceInfoLibModel.findOne({ compilationID, period }).lean();
   if (!lib) {
     lib = {
@@ -300,7 +295,6 @@ async function saveData(compilationID, period, area, sourceData, classNameMap) {
     };
     await priceInfoLibModel.insertMany([lib]);
   }
-  const areaID = areaItem.ID;
   const libID = lib.ID;
   // 如果该期数该地区下存在数据,则不处理,防止重复插入数据
   // 造价通地区数据更新不同步,可能需要多次导入数据补全一期数据,如果已经有数据,说明该地区已经导入成功过了,直接跳过
@@ -398,7 +392,19 @@ async function crawlData(from, to, compilationID) {
   const hintInfos = [];
   for (const period of periods) {
     const sourcePeriod = period.replace(/年|月/g, '');
-    for (const { city, county } of areas) {
+    for (let i = 0; i < areas.length; i++) {
+      // 存入地区
+      const { city, county } = areas[i];
+      const area = `${city}-${county}`;
+      let areaItem = await priceInfoAreaModel.findOne({ compilationID, name: area }).lean();
+      const serialNo = i + 1;
+      if (!areaItem) {
+        areaItem = { compilationID, serialNo, ID: uuidV1(), name: area };
+        await priceInfoAreaModel.insertMany([areaItem]);
+      } else if (!areaItem.serialNo) { // 需求变更,需要排序,旧数据可能没有排序字段,需要加上
+        await priceInfoAreaModel.update({ ID: areaItem.ID }, { $set: { serialNo } });
+      }
+      // 存入信息价相关数据
       const sourceData = await getPriceInfoSource(token, sourcePeriod, city, county);
       if (typeof sourceData === 'string') {
         hintInfos.push(sourceData);