|
@@ -197,26 +197,26 @@ func (p *OptionOpportunity) MergeObject(jsonString string) error { |
|
@@ -197,26 +197,26 @@ func (p *OptionOpportunity) MergeObject(jsonString string) error { |
197
|
}
|
197
|
}
|
198
|
p.CheckMap[obj.Check] = 1
|
198
|
p.CheckMap[obj.Check] = 1
|
199
|
departMap := make(map[int64]*CheckDeparment)
|
199
|
departMap := make(map[int64]*CheckDeparment)
|
200
|
- for k := range p.CheckOption.Departments {
|
|
|
201
|
- i := p.CheckOption.Departments[k].Id
|
|
|
202
|
- departMap[i] = &p.CheckOption.Departments[k]
|
200
|
+ for i := range p.CheckOption.Departments {
|
|
|
201
|
+ id := p.CheckOption.Departments[i].Id
|
|
|
202
|
+ departMap[id] = &p.CheckOption.Departments[i]
|
203
|
}
|
203
|
}
|
204
|
//列表合并
|
204
|
//列表合并
|
205
|
- for k := range obj.CheckOption.Departments {
|
|
|
206
|
- i := obj.CheckOption.Departments[k].Id
|
|
|
207
|
- if _, ok := departMap[i]; ok {
|
|
|
208
|
- if obj.CheckOption.Departments[k].OpenAll > departMap[i].OpenAll {
|
|
|
209
|
- departMap[i].OpenAll = obj.CheckOption.Departments[k].OpenAll
|
205
|
+ for i := range obj.CheckOption.Departments {
|
|
|
206
|
+ id := obj.CheckOption.Departments[i].Id
|
|
|
207
|
+ if _, ok := departMap[id]; ok {
|
|
|
208
|
+ if obj.CheckOption.Departments[i].OpenAll > departMap[id].OpenAll {
|
|
|
209
|
+ departMap[id].OpenAll = obj.CheckOption.Departments[i].OpenAll
|
210
|
}
|
210
|
}
|
211
|
- if obj.CheckOption.Departments[k].OpenDepart > departMap[i].OpenDepart {
|
|
|
212
|
- departMap[i].OpenDepart = obj.CheckOption.Departments[k].OpenDepart
|
211
|
+ if obj.CheckOption.Departments[i].OpenDepart > departMap[id].OpenDepart {
|
|
|
212
|
+ departMap[id].OpenDepart = obj.CheckOption.Departments[i].OpenDepart
|
213
|
}
|
213
|
}
|
214
|
- if obj.CheckOption.Departments[k].Wait > departMap[i].Wait {
|
|
|
215
|
- departMap[i].Wait = obj.CheckOption.Departments[k].Wait
|
214
|
+ if obj.CheckOption.Departments[i].Wait > departMap[id].Wait {
|
|
|
215
|
+ departMap[id].Wait = obj.CheckOption.Departments[i].Wait
|
216
|
}
|
216
|
}
|
217
|
} else {
|
217
|
} else {
|
218
|
|
218
|
|
219
|
- departMap[i] = &obj.CheckOption.Departments[k]
|
219
|
+ departMap[id] = &obj.CheckOption.Departments[i]
|
220
|
|
220
|
|
221
|
}
|
221
|
}
|
222
|
}
|
222
|
}
|
|
@@ -297,7 +297,6 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, |
|
@@ -297,7 +297,6 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, |
297
|
} else {
|
297
|
} else {
|
298
|
log.Error("未知code:%s", v.Code)
|
298
|
log.Error("未知code:%s", v.Code)
|
299
|
}
|
299
|
}
|
300
|
-
|
|
|
301
|
}
|
300
|
}
|
302
|
return objMap, nil
|
301
|
return objMap, nil
|
303
|
}
|
302
|
}
|
|
@@ -305,7 +304,7 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, |
|
@@ -305,7 +304,7 @@ func getUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, |
305
|
//获取用户权限
|
304
|
//获取用户权限
|
306
|
func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) {
|
305
|
func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) {
|
307
|
op = &OptionOpportunity{}
|
306
|
op = &OptionOpportunity{}
|
308
|
- mp, e := getUserPermission(userCompanyid)
|
307
|
+ mp, e := getUserChancePermission(userCompanyid)
|
309
|
if e != nil {
|
308
|
if e != nil {
|
310
|
log.Error(e)
|
309
|
log.Error(e)
|
311
|
}
|
310
|
}
|
|
@@ -319,3 +318,77 @@ func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) { |
|
@@ -319,3 +318,77 @@ func GetUserPermission(userCompanyid int64) (op *OptionOpportunity, err error) { |
319
|
}
|
318
|
}
|
320
|
return
|
319
|
return
|
321
|
}
|
320
|
}
|
|
|
321
|
+
|
|
|
322
|
+//获取用户机会权限
|
|
|
323
|
+func getUserChancePermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
|
|
|
324
|
+ type CodeOpptionData struct {
|
|
|
325
|
+ Code string `orm:"column(code)"`
|
|
|
326
|
+ Opption string `orm:"column(opption)"`
|
|
|
327
|
+ }
|
|
|
328
|
+ var datasql string = fmt.Sprintf(`SELECT a.code,a.opption,c.id role_id
|
|
|
329
|
+ FROM role_menu AS a
|
|
|
330
|
+ JOIN user_role AS b ON a.role_id = b.role_id
|
|
|
331
|
+ JOIN role AS c ON a.role_id = c.id
|
|
|
332
|
+ WHERE a.code='%v' AND b.user_company_id=? AND c.delete_at =0`, M_SYSTEM_OPPORTUNITY)
|
|
|
333
|
+
|
|
|
334
|
+ var (
|
|
|
335
|
+ data []CodeOpptionData
|
|
|
336
|
+ err error
|
|
|
337
|
+ )
|
|
|
338
|
+ err = utils.ExecuteQueryAll(&data, datasql, userCompanyid)
|
|
|
339
|
+ if err != nil {
|
|
|
340
|
+ e := fmt.Errorf("EXCUTE SQL ERR:%s", err)
|
|
|
341
|
+ return nil, e
|
|
|
342
|
+ }
|
|
|
343
|
+ var list []OptionOpportunity
|
|
|
344
|
+ for _, v := range data {
|
|
|
345
|
+ tmp := OptionOpportunity{}
|
|
|
346
|
+ if err = json.Unmarshal([]byte(v.Opption), &tmp); err != nil {
|
|
|
347
|
+ log.Debug("解析权限配置option 失败", v.Opption, err)
|
|
|
348
|
+ }
|
|
|
349
|
+ list = append(list, tmp)
|
|
|
350
|
+ }
|
|
|
351
|
+ return getPermissionMap(list)
|
|
|
352
|
+}
|
|
|
353
|
+
|
|
|
354
|
+//获取机会权限map
|
|
|
355
|
+func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObject, error) {
|
|
|
356
|
+ var (
|
|
|
357
|
+ objMap = make(map[string]PermissionOptionObject)
|
|
|
358
|
+ obj = &OptionOpportunity{}
|
|
|
359
|
+ )
|
|
|
360
|
+ if len(list) == 0 {
|
|
|
361
|
+ obj.Check = OpportunityCheckLv4
|
|
|
362
|
+ }
|
|
|
363
|
+ checkEnable := func(old, new int) int {
|
|
|
364
|
+ if old == 0 && new == 1 {
|
|
|
365
|
+ return 1
|
|
|
366
|
+ }
|
|
|
367
|
+ return old
|
|
|
368
|
+ }
|
|
|
369
|
+ specialDepIds := make(map[int64]CheckDeparment) //特定部门
|
|
|
370
|
+ for i := range list {
|
|
|
371
|
+ tmp := list[i]
|
|
|
372
|
+ if tmp.Check > obj.Check {
|
|
|
373
|
+ obj.Check = tmp.Check
|
|
|
374
|
+ }
|
|
|
375
|
+ if tmp.Check == obj.Check && obj.Check == OpportunityCheckLv3 { //当前是特定部门时 合并特定部门的部门列表
|
|
|
376
|
+ for i := range tmp.CheckOption.Departments { //合并特殊部门
|
|
|
377
|
+ d := tmp.CheckOption.Departments[i]
|
|
|
378
|
+ if _, ok := specialDepIds[d.Id]; !ok {
|
|
|
379
|
+ specialDepIds[d.Id] = d
|
|
|
380
|
+ }
|
|
|
381
|
+ }
|
|
|
382
|
+ }
|
|
|
383
|
+ obj.EditChance = checkEnable(obj.EditChance, tmp.EditChance)
|
|
|
384
|
+ obj.EditSorce = checkEnable(obj.EditSorce, tmp.EditSorce)
|
|
|
385
|
+ obj.EditPublicStatus = checkEnable(obj.EditPublicStatus, tmp.EditPublicStatus)
|
|
|
386
|
+ }
|
|
|
387
|
+ if obj.Check == OpportunityCheckLv3 { //合并特殊部门
|
|
|
388
|
+ for _, v := range specialDepIds {
|
|
|
389
|
+ obj.CheckOption.Departments = append(obj.CheckOption.Departments, v)
|
|
|
390
|
+ }
|
|
|
391
|
+ }
|
|
|
392
|
+ objMap[M_SYSTEM_OPPORTUNITY] = obj
|
|
|
393
|
+ return objMap, nil
|
|
|
394
|
+} |