Pārlūkot izejas kodu

feat: 广东信息价,减少接口次数消耗

vian 4 gadi atpakaļ
vecāks
revīzija
daf3e6a4b5

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

@@ -265,7 +265,7 @@ function getDateForApi(journalList, period) {
   if (fullYear) {
     return fullYear;
   }
-  return monthPeriod;
+  return null;
 }
 
 // 获取信息价
@@ -273,10 +273,6 @@ async function getPriceInfoSource(token, period, city, county) {
   const province = '广东';
   const area = `${province}-${city}-${county}`;
   const industry = 1;
-  /* const existData = await priceInfoSourceModel.find({ period, area, industry }).lean();
-  if (existData.length) {
-    return existData;
-  } */
   const body = {
     token,
     province,
@@ -288,7 +284,14 @@ async function getPriceInfoSource(token, period, city, county) {
   // 获取期刊数据
   const year = period.split('-')[0];
   const journalRst = await post('/gov/journal_list', { ...body, date: year });
-  const date = journalRst && journalRst.results ? getDateForApi(journalRst.results, period) : `${period}-05`;
+  if (!journalRst || !journalRst.results) {
+    // 不抛出错误,不同地区更新信息价期刊的时间不同,如果导入数据时,有地区没发布数据,直接跳过并提示
+    return `retCode: ${journalRst.retCode} ${journalRst.msg} (${period} ${city} ${county})`;
+  }
+  const date = getDateForApi(journalRst.results, period);
+  if (!date) {
+    return `retCode: 1000 暂无数据 (${period} ${city} ${county})`;
+  }
   const sourceData = await post('/gov/get', { ...body, date });
   if (!sourceData.results) {
     // 不抛出错误,不同地区更新信息价期刊的时间不同,如果导入数据时,有地区没发布数据,直接跳过并提示