houyaf 3 anos atrás
pai
commit
96f8397bb6

+ 0 - 12
pkg/app/controller/app_controller.go

@@ -18,7 +18,6 @@ func (c *AppController) BeforeActivation(b mvc.BeforeActivation) {
 	b.Handle("POST", "/add", "Create")
 	b.Handle("PUT", "/update", "Update")
 	b.Handle("DELETE", "/{appId:int64}", "DeleteByID")
-	b.Handle("GET", "/user/permit", "GetPermit")
 }
 
 func (c *AppController) GetList() *JsonResult {
@@ -96,14 +95,3 @@ func (c *AppController) DeleteByID(appId int64) *JsonResult {
 		return ResultOk("删除成功", nil)
 	}
 }
-
-func (c *AppController) GetPermit() *JsonResult {
-	roleId := c.GetCurUserRoleId()
-	appKey := c.GetAppKey()
-	data, err := c.Service.GetPermit(roleId, appKey)
-	if err != nil {
-		return ResultErr(err.Error(), nil)
-	} else {
-		return ResultOk("获取成功", data)
-	}
-}

+ 0 - 9
pkg/app/service/app_service.go

@@ -15,7 +15,6 @@ type AppService interface {
 	Create(d *datamodel.App) error
 	Update(d *datamodel.App) error
 	Delete(m map[string]interface{}) error
-	GetPermit(roleId int64, appKey string) ([]viewmodel.AppPermitInfo, error)
 }
 
 type appService struct {
@@ -26,7 +25,6 @@ type appService struct {
 func NewAppService() AppService {
 	return &appService{
 		appRepo:       repository.NewAppRepo(datasource.InstanceMaster()),
-		appPermitRepo: repository.NewAppPermitRepo(datasource.InstanceMaster()),
 	}
 }
 
@@ -54,10 +52,3 @@ func (s *appService) Update(App *datamodel.App) error {
 func (s *appService) Delete(m map[string]interface{}) error {
 	return s.appRepo.Delete(m)
 }
-
-func (s *appService) GetPermit(roleId int64, appKey string) ([]viewmodel.AppPermitInfo, error) {
-	m := make(map[string]interface{}, 0)
-	m["appKey"] = appKey
-	m["roleId"] = roleId
-	return s.appPermitRepo.GetList(m)
-}

+ 9 - 0
pkg/system/controller/base.go

@@ -102,6 +102,15 @@ func (b *Base) GetAppSecret() string {
 	return appSecret
 }
 
+func (b *Base) GetCurUserRoleId() int64 {
+	userId, _ := b.Ctx.Values().GetInt64("userId")
+	userData := GetCurUser(userId)
+	if userData != nil {
+		return userData.RoleId
+	}
+	return 0
+}
+
 func (b *Base) GetJsonData() (map[string]interface{}, error) {
 	data, err := io.ReadAll(b.Ctx.Request().Body)
 	if err != nil {

+ 14 - 0
pkg/system/controller/user_controller.go

@@ -26,6 +26,7 @@ func (c *UserController) BeforeActivation(b mvc.BeforeActivation) {
 	b.Handle("GET", "/IsStaffNoExist/{staffNo: string}", "IsStaffNoExist")
 	b.Handle("GET", "/IsEmailExist/{email: string}", "IsEmailExist")
 	b.Handle("GET", "/select", "SelectUser")
+	b.Handle("GET", "/permit", "GetPermit")
 }
 
 func (c *UserController) GetPage() *JsonResult {
@@ -202,3 +203,16 @@ func (c *UserController) SelectUser() *JsonResult {
 		return ResultOk("获取成功", data)
 	}
 }
+
+
+func (c *UserController) GetPermit() *JsonResult {
+	roleId := c.GetCurUserRoleId()
+	appKey := c.GetAppKey()
+	data, err := c.Service.GetPermit(roleId, appKey)
+	if err != nil {
+		return ResultErr(err.Error(), nil)
+	} else {
+		return ResultOk("获取成功", data)
+	}
+}
+

+ 13 - 0
pkg/system/service/user_service.go

@@ -4,6 +4,8 @@ import (
 	"time"
 	"xps/cmd/constant"
 	"xps/cmd/datasource"
+	appRepo "xps/pkg/app/repository"
+	appViewModel "xps/pkg/app/viewmodel"
 	"xps/pkg/base"
 	"xps/pkg/system/datamodel"
 	"xps/pkg/system/repository"
@@ -26,6 +28,8 @@ type UserService interface {
 	IsStaffNoExist(ocId int64, staffNo string) (bool, error)
 	IsEmailExist(ocId int64, staffNo string) (bool, error)
 	SelectUser(ocId int64) ([]viewmodel.UserSelectVo, error)
+	GetPermit(roleId int64, appKey string) ([]appViewModel.AppPermitInfo, error)
+	
 }
 
 type userService struct {
@@ -35,6 +39,7 @@ type userService struct {
 	groupRepo               *repository.GroupRepo
 	groupMemberRepo         *repository.GroupMemberRepo
 	groupMemberPositionRepo *repository.GroupMemberPositionRepo
+	appPermitRepo           *appRepo.AppPermitRepo
 }
 
 func NewUserService() UserService {
@@ -45,6 +50,7 @@ func NewUserService() UserService {
 		groupRepo:               repository.NewGroupRepo(datasource.InstanceMaster()),
 		groupMemberRepo:         repository.NewGroupMemberRepo(datasource.InstanceMaster()),
 		groupMemberPositionRepo: repository.NewGroupMemberPositionRepo(datasource.InstanceMaster()),
+		appPermitRepo:           appRepo.NewAppPermitRepo(datasource.InstanceMaster()),
 	}
 }
 
@@ -302,3 +308,10 @@ func (s *userService) SelectUser(ocId int64) ([]viewmodel.UserSelectVo, error) {
 
 	return voList, nil
 }
+
+func (s *userService) GetPermit(roleId int64, appKey string) ([]appViewModel.AppPermitInfo, error) {
+	m := make(map[string]interface{}, 0)
+	m["appKey"] = appKey
+	m["roleId"] = roleId
+	return s.appPermitRepo.GetList(m)
+}