【权限模块】

This commit is contained in:
weizhihong 2023-08-30 09:28:21 +08:00
parent de5bf8b82a
commit 5307bc7bb1
27 changed files with 4951 additions and 16 deletions

381
api/auth.go Normal file
View File

@ -0,0 +1,381 @@
package api
import (
"net/http"
"strconv"
jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service"
)
func InitAuthRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/auth").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
authed.GET("/role/paging", pageQueryRole)
authed.GET("/role/list", listQueryRole)
authed.POST("/role", createRole)
authed.GET("/role/:id", queryRoleInfo)
authed.PUT("/role/:id", updateRoleInfo)
authed.DELETE("/role/:id", deleteRoleInfo)
authed.GET("/path/paging", pageQueryApiPath)
authed.GET("/path/list", listQueryApiPath)
authed.POST("/path", createApiPath)
authed.GET("/path/:id", queryApiPathInfo)
authed.PUT("/path/:id", updateApiPathInfo)
authed.DELETE("/path/:id", deleteApiPathInfo)
authed.POST("/userLinkRole", assignRoleToUser)
}
// 分页查询角色信息
//
// @Summary 分页查询角色信息
//
// @Security JwtAuth
//
// @Description 分页查询角色信息
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param PageQueryDto query dto.PageQueryDto true "分页信息"
// @Success 200 {object} dto.PageDto
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/auth/role/paging [get]
func pageQueryRole(c *gin.Context) {
req := dto.PageQueryDto{}
if err := c.ShouldBind(&req); err != nil {
zap.S().Warn("分页查询参数绑定错误,使用默认参数", err)
req.Default()
}
page, err := service.PageAuthRoleQuery(&req)
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return
}
c.JSON(http.StatusOK, page)
}
// 查询角色列表
//
// @Summary 查询角色列表
//
// @Security JwtAuth
//
// @Description 查询角色列表
// @Tags 权限Api
// @Accept json
// @Produce json
// @Success 200 {object} dto.AuthRoleRspDto
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/auth/role/list [get]
func listQueryRole(c *gin.Context) {
page := service.ListAuthRoleQuery()
c.JSON(http.StatusOK, page)
}
// 创建角色
//
// @Summary 创建角色
//
// @Security JwtAuth
//
// @Description 创建角色
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param AuthRoleReqDto query dto.AuthRoleReqDto true "创建角色"
// @Success 200 {object} bool
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/role [post]
func createRole(c *gin.Context) {
req := dto.AuthRoleReqDto{}
if err := c.ShouldBind(&req); err != nil {
c.JSON(http.StatusBadRequest, "传入参数错误")
return
}
zap.S().Debug("保存数据", req)
c.JSON(http.StatusOK, service.CreateAuthRole(&req))
}
// 查询角色详情
//
// @Summary 查询角色详情
//
// @Security JwtAuth
//
// @Description 查询角色详情
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param id path int true "角色ID"
// @Success 200 {object} dto.AuthRoleDetailRspDto
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/role/{id} [get]
func queryRoleInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
c.JSON(http.StatusBadRequest, "必要参数id不存在")
return
}
zap.S().Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryAuthRole(int32(int64Id)))
}
// 修改角色信息
//
// @Summary 修改角色信息
//
// @Security JwtAuth
//
// @Description 修改角色信息
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param id path int true "角色信息ID"
// @Param authRoleReqDto query dto.AuthRoleReqDto true "修改的角色信息"
// @Success 200 {object} bool
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/role/{id} [put]
func updateRoleInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
c.JSON(http.StatusBadRequest, "必要参数id不存在")
return
}
zap.S().Debug("传入参数id为" + id)
req := dto.AuthRoleReqDto{}
if err := c.ShouldBind(&req); err != nil {
c.JSON(http.StatusBadRequest, "保存参数出错")
return
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.UpdateAuthRole(int32(int64Id), &req))
}
// 删除角色信息
//
// @Summary 删除角色信息
//
// @Security JwtAuth
//
// @Description 删除角色信息
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param id path int true "角色ID"
// @Success 200 {object} bool
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/role/{id} [delete]
func deleteRoleInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
c.JSON(http.StatusBadRequest, "必要参数id不存在")
return
}
zap.S().Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.DeleteAuthRole(int32(int64Id)))
}
// 分页查询接口路径信息
//
// @Summary 分页查询接口路径信息
//
// @Security JwtAuth
//
// @Description 分页查询接口路径信息
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param authApiPathPageReqDto query dto.AuthApiPathPageReqDto true "分页信息"
// @Success 200 {object} dto.PageDto
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/auth/path/paging [get]
func pageQueryApiPath(c *gin.Context) {
req := dto.AuthApiPathPageReqDto{}
if err := c.ShouldBind(&req); err != nil {
zap.S().Warn("分页查询参数绑定错误,使用默认参数", err)
req.Default()
}
page, err := service.PageAuthApiPathQuery(&req)
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return
}
c.JSON(http.StatusOK, page)
}
// 查询接口路径列表
//
// @Summary 查询接口路径列表
//
// @Security JwtAuth
//
// @Description 查询接口路径列表
// @Tags 权限Api
// @Accept json
// @Produce json
// @Success 200 {object} model.AuthAPIPath
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/auth/path/list [get]
func listQueryApiPath(c *gin.Context) {
c.JSON(http.StatusOK, service.ListAuthApiPathQuery())
}
// 创建接口路径
//
// @Summary 创建接口路径
//
// @Security JwtAuth
//
// @Description 创建接口路径
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param authApiPathReqDto query dto.AuthApiPathReqDto true "创建路径信息"
// @Success 200 {object} bool
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/auth/path [post]
func createApiPath(c *gin.Context) {
req := dto.AuthApiPathReqDto{}
if err := c.ShouldBind(&req); err != nil {
c.JSON(http.StatusBadRequest, "传入参数错误")
return
}
zap.S().Debug("保存数据", req)
c.JSON(http.StatusOK, service.CreateAuthApiPath(&req))
}
// 查询接口路径
//
// @Summary 查询接口路径
//
// @Security JwtAuth
//
// @Description 查询接口路径
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param id path int true "接口路径ID"
// @Success 200 {object} model.AuthAPIPath
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/auth/path/{id} [get]
func queryApiPathInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
c.JSON(http.StatusBadRequest, "必要参数id不存在")
return
}
zap.S().Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryAuthApiPath(int32(int64Id)))
}
// 修改接口路径
//
// @Summary 修改接口路径
//
// @Security JwtAuth
//
// @Description 修改接口路径
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param id path int true "接口路径ID"
// @Param authApiPathReqDto query dto.AuthApiPathReqDto true "修改的接口路径"
// @Success 200 {object} bool
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/auth/path/{id} [put]
func updateApiPathInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
c.JSON(http.StatusBadRequest, "必要参数id不存在")
return
}
zap.S().Debug("传入参数id为" + id)
req := dto.AuthApiPathReqDto{}
if err := c.ShouldBind(&req); err != nil {
c.JSON(http.StatusBadRequest, "保存参数出错")
return
}
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.UpdateAuthApiPath(int32(int64Id), &req))
}
// 删除接口路径
//
// @Summary 删除接口路径
//
// @Security JwtAuth
//
// @Description 删除接口路径
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param id path int true "接口路径ID"
// @Success 200 {object} bool
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/auth/path/{id} [delete]
func deleteApiPathInfo(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
c.JSON(http.StatusBadRequest, "必要参数id不存在")
return
}
zap.S().Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.DeleteAuthApiPath(int32(int64Id)))
}
// 用户关联角色
//
// @Summary 用户关联角色
//
// @Security JwtAuth
//
// @Description 用户关联角色
// @Tags 权限Api
// @Accept json
// @Produce json
// @Param authRoleUserReqDto query dto.AuthRoleUserReqDto true "关联角色信息"
// @Success 200 {object} bool
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/auth/userLinkRole [post]
func assignRoleToUser(c *gin.Context) {
req := dto.AuthRoleUserReqDto{}
if err := c.ShouldBind(&req); err != nil {
c.JSON(http.StatusBadRequest, "保存参数出错")
return
}
c.JSON(http.StatusOK, service.UserLinkRole(&req))
}

View File

@ -13,7 +13,7 @@ import (
) )
func InitCategoryRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { func InitCategoryRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/category").Use(authMiddleware.MiddlewareFunc()) authed := api.Group("/v1/category").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
authed.GET("/paging", pageQueryCategory) authed.GET("/paging", pageQueryCategory)
authed.GET("/list", listQueryCategory) authed.GET("/list", listQueryCategory)
authed.POST("", createCategory) authed.POST("", createCategory)

View File

@ -14,7 +14,7 @@ import (
) )
func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/drafting").Use(authMiddleware.MiddlewareFunc()) authed := api.Group("/v1/drafting").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
authed.GET("/paging", pageQueryDrafting) authed.GET("/paging", pageQueryDrafting)
authed.POST("", createDrafting) authed.POST("", createDrafting)
authed.POST("/:id/saveAs", saveAsDrafting) authed.POST("/:id/saveAs", saveAsDrafting)

View File

@ -9,10 +9,11 @@ import (
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData" "joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory" "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
) )
func InitGenerateGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { func InitGenerateGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/generate").Use(authMiddleware.MiddlewareFunc()) authed := api.Group("/v1/generate").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
authed.POST("/calculatelink", generateCalculateLinkData) authed.POST("/calculatelink", generateCalculateLinkData)
} }

View File

@ -13,7 +13,7 @@ import (
) )
func InitProjectRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { func InitProjectRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/project").Use(authMiddleware.MiddlewareFunc()) authed := api.Group("/v1/project").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
authed.GET("/paging", pageQueryProject) authed.GET("/paging", pageQueryProject)
authed.GET("/list", listQueryProject) authed.GET("/list", listQueryProject)
authed.POST("", createProject) authed.POST("", createProject)

View File

@ -8,13 +8,15 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service" "joylink.club/bj-rtsts-server/service"
) )
func InitProjectLinkRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { func InitProjectLinkRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/projectLink").Use(authMiddleware.MiddlewareFunc()) authed := api.Group("/v1/projectLink").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
authed.GET("/info/:id", queryProjectLinkInfo) authed.GET("/info/:id", queryProjectLinkInfo)
authed.GET("/mapInfo/trainSize/:id", queryTrainSizeByMapId) authed.GET("/mapInfo/trainSize/:id", queryTrainSizeByMapId)
authed.GET("/project/trainSize/:id", queryTrainSizeByPId)
authed.POST("", saveProjectLinkInfo) authed.POST("", saveProjectLinkInfo)
} }
@ -45,6 +47,33 @@ func queryProjectLinkInfo(c *gin.Context) {
c.JSON(http.StatusOK, service.QueryProjectLinkInfo(int32(int64Id))) c.JSON(http.StatusOK, service.QueryProjectLinkInfo(int32(int64Id)))
} }
// 通过项目ID查询项目的关联列车尺寸信息
//
// @Summary 通过项目ID查询项目的关联列车尺寸信息
//
// @Security JwtAuth
//
// @Description 通过项目ID查询项目的关联列车尺寸信息
// @Tags 项目关联信息Api
// @Accept json
// @Produce json
// @Param id path int true "地图ID"
// @Success 200 {object} dto.TrainSizeDto
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/projectLink/project/trainSize/{id} [get]
func queryTrainSizeByMapId(c *gin.Context) {
id, exist := c.Params.Get("id")
if !exist {
c.JSON(http.StatusBadRequest, "必要参数id不存在")
return
}
zap.S().Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryTrainSizeByMapId(int32(int64Id)))
}
// 通过地图ID查询项目的关联列车尺寸信息 // 通过地图ID查询项目的关联列车尺寸信息
// //
// @Summary 通过地图ID查询项目的关联列车尺寸信息 // @Summary 通过地图ID查询项目的关联列车尺寸信息
@ -61,7 +90,7 @@ func queryProjectLinkInfo(c *gin.Context) {
// @Failure 404 {object} dto.ErrorDto // @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/projectLink/mapInfo/trainSize/{id} [get] // @Router /api/v1/projectLink/mapInfo/trainSize/{id} [get]
func queryTrainSizeByMapId(c *gin.Context) { func queryTrainSizeByPId(c *gin.Context) {
id, exist := c.Params.Get("id") id, exist := c.Params.Get("id")
if !exist { if !exist {
c.JSON(http.StatusBadRequest, "必要参数id不存在") c.JSON(http.StatusBadRequest, "必要参数id不存在")
@ -69,7 +98,8 @@ func queryTrainSizeByMapId(c *gin.Context) {
} }
zap.S().Debug("传入参数id为" + id) zap.S().Debug("传入参数id为" + id)
int64Id, _ := strconv.ParseInt(id, 10, 64) int64Id, _ := strconv.ParseInt(id, 10, 64)
c.JSON(http.StatusOK, service.QueryTrainSizeByMapId(int32(int64Id))) trainSizeArr := service.QueryProjectTrainSize(int32(int64Id))
c.JSON(http.StatusOK, dto.ConvertFromTrainSizeDto(trainSizeArr))
} }
// 保存项目的所有关联信息 // 保存项目的所有关联信息

View File

@ -15,7 +15,7 @@ import (
) )
func InitPublishedGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { func InitPublishedGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/publishedGi").Use(authMiddleware.MiddlewareFunc()) authed := api.Group("/v1/publishedGi").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
authed.GET("/paging", pageQueryPublishedGi) authed.GET("/paging", pageQueryPublishedGi)
authed.GET("/list", listQueryPublishedGi) authed.GET("/list", listQueryPublishedGi)
authed.GET("/:id", getPublishedGiById) authed.GET("/:id", getPublishedGiById)

View File

@ -15,11 +15,12 @@ import (
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory" "joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
apiproto "joylink.club/bj-rtsts-server/grpcproto" apiproto "joylink.club/bj-rtsts-server/grpcproto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service" "joylink.club/bj-rtsts-server/service"
) )
func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/simulation").Use(authMiddleware.MiddlewareFunc()) authed := api.Group("/v1/simulation").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
authed.POST("/create", create) authed.POST("/create", create)
authed.GET("/state/:id", findSimulationState) authed.GET("/state/:id", findSimulationState)
authed.POST("/destroy/:id", destroy) authed.POST("/destroy/:id", destroy)

View File

@ -9,11 +9,12 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service" "joylink.club/bj-rtsts-server/service"
) )
func InitTrainManageRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { func InitTrainManageRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
authed := api.Group("/v1/trainManage").Use(authMiddleware.MiddlewareFunc()) authed := api.Group("/v1/trainManage").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
authed.GET("/model/paging", pageQueryTrainModel) authed.GET("/model/paging", pageQueryTrainModel)
authed.GET("/model/list", queryTrainModelList) authed.GET("/model/list", queryTrainModelList)
authed.POST("/model", createTrainModel) authed.POST("/model", createTrainModel)

View File

@ -1,6 +1,8 @@
package api package api
import ( import (
"net/http"
jwt "github.com/appleboy/gin-jwt/v2" jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"go.uber.org/zap" "go.uber.org/zap"
@ -8,7 +10,6 @@ import (
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware" "joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service" "joylink.club/bj-rtsts-server/service"
"net/http"
) )
func InitUserRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { func InitUserRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
@ -16,7 +17,7 @@ func InitUserRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware)
unauthed.POST("/login", login(authMiddleware)) unauthed.POST("/login", login(authMiddleware))
unauthed.POST("/register", register) unauthed.POST("/register", register)
authed := api.Group("/v1/user").Use(authMiddleware.MiddlewareFunc()) authed := api.Group("/v1/user").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
authed.GET("/paging", pageQueryUser) authed.GET("/paging", pageQueryUser)
authed.GET("/current", findUserInfo) authed.GET("/current", findUserInfo)
} }

View File

@ -0,0 +1,392 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package dbquery
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"joylink.club/bj-rtsts-server/db/model"
)
func newAuthAPIPath(db *gorm.DB, opts ...gen.DOOption) authAPIPath {
_authAPIPath := authAPIPath{}
_authAPIPath.authAPIPathDo.UseDB(db, opts...)
_authAPIPath.authAPIPathDo.UseModel(&model.AuthAPIPath{})
tableName := _authAPIPath.authAPIPathDo.TableName()
_authAPIPath.ALL = field.NewAsterisk(tableName)
_authAPIPath.ID = field.NewInt32(tableName, "id")
_authAPIPath.Name = field.NewString(tableName, "name")
_authAPIPath.Path = field.NewString(tableName, "path")
_authAPIPath.Method = field.NewString(tableName, "method")
_authAPIPath.fillFieldMap()
return _authAPIPath
}
type authAPIPath struct {
authAPIPathDo
ALL field.Asterisk
ID field.Int32 // 主键
Name field.String // 功能名称
Path field.String // 请求路径
Method field.String // 请求方式
fieldMap map[string]field.Expr
}
func (a authAPIPath) Table(newTableName string) *authAPIPath {
a.authAPIPathDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a authAPIPath) As(alias string) *authAPIPath {
a.authAPIPathDo.DO = *(a.authAPIPathDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *authAPIPath) updateTableName(table string) *authAPIPath {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt32(table, "id")
a.Name = field.NewString(table, "name")
a.Path = field.NewString(table, "path")
a.Method = field.NewString(table, "method")
a.fillFieldMap()
return a
}
func (a *authAPIPath) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := a.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (a *authAPIPath) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 4)
a.fieldMap["id"] = a.ID
a.fieldMap["name"] = a.Name
a.fieldMap["path"] = a.Path
a.fieldMap["method"] = a.Method
}
func (a authAPIPath) clone(db *gorm.DB) authAPIPath {
a.authAPIPathDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a authAPIPath) replaceDB(db *gorm.DB) authAPIPath {
a.authAPIPathDo.ReplaceDB(db)
return a
}
type authAPIPathDo struct{ gen.DO }
type IAuthAPIPathDo interface {
gen.SubQuery
Debug() IAuthAPIPathDo
WithContext(ctx context.Context) IAuthAPIPathDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAuthAPIPathDo
WriteDB() IAuthAPIPathDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAuthAPIPathDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAuthAPIPathDo
Not(conds ...gen.Condition) IAuthAPIPathDo
Or(conds ...gen.Condition) IAuthAPIPathDo
Select(conds ...field.Expr) IAuthAPIPathDo
Where(conds ...gen.Condition) IAuthAPIPathDo
Order(conds ...field.Expr) IAuthAPIPathDo
Distinct(cols ...field.Expr) IAuthAPIPathDo
Omit(cols ...field.Expr) IAuthAPIPathDo
Join(table schema.Tabler, on ...field.Expr) IAuthAPIPathDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAuthAPIPathDo
RightJoin(table schema.Tabler, on ...field.Expr) IAuthAPIPathDo
Group(cols ...field.Expr) IAuthAPIPathDo
Having(conds ...gen.Condition) IAuthAPIPathDo
Limit(limit int) IAuthAPIPathDo
Offset(offset int) IAuthAPIPathDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAuthAPIPathDo
Unscoped() IAuthAPIPathDo
Create(values ...*model.AuthAPIPath) error
CreateInBatches(values []*model.AuthAPIPath, batchSize int) error
Save(values ...*model.AuthAPIPath) error
First() (*model.AuthAPIPath, error)
Take() (*model.AuthAPIPath, error)
Last() (*model.AuthAPIPath, error)
Find() ([]*model.AuthAPIPath, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AuthAPIPath, err error)
FindInBatches(result *[]*model.AuthAPIPath, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AuthAPIPath) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IAuthAPIPathDo
Assign(attrs ...field.AssignExpr) IAuthAPIPathDo
Joins(fields ...field.RelationField) IAuthAPIPathDo
Preload(fields ...field.RelationField) IAuthAPIPathDo
FirstOrInit() (*model.AuthAPIPath, error)
FirstOrCreate() (*model.AuthAPIPath, error)
FindByPage(offset int, limit int) (result []*model.AuthAPIPath, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IAuthAPIPathDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a authAPIPathDo) Debug() IAuthAPIPathDo {
return a.withDO(a.DO.Debug())
}
func (a authAPIPathDo) WithContext(ctx context.Context) IAuthAPIPathDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a authAPIPathDo) ReadDB() IAuthAPIPathDo {
return a.Clauses(dbresolver.Read)
}
func (a authAPIPathDo) WriteDB() IAuthAPIPathDo {
return a.Clauses(dbresolver.Write)
}
func (a authAPIPathDo) Session(config *gorm.Session) IAuthAPIPathDo {
return a.withDO(a.DO.Session(config))
}
func (a authAPIPathDo) Clauses(conds ...clause.Expression) IAuthAPIPathDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a authAPIPathDo) Returning(value interface{}, columns ...string) IAuthAPIPathDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a authAPIPathDo) Not(conds ...gen.Condition) IAuthAPIPathDo {
return a.withDO(a.DO.Not(conds...))
}
func (a authAPIPathDo) Or(conds ...gen.Condition) IAuthAPIPathDo {
return a.withDO(a.DO.Or(conds...))
}
func (a authAPIPathDo) Select(conds ...field.Expr) IAuthAPIPathDo {
return a.withDO(a.DO.Select(conds...))
}
func (a authAPIPathDo) Where(conds ...gen.Condition) IAuthAPIPathDo {
return a.withDO(a.DO.Where(conds...))
}
func (a authAPIPathDo) Order(conds ...field.Expr) IAuthAPIPathDo {
return a.withDO(a.DO.Order(conds...))
}
func (a authAPIPathDo) Distinct(cols ...field.Expr) IAuthAPIPathDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a authAPIPathDo) Omit(cols ...field.Expr) IAuthAPIPathDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a authAPIPathDo) Join(table schema.Tabler, on ...field.Expr) IAuthAPIPathDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a authAPIPathDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAuthAPIPathDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a authAPIPathDo) RightJoin(table schema.Tabler, on ...field.Expr) IAuthAPIPathDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a authAPIPathDo) Group(cols ...field.Expr) IAuthAPIPathDo {
return a.withDO(a.DO.Group(cols...))
}
func (a authAPIPathDo) Having(conds ...gen.Condition) IAuthAPIPathDo {
return a.withDO(a.DO.Having(conds...))
}
func (a authAPIPathDo) Limit(limit int) IAuthAPIPathDo {
return a.withDO(a.DO.Limit(limit))
}
func (a authAPIPathDo) Offset(offset int) IAuthAPIPathDo {
return a.withDO(a.DO.Offset(offset))
}
func (a authAPIPathDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAuthAPIPathDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a authAPIPathDo) Unscoped() IAuthAPIPathDo {
return a.withDO(a.DO.Unscoped())
}
func (a authAPIPathDo) Create(values ...*model.AuthAPIPath) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a authAPIPathDo) CreateInBatches(values []*model.AuthAPIPath, batchSize int) error {
return a.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (a authAPIPathDo) Save(values ...*model.AuthAPIPath) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a authAPIPathDo) First() (*model.AuthAPIPath, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.AuthAPIPath), nil
}
}
func (a authAPIPathDo) Take() (*model.AuthAPIPath, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.AuthAPIPath), nil
}
}
func (a authAPIPathDo) Last() (*model.AuthAPIPath, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.AuthAPIPath), nil
}
}
func (a authAPIPathDo) Find() ([]*model.AuthAPIPath, error) {
result, err := a.DO.Find()
return result.([]*model.AuthAPIPath), err
}
func (a authAPIPathDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AuthAPIPath, err error) {
buf := make([]*model.AuthAPIPath, 0, batchSize)
err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (a authAPIPathDo) FindInBatches(result *[]*model.AuthAPIPath, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a authAPIPathDo) Attrs(attrs ...field.AssignExpr) IAuthAPIPathDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a authAPIPathDo) Assign(attrs ...field.AssignExpr) IAuthAPIPathDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a authAPIPathDo) Joins(fields ...field.RelationField) IAuthAPIPathDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a authAPIPathDo) Preload(fields ...field.RelationField) IAuthAPIPathDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a authAPIPathDo) FirstOrInit() (*model.AuthAPIPath, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.AuthAPIPath), nil
}
}
func (a authAPIPathDo) FirstOrCreate() (*model.AuthAPIPath, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.AuthAPIPath), nil
}
}
func (a authAPIPathDo) FindByPage(offset int, limit int) (result []*model.AuthAPIPath, count int64, err error) {
result, err = a.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = a.Offset(-1).Limit(-1).Count()
return
}
func (a authAPIPathDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = a.Count()
if err != nil {
return
}
err = a.Offset(offset).Limit(limit).Scan(result)
return
}
func (a authAPIPathDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a authAPIPathDo) Delete(models ...*model.AuthAPIPath) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *authAPIPathDo) withDO(do gen.Dao) *authAPIPathDo {
a.DO = *do.(*gen.DO)
return a
}

