...
|
...
|
@@ -78,31 +78,112 @@ func GetRank(companyId, rankTypeId, rankRangeId, rankPeriodId int, relationId in |
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
func GetRanksByUser(companyId int64, rankTypeId, rankRangeId, rankPeriodId int, pageIndex, pageSize int, v interface{}) (total int, err error) {
|
|
|
//排行列表-用户
|
|
|
func GetRanksByUser(companyId int64, rankTypeId, rankRangeId, rankPeriodId int, key string, pageIndex, pageSize int, v interface{}) (total int, err error) {
|
|
|
//var filterDepartment string = getFilterSqlByDIds(dIds)
|
|
|
pageIndex, pageSize = utils.GetPageInfo(pageIndex, pageSize)
|
|
|
sql := fmt.Sprintf(`select a.*,b.nick_name name from (
|
|
|
select ranking,score,relation_id,user_id from(
|
|
|
select a.discovery_score score,a.relation_id,(@rowno:=@rowno+1) as ranking,user_id from rank a inner join user_company c on a.relation_id=c.id,(select (@rowno:=0)) b
|
|
|
sql := fmt.Sprintf(`select (@rowno:=@rowno+1) as ranking,a.*,b.nick_name name from
|
|
|
(
|
|
|
select score,relation_id,user_id from(
|
|
|
select a.%v score,a.relation_id,user_id from rank a inner join user_company c on a.relation_id=c.id
|
|
|
where a.company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v
|
|
|
order by a.discovery_score desc,c.create_at asc
|
|
|
) a
|
|
|
#where relation_id=?
|
|
|
order by a.%v desc,c.create_at asc
|
|
|
) a,(select @rowno:=%v) b
|
|
|
limit %v,%v
|
|
|
)a inner join user b on a.user_id = b.id
|
|
|
`, companyId, rankTypeId, rankRangeId, rankPeriodId, pageIndex, pageSize)
|
|
|
|
|
|
//if public==protocol.pu
|
|
|
`, key, companyId, rankTypeId, rankRangeId, rankPeriodId, key, pageIndex, pageIndex, pageSize)
|
|
|
|
|
|
sqlCount := fmt.Sprintf(`
|
|
|
select count(0) from rank
|
|
|
where company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v
|
|
|
`, companyId, rankTypeId, rankRangeId, rankPeriodId)
|
|
|
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
|
|
|
return
|
|
|
}
|
|
|
if v != nil {
|
|
|
if err = utils.ExecuteQueryAll(v, sql); err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//排行榜列表-用户-自己的排名
|
|
|
func GetRanksByUserSelf(companyId int64, rankTypeId, rankRangeId, rankPeriodId int, key string, relationId int64, v interface{}) (err error) {
|
|
|
//var filterDepartment string = getFilterSqlByDIds(dIds)
|
|
|
sql := fmt.Sprintf(`
|
|
|
|
|
|
select a.*,b.nick_name name from
|
|
|
(
|
|
|
select score,relation_id,user_id,(@rowno:=@rowno+1) as ranking from(
|
|
|
select a.%v score,a.relation_id,user_id from rank a inner join user_company c on a.relation_id=c.id
|
|
|
where a.company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v
|
|
|
order by a.%v desc,c.create_at asc
|
|
|
) a,(select @rowno:=0 ) b
|
|
|
)a inner join user b on a.user_id = b.id
|
|
|
where relation_id=%v
|
|
|
|
|
|
`, key, companyId, rankTypeId, rankRangeId, rankPeriodId, key, relationId)
|
|
|
|
|
|
if v != nil {
|
|
|
if err = utils.ExecuteQueryOne(v, sql); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//排行榜列表-部门
|
|
|
func GetRanksByDepartment(companyId int64, rankTypeId, rankRangeId, rankPeriodId int, key string, pageIndex, pageSize int, v interface{}) (total int, err error) {
|
|
|
//var filterDepartment string = getFilterSqlByDIds(dIds)
|
|
|
pageIndex, pageSize = utils.GetPageInfo(pageIndex, pageSize)
|
|
|
sql := fmt.Sprintf(`
|
|
|
select a.*,(@rowno:=@rowno+1) as ranking from
|
|
|
(
|
|
|
select a.%v score,a.relation_id,c.name
|
|
|
from rank a inner join department c on a.relation_id=c.id
|
|
|
where a.company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v
|
|
|
order by a.%v desc,c.create_at asc
|
|
|
)a,(select (@rowno:=%v)) b
|
|
|
limit %v,%v
|
|
|
`, key, companyId, rankTypeId, rankRangeId, rankPeriodId, key, pageIndex, pageIndex, pageSize)
|
|
|
|
|
|
sqlCount := fmt.Sprintf(`
|
|
|
select count(0) from rank
|
|
|
where company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v
|
|
|
`, companyId, rankTypeId, rankRangeId, rankPeriodId)
|
|
|
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
|
|
|
return
|
|
|
}
|
|
|
if v != nil {
|
|
|
if err = utils.ExecuteQueryAll(v, sql); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//排行榜列表-部门
|
|
|
func GetRanksByDepartmentSelf(companyId int64, rankTypeId, rankRangeId, rankPeriodId int, key string, relationId int64, v interface{}) (err error) {
|
|
|
sql := fmt.Sprintf(`select * from (
|
|
|
select a.*,(@rowno:=@rowno+1) as ranking from (
|
|
|
select a.%v score,a.relation_id,c.name from rank a inner join department c on a.relation_id=c.id
|
|
|
where a.company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v
|
|
|
order by a.%v desc,c.create_at asc
|
|
|
) a,(select (@rowno:=0)) b
|
|
|
)a
|
|
|
where a.relation_id=%v
|
|
|
|
|
|
`, key, companyId, rankTypeId, rankRangeId, rankPeriodId, key, relationId)
|
|
|
|
|
|
if v != nil {
|
|
|
if err = utils.ExecuteQueryOne(v, sql); err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
...
|
...
|
|