first commit
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
systemReq "sundynix-go/model/system/request"
|
||||
systemRes "sundynix-go/model/system/response"
|
||||
"sundynix-go/utils/auth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var store = base64Captcha.DefaultMemStore
|
||||
|
||||
type AuthApi struct{}
|
||||
|
||||
// Login
|
||||
// @Tags 登录相关
|
||||
// @Summary pc登录
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.Login true "用户名, 密码, 验证码,验证码id"
|
||||
// @Success 200 {object} response.Response{msg=string} "登录成功"
|
||||
// @Router /auth/login [post]
|
||||
func (a *AuthApi) Login(c *gin.Context) {
|
||||
var l systemReq.Login
|
||||
err := c.ShouldBindJSON(&l)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if l.CaptchaId != "" && l.Captcha != "" && store.Verify(l.CaptchaId, l.Captcha, true) {
|
||||
u := &system.User{Account: l.Account, Password: l.Password}
|
||||
user, err := userService.Login(u)
|
||||
if err != nil {
|
||||
global.Logger.Error("登录失败! 用户名不存在或者密码错误!", zap.Error(err))
|
||||
response.FailWithMsg("用户名不存在或者密码错误", c)
|
||||
return
|
||||
}
|
||||
a.GetToken(c, *user)
|
||||
return
|
||||
}
|
||||
response.FailWithMsg("验证码错误", c)
|
||||
}
|
||||
|
||||
// Logout
|
||||
// @Tags 登录相关
|
||||
// @Summary pc登出
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "登出成功"
|
||||
// @Router /auth/logout [get]
|
||||
func (a *AuthApi) Logout(c *gin.Context) {
|
||||
token := auth.GetToken(c)
|
||||
userId := auth.GetUserId(c)
|
||||
err := jwtService.PutBlacklist(userId, token)
|
||||
if err != nil {
|
||||
global.Logger.Error("登出失败!", zap.Error(err))
|
||||
response.FailWithMsg("登出失败", c)
|
||||
return
|
||||
}
|
||||
auth.ClearToken(c)
|
||||
response.OkWithMsg("登出成功", c)
|
||||
|
||||
}
|
||||
|
||||
// Captcha
|
||||
// @Tags 登录相关
|
||||
// @Summary 获取验证码
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=systemRes.CaptchaRes} "获取验证码"
|
||||
// @Router /auth/captcha [get]
|
||||
func (a *AuthApi) Captcha(c *gin.Context) {
|
||||
var driver = base64Captcha.DriverString{
|
||||
Height: 80,
|
||||
Width: 240,
|
||||
NoiseCount: 2,
|
||||
ShowLineOptions: 4,
|
||||
Length: 4,
|
||||
Source: "1234567890",
|
||||
}
|
||||
|
||||
cp := base64Captcha.NewCaptcha(&driver, store)
|
||||
id, b64s, _, err := cp.Generate()
|
||||
if err != nil {
|
||||
global.Logger.Error("GenerateCaptcha err", zap.Error(err))
|
||||
response.FailWithMsg("GenerateCaptcha err", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(systemRes.CaptchaRes{
|
||||
CaptchaId: id,
|
||||
Captcha: b64s,
|
||||
}, c)
|
||||
}
|
||||
|
||||
func (a *AuthApi) GetToken(c *gin.Context, user system.User) {
|
||||
token, claims, err := auth.GetLoginToken(&user)
|
||||
if err != nil {
|
||||
global.Logger.Error("GetToken err", zap.Error(err))
|
||||
response.FailWithMsg("GetToken err", c)
|
||||
}
|
||||
response.OkWithData(systemRes.LoginResponse{
|
||||
ExpiresAt: claims.RegisteredClaims.ExpiresAt.Unix() * 1000,
|
||||
Token: token,
|
||||
User: user,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// MiniLogin
|
||||
// @Tags 登录相关
|
||||
// @Summary 小程序登录
|
||||
// @Produce application/json
|
||||
// @Param code query string true "code"
|
||||
// @Success 200 {object} response.Response{data=systemRes.LoginResponse} "小程序登录"
|
||||
// @Router /auth/miniLogin [get]
|
||||
func (a *AuthApi) MiniLogin(c *gin.Context) {
|
||||
jsCode := c.Query("code")
|
||||
user, err := userService.MiniLogin(jsCode)
|
||||
if err != nil {
|
||||
global.Logger.Error("登录失败!", zap.Error(err))
|
||||
response.FailWithMsg("登录失败", c)
|
||||
return
|
||||
}
|
||||
a.GetToken(c, *user)
|
||||
return
|
||||
}
|
||||
|
||||
// GetPhone
|
||||
// @Tags 登录相关
|
||||
// @Summary 获取手机号
|
||||
// @Produce application/json
|
||||
// @Param code query string true "code"
|
||||
// @Param openId query string true "openId"
|
||||
// @Router /auth/getPhone [get]
|
||||
func (a *AuthApi) GetPhone(c *gin.Context) {
|
||||
jsCode := c.Query("code")
|
||||
openId := c.Query("openId")
|
||||
user, err := userService.LoginByPhone(jsCode, openId)
|
||||
if err != nil {
|
||||
global.Logger.Error("登录失败!", zap.Error(err))
|
||||
response.FailWithMsg("登录失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(user, c)
|
||||
}
|
||||
|
||||
// GetLocation
|
||||
// @Tags 登录相关
|
||||
// @Summary 获取位置信息
|
||||
// @Produce application/json
|
||||
// @Param longitude query string true "longitude"
|
||||
// @Param latitude query string true "latitude"
|
||||
// @Router /auth/getLocation [get]
|
||||
func (a *AuthApi) GetLocation(c *gin.Context) {
|
||||
longitude := c.Query("longitude") //经度
|
||||
latitude := c.Query("latitude")
|
||||
location, err := userService.GetLocation(longitude, latitude)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取位置信息失败!", zap.Error(err))
|
||||
response.FailWithMsg("获取位置信息失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(location, c)
|
||||
}
|
||||
|
||||
// GetWeather
|
||||
// @Tags 登录相关
|
||||
// @Summary 获取天气信息
|
||||
// @Produce application/json
|
||||
// @Param adcode query string true "adcode"
|
||||
// @Router /auth/getWeather [get]
|
||||
func (a *AuthApi) GetWeather(c *gin.Context) {
|
||||
value := c.Query("adcode")
|
||||
weather, err := userService.GetWeather(value)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取天气信息失败!", zap.Error(err))
|
||||
response.FailWithMsg("获取天气信息失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(weather, c)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package system
|
||||
|
||||
import "sundynix-go/service"
|
||||
|
||||
type ApiGroup struct {
|
||||
AuthApi
|
||||
UserApi
|
||||
ClientApi
|
||||
RoleApi
|
||||
MenuApi
|
||||
OperationRecordApi
|
||||
OssApi
|
||||
}
|
||||
|
||||
var (
|
||||
jwtService = service.GroupApp.SystemServiceGroup.JwtService
|
||||
userService = service.GroupApp.SystemServiceGroup.UserService
|
||||
clientService = service.GroupApp.SystemServiceGroup.ClientService
|
||||
roleService = service.GroupApp.SystemServiceGroup.RoleService
|
||||
menuService = service.GroupApp.SystemServiceGroup.MenuService
|
||||
operationRecordService = service.GroupApp.SystemServiceGroup.OperationRecordService
|
||||
ossService = service.GroupApp.SystemServiceGroup.OssService
|
||||
)
|
||||
@@ -0,0 +1,116 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
sysReq "sundynix-go/model/system/request"
|
||||
sysResp "sundynix-go/model/system/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type OssApi struct {
|
||||
}
|
||||
|
||||
// UploadFile
|
||||
// @tags 文件相关
|
||||
// @Summary 文件上传
|
||||
// @Security ApiKeyAuth
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param file formData file true "上传文件"
|
||||
// @Success 200 {object} response.Response{msg=string} "上传文件"
|
||||
// @router /oss/upload [post]
|
||||
func (o *OssApi) UploadFile(c *gin.Context) {
|
||||
var file system.Oss
|
||||
multipartFile, header, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
global.Logger.Error("接收文件失败!", zap.Error(err))
|
||||
response.FailWithMsg("接收文件失败!", c)
|
||||
return
|
||||
}
|
||||
file, err = ossService.Upload(multipartFile, header) //上传完成后拿到文件信息
|
||||
if err != nil {
|
||||
global.Logger.Error("上传文件失败!", zap.Error(err))
|
||||
response.FailWithMsg("上传文件失败!", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(sysResp.UploadFileResponse{File: file}, c)
|
||||
}
|
||||
|
||||
// DeleteFile
|
||||
// @tags 文件相关
|
||||
// @Summary 删除文件
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除文件"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除文件"
|
||||
// @router /oss/delete [post]
|
||||
func (o *OssApi) DeleteFile(c *gin.Context) {
|
||||
var ids request.IdsReq
|
||||
err := c.ShouldBindJSON(&ids)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = ossService.DeleteFileByIds(ids)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除文件失败!", zap.Error(err))
|
||||
response.FailWithMsg("删除文件失败!", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("删除文件成功!", c)
|
||||
}
|
||||
|
||||
// GetFileList
|
||||
// @tags 文件相关
|
||||
// @Summary 文件列表
|
||||
// @Security ApiKeyAuth
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body sysReq.GetOssFileList true "文件列表"
|
||||
// @Success 200 {object} response.Response{data=string} "文件列表"
|
||||
// @router /oss/getFileList [post]
|
||||
func (o *OssApi) GetFileList(c *gin.Context) {
|
||||
var pageInfo sysReq.GetOssFileList
|
||||
err := c.ShouldBindJSON(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := ossService.GetFileList(pageInfo)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取文件列表失败!", zap.Error(err))
|
||||
response.FailWithMsg("获取文件列表失败!", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Current,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// Detail
|
||||
// @tags 文件相关
|
||||
// @Summary 文件详情
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param id query string true "文件id"
|
||||
// @Success 200 {object} response.Response{data=string} "文件详情"
|
||||
// @router /oss/detail [get]
|
||||
func (o *OssApi) Detail(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
file, err := ossService.GetById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取文件详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(file, c)
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
systemReq "sundynix-go/model/system/request"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type ClientApi struct {
|
||||
}
|
||||
|
||||
// SaveClient
|
||||
// @Tags 客户端管理
|
||||
// @Summary 创建client
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.Client true "client"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建client"
|
||||
// @Router /client/save [post]
|
||||
func (s *ClientApi) SaveClient(c *gin.Context) {
|
||||
var client system.Client
|
||||
err := c.ShouldBindJSON(&client)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = clientService.SaveClient(client)
|
||||
if err != nil {
|
||||
global.Logger.Error("保存客户端失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("保存客户端成功!", c)
|
||||
}
|
||||
|
||||
// UpdateClient
|
||||
// @Tags 客户端管理
|
||||
// @Summary 更新client
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.Client true "client"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新client"
|
||||
// @Router /client/update [post]
|
||||
func (s *ClientApi) UpdateClient(c *gin.Context) {
|
||||
var client system.Client
|
||||
err := c.ShouldBindJSON(&client)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = clientService.UpdateClient(client)
|
||||
if err != nil {
|
||||
global.Logger.Error("更新客户端失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("更新客户端成功!", c)
|
||||
}
|
||||
|
||||
// GetClientList
|
||||
// @Tags 客户端管理
|
||||
// @Summary 获取client列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.GetClientList true "client"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取client列表"
|
||||
// @Router /client/getClientList [post]
|
||||
func (s *ClientApi) GetClientList(c *gin.Context) {
|
||||
var pageInfo systemReq.GetClientList
|
||||
err := c.ShouldBindJSON(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := clientService.GetClientList(pageInfo)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取客户端列表失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Current,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// Delete
|
||||
// @Tags 客户端管理
|
||||
// @Summary 删除client
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "ids"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除client"
|
||||
// @Router /client/delete [post]
|
||||
func (s *ClientApi) Delete(c *gin.Context) {
|
||||
var ids request.IdsReq
|
||||
err := c.ShouldBindJSON(&ids)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = clientService.DeleteClientByIds(ids)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除客户端失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("删除客户端成功!", c)
|
||||
}
|
||||
|
||||
// Detail
|
||||
// @Tags 客户端管理
|
||||
// @Summary 获取client详情
|
||||
// @Description id获取详情
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param id query string true "id"
|
||||
// @Success 200 {object} response.Response{data=system.Client,msg=string} "获取client详情"
|
||||
// @Router /client/detail [get]
|
||||
func (s *ClientApi) Detail(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
client, err := clientService.GetClientById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取客户端详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(client, c)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
systemReq "sundynix-go/model/system/request"
|
||||
"sundynix-go/utils/auth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MenuApi struct {
|
||||
}
|
||||
|
||||
// SaveMenu
|
||||
// @Tags 菜单管理
|
||||
// @Summary 新增菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.Menu false "menu"
|
||||
// @Success 200 {object} response.Response{msg=string} "新建菜单/按钮"
|
||||
// @Router /menu/save [post]
|
||||
func (m *MenuApi) SaveMenu(c *gin.Context) {
|
||||
var menu system.Menu
|
||||
err := c.ShouldBindJSON(&menu)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err = menuService.SaveMenu(menu); err != nil {
|
||||
global.Logger.Error("保存菜单失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
} else {
|
||||
response.OkWithMsg("保存菜单成功!", c)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateMenu
|
||||
// @Tags 菜单管理
|
||||
// @Summary 更新菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.Menu false "menu"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新菜单"
|
||||
// @Router /menu/update [post]
|
||||
func (m *MenuApi) UpdateMenu(c *gin.Context) {
|
||||
var menu system.Menu
|
||||
err := c.ShouldBindJSON(&menu)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err = menuService.UpdateMenu(&menu); err != nil {
|
||||
global.Logger.Error("更新菜单失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
} else {
|
||||
response.OkWithMsg("更新菜单成功!", c)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteMenu
|
||||
// @Tags 菜单管理
|
||||
// @Summary 删除menu
|
||||
// @Description 删除menu
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param id query string true "id"
|
||||
// @Success 200 {object} response.Response{msg=string} "详情"
|
||||
// @Router /menu/delete [get]
|
||||
func (m *MenuApi) DeleteMenu(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
err := menuService.DeleteMenu(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除菜单失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("删除菜单成功!", c)
|
||||
}
|
||||
|
||||
// Detail
|
||||
// @Tags 菜单管理
|
||||
// @Summary 获取menu详情
|
||||
// @Description id获取详情
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param id query string true "id"
|
||||
// @Success 200 {object} response.Response{data=system.Menu,msg=string} "详情"
|
||||
// @Router /menu/detail [get]
|
||||
func (m *MenuApi) Detail(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
menu, err := menuService.GetMenuById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取菜单详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(menu, c)
|
||||
}
|
||||
|
||||
// GetAllMenuTree
|
||||
// @Tags 菜单管理
|
||||
// @Summary 获取所有菜单树
|
||||
// @Security ApiKeyAuth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param data body systemReq.GetMenuTree true "菜单信息"
|
||||
// @Success 200 {object} response.Response{data=[]system.Menu,msg=string} "获取所有菜单树"
|
||||
// @Router /menu/getAllMenuTree [post]
|
||||
func (m *MenuApi) GetAllMenuTree(c *gin.Context) {
|
||||
var param systemReq.GetMenuTree
|
||||
err := c.ShouldBindJSON(¶m)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
menus, err := menuService.GetAllMenuTree(param.Category, param.ParentId)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取菜单树结构失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(menus, c)
|
||||
}
|
||||
|
||||
// GetUserMenuTree
|
||||
// @Tags 菜单管理
|
||||
// @Summary 用户菜单数据
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.Response{data=[]system.Menu,msg=string} "用户菜单数据"
|
||||
// @Router /menu/getUserMenuTree [get]
|
||||
func (m *MenuApi) GetUserMenuTree(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
routes, err := menuService.GetUserRoutes(userId)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取用户菜单失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(routes, c)
|
||||
}
|
||||
|
||||
// Route
|
||||
// @Tags 菜单管理
|
||||
// @Summary 用户路由
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.Response{data=[]system.Menu,msg=string} "用户route"
|
||||
// @Router /menu/route [get]
|
||||
func (m *MenuApi) Route(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
routes, err := menuService.GetUserRoutes(userId)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取用户菜单失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(routes, c)
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
systemReq "sundynix-go/model/system/request"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type OperationRecordApi struct {
|
||||
}
|
||||
|
||||
func (s *OperationRecordApi) CreateOperationRecord(c *gin.Context) {
|
||||
var sysOperationRecord system.SysOperationRecord
|
||||
err := c.ShouldBindJSON(&sysOperationRecord)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = operationRecordService.CreateOperationRecord(sysOperationRecord)
|
||||
if err != nil {
|
||||
global.Logger.Error("创建操作记录失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("创建操作记录成功!", c)
|
||||
}
|
||||
|
||||
func (s *OperationRecordApi) GetRecordList(c *gin.Context) {
|
||||
var pageInfo systemReq.GetOperationRecordList
|
||||
err := c.ShouldBindJSON(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := operationRecordService.GetRecordList(pageInfo)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取操作记录列表失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Current,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}
|
||||
|
||||
func (s *OperationRecordApi) GetRecordById(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
record, err := operationRecordService.GetRecordById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取操作记录详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(record, c)
|
||||
}
|
||||
|
||||
func (s *OperationRecordApi) DeleteRecordsByIds(c *gin.Context) {
|
||||
var ids request.IdsReq
|
||||
err := c.ShouldBindJSON(&ids)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = operationRecordService.DeleteRecordsByIds(ids)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除操作记录失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("删除操作记录成功!", c)
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
systemreq "sundynix-go/model/system/request"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type RoleApi struct {
|
||||
}
|
||||
|
||||
// SaveRole
|
||||
// @tags 角色管理
|
||||
// @Summary 创建角色
|
||||
// @Security ApiKeyAuth
|
||||
// @accept json
|
||||
// @Produce json
|
||||
// @Param data body system.Role true "角色信息"
|
||||
// @Success 200 {object} response.Response
|
||||
// @Router /role/save [post]
|
||||
func (a *RoleApi) SaveRole(context *gin.Context) {
|
||||
var role system.Role
|
||||
err := context.ShouldBindJSON(&role)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误"+err.Error(), context)
|
||||
return
|
||||
}
|
||||
err = roleService.SaveRole(role)
|
||||
if err != nil {
|
||||
global.Logger.Error("保存角色失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("保存角色成功!", context)
|
||||
}
|
||||
|
||||
// UpdateRole
|
||||
// @tags 角色管理
|
||||
// @Summary 修改角色
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.Role true "角色ID"
|
||||
// @Success 200 {object} response.Response"
|
||||
// @Router /role/update [post]
|
||||
func (a *RoleApi) UpdateRole(context *gin.Context) {
|
||||
var role system.Role
|
||||
err := context.ShouldBindJSON(&role)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
return
|
||||
}
|
||||
err = roleService.UpdateRole(role)
|
||||
if err != nil {
|
||||
global.Logger.Error("更新角色失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("更新角色成功!", context)
|
||||
}
|
||||
|
||||
// GetRoleList
|
||||
// @tags 角色管理
|
||||
// @Summary 获取角色列表
|
||||
// @Description 获取角色列表
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body systemreq.GetRoleList true "页码, 每页大小, 搜索条件"
|
||||
// @success 200 {object} response.Response{data=response.PageResult,msg=string} "获取角色列表,返回包括列表,总数,页码,每页大小"
|
||||
// @Router /role/getRoleList [post]
|
||||
func (a *RoleApi) GetRoleList(c *gin.Context) {
|
||||
var pageInfo systemreq.GetRoleList
|
||||
err := c.ShouldBindJSON(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := roleService.GetRoleList(pageInfo)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取角色列表失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
}
|
||||
response.OkWithData(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Current,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// Delete
|
||||
// @Tags 角色管理
|
||||
// @Summary 删除角色
|
||||
// @Description 删除角色
|
||||
// @Accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除角色"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除角色"
|
||||
// @Router /role/delete [post]
|
||||
func (a *RoleApi) Delete(context *gin.Context) {
|
||||
var ids request.IdsReq
|
||||
err := context.ShouldBindJSON(&ids)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
return
|
||||
}
|
||||
err = roleService.DeleteRoleByIds(ids)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除角色失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("删除角色成功!", context)
|
||||
}
|
||||
|
||||
// Detail
|
||||
// @Tags 角色管理
|
||||
// @Summary 角色详情
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param id query string true "id"
|
||||
// @Success 200 {object} response.Response{data=system.Role} "角色详情"
|
||||
// @Router /role/detail [get]
|
||||
func (a *RoleApi) Detail(context *gin.Context) {
|
||||
id := context.Query("id")
|
||||
role, err := roleService.GetRoleById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取角色详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), context)
|
||||
return
|
||||
}
|
||||
response.OkWithData(role, context)
|
||||
}
|
||||
|
||||
// GrantMenu
|
||||
// @tags 角色管理
|
||||
// @Summary 授权菜单给角色
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body systemreq.GrantMenu true "授权菜单给角色"
|
||||
// @success 200 {object} response.Response "授权菜单给角色"
|
||||
// @Router /role/grantMenu [post]
|
||||
func (a *RoleApi) GrantMenu(c *gin.Context) {
|
||||
var grantMenu systemreq.GrantMenu
|
||||
err := c.ShouldBindJSON(&grantMenu)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = roleService.GrantMenu(grantMenu.RoleId, grantMenu.MenuIds)
|
||||
if err != nil {
|
||||
global.Logger.Error("授权菜单失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("授权菜单成功!", c)
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/commom/request"
|
||||
"sundynix-go/model/commom/response"
|
||||
"sundynix-go/model/system"
|
||||
systemReq "sundynix-go/model/system/request"
|
||||
"sundynix-go/utils/auth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type UserApi struct {
|
||||
}
|
||||
|
||||
// CurrentUser
|
||||
// @tags 用户管理
|
||||
// @Summary 当前登录用户
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.Response "{"code": 200, "data": {}, "msg": "添加成功"}"
|
||||
// @Router /user/info [get]
|
||||
func (u *UserApi) CurrentUser(c *gin.Context) {
|
||||
userId := auth.GetUserId(c)
|
||||
user, err := userService.GetUserById(userId)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取用户信息失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(user, c)
|
||||
}
|
||||
|
||||
// SaveUser
|
||||
// @tags 用户管理
|
||||
// @Summary 新增用户
|
||||
// @Security ApiKeyAuth
|
||||
// @accept json
|
||||
// @Produce json
|
||||
// @Param data body system.User true "用户信息"
|
||||
// @Success 200 {object} response.Response "{"code": 200, "data": {}, "msg": "添加成功"}"
|
||||
// @Router /user/save [post]
|
||||
func (u *UserApi) SaveUser(c *gin.Context) {
|
||||
var user system.User
|
||||
err := c.ShouldBindJSON(&user)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err = userService.SaveUser(user); err != nil {
|
||||
global.Logger.Error("保存用户失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
} else {
|
||||
response.OkWithMsg("保存用户成功!", c)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateUser
|
||||
// @tags 用户管理
|
||||
// @Summary 更新用户
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.User true "用户ID,用户信息"
|
||||
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
|
||||
// @Router /user/update [post]
|
||||
func (u *UserApi) UpdateUser(c *gin.Context) {
|
||||
var user system.User
|
||||
err := c.ShouldBindJSON(&user)
|
||||
if err != nil {
|
||||
response.FailWithMsg("参数错误:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err = userService.UpdateUser(&user); err != nil {
|
||||
global.Logger.Error("更新用户失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
} else {
|
||||
response.OkWithMsg("更新用户成功!", c)
|
||||
}
|
||||
}
|
||||
|
||||
// GetUserList
|
||||
// @tags 用户管理
|
||||
// @Summary 获取用户列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.GetUserList true "页码, 每页大小, 搜索条件"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取用户列表,返回包括列表,总数,页码,每页大小"
|
||||
// @Router /user/getUserList [post]
|
||||
func (u *UserApi) GetUserList(c *gin.Context) {
|
||||
var pageInfo systemReq.GetUserList
|
||||
err := c.ShouldBindJSON(&pageInfo)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
list, total, err := userService.GetUserList(pageInfo)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取用户列表失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(response.PageResult{
|
||||
List: list,
|
||||
Total: total,
|
||||
Page: pageInfo.Current,
|
||||
PageSize: pageInfo.PageSize,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// Delete
|
||||
// @Tags 用户管理
|
||||
// @Summary 删除用户
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.IdsReq true "批量删除用户"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除用户"
|
||||
// @Router /user/delete [post]
|
||||
func (u *UserApi) Delete(c *gin.Context) {
|
||||
var ids request.IdsReq
|
||||
err := c.ShouldBindJSON(&ids)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = userService.DeleteUserByIds(ids)
|
||||
if err != nil {
|
||||
global.Logger.Error("删除用户失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("删除用户成功!", c)
|
||||
}
|
||||
|
||||
// Detail
|
||||
// @Tags 用户管理
|
||||
// @Summary 获取用户详情
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param id query string true "id"
|
||||
// @Success 200 {object} response.Response{data=system.User} "获取用户详情成功"
|
||||
// @Router /user/detail [get]
|
||||
func (u *UserApi) Detail(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
user, err := userService.GetUserById(id)
|
||||
if err != nil {
|
||||
global.Logger.Error("获取用户详情失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(user, c)
|
||||
}
|
||||
|
||||
// ChangePassword
|
||||
// @Tags 用户管理
|
||||
// @Summary 修改密码
|
||||
// @Security ApiKeyAuth
|
||||
// @Description 修改密码
|
||||
// @accept json
|
||||
// @Produce application/json
|
||||
// @Param data body request.ChangePwd true "用户id"
|
||||
// @Success 200 {object} response.Response{data=system.User} "修改密码成功"
|
||||
// @Router /user/changePassword [post]
|
||||
func (u *UserApi) ChangePassword(c *gin.Context) {
|
||||
var changePwd systemReq.ChangePwd
|
||||
err := c.ShouldBindJSON(&changePwd)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = userService.ChangePassword(changePwd.Id, changePwd.NewPwd)
|
||||
if err != nil {
|
||||
global.Logger.Error("修改密码失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("修改密码成功", c)
|
||||
}
|
||||
|
||||
// GrantRole
|
||||
// @Tags 用户管理
|
||||
// @Summary 给用户分配角色
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body systemReq.GrantRole true "用户ID, 角色ID"
|
||||
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
|
||||
// @Router /user/grantRole [post]
|
||||
func (u *UserApi) GrantRole(c *gin.Context) {
|
||||
var grantRole systemReq.GrantRole
|
||||
err := c.ShouldBindJSON(&grantRole)
|
||||
if err != nil {
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = roleService.GrantRole(grantRole.UserId, grantRole.RoleIds)
|
||||
if err != nil {
|
||||
global.Logger.Error("授权角色失败!", zap.Error(err))
|
||||
response.FailWithMsg(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMsg("授权角色成功!", c)
|
||||
}
|
||||
Reference in New Issue
Block a user