lintry

调整字段名

...@@ -66,10 +66,15 @@ module.exports = function (sequelize, DataTypes) { ...@@ -66,10 +66,15 @@ module.exports = function (sequelize, DataTypes) {
66 "comment": "更新时间", 66 "comment": "更新时间",
67 "field": "update_time" 67 "field": "update_time"
68 }, 68 },
69 - "country": { 69 + "country_name": {
70 "type": DataTypes.STRING(40), 70 "type": DataTypes.STRING(40),
71 "comment": "国家", 71 "comment": "国家",
72 - "field": "country" 72 + "field": "country_name"
73 + },
74 + "continent_name": {
75 + "type": DataTypes.STRING(40),
76 + "comment": "洲",
77 + "field": "continent_name"
73 } 78 }
74 }); 79 });
75 80
......
...@@ -37,55 +37,55 @@ module.exports = function (dbo) { ...@@ -37,55 +37,55 @@ module.exports = function (dbo) {
37 ) 37 )
38 , ta as ( 38 , ta as (
39 select * from ( 39 select * from (
40 - select country, province_short_name province, update_time::date, confirmed_count, 40 + select countryName, province_short_name province, update_time::date, confirmed_count,
41 - row_number() over(partition by country, province_short_name, update_time::date order by update_time desc) rn 41 + row_number() over(partition by countryName, province_short_name, update_time::date order by update_time desc) rn
42 from tb_mf_timeline_area 42 from tb_mf_timeline_area
43 ) t 43 ) t
44 where rn = 1 44 where rn = 1
45 ) 45 )
46 , stats as ( 46 , stats as (
47 - select country, ta.province, d.today, confirmed_count 47 + select countryName, ta.province, d.today, confirmed_count
48 from days d 48 from days d
49 left join ta on ta.update_time = d.today 49 left join ta on ta.update_time = d.today
50 - where country notnull 50 + where countryName notnull
51 order by 1,2,3 51 order by 1,2,3
52 ) 52 )
53 , pr as ( 53 , pr as (
54 - select country, province from stats group by 1,2 54 + select countryName, province from stats group by 1,2
55 ) 55 )
56 , dat as( 56 , dat as(
57 - 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 57 + 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
58 from pr 58 from pr
59 cross join days d 59 cross join days d
60 left join stats st on st.province = pr.province and st.today = d.today 60 left join stats st on st.province = pr.province and st.today = d.today
61 order by 1,2,3 61 order by 1,2,3
62 ) 62 )
63 , rpt as ( 63 , rpt as (
64 - select country, province, today, confirmed_count, confirmed_count - COALESCE(lag(confirmed_count) over(partition by country, province order by today), 0) increase 64 + select countryName, province, today, confirmed_count, confirmed_count - COALESCE(lag(confirmed_count) over(partition by countryName, province order by today), 0) increase
65 from dat 65 from dat
66 order by 1,2,3 66 order by 1,2,3
67 ) 67 )
68 , summ as ( 68 , summ as (
69 - select country, today, sum(confirmed_count) confirmed_sum, sum(increase) increase 69 + select countryName, today, sum(confirmed_count) confirmed_sum, sum(increase) increase
70 from rpt 70 from rpt
71 group by 1,2 71 group by 1,2
72 - order by country, confirmed_sum desc 72 + order by countryName, confirmed_sum desc
73 ) 73 )
74 - select country, province, max(confirmed_count) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_count order by today) confirmed_counts, 74 + select countryName, province, max(confirmed_count) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_count order by today) confirmed_counts,
75 jsonb_agg(increase order by today) increase, 75 jsonb_agg(increase order by today) increase,
76 max(confirmed_sum) confirmed_sum 76 max(confirmed_sum) confirmed_sum
77 - from ( select *, sum(confirmed_count) over(partition by country, today) confirmed_sum from rpt 77 + from ( select *, sum(confirmed_count) over(partition by countryName, today) confirmed_sum from rpt
78 where province ~ :province 78 where province ~ :province
79 ) t 79 ) t
80 group by 1,2 80 group by 1,2
81 union all 81 union all
82 - select country, '全国' province, max(confirmed_sum) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_sum order by today) confirmed_counts, 82 + select countryName, '全国' province, max(confirmed_sum) max_count, jsonb_agg(today order by today) days, jsonb_agg(confirmed_sum order by today) confirmed_counts,
83 jsonb_agg(increase order by today) increase, 83 jsonb_agg(increase order by today) increase,
84 max(confirmed_sum) 84 max(confirmed_sum)
85 from summ 85 from summ
86 - where country = '中国' 86 + where countryName = '中国'
87 group by 1 87 group by 1
88 - order by country, max_count desc 88 + order by countryName, max_count desc
89 `, {replacements: {province}, type: dbo.QueryTypes.SELECT}); 89 `, {replacements: {province}, type: dbo.QueryTypes.SELECT});
90 90
91 return Result.Ok('成功!', result); 91 return Result.Ok('成功!', result);
...@@ -111,12 +111,12 @@ module.exports = function (dbo) { ...@@ -111,12 +111,12 @@ module.exports = function (dbo) {
111 // 代码逻辑区域 111 // 代码逻辑区域
112 let result = await dbo.query(` 112 let result = await dbo.query(`
113 with t as ( 113 with t as (
114 - 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 114 + 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
115 from tb_mf_timeline_area 115 from tb_mf_timeline_area
116 where update_time::date = :date 116 where update_time::date = :date
117 and province_name ~ :province 117 and province_name ~ :province
118 ) 118 )
119 - select update_time, province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country 119 + select update_time, province, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, countryName
120 from t 120 from t
121 where rn = 1 121 where rn = 1
122 order by confirmed_count desc 122 order by confirmed_count desc
......
...@@ -26,7 +26,8 @@ class DataImporter { ...@@ -26,7 +26,8 @@ class DataImporter {
26 let areas = []; 26 let areas = [];
27 27
28 for (let row of json_data) { 28 for (let row of json_data) {
29 - let {provinceName, 29 + let {
30 + provinceName,
30 provinceShortName, 31 provinceShortName,
31 confirmedCount, 32 confirmedCount,
32 suspectedCount, 33 suspectedCount,
...@@ -35,7 +36,9 @@ class DataImporter { ...@@ -35,7 +36,9 @@ class DataImporter {
35 comment, 36 comment,
36 cities, 37 cities,
37 updateTime, 38 updateTime,
38 - country} = row; 39 + countryName,
40 + continentName
41 + } = row;
39 42
40 areas.push({ 43 areas.push({
41 id: uid.hash(updateTime, provinceName), 44 id: uid.hash(updateTime, provinceName),
...@@ -48,7 +51,8 @@ class DataImporter { ...@@ -48,7 +51,8 @@ class DataImporter {
48 comment, 51 comment,
49 cities, 52 cities,
50 update_time: updateTime, 53 update_time: updateTime,
51 - country 54 + country_name: countryName,
55 + continent_name: continentName
52 }) 56 })
53 } 57 }
54 58
...@@ -61,7 +65,7 @@ class DataImporter { ...@@ -61,7 +65,7 @@ class DataImporter {
61 logger.error('同步数据失败', json_data) 65 logger.error('同步数据失败', json_data)
62 throw new Error('同步数据失败'); 66 throw new Error('同步数据失败');
63 } 67 }
64 - await this.import_data(json_data.results||[]); 68 + await this.import_data(json_data.results || []);
65 } 69 }
66 } 70 }
67 71
......