parent
2cf67f776d
commit
d4a2074aab
|
@ -7,6 +7,9 @@ import (
|
|||
jwt "github.com/appleboy/gin-jwt/v2"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
|
||||
"joylink.club/bj-rtsts-server/db/model"
|
||||
"joylink.club/bj-rtsts-server/dto"
|
||||
"joylink.club/bj-rtsts-server/middleware"
|
||||
|
@ -21,6 +24,7 @@ func InitDraftingRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewa
|
|||
authed.GET("/:id", queryDraftingInfo)
|
||||
authed.PUT("/:id", updateDraftingInfo)
|
||||
authed.DELETE("/:id", deleteDrafting)
|
||||
authed.POST("/calculatelink", generateCalculateLinkData)
|
||||
}
|
||||
|
||||
// 分页查询草稿
|
||||
|
@ -211,3 +215,29 @@ func deleteDrafting(c *gin.Context) {
|
|||
service.DeleteDraftingById(id)
|
||||
c.JSON(http.StatusOK, true)
|
||||
}
|
||||
|
||||
// 根据地图数据新生成计算的link信息
|
||||
//
|
||||
// @Summary 根据地图数据新生成计算的link信息
|
||||
//
|
||||
// @Security JwtAuth
|
||||
//
|
||||
// @Description 根据地图数据新生成计算的link信息
|
||||
// @Tags 草稿Api
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param DraftingMapDataDto query dto.DraftingMapDataDto true "地图信息"
|
||||
// @Success 200 {object} nil
|
||||
// @Failure 401 {object} dto.ErrorDto
|
||||
// @Failure 404 {object} dto.ErrorDto
|
||||
// @Failure 500 {object} dto.ErrorDto
|
||||
// @Router /api/v1/drafting/calculatelink [post]
|
||||
func generateCalculateLinkData(c *gin.Context) {
|
||||
req := dto.DraftingMapDataDto{}
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
||||
}
|
||||
gd := &graphicData.RtssGraphicStorage{}
|
||||
proto.Unmarshal(req.Proto, gd)
|
||||
c.JSON(http.StatusOK, memory.BuildCalculateLinkData(gd))
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
jwt "github.com/appleboy/gin-jwt/v2"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside/memory"
|
||||
"joylink.club/bj-rtsts-server/dto"
|
||||
"joylink.club/bj-rtsts-server/middleware"
|
||||
)
|
||||
|
||||
func InitGenerateGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
authed := api.Group("/v1/generate").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
|
||||
authed.POST("/calculatelink", generateCalculateLinkData)
|
||||
}
|
||||
|
||||
// 根据地图数据新生成计算的link信息
|
||||
//
|
||||
// @Summary 根据地图数据新生成计算的link信息
|
||||
//
|
||||
// @Security JwtAuth
|
||||
//
|
||||
// @Description 根据地图数据新生成计算的link信息
|
||||
// @Tags GenerateApi
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param DraftingMapDataDto query dto.DraftingMapDataDto true "地图信息"
|
||||
// @Success 200 {object} nil
|
||||
// @Failure 401 {object} dto.ErrorDto
|
||||
// @Failure 404 {object} dto.ErrorDto
|
||||
// @Failure 500 {object} dto.ErrorDto
|
||||
// @Router /api/v1/generate/calculatelink [post]
|
||||
func generateCalculateLinkData(c *gin.Context) {
|
||||
req := dto.DraftingMapDataDto{}
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
||||
}
|
||||
gd := &graphicData.RtssGraphicStorage{}
|
||||
proto.Unmarshal(req.Proto, gd)
|
||||
c.JSON(http.StatusOK, memory.BuildCalculateLinkData(gd))
|
||||
}
|
|
@ -29,7 +29,6 @@ func newAuthRole(db *gorm.DB, opts ...gen.DOOption) authRole {
|
|||
_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()
|
||||
|
@ -43,7 +42,6 @@ type authRole struct {
|
|||
ALL field.Asterisk
|
||||
ID field.Int32 // 主键
|
||||
Name field.String // 角色名字
|
||||
Weight field.Int32 // 角色
|
||||
CreateTime field.Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
|
@ -63,7 +61,6 @@ 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()
|
||||
|
@ -81,10 +78,9 @@ func (a *authRole) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|||
}
|
||||
|
||||
func (a *authRole) fillFieldMap() {
|
||||
a.fieldMap = make(map[string]field.Expr, 4)
|
||||
a.fieldMap = make(map[string]field.Expr, 3)
|
||||
a.fieldMap["id"] = a.ID
|
||||
a.fieldMap["name"] = a.Name
|
||||
a.fieldMap["weight"] = a.Weight
|
||||
a.fieldMap["create_time"] = a.CreateTime
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ const TableNameAuthRole = "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"`
|
||||
}
|
||||
|
||||
|
|
144
docs/docs.go
144
docs/docs.go
|
@ -1272,6 +1272,60 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/drafting/calculatelink": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"JwtAuth": []
|
||||
}
|
||||
],
|
||||
"description": "根据地图数据新生成计算的link信息",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"草稿Api"
|
||||
],
|
||||
"summary": "根据地图数据新生成计算的link信息",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
},
|
||||
"collectionFormat": "csv",
|
||||
"name": "proto",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"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/drafting/paging": {
|
||||
"get": {
|
||||
"security": [
|
||||
|
@ -1626,60 +1680,6 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/generate/calculatelink": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"JwtAuth": []
|
||||
}
|
||||
],
|
||||
"description": "根据地图数据新生成计算的link信息",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"GenerateApi"
|
||||
],
|
||||
"summary": "根据地图数据新生成计算的link信息",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
},
|
||||
"collectionFormat": "csv",
|
||||
"name": "proto",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"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/project": {
|
||||
"post": {
|
||||
"security": [
|
||||
|
@ -4245,7 +4245,7 @@ const docTemplate = `{
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.RegisterUser"
|
||||
"$ref": "#/definitions/dto.UserRspDto"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
|
@ -4768,6 +4768,40 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"dto.UserRspDto": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"mobile": {
|
||||
"description": "手机号",
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "名字",
|
||||
"type": "string"
|
||||
},
|
||||
"paths": {
|
||||
"description": "权限路径",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/model.AuthAPIPath"
|
||||
}
|
||||
},
|
||||
"register_time": {
|
||||
"description": "注册时间",
|
||||
"type": "string"
|
||||
},
|
||||
"roles": {
|
||||
"description": "用户角色",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.AuthRoleRspDto"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"graphicData.PictureType": {
|
||||
"type": "integer",
|
||||
"enum": [
|
||||
|
|
|
@ -1265,6 +1265,60 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/drafting/calculatelink": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"JwtAuth": []
|
||||
}
|
||||
],
|
||||
"description": "根据地图数据新生成计算的link信息",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"草稿Api"
|
||||
],
|
||||
"summary": "根据地图数据新生成计算的link信息",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
},
|
||||
"collectionFormat": "csv",
|
||||
"name": "proto",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"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/drafting/paging": {
|
||||
"get": {
|
||||
"security": [
|
||||
|
@ -1619,60 +1673,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/generate/calculatelink": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"JwtAuth": []
|
||||
}
|
||||
],
|
||||
"description": "根据地图数据新生成计算的link信息",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"GenerateApi"
|
||||
],
|
||||
"summary": "根据地图数据新生成计算的link信息",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
},
|
||||
"collectionFormat": "csv",
|
||||
"name": "proto",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"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/project": {
|
||||
"post": {
|
||||
"security": [
|
||||
|
@ -4238,7 +4238,7 @@
|
|||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.RegisterUser"
|
||||
"$ref": "#/definitions/dto.UserRspDto"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
|
@ -4761,6 +4761,40 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"dto.UserRspDto": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"mobile": {
|
||||
"description": "手机号",
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"description": "名字",
|
||||
"type": "string"
|
||||
},
|
||||
"paths": {
|
||||
"description": "权限路径",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/model.AuthAPIPath"
|
||||
}
|
||||
},
|
||||
"register_time": {
|
||||
"description": "注册时间",
|
||||
"type": "string"
|
||||
},
|
||||
"roles": {
|
||||
"description": "用户角色",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.AuthRoleRspDto"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"graphicData.PictureType": {
|
||||
"type": "integer",
|
||||
"enum": [
|
||||
|
|
|
@ -240,6 +240,30 @@ definitions:
|
|||
total_length:
|
||||
type: integer
|
||||
type: object
|
||||
dto.UserRspDto:
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
mobile:
|
||||
description: 手机号
|
||||
type: string
|
||||
name:
|
||||
description: 名字
|
||||
type: string
|
||||
paths:
|
||||
description: 权限路径
|
||||
items:
|
||||
$ref: '#/definitions/model.AuthAPIPath'
|
||||
type: array
|
||||
register_time:
|
||||
description: 注册时间
|
||||
type: string
|
||||
roles:
|
||||
description: 用户角色
|
||||
items:
|
||||
$ref: '#/definitions/dto.AuthRoleRspDto'
|
||||
type: array
|
||||
type: object
|
||||
graphicData.PictureType:
|
||||
enum:
|
||||
- 0
|
||||
|
@ -1407,6 +1431,40 @@ paths:
|
|||
summary: 草稿另存为
|
||||
tags:
|
||||
- 草稿Api
|
||||
/api/v1/drafting/calculatelink:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 根据地图数据新生成计算的link信息
|
||||
parameters:
|
||||
- collectionFormat: csv
|
||||
in: query
|
||||
items:
|
||||
type: integer
|
||||
name: proto
|
||||
type: array
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
"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: 根据地图数据新生成计算的link信息
|
||||
tags:
|
||||
- 草稿Api
|
||||
/api/v1/drafting/paging:
|
||||
get:
|
||||
consumes:
|
||||
|
@ -1452,40 +1510,6 @@ paths:
|
|||
summary: 分页查询草稿
|
||||
tags:
|
||||
- 草稿Api
|
||||
/api/v1/generate/calculatelink:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 根据地图数据新生成计算的link信息
|
||||
parameters:
|
||||
- collectionFormat: csv
|
||||
in: query
|
||||
items:
|
||||
type: integer
|
||||
name: proto
|
||||
type: array
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
"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: 根据地图数据新生成计算的link信息
|
||||
tags:
|
||||
- GenerateApi
|
||||
/api/v1/project:
|
||||
post:
|
||||
consumes:
|
||||
|
@ -3110,7 +3134,7 @@ paths:
|
|||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/dto.RegisterUser'
|
||||
$ref: '#/definitions/dto.UserRspDto'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
|
|
|
@ -51,7 +51,7 @@ type AuthRoleUserReqDto struct {
|
|||
type AuthRoleType int32
|
||||
|
||||
const (
|
||||
ADMIN AuthRoleType = iota
|
||||
ADMIN AuthRoleType = iota + 1
|
||||
USER
|
||||
)
|
||||
|
||||
|
|
|
@ -22,7 +22,8 @@ type UserRspDto struct {
|
|||
Name string `json:"name" form:"name"` // 名字
|
||||
Mobile string `json:"mobile" form:"mobile"` // 手机号
|
||||
RegisterTime time.Time `json:"register_time" form:"register_time"` // 注册时间
|
||||
Roles []*AuthRoleRspDto `json:"roles" form:"roles"`
|
||||
Roles []*AuthRoleRspDto `json:"roles" form:"roles"` // 用户角色
|
||||
Paths []*model.AuthAPIPath `json:"paths" form:"paths"` // 权限路径
|
||||
}
|
||||
|
||||
func ConvertFromUserDto(u *model.User) *UserRspDto {
|
||||
|
|
1
main.go
1
main.go
|
@ -33,7 +33,6 @@ func main() {
|
|||
api.InitPublishedGiRouter(router, authMiddleware)
|
||||
api.InitSimulationRouter(router, authMiddleware)
|
||||
api.InitCategoryRouter(router, authMiddleware)
|
||||
api.InitGenerateGiRouter(router, authMiddleware)
|
||||
api.InitProjectRouter(router, authMiddleware)
|
||||
api.InitTrainManageRouter(router, authMiddleware)
|
||||
api.InitProjectLinkRouter(router, authMiddleware)
|
||||
|
|
114
service/auth.go
114
service/auth.go
|
@ -58,26 +58,33 @@ func QueryAuthRole(rid int32) *dto.AuthRoleDetailRspDto {
|
|||
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()
|
||||
rsp := &dto.AuthRoleDetailRspDto{
|
||||
Id: role.ID,
|
||||
Name: role.Name,
|
||||
Paths: QueryAuthApiPathByRids([]int32{rid}),
|
||||
}
|
||||
return rsp
|
||||
}
|
||||
|
||||
// 查询用户的角色
|
||||
func QueryAuthRoleByUid(uid int32) []*model.AuthRole {
|
||||
aru := dbquery.AuthRoleUser
|
||||
arus, err1 := aru.Distinct(aru.Rid).Select(aru.Rid).Where(aru.UID.Eq(uid)).Find()
|
||||
if err1 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: err1.Error()})
|
||||
}
|
||||
if len(arus) == 0 {
|
||||
return nil
|
||||
}
|
||||
rids := make([]int32, len(arus))
|
||||
for i, v := range arus {
|
||||
rids[i] = v.Rid
|
||||
}
|
||||
roles, err2 := dbquery.AuthRole.Where(dbquery.AuthRole.ID.In(rids...)).Find()
|
||||
if err2 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: err2.Error()})
|
||||
}
|
||||
pn := len(linkPids)
|
||||
if pn == 0 { // 无关联路径
|
||||
return rsp
|
||||
}
|
||||
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
|
||||
return roles
|
||||
}
|
||||
|
||||
// 编辑角色信息
|
||||
|
@ -114,7 +121,7 @@ func DeleteAuthRole(rid int32) bool {
|
|||
if err1 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err1.Error()})
|
||||
}
|
||||
if dto.IsSystemRole(oldD.Weight) {
|
||||
if dto.IsSystemRole(oldD.ID) {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: "系统角色不可删除"})
|
||||
}
|
||||
// 如果有用户关联则不删除
|
||||
|
@ -176,6 +183,30 @@ func QueryAuthApiPath(id int32) *model.AuthAPIPath {
|
|||
return data
|
||||
}
|
||||
|
||||
// 根据角色ID查询路径信息
|
||||
func QueryAuthApiPathByRids(rids []int32) []*model.AuthAPIPath {
|
||||
if len(rids) == 0 {
|
||||
return nil
|
||||
}
|
||||
linkPids, err2 := dbquery.AuthRoleAPIPath.Distinct(dbquery.AuthRoleAPIPath.Pid).Where(dbquery.AuthRoleAPIPath.Rid.In(rids...)).Find()
|
||||
if err2 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
|
||||
}
|
||||
pn := len(linkPids)
|
||||
if pn == 0 { // 无关联路径
|
||||
return nil
|
||||
}
|
||||
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()})
|
||||
}
|
||||
return apiPaths
|
||||
}
|
||||
|
||||
// 更新接口路径信息
|
||||
func UpdateAuthApiPath(id int32, a *dto.AuthApiPathReqDto) bool {
|
||||
dbqa := dbquery.AuthAPIPath
|
||||
|
@ -232,53 +263,22 @@ func UserLinkRole(linkInfo *dto.AuthRoleUserReqDto) bool {
|
|||
|
||||
// 查询用户权限信息
|
||||
func QueryUserAuthApiPath(uid int32) *dto.AuthUserStorageDto {
|
||||
linkRids, err1 := dbquery.AuthRoleUser.Distinct(dbquery.AuthRoleUser.Rid).Where(dbquery.AuthRoleUser.UID.Eq(uid)).Find()
|
||||
if err1 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err1.Error()})
|
||||
}
|
||||
authUser := &dto.AuthUserStorageDto{UID: uid, IsAdmin: false}
|
||||
rn := len(linkRids) // 查询用户角色
|
||||
roleQuery := dbquery.AuthRole.Where()
|
||||
// 查询用户角色
|
||||
roles := QueryAuthRoleByUid(uid)
|
||||
rn := len(roles)
|
||||
rids := make([]int32, rn+1)
|
||||
if rn > 0 {
|
||||
rids := make([]int32, rn)
|
||||
for i, r := range linkRids {
|
||||
rids[i] = r.Rid
|
||||
}
|
||||
authUser.RoleIds = rids // 用户角色ID
|
||||
roleQuery = roleQuery.Where(dbquery.AuthRole.ID.In(rids...))
|
||||
}
|
||||
// 查询用户角色信息
|
||||
roles, err2 := roleQuery.Or(dbquery.AuthRole.Weight.Eq(int32(dto.USER))).Find()
|
||||
if err2 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataOperationError, Message: err2.Error()})
|
||||
}
|
||||
// 判断是否是管理员
|
||||
rids := make([]int32, len(roles))
|
||||
for i, r := range roles {
|
||||
rids[i] = r.ID
|
||||
authUser.IsAdmin = authUser.IsAdmin || (r.Weight == int32(dto.ADMIN))
|
||||
authUser.IsAdmin = authUser.IsAdmin || (r.ID == int32(dto.ADMIN))
|
||||
}
|
||||
if authUser.IsAdmin { // 管理员直接返回
|
||||
return authUser
|
||||
}
|
||||
// 非管理员时,查询角色权限路径
|
||||
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 {
|
||||
return authUser
|
||||
}
|
||||
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()})
|
||||
}
|
||||
rids[rn] = int32(dto.USER) // 最后添加一个普通用户角色
|
||||
apiPaths := QueryAuthApiPathByRids(rids) // 查询角色拥有的权限路径
|
||||
authUser.AuthPaths = dto.ConvertFromAuthPath(apiPaths) // 赋值路径数组
|
||||
return authUser
|
||||
}
|
||||
|
|
|
@ -53,29 +53,17 @@ func FindUserInfo(userId int32) *dto.UserRspDto {
|
|||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: "没有获取到对应的用户信息"})
|
||||
}
|
||||
rspUser := dto.ConvertFromUserDto(user)
|
||||
// 查找关联关系
|
||||
aru := dbquery.AuthRoleUser
|
||||
arus, err1 := aru.Distinct(aru.Rid).Select(aru.Rid).Where(aru.UID.Eq(user.ID)).Find()
|
||||
if err1 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: err1.Error()})
|
||||
}
|
||||
if len(arus) == 0 {
|
||||
return rspUser
|
||||
}
|
||||
rids := make([]int32, len(arus))
|
||||
for i, v := range arus {
|
||||
rids[i] = v.Rid
|
||||
}
|
||||
roles, err2 := dbquery.AuthRole.Where(dbquery.AuthRole.ID.In(rids...)).Find()
|
||||
if err2 != nil {
|
||||
panic(dto.ErrorDto{Code: dto.DataNotExist, Message: err2.Error()})
|
||||
}
|
||||
roles := QueryAuthRoleByUid(user.ID)
|
||||
if len(roles) == 0 {
|
||||
return rspUser
|
||||
}
|
||||
for _, r := range roles {
|
||||
rids := make([]int32, len(roles))
|
||||
for i, r := range roles {
|
||||
rids[i] = r.ID
|
||||
rspUser.Roles = append(rspUser.Roles, &dto.AuthRoleRspDto{Id: r.ID, Name: r.Name})
|
||||
}
|
||||
// 查询权限路径
|
||||
rspUser.Paths = QueryAuthApiPathByRids(rids)
|
||||
return rspUser
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue