...
|
...
|
@@ -197,26 +197,26 @@ func (p *OptionOpportunity) MergeObject(jsonString string) error { |
|
|
}
|
|
|
p.CheckMap[obj.Check] = 1
|
|
|
departMap := make(map[int64]*CheckDeparment)
|
|
|
for k := range p.CheckOption.Departments {
|
|
|
i := p.CheckOption.Departments[k].Id
|
|
|
departMap[i] = &p.CheckOption.Departments[k]
|
|
|
for i := range p.CheckOption.Departments {
|
|
|
id := p.CheckOption.Departments[i].Id
|
|
|
departMap[id] = &p.CheckOption.Departments[i]
|
|
|
}
|
|
|
//列表合并
|
|
|
for k := range obj.CheckOption.Departments {
|
|
|
i := obj.CheckOption.Departments[k].Id
|
|
|
if _, ok := departMap[i]; ok {
|
|
|
if obj.CheckOption.Departments[k].OpenAll > departMap[i].OpenAll {
|
|
|
departMap[i].OpenAll = obj.CheckOption.Departments[k].OpenAll
|
|
|
for i := range obj.CheckOption.Departments {
|
|
|
id := obj.CheckOption.Departments[i].Id
|
|
|
if _, ok := departMap[id]; ok {
|
|
|
if obj.CheckOption.Departments[i].OpenAll > departMap[id].OpenAll {
|
|
|
departMap[id].OpenAll = obj.CheckOption.Departments[i].OpenAll
|
|
|
}
|
|
|
if obj.CheckOption.Departments[k].OpenDepart > departMap[i].OpenDepart {
|
|
|
departMap[i].OpenDepart = obj.CheckOption.Departments[k].OpenDepart
|
|
|
if obj.CheckOption.Departments[i].OpenDepart > departMap[id].OpenDepart {
|
|
|
departMap[id].OpenDepart = obj.CheckOption.Departments[i].OpenDepart
|
|
|
}
|
|
|
if obj.CheckOption.Departments[k].Wait > departMap[i].Wait {
|
|
|
departMap[i].Wait = obj.CheckOption.Departments[k].Wait
|
|
|
if obj.CheckOption.Departments[i].Wait > departMap[id].Wait {
|
|
|
departMap[id].Wait = obj.CheckOption.Departments[i].Wait
|
|
|
}
|
|
|
} else {
|
|
|
|
|
|
departMap[i] = &obj.CheckOption.Departments[k]
|
|
|
departMap[id] = &obj.CheckOption.Departments[i]
|
|
|
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -297,7 +297,6 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, |
|
|
} else {
|
|
|
log.Error("未知code:%s", v.Code)
|
|
|
}
|
|
|
|
|
|
}
|
|
|
return objMap, nil
|
|
|
}
|
...
|
...
|
@@ -305,7 +304,7 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, |
|
|
//获取用户权限
|
|
|
func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) {
|
|
|
op = &OptionOpportunity{}
|
|
|
mp, e := getUserPermission(userCompanyid)
|
|
|
mp, e := getUserChancePermission(userCompanyid)
|
|
|
if e != nil {
|
|
|
log.Error(e)
|
|
|
}
|
...
|
...
|
@@ -319,3 +318,77 @@ func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) { |
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//获取用户机会权限
|
|
|
func getUserChancePermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
|
|
|
type CodeOpptionData struct {
|
|
|
Code string `orm:"column(code)"`
|
|
|
Opption string `orm:"column(opption)"`
|
|
|
}
|
|
|
var datasql string = fmt.Sprintf(`SELECT a.code,a.opption,c.id role_id
|
|
|
FROM role_menu AS a
|
|
|
JOIN user_role AS b ON a.role_id = b.role_id
|
|
|
JOIN role AS c ON a.role_id = c.id
|
|
|
WHERE a.code='%v' AND b.user_company_id=? AND c.delete_at =0`, M_SYSTEM_OPPORTUNITY)
|
|
|
|
|
|
var (
|
|
|
data []CodeOpptionData
|
|
|
err error
|
|
|
)
|
|
|
err = utils.ExecuteQueryAll(&data, datasql, userCompanyid)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("EXCUTE SQL ERR:%s", err)
|
|
|
return nil, e
|
|
|
}
|
|
|
var list []OptionOpportunity
|
|
|
for _, v := range data {
|
|
|
tmp := OptionOpportunity{}
|
|
|
if err = json.Unmarshal([]byte(v.Opption), &tmp); err != nil {
|
|
|
log.Debug("解析权限配置option 失败", v.Opption, err)
|
|
|
}
|
|
|
list = append(list, tmp)
|
|
|
}
|
|
|
return getPermissionMap(list)
|
|
|
}
|
|
|
|
|
|
//获取机会权限map
|
|
|
func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObject, error) {
|
|
|
var (
|
|
|
objMap = make(map[string]PermissionOptionObject)
|
|
|
obj = &OptionOpportunity{}
|
|
|
)
|
|
|
if len(list) == 0 {
|
|
|
obj.Check = OpportunityCheckLv4
|
|
|
}
|
|
|
checkEnable := func(old, new int) int {
|
|
|
if old == 0 && new == 1 {
|
|
|
return 1
|
|
|
}
|
|
|
return old
|
|
|
}
|
|
|
specialDepIds := make(map[int64]CheckDeparment) //特定部门
|
|
|
for i := range list {
|
|
|
tmp := list[i]
|
|
|
if tmp.Check > obj.Check {
|
|
|
obj.Check = tmp.Check
|
|
|
}
|
|
|
if tmp.Check == obj.Check && obj.Check == OpportunityCheckLv3 { //当前是特定部门时 合并特定部门的部门列表
|
|
|
for i := range tmp.CheckOption.Departments { //合并特殊部门
|
|
|
d := tmp.CheckOption.Departments[i]
|
|
|
if _, ok := specialDepIds[d.Id]; !ok {
|
|
|
specialDepIds[d.Id] = d
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
obj.EditChance = checkEnable(obj.EditChance, tmp.EditChance)
|
|
|
obj.EditSorce = checkEnable(obj.EditSorce, tmp.EditSorce)
|
|
|
obj.EditPublicStatus = checkEnable(obj.EditPublicStatus, tmp.EditPublicStatus)
|
|
|
}
|
|
|
if obj.Check == OpportunityCheckLv3 { //合并特殊部门
|
|
|
for _, v := range specialDepIds {
|
|
|
obj.CheckOption.Departments = append(obj.CheckOption.Departments, v)
|
|
|
}
|
|
|
}
|
|
|
objMap[M_SYSTEM_OPPORTUNITY] = obj
|
|
|
return objMap, nil
|
|
|
} |
...
|
...
|
|