hpds_jkw_web/internal/handler/user.go

144 lines
5.4 KiB
Go
Raw Permalink Normal View History

2023-01-06 10:09:23 +08:00
package handler
import (
2023-03-23 18:03:09 +08:00
"fmt"
2023-01-06 10:09:23 +08:00
"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
}
2023-04-02 23:36:16 +08:00
func (s HandlerService) AddUser(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.UserRequestItem
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddUser", "System", "", "", req.ToString(), "", c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddUser(c, req)
go s.SaveLog("新增用户", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditUser(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.UserRequestItem
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("EditUser", "System", "", "", req.ToString(), "", c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditUser(c, req)
go s.SaveLog("修改用户信息", "Manage", "", "", "", fmt.Sprintf("%d", userInfo.UserId), c.Request.RemoteAddr, "")
return
}
2023-01-06 10:09:23 +08:00
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
}
2023-01-10 10:01:42 +08:00
2023-03-23 18:03:09 +08:00
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
}
2023-01-10 10:01:42 +08:00
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)
if err != nil {
go s.SaveLog("GetUserList", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
go s.SaveLog("获取用户菜单列表", "Manage", "", "", "", fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
2023-01-10 10:01:42 +08:00
return
}
2023-05-14 18:23:12 +08:00
func (s HandlerService) GetRoleList(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.RoleRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("GetRoleList", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.GetRoleList(c, req)
if err != nil {
go s.SaveLog("GetRoleList", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
go s.SaveLog("获取用户角色列表", "Manage", "", "", "", fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) AddRole(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.RoleItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("AddRole", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.AddRole(c, req)
if err != nil {
go s.SaveLog("AddRole", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
go s.SaveLog("新增用户角色", "Manage", "", "", "", fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return
}
func (s HandlerService) EditRole(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.RoleItemRequest
err = c.ShouldBindJSON(&req)
if err != nil {
go s.SaveLog("GetRoleList", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
data, err = repo.EditRole(c, req)
if err != nil {
go s.SaveLog("EditRole", "Manage", "", "", userinfo.ToString(), fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return nil, e.NewValidErr(err)
}
go s.SaveLog("修改用户角色", "Manage", "", "", "", fmt.Sprintf("%d", userinfo.UserId), c.Request.RemoteAddr, "")
return
}