正在显示
11 个修改的文件
包含
162 行增加
和
44 行删除
@@ -13,6 +13,7 @@ import ( | @@ -13,6 +13,7 @@ import ( | ||
13 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" | 13 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" |
14 | "opp/internal/utils" | 14 | "opp/internal/utils" |
15 | _ "opp/routers" | 15 | _ "opp/routers" |
16 | + "opp/services/contrab" | ||
16 | "os" | 17 | "os" |
17 | "strings" | 18 | "strings" |
18 | "time" | 19 | "time" |
@@ -91,7 +92,7 @@ func main() { | @@ -91,7 +92,7 @@ func main() { | ||
91 | //beego.BConfig.Listen.HTTPSPort = 8089 | 92 | //beego.BConfig.Listen.HTTPSPort = 8089 |
92 | //beego.BConfig.Listen.HTTPSCertFile = "conf/server.crt" | 93 | //beego.BConfig.Listen.HTTPSCertFile = "conf/server.crt" |
93 | //beego.BConfig.Listen.HTTPSKeyFile = "conf/server.key" | 94 | //beego.BConfig.Listen.HTTPSKeyFile = "conf/server.key" |
94 | - //contrab.Run() | 95 | + contrab.Run() |
95 | 96 | ||
96 | beego.Run() | 97 | beego.Run() |
97 | } | 98 | } |
@@ -100,3 +100,16 @@ select id from department where company_id=? and relation like '%v%%' and delet | @@ -100,3 +100,16 @@ select id from department where company_id=? and relation like '%v%%' and delet | ||
100 | } | 100 | } |
101 | return | 101 | return |
102 | } | 102 | } |
103 | + | ||
104 | +func GetDepartmentIdsByCompanyId(companyId int) (v []int64, err error) { | ||
105 | + o := orm.NewOrm() | ||
106 | + sql := ` | ||
107 | +select id | ||
108 | +from department | ||
109 | +where company_id =? and delete_at =0 | ||
110 | +order by parent_id,id` | ||
111 | + if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil { | ||
112 | + return | ||
113 | + } | ||
114 | + return | ||
115 | +} |
@@ -8,7 +8,7 @@ import ( | @@ -8,7 +8,7 @@ import ( | ||
8 | ) | 8 | ) |
9 | 9 | ||
10 | type Rank struct { | 10 | type Rank struct { |
11 | - Id int `orm:"column(id);auto"` | 11 | + Id int64 `orm:"column(id);auto"` |
12 | CompanyId int `orm:"column(company_id)" description:"公司编号 表company.id"` | 12 | CompanyId int `orm:"column(company_id)" description:"公司编号 表company.id"` |
13 | RankTypeId int `orm:"column(rank_type_id)" description:"榜单类型编号"` | 13 | RankTypeId int `orm:"column(rank_type_id)" description:"榜单类型编号"` |
14 | RankRangeId int `orm:"column(rank_range_id)" description:"榜单范围编号"` | 14 | RankRangeId int `orm:"column(rank_range_id)" description:"榜单范围编号"` |
@@ -43,7 +43,7 @@ func AddRank(m *Rank) (id int64, err error) { | @@ -43,7 +43,7 @@ func AddRank(m *Rank) (id int64, err error) { | ||
43 | 43 | ||
44 | // GetRankById retrieves Rank by Id. Returns error if | 44 | // GetRankById retrieves Rank by Id. Returns error if |
45 | // Id doesn't exist | 45 | // Id doesn't exist |
46 | -func GetRankById(id int) (v *Rank, err error) { | 46 | +func GetRankById(id int64) (v *Rank, err error) { |
47 | o := orm.NewOrm() | 47 | o := orm.NewOrm() |
48 | v = &Rank{Id: id} | 48 | v = &Rank{Id: id} |
49 | if err = o.Read(v); err == nil { | 49 | if err = o.Read(v); err == nil { |
@@ -70,8 +70,8 @@ func UpdateRankById(m *Rank) (err error) { | @@ -70,8 +70,8 @@ func UpdateRankById(m *Rank) (err error) { | ||
70 | //取用户当前榜单数据 | 70 | //取用户当前榜单数据 |
71 | func GetRank(companyId, rankTypeId, rankRangeId, rankPeriodId int, relationId int64) (v *Rank, err error) { | 71 | func GetRank(companyId, rankTypeId, rankRangeId, rankPeriodId int, relationId int64) (v *Rank, err error) { |
72 | o := orm.NewOrm() | 72 | o := orm.NewOrm() |
73 | - sql := "select * from rank where company_id=? and rank_type_id=? and rank_period_id=? and relation_id=?" | ||
74 | - if err = o.Raw(sql, companyId, rankTypeId, rankRangeId, rankPeriodId, relationId).QueryRow(v); err == nil { | 73 | + sql := "select * from rank where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id=? and relation_id=?" |
74 | + if err = o.Raw(sql, companyId, rankTypeId, rankRangeId, rankPeriodId, relationId).QueryRow(&v); err == nil { | ||
75 | return v, nil | 75 | return v, nil |
76 | } | 76 | } |
77 | return nil, err | 77 | return nil, err |
@@ -83,7 +83,7 @@ func GetRankRanges(companyId int) (v []*RankRange, err error) { | @@ -83,7 +83,7 @@ func GetRankRanges(companyId int) (v []*RankRange, err error) { | ||
83 | sql := mybeego.NewSqlExutor() | 83 | sql := mybeego.NewSqlExutor() |
84 | sql.Table((&RankRange{}).TableName()) | 84 | sql.Table((&RankRange{}).TableName()) |
85 | if companyId > 0 { | 85 | if companyId > 0 { |
86 | - sql.Where(fmt.Sprintf("companyId=%v", companyId)) | 86 | + sql.Where(fmt.Sprintf("company_id=%v", companyId)) |
87 | } | 87 | } |
88 | sql.Order("sort_num") | 88 | sql.Order("sort_num") |
89 | _, err = sql.Querys(&v) | 89 | _, err = sql.Querys(&v) |
@@ -2,19 +2,20 @@ package models | @@ -2,19 +2,20 @@ package models | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
5 | "time" | 6 | "time" |
6 | 7 | ||
7 | "github.com/astaxie/beego/orm" | 8 | "github.com/astaxie/beego/orm" |
8 | ) | 9 | ) |
9 | 10 | ||
10 | type RankType struct { | 11 | type RankType struct { |
11 | - Id int `orm:"column(id);auto"` | ||
12 | - Name string `orm:"column(name);size(50)" description:"榜单名称"` | ||
13 | - CompanyId int `orm:"column(company_id)" description:"公司编号 company.id"` | ||
14 | - CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
15 | - UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` | ||
16 | - EnableStatus int8 `orm:"column(enable_status);null" description:"是否有效 【1:禁用】【2:启用】"` | ||
17 | - Type int8 `orm:"column(type);null" description:"榜单类型(1赛季榜、2年榜)"` | 12 | + Id int `orm:"column(id);auto" json:"id"` |
13 | + Name string `orm:"column(name);size(50)" description:"榜单名称" json:"name"` | ||
14 | + CompanyId int `orm:"column(company_id)" description:"公司编号 company.id" json:"-"` | ||
15 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间" json:"-"` | ||
16 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间" json:"-"` | ||
17 | + EnableStatus int8 `orm:"column(enable_status);null" description:"是否有效 【1:禁用】【2:启用】" json:"-"` | ||
18 | + Type int8 `orm:"column(type);null" description:"榜单类型(1赛季榜、2年榜) json:"type"` | ||
18 | } | 19 | } |
19 | 20 | ||
20 | func (t *RankType) TableName() string { | 21 | func (t *RankType) TableName() string { |
@@ -73,3 +74,17 @@ func DeleteRankType(id int) (err error) { | @@ -73,3 +74,17 @@ func DeleteRankType(id int) (err error) { | ||
73 | } | 74 | } |
74 | return | 75 | return |
75 | } | 76 | } |
77 | + | ||
78 | +// | ||
79 | +func GetRankTypes(companyId int64) (v []*RankType, err error) { | ||
80 | + sql := mybeego.NewSqlExutor() | ||
81 | + sql.Table((&RankType{}).TableName()) | ||
82 | + if companyId > 0 { | ||
83 | + sql.Where(fmt.Sprintf("company_id=%v", companyId)) | ||
84 | + } | ||
85 | + sql.Where(fmt.Sprintf("enable_status=2")) | ||
86 | + sql.Order("type") | ||
87 | + sql.Limit(0, 2) | ||
88 | + _, err = sql.Querys(&v) | ||
89 | + return | ||
90 | +} |
@@ -109,3 +109,12 @@ func GetUserCompanysFirst(uid int64) (v *UserCompany, err error) { | @@ -109,3 +109,12 @@ func GetUserCompanysFirst(uid int64) (v *UserCompany, err error) { | ||
109 | } | 109 | } |
110 | return nil, err | 110 | return nil, err |
111 | } | 111 | } |
112 | + | ||
113 | +func GetUserCompanyIdAll(companyId int) (v []int64, err error) { | ||
114 | + o := orm.NewOrm() | ||
115 | + sql := "select id from user_company where company_id=? and enable=1" //and enable=1 | ||
116 | + if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil { | ||
117 | + return v, nil | ||
118 | + } | ||
119 | + return nil, err | ||
120 | +} |
@@ -9,7 +9,7 @@ type GetConfigScoreResponse struct { | @@ -9,7 +9,7 @@ type GetConfigScoreResponse struct { | ||
9 | 9 | ||
10 | type ScoreConfig struct { | 10 | type ScoreConfig struct { |
11 | DiscoveryScore *DiscoveryScore `json:"discoveryScore"` | 11 | DiscoveryScore *DiscoveryScore `json:"discoveryScore"` |
12 | - SumScore *SumScore `json:"-"` //sumScore | 12 | + SumScore *SumScore `json:"sumScore"` //sumScore |
13 | BasicScore *ScoreRange `json:"basicScore"` | 13 | BasicScore *ScoreRange `json:"basicScore"` |
14 | ExtraScore *ScoreRange `json:"extraScore"` | 14 | ExtraScore *ScoreRange `json:"extraScore"` |
15 | ValueScore *ScoreRange `json:"valueScore"` | 15 | ValueScore *ScoreRange `json:"valueScore"` |
@@ -36,7 +36,7 @@ type RankItem struct { | @@ -36,7 +36,7 @@ type RankItem struct { | ||
36 | type GetRankTypeRequest struct { | 36 | type GetRankTypeRequest struct { |
37 | } | 37 | } |
38 | type GetRankTypeResponse struct { | 38 | type GetRankTypeResponse struct { |
39 | - List []RankType | 39 | + List []NameItem `json:"rankTypes"` |
40 | } | 40 | } |
41 | type RankType struct { | 41 | type RankType struct { |
42 | Id int `json:"id"` | 42 | Id int `json:"id"` |
@@ -47,12 +47,19 @@ type RankType struct { | @@ -47,12 +47,19 @@ type RankType struct { | ||
47 | type GetRankRangeRequest struct { | 47 | type GetRankRangeRequest struct { |
48 | } | 48 | } |
49 | type GetRankRangeResponse struct { | 49 | type GetRankRangeResponse struct { |
50 | -} | ||
51 | -type RankRange struct { | 50 | + List []NameItem `json:"rankRanges"` |
52 | } | 51 | } |
53 | 52 | ||
54 | /*GetRankPeriods 获取榜单竞争范围列表*/ | 53 | /*GetRankPeriods 获取榜单竞争范围列表*/ |
55 | type GetRankPeriodsRequest struct { | 54 | type GetRankPeriodsRequest struct { |
56 | } | 55 | } |
57 | type GetRankPeriodsResponse struct { | 56 | type GetRankPeriodsResponse struct { |
57 | + List []RankPeriod `json:"rankPeriods"` | ||
58 | +} | ||
59 | + | ||
60 | +type RankPeriod struct { | ||
61 | + Id int `json:"id"` | ||
62 | + SeasonName string `json:"seasonName"` | ||
63 | + BeginTime int64 `json:"beginTime"` | ||
64 | + EndTime int64 `json:"endTime"` | ||
58 | } | 65 | } |
@@ -7,6 +7,8 @@ var ( | @@ -7,6 +7,8 @@ var ( | ||
7 | ) | 7 | ) |
8 | 8 | ||
9 | func Run() { | 9 | func Run() { |
10 | + //ComputeRankScore() | ||
11 | + | ||
10 | taskRank := toolbox.NewTask("taskComputeRankScore", taskComputeRankScore, ComputeRankScore) | 12 | taskRank := toolbox.NewTask("taskComputeRankScore", taskComputeRankScore, ComputeRankScore) |
11 | toolbox.AddTask("taskComputeRankScore", taskRank) | 13 | toolbox.AddTask("taskComputeRankScore", taskRank) |
12 | 14 |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "encoding/json" | 4 | "encoding/json" |
5 | "fmt" | 5 | "fmt" |
6 | "github.com/astaxie/beego/orm" | 6 | "github.com/astaxie/beego/orm" |
7 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen" | ||
7 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 8 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
8 | "opp/internal/utils" | 9 | "opp/internal/utils" |
9 | "opp/models" | 10 | "opp/models" |
@@ -57,7 +58,7 @@ func ComputeRankScore() error { | @@ -57,7 +58,7 @@ func ComputeRankScore() error { | ||
57 | defer func() { | 58 | defer func() { |
58 | atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 1, 0) | 59 | atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 1, 0) |
59 | }() | 60 | }() |
60 | - | 61 | + //TODO:启用多个协程执行 |
61 | return computeRankScore() | 62 | return computeRankScore() |
62 | } | 63 | } |
63 | func computeRankScore() (err error) { | 64 | func computeRankScore() (err error) { |
@@ -82,18 +83,26 @@ func computeRankScore() (err error) { | @@ -82,18 +83,26 @@ func computeRankScore() (err error) { | ||
82 | continue | 83 | continue |
83 | } | 84 | } |
84 | //所有部门 | 85 | //所有部门 |
85 | - | 86 | + depIdAll, e := models.GetDepartmentIdsByCompanyId(period.CompanyId) |
87 | + if e != nil { | ||
88 | + log.Error(e) | ||
89 | + continue | ||
90 | + } | ||
86 | //所有用户 | 91 | //所有用户 |
87 | - | 92 | + userIdAll, e := models.GetUserCompanyIdAll(period.CompanyId) |
93 | + if e != nil { | ||
94 | + log.Error(e) | ||
95 | + continue | ||
96 | + } | ||
88 | //按类型 | 97 | //按类型 |
89 | //3.查询用户列表/部门列表 | 98 | //3.查询用户列表/部门列表 |
90 | for j := range rankRanges { | 99 | for j := range rankRanges { |
91 | var relationIds []int64 | 100 | var relationIds []int64 |
92 | rankRange := rankRanges[j] | 101 | rankRange := rankRanges[j] |
93 | if rankRange.Type == protocol.RankRangeTypeAllCompanyUser { | 102 | if rankRange.Type == protocol.RankRangeTypeAllCompanyUser { |
94 | - | 103 | + relationIds = userIdAll |
95 | } else if rankRange.Type == protocol.RankRangeTypeAllCompanyDepartment { | 104 | } else if rankRange.Type == protocol.RankRangeTypeAllCompanyDepartment { |
96 | - | 105 | + relationIds = depIdAll |
97 | } else { | 106 | } else { |
98 | if rankRangeDatas, err = models.GetRankRangeDataList(rankRange.Id); err == orm.ErrNoRows { | 107 | if rankRangeDatas, err = models.GetRankRangeDataList(rankRange.Id); err == orm.ErrNoRows { |
99 | continue | 108 | continue |
@@ -124,6 +133,8 @@ func updateRankByRelationIds(relationIds []int64, period *models.RankPeriod, ran | @@ -124,6 +133,8 @@ func updateRankByRelationIds(relationIds []int64, period *models.RankPeriod, ran | ||
124 | RankPeriodId: period.Id, | 133 | RankPeriodId: period.Id, |
125 | RelationId: relationIds[i], | 134 | RelationId: relationIds[i], |
126 | Type: int(rankRange.Type), | 135 | Type: int(rankRange.Type), |
136 | + BeginTime: period.BeginTime, | ||
137 | + EndTime: period.EndTime, | ||
127 | } | 138 | } |
128 | updateRank(option) | 139 | updateRank(option) |
129 | } | 140 | } |
@@ -135,12 +146,13 @@ func updateRank(o RankOption) { | @@ -135,12 +146,13 @@ func updateRank(o RankOption) { | ||
135 | var ( | 146 | var ( |
136 | rank *models.Rank | 147 | rank *models.Rank |
137 | e error | 148 | e error |
138 | - isNew = true | 149 | + isNew = false |
139 | rankTmp models.Rank | 150 | rankTmp models.Rank |
140 | ) | 151 | ) |
141 | - if rank, e = models.GetRank(o.CompanyId, o.RankTypeId, o.RankRangeId, o.RankPeriodId, o.RelationId); e != nil && e == orm.ErrNoRows { | 152 | + if rank, e = models.GetRank(o.CompanyId, o.RankTypeId, o.RankRangeId, o.RankPeriodId, o.RelationId); e != nil { |
142 | isNew = true | 153 | isNew = true |
143 | rank = &models.Rank{ | 154 | rank = &models.Rank{ |
155 | + Id: idgen.Next(), | ||
144 | CompanyId: o.CompanyId, | 156 | CompanyId: o.CompanyId, |
145 | RankTypeId: o.RankTypeId, | 157 | RankTypeId: o.RankTypeId, |
146 | RankRangeId: o.RankRangeId, | 158 | RankRangeId: o.RankRangeId, |
@@ -154,6 +166,7 @@ func updateRank(o RankOption) { | @@ -154,6 +166,7 @@ func updateRank(o RankOption) { | ||
154 | } else { | 166 | } else { |
155 | rankTmp = *rank | 167 | rankTmp = *rank |
156 | } | 168 | } |
169 | + o.Rank = rank | ||
157 | for i := range rankList { | 170 | for i := range rankList { |
158 | item := rankList[i] | 171 | item := rankList[i] |
159 | if o.Type == protocol.RankRangeTypeAllCompanyDepartment || o.Type == protocol.RankRangeTypeAllSpecifyDepartment { | 172 | if o.Type == protocol.RankRangeTypeAllCompanyDepartment || o.Type == protocol.RankRangeTypeAllSpecifyDepartment { |
@@ -169,6 +182,7 @@ func updateRank(o RankOption) { | @@ -169,6 +182,7 @@ func updateRank(o RankOption) { | ||
169 | } else { | 182 | } else { |
170 | //数据有变化的时候才更新到表 | 183 | //数据有变化的时候才更新到表 |
171 | if !reflect.DeepEqual(rankTmp, *rank) { | 184 | if !reflect.DeepEqual(rankTmp, *rank) { |
185 | + rank.UpdateAt = time.Now() | ||
172 | if e = models.UpdateRankById(rank); e != nil { | 186 | if e = models.UpdateRankById(rank); e != nil { |
173 | log.Error(e) | 187 | log.Error(e) |
174 | } | 188 | } |
@@ -192,10 +206,14 @@ company_id=%v and rank_type_id=%v and rank_period_id=%v` | @@ -192,10 +206,14 @@ company_id=%v and rank_type_id=%v and rank_period_id=%v` | ||
192 | return | 206 | return |
193 | } | 207 | } |
194 | if err = json.Unmarshal([]byte(config.Content), &scoreConfig); err != nil { | 208 | if err = json.Unmarshal([]byte(config.Content), &scoreConfig); err != nil { |
195 | - err = protocol.NewErrWithMessage(5510) | 209 | + //err = protocol.NewErrWithMessage(5510) |
196 | log.Error(err) | 210 | log.Error(err) |
197 | return | 211 | return |
198 | } | 212 | } |
213 | + if scoreConfig.SumScore == nil { | ||
214 | + log.Error(o.CompanyId, config.Content, "未设置总分配置") | ||
215 | + return | ||
216 | + } | ||
199 | sql = fmt.Sprintf(sql, | 217 | sql = fmt.Sprintf(sql, |
200 | scoreConfig.SumScore.DiscoveryFactor, | 218 | scoreConfig.SumScore.DiscoveryFactor, |
201 | scoreConfig.SumScore.CatchFactor, o.CompanyId, o.RankTypeId, o.RankPeriodId) | 219 | scoreConfig.SumScore.CatchFactor, o.CompanyId, o.RankTypeId, o.RankPeriodId) |
@@ -211,12 +229,13 @@ type RankDiscovery struct{} | @@ -211,12 +229,13 @@ type RankDiscovery struct{} | ||
211 | 229 | ||
212 | func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult) { | 230 | func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult) { |
213 | var ( | 231 | var ( |
214 | - sql = "select sum(discovery_score) score,count(0) total from chance where user_id =? and review_status=3" | 232 | + sql = `select sum(discovery_score) score,count(0) total from chance where user_id =? and review_status=3 |
233 | + and UNIX_TIMESTAMP(approve_time)>=? and UNIX_TIMESTAMP(approve_time)<?` | ||
215 | score float64 | 234 | score float64 |
216 | total int | 235 | total int |
217 | ) | 236 | ) |
218 | orm := orm.NewOrm() | 237 | orm := orm.NewOrm() |
219 | - if err = orm.Raw(sql, o.RelationId).QueryRow(&score, &total); err != nil { | 238 | + if err = orm.Raw(sql, o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix()).QueryRow(&score, &total); err != nil { |
220 | log.Error(err) | 239 | log.Error(err) |
221 | return | 240 | return |
222 | } | 241 | } |
@@ -226,12 +245,14 @@ func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult) | @@ -226,12 +245,14 @@ func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult) | ||
226 | } | 245 | } |
227 | func (rank RankDiscovery) RankDepartment(o RankOption) (err error, result RankResult) { | 246 | func (rank RankDiscovery) RankDepartment(o RankOption) (err error, result RankResult) { |
228 | var ( | 247 | var ( |
229 | - sql = "select sum(discovery_score) score,count(0) total from chance where department_id =? and review_status=3" | 248 | + sql = `select sum(discovery_score) score,count(0) total from chance where department_id =? and review_status=3 |
249 | + and UNIX_TIMESTAMP(approve_time)>=? and UNIX_TIMESTAMP(approve_time)<? | ||
250 | +` | ||
230 | score float64 | 251 | score float64 |
231 | total int | 252 | total int |
232 | ) | 253 | ) |
233 | orm := orm.NewOrm() | 254 | orm := orm.NewOrm() |
234 | - if err = orm.Raw(sql, o.RelationId).QueryRow(&score, &total); err != nil { | 255 | + if err = orm.Raw(sql, o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix()).QueryRow(&score, &total); err != nil { |
235 | log.Error(err) | 256 | log.Error(err) |
236 | return | 257 | return |
237 | } | 258 | } |
@@ -246,15 +267,15 @@ type RankGrasp struct{} | @@ -246,15 +267,15 @@ type RankGrasp struct{} | ||
246 | func (rank RankGrasp) RankUser(o RankOption) (err error, result RankResult) { | 267 | func (rank RankGrasp) RankUser(o RankOption) (err error, result RankResult) { |
247 | var ( | 268 | var ( |
248 | sql = `select sum(a.user_grasp_score) score from( | 269 | sql = `select sum(a.user_grasp_score) score from( |
249 | -select user_grasp_score from achievement where user_company_id=? | 270 | +select user_grasp_score from achievement where user_company_id=? and UNIX_TIMESTAMP(create_at) >=? and UNIX_TIMESTAMP(create_at)<? |
250 | UNION ALL | 271 | UNION ALL |
251 | -select user_grasp_score from achievement_provider where user_company_id=? | 272 | +select user_grasp_score from achievement_provider where user_company_id=? and UNIX_TIMESTAMP(create_at) >=? and UNIX_TIMESTAMP(create_at)<? |
252 | ) a | 273 | ) a |
253 | ` | 274 | ` |
254 | score float64 | 275 | score float64 |
255 | ) | 276 | ) |
256 | orm := orm.NewOrm() | 277 | orm := orm.NewOrm() |
257 | - if err = orm.Raw(sql, o.RelationId, o.RelationId).QueryRow(&score); err != nil { | 278 | + if err = orm.Raw(sql, o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix(), o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix()).QueryRow(&score); err != nil { |
258 | log.Error(err) | 279 | log.Error(err) |
259 | return | 280 | return |
260 | } | 281 | } |
@@ -264,15 +285,15 @@ select user_grasp_score from achievement_provider where user_company_id=? | @@ -264,15 +285,15 @@ select user_grasp_score from achievement_provider where user_company_id=? | ||
264 | func (rank RankGrasp) RankDepartment(o RankOption) (err error, result RankResult) { | 285 | func (rank RankGrasp) RankDepartment(o RankOption) (err error, result RankResult) { |
265 | var ( | 286 | var ( |
266 | sql = `select sum(a.user_grasp_score) score from( | 287 | sql = `select sum(a.user_grasp_score) score from( |
267 | -select user_grasp_score from achievement where department_id=? | 288 | +select user_grasp_score from achievement where department_id=? and UNIX_TIMESTAMP(create_at) >=? and UNIX_TIMESTAMP(create_at)<? |
268 | UNION ALL | 289 | UNION ALL |
269 | -select user_grasp_score from achievement_provider where department_id=? | 290 | +select user_grasp_score from achievement_provider where department_id=? and UNIX_TIMESTAMP(create_at) >=? and UNIX_TIMESTAMP(create_at)<? |
270 | ) a | 291 | ) a |
271 | ` | 292 | ` |
272 | score float64 | 293 | score float64 |
273 | ) | 294 | ) |
274 | orm := orm.NewOrm() | 295 | orm := orm.NewOrm() |
275 | - if err = orm.Raw(sql, o.RelationId, o.RelationId).QueryRow(&score); err != nil { | 296 | + if err = orm.Raw(sql, o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix(), o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix()).QueryRow(&score); err != nil { |
276 | log.Error(err) | 297 | log.Error(err) |
277 | return | 298 | return |
278 | } | 299 | } |
@@ -285,12 +306,12 @@ type RankComment struct{} | @@ -285,12 +306,12 @@ type RankComment struct{} | ||
285 | 306 | ||
286 | func (rank RankComment) RankUser(o RankOption) (err error, result RankResult) { | 307 | func (rank RankComment) RankUser(o RankOption) (err error, result RankResult) { |
287 | var ( | 308 | var ( |
288 | - sql = `select count(0) total from comment where user_id=? | 309 | + sql = `select count(0) total from comment where user_id=? and UNIX_TIMESTAMP(create_at) >=? and UNIX_TIMESTAMP(create_at)<? |
289 | ` | 310 | ` |
290 | total int | 311 | total int |
291 | ) | 312 | ) |
292 | orm := orm.NewOrm() | 313 | orm := orm.NewOrm() |
293 | - if err = orm.Raw(sql, o.RelationId).QueryRow(&total); err != nil { | 314 | + if err = orm.Raw(sql, o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix()).QueryRow(&total); err != nil { |
294 | log.Error(err) | 315 | log.Error(err) |
295 | return | 316 | return |
296 | } | 317 | } |
@@ -299,7 +320,7 @@ func (rank RankComment) RankUser(o RankOption) (err error, result RankResult) { | @@ -299,7 +320,7 @@ func (rank RankComment) RankUser(o RankOption) (err error, result RankResult) { | ||
299 | } | 320 | } |
300 | func (rank RankComment) RankDepartment(o RankOption) (err error, result RankResult) { | 321 | func (rank RankComment) RankDepartment(o RankOption) (err error, result RankResult) { |
301 | var ( | 322 | var ( |
302 | - sql = `select count(0) total from comment where user_id in (%v) | 323 | + sql = `select count(0) total from comment where user_id in (%v) and UNIX_TIMESTAMP(create_at) >=%v and UNIX_TIMESTAMP(create_at)<%v |
303 | ` | 324 | ` |
304 | sqlUserDepartment = `select user_company_id from user_department where department_id=?` | 325 | sqlUserDepartment = `select user_company_id from user_department where department_id=?` |
305 | total int | 326 | total int |
@@ -313,7 +334,7 @@ func (rank RankComment) RankDepartment(o RankOption) (err error, result RankResu | @@ -313,7 +334,7 @@ func (rank RankComment) RankDepartment(o RankOption) (err error, result RankResu | ||
313 | if len(userIds) == 0 { | 334 | if len(userIds) == 0 { |
314 | return | 335 | return |
315 | } | 336 | } |
316 | - sql = fmt.Sprintf(sql, utils.JoinInts(userIds, ",")) | 337 | + sql = fmt.Sprintf(sql, utils.JoinInts(userIds, ","), o.BeginTime.Unix(), o.EndTime.Unix()) |
317 | if err = orm.Raw(sql).QueryRow(&total); err != nil { | 338 | if err = orm.Raw(sql).QueryRow(&total); err != nil { |
318 | log.Error(err) | 339 | log.Error(err) |
319 | return | 340 | return |
1 | package rank | 1 | package rank |
2 | 2 | ||
3 | -import "opp/protocol" | 3 | +import ( |
4 | + "github.com/astaxie/beego/orm" | ||
5 | + "github.com/prometheus/common/log" | ||
6 | + "opp/models" | ||
7 | + "opp/protocol" | ||
8 | +) | ||
4 | 9 | ||
5 | //排行榜 | 10 | //排行榜 |
6 | func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRequest) (rsp *protocol.GetRankListResponse, err error) { | 11 | func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRequest) (rsp *protocol.GetRankListResponse, err error) { |
@@ -11,21 +16,66 @@ func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRe | @@ -11,21 +16,66 @@ func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRe | ||
11 | 16 | ||
12 | //获取榜单类型列表 | 17 | //获取榜单类型列表 |
13 | func GetRankType(header *protocol.RequestHeader, request *protocol.GetRankTypeRequest) (rsp *protocol.GetRankTypeResponse, err error) { | 18 | func GetRankType(header *protocol.RequestHeader, request *protocol.GetRankTypeRequest) (rsp *protocol.GetRankTypeResponse, err error) { |
14 | - var () | 19 | + var ( |
20 | + lists []*models.RankType | ||
21 | + ) | ||
22 | + if lists, err = models.GetRankTypes(header.CompanyId); err != nil { | ||
23 | + if err == orm.ErrNoRows { | ||
24 | + err = nil | ||
25 | + return | ||
26 | + } | ||
27 | + log.Error(err) | ||
28 | + return | ||
29 | + } | ||
15 | rsp = &protocol.GetRankTypeResponse{} | 30 | rsp = &protocol.GetRankTypeResponse{} |
31 | + for i := range lists { | ||
32 | + rsp.List = append(rsp.List, protocol.NameItem{Id: lists[i].Id, Name: lists[i].Name}) | ||
33 | + } | ||
16 | return | 34 | return |
17 | } | 35 | } |
18 | 36 | ||
19 | //获取榜单范围列表 | 37 | //获取榜单范围列表 |
20 | func GetRankRange(header *protocol.RequestHeader, request *protocol.GetRankRangeRequest) (rsp *protocol.GetRankRangeResponse, err error) { | 38 | func GetRankRange(header *protocol.RequestHeader, request *protocol.GetRankRangeRequest) (rsp *protocol.GetRankRangeResponse, err error) { |
21 | - var () | 39 | + var ( |
40 | + lists []*models.RankRange | ||
41 | + ) | ||
42 | + if lists, err = models.GetRankRanges(int(header.CompanyId)); err != nil { | ||
43 | + if err == orm.ErrNoRows { | ||
44 | + err = nil | ||
45 | + return | ||
46 | + } | ||
47 | + log.Error(err) | ||
48 | + return | ||
49 | + } | ||
22 | rsp = &protocol.GetRankRangeResponse{} | 50 | rsp = &protocol.GetRankRangeResponse{} |
51 | + for i := range lists { | ||
52 | + rsp.List = append(rsp.List, protocol.NameItem{Id: lists[i].Id, Name: lists[i].Name}) | ||
53 | + } | ||
23 | return | 54 | return |
24 | } | 55 | } |
25 | 56 | ||
26 | //获取排行榜周期列表 | 57 | //获取排行榜周期列表 |
27 | func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPeriodsRequest) (rsp *protocol.GetRankPeriodsResponse, err error) { | 58 | func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPeriodsRequest) (rsp *protocol.GetRankPeriodsResponse, err error) { |
28 | - var () | ||
29 | - rsp = &protocol.GetRankPeriodsResponse{} | 59 | + var ( |
60 | + lists []*models.RankPeriod | ||
61 | + ) | ||
62 | + rsp = &protocol.GetRankPeriodsResponse{List: make([]protocol.RankPeriod, 0)} | ||
63 | + if lists, err = models.GetRankPeriods([]int{protocol.RankPeriodBegin, protocol.RankPeriodEnd}); err != nil { | ||
64 | + if err == orm.ErrNoRows { | ||
65 | + err = nil | ||
66 | + return | ||
67 | + } | ||
68 | + log.Error(err) | ||
69 | + return | ||
70 | + } | ||
71 | + for i := range lists { | ||
72 | + item := lists[i] | ||
73 | + rsp.List = append(rsp.List, protocol.RankPeriod{ | ||
74 | + Id: item.Id, | ||
75 | + SeasonName: item.SeasonName, | ||
76 | + BeginTime: item.BeginTime.Unix() * 1000, | ||
77 | + EndTime: item.EndTime.Unix() * 1000, | ||
78 | + }) | ||
79 | + } | ||
30 | return | 80 | return |
31 | } | 81 | } |
-
请 注册 或 登录 后发表评论