From 30f137e85a76420d872a96c30b2177f59e9706d2 Mon Sep 17 00:00:00 2001 From: wangpengfei <274878379@qq.com> Date: 星期一, 17 七月 2023 16:13:59 +0800 Subject: [PATCH] add --- router/authority.go | 2 service/menu.go | 12 + model/api.go | 12 + model/request/authority.go | 3 api/v1/authority.go | 52 ++-- service/authority.go | 33 +-- go.mod | 14 + pkg/ecode/code.go | 4 docs/swagger.yaml | 76 +++++- model/menu.go | 4 docs/docs.go | 122 +++++++++--- docs/swagger.json | 122 +++++++++--- model/response/response.go | 2 model/followRecord.go | 4 model/authority.go | 17 + model/request/casbin.go | 27 ++ go.sum | 42 ++++ model/user.go | 2 api/v1/user.go | 9 model/index.go | 2 service/casbin.go | 5 router/index.go | 5 api/v1/menu.go | 1 23 files changed, 426 insertions(+), 146 deletions(-) diff --git a/api/v1/authority.go b/api/v1/authority.go index 32a299d..90ab274 100644 --- a/api/v1/authority.go +++ b/api/v1/authority.go @@ -5,12 +5,7 @@ "aps_crm/model/request" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" - "github.com/flipped-aurora/gin-vue-admin/server/global" - "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" - "github.com/flipped-aurora/gin-vue-admin/server/model/system" - "github.com/flipped-aurora/gin-vue-admin/server/utils" "github.com/gin-gonic/gin" - "go.uber.org/zap" ) type AuthorityApi struct{} @@ -38,13 +33,15 @@ return } - errCode = authorityService.CreateAuthority(auth) + errCode, auth.Id = authorityService.CreateAuthority(auth) if errCode != ecode.OK { ctx.Fail(errCode) } - //_ = menuService.AddMenuAuthority(systemReq.DefaultMenu(), authority.AuthorityId) - //_ = casbinService.UpdateCasbin(authority.AuthorityId, systemReq.DefaultCasbin()) + casbinInfos := append(request.DefaultCasbin(), params.CasbinInfos...) + + //_ = menuService.AddMenuAuthority(systemReq.DefaultMenu(), authority.Id) + _ = casbinService.UpdateCasbin(auth.Id, casbinInfos) ctx.Ok() } @@ -141,34 +138,41 @@ // }, "鑾峰彇鎴愬姛", c) //} -// SetDataAuthority +// SetMenuAuthority // // @Tags Authority -// @Summary 璁剧疆瑙掕壊璧勬簮鏉冮檺 +// @Summary 璁剧疆瑙掕壊鑿滃崟 // @Security ApiKeyAuth // @accept application/json // @Produce application/json -// @Param data body request.AddAuthority true "璁剧疆瑙掕壊璧勬簮鏉冮檺" -// @Router /authority/setDataAuthority [post] -func (a *AuthorityApi) SetDataAuthority(c *gin.Context) { - var auth system.SysAuthority - err := c.ShouldBindJSON(&auth) - if err != nil { - response.FailWithMessage(err.Error(), c) +// @Param data body request.SetAuthorityMenu true "璁剧疆瑙掕壊璧勬簮鏉冮檺" +// @Success 200 {object} contextx.Response{} +// @Router /api/authority/setMenuAuthority [post] +func (a *AuthorityApi) SetMenuAuthority(c *gin.Context) { + var params request.SetAuthorityMenu + ctx, ok := contextx.NewContext(c, ¶ms) + if !ok { return } - err = utils.Verify(auth, utils.AuthorityIdVerify) - if err != nil { - response.FailWithMessage(err.Error(), c) + + menus, errCode := menuService.GetMenusByIds(params.Menus) + if errCode != ecode.OK { + ctx.Fail(ecode.MenuListErr) return } - err = authorityService.SetDataAuthority(auth) + + auth := model.Authority{ + Id: params.AuthorityId, + Menus: menus, + } + + err := authorityService.SetMenuAuthority(&auth) if err != nil { - global.GVA_LOG.Error("璁剧疆澶辫触!", zap.Error(err)) - response.FailWithMessage("璁剧疆澶辫触"+err.Error(), c) + ctx.Fail(ecode.SetMenuAuthorityErr) return } - response.OkWithMessage("璁剧疆鎴愬姛", c) + + ctx.Ok() } func checkAuthorityParams(params *request.AddAuthority) (int, model.Authority) { diff --git a/api/v1/menu.go b/api/v1/menu.go index 8604bfa..a5a18a0 100644 --- a/api/v1/menu.go +++ b/api/v1/menu.go @@ -14,6 +14,7 @@ // @Tags Menu // @Summary 鑾峰彇鑿滃崟鏍� // @Security ApiKeyAuth +// @param Authorization header string true "Authorization" // @Produce application/json // @Success 200 {object} contextx.Response{data=response.MenuTreeResponse} // @Router /api/menu/getMenu [get] diff --git a/api/v1/user.go b/api/v1/user.go index baf9e7e..bd53901 100644 --- a/api/v1/user.go +++ b/api/v1/user.go @@ -81,10 +81,11 @@ logx.Infof("TokenNext user:%+v", user) j := &utils.JWT{SigningKey: []byte(conf.Conf.JWT.SigningKey)} // 鍞竴绛惧悕 claims := j.CreateClaims(request.BaseClaims{ - UserId: user.ID, - Username: user.Username, - ParentId: user.ParentName, - UserType: user.UserType, + UserId: user.ID, + Username: user.Username, + ParentId: user.ParentName, + UserType: user.UserType, + AuthorityId: user.AuthorityId, }) token, err := j.CreateToken(claims) if err != nil { diff --git a/docs/docs.go b/docs/docs.go index 63dbcf3..ac27a6c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -54,6 +54,44 @@ } } }, + "/api/authority/setMenuAuthority": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Authority" + ], + "summary": "璁剧疆瑙掕壊鑿滃崟", + "parameters": [ + { + "description": "璁剧疆瑙掕壊璧勬簮鏉冮檺", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SetAuthorityMenu" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/base/captcha": { "post": { "produces": [ @@ -1965,6 +2003,11 @@ }, "/api/menu/getMenu": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "produces": [ "application/json" ], @@ -1972,6 +2015,15 @@ "Menu" ], "summary": "鑾峰彇鑿滃崟鏍�", + "parameters": [ + { + "type": "string", + "description": "Authorization", + "name": "Authorization", + "in": "header", + "required": true + } + ], "responses": { "200": { "description": "OK", @@ -4757,37 +4809,6 @@ } } } - }, - "/authority/setDataAuthority": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Authority" - ], - "summary": "璁剧疆瑙掕壊璧勬簮鏉冮檺", - "parameters": [ - { - "description": "璁剧疆瑙掕壊璧勬簮鏉冮檺", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.AddAuthority" - } - } - ], - "responses": {} - } } }, "definitions": { @@ -5278,11 +5299,17 @@ "model.FollowRecord": { "type": "object", "properties": { + "client": { + "$ref": "#/definitions/model.Client" + }, "client_id": { "type": "integer" }, "client_status_id": { "type": "integer" + }, + "contact": { + "$ref": "#/definitions/model.Contact" }, "contact_id": { "type": "integer" @@ -6103,6 +6130,12 @@ "properties": { "authorityName": { "type": "string" + }, + "casbinInfos": { + "type": "array", + "items": { + "$ref": "#/definitions/request.CasbinInfo" + } } } }, @@ -6898,6 +6931,19 @@ } } }, + "request.CasbinInfo": { + "type": "object", + "properties": { + "method": { + "description": "鏂规硶", + "type": "string" + }, + "path": { + "description": "璺緞", + "type": "string" + } + } + }, "request.ChangePasswordReq": { "type": "object", "properties": { @@ -7383,6 +7429,20 @@ } } }, + "request.SetAuthorityMenu": { + "type": "object", + "properties": { + "authorityId": { + "type": "integer" + }, + "menus": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "request.SetCity": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index aa5e2c0..68f17b6 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -42,6 +42,44 @@ } } }, + "/api/authority/setMenuAuthority": { + "post": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Authority" + ], + "summary": "璁剧疆瑙掕壊鑿滃崟", + "parameters": [ + { + "description": "璁剧疆瑙掕壊璧勬簮鏉冮檺", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/request.SetAuthorityMenu" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/contextx.Response" + } + } + } + } + }, "/api/base/captcha": { "post": { "produces": [ @@ -1953,6 +1991,11 @@ }, "/api/menu/getMenu": { "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], "produces": [ "application/json" ], @@ -1960,6 +2003,15 @@ "Menu" ], "summary": "鑾峰彇鑿滃崟鏍�", + "parameters": [ + { + "type": "string", + "description": "Authorization", + "name": "Authorization", + "in": "header", + "required": true + } + ], "responses": { "200": { "description": "OK", @@ -4745,37 +4797,6 @@ } } } - }, - "/authority/setDataAuthority": { - "post": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Authority" - ], - "summary": "璁剧疆瑙掕壊璧勬簮鏉冮檺", - "parameters": [ - { - "description": "璁剧疆瑙掕壊璧勬簮鏉冮檺", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/request.AddAuthority" - } - } - ], - "responses": {} - } } }, "definitions": { @@ -5266,11 +5287,17 @@ "model.FollowRecord": { "type": "object", "properties": { + "client": { + "$ref": "#/definitions/model.Client" + }, "client_id": { "type": "integer" }, "client_status_id": { "type": "integer" + }, + "contact": { + "$ref": "#/definitions/model.Contact" }, "contact_id": { "type": "integer" @@ -6091,6 +6118,12 @@ "properties": { "authorityName": { "type": "string" + }, + "casbinInfos": { + "type": "array", + "items": { + "$ref": "#/definitions/request.CasbinInfo" + } } } }, @@ -6886,6 +6919,19 @@ } } }, + "request.CasbinInfo": { + "type": "object", + "properties": { + "method": { + "description": "鏂规硶", + "type": "string" + }, + "path": { + "description": "璺緞", + "type": "string" + } + } + }, "request.ChangePasswordReq": { "type": "object", "properties": { @@ -7371,6 +7417,20 @@ } } }, + "request.SetAuthorityMenu": { + "type": "object", + "properties": { + "authorityId": { + "type": "integer" + }, + "menus": { + "type": "array", + "items": { + "type": "integer" + } + } + } + }, "request.SetCity": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 5a70e9f..616f200 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -329,10 +329,14 @@ type: object model.FollowRecord: properties: + client: + $ref: '#/definitions/model.Client' client_id: type: integer client_status_id: type: integer + contact: + $ref: '#/definitions/model.Contact' contact_id: type: integer contact_information_id: @@ -873,6 +877,10 @@ properties: authorityName: type: string + casbinInfos: + items: + $ref: '#/definitions/request.CasbinInfo' + type: array type: object request.AddCity: properties: @@ -1406,6 +1414,15 @@ subOrder: $ref: '#/definitions/request.SubOrder' type: object + request.CasbinInfo: + properties: + method: + description: 鏂规硶 + type: string + path: + description: 璺緞 + type: string + type: object request.ChangePasswordReq: properties: newPassword: @@ -1743,6 +1760,15 @@ type: string status: type: integer + type: object + request.SetAuthorityMenu: + properties: + authorityId: + type: integer + menus: + items: + type: integer + type: array type: object request.SetCity: properties: @@ -2861,6 +2887,29 @@ security: - ApiKeyAuth: [] summary: 鍒涘缓瑙掕壊 + tags: + - Authority + /api/authority/setMenuAuthority: + post: + consumes: + - application/json + parameters: + - description: 璁剧疆瑙掕壊璧勬簮鏉冮檺 + in: body + name: data + required: true + schema: + $ref: '#/definitions/request.SetAuthorityMenu' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/contextx.Response' + security: + - ApiKeyAuth: [] + summary: 璁剧疆瑙掕壊鑿滃崟 tags: - Authority /api/base/captcha: @@ -4033,6 +4082,12 @@ - MasterOrder /api/menu/getMenu: get: + parameters: + - description: Authorization + in: header + name: Authorization + required: true + type: string produces: - application/json responses: @@ -4045,6 +4100,8 @@ data: $ref: '#/definitions/response.MenuTreeResponse' type: object + security: + - ApiKeyAuth: [] summary: 鑾峰彇鑿滃崟鏍� tags: - Menu @@ -5754,23 +5811,4 @@ summary: 璁剧疆鐢ㄦ埛淇℃伅 tags: - User - /authority/setDataAuthority: - post: - consumes: - - application/json - parameters: - - description: 璁剧疆瑙掕壊璧勬簮鏉冮檺 - in: body - name: data - required: true - schema: - $ref: '#/definitions/request.AddAuthority' - produces: - - application/json - responses: {} - security: - - ApiKeyAuth: [] - summary: 璁剧疆瑙掕壊璧勬簮鏉冮檺 - tags: - - Authority swagger: "2.0" diff --git a/go.mod b/go.mod index 0abb619..8681cc6 100644 --- a/go.mod +++ b/go.mod @@ -36,6 +36,8 @@ require ( github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect github.com/KyleBanks/depth v1.2.1 // indirect + github.com/aliyun/aliyun-oss-go-sdk v2.1.6+incompatible // indirect + github.com/aws/aws-sdk-go v1.42.27 // indirect github.com/bytedance/sonic v1.9.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect @@ -63,13 +65,18 @@ github.com/golang-sql/sqlexp v0.1.0 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/golang/protobuf v1.5.3 // indirect + github.com/google/go-querystring v1.0.0 // indirect github.com/google/uuid v1.3.0 // indirect + github.com/gookit/color v1.3.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.8+incompatible // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgx/v5 v5.3.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect + github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect @@ -82,22 +89,28 @@ github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/mozillazg/go-httpheader v0.2.1 // indirect github.com/onsi/gomega v1.27.4 // indirect + github.com/otiai10/copy v1.7.0 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/qiniu/api.v7/v7 v7.4.1 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect + github.com/sashabaranov/go-openai v1.5.7 // indirect github.com/shirou/gopsutil/v3 v3.22.5 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect + github.com/tencentyun/cos-go-sdk-v5 v0.7.19 // indirect github.com/tklauser/go-sysconf v0.3.10 // indirect github.com/tklauser/numcpus v0.4.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect + github.com/unrolled/secure v1.0.7 // indirect github.com/yusufpapurcu/wmi v1.2.2 // indirect go.etcd.io/etcd/api/v3 v3.5.9 // indirect go.uber.org/atomic v1.9.0 // indirect @@ -107,6 +120,7 @@ golang.org/x/net v0.10.0 // indirect golang.org/x/sys v0.9.0 // indirect golang.org/x/text v0.10.0 // indirect + golang.org/x/time v0.1.0 // indirect golang.org/x/tools v0.9.1 // indirect google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect google.golang.org/grpc v1.55.0 // indirect diff --git a/go.sum b/go.sum index 78b302a..e8a4535 100644 --- a/go.sum +++ b/go.sum @@ -50,6 +50,12 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= +github.com/aliyun/aliyun-oss-go-sdk v2.1.6+incompatible h1:Ft+KeWIJxFP76LqgJbvtOA1qBIoC8vGkTV3QeCOeJC4= +github.com/aliyun/aliyun-oss-go-sdk v2.1.6+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8= +github.com/aws/aws-sdk-go v1.42.27 h1:kxsBXQg3ee6LLbqjp5/oUeDgG7TENFrWYDmEVnd7spU= +github.com/aws/aws-sdk-go v1.42.27/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc= +github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f h1:ZNv7On9kyUzm7fvRZumSyy/IUiSC7AzL0I1jKKtwooA= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= @@ -74,6 +80,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/codegangsta/negroni v1.0.0 h1:+aYywywx4bnKXWvoWtRfJ91vC59NbEhEY03sZjQhbVY= +github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= @@ -224,6 +232,8 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -240,12 +250,15 @@ github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= +github.com/gookit/color v1.3.1 h1:PPD/C7sf8u2L8XQPdPgsWRoAiLQGZEZOzU3cf5IYYUk= +github.com/gookit/color v1.3.1/go.mod h1:R3ogXq2B9rTbXoSHJ1HyUVAZ3poOJHpd9nQmyGZsfvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= @@ -256,6 +269,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.8+incompatible h1:3kDd8PIWAdU+qGs/+0QUgsMI2ZSiJPt45Xn0su+x/Q0= +github.com/huaweicloud/huaweicloud-sdk-go-obs v3.21.8+incompatible/go.mod h1:l7VUhRbTKCzdOacdT4oWCwATKyvZqUOlOqr0Ous3k4s= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= @@ -313,6 +328,12 @@ github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84 h1:pS0A6cr4aHYZnYwC7Uw+rwgb39+nzkm2QhwZ+S6Gn5I= +github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -377,11 +398,20 @@ github.com/mojocn/base64Captcha v1.3.5 h1:Qeilr7Ta6eDtG4S+tQuZ5+hO+QHbiGAJdi4PfoagaA0= github.com/mojocn/base64Captcha v1.3.5/go.mod h1:/tTTXn4WTpX9CfrmipqRytCpJ27Uw3G6I7NcP2WwcmY= github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/mozillazg/go-httpheader v0.2.1 h1:geV7TrjbL8KXSyvghnFm+NyTux/hxwueTSrwhe88TQQ= +github.com/mozillazg/go-httpheader v0.2.1/go.mod h1:jJ8xECTlalr6ValeXYdOF8fFUISeBAdw6E61aqQma60= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E= github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3q3fQ= +github.com/otiai10/copy v1.7.0 h1:hVoPiN+t+7d2nzzwMiDHPSOogsWAStewq3TwU05+clE= +github.com/otiai10/copy v1.7.0/go.mod h1:rmRl6QPdJj6EiUqXQ/4Nn2lLXoNQjFCQbbNrxgc/t3U= +github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= +github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= +github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= +github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI= +github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= @@ -397,6 +427,8 @@ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/qiniu/api.v7/v7 v7.4.1 h1:BnNUBimLk6nrA/mIwsww9yJRupmViSsb1ndLMC7a9OY= +github.com/qiniu/api.v7/v7 v7.4.1/go.mod h1:VE5oC5rkE1xul0u1S2N0b2Uxq9/6hZzhyqjgK25XDcM= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= @@ -410,6 +442,9 @@ github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= +github.com/sashabaranov/go-openai v1.5.7 h1:8DGgRG+P7yWixte5j720y6yiXgY3Hlgcd0gcpHdltfo= +github.com/sashabaranov/go-openai v1.5.7/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg= +github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/shirou/gopsutil/v3 v3.22.5 h1:atX36I/IXgFiB81687vSiBI5zrMsxcIBkP9cQMJQoJA= github.com/shirou/gopsutil/v3 v3.22.5/go.mod h1:so9G9VzeHt/hsd0YwqprnjHnfARAUktauykSbr+y2gA= @@ -455,6 +490,8 @@ github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo= github.com/swaggo/swag v1.16.1 h1:fTNRhKstPKxcnoKsytm4sahr8FaYzUcT7i1/3nd/fBg= github.com/swaggo/swag v1.16.1/go.mod h1:9/LMvHycG3NFHfR6LwvikHv5iFvmPADQ359cKikGxto= +github.com/tencentyun/cos-go-sdk-v5 v0.7.19 h1:janAfTO4MglOrUFuKGTQJBuMc66+F7TgtEIt1wPsJ+k= +github.com/tencentyun/cos-go-sdk-v5 v0.7.19/go.mod h1:wQBO5HdAkLjj2q6XQiIfDSP8DXDNrppDRw2Kp/1BODA= github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o= @@ -465,6 +502,8 @@ github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/unrolled/secure v1.0.7 h1:BcQHp3iKZyZCKj5gRqwQG+5urnGBF00wGgoPPwtheVQ= +github.com/unrolled/secure v1.0.7/go.mod h1:uGc1OcRF8gCVBA+ANksKmvM85Hka6SZtQIbrKc3sHS4= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -607,6 +646,7 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= @@ -723,6 +763,8 @@ golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.1.0 h1:xYY+Bajn2a7VBmTM5GikTmnK8ZuX8YgnQCqZpbBNtmA= +golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= diff --git a/model/api.go b/model/api.go new file mode 100644 index 0000000..b305fc8 --- /dev/null +++ b/model/api.go @@ -0,0 +1,12 @@ +package model + +type Api struct { + Id uint `json:"id" gorm:"column:id;autoIncrement;not null;unique;primary_key;comment:瑙掕壊ID;size:90"` // 瑙掕壊ID + Path string `json:"path" gorm:"comment:api璺緞"` // api璺緞 + Description string `json:"description" gorm:"comment:api涓枃鎻忚堪"` // api涓枃鎻忚堪 + Method string `json:"method" gorm:"default:POST;comment:鏂规硶"` // 鏂规硶:鍒涘缓POST(榛樿)|鏌ョ湅GET|鏇存柊PUT|鍒犻櫎DELETE +} + +func (Api) TableName() string { + return "apis" +} diff --git a/model/authority.go b/model/authority.go index b05889b..7de6325 100644 --- a/model/authority.go +++ b/model/authority.go @@ -7,8 +7,8 @@ type ( Authority struct { - AuthorityId uint `json:"authorityId" gorm:"not null;unique;primary_key;comment:瑙掕壊ID;size:90"` // 瑙掕壊ID - AuthorityName string `json:"authorityName" gorm:"comment:瑙掕壊鍚�"` // 瑙掕壊鍚� + Id uint `json:"id" gorm:"column:id;autoIncrement;not null;unique;primary_key;comment:瑙掕壊ID;size:90"` // 瑙掕壊ID + AuthorityName string `json:"authorityName" gorm:"comment:瑙掕壊鍚�"` // 瑙掕壊鍚� Users []User `json:"-" gorm:"many2many:user_authority;"` Menus []Menu `json:"menus" gorm:"many2many:authority_menus;"` DefaultRouter string `json:"defaultRouter" gorm:"comment:榛樿鑿滃崟;default:dashboard"` // 榛樿鑿滃崟(榛樿dashboard) @@ -22,7 +22,7 @@ ) func (Authority) TableName() string { - return "sys_authorities" + return "authorities" } func NewSysAuthoritySearch() *SysAuthoritySearch { @@ -33,8 +33,8 @@ func (slf *SysAuthoritySearch) build() *gorm.DB { var db = slf.Orm.Model(&Authority{}) - if slf.AuthorityId != 0 { - db = db.Where("authority_id = ?", slf.AuthorityId) + if slf.Id != 0 { + db = db.Where("id = ?", slf.Id) } return db @@ -62,6 +62,11 @@ } func (slf *SysAuthoritySearch) SetAuthorityId(id uint) *SysAuthoritySearch { - slf.AuthorityId = id + slf.Id = id return slf } + +func (slf *SysAuthoritySearch) SetMenuAuthority(auth *Authority) error { + var db = slf.build() + return db.Model(auth).Association("Menus").Append(auth.Menus) +} diff --git a/model/followRecord.go b/model/followRecord.go index d77a034..29123cd 100644 --- a/model/followRecord.go +++ b/model/followRecord.go @@ -23,6 +23,8 @@ NextFollowTime time.Time `json:"next_follow_time" gorm:"column:next_follow_time;type:datetime;comment:涓嬫璺熻繘鏃堕棿"` Purpose string `json:"purpose" gorm:"column:purpose;type:varchar(255);comment:璺熻繘鐩殑"` Content string `json:"content" gorm:"column:content;type:MEDIUMTEXT;comment:璺熻繘鍐呭"` + Client Client `json:"client" gorm:"foreignKey:ClientId"` + Contact Contact `json:"contact" gorm:"foreignKey:ContactId"` gorm.Model `json:"-"` } @@ -101,7 +103,7 @@ func (slf *FollowRecordSearch) Find() ([]*FollowRecord, error) { var records = make([]*FollowRecord, 0) - err := slf.build().Find(&records).Error + err := slf.build().Preload("Client").Preload("Contact").Find(&records).Error return records, err } diff --git a/model/index.go b/model/index.go index e1495ff..00b8544 100644 --- a/model/index.go +++ b/model/index.go @@ -60,6 +60,8 @@ ServiceFollowup{}, CustomerServiceSheet{}, ServiceFeeManage{}, + Authority{}, + Api{}, ) return err } diff --git a/model/menu.go b/model/menu.go index 715f476..a81cf75 100644 --- a/model/menu.go +++ b/model/menu.go @@ -247,9 +247,9 @@ return records, nil } -func (slf *MenuSearch) FindAll() ([]*Menu, error) { +func (slf *MenuSearch) FindAll() ([]Menu, error) { var ( - records = make([]*Menu, 0) + records = make([]Menu, 0) db = slf.build() ) diff --git a/model/request/authority.go b/model/request/authority.go index 287f7b6..678ca34 100644 --- a/model/request/authority.go +++ b/model/request/authority.go @@ -1,7 +1,8 @@ package request type AddAuthority struct { - AuthorityName string `json:"authorityName"` + AuthorityName string `json:"authorityName"` + CasbinInfos []CasbinInfo `json:"casbinInfos"` } type SetAuthorityMenu struct { diff --git a/model/request/casbin.go b/model/request/casbin.go new file mode 100644 index 0000000..e4d2a49 --- /dev/null +++ b/model/request/casbin.go @@ -0,0 +1,27 @@ +package request + +// Casbin info structure +type CasbinInfo struct { + Path string `json:"path"` // 璺緞 + Method string `json:"method"` // 鏂规硶 +} + +// Casbin structure for input parameters +type CasbinInReceive struct { + AuthorityId uint `json:"authorityId"` // 鏉冮檺id + CasbinInfos []CasbinInfo `json:"casbinInfos"` +} + +func DefaultCasbin() []CasbinInfo { + return []CasbinInfo{ + {Path: "/menu/getMenu", Method: "POST"}, + {Path: "/jwt/jsonInBlacklist", Method: "POST"}, + {Path: "/base/login", Method: "POST"}, + {Path: "/user/admin_register", Method: "POST"}, + {Path: "/user/changePassword", Method: "POST"}, + {Path: "/user/setUserAuthority", Method: "POST"}, + {Path: "/user/setUserInfo", Method: "PUT"}, + {Path: "/user/getUserInfo", Method: "GET"}, + {Path: "/city/list", Method: "GET"}, + } +} diff --git a/model/response/response.go b/model/response/response.go index 08d86e3..b10d79a 100644 --- a/model/response/response.go +++ b/model/response/response.go @@ -175,6 +175,6 @@ } MenuTreeResponse struct { - List []*model.Menu `json:"list"` + List []model.Menu `json:"list"` } ) diff --git a/model/user.go b/model/user.go index 411cc42..529e9bd 100644 --- a/model/user.go +++ b/model/user.go @@ -34,6 +34,8 @@ Ip string `json:"ip" gorm:"type:varchar(255);comment:闆嗙兢Ip"` Port string `json:"port" gorm:"type:varchar(255);comment:绔彛鍙�"` Status int `json:"status" gorm:"type:int(11);comment:鐢ㄦ埛瀹℃牳鐘舵�� 0:绂佺敤; 1:姝e父; 2:瀹℃牳涓�"` + AuthorityId uint `json:"authorityId" gorm:"default:888;comment:鐢ㄦ埛瑙掕壊ID"` // 鐢ㄦ埛瑙掕壊ID + Authority Authority `json:"authority" gorm:"foreignKey:AuthorityId"` } UserSearch struct { diff --git a/pkg/ecode/code.go b/pkg/ecode/code.go index cc8acc3..e6f7145 100644 --- a/pkg/ecode/code.go +++ b/pkg/ecode/code.go @@ -276,5 +276,7 @@ RoleDeleteErr = 3800006 // 鍒犻櫎瑙掕壊澶辫触 RoleDeleteErr1 = 3800007 // 璇ヨ鑹蹭笅瀛樺湪鐢ㄦ埛锛屾棤娉曞垹闄� - MenuListErr = 3900001 // 鑾峰彇鑿滃崟鍒楄〃澶辫触 + MenuListErr = 3900001 // 鑾峰彇鑿滃崟鍒楄〃澶辫触 + SetMenuAuthorityErr = 3900002 // 璁剧疆鑿滃崟鏉冮檺澶辫触 + ) diff --git a/router/authority.go b/router/authority.go index 64f8160..269fc5c 100644 --- a/router/authority.go +++ b/router/authority.go @@ -15,7 +15,7 @@ //authorityRouter.DELETE("delete", authorityApi.Delete) // 鍒犻櫎瑙掕壊 //authorityRouter.PUT("update", authorityApi.Update) // 鏇存柊瑙掕壊 //authorityRouter.POST("getAuthorityList", authorityApi.GetAuthorityList) // 鑾峰彇瑙掕壊鍒楄〃 - authorityRouter.POST("setDataAuthority", authorityApi.SetDataAuthority) // 璁剧疆瑙掕壊璧勬簮鏉冮檺 + authorityRouter.POST("setMenuAuthority", authorityApi.SetMenuAuthority) // 璁剧疆瑙掕壊璧勬簮鏉冮檺 //authorityRouter.POST("getAuthorityId", authorityApi.GetAuthorityId) // 鑾峰彇鎸囧畾瑙掕壊鏉冮檺 } } diff --git a/router/index.go b/router/index.go index 86e30e3..16abfb3 100644 --- a/router/index.go +++ b/router/index.go @@ -3,6 +3,7 @@ import ( "aps_crm/conf" _ "aps_crm/docs" + "aps_crm/middleware" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" @@ -79,7 +80,9 @@ } PrivateGroup := Router.Group("api") - //PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) + PrivateGroup.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) + //PrivateGroup.Use(middleware.JWTAuth()) + //PrivateGroup.Use(middleware.CasbinHandler()) { routerGroup.InitJwtRouter(PrivateGroup) // jwt鐩稿叧璺敱 routerGroup.InitUserRouter(PrivateGroup) // 娉ㄥ唽鐢ㄦ埛璺敱 diff --git a/service/authority.go b/service/authority.go index b2aefb2..b4cdb92 100644 --- a/service/authority.go +++ b/service/authority.go @@ -5,7 +5,6 @@ "aps_crm/pkg/ecode" "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/system" - "gorm.io/gorm" "strconv" ) @@ -13,33 +12,30 @@ var AuthorityServiceApp = new(AuthorityService) -func (authorityService *AuthorityService) CreateAuthority(auth model.Authority) int { - _, err := model.NewSysAuthoritySearch().SetAuthorityId(auth.AuthorityId).Find() - if err != gorm.ErrRecordNotFound { - return ecode.RoleExist - } - - err = model.NewSysAuthoritySearch().Create(&auth) +// CreateAuthority create authority and return authority id and error code +func (authorityService *AuthorityService) CreateAuthority(auth model.Authority) (int, uint) { + // check if authority name exists + err := model.NewSysAuthoritySearch().Create(&auth) if err != nil { - return ecode.SubOrderExist + return ecode.RoleExist, 0 } - return ecode.OK + return ecode.OK, auth.Id } func (authorityService *AuthorityService) UpdateAuthority(auth model.Authority) int { - _, err := model.NewSysAuthoritySearch().SetAuthorityId(auth.AuthorityId).Find() + _, err := model.NewSysAuthoritySearch().SetAuthorityId(auth.Id).Find() if err != nil { return ecode.RoleNotExist } - err = model.NewSysAuthoritySearch().SetAuthorityId(auth.AuthorityId).Update(&auth) + err = model.NewSysAuthoritySearch().SetAuthorityId(auth.Id).Update(&auth) return ecode.OK } func (authorityService *AuthorityService) DeleteAuthority(auth *model.Authority) int { - _, err := model.NewSysAuthoritySearch().SetAuthorityId(auth.AuthorityId).Find() + _, err := model.NewSysAuthoritySearch().SetAuthorityId(auth.Id).Find() if err != nil { return ecode.RoleNotExist } @@ -48,7 +44,7 @@ return ecode.RoleDeleteErr1 } - authorityId := strconv.Itoa(int(auth.AuthorityId)) + authorityId := strconv.Itoa(int(auth.Id)) CasbinServiceApp.ClearCasbin(0, authorityId) return ecode.OK } @@ -65,7 +61,7 @@ } //@author: [piexlmax](https://github.com/piexlmax) -//@function: SetDataAuthority +//@function: SetMenuAuthority //@description: 璁剧疆瑙掕壊璧勬簮鏉冮檺 //@param: auth model.Authority //@return: error @@ -83,9 +79,6 @@ //@param: auth *model.Authority //@return: error -func (authorityService *AuthorityService) SetMenuAuthority(auth *system.SysAuthority) error { - var s system.SysAuthority - global.GVA_DB.Preload("SysBaseMenus").First(&s, "authority_id = ?", auth.AuthorityId) - err := global.GVA_DB.Model(&s).Association("SysBaseMenus").Replace(&auth.SysBaseMenus) - return err +func (authorityService *AuthorityService) SetMenuAuthority(auth *model.Authority) error { + return model.NewSysAuthoritySearch().SetMenuAuthority(auth) } diff --git a/service/casbin.go b/service/casbin.go index 38ec1d0..585de73 100644 --- a/service/casbin.go +++ b/service/casbin.go @@ -1,9 +1,10 @@ package service import ( + "aps_crm/model/request" + "aps_crm/pkg/mysqlx" "errors" "github.com/flipped-aurora/gin-vue-admin/server/global" - "github.com/flipped-aurora/gin-vue-admin/server/model/system/request" "strconv" "sync" @@ -101,7 +102,7 @@ func (casbinService *CasbinService) Casbin() *casbin.SyncedCachedEnforcer { once.Do(func() { - a, err := gormadapter.NewAdapterByDB(global.GVA_DB) + a, err := gormadapter.NewAdapterByDB(mysqlx.GetDB()) if err != nil { zap.L().Error("閫傞厤鏁版嵁搴撳け璐ヨ妫�鏌asbin琛ㄦ槸鍚︿负InnoDB寮曟搸!", zap.Error(err)) return diff --git a/service/menu.go b/service/menu.go index 3f11055..42e71a2 100644 --- a/service/menu.go +++ b/service/menu.go @@ -7,7 +7,7 @@ type MenuService struct{} -func (MenuService) GetMenuTree() ([]*model.Menu, int) { +func (MenuService) GetMenuTree() ([]model.Menu, int) { list, err := model.NewMenuSearch(nil).FindAll() if err != nil { return nil, ecode.MenuListErr @@ -15,3 +15,13 @@ return list, ecode.OK } + +// GetMenusByIds get menus by ids +func (MenuService) GetMenusByIds(ids []uint) ([]model.Menu, int) { + list, err := model.NewMenuSearch(nil).SetIds(ids).FindAll() + if err != nil { + return nil, ecode.MenuListErr + } + + return list, ecode.OK +} -- Gitblit v1.8.0