Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33-pai
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
szh
chain33-pai
Commits
f8a4a973
Commit
f8a4a973
authored
May 08, 2020
by
szh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统计信息更新 增加历史表和info信息具体到字段
parent
fc1eb543
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
134 additions
and
6 deletions
+134
-6
main.go
cmd/api/main.go
+1
-1
main.go
main.go
+1
-1
raspDevHistory.go
models/raspDevHistory.go
+31
-0
raspDevList.go
models/raspDevList.go
+68
-0
process.go
pkg/app/process.go
+7
-1
util.go
pkg/util/util.go
+5
-0
pai.go
routers/api/v1/pai.go
+17
-2
pai.go
service/pai_service/pai.go
+4
-1
No files found.
cmd/api/main.go
View file @
f8a4a973
...
@@ -29,7 +29,7 @@ func init() {
...
@@ -29,7 +29,7 @@ func init() {
// @license.name MIT
// @license.name MIT
// @license.url https://chain33-pai/blob/master/LICENSE
// @license.url https://chain33-pai/blob/master/LICENSE
func
main
()
{
func
main
()
{
go
app
.
Corn
Clean
(
time
.
NewTicker
(
time
.
Hour
*
24
))
go
app
.
Corn
DayJob
(
time
.
NewTicker
(
time
.
Hour
*
24
))
go
app
.
CornData
(
time
.
NewTicker
(
time
.
Minute
*
5
))
go
app
.
CornData
(
time
.
NewTicker
(
time
.
Minute
*
5
))
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
routersInit
:=
routers
.
InitRouter
()
routersInit
:=
routers
.
InitRouter
()
...
...
main.go
View file @
f8a4a973
...
@@ -29,7 +29,7 @@ func init() {
...
@@ -29,7 +29,7 @@ func init() {
// @license.name MIT
// @license.name MIT
// @license.url https://chain33-pai/blob/master/LICENSE
// @license.url https://chain33-pai/blob/master/LICENSE
func
main
()
{
func
main
()
{
go
app
.
Corn
Clean
(
time
.
NewTicker
(
time
.
Hour
*
24
))
go
app
.
Corn
DayJob
(
time
.
NewTicker
(
time
.
Hour
*
24
))
go
app
.
CornData
(
time
.
NewTicker
(
time
.
Minute
*
5
))
go
app
.
CornData
(
time
.
NewTicker
(
time
.
Minute
*
5
))
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
gin
.
SetMode
(
setting
.
ServerSetting
.
RunMode
)
routersInit
:=
routers
.
InitRouter
()
routersInit
:=
routers
.
InitRouter
()
...
...
models/raspDevHistory.go
0 → 100644
View file @
f8a4a973
package
models
import
"chain33-pai/pkg/util"
type
RaspDevHistory
struct
{
//Model
Id
int64
`json:"id" gorm:"PRIMARY_KEY"`
Addr
string
`json:"addr"`
Info
string
`json:"info"`
Addtime
string
`json:"addtime"`
}
const
MonthDevHistoryTable
=
`
DROP TABLE IF EXISTS '?_rasp_miner_stat';
CREATE TABLE '?_rasp_dev_history' (
'id' bigint(20) NOT NULL AUTO_INCREMENT,
'addr' varchar(20) NOT NULL,
'info' text,
'addtime' varchar(32) DEFAULT NULL,
PRIMARY KEY ('id')
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COMMENT='上传历史'`
//
func
CreateMonthDevHistoryTable
()
error
{
date
:=
util
.
GetMonthDate
()
return
db
.
Raw
(
MonthDevHistoryTable
,
date
,
date
)
.
Error
}
func
AddDevHistory
(
rasp
*
RaspDevHistory
)
error
{
return
db
.
Create
(
rasp
)
.
Error
}
models/raspDevList.go
0 → 100644
View file @
f8a4a973
package
models
import
(
"chain33-pai/service/pai_service"
"encoding/json"
"time"
"strings"
)
type
RaspDevList
struct
{
Id
int64
`json:"id"`
Addr
string
`json:"addr"`
PaiVersion
string
`json:"pai_version"`
UpdateTime
int64
`json:"update_time"`
Height
int64
`json:"height"`
BtyVersion
string
`json:"bty_version"`
ExtIp
string
`json:"ext_ip"`
Error
string
`json:"error"`
WalletStatus
int32
`json:"wallet_status"`
NodeStatus
int32
`json:"node_status"`
PaiStatus
int32
`json:"pai_status"`
UserName
string
`json:"user_name"`
Email
string
`json:"email"`
Phone
string
`json:"phone"`
}
func
convertDevList
(
params
map
[
string
]
string
)
RaspDevList
{
var
pai
pai_service
.
Pai
var
rasp
RaspDevList
rasp
.
Addr
=
params
[
"addr"
]
rasp
.
PaiVersion
=
params
[
"version"
]
err
:=
json
.
Unmarshal
([]
byte
(
params
[
"info"
]),
&
pai
)
if
err
!=
nil
{
rasp
.
Error
=
err
.
Error
()
return
rasp
}
rasp
.
UpdateTime
=
time
.
Now
()
.
Unix
()
if
pai
.
Err
==
""
{
rasp
.
NodeStatus
=
1
rasp
.
Height
=
pai
.
LastHeight
if
!
pai
.
WalletStatus
.
IsTicketLock
{
rasp
.
WalletStatus
=
2
}
else
if
!
pai
.
WalletStatus
.
IsWalletLock
&&
pai
.
WalletStatus
.
IsTicketLock
{
rasp
.
WalletStatus
=
1
}
else
if
pai
.
WalletStatus
.
IsTicketLock
&&
pai
.
WalletStatus
.
IsWalletLock
{
rasp
.
WalletStatus
=
3
}
laddr
:=
strings
.
Split
(
pai
.
NetInfo
.
Externaladdr
,
":"
)
if
len
(
laddr
)
==
2
{
rasp
.
ExtIp
=
laddr
[
0
]
}
else
{
rasp
.
ExtIp
=
pai
.
NetInfo
.
Externaladdr
}
rasp
.
BtyVersion
=
pai
.
BtyVersion
.
App
}
return
rasp
}
func
UpdateDevList
(
params
map
[
string
]
string
)
error
{
var
dev
RaspDevList
rasp
:=
convertDevList
(
params
)
err
:=
db
.
Where
(
RaspDevList
{
Addr
:
rasp
.
Addr
})
.
Assign
(
rasp
)
.
FirstOrCreate
(
&
dev
)
.
Error
if
err
!=
nil
{
return
err
}
return
nil
}
pkg/app/process.go
View file @
f8a4a973
...
@@ -137,12 +137,13 @@ func CleanUpNossh(){
...
@@ -137,12 +137,13 @@ func CleanUpNossh(){
models
.
DeleteCompleteFeedbackNossh
()
models
.
DeleteCompleteFeedbackNossh
()
}
}
func
Corn
Clean
(
ticker
*
time
.
Ticker
){
func
Corn
DayJob
(
ticker
*
time
.
Ticker
){
for
{
for
{
select
{
select
{
case
<-
ticker
.
C
:
case
<-
ticker
.
C
:
CleanUp
()
CleanUp
()
CleanUpNossh
()
CleanUpNossh
()
CreateMonthTable
()
}
}
}
}
}
}
...
@@ -172,3 +173,7 @@ func UploadMinerData() bool {
...
@@ -172,3 +173,7 @@ func UploadMinerData() bool {
}
}
}
}
func
CreateMonthTable
()
error
{
return
models
.
CreateMonthDevHistoryTable
()
}
\ No newline at end of file
pkg/util/util.go
View file @
f8a4a973
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"chain33-pai/pkg/setting"
"chain33-pai/pkg/setting"
"net"
"net"
"errors"
"errors"
"time"
)
)
// Setup Initialize the util
// Setup Initialize the util
...
@@ -38,3 +39,7 @@ func GetLocalIP() (ipv4 *net.IPNet, err error) {
...
@@ -38,3 +39,7 @@ func GetLocalIP() (ipv4 *net.IPNet, err error) {
err
=
errors
.
New
(
"ERR_NO_LOCAL_IP_FOUND"
)
err
=
errors
.
New
(
"ERR_NO_LOCAL_IP_FOUND"
)
return
return
}
}
func
GetMonthDate
()
string
{
return
time
.
Now
()
.
Format
(
"2006-1"
)
}
routers/api/v1/pai.go
View file @
f8a4a973
...
@@ -269,11 +269,26 @@ func GetUploadInfo(c *gin.Context){
...
@@ -269,11 +269,26 @@ func GetUploadInfo(c *gin.Context){
appG
.
Response
(
http
.
StatusOK
,
e
.
INVALID_PARAMS
,
nil
)
appG
.
Response
(
http
.
StatusOK
,
e
.
INVALID_PARAMS
,
nil
)
return
return
}
}
date
:=
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
)
t
:=
time
.
Now
()
date
:=
t
.
Format
(
"2006-01-02 15:04:05"
)
KP
[
"date"
]
=
date
KP
[
"date"
]
=
date
history
:=
&
models
.
RaspDevHistory
{
Addr
:
KP
[
"addr"
],
Info
:
KP
[
"info"
],
Addtime
:
date
,
}
err
=
models
.
AddDevHistory
(
history
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
nil
)
return
}
err
=
models
.
UpdateDevList
(
KP
)
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
nil
)
return
}
err
=
models
.
UpdateDevVersion
(
KP
)
err
=
models
.
UpdateDevVersion
(
KP
)
if
err
!=
nil
{
if
err
!=
nil
{
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
nil
)
appG
.
Response
(
http
.
StatusOK
,
e
.
ERROR
,
nil
)
return
return
}
}
...
...
service/pai_service/pai.go
View file @
f8a4a973
...
@@ -17,16 +17,19 @@ var (
...
@@ -17,16 +17,19 @@ var (
pai_serial
string
pai_serial
string
)
)
type
Pai
struct
{
type
Pai
struct
{
Hardware
string
`json:"hardware"`
Hardware
string
`json:"hardware"`
Revision
string
`json:"revision"`
Revision
string
`json:"revision"`
Serial
string
`json:"serial"`
Serial
string
`json:"serial"`
//PeerList *types.PeerList
LocalLastHeight
int64
`json:"local_last_height"`
LocalLastHeight
int64
`json:"local_last_height"`
LastHeight
int64
`json:"last_height"`
LastHeight
int64
`json:"last_height"`
IsNtpSync
bool
`json:"is_ntp_sync"`
IsNtpSync
bool
`json:"is_ntp_sync"`
WalletStatus
*
types
.
WalletStatus
`json:"wallet_status"`
WalletStatus
*
types
.
WalletStatus
`json:"wallet_status"`
NetInfo
*
types
.
NodeNetInfo
`json:"net_info"`
NetInfo
*
types
.
NodeNetInfo
`json:"net_info"`
BtyVersion
*
types
.
VersionInfo
`json:"bty_version"`
Err
string
`json:"err"`
Arch
string
`json:"arch"`
}
}
type
MinedInfo
struct
{
type
MinedInfo
struct
{
...
...
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