54 lines
1.7 KiB
Go
54 lines
1.7 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) Login(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewUserService(s.Engine, s.Logger)
|
|
var req proto.UserLogin
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("UserLogin", "System", "", "", req.ToString(), "", c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.Login(c, req.UserName, req.UserPass)
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) GetUserInfo(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewUserService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userinfo := us.(*model.SystemUser)
|
|
data, err = repo.GetUserInfo(c, userinfo.UserId)
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) GetUserList(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewUserService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userInfo := us.(*model.SystemUser)
|
|
var req proto.UserRequest
|
|
err = c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
go s.SaveLog("GetUserList", "Manage", "", "", req.ToString(), fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return nil, e.NewValidErr(err)
|
|
}
|
|
data, err = repo.GetUserList(c, req)
|
|
go s.SaveLog("获取用户列表", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
|
|
return
|
|
}
|
|
|
|
func (s HandlerService) MenuList(c *gin.Context) (data interface{}, err error) {
|
|
repo := service.NewUserService(s.Engine, s.Logger)
|
|
us, _ := c.Get("operatorUser")
|
|
userinfo := us.(*model.SystemUser)
|
|
data, err = repo.MenuList(c, userinfo.UserId)
|
|
return
|
|
}
|