lintry

调整字段名

......@@ -66,10 +66,15 @@ module.exports = function (sequelize, DataTypes) {
"comment": "更新时间",
"field": "update_time"
},
"country": {
"country_name": {
"type": DataTypes.STRING(40),
"comment": "国家",
"field": "country"
"field": "country_name"
},
"continent_name": {
"type": DataTypes.STRING(40),
"comment": "洲",
"field": "continent_name"
}
});
......
......@@ -37,55 +37,55 @@ module.exports = function (dbo) {
)
, ta as (
select * from (
select country, province_short_name province, update_time::date, confirmed_count,
row_number() over(partition by country, province_short_name, update_time::date order by update_time desc) rn
select countryName, province_short_name province, update_time::date, confirmed_count,
row_number() over(partition by countryName, province_short_name, update_time::date order by update_time desc) rn
from tb_mf_timeline_area
) t
where rn = 1
)
, stats as (
select country, ta.province, d.today, confirmed_count
select countryName, ta.province, d.today, confirmed_count
from days d
left join ta on ta.update_time = d.today
where country notnull
where countryName notnull
order by 1,2,3
)
, pr as (
select country, province from stats group by 1,2
select countryName, province from stats group by 1,2
)
, dat as(
select pr.country, pr.province, d.today, COALESCE(st.confirmed_count, max(st.confirmed_count) over(partition by pr.province order by d.today)) confirmed_count
select pr.countryName, pr.province, d.today, COALESCE(st.confirmed_count, max(st.confirmed_count) over(partition by pr.province order by d.today)) confirmed_count
from pr
cross join days d
left join stats st on st.province = pr.province and st.today = d.today
order by 1,2,3
)
, rpt as (
select country, province, today, confirmed_count, confirmed_count - COALESCE(lag(confirmed_count) over(partition by country, province order by today), 0) increase
select countryName, province, today, confirmed_count, confirmed_count - COALESCE(lag(confirmed_count) over(partition by countryName, province order by today), 0) increase
from dat
order by 1,2,3
)
, summ as (
select country, today, sum(confirmed_count) confirmed_sum, sum(increase) increase
select countryName, today, sum(confirmed_count) confirmed_sum, sum(increase) increase
from rpt
group by 1,2
order by country, confirmed_sum desc
order by countryName, confirmed_sum desc
)
select country, province, max(confirmed_count) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_count order by today) confirmed_counts,
select countryName, province, max(confirmed_count) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_count order by today) confirmed_counts,
jsonb_agg(increase order by today) increase,
max(confirmed_sum) confirmed_sum
from ( select *, sum(confirmed_count) over(partition by country, today) confirmed_sum from rpt
from ( select *, sum(confirmed_count) over(partition by countryName, today) confirmed_sum from rpt
where province ~ :province
) t
group by 1,2
union all
select country, '全国' province, max(confirmed_sum) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_sum order by today) confirmed_counts,
select countryName, '全国' province, max(confirmed_sum) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_sum order by today) confirmed_counts,
jsonb_agg(increase order by today) increase,
max(confirmed_sum)
from summ
where country = '中国'
where countryName = '中国'
group by 1
order by country, max_count desc
order by countryName, max_count desc
`, {replacements: {province}, type: dbo.QueryTypes.SELECT});
return Result.Ok('成功!', result);
......@@ -111,12 +111,12 @@ module.exports = function (dbo) {
// 代码逻辑区域
let result = await dbo.query(`
with t as (
select update_time, province_short_name province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country, row_number() over(partition by province_short_name order by update_time desc) rn
select update_time, province_short_name province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, countryName, row_number() over(partition by province_short_name order by update_time desc) rn
from tb_mf_timeline_area
where update_time::date = :date
and province_name ~ :province
)
select update_time, province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country
select update_time, province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, countryName
from t
where rn = 1
order by confirmed_count desc
......
......@@ -26,7 +26,8 @@ class DataImporter {
let areas = [];
for (let row of json_data) {
let {provinceName,
let {
provinceName,
provinceShortName,
confirmedCount,
suspectedCount,
......@@ -35,7 +36,9 @@ class DataImporter {
comment,
cities,
updateTime,
country} = row;
countryName,
continentName
} = row;
areas.push({
id: uid.hash(updateTime, provinceName),
......@@ -48,7 +51,8 @@ class DataImporter {
comment,
cities,
update_time: updateTime,
country
country_name: countryName,
continent_name: continentName
})
}
......@@ -61,7 +65,7 @@ class DataImporter {
logger.error('同步数据失败', json_data)
throw new Error('同步数据失败');
}
await this.import_data(json_data.results||[]);
await this.import_data(json_data.results || []);
}
}
......