hpds_jkw_web/internal/handler/system.go

179 lines
6.3 KiB
Go
Raw Normal View History

2023-01-11 18:05:29 +08:00
package handler
import (
"fmt"
"github.com/gin-gonic/gin"
"hpds-iot-web/internal/proto"
"hpds-iot-web/internal/service"
"hpds-iot-web/model"
e "hpds-iot-web/pkg/err"
)
func (s HandlerService) BrandList(c *gin.Context) (data interface{}, err error) {
repo := service.NewSystemService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.BrandRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("BrandList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
if req.Size < 1 {
req.Size = 20
}
if req.Size > 100 {
req.Size = 100
}
if req.Page < 1 {
req.Page = 1
}
data, err = repo.BrandList(c, req)
go s.SaveLog("获取品牌列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) BrandInfo(c *gin.Context) (data interface{}, err error) {
repo := service.NewSystemService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.BrandItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("BrandInfo", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.BrandInfo(c, req)
go s.SaveLog("获取品牌信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddBrand(c *gin.Context) (data interface{}, err error) {
repo := service.NewSystemService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.BrandItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddBrand", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddBrand(c, req)
go s.SaveLog("新增品牌", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditBrand(c *gin.Context) (data interface{}, err error) {
repo := service.NewSystemService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.BrandItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EditBrand", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditBrand(c, req)
go s.SaveLog("修改品牌", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) DeleteBrand(c *gin.Context) (data interface{}, err error) {
repo := service.NewSystemService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.BrandItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("DeleteBrand", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.DeleteBrand(c, req)
go s.SaveLog("删除品牌", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
2023-03-23 18:03:09 +08:00
func (s HandlerService) NodeList(c *gin.Context) (data interface{}, err error) {
repo := service.NewSystemService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.NodeRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("NodeList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
if req.Size < 1 {
req.Size = 20
}
if req.Size > 100 {
req.Size = 100
}
if req.Page < 1 {
req.Page = 1
}
data, err = repo.NodeList(c, req)
go s.SaveLog("获取节点列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) NodeInfo(c *gin.Context) (data interface{}, err error) {
repo := service.NewSystemService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.NodeItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("NodeInfo", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.NodeInfo(c, req)
go s.SaveLog("获取节点信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditNode(c *gin.Context) (data interface{}, err error) {
repo := service.NewSystemService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.NodeItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EditNode", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditNode(c, req)
go s.SaveLog("修改节点", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) NodeState(c *gin.Context) (data interface{}, err error) {
repo := service.NewSystemService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.NodeInfoRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("NodeState", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.NodeState(c, req)
go s.SaveLog("获取节点运行信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) NodeLastState(c *gin.Context) (data interface{}, err error) {
repo := service.NewSystemService(s.Engine, s.Logger)
us, _ := c.Get("operatorUser")
userInfo := us.(*model.SystemUser)
var req proto.NodeInfoRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("NodeLastState", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.NodeLastState(c, req)
go s.SaveLog("获取节点最后运行信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}