Fixed: c.ShouldBindXXX 未错误处理 #1224 (#1229)

* Fixed: c.ShouldBindXXX 未错误处理 #1224
- api层错误处理以及代码格式统一化
* Update: 代码生成器 api.go ShouldBindXxx 错误处理
This commit is contained in:
SliverHorn
2022-09-25 13:23:44 +08:00
committed by GitHub
parent a7715648d0
commit 2d4b16db46
26 changed files with 3151 additions and 2560 deletions
@@ -16,14 +16,15 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
// @Tags ExaFileUploadAndDownload // BreakpointContinue
// @Summary 断点续传到服务器 // @Tags ExaFileUploadAndDownload
// @Security ApiKeyAuth // @Summary 断点续传到服务器
// @accept multipart/form-data // @Security ApiKeyAuth
// @Produce application/json // @accept multipart/form-data
// @Param file formData file true "an example for breakpoint resume, 断点续传示例" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "断点续传到服务器" // @Param file formData file true "an example for breakpoint resume, 断点续传示例"
// @Router /fileUploadAndDownload/breakpointContinue [post] // @Success 200 {object} response.Response{msg=string} "断点续传到服务器"
// @Router /fileUploadAndDownload/breakpointContinue [post]
func (b *FileUploadAndDownloadApi) BreakpointContinue(c *gin.Context) { func (b *FileUploadAndDownloadApi) BreakpointContinue(c *gin.Context) {
fileMd5 := c.Request.FormValue("fileMd5") fileMd5 := c.Request.FormValue("fileMd5")
fileName := c.Request.FormValue("fileName") fileName := c.Request.FormValue("fileName")
@@ -75,14 +76,15 @@ func (b *FileUploadAndDownloadApi) BreakpointContinue(c *gin.Context) {
response.OkWithMessage("切片创建成功", c) response.OkWithMessage("切片创建成功", c)
} }
// @Tags ExaFileUploadAndDownload // FindFile
// @Summary 查找文件 // @Tags ExaFileUploadAndDownload
// @Security ApiKeyAuth // @Summary 查找文件
// @accept multipart/form-data // @Security ApiKeyAuth
// @Produce application/json // @accept multipart/form-data
// @Param file formData file true "Find the file, 查找文件" // @Produce application/json
// @Success 200 {object} response.Response{data=exampleRes.FileResponse,msg=string} "查找文件,返回包括文件详情" // @Param file formData file true "Find the file, 查找文件"
// @Router /fileUploadAndDownload/findFile [post] // @Success 200 {object} response.Response{data=exampleRes.FileResponse,msg=string} "查找文件,返回包括文件详情"
// @Router /fileUploadAndDownload/findFile [post]
func (b *FileUploadAndDownloadApi) FindFile(c *gin.Context) { func (b *FileUploadAndDownloadApi) FindFile(c *gin.Context) {
fileMd5 := c.Query("fileMd5") fileMd5 := c.Query("fileMd5")
fileName := c.Query("fileName") fileName := c.Query("fileName")
@@ -96,14 +98,15 @@ func (b *FileUploadAndDownloadApi) FindFile(c *gin.Context) {
} }
} }
// @Tags ExaFileUploadAndDownload // BreakpointContinueFinish
// @Summary 创建文件 // @Tags ExaFileUploadAndDownload
// @Security ApiKeyAuth // @Summary 创建文件
// @accept multipart/form-data // @Security ApiKeyAuth
// @Produce application/json // @accept multipart/form-data
// @Param file formData file true "上传文件完成" // @Produce application/json
// @Success 200 {object} response.Response{data=exampleRes.FilePathResponse,msg=string} "创建文件,返回包括文件路径" // @Param file formData file true "上传文件完成"
// @Router /fileUploadAndDownload/findFile [post] // @Success 200 {object} response.Response{data=exampleRes.FilePathResponse,msg=string} "创建文件,返回包括文件路径"
// @Router /fileUploadAndDownload/findFile [post]
func (b *FileUploadAndDownloadApi) BreakpointContinueFinish(c *gin.Context) { func (b *FileUploadAndDownloadApi) BreakpointContinueFinish(c *gin.Context) {
fileMd5 := c.Query("fileMd5") fileMd5 := c.Query("fileMd5")
fileName := c.Query("fileName") fileName := c.Query("fileName")
@@ -116,18 +119,23 @@ func (b *FileUploadAndDownloadApi) BreakpointContinueFinish(c *gin.Context) {
} }
} }
// @Tags ExaFileUploadAndDownload // RemoveChunk
// @Summary 删除切片 // @Tags ExaFileUploadAndDownload
// @Security ApiKeyAuth // @Summary 删除切片
// @accept multipart/form-data // @Security ApiKeyAuth
// @Produce application/json // @accept multipart/form-data
// @Param file formData file true "删除缓存切片" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "删除切片" // @Param file formData file true "删除缓存切片"
// @Router /fileUploadAndDownload/removeChunk [post] // @Success 200 {object} response.Response{msg=string} "删除切片"
// @Router /fileUploadAndDownload/removeChunk [post]
func (b *FileUploadAndDownloadApi) RemoveChunk(c *gin.Context) { func (b *FileUploadAndDownloadApi) RemoveChunk(c *gin.Context) {
var file example.ExaFile var file example.ExaFile
_ = c.ShouldBindJSON(&file) err := c.ShouldBindJSON(&file)
err := utils.RemoveChunk(file.FileMd5) if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.RemoveChunk(file.FileMd5)
if err != nil { if err != nil {
global.GVA_LOG.Error("缓存切片删除失败!", zap.Error(err)) global.GVA_LOG.Error("缓存切片删除失败!", zap.Error(err))
return return
@@ -136,7 +144,7 @@ func (b *FileUploadAndDownloadApi) RemoveChunk(c *gin.Context) {
if err != nil { if err != nil {
global.GVA_LOG.Error(err.Error(), zap.Error(err)) global.GVA_LOG.Error(err.Error(), zap.Error(err))
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
} else { return
response.OkWithMessage("缓存切片删除成功", c)
} }
response.OkWithMessage("缓存切片删除成功", c)
} }
+103 -69
View File
@@ -13,93 +13,121 @@ import (
type CustomerApi struct{} type CustomerApi struct{}
// @Tags ExaCustomer // CreateExaCustomer
// @Summary 创建客户 // @Tags ExaCustomer
// @Security ApiKeyAuth // @Summary 创建客户
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body example.ExaCustomer true "客户用户名, 客户手机号码" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "创建客户" // @Param data body example.ExaCustomer true "客户用户名, 客户手机号码"
// @Router /customer/customer [post] // @Success 200 {object} response.Response{msg=string} "创建客户"
// @Router /customer/customer [post]
func (e *CustomerApi) CreateExaCustomer(c *gin.Context) { func (e *CustomerApi) CreateExaCustomer(c *gin.Context) {
var customer example.ExaCustomer var customer example.ExaCustomer
_ = c.ShouldBindJSON(&customer) err := c.ShouldBindJSON(&customer)
if err := utils.Verify(customer, utils.CustomerVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(customer, utils.CustomerVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
customer.SysUserID = utils.GetUserID(c) customer.SysUserID = utils.GetUserID(c)
customer.SysUserAuthorityID = utils.GetUserAuthorityId(c) customer.SysUserAuthorityID = utils.GetUserAuthorityId(c)
if err := customerService.CreateExaCustomer(customer); err != nil { err = customerService.CreateExaCustomer(customer)
if err != nil {
global.GVA_LOG.Error("创建失败!", zap.Error(err)) global.GVA_LOG.Error("创建失败!", zap.Error(err))
response.FailWithMessage("创建失败", c) response.FailWithMessage("创建失败", c)
} else { return
response.OkWithMessage("创建成功", c)
} }
response.OkWithMessage("创建成功", c)
} }
// @Tags ExaCustomer // DeleteExaCustomer
// @Summary 删除客户 // @Tags ExaCustomer
// @Security ApiKeyAuth // @Summary 删除客户
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body example.ExaCustomer true "客户ID" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "删除客户" // @Param data body example.ExaCustomer true "客户ID"
// @Router /customer/customer [delete] // @Success 200 {object} response.Response{msg=string} "删除客户"
// @Router /customer/customer [delete]
func (e *CustomerApi) DeleteExaCustomer(c *gin.Context) { func (e *CustomerApi) DeleteExaCustomer(c *gin.Context) {
var customer example.ExaCustomer var customer example.ExaCustomer
_ = c.ShouldBindJSON(&customer) err := c.ShouldBindJSON(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := customerService.DeleteExaCustomer(customer); err != nil { err = utils.Verify(customer.GVA_MODEL, utils.IdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = customerService.DeleteExaCustomer(customer)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err)) global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c) response.FailWithMessage("删除失败", c)
} else { return
response.OkWithMessage("删除成功", c)
} }
response.OkWithMessage("删除成功", c)
} }
// @Tags ExaCustomer // UpdateExaCustomer
// @Summary 更新客户信息 // @Tags ExaCustomer
// @Security ApiKeyAuth // @Summary 更新客户信息
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body example.ExaCustomer true "客户ID, 客户信息" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "更新客户信息" // @Param data body example.ExaCustomer true "客户ID, 客户信息"
// @Router /customer/customer [put] // @Success 200 {object} response.Response{msg=string} "更新客户信息"
// @Router /customer/customer [put]
func (e *CustomerApi) UpdateExaCustomer(c *gin.Context) { func (e *CustomerApi) UpdateExaCustomer(c *gin.Context) {
var customer example.ExaCustomer var customer example.ExaCustomer
_ = c.ShouldBindJSON(&customer) err := c.ShouldBindJSON(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := utils.Verify(customer, utils.CustomerVerify); err != nil { err = utils.Verify(customer.GVA_MODEL, utils.IdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := customerService.UpdateExaCustomer(&customer); err != nil { err = utils.Verify(customer, utils.CustomerVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = customerService.UpdateExaCustomer(&customer)
if err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err)) global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c) response.FailWithMessage("更新失败", c)
} else { return
response.OkWithMessage("更新成功", c)
} }
response.OkWithMessage("更新成功", c)
} }
// @Tags ExaCustomer // GetExaCustomer
// @Summary 获取单一客户信息 // @Tags ExaCustomer
// @Security ApiKeyAuth // @Summary 获取单一客户信息
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data query example.ExaCustomer true "客户ID" // @Produce application/json
// @Success 200 {object} response.Response{data=exampleRes.ExaCustomerResponse,msg=string} "获取单一客户信息,返回包括客户详情" // @Param data query example.ExaCustomer true "客户ID"
// @Router /customer/customer [get] // @Success 200 {object} response.Response{data=exampleRes.ExaCustomerResponse,msg=string} "获取单一客户信息,返回包括客户详情"
// @Router /customer/customer [get]
func (e *CustomerApi) GetExaCustomer(c *gin.Context) { func (e *CustomerApi) GetExaCustomer(c *gin.Context) {
var customer example.ExaCustomer var customer example.ExaCustomer
_ = c.ShouldBindQuery(&customer) err := c.ShouldBindQuery(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(customer.GVA_MODEL, utils.IdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
@@ -107,23 +135,29 @@ func (e *CustomerApi) GetExaCustomer(c *gin.Context) {
if err != nil { if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(exampleRes.ExaCustomerResponse{Customer: data}, "获取成功", c)
} }
response.OkWithDetailed(exampleRes.ExaCustomerResponse{Customer: data}, "获取成功", c)
} }
// @Tags ExaCustomer // GetExaCustomerList
// @Summary 分页获取权限客户列表 // @Tags ExaCustomer
// @Security ApiKeyAuth // @Summary 分页获取权限客户列表
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data query request.PageInfo true "页码, 每页大小" // @Produce application/json
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取权限客户列表,返回包括列表,总数,页码,每页数量" // @Param data query request.PageInfo true "页码, 每页大小"
// @Router /customer/customerList [get] // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取权限客户列表,返回包括列表,总数,页码,每页数量"
// @Router /customer/customerList [get]
func (e *CustomerApi) GetExaCustomerList(c *gin.Context) { func (e *CustomerApi) GetExaCustomerList(c *gin.Context) {
var pageInfo request.PageInfo var pageInfo request.PageInfo
_ = c.ShouldBindQuery(&pageInfo) err := c.ShouldBindQuery(&pageInfo)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(pageInfo, utils.PageInfoVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
@@ -131,12 +165,12 @@ func (e *CustomerApi) GetExaCustomerList(c *gin.Context) {
if err != nil { if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败"+err.Error(), c) response.FailWithMessage("获取失败"+err.Error(), c)
} else { return
response.OkWithDetailed(response.PageResult{
List: customerList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
response.OkWithDetailed(response.PageResult{
List: customerList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
+40 -32
View File
@@ -18,23 +18,28 @@ type ExcelApi struct{}
// /excel/exportExcel 接口,用于读取前端传来的tableData,生成Excel文件并返回 // /excel/exportExcel 接口,用于读取前端传来的tableData,生成Excel文件并返回
// /excel/downloadTemplate 接口,用于下载resource/excel目录下的 ExcelTemplate.xlsx 文件,作为导入的模板 // /excel/downloadTemplate 接口,用于下载resource/excel目录下的 ExcelTemplate.xlsx 文件,作为导入的模板
// @Tags excel // ExportExcel
// @Summary 导出Excel // @Tags excel
// @Security ApiKeyAuth // @Summary 导出Excel
// @accept application/json // @Security ApiKeyAuth
// @Produce application/octet-stream // @accept application/json
// @Param data body example.ExcelInfo true "导出Excel文件信息" // @Produce application/octet-stream
// @Success 200 // @Param data body example.ExcelInfo true "导出Excel文件信息"
// @Router /excel/exportExcel [post] // @Success 200
// @Router /excel/exportExcel [post]
func (e *ExcelApi) ExportExcel(c *gin.Context) { func (e *ExcelApi) ExportExcel(c *gin.Context) {
var excelInfo example.ExcelInfo var excelInfo example.ExcelInfo
_ = c.ShouldBindJSON(&excelInfo) err := c.ShouldBindJSON(&excelInfo)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if strings.Index(excelInfo.FileName, "..") > -1 { if strings.Index(excelInfo.FileName, "..") > -1 {
response.FailWithMessage("包含非法字符", c) response.FailWithMessage("包含非法字符", c)
return return
} }
filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName
err := excelService.ParseInfoList2Excel(excelInfo.InfoList, filePath) err = excelService.ParseInfoList2Excel(excelInfo.InfoList, filePath)
if err != nil { if err != nil {
global.GVA_LOG.Error("转换Excel失败!", zap.Error(err)) global.GVA_LOG.Error("转换Excel失败!", zap.Error(err))
response.FailWithMessage("转换Excel失败", c) response.FailWithMessage("转换Excel失败", c)
@@ -44,14 +49,15 @@ func (e *ExcelApi) ExportExcel(c *gin.Context) {
c.File(filePath) c.File(filePath)
} }
// @Tags excel // ImportExcel
// @Summary 导入Excel文件 // @Tags excel
// @Security ApiKeyAuth // @Summary 导入Excel文件
// @accept multipart/form-data // @Security ApiKeyAuth
// @Produce application/json // @accept multipart/form-data
// @Param file formData file true "导入Excel文件" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "导入Excel文件" // @Param file formData file true "导入Excel文件"
// @Router /excel/importExcel [post] // @Success 200 {object} response.Response{msg=string} "导入Excel文件"
// @Router /excel/importExcel [post]
func (e *ExcelApi) ImportExcel(c *gin.Context) { func (e *ExcelApi) ImportExcel(c *gin.Context) {
_, header, err := c.Request.FormFile("file") _, header, err := c.Request.FormFile("file")
if err != nil { if err != nil {
@@ -63,12 +69,13 @@ func (e *ExcelApi) ImportExcel(c *gin.Context) {
response.OkWithMessage("导入成功", c) response.OkWithMessage("导入成功", c)
} }
// @Tags excel // LoadExcel
// @Summary 加载Excel数据 // @Tags excel
// @Security ApiKeyAuth // @Summary 加载Excel数据
// @Produce application/json // @Security ApiKeyAuth
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "加载Excel数据,返回包括列表,总数,页码,每页数量" // @Produce application/json
// @Router /excel/loadExcel [get] // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "加载Excel数据,返回包括列表,总数,页码,每页数量"
// @Router /excel/loadExcel [get]
func (e *ExcelApi) LoadExcel(c *gin.Context) { func (e *ExcelApi) LoadExcel(c *gin.Context) {
menus, err := excelService.ParseExcel2InfoList() menus, err := excelService.ParseExcel2InfoList()
if err != nil { if err != nil {
@@ -84,14 +91,15 @@ func (e *ExcelApi) LoadExcel(c *gin.Context) {
}, "加载数据成功", c) }, "加载数据成功", c)
} }
// @Tags excel // DownloadTemplate
// @Summary 下载模板 // @Tags excel
// @Security ApiKeyAuth // @Summary 下载模板
// @accept multipart/form-data // @Security ApiKeyAuth
// @Produce application/json // @accept multipart/form-data
// @Param fileName query string true "模板名称" // @Produce application/json
// @Success 200 // @Param fileName query string true "模板名称"
// @Router /excel/downloadTemplate [get] // @Success 200
// @Router /excel/downloadTemplate [get]
func (e *ExcelApi) DownloadTemplate(c *gin.Context) { func (e *ExcelApi) DownloadTemplate(c *gin.Context) {
fileName := c.Query("fileName") fileName := c.Query("fileName")
filePath := global.GVA_CONFIG.Excel.Dir + fileName filePath := global.GVA_CONFIG.Excel.Dir + fileName
@@ -12,14 +12,15 @@ import (
type FileUploadAndDownloadApi struct{} type FileUploadAndDownloadApi struct{}
// @Tags ExaFileUploadAndDownload // UploadFile
// @Summary 上传文件示例 // @Tags ExaFileUploadAndDownload
// @Security ApiKeyAuth // @Summary 上传文件示例
// @accept multipart/form-data // @Security ApiKeyAuth
// @Produce application/json // @accept multipart/form-data
// @Param file formData file true "上传文件示例" // @Produce application/json
// @Success 200 {object} response.Response{data=exampleRes.ExaFileResponse,msg=string} "上传文件示例,返回包括文件详情" // @Param file formData file true "上传文件示例"
// @Router /fileUploadAndDownload/upload [post] // @Success 200 {object} response.Response{data=exampleRes.ExaFileResponse,msg=string} "上传文件示例,返回包括文件详情"
// @Router /fileUploadAndDownload/upload [post]
func (b *FileUploadAndDownloadApi) UploadFile(c *gin.Context) { func (b *FileUploadAndDownloadApi) UploadFile(c *gin.Context) {
var file example.ExaFileUploadAndDownload var file example.ExaFileUploadAndDownload
noSave := c.DefaultQuery("noSave", "0") noSave := c.DefaultQuery("noSave", "0")
@@ -41,8 +42,13 @@ func (b *FileUploadAndDownloadApi) UploadFile(c *gin.Context) {
// EditFileName 编辑文件名或者备注 // EditFileName 编辑文件名或者备注
func (b *FileUploadAndDownloadApi) EditFileName(c *gin.Context) { func (b *FileUploadAndDownloadApi) EditFileName(c *gin.Context) {
var file example.ExaFileUploadAndDownload var file example.ExaFileUploadAndDownload
_ = c.ShouldBindJSON(&file) err := c.ShouldBindJSON(&file)
if err := fileUploadAndDownloadService.EditFileName(file); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = fileUploadAndDownloadService.EditFileName(file)
if err != nil {
global.GVA_LOG.Error("编辑失败!", zap.Error(err)) global.GVA_LOG.Error("编辑失败!", zap.Error(err))
response.FailWithMessage("编辑失败", c) response.FailWithMessage("编辑失败", c)
return return
@@ -50,16 +56,21 @@ func (b *FileUploadAndDownloadApi) EditFileName(c *gin.Context) {
response.OkWithMessage("编辑成功", c) response.OkWithMessage("编辑成功", c)
} }
// @Tags ExaFileUploadAndDownload // DeleteFile
// @Summary 删除文件 // @Tags ExaFileUploadAndDownload
// @Security ApiKeyAuth // @Summary 删除文件
// @Produce application/json // @Security ApiKeyAuth
// @Param data body example.ExaFileUploadAndDownload true "传入文件里面id即可" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "删除文件" // @Param data body example.ExaFileUploadAndDownload true "传入文件里面id即可"
// @Router /fileUploadAndDownload/deleteFile [post] // @Success 200 {object} response.Response{msg=string} "删除文件"
// @Router /fileUploadAndDownload/deleteFile [post]
func (b *FileUploadAndDownloadApi) DeleteFile(c *gin.Context) { func (b *FileUploadAndDownloadApi) DeleteFile(c *gin.Context) {
var file example.ExaFileUploadAndDownload var file example.ExaFileUploadAndDownload
_ = c.ShouldBindJSON(&file) err := c.ShouldBindJSON(&file)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := fileUploadAndDownloadService.DeleteFile(file); err != nil { if err := fileUploadAndDownloadService.DeleteFile(file); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err)) global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c) response.FailWithMessage("删除失败", c)
@@ -68,27 +79,32 @@ func (b *FileUploadAndDownloadApi) DeleteFile(c *gin.Context) {
response.OkWithMessage("删除成功", c) response.OkWithMessage("删除成功", c)
} }
// @Tags ExaFileUploadAndDownload // GetFileList
// @Summary 分页文件列表 // @Tags ExaFileUploadAndDownload
// @Security ApiKeyAuth // @Summary 分页文件列表
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.PageInfo true "页码, 每页大小" // @Produce application/json
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页文件列表,返回包括列表,总数,页码,每页数量" // @Param data body request.PageInfo true "页码, 每页大小"
// @Router /fileUploadAndDownload/getFileList [post] // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页文件列表,返回包括列表,总数,页码,每页数量"
// @Router /fileUploadAndDownload/getFileList [post]
func (b *FileUploadAndDownloadApi) GetFileList(c *gin.Context) { func (b *FileUploadAndDownloadApi) GetFileList(c *gin.Context) {
var pageInfo request.PageInfo var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo) err := c.ShouldBindJSON(&pageInfo)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
list, total, err := fileUploadAndDownloadService.GetFileRecordInfoList(pageInfo) list, total, err := fileUploadAndDownloadService.GetFileRecordInfoList(pageInfo)
if err != nil { if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
+124 -87
View File
@@ -15,88 +15,110 @@ import (
type SystemApiApi struct{} type SystemApiApi struct{}
// @Tags SysApi // CreateApi
// @Summary 创建基础api // @Tags SysApi
// @Security ApiKeyAuth // @Summary 创建基础api
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysApi true "api路径, api中文描述, api组, 方法" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "创建基础api" // @Param data body system.SysApi true "api路径, api中文描述, api组, 方法"
// @Router /api/createApi [post] // @Success 200 {object} response.Response{msg=string} "创建基础api"
// @Router /api/createApi [post]
func (s *SystemApiApi) CreateApi(c *gin.Context) { func (s *SystemApiApi) CreateApi(c *gin.Context) {
var api system.SysApi var api system.SysApi
_ = c.ShouldBindJSON(&api) err := c.ShouldBindJSON(&api)
if err := utils.Verify(api, utils.ApiVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := apiService.CreateApi(api); err != nil { err = utils.Verify(api, utils.ApiVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = apiService.CreateApi(api)
if err != nil {
global.GVA_LOG.Error("创建失败!", zap.Error(err)) global.GVA_LOG.Error("创建失败!", zap.Error(err))
response.FailWithMessage("创建失败", c) response.FailWithMessage("创建失败", c)
} else { return
response.OkWithMessage("创建成功", c)
} }
response.OkWithMessage("创建成功", c)
} }
// @Tags SysApi // DeleteApi
// @Summary 删除api // @Tags SysApi
// @Security ApiKeyAuth // @Summary 删除api
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysApi true "ID" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "删除api" // @Param data body system.SysApi true "ID"
// @Router /api/deleteApi [post] // @Success 200 {object} response.Response{msg=string} "删除api"
// @Router /api/deleteApi [post]
func (s *SystemApiApi) DeleteApi(c *gin.Context) { func (s *SystemApiApi) DeleteApi(c *gin.Context) {
var api system.SysApi var api system.SysApi
_ = c.ShouldBindJSON(&api) err := c.ShouldBindJSON(&api)
if err := utils.Verify(api.GVA_MODEL, utils.IdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := apiService.DeleteApi(api); err != nil { err = utils.Verify(api.GVA_MODEL, utils.IdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = apiService.DeleteApi(api)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err)) global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c) response.FailWithMessage("删除失败", c)
} else { return
response.OkWithMessage("删除成功", c)
} }
response.OkWithMessage("删除成功", c)
} }
// @Tags SysApi // GetApiList
// @Summary 分页获取API列表 // @Tags SysApi
// @Security ApiKeyAuth // @Summary 分页获取API列表
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body systemReq.SearchApiParams true "分页获取API列表" // @Produce application/json
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取API列表,返回包括列表,总数,页码,每页数量" // @Param data body systemReq.SearchApiParams true "分页获取API列表"
// @Router /api/getApiList [post] // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取API列表,返回包括列表,总数,页码,每页数量"
// @Router /api/getApiList [post]
func (s *SystemApiApi) GetApiList(c *gin.Context) { func (s *SystemApiApi) GetApiList(c *gin.Context) {
var pageInfo systemReq.SearchApiParams var pageInfo systemReq.SearchApiParams
_ = c.ShouldBindJSON(&pageInfo) err := c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if list, total, err := apiService.GetAPIInfoList(pageInfo.SysApi, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil { err = utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
list, total, err := apiService.GetAPIInfoList(pageInfo.SysApi, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
// @Tags SysApi // GetApiById
// @Summary 根据id获取api // @Tags SysApi
// @Security ApiKeyAuth // @Summary 根据id获取api
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.GetById true "根据id获取api" // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.SysAPIResponse} "根据id获取api,返回包括api详情" // @Param data body request.GetById true "根据id获取api"
// @Router /api/getApiById [post] // @Success 200 {object} response.Response{data=systemRes.SysAPIResponse} "根据id获取api,返回包括api详情"
// @Router /api/getApiById [post]
func (s *SystemApiApi) GetApiById(c *gin.Context) { func (s *SystemApiApi) GetApiById(c *gin.Context) {
var idInfo request.GetById var idInfo request.GetById
_ = c.ShouldBindJSON(&idInfo) _ = c.ShouldBindJSON(&idInfo)
@@ -113,60 +135,75 @@ func (s *SystemApiApi) GetApiById(c *gin.Context) {
} }
} }
// @Tags SysApi // UpdateApi
// @Summary 修改基础api // @Tags SysApi
// @Security ApiKeyAuth // @Summary 修改基础api
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysApi true "api路径, api中文描述, api组, 方法" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "修改基础api" // @Param data body system.SysApi true "api路径, api中文描述, api组, 方法"
// @Router /api/updateApi [post] // @Success 200 {object} response.Response{msg=string} "修改基础api"
// @Router /api/updateApi [post]
func (s *SystemApiApi) UpdateApi(c *gin.Context) { func (s *SystemApiApi) UpdateApi(c *gin.Context) {
var api system.SysApi var api system.SysApi
_ = c.ShouldBindJSON(&api) err := c.ShouldBindJSON(&api)
if err := utils.Verify(api, utils.ApiVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := apiService.UpdateApi(api); err != nil { err = utils.Verify(api, utils.ApiVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = apiService.UpdateApi(api)
if err != nil {
global.GVA_LOG.Error("修改失败!", zap.Error(err)) global.GVA_LOG.Error("修改失败!", zap.Error(err))
response.FailWithMessage("修改失败", c) response.FailWithMessage("修改失败", c)
} else { return
response.OkWithMessage("修改成功", c)
} }
response.OkWithMessage("修改成功", c)
} }
// @Tags SysApi // GetAllApis
// @Summary 获取所有的Api 不分页 // @Tags SysApi
// @Security ApiKeyAuth // @Summary 获取所有的Api 不分页
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Success 200 {object} response.Response{data=systemRes.SysAPIListResponse,msg=string} "获取所有的Api 不分页,返回包括api列表" // @Produce application/json
// @Router /api/getAllApis [post] // @Success 200 {object} response.Response{data=systemRes.SysAPIListResponse,msg=string} "获取所有的Api 不分页,返回包括api列表"
// @Router /api/getAllApis [post]
func (s *SystemApiApi) GetAllApis(c *gin.Context) { func (s *SystemApiApi) GetAllApis(c *gin.Context) {
if apis, err := apiService.GetAllApis(); err != nil { apis, err := apiService.GetAllApis()
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(systemRes.SysAPIListResponse{Apis: apis}, "获取成功", c)
} }
response.OkWithDetailed(systemRes.SysAPIListResponse{Apis: apis}, "获取成功", c)
} }
// @Tags SysApi // DeleteApisByIds
// @Summary 删除选中Api // @Tags SysApi
// @Security ApiKeyAuth // @Summary 删除选中Api
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.IdsReq true "ID" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "删除选中Api" // @Param data body request.IdsReq true "ID"
// @Router /api/deleteApisByIds [delete] // @Success 200 {object} response.Response{msg=string} "删除选中Api"
// @Router /api/deleteApisByIds [delete]
func (s *SystemApiApi) DeleteApisByIds(c *gin.Context) { func (s *SystemApiApi) DeleteApisByIds(c *gin.Context) {
var ids request.IdsReq var ids request.IdsReq
_ = c.ShouldBindJSON(&ids) err := c.ShouldBindJSON(&ids)
if err := apiService.DeleteApisByIds(ids); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = apiService.DeleteApisByIds(ids)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err)) global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c) response.FailWithMessage("删除失败", c)
} else { return
response.OkWithMessage("删除成功", c)
} }
response.OkWithMessage("删除成功", c)
} }
+124 -81
View File
@@ -15,18 +15,25 @@ import (
type AuthorityApi struct{} type AuthorityApi struct{}
// @Tags Authority // CreateAuthority
// @Summary 创建角色 // @Tags Authority
// @Security ApiKeyAuth // @Summary 创建角色
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysAuthority true "权限id, 权限名, 父角色id" // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.SysAuthorityResponse,msg=string} "创建角色,返回包括系统角色详情" // @Param data body system.SysAuthority true "权限id, 权限名, 父角色id"
// @Router /authority/createAuthority [post] // @Success 200 {object} response.Response{data=systemRes.SysAuthorityResponse,msg=string} "创建角色,返回包括系统角色详情"
// @Router /authority/createAuthority [post]
func (a *AuthorityApi) CreateAuthority(c *gin.Context) { func (a *AuthorityApi) CreateAuthority(c *gin.Context) {
var authority system.SysAuthority var authority system.SysAuthority
_ = c.ShouldBindJSON(&authority) err := c.ShouldBindJSON(&authority)
if err := utils.Verify(authority, utils.AuthorityVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(authority, utils.AuthorityVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
@@ -40,126 +47,162 @@ func (a *AuthorityApi) CreateAuthority(c *gin.Context) {
} }
} }
// @Tags Authority // CopyAuthority
// @Summary 拷贝角色 // @Tags Authority
// @Security ApiKeyAuth // @Summary 拷贝角色
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body response.SysAuthorityCopyResponse true "旧角色id, 新权限id, 新权限名, 新父角色id" // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.SysAuthorityResponse,msg=string} "拷贝角色,返回包括系统角色详情" // @Param data body response.SysAuthorityCopyResponse true "旧角色id, 新权限id, 新权限名, 新父角色id"
// @Router /authority/copyAuthority [post] // @Success 200 {object} response.Response{data=systemRes.SysAuthorityResponse,msg=string} "拷贝角色,返回包括系统角色详情"
// @Router /authority/copyAuthority [post]
func (a *AuthorityApi) CopyAuthority(c *gin.Context) { func (a *AuthorityApi) CopyAuthority(c *gin.Context) {
var copyInfo systemRes.SysAuthorityCopyResponse var copyInfo systemRes.SysAuthorityCopyResponse
_ = c.ShouldBindJSON(&copyInfo) err := c.ShouldBindJSON(&copyInfo)
if err := utils.Verify(copyInfo, utils.OldAuthorityVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := utils.Verify(copyInfo.Authority, utils.AuthorityVerify); err != nil { err = utils.Verify(copyInfo, utils.OldAuthorityVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if authBack, err := authorityService.CopyAuthority(copyInfo); err != nil { err = utils.Verify(copyInfo.Authority, utils.AuthorityVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
authBack, err := authorityService.CopyAuthority(copyInfo)
if err != nil {
global.GVA_LOG.Error("拷贝失败!", zap.Error(err)) global.GVA_LOG.Error("拷贝失败!", zap.Error(err))
response.FailWithMessage("拷贝失败"+err.Error(), c) response.FailWithMessage("拷贝失败"+err.Error(), c)
} else { return
response.OkWithDetailed(systemRes.SysAuthorityResponse{Authority: authBack}, "拷贝成功", c)
} }
response.OkWithDetailed(systemRes.SysAuthorityResponse{Authority: authBack}, "拷贝成功", c)
} }
// @Tags Authority // DeleteAuthority
// @Summary 删除角色 // @Tags Authority
// @Security ApiKeyAuth // @Summary 删除角色
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysAuthority true "删除角色" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "删除角色" // @Param data body system.SysAuthority true "删除角色"
// @Router /authority/deleteAuthority [post] // @Success 200 {object} response.Response{msg=string} "删除角色"
// @Router /authority/deleteAuthority [post]
func (a *AuthorityApi) DeleteAuthority(c *gin.Context) { func (a *AuthorityApi) DeleteAuthority(c *gin.Context) {
var authority system.SysAuthority var authority system.SysAuthority
_ = c.ShouldBindJSON(&authority) err := c.ShouldBindJSON(&authority)
if err := utils.Verify(authority, utils.AuthorityIdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := authorityService.DeleteAuthority(&authority); err != nil { // 删除角色之前需要判断是否有用户正在使用此角色 err = utils.Verify(authority, utils.AuthorityIdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = authorityService.DeleteAuthority(&authority)
if err != nil { // 删除角色之前需要判断是否有用户正在使用此角色
global.GVA_LOG.Error("删除失败!", zap.Error(err)) global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败"+err.Error(), c) response.FailWithMessage("删除失败"+err.Error(), c)
} else { return
response.OkWithMessage("删除成功", c)
} }
response.OkWithMessage("删除成功", c)
} }
// @Tags Authority // UpdateAuthority
// @Summary 更新角色信息 // @Tags Authority
// @Security ApiKeyAuth // @Summary 更新角色信息
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysAuthority true "权限id, 权限名, 父角色id" // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.SysAuthorityResponse,msg=string} "更新角色信息,返回包括系统角色详情" // @Param data body system.SysAuthority true "权限id, 权限名, 父角色id"
// @Router /authority/updateAuthority [post] // @Success 200 {object} response.Response{data=systemRes.SysAuthorityResponse,msg=string} "更新角色信息,返回包括系统角色详情"
// @Router /authority/updateAuthority [post]
func (a *AuthorityApi) UpdateAuthority(c *gin.Context) { func (a *AuthorityApi) UpdateAuthority(c *gin.Context) {
var auth system.SysAuthority var auth system.SysAuthority
_ = c.ShouldBindJSON(&auth) err := c.ShouldBindJSON(&auth)
if err := utils.Verify(auth, utils.AuthorityVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if authority, err := authorityService.UpdateAuthority(auth); err != nil { err = utils.Verify(auth, utils.AuthorityVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
authority, err := authorityService.UpdateAuthority(auth)
if err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err)) global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败"+err.Error(), c) response.FailWithMessage("更新失败"+err.Error(), c)
} else { return
response.OkWithDetailed(systemRes.SysAuthorityResponse{Authority: authority}, "更新成功", c)
} }
response.OkWithDetailed(systemRes.SysAuthorityResponse{Authority: authority}, "更新成功", c)
} }
// @Tags Authority // GetAuthorityList
// @Summary 分页获取角色列表 // @Tags Authority
// @Security ApiKeyAuth // @Summary 分页获取角色列表
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.PageInfo true "页码, 每页大小" // @Produce application/json
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取角色列表,返回包括列表,总数,页码,每页数量" // @Param data body request.PageInfo true "页码, 每页大小"
// @Router /authority/getAuthorityList [post] // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取角色列表,返回包括列表,总数,页码,每页数量"
// @Router /authority/getAuthorityList [post]
func (a *AuthorityApi) GetAuthorityList(c *gin.Context) { func (a *AuthorityApi) GetAuthorityList(c *gin.Context) {
var pageInfo request.PageInfo var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo) err := c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if list, total, err := authorityService.GetAuthorityInfoList(pageInfo); err != nil { err = utils.Verify(pageInfo, utils.PageInfoVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
list, total, err := authorityService.GetAuthorityInfoList(pageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败"+err.Error(), c) response.FailWithMessage("获取失败"+err.Error(), c)
} else { return
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
// @Tags Authority // SetDataAuthority
// @Summary 设置角色资源权限 // @Tags Authority
// @Security ApiKeyAuth // @Summary 设置角色资源权限
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysAuthority true "设置角色资源权限" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "设置角色资源权限" // @Param data body system.SysAuthority true "设置角色资源权限"
// @Router /authority/setDataAuthority [post] // @Success 200 {object} response.Response{msg=string} "设置角色资源权限"
// @Router /authority/setDataAuthority [post]
func (a *AuthorityApi) SetDataAuthority(c *gin.Context) { func (a *AuthorityApi) SetDataAuthority(c *gin.Context) {
var auth system.SysAuthority var auth system.SysAuthority
_ = c.ShouldBindJSON(&auth) err := c.ShouldBindJSON(&auth)
if err := utils.Verify(auth, utils.AuthorityIdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := authorityService.SetDataAuthority(auth); err != nil { err = utils.Verify(auth, utils.AuthorityIdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = authorityService.SetDataAuthority(auth)
if err != nil {
global.GVA_LOG.Error("设置失败!", zap.Error(err)) global.GVA_LOG.Error("设置失败!", zap.Error(err))
response.FailWithMessage("设置失败"+err.Error(), c) response.FailWithMessage("设置失败"+err.Error(), c)
} else { return
response.OkWithMessage("设置成功", c)
} }
response.OkWithMessage("设置成功", c)
} }
+44 -34
View File
@@ -10,57 +10,67 @@ import (
type AuthorityBtnApi struct{} type AuthorityBtnApi struct{}
// @Tags AuthorityBtn // GetAuthorityBtn
// @Summary 获取权限按钮 // @Tags AuthorityBtn
// @Security ApiKeyAuth // @Summary 获取权限按钮
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.SysAuthorityBtnReq true "菜单id, 角色id, 选中的按钮id" // @Produce application/json
// @Success 200 {object} response.Response{data=response.SysAuthorityBtnRes,msg=string} "返回列表成功" // @Param data body request.SysAuthorityBtnReq true "菜单id, 角色id, 选中的按钮id"
// @Router /authorityBtn/getAuthorityBtn [post] // @Success 200 {object} response.Response{data=response.SysAuthorityBtnRes,msg=string} "返回列表成功"
// @Router /authorityBtn/getAuthorityBtn [post]
func (a *AuthorityBtnApi) GetAuthorityBtn(c *gin.Context) { func (a *AuthorityBtnApi) GetAuthorityBtn(c *gin.Context) {
var req request.SysAuthorityBtnReq var req request.SysAuthorityBtnReq
_ = c.ShouldBindJSON(&req) err := c.ShouldBindJSON(&req)
if res, err := authorityBtnService.GetAuthorityBtn(req); err != nil { res, err := authorityBtnService.GetAuthorityBtn(req)
if err != nil {
global.GVA_LOG.Error("查询失败!", zap.Error(err)) global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败", c) response.FailWithMessage("查询失败", c)
} else { return
response.OkWithDetailed(res, "查询成功", c)
} }
response.OkWithDetailed(res, "查询成功", c)
} }
// @Tags AuthorityBtn // SetAuthorityBtn
// @Summary 设置权限按钮 // @Tags AuthorityBtn
// @Security ApiKeyAuth // @Summary 设置权限按钮
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.SysAuthorityBtnReq true "菜单id, 角色id, 选中的按钮id" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "返回列表成功" // @Param data body request.SysAuthorityBtnReq true "菜单id, 角色id, 选中的按钮id"
// @Router /authorityBtn/setAuthorityBtn [post] // @Success 200 {object} response.Response{msg=string} "返回列表成功"
// @Router /authorityBtn/setAuthorityBtn [post]
func (a *AuthorityBtnApi) SetAuthorityBtn(c *gin.Context) { func (a *AuthorityBtnApi) SetAuthorityBtn(c *gin.Context) {
var req request.SysAuthorityBtnReq var req request.SysAuthorityBtnReq
_ = c.ShouldBindJSON(&req) err := c.ShouldBindJSON(&req)
if err := authorityBtnService.SetAuthorityBtn(req); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = authorityBtnService.SetAuthorityBtn(req)
if err != nil {
global.GVA_LOG.Error("分配失败!", zap.Error(err)) global.GVA_LOG.Error("分配失败!", zap.Error(err))
response.FailWithMessage("分配失败", c) response.FailWithMessage("分配失败", c)
} else { return
response.OkWithMessage("分配成功", c)
} }
response.OkWithMessage("分配成功", c)
} }
// @Tags AuthorityBtn // CanRemoveAuthorityBtn
// @Summary 设置权限按钮 // @Tags AuthorityBtn
// @Security ApiKeyAuth // @Summary 设置权限按钮
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Success 200 {object} response.Response{msg=string} "删除成功" // @Produce application/json
// @Router /authorityBtn/canRemoveAuthorityBtn [post] // @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /authorityBtn/canRemoveAuthorityBtn [post]
func (a *AuthorityBtnApi) CanRemoveAuthorityBtn(c *gin.Context) { func (a *AuthorityBtnApi) CanRemoveAuthorityBtn(c *gin.Context) {
id := c.Query("id") id := c.Query("id")
if err := authorityBtnService.CanRemoveAuthorityBtn(id); err != nil { err := authorityBtnService.CanRemoveAuthorityBtn(id)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err)) global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
} else { return
response.OkWithMessage("删除成功", c)
} }
response.OkWithMessage("删除成功", c)
} }
+94 -82
View File
@@ -23,14 +23,14 @@ type AutoCodeApi struct{}
var caser = cases.Title(language.English) var caser = cases.Title(language.English)
// PreviewTemp // PreviewTemp
// @Tags AutoCode // @Tags AutoCode
// @Summary 预览创建后的代码 // @Summary 预览创建后的代码
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body system.AutoCodeStruct true "预览创建代码" // @Param data body system.AutoCodeStruct true "预览创建代码"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "预览创建后的代码" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "预览创建后的代码"
// @Router /autoCode/preview [post] // @Router /autoCode/preview [post]
func (autoApi *AutoCodeApi) PreviewTemp(c *gin.Context) { func (autoApi *AutoCodeApi) PreviewTemp(c *gin.Context) {
var a system.AutoCodeStruct var a system.AutoCodeStruct
_ = c.ShouldBindJSON(&a) _ = c.ShouldBindJSON(&a)
@@ -50,14 +50,14 @@ func (autoApi *AutoCodeApi) PreviewTemp(c *gin.Context) {
} }
// CreateTemp // CreateTemp
// @Tags AutoCode // @Tags AutoCode
// @Summary 自动代码模板 // @Summary 自动代码模板
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body system.AutoCodeStruct true "创建自动代码" // @Param data body system.AutoCodeStruct true "创建自动代码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /autoCode/createTemp [post] // @Router /autoCode/createTemp [post]
func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) { func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) {
var a system.AutoCodeStruct var a system.AutoCodeStruct
_ = c.ShouldBindJSON(&a) _ = c.ShouldBindJSON(&a)
@@ -98,13 +98,13 @@ func (autoApi *AutoCodeApi) CreateTemp(c *gin.Context) {
} }
// GetDB // GetDB
// @Tags AutoCode // @Tags AutoCode
// @Summary 获取当前所有数据库 // @Summary 获取当前所有数据库
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取当前所有数据库" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取当前所有数据库"
// @Router /autoCode/getDatabase [get] // @Router /autoCode/getDatabase [get]
func (autoApi *AutoCodeApi) GetDB(c *gin.Context) { func (autoApi *AutoCodeApi) GetDB(c *gin.Context) {
dbs, err := autoCodeService.Database().GetDB() dbs, err := autoCodeService.Database().GetDB()
if err != nil { if err != nil {
@@ -116,13 +116,13 @@ func (autoApi *AutoCodeApi) GetDB(c *gin.Context) {
} }
// GetTables // GetTables
// @Tags AutoCode // @Tags AutoCode
// @Summary 获取当前数据库所有表 // @Summary 获取当前数据库所有表
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取当前数据库所有表" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取当前数据库所有表"
// @Router /autoCode/getTables [get] // @Router /autoCode/getTables [get]
func (autoApi *AutoCodeApi) GetTables(c *gin.Context) { func (autoApi *AutoCodeApi) GetTables(c *gin.Context) {
dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname) dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname)
tables, err := autoCodeService.Database().GetTables(dbName) tables, err := autoCodeService.Database().GetTables(dbName)
@@ -135,13 +135,13 @@ func (autoApi *AutoCodeApi) GetTables(c *gin.Context) {
} }
// GetColumn // GetColumn
// @Tags AutoCode // @Tags AutoCode
// @Summary 获取当前表所有字段 // @Summary 获取当前表所有字段
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取当前表所有字段" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取当前表所有字段"
// @Router /autoCode/getColumn [get] // @Router /autoCode/getColumn [get]
func (autoApi *AutoCodeApi) GetColumn(c *gin.Context) { func (autoApi *AutoCodeApi) GetColumn(c *gin.Context) {
dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname) dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname)
tableName := c.Query("tableName") tableName := c.Query("tableName")
@@ -155,14 +155,14 @@ func (autoApi *AutoCodeApi) GetColumn(c *gin.Context) {
} }
// CreatePackage // CreatePackage
// @Tags AutoCode // @Tags AutoCode
// @Summary 创建package // @Summary 创建package
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body system.SysAutoCode true "创建package" // @Param data body system.SysAutoCode true "创建package"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功"
// @Router /autoCode/createPackage [post] // @Router /autoCode/createPackage [post]
func (autoApi *AutoCodeApi) CreatePackage(c *gin.Context) { func (autoApi *AutoCodeApi) CreatePackage(c *gin.Context) {
var a system.SysAutoCode var a system.SysAutoCode
_ = c.ShouldBindJSON(&a) _ = c.ShouldBindJSON(&a)
@@ -180,13 +180,13 @@ func (autoApi *AutoCodeApi) CreatePackage(c *gin.Context) {
} }
// GetPackage // GetPackage
// @Tags AutoCode // @Tags AutoCode
// @Summary 获取package // @Summary 获取package
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建package成功"
// @Router /autoCode/getPackage [post] // @Router /autoCode/getPackage [post]
func (autoApi *AutoCodeApi) GetPackage(c *gin.Context) { func (autoApi *AutoCodeApi) GetPackage(c *gin.Context) {
pkgs, err := autoCodeService.GetPackage() pkgs, err := autoCodeService.GetPackage()
if err != nil { if err != nil {
@@ -198,14 +198,14 @@ func (autoApi *AutoCodeApi) GetPackage(c *gin.Context) {
} }
// DelPackage // DelPackage
// @Tags AutoCode // @Tags AutoCode
// @Summary 删除package // @Summary 删除package
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body system.SysAutoCode true "创建package" // @Param data body system.SysAutoCode true "创建package"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "删除package成功" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "删除package成功"
// @Router /autoCode/delPackage [post] // @Router /autoCode/delPackage [post]
func (autoApi *AutoCodeApi) DelPackage(c *gin.Context) { func (autoApi *AutoCodeApi) DelPackage(c *gin.Context) {
var a system.SysAutoCode var a system.SysAutoCode
_ = c.ShouldBindJSON(&a) _ = c.ShouldBindJSON(&a)
@@ -219,28 +219,41 @@ func (autoApi *AutoCodeApi) DelPackage(c *gin.Context) {
} }
// AutoPlug // AutoPlug
// @Tags AutoCode // @Tags AutoCode
// @Summary 创建插件模板 // @Summary 创建插件模板
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body system.SysAutoCode true "创建插件模板" // @Param data body system.SysAutoCode true "创建插件模板"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建插件模板成功" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "创建插件模板成功"
// @Router /autoCode/createPlug [post] // @Router /autoCode/createPlug [post]
func (autoApi *AutoCodeApi) AutoPlug(c *gin.Context) { func (autoApi *AutoCodeApi) AutoPlug(c *gin.Context) {
var a system.AutoPlugReq var a system.AutoPlugReq
_ = c.ShouldBindJSON(&a) err := c.ShouldBindJSON(&a)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
a.Snake = strings.ToLower(a.PlugName) a.Snake = strings.ToLower(a.PlugName)
a.NeedModel = a.HasRequest || a.HasResponse a.NeedModel = a.HasRequest || a.HasResponse
err := autoCodeService.CreatePlug(a) err = autoCodeService.CreatePlug(a)
if err != nil { if err != nil {
global.GVA_LOG.Error("预览失败!", zap.Error(err)) global.GVA_LOG.Error("预览失败!", zap.Error(err))
response.FailWithMessage("预览失败", c) response.FailWithMessage("预览失败", c)
} else { return
response.Ok(c)
} }
response.Ok(c)
} }
// InstallPlugin
// @Tags AutoCode
// @Summary 安装插件
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
// @Param plug formData file true "this is a test file"
// @Success 200 {object} response.Response{data=[]interface{},msg=string} "安装插件成功"
// @Router /autoCode/createPlug [post]
func (autoApi *AutoCodeApi) InstallPlugin(c *gin.Context) { func (autoApi *AutoCodeApi) InstallPlugin(c *gin.Context) {
header, err := c.FormFile("plug") header, err := c.FormFile("plug")
if err != nil { if err != nil {
@@ -259,15 +272,14 @@ func (autoApi *AutoCodeApi) InstallPlugin(c *gin.Context) {
if err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} else {
response.OkWithData([]interface{}{
gin.H{
"code": web,
"msg": webStr,
},
gin.H{
"code": server,
"msg": serverStr,
}}, c)
} }
response.OkWithData([]interface{}{
gin.H{
"code": web,
"msg": webStr,
},
gin.H{
"code": server,
"msg": serverStr,
}}, c)
} }
+55 -38
View File
@@ -12,17 +12,21 @@ import (
type AutoCodeHistoryApi struct{} type AutoCodeHistoryApi struct{}
// First // First
// @Tags AutoCode // @Tags AutoCode
// @Summary 获取meta信息 // @Summary 获取meta信息
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body request.GetById true "请求参数" // @Param data body request.GetById true "请求参数"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取meta信息" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取meta信息"
// @Router /autoCode/getMeta [post] // @Router /autoCode/getMeta [post]
func (a *AutoCodeHistoryApi) First(c *gin.Context) { func (a *AutoCodeHistoryApi) First(c *gin.Context) {
var info request.GetById var info request.GetById
_ = c.ShouldBindJSON(&info) err := c.ShouldBindJSON(&info)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
data, err := autoCodeHistoryService.First(&info) data, err := autoCodeHistoryService.First(&info)
if err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
@@ -32,18 +36,22 @@ func (a *AutoCodeHistoryApi) First(c *gin.Context) {
} }
// Delete // Delete
// @Tags AutoCode // @Tags AutoCode
// @Summary 删除回滚记录 // @Summary 删除回滚记录
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body request.GetById true "请求参数" // @Param data body request.GetById true "请求参数"
// @Success 200 {object} response.Response{msg=string} "删除回滚记录" // @Success 200 {object} response.Response{msg=string} "删除回滚记录"
// @Router /autoCode/delSysHistory [post] // @Router /autoCode/delSysHistory [post]
func (a *AutoCodeHistoryApi) Delete(c *gin.Context) { func (a *AutoCodeHistoryApi) Delete(c *gin.Context) {
var info request.GetById var info request.GetById
_ = c.ShouldBindJSON(&info) err := c.ShouldBindJSON(&info)
err := autoCodeHistoryService.Delete(&info) if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = autoCodeHistoryService.Delete(&info)
if err != nil { if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err)) global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c) response.FailWithMessage("删除失败", c)
@@ -53,18 +61,23 @@ func (a *AutoCodeHistoryApi) Delete(c *gin.Context) {
} }
// RollBack // RollBack
// @Tags AutoCode // @Tags AutoCode
// @Summary 回滚自动生成代码 // @Summary 回滚自动生成代码
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body systemReq.RollBack true "请求参数" // @Param data body systemReq.RollBack true "请求参数"
// @Success 200 {object} response.Response{msg=string} "回滚自动生成代码" // @Success 200 {object} response.Response{msg=string} "回滚自动生成代码"
// @Router /autoCode/rollback [post] // @Router /autoCode/rollback [post]
func (a *AutoCodeHistoryApi) RollBack(c *gin.Context) { func (a *AutoCodeHistoryApi) RollBack(c *gin.Context) {
var info systemReq.RollBack var info systemReq.RollBack
_ = c.ShouldBindJSON(&info) err := c.ShouldBindJSON(&info)
if err := autoCodeHistoryService.RollBack(&info); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = autoCodeHistoryService.RollBack(&info)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
@@ -72,17 +85,21 @@ func (a *AutoCodeHistoryApi) RollBack(c *gin.Context) {
} }
// GetList // GetList
// @Tags AutoCode // @Tags AutoCode
// @Summary 查询回滚记录 // @Summary 查询回滚记录
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Param data body systemReq.SysAutoHistory true "请求参数" // @Param data body systemReq.SysAutoHistory true "请求参数"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "查询回滚记录,返回包括列表,总数,页码,每页数量" // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "查询回滚记录,返回包括列表,总数,页码,每页数量"
// @Router /autoCode/getSysHistory [post] // @Router /autoCode/getSysHistory [post]
func (a *AutoCodeHistoryApi) GetList(c *gin.Context) { func (a *AutoCodeHistoryApi) GetList(c *gin.Context) {
var search systemReq.SysAutoHistory var search systemReq.SysAutoHistory
_ = c.ShouldBindJSON(&search) err := c.ShouldBindJSON(&search)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
list, total, err := autoCodeHistoryService.GetList(search.PageInfo) list, total, err := autoCodeHistoryService.GetList(search.PageInfo)
if err != nil { if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
+15 -14
View File
@@ -16,27 +16,28 @@ var store = base64Captcha.DefaultMemStore
type BaseApi struct{} type BaseApi struct{}
// Captcha // Captcha
// @Tags Base // @Tags Base
// @Summary 生成验证码 // @Summary 生成验证码
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @accept application/json // @accept application/json
// @Produce application/json // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.SysCaptchaResponse,msg=string} "生成验证码,返回包括随机数id,base64,验证码长度" // @Success 200 {object} response.Response{data=systemRes.SysCaptchaResponse,msg=string} "生成验证码,返回包括随机数id,base64,验证码长度"
// @Router /base/captcha [post] // @Router /base/captcha [post]
func (b *BaseApi) Captcha(c *gin.Context) { func (b *BaseApi) Captcha(c *gin.Context) {
// 字符,公式,验证码配置 // 字符,公式,验证码配置
// 生成默认数字的driver // 生成默认数字的driver
driver := base64Captcha.NewDriverDigit(global.GVA_CONFIG.Captcha.ImgHeight, global.GVA_CONFIG.Captcha.ImgWidth, global.GVA_CONFIG.Captcha.KeyLong, 0.7, 80) driver := base64Captcha.NewDriverDigit(global.GVA_CONFIG.Captcha.ImgHeight, global.GVA_CONFIG.Captcha.ImgWidth, global.GVA_CONFIG.Captcha.KeyLong, 0.7, 80)
// cp := base64Captcha.NewCaptcha(driver, store.UseWithCtx(c)) // v8下使用redis // cp := base64Captcha.NewCaptcha(driver, store.UseWithCtx(c)) // v8下使用redis
cp := base64Captcha.NewCaptcha(driver, store) cp := base64Captcha.NewCaptcha(driver, store)
if id, b64s, err := cp.Generate(); err != nil { id, b64s, err := cp.Generate()
if err != nil {
global.GVA_LOG.Error("验证码获取失败!", zap.Error(err)) global.GVA_LOG.Error("验证码获取失败!", zap.Error(err))
response.FailWithMessage("验证码获取失败", c) response.FailWithMessage("验证码获取失败", c)
} else { return
response.OkWithDetailed(systemRes.SysCaptchaResponse{
CaptchaId: id,
PicPath: b64s,
CaptchaLength: global.GVA_CONFIG.Captcha.KeyLong,
}, "验证码获取成功", c)
} }
response.OkWithDetailed(systemRes.SysCaptchaResponse{
CaptchaId: id,
PicPath: b64s,
CaptchaLength: global.GVA_CONFIG.Captcha.KeyLong,
}, "验证码获取成功", c)
} }
+36 -23
View File
@@ -12,41 +12,54 @@ import (
type CasbinApi struct{} type CasbinApi struct{}
// @Tags Casbin // UpdateCasbin
// @Summary 更新角色api权限 // @Tags Casbin
// @Security ApiKeyAuth // @Summary 更新角色api权限
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.CasbinInReceive true "权限id, 权限模型列表" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "更新角色api权限" // @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
// @Router /casbin/UpdateCasbin [post] // @Success 200 {object} response.Response{msg=string} "更新角色api权限"
// @Router /casbin/UpdateCasbin [post]
func (cas *CasbinApi) UpdateCasbin(c *gin.Context) { func (cas *CasbinApi) UpdateCasbin(c *gin.Context) {
var cmr request.CasbinInReceive var cmr request.CasbinInReceive
_ = c.ShouldBindJSON(&cmr) err := c.ShouldBindJSON(&cmr)
if err := utils.Verify(cmr, utils.AuthorityIdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := casbinService.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos); err != nil { err = utils.Verify(cmr, utils.AuthorityIdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = casbinService.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos)
if err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err)) global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c) response.FailWithMessage("更新失败", c)
} else { return
response.OkWithMessage("更新成功", c)
} }
response.OkWithMessage("更新成功", c)
} }
// @Tags Casbin // GetPolicyPathByAuthorityId
// @Summary 获取权限列表 // @Tags Casbin
// @Security ApiKeyAuth // @Summary 获取权限列表
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.CasbinInReceive true "权限id, 权限模型列表" // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.PolicyPathResponse,msg=string} "获取权限列表,返回包括casbin详情列表" // @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
// @Router /casbin/getPolicyPathByAuthorityId [post] // @Success 200 {object} response.Response{data=systemRes.PolicyPathResponse,msg=string} "获取权限列表,返回包括casbin详情列表"
// @Router /casbin/getPolicyPathByAuthorityId [post]
func (cas *CasbinApi) GetPolicyPathByAuthorityId(c *gin.Context) { func (cas *CasbinApi) GetPolicyPathByAuthorityId(c *gin.Context) {
var casbin request.CasbinInReceive var casbin request.CasbinInReceive
_ = c.ShouldBindJSON(&casbin) err := c.ShouldBindJSON(&casbin)
if err := utils.Verify(casbin, utils.AuthorityIdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(casbin, utils.AuthorityIdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
+125 -94
View File
@@ -12,106 +12,137 @@ import (
type DictionaryApi struct{} type DictionaryApi struct{}
// @Tags SysDictionary // CreateSysDictionary
// @Summary 创建SysDictionary // @Tags SysDictionary
// @Security ApiKeyAuth // @Summary 创建SysDictionary
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysDictionary true "SysDictionary模型" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "创建SysDictionary" // @Param data body system.SysDictionary true "SysDictionary模型"
// @Router /sysDictionary/createSysDictionary [post] // @Success 200 {object} response.Response{msg=string} "创建SysDictionary"
// @Router /sysDictionary/createSysDictionary [post]
func (s *DictionaryApi) CreateSysDictionary(c *gin.Context) { func (s *DictionaryApi) CreateSysDictionary(c *gin.Context) {
var dictionary system.SysDictionary var dictionary system.SysDictionary
_ = c.ShouldBindJSON(&dictionary) err := c.ShouldBindJSON(&dictionary)
if err := dictionaryService.CreateSysDictionary(dictionary); err != nil { if err != nil {
global.GVA_LOG.Error("创建失败!", zap.Error(err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysDictionary
// @Summary 删除SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.SysDictionary true "SysDictionary模型"
// @Success 200 {object} response.Response{msg=string} "删除SysDictionary"
// @Router /sysDictionary/deleteSysDictionary [delete]
func (s *DictionaryApi) DeleteSysDictionary(c *gin.Context) {
var dictionary system.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := dictionaryService.DeleteSysDictionary(dictionary); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysDictionary
// @Summary 更新SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.SysDictionary true "SysDictionary模型"
// @Success 200 {object} response.Response{msg=string} "更新SysDictionary"
// @Router /sysDictionary/updateSysDictionary [put]
func (s *DictionaryApi) UpdateSysDictionary(c *gin.Context) {
var dictionary system.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := dictionaryService.UpdateSysDictionary(&dictionary); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// @Tags SysDictionary
// @Summary 用id查询SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query system.SysDictionary true "ID或字典英名"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询SysDictionary"
// @Router /sysDictionary/findSysDictionary [get]
func (s *DictionaryApi) FindSysDictionary(c *gin.Context) {
var dictionary system.SysDictionary
_ = c.ShouldBindQuery(&dictionary)
if sysDictionary, err := dictionaryService.GetSysDictionary(dictionary.Type, dictionary.ID, dictionary.Status); err != nil {
global.GVA_LOG.Error("字典未创建或未开启!", zap.Error(err))
response.FailWithMessage("字典未创建或未开启", c)
} else {
response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
}
}
// @Tags SysDictionary
// @Summary 分页获取SysDictionary列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysDictionary列表,返回包括列表,总数,页码,每页数量"
// @Router /sysDictionary/getSysDictionaryList [get]
func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
var pageInfo request.SysDictionarySearch
_ = c.ShouldBindQuery(&pageInfo)
if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if list, total, err := dictionaryService.GetSysDictionaryInfoList(pageInfo); err != nil { err = dictionaryService.CreateSysDictionary(dictionary)
if err != nil {
global.GVA_LOG.Error("创建失败!", zap.Error(err))
response.FailWithMessage("创建失败", c)
return
}
response.OkWithMessage("创建成功", c)
}
// DeleteSysDictionary
// @Tags SysDictionary
// @Summary 删除SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.SysDictionary true "SysDictionary模型"
// @Success 200 {object} response.Response{msg=string} "删除SysDictionary"
// @Router /sysDictionary/deleteSysDictionary [delete]
func (s *DictionaryApi) DeleteSysDictionary(c *gin.Context) {
var dictionary system.SysDictionary
err := c.ShouldBindJSON(&dictionary)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = dictionaryService.DeleteSysDictionary(dictionary)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c)
return
}
response.OkWithMessage("删除成功", c)
}
// UpdateSysDictionary
// @Tags SysDictionary
// @Summary 更新SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.SysDictionary true "SysDictionary模型"
// @Success 200 {object} response.Response{msg=string} "更新SysDictionary"
// @Router /sysDictionary/updateSysDictionary [put]
func (s *DictionaryApi) UpdateSysDictionary(c *gin.Context) {
var dictionary system.SysDictionary
err := c.ShouldBindJSON(&dictionary)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = dictionaryService.UpdateSysDictionary(&dictionary)
if err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c)
return
}
response.OkWithMessage("更新成功", c)
}
// FindSysDictionary
// @Tags SysDictionary
// @Summary 用id查询SysDictionary
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query system.SysDictionary true "ID或字典英名"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询SysDictionary"
// @Router /sysDictionary/findSysDictionary [get]
func (s *DictionaryApi) FindSysDictionary(c *gin.Context) {
var dictionary system.SysDictionary
err := c.ShouldBindQuery(&dictionary)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
sysDictionary, err := dictionaryService.GetSysDictionary(dictionary.Type, dictionary.ID, dictionary.Status)
if err != nil {
global.GVA_LOG.Error("字典未创建或未开启!", zap.Error(err))
response.FailWithMessage("字典未创建或未开启", c)
return
}
response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
}
// GetSysDictionaryList
// @Tags SysDictionary
// @Summary 分页获取SysDictionary列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysDictionary列表,返回包括列表,总数,页码,每页数量"
// @Router /sysDictionary/getSysDictionaryList [get]
func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
var pageInfo request.SysDictionarySearch
err := c.ShouldBindQuery(&pageInfo)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
list, total, err := dictionaryService.GetSysDictionaryInfoList(pageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
+120 -89
View File
@@ -12,106 +12,137 @@ import (
type DictionaryDetailApi struct{} type DictionaryDetailApi struct{}
// @Tags SysDictionaryDetail // CreateSysDictionaryDetail
// @Summary 创建SysDictionaryDetail // @Tags SysDictionaryDetail
// @Security ApiKeyAuth // @Summary 创建SysDictionaryDetail
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysDictionaryDetail true "SysDictionaryDetail模型" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "创建SysDictionaryDetail" // @Param data body system.SysDictionaryDetail true "SysDictionaryDetail模型"
// @Router /sysDictionaryDetail/createSysDictionaryDetail [post] // @Success 200 {object} response.Response{msg=string} "创建SysDictionaryDetail"
// @Router /sysDictionaryDetail/createSysDictionaryDetail [post]
func (s *DictionaryDetailApi) CreateSysDictionaryDetail(c *gin.Context) { func (s *DictionaryDetailApi) CreateSysDictionaryDetail(c *gin.Context) {
var detail system.SysDictionaryDetail var detail system.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail) err := c.ShouldBindJSON(&detail)
if err := dictionaryDetailService.CreateSysDictionaryDetail(detail); err != nil { if err != nil {
global.GVA_LOG.Error("创建失败!", zap.Error(err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysDictionaryDetail
// @Summary 删除SysDictionaryDetail
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.SysDictionaryDetail true "SysDictionaryDetail模型"
// @Success 200 {object} response.Response{msg=string} "删除SysDictionaryDetail"
// @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete]
func (s *DictionaryDetailApi) DeleteSysDictionaryDetail(c *gin.Context) {
var detail system.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := dictionaryDetailService.DeleteSysDictionaryDetail(detail); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysDictionaryDetail
// @Summary 更新SysDictionaryDetail
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.SysDictionaryDetail true "更新SysDictionaryDetail"
// @Success 200 {object} response.Response{msg=string} "更新SysDictionaryDetail"
// @Router /sysDictionaryDetail/updateSysDictionaryDetail [put]
func (s *DictionaryDetailApi) UpdateSysDictionaryDetail(c *gin.Context) {
var detail system.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := dictionaryDetailService.UpdateSysDictionaryDetail(&detail); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// @Tags SysDictionaryDetail
// @Summary 用id查询SysDictionaryDetail
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query system.SysDictionaryDetail true "用id查询SysDictionaryDetail"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询SysDictionaryDetail"
// @Router /sysDictionaryDetail/findSysDictionaryDetail [get]
func (s *DictionaryDetailApi) FindSysDictionaryDetail(c *gin.Context) {
var detail system.SysDictionaryDetail
_ = c.ShouldBindQuery(&detail)
if err := utils.Verify(detail, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if reSysDictionaryDetail, err := dictionaryDetailService.GetSysDictionaryDetail(detail.ID); err != nil { err = dictionaryDetailService.CreateSysDictionaryDetail(detail)
global.GVA_LOG.Error("查询失败!", zap.Error(err)) if err != nil {
response.FailWithMessage("查询失败", c) global.GVA_LOG.Error("创建失败!", zap.Error(err))
} else { response.FailWithMessage("创建失败", c)
response.OkWithDetailed(gin.H{"reSysDictionaryDetail": reSysDictionaryDetail}, "查询成功", c) return
} }
response.OkWithMessage("创建成功", c)
} }
// @Tags SysDictionaryDetail // DeleteSysDictionaryDetail
// @Summary 分页获取SysDictionaryDetail列表 // @Tags SysDictionaryDetail
// @Security ApiKeyAuth // @Summary 删除SysDictionaryDetail
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data query request.SysDictionaryDetailSearch true "页码, 每页大小, 搜索条件" // @Produce application/json
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysDictionaryDetail列表,返回包括列表,总数,页码,每页数量" // @Param data body system.SysDictionaryDetail true "SysDictionaryDetail模型"
// @Router /sysDictionaryDetail/getSysDictionaryDetailList [get] // @Success 200 {object} response.Response{msg=string} "删除SysDictionaryDetail"
// @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete]
func (s *DictionaryDetailApi) DeleteSysDictionaryDetail(c *gin.Context) {
var detail system.SysDictionaryDetail
err := c.ShouldBindJSON(&detail)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = dictionaryDetailService.DeleteSysDictionaryDetail(detail)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c)
return
}
response.OkWithMessage("删除成功", c)
}
// UpdateSysDictionaryDetail
// @Tags SysDictionaryDetail
// @Summary 更新SysDictionaryDetail
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.SysDictionaryDetail true "更新SysDictionaryDetail"
// @Success 200 {object} response.Response{msg=string} "更新SysDictionaryDetail"
// @Router /sysDictionaryDetail/updateSysDictionaryDetail [put]
func (s *DictionaryDetailApi) UpdateSysDictionaryDetail(c *gin.Context) {
var detail system.SysDictionaryDetail
err := c.ShouldBindJSON(&detail)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = dictionaryDetailService.UpdateSysDictionaryDetail(&detail)
if err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c)
return
}
response.OkWithMessage("更新成功", c)
}
// FindSysDictionaryDetail
// @Tags SysDictionaryDetail
// @Summary 用id查询SysDictionaryDetail
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query system.SysDictionaryDetail true "用id查询SysDictionaryDetail"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询SysDictionaryDetail"
// @Router /sysDictionaryDetail/findSysDictionaryDetail [get]
func (s *DictionaryDetailApi) FindSysDictionaryDetail(c *gin.Context) {
var detail system.SysDictionaryDetail
err := c.ShouldBindQuery(&detail)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(detail, utils.IdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
reSysDictionaryDetail, err := dictionaryDetailService.GetSysDictionaryDetail(detail.ID)
if err != nil {
global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败", c)
return
}
response.OkWithDetailed(gin.H{"reSysDictionaryDetail": reSysDictionaryDetail}, "查询成功", c)
}
// GetSysDictionaryDetailList
// @Tags SysDictionaryDetail
// @Summary 分页获取SysDictionaryDetail列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.SysDictionaryDetailSearch true "页码, 每页大小, 搜索条件"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysDictionaryDetail列表,返回包括列表,总数,页码,每页数量"
// @Router /sysDictionaryDetail/getSysDictionaryDetailList [get]
func (s *DictionaryDetailApi) GetSysDictionaryDetailList(c *gin.Context) { func (s *DictionaryDetailApi) GetSysDictionaryDetailList(c *gin.Context) {
var pageInfo request.SysDictionaryDetailSearch var pageInfo request.SysDictionaryDetailSearch
_ = c.ShouldBindQuery(&pageInfo) err := c.ShouldBindQuery(&pageInfo)
if list, total, err := dictionaryDetailService.GetSysDictionaryDetailInfoList(pageInfo); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
list, total, err := dictionaryDetailService.GetSysDictionaryDetailInfoList(pageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
+9 -9
View File
@@ -12,12 +12,12 @@ import (
type DBApi struct{} type DBApi struct{}
// InitDB // InitDB
// @Tags InitDB // @Tags InitDB
// @Summary 初始化用户数据库 // @Summary 初始化用户数据库
// @Produce application/json // @Produce application/json
// @Param data body request.InitDB true "初始化数据库参数" // @Param data body request.InitDB true "初始化数据库参数"
// @Success 200 {object} response.Response{data=string} "初始化用户数据库" // @Success 200 {object} response.Response{data=string} "初始化用户数据库"
// @Router /init/initdb [post] // @Router /init/initdb [post]
func (i *DBApi) InitDB(c *gin.Context) { func (i *DBApi) InitDB(c *gin.Context) {
if global.GVA_DB != nil { if global.GVA_DB != nil {
global.GVA_LOG.Error("已存在数据库配置!") global.GVA_LOG.Error("已存在数据库配置!")
@@ -39,11 +39,11 @@ func (i *DBApi) InitDB(c *gin.Context) {
} }
// CheckDB // CheckDB
// @Tags CheckDB // @Tags CheckDB
// @Summary 初始化用户数据库 // @Summary 初始化用户数据库
// @Produce application/json // @Produce application/json
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "初始化用户数据库" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "初始化用户数据库"
// @Router /init/checkdb [post] // @Router /init/checkdb [post]
func (i *DBApi) CheckDB(c *gin.Context) { func (i *DBApi) CheckDB(c *gin.Context) {
var ( var (
message = "前往初始化数据库" message = "前往初始化数据库"
+12 -10
View File
@@ -10,20 +10,22 @@ import (
type JwtApi struct{} type JwtApi struct{}
// @Tags Jwt // JsonInBlacklist
// @Summary jwt加入黑名单 // @Tags Jwt
// @Security ApiKeyAuth // @Summary jwt加入黑名单
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Success 200 {object} response.Response{msg=string} "jwt加入黑名单" // @Produce application/json
// @Router /jwt/jsonInBlacklist [post] // @Success 200 {object} response.Response{msg=string} "jwt加入黑名单"
// @Router /jwt/jsonInBlacklist [post]
func (j *JwtApi) JsonInBlacklist(c *gin.Context) { func (j *JwtApi) JsonInBlacklist(c *gin.Context) {
token := c.Request.Header.Get("x-token") token := c.Request.Header.Get("x-token")
jwt := system.JwtBlacklist{Jwt: token} jwt := system.JwtBlacklist{Jwt: token}
if err := jwtService.JsonInBlacklist(jwt); err != nil { err := jwtService.JsonInBlacklist(jwt)
if err != nil {
global.GVA_LOG.Error("jwt作废失败!", zap.Error(err)) global.GVA_LOG.Error("jwt作废失败!", zap.Error(err))
response.FailWithMessage("jwt作废失败", c) response.FailWithMessage("jwt作废失败", c)
} else { return
response.OkWithMessage("jwt作废成功", c)
} }
response.OkWithMessage("jwt作废成功", c)
} }
+164 -117
View File
@@ -15,49 +15,53 @@ import (
type AuthorityMenuApi struct{} type AuthorityMenuApi struct{}
// @Tags AuthorityMenu // GetMenu
// @Summary 获取用户动态路由 // @Tags AuthorityMenu
// @Security ApiKeyAuth // @Summary 获取用户动态路由
// @Produce application/json // @Security ApiKeyAuth
// @Param data body request.Empty true "空" // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.SysMenusResponse,msg=string} "获取用户动态路由,返回包括系统菜单详情列表" // @Param data body request.Empty true "空"
// @Router /menu/getMenu [post] // @Success 200 {object} response.Response{data=systemRes.SysMenusResponse,msg=string} "获取用户动态路由,返回包括系统菜单详情列表"
// @Router /menu/getMenu [post]
func (a *AuthorityMenuApi) GetMenu(c *gin.Context) { func (a *AuthorityMenuApi) GetMenu(c *gin.Context) {
if menus, err := menuService.GetMenuTree(utils.GetUserAuthorityId(c)); err != nil { menus, err := menuService.GetMenuTree(utils.GetUserAuthorityId(c))
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else {
if menus == nil {
menus = []system.SysMenu{}
}
response.OkWithDetailed(systemRes.SysMenusResponse{Menus: menus}, "获取成功", c)
} }
if menus == nil {
menus = []system.SysMenu{}
}
response.OkWithDetailed(systemRes.SysMenusResponse{Menus: menus}, "获取成功", c)
} }
// @Tags AuthorityMenu // GetBaseMenuTree
// @Summary 获取用户动态路由 // @Tags AuthorityMenu
// @Security ApiKeyAuth // @Summary 获取用户动态路由
// @Produce application/json // @Security ApiKeyAuth
// @Param data body request.Empty true "空" // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.SysBaseMenusResponse,msg=string} "获取用户动态路由,返回包括系统菜单列表" // @Param data body request.Empty true "空"
// @Router /menu/getBaseMenuTree [post] // @Success 200 {object} response.Response{data=systemRes.SysBaseMenusResponse,msg=string} "获取用户动态路由,返回包括系统菜单列表"
// @Router /menu/getBaseMenuTree [post]
func (a *AuthorityMenuApi) GetBaseMenuTree(c *gin.Context) { func (a *AuthorityMenuApi) GetBaseMenuTree(c *gin.Context) {
if menus, err := menuService.GetBaseMenuTree(); err != nil { menus, err := menuService.GetBaseMenuTree()
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(systemRes.SysBaseMenusResponse{Menus: menus}, "获取成功", c)
} }
response.OkWithDetailed(systemRes.SysBaseMenusResponse{Menus: menus}, "获取成功", c)
} }
// @Tags AuthorityMenu // AddMenuAuthority
// @Summary 增加menu和角色关联关系 // @Tags AuthorityMenu
// @Security ApiKeyAuth // @Summary 增加menu和角色关联关系
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body systemReq.AddMenuAuthorityInfo true "角色ID" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "增加menu和角色关联关系" // @Param data body systemReq.AddMenuAuthorityInfo true "角色ID"
// @Router /menu/addMenuAuthority [post] // @Success 200 {object} response.Response{msg=string} "增加menu和角色关联关系"
// @Router /menu/addMenuAuthority [post]
func (a *AuthorityMenuApi) AddMenuAuthority(c *gin.Context) { func (a *AuthorityMenuApi) AddMenuAuthority(c *gin.Context) {
var authorityMenu systemReq.AddMenuAuthorityInfo var authorityMenu systemReq.AddMenuAuthorityInfo
_ = c.ShouldBindJSON(&authorityMenu) _ = c.ShouldBindJSON(&authorityMenu)
@@ -73,154 +77,197 @@ func (a *AuthorityMenuApi) AddMenuAuthority(c *gin.Context) {
} }
} }
// @Tags AuthorityMenu // GetMenuAuthority
// @Summary 获取指定角色menu // @Tags AuthorityMenu
// @Security ApiKeyAuth // @Summary 获取指定角色menu
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.GetAuthorityId true "角色ID" // @Produce application/json
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取指定角色menu" // @Param data body request.GetAuthorityId true "角色ID"
// @Router /menu/getMenuAuthority [post] // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取指定角色menu"
// @Router /menu/getMenuAuthority [post]
func (a *AuthorityMenuApi) GetMenuAuthority(c *gin.Context) { func (a *AuthorityMenuApi) GetMenuAuthority(c *gin.Context) {
var param request.GetAuthorityId var param request.GetAuthorityId
_ = c.ShouldBindJSON(&param) err := c.ShouldBindJSON(&param)
if err := utils.Verify(param, utils.AuthorityIdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if menus, err := menuService.GetMenuAuthority(&param); err != nil { err = utils.Verify(param, utils.AuthorityIdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
menus, err := menuService.GetMenuAuthority(&param)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithDetailed(systemRes.SysMenusResponse{Menus: menus}, "获取失败", c) response.FailWithDetailed(systemRes.SysMenusResponse{Menus: menus}, "获取失败", c)
} else { return
response.OkWithDetailed(gin.H{"menus": menus}, "获取成功", c)
} }
response.OkWithDetailed(gin.H{"menus": menus}, "获取成功", c)
} }
// @Tags Menu // AddBaseMenu
// @Summary 新增菜单 // @Tags Menu
// @Security ApiKeyAuth // @Summary 新增菜单
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "新增菜单" // @Param data body system.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
// @Router /menu/addBaseMenu [post] // @Success 200 {object} response.Response{msg=string} "新增菜单"
// @Router /menu/addBaseMenu [post]
func (a *AuthorityMenuApi) AddBaseMenu(c *gin.Context) { func (a *AuthorityMenuApi) AddBaseMenu(c *gin.Context) {
var menu system.SysBaseMenu var menu system.SysBaseMenu
_ = c.ShouldBindJSON(&menu) err := c.ShouldBindJSON(&menu)
if err := utils.Verify(menu, utils.MenuVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := utils.Verify(menu.Meta, utils.MenuMetaVerify); err != nil { err = utils.Verify(menu, utils.MenuVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := menuService.AddBaseMenu(menu); err != nil { err = utils.Verify(menu.Meta, utils.MenuMetaVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = menuService.AddBaseMenu(menu)
if err != nil {
global.GVA_LOG.Error("添加失败!", zap.Error(err)) global.GVA_LOG.Error("添加失败!", zap.Error(err))
response.FailWithMessage("添加失败", c) response.FailWithMessage("添加失败", c)
} else { return
response.OkWithMessage("添加成功", c)
} }
response.OkWithMessage("添加成功", c)
} }
// @Tags Menu // DeleteBaseMenu
// @Summary 删除菜单 // @Tags Menu
// @Security ApiKeyAuth // @Summary 删除菜单
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.GetById true "菜单id" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "删除菜单" // @Param data body request.GetById true "菜单id"
// @Router /menu/deleteBaseMenu [post] // @Success 200 {object} response.Response{msg=string} "删除菜单"
// @Router /menu/deleteBaseMenu [post]
func (a *AuthorityMenuApi) DeleteBaseMenu(c *gin.Context) { func (a *AuthorityMenuApi) DeleteBaseMenu(c *gin.Context) {
var menu request.GetById var menu request.GetById
_ = c.ShouldBindJSON(&menu) err := c.ShouldBindJSON(&menu)
if err := utils.Verify(menu, utils.IdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := baseMenuService.DeleteBaseMenu(menu.ID); err != nil { err = utils.Verify(menu, utils.IdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = baseMenuService.DeleteBaseMenu(menu.ID)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err)) global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c) response.FailWithMessage("删除失败", c)
} else { return
response.OkWithMessage("删除成功", c)
} }
response.OkWithMessage("删除成功", c)
} }
// @Tags Menu // UpdateBaseMenu
// @Summary 更新菜单 // @Tags Menu
// @Security ApiKeyAuth // @Summary 更新菜单
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "更新菜单" // @Param data body system.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
// @Router /menu/updateBaseMenu [post] // @Success 200 {object} response.Response{msg=string} "更新菜单"
// @Router /menu/updateBaseMenu [post]
func (a *AuthorityMenuApi) UpdateBaseMenu(c *gin.Context) { func (a *AuthorityMenuApi) UpdateBaseMenu(c *gin.Context) {
var menu system.SysBaseMenu var menu system.SysBaseMenu
_ = c.ShouldBindJSON(&menu) err := c.ShouldBindJSON(&menu)
if err := utils.Verify(menu, utils.MenuVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := utils.Verify(menu.Meta, utils.MenuMetaVerify); err != nil { err = utils.Verify(menu, utils.MenuVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if err := baseMenuService.UpdateBaseMenu(menu); err != nil { err = utils.Verify(menu.Meta, utils.MenuMetaVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = baseMenuService.UpdateBaseMenu(menu)
if err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err)) global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c) response.FailWithMessage("更新失败", c)
} else { return
response.OkWithMessage("更新成功", c)
} }
response.OkWithMessage("更新成功", c)
} }
// @Tags Menu // GetBaseMenuById
// @Summary 根据id获取菜单 // @Tags Menu
// @Security ApiKeyAuth // @Summary 根据id获取菜单
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.GetById true "菜单id" // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.SysBaseMenuResponse,msg=string} "根据id获取菜单,返回包括系统菜单列表" // @Param data body request.GetById true "菜单id"
// @Router /menu/getBaseMenuById [post] // @Success 200 {object} response.Response{data=systemRes.SysBaseMenuResponse,msg=string} "根据id获取菜单,返回包括系统菜单列表"
// @Router /menu/getBaseMenuById [post]
func (a *AuthorityMenuApi) GetBaseMenuById(c *gin.Context) { func (a *AuthorityMenuApi) GetBaseMenuById(c *gin.Context) {
var idInfo request.GetById var idInfo request.GetById
_ = c.ShouldBindJSON(&idInfo) err := c.ShouldBindJSON(&idInfo)
if err := utils.Verify(idInfo, utils.IdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if menu, err := baseMenuService.GetBaseMenuById(idInfo.ID); err != nil { err = utils.Verify(idInfo, utils.IdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
menu, err := baseMenuService.GetBaseMenuById(idInfo.ID)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(systemRes.SysBaseMenuResponse{Menu: menu}, "获取成功", c)
} }
response.OkWithDetailed(systemRes.SysBaseMenuResponse{Menu: menu}, "获取成功", c)
} }
// @Tags Menu // GetMenuList
// @Summary 分页获取基础menu列表 // @Tags Menu
// @Security ApiKeyAuth // @Summary 分页获取基础menu列表
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.PageInfo true "页码, 每页大小" // @Produce application/json
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取基础menu列表,返回包括列表,总数,页码,每页数量" // @Param data body request.PageInfo true "页码, 每页大小"
// @Router /menu/getMenuList [post] // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取基础menu列表,返回包括列表,总数,页码,每页数量"
// @Router /menu/getMenuList [post]
func (a *AuthorityMenuApi) GetMenuList(c *gin.Context) { func (a *AuthorityMenuApi) GetMenuList(c *gin.Context) {
var pageInfo request.PageInfo var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo) err := c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if menuList, total, err := menuService.GetInfoList(); err != nil { err = utils.Verify(pageInfo, utils.PageInfoVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
menuList, total, err := menuService.GetInfoList()
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(response.PageResult{
List: menuList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
response.OkWithDetailed(response.PageResult{
List: menuList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
+120 -89
View File
@@ -13,106 +13,137 @@ import (
type OperationRecordApi struct{} type OperationRecordApi struct{}
// @Tags SysOperationRecord // CreateSysOperationRecord
// @Summary 创建SysOperationRecord // @Tags SysOperationRecord
// @Security ApiKeyAuth // @Summary 创建SysOperationRecord
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysOperationRecord true "创建SysOperationRecord" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "创建SysOperationRecord" // @Param data body system.SysOperationRecord true "创建SysOperationRecord"
// @Router /sysOperationRecord/createSysOperationRecord [post] // @Success 200 {object} response.Response{msg=string} "创建SysOperationRecord"
// @Router /sysOperationRecord/createSysOperationRecord [post]
func (s *OperationRecordApi) CreateSysOperationRecord(c *gin.Context) { func (s *OperationRecordApi) CreateSysOperationRecord(c *gin.Context) {
var sysOperationRecord system.SysOperationRecord var sysOperationRecord system.SysOperationRecord
_ = c.ShouldBindJSON(&sysOperationRecord) err := c.ShouldBindJSON(&sysOperationRecord)
if err := operationRecordService.CreateSysOperationRecord(sysOperationRecord); err != nil { if err != nil {
global.GVA_LOG.Error("创建失败!", zap.Error(err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysOperationRecord
// @Summary 删除SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body system.SysOperationRecord true "SysOperationRecord模型"
// @Success 200 {object} response.Response{msg=string} "删除SysOperationRecord"
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
func (s *OperationRecordApi) DeleteSysOperationRecord(c *gin.Context) {
var sysOperationRecord system.SysOperationRecord
_ = c.ShouldBindJSON(&sysOperationRecord)
if err := operationRecordService.DeleteSysOperationRecord(sysOperationRecord); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysOperationRecord
// @Summary 批量删除SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除SysOperationRecord"
// @Success 200 {object} response.Response{msg=string} "批量删除SysOperationRecord"
// @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete]
func (s *OperationRecordApi) DeleteSysOperationRecordByIds(c *gin.Context) {
var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS)
if err := operationRecordService.DeleteSysOperationRecordByIds(IDS); err != nil {
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
response.FailWithMessage("批量删除失败", c)
} else {
response.OkWithMessage("批量删除成功", c)
}
}
// @Tags SysOperationRecord
// @Summary 用id查询SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query system.SysOperationRecord true "Id"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询SysOperationRecord"
// @Router /sysOperationRecord/findSysOperationRecord [get]
func (s *OperationRecordApi) FindSysOperationRecord(c *gin.Context) {
var sysOperationRecord system.SysOperationRecord
_ = c.ShouldBindQuery(&sysOperationRecord)
if err := utils.Verify(sysOperationRecord, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if reSysOperationRecord, err := operationRecordService.GetSysOperationRecord(sysOperationRecord.ID); err != nil { err = operationRecordService.CreateSysOperationRecord(sysOperationRecord)
global.GVA_LOG.Error("查询失败!", zap.Error(err)) if err != nil {
response.FailWithMessage("查询失败", c) global.GVA_LOG.Error("创建失败!", zap.Error(err))
} else { response.FailWithMessage("创建失败", c)
response.OkWithDetailed(gin.H{"reSysOperationRecord": reSysOperationRecord}, "查询成功", c) return
} }
response.OkWithMessage("创建成功", c)
} }
// @Tags SysOperationRecord // DeleteSysOperationRecord
// @Summary 分页获取SysOperationRecord列表 // @Tags SysOperationRecord
// @Security ApiKeyAuth // @Summary 删除SysOperationRecord
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data query request.SysOperationRecordSearch true "页码, 每页大小, 搜索条件" // @Produce application/json
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysOperationRecord列表,返回包括列表,总数,页码,每页数量" // @Param data body system.SysOperationRecord true "SysOperationRecord模型"
// @Router /sysOperationRecord/getSysOperationRecordList [get] // @Success 200 {object} response.Response{msg=string} "删除SysOperationRecord"
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
func (s *OperationRecordApi) DeleteSysOperationRecord(c *gin.Context) {
var sysOperationRecord system.SysOperationRecord
err := c.ShouldBindJSON(&sysOperationRecord)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = operationRecordService.DeleteSysOperationRecord(sysOperationRecord)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c)
return
}
response.OkWithMessage("删除成功", c)
}
// DeleteSysOperationRecordByIds
// @Tags SysOperationRecord
// @Summary 批量删除SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除SysOperationRecord"
// @Success 200 {object} response.Response{msg=string} "批量删除SysOperationRecord"
// @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete]
func (s *OperationRecordApi) DeleteSysOperationRecordByIds(c *gin.Context) {
var IDS request.IdsReq
err := c.ShouldBindJSON(&IDS)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = operationRecordService.DeleteSysOperationRecordByIds(IDS)
if err != nil {
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
response.FailWithMessage("批量删除失败", c)
return
}
response.OkWithMessage("批量删除成功", c)
}
// FindSysOperationRecord
// @Tags SysOperationRecord
// @Summary 用id查询SysOperationRecord
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query system.SysOperationRecord true "Id"
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询SysOperationRecord"
// @Router /sysOperationRecord/findSysOperationRecord [get]
func (s *OperationRecordApi) FindSysOperationRecord(c *gin.Context) {
var sysOperationRecord system.SysOperationRecord
err := c.ShouldBindQuery(&sysOperationRecord)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(sysOperationRecord, utils.IdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
reSysOperationRecord, err := operationRecordService.GetSysOperationRecord(sysOperationRecord.ID)
if err != nil {
global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败", c)
return
}
response.OkWithDetailed(gin.H{"reSysOperationRecord": reSysOperationRecord}, "查询成功", c)
}
// GetSysOperationRecordList
// @Tags SysOperationRecord
// @Summary 分页获取SysOperationRecord列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.SysOperationRecordSearch true "页码, 每页大小, 搜索条件"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysOperationRecord列表,返回包括列表,总数,页码,每页数量"
// @Router /sysOperationRecord/getSysOperationRecordList [get]
func (s *OperationRecordApi) GetSysOperationRecordList(c *gin.Context) { func (s *OperationRecordApi) GetSysOperationRecordList(c *gin.Context) {
var pageInfo systemReq.SysOperationRecordSearch var pageInfo systemReq.SysOperationRecordSearch
_ = c.ShouldBindQuery(&pageInfo) err := c.ShouldBindQuery(&pageInfo)
if list, total, err := operationRecordService.GetSysOperationRecordInfoList(pageInfo); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
list, total, err := operationRecordService.GetSysOperationRecordInfoList(pageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
+48 -37
View File
@@ -13,66 +13,77 @@ import (
type SystemApi struct{} type SystemApi struct{}
// @Tags System // GetSystemConfig
// @Summary 获取配置文件内容 // @Tags System
// @Security ApiKeyAuth // @Summary 获取配置文件内容
// @Produce application/json // @Security ApiKeyAuth
// @Success 200 {object} response.Response{data=systemRes.SysConfigResponse,msg=string} "获取配置文件内容,返回包括系统配置" // @Produce application/json
// @Router /system/getSystemConfig [post] // @Success 200 {object} response.Response{data=systemRes.SysConfigResponse,msg=string} "获取配置文件内容,返回包括系统配置"
// @Router /system/getSystemConfig [post]
func (s *SystemApi) GetSystemConfig(c *gin.Context) { func (s *SystemApi) GetSystemConfig(c *gin.Context) {
if config, err := systemConfigService.GetSystemConfig(); err != nil { config, err := systemConfigService.GetSystemConfig()
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(systemRes.SysConfigResponse{Config: config}, "获取成功", c)
} }
response.OkWithDetailed(systemRes.SysConfigResponse{Config: config}, "获取成功", c)
} }
// @Tags System // SetSystemConfig
// @Summary 设置配置文件内容 // @Tags System
// @Security ApiKeyAuth // @Summary 设置配置文件内容
// @Produce application/json // @Security ApiKeyAuth
// @Param data body system.System true "设置配置文件内容" // @Produce application/json
// @Success 200 {object} response.Response{data=string} "设置配置文件内容" // @Param data body system.System true "设置配置文件内容"
// @Router /system/setSystemConfig [post] // @Success 200 {object} response.Response{data=string} "设置配置文件内容"
// @Router /system/setSystemConfig [post]
func (s *SystemApi) SetSystemConfig(c *gin.Context) { func (s *SystemApi) SetSystemConfig(c *gin.Context) {
var sys system.System var sys system.System
_ = c.ShouldBindJSON(&sys) err := c.ShouldBindJSON(&sys)
if err := systemConfigService.SetSystemConfig(sys); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = systemConfigService.SetSystemConfig(sys)
if err != nil {
global.GVA_LOG.Error("设置失败!", zap.Error(err)) global.GVA_LOG.Error("设置失败!", zap.Error(err))
response.FailWithMessage("设置失败", c) response.FailWithMessage("设置失败", c)
} else { return
response.OkWithMessage("设置成功", c)
} }
response.OkWithMessage("设置成功", c)
} }
// @Tags System // ReloadSystem
// @Summary 重启系统 // @Tags System
// @Security ApiKeyAuth // @Summary 重启系统
// @Produce application/json // @Security ApiKeyAuth
// @Success 200 {object} response.Response{msg=string} "重启系统" // @Produce application/json
// @Router /system/reloadSystem [post] // @Success 200 {object} response.Response{msg=string} "重启系统"
// @Router /system/reloadSystem [post]
func (s *SystemApi) ReloadSystem(c *gin.Context) { func (s *SystemApi) ReloadSystem(c *gin.Context) {
err := utils.Reload() err := utils.Reload()
if err != nil { if err != nil {
global.GVA_LOG.Error("重启系统失败!", zap.Error(err)) global.GVA_LOG.Error("重启系统失败!", zap.Error(err))
response.FailWithMessage("重启系统失败", c) response.FailWithMessage("重启系统失败", c)
} else { return
response.OkWithMessage("重启系统成功", c)
} }
response.OkWithMessage("重启系统成功", c)
} }
// @Tags System // GetServerInfo
// @Summary 获取服务器信息 // @Tags System
// @Security ApiKeyAuth // @Summary 获取服务器信息
// @Produce application/json // @Security ApiKeyAuth
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取服务器信息" // @Produce application/json
// @Router /system/getServerInfo [post] // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取服务器信息"
// @Router /system/getServerInfo [post]
func (s *SystemApi) GetServerInfo(c *gin.Context) { func (s *SystemApi) GetServerInfo(c *gin.Context) {
if server, err := systemConfigService.GetServerInfo(); err != nil { server, err := systemConfigService.GetServerInfo()
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
} }
response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
} }
+225 -160
View File
@@ -16,38 +16,44 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
// @Tags Base // Login
// @Summary 用户登录 // @Tags Base
// @Produce application/json // @Summary 用户登录
// @Param data body systemReq.Login true "用户名, 密码, 验证码" // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.LoginResponse,msg=string} "返回包括用户信息,token,过期时间" // @Param data body systemReq.Login true "用户名, 密码, 验证码"
// @Router /base/login [post] // @Success 200 {object} response.Response{data=systemRes.LoginResponse,msg=string} "返回包括用户信息,token,过期时间"
// @Router /base/login [post]
func (b *BaseApi) Login(c *gin.Context) { func (b *BaseApi) Login(c *gin.Context) {
var l systemReq.Login var l systemReq.Login
_ = c.ShouldBindJSON(&l) err := c.ShouldBindJSON(&l)
if err := utils.Verify(l, utils.LoginVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(l, utils.LoginVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if store.Verify(l.CaptchaId, l.Captcha, true) { if store.Verify(l.CaptchaId, l.Captcha, true) {
u := &system.SysUser{Username: l.Username, Password: l.Password} u := &system.SysUser{Username: l.Username, Password: l.Password}
if user, err := userService.Login(u); err != nil { user, err := userService.Login(u)
if err != nil {
global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误!", zap.Error(err)) global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误!", zap.Error(err))
response.FailWithMessage("用户名不存在或者密码错误", c) response.FailWithMessage("用户名不存在或者密码错误", c)
} else { return
if user.Enable != 1 {
global.GVA_LOG.Error("登陆失败! 用户被禁止登录!")
response.FailWithMessage("用户被禁止登录", c)
return
}
b.TokenNext(c, *user)
} }
} else { if user.Enable != 1 {
response.FailWithMessage("验证码错误", c) global.GVA_LOG.Error("登陆失败! 用户被禁止登录!")
response.FailWithMessage("用户被禁止登录", c)
return
}
b.TokenNext(c, *user)
} }
response.FailWithMessage("验证码错误", c)
} }
// 登录以后签发jwt // TokenNext 登录以后签发jwt
func (b *BaseApi) TokenNext(c *gin.Context, user system.SysUser) { func (b *BaseApi) TokenNext(c *gin.Context, user system.SysUser) {
j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名 j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
claims := j.CreateClaims(systemReq.BaseClaims{ claims := j.CreateClaims(systemReq.BaseClaims{
@@ -105,16 +111,22 @@ func (b *BaseApi) TokenNext(c *gin.Context, user system.SysUser) {
} }
} }
// @Tags SysUser // Register
// @Summary 用户注册账号 // @Tags SysUser
// @Produce application/json // @Summary 用户注册账号
// @Param data body systemReq.Register true "用户名, 昵称, 密码, 角色ID" // @Produce application/json
// @Success 200 {object} response.Response{data=systemRes.SysUserResponse,msg=string} "用户注册账号,返回包括用户信息" // @Param data body systemReq.Register true "用户名, 昵称, 密码, 角色ID"
// @Router /user/admin_register [post] // @Success 200 {object} response.Response{data=systemRes.SysUserResponse,msg=string} "用户注册账号,返回包括用户信息"
// @Router /user/admin_register [post]
func (b *BaseApi) Register(c *gin.Context) { func (b *BaseApi) Register(c *gin.Context) {
var r systemReq.Register var r systemReq.Register
_ = c.ShouldBindJSON(&r) err := c.ShouldBindJSON(&r)
if err := utils.Verify(r, utils.RegisterVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(r, utils.RegisterVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
@@ -129,129 +141,161 @@ func (b *BaseApi) Register(c *gin.Context) {
if err != nil { if err != nil {
global.GVA_LOG.Error("注册失败!", zap.Error(err)) global.GVA_LOG.Error("注册失败!", zap.Error(err))
response.FailWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册失败", c) response.FailWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册失败", c)
} else { return
response.OkWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册成功", c)
} }
response.OkWithDetailed(systemRes.SysUserResponse{User: userReturn}, "注册成功", c)
} }
// @Tags SysUser // ChangePassword
// @Summary 用户修改密码 // @Tags SysUser
// @Security ApiKeyAuth // @Summary 用户修改密码
// @Security ApiKeyAuth
// @Produce application/json // @Produce application/json
// @Param data body systemReq.ChangePasswordReq true "用户名, 原密码, 新密码" // @Param data body systemReq.ChangePasswordReq true "用户名, 原密码, 新密码"
// @Success 200 {object} response.Response{msg=string} "用户修改密码" // @Success 200 {object} response.Response{msg=string} "用户修改密码"
// @Router /user/changePassword [post] // @Router /user/changePassword [post]
func (b *BaseApi) ChangePassword(c *gin.Context) { func (b *BaseApi) ChangePassword(c *gin.Context) {
var req systemReq.ChangePasswordReq var req systemReq.ChangePasswordReq
_ = c.ShouldBindJSON(&req) err := c.ShouldBindJSON(&req)
if err := utils.Verify(req, utils.ChangePasswordVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(req, utils.ChangePasswordVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
uid := utils.GetUserID(c) uid := utils.GetUserID(c)
u := &system.SysUser{GVA_MODEL: global.GVA_MODEL{ID: uid}, Password: req.Password} u := &system.SysUser{GVA_MODEL: global.GVA_MODEL{ID: uid}, Password: req.Password}
if _, err := userService.ChangePassword(u, req.NewPassword); err != nil { _, err = userService.ChangePassword(u, req.NewPassword)
if err != nil {
global.GVA_LOG.Error("修改失败!", zap.Error(err)) global.GVA_LOG.Error("修改失败!", zap.Error(err))
response.FailWithMessage("修改失败,原密码与当前账户不符", c) response.FailWithMessage("修改失败,原密码与当前账户不符", c)
} else { return
response.OkWithMessage("修改成功", c)
} }
response.OkWithMessage("修改成功", c)
} }
// @Tags SysUser // GetUserList
// @Summary 分页获取用户列表 // GetUserList
// @Security ApiKeyAuth // @Tags SysUser
// @accept application/json // @Summary 分页获取用户列表
// @Produce application/json // @Security ApiKeyAuth
// @Param data body request.PageInfo true "页码, 每页大小" // @accept application/json
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取用户列表,返回包括列表,总数,页码,每页数量" // @Produce application/json
// @Router /user/getUserList [post] // @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取用户列表,返回包括列表,总数,页码,每页数量"
// @Router /user/getUserList [post]
func (b *BaseApi) GetUserList(c *gin.Context) { func (b *BaseApi) GetUserList(c *gin.Context) {
var pageInfo request.PageInfo var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo) err := c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if list, total, err := userService.GetUserInfoList(pageInfo); err != nil { err = utils.Verify(pageInfo, utils.PageInfoVerify)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
list, total, err := userService.GetUserInfoList(pageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
} }
// @Tags SysUser // SetUserAuthority
// @Summary 更改用户权限 // @Tags SysUser
// @Security ApiKeyAuth // @Summary 更改用户权限
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body systemReq.SetUserAuth true "用户UUID, 角色ID" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "设置用户权限" // @Param data body systemReq.SetUserAuth true "用户UUID, 角色ID"
// @Router /user/setUserAuthority [post] // @Success 200 {object} response.Response{msg=string} "设置用户权限"
// @Router /user/setUserAuthority [post]
func (b *BaseApi) SetUserAuthority(c *gin.Context) { func (b *BaseApi) SetUserAuthority(c *gin.Context) {
var sua systemReq.SetUserAuth var sua systemReq.SetUserAuth
_ = c.ShouldBindJSON(&sua) err := c.ShouldBindJSON(&sua)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if UserVerifyErr := utils.Verify(sua, utils.SetUserAuthorityVerify); UserVerifyErr != nil { if UserVerifyErr := utils.Verify(sua, utils.SetUserAuthorityVerify); UserVerifyErr != nil {
response.FailWithMessage(UserVerifyErr.Error(), c) response.FailWithMessage(UserVerifyErr.Error(), c)
return return
} }
userID := utils.GetUserID(c) userID := utils.GetUserID(c)
if err := userService.SetUserAuthority(userID, sua.AuthorityId); err != nil { err = userService.SetUserAuthority(userID, sua.AuthorityId)
if err != nil {
global.GVA_LOG.Error("修改失败!", zap.Error(err))
response.FailWithMessage(err.Error(), c)
return
}
claims := utils.GetUserInfo(c)
j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
claims.AuthorityId = sua.AuthorityId
if token, err := j.CreateToken(*claims); err != nil {
global.GVA_LOG.Error("修改失败!", zap.Error(err)) global.GVA_LOG.Error("修改失败!", zap.Error(err))
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
} else { } else {
claims := utils.GetUserInfo(c) c.Header("new-token", token)
j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名 c.Header("new-expires-at", strconv.FormatInt(claims.ExpiresAt, 10))
claims.AuthorityId = sua.AuthorityId
if token, err := j.CreateToken(*claims); err != nil {
global.GVA_LOG.Error("修改失败!", zap.Error(err))
response.FailWithMessage(err.Error(), c)
} else {
c.Header("new-token", token)
c.Header("new-expires-at", strconv.FormatInt(claims.ExpiresAt, 10))
response.OkWithMessage("修改成功", c)
}
}
}
// @Tags SysUser
// @Summary 设置用户权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body systemReq.SetUserAuthorities true "用户UUID, 角色ID"
// @Success 200 {object} response.Response{msg=string} "设置用户权限"
// @Router /user/setUserAuthorities [post]
func (b *BaseApi) SetUserAuthorities(c *gin.Context) {
var sua systemReq.SetUserAuthorities
_ = c.ShouldBindJSON(&sua)
if err := userService.SetUserAuthorities(sua.ID, sua.AuthorityIds); err != nil {
global.GVA_LOG.Error("修改失败!", zap.Error(err))
response.FailWithMessage("修改失败", c)
} else {
response.OkWithMessage("修改成功", c) response.OkWithMessage("修改成功", c)
} }
} }
// @Tags SysUser // SetUserAuthorities
// @Summary 删除用户 // @Tags SysUser
// @Security ApiKeyAuth // @Summary 设置用户权限
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body request.GetById true "用户ID" // @Produce application/json
// @Success 200 {object} response.Response{msg=string} "删除用户" // @Param data body systemReq.SetUserAuthorities true "用户UUID, 角色ID"
// @Router /user/deleteUser [delete] // @Success 200 {object} response.Response{msg=string} "设置用户权限"
// @Router /user/setUserAuthorities [post]
func (b *BaseApi) SetUserAuthorities(c *gin.Context) {
var sua systemReq.SetUserAuthorities
err := c.ShouldBindJSON(&sua)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = userService.SetUserAuthorities(sua.ID, sua.AuthorityIds)
if err != nil {
global.GVA_LOG.Error("修改失败!", zap.Error(err))
response.FailWithMessage("修改失败", c)
return
}
response.OkWithMessage("修改成功", c)
}
// DeleteUser
// @Tags SysUser
// @Summary 删除用户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "用户ID"
// @Success 200 {object} response.Response{msg=string} "删除用户"
// @Router /user/deleteUser [delete]
func (b *BaseApi) DeleteUser(c *gin.Context) { func (b *BaseApi) DeleteUser(c *gin.Context) {
var reqId request.GetById var reqId request.GetById
_ = c.ShouldBindJSON(&reqId) err := c.ShouldBindJSON(&reqId)
if err := utils.Verify(reqId, utils.IdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(reqId, utils.IdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
@@ -260,40 +304,46 @@ func (b *BaseApi) DeleteUser(c *gin.Context) {
response.FailWithMessage("删除失败, 自杀失败", c) response.FailWithMessage("删除失败, 自杀失败", c)
return return
} }
if err := userService.DeleteUser(reqId.ID); err != nil { err = userService.DeleteUser(reqId.ID)
if err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err)) global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c) response.FailWithMessage("删除失败", c)
} else { return
response.OkWithMessage("删除成功", c)
} }
response.OkWithMessage("删除成功", c)
} }
// @Tags SysUser // SetUserInfo
// @Summary 设置用户信息 // @Tags SysUser
// @Security ApiKeyAuth // @Summary 设置用户信息
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysUser true "ID, 用户名, 昵称, 头像链接" // @Produce application/json
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息" // @Param data body system.SysUser true "ID, 用户名, 昵称, 头像链接"
// @Router /user/setUserInfo [put] // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息"
// @Router /user/setUserInfo [put]
func (b *BaseApi) SetUserInfo(c *gin.Context) { func (b *BaseApi) SetUserInfo(c *gin.Context) {
var user systemReq.ChangeUserInfo var user systemReq.ChangeUserInfo
_ = c.ShouldBindJSON(&user) err := c.ShouldBindJSON(&user)
if err := utils.Verify(user, utils.IdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = utils.Verify(user, utils.IdVerify)
if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if len(user.AuthorityIds) != 0 { if len(user.AuthorityIds) != 0 {
err := userService.SetUserAuthorities(user.ID, user.AuthorityIds) err = userService.SetUserAuthorities(user.ID, user.AuthorityIds)
if err != nil { if err != nil {
global.GVA_LOG.Error("设置失败!", zap.Error(err)) global.GVA_LOG.Error("设置失败!", zap.Error(err))
response.FailWithMessage("设置失败", c) response.FailWithMessage("设置失败", c)
return return
} }
} }
err = userService.SetUserInfo(system.SysUser{
if err := userService.SetUserInfo(system.SysUser{
GVA_MODEL: global.GVA_MODEL{ GVA_MODEL: global.GVA_MODEL{
ID: user.ID, ID: user.ID,
}, },
@@ -303,27 +353,33 @@ func (b *BaseApi) SetUserInfo(c *gin.Context) {
Email: user.Email, Email: user.Email,
SideMode: user.SideMode, SideMode: user.SideMode,
Enable: user.Enable, Enable: user.Enable,
}); err != nil { })
if err != nil {
global.GVA_LOG.Error("设置失败!", zap.Error(err)) global.GVA_LOG.Error("设置失败!", zap.Error(err))
response.FailWithMessage("设置失败", c) response.FailWithMessage("设置失败", c)
} else { return
response.OkWithMessage("设置成功", c)
} }
response.OkWithMessage("设置成功", c)
} }
// @Tags SysUser // SetSelfInfo
// @Summary 设置用户信息 // @Tags SysUser
// @Security ApiKeyAuth // @Summary 设置用户信息
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Param data body system.SysUser true "ID, 用户名, 昵称, 头像链接" // @Produce application/json
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息" // @Param data body system.SysUser true "ID, 用户名, 昵称, 头像链接"
// @Router /user/SetSelfInfo [put] // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息"
// @Router /user/SetSelfInfo [put]
func (b *BaseApi) SetSelfInfo(c *gin.Context) { func (b *BaseApi) SetSelfInfo(c *gin.Context) {
var user systemReq.ChangeUserInfo var user systemReq.ChangeUserInfo
_ = c.ShouldBindJSON(&user) err := c.ShouldBindJSON(&user)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
user.ID = utils.GetUserID(c) user.ID = utils.GetUserID(c)
if err := userService.SetUserInfo(system.SysUser{ err = userService.SetUserInfo(system.SysUser{
GVA_MODEL: global.GVA_MODEL{ GVA_MODEL: global.GVA_MODEL{
ID: user.ID, ID: user.ID,
}, },
@@ -333,45 +389,54 @@ func (b *BaseApi) SetSelfInfo(c *gin.Context) {
Email: user.Email, Email: user.Email,
SideMode: user.SideMode, SideMode: user.SideMode,
Enable: user.Enable, Enable: user.Enable,
}); err != nil { })
if err != nil {
global.GVA_LOG.Error("设置失败!", zap.Error(err)) global.GVA_LOG.Error("设置失败!", zap.Error(err))
response.FailWithMessage("设置失败", c) response.FailWithMessage("设置失败", c)
} else { return
response.OkWithMessage("设置成功", c)
} }
response.OkWithMessage("设置成功", c)
} }
// @Tags SysUser // GetUserInfo
// @Summary 获取用户信息 // @Tags SysUser
// @Security ApiKeyAuth // @Summary 获取用户信息
// @accept application/json // @Security ApiKeyAuth
// @Produce application/json // @accept application/json
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取用户信息" // @Produce application/json
// @Router /user/getUserInfo [get] // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取用户信息"
// @Router /user/getUserInfo [get]
func (b *BaseApi) GetUserInfo(c *gin.Context) { func (b *BaseApi) GetUserInfo(c *gin.Context) {
uuid := utils.GetUserUuid(c) uuid := utils.GetUserUuid(c)
if ReqUser, err := userService.GetUserInfo(uuid); err != nil { ReqUser, err := userService.GetUserInfo(uuid)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
} else { return
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "获取成功", c)
} }
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "获取成功", c)
} }
// @Tags SysUser // ResetPassword
// @Summary 重置用户密码 // @Tags SysUser
// @Security ApiKeyAuth // @Summary 重置用户密码
// @Security ApiKeyAuth
// @Produce application/json // @Produce application/json
// @Param data body system.SysUser true "ID" // @Param data body system.SysUser true "ID"
// @Success 200 {object} response.Response{msg=string} "重置用户密码" // @Success 200 {object} response.Response{msg=string} "重置用户密码"
// @Router /user/resetPassword [post] // @Router /user/resetPassword [post]
func (b *BaseApi) ResetPassword(c *gin.Context) { func (b *BaseApi) ResetPassword(c *gin.Context) {
var user system.SysUser var user system.SysUser
_ = c.ShouldBindJSON(&user) err := c.ShouldBindJSON(&user)
if err := userService.ResetPassword(user.ID); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = userService.ResetPassword(user.ID)
if err != nil {
global.GVA_LOG.Error("重置失败!", zap.Error(err)) global.GVA_LOG.Error("重置失败!", zap.Error(err))
response.FailWithMessage("重置失败"+err.Error(), c) response.FailWithMessage("重置失败"+err.Error(), c)
} else { return
response.OkWithMessage("重置成功", c)
} }
response.OkWithMessage("重置成功", c)
} }
+572 -521
View File
File diff suppressed because it is too large Load Diff
+572 -521
View File
File diff suppressed because it is too large Load Diff
+389 -350
View File
File diff suppressed because it is too large Load Diff
+7 -7
View File
@@ -13,13 +13,13 @@ import (
//go:generate go mod tidy //go:generate go mod tidy
//go:generate go mod download //go:generate go mod download
// @title Swagger Example API // @title Swagger Example API
// @version 0.0.1 // @version 0.0.1
// @description This is a sample Server pets // @description This is a sample Server pets
// @securityDefinitions.apikey ApiKeyAuth // @securityDefinitions.apikey ApiKeyAuth
// @in header // @in header
// @name x-token // @name x-token
// @BasePath / // @BasePath /
func main() { func main() {
global.GVA_VP = core.Viper() // 初始化Viper global.GVA_VP = core.Viper() // 初始化Viper
initialize.OtherInit() initialize.OtherInit()
+28 -20
View File
@@ -11,35 +11,43 @@ import (
type EmailApi struct{} type EmailApi struct{}
// @Tags System // EmailTest
// @Summary 发送测试邮件 // @Tags System
// @Security ApiKeyAuth // @Summary 发送测试邮件
// @Produce application/json // @Security ApiKeyAuth
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}" // @Produce application/json
// @Router /email/emailTest [post] // @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
// @Router /email/emailTest [post]
func (s *EmailApi) EmailTest(c *gin.Context) { func (s *EmailApi) EmailTest(c *gin.Context) {
if err := service.ServiceGroupApp.EmailTest(); err != nil { err := service.ServiceGroupApp.EmailTest()
if err != nil {
global.GVA_LOG.Error("发送失败!", zap.Error(err)) global.GVA_LOG.Error("发送失败!", zap.Error(err))
response.FailWithMessage("发送失败", c) response.FailWithMessage("发送失败", c)
} else { return
response.OkWithMessage("发送成功", c)
} }
response.OkWithMessage("发送成功", c)
} }
// @Tags System // SendEmail
// @Summary 发送邮件 // @Tags System
// @Security ApiKeyAuth // @Summary 发送邮件
// @Produce application/json // @Security ApiKeyAuth
// @Param data body email_response.Email true "发送邮件必须的参数" // @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}" // @Param data body email_response.Email true "发送邮件必须的参数"
// @Router /email/sendEmail [post] // @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
// @Router /email/sendEmail [post]
func (s *EmailApi) SendEmail(c *gin.Context) { func (s *EmailApi) SendEmail(c *gin.Context) {
var email email_response.Email var email email_response.Email
_ = c.ShouldBindJSON(&email) err := c.ShouldBindJSON(&email)
if err := service.ServiceGroupApp.SendEmail(email.To, email.Subject, email.Body); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = service.ServiceGroupApp.SendEmail(email.To, email.Subject, email.Body)
if err != nil {
global.GVA_LOG.Error("发送失败!", zap.Error(err)) global.GVA_LOG.Error("发送失败!", zap.Error(err))
response.FailWithMessage("发送失败", c) response.FailWithMessage("发送失败", c)
} else { return
response.OkWithMessage("发送成功", c)
} }
response.OkWithMessage("发送成功", c)
} }
@@ -33,7 +33,11 @@ var {{.Abbreviation}}Service = service.ServiceGroupApp.{{.PackageT}}ServiceGroup
// @Router /{{.Abbreviation}}/create{{.StructName}} [post] // @Router /{{.Abbreviation}}/create{{.StructName}} [post]
func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Context) { func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} {{.Package}}.{{.StructName}} var {{.Abbreviation}} {{.Package}}.{{.StructName}}
_ = c.ShouldBindJSON(&{{.Abbreviation}}) err := c.ShouldBindJSON(&{{.Abbreviation}})
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
{{- if .AutoCreateResource }} {{- if .AutoCreateResource }}
{{.Abbreviation}}.CreatedBy = utils.GetUserID(c) {{.Abbreviation}}.CreatedBy = utils.GetUserID(c)
{{- end }} {{- end }}
@@ -69,7 +73,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Create{{.StructName}}(c *gin.Con
// @Router /{{.Abbreviation}}/delete{{.StructName}} [delete] // @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Context) { func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} {{.Package}}.{{.StructName}} var {{.Abbreviation}} {{.Package}}.{{.StructName}}
_ = c.ShouldBindJSON(&{{.Abbreviation}}) err := c.ShouldBindJSON(&{{.Abbreviation}})
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
{{- if .AutoCreateResource }} {{- if .AutoCreateResource }}
{{.Abbreviation}}.DeletedBy = utils.GetUserID(c) {{.Abbreviation}}.DeletedBy = utils.GetUserID(c)
{{- end }} {{- end }}
@@ -92,7 +100,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}(c *gin.Con
// @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete] // @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete]
func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gin.Context) { func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gin.Context) {
var IDS request.IdsReq var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS) err := c.ShouldBindJSON(&IDS)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
{{- if .AutoCreateResource }} {{- if .AutoCreateResource }}
deletedBy := utils.GetUserID(c) deletedBy := utils.GetUserID(c)
{{- end }} {{- end }}
@@ -115,7 +127,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Delete{{.StructName}}ByIds(c *gi
// @Router /{{.Abbreviation}}/update{{.StructName}} [put] // @Router /{{.Abbreviation}}/update{{.StructName}} [put]
func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Context) { func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} {{.Package}}.{{.StructName}} var {{.Abbreviation}} {{.Package}}.{{.StructName}}
_ = c.ShouldBindJSON(&{{.Abbreviation}}) err := c.ShouldBindJSON(&{{.Abbreviation}})
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
{{- if .AutoCreateResource }} {{- if .AutoCreateResource }}
{{.Abbreviation}}.UpdatedBy = utils.GetUserID(c) {{.Abbreviation}}.UpdatedBy = utils.GetUserID(c)
{{- end }} {{- end }}
@@ -151,7 +167,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Update{{.StructName}}(c *gin.Con
// @Router /{{.Abbreviation}}/find{{.StructName}} [get] // @Router /{{.Abbreviation}}/find{{.StructName}} [get]
func ({{.Abbreviation}}Api *{{.StructName}}Api) Find{{.StructName}}(c *gin.Context) { func ({{.Abbreviation}}Api *{{.StructName}}Api) Find{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} {{.Package}}.{{.StructName}} var {{.Abbreviation}} {{.Package}}.{{.StructName}}
_ = c.ShouldBindQuery(&{{.Abbreviation}}) err := c.ShouldBindQuery(&{{.Abbreviation}})
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if re{{.Abbreviation}}, err := {{.Abbreviation}}Service.Get{{.StructName}}({{.Abbreviation}}.ID); err != nil { if re{{.Abbreviation}}, err := {{.Abbreviation}}Service.Get{{.StructName}}({{.Abbreviation}}.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Error(err)) global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败", c) response.FailWithMessage("查询失败", c)
@@ -171,7 +191,11 @@ func ({{.Abbreviation}}Api *{{.StructName}}Api) Find{{.StructName}}(c *gin.Conte
// @Router /{{.Abbreviation}}/get{{.StructName}}List [get] // @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Context) { func ({{.Abbreviation}}Api *{{.StructName}}Api) Get{{.StructName}}List(c *gin.Context) {
var pageInfo {{.Package}}Req.{{.StructName}}Search var pageInfo {{.Package}}Req.{{.StructName}}Search
_ = c.ShouldBindQuery(&pageInfo) err := c.ShouldBindQuery(&pageInfo)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if list, total, err := {{.Abbreviation}}Service.Get{{.StructName}}InfoList(pageInfo); err != nil { if list, total, err := {{.Abbreviation}}Service.Get{{.StructName}}InfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err)) global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c) response.FailWithMessage("获取失败", c)
+1
View File
@@ -43,6 +43,7 @@ func NotEmpty() string {
// @description: 正则校验 校验输入项是否满足正则表达式 // @description: 正则校验 校验输入项是否满足正则表达式
// @param: rule string // @param: rule string
// @return: string // @return: string
func RegexpMatch(rule string) string { func RegexpMatch(rule string) string {
return "regexp=" + rule return "regexp=" + rule
} }