392
db/dbquery/auth_role.gen.go Normal file
View File

@ -0,0 +1,392 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package dbquery
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"joylink.club/bj-rtsts-server/db/model"
)
func newAuthRole(db *gorm.DB, opts ...gen.DOOption) authRole {
_authRole := authRole{}
_authRole.authRoleDo.UseDB(db, opts...)
_authRole.authRoleDo.UseModel(&model.AuthRole{})
tableName := _authRole.authRoleDo.TableName()
_authRole.ALL = field.NewAsterisk(tableName)
_authRole.ID = field.NewInt32(tableName, "id")
_authRole.Name = field.NewString(tableName, "name")
_authRole.Weight = field.NewInt32(tableName, "weight")
_authRole.CreateTime = field.NewTime(tableName, "create_time")
_authRole.fillFieldMap()
return _authRole
}
type authRole struct {
authRoleDo
ALL field.Asterisk
ID field.Int32 // 主键
Name field.String // 角色名字
Weight field.Int32 // 角色
CreateTime field.Time
fieldMap map[string]field.Expr
}
func (a authRole) Table(newTableName string) *authRole {
a.authRoleDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a authRole) As(alias string) *authRole {
a.authRoleDo.DO = *(a.authRoleDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *authRole) updateTableName(table string) *authRole {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt32(table, "id")
a.Name = field.NewString(table, "name")
a.Weight = field.NewInt32(table, "weight")
a.CreateTime = field.NewTime(table, "create_time")
a.fillFieldMap()
return a
}
func (a *authRole) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := a.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (a *authRole) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 4)
a.fieldMap["id"] = a.ID
a.fieldMap["name"] = a.Name
a.fieldMap["weight"] = a.Weight
a.fieldMap["create_time"] = a.CreateTime
}
func (a authRole) clone(db *gorm.DB) authRole {
a.authRoleDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a authRole) replaceDB(db *gorm.DB) authRole {
a.authRoleDo.ReplaceDB(db)
return a
}
type authRoleDo struct{ gen.DO }
type IAuthRoleDo interface {
gen.SubQuery
Debug() IAuthRoleDo
WithContext(ctx context.Context) IAuthRoleDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAuthRoleDo
WriteDB() IAuthRoleDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAuthRoleDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAuthRoleDo
Not(conds ...gen.Condition) IAuthRoleDo
Or(conds ...gen.Condition) IAuthRoleDo
Select(conds ...field.Expr) IAuthRoleDo
Where(conds ...gen.Condition) IAuthRoleDo
Order(conds ...field.Expr) IAuthRoleDo
Distinct(cols ...field.Expr) IAuthRoleDo
Omit(cols ...field.Expr) IAuthRoleDo
Join(table schema.Tabler, on ...field.Expr) IAuthRoleDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAuthRoleDo
RightJoin(table schema.Tabler, on ...field.Expr) IAuthRoleDo
Group(cols ...field.Expr) IAuthRoleDo
Having(conds ...gen.Condition) IAuthRoleDo
Limit(limit int) IAuthRoleDo
Offset(offset int) IAuthRoleDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAuthRoleDo
Unscoped() IAuthRoleDo
Create(values ...*model.AuthRole) error
CreateInBatches(values []*model.AuthRole, batchSize int) error
Save(values ...*model.AuthRole) error
First() (*model.AuthRole, error)
Take() (*model.AuthRole, error)
Last() (*model.AuthRole, error)
Find() ([]*model.AuthRole, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AuthRole, err error)
FindInBatches(result *[]*model.AuthRole, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AuthRole) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IAuthRoleDo
Assign(attrs ...field.AssignExpr) IAuthRoleDo
Joins(fields ...field.RelationField) IAuthRoleDo
Preload(fields ...field.RelationField) IAuthRoleDo
FirstOrInit() (*model.AuthRole, error)
FirstOrCreate() (*model.AuthRole, error)
FindByPage(offset int, limit int) (result []*model.AuthRole, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IAuthRoleDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a authRoleDo) Debug() IAuthRoleDo {
return a.withDO(a.DO.Debug())
}
func (a authRoleDo) WithContext(ctx context.Context) IAuthRoleDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a authRoleDo) ReadDB() IAuthRoleDo {
return a.Clauses(dbresolver.Read)
}
func (a authRoleDo) WriteDB() IAuthRoleDo {
return a.Clauses(dbresolver.Write)
}
func (a authRoleDo) Session(config *gorm.Session) IAuthRoleDo {
return a.withDO(a.DO.Session(config))
}
func (a authRoleDo) Clauses(conds ...clause.Expression) IAuthRoleDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a authRoleDo) Returning(value interface{}, columns ...string) IAuthRoleDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a authRoleDo) Not(conds ...gen.Condition) IAuthRoleDo {
return a.withDO(a.DO.Not(conds...))
}
func (a authRoleDo) Or(conds ...gen.Condition) IAuthRoleDo {
return a.withDO(a.DO.Or(conds...))
}
func (a authRoleDo) Select(conds ...field.Expr) IAuthRoleDo {
return a.withDO(a.DO.Select(conds...))
}
func (a authRoleDo) Where(conds ...gen.Condition) IAuthRoleDo {
return a.withDO(a.DO.Where(conds...))
}
func (a authRoleDo) Order(conds ...field.Expr) IAuthRoleDo {
return a.withDO(a.DO.Order(conds...))
}
func (a authRoleDo) Distinct(cols ...field.Expr) IAuthRoleDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a authRoleDo) Omit(cols ...field.Expr) IAuthRoleDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a authRoleDo) Join(table schema.Tabler, on ...field.Expr) IAuthRoleDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a authRoleDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAuthRoleDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a authRoleDo) RightJoin(table schema.Tabler, on ...field.Expr) IAuthRoleDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a authRoleDo) Group(cols ...field.Expr) IAuthRoleDo {
return a.withDO(a.DO.Group(cols...))
}
func (a authRoleDo) Having(conds ...gen.Condition) IAuthRoleDo {
return a.withDO(a.DO.Having(conds...))
}
func (a authRoleDo) Limit(limit int) IAuthRoleDo {
return a.withDO(a.DO.Limit(limit))
}
func (a authRoleDo) Offset(offset int) IAuthRoleDo {
return a.withDO(a.DO.Offset(offset))
}
func (a authRoleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAuthRoleDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a authRoleDo) Unscoped() IAuthRoleDo {
return a.withDO(a.DO.Unscoped())
}
func (a authRoleDo) Create(values ...*model.AuthRole) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a authRoleDo) CreateInBatches(values []*model.AuthRole, batchSize int) error {
return a.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (a authRoleDo) Save(values ...*model.AuthRole) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a authRoleDo) First() (*model.AuthRole, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.AuthRole), nil
}
}
func (a authRoleDo) Take() (*model.AuthRole, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.AuthRole), nil
}
}
func (a authRoleDo) Last() (*model.AuthRole, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.AuthRole), nil
}
}
func (a authRoleDo) Find() ([]*model.AuthRole, error) {
result, err := a.DO.Find()
return result.([]*model.AuthRole), err
}
func (a authRoleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AuthRole, err error) {
buf := make([]*model.AuthRole, 0, batchSize)
err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (a authRoleDo) FindInBatches(result *[]*model.AuthRole, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a authRoleDo) Attrs(attrs ...field.AssignExpr) IAuthRoleDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a authRoleDo) Assign(attrs ...field.AssignExpr) IAuthRoleDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a authRoleDo) Joins(fields ...field.RelationField) IAuthRoleDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a authRoleDo) Preload(fields ...field.RelationField) IAuthRoleDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a authRoleDo) FirstOrInit() (*model.AuthRole, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.AuthRole), nil
}
}
func (a authRoleDo) FirstOrCreate() (*model.AuthRole, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.AuthRole), nil
}
}
func (a authRoleDo) FindByPage(offset int, limit int) (result []*model.AuthRole, count int64, err error) {
result, err = a.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = a.Offset(-1).Limit(-1).Count()
return
}
func (a authRoleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = a.Count()
if err != nil {
return
}
err = a.Offset(offset).Limit(limit).Scan(result)
return
}
func (a authRoleDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a authRoleDo) Delete(models ...*model.AuthRole) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *authRoleDo) withDO(do gen.Dao) *authRoleDo {
a.DO = *do.(*gen.DO)
return a
}

