|
@@ -4,6 +4,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"eta/eta_api/models"
|
|
|
"eta/eta_api/models/system"
|
|
|
+ "eta/eta_api/services"
|
|
|
"eta/eta_api/services/eta_forum"
|
|
|
"eta/eta_api/utils"
|
|
|
"strings"
|
|
@@ -38,22 +39,75 @@ func (this *SysGroupController) Add() {
|
|
|
br.ErrMsg = "部门ID不可为空"
|
|
|
return
|
|
|
}
|
|
|
- if req.GroupName == "" {
|
|
|
- br.Msg = "分组名称不能为空"
|
|
|
+ //构建部门的分组树
|
|
|
+ groupList,err:=system.GetGroupByDepartmentId(req.DepartmentId)
|
|
|
+ if err!=nil{
|
|
|
+ br.Msg = "获取数据失败,获取当前部门的分组列表失败"
|
|
|
+ br.ErrMsg = "获取当前部门的分组列表失败,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
+ //获取传入部门下的分组名称,分组名称为唯一标识,不会重复
|
|
|
groupNameArr := strings.Split(req.GroupName, ",")
|
|
|
- groupIds := make([]int, 0)
|
|
|
+ root := new(services.GroupNode)
|
|
|
+ services.BuildGroupTree(groupList,0,2,root)
|
|
|
+ //现有的分组名称
|
|
|
+ existGroupMap:=make(map[string]bool,len(root.Child))
|
|
|
+ for _, v := range root.Child {
|
|
|
+ existGroupMap[v.GroupName] = false
|
|
|
+ }
|
|
|
+ //传入的分组名称
|
|
|
+ reqGroupMap:=make(map[string]int,len(groupNameArr))
|
|
|
for _, v := range groupNameArr {
|
|
|
- count, err := system.GetSysGroupCount(req.DepartmentId, v)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取数据失败"
|
|
|
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
|
|
|
- return
|
|
|
+ reqGroupMap[v] = 1
|
|
|
+ }
|
|
|
+ //新增分组名称
|
|
|
+ newGroupMap := make(map[string]int)
|
|
|
+ groupIds := make([]int, 0)
|
|
|
+ if len(reqGroupMap)>0{
|
|
|
+ for k, _ := range reqGroupMap {
|
|
|
+ if _, ok := existGroupMap[k]; !ok {
|
|
|
+ newGroupMap[k] = 1
|
|
|
+ groupIds = append(groupIds, 0)
|
|
|
+ }else{
|
|
|
+ existGroupMap[k] = true
|
|
|
+ }
|
|
|
}
|
|
|
- if count <= 0 {
|
|
|
+ }
|
|
|
+ var deleteIds []int
|
|
|
+ var addGroup bool
|
|
|
+ //删除所有分组即可
|
|
|
+ if req.GroupName == "" {
|
|
|
+ addGroup=false
|
|
|
+ for _, node := range root.Child {
|
|
|
+ //分组Id
|
|
|
+ deleteIds = append(deleteIds, node.GroupId)
|
|
|
+ //teamId
|
|
|
+ for _, subNode := range node.Child {
|
|
|
+ deleteIds=append(deleteIds, subNode.GroupId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ addGroup=true
|
|
|
+ for k, v := range existGroupMap {
|
|
|
+ if !v{
|
|
|
+ for _, node := range root.Child {
|
|
|
+ if node.GroupName == k{
|
|
|
+ //分组Id
|
|
|
+ deleteIds = append(deleteIds, node.GroupId)
|
|
|
+ //teamId
|
|
|
+ for _, subNode := range node.Child {
|
|
|
+ deleteIds=append(deleteIds, subNode.GroupId)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if addGroup{
|
|
|
+ //新增分组
|
|
|
+ for k, _ := range newGroupMap {
|
|
|
item := new(system.SysGroup)
|
|
|
- item.GroupName = v
|
|
|
+ item.GroupName = k
|
|
|
item.DepartmentId = req.DepartmentId
|
|
|
item.CreateTime = time.Now()
|
|
|
groupId, e := system.AddSysGroup(item)
|
|
@@ -62,7 +116,6 @@ func (this *SysGroupController) Add() {
|
|
|
br.ErrMsg = "新增失败,Err:" + e.Error()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
// 同步分组缓存
|
|
|
if utils.BusinessCode == utils.BusinessCodeRelease {
|
|
|
var syncData system.SyncGroupData
|
|
@@ -72,12 +125,30 @@ func (this *SysGroupController) Add() {
|
|
|
}
|
|
|
groupIds = append(groupIds, int(groupId))
|
|
|
}
|
|
|
+ go eta_forum.GroupSave(groupIds)
|
|
|
+ //删除分组合他的子分组,写死只有2层分组,因此逻辑代码也就写死2层,一层分组,一层team
|
|
|
+ }
|
|
|
+ if len(deleteIds)>0 {
|
|
|
+ err =services.DeleteSysGroupByIds(deleteIds)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "删除失败"
|
|
|
+ br.ErrMsg = "删除失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 同步分组缓存
|
|
|
+ if utils.BusinessCode == utils.BusinessCodeRelease {
|
|
|
+ for _, groupId := range deleteIds {
|
|
|
+ var syncData system.SyncGroupData
|
|
|
+ syncData.Source = utils.SOURCE_ETA_FLAG
|
|
|
+ syncData.GroupId = groupId
|
|
|
+ _ = utils.Rc.LPush(utils.CACHE_SYNC_GROUP, syncData)
|
|
|
+ go eta_forum.GroupDelete(groupId)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- go eta_forum.GroupSave(groupIds)
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
- br.Msg = "新增成功"
|
|
|
+ br.Msg = "保存成功"
|
|
|
}
|
|
|
|
|
|
// @Title 修改分组
|