作者 yangfu

部门统计修改

... ... @@ -35,7 +35,7 @@ func (this *RankController) GetRankList() {
}
//GetRankType 获取榜单类型列表 (年榜/赛季榜)
// @router /getRankType [post]
// @router /getRankTypes [post]
func (this *RankController) GetRankType() {
var msg *protocol.ResponseMessage
defer func() {
... ... @@ -56,7 +56,7 @@ func (this *RankController) GetRankType() {
}
//GetRankRange 获取榜单竞争范围列表
//@router /getRankRange [post]
//@router /getRankRanges [post]
func (this *RankController) GetRankRange() {
var msg *protocol.ResponseMessage
defer func() {
... ...
... ... @@ -13,7 +13,6 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket"
"opp/internal/utils"
_ "opp/routers"
"opp/services/contrab"
"os"
"strings"
"time"
... ... @@ -92,7 +91,7 @@ func main() {
//beego.BConfig.Listen.HTTPSPort = 8089
//beego.BConfig.Listen.HTTPSCertFile = "conf/server.crt"
//beego.BConfig.Listen.HTTPSKeyFile = "conf/server.key"
contrab.Run()
//contrab.Run()
beego.Run()
}
... ...
... ... @@ -76,3 +76,33 @@ func GetRank(companyId, rankTypeId, rankRangeId, rankPeriodId int, relationId in
}
return nil, err
}
//func GetRanksByUser(companyId, rankTypeId, rankRangeId, rankPeriodId int, relationId int64,v interface{})(total int, err error) {
// //var filterDepartment string = getFilterSqlByDIds(dIds)
// 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
//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=?
//limit %v,%v
//)a inner join user b on a.user_id = b.id
//`, companyId,rankTypeId,rankRangeId,rankPeriodId,)
//
// //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 and status=1 %v
//) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId, filterDepartment)
// 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
//}
... ...
... ... @@ -81,9 +81,15 @@ func DeleteRankPeriod(id int) (err error) {
}
//获取进行中的赛季周期 状态 0:未开始 1:开始 2:结束
func GetRankPeriods(status []int) (v []*RankPeriod, err error) {
func GetRankPeriods(companyId int, rankTypeId int, status []int) (v []*RankPeriod, err error) {
sql := mybeego.NewSqlExutor()
sql.Table((&RankPeriod{}).TableName())
if companyId > 0 {
sql.Where(fmt.Sprintf("company_id=%v", companyId))
}
if rankTypeId > 0 {
sql.Where(fmt.Sprintf("rank_type_id=%v", rankTypeId))
}
if len(status) > 0 {
sql.Where(fmt.Sprintf("status in (%v)", utils.JoinInts(status, ",")))
}
... ...
... ... @@ -79,12 +79,15 @@ func DeleteRankRange(id int) (err error) {
}
//获取榜单范围数据
func GetRankRanges(companyId int) (v []*RankRange, err error) {
func GetRankRanges(companyId int, rankTypeId int) (v []*RankRange, err error) {
sql := mybeego.NewSqlExutor()
sql.Table((&RankRange{}).TableName())
if companyId > 0 {
sql.Where(fmt.Sprintf("company_id=%v", companyId))
}
if rankTypeId > 0 {
sql.Where(fmt.Sprintf("rank_type_id=%v", rankTypeId))
}
sql.Order("sort_num")
_, err = sql.Querys(&v)
return
... ...
... ... @@ -45,6 +45,7 @@ type RankType struct {
/*GetRankRange */
type GetRankRangeRequest struct {
RankTypeId int `json:"rankTypeId" valid:"Required"`
}
type GetRankRangeResponse struct {
List []NameItem `json:"rankRanges"`
... ... @@ -52,6 +53,7 @@ type GetRankRangeResponse struct {
/*GetRankPeriods 获取榜单竞争范围列表*/
type GetRankPeriodsRequest struct {
RankTypeId int `json:"rankTypeId" valid:"Required"`
}
type GetRankPeriodsResponse struct {
List []RankPeriod `json:"rankPeriods"`
... ...
... ... @@ -474,7 +474,7 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"],
beego.ControllerComments{
Method: "GetRankRange",
Router: `/getRankRange`,
Router: `/getRankRanges`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
... ... @@ -482,7 +482,7 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"],
beego.ControllerComments{
Method: "GetRankType",
Router: `/getRankType`,
Router: `/getRankTypes`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
... ...
... ... @@ -25,6 +25,7 @@ func init() {
beego.NSNamespace("config", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ConfigController{})),
beego.NSNamespace("file", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.FileController{})),
beego.NSNamespace("achievement", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.AchievementController{})),
beego.NSNamespace("rank", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.RankController{})),
)
beego.AddNamespace(nsV1)
... ...
... ... @@ -3,7 +3,7 @@ package contrab
import "github.com/astaxie/beego/toolbox"
var (
taskComputeRankScore = "0 5 0 * * *" //每0:5分 计算排行榜分数
taskComputeRankScore = "0 46 8 * * *" //每0:5分 计算排行榜分数
)
func Run() {
... ...
... ... @@ -51,6 +51,7 @@ func ComputeRankScore() error {
}
}()
if !atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 0, 1) {
log.Warn("ComputeRankScore is working", ComputeRankScoreFlag)
return fmt.Errorf("ComputeRankScore is working. try later")
} else {
defer utils.Profiling("ComputeRankScore 执行耗时")()
... ... @@ -73,13 +74,13 @@ func computeRankScore() (err error) {
}
}()
//1.l 查询进行中的赛季
if periods, err = models.GetRankPeriods([]int{protocol.RankPeriodBegin}); err != nil {
if periods, err = models.GetRankPeriods(0, 0, []int{protocol.RankPeriodBegin}); err != nil {
return
}
//2.查询对应 rank_type_id 的rank_data
for i := range periods {
period := periods[i]
if rankRanges, err = models.GetRankRanges(period.CompanyId); err == orm.ErrNoRows {
if rankRanges, err = models.GetRankRanges(period.CompanyId, period.RankTypeId); err == orm.ErrNoRows {
continue
}
//所有部门
... ... @@ -229,7 +230,7 @@ type RankDiscovery struct{}
func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult) {
var (
sql = `select sum(discovery_score) score,count(0) total from chance where user_id =? and review_status=3
sql = `select sum(discovery_score) score,count(0) total from chance where user_id =? and review_status=3 and status=1
and UNIX_TIMESTAMP(approve_time)>=? and UNIX_TIMESTAMP(approve_time)<?`
score float64
total int
... ... @@ -245,7 +246,7 @@ func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult)
}
func (rank RankDiscovery) RankDepartment(o RankOption) (err error, result RankResult) {
var (
sql = `select sum(discovery_score) score,count(0) total from chance where department_id =? and review_status=3
sql = `select sum(discovery_score) score,count(0) total from chance where department_id =? and review_status=3 and status=1
and UNIX_TIMESTAMP(approve_time)>=? and UNIX_TIMESTAMP(approve_time)<?
`
score float64
... ...
... ... @@ -43,9 +43,9 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe
}
rsp.Departments = tmpDepartment.Departments
rsp.Departments = rsp.GetRootDepartment()
for i := range rsp.Departments {
rsp.Departments[i].Departments = make([]*protocol.Department, 0)
}
//for i := range rsp.Departments {
// rsp.Departments[i].Departments = make([]*protocol.Department, 0)
//}
default:
break
}
... ...
... ... @@ -9,7 +9,10 @@ import (
//排行榜
func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRequest) (rsp *protocol.GetRankListResponse, err error) {
var ()
var (
ranks []*models.Rank
)
rsp = &protocol.GetRankListResponse{}
return
}
... ... @@ -39,7 +42,7 @@ func GetRankRange(header *protocol.RequestHeader, request *protocol.GetRankRange
var (
lists []*models.RankRange
)
if lists, err = models.GetRankRanges(int(header.CompanyId)); err != nil {
if lists, err = models.GetRankRanges(int(header.CompanyId), request.RankTypeId); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -60,7 +63,7 @@ func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPer
lists []*models.RankPeriod
)
rsp = &protocol.GetRankPeriodsResponse{List: make([]protocol.RankPeriod, 0)}
if lists, err = models.GetRankPeriods([]int{protocol.RankPeriodBegin, protocol.RankPeriodEnd}); err != nil {
if lists, err = models.GetRankPeriods(int(header.CompanyId), request.RankTypeId, []int{protocol.RankPeriodBegin, protocol.RankPeriodEnd}); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ...