77 lines
2.6 KiB
Go
77 lines
2.6 KiB
Go
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) ModelList(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewModelService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.ModelRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("ModelList", "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.ModelList(c, req)
|
|
go s.SaveLog("获取模型列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
func (s HandlerService) AddModel(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewModelService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.ModelItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("AddModel", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.AddModel(c, req)
|
|
go s.SaveLog("新增模型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
func (s HandlerService) EditModel(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewModelService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.ModelItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("EditModel", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.EditModel(c, req)
|
|
go s.SaveLog("新增模型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
func (s HandlerService) DelModel(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewModelService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.ModelItemRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("EditModel", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.DelModel(c, req)
|
|
go s.SaveLog("删除模型", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|