View File

@ -0,0 +1,388 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package dbquery
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"joylink.club/bj-rtsts-server/db/model"
)
func newAuthRoleAPIPath(db *gorm.DB, opts ...gen.DOOption) authRoleAPIPath {
_authRoleAPIPath := authRoleAPIPath{}
_authRoleAPIPath.authRoleAPIPathDo.UseDB(db, opts...)
_authRoleAPIPath.authRoleAPIPathDo.UseModel(&model.AuthRoleAPIPath{})
tableName := _authRoleAPIPath.authRoleAPIPathDo.TableName()
_authRoleAPIPath.ALL = field.NewAsterisk(tableName)
_authRoleAPIPath.ID = field.NewInt32(tableName, "id")
_authRoleAPIPath.Rid = field.NewInt32(tableName, "rid")
_authRoleAPIPath.Pid = field.NewInt32(tableName, "pid")
_authRoleAPIPath.fillFieldMap()
return _authRoleAPIPath
}
type authRoleAPIPath struct {
authRoleAPIPathDo
ALL field.Asterisk
ID field.Int32 // 主键
Rid field.Int32 // 角色ID
Pid field.Int32 // 路径ID
fieldMap map[string]field.Expr
}
func (a authRoleAPIPath) Table(newTableName string) *authRoleAPIPath {
a.authRoleAPIPathDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a authRoleAPIPath) As(alias string) *authRoleAPIPath {
a.authRoleAPIPathDo.DO = *(a.authRoleAPIPathDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *authRoleAPIPath) updateTableName(table string) *authRoleAPIPath {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt32(table, "id")
a.Rid = field.NewInt32(table, "rid")
a.Pid = field.NewInt32(table, "pid")
a.fillFieldMap()
return a
}
func (a *authRoleAPIPath) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := a.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (a *authRoleAPIPath) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 3)
a.fieldMap["id"] = a.ID
a.fieldMap["rid"] = a.Rid
a.fieldMap["pid"] = a.Pid
}
func (a authRoleAPIPath) clone(db *gorm.DB) authRoleAPIPath {
a.authRoleAPIPathDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a authRoleAPIPath) replaceDB(db *gorm.DB) authRoleAPIPath {
a.authRoleAPIPathDo.ReplaceDB(db)
return a
}
type authRoleAPIPathDo struct{ gen.DO }
type IAuthRoleAPIPathDo interface {
gen.SubQuery
Debug() IAuthRoleAPIPathDo
WithContext(ctx context.Context) IAuthRoleAPIPathDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAuthRoleAPIPathDo
WriteDB() IAuthRoleAPIPathDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAuthRoleAPIPathDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAuthRoleAPIPathDo
Not(conds ...gen.Condition) IAuthRoleAPIPathDo
Or(conds ...gen.Condition) IAuthRoleAPIPathDo
Select(conds ...field.Expr) IAuthRoleAPIPathDo
Where(conds ...gen.Condition) IAuthRoleAPIPathDo
Order(conds ...field.Expr) IAuthRoleAPIPathDo
Distinct(cols ...field.Expr) IAuthRoleAPIPathDo
Omit(cols ...field.Expr) IAuthRoleAPIPathDo
Join(table schema.Tabler, on ...field.Expr) IAuthRoleAPIPathDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAuthRoleAPIPathDo
RightJoin(table schema.Tabler, on ...field.Expr) IAuthRoleAPIPathDo
Group(cols ...field.Expr) IAuthRoleAPIPathDo
Having(conds ...gen.Condition) IAuthRoleAPIPathDo
Limit(limit int) IAuthRoleAPIPathDo
Offset(offset int) IAuthRoleAPIPathDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAuthRoleAPIPathDo
Unscoped() IAuthRoleAPIPathDo
Create(values ...*model.AuthRoleAPIPath) error
CreateInBatches(values []*model.AuthRoleAPIPath, batchSize int) error
Save(values ...*model.AuthRoleAPIPath) error
First() (*model.AuthRoleAPIPath, error)
Take() (*model.AuthRoleAPIPath, error)
Last() (*model.AuthRoleAPIPath, error)
Find() ([]*model.AuthRoleAPIPath, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AuthRoleAPIPath, err error)
FindInBatches(result *[]*model.AuthRoleAPIPath, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AuthRoleAPIPath) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IAuthRoleAPIPathDo
Assign(attrs ...field.AssignExpr) IAuthRoleAPIPathDo
Joins(fields ...field.RelationField) IAuthRoleAPIPathDo
Preload(fields ...field.RelationField) IAuthRoleAPIPathDo
FirstOrInit() (*model.AuthRoleAPIPath, error)
FirstOrCreate() (*model.AuthRoleAPIPath, error)
FindByPage(offset int, limit int) (result []*model.AuthRoleAPIPath, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IAuthRoleAPIPathDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a authRoleAPIPathDo) Debug() IAuthRoleAPIPathDo {
return a.withDO(a.DO.Debug())
}
func (a authRoleAPIPathDo) WithContext(ctx context.Context) IAuthRoleAPIPathDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a authRoleAPIPathDo) ReadDB() IAuthRoleAPIPathDo {
return a.Clauses(dbresolver.Read)
}
func (a authRoleAPIPathDo) WriteDB() IAuthRoleAPIPathDo {
return a.Clauses(dbresolver.Write)
}
func (a authRoleAPIPathDo) Session(config *gorm.Session) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Session(config))
}
func (a authRoleAPIPathDo) Clauses(conds ...clause.Expression) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a authRoleAPIPathDo) Returning(value interface{}, columns ...string) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a authRoleAPIPathDo) Not(conds ...gen.Condition) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Not(conds...))
}
func (a authRoleAPIPathDo) Or(conds ...gen.Condition) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Or(conds...))
}
func (a authRoleAPIPathDo) Select(conds ...field.Expr) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Select(conds...))
}
func (a authRoleAPIPathDo) Where(conds ...gen.Condition) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Where(conds...))
}
func (a authRoleAPIPathDo) Order(conds ...field.Expr) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Order(conds...))
}
func (a authRoleAPIPathDo) Distinct(cols ...field.Expr) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a authRoleAPIPathDo) Omit(cols ...field.Expr) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a authRoleAPIPathDo) Join(table schema.Tabler, on ...field.Expr) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a authRoleAPIPathDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAuthRoleAPIPathDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a authRoleAPIPathDo) RightJoin(table schema.Tabler, on ...field.Expr) IAuthRoleAPIPathDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a authRoleAPIPathDo) Group(cols ...field.Expr) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Group(cols...))
}
func (a authRoleAPIPathDo) Having(conds ...gen.Condition) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Having(conds...))
}
func (a authRoleAPIPathDo) Limit(limit int) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Limit(limit))
}
func (a authRoleAPIPathDo) Offset(offset int) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Offset(offset))
}
func (a authRoleAPIPathDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a authRoleAPIPathDo) Unscoped() IAuthRoleAPIPathDo {
return a.withDO(a.DO.Unscoped())
}
func (a authRoleAPIPathDo) Create(values ...*model.AuthRoleAPIPath) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a authRoleAPIPathDo) CreateInBatches(values []*model.AuthRoleAPIPath, batchSize int) error {
return a.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (a authRoleAPIPathDo) Save(values ...*model.AuthRoleAPIPath) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a authRoleAPIPathDo) First() (*model.AuthRoleAPIPath, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.AuthRoleAPIPath), nil
}
}
func (a authRoleAPIPathDo) Take() (*model.AuthRoleAPIPath, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.AuthRoleAPIPath), nil
}
}
func (a authRoleAPIPathDo) Last() (*model.AuthRoleAPIPath, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.AuthRoleAPIPath), nil
}
}
func (a authRoleAPIPathDo) Find() ([]*model.AuthRoleAPIPath, error) {
result, err := a.DO.Find()
return result.([]*model.AuthRoleAPIPath), err
}
func (a authRoleAPIPathDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AuthRoleAPIPath, err error) {
buf := make([]*model.AuthRoleAPIPath, 0, batchSize)
err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (a authRoleAPIPathDo) FindInBatches(result *[]*model.AuthRoleAPIPath, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a authRoleAPIPathDo) Attrs(attrs ...field.AssignExpr) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a authRoleAPIPathDo) Assign(attrs ...field.AssignExpr) IAuthRoleAPIPathDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a authRoleAPIPathDo) Joins(fields ...field.RelationField) IAuthRoleAPIPathDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a authRoleAPIPathDo) Preload(fields ...field.RelationField) IAuthRoleAPIPathDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a authRoleAPIPathDo) FirstOrInit() (*model.AuthRoleAPIPath, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.AuthRoleAPIPath), nil
}
}
func (a authRoleAPIPathDo) FirstOrCreate() (*model.AuthRoleAPIPath, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.AuthRoleAPIPath), nil
}
}
func (a authRoleAPIPathDo) FindByPage(offset int, limit int) (result []*model.AuthRoleAPIPath, count int64, err error) {
result, err = a.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = a.Offset(-1).Limit(-1).Count()
return
}
func (a authRoleAPIPathDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = a.Count()
if err != nil {
return
}
err = a.Offset(offset).Limit(limit).Scan(result)
return
}
func (a authRoleAPIPathDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a authRoleAPIPathDo) Delete(models ...*model.AuthRoleAPIPath) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *authRoleAPIPathDo) withDO(do gen.Dao) *authRoleAPIPathDo {
a.DO = *do.(*gen.DO)
return a
}

View File

