后端重构
This commit is contained in:
@@ -8,6 +8,7 @@ type ApiGroup struct {
|
||||
UserApi
|
||||
ApiApi
|
||||
AuthorityApi
|
||||
AuthorityBtnApi
|
||||
MenuApi
|
||||
DictionaryApi
|
||||
DictionaryDetailApi
|
||||
@@ -25,27 +26,31 @@ type ApiGroup struct {
|
||||
AutoCodePackageApi
|
||||
AutoCodeTemplateApi
|
||||
AutoCodePluginApi
|
||||
AutoCodeMcpApi
|
||||
}
|
||||
|
||||
// 业务层依赖
|
||||
var (
|
||||
userUsecase *system.UserUsecase
|
||||
apiUsecase *system.ApiUsecase
|
||||
authorityUsecase *system.AuthorityUsecase
|
||||
authorityBtnUsecase *system.AuthorityBtnUsecase
|
||||
menuUsecase *system.MenuUsecase
|
||||
dictionaryUsecase *system.DictionaryUsecase
|
||||
casbinUsecase *system.CasbinUsecase
|
||||
jwtBlacklistUsecase *system.JwtBlacklistUsecase
|
||||
operationRecordUsecase *system.OperationRecordUsecase
|
||||
paramsUsecase *system.ParamsUsecase
|
||||
errorUsecase *system.ErrorUsecase
|
||||
versionUsecase *system.VersionUsecase
|
||||
systemUsecase *system.SystemUsecase
|
||||
exportTemplateUsecase *system.ExportTemplateUsecase
|
||||
autoCodeUsecase *system.AutoCodeUsecase
|
||||
autoCodeHistoryUsecase *system.AutoCodeHistoryUsecase
|
||||
autoCodePackageUsecase *system.AutoCodePackageUsecase
|
||||
userUsecase *system.UserUsecase
|
||||
apiUsecase *system.ApiUsecase
|
||||
authorityUsecase *system.AuthorityUsecase
|
||||
authorityBtnUsecase *system.AuthorityBtnUsecase
|
||||
menuUsecase *system.MenuUsecase
|
||||
dictionaryUsecase *system.DictionaryUsecase
|
||||
casbinUsecase *system.CasbinUsecase
|
||||
jwtBlacklistUsecase *system.JwtBlacklistUsecase
|
||||
operationRecordUsecase *system.OperationRecordUsecase
|
||||
paramsUsecase *system.ParamsUsecase
|
||||
errorUsecase *system.ErrorUsecase
|
||||
versionUsecase *system.VersionUsecase
|
||||
systemUsecase *system.SystemUsecase
|
||||
exportTemplateUsecase *system.ExportTemplateUsecase
|
||||
autoCodeUsecase *system.AutoCodeUsecase
|
||||
autoCodeHistoryUsecase *system.AutoCodeHistoryUsecase
|
||||
autoCodePackageUsecase *system.AutoCodePackageUsecase
|
||||
autoCodeTemplateUsecase *system.AutoCodeTemplateUsecase
|
||||
autoCodePluginUsecase *system.AutoCodePluginUsecase
|
||||
autoCodeMcpUsecase *system.AutoCodeMCPUsecase
|
||||
)
|
||||
|
||||
// InitUsecases 初始化业务层依赖
|
||||
@@ -67,6 +72,9 @@ func InitUsecases(
|
||||
autoCode *system.AutoCodeUsecase,
|
||||
autoCodeHistory *system.AutoCodeHistoryUsecase,
|
||||
autoCodePackage *system.AutoCodePackageUsecase,
|
||||
autoCodeTemplate *system.AutoCodeTemplateUsecase,
|
||||
autoCodePlugin *system.AutoCodePluginUsecase,
|
||||
autoCodeMcp *system.AutoCodeMCPUsecase,
|
||||
) {
|
||||
userUsecase = user
|
||||
apiUsecase = api
|
||||
@@ -85,9 +93,13 @@ func InitUsecases(
|
||||
autoCodeUsecase = autoCode
|
||||
autoCodeHistoryUsecase = autoCodeHistory
|
||||
autoCodePackageUsecase = autoCodePackage
|
||||
autoCodeTemplateUsecase = autoCodeTemplate
|
||||
autoCodePluginUsecase = autoCodePlugin
|
||||
autoCodeMcpUsecase = autoCodeMcp
|
||||
}
|
||||
|
||||
// Api类型定义
|
||||
type AutoCodePackageApi struct{}
|
||||
type AutoCodeTemplateApi struct{}
|
||||
type AutoCodePluginApi struct{}
|
||||
type AutoCodeMcpApi struct{}
|
||||
|
||||
@@ -54,7 +54,15 @@ type DeleteApisByIdsRequest struct {
|
||||
Ids []uint `json:"ids" binding:"required"`
|
||||
}
|
||||
|
||||
// CreateApi 创建API
|
||||
// CreateApi
|
||||
// @Tags SysApi
|
||||
// @Summary 创建基础api
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body CreateApiRequest true "api路径, api中文描述, api组, 方法"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建基础api"
|
||||
// @Router /api/createApi [post]
|
||||
func (a *ApiApi) CreateApi(c *gin.Context) {
|
||||
var req CreateApiRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -77,7 +85,15 @@ func (a *ApiApi) CreateApi(c *gin.Context) {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteApi 删除API
|
||||
// DeleteApi
|
||||
// @Tags SysApi
|
||||
// @Summary 删除api
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DeleteApiRequest true "ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除api"
|
||||
// @Router /api/deleteApi [post]
|
||||
func (a *ApiApi) DeleteApi(c *gin.Context) {
|
||||
var req DeleteApiRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -93,7 +109,15 @@ func (a *ApiApi) DeleteApi(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateApi 更新API
|
||||
// UpdateApi
|
||||
// @Tags SysApi
|
||||
// @Summary 修改基础api
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body UpdateApiRequest true "api路径, api中文描述, api组, 方法"
|
||||
// @Success 200 {object} response.Response{msg=string} "修改基础api"
|
||||
// @Router /api/updateApi [post]
|
||||
func (a *ApiApi) UpdateApi(c *gin.Context) {
|
||||
var req UpdateApiRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -117,7 +141,15 @@ func (a *ApiApi) UpdateApi(c *gin.Context) {
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
|
||||
// GetApiList 获取API列表
|
||||
// GetApiList
|
||||
// @Tags SysApi
|
||||
// @Summary 分页获取API列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body GetApiListRequest true "分页获取API列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取API列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /api/getApiList [post]
|
||||
func (a *ApiApi) GetApiList(c *gin.Context) {
|
||||
var req GetApiListRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -160,7 +192,15 @@ func (a *ApiApi) GetApiList(c *gin.Context) {
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetApiById 根据ID获取API
|
||||
// GetApiById
|
||||
// @Tags SysApi
|
||||
// @Summary 根据id获取api
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body GetApiByIdRequest true "根据id获取api"
|
||||
// @Success 200 {object} response.Response{data=system.Api} "根据id获取api,返回包括api详情"
|
||||
// @Router /api/getApiById [post]
|
||||
func (a *ApiApi) GetApiById(c *gin.Context) {
|
||||
var req GetApiByIdRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -177,7 +217,14 @@ func (a *ApiApi) GetApiById(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"api": api}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetAllApis 获取所有API
|
||||
// GetAllApis
|
||||
// @Tags SysApi
|
||||
// @Summary 获取所有的Api 不分页
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=[]system.Api,msg=string} "获取所有的Api 不分页,返回包括api列表"
|
||||
// @Router /api/getAllApis [post]
|
||||
func (a *ApiApi) GetAllApis(c *gin.Context) {
|
||||
authorityID := utils.GetUserAuthorityId(c)
|
||||
apis, err := apiUsecase.GetAllApis(c, authorityID)
|
||||
@@ -189,7 +236,15 @@ func (a *ApiApi) GetAllApis(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"apis": apis}, "获取成功", c)
|
||||
}
|
||||
|
||||
// DeleteApisByIds 批量删除API
|
||||
// DeleteApisByIds
|
||||
// @Tags SysApi
|
||||
// @Summary 删除选中Api
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DeleteApisByIdsRequest true "ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除选中Api"
|
||||
// @Router /api/deleteApisByIds [delete]
|
||||
func (a *ApiApi) DeleteApisByIds(c *gin.Context) {
|
||||
var req DeleteApisByIdsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -205,7 +260,13 @@ func (a *ApiApi) DeleteApisByIds(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// FreshCasbin 刷新Casbin缓存
|
||||
// FreshCasbin
|
||||
// @Tags SysApi
|
||||
// @Summary 刷新casbin缓存
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "刷新成功"
|
||||
// @Router /api/freshCasbin [get]
|
||||
func (a *ApiApi) FreshCasbin(c *gin.Context) {
|
||||
if err := casbinUsecase.FreshCasbin(); err != nil {
|
||||
response.FailWithMessage("刷新失败", c)
|
||||
@@ -214,3 +275,107 @@ func (a *ApiApi) FreshCasbin(c *gin.Context) {
|
||||
|
||||
response.OkWithMessage("刷新成功", c)
|
||||
}
|
||||
|
||||
// IgnoreApiRequest 忽略API请求
|
||||
type IgnoreApiRequest struct {
|
||||
Path string `json:"path" binding:"required"`
|
||||
Method string `json:"method" binding:"required"`
|
||||
Flag bool `json:"flag"` // true: 忽略, false: 取消忽略
|
||||
}
|
||||
|
||||
// SyncApisRequest 同步API请求
|
||||
type SyncApisRequest struct {
|
||||
NewApis []*system.Api `json:"newApis"`
|
||||
DeleteApis []*system.Api `json:"deleteApis"`
|
||||
}
|
||||
|
||||
// SyncApi
|
||||
// @Tags SysApi
|
||||
// @Summary 同步API
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "同步API"
|
||||
// @Router /api/syncApi [get]
|
||||
func (a *ApiApi) SyncApi(c *gin.Context) {
|
||||
newApis, deleteApis, ignoreApis, err := apiUsecase.SyncApi(c)
|
||||
if err != nil {
|
||||
response.FailWithMessage("同步失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithData(gin.H{
|
||||
"newApis": newApis,
|
||||
"deleteApis": deleteApis,
|
||||
"ignoreApis": ignoreApis,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// GetApiGroups
|
||||
// @Tags SysApi
|
||||
// @Summary 获取API分组
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "获取API分组"
|
||||
// @Router /api/getApiGroups [get]
|
||||
func (a *ApiApi) GetApiGroups(c *gin.Context) {
|
||||
groups, apiGroupMap, err := apiUsecase.GetApiGroups(c)
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithData(gin.H{
|
||||
"groups": groups,
|
||||
"apiGroupMap": apiGroupMap,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// IgnoreApi
|
||||
// @Tags SysApi
|
||||
// @Summary 忽略API
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body IgnoreApiRequest true "忽略API请求"
|
||||
// @Success 200 {object} response.Response{msg=string} "忽略API"
|
||||
// @Router /api/ignoreApi [post]
|
||||
func (a *ApiApi) IgnoreApi(c *gin.Context) {
|
||||
var req IgnoreApiRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := apiUsecase.IgnoreApi(c, req.Path, req.Method, req.Flag); err != nil {
|
||||
response.FailWithMessage("忽略失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
response.Ok(c)
|
||||
}
|
||||
|
||||
// EnterSyncApi
|
||||
// @Tags SysApi
|
||||
// @Summary 确认同步API
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body SyncApisRequest true "同步API请求"
|
||||
// @Success 200 {object} response.Response{msg=string} "确认同步API"
|
||||
// @Router /api/enterSyncApi [post]
|
||||
func (a *ApiApi) EnterSyncApi(c *gin.Context) {
|
||||
var req SyncApisRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := apiUsecase.EnterSyncApi(c, req.NewApis, req.DeleteApis); err != nil {
|
||||
response.FailWithMessage("同步失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
response.Ok(c)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,15 @@ type GetAuthorityListRequest struct {
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
|
||||
// CreateAuthority 创建角色
|
||||
// CreateAuthority
|
||||
// @Tags Authority
|
||||
// @Summary 创建角色
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body CreateAuthorityRequest true "权限id, 权限名, 父角色id"
|
||||
// @Success 200 {object} response.Response{data=system.Authority,msg=string} "创建角色,返回包括系统角色详情"
|
||||
// @Router /authority/createAuthority [post]
|
||||
func (a *AuthorityApi) CreateAuthority(c *gin.Context) {
|
||||
var req CreateAuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -70,10 +78,24 @@ func (a *AuthorityApi) CreateAuthority(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 刷新Casbin权限
|
||||
if err := casbinUsecase.FreshCasbin(); err != nil {
|
||||
response.FailWithMessage("创建成功,权限刷新失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithDetailed(gin.H{"authority": created}, "创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteAuthority 删除角色
|
||||
// DeleteAuthority
|
||||
// @Tags Authority
|
||||
// @Summary 删除角色
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DeleteAuthorityRequest true "删除角色"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除角色"
|
||||
// @Router /authority/deleteAuthority [post]
|
||||
func (a *AuthorityApi) DeleteAuthority(c *gin.Context) {
|
||||
var req DeleteAuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -86,10 +108,21 @@ func (a *AuthorityApi) DeleteAuthority(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 刷新Casbin权限
|
||||
_ = casbinUsecase.FreshCasbin()
|
||||
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateAuthority 更新角色
|
||||
// UpdateAuthority
|
||||
// @Tags Authority
|
||||
// @Summary 更新角色信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body UpdateAuthorityRequest true "权限id, 权限名, 父角色id"
|
||||
// @Success 200 {object} response.Response{data=system.Authority,msg=string} "更新角色信息,返回包括系统角色详情"
|
||||
// @Router /authority/updateAuthority [post]
|
||||
func (a *AuthorityApi) UpdateAuthority(c *gin.Context) {
|
||||
var req UpdateAuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -113,7 +146,15 @@ func (a *AuthorityApi) UpdateAuthority(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"authority": updated}, "更新成功", c)
|
||||
}
|
||||
|
||||
// GetAuthorityList 获取角色列表
|
||||
// GetAuthorityList
|
||||
// @Tags Authority
|
||||
// @Summary 分页获取角色列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body GetAuthorityListRequest true "页码, 每页大小"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取角色列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /authority/getAuthorityList [post]
|
||||
func (a *AuthorityApi) GetAuthorityList(c *gin.Context) {
|
||||
// 从JWT获取当前用户的角色ID
|
||||
claims, exists := c.Get("claims")
|
||||
@@ -132,7 +173,15 @@ func (a *AuthorityApi) GetAuthorityList(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"list": list}, "获取成功", c)
|
||||
}
|
||||
|
||||
// CopyAuthority 复制角色
|
||||
// CopyAuthority
|
||||
// @Tags Authority
|
||||
// @Summary 拷贝角色
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body CopyAuthorityRequest true "旧角色id, 新权限id, 新权限名, 新父角色id"
|
||||
// @Success 200 {object} response.Response{data=system.Authority,msg=string} "拷贝角色,返回包括系统角色详情"
|
||||
// @Router /authority/copyAuthority [post]
|
||||
func (a *AuthorityApi) CopyAuthority(c *gin.Context) {
|
||||
var req CopyAuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -164,7 +213,15 @@ func (a *AuthorityApi) CopyAuthority(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"authority": created}, "复制成功", c)
|
||||
}
|
||||
|
||||
// SetDataAuthority 设置数据权限
|
||||
// SetDataAuthority
|
||||
// @Tags Authority
|
||||
// @Summary 设置角色资源权限
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body SetDataAuthorityRequest true "设置角色资源权限"
|
||||
// @Success 200 {object} response.Response{msg=string} "设置角色资源权限"
|
||||
// @Router /authority/setDataAuthority [post]
|
||||
func (a *AuthorityApi) SetDataAuthority(c *gin.Context) {
|
||||
var req SetDataAuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"kra/pkg/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type AuthorityBtnApi struct{}
|
||||
|
||||
// AuthorityBtnRequest 权限按钮请求
|
||||
type AuthorityBtnRequest struct {
|
||||
MenuID uint `json:"menuID" binding:"required"`
|
||||
AuthorityId uint `json:"authorityId" binding:"required"`
|
||||
Selected []uint `json:"selected"`
|
||||
}
|
||||
|
||||
// GetAuthorityBtn
|
||||
// @Tags AuthorityBtn
|
||||
// @Summary 获取权限按钮
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body AuthorityBtnRequest true "菜单ID, 角色ID, 选中的按钮ID集合"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取权限按钮"
|
||||
// @Router /authorityBtn/getAuthorityBtn [post]
|
||||
func (a *AuthorityBtnApi) GetAuthorityBtn(c *gin.Context) {
|
||||
var req AuthorityBtnRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
res, err := authorityBtnUsecase.GetAuthorityBtn(c, req.AuthorityId, req.MenuID)
|
||||
if err != nil {
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithDetailed(res, "查询成功", c)
|
||||
}
|
||||
|
||||
// SetAuthorityBtn
|
||||
// @Tags AuthorityBtn
|
||||
// @Summary 设置权限按钮
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body AuthorityBtnRequest true "菜单ID, 角色ID, 选中的按钮ID集合"
|
||||
// @Success 200 {object} response.Response{msg=string} "设置权限按钮"
|
||||
// @Router /authorityBtn/setAuthorityBtn [post]
|
||||
func (a *AuthorityBtnApi) SetAuthorityBtn(c *gin.Context) {
|
||||
var req AuthorityBtnRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := authorityBtnUsecase.SetAuthorityBtn(c, req.AuthorityId, req.MenuID, req.Selected); err != nil {
|
||||
response.FailWithMessage("分配失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMessage("分配成功", c)
|
||||
}
|
||||
|
||||
// CanRemoveAuthorityBtn
|
||||
// @Tags AuthorityBtn
|
||||
// @Summary 检查是否可以删除权限按钮
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param id query string true "按钮ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /authorityBtn/canRemoveAuthorityBtn [post]
|
||||
func (a *AuthorityBtnApi) CanRemoveAuthorityBtn(c *gin.Context) {
|
||||
idStr := c.Query("id")
|
||||
if idStr == "" {
|
||||
response.FailWithMessage("缺少参数: id", c)
|
||||
return
|
||||
}
|
||||
|
||||
var id uint
|
||||
for _, ch := range idStr {
|
||||
if ch >= '0' && ch <= '9' {
|
||||
id = id*10 + uint(ch-'0')
|
||||
}
|
||||
}
|
||||
|
||||
if err := authorityBtnUsecase.CanRemoveAuthorityBtn(c, id); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
@@ -6,42 +6,55 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// JSONMap 通用JSON Map类型
|
||||
type JSONMap map[string]interface{}
|
||||
|
||||
type AutoCodeApi struct{}
|
||||
|
||||
// GetDB 获取当前所有数据库
|
||||
// @Summary 获取当前所有数据库
|
||||
// @Tags AutoCode
|
||||
// @Security ApiKeyAuth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{}}
|
||||
// @Param businessDB query string false "业务数据库别名"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取当前所有数据库"
|
||||
// @Router /autoCode/getDB [get]
|
||||
func (api *AutoCodeApi) GetDB(c *gin.Context) {
|
||||
dbs, err := autoCodeUsecase.GetDB(c.Request.Context())
|
||||
businessDB := c.Query("businessDB")
|
||||
// 获取数据库列表
|
||||
dbs, err := autoCodeUsecase.GetDB(c.Request.Context(), businessDB)
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取失败: "+err.Error(), c)
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c)
|
||||
// 获取配置的数据库列表
|
||||
dbList := autoCodeUsecase.GetDBList()
|
||||
response.OkWithDetailed(gin.H{"dbs": dbs, "dbList": dbList}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetTables 获取当前数据库所有表
|
||||
// @Summary 获取当前数据库所有表
|
||||
// @Tags AutoCode
|
||||
// @Security ApiKeyAuth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param dbName query string false "数据库名"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{}}
|
||||
// @Param businessDB query string false "业务数据库别名"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取当前数据库所有表"
|
||||
// @Router /autoCode/getTables [get]
|
||||
func (api *AutoCodeApi) GetTables(c *gin.Context) {
|
||||
dbName := c.Query("dbName")
|
||||
businessDB := c.Query("businessDB")
|
||||
|
||||
// 如果dbName为空,使用默认数据库名
|
||||
if dbName == "" {
|
||||
response.FailWithMessage("数据库名不能为空", c)
|
||||
return
|
||||
dbName = autoCodeUsecase.GetActiveDBName(businessDB)
|
||||
}
|
||||
|
||||
tables, err := autoCodeUsecase.GetTables(c.Request.Context(), dbName)
|
||||
tables, err := autoCodeUsecase.GetTables(c.Request.Context(), businessDB, dbName)
|
||||
if err != nil {
|
||||
response.FailWithMessage("查询table失败: "+err.Error(), c)
|
||||
response.FailWithMessage("查询table失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(gin.H{"tables": tables}, "获取成功", c)
|
||||
@@ -50,28 +63,51 @@ func (api *AutoCodeApi) GetTables(c *gin.Context) {
|
||||
// GetColumn 获取当前表所有字段
|
||||
// @Summary 获取当前表所有字段
|
||||
// @Tags AutoCode
|
||||
// @Security ApiKeyAuth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param dbName query string false "数据库名"
|
||||
// @Param tableName query string true "表名"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{}}
|
||||
// @Param businessDB query string false "业务数据库别名"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取当前表所有字段"
|
||||
// @Router /autoCode/getColumn [get]
|
||||
func (api *AutoCodeApi) GetColumn(c *gin.Context) {
|
||||
businessDB := c.Query("businessDB")
|
||||
dbName := c.Query("dbName")
|
||||
tableName := c.Query("tableName")
|
||||
if tableName == "" {
|
||||
response.FailWithMessage("表名不能为空", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 如果dbName为空,使用默认数据库名
|
||||
if dbName == "" {
|
||||
response.FailWithMessage("数据库名不能为空", c)
|
||||
return
|
||||
dbName = autoCodeUsecase.GetActiveDBName(businessDB)
|
||||
}
|
||||
|
||||
columns, err := autoCodeUsecase.GetColumn(c.Request.Context(), tableName, dbName)
|
||||
columns, err := autoCodeUsecase.GetColumn(c.Request.Context(), businessDB, tableName, dbName)
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取失败: "+err.Error(), c)
|
||||
response.FailWithMessage("获取失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c)
|
||||
}
|
||||
|
||||
// LLMAuto 大模型自动生成代码
|
||||
// @Summary 大模型自动生成代码
|
||||
// @Tags AutoCode
|
||||
// @Security ApiKeyAuth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param data body JSONMap true "LLM参数"
|
||||
// @Success 200 {object} response.Response{data=interface{}}
|
||||
// @Router /autoCode/llmAuto [post]
|
||||
func (api *AutoCodeApi) LLMAuto(c *gin.Context) {
|
||||
var llm JSONMap
|
||||
if err := c.ShouldBindJSON(&llm); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
data, err := autoCodeUsecase.LLMAuto(c.Request.Context(), llm)
|
||||
if err != nil {
|
||||
response.FailWithMessage("大模型生成失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(data, c)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
|
||||
"kra/internal/biz/system"
|
||||
"kra/internal/conf"
|
||||
mcpClient "kra/pkg/mcp/client"
|
||||
"kra/pkg/response"
|
||||
)
|
||||
|
||||
// MCP配置(通过InitMcpConfig初始化)
|
||||
var (
|
||||
mcpConfig *conf.MCP
|
||||
serverConf *conf.Server
|
||||
)
|
||||
|
||||
// InitMcpConfig 初始化MCP配置
|
||||
func InitMcpConfig(mcp *conf.MCP, server *conf.Server) {
|
||||
mcpConfig = mcp
|
||||
serverConf = server
|
||||
}
|
||||
|
||||
// MCP 创建MCP工具
|
||||
// @Tags MCP
|
||||
// @Summary 创建MCP工具
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body system.AutoMcpTool true "MCP工具信息"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /autoCode/mcp [post]
|
||||
func (a *AutoCodeMcpApi) MCP(c *gin.Context) {
|
||||
var info system.AutoMcpTool
|
||||
err := c.ShouldBindJSON(&info)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
toolFilePath, err := autoCodeMcpUsecase.CreateMcp(c.Request.Context(), info)
|
||||
if err != nil {
|
||||
response.FailWithMessage("创建失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功,MCP Tool路径:"+toolFilePath, c)
|
||||
}
|
||||
|
||||
// MCPList 获取MCP工具列表
|
||||
// @Tags MCP
|
||||
// @Summary 获取MCP工具列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=interface{}} "获取成功"
|
||||
// @Router /autoCode/mcpList [get]
|
||||
func (a *AutoCodeMcpApi) MCPList(c *gin.Context) {
|
||||
if mcpConfig == nil || !mcpConfig.Enabled {
|
||||
response.OkWithData(gin.H{
|
||||
"mcpServerConfig": map[string]interface{}{},
|
||||
"list": []interface{}{},
|
||||
}, c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取服务器地址
|
||||
addr := "8888"
|
||||
if serverConf != nil && serverConf.Http != nil {
|
||||
addr = serverConf.Http.Addr
|
||||
}
|
||||
|
||||
baseUrl := fmt.Sprintf("http://127.0.0.1:%s%s", addr, mcpConfig.SsePath)
|
||||
|
||||
client, err := mcpClient.NewClient(baseUrl, "testClient", "v1.0.0", mcpConfig.Name)
|
||||
if err != nil {
|
||||
response.FailWithMessage("连接MCP服务失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
toolsRequest := mcp.ListToolsRequest{}
|
||||
list, err := client.ListTools(c.Request.Context(), toolsRequest)
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取工具列表失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
mcpServerConfig := map[string]interface{}{
|
||||
"mcpServers": map[string]interface{}{
|
||||
mcpConfig.Name: map[string]string{
|
||||
"url": baseUrl,
|
||||
},
|
||||
},
|
||||
}
|
||||
response.OkWithData(gin.H{
|
||||
"mcpServerConfig": mcpServerConfig,
|
||||
"list": list,
|
||||
}, c)
|
||||
}
|
||||
|
||||
// MCPTest 测试MCP工具
|
||||
// @Tags MCP
|
||||
// @Summary 测试MCP工具
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body object true "MCP工具调用参数"
|
||||
// @Success 200 {object} response.Response{data=interface{}} "测试成功"
|
||||
// @Router /autoCode/mcpTest [post]
|
||||
func (a *AutoCodeMcpApi) MCPTest(c *gin.Context) {
|
||||
// 定义接口请求结构
|
||||
var testRequest struct {
|
||||
Name string `json:"name" binding:"required"` // 工具名称
|
||||
Arguments map[string]interface{} `json:"arguments" binding:"required"` // 工具参数
|
||||
}
|
||||
|
||||
// 绑定JSON请求体
|
||||
if err := c.ShouldBindJSON(&testRequest); err != nil {
|
||||
response.FailWithMessage("参数解析失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if mcpConfig == nil || !mcpConfig.Enabled {
|
||||
response.FailWithMessage("MCP服务未启用", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取服务器地址
|
||||
addr := "8888"
|
||||
if serverConf != nil && serverConf.Http != nil {
|
||||
addr = serverConf.Http.Addr
|
||||
}
|
||||
|
||||
// 创建MCP客户端
|
||||
baseUrl := fmt.Sprintf("http://127.0.0.1:%s%s", addr, mcpConfig.SsePath)
|
||||
client, err := mcpClient.NewClient(baseUrl, "testClient", "v1.0.0", mcpConfig.Name)
|
||||
if err != nil {
|
||||
response.FailWithMessage("创建MCP客户端失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
ctx := c.Request.Context()
|
||||
|
||||
// 初始化MCP连接
|
||||
initRequest := mcp.InitializeRequest{}
|
||||
initRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
|
||||
initRequest.Params.ClientInfo = mcp.Implementation{
|
||||
Name: "testClient",
|
||||
Version: "v1.0.0",
|
||||
}
|
||||
|
||||
_, err = client.Initialize(ctx, initRequest)
|
||||
if err != nil {
|
||||
response.FailWithMessage("初始化MCP连接失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 构建工具调用请求
|
||||
request := mcp.CallToolRequest{}
|
||||
request.Params.Name = testRequest.Name
|
||||
request.Params.Arguments = testRequest.Arguments
|
||||
|
||||
// 调用工具
|
||||
result, err := client.CallTool(ctx, request)
|
||||
if err != nil {
|
||||
response.FailWithMessage("工具调用失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理响应结果
|
||||
if len(result.Content) == 0 {
|
||||
response.FailWithMessage("工具未返回任何内容", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
response.OkWithData(result.Content, c)
|
||||
}
|
||||
@@ -1,37 +1,56 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"kra/internal/biz/system"
|
||||
"kra/pkg/response"
|
||||
"kra/pkg/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// GetPackages 获取所有包
|
||||
// Create 创建package
|
||||
// @Tags AutoCodePackage
|
||||
// @Summary 获取所有包
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=[]system.SysAutoCodePackage} "获取成功"
|
||||
// @Router /autoCode/getPackage [post]
|
||||
func GetPackages(c *gin.Context) {
|
||||
pkgs, err := autoCodePackageUsecase.All(c.Request.Context())
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(pkgs, "获取成功", c)
|
||||
}
|
||||
|
||||
// DeletePackage 删除包
|
||||
// @Tags AutoCodePackage
|
||||
// @Summary 删除包
|
||||
// @Summary 创建package
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body request.GetById true "删除包"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Param data body system.SysAutoCodePackage true "创建package"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建package成功"
|
||||
// @Router /autoCode/createPackage [post]
|
||||
func (a *AutoCodePackageApi) Create(c *gin.Context) {
|
||||
var info system.SysAutoCodePackage
|
||||
if err := c.ShouldBindJSON(&info); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err := utils.Verify(info, utils.AutoPackageVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
// PackageName可能导致路径穿越的问题 / 和 \ 都要防止
|
||||
if strings.Contains(info.PackageName, "\\") || strings.Contains(info.PackageName, "/") || strings.Contains(info.PackageName, "..") {
|
||||
response.FailWithMessage("包名不合法", c)
|
||||
return
|
||||
}
|
||||
if err := autoCodePackageUsecase.Create(c.Request.Context(), &info); err != nil {
|
||||
response.FailWithMessage("创建失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// Delete 删除package
|
||||
// @Tags AutoCodePackage
|
||||
// @Summary 删除package
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body map[string]uint true "删除package"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除package成功"
|
||||
// @Router /autoCode/delPackage [post]
|
||||
func DeletePackage(c *gin.Context) {
|
||||
func (a *AutoCodePackageApi) Delete(c *gin.Context) {
|
||||
var req struct {
|
||||
ID uint `json:"id"`
|
||||
}
|
||||
@@ -46,15 +65,36 @@ func DeletePackage(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// GetTemplates 获取所有模版
|
||||
// All 获取所有package
|
||||
// @Tags AutoCodePackage
|
||||
// @Summary 获取package
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取package成功"
|
||||
// @Router /autoCode/getPackage [post]
|
||||
func (a *AutoCodePackageApi) All(c *gin.Context) {
|
||||
data, err := autoCodePackageUsecase.All(c.Request.Context())
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(gin.H{"pkgs": data}, "获取成功", c)
|
||||
}
|
||||
|
||||
// Templates 获取所有模版
|
||||
// @Tags AutoCodePackage
|
||||
// @Summary 获取所有模版
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=[]string} "获取成功"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取模版成功"
|
||||
// @Router /autoCode/getTemplates [get]
|
||||
func GetTemplates(c *gin.Context) {
|
||||
// 返回固定的模版列表
|
||||
templates := []string{"package", "plugin"}
|
||||
response.OkWithDetailed(templates, "获取成功", c)
|
||||
func (a *AutoCodePackageApi) Templates(c *gin.Context) {
|
||||
data, err := autoCodePackageUsecase.GetTemplateNames(c.Request.Context())
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(data, "获取成功", c)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"kra/internal/biz/system"
|
||||
"kra/pkg/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// InstallPlugin 安装插件
|
||||
// Install 安装插件
|
||||
// @Tags AutoCodePlugin
|
||||
// @Summary 安装插件
|
||||
// @Security ApiKeyAuth
|
||||
@@ -15,12 +18,37 @@ import (
|
||||
// @Param plug formData file true "插件文件"
|
||||
// @Success 200 {object} response.Response{data=[]interface{}} "安装成功"
|
||||
// @Router /autoCode/installPlugin [post]
|
||||
func InstallPlugin(c *gin.Context) {
|
||||
// TODO: 实现插件安装功能
|
||||
response.FailWithMessage("功能开发中", c)
|
||||
func (a *AutoCodePluginApi) Install(c *gin.Context) {
|
||||
header, err := c.FormFile("plug")
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
web, server, err := autoCodePluginUsecase.Install(header)
|
||||
webStr := "web插件安装成功"
|
||||
serverStr := "server插件安装成功"
|
||||
if web == -1 {
|
||||
webStr = "web端插件未成功安装,请按照文档自行解压安装,如果为纯后端插件请忽略此条提示"
|
||||
}
|
||||
if server == -1 {
|
||||
serverStr = "server端插件未成功安装,请按照文档自行解压安装,如果为纯前端插件请忽略此条提示"
|
||||
}
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData([]interface{}{
|
||||
gin.H{
|
||||
"code": web,
|
||||
"msg": webStr,
|
||||
},
|
||||
gin.H{
|
||||
"code": server,
|
||||
"msg": serverStr,
|
||||
}}, c)
|
||||
}
|
||||
|
||||
// PackagedPlugin 打包插件
|
||||
// Packaged 打包插件
|
||||
// @Tags AutoCodePlugin
|
||||
// @Summary 打包插件
|
||||
// @Security ApiKeyAuth
|
||||
@@ -29,35 +57,60 @@ func InstallPlugin(c *gin.Context) {
|
||||
// @Param plugName query string true "插件名称"
|
||||
// @Success 200 {object} response.Response{msg=string} "打包成功"
|
||||
// @Router /autoCode/pubPlug [post]
|
||||
func PackagedPlugin(c *gin.Context) {
|
||||
// TODO: 实现插件打包功能
|
||||
response.FailWithMessage("功能开发中", c)
|
||||
func (a *AutoCodePluginApi) Packaged(c *gin.Context) {
|
||||
plugName := c.Query("plugName")
|
||||
zipPath, err := autoCodePluginUsecase.PubPlug(plugName)
|
||||
if err != nil {
|
||||
response.FailWithMessage("打包失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage(fmt.Sprintf("打包成功,文件路径为:%s", zipPath), c)
|
||||
}
|
||||
|
||||
// InitPluginMenu 初始化插件菜单
|
||||
// InitMenu 初始化插件菜单
|
||||
// @Tags AutoCodePlugin
|
||||
// @Summary 初始化插件菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body map[string]interface{} true "菜单信息"
|
||||
// @Param data body system.InitMenuRequest true "菜单信息"
|
||||
// @Success 200 {object} response.Response{msg=string} "初始化成功"
|
||||
// @Router /autoCode/initMenu [post]
|
||||
func InitPluginMenu(c *gin.Context) {
|
||||
// TODO: 实现插件菜单初始化功能
|
||||
response.FailWithMessage("功能开发中", c)
|
||||
func (a *AutoCodePluginApi) InitMenu(c *gin.Context) {
|
||||
var menuInfo system.InitMenuRequest
|
||||
err := c.ShouldBindJSON(&menuInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = autoCodePluginUsecase.InitMenu(c.Request.Context(), menuInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage("创建初始化Menu失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("文件变更成功", c)
|
||||
}
|
||||
|
||||
// InitPluginAPI 初始化插件API
|
||||
// InitAPI 初始化插件API
|
||||
// @Tags AutoCodePlugin
|
||||
// @Summary 初始化插件API
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body map[string]interface{} true "API信息"
|
||||
// @Param data body system.InitApiRequest true "API信息"
|
||||
// @Success 200 {object} response.Response{msg=string} "初始化成功"
|
||||
// @Router /autoCode/initAPI [post]
|
||||
func InitPluginAPI(c *gin.Context) {
|
||||
// TODO: 实现插件API初始化功能
|
||||
response.FailWithMessage("功能开发中", c)
|
||||
func (a *AutoCodePluginApi) InitAPI(c *gin.Context) {
|
||||
var apiInfo system.InitApiRequest
|
||||
err := c.ShouldBindJSON(&apiInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = autoCodePluginUsecase.InitAPI(c.Request.Context(), apiInfo)
|
||||
if err != nil {
|
||||
response.FailWithMessage("创建初始化API失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("文件变更成功", c)
|
||||
}
|
||||
|
||||
@@ -1,37 +1,76 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"go/token"
|
||||
"strings"
|
||||
|
||||
"kra/internal/biz/system"
|
||||
"kra/pkg/response"
|
||||
"kra/pkg/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// PreviewCode 预览代码
|
||||
// Preview 预览创建后的代码
|
||||
// @Tags AutoCodeTemplate
|
||||
// @Summary 预览创建后的代码
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body map[string]interface{} true "预览创建代码"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{}} "预览成功"
|
||||
// @Param data body system.AutoCodeInfo true "预览创建代码"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "预览创建后的代码"
|
||||
// @Router /autoCode/preview [post]
|
||||
func PreviewCode(c *gin.Context) {
|
||||
// TODO: 实现代码预览功能
|
||||
response.FailWithMessage("功能开发中", c)
|
||||
func (a *AutoCodeTemplateApi) Preview(c *gin.Context) {
|
||||
var info system.AutoCodeInfo
|
||||
if err := c.ShouldBindJSON(&info); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err := utils.Verify(info, utils.AutoCodeVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err := pretreatment(&info); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
info.PackageT = utils.FirstUpper(info.Package)
|
||||
autoCode, err := autoCodeTemplateUsecase.Preview(c.Request.Context(), &info)
|
||||
if err != nil {
|
||||
response.FailWithMessage("预览失败:"+err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithDetailed(gin.H{"autoCode": autoCode}, "预览成功", c)
|
||||
}
|
||||
|
||||
// CreateCode 创建代码
|
||||
// Create 自动代码模板
|
||||
// @Tags AutoCodeTemplate
|
||||
// @Summary 自动代码模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body map[string]interface{} true "创建自动代码"
|
||||
// @Param data body system.AutoCodeInfo true "创建自动代码"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /autoCode/createTemp [post]
|
||||
func CreateCode(c *gin.Context) {
|
||||
// TODO: 实现代码创建功能
|
||||
response.FailWithMessage("功能开发中", c)
|
||||
func (a *AutoCodeTemplateApi) Create(c *gin.Context) {
|
||||
var info system.AutoCodeInfo
|
||||
if err := c.ShouldBindJSON(&info); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err := utils.Verify(info, utils.AutoCodeVerify); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err := pretreatment(&info); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if err := autoCodeTemplateUsecase.Create(c.Request.Context(), &info); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// AddFunc 增加方法
|
||||
@@ -40,10 +79,131 @@ func CreateCode(c *gin.Context) {
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body map[string]interface{} true "增加方法"
|
||||
// @Param data body system.AutoFuncInfo true "增加方法"
|
||||
// @Success 200 {object} response.Response{msg=string} "注入成功"
|
||||
// @Router /autoCode/addFunc [post]
|
||||
func AddFunc(c *gin.Context) {
|
||||
// TODO: 实现方法注入功能
|
||||
response.FailWithMessage("功能开发中", c)
|
||||
func (a *AutoCodeTemplateApi) AddFunc(c *gin.Context) {
|
||||
var info system.AutoFuncInfo
|
||||
if err := c.ShouldBindJSON(&info); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
var tempMap map[string]string
|
||||
var err error
|
||||
if info.IsPreview {
|
||||
info.Router = "填充router"
|
||||
info.FuncName = "填充funcName"
|
||||
info.Method = "填充method"
|
||||
info.Description = "填充description"
|
||||
tempMap, err = autoCodeTemplateUsecase.GetApiAndServer(&info)
|
||||
} else {
|
||||
err = autoCodeTemplateUsecase.AddFunc(&info)
|
||||
}
|
||||
if err != nil {
|
||||
response.FailWithMessage("注入失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
if info.IsPreview {
|
||||
response.OkWithDetailed(tempMap, "注入成功", c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("注入成功", c)
|
||||
}
|
||||
|
||||
// pretreatment 预处理AutoCodeInfo
|
||||
func pretreatment(r *system.AutoCodeInfo) error {
|
||||
// 处理Go关键字
|
||||
if token.IsKeyword(r.Abbreviation) {
|
||||
r.Abbreviation = r.Abbreviation + "_"
|
||||
}
|
||||
// 处理test后缀
|
||||
if strings.HasSuffix(r.HumpPackageName, "test") {
|
||||
r.HumpPackageName = r.HumpPackageName + "_"
|
||||
}
|
||||
|
||||
length := len(r.Fields)
|
||||
dict := make(map[string]string, length)
|
||||
r.DataSourceMap = make(map[string]*system.DataSource, length)
|
||||
|
||||
for i := 0; i < length; i++ {
|
||||
if r.Fields[i].Excel {
|
||||
r.HasExcel = true
|
||||
}
|
||||
if r.Fields[i].DictType != "" {
|
||||
dict[r.Fields[i].DictType] = ""
|
||||
}
|
||||
if r.Fields[i].Sort {
|
||||
r.NeedSort = true
|
||||
}
|
||||
switch r.Fields[i].FieldType {
|
||||
case "file":
|
||||
r.HasFile = true
|
||||
r.NeedJSON = true
|
||||
case "json":
|
||||
r.NeedJSON = true
|
||||
case "array":
|
||||
r.NeedJSON = true
|
||||
r.HasArray = true
|
||||
case "video":
|
||||
r.HasPic = true
|
||||
case "richtext":
|
||||
r.HasRichText = true
|
||||
case "picture":
|
||||
r.HasPic = true
|
||||
case "pictures":
|
||||
r.HasPic = true
|
||||
r.NeedJSON = true
|
||||
case "time.Time":
|
||||
r.HasTimer = true
|
||||
if r.Fields[i].FieldSearchType != "" && r.Fields[i].FieldSearchType != "BETWEEN" && r.Fields[i].FieldSearchType != "NOT BETWEEN" {
|
||||
r.HasSearchTimer = true
|
||||
}
|
||||
}
|
||||
if r.Fields[i].DataSource != nil {
|
||||
if r.Fields[i].DataSource.Table != "" && r.Fields[i].DataSource.Label != "" && r.Fields[i].DataSource.Value != "" {
|
||||
r.HasDataSource = true
|
||||
r.Fields[i].CheckDataSource = true
|
||||
r.DataSourceMap[r.Fields[i].FieldJson] = r.Fields[i].DataSource
|
||||
}
|
||||
}
|
||||
if !r.GvaModel && r.PrimaryField == nil && r.Fields[i].PrimaryKey {
|
||||
r.PrimaryField = r.Fields[i]
|
||||
}
|
||||
}
|
||||
|
||||
// 收集字典类型
|
||||
for key := range dict {
|
||||
r.DictTypes = append(r.DictTypes, key)
|
||||
}
|
||||
|
||||
// 处理默认Model(GvaModel字段名保留以兼容前端API)
|
||||
if r.GvaModel {
|
||||
r.PrimaryField = &system.AutoCodeField{
|
||||
FieldName: "ID",
|
||||
FieldType: "uint",
|
||||
FieldDesc: "ID",
|
||||
FieldJson: "ID",
|
||||
DataTypeLong: "20",
|
||||
Comment: "主键ID",
|
||||
ColumnName: "id",
|
||||
}
|
||||
}
|
||||
|
||||
// 新增字段模式下不关注主键
|
||||
if r.IsAdd && r.PrimaryField == nil {
|
||||
r.PrimaryField = new(system.AutoCodeField)
|
||||
}
|
||||
|
||||
// Package首字母大写
|
||||
if r.Package != "" {
|
||||
packages := []rune(r.Package)
|
||||
if len(packages) > 0 {
|
||||
if packages[0] >= 97 && packages[0] <= 122 {
|
||||
packages[0] = packages[0] - 32
|
||||
}
|
||||
r.PackageT = string(packages)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"kra/internal/biz/system"
|
||||
"kra/pkg/jwt"
|
||||
"kra/pkg/response"
|
||||
"kra/pkg/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
type BaseApi struct{}
|
||||
@@ -28,12 +34,108 @@ type LoginResponse struct {
|
||||
// JWT实例(需要在初始化时设置)
|
||||
var jwtInstance *jwt.JWT
|
||||
|
||||
// 验证码存储
|
||||
var captchaStore base64Captcha.Store = base64Captcha.DefaultMemStore
|
||||
|
||||
// 验证码配置
|
||||
var (
|
||||
openCaptcha int = 0 // 防爆次数,0表示关闭
|
||||
openCaptchaTimeOut int = 300 // 缓存超时时间(秒)
|
||||
useMultipoint bool // 是否开启多点登录
|
||||
)
|
||||
|
||||
// 黑名单缓存
|
||||
var blackCache = NewLoginBlackCache()
|
||||
|
||||
// LoginBlackCache 登录黑名单缓存
|
||||
type LoginBlackCache struct {
|
||||
mu sync.RWMutex
|
||||
items map[string]*loginCacheItem
|
||||
}
|
||||
|
||||
type loginCacheItem struct {
|
||||
value int
|
||||
expiration time.Time
|
||||
}
|
||||
|
||||
// NewLoginBlackCache 创建登录黑名单缓存
|
||||
func NewLoginBlackCache() *LoginBlackCache {
|
||||
bc := &LoginBlackCache{
|
||||
items: make(map[string]*loginCacheItem),
|
||||
}
|
||||
go bc.cleanup()
|
||||
return bc
|
||||
}
|
||||
|
||||
func (c *LoginBlackCache) Set(key string, value int, duration time.Duration) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.items[key] = &loginCacheItem{
|
||||
value: value,
|
||||
expiration: time.Now().Add(duration),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *LoginBlackCache) Get(key string) (int, bool) {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
item, ok := c.items[key]
|
||||
if !ok || time.Now().After(item.expiration) {
|
||||
return 0, false
|
||||
}
|
||||
return item.value, true
|
||||
}
|
||||
|
||||
func (c *LoginBlackCache) Increment(key string, delta int) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if item, ok := c.items[key]; ok {
|
||||
item.value += delta
|
||||
}
|
||||
}
|
||||
|
||||
func (c *LoginBlackCache) cleanup() {
|
||||
ticker := time.NewTicker(time.Minute)
|
||||
for range ticker.C {
|
||||
c.mu.Lock()
|
||||
now := time.Now()
|
||||
for k, v := range c.items {
|
||||
if now.After(v.expiration) {
|
||||
delete(c.items, k)
|
||||
}
|
||||
}
|
||||
c.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
// SetJWTInstance 设置JWT实例
|
||||
func SetJWTInstance(j *jwt.JWT) {
|
||||
jwtInstance = j
|
||||
}
|
||||
|
||||
// Login 用户登录
|
||||
// SetCaptchaStore 设置验证码存储
|
||||
func SetCaptchaStore(store base64Captcha.Store) {
|
||||
captchaStore = store
|
||||
}
|
||||
|
||||
// SetCaptchaConfig 设置验证码配置
|
||||
func SetCaptchaConfig(open, timeout int) {
|
||||
openCaptcha = open
|
||||
openCaptchaTimeOut = timeout
|
||||
}
|
||||
|
||||
// SetUseMultipoint 设置是否开启多点登录
|
||||
func SetUseMultipoint(use bool) {
|
||||
useMultipoint = use
|
||||
}
|
||||
|
||||
// Login
|
||||
// @Tags Base
|
||||
// @Summary 用户登录
|
||||
// @Produce application/json
|
||||
// @Param data body LoginRequest true "用户名, 密码, 验证码"
|
||||
// @Success 200 {object} response.Response{data=LoginResponse,msg=string} "返回包括用户信息,token,过期时间"
|
||||
// @Router /base/login [post]
|
||||
func (b *BaseApi) Login(c *gin.Context) {
|
||||
var req LoginRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -41,17 +143,49 @@ func (b *BaseApi) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
key := c.ClientIP()
|
||||
|
||||
// 判断验证码是否开启
|
||||
v, ok := blackCache.Get(key)
|
||||
if !ok {
|
||||
blackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut))
|
||||
}
|
||||
|
||||
// 检查是否需要验证码
|
||||
var needCaptcha bool = openCaptcha == 0 || openCaptcha < v
|
||||
if needCaptcha && (req.Captcha == "" || req.CaptchaId == "" || !captchaStore.Verify(req.CaptchaId, req.Captcha, true)) {
|
||||
// 验证码次数+1
|
||||
blackCache.Increment(key, 1)
|
||||
response.FailWithMessage("验证码错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := userUsecase.Login(c, req.Username, req.Password)
|
||||
if err != nil {
|
||||
// 验证码次数+1
|
||||
blackCache.Increment(key, 1)
|
||||
response.FailWithMessage("用户名不存在或者密码错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
if user.Enable != 1 {
|
||||
// 验证码次数+1
|
||||
blackCache.Increment(key, 1)
|
||||
response.FailWithMessage("用户被禁止登录", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 检查用户角色默认路由
|
||||
if user.Authority != nil {
|
||||
defaultRouter := menuUsecase.UserAuthorityDefaultRouter(c, user.AuthorityId, user.Authority.DefaultRouter)
|
||||
user.Authority.DefaultRouter = defaultRouter
|
||||
}
|
||||
|
||||
b.TokenNext(c, user)
|
||||
}
|
||||
|
||||
// TokenNext 登录以后签发jwt
|
||||
func (b *BaseApi) TokenNext(c *gin.Context, user *system.User) {
|
||||
// 生成token
|
||||
claims := jwtInstance.CreateClaims(jwt.BaseClaims{
|
||||
UUID: user.UUID.String(),
|
||||
@@ -67,11 +201,103 @@ func (b *BaseApi) Login(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
utils.SetToken(c, token, int(jwtInstance.ExpiresAt.Seconds()))
|
||||
if !useMultipoint {
|
||||
utils.SetToken(c, token, int(claims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
response.OkWithDetailed(LoginResponse{
|
||||
User: toUserResponse(user),
|
||||
Token: token,
|
||||
ExpiresAt: claims.ExpiresAt.UnixMilli(),
|
||||
}, "登录成功", c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithDetailed(LoginResponse{
|
||||
User: toUserResponse(user),
|
||||
Token: token,
|
||||
ExpiresAt: claims.ExpiresAt.UnixMilli(),
|
||||
}, "登录成功", c)
|
||||
// 多点登录处理
|
||||
if jwtStr, err := jwtBlacklistUsecase.GetRedisJWT(c, user.Username); err == redis.Nil {
|
||||
// 没有旧token,直接设置新token
|
||||
if err := utils.SetRedisJWT(token, user.Username); err != nil {
|
||||
response.FailWithMessage("设置登录状态失败", c)
|
||||
return
|
||||
}
|
||||
utils.SetToken(c, token, int(claims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
response.OkWithDetailed(LoginResponse{
|
||||
User: toUserResponse(user),
|
||||
Token: token,
|
||||
ExpiresAt: claims.ExpiresAt.UnixMilli(),
|
||||
}, "登录成功", c)
|
||||
} else if err != nil {
|
||||
response.FailWithMessage("设置登录状态失败", c)
|
||||
} else {
|
||||
// 有旧token,将旧token加入黑名单
|
||||
if err := jwtBlacklistUsecase.JsonInBlacklist(c, jwtStr); err != nil {
|
||||
response.FailWithMessage("jwt作废失败", c)
|
||||
return
|
||||
}
|
||||
if err := utils.SetRedisJWT(token, user.Username); err != nil {
|
||||
response.FailWithMessage("设置登录状态失败", c)
|
||||
return
|
||||
}
|
||||
utils.SetToken(c, token, int(claims.ExpiresAt.Unix()-time.Now().Unix()))
|
||||
response.OkWithDetailed(LoginResponse{
|
||||
User: toUserResponse(user),
|
||||
Token: token,
|
||||
ExpiresAt: claims.ExpiresAt.UnixMilli(),
|
||||
}, "登录成功", c)
|
||||
}
|
||||
}
|
||||
|
||||
// CaptchaResponse 验证码响应
|
||||
type CaptchaResponse struct {
|
||||
CaptchaId string `json:"captchaId"`
|
||||
PicPath string `json:"picPath"`
|
||||
CaptchaLength int `json:"captchaLength"`
|
||||
OpenCaptcha bool `json:"openCaptcha"`
|
||||
}
|
||||
|
||||
// 验证码图片配置
|
||||
var (
|
||||
captchaImgHeight int = 80
|
||||
captchaImgWidth int = 240
|
||||
captchaKeyLong int = 6
|
||||
)
|
||||
|
||||
// SetCaptchaImgConfig 设置验证码图片配置
|
||||
func SetCaptchaImgConfig(height, width, keyLong int) {
|
||||
captchaImgHeight = height
|
||||
captchaImgWidth = width
|
||||
captchaKeyLong = keyLong
|
||||
}
|
||||
|
||||
// Captcha
|
||||
// @Tags Base
|
||||
// @Summary 生成验证码
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=CaptchaResponse,msg=string} "生成验证码,返回包括随机数id,base64,验证码长度,是否开启验证码"
|
||||
// @Router /base/captcha [post]
|
||||
func (b *BaseApi) Captcha(c *gin.Context) {
|
||||
key := c.ClientIP()
|
||||
v, ok := blackCache.Get(key)
|
||||
if !ok {
|
||||
blackCache.Set(key, 1, time.Second*time.Duration(openCaptchaTimeOut))
|
||||
}
|
||||
|
||||
var oc bool
|
||||
if openCaptcha == 0 || openCaptcha < v {
|
||||
oc = true
|
||||
}
|
||||
|
||||
// 生成数字验证码
|
||||
driver := base64Captcha.NewDriverDigit(captchaImgHeight, captchaImgWidth, captchaKeyLong, 0.7, 80)
|
||||
cp := base64Captcha.NewCaptcha(driver, captchaStore)
|
||||
id, b64s, _, err := cp.Generate()
|
||||
if err != nil {
|
||||
response.FailWithMessage("验证码获取失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithDetailed(CaptchaResponse{
|
||||
CaptchaId: id,
|
||||
PicPath: b64s,
|
||||
CaptchaLength: captchaKeyLong,
|
||||
OpenCaptcha: oc,
|
||||
}, "验证码获取成功", c)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package system
|
||||
|
||||
import (
|
||||
"kra/pkg/response"
|
||||
"kra/pkg/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -25,7 +26,15 @@ type GetPolicyPathByAuthorityIdRequest struct {
|
||||
AuthorityId uint `json:"authorityId" binding:"required"`
|
||||
}
|
||||
|
||||
// UpdateCasbin 更新Casbin权限
|
||||
// UpdateCasbin
|
||||
// @Tags Casbin
|
||||
// @Summary 更新角色api权限
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body UpdateCasbinRequest true "权限id, 权限模型列表"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新角色api权限"
|
||||
// @Router /casbin/updateCasbin [post]
|
||||
func (ca *CasbinApi) UpdateCasbin(c *gin.Context) {
|
||||
var req UpdateCasbinRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -33,6 +42,9 @@ func (ca *CasbinApi) UpdateCasbin(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取当前用户的角色ID
|
||||
adminAuthorityID := utils.GetUserAuthorityId(c)
|
||||
|
||||
// 转换为业务层格式
|
||||
rules := make([]struct {
|
||||
Path string
|
||||
@@ -48,7 +60,7 @@ func (ca *CasbinApi) UpdateCasbin(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := casbinUsecase.UpdateCasbin(0, req.AuthorityId, rules); err != nil {
|
||||
if err := casbinUsecase.UpdateCasbin(adminAuthorityID, req.AuthorityId, rules); err != nil {
|
||||
response.FailWithMessage("更新失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
@@ -56,7 +68,15 @@ func (ca *CasbinApi) UpdateCasbin(c *gin.Context) {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// GetPolicyPathByAuthorityId 获取权限路径
|
||||
// GetPolicyPathByAuthorityId
|
||||
// @Tags Casbin
|
||||
// @Summary 获取权限列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body GetPolicyPathByAuthorityIdRequest true "权限id, 权限模型列表"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取权限列表,返回包括casbin详情列表"
|
||||
// @Router /casbin/getPolicyPathByAuthorityId [post]
|
||||
func (ca *CasbinApi) GetPolicyPathByAuthorityId(c *gin.Context) {
|
||||
var req GetPolicyPathByAuthorityIdRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
|
||||
@@ -35,7 +35,15 @@ type GetDictionaryListRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// CreateSysDictionary 创建字典
|
||||
// CreateSysDictionary
|
||||
// @Tags SysDictionary
|
||||
// @Summary 创建SysDictionary
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body CreateDictionaryRequest true "SysDictionary模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建SysDictionary"
|
||||
// @Router /sysDictionary/createSysDictionary [post]
|
||||
func (d *DictionaryApi) CreateSysDictionary(c *gin.Context) {
|
||||
var req CreateDictionaryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -58,7 +66,15 @@ func (d *DictionaryApi) CreateSysDictionary(c *gin.Context) {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteSysDictionary 删除字典
|
||||
// DeleteSysDictionary
|
||||
// @Tags SysDictionary
|
||||
// @Summary 删除SysDictionary
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "字典ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除SysDictionary"
|
||||
// @Router /sysDictionary/deleteSysDictionary [delete]
|
||||
func (d *DictionaryApi) DeleteSysDictionary(c *gin.Context) {
|
||||
idStr := c.Query("ID")
|
||||
if idStr == "" {
|
||||
@@ -80,7 +96,15 @@ func (d *DictionaryApi) DeleteSysDictionary(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateSysDictionary 更新字典
|
||||
// UpdateSysDictionary
|
||||
// @Tags SysDictionary
|
||||
// @Summary 更新SysDictionary
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body UpdateDictionaryRequest true "SysDictionary模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新SysDictionary"
|
||||
// @Router /sysDictionary/updateSysDictionary [put]
|
||||
func (d *DictionaryApi) UpdateSysDictionary(c *gin.Context) {
|
||||
var req UpdateDictionaryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -104,7 +128,16 @@ func (d *DictionaryApi) UpdateSysDictionary(c *gin.Context) {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindSysDictionary 根据ID或type获取字典
|
||||
// FindSysDictionary
|
||||
// @Tags SysDictionary
|
||||
// @Summary 用id查询SysDictionary
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string false "字典ID"
|
||||
// @Param type query string false "字典英名"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询SysDictionary"
|
||||
// @Router /sysDictionary/findSysDictionary [get]
|
||||
func (d *DictionaryApi) FindSysDictionary(c *gin.Context) {
|
||||
idStr := c.Query("ID")
|
||||
dictType := c.Query("type")
|
||||
@@ -128,7 +161,15 @@ func (d *DictionaryApi) FindSysDictionary(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"resysDictionary": dict}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetSysDictionaryList 获取字典列表
|
||||
// GetSysDictionaryList
|
||||
// @Tags SysDictionary
|
||||
// @Summary 分页获取SysDictionary列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param name query string false "字典名称"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysDictionary列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /sysDictionary/getSysDictionaryList [get]
|
||||
func (d *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
|
||||
name := c.Query("name")
|
||||
|
||||
@@ -140,3 +181,63 @@ func (d *DictionaryApi) GetSysDictionaryList(c *gin.Context) {
|
||||
|
||||
response.OkWithDetailed(gin.H{"list": list}, "获取成功", c)
|
||||
}
|
||||
|
||||
// ExportSysDictionary
|
||||
// @Tags SysDictionary
|
||||
// @Summary 导出字典JSON(包含字典详情)
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "字典ID"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "导出字典JSON"
|
||||
// @Router /sysDictionary/exportSysDictionary [get]
|
||||
func (d *DictionaryApi) ExportSysDictionary(c *gin.Context) {
|
||||
idStr := c.Query("ID")
|
||||
if idStr == "" {
|
||||
response.FailWithMessage("字典ID不能为空", c)
|
||||
return
|
||||
}
|
||||
|
||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
||||
if err != nil {
|
||||
response.FailWithMessage("参数错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
exportData, err := dictionaryUsecase.ExportDictionary(c, uint(id))
|
||||
if err != nil {
|
||||
response.FailWithMessage("导出失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithDetailed(exportData, "导出成功", c)
|
||||
}
|
||||
|
||||
// ImportSysDictionaryRequest 导入字典请求
|
||||
type ImportSysDictionaryRequest struct {
|
||||
Json string `json:"json" binding:"required"`
|
||||
}
|
||||
|
||||
// ImportSysDictionary
|
||||
// @Tags SysDictionary
|
||||
// @Summary 导入字典JSON(包含字典详情)
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body ImportSysDictionaryRequest true "字典JSON数据"
|
||||
// @Success 200 {object} response.Response{msg=string} "导入字典"
|
||||
// @Router /sysDictionary/importSysDictionary [post]
|
||||
func (d *DictionaryApi) ImportSysDictionary(c *gin.Context) {
|
||||
var req ImportSysDictionaryRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := dictionaryUsecase.ImportDictionary(c, req.Json); err != nil {
|
||||
response.FailWithMessage("导入失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMessage("导入成功", c)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,15 @@ type GetDictionaryDetailsByParentRequest struct {
|
||||
IncludeChildren bool `json:"includeChildren" form:"includeChildren"`
|
||||
}
|
||||
|
||||
// CreateSysDictionaryDetail 创建字典详情
|
||||
// CreateSysDictionaryDetail
|
||||
// @Tags SysDictionaryDetail
|
||||
// @Summary 创建SysDictionaryDetail
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DictionaryDetailRequest true "SysDictionaryDetail模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建SysDictionaryDetail"
|
||||
// @Router /sysDictionaryDetail/createSysDictionaryDetail [post]
|
||||
func (d *DictionaryDetailApi) CreateSysDictionaryDetail(c *gin.Context) {
|
||||
var req DictionaryDetailRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -67,7 +75,15 @@ func (d *DictionaryDetailApi) CreateSysDictionaryDetail(c *gin.Context) {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteSysDictionaryDetail 删除字典详情
|
||||
// DeleteSysDictionaryDetail
|
||||
// @Tags SysDictionaryDetail
|
||||
// @Summary 删除SysDictionaryDetail
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DictionaryDetailRequest true "SysDictionaryDetail模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除SysDictionaryDetail"
|
||||
// @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete]
|
||||
func (d *DictionaryDetailApi) DeleteSysDictionaryDetail(c *gin.Context) {
|
||||
var req DictionaryDetailRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -82,7 +98,15 @@ func (d *DictionaryDetailApi) DeleteSysDictionaryDetail(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateSysDictionaryDetail 更新字典详情
|
||||
// UpdateSysDictionaryDetail
|
||||
// @Tags SysDictionaryDetail
|
||||
// @Summary 更新SysDictionaryDetail
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DictionaryDetailRequest true "更新SysDictionaryDetail"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新SysDictionaryDetail"
|
||||
// @Router /sysDictionaryDetail/updateSysDictionaryDetail [put]
|
||||
func (d *DictionaryDetailApi) UpdateSysDictionaryDetail(c *gin.Context) {
|
||||
var req DictionaryDetailRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -108,7 +132,15 @@ func (d *DictionaryDetailApi) UpdateSysDictionaryDetail(c *gin.Context) {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindSysDictionaryDetail 根据ID获取字典详情
|
||||
// FindSysDictionaryDetail
|
||||
// @Tags SysDictionaryDetail
|
||||
// @Summary 用id查询SysDictionaryDetail
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "用id查询SysDictionaryDetail"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询SysDictionaryDetail"
|
||||
// @Router /sysDictionaryDetail/findSysDictionaryDetail [get]
|
||||
func (d *DictionaryDetailApi) FindSysDictionaryDetail(c *gin.Context) {
|
||||
idStr := c.Query("ID")
|
||||
if idStr == "" {
|
||||
@@ -125,7 +157,15 @@ func (d *DictionaryDetailApi) FindSysDictionaryDetail(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"reSysDictionaryDetail": toDictionaryDetailResponse(detail)}, "查询成功", c)
|
||||
}
|
||||
|
||||
// GetSysDictionaryDetailList 分页获取字典详情列表
|
||||
// GetSysDictionaryDetailList
|
||||
// @Tags SysDictionaryDetail
|
||||
// @Summary 分页获取SysDictionaryDetail列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query DictionaryDetailSearchRequest true "页码, 每页大小, 搜索条件"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysDictionaryDetail列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /sysDictionaryDetail/getSysDictionaryDetailList [get]
|
||||
func (d *DictionaryDetailApi) GetSysDictionaryDetailList(c *gin.Context) {
|
||||
var req DictionaryDetailSearchRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
@@ -179,7 +219,15 @@ func (d *DictionaryDetailApi) GetSysDictionaryDetailList(c *gin.Context) {
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetDictionaryTreeList 获取字典详情树形结构
|
||||
// GetDictionaryTreeList
|
||||
// @Tags SysDictionaryDetail
|
||||
// @Summary 获取字典详情树形结构
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param sysDictionaryID query int true "字典ID"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取字典详情树形结构"
|
||||
// @Router /sysDictionaryDetail/getDictionaryTreeList [get]
|
||||
func (d *DictionaryDetailApi) GetDictionaryTreeList(c *gin.Context) {
|
||||
sysDictionaryID := c.Query("sysDictionaryID")
|
||||
if sysDictionaryID == "" {
|
||||
@@ -201,7 +249,15 @@ func (d *DictionaryDetailApi) GetDictionaryTreeList(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"list": toDictionaryDetailTreeResponse(list)}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetDictionaryTreeListByType 根据字典类型获取字典详情树形结构
|
||||
// GetDictionaryTreeListByType
|
||||
// @Tags SysDictionaryDetail
|
||||
// @Summary 根据字典类型获取字典详情树形结构
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param type query string true "字典类型"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取字典详情树形结构"
|
||||
// @Router /sysDictionaryDetail/getDictionaryTreeListByType [get]
|
||||
func (d *DictionaryDetailApi) GetDictionaryTreeListByType(c *gin.Context) {
|
||||
dictType := c.Query("type")
|
||||
if dictType == "" {
|
||||
@@ -217,7 +273,15 @@ func (d *DictionaryDetailApi) GetDictionaryTreeListByType(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"list": toDictionaryDetailTreeResponse(list)}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetDictionaryDetailsByParent 根据父级ID获取字典详情
|
||||
// GetDictionaryDetailsByParent
|
||||
// @Tags SysDictionaryDetail
|
||||
// @Summary 根据父级ID获取字典详情
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query GetDictionaryDetailsByParentRequest true "查询参数"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取字典详情列表"
|
||||
// @Router /sysDictionaryDetail/getDictionaryDetailsByParent [get]
|
||||
func (d *DictionaryDetailApi) GetDictionaryDetailsByParent(c *gin.Context) {
|
||||
var req GetDictionaryDetailsByParentRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
@@ -233,7 +297,15 @@ func (d *DictionaryDetailApi) GetDictionaryDetailsByParent(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"list": toDictionaryDetailTreeResponse(list)}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetDictionaryPath 获取字典详情的完整路径
|
||||
// GetDictionaryPath
|
||||
// @Tags SysDictionaryDetail
|
||||
// @Summary 获取字典详情的完整路径
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param id query uint true "字典详情ID"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取字典详情路径"
|
||||
// @Router /sysDictionaryDetail/getDictionaryPath [get]
|
||||
func (d *DictionaryDetailApi) GetDictionaryPath(c *gin.Context) {
|
||||
idStr := c.Query("id")
|
||||
if idStr == "" {
|
||||
|
||||
@@ -30,7 +30,15 @@ type SysErrorSearchRequest struct {
|
||||
CreatedAtRange []time.Time `json:"createdAtRange" form:"createdAtRange[]"`
|
||||
}
|
||||
|
||||
// CreateSysError 创建错误日志
|
||||
// CreateSysError
|
||||
// @Tags SysError
|
||||
// @Summary 创建错误日志
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body SysErrorRequest true "错误日志模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建错误日志"
|
||||
// @Router /sysError/createSysError [post]
|
||||
func (e *ErrorApi) CreateSysError(c *gin.Context) {
|
||||
var req SysErrorRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -52,7 +60,15 @@ func (e *ErrorApi) CreateSysError(c *gin.Context) {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteSysError 删除错误日志
|
||||
// DeleteSysError
|
||||
// @Tags SysError
|
||||
// @Summary 删除错误日志
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "错误日志ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除错误日志"
|
||||
// @Router /sysError/deleteSysError [delete]
|
||||
func (e *ErrorApi) DeleteSysError(c *gin.Context) {
|
||||
id := c.Query("ID")
|
||||
if id == "" {
|
||||
@@ -67,7 +83,15 @@ func (e *ErrorApi) DeleteSysError(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteSysErrorByIds 批量删除错误日志
|
||||
// DeleteSysErrorByIds
|
||||
// @Tags SysError
|
||||
// @Summary 批量删除错误日志
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param IDs[] query []string true "错误日志ID列表"
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除错误日志"
|
||||
// @Router /sysError/deleteSysErrorByIds [delete]
|
||||
func (e *ErrorApi) DeleteSysErrorByIds(c *gin.Context) {
|
||||
ids := c.QueryArray("IDs[]")
|
||||
if len(ids) == 0 {
|
||||
@@ -82,7 +106,15 @@ func (e *ErrorApi) DeleteSysErrorByIds(c *gin.Context) {
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateSysError 更新错误日志
|
||||
// UpdateSysError
|
||||
// @Tags SysError
|
||||
// @Summary 更新错误日志
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body SysErrorRequest true "错误日志模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新错误日志"
|
||||
// @Router /sysError/updateSysError [put]
|
||||
func (e *ErrorApi) UpdateSysError(c *gin.Context) {
|
||||
var req SysErrorRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -106,7 +138,15 @@ func (e *ErrorApi) UpdateSysError(c *gin.Context) {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindSysError 根据ID获取错误日志
|
||||
// FindSysError
|
||||
// @Tags SysError
|
||||
// @Summary 根据ID获取错误日志
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "错误日志ID"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取错误日志"
|
||||
// @Router /sysError/findSysError [get]
|
||||
func (e *ErrorApi) FindSysError(c *gin.Context) {
|
||||
id := c.Query("ID")
|
||||
if id == "" {
|
||||
@@ -122,7 +162,15 @@ func (e *ErrorApi) FindSysError(c *gin.Context) {
|
||||
response.OkWithData(toErrorResponse(sysError), c)
|
||||
}
|
||||
|
||||
// GetSysErrorList 分页获取错误日志列表
|
||||
// GetSysErrorList
|
||||
// @Tags SysError
|
||||
// @Summary 分页获取错误日志列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query SysErrorSearchRequest true "页码, 每页大小, 搜索条件"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取错误日志列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /sysError/getSysErrorList [get]
|
||||
func (e *ErrorApi) GetSysErrorList(c *gin.Context) {
|
||||
var req SysErrorSearchRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
@@ -164,7 +212,15 @@ func (e *ErrorApi) GetSysErrorList(c *gin.Context) {
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetSysErrorSolution 触发AI处理错误日志
|
||||
// GetSysErrorSolution
|
||||
// @Tags SysError
|
||||
// @Summary 触发AI处理错误日志
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param id query string true "错误日志ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "已提交至AI处理"
|
||||
// @Router /sysError/getSysErrorSolution [get]
|
||||
func (e *ErrorApi) GetSysErrorSolution(c *gin.Context) {
|
||||
id := c.Query("id")
|
||||
if id == "" {
|
||||
|
||||
@@ -105,7 +105,15 @@ type GetSysExportTemplateListRequest struct {
|
||||
EndCreatedAt *time.Time `form:"endCreatedAt"`
|
||||
}
|
||||
|
||||
// CreateSysExportTemplate 创建导出模板
|
||||
// CreateSysExportTemplate
|
||||
// @Tags SysExportTemplate
|
||||
// @Summary 创建导出模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body CreateSysExportTemplateRequest true "创建导出模板"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
||||
// @Router /sysExportTemplate/createSysExportTemplate [post]
|
||||
func (e *ExportTemplateApi) CreateSysExportTemplate(c *gin.Context) {
|
||||
var req CreateSysExportTemplateRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -156,7 +164,15 @@ func (e *ExportTemplateApi) CreateSysExportTemplate(c *gin.Context) {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteSysExportTemplate 删除导出模板
|
||||
// DeleteSysExportTemplate
|
||||
// @Tags SysExportTemplate
|
||||
// @Summary 删除导出模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DeleteSysExportTemplateRequest true "删除导出模板"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
||||
// @Router /sysExportTemplate/deleteSysExportTemplate [delete]
|
||||
func (e *ExportTemplateApi) DeleteSysExportTemplate(c *gin.Context) {
|
||||
var req DeleteSysExportTemplateRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -171,7 +187,15 @@ func (e *ExportTemplateApi) DeleteSysExportTemplate(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteSysExportTemplateByIds 批量删除导出模板
|
||||
// DeleteSysExportTemplateByIds
|
||||
// @Tags SysExportTemplate
|
||||
// @Summary 批量删除导出模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DeleteSysExportTemplateByIdsRequest true "批量删除导出模板"
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
||||
// @Router /sysExportTemplate/deleteSysExportTemplateByIds [delete]
|
||||
func (e *ExportTemplateApi) DeleteSysExportTemplateByIds(c *gin.Context) {
|
||||
var req DeleteSysExportTemplateByIdsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -186,7 +210,15 @@ func (e *ExportTemplateApi) DeleteSysExportTemplateByIds(c *gin.Context) {
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateSysExportTemplate 更新导出模板
|
||||
// UpdateSysExportTemplate
|
||||
// @Tags SysExportTemplate
|
||||
// @Summary 更新导出模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body UpdateSysExportTemplateRequest true "更新导出模板"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
||||
// @Router /sysExportTemplate/updateSysExportTemplate [put]
|
||||
func (e *ExportTemplateApi) UpdateSysExportTemplate(c *gin.Context) {
|
||||
var req UpdateSysExportTemplateRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -238,7 +270,15 @@ func (e *ExportTemplateApi) UpdateSysExportTemplate(c *gin.Context) {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// FindSysExportTemplate 根据ID获取导出模板
|
||||
// FindSysExportTemplate
|
||||
// @Tags SysExportTemplate
|
||||
// @Summary 用id查询导出模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query uint true "用id查询导出模板"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "查询成功"
|
||||
// @Router /sysExportTemplate/findSysExportTemplate [get]
|
||||
func (e *ExportTemplateApi) FindSysExportTemplate(c *gin.Context) {
|
||||
var req struct {
|
||||
ID uint `form:"ID" binding:"required"`
|
||||
@@ -256,7 +296,15 @@ func (e *ExportTemplateApi) FindSysExportTemplate(c *gin.Context) {
|
||||
response.OkWithData(gin.H{"resysExportTemplate": toExportTemplateResponse(template)}, c)
|
||||
}
|
||||
|
||||
// GetSysExportTemplateList 分页获取导出模板列表
|
||||
// GetSysExportTemplateList
|
||||
// @Tags SysExportTemplate
|
||||
// @Summary 分页获取导出模板列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query GetSysExportTemplateListRequest true "分页获取导出模板列表"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
||||
// @Router /sysExportTemplate/getSysExportTemplateList [get]
|
||||
func (e *ExportTemplateApi) GetSysExportTemplateList(c *gin.Context) {
|
||||
var req GetSysExportTemplateListRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
@@ -293,7 +341,15 @@ func (e *ExportTemplateApi) GetSysExportTemplateList(c *gin.Context) {
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// ExportExcel 导出Excel(获取token)
|
||||
// ExportExcel
|
||||
// @Tags SysExportTemplate
|
||||
// @Summary 导出表格token
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param templateID query string true "模板ID"
|
||||
// @Success 200 {object} response.Response{data=string,msg=string} "获取导出链接"
|
||||
// @Router /sysExportTemplate/exportExcel [get]
|
||||
func (e *ExportTemplateApi) ExportExcel(c *gin.Context) {
|
||||
templateID := c.Query("templateID")
|
||||
if templateID == "" {
|
||||
@@ -323,7 +379,15 @@ func (e *ExportTemplateApi) ExportExcel(c *gin.Context) {
|
||||
response.OkWithData(exportUrl, c)
|
||||
}
|
||||
|
||||
// ExportExcelByToken 通过token导出Excel
|
||||
// ExportExcelByToken
|
||||
// @Tags ExportExcelByToken
|
||||
// @Summary 导出表格
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param token query string true "导出token"
|
||||
// @Success 200 {file} csv "导出CSV文件"
|
||||
// @Router /sysExportTemplate/exportExcelByToken [get]
|
||||
func (e *ExportTemplateApi) ExportExcelByToken(c *gin.Context) {
|
||||
token := c.Query("token")
|
||||
if token == "" {
|
||||
@@ -371,7 +435,16 @@ func (e *ExportTemplateApi) ExportExcelByToken(c *gin.Context) {
|
||||
c.Data(http.StatusOK, "text/csv", file.Bytes())
|
||||
}
|
||||
|
||||
// PreviewSQL 预览SQL
|
||||
// PreviewSQL
|
||||
// @Tags SysExportTemplate
|
||||
// @Summary 预览最终生成的SQL
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param templateID query string true "导出模板ID"
|
||||
// @Param params query string false "查询参数编码字符串"
|
||||
// @Success 200 {object} response.Response{data=map[string]string,msg=string} "获取成功"
|
||||
// @Router /sysExportTemplate/previewSQL [get]
|
||||
func (e *ExportTemplateApi) PreviewSQL(c *gin.Context) {
|
||||
templateID := c.Query("templateID")
|
||||
if templateID == "" {
|
||||
@@ -389,7 +462,15 @@ func (e *ExportTemplateApi) PreviewSQL(c *gin.Context) {
|
||||
response.OkWithData(gin.H{"sql": sqlPreview}, c)
|
||||
}
|
||||
|
||||
// ExportTemplate 导出Excel模板(获取token)
|
||||
// ExportTemplate
|
||||
// @Tags SysExportTemplate
|
||||
// @Summary 导出表格模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param templateID query string true "模板ID"
|
||||
// @Success 200 {object} response.Response{data=string,msg=string} "获取导出链接"
|
||||
// @Router /sysExportTemplate/exportTemplate [get]
|
||||
func (e *ExportTemplateApi) ExportTemplate(c *gin.Context) {
|
||||
templateID := c.Query("templateID")
|
||||
if templateID == "" {
|
||||
@@ -417,7 +498,15 @@ func (e *ExportTemplateApi) ExportTemplate(c *gin.Context) {
|
||||
response.OkWithData(exportUrl, c)
|
||||
}
|
||||
|
||||
// ExportTemplateByToken 通过token导出模板
|
||||
// ExportTemplateByToken
|
||||
// @Tags ExportTemplateByToken
|
||||
// @Summary 通过token导出表格模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param token query string true "导出token"
|
||||
// @Success 200 {file} csv "导出CSV模板文件"
|
||||
// @Router /sysExportTemplate/exportTemplateByToken [get]
|
||||
func (e *ExportTemplateApi) ExportTemplateByToken(c *gin.Context) {
|
||||
token := c.Query("token")
|
||||
if token == "" {
|
||||
@@ -471,7 +560,16 @@ func (e *ExportTemplateApi) ExportTemplateByToken(c *gin.Context) {
|
||||
c.Data(http.StatusOK, "text/csv", file.Bytes())
|
||||
}
|
||||
|
||||
// ImportExcel 导入Excel
|
||||
// ImportExcel
|
||||
// @Tags SysImportTemplate
|
||||
// @Summary 导入表格
|
||||
// @Security ApiKeyAuth
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param templateID query string true "模板ID"
|
||||
// @Param file formData file true "导入文件"
|
||||
// @Success 200 {object} response.Response{msg=string} "导入成功"
|
||||
// @Router /sysExportTemplate/importExcel [post]
|
||||
func (e *ExportTemplateApi) ImportExcel(c *gin.Context) {
|
||||
templateID := c.Query("templateID")
|
||||
if templateID == "" {
|
||||
|
||||
@@ -20,16 +20,27 @@ type InitDBRequest struct {
|
||||
DBPath string `json:"dbPath"`
|
||||
}
|
||||
|
||||
// InitDB 初始化数据库
|
||||
// InitDB
|
||||
// @Tags InitDB
|
||||
// @Summary 初始化用户数据库
|
||||
// @Produce application/json
|
||||
// @Param data body InitDBRequest true "初始化数据库参数"
|
||||
// @Success 200 {object} response.Response{msg=string} "初始化用户数据库"
|
||||
// @Router /init/initdb [post]
|
||||
// 注意:KRA 项目使用 Kratos 框架,数据库配置通过 config.yaml 管理
|
||||
// 此接口主要用于兼容 GVA 前端
|
||||
// 此接口主要用于兼容前端初始化流程
|
||||
func (d *DBApi) InitDB(c *gin.Context) {
|
||||
// KRA 项目数据库已通过配置文件初始化
|
||||
// 此接口返回成功以兼容前端
|
||||
response.OkWithMessage("数据库已初始化", c)
|
||||
}
|
||||
|
||||
// CheckDB 检测是否需要初始化数据库
|
||||
// CheckDB
|
||||
// @Tags CheckDB
|
||||
// @Summary 初始化用户数据库
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "初始化用户数据库"
|
||||
// @Router /init/checkdb [post]
|
||||
func (d *DBApi) CheckDB(c *gin.Context) {
|
||||
// KRA 项目数据库通过配置文件管理,无需初始化
|
||||
response.OkWithDetailed(gin.H{"needInit": false}, "数据库无需初始化", c)
|
||||
|
||||
@@ -9,7 +9,14 @@ import (
|
||||
|
||||
type JwtApi struct{}
|
||||
|
||||
// JsonInBlacklist JWT加入黑名单
|
||||
// JsonInBlacklist
|
||||
// @Tags Jwt
|
||||
// @Summary jwt加入黑名单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "jwt加入黑名单"
|
||||
// @Router /jwt/jsonInBlacklist [post]
|
||||
func (j *JwtApi) JsonInBlacklist(c *gin.Context) {
|
||||
token := utils.GetToken(c)
|
||||
if token == "" {
|
||||
|
||||
@@ -71,7 +71,15 @@ type GetMenuAuthorityRequest struct {
|
||||
AuthorityId uint `json:"authorityId" binding:"required"`
|
||||
}
|
||||
|
||||
// AddBaseMenu 添加菜单
|
||||
// AddBaseMenu
|
||||
// @Tags Menu
|
||||
// @Summary 新增菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body AddBaseMenuRequest true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
|
||||
// @Success 200 {object} response.Response{msg=string} "新增菜单"
|
||||
// @Router /menu/addBaseMenu [post]
|
||||
func (m *MenuApi) AddBaseMenu(c *gin.Context) {
|
||||
var req AddBaseMenuRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -96,7 +104,15 @@ func (m *MenuApi) AddBaseMenu(c *gin.Context) {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteBaseMenu 删除菜单
|
||||
// DeleteBaseMenu
|
||||
// @Tags Menu
|
||||
// @Summary 删除菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DeleteBaseMenuRequest true "菜单id"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除菜单"
|
||||
// @Router /menu/deleteBaseMenu [post]
|
||||
func (m *MenuApi) DeleteBaseMenu(c *gin.Context) {
|
||||
var req DeleteBaseMenuRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -112,7 +128,15 @@ func (m *MenuApi) DeleteBaseMenu(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateBaseMenu 更新菜单
|
||||
// UpdateBaseMenu
|
||||
// @Tags Menu
|
||||
// @Summary 更新菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body UpdateBaseMenuRequest true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新菜单"
|
||||
// @Router /menu/updateBaseMenu [post]
|
||||
func (m *MenuApi) UpdateBaseMenu(c *gin.Context) {
|
||||
var req UpdateBaseMenuRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -138,7 +162,13 @@ func (m *MenuApi) UpdateBaseMenu(c *gin.Context) {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// GetMenu 获取用户菜单
|
||||
// GetMenu
|
||||
// @Tags Menu
|
||||
// @Summary 获取用户动态路由
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取用户动态路由,返回包括系统菜单详情列表"
|
||||
// @Router /menu/getMenu [post]
|
||||
func (m *MenuApi) GetMenu(c *gin.Context) {
|
||||
authorityId := utils.GetUserAuthorityId(c)
|
||||
menus, err := menuUsecase.GetMenuTree(c, authorityId)
|
||||
@@ -150,7 +180,14 @@ func (m *MenuApi) GetMenu(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"menus": menus}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetMenuList 获取菜单列表
|
||||
// GetMenuList
|
||||
// @Tags Menu
|
||||
// @Summary 分页获取基础menu列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取基础menu列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /menu/getMenuList [post]
|
||||
func (m *MenuApi) GetMenuList(c *gin.Context) {
|
||||
authorityId := utils.GetUserAuthorityId(c)
|
||||
menus, err := menuUsecase.GetInfoList(c, authorityId)
|
||||
@@ -162,7 +199,13 @@ func (m *MenuApi) GetMenuList(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"list": menus}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetBaseMenuTree 获取菜单树
|
||||
// GetBaseMenuTree
|
||||
// @Tags Menu
|
||||
// @Summary 获取用户动态路由
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取用户动态路由,返回包括系统菜单列表"
|
||||
// @Router /menu/getBaseMenuTree [post]
|
||||
func (m *MenuApi) GetBaseMenuTree(c *gin.Context) {
|
||||
authorityId := utils.GetUserAuthorityId(c)
|
||||
menus, err := menuUsecase.GetBaseMenuTree(c, authorityId)
|
||||
@@ -174,7 +217,15 @@ func (m *MenuApi) GetBaseMenuTree(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"menus": menus}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetBaseMenuById 根据ID获取菜单
|
||||
// GetBaseMenuById
|
||||
// @Tags Menu
|
||||
// @Summary 根据id获取菜单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body GetMenuByIdRequest true "菜单id"
|
||||
// @Success 200 {object} response.Response{data=system.BaseMenu,msg=string} "根据id获取菜单,返回包括系统菜单详情"
|
||||
// @Router /menu/getBaseMenuById [post]
|
||||
func (m *MenuApi) GetBaseMenuById(c *gin.Context) {
|
||||
var req GetMenuByIdRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -191,7 +242,15 @@ func (m *MenuApi) GetBaseMenuById(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"menu": menu}, "获取成功", c)
|
||||
}
|
||||
|
||||
// AddMenuAuthority 添加菜单权限
|
||||
// AddMenuAuthority
|
||||
// @Tags Menu
|
||||
// @Summary 增加menu和角色关联关系
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body AddMenuAuthorityRequest true "角色ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "增加menu和角色关联关系"
|
||||
// @Router /menu/addMenuAuthority [post]
|
||||
func (m *MenuApi) AddMenuAuthority(c *gin.Context) {
|
||||
var req AddMenuAuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -216,7 +275,15 @@ func (m *MenuApi) AddMenuAuthority(c *gin.Context) {
|
||||
response.OkWithMessage("添加成功", c)
|
||||
}
|
||||
|
||||
// GetMenuAuthority 获取菜单权限
|
||||
// GetMenuAuthority
|
||||
// @Tags Menu
|
||||
// @Summary 获取指定角色menu
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body GetMenuAuthorityRequest true "角色ID"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取指定角色menu"
|
||||
// @Router /menu/getMenuAuthority [post]
|
||||
func (m *MenuApi) GetMenuAuthority(c *gin.Context) {
|
||||
var req GetMenuAuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
|
||||
@@ -27,7 +27,15 @@ type GetOperationRecordListRequest struct {
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
// DeleteSysOperationRecord 删除操作记录
|
||||
// DeleteSysOperationRecord
|
||||
// @Tags SysOperationRecord
|
||||
// @Summary 删除SysOperationRecord
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DeleteOperationRecordRequest true "SysOperationRecord模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除SysOperationRecord"
|
||||
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
|
||||
func (o *OperationRecordApi) DeleteSysOperationRecord(c *gin.Context) {
|
||||
var req DeleteOperationRecordRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -43,7 +51,15 @@ func (o *OperationRecordApi) DeleteSysOperationRecord(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteSysOperationRecordByIds 批量删除操作记录
|
||||
// DeleteSysOperationRecordByIds
|
||||
// @Tags SysOperationRecord
|
||||
// @Summary 批量删除SysOperationRecord
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DeleteOperationRecordByIdsRequest true "批量删除SysOperationRecord"
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除SysOperationRecord"
|
||||
// @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete]
|
||||
func (o *OperationRecordApi) DeleteSysOperationRecordByIds(c *gin.Context) {
|
||||
var req DeleteOperationRecordByIdsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -59,7 +75,15 @@ func (o *OperationRecordApi) DeleteSysOperationRecordByIds(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// FindSysOperationRecord 根据ID获取操作记录
|
||||
// FindSysOperationRecord
|
||||
// @Tags SysOperationRecord
|
||||
// @Summary 用id查询SysOperationRecord
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "Id"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用id查询SysOperationRecord"
|
||||
// @Router /sysOperationRecord/findSysOperationRecord [get]
|
||||
func (o *OperationRecordApi) FindSysOperationRecord(c *gin.Context) {
|
||||
idStr := c.Query("ID")
|
||||
if idStr == "" {
|
||||
@@ -84,7 +108,15 @@ func (o *OperationRecordApi) FindSysOperationRecord(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"reSysOperationRecord": record}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetSysOperationRecordList 获取操作记录列表
|
||||
// GetSysOperationRecordList
|
||||
// @Tags SysOperationRecord
|
||||
// @Summary 分页获取SysOperationRecord列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query GetOperationRecordListRequest true "页码, 每页大小, 搜索条件"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取SysOperationRecord列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /sysOperationRecord/getSysOperationRecordList [get]
|
||||
func (o *OperationRecordApi) GetSysOperationRecordList(c *gin.Context) {
|
||||
var req GetOperationRecordListRequest
|
||||
// GET请求从query获取参数
|
||||
|
||||
@@ -39,7 +39,15 @@ type GetParamsListRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// CreateSysParams 创建参数
|
||||
// CreateSysParams
|
||||
// @Tags SysParams
|
||||
// @Summary 创建参数
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body CreateParamsRequest true "参数模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建参数"
|
||||
// @Router /sysParams/createSysParams [post]
|
||||
func (p *ParamsApi) CreateSysParams(c *gin.Context) {
|
||||
var req CreateParamsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -62,15 +70,30 @@ func (p *ParamsApi) CreateSysParams(c *gin.Context) {
|
||||
response.OkWithMessage("创建成功", c)
|
||||
}
|
||||
|
||||
// DeleteSysParams 删除参数
|
||||
// DeleteSysParams
|
||||
// @Tags SysParams
|
||||
// @Summary 删除参数
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "参数ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除参数"
|
||||
// @Router /sysParams/deleteSysParams [delete]
|
||||
func (p *ParamsApi) DeleteSysParams(c *gin.Context) {
|
||||
var req DeleteParamsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
ID := c.Query("ID")
|
||||
if ID == "" {
|
||||
response.FailWithMessage("参数错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := paramsUsecase.Delete(c, req.ID); err != nil {
|
||||
var id uint
|
||||
for _, ch := range ID {
|
||||
if ch >= '0' && ch <= '9' {
|
||||
id = id*10 + uint(ch-'0')
|
||||
}
|
||||
}
|
||||
|
||||
if err := paramsUsecase.Delete(c, id); err != nil {
|
||||
response.FailWithMessage("删除失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
@@ -78,7 +101,53 @@ func (p *ParamsApi) DeleteSysParams(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateSysParams 更新参数
|
||||
// DeleteSysParamsByIds
|
||||
// @Tags SysParams
|
||||
// @Summary 批量删除参数
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param IDs[] query []string true "参数ID列表"
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除参数"
|
||||
// @Router /sysParams/deleteSysParamsByIds [delete]
|
||||
func (p *ParamsApi) DeleteSysParamsByIds(c *gin.Context) {
|
||||
IDStrs := c.QueryArray("IDs[]")
|
||||
if len(IDStrs) == 0 {
|
||||
response.FailWithMessage("参数错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 转换字符串ID为uint
|
||||
ids := make([]uint, 0, len(IDStrs))
|
||||
for _, idStr := range IDStrs {
|
||||
var id uint
|
||||
for _, ch := range idStr {
|
||||
if ch >= '0' && ch <= '9' {
|
||||
id = id*10 + uint(ch-'0')
|
||||
}
|
||||
}
|
||||
if id > 0 {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
|
||||
if err := paramsUsecase.DeleteByIds(c, ids); err != nil {
|
||||
response.FailWithMessage("批量删除失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// UpdateSysParams
|
||||
// @Tags SysParams
|
||||
// @Summary 更新参数
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body UpdateParamsRequest true "参数模型"
|
||||
// @Success 200 {object} response.Response{msg=string} "更新参数"
|
||||
// @Router /sysParams/updateSysParams [put]
|
||||
func (p *ParamsApi) UpdateSysParams(c *gin.Context) {
|
||||
var req UpdateParamsRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -102,7 +171,15 @@ func (p *ParamsApi) UpdateSysParams(c *gin.Context) {
|
||||
response.OkWithMessage("更新成功", c)
|
||||
}
|
||||
|
||||
// GetSysParams 根据Key获取参数
|
||||
// GetSysParams
|
||||
// @Tags SysParams
|
||||
// @Summary 根据Key获取参数
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param key query string true "参数Key"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取参数"
|
||||
// @Router /sysParams/getSysParams [get]
|
||||
func (p *ParamsApi) GetSysParams(c *gin.Context) {
|
||||
key := c.Query("key")
|
||||
if key == "" {
|
||||
@@ -112,14 +189,54 @@ func (p *ParamsApi) GetSysParams(c *gin.Context) {
|
||||
|
||||
params, err := paramsUsecase.GetByKey(c, key)
|
||||
if err != nil {
|
||||
response.FailWithMessage("获取失败", c)
|
||||
response.FailWithMessage("获取失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithDetailed(gin.H{"sysParams": params}, "获取成功", c)
|
||||
response.OkWithDetailed(params, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetSysParamsList 获取参数列表
|
||||
// FindSysParams
|
||||
// @Tags SysParams
|
||||
// @Summary 根据ID获取参数
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "参数ID"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取参数"
|
||||
// @Router /sysParams/findSysParams [get]
|
||||
func (p *ParamsApi) FindSysParams(c *gin.Context) {
|
||||
idStr := c.Query("ID")
|
||||
if idStr == "" {
|
||||
response.FailWithMessage("参数错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
var id uint
|
||||
for _, ch := range idStr {
|
||||
if ch >= '0' && ch <= '9' {
|
||||
id = id*10 + uint(ch-'0')
|
||||
}
|
||||
}
|
||||
|
||||
params, err := paramsUsecase.GetByID(c, id)
|
||||
if err != nil {
|
||||
response.FailWithMessage("查询失败: "+err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
response.OkWithData(params, c)
|
||||
}
|
||||
|
||||
// GetSysParamsList
|
||||
// @Tags SysParams
|
||||
// @Summary 分页获取参数列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body GetParamsListRequest true "页码, 每页大小, 搜索条件"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取参数列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /sysParams/getSysParamsList [post]
|
||||
func (p *ParamsApi) GetSysParamsList(c *gin.Context) {
|
||||
var req GetParamsListRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
|
||||
@@ -8,7 +8,13 @@ import (
|
||||
|
||||
type SystemApi struct{}
|
||||
|
||||
// GetServerInfo 获取服务器信息
|
||||
// GetServerInfo
|
||||
// @Tags System
|
||||
// @Summary 获取服务器信息
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取服务器信息"
|
||||
// @Router /system/getServerInfo [post]
|
||||
func (s *SystemApi) GetServerInfo(c *gin.Context) {
|
||||
serverInfo, err := systemUsecase.GetServerInfo(c.Request.Context())
|
||||
if err != nil {
|
||||
@@ -18,7 +24,13 @@ func (s *SystemApi) GetServerInfo(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"server": serverInfo}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetSystemConfig 获取配置文件内容
|
||||
// GetSystemConfig
|
||||
// @Tags System
|
||||
// @Summary 获取配置文件内容
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取配置文件内容,返回包括系统配置"
|
||||
// @Router /system/getSystemConfig [post]
|
||||
func (s *SystemApi) GetSystemConfig(c *gin.Context) {
|
||||
// 简化实现:返回基本配置信息
|
||||
response.OkWithDetailed(gin.H{
|
||||
@@ -30,13 +42,26 @@ func (s *SystemApi) GetSystemConfig(c *gin.Context) {
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// SetSystemConfig 设置配置文件内容
|
||||
// SetSystemConfig
|
||||
// @Tags System
|
||||
// @Summary 设置配置文件内容
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body map[string]interface{} true "设置配置文件内容"
|
||||
// @Success 200 {object} response.Response{msg=string} "设置配置文件内容"
|
||||
// @Router /system/setSystemConfig [post]
|
||||
func (s *SystemApi) SetSystemConfig(c *gin.Context) {
|
||||
// 简化实现:配置设置功能
|
||||
response.OkWithMessage("设置成功", c)
|
||||
}
|
||||
|
||||
// ReloadSystem 重载系统
|
||||
// ReloadSystem
|
||||
// @Tags System
|
||||
// @Summary 重载系统
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{msg=string} "重载系统"
|
||||
// @Router /system/reloadSystem [post]
|
||||
func (s *SystemApi) ReloadSystem(c *gin.Context) {
|
||||
// 简化实现:系统重载功能
|
||||
response.OkWithMessage("重载系统成功", c)
|
||||
|
||||
@@ -84,7 +84,13 @@ type DeleteUserRequest struct {
|
||||
ID uint `json:"ID" binding:"required"`
|
||||
}
|
||||
|
||||
// Register 用户注册
|
||||
// Register
|
||||
// @Tags SysUser
|
||||
// @Summary 用户注册账号
|
||||
// @Produce application/json
|
||||
// @Param data body RegisterRequest true "用户名, 昵称, 密码, 角色ID"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "用户注册账号,返回包括用户信息"
|
||||
// @Router /user/admin_register [post]
|
||||
func (u *UserApi) Register(c *gin.Context) {
|
||||
var req RegisterRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -112,7 +118,14 @@ func (u *UserApi) Register(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{"user": toUserResponse(created)}, "注册成功", c)
|
||||
}
|
||||
|
||||
// ChangePassword 修改密码
|
||||
// ChangePassword
|
||||
// @Tags SysUser
|
||||
// @Summary 用户修改密码
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body ChangePasswordRequest true "用户名, 原密码, 新密码"
|
||||
// @Success 200 {object} response.Response{msg=string} "用户修改密码"
|
||||
// @Router /user/changePassword [post]
|
||||
func (u *UserApi) ChangePassword(c *gin.Context) {
|
||||
var req ChangePasswordRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -134,7 +147,14 @@ func (u *UserApi) ChangePassword(c *gin.Context) {
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
|
||||
// ResetPassword 重置密码
|
||||
// ResetPassword
|
||||
// @Tags SysUser
|
||||
// @Summary 重置用户密码
|
||||
// @Security ApiKeyAuth
|
||||
// @Produce application/json
|
||||
// @Param data body ResetPasswordRequest true "ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "重置用户密码"
|
||||
// @Router /user/resetPassword [post]
|
||||
func (u *UserApi) ResetPassword(c *gin.Context) {
|
||||
var req ResetPasswordRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -150,7 +170,14 @@ func (u *UserApi) ResetPassword(c *gin.Context) {
|
||||
response.OkWithMessage("重置成功", c)
|
||||
}
|
||||
|
||||
// GetUserInfo 获取用户信息
|
||||
// GetUserInfo
|
||||
// @Tags SysUser
|
||||
// @Summary 获取用户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取用户信息"
|
||||
// @Router /user/getUserInfo [get]
|
||||
func (u *UserApi) GetUserInfo(c *gin.Context) {
|
||||
uuid := utils.GetUserUuid(c)
|
||||
user, err := userUsecase.GetUserInfo(c, uuid.String())
|
||||
@@ -159,10 +186,24 @@ func (u *UserApi) GetUserInfo(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 检查用户角色默认路由
|
||||
if user.Authority != nil {
|
||||
defaultRouter := menuUsecase.UserAuthorityDefaultRouter(c, user.AuthorityId, user.Authority.DefaultRouter)
|
||||
user.Authority.DefaultRouter = defaultRouter
|
||||
}
|
||||
|
||||
response.OkWithDetailed(gin.H{"userInfo": toUserResponse(user)}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetUserList 获取用户列表
|
||||
// GetUserList
|
||||
// @Tags SysUser
|
||||
// @Summary 分页获取用户列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body GetUserListRequest true "页码, 每页大小"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取用户列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /user/getUserList [post]
|
||||
func (u *UserApi) GetUserList(c *gin.Context) {
|
||||
var req GetUserListRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -210,7 +251,15 @@ func (u *UserApi) GetUserList(c *gin.Context) {
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// SetUserInfo 设置用户信息
|
||||
// SetUserInfo
|
||||
// @Tags SysUser
|
||||
// @Summary 设置用户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body SetUserInfoRequest true "ID, 用户名, 昵称, 头像链接"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息"
|
||||
// @Router /user/setUserInfo [put]
|
||||
func (u *UserApi) SetUserInfo(c *gin.Context) {
|
||||
var req SetUserInfoRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -244,7 +293,15 @@ func (u *UserApi) SetUserInfo(c *gin.Context) {
|
||||
response.OkWithMessage("设置成功", c)
|
||||
}
|
||||
|
||||
// SetSelfInfo 设置自己信息
|
||||
// SetSelfInfo
|
||||
// @Tags SysUser
|
||||
// @Summary 设置用户信息
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body SetSelfInfoRequest true "ID, 用户名, 昵称, 头像链接"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户信息"
|
||||
// @Router /user/SetSelfInfo [put]
|
||||
func (u *UserApi) SetSelfInfo(c *gin.Context) {
|
||||
var req SetSelfInfoRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -274,7 +331,15 @@ func (u *UserApi) SetSelfInfo(c *gin.Context) {
|
||||
response.OkWithMessage("设置成功", c)
|
||||
}
|
||||
|
||||
// SetSelfSetting 设置自己配置
|
||||
// SetSelfSetting
|
||||
// @Tags SysUser
|
||||
// @Summary 设置用户配置
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body map[string]interface{} true "用户配置数据"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "设置用户配置"
|
||||
// @Router /user/SetSelfSetting [put]
|
||||
func (u *UserApi) SetSelfSetting(c *gin.Context) {
|
||||
var req map[string]interface{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -297,7 +362,15 @@ func (u *UserApi) SetSelfSetting(c *gin.Context) {
|
||||
response.OkWithMessage("设置成功", c)
|
||||
}
|
||||
|
||||
// DeleteUser 删除用户
|
||||
// DeleteUser
|
||||
// @Tags SysUser
|
||||
// @Summary 删除用户
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body DeleteUserRequest true "用户ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除用户"
|
||||
// @Router /user/deleteUser [delete]
|
||||
func (u *UserApi) DeleteUser(c *gin.Context) {
|
||||
var req DeleteUserRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -319,7 +392,15 @@ func (u *UserApi) DeleteUser(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// SetUserAuthority 设置用户角色
|
||||
// SetUserAuthority
|
||||
// @Tags SysUser
|
||||
// @Summary 更改用户权限
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body SetUserAuthorityRequest true "用户UUID, 角色ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "设置用户权限"
|
||||
// @Router /user/setUserAuthority [post]
|
||||
func (u *UserApi) SetUserAuthority(c *gin.Context) {
|
||||
var req SetUserAuthorityRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -359,7 +440,15 @@ func (u *UserApi) SetUserAuthority(c *gin.Context) {
|
||||
response.OkWithMessage("修改成功", c)
|
||||
}
|
||||
|
||||
// SetUserAuthorities 设置用户多角色
|
||||
// SetUserAuthorities
|
||||
// @Tags SysUser
|
||||
// @Summary 设置用户权限
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body SetUserAuthoritiesRequest true "用户UUID, 角色ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "设置用户权限"
|
||||
// @Router /user/setUserAuthorities [post]
|
||||
func (u *UserApi) SetUserAuthorities(c *gin.Context) {
|
||||
var req SetUserAuthoritiesRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
|
||||
@@ -50,7 +50,15 @@ type ExportVersionResponse struct {
|
||||
Dictionaries []map[string]interface{} `json:"dictionaries"`
|
||||
}
|
||||
|
||||
// DeleteSysVersion 删除版本
|
||||
// DeleteSysVersion
|
||||
// @Tags SysVersion
|
||||
// @Summary 删除版本
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "版本ID"
|
||||
// @Success 200 {object} response.Response{msg=string} "删除版本"
|
||||
// @Router /sysVersion/deleteSysVersion [delete]
|
||||
func (v *VersionApi) DeleteSysVersion(c *gin.Context) {
|
||||
id := c.Query("ID")
|
||||
if id == "" {
|
||||
@@ -65,7 +73,15 @@ func (v *VersionApi) DeleteSysVersion(c *gin.Context) {
|
||||
response.OkWithMessage("删除成功", c)
|
||||
}
|
||||
|
||||
// DeleteSysVersionByIds 批量删除版本
|
||||
// DeleteSysVersionByIds
|
||||
// @Tags SysVersion
|
||||
// @Summary 批量删除版本
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param IDs[] query []string true "版本ID列表"
|
||||
// @Success 200 {object} response.Response{msg=string} "批量删除版本"
|
||||
// @Router /sysVersion/deleteSysVersionByIds [delete]
|
||||
func (v *VersionApi) DeleteSysVersionByIds(c *gin.Context) {
|
||||
ids := c.QueryArray("IDs[]")
|
||||
if len(ids) == 0 {
|
||||
@@ -80,7 +96,15 @@ func (v *VersionApi) DeleteSysVersionByIds(c *gin.Context) {
|
||||
response.OkWithMessage("批量删除成功", c)
|
||||
}
|
||||
|
||||
// FindSysVersion 根据ID获取版本
|
||||
// FindSysVersion
|
||||
// @Tags SysVersion
|
||||
// @Summary 根据ID获取版本
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "版本ID"
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取版本"
|
||||
// @Router /sysVersion/findSysVersion [get]
|
||||
func (v *VersionApi) FindSysVersion(c *gin.Context) {
|
||||
id := c.Query("ID")
|
||||
if id == "" {
|
||||
@@ -96,7 +120,15 @@ func (v *VersionApi) FindSysVersion(c *gin.Context) {
|
||||
response.OkWithData(toVersionResponse(version), c)
|
||||
}
|
||||
|
||||
// GetSysVersionList 分页获取版本列表
|
||||
// GetSysVersionList
|
||||
// @Tags SysVersion
|
||||
// @Summary 分页获取版本列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data query VersionSearchRequest true "页码, 每页大小, 搜索条件"
|
||||
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "分页获取版本列表,返回包括列表,总数,页码,每页数量"
|
||||
// @Router /sysVersion/getSysVersionList [get]
|
||||
func (v *VersionApi) GetSysVersionList(c *gin.Context) {
|
||||
var req VersionSearchRequest
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
@@ -138,14 +170,27 @@ func (v *VersionApi) GetSysVersionList(c *gin.Context) {
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// GetSysVersionPublic 公开版本接口
|
||||
// GetSysVersionPublic
|
||||
// @Tags SysVersion
|
||||
// @Summary 公开版本接口
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} response.Response{data=map[string]interface{},msg=string} "获取公开版本信息"
|
||||
// @Router /sysVersion/getSysVersionPublic [get]
|
||||
func (v *VersionApi) GetSysVersionPublic(c *gin.Context) {
|
||||
response.OkWithDetailed(gin.H{
|
||||
"info": "不需要鉴权的版本管理接口信息",
|
||||
}, "获取成功", c)
|
||||
}
|
||||
|
||||
// ExportVersion 创建发版数据
|
||||
// ExportVersion
|
||||
// @Tags SysVersion
|
||||
// @Summary 创建发版数据
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body ExportVersionRequest true "发版数据"
|
||||
// @Success 200 {object} response.Response{msg=string} "创建发版成功"
|
||||
// @Router /sysVersion/exportVersion [post]
|
||||
func (v *VersionApi) ExportVersion(c *gin.Context) {
|
||||
var req ExportVersionRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -246,7 +291,15 @@ func (v *VersionApi) ExportVersion(c *gin.Context) {
|
||||
response.OkWithMessage("创建发版成功", c)
|
||||
}
|
||||
|
||||
// DownloadVersionJson 下载版本JSON数据
|
||||
// DownloadVersionJson
|
||||
// @Tags SysVersion
|
||||
// @Summary 下载版本JSON数据
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param ID query string true "版本ID"
|
||||
// @Success 200 {file} json "版本JSON文件"
|
||||
// @Router /sysVersion/downloadVersionJson [get]
|
||||
func (v *VersionApi) DownloadVersionJson(c *gin.Context) {
|
||||
id := c.Query("ID")
|
||||
if id == "" {
|
||||
@@ -283,7 +336,15 @@ func (v *VersionApi) DownloadVersionJson(c *gin.Context) {
|
||||
c.Data(http.StatusOK, "application/json", jsonData)
|
||||
}
|
||||
|
||||
// ImportVersion 导入版本数据
|
||||
// ImportVersion
|
||||
// @Tags SysVersion
|
||||
// @Summary 导入版本数据
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body map[string]interface{} true "版本JSON数据"
|
||||
// @Success 200 {object} response.Response{msg=string} "导入成功"
|
||||
// @Router /sysVersion/importVersion [post]
|
||||
func (v *VersionApi) ImportVersion(c *gin.Context) {
|
||||
var importData map[string]interface{}
|
||||
if err := c.ShouldBindJSON(&importData); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user