houyaf пре 3 година
родитељ
комит
439494d1af

+ 32 - 1
repositories/system/app_permit_repo.go

@@ -17,7 +17,7 @@ func NewAppPermitRepo(engine *xorm.Engine) *AppPermitRepo {
 	}
 }
 
-func (d *AppPermitRepo) GetByList(m map[string]interface{})([]viewmodels.AppPermitInfo, error) {
+func (d *AppPermitRepo) GetList(m map[string]interface{})([]viewmodels.AppPermitInfo, error) {
 	roleId    := m["roleId"].(int64)
 	keywords  := m["keywords"].(string)
 	appKey    := m["appKey"].(string)
@@ -56,6 +56,37 @@ func (d *AppPermitRepo) GetByList(m map[string]interface{})([]viewmodels.AppPerm
 	}
 }
 
+func (d *AppPermitRepo) GetListByKey(appKey string, roleId int64)([]viewmodels.AppPermitInfo, error) {
+	sqlSelect := ` SELECT A.app_id,
+                          A.role_id,
+                          A.permit_id,
+                          A.permit_title,
+                          A.permit_code,
+                          A.permit_desc,
+                          A.permit_type,
+                          A.root_id,
+                          A.parent_id,
+                          A.sort_no     `
+	sqlFrom   := ` FROM  app_permit  AS A
+                   JOIN  app         AS B ON (A.app_id = B.app_id) `
+	sqlWhere  := ` WHERE A.deleted_flag = 0 `
+	if appKey != "" {
+		sqlWhere += ` AND B.app_key = '` + appKey + "'"
+	}
+	if roleId >= 0 {
+		sqlWhere += ` AND A.role_id = ` + fmt.Sprintf("%d", roleId)
+	}
+	sqlOrderBy := " ORDER BY A.app_id, A.role_id, A.parent_id, A.sort_no "
+	
+	datalist := make([]viewmodels.AppPermitInfo, 0)
+	err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy).Find(&datalist)
+	if err != nil {
+		return nil, err
+	} else {
+		return datalist, nil
+	}
+}
+
 func (d *AppPermitRepo) GetById(appId, roleId, permitId int64)(*viewmodels.AppPermitInfo, error) {
 	sqlSelect := ` SELECT A.app_id,
                           A.role_id,

+ 3 - 3
service/system/app_permit_service.go

@@ -8,7 +8,7 @@ import (
 )
 
 type AppPermitService interface {
-	GetByList(m map[string]interface{})([]viewmodels.AppPermitInfo, error)
+	GetList(m map[string]interface{})([]viewmodels.AppPermitInfo, error)
 	GetById(appId, roleId, permitId int64) (*viewmodels.AppPermitInfo, error)
 	Create(permit *datamodels.AppPermit) error
 	Update(permit *datamodels.AppPermit) error
@@ -25,8 +25,8 @@ func NewAppPermitService() AppPermitService {
 	}
 }
 
-func (s *appPermitService) GetByList(m map[string]interface{})([]viewmodels.AppPermitInfo, error) {
-	return s.repo.GetByList(m)
+func (s *appPermitService) GetList(m map[string]interface{})([]viewmodels.AppPermitInfo, error) {
+	return s.repo.GetList(m)
 }
 
 func (s *appPermitService) GetById(appId, roleId, permitId int64) (*viewmodels.AppPermitInfo, error) {

+ 8 - 12
web/controllers/app_permit_controller.go

@@ -12,19 +12,19 @@ type AppPermitController struct {
 }
 
 func (c *AppPermitController) BeforeActivation(b mvc.BeforeActivation) {
-	b.Handle("GET",     "/",                                                "GetByList" )
+	b.Handle("GET",     "/{appId:int64}/{roleId:int64}",                    "GetList" )
 	b.Handle("GET",     "/{appId:int64}/{roleId:int64}/{permitId:int64}",   "GetById"   )
 	b.Handle("POST",    "/add",                                             "Create"    )
 	b.Handle("PUT",     "/update",                                          "Update"    )
 	b.Handle("DELETE",  "/{appId:int64}/{roleId:int64}/{permitId:int64}",   "DeleteByID")
 }
 
-func (c *AppPermitController) GetByList() *JsonResult {
-	appKey := c.Ctx.URLParamDefault("appKey", "")
- 
+func (c *AppPermitController) GetList(appId, roleId int64) *JsonResult {
 	params := c.buildParams()
-	params["appKey"] = appKey
-	data, err := c.Service.GetByList(params)
+	params["appId"]  = appId
+	params["roleId"] = roleId
+
+	data, err := c.Service.GetList(params)
 	if err != nil {
 		return ResultErr(err.Error(), nil)
 	} else {
@@ -32,7 +32,6 @@ func (c *AppPermitController) GetByList() *JsonResult {
 	}
 }
 
-
 func (c *AppPermitController) GetById(appId, roleId, permitId int64) *JsonResult {
 	data, err := c.Service.GetById(appId, roleId, permitId)
 	if err != nil {
@@ -43,8 +42,7 @@ func (c *AppPermitController) GetById(appId, roleId, permitId int64) *JsonResult
 }
 
 func (c *AppPermitController) Create() *JsonResult {
-	userId   := c.GetCurUserId()
-	
+	userId    := c.GetCurUserId()
 	appPermit := datamodels.AppPermit{}
 	appPermit.CreatedBy = userId
 	err := c.Ctx.ReadJSON(&appPermit)
@@ -61,8 +59,7 @@ func (c *AppPermitController) Create() *JsonResult {
 }
 
 func (c *AppPermitController) Update() *JsonResult {
-	userId   := c.GetCurUserId()
-	
+	userId    := c.GetCurUserId()
 	appPermit := datamodels.AppPermit{}
 	if err := c.Ctx.ReadJSON(&appPermit); err != nil {
 		return ResultErr("读取数据失败", nil)
@@ -79,7 +76,6 @@ func (c *AppPermitController) Update() *JsonResult {
 
 func (c *AppPermitController) DeleteByID(appId, roleId, permitId int64) *JsonResult {
 	userId := c.GetCurUserId()
-	
 	m  := make(map[string]interface{})
 	m["appId"]     = appId
 	m["roleId"]    = roleId

+ 1 - 1
web/router/routes.go

@@ -13,7 +13,7 @@ import (
 
 func Configure(b *bootstrap.Bootstrapper) {
 	crs := cors.New(cors.Options{
-		AllowedOrigins:   []string{"*"}, // allows everything, use that to change the hosts.
+		AllowedOrigins:   []string{"*"},
 		AllowedMethods:   []string{"PUT", "PATCH", "GET", "POST", "OPTIONS", "DELETE"},
 		AllowedHeaders:   []string{"*"},
 		ExposedHeaders:   []string{"Accept", "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization"},