Commit 5dbf80ac authored by brent's avatar brent

modify

parent def320d9
...@@ -54,15 +54,26 @@ func (server *MonitorController) NodeManagersByPage() { ...@@ -54,15 +54,26 @@ func (server *MonitorController) NodeManagersByPage() {
err := json.Unmarshal(body, &appRequest) //解析body中数据 err := json.Unmarshal(body, &appRequest) //解析body中数据
logs.Debug("appRequest", appRequest, string(body)) logs.Debug("appRequest", appRequest, string(body))
if appRequest.Page > 0 {
appRequest.Page = appRequest.Page - 1
}
if appRequest.Size == 0 { if appRequest.Size == 0 {
appRequest.Size = 10 appRequest.Size = 10
} }
data, err := registry.NodeManagersByPage(int(appRequest.Size), int(appRequest.Page)) data, total, err := registry.NodeManagersByPage(int(appRequest.Size), int(appRequest.Page))
if err != nil { if err != nil {
server.respond(models.BusinessFailed, err.Error()) server.respond(models.BusinessFailed, err.Error())
return return
} }
server.respond(http.StatusOK, "", data) responseData := struct {
Total int64 `json:"total"`
Data interface{} `json:"data,omitempty"`
}{
Total: int64(total),
Data: data,
}
server.respond(http.StatusOK, "", responseData)
} }
func (server *MonitorController) GatewaysByPage() { func (server *MonitorController) GatewaysByPage() {
...@@ -71,15 +82,26 @@ func (server *MonitorController) GatewaysByPage() { ...@@ -71,15 +82,26 @@ func (server *MonitorController) GatewaysByPage() {
err := json.Unmarshal(body, &appRequest) //解析body中数据 err := json.Unmarshal(body, &appRequest) //解析body中数据
logs.Debug("appRequest", appRequest, string(body)) logs.Debug("appRequest", appRequest, string(body))
if appRequest.Page > 0 {
appRequest.Page = appRequest.Page - 1
}
if appRequest.Size == 0 { if appRequest.Size == 0 {
appRequest.Size = 10 appRequest.Size = 10
} }
data, err := registry.GatewaysByPage(int(appRequest.Size), int(appRequest.Page)) data, total, err := registry.GatewaysByPage(int(appRequest.Size), int(appRequest.Page))
if err != nil { if err != nil {
server.respond(models.BusinessFailed, err.Error()) server.respond(models.BusinessFailed, err.Error())
return return
} }
server.respond(http.StatusOK, "", data) responseData := struct {
Total int64 `json:"total"`
Data interface{} `json:"data,omitempty"`
}{
Total: int64(total),
Data: data,
}
server.respond(http.StatusOK, "", responseData)
} }
func (server *MonitorController) WorkersByPage() { func (server *MonitorController) WorkersByPage() {
...@@ -88,15 +110,26 @@ func (server *MonitorController) WorkersByPage() { ...@@ -88,15 +110,26 @@ func (server *MonitorController) WorkersByPage() {
err := json.Unmarshal(body, &appRequest) //解析body中数据 err := json.Unmarshal(body, &appRequest) //解析body中数据
logs.Debug("appRequest", appRequest, string(body)) logs.Debug("appRequest", appRequest, string(body))
if appRequest.Page > 0 {
appRequest.Page = appRequest.Page - 1
}
if appRequest.Size == 0 { if appRequest.Size == 0 {
appRequest.Size = 10 appRequest.Size = 10
} }
data, err := registry.WorkersByPage(int(appRequest.Size), int(appRequest.Page)) data, total, err := registry.WorkersByPage(int(appRequest.Size), int(appRequest.Page))
if err != nil { if err != nil {
server.respond(models.BusinessFailed, err.Error()) server.respond(models.BusinessFailed, err.Error())
return return
} }
server.respond(http.StatusOK, "", data) responseData := struct {
Total int64 `json:"total"`
Data interface{} `json:"data,omitempty"`
}{
Total: int64(total),
Data: data,
}
server.respond(http.StatusOK, "", responseData)
} }
func (server *MonitorController) SchedulesByPage() { func (server *MonitorController) SchedulesByPage() {
...@@ -105,13 +138,23 @@ func (server *MonitorController) SchedulesByPage() { ...@@ -105,13 +138,23 @@ func (server *MonitorController) SchedulesByPage() {
err := json.Unmarshal(body, &appRequest) //解析body中数据 err := json.Unmarshal(body, &appRequest) //解析body中数据
logs.Debug("appRequest", appRequest, string(body)) logs.Debug("appRequest", appRequest, string(body))
if appRequest.Page > 0 {
appRequest.Page = appRequest.Page - 1
}
if appRequest.Size == 0 { if appRequest.Size == 0 {
appRequest.Size = 10 appRequest.Size = 10
} }
data, err := registry.SchedulesByPage(int(appRequest.Size), int(appRequest.Page)) data, total, err := registry.SchedulesByPage(int(appRequest.Size), int(appRequest.Page))
if err != nil { if err != nil {
server.respond(models.BusinessFailed, err.Error()) server.respond(models.BusinessFailed, err.Error())
return return
} }
server.respond(http.StatusOK, "", data) responseData := struct {
Total int64 `json:"total"`
Data interface{} `json:"data,omitempty"`
}{
Total: int64(total),
Data: data,
}
server.respond(http.StatusOK, "", responseData)
} }
...@@ -98,9 +98,14 @@ func (server *UserController) Login() { ...@@ -98,9 +98,14 @@ func (server *UserController) Login() {
checkUser := &models.User{Mail: user.Mail} checkUser := &models.User{Mail: user.Mail}
err = mysql.GetMysqlInstace().Ormer.Read(checkUser, "mail") err = mysql.GetMysqlInstace().Ormer.Read(checkUser, "mail")
if err != nil { stats := mysql.Ping()
if stats != nil {
server.respond(models.CreateUserFailed, stats.Error())
return
}
if err != nil && stats == nil {
checkUser, err = regisgerUser(user) checkUser, err = regisgerUser(user)
if err != nil { if checkUser == nil {
server.respond(models.CreateUserFailed, err.Error()) server.respond(models.CreateUserFailed, err.Error())
return return
} }
...@@ -187,11 +192,11 @@ func (server *UserController) UserInfo() { ...@@ -187,11 +192,11 @@ func (server *UserController) UserInfo() {
func regisgerUser(user models.User) (*models.User, error) { func regisgerUser(user models.User) (*models.User, error) {
var err error var err error
qs := mysql.GetMysqlInstace().Ormer.QueryTable("user") qs := mysql.GetMysqlInstace().Ormer.QueryTable("user")
usernameQs := qs.Filter("username", user.Username) usernameQs := qs.Filter("mail", user.Mail)
var count int64 var count int64
count, err = usernameQs.Count() count, err = usernameQs.Count()
if count > 0 { if count > 0 {
return nil, errors.New("用户已存在") return nil, errors.New("用户已存在")
} }
//if len(user.CustomId) > 0 { //if len(user.CustomId) > 0 {
// customIdQs := qs.Filter("custom_id", user.CustomId) // customIdQs := qs.Filter("custom_id", user.CustomId)
......
...@@ -65,3 +65,11 @@ func init() { ...@@ -65,3 +65,11 @@ func init() {
orm.SetMaxIdleConns("default", 10) orm.SetMaxIdleConns("default", 10)
orm.SetMaxOpenConns("default", 100) orm.SetMaxOpenConns("default", 100)
} }
func Ping() error {
db, err := orm.GetDB("default")
if err != nil {
return err
}
return db.Ping()
}
...@@ -43,19 +43,19 @@ func Schedules() ([]string, error) { ...@@ -43,19 +43,19 @@ func Schedules() ([]string, error) {
return querier.Select(common.SERVICE_SCHEDULER).List() return querier.Select(common.SERVICE_SCHEDULER).List()
} }
func NodeManagersByPage(pageSize int, pageNum int) ([]string, error) { func NodeManagersByPage(pageSize int, pageNum int) ([]string, int, error) {
return querier.Select(common.SERVICE_NODE_MANAGER).ListByPage(pageSize, pageNum) return querier.Select(common.SERVICE_NODE_MANAGER).ListByPage(pageSize, pageNum)
} }
func GatewaysByPage(pageSize int, pageNum int) ([]string, error) { func GatewaysByPage(pageSize int, pageNum int) ([]string, int, error) {
return querier.Select(common.SERVICE_API_GATEWAY).ListByPage(pageSize, pageNum) return querier.Select(common.SERVICE_API_GATEWAY).ListByPage(pageSize, pageNum)
} }
func WorkersByPage(pageSize int, pageNum int) ([]string, error) { func WorkersByPage(pageSize int, pageNum int) ([]string, int, error) {
return querier.Select(common.SERVICE_WORKER).ListByPage(pageSize, pageNum) return querier.Select(common.SERVICE_WORKER).ListByPage(pageSize, pageNum)
} }
func SchedulesByPage(pageSize int, pageNum int) ([]string, error) { func SchedulesByPage(pageSize int, pageNum int) ([]string, int, error) {
return querier.Select(common.SERVICE_SCHEDULER).ListByPage(pageSize, pageNum) return querier.Select(common.SERVICE_SCHEDULER).ListByPage(pageSize, pageNum)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment