houyaf пре 3 година
родитељ
комит
8f7738da3e

+ 32 - 0
repositories/group_repo.go

@@ -88,6 +88,38 @@ func (d *GroupRepo) GetList(m map[string]interface{})([]viewmodels.GroupInfo, er
     return datalist, nil
 }
 
+func (d *GroupRepo) GetAll(ocId int64)([]viewmodels.GroupInfo, error) {
+    sqlSelect := ` SELECT A.oc_id,
+                          A.group_id ,
+                          A.group_name,
+                          A.group_cat_id,
+                          B.group_cat_title,
+                          A.group_code,
+                          A.group_select,
+                          A.group_path,
+                          A.group_desc,
+                          A.root_id,
+                          A.parent_id,
+                          C.group_name as parent_name,
+                          A.node_left,
+                          A.node_right,
+                          A.node_level,
+                          A.is_leaf,
+                          A.is_fixed           `
+    sqlFrom  := ` FROM       s_group      AS A
+                  LEFT JOIN  s_group_cat  AS B ON (A.oc_id = B.oc_id AND A.group_cat_id     = B.group_cat_id)
+                  LEFT JOIN  s_group      AS C ON (A.oc_id = C.oc_id AND A.parent_id  = C.group_id )`
+    
+    sqlWhere := ` WHERE A.deleted_flag = 0 and A.oc_id = ` + fmt.Sprintf("%d" ,ocId)
+   
+    datalist := make([]viewmodels.GroupInfo, 0)
+    err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere).OrderBy("group_id ASC").Find(&datalist)
+    if err != nil{
+        return nil, err
+    }
+    return datalist, nil
+}
+
 func (d *GroupRepo) Delete(m map[string]interface{}) error {
     ocId       := m["ocId"].(int64)
     groupId    := m["groupId"].(int64)

+ 26 - 0
repositories/model_object_repo.go

@@ -82,7 +82,32 @@ func (d *ModelObjectRepo) GetAll() ([]viewmodels.ModelObjectInfo, error) {
                               B.model_title      `
 	sqlFrom    := ` FROM      ds_object  AS A
                     LEFT JOIN ds_model   AS B ON (A.model_id = B.model_id)  `
+	sqlWhere   := ` WHERE A.deleted_flag = 0  `
+	sqlOrderBy := " ORDER BY A.model_id, A.object_id "
+	
+	datalist := make([]viewmodels.ModelObjectInfo, 0)
+	err := d.engine.SQL(sqlSelect + sqlFrom + sqlWhere + sqlOrderBy).Find(&datalist)
+	if err != nil {
+		return nil, err
+	} else {
+		return datalist, nil
+	}
+}
+
+func (d *ModelObjectRepo) SelectForBizObjectMapping(modelId, targetBizId, targetObjectId int64)([]viewmodels.ModelObjectInfo, error) {
+	sqlSelect  := ` SELECT    A.*,
+                              B.model_title      `
+	sqlFrom    := ` FROM      ds_object  AS A
+                    LEFT JOIN ds_model   AS B ON (A.model_id = B.model_id)  `
 	sqlWhere   := ` WHERE A.deleted_flag = 0 `
+	sqlWhere   += ` AND NOT EXISTS (
+                        SELECT *
+						FROM  biz_object_mapping  AS M
+						WHERE A.model_id = M.mapping_model_id AND A.object_id = M.mapping_object_id`
+	sqlWhere   += fmt.Sprintf(" AND M.biz_id    = %d ", targetBizId)
+	sqlWhere   += fmt.Sprintf(" AND M.object_id = %d ", targetObjectId)
+	sqlWhere   +=  ` )  `
+	sqlWhere   += fmt.Sprintf(" AND A.model_id = %d ", modelId)
 	sqlOrderBy := " ORDER BY A.model_id, A.object_id "
 	
 	datalist := make([]viewmodels.ModelObjectInfo, 0)
@@ -94,6 +119,7 @@ func (d *ModelObjectRepo) GetAll() ([]viewmodels.ModelObjectInfo, error) {
 	}
 }
 
+
 func (d *ModelObjectRepo) GetById(modelId, objectId int64) (*viewmodels.ModelObjectInfo, error) {
 	sqlSelect := ` SELECT A.*,
                           B.model_title      `

+ 23 - 21
repositories/user_repo.go

@@ -18,7 +18,7 @@ func NewUserRepo(engine *xorm.Engine) *UserRepo {
     }
 }
 
-func (d *UserRepo) GetById(ocId int64, userId int64)(*viewmodels.UserInfo, error){
+func (d *UserRepo) GetById(ocId, groupId, userId int64)(*viewmodels.UserInfo, error){
     sqlSelect := ` SELECT   A.gm_id,
                             A.oc_id,
                             A.group_id,
@@ -42,14 +42,16 @@ func (d *UserRepo) GetById(ocId int64, userId int64)(*viewmodels.UserInfo, error
                             F.gmpg_id,
                             F.grant_group_id,
                             G.group_name  AS grant_group_name  `
-    sqlFrom := `  FROM  s_group_member                        AS  A
-                  LEFT  JOIN account                          AS  B  ON ( A.oc_id = B.oc_id AND A.account_id  = B.account_id  )
-                  LEFT  JOIN s_group                          AS  C  ON ( A.oc_id = C.oc_id AND A.group_id    = C.group_id )
-                  LEFT  JOIN s_group_member_position          AS  E  ON ( A.oc_id = E.oc_id AND A.account_id  = E.account_id AND E.group_id= #{groupId ,jdbcType=BIGINT} )
-                  LEFT  JOIN s_group_member_position_grant    AS  F  ON ( E.oc_id = F.oc_id AND E.account_id  = F.account_id AND E.position_id = F.position_id  AND F.group_id = #{groupId ,jdbcType=BIGINT} )
-                  LEFT  JOIN s_group                          AS  G  ON ( G.oc_id = F.oc_id AND G.group_id    = F.grant_group_id )
-                  LEFT  JOIN s_position                       AS  H  ON ( A.oc_id = E.oc_id AND H.position_id = E.position_id    ) `
-    sqlWhere := ` WHERE B.deleted_flag = 0 AND A.oc_id      = ` + fmt.Sprintf("%d", ocId)
+    sqlFrom := `  FROM  s_group_member                        AS  A `
+    sqlFrom += `   LEFT  JOIN account                          AS  B  ON ( A.oc_id = B.oc_id AND A.account_id  = B.account_id  ) `
+    sqlFrom += `   LEFT  JOIN s_group                          AS  C  ON ( A.oc_id = C.oc_id AND A.group_id    = C.group_id )    `
+    sqlFrom += fmt.Sprintf(`   LEFT  JOIN s_group_member_position          AS  E  ON ( A.oc_id = E.oc_id AND A.account_id  = E.account_id AND E.group_id= %d )`, groupId)
+    sqlFrom += fmt.Sprintf(`   LEFT  JOIN s_group_member_position_grant    AS  F  ON ( E.oc_id = F.oc_id AND E.account_id  = F.account_id AND E.position_id = F.position_id  AND F.group_id = %d )`, groupId)
+    sqlFrom += `   LEFT  JOIN s_group                          AS  G  ON ( G.oc_id = F.oc_id AND G.group_id    = F.grant_group_id ) `
+    sqlFrom += `   LEFT  JOIN s_position                       AS  H  ON ( A.oc_id = E.oc_id AND H.position_id = E.position_id    ) `
+    
+    sqlWhere := ` WHERE B.deleted_flag = 0 `
+    sqlWhere += ` AND   A.oc_id      = ` + fmt.Sprintf("%d", ocId)
     sqlWhere += ` AND   A.account_id = ` + fmt.Sprintf("%d", userId)
     
     data := &viewmodels.UserInfo{}
@@ -62,11 +64,11 @@ func (d *UserRepo) GetById(ocId int64, userId int64)(*viewmodels.UserInfo, error
 }
 
 func (d *UserRepo) GetPage(m map[string]interface{})(*viewmodels.PageResult, error){
-    ocId       := m["ocId"].(int64)
-    limit      := m["limit"].(int)
-    page       := m["page"].(int)
+    ocId      := m["ocId"].(int64)
+    limit     := m["limit"].(int)
+    page      := m["page"].(int)
     
-    sqlSelect := `SELECT
+    sqlSelect := ` SELECT
                     DISTINCT(A.account_id),
                     A.gm_id,
                     A.oc_id,
@@ -87,12 +89,12 @@ func (d *UserRepo) GetPage(m map[string]interface{})(*viewmodels.PageResult, err
                     E.gmpg_id,
                     E.grant_group_id,
                     F.group_name as grant_group_name  `
-    sqlFrom := `FROM      s_group_member                AS A
-                LEFT JOIN account                       AS B ON (A.oc_id = B.oc_id AND A.account_id     = B.account_id)
-                LEFT JOIN s_group                       AS C ON (A.oc_id = C.oc_id AND A.group_id       = C.group_id)
-                LEFT JOIN s_group_member_position_grant AS E ON (B.oc_id = E.oc_id AND B.account_id     = E.account_id)
-                LEFT JOIN s_group                       AS F ON (E.oc_id = F.oc_id AND E.grant_group_id = F.group_id)
-                LEFT JOIN (
+    sqlFrom := ` FROM      s_group_member                AS A
+                 LEFT JOIN account                       AS B ON (A.oc_id = B.oc_id AND A.account_id     = B.account_id )
+                 LEFT JOIN s_group                       AS C ON (A.oc_id = C.oc_id AND A.group_id       = C.group_id   )
+                 LEFT JOIN s_group_member_position_grant AS E ON (B.oc_id = E.oc_id AND B.account_id     = E.account_id )
+                 LEFT JOIN s_group                       AS F ON (E.oc_id = F.oc_id AND E.grant_group_id = F.group_id   )
+                 LEFT JOIN (
                     SELECT
                         M.oc_id,
                         M.account_id,
@@ -177,9 +179,9 @@ func (d *UserRepo) GetList(m map[string]interface{})([]viewmodels.UserInfo, erro
                             F.group_name as grant_group_name  `
     sqlFrom := `  FROM      s_group_member                AS A
                   LEFT JOIN account                       AS B ON (A.oc_id = B.oc_id AND A.account_id     = B.account_id)
-                  LEFT JOIN s_group                       AS C ON (A.oc_id = C.oc_id AND A.group_id       = C.group_id)
+                  LEFT JOIN s_group                       AS C ON (A.oc_id = C.oc_id AND A.group_id       = C.group_id  )
                   LEFT JOIN s_group_member_position_grant AS E ON (B.oc_id = E.oc_id AND B.account_id     = E.account_id)
-                  LEFT JOIN s_group                       AS F ON (E.oc_id = F.oc_id AND E.grant_group_id = F.group_id)
+                  LEFT JOIN s_group                       AS F ON (E.oc_id = F.oc_id AND E.grant_group_id = F.group_id  )
                   LEFT JOIN (
                       SELECT
                           M.oc_id,

+ 9 - 9
service/biz_object_mapping_service.go

@@ -48,26 +48,26 @@ func (s *bizObjectMappingService) GetById(bizId, objectId, attrId int64) (*viewm
     return s.repo.GetById(bizId, objectId, attrId)
 }
 
-func (s *bizObjectMappingService) Create(attr *datamodels.BizObjectMapping) error {
-    attr.MappingId = NewID()
-    err := s.repo.Create(attr)
+func (s *bizObjectMappingService) Create(m *datamodels.BizObjectMapping) error {
+    m.MappingId = NewID()
+    err := s.repo.Create(m)
     if err != nil {
         return nil
     }
     
-    bizId    := attr.BizId
-    objectId := attr.ObjectId
+    bizId    := m.BizId
+    objectId := m.ObjectId
     return s.CacheBizObjectMapping(bizId, objectId)
 }
 
-func (s *bizObjectMappingService) Update(attr *datamodels.BizObjectMapping) error {
-    err := s.repo.Update(attr)
+func (s *bizObjectMappingService) Update(m *datamodels.BizObjectMapping) error {
+    err := s.repo.Update(m)
     if err != nil {
         return nil
     }
     
-    bizId    := attr.BizId
-    objectId := attr.ObjectId
+    bizId    := m.BizId
+    objectId := m.ObjectId
     return s.CacheBizObjectMapping(bizId, objectId)
 }
 

+ 33 - 0
service/group_service.go

@@ -10,6 +10,7 @@ import (
 
 type GroupService interface {
     GetList(m map[string]interface{})([]viewmodels.GroupInfo, error)
+    GetTreeView(ocId int64) ([]viewmodels.GroupTreeViewInfo, error)
     GetById(ocId int64 ,groupId int64)(*viewmodels.GroupInfo, error)
     Create(group *datamodels.Group) error
     Update(group *datamodels.Group) error
@@ -36,6 +37,38 @@ func (s *groupService) GetList(m map[string]interface{})([]viewmodels.GroupInfo,
     return s.groupRepo.GetList(m)
 }
 
+func (s *groupService) GetTreeView(ocId int64)([]viewmodels.GroupTreeViewInfo, error){
+    groupList, err := s.groupRepo.GetAll(ocId)
+    if err != nil {
+        return nil, err
+    }
+    return s.GenerateTreeInfo(0, groupList)
+}
+
+func (s *groupService) GenerateTreeInfo(parentId int64, groups []viewmodels.GroupInfo)([]viewmodels.GroupTreeViewInfo, error) {
+
+    treeItemList := make([]viewmodels.GroupTreeViewInfo, 0)
+    for _, group := range groups {
+        if group.ParentId == parentId {
+            itemId := group.GroupId
+            
+            children, err := s.GenerateTreeInfo(itemId, groups)
+            if err != nil {
+                return nil, err
+            }
+            treeItem := viewmodels.GroupTreeViewInfo{
+                Id: itemId,
+                Label: group.GroupName,
+                GroupId: group.GroupId,
+                GroupName: group.GroupName,
+                Children: children,
+            }
+            treeItemList = append(treeItemList, treeItem)
+        }
+    }
+    return treeItemList, nil
+}
+
 func (s *groupService) GetById(ocId int64 ,gid int64)(*viewmodels.GroupInfo, error) {
     return s.groupRepo.GetById(ocId ,gid)
 }

+ 5 - 0
service/model_object_service.go

@@ -16,6 +16,7 @@ type ModelObjectService interface {
 	Create(o *datamodels.ModelObject) error
 	Update(o *datamodels.ModelObject) error
 	Delete(m map[string]interface{}) error
+	Select(modelId, bizId, objectId int64) ([]viewmodels.ModelObjectInfo, error)
 	
 	CacheModelObject(modelId, objectId int64) error
 }
@@ -36,6 +37,10 @@ func (s *modelObjectService) GetList(m map[string]interface{}) ([]viewmodels.Mod
 	return s.modelObjectRepo.GetList(m)
 }
 
+func (s *modelObjectService) Select(modelId, targetBizId, targetObjectId int64) ([]viewmodels.ModelObjectInfo, error) {
+	return s.modelObjectRepo.SelectForBizObjectMapping(modelId, targetBizId, targetObjectId)
+}
+
 func (s *modelObjectService) GetPage(m map[string]interface{}) (*viewmodels.PageResult, error) {
 	return s.modelObjectRepo.GetPage(m)
 }

+ 1 - 1
service/user_service.go

@@ -82,7 +82,7 @@ func (s *userService) GetPage(m map[string]interface{}) (*viewmodels.PageResult,
 }
 
 func (s *userService) GetById(ocId, groupId, userId int64) (*viewmodels.UserInfo, error) {
-    return s.GetById(ocId, groupId, userId)
+    return s.userRepo.GetById(ocId, groupId, userId)
 }
 
 func (s *userService) Create(ocTypeId int64, user *viewmodels.UserInfo) error {

+ 9 - 0
viewmodels/group_tree_view_info.go

@@ -0,0 +1,9 @@
+package viewmodels
+
+type GroupTreeViewInfo struct {
+    Id               int64   `json:"id"              xorm:"'id'                  bigint not null pk     comment('ID')  " `
+    Label            string  `json:"label"           xorm:"'label'               varchar(127) not null  comment('群组名称')    " `
+    GroupId          int64   `json:"groupId"         xorm:"'group_id'            bigint not null pk     comment('群组ID')      " `
+    GroupName        string  `json:"groupName"       xorm:"'group_name'          varchar(127) not null  comment('群组名称')    " `
+    Children    []GroupTreeViewInfo `json:"children"`
+}

+ 0 - 1
web/controllers/biz_object_mapping_controller.go

@@ -74,7 +74,6 @@ func (c *BizObjectMappingController) GetById(bizId, objectId, mappingId int64) *
 
 func (c *BizObjectMappingController) Create() *JsonResult {
     userId     := c.GetCurUserId()
-    
     objectData := datamodels.BizObjectMapping{}
     if err := c.Ctx.ReadJSON(&objectData); err != nil {
         return ResultErr("读取数据失败", nil)

+ 11 - 0
web/controllers/group_controller.go

@@ -14,6 +14,7 @@ type GroupController struct {
 func (c *GroupController) BeforeActivation(b mvc.BeforeActivation) {
     b.Handle("GET"      ,"/"                         ,"GetList"     )
     b.Handle("GET"      ,"/groupId:int64}"           ,"GetById"     )
+    b.Handle("GET"      ,"/view"                     ,"GetTreeView" )
     b.Handle("POST"     ,"/add"                      ,"Create"      )
     b.Handle("PUT"      ,"/update"                   ,"Update"      )
     b.Handle("DELETE"   ,"/{groupId:int64}"          ,"DeleteById"  )
@@ -32,6 +33,16 @@ func (c *GroupController)  GetList() *JsonResult {
     }
 }
 
+func (c *GroupController) GetTreeView() *JsonResult {
+    ocId   := c.GetCurOcId()
+    data, err := c.Service.GetTreeView(ocId)
+    if err != nil {
+        return ResultErr(err.Error(), nil)
+    } else {
+        return ResultOk("获取成功", data)
+    }
+}
+
 func (c *GroupController) GetById(groupId int64) *JsonResult {
     ocId      := c.GetCurOcId()
     data, err := c.Service.GetById(ocId, groupId)

+ 16 - 6
web/controllers/model_object_controller.go

@@ -12,12 +12,13 @@ type ModelObjectController struct {
 }
 
 func (c *ModelObjectController) BeforeActivation(b mvc.BeforeActivation) {
-	b.Handle("GET",         "/",                                 "GetList"   )
-	b.Handle("GET",         "/page",                             "GetPage"   )
-	b.Handle("GET",         "/{modelId:int64}/{objectId:int64}", "GetById"   )
-	b.Handle("POST",        "/add",                              "Create"    )
-	b.Handle("PUT",         "/update",                           "Update"    )
-	b.Handle("DELETE",      "/{modelId:int64}/{objectId:int64}", "DeleteByID")
+	b.Handle("GET",         "/",                                                                    "GetList"   )
+	b.Handle("GET",         "/page",                                                                "GetPage"   )
+	b.Handle("GET",         "/{modelId:int64}/{objectId:int64}",                                    "GetById"   )
+	b.Handle("GET",         "/select/{modelId:int64}/{targetBizId:int64}/{targetObjectId:int64}",   "Select"    )
+	b.Handle("POST",        "/add",                                                                 "Create"    )
+	b.Handle("PUT",         "/update",                                                              "Update"    )
+	b.Handle("DELETE",      "/{modelId:int64}/{objectId:int64}",                                    "DeleteByID")
 }
 
 func (c *ModelObjectController) GetList() *JsonResult {
@@ -35,6 +36,15 @@ func (c *ModelObjectController) GetList() *JsonResult {
 	}
 }
 
+func (c *ModelObjectController) Select(modelId, targetBizId, targetObjectId int64) *JsonResult {
+	data, err := c.Service.Select(modelId, targetBizId, targetObjectId)
+	if err != nil {
+		return ResultErr(err.Error(), nil)
+	} else {
+		return ResultOk("获取成功", data)
+	}
+}
+
 func (c *ModelObjectController) GetPage() *JsonResult {
 	params  := c.buildParams()
 	modelId := c.Ctx.URLParamInt64Default("modelId", 0)