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,6 +16,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
// BreakpointContinue
// @Tags ExaFileUploadAndDownload // @Tags ExaFileUploadAndDownload
// @Summary 断点续传到服务器 // @Summary 断点续传到服务器
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -75,6 +76,7 @@ func (b *FileUploadAndDownloadApi) BreakpointContinue(c *gin.Context) {
response.OkWithMessage("切片创建成功", c) response.OkWithMessage("切片创建成功", c)
} }
// FindFile
// @Tags ExaFileUploadAndDownload // @Tags ExaFileUploadAndDownload
// @Summary 查找文件 // @Summary 查找文件
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -96,6 +98,7 @@ func (b *FileUploadAndDownloadApi) FindFile(c *gin.Context) {
} }
} }
// BreakpointContinueFinish
// @Tags ExaFileUploadAndDownload // @Tags ExaFileUploadAndDownload
// @Summary 创建文件 // @Summary 创建文件
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -116,6 +119,7 @@ func (b *FileUploadAndDownloadApi) BreakpointContinueFinish(c *gin.Context) {
} }
} }
// RemoveChunk
// @Tags ExaFileUploadAndDownload // @Tags ExaFileUploadAndDownload
// @Summary 删除切片 // @Summary 删除切片
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -126,8 +130,12 @@ func (b *FileUploadAndDownloadApi) BreakpointContinueFinish(c *gin.Context) {
// @Router /fileUploadAndDownload/removeChunk [post] // @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)
} }
}
+58 -24
View File
@@ -13,6 +13,7 @@ import (
type CustomerApi struct{} type CustomerApi struct{}
// CreateExaCustomer
// @Tags ExaCustomer // @Tags ExaCustomer
// @Summary 创建客户 // @Summary 创建客户
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -23,21 +24,28 @@ type CustomerApi struct{}
// @Router /customer/customer [post] // @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)
} }
}
// DeleteExaCustomer
// @Tags ExaCustomer // @Tags ExaCustomer
// @Summary 删除客户 // @Summary 删除客户
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -48,19 +56,26 @@ func (e *CustomerApi) CreateExaCustomer(c *gin.Context) {
// @Router /customer/customer [delete] // @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)
} }
}
// UpdateExaCustomer
// @Tags ExaCustomer // @Tags ExaCustomer
// @Summary 更新客户信息 // @Summary 更新客户信息
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -71,23 +86,31 @@ func (e *CustomerApi) DeleteExaCustomer(c *gin.Context) {
// @Router /customer/customer [put] // @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)
} }
}
// GetExaCustomer
// @Tags ExaCustomer // @Tags ExaCustomer
// @Summary 获取单一客户信息 // @Summary 获取单一客户信息
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -98,8 +121,13 @@ func (e *CustomerApi) UpdateExaCustomer(c *gin.Context) {
// @Router /customer/customer [get] // @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,11 +135,12 @@ 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)
} }
}
// GetExaCustomerList
// @Tags ExaCustomer // @Tags ExaCustomer
// @Summary 分页获取权限客户列表 // @Summary 分页获取权限客户列表
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -122,8 +151,13 @@ func (e *CustomerApi) GetExaCustomer(c *gin.Context) {
// @Router /customer/customerList [get] // @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,7 +165,8 @@ 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{ response.OkWithDetailed(response.PageResult{
List: customerList, List: customerList,
Total: total, Total: total,
@@ -139,4 +174,3 @@ func (e *CustomerApi) GetExaCustomerList(c *gin.Context) {
PageSize: pageInfo.PageSize, PageSize: pageInfo.PageSize,
}, "获取成功", c) }, "获取成功", c)
} }
}
+10 -2
View File
@@ -18,6 +18,7 @@ type ExcelApi struct{}
// /excel/exportExcel 接口,用于读取前端传来的tableData,生成Excel文件并返回 // /excel/exportExcel 接口,用于读取前端传来的tableData,生成Excel文件并返回
// /excel/downloadTemplate 接口,用于下载resource/excel目录下的 ExcelTemplate.xlsx 文件,作为导入的模板 // /excel/downloadTemplate 接口,用于下载resource/excel目录下的 ExcelTemplate.xlsx 文件,作为导入的模板
// ExportExcel
// @Tags excel // @Tags excel
// @Summary 导出Excel // @Summary 导出Excel
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -28,13 +29,17 @@ type ExcelApi struct{}
// @Router /excel/exportExcel [post] // @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,6 +49,7 @@ func (e *ExcelApi) ExportExcel(c *gin.Context) {
c.File(filePath) c.File(filePath)
} }
// ImportExcel
// @Tags excel // @Tags excel
// @Summary 导入Excel文件 // @Summary 导入Excel文件
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -63,6 +69,7 @@ func (e *ExcelApi) ImportExcel(c *gin.Context) {
response.OkWithMessage("导入成功", c) response.OkWithMessage("导入成功", c)
} }
// LoadExcel
// @Tags excel // @Tags excel
// @Summary 加载Excel数据 // @Summary 加载Excel数据
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -84,6 +91,7 @@ func (e *ExcelApi) LoadExcel(c *gin.Context) {
}, "加载数据成功", c) }, "加载数据成功", c)
} }
// DownloadTemplate
// @Tags excel // @Tags excel
// @Summary 下载模板 // @Summary 下载模板
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -12,6 +12,7 @@ import (
type FileUploadAndDownloadApi struct{} type FileUploadAndDownloadApi struct{}
// UploadFile
// @Tags ExaFileUploadAndDownload // @Tags ExaFileUploadAndDownload
// @Summary 上传文件示例 // @Summary 上传文件示例
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -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,6 +56,7 @@ func (b *FileUploadAndDownloadApi) EditFileName(c *gin.Context) {
response.OkWithMessage("编辑成功", c) response.OkWithMessage("编辑成功", c)
} }
// DeleteFile
// @Tags ExaFileUploadAndDownload // @Tags ExaFileUploadAndDownload
// @Summary 删除文件 // @Summary 删除文件
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -59,7 +66,11 @@ func (b *FileUploadAndDownloadApi) EditFileName(c *gin.Context) {
// @Router /fileUploadAndDownload/deleteFile [post] // @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,6 +79,7 @@ func (b *FileUploadAndDownloadApi) DeleteFile(c *gin.Context) {
response.OkWithMessage("删除成功", c) response.OkWithMessage("删除成功", c)
} }
// GetFileList
// @Tags ExaFileUploadAndDownload // @Tags ExaFileUploadAndDownload
// @Summary 分页文件列表 // @Summary 分页文件列表
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -78,12 +90,17 @@ func (b *FileUploadAndDownloadApi) DeleteFile(c *gin.Context) {
// @Router /fileUploadAndDownload/getFileList [post] // @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{ response.OkWithDetailed(response.PageResult{
List: list, List: list,
Total: total, Total: total,
@@ -91,4 +108,3 @@ func (b *FileUploadAndDownloadApi) GetFileList(c *gin.Context) {
PageSize: pageInfo.PageSize, PageSize: pageInfo.PageSize,
}, "获取成功", c) }, "获取成功", c)
} }
}
+64 -27
View File
@@ -15,6 +15,7 @@ import (
type SystemApiApi struct{} type SystemApiApi struct{}
// CreateApi
// @Tags SysApi // @Tags SysApi
// @Summary 创建基础api // @Summary 创建基础api
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -25,19 +26,26 @@ type SystemApiApi struct{}
// @Router /api/createApi [post] // @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)
} }
}
// DeleteApi
// @Tags SysApi // @Tags SysApi
// @Summary 删除api // @Summary 删除api
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -48,19 +56,26 @@ func (s *SystemApiApi) CreateApi(c *gin.Context) {
// @Router /api/deleteApi [post] // @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)
} }
}
// GetApiList
// @Tags SysApi // @Tags SysApi
// @Summary 分页获取API列表 // @Summary 分页获取API列表
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -71,15 +86,22 @@ func (s *SystemApiApi) DeleteApi(c *gin.Context) {
// @Router /api/getApiList [post] // @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{ response.OkWithDetailed(response.PageResult{
List: list, List: list,
Total: total, Total: total,
@@ -87,8 +109,8 @@ func (s *SystemApiApi) GetApiList(c *gin.Context) {
PageSize: pageInfo.PageSize, PageSize: pageInfo.PageSize,
}, "获取成功", c) }, "获取成功", c)
} }
}
// GetApiById
// @Tags SysApi // @Tags SysApi
// @Summary 根据id获取api // @Summary 根据id获取api
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -113,6 +135,7 @@ func (s *SystemApiApi) GetApiById(c *gin.Context) {
} }
} }
// UpdateApi
// @Tags SysApi // @Tags SysApi
// @Summary 修改基础api // @Summary 修改基础api
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -123,19 +146,26 @@ func (s *SystemApiApi) GetApiById(c *gin.Context) {
// @Router /api/updateApi [post] // @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)
} }
}
// GetAllApis
// @Tags SysApi // @Tags SysApi
// @Summary 获取所有的Api 不分页 // @Summary 获取所有的Api 不分页
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -144,14 +174,16 @@ func (s *SystemApiApi) UpdateApi(c *gin.Context) {
// @Success 200 {object} response.Response{data=systemRes.SysAPIListResponse,msg=string} "获取所有的Api 不分页,返回包括api列表" // @Success 200 {object} response.Response{data=systemRes.SysAPIListResponse,msg=string} "获取所有的Api 不分页,返回包括api列表"
// @Router /api/getAllApis [post] // @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)
} }
}
// DeleteApisByIds
// @Tags SysApi // @Tags SysApi
// @Summary 删除选中Api // @Summary 删除选中Api
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -162,11 +194,16 @@ func (s *SystemApiApi) GetAllApis(c *gin.Context) {
// @Router /api/deleteApisByIds [delete] // @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)
} }
}
+71 -28
View File
@@ -15,6 +15,7 @@ import (
type AuthorityApi struct{} type AuthorityApi struct{}
// CreateAuthority
// @Tags Authority // @Tags Authority
// @Summary 创建角色 // @Summary 创建角色
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -25,8 +26,14 @@ type AuthorityApi struct{}
// @Router /authority/createAuthority [post] // @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,6 +47,7 @@ func (a *AuthorityApi) CreateAuthority(c *gin.Context) {
} }
} }
// CopyAuthority
// @Tags Authority // @Tags Authority
// @Summary 拷贝角色 // @Summary 拷贝角色
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -50,23 +58,31 @@ func (a *AuthorityApi) CreateAuthority(c *gin.Context) {
// @Router /authority/copyAuthority [post] // @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)
} }
}
// DeleteAuthority
// @Tags Authority // @Tags Authority
// @Summary 删除角色 // @Summary 删除角色
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -77,19 +93,26 @@ func (a *AuthorityApi) CopyAuthority(c *gin.Context) {
// @Router /authority/deleteAuthority [post] // @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)
} }
}
// UpdateAuthority
// @Tags Authority // @Tags Authority
// @Summary 更新角色信息 // @Summary 更新角色信息
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -100,19 +123,26 @@ func (a *AuthorityApi) DeleteAuthority(c *gin.Context) {
// @Router /authority/updateAuthority [post] // @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)
} }
}
// GetAuthorityList
// @Tags Authority // @Tags Authority
// @Summary 分页获取角色列表 // @Summary 分页获取角色列表
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -123,15 +153,22 @@ func (a *AuthorityApi) UpdateAuthority(c *gin.Context) {
// @Router /authority/getAuthorityList [post] // @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{ response.OkWithDetailed(response.PageResult{
List: list, List: list,
Total: total, Total: total,
@@ -139,8 +176,8 @@ func (a *AuthorityApi) GetAuthorityList(c *gin.Context) {
PageSize: pageInfo.PageSize, PageSize: pageInfo.PageSize,
}, "获取成功", c) }, "获取成功", c)
} }
}
// SetDataAuthority
// @Tags Authority // @Tags Authority
// @Summary 设置角色资源权限 // @Summary 设置角色资源权限
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -151,15 +188,21 @@ func (a *AuthorityApi) GetAuthorityList(c *gin.Context) {
// @Router /authority/setDataAuthority [post] // @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)
} }
}
+21 -11
View File
@@ -10,6 +10,7 @@ import (
type AuthorityBtnApi struct{} type AuthorityBtnApi struct{}
// GetAuthorityBtn
// @Tags AuthorityBtn // @Tags AuthorityBtn
// @Summary 获取权限按钮 // @Summary 获取权限按钮
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -20,15 +21,17 @@ type AuthorityBtnApi struct{}
// @Router /authorityBtn/getAuthorityBtn [post] // @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)
} }
}
// SetAuthorityBtn
// @Tags AuthorityBtn // @Tags AuthorityBtn
// @Summary 设置权限按钮 // @Summary 设置权限按钮
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -39,15 +42,21 @@ func (a *AuthorityBtnApi) GetAuthorityBtn(c *gin.Context) {
// @Router /authorityBtn/setAuthorityBtn [post] // @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)
} }
}
// CanRemoveAuthorityBtn
// @Tags AuthorityBtn // @Tags AuthorityBtn
// @Summary 设置权限按钮 // @Summary 设置权限按钮
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -57,10 +66,11 @@ func (a *AuthorityBtnApi) SetAuthorityBtn(c *gin.Context) {
// @Router /authorityBtn/canRemoveAuthorityBtn [post] // @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)
} }
}
+18 -6
View File
@@ -229,18 +229,31 @@ func (autoApi *AutoCodeApi) DelPackage(c *gin.Context) {
// @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,7 +272,7 @@ 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{}{ response.OkWithData([]interface{}{
gin.H{ gin.H{
"code": web, "code": web,
@@ -270,4 +283,3 @@ func (autoApi *AutoCodeApi) InstallPlugin(c *gin.Context) {
"msg": serverStr, "msg": serverStr,
}}, c) }}, c)
} }
}
+23 -6
View File
@@ -22,7 +22,11 @@ type AutoCodeHistoryApi struct{}
// @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)
@@ -42,8 +46,12 @@ func (a *AutoCodeHistoryApi) First(c *gin.Context) {
// @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)
@@ -63,8 +71,13 @@ func (a *AutoCodeHistoryApi) Delete(c *gin.Context) {
// @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
} }
@@ -82,7 +95,11 @@ func (a *AutoCodeHistoryApi) RollBack(c *gin.Context) {
// @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))
+4 -3
View File
@@ -29,14 +29,15 @@ func (b *BaseApi) Captcha(c *gin.Context) {
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{ response.OkWithDetailed(systemRes.SysCaptchaResponse{
CaptchaId: id, CaptchaId: id,
PicPath: b64s, PicPath: b64s,
CaptchaLength: global.GVA_CONFIG.Captcha.KeyLong, CaptchaLength: global.GVA_CONFIG.Captcha.KeyLong,
}, "验证码获取成功", c) }, "验证码获取成功", c)
} }
}
+20 -7
View File
@@ -12,6 +12,7 @@ import (
type CasbinApi struct{} type CasbinApi struct{}
// UpdateCasbin
// @Tags Casbin // @Tags Casbin
// @Summary 更新角色api权限 // @Summary 更新角色api权限
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -22,19 +23,26 @@ type CasbinApi struct{}
// @Router /casbin/UpdateCasbin [post] // @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)
} }
}
// GetPolicyPathByAuthorityId
// @Tags Casbin // @Tags Casbin
// @Summary 获取权限列表 // @Summary 获取权限列表
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -45,8 +53,13 @@ func (cas *CasbinApi) UpdateCasbin(c *gin.Context) {
// @Router /casbin/getPolicyPathByAuthorityId [post] // @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
} }
+52 -21
View File
@@ -12,6 +12,7 @@ import (
type DictionaryApi struct{} type DictionaryApi struct{}
// CreateSysDictionary
// @Tags SysDictionary // @Tags SysDictionary
// @Summary 创建SysDictionary // @Summary 创建SysDictionary
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -22,15 +23,21 @@ type DictionaryApi struct{}
// @Router /sysDictionary/createSysDictionary [post] // @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 {
response.FailWithMessage(err.Error(), c)
return
}
err = dictionaryService.CreateSysDictionary(dictionary)
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)
} }
}
// DeleteSysDictionary
// @Tags SysDictionary // @Tags SysDictionary
// @Summary 删除SysDictionary // @Summary 删除SysDictionary
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -41,15 +48,21 @@ func (s *DictionaryApi) CreateSysDictionary(c *gin.Context) {
// @Router /sysDictionary/deleteSysDictionary [delete] // @Router /sysDictionary/deleteSysDictionary [delete]
func (s *DictionaryApi) DeleteSysDictionary(c *gin.Context) { func (s *DictionaryApi) DeleteSysDictionary(c *gin.Context) {
var dictionary system.SysDictionary var dictionary system.SysDictionary
_ = c.ShouldBindJSON(&dictionary) err := c.ShouldBindJSON(&dictionary)
if err := dictionaryService.DeleteSysDictionary(dictionary); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = dictionaryService.DeleteSysDictionary(dictionary)
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)
} }
}
// UpdateSysDictionary
// @Tags SysDictionary // @Tags SysDictionary
// @Summary 更新SysDictionary // @Summary 更新SysDictionary
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -60,15 +73,21 @@ func (s *DictionaryApi) DeleteSysDictionary(c *gin.Context) {
// @Router /sysDictionary/updateSysDictionary [put] // @Router /sysDictionary/updateSysDictionary [put]
func (s *DictionaryApi) UpdateSysDictionary(c *gin.Context) { func (s *DictionaryApi) UpdateSysDictionary(c *gin.Context) {
var dictionary system.SysDictionary var dictionary system.SysDictionary
_ = c.ShouldBindJSON(&dictionary) err := c.ShouldBindJSON(&dictionary)
if err := dictionaryService.UpdateSysDictionary(&dictionary); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = dictionaryService.UpdateSysDictionary(&dictionary)
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)
} }
}
// FindSysDictionary
// @Tags SysDictionary // @Tags SysDictionary
// @Summary 用id查询SysDictionary // @Summary 用id查询SysDictionary
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -79,15 +98,21 @@ func (s *DictionaryApi) UpdateSysDictionary(c *gin.Context) {
// @Router /sysDictionary/findSysDictionary [get] // @Router /sysDictionary/findSysDictionary [get]
func (s *DictionaryApi) FindSysDictionary(c *gin.Context) { func (s *DictionaryApi) FindSysDictionary(c *gin.Context) {
var dictionary system.SysDictionary var dictionary system.SysDictionary
_ = c.ShouldBindQuery(&dictionary) err := c.ShouldBindQuery(&dictionary)
if sysDictionary, err := dictionaryService.GetSysDictionary(dictionary.Type, dictionary.ID, dictionary.Status); err != nil { 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)) global.GVA_LOG.Error("字典未创建或未开启!", zap.Error(err))
response.FailWithMessage("字典未创建或未开启", c) response.FailWithMessage("字典未创建或未开启", c)
} else { return
}
response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c) response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
} }
}
// GetSysDictionaryList
// @Tags SysDictionary // @Tags SysDictionary
// @Summary 分页获取SysDictionary列表 // @Summary 分页获取SysDictionary列表
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -98,15 +123,22 @@ func (s *DictionaryApi) FindSysDictionary(c *gin.Context) {
// @Router /sysDictionary/getSysDictionaryList [get] // @Router /sysDictionary/getSysDictionaryList [get]
func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) { func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
var pageInfo request.SysDictionarySearch var pageInfo request.SysDictionarySearch
_ = c.ShouldBindQuery(&pageInfo) err := c.ShouldBindQuery(&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 := dictionaryService.GetSysDictionaryInfoList(pageInfo); err != nil { 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{ response.OkWithDetailed(response.PageResult{
List: list, List: list,
Total: total, Total: total,
@@ -114,4 +146,3 @@ func (s *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
PageSize: pageInfo.PageSize, PageSize: pageInfo.PageSize,
}, "获取成功", c) }, "获取成功", c)
} }
}
+52 -21
View File
@@ -12,6 +12,7 @@ import (
type DictionaryDetailApi struct{} type DictionaryDetailApi struct{}
// CreateSysDictionaryDetail
// @Tags SysDictionaryDetail // @Tags SysDictionaryDetail
// @Summary 创建SysDictionaryDetail // @Summary 创建SysDictionaryDetail
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -22,15 +23,21 @@ type DictionaryDetailApi struct{}
// @Router /sysDictionaryDetail/createSysDictionaryDetail [post] // @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 {
response.FailWithMessage(err.Error(), c)
return
}
err = dictionaryDetailService.CreateSysDictionaryDetail(detail)
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)
} }
}
// DeleteSysDictionaryDetail
// @Tags SysDictionaryDetail // @Tags SysDictionaryDetail
// @Summary 删除SysDictionaryDetail // @Summary 删除SysDictionaryDetail
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -41,15 +48,21 @@ func (s *DictionaryDetailApi) CreateSysDictionaryDetail(c *gin.Context) {
// @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete] // @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete]
func (s *DictionaryDetailApi) DeleteSysDictionaryDetail(c *gin.Context) { func (s *DictionaryDetailApi) DeleteSysDictionaryDetail(c *gin.Context) {
var detail system.SysDictionaryDetail var detail system.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail) err := c.ShouldBindJSON(&detail)
if err := dictionaryDetailService.DeleteSysDictionaryDetail(detail); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = dictionaryDetailService.DeleteSysDictionaryDetail(detail)
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)
} }
}
// UpdateSysDictionaryDetail
// @Tags SysDictionaryDetail // @Tags SysDictionaryDetail
// @Summary 更新SysDictionaryDetail // @Summary 更新SysDictionaryDetail
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -60,15 +73,21 @@ func (s *DictionaryDetailApi) DeleteSysDictionaryDetail(c *gin.Context) {
// @Router /sysDictionaryDetail/updateSysDictionaryDetail [put] // @Router /sysDictionaryDetail/updateSysDictionaryDetail [put]
func (s *DictionaryDetailApi) UpdateSysDictionaryDetail(c *gin.Context) { func (s *DictionaryDetailApi) UpdateSysDictionaryDetail(c *gin.Context) {
var detail system.SysDictionaryDetail var detail system.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail) err := c.ShouldBindJSON(&detail)
if err := dictionaryDetailService.UpdateSysDictionaryDetail(&detail); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = dictionaryDetailService.UpdateSysDictionaryDetail(&detail)
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)
} }
}
// FindSysDictionaryDetail
// @Tags SysDictionaryDetail // @Tags SysDictionaryDetail
// @Summary 用id查询SysDictionaryDetail // @Summary 用id查询SysDictionaryDetail
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -79,19 +98,26 @@ func (s *DictionaryDetailApi) UpdateSysDictionaryDetail(c *gin.Context) {
// @Router /sysDictionaryDetail/findSysDictionaryDetail [get] // @Router /sysDictionaryDetail/findSysDictionaryDetail [get]
func (s *DictionaryDetailApi) FindSysDictionaryDetail(c *gin.Context) { func (s *DictionaryDetailApi) FindSysDictionaryDetail(c *gin.Context) {
var detail system.SysDictionaryDetail var detail system.SysDictionaryDetail
_ = c.ShouldBindQuery(&detail) err := c.ShouldBindQuery(&detail)
if err := utils.Verify(detail, utils.IdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if reSysDictionaryDetail, err := dictionaryDetailService.GetSysDictionaryDetail(detail.ID); err != nil { 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)) global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败", c) response.FailWithMessage("查询失败", c)
} else { return
}
response.OkWithDetailed(gin.H{"reSysDictionaryDetail": reSysDictionaryDetail}, "查询成功", c) response.OkWithDetailed(gin.H{"reSysDictionaryDetail": reSysDictionaryDetail}, "查询成功", c)
} }
}
// GetSysDictionaryDetailList
// @Tags SysDictionaryDetail // @Tags SysDictionaryDetail
// @Summary 分页获取SysDictionaryDetail列表 // @Summary 分页获取SysDictionaryDetail列表
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -102,11 +128,17 @@ func (s *DictionaryDetailApi) FindSysDictionaryDetail(c *gin.Context) {
// @Router /sysDictionaryDetail/getSysDictionaryDetailList [get] // @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{ response.OkWithDetailed(response.PageResult{
List: list, List: list,
Total: total, Total: total,
@@ -114,4 +146,3 @@ func (s *DictionaryDetailApi) GetSysDictionaryDetailList(c *gin.Context) {
PageSize: pageInfo.PageSize, PageSize: pageInfo.PageSize,
}, "获取成功", c) }, "获取成功", c)
} }
}
+5 -3
View File
@@ -10,6 +10,7 @@ import (
type JwtApi struct{} type JwtApi struct{}
// JsonInBlacklist
// @Tags Jwt // @Tags Jwt
// @Summary jwt加入黑名单 // @Summary jwt加入黑名单
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -20,10 +21,11 @@ type JwtApi struct{}
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)
} }
}
+86 -39
View File
@@ -15,6 +15,7 @@ import (
type AuthorityMenuApi struct{} type AuthorityMenuApi struct{}
// GetMenu
// @Tags AuthorityMenu // @Tags AuthorityMenu
// @Summary 获取用户动态路由 // @Summary 获取用户动态路由
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -23,17 +24,18 @@ type AuthorityMenuApi struct{}
// @Success 200 {object} response.Response{data=systemRes.SysMenusResponse,msg=string} "获取用户动态路由,返回包括系统菜单详情列表" // @Success 200 {object} response.Response{data=systemRes.SysMenusResponse,msg=string} "获取用户动态路由,返回包括系统菜单详情列表"
// @Router /menu/getMenu [post] // @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 { if menus == nil {
menus = []system.SysMenu{} menus = []system.SysMenu{}
} }
response.OkWithDetailed(systemRes.SysMenusResponse{Menus: menus}, "获取成功", c) response.OkWithDetailed(systemRes.SysMenusResponse{Menus: menus}, "获取成功", c)
} }
}
// GetBaseMenuTree
// @Tags AuthorityMenu // @Tags AuthorityMenu
// @Summary 获取用户动态路由 // @Summary 获取用户动态路由
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -42,14 +44,16 @@ func (a *AuthorityMenuApi) GetMenu(c *gin.Context) {
// @Success 200 {object} response.Response{data=systemRes.SysBaseMenusResponse,msg=string} "获取用户动态路由,返回包括系统菜单列表" // @Success 200 {object} response.Response{data=systemRes.SysBaseMenusResponse,msg=string} "获取用户动态路由,返回包括系统菜单列表"
// @Router /menu/getBaseMenuTree [post] // @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)
} }
}
// AddMenuAuthority
// @Tags AuthorityMenu // @Tags AuthorityMenu
// @Summary 增加menu和角色关联关系 // @Summary 增加menu和角色关联关系
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -73,6 +77,7 @@ func (a *AuthorityMenuApi) AddMenuAuthority(c *gin.Context) {
} }
} }
// GetMenuAuthority
// @Tags AuthorityMenu // @Tags AuthorityMenu
// @Summary 获取指定角色menu // @Summary 获取指定角色menu
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -83,19 +88,26 @@ func (a *AuthorityMenuApi) AddMenuAuthority(c *gin.Context) {
// @Router /menu/getMenuAuthority [post] // @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)
} }
}
// AddBaseMenu
// @Tags Menu // @Tags Menu
// @Summary 新增菜单 // @Summary 新增菜单
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -106,24 +118,31 @@ func (a *AuthorityMenuApi) GetMenuAuthority(c *gin.Context) {
// @Router /menu/addBaseMenu [post] // @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)
} }
}
// DeleteBaseMenu
// @Tags Menu // @Tags Menu
// @Summary 删除菜单 // @Summary 删除菜单
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -134,19 +153,26 @@ func (a *AuthorityMenuApi) AddBaseMenu(c *gin.Context) {
// @Router /menu/deleteBaseMenu [post] // @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)
} }
}
// UpdateBaseMenu
// @Tags Menu // @Tags Menu
// @Summary 更新菜单 // @Summary 更新菜单
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -157,23 +183,31 @@ func (a *AuthorityMenuApi) DeleteBaseMenu(c *gin.Context) {
// @Router /menu/updateBaseMenu [post] // @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)
} }
}
// GetBaseMenuById
// @Tags Menu // @Tags Menu
// @Summary 根据id获取菜单 // @Summary 根据id获取菜单
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -184,19 +218,26 @@ func (a *AuthorityMenuApi) UpdateBaseMenu(c *gin.Context) {
// @Router /menu/getBaseMenuById [post] // @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)
} }
}
// GetMenuList
// @Tags Menu // @Tags Menu
// @Summary 分页获取基础menu列表 // @Summary 分页获取基础menu列表
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -207,15 +248,22 @@ func (a *AuthorityMenuApi) GetBaseMenuById(c *gin.Context) {
// @Router /menu/getMenuList [post] // @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{ response.OkWithDetailed(response.PageResult{
List: menuList, List: menuList,
Total: total, Total: total,
@@ -223,4 +271,3 @@ func (a *AuthorityMenuApi) GetMenuList(c *gin.Context) {
PageSize: pageInfo.PageSize, PageSize: pageInfo.PageSize,
}, "获取成功", c) }, "获取成功", c)
} }
}
+52 -21
View File
@@ -13,6 +13,7 @@ import (
type OperationRecordApi struct{} type OperationRecordApi struct{}
// CreateSysOperationRecord
// @Tags SysOperationRecord // @Tags SysOperationRecord
// @Summary 创建SysOperationRecord // @Summary 创建SysOperationRecord
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -23,15 +24,21 @@ type OperationRecordApi struct{}
// @Router /sysOperationRecord/createSysOperationRecord [post] // @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 {
response.FailWithMessage(err.Error(), c)
return
}
err = operationRecordService.CreateSysOperationRecord(sysOperationRecord)
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)
} }
}
// DeleteSysOperationRecord
// @Tags SysOperationRecord // @Tags SysOperationRecord
// @Summary 删除SysOperationRecord // @Summary 删除SysOperationRecord
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -42,15 +49,21 @@ func (s *OperationRecordApi) CreateSysOperationRecord(c *gin.Context) {
// @Router /sysOperationRecord/deleteSysOperationRecord [delete] // @Router /sysOperationRecord/deleteSysOperationRecord [delete]
func (s *OperationRecordApi) DeleteSysOperationRecord(c *gin.Context) { func (s *OperationRecordApi) DeleteSysOperationRecord(c *gin.Context) {
var sysOperationRecord system.SysOperationRecord var sysOperationRecord system.SysOperationRecord
_ = c.ShouldBindJSON(&sysOperationRecord) err := c.ShouldBindJSON(&sysOperationRecord)
if err := operationRecordService.DeleteSysOperationRecord(sysOperationRecord); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = operationRecordService.DeleteSysOperationRecord(sysOperationRecord)
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)
} }
}
// DeleteSysOperationRecordByIds
// @Tags SysOperationRecord // @Tags SysOperationRecord
// @Summary 批量删除SysOperationRecord // @Summary 批量删除SysOperationRecord
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -61,15 +74,21 @@ func (s *OperationRecordApi) DeleteSysOperationRecord(c *gin.Context) {
// @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete] // @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete]
func (s *OperationRecordApi) DeleteSysOperationRecordByIds(c *gin.Context) { func (s *OperationRecordApi) DeleteSysOperationRecordByIds(c *gin.Context) {
var IDS request.IdsReq var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS) err := c.ShouldBindJSON(&IDS)
if err := operationRecordService.DeleteSysOperationRecordByIds(IDS); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err = operationRecordService.DeleteSysOperationRecordByIds(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)
} }
}
// FindSysOperationRecord
// @Tags SysOperationRecord // @Tags SysOperationRecord
// @Summary 用id查询SysOperationRecord // @Summary 用id查询SysOperationRecord
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -80,19 +99,26 @@ func (s *OperationRecordApi) DeleteSysOperationRecordByIds(c *gin.Context) {
// @Router /sysOperationRecord/findSysOperationRecord [get] // @Router /sysOperationRecord/findSysOperationRecord [get]
func (s *OperationRecordApi) FindSysOperationRecord(c *gin.Context) { func (s *OperationRecordApi) FindSysOperationRecord(c *gin.Context) {
var sysOperationRecord system.SysOperationRecord var sysOperationRecord system.SysOperationRecord
_ = c.ShouldBindQuery(&sysOperationRecord) err := c.ShouldBindQuery(&sysOperationRecord)
if err := utils.Verify(sysOperationRecord, utils.IdVerify); err != nil { if err != nil {
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
return return
} }
if reSysOperationRecord, err := operationRecordService.GetSysOperationRecord(sysOperationRecord.ID); err != nil { 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)) global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败", c) response.FailWithMessage("查询失败", c)
} else { return
}
response.OkWithDetailed(gin.H{"reSysOperationRecord": reSysOperationRecord}, "查询成功", c) response.OkWithDetailed(gin.H{"reSysOperationRecord": reSysOperationRecord}, "查询成功", c)
} }
}
// GetSysOperationRecordList
// @Tags SysOperationRecord // @Tags SysOperationRecord
// @Summary 分页获取SysOperationRecord列表 // @Summary 分页获取SysOperationRecord列表
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -103,11 +129,17 @@ func (s *OperationRecordApi) FindSysOperationRecord(c *gin.Context) {
// @Router /sysOperationRecord/getSysOperationRecordList [get] // @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{ response.OkWithDetailed(response.PageResult{
List: list, List: list,
Total: total, Total: total,
@@ -115,4 +147,3 @@ func (s *OperationRecordApi) GetSysOperationRecordList(c *gin.Context) {
PageSize: pageInfo.PageSize, PageSize: pageInfo.PageSize,
}, "获取成功", c) }, "获取成功", c)
} }
}
+23 -12
View File
@@ -13,6 +13,7 @@ import (
type SystemApi struct{} type SystemApi struct{}
// GetSystemConfig
// @Tags System // @Tags System
// @Summary 获取配置文件内容 // @Summary 获取配置文件内容
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -20,14 +21,16 @@ type SystemApi struct{}
// @Success 200 {object} response.Response{data=systemRes.SysConfigResponse,msg=string} "获取配置文件内容,返回包括系统配置" // @Success 200 {object} response.Response{data=systemRes.SysConfigResponse,msg=string} "获取配置文件内容,返回包括系统配置"
// @Router /system/getSystemConfig [post] // @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)
} }
}
// SetSystemConfig
// @Tags System // @Tags System
// @Summary 设置配置文件内容 // @Summary 设置配置文件内容
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -37,15 +40,21 @@ func (s *SystemApi) GetSystemConfig(c *gin.Context) {
// @Router /system/setSystemConfig [post] // @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)
} }
}
// ReloadSystem
// @Tags System // @Tags System
// @Summary 重启系统 // @Summary 重启系统
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -57,11 +66,12 @@ func (s *SystemApi) ReloadSystem(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.OkWithMessage("重启系统成功", c) response.OkWithMessage("重启系统成功", c)
} }
}
// GetServerInfo
// @Tags System // @Tags System
// @Summary 获取服务器信息 // @Summary 获取服务器信息
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -69,10 +79,11 @@ func (s *SystemApi) ReloadSystem(c *gin.Context) {
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取服务器信息" // @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取服务器信息"
// @Router /system/getServerInfo [post] // @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)
} }
}
+120 -55
View File
@@ -16,6 +16,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
// Login
// @Tags Base // @Tags Base
// @Summary 用户登录 // @Summary 用户登录
// @Produce application/json // @Produce application/json
@@ -24,17 +25,24 @@ import (
// @Router /base/login [post] // @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 { if user.Enable != 1 {
global.GVA_LOG.Error("登陆失败! 用户被禁止登录!") global.GVA_LOG.Error("登陆失败! 用户被禁止登录!")
response.FailWithMessage("用户被禁止登录", c) response.FailWithMessage("用户被禁止登录", c)
@@ -42,12 +50,10 @@ func (b *BaseApi) Login(c *gin.Context) {
} }
b.TokenNext(c, *user) b.TokenNext(c, *user)
} }
} else {
response.FailWithMessage("验证码错误", c) 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,6 +111,7 @@ func (b *BaseApi) TokenNext(c *gin.Context, user system.SysUser) {
} }
} }
// Register
// @Tags SysUser // @Tags SysUser
// @Summary 用户注册账号 // @Summary 用户注册账号
// @Produce application/json // @Produce application/json
@@ -113,8 +120,13 @@ func (b *BaseApi) TokenNext(c *gin.Context, user system.SysUser) {
// @Router /user/admin_register [post] // @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,11 +141,12 @@ 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)
} }
}
// ChangePassword
// @Tags SysUser // @Tags SysUser
// @Summary 用户修改密码 // @Summary 用户修改密码
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -143,21 +156,29 @@ func (b *BaseApi) Register(c *gin.Context) {
// @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)
} }
}
// GetUserList
// GetUserList
// @Tags SysUser // @Tags SysUser
// @Summary 分页获取用户列表 // @Summary 分页获取用户列表
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -168,15 +189,22 @@ func (b *BaseApi) ChangePassword(c *gin.Context) {
// @Router /user/getUserList [post] // @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{ response.OkWithDetailed(response.PageResult{
List: list, List: list,
Total: total, Total: total,
@@ -184,8 +212,8 @@ func (b *BaseApi) GetUserList(c *gin.Context) {
PageSize: pageInfo.PageSize, PageSize: pageInfo.PageSize,
}, "获取成功", c) }, "获取成功", c)
} }
}
// SetUserAuthority
// @Tags SysUser // @Tags SysUser
// @Summary 更改用户权限 // @Summary 更改用户权限
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -196,16 +224,22 @@ func (b *BaseApi) GetUserList(c *gin.Context) {
// @Router /user/setUserAuthority [post] // @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)) global.GVA_LOG.Error("修改失败!", zap.Error(err))
response.FailWithMessage(err.Error(), c) response.FailWithMessage(err.Error(), c)
} else { return
}
claims := utils.GetUserInfo(c) claims := utils.GetUserInfo(c)
j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名 j := &utils.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
claims.AuthorityId = sua.AuthorityId claims.AuthorityId = sua.AuthorityId
@@ -217,10 +251,9 @@ func (b *BaseApi) SetUserAuthority(c *gin.Context) {
c.Header("new-expires-at", strconv.FormatInt(claims.ExpiresAt, 10)) c.Header("new-expires-at", strconv.FormatInt(claims.ExpiresAt, 10))
response.OkWithMessage("修改成功", c) response.OkWithMessage("修改成功", c)
} }
}
} }
// SetUserAuthorities
// @Tags SysUser // @Tags SysUser
// @Summary 设置用户权限 // @Summary 设置用户权限
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -231,15 +264,21 @@ func (b *BaseApi) SetUserAuthority(c *gin.Context) {
// @Router /user/setUserAuthorities [post] // @Router /user/setUserAuthorities [post]
func (b *BaseApi) SetUserAuthorities(c *gin.Context) { func (b *BaseApi) SetUserAuthorities(c *gin.Context) {
var sua systemReq.SetUserAuthorities var sua systemReq.SetUserAuthorities
_ = c.ShouldBindJSON(&sua) err := c.ShouldBindJSON(&sua)
if err := userService.SetUserAuthorities(sua.ID, sua.AuthorityIds); err != nil { 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)) global.GVA_LOG.Error("修改失败!", zap.Error(err))
response.FailWithMessage("修改失败", c) response.FailWithMessage("修改失败", c)
} else { return
}
response.OkWithMessage("修改成功", c) response.OkWithMessage("修改成功", c)
} }
}
// DeleteUser
// @Tags SysUser // @Tags SysUser
// @Summary 删除用户 // @Summary 删除用户
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -250,8 +289,13 @@ func (b *BaseApi) SetUserAuthorities(c *gin.Context) {
// @Router /user/deleteUser [delete] // @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,14 +304,16 @@ 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)
} }
}
// SetUserInfo
// @Tags SysUser // @Tags SysUser
// @Summary 设置用户信息 // @Summary 设置用户信息
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -278,22 +324,26 @@ func (b *BaseApi) DeleteUser(c *gin.Context) {
// @Router /user/setUserInfo [put] // @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,14 +353,16 @@ 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)
} }
}
// SetSelfInfo
// @Tags SysUser // @Tags SysUser
// @Summary 设置用户信息 // @Summary 设置用户信息
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -321,9 +373,13 @@ func (b *BaseApi) SetUserInfo(c *gin.Context) {
// @Router /user/SetSelfInfo [put] // @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,14 +389,16 @@ 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)
} }
}
// GetUserInfo
// @Tags SysUser // @Tags SysUser
// @Summary 获取用户信息 // @Summary 获取用户信息
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -350,14 +408,16 @@ func (b *BaseApi) SetSelfInfo(c *gin.Context) {
// @Router /user/getUserInfo [get] // @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)
} }
}
// ResetPassword
// @Tags SysUser // @Tags SysUser
// @Summary 重置用户密码 // @Summary 重置用户密码
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -367,11 +427,16 @@ func (b *BaseApi) GetUserInfo(c *gin.Context) {
// @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
+15 -7
View File
@@ -11,6 +11,7 @@ import (
type EmailApi struct{} type EmailApi struct{}
// EmailTest
// @Tags System // @Tags System
// @Summary 发送测试邮件 // @Summary 发送测试邮件
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -18,14 +19,16 @@ type EmailApi struct{}
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
// @Router /email/emailTest [post] // @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)
} }
}
// SendEmail
// @Tags System // @Tags System
// @Summary 发送邮件 // @Summary 发送邮件
// @Security ApiKeyAuth // @Security ApiKeyAuth
@@ -35,11 +38,16 @@ func (s *EmailApi) EmailTest(c *gin.Context) {
// @Router /email/sendEmail [post] // @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
} }