@ -0,0 +1,388 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package dbquery
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"joylink.club/bj-rtsts-server/db/model"
)
func newAuthRoleUser(db *gorm.DB, opts ...gen.DOOption) authRoleUser {
_authRoleUser := authRoleUser{}
_authRoleUser.authRoleUserDo.UseDB(db, opts...)
_authRoleUser.authRoleUserDo.UseModel(&model.AuthRoleUser{})
tableName := _authRoleUser.authRoleUserDo.TableName()
_authRoleUser.ALL = field.NewAsterisk(tableName)
_authRoleUser.ID = field.NewInt32(tableName, "id")
_authRoleUser.Rid = field.NewInt32(tableName, "rid")
_authRoleUser.UID = field.NewInt32(tableName, "uid")
_authRoleUser.fillFieldMap()
return _authRoleUser
}
type authRoleUser struct {
authRoleUserDo
ALL field.Asterisk
ID field.Int32 // 主键
Rid field.Int32 // 角色ID
UID field.Int32 // 用户ID
fieldMap map[string]field.Expr
}
func (a authRoleUser) Table(newTableName string) *authRoleUser {
a.authRoleUserDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a authRoleUser) As(alias string) *authRoleUser {
a.authRoleUserDo.DO = *(a.authRoleUserDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *authRoleUser) updateTableName(table string) *authRoleUser {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt32(table, "id")
a.Rid = field.NewInt32(table, "rid")
a.UID = field.NewInt32(table, "uid")
a.fillFieldMap()
return a
}
func (a *authRoleUser) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := a.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (a *authRoleUser) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 3)
a.fieldMap["id"] = a.ID
a.fieldMap["rid"] = a.Rid
a.fieldMap["uid"] = a.UID
}
func (a authRoleUser) clone(db *gorm.DB) authRoleUser {
a.authRoleUserDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a authRoleUser) replaceDB(db *gorm.DB) authRoleUser {
a.authRoleUserDo.ReplaceDB(db)
return a
}
type authRoleUserDo struct{ gen.DO }
type IAuthRoleUserDo interface {
gen.SubQuery
Debug() IAuthRoleUserDo
WithContext(ctx context.Context) IAuthRoleUserDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IAuthRoleUserDo
WriteDB() IAuthRoleUserDo
As(alias string) gen.Dao
Session(config *gorm.Session) IAuthRoleUserDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IAuthRoleUserDo
Not(conds ...gen.Condition) IAuthRoleUserDo
Or(conds ...gen.Condition) IAuthRoleUserDo
Select(conds ...field.Expr) IAuthRoleUserDo
Where(conds ...gen.Condition) IAuthRoleUserDo
Order(conds ...field.Expr) IAuthRoleUserDo
Distinct(cols ...field.Expr) IAuthRoleUserDo
Omit(cols ...field.Expr) IAuthRoleUserDo
Join(table schema.Tabler, on ...field.Expr) IAuthRoleUserDo
LeftJoin(table schema.Tabler, on ...field.Expr) IAuthRoleUserDo
RightJoin(table schema.Tabler, on ...field.Expr) IAuthRoleUserDo
Group(cols ...field.Expr) IAuthRoleUserDo
Having(conds ...gen.Condition) IAuthRoleUserDo
Limit(limit int) IAuthRoleUserDo
Offset(offset int) IAuthRoleUserDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IAuthRoleUserDo
Unscoped() IAuthRoleUserDo
Create(values ...*model.AuthRoleUser) error
CreateInBatches(values []*model.AuthRoleUser, batchSize int) error
Save(values ...*model.AuthRoleUser) error
First() (*model.AuthRoleUser, error)
Take() (*model.AuthRoleUser, error)
Last() (*model.AuthRoleUser, error)
Find() ([]*model.AuthRoleUser, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AuthRoleUser, err error)
FindInBatches(result *[]*model.AuthRoleUser, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*model.AuthRoleUser) (info gen.ResultInfo, err error)
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
Updates(value interface{}) (info gen.ResultInfo, err error)
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
UpdateFrom(q gen.SubQuery) gen.Dao
Attrs(attrs ...field.AssignExpr) IAuthRoleUserDo
Assign(attrs ...field.AssignExpr) IAuthRoleUserDo
Joins(fields ...field.RelationField) IAuthRoleUserDo
Preload(fields ...field.RelationField) IAuthRoleUserDo
FirstOrInit() (*model.AuthRoleUser, error)
FirstOrCreate() (*model.AuthRoleUser, error)
FindByPage(offset int, limit int) (result []*model.AuthRoleUser, count int64, err error)
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
Scan(result interface{}) (err error)
Returning(value interface{}, columns ...string) IAuthRoleUserDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (a authRoleUserDo) Debug() IAuthRoleUserDo {
return a.withDO(a.DO.Debug())
}
func (a authRoleUserDo) WithContext(ctx context.Context) IAuthRoleUserDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a authRoleUserDo) ReadDB() IAuthRoleUserDo {
return a.Clauses(dbresolver.Read)
}
func (a authRoleUserDo) WriteDB() IAuthRoleUserDo {
return a.Clauses(dbresolver.Write)
}
func (a authRoleUserDo) Session(config *gorm.Session) IAuthRoleUserDo {
return a.withDO(a.DO.Session(config))
}
func (a authRoleUserDo) Clauses(conds ...clause.Expression) IAuthRoleUserDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a authRoleUserDo) Returning(value interface{}, columns ...string) IAuthRoleUserDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a authRoleUserDo) Not(conds ...gen.Condition) IAuthRoleUserDo {
return a.withDO(a.DO.Not(conds...))
}
func (a authRoleUserDo) Or(conds ...gen.Condition) IAuthRoleUserDo {
return a.withDO(a.DO.Or(conds...))
}
func (a authRoleUserDo) Select(conds ...field.Expr) IAuthRoleUserDo {
return a.withDO(a.DO.Select(conds...))
}
func (a authRoleUserDo) Where(conds ...gen.Condition) IAuthRoleUserDo {
return a.withDO(a.DO.Where(conds...))
}
func (a authRoleUserDo) Order(conds ...field.Expr) IAuthRoleUserDo {
return a.withDO(a.DO.Order(conds...))
}
func (a authRoleUserDo) Distinct(cols ...field.Expr) IAuthRoleUserDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a authRoleUserDo) Omit(cols ...field.Expr) IAuthRoleUserDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a authRoleUserDo) Join(table schema.Tabler, on ...field.Expr) IAuthRoleUserDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a authRoleUserDo) LeftJoin(table schema.Tabler, on ...field.Expr) IAuthRoleUserDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a authRoleUserDo) RightJoin(table schema.Tabler, on ...field.Expr) IAuthRoleUserDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a authRoleUserDo) Group(cols ...field.Expr) IAuthRoleUserDo {
return a.withDO(a.DO.Group(cols...))
}
func (a authRoleUserDo) Having(conds ...gen.Condition) IAuthRoleUserDo {
return a.withDO(a.DO.Having(conds...))
}
func (a authRoleUserDo) Limit(limit int) IAuthRoleUserDo {
return a.withDO(a.DO.Limit(limit))
}
func (a authRoleUserDo) Offset(offset int) IAuthRoleUserDo {
return a.withDO(a.DO.Offset(offset))
}
func (a authRoleUserDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IAuthRoleUserDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a authRoleUserDo) Unscoped() IAuthRoleUserDo {
return a.withDO(a.DO.Unscoped())
}
func (a authRoleUserDo) Create(values ...*model.AuthRoleUser) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a authRoleUserDo) CreateInBatches(values []*model.AuthRoleUser, batchSize int) error {
return a.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (a authRoleUserDo) Save(values ...*model.AuthRoleUser) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a authRoleUserDo) First() (*model.AuthRoleUser, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.AuthRoleUser), nil
}
}
func (a authRoleUserDo) Take() (*model.AuthRoleUser, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.AuthRoleUser), nil
}
}
func (a authRoleUserDo) Last() (*model.AuthRoleUser, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.AuthRoleUser), nil
}
}
func (a authRoleUserDo) Find() ([]*model.AuthRoleUser, error) {
result, err := a.DO.Find()
return result.([]*model.AuthRoleUser), err
}
func (a authRoleUserDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.AuthRoleUser, err error) {
buf := make([]*model.AuthRoleUser, 0, batchSize)
err = a.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (a authRoleUserDo) FindInBatches(result *[]*model.AuthRoleUser, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a authRoleUserDo) Attrs(attrs ...field.AssignExpr) IAuthRoleUserDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a authRoleUserDo) Assign(attrs ...field.AssignExpr) IAuthRoleUserDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a authRoleUserDo) Joins(fields ...field.RelationField) IAuthRoleUserDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a authRoleUserDo) Preload(fields ...field.RelationField) IAuthRoleUserDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a authRoleUserDo) FirstOrInit() (*model.AuthRoleUser, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.AuthRoleUser), nil
}
}
func (a authRoleUserDo) FirstOrCreate() (*model.AuthRoleUser, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.AuthRoleUser), nil
}
}
func (a authRoleUserDo) FindByPage(offset int, limit int) (result []*model.AuthRoleUser, count int64, err error) {
result, err = a.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = a.Offset(-1).Limit(-1).Count()
return
}
func (a authRoleUserDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = a.Count()
if err != nil {
return
}
err = a.Offset(offset).Limit(limit).Scan(result)
return
}
func (a authRoleUserDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a authRoleUserDo) Delete(models ...*model.AuthRoleUser) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *authRoleUserDo) withDO(do gen.Dao) *authRoleUserDo {
a.DO = *do.(*gen.DO)
return a
}

View File

