作者 yangfu

机会池修改

@@ -327,6 +327,85 @@ select count(0) from ( @@ -327,6 +327,85 @@ select count(0) from (
327 return 327 return
328 } 328 }
329 329
  330 +//type32 特定部门机会 - 多角色时包含levl2 部门公开
  331 +func GetChancePoolDepartment(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64, userDepartmetIds []int64) (total int, err error) {
  332 +
  333 + sql := fmt.Sprintf(`
  334 +select a.*,b.images,speechs,videos from (
  335 +select * from (
  336 + ##指定部门-机会公开的部门
  337 + select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from (
  338 + select DISTINCT chance_id from chance_department where department_id in (%v)
  339 + )a inner join chance b on a.chance_id = b.id
  340 + UNION
  341 +
  342 + ##公司公开的机会
  343 + select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
  344 + where company_id = %v and publish_status = 2
  345 + UNION
  346 +
  347 + ##指定部门-机会提交的部门
  348 + select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
  349 + where department_id in (%v)
  350 + UNION
  351 +
  352 + ##本人
  353 + select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
  354 + where user_id = %v
  355 + UNION
  356 +
  357 + ##我审核
  358 + select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from (
  359 + select DISTINCT chance_id from audit_flow_process where uid =%v
  360 + ) a inner join chance b on a.chance_id = b.id
  361 +
  362 +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or id<%v) and a.enable_status=1
  363 +order by create_at desc
  364 +limit %v
  365 +) a left JOIN chance_data b on a.id =b.chance_id
  366 +`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
  367 +
  368 + sqlCount := fmt.Sprintf(`
  369 +select count(0) from (
  370 + ##指定部门-机会公开的部门
  371 + select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from (
  372 + select DISTINCT chance_id from chance_department where department_id in (%v)
  373 + )a inner join chance b on a.chance_id = b.id
  374 + UNION
  375 +
  376 + ##公司公开的机会
  377 + select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
  378 + where company_id = %v and publish_status = 2
  379 + UNION
  380 +
  381 + ##指定部门-机会提交的部门
  382 + select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
  383 + where department_id in (%v)
  384 + UNION
  385 +
  386 + ##本人
  387 + select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from chance
  388 + where user_id = %v
  389 + UNION
  390 +
  391 + ##我审核
  392 + select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id from (
  393 + select DISTINCT chance_id from audit_flow_process where uid =%v
  394 + ) a inner join chance b on a.chance_id = b.id
  395 +
  396 +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1
  397 +`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId)
  398 + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
  399 + return
  400 + }
  401 + if v != nil {
  402 + if err = utils.ExecuteQueryAll(v, sql); err != nil {
  403 + return
  404 + }
  405 + }
  406 + return
  407 +}
  408 +
330 //type2 对我所在部门公开的机会 公司公开的机会 409 //type2 对我所在部门公开的机会 公司公开的机会
331 func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) { 410 func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
332 sql := fmt.Sprintf(` 411 sql := fmt.Sprintf(`
@@ -11,6 +11,7 @@ import ( @@ -11,6 +11,7 @@ import (
11 func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) { 11 func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
12 var ( 12 var (
13 check int 13 check int
  14 + checkMap map[int]int
14 specialDIds []int64 15 specialDIds []int64
15 userDIds []int64 16 userDIds []int64
16 ) 17 )
@@ -19,6 +20,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, @@ -19,6 +20,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
19 specialDIds = append(specialDIds, op.CheckOption.Departments[i].Id) 20 specialDIds = append(specialDIds, op.CheckOption.Departments[i].Id)
20 } 21 }
21 check = op.Check 22 check = op.Check
  23 + checkMap = op.CheckMap
22 } 24 }
23 if len(specialDIds) == 0 { 25 if len(specialDIds) == 0 {
24 specialDIds = append(specialDIds, 0) 26 specialDIds = append(specialDIds, 0)
@@ -34,6 +36,13 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, @@ -34,6 +36,13 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
34 } 36 }
35 return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, lastId, pageSize, v, userDIds) 37 return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, lastId, pageSize, v, userDIds)
36 case OpportunityCheckLv3: 38 case OpportunityCheckLv3:
  39 + if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会
  40 + if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil {
  41 + log.Error(err)
  42 + return
  43 + }
  44 + return models.GetChancePoolDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds, userDIds)
  45 + }
37 return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds) 46 return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds)
38 case OpportunityCheckLv4: 47 case OpportunityCheckLv4:
39 return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v) 48 return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v)
@@ -47,6 +56,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, @@ -47,6 +56,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
47 func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (err error) { 56 func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (err error) {
48 var ( 57 var (
49 check int 58 check int
  59 + checkMap map[int]int
50 specialDIds []int64 60 specialDIds []int64
51 userDIds []int64 61 userDIds []int64
52 ) 62 )
@@ -54,6 +64,7 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er @@ -54,6 +64,7 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er
54 for i := range op.CheckOption.Departments { 64 for i := range op.CheckOption.Departments {
55 specialDIds = append(specialDIds, op.CheckOption.Departments[i].Id) 65 specialDIds = append(specialDIds, op.CheckOption.Departments[i].Id)
56 } 66 }
  67 + checkMap = op.CheckMap
57 check = op.Check 68 check = op.Check
58 } else { 69 } else {
59 log.Error(err) 70 log.Error(err)
@@ -115,6 +126,19 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er @@ -115,6 +126,19 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er
115 if chanceUserId == uid { 126 if chanceUserId == uid {
116 continue 127 continue
117 } 128 }
  129 + if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会
  130 + if chancePublicStatus == protocol.PublicToDepartment {
  131 + if len(userDIds) == 0 {
  132 + if e := models.GetUserDepartmentIds(uid, cid, &userDIds); e != nil {
  133 + log.Error(e)
  134 + return
  135 + }
  136 + }
  137 + if _, e := models.ExitsChanceByPublicDeparmentIds(chanceId, userDIds); e == nil {
  138 + continue
  139 + }
  140 + }
  141 + }
118 if _, e := models.ExitsChanceByDeparmentIds(chanceId, specialDIds); e == nil { 142 if _, e := models.ExitsChanceByDeparmentIds(chanceId, specialDIds); e == nil {
119 continue 143 continue
120 } 144 }
@@ -355,7 +355,9 @@ func getUserChancePermission(userCompanyid int64) (map[string]PermissionOptionOb @@ -355,7 +355,9 @@ func getUserChancePermission(userCompanyid int64) (map[string]PermissionOptionOb
355 func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObject, error) { 355 func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObject, error) {
356 var ( 356 var (
357 objMap = make(map[string]PermissionOptionObject) 357 objMap = make(map[string]PermissionOptionObject)
358 - obj = &OptionOpportunity{} 358 + obj = &OptionOpportunity{
  359 + CheckMap: make(map[int]int),
  360 + }
359 ) 361 )
360 if len(list) == 0 { 362 if len(list) == 0 {
361 obj.Check = OpportunityCheckLv4 363 obj.Check = OpportunityCheckLv4
@@ -372,6 +374,9 @@ func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObje @@ -372,6 +374,9 @@ func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObje
372 if tmp.Check > obj.Check { 374 if tmp.Check > obj.Check {
373 obj.Check = tmp.Check 375 obj.Check = tmp.Check
374 } 376 }
  377 + if _, ok := obj.CheckMap[tmp.Check]; !ok { //所有的check都加进来
  378 + obj.CheckMap[tmp.Check] = tmp.Check
  379 + }
375 if tmp.Check == obj.Check && obj.Check == OpportunityCheckLv3 { //当前是特定部门时 合并特定部门的部门列表 380 if tmp.Check == obj.Check && obj.Check == OpportunityCheckLv3 { //当前是特定部门时 合并特定部门的部门列表
376 for i := range tmp.CheckOption.Departments { //合并特殊部门 381 for i := range tmp.CheckOption.Departments { //合并特殊部门
377 d := tmp.CheckOption.Departments[i] 382 d := tmp.CheckOption.Departments[i]