2023-01-11 18:05:29 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"git.hpds.cc/Component/logging"
|
|
|
|
"hpds-iot-web/internal/proto"
|
|
|
|
"hpds-iot-web/model"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
"xorm.io/xorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SystemService interface {
|
|
|
|
BrandList(ctx context.Context, req proto.BrandRequest) (rsp *proto.BaseResponse, err error)
|
|
|
|
BrandInfo(ctx context.Context, req proto.BrandItemRequest) (rsp *proto.BaseResponse, err error)
|
|
|
|
AddBrand(ctx context.Context, req proto.BrandItemRequest) (rsp *proto.BaseResponse, err error)
|
|
|
|
EditBrand(ctx context.Context, req proto.BrandItemRequest) (rsp *proto.BaseResponse, err error)
|
|
|
|
DeleteBrand(ctx context.Context, req proto.BrandItemRequest) (rsp *proto.BaseResponse, err error)
|
2023-03-23 18:03:09 +08:00
|
|
|
|
|
|
|
NodeList(ctx context.Context, req proto.NodeRequest) (rsp *proto.BaseResponse, err error)
|
|
|
|
NodeInfo(ctx context.Context, req proto.NodeItemRequest) (rsp *proto.BaseResponse, err error)
|
|
|
|
EditNode(ctx context.Context, req proto.NodeItemRequest) (rsp *proto.BaseResponse, err error)
|
|
|
|
NodeState(ctx context.Context, req proto.NodeInfoRequest) (rsp *proto.BaseResponse, err error)
|
|
|
|
NodeLastState(ctx context.Context, req proto.NodeInfoRequest) (rsp *proto.BaseResponse, err error)
|
2023-06-17 09:38:26 +08:00
|
|
|
|
|
|
|
GetAnalysisInfo(ctx context.Context) (rsp *proto.BaseResponse, err error)
|
2023-01-11 18:05:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewSystemService(engine *xorm.Engine, logger *logging.Logger) SystemService {
|
|
|
|
return &repo{
|
|
|
|
engine: engine,
|
|
|
|
logger: logger,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *repo) BrandList(ctx context.Context, req proto.BrandRequest) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
data := make([]model.Brand, 0)
|
|
|
|
count, err := rp.engine.Where("(? = '' or brand_name like ?)", req.BrandName, "%"+req.BrandName+"%").
|
|
|
|
And("status = 1").Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
|
|
|
|
FindAndCount(&data)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "成功"
|
|
|
|
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
|
|
|
|
rsp.Err = err
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *repo) BrandInfo(ctx context.Context, req proto.BrandItemRequest) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
var h bool
|
|
|
|
item := new(model.Brand)
|
|
|
|
h, err = rp.engine.ID(req.BrandId).Get(item)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
if !h {
|
|
|
|
err = fmt.Errorf("未能找到对应的品牌")
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "获取品牌成功"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
rsp.Data = item
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
func (rp *repo) AddBrand(ctx context.Context, req proto.BrandItemRequest) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
item := &model.Brand{
|
|
|
|
BrandName: req.BrandName,
|
|
|
|
BrandLogo: req.BrandLogo,
|
|
|
|
BrandWeb: req.BrandWeb,
|
|
|
|
Status: 1,
|
|
|
|
CreateAt: time.Now().Unix(),
|
|
|
|
UpdateAt: time.Now().Unix(),
|
|
|
|
}
|
|
|
|
_, err = rp.engine.Insert(item)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "新增品牌成功"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
rsp.Data = item
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
func (rp *repo) EditBrand(ctx context.Context, req proto.BrandItemRequest) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
var h bool
|
|
|
|
item := new(model.Brand)
|
|
|
|
h, err = rp.engine.ID(req.BrandId).Get(item)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
if !h {
|
|
|
|
err = fmt.Errorf("未能找到对应的品牌")
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
if len(req.BrandName) > 0 {
|
|
|
|
item.BrandName = req.BrandName
|
|
|
|
}
|
|
|
|
if len(req.BrandLogo) > 0 {
|
|
|
|
item.BrandLogo = req.BrandLogo
|
|
|
|
}
|
|
|
|
if len(req.BrandWeb) > 0 {
|
|
|
|
item.BrandWeb = req.BrandWeb
|
|
|
|
}
|
|
|
|
item.UpdateAt = time.Now().Unix()
|
|
|
|
_, err = rp.engine.ID(req.BrandId).AllCols().Update(item)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "修改品牌成功"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
rsp.Data = item
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
func (rp *repo) DeleteBrand(ctx context.Context, req proto.BrandItemRequest) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
var h bool
|
|
|
|
item := new(model.Brand)
|
|
|
|
h, err = rp.engine.ID(req.BrandId).Get(item)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
if !h {
|
|
|
|
err = fmt.Errorf("未能找到对应的品牌")
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
item.Status = 0
|
|
|
|
item.UpdateAt = time.Now().Unix()
|
|
|
|
_, err = rp.engine.ID(req.BrandId).AllCols().Update(item)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "删除品牌成功"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|
2023-03-23 18:03:09 +08:00
|
|
|
|
|
|
|
func (rp *repo) NodeList(ctx context.Context, req proto.NodeRequest) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
data := make([]model.Node, 0)
|
|
|
|
var count int64
|
|
|
|
count, err = rp.engine.Where("(? = '' or node_name like ?)", req.NodeName, "%"+req.NodeName+"%").
|
|
|
|
And("(? = '' or node_guid like ?)", req.NodeGuid, "%"+req.NodeGuid+"%").
|
|
|
|
And("(? = 0 or node_type = ?)", req.NodeType, req.NodeType).
|
|
|
|
And("node_status = 1").Limit(int(req.Size), int(((req.Page)-1)*req.Size)).
|
|
|
|
FindAndCount(&data)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "成功"
|
|
|
|
rsp = FillPaging(count, req.Page, req.Size, data, rsp)
|
|
|
|
rsp.Err = err
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *repo) NodeInfo(ctx context.Context, req proto.NodeItemRequest) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
var h bool
|
|
|
|
item := new(model.Node)
|
|
|
|
h, err = rp.engine.ID(req.NodeId).Get(item)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
if !h {
|
|
|
|
err = fmt.Errorf("未能找到对应的节点")
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "获取节点成功"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
rsp.Data = item
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *repo) EditNode(ctx context.Context, req proto.NodeItemRequest) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
var h bool
|
|
|
|
item := new(model.Node)
|
|
|
|
h, err = rp.engine.ID(req.NodeId).Get(item)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
if !h {
|
|
|
|
err = fmt.Errorf("未能找到对应的节点")
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
if len(req.NodeName) > 0 {
|
|
|
|
item.NodeName = req.NodeName
|
|
|
|
}
|
|
|
|
if req.NodeType > 0 {
|
|
|
|
item.NodeType = req.NodeType
|
|
|
|
}
|
|
|
|
if len(req.Platform) > 0 {
|
|
|
|
item.Platform = req.Platform
|
|
|
|
}
|
|
|
|
if len(req.PlatformVersion) > 0 {
|
|
|
|
item.PlatformVersion = req.PlatformVersion
|
|
|
|
}
|
|
|
|
if len(req.CPU) > 0 {
|
|
|
|
item.CPU = req.CPU
|
|
|
|
}
|
|
|
|
if req.MemTotal > 0 {
|
|
|
|
item.MemTotal = req.MemTotal
|
|
|
|
}
|
|
|
|
if req.DiskTotal > 0 {
|
|
|
|
item.DiskTotal = req.DiskTotal
|
|
|
|
}
|
|
|
|
if req.SwapTotal > 0 {
|
|
|
|
item.SwapTotal = req.SwapTotal
|
|
|
|
}
|
|
|
|
if len(req.Arch) > 0 {
|
|
|
|
item.Arch = req.Arch
|
|
|
|
}
|
|
|
|
if len(req.Virtualization) > 0 {
|
|
|
|
item.Virtualization = req.Virtualization
|
|
|
|
}
|
|
|
|
if req.BootTime > 0 {
|
|
|
|
item.BootTime = req.BootTime
|
|
|
|
}
|
|
|
|
if len(req.IP) > 0 {
|
|
|
|
item.IP = req.IP
|
|
|
|
}
|
|
|
|
if len(req.CountryCode) > 0 {
|
|
|
|
item.CountryCode = req.CountryCode
|
|
|
|
}
|
|
|
|
if len(req.Version) > 0 {
|
|
|
|
item.Version = req.Version
|
|
|
|
}
|
|
|
|
item.UpdateAt = time.Now().Unix()
|
|
|
|
_, err = rp.engine.ID(req.NodeId).AllCols().Update(item)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "修改节点成功"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
rsp.Data = item
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *repo) NodeState(ctx context.Context, req proto.NodeInfoRequest) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
list := make([]model.NodeState, 0)
|
2023-04-24 15:21:17 +08:00
|
|
|
err = rp.engine.Where("node_guid = ?", req.NodeGuid).
|
2023-03-23 18:03:09 +08:00
|
|
|
And(" uptime > UNIX_TIMESTAMP(DATE_ADD(NOW(),INTERVAL -24 HOUR))").
|
|
|
|
Find(&list)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
state := new(proto.NodeState)
|
|
|
|
state.List = list
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "获取节点状态信息成功"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
rsp.Data = state
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rp *repo) NodeLastState(ctx context.Context, req proto.NodeInfoRequest) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
list := make([]proto.NodeLastStateItem, 0)
|
|
|
|
//err = rp.engine.Where("node_name = ?", req.NodeGuid).
|
|
|
|
// And("? + uptime > UNIX_TIMESTAMP(DATE_ADD(NOW(),INTERVAL -24 HOUR))", req.Uptime).Desc("uptime").
|
|
|
|
// Find(&list)
|
|
|
|
err = rp.engine.SQL(`select c.node_id,c.node_name,c.node_guid,c.node_type,c.node_type,c.platform,c.platform_version,c.c_p_u,c.mem_total,
|
|
|
|
c.disk_total,c.swap_total,a.c_p_u cpu_used,c.node_status, a.mem_used,a.swap_used, a.disk_used, a.net_in_transfer, a.net_in_speed,
|
|
|
|
a.net_out_speed, a.net_out_transfer, a.load1, a.load5, a.load15, a.tcp_conn_count, a.udp_conn_count, a.process_count,
|
|
|
|
d.task_name exec_task from node_state a , (select node_name, max(uptime) uptime from node_state group by node_name) b, node c
|
|
|
|
left join (select t2.node_id, t2.task_name from task t2, (select node_id, max(start_time) start from task group by node_id) t1 where t2.node_id = t1.node_id and t2.start_time = t1.start and t2.status = 1) d on c.node_id = d.node_id
|
2023-06-17 09:38:26 +08:00
|
|
|
where a.node_name = b.node_name and a.uptime = b.uptime and a.node_name = c.node_name and c.node_status > 0 and (? = '' or a.node_name = ?) `, req.NodeGuid, req.NodeGuid).Find(&list)
|
2023-03-23 18:03:09 +08:00
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
state := new(proto.NodeLastState)
|
|
|
|
state.List = list
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "获取节点状态信息成功"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
rsp.Data = state
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|
2023-06-17 09:38:26 +08:00
|
|
|
|
|
|
|
func (rp *repo) GetAnalysisInfo(ctx context.Context) (rsp *proto.BaseResponse, err error) {
|
|
|
|
rsp = new(proto.BaseResponse)
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = fmt.Errorf("超时/取消")
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Message = "超时/取消"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
return rsp, ctx.Err()
|
|
|
|
default:
|
|
|
|
data := new(proto.AnalysisInfo)
|
|
|
|
type AnalysisItem struct {
|
|
|
|
BizType int
|
|
|
|
Total int64
|
|
|
|
}
|
|
|
|
modelTotal := make([]AnalysisItem, 0)
|
|
|
|
err = rp.engine.SQL(`select biz_type, count(model_id) total from model where status = 1 group by biz_type`).Find(&modelTotal)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
for _, v := range modelTotal {
|
|
|
|
switch v.BizType {
|
|
|
|
case 1:
|
|
|
|
data.RoadModel = v.Total
|
|
|
|
case 2:
|
|
|
|
data.BridgeModel = v.Total
|
|
|
|
case 3:
|
|
|
|
data.TunnelModel = v.Total
|
|
|
|
case 4:
|
|
|
|
data.SideSlopeModel = v.Total
|
|
|
|
}
|
|
|
|
data.ModelTotal += v.Total
|
|
|
|
}
|
|
|
|
projectTotal := make([]AnalysisItem, 0)
|
|
|
|
err = rp.engine.SQL(`select biz_type, count(project_id) total from project where status = 1 group by biz_type`).Find(&projectTotal)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
for _, v := range projectTotal {
|
|
|
|
switch v.BizType {
|
|
|
|
case 1:
|
|
|
|
data.RoadProject = v.Total
|
|
|
|
case 2:
|
|
|
|
data.BridgeProject = v.Total
|
|
|
|
case 3:
|
|
|
|
data.TunnelProject = v.Total
|
|
|
|
case 4:
|
|
|
|
data.SideSlopeProject = v.Total
|
|
|
|
}
|
|
|
|
data.ProjectTotal += v.Total
|
|
|
|
}
|
|
|
|
deviceTotal := make([]AnalysisItem, 0)
|
|
|
|
err = rp.engine.SQL(`select node_type biz_type, count(node_id) total from node group by node_type`).Find(&deviceTotal)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
for _, v := range deviceTotal {
|
|
|
|
switch v.BizType {
|
|
|
|
case 1:
|
|
|
|
data.CloudDevice = v.Total
|
|
|
|
case 2:
|
|
|
|
data.EdgeDevice = v.Total
|
|
|
|
}
|
|
|
|
data.DeviceTotal += v.Total
|
|
|
|
}
|
|
|
|
labelTotal := make([]AnalysisItem, 0)
|
|
|
|
err = rp.engine.SQL(`select category_id biz_type, sum(file_size) total from label_file group by category_id`).Find(&labelTotal)
|
|
|
|
if err != nil {
|
|
|
|
goto ReturnPoint
|
|
|
|
}
|
|
|
|
for _, v := range labelTotal {
|
|
|
|
switch v.BizType {
|
|
|
|
case 1:
|
|
|
|
data.RoadLabelData = v.Total
|
|
|
|
case 2:
|
|
|
|
data.BridgeLabelData = v.Total
|
|
|
|
case 3:
|
|
|
|
data.TunnelLabelData = v.Total
|
|
|
|
case 4:
|
|
|
|
data.SideSlopeLabelData = v.Total
|
|
|
|
}
|
|
|
|
data.TotalLabelData += v.Total
|
|
|
|
}
|
|
|
|
|
|
|
|
rsp.Code = http.StatusOK
|
|
|
|
rsp.Status = http.StatusText(http.StatusOK)
|
|
|
|
rsp.Message = "获取统计数据"
|
|
|
|
rsp.Err = ctx.Err()
|
|
|
|
rsp.Data = data
|
|
|
|
return rsp, err
|
|
|
|
}
|
|
|
|
ReturnPoint:
|
|
|
|
if err != nil {
|
|
|
|
rsp.Code = http.StatusInternalServerError
|
|
|
|
rsp.Status = http.StatusText(http.StatusInternalServerError)
|
|
|
|
rsp.Err = err
|
|
|
|
rsp.Message = "失败"
|
|
|
|
}
|
|
|
|
return rsp, err
|
|
|
|
}
|