作者 yangfu

机会池修改

... ... @@ -327,6 +327,85 @@ select count(0) from (
return
}
//type32 特定部门机会 - 多角色时包含levl2 部门公开
func GetChancePoolDepartment(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64, userDepartmetIds []int64) (total int, err error) {
sql := fmt.Sprintf(`
select a.*,b.images,speechs,videos from (
select * from (
##指定部门-机会公开的部门
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 (
select DISTINCT chance_id from chance_department where department_id in (%v)
)a inner join chance b on a.chance_id = b.id
UNION
##公司公开的机会
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
where company_id = %v and publish_status = 2
UNION
##指定部门-机会提交的部门
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
where department_id in (%v)
UNION
##本人
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
where user_id = %v
UNION
##我审核
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 (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or id<%v) and a.enable_status=1
order by create_at desc
limit %v
) a left JOIN chance_data b on a.id =b.chance_id
`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
sqlCount := fmt.Sprintf(`
select count(0) from (
##指定部门-机会公开的部门
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 (
select DISTINCT chance_id from chance_department where department_id in (%v)
)a inner join chance b on a.chance_id = b.id
UNION
##公司公开的机会
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
where company_id = %v and publish_status = 2
UNION
##指定部门-机会提交的部门
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
where department_id in (%v)
UNION
##本人
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
where user_id = %v
UNION
##我审核
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 (
select DISTINCT chance_id from audit_flow_process where uid =%v
) a inner join chance b on a.chance_id = b.id
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1
`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId)
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql); err != nil {
return
}
}
return
}
//type2 对我所在部门公开的机会 公司公开的机会
func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
sql := fmt.Sprintf(`
... ...
... ... @@ -11,6 +11,7 @@ import (
func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
var (
check int
checkMap map[int]int
specialDIds []int64
userDIds []int64
)
... ... @@ -19,6 +20,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
specialDIds = append(specialDIds, op.CheckOption.Departments[i].Id)
}
check = op.Check
checkMap = op.CheckMap
}
if len(specialDIds) == 0 {
specialDIds = append(specialDIds, 0)
... ... @@ -34,6 +36,13 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
}
return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, lastId, pageSize, v, userDIds)
case OpportunityCheckLv3:
if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会
if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil {
log.Error(err)
return
}
return models.GetChancePoolDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds, userDIds)
}
return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds)
case OpportunityCheckLv4:
return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v)
... ... @@ -47,6 +56,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (err error) {
var (
check int
checkMap map[int]int
specialDIds []int64
userDIds []int64
)
... ... @@ -54,6 +64,7 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er
for i := range op.CheckOption.Departments {
specialDIds = append(specialDIds, op.CheckOption.Departments[i].Id)
}
checkMap = op.CheckMap
check = op.Check
} else {
log.Error(err)
... ... @@ -115,6 +126,19 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er
if chanceUserId == uid {
continue
}
if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会
if chancePublicStatus == protocol.PublicToDepartment {
if len(userDIds) == 0 {
if e := models.GetUserDepartmentIds(uid, cid, &userDIds); e != nil {
log.Error(e)
return
}
}
if _, e := models.ExitsChanceByPublicDeparmentIds(chanceId, userDIds); e == nil {
continue
}
}
}
if _, e := models.ExitsChanceByDeparmentIds(chanceId, specialDIds); e == nil {
continue
}
... ...
... ... @@ -355,7 +355,9 @@ func getUserChancePermission(userCompanyid int64) (map[string]PermissionOptionOb
func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObject, error) {
var (
objMap = make(map[string]PermissionOptionObject)
obj = &OptionOpportunity{}
obj = &OptionOpportunity{
CheckMap: make(map[int]int),
}
)
if len(list) == 0 {
obj.Check = OpportunityCheckLv4
... ... @@ -372,6 +374,9 @@ func getPermissionMap(list []OptionOpportunity) (map[string]PermissionOptionObje
if tmp.Check > obj.Check {
obj.Check = tmp.Check
}
if _, ok := obj.CheckMap[tmp.Check]; !ok { //所有的check都加进来
obj.CheckMap[tmp.Check] = tmp.Check
}
if tmp.Check == obj.Check && obj.Check == OpportunityCheckLv3 { //当前是特定部门时 合并特定部门的部门列表
for i := range tmp.CheckOption.Departments { //合并特殊部门
d := tmp.CheckOption.Departments[i]
... ...