@ -17,6 +17,10 @@ import (
var ( var (
Q = new(Query) Q = new(Query)
AuthAPIPath *authAPIPath
AuthRole *authRole
AuthRoleAPIPath *authRoleAPIPath
AuthRoleUser *authRoleUser
Category *category Category *category
Drafting *drafting Drafting *drafting
Project *project Project *project
@ -31,6 +35,10 @@ var (
func SetDefault(db *gorm.DB, opts ...gen.DOOption) { func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
*Q = *Use(db, opts...) *Q = *Use(db, opts...)
AuthAPIPath = &Q.AuthAPIPath
AuthRole = &Q.AuthRole
AuthRoleAPIPath = &Q.AuthRoleAPIPath
AuthRoleUser = &Q.AuthRoleUser
Category = &Q.Category Category = &Q.Category
Drafting = &Q.Drafting Drafting = &Q.Drafting
Project = &Q.Project Project = &Q.Project
@ -46,6 +54,10 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
func Use(db *gorm.DB, opts ...gen.DOOption) *Query { func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{ return &Query{
db: db, db: db,
AuthAPIPath: newAuthAPIPath(db, opts...),
AuthRole: newAuthRole(db, opts...),
AuthRoleAPIPath: newAuthRoleAPIPath(db, opts...),
AuthRoleUser: newAuthRoleUser(db, opts...),
Category: newCategory(db, opts...), Category: newCategory(db, opts...),
Drafting: newDrafting(db, opts...), Drafting: newDrafting(db, opts...),
Project: newProject(db, opts...), Project: newProject(db, opts...),
@ -62,6 +74,10 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
type Query struct { type Query struct {
db *gorm.DB db *gorm.DB
AuthAPIPath authAPIPath
AuthRole authRole
AuthRoleAPIPath authRoleAPIPath
AuthRoleUser authRoleUser
Category category Category category
Drafting drafting Drafting drafting
Project project Project project
@ -79,6 +95,10 @@ func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query { func (q *Query) clone(db *gorm.DB) *Query {
return &Query{ return &Query{
db: db, db: db,
AuthAPIPath: q.AuthAPIPath.clone(db),
AuthRole: q.AuthRole.clone(db),
AuthRoleAPIPath: q.AuthRoleAPIPath.clone(db),
AuthRoleUser: q.AuthRoleUser.clone(db),
Category: q.Category.clone(db), Category: q.Category.clone(db),
Drafting: q.Drafting.clone(db), Drafting: q.Drafting.clone(db),
Project: q.Project.clone(db), Project: q.Project.clone(db),
@ -103,6 +123,10 @@ func (q *Query) WriteDB() *Query {
func (q *Query) ReplaceDB(db *gorm.DB) *Query { func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{ return &Query{
db: db, db: db,
AuthAPIPath: q.AuthAPIPath.replaceDB(db),
AuthRole: q.AuthRole.replaceDB(db),
AuthRoleAPIPath: q.AuthRoleAPIPath.replaceDB(db),
AuthRoleUser: q.AuthRoleUser.replaceDB(db),
Category: q.Category.replaceDB(db), Category: q.Category.replaceDB(db),
Drafting: q.Drafting.replaceDB(db), Drafting: q.Drafting.replaceDB(db),
Project: q.Project.replaceDB(db), Project: q.Project.replaceDB(db),
@ -117,6 +141,10 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
} }
type queryCtx struct { type queryCtx struct {
AuthAPIPath IAuthAPIPathDo
AuthRole IAuthRoleDo
AuthRoleAPIPath IAuthRoleAPIPathDo
AuthRoleUser IAuthRoleUserDo
Category ICategoryDo Category ICategoryDo
Drafting IDraftingDo Drafting IDraftingDo
Project IProjectDo Project IProjectDo
@ -131,6 +159,10 @@ type queryCtx struct {
func (q *Query) WithContext(ctx context.Context) *queryCtx { func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{ return &queryCtx{
AuthAPIPath: q.AuthAPIPath.WithContext(ctx),
AuthRole: q.AuthRole.WithContext(ctx),
AuthRoleAPIPath: q.AuthRoleAPIPath.WithContext(ctx),
AuthRoleUser: q.AuthRoleUser.WithContext(ctx),
Category: q.Category.WithContext(ctx), Category: q.Category.WithContext(ctx),
Drafting: q.Drafting.WithContext(ctx), Drafting: q.Drafting.WithContext(ctx),
Project: q.Project.WithContext(ctx), Project: q.Project.WithContext(ctx),

View File

@ -0,0 +1,20 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
const TableNameAuthAPIPath = "auth_api_path"
// AuthAPIPath mapped from table <auth_api_path>
type AuthAPIPath struct {
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键
Name string `gorm:"column:name;comment:功能名称" json:"name"` // 功能名称
Path string `gorm:"column:path;comment:请求路径" json:"path"` // 请求路径
Method string `gorm:"column:method;comment:请求方式" json:"method"` // 请求方式
}
// TableName AuthAPIPath's table name
func (*AuthAPIPath) TableName() string {
return TableNameAuthAPIPath
}

24
db/model/auth_role.gen.go Normal file
View File

@ -0,0 +1,24 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
)
const TableNameAuthRole = "auth_role"
// AuthRole mapped from table <auth_role>
type AuthRole struct {
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键
Name string `gorm:"column:name;comment:角色名字" json:"name"` // 角色名字
Weight int32 `gorm:"column:weight;comment:角色" json:"weight"` // 角色
CreateTime time.Time `gorm:"column:create_time" json:"create_time"`
}
// TableName AuthRole's table name
func (*AuthRole) TableName() string {
return TableNameAuthRole
}

View File

@ -0,0 +1,19 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
const TableNameAuthRoleAPIPath = "auth_role_api_path"
// AuthRoleAPIPath mapped from table <auth_role_api_path>
type AuthRoleAPIPath struct {
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键
Rid int32 `gorm:"column:rid;comment:角色ID" json:"rid"` // 角色ID
Pid int32 `gorm:"column:pid;comment:路径ID" json:"pid"` // 路径ID
}
// TableName AuthRoleAPIPath's table name
func (*AuthRoleAPIPath) TableName() string {
return TableNameAuthRoleAPIPath
}

View File

@ -0,0 +1,19 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
const TableNameAuthRoleUser = "auth_role_user"
// AuthRoleUser mapped from table <auth_role_user>
type AuthRoleUser struct {
ID int32 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键" json:"id"` // 主键
Rid int32 `gorm:"column:rid;comment:角色ID" json:"rid"` // 角色ID
UID int32 `gorm:"column:uid;comment:用户ID" json:"uid"` // 用户ID
}
// TableName AuthRoleUser's table name
func (*AuthRoleUser) TableName() string {
return TableNameAuthRoleUser
}

View File

@ -378,6 +378,551 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/auth/path": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "创建接口路径",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "创建接口路径",
"parameters": [
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "method",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "string",
"name": "path",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/path/list": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "查询接口路径列表",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "查询接口路径列表",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.AuthAPIPath"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/path/paging": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "分页查询接口路径信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "分页查询接口路径信息",
"parameters": [
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "integer",
"example": 1,
"description": "页码",
"name": "current",
"in": "query",
"required": true
},
{
"type": "integer",
"example": 10,
"description": "页面行数",
"name": "size",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.PageDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/path/{id}": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "查询接口路径",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "查询接口路径",
"parameters": [
{
"type": "integer",
"description": "接口路径ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.AuthAPIPath"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
},
"put": {
"security": [
{
"JwtAuth": []
}
],
"description": "修改接口路径",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "修改接口路径",
"parameters": [
{
"type": "integer",
"description": "接口路径ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "method",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "string",
"name": "path",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
},
"delete": {
"security": [
{
"JwtAuth": []
}
],
"description": "删除接口路径",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "删除接口路径",
"parameters": [
{
"type": "integer",
"description": "接口路径ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/role/list": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "查询角色列表",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "查询角色列表",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.AuthRoleRspDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/role/paging": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "分页查询角色信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "分页查询角色信息",
"parameters": [
{
"type": "integer",
"example": 1,
"description": "页码",
"name": "current",
"in": "query",
"required": true
},
{
"type": "integer",
"example": 10,
"description": "页面行数",
"name": "size",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.PageDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/userLinkRole": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "用户关联角色",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "用户关联角色",
"parameters": [
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "addRids",
"in": "query"
},
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "delRids",
"in": "query"
},
{
"type": "integer",
"name": "uid",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/category": { "/api/v1/category": {
"post": { "post": {
"security": [ "security": [
@ -1407,6 +1952,61 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/projectLink/project/trainSize/{id}": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "通过项目ID查询项目的关联列车尺寸信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"项目关联信息Api"
],
"summary": "通过项目ID查询项目的关联列车尺寸信息",
"parameters": [
{
"type": "integer",
"description": "地图ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.TrainSizeDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/publishedGi/list": { "/api/v1/publishedGi/list": {
"get": { "get": {
"security": [ "security": [
@ -1741,6 +2341,271 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/role": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "创建角色",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "创建角色",
"parameters": [
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "addPaths",
"in": "query"
},
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "delPaths",
"in": "query"
},
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/role/{id}": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "查询角色详情",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "查询角色详情",
"parameters": [
{
"type": "integer",
"description": "角色ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.AuthRoleDetailRspDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
},
"put": {
"security": [
{
"JwtAuth": []
}
],
"description": "修改角色信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "修改角色信息",
"parameters": [
{
"type": "integer",
"description": "角色信息ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "addPaths",
"in": "query"
},
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "delPaths",
"in": "query"
},
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
},
"delete": {
"security": [
{
"JwtAuth": []
}
],
"description": "删除角色信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "删除角色信息",
"parameters": [
{
"type": "integer",
"description": "角色ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/check/data": { "/api/v1/simulation/check/data": {
"post": { "post": {
"security": [ "security": [
@ -3449,6 +4314,34 @@ const docTemplate = `{
} }
} }
}, },
"dto.AuthRoleDetailRspDto": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"paths": {
"type": "array",
"items": {
"$ref": "#/definitions/model.AuthAPIPath"
}
}
}
},
"dto.AuthRoleRspDto": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"dto.CheckMapDataReqDto": { "dto.CheckMapDataReqDto": {
"type": "object", "type": "object",
"required": [ "required": [
@ -3724,6 +4617,27 @@ const docTemplate = `{
"PictureType_Psl" "PictureType_Psl"
] ]
}, },
"model.AuthAPIPath": {
"type": "object",
"properties": {
"id": {
"description": "主键",
"type": "integer"
},
"method": {
"description": "请求方式",
"type": "string"
},
"name": {
"description": "功能名称",
"type": "string"
},
"path": {
"description": "请求路径",
"type": "string"
}
}
},
"model.Category": { "model.Category": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -371,6 +371,551 @@
} }
} }
}, },
"/api/v1/auth/path": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "创建接口路径",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "创建接口路径",
"parameters": [
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "method",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "string",
"name": "path",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/path/list": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "查询接口路径列表",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "查询接口路径列表",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.AuthAPIPath"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/path/paging": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "分页查询接口路径信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "分页查询接口路径信息",
"parameters": [
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "integer",
"example": 1,
"description": "页码",
"name": "current",
"in": "query",
"required": true
},
{
"type": "integer",
"example": 10,
"description": "页面行数",
"name": "size",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.PageDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/path/{id}": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "查询接口路径",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "查询接口路径",
"parameters": [
{
"type": "integer",
"description": "接口路径ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.AuthAPIPath"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
},
"put": {
"security": [
{
"JwtAuth": []
}
],
"description": "修改接口路径",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "修改接口路径",
"parameters": [
{
"type": "integer",
"description": "接口路径ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "method",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
},
{
"type": "string",
"name": "path",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
},
"delete": {
"security": [
{
"JwtAuth": []
}
],
"description": "删除接口路径",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "删除接口路径",
"parameters": [
{
"type": "integer",
"description": "接口路径ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/role/list": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "查询角色列表",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "查询角色列表",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.AuthRoleRspDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/role/paging": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "分页查询角色信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "分页查询角色信息",
"parameters": [
{
"type": "integer",
"example": 1,
"description": "页码",
"name": "current",
"in": "query",
"required": true
},
{
"type": "integer",
"example": 10,
"description": "页面行数",
"name": "size",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.PageDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/auth/userLinkRole": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "用户关联角色",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "用户关联角色",
"parameters": [
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "addRids",
"in": "query"
},
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "delRids",
"in": "query"
},
{
"type": "integer",
"name": "uid",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/category": { "/api/v1/category": {
"post": { "post": {
"security": [ "security": [
@ -1400,6 +1945,61 @@
} }
} }
}, },
"/api/v1/projectLink/project/trainSize/{id}": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "通过项目ID查询项目的关联列车尺寸信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"项目关联信息Api"
],
"summary": "通过项目ID查询项目的关联列车尺寸信息",
"parameters": [
{
"type": "integer",
"description": "地图ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.TrainSizeDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/publishedGi/list": { "/api/v1/publishedGi/list": {
"get": { "get": {
"security": [ "security": [
@ -1734,6 +2334,271 @@
} }
} }
}, },
"/api/v1/role": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "创建角色",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "创建角色",
"parameters": [
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "addPaths",
"in": "query"
},
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "delPaths",
"in": "query"
},
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/role/{id}": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "查询角色详情",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "查询角色详情",
"parameters": [
{
"type": "integer",
"description": "角色ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.AuthRoleDetailRspDto"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
},
"put": {
"security": [
{
"JwtAuth": []
}
],
"description": "修改角色信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "修改角色信息",
"parameters": [
{
"type": "integer",
"description": "角色信息ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "addPaths",
"in": "query"
},
{
"type": "array",
"items": {
"type": "integer"
},
"collectionFormat": "csv",
"name": "delPaths",
"in": "query"
},
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "name",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
},
"delete": {
"security": [
{
"JwtAuth": []
}
],
"description": "删除角色信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"权限Api"
],
"summary": "删除角色信息",
"parameters": [
{
"type": "integer",
"description": "角色ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "boolean"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/check/data": { "/api/v1/simulation/check/data": {
"post": { "post": {
"security": [ "security": [
@ -3442,6 +4307,34 @@
} }
} }
}, },
"dto.AuthRoleDetailRspDto": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"paths": {
"type": "array",
"items": {
"$ref": "#/definitions/model.AuthAPIPath"
}
}
}
},
"dto.AuthRoleRspDto": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"dto.CheckMapDataReqDto": { "dto.CheckMapDataReqDto": {
"type": "object", "type": "object",
"required": [ "required": [
@ -3717,6 +4610,27 @@
"PictureType_Psl" "PictureType_Psl"
] ]
}, },
"model.AuthAPIPath": {
"type": "object",
"properties": {
"id": {
"description": "主键",
"type": "integer"
},
"method": {
"description": "请求方式",
"type": "string"
},
"name": {
"description": "功能名称",
"type": "string"
},
"path": {
"description": "请求路径",
"type": "string"
}
}
},
"model.Category": { "model.Category": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -36,6 +36,24 @@ definitions:
description: 新添加的列车的索引 description: 新添加的列车的索引
type: string type: string
type: object type: object
dto.AuthRoleDetailRspDto:
properties:
id:
type: integer
name:
type: string
paths:
items:
$ref: '#/definitions/model.AuthAPIPath'
type: array
type: object
dto.AuthRoleRspDto:
properties:
id:
type: integer
name:
type: string
type: object
dto.CheckMapDataReqDto: dto.CheckMapDataReqDto:
properties: properties:
data: data:
@ -222,6 +240,21 @@ definitions:
x-enum-varnames: x-enum-varnames:
- PictureType_StationLayout - PictureType_StationLayout
- PictureType_Psl - PictureType_Psl
model.AuthAPIPath:
properties:
id:
description: 主键
type: integer
method:
description: 请求方式
type: string
name:
description: 功能名称
type: string
path:
description: 请求路径
type: string
type: object
model.Category: model.Category:
properties: properties:
code: code:
@ -610,6 +643,353 @@ paths:
summary: 分页查询项目信息 summary: 分页查询项目信息
tags: tags:
- 项目信息Api - 项目信息Api
/api/v1/auth/path:
post:
consumes:
- application/json
description: 创建接口路径
parameters:
- in: query
name: id
type: integer
- in: query
name: method
type: string
- in: query
name: name
type: string
- in: query
name: path
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
type: boolean
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 创建接口路径
tags:
- 权限Api
/api/v1/auth/path/{id}:
delete:
consumes:
- application/json
description: 删除接口路径
parameters:
- description: 接口路径ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
type: boolean
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 删除接口路径
tags:
- 权限Api
get:
consumes:
- application/json
description: 查询接口路径
parameters:
- description: 接口路径ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/model.AuthAPIPath'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 查询接口路径
tags:
- 权限Api
put:
consumes:
- application/json
description: 修改接口路径
parameters:
- description: 接口路径ID
in: path
name: id
required: true
type: integer
- in: query
name: id
type: integer
- in: query
name: method
type: string
- in: query
name: name
type: string
- in: query
name: path
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
type: boolean
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 修改接口路径
tags:
- 权限Api
/api/v1/auth/path/list:
get:
consumes:
- application/json
description: 查询接口路径列表
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/model.AuthAPIPath'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 查询接口路径列表
tags:
- 权限Api
/api/v1/auth/path/paging:
get:
consumes:
- application/json
description: 分页查询接口路径信息
parameters:
- in: query
name: name
type: string
- description: 页码
example: 1
in: query
name: current
required: true
type: integer
- description: 页面行数
example: 10
in: query
name: size
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dto.PageDto'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 分页查询接口路径信息
tags:
- 权限Api
/api/v1/auth/role/list:
get:
consumes:
- application/json
description: 查询角色列表
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dto.AuthRoleRspDto'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 查询角色列表
tags:
- 权限Api
/api/v1/auth/role/paging:
get:
consumes:
- application/json
description: 分页查询角色信息
parameters:
- description: 页码
example: 1
in: query
name: current
required: true
type: integer
- description: 页面行数
example: 10
in: query
name: size
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dto.PageDto'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 分页查询角色信息
tags:
- 权限Api
/api/v1/auth/userLinkRole:
post:
consumes:
- application/json
description: 用户关联角色
parameters:
- collectionFormat: csv
in: query
items:
type: integer
name: addRids
type: array
- collectionFormat: csv
in: query
items:
type: integer
name: delRids
type: array
- in: query
name: uid
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
type: boolean
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 用户关联角色
tags:
- 权限Api
/api/v1/category: /api/v1/category:
post: post:
consumes: consumes:
@ -1265,6 +1645,41 @@ paths:
summary: 通过地图ID查询项目的关联列车尺寸信息 summary: 通过地图ID查询项目的关联列车尺寸信息
tags: tags:
- 项目关联信息Api - 项目关联信息Api
/api/v1/projectLink/project/trainSize/{id}:
get:
consumes:
- application/json
description: 通过项目ID查询项目的关联列车尺寸信息
parameters:
- description: 地图ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dto.TrainSizeDto'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 通过项目ID查询项目的关联列车尺寸信息
tags:
- 项目关联信息Api
/api/v1/publishedGi/{id}: /api/v1/publishedGi/{id}:
delete: delete:
consumes: consumes:
@ -1476,6 +1891,175 @@ paths:
summary: 从发布数据拉取信息到草稿 summary: 从发布数据拉取信息到草稿
tags: tags:
- 发布的图形数据Api - 发布的图形数据Api
/api/v1/role:
post:
consumes:
- application/json
description: 创建角色
parameters:
- collectionFormat: csv
in: query
items:
type: integer
name: addPaths
type: array
- collectionFormat: csv
in: query
items:
type: integer
name: delPaths
type: array
- in: query
name: id
type: integer
- in: query
name: name
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
type: boolean
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 创建角色
tags:
- 权限Api
/api/v1/role/{id}:
delete:
consumes:
- application/json
description: 删除角色信息
parameters:
- description: 角色ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
type: boolean
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 删除角色信息
tags:
- 权限Api
get:
consumes:
- application/json
description: 查询角色详情
parameters:
- description: 角色ID
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dto.AuthRoleDetailRspDto'
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 查询角色详情
tags:
- 权限Api
put:
consumes:
- application/json
description: 修改角色信息
parameters:
- description: 角色信息ID
in: path
name: id
required: true
type: integer
- collectionFormat: csv
in: query
items:
type: integer
name: addPaths
type: array
- collectionFormat: csv
in: query
items:
type: integer
name: delPaths
type: array
- in: query
name: id
type: integer
- in: query
name: name
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
type: boolean
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 修改角色信息
tags:
- 权限Api
/api/v1/simulation/check/data: /api/v1/simulation/check/data:
post: post:
consumes: consumes:

75
dto/auth.go Normal file
View File

@ -0,0 +1,75 @@
package dto
import "joylink.club/bj-rtsts-server/db/model"
// 角色创建
type AuthRoleReqDto struct {
Id int32 `json:"id" form:"id"`
Name string `json:"name" form:"name"`
DelPaths []int32 `json:"delPaths" form:"delPaths"`
AddPaths []int32 `json:"addPaths" form:"addPaths"`
}
type AuthRoleRspDto struct {
Id int32 `json:"id" form:"id"`
Name string `json:"name" form:"name"`
}
func ConvertFromAuthRole(auths []*model.AuthRole) []*AuthRoleRspDto {
var result = make([]*AuthRoleRspDto, len(auths))
for i, a := range auths {
result[i] = &AuthRoleRspDto{Id: a.ID, Name: a.Name}
}
return result
}
type AuthRoleDetailRspDto struct {
Id int32 `json:"id" form:"id"`
Name string `json:"name" form:"name"`
Paths []*model.AuthAPIPath `json:"paths" form:"paths"`
}
type AuthApiPathPageReqDto struct {
PageQueryDto
Name string `json:"name" form:"name"`
}
type AuthApiPathReqDto struct {
Id int32 `json:"id" form:"id"`
Name string `json:"name" form:"name"`
Path string `json:"path" form:"path"`
Method string `json:"method" form:"method"`
}
type AuthRoleUserReqDto struct {
Uid int32 `json:"uid" form:"uid"`
AddRids []int32 `json:"addRids" form:"addRids"`
DelRids []int32 `json:"delRids" form:"delRids"`
}
// 角色类型
type AuthRoleType int32
const (
ADMIN AuthRoleType = iota
USER
)
type AuthUserStorageDto struct {
IsAdmin bool `json:"isAdmin" form:"isAdmin"`
RoleIds []int32 `json:"roleIds" form:"roleIds"`
AuthPaths []*AuthPath `json:"authPath" form:"authPath"`
}
type AuthPath struct {
Path string `json:"path" form:"path"`
Method string `json:"method" form:"method"`
}
func ConvertFromAuthPath(paths []*model.AuthAPIPath) []*AuthPath {
var result = make([]*AuthPath, len(paths))
for i, a := range paths {
result[i] = &AuthPath{Path: a.Path, Method: a.Method}
}
return result
}

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
swaggerFiles "github.com/swaggo/files" swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger" ginSwagger "github.com/swaggo/gin-swagger"
"joylink.club/bj-rtsts-server/api" "joylink.club/bj-rtsts-server/api"
@ -26,7 +27,6 @@ import (
func main() { func main() {
engine := InitServer() engine := InitServer()
authMiddleware := middleware.InitGinJwtMiddleware() authMiddleware := middleware.InitGinJwtMiddleware()
router := engine.Group("/api") router := engine.Group("/api")
api.InitUserRouter(router, authMiddleware) api.InitUserRouter(router, authMiddleware)
api.InitDraftingRouter(router, authMiddleware) api.InitDraftingRouter(router, authMiddleware)
@ -34,11 +34,10 @@ func main() {
api.InitSimulationRouter(router, authMiddleware) api.InitSimulationRouter(router, authMiddleware)
api.InitCategoryRouter(router, authMiddleware) api.InitCategoryRouter(router, authMiddleware)
api.InitGenerateGiRouter(router, authMiddleware) api.InitGenerateGiRouter(router, authMiddleware)
api.InitProjectRouter(router, authMiddleware) api.InitProjectRouter(router, authMiddleware)
api.InitTrainManageRouter(router, authMiddleware) api.InitTrainManageRouter(router, authMiddleware)
api.InitProjectLinkRouter(router, authMiddleware) api.InitProjectLinkRouter(router, authMiddleware)
api.InitAuthRouter(router, authMiddleware)
docs.SwaggerInfo.Title = "CBTC测试系统API" docs.SwaggerInfo.Title = "CBTC测试系统API"
engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

78
middleware/auth.go Normal file
View File

@ -0,0 +1,78 @@
package middleware
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/service"
)
// 用户权限缓存
var userAuthPathMap = make(map[int32]*dto.AuthUserStorageDto)
var PermissMiddleware = permissionMiddleware()
// 权限验证信息0
func permissionMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
user, _ := c.Get(IdentityKey)
if user == nil { // 用户未登录
c.Next()
} else {
uid := user.(*model.User).ID
zap.S().Debugf("获取用户ID:%d", uid)
userAuth := userAuthPathMap[uid]
if userAuth == nil {
userAuthPathMap[uid] = service.QueryUserAuthApiPath(uid)
userAuth = userAuthPathMap[uid]
}
if userAuth.IsAdmin { // 用户是超级管理员
c.Next()
} else {
path, method := c.Request.URL.Path, c.Request.Method
zap.S().Debugf("获取请求路径:%s, 方法:%s", path, method)
isVaild := validateUserPath(path, method, userAuth.AuthPaths)
if isVaild { // 用户有权限
c.Next()
} else {
c.JSON(http.StatusUnauthorized, "无权限访问")
}
}
}
}
}
// 验证路径
func validateUserPath(path, method string, paths []*dto.AuthPath) bool {
reqPathArr := strings.Split(path, "/")
for _, p := range paths {
if p.Method == "*" || p.Method == method {
authPathArr := strings.Split(p.Path, "/")
isValid := true
for i, p := range reqPathArr {
if p == "{id}" || p == ":id" || p == authPathArr[i] {
continue
} else if authPathArr[i] == "*" {
isValid = true
break
} else {
isValid = false
break
}
}
if isValid {
return true
}
}
}
return false
}
// 重新登录时移除权限
func clearUserPermission(userId int32) {
delete(userAuthPathMap, userId)
}

View File

@ -51,7 +51,8 @@ func InitGinJwtMiddleware() (authMiddleware *jwt.GinJWTMiddleware) {
if err != nil { if err != nil {
return nil, jwt.ErrFailedAuthentication return nil, jwt.ErrFailedAuthentication
} }
// 清理权限
clearUserPermission(user.ID)
return user, nil return user, nil
}, },
// Authorizator: func(data interface{}, c *gin.Context) bool { // Authorizator: func(data interface{}, c *gin.Context) bool {

281
service/auth.go Normal file
View File

@ -0,0 +1,281 @@
package service
import (
"fmt"
"time"
"joylink.club/bj-rtsts-server/db/dbquery"
"joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/dto"
)
// 查询权限角色信息列表
func PageAuthRoleQuery(query *dto.PageQueryDto) (*dto.PageDto, error) {
d := dbquery.AuthRole
records, total, err := d.Debug().Select(d.ID, d.Name).Order(d.CreateTime).FindByPage(query.Offset(), query.Size)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: *query, Records: dto.ConvertFromAuthRole(records)}, nil
}
// 获取角色列表
func ListAuthRoleQuery() []*dto.AuthRoleRspDto {
d := dbquery.AuthRole
records, err := d.Debug().Select(d.ID, d.Name).Order(d.CreateTime).Find()
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
return dto.ConvertFromAuthRole(records)
}
// 创建权限角色
func CreateAuthRole(a *dto.AuthRoleReqDto) bool {
createTime := time.Now()
d := model.AuthRole{Name: a.Name, CreateTime: createTime}
aq := dbquery.AuthRole
err := aq.Save(&d)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
n := len(a.AddPaths)
if n > 0 {
// 查询刚插入的角色
newAuthRole, _ := aq.Where(aq.Name.Eq(a.Name), aq.CreateTime.Eq(createTime)).First()
rolePaths := make([]*model.AuthRoleAPIPath, n)
for i, v := range a.AddPaths {
rolePaths[i] = &model.AuthRoleAPIPath{Rid: newAuthRole.ID, Pid: v}
}
dbquery.AuthRoleAPIPath.Save(rolePaths...)
return true
}
return false
}
// 查询角色详情
func QueryAuthRole(rid int32) *dto.AuthRoleDetailRspDto {
// 查询用户角色信息
role, err := dbquery.AuthRole.Where(dbquery.AuthRole.ID.Eq(rid)).First()
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
rsp := &dto.AuthRoleDetailRspDto{Id: role.ID, Name: role.Name}
// 查询角色与路径关联信息
linkPids, err2 := dbquery.AuthRoleAPIPath.Distinct(dbquery.AuthRoleAPIPath.Pid).Where(dbquery.AuthRoleAPIPath.Rid.Eq(rid)).Find()
if err2 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
}
pn := len(linkPids)
if pn > 0 {
pids := make([]int32, pn)
for i, r := range linkPids {
pids[i] = r.Pid
}
apiPaths, err4 := dbquery.AuthAPIPath.Where(dbquery.AuthAPIPath.ID.In(pids...)).Find()
if err4 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err4.Error()})
}
rsp.Paths = apiPaths
}
return rsp
}
// 编辑角色信息
func UpdateAuthRole(rid int32, info *dto.AuthRoleReqDto) bool {
// 查询用户角色信息
role, err := dbquery.AuthRole.Where(dbquery.AuthRole.ID.Eq(rid)).First()
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
if role.Weight == int32(dto.ADMIN) {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "超级管理员不可编辑"})
}
role.Name = info.Name
// 更新名称
dbquery.AuthRole.Updates(role)
// 删除关联
dqarap := dbquery.AuthRoleAPIPath
rn := len(info.DelPaths)
if rn > 0 {
dqarap.Where(dqarap.Rid.Eq(rid), dqarap.Pid.In(info.DelPaths...)).Delete()
}
// 增加关联
an := len(info.AddPaths)
if an > 0 {
rolePaths := make([]*model.AuthRoleAPIPath, an)
for i, v := range info.AddPaths {
rolePaths[i] = &model.AuthRoleAPIPath{Rid: rid, Pid: v}
}
dqarap.Save(rolePaths...)
}
return true
}
// 删除权限角色
func DeleteAuthRole(rid int32) bool {
oldD, err1 := dbquery.AuthRole.Where(dbquery.AuthRole.ID.Eq(rid)).First()
if err1 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err1.Error()})
}
if oldD.Weight == int32(dto.ADMIN) {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "超级管理员不可删除"})
}
// 如果有用户关联则不删除
count, err2 := dbquery.AuthRoleUser.Where(dbquery.AuthRoleUser.Rid.Eq(rid)).Count()
if err2 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
}
if count > 0 {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "有用户关联该角色"})
}
// 删除用户关联关系
dbquery.AuthRoleUser.Where(dbquery.AuthRoleUser.Rid.Eq(rid)).Delete()
// 删除路径关联关系
dbquery.AuthRoleAPIPath.Where(dbquery.AuthRoleAPIPath.Rid.Eq(rid)).Delete()
// 删除角色
dbquery.AuthRole.Where(dbquery.AuthRole.ID.Eq(rid)).Delete()
return true
}
// 查询接口路径信息列表
func PageAuthApiPathQuery(query *dto.AuthApiPathPageReqDto) (*dto.PageDto, error) {
d := dbquery.AuthAPIPath
dq := d.Where()
if query.Name != "" {
dq = dq.Where(d.Name.Like(fmt.Sprintf("%%%s%%", query.Name)))
}
records, total, err := dq.Debug().FindByPage(query.Offset(), query.Size)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, nil
}
// 查询接口路径信息列表
func ListAuthApiPathQuery() []*model.AuthAPIPath {
records, err := dbquery.AuthAPIPath.Find()
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
return records
}
// 创建接口路径信息
func CreateAuthApiPath(ap *dto.AuthApiPathReqDto) bool {
d := model.AuthAPIPath{Name: ap.Name, Path: ap.Path, Method: ap.Method}
err := dbquery.AuthAPIPath.Save(&d)
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
return true
}
// 查询接口路径信息
func QueryAuthApiPath(id int32) *model.AuthAPIPath {
data, err := dbquery.AuthAPIPath.Where(dbquery.AuthAPIPath.ID.Eq(id)).Debug().First()
if err != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err.Error()})
}
return data
}
// 更新接口路径信息
func UpdateAuthApiPath(id int32, a *dto.AuthApiPathReqDto) bool {
dbqa := dbquery.AuthAPIPath
oldD, err1 := dbqa.Where(dbqa.ID.Eq(id)).Debug().First()
if oldD == nil || err1 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err1.Error()})
}
oldD.Name = a.Name
oldD.Path = a.Path
oldD.Method = a.Method
_, err2 := dbqa.Updates(oldD)
if err2 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
}
return true
}
// 删除接口路径信息
func DeleteAuthApiPath(id int32) bool {
_, err1 := dbquery.AuthAPIPath.Where(dbquery.AuthAPIPath.ID.Eq(id)).First()
if err1 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err1.Error()})
}
// 删除角色中的路径信息
dbquery.AuthRoleAPIPath.Where(dbquery.AuthRoleAPIPath.Pid.Eq(id)).Delete()
// 删除接口路径信息
dbquery.AuthAPIPath.Where(dbquery.AuthAPIPath.ID.Eq(id)).Delete()
return true
}
// 用户关联角色信息
func UserLinkRole(linkInfo *dto.AuthRoleUserReqDto) bool {
dbar := dbquery.AuthRoleUser
// 删除角色关联信息
_, err1 := dbar.Where(dbar.UID.Eq(linkInfo.Uid), dbar.Rid.In(linkInfo.DelRids...)).Delete()
if err1 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err1.Error()})
}
// 插入关联关系
n := len(linkInfo.AddRids)
if n > 0 {
arul := make([]*model.AuthRoleUser, n)
for i, l := range linkInfo.AddRids {
arul[i] = &model.AuthRoleUser{UID: linkInfo.Uid, Rid: l}
}
err2 := dbar.Save(arul...)
if err2 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
}
}
return true
}
// 查询用户权限信息
func QueryUserAuthApiPath(uid int32) *dto.AuthUserStorageDto {
linkRids, err1 := dbquery.AuthRoleUser.Where(dbquery.AuthRoleUser.UID.Eq(uid)).Find()
if err1 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err1.Error()})
}
authUser := &dto.AuthUserStorageDto{IsAdmin: false}
rn := len(linkRids)
if rn > 0 {
rids := make([]int32, rn)
for i, r := range linkRids {
rids[i] = r.Rid
}
authUser.RoleIds = rids // 用户角色ID
// 查询用户角色信息
roles, err2 := dbquery.AuthRole.Where(dbquery.AuthRole.ID.In(rids...)).Find()
if err2 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
}
// 判断是否是管理员
for _, r := range roles {
authUser.IsAdmin = (authUser.IsAdmin || (r.Weight == int32(dto.ADMIN)))
}
// 非管理员时,查询角色权限路径
if !authUser.IsAdmin {
// 查询角色与路径关联信息
linkPids, err3 := dbquery.AuthRoleAPIPath.Distinct(dbquery.AuthRoleAPIPath.Pid).Where(dbquery.AuthRoleAPIPath.Rid.In(rids...)).Find()
if err3 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err3.Error()})
}
pn := len(linkPids)
if pn > 0 {
pids := make([]int32, pn)
for i, r := range linkPids {
pids[i] = r.Pid
}
apiPaths, err4 := dbquery.AuthAPIPath.Where(dbquery.AuthAPIPath.ID.In(pids...)).Find()
if err4 != nil {
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err4.Error()})
}
// 赋值路径数组
authUser.AuthPaths = dto.ConvertFromAuthPath(apiPaths)
}
}
}
return authUser
}