Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1fdcb65c
authored
Jan 08, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 优化数据看板性能和显示效果
parent
1d6b3282
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
16 deletions
+35
-16
controller/usedata.go
+2
-1
model/usedata.go
+7
-2
web/src/pages/Detail/index.js
+26
-13
No files found.
controller/usedata.go
View file @
1fdcb65c
...
@@ -10,7 +10,8 @@ import (
...
@@ -10,7 +10,8 @@ import (
func
GetAllQuotaDates
(
c
*
gin
.
Context
)
{
func
GetAllQuotaDates
(
c
*
gin
.
Context
)
{
startTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"start_timestamp"
),
10
,
64
)
startTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"start_timestamp"
),
10
,
64
)
endTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"end_timestamp"
),
10
,
64
)
endTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"end_timestamp"
),
10
,
64
)
dates
,
err
:=
model
.
GetAllQuotaDates
(
startTimestamp
,
endTimestamp
)
username
:=
c
.
Query
(
"username"
)
dates
,
err
:=
model
.
GetAllQuotaDates
(
startTimestamp
,
endTimestamp
,
username
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"success"
:
false
,
...
...
model/usedata.go
View file @
1fdcb65c
...
@@ -102,9 +102,14 @@ func GetQuotaDataByUserId(userId int, startTime int64, endTime int64) (quotaData
...
@@ -102,9 +102,14 @@ func GetQuotaDataByUserId(userId int, startTime int64, endTime int64) (quotaData
return
quotaDatas
,
err
return
quotaDatas
,
err
}
}
func
GetAllQuotaDates
(
startTime
int64
,
endTime
int64
)
(
quotaData
[]
*
QuotaData
,
err
error
)
{
func
GetAllQuotaDates
(
startTime
int64
,
endTime
int64
,
username
string
)
(
quotaData
[]
*
QuotaData
,
err
error
)
{
if
username
!=
""
{
return
GetQuotaDataByUsername
(
username
,
startTime
,
endTime
)
}
var
quotaDatas
[]
*
QuotaData
var
quotaDatas
[]
*
QuotaData
// 从quota_data表中查询数据
// 从quota_data表中查询数据
err
=
DB
.
Table
(
"quota_data"
)
.
Where
(
"created_at >= ? and created_at <= ?"
,
startTime
,
endTime
)
.
Find
(
&
quotaDatas
)
.
Error
// only select model_name, sum(count) as count, sum(quota) as quota, model_name, created_at from quota_data group by model_name, created_at;
//err = DB.Table("quota_data").Where("created_at >= ? and created_at <= ?", startTime, endTime).Find("aDatas).Error
err
=
DB
.
Table
(
"quota_data"
)
.
Select
(
"model_name, sum(count) as count, sum(quota) as quota, created_at"
)
.
Where
(
"created_at >= ? and created_at <= ?"
,
startTime
,
endTime
)
.
Group
(
"model_name, created_at"
)
.
Find
(
&
quotaDatas
)
.
Error
return
quotaDatas
,
err
return
quotaDatas
,
err
}
}
web/src/pages/Detail/index.js
View file @
1fdcb65c
...
@@ -72,9 +72,18 @@ const Detail = (props) => {
...
@@ -72,9 +72,18 @@ const Detail = (props) => {
content
:
[
content
:
[
{
{
key
:
datum
=>
datum
[
'Model'
],
key
:
datum
=>
datum
[
'Model'
],
value
:
datum
=>
renderQuotaNumberWithDigit
(
datum
[
'Usage'
],
4
)
value
:
datum
=>
datum
[
'Usage'
]
}
],
updateContent
:
array
=>
{
// sort by value
array
.
sort
((
a
,
b
)
=>
b
.
value
-
a
.
value
);
// add $
for
(
let
i
=
0
;
i
<
array
.
length
;
i
++
)
{
array
[
i
].
value
=
renderQuotaNumberWithDigit
(
array
[
i
].
value
,
4
);
}
return
array
;
}
}
]
}
}
}
}
};
};
...
@@ -86,7 +95,6 @@ const Detail = (props) => {
...
@@ -86,7 +95,6 @@ const Detail = (props) => {
id
:
'id0'
,
id
:
'id0'
,
values
:
[
values
:
[
{
type
:
'null'
,
value
:
'0'
},
{
type
:
'null'
,
value
:
'0'
},
{
type
:
'null'
,
value
:
'0'
},
]
]
}
}
],
],
...
@@ -151,7 +159,12 @@ const Detail = (props) => {
...
@@ -151,7 +159,12 @@ const Detail = (props) => {
if
(
success
)
{
if
(
success
)
{
setQuotaData
(
data
);
setQuotaData
(
data
);
if
(
data
.
length
===
0
)
{
if
(
data
.
length
===
0
)
{
return
;
data
.
push
({
'count'
:
0
,
'model_name'
:
'无数据'
,
'quota'
:
0
,
'created_at'
:
now
.
getTime
()
/
1000
})
}
}
updateChart
(
lineChart
,
pieChart
,
data
);
updateChart
(
lineChart
,
pieChart
,
data
);
}
else
{
}
else
{
...
@@ -169,13 +182,13 @@ const Detail = (props) => {
...
@@ -169,13 +182,13 @@ const Detail = (props) => {
if
(
!
modelDataChart
)
{
if
(
!
modelDataChart
)
{
lineChart
=
new
VChart
(
spec_line
,
{
dom
:
'model_data'
});
lineChart
=
new
VChart
(
spec_line
,
{
dom
:
'model_data'
});
setModelDataChart
(
lineChart
);
setModelDataChart
(
lineChart
);
await
lineChart
.
renderAsync
();
lineChart
.
renderAsync
();
}
}
let
pieChart
=
modelDataPieChart
let
pieChart
=
modelDataPieChart
if
(
!
modelDataPieChart
)
{
if
(
!
modelDataPieChart
)
{
pieChart
=
new
VChart
(
spec_pie
,
{
dom
:
'model_pie'
});
pieChart
=
new
VChart
(
spec_pie
,
{
dom
:
'model_pie'
});
setModelDataPieChart
(
pieChart
);
setModelDataPieChart
(
pieChart
);
await
pieChart
.
renderAsync
();
pieChart
.
renderAsync
();
}
}
console
.
log
(
'init vchart'
);
console
.
log
(
'init vchart'
);
await
loadQuotaData
(
lineChart
,
pieChart
)
await
loadQuotaData
(
lineChart
,
pieChart
)
...
@@ -248,13 +261,13 @@ const Detail = (props) => {
...
@@ -248,13 +261,13 @@ const Detail = (props) => {
value
=
{
end_timestamp
}
type
=
'dateTime'
value
=
{
end_timestamp
}
type
=
'dateTime'
name
=
'end_timestamp'
name
=
'end_timestamp'
onChange
=
{
value
=>
handleInputChange
(
value
,
'end_timestamp'
)}
/
>
onChange
=
{
value
=>
handleInputChange
(
value
,
'end_timestamp'
)}
/
>
{
/*{*/
}
{
{
/* isAdminUser && <>*/
}
isAdminUser
&&
<>
{
/* <Form.Input field="username" label='用户名称' style={{width: 176}} value={username}*/
}
<
Form
.
Input
field
=
"username"
label
=
'用户名称'
style
=
{{
width
:
176
}}
value
=
{
username
}
{
/* placeholder={'可选值'} name='username'*/
}
placeholder
=
{
'可选值'
}
name
=
'username'
{
/* onChange={value => handleInputChange(value, 'username')}/>*/
}
onChange
=
{
value
=>
handleInputChange
(
value
,
'username'
)}
/
>
{
/* </>*/
}
<
/
>
{
/*}*/
}
}
<
Form
.
Section
>
<
Form
.
Section
>
<
Button
label
=
'查询'
type
=
"primary"
htmlType
=
"submit"
className
=
"btn-margin-right"
<
Button
label
=
'查询'
type
=
"primary"
htmlType
=
"submit"
className
=
"btn-margin-right"
onClick
=
{
refresh
}
loading
=
{
loading
}
>
查询
<
/Button
>
onClick
=
{
refresh
}
loading
=
{
loading
}
>
查询
<
/Button
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment