作者 yangfu

机会池修改

... ... @@ -149,33 +149,6 @@ from audit_flow_process where uid=? and enable_status =1 and review_status in (%
return
}
func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,speechs,videos
from (
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance
where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or id<?) and enable_status=1
order by create_at desc
limit ?
) a left JOIN chance_data b on a.id =b.chance_id`
//if public==protocol.pu
sqlCount := fmt.Sprintf(`select count(0) from (
select id from chance
where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1
order by create_at desc
) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId)
if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql, cid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize); err != nil {
return
}
}
return
}
func GetChanceCollect(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total from (
... ... @@ -257,3 +230,202 @@ where user_id =?`
}
return
}
//type4 查看所有机会
func GetChancePoolAll(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,speechs,videos
from (
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance
where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or id<?) and enable_status=1
order by create_at desc
limit ?
) a left JOIN chance_data b on a.id =b.chance_id`
//if public==protocol.pu
sqlCount := fmt.Sprintf(`select count(0) from (
select id from chance
where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1
order by create_at desc
) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId)
if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql, cid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize); err != nil {
return
}
}
return
}
//type3 特定部门机会
func GetChancePoolSpecialDepartment(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []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 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(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 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(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(`
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 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 (
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 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
`, 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 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 (
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 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
`, 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
}
//type1 禁止查看所有机会
func GetChancePoolMyself(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (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 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
`, 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 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
`, 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
}
... ...
... ... @@ -87,3 +87,15 @@ where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete
}
return
}
func GetUserDepartmentIds(id int64, companyId int64, v interface{}) (err error) {
o := orm.NewOrm()
sql := `
select a.department_id
from user_department a INNER JOIN department b on a.department_id = b.id
where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete_at =0`
if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil {
return
}
return
}
... ...
package agg
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/models"
)
//机会池
func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
var (
check int
specialDIds []int64
userDIds []int64
)
if op, e := GetUserPermission(uid); e == nil {
for i := range op.CheckOption.Departments {
specialDIds = append(specialDIds, op.CheckOption.Departments[i].Id)
}
check = op.Check
}
if len(specialDIds) == 0 {
specialDIds = append(specialDIds, 0)
}
log.Debug(fmt.Sprintf("user:%v check:%v", uid, check))
switch check {
case OpportunityCheckLv1:
return models.GetChancePoolMyself(uid, cid, chanceTypeId, lastId, pageSize, v)
case OpportunityCheckLv2:
if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil {
log.Error(err)
return
}
return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, lastId, pageSize, v, userDIds)
case OpportunityCheckLv3:
return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds)
case OpportunityCheckLv4:
return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v)
default:
return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v)
}
return
}
... ...
... ... @@ -1199,7 +1199,7 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
rsp = &protocol.ChanceStatisticsResponse{}
for i := range chanceType {
item := chanceType[i]
if total, err = models.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, 0, nil); err != nil {
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, 0, nil); err != nil {
log.Error(err)
return
}
... ... @@ -1276,7 +1276,7 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
provider *protocol.BaseUserInfo
flag int
)
if total, err = models.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.PageSize, &myChances); err != nil {
if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.PageSize, &myChances); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1849,6 +1849,10 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ
rsp.EditScore = op.EditSorce
rsp.Check = op.Check
}
//未设置查看权限
if rsp.Check == 0 {
rsp.Check = 4
}
for i := range op.CheckOption.Departments {
rsp.DepartmentIds = append(rsp.DepartmentIds, op.CheckOption.Departments[i].Id)
}
... ...