Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ncov
/
back
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
lintry
2020-01-28 19:28:10 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
033feac2e2cfef7b782953d2a4997f768457a48b
033feac2
1 parent
762bf570
增加查询接口
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
127 additions
and
1 deletions
server/modules/UniqueId.js
server/routers/c/info_action.js
server/service/data_importer.js
server/modules/UniqueId.js
0 → 100644
View file @
033feac
/**
* UniqueId
* Created by lintry on 2018/8/14.
*/
const
crypto_utils
=
require
(
'kml-crypto-utils'
);
/**
* 唯一键值生成器
*/
class
UniqueId
{
constructor
(
join_char
)
{
this
.
join_char
=
join_char
||
'-'
;
}
/**
* 根据参数合成唯一ID
* @param args
* @returns {string}
*/
hash
(...
args
)
{
if
(
!
args
||
!
args
.
length
)
{
throw
new
Error
(
'参数不能为空'
);
}
let
keys
=
[];
args
.
forEach
(
arg
=>
{
if
(
Array
.
isArray
(
arg
))
{
keys
.
concat
(
arg
.
sort
());
}
else
{
keys
.
push
(
arg
);
}
});
return
crypto_utils
.
MD5
(
args
.
join
(
this
.
join_char
));
}
}
module
.
exports
=
UniqueId
;
\ No newline at end of file
server/routers/c/info_action.js
0 → 100644
View file @
033feac
/**
* info_action
* Created by lintry on 2020/1/28.
*/
"use strict"
;
module
.
exports
=
function
(
dbo
)
{
//api公共模块
const
_
=
require
(
'lodash'
),
po
=
global
.
po
,
Result
=
require
(
'kml-express-stage-lib'
).
Result
,
logger
=
global
.
loggers
.
system
,
redisDb
=
require
(
'../../init/redis-promisify'
),
moment
=
require
(
'moment'
);
/**
* 按日期统计
* @param req
* @returns {Promise<Result>}
*/
this
.
statGet
=
async
(
req
)
=>
{
try
{
// 获取数据
let
params
=
req
.
query
;
let
{
province_name
}
=
params
;
province_name
=
province_name
||
''
;
// 代码逻辑区域
let
result
=
await
dbo
.
query
(
`
with days as (
select generate_series('2020-01-24'::date, CURRENT_DATE, '1 days')::date today
)
select province_short_name, d.today, max(confirmed_count) confirmed_count
from days d
left join tb_mf_timeline_area ta on ta.update_time::date = d.today
where 1=1
and province_name ~ :province_name
group by 1,2
order by 2, 1
`
,
{
replacements
:
{
province_name
},
type
:
dbo
.
QueryTypes
.
SELECT
});
return
Result
.
Ok
(
'成功!'
,
result
);
}
catch
(
e
)
{
logger
.
error
(
'失败!'
,
e
);
return
Result
.
Error
(
'失败!'
,
e
.
message
);
}
};
/**
* 最新情况
* @param req
* @returns {Promise<Result>}
*/
this
.
latestGet
=
async
(
req
)
=>
{
try
{
// 获取数据
let
params
=
req
.
query
;
let
{
date
}
=
params
;
date
=
date
||
moment
().
format
(
'YYYY-MM-DD'
);
// 代码逻辑区域
let
result
=
await
dbo
.
query
(
`
with t as (
select update_time, province_short_name, 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
from tb_mf_timeline_area
where update_time::date = :date
)
select update_time, province_short_name, confirmed_count, suspected_count, cured_count, dead_count, "comment", cities, country
from t
where rn = 1
order by confirmed_count desc
`
,
{
replacements
:
{
date
},
type
:
dbo
.
QueryTypes
.
SELECT
});
return
Result
.
Ok
(
'成功!'
,
result
);
}
catch
(
e
)
{
logger
.
error
(
'失败!'
,
e
);
return
Result
.
Error
(
'失败!'
,
e
.
message
);
}
};
};
server/service/data_importer.js
View file @
033feac
...
...
@@ -7,6 +7,7 @@ const _ = require('lodash'),
logger
=
global
.
loggers
.
system
;
const
id_worker
=
require
(
'../modules/id_worker'
);
const
api_sdk
=
new
(
require
(
'kml-api-request'
))();
const
uid
=
new
(
require
(
'../modules/UniqueId'
))();
class
DataImporter
{
constructor
(
dbo
)
{
...
...
@@ -37,7 +38,7 @@ class DataImporter {
country
}
=
row
;
areas
.
push
({
id
:
id_worker
.
nextId
(
),
id
:
uid
.
hash
(
updateTime
,
provinceName
),
province_name
:
provinceName
,
province_short_name
:
provinceShortName
,
confirmed_count
:
confirmedCount
,
...
...
Please
register
or
login
to post a comment