|
@@ -219,24 +219,73 @@ function getPeriodData(from, to) {
|
|
|
return periods;
|
|
|
}
|
|
|
|
|
|
-// 获取信息价期刊
|
|
|
+// 根据期刊数据,获取需要信息价接口需要的date
|
|
|
+function getDateForApi(journalList, period) {
|
|
|
+ const monthPeriod = `${period}-05`; // 月度
|
|
|
+ const matchMonth = journalList.find(dateItem => dateItem.date === monthPeriod);
|
|
|
+ if (matchMonth) {
|
|
|
+ return matchMonth.date;
|
|
|
+ }
|
|
|
+ // 没匹配到月度数据,去匹配季度
|
|
|
+ const month = period.split('-')[1];
|
|
|
+ let quaterDate;
|
|
|
+ if (['1', '2', '3'].includes(month)) {
|
|
|
+ quaterDate = '03-15';
|
|
|
+ } else if (['4', '5', '6'].includes(month)) {
|
|
|
+ quaterDate = '06-15';
|
|
|
+ } else if (['7', '8', '9'].includes(month)) {
|
|
|
+ quaterDate = '09-15';
|
|
|
+ } else if (['10', '11', '12'].includes(month)) {
|
|
|
+ quaterDate = '12-15';
|
|
|
+ }
|
|
|
+ const year = period.split('-')[0];
|
|
|
+ const matchQuater = journalList.find(dateItem => dateItem.date === `${year}-${quaterDate}`);
|
|
|
+ if (matchQuater) {
|
|
|
+ return matchQuater.date;
|
|
|
+ }
|
|
|
+ // 没匹配到季度数据,去匹配半年数据
|
|
|
+ if (month / 6 <= 1 ) {
|
|
|
+ const firstHalfYear = journalList.find(dateItem => dateItem.date === `${year}-06-25`);
|
|
|
+ if (firstHalfYear) {
|
|
|
+ return firstHalfYear.date;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (month /6 > 1) {
|
|
|
+ const secondHalfYear = journalList.find(dateItem => dateItem.date === `${year}-12-25`);
|
|
|
+ if (secondHalfYear) {
|
|
|
+ return secondHalfYear.date;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 匹配全年数据
|
|
|
+ const fullYear = journalList.find(dateItem => dateItem.date === `${year}-12-30`);
|
|
|
+ if (fullYear) {
|
|
|
+ return fullYear;
|
|
|
+ }
|
|
|
+ return monthPeriod;
|
|
|
+}
|
|
|
+
|
|
|
+// 获取信息价
|
|
|
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();
|
|
|
+ /* const existData = await priceInfoSourceModel.find({ period, area, industry }).lean();
|
|
|
if (existData.length) {
|
|
|
return existData;
|
|
|
- }
|
|
|
+ } */
|
|
|
const body = {
|
|
|
token,
|
|
|
province,
|
|
|
city,
|
|
|
county,
|
|
|
industry,
|
|
|
- date: `${period}-05` // 天数05表示请求月度数据
|
|
|
+ // date: `${period}-05` // 天数05表示请求月度数据
|
|
|
};
|
|
|
- const sourceData = await post('/gov/get', body);
|
|
|
+ // 获取期刊数据
|
|
|
+ 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`;
|
|
|
+ const sourceData = await post('/gov/get', { ...body, date });
|
|
|
if (!sourceData.results) {
|
|
|
// 不抛出错误,不同地区更新信息价期刊的时间不同,如果导入数据时,有地区没发布数据,直接跳过并提示
|
|
|
return `retCode: ${sourceData.retCode} ${sourceData.msg} (${period} ${city} ${county})`;
|
|
@@ -256,9 +305,9 @@ async function getPriceInfoSource(token, period, city, county) {
|
|
|
specs: item.spec,
|
|
|
remark: item.notes,
|
|
|
}));
|
|
|
- if (insertData.length) {
|
|
|
+ /* if (insertData.length) {
|
|
|
await priceInfoSourceModel.insertMany(insertData);
|
|
|
- }
|
|
|
+ } */
|
|
|
return insertData;
|
|
|
}
|
|
|
|