Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-group
Commits
a6c36dee
Commit
a6c36dee
authored
Mar 08, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:家族榜单
parent
3534f327
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
169 additions
and
0 deletions
+169
-0
group_rank.go
cv/group_power_cv/group_rank.go
+22
-0
group_grade.go
domain/model/groupPower_m/group_grade.go
+14
-0
group_rank.go
domain/model/groupPower_m/group_rank.go
+37
-0
group_rank.go
route/group_power_r/group_rank.go
+95
-0
router.go
route/router.go
+1
-0
No files found.
cv/group_power_cv/group_rank.go
0 → 100644
View file @
a6c36dee
package
group_power_cv
import
(
"git.hilo.cn/hilo-common/resource/mysql"
"hilo-group/_const/enum/groupPower_e"
)
type
CvGroupPowerRankData
struct
{
GroupPowerId
mysql
.
ID
`json:"groupPowerId"`
// 家族id
GroupPic
string
`json:"groupPic"`
// 家族图片
Name
string
`json:"name"`
// 家族名
Nameplate
string
`json:"nameplate"`
// 铭牌
Grade
groupPower_e
.
GroupPowerGrade
`json:"grade"`
// 等级 0:无 1:青铜 2:白银 3:黄金 4:黑金
Exp
mysql
.
Num
`json:"exp"`
// 经验值
Rank
int
`json:"rank"`
// 排名
// todo 铭牌,图片等字段, 等伟健哥哥的结构体
}
type
CvGroupPowerRank
struct
{
MyGroupPower
CvGroupPowerRankData
`json:"myGroupPower"`
Items
[]
CvGroupPowerRankData
`json:"items"`
}
domain/model/groupPower_m/group_grade.go
View file @
a6c36dee
...
...
@@ -271,3 +271,17 @@ func ClearGroupPowerGrade(model *domain.Model) error {
return
nil
})
}
// 批量获取家族等级
func
MGetGroupPowerGrade
(
model
*
domain
.
Model
,
groupPowerIds
[]
mysql
.
ID
)
(
map
[
mysql
.
ID
]
GroupPowerGrade
,
error
)
{
var
rows
[]
GroupPowerGrade
res
:=
make
(
map
[
mysql
.
ID
]
GroupPowerGrade
)
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerGrade
{})
.
Where
(
"group_power_id in ?"
,
groupPowerIds
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"MGetGroupPowerGrade fail:%v"
,
err
)
return
res
,
err
}
for
i
,
v
:=
range
rows
{
res
[
v
.
GroupPowerId
]
=
rows
[
i
]
}
return
res
,
nil
}
domain/model/groupPower_m/group_rank.go
0 → 100644
View file @
a6c36dee
package
groupPower_m
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
)
type
GroupPowerExpRank
struct
{
GroupPowerId
mysql
.
ID
Exp
mysql
.
Num
Rank
int
}
// 获取家族经验排行榜
// param limit: 排行榜人数
func
GetGroupPowerExpRank
(
model
*
domain
.
Model
,
beginDate
,
endDate
string
,
limit
int
)
([]
GroupPowerExpRank
,
error
)
{
var
res
[]
GroupPowerExpRank
if
err
:=
model
.
DB
()
.
Table
(
"group_power_day_exp p"
)
.
Joins
(
",(SELECT @curRank := 0) p"
)
.
Where
(
"date BETWEEN ? AND ?"
,
beginDate
,
endDate
)
.
Select
(
"group_power_id,SUM(exp) as exp,@curRank := @curRank + 1 `rank`"
)
.
Group
(
"group_power_id"
)
.
Order
(
"exp DESC"
)
.
Limit
(
limit
)
.
Find
(
&
res
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetGroupPowerExpRank fail:%v"
,
err
)
return
res
,
err
}
return
res
,
nil
}
// 获取我的家族排行
func
GetGroupPowerExpMyRank
(
model
*
domain
.
Model
,
beginDate
,
endDate
string
,
groupPowerId
mysql
.
ID
)
(
GroupPowerExpRank
,
error
)
{
table
:=
fmt
.
Sprintf
(
"(select group_power_id,SUM(exp) as exp,@curRank := @curRank + 1 `rank` from group_power_day_exp p,(SELECT @curRank := 0) tmp"
+
" WHERE `date` BETWEEN '%s' AND '%s' group BY group_power_id ORDER BY exp DESC ) t"
,
beginDate
,
endDate
)
var
res
GroupPowerExpRank
if
err
:=
model
.
DB
()
.
Table
(
table
)
.
Select
(
"t.group_power_id,t.exp,t.`rank`"
)
.
Where
(
"t.group_power_id = ?"
,
groupPowerId
)
.
Scan
(
&
res
)
.
Error
;
err
!=
nil
{
return
res
,
err
}
return
res
,
nil
}
route/group_power_r/group_rank.go
0 → 100644
View file @
a6c36dee
package
group_power_r
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/utils"
"github.com/gin-gonic/gin"
"github.com/jinzhu/now"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/cv/group_power_cv"
"hilo-group/domain/model/groupPower_m"
"hilo-group/myerr/bizerr"
"hilo-group/req"
"hilo-group/resp"
"time"
)
// @Tags 国家势力
// @Summary 家族榜单
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Param period path string true "榜单周期 day:日 week:周 month:月"
// @Success 200 {object} group_power_cv.CvGroupPowerRank
// @Router /v1/groupPower/rank/{period} [get]
func
GroupPowerRank
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myContext
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
userId
,
err
:=
req
.
GetUserId
(
c
)
if
err
!=
nil
{
return
myContext
,
err
}
period
:=
c
.
Param
(
"period"
)
if
period
!=
"day"
&&
period
!=
"week"
&&
period
!=
"month"
{
return
myContext
,
bizerr
.
InvalidParameter
}
// day
var
beginDate
,
endDate
string
switch
period
{
case
"day"
:
beginDate
,
endDate
=
time
.
Now
()
.
Format
(
"2006-01-02"
),
time
.
Now
()
.
Format
(
"2006-01-02"
)
case
"week"
:
beginDate
,
endDate
=
utils
.
GetMonday
(
time
.
Now
())
.
Format
(
"2006-01-02"
),
utils
.
GetMonday
(
time
.
Now
())
.
AddDate
(
0
,
0
,
6
)
.
Format
(
"2006-01-02"
)
case
"month"
:
beginDate
,
endDate
=
now
.
BeginningOfMonth
()
.
Format
(
"2006-01-02"
),
now
.
EndOfMonth
()
.
Format
(
"2006-01-02"
)
}
var
model
=
domain
.
CreateModelContext
(
myContext
)
rank
,
err
:=
groupPower_m
.
GetGroupPowerExpRank
(
model
,
beginDate
,
endDate
,
30
)
if
err
!=
nil
{
return
myContext
,
err
}
var
ids
[]
mysql
.
ID
for
_
,
g
:=
range
rank
{
ids
=
append
(
ids
,
g
.
GroupPowerId
)
}
response
:=
group_power_cv
.
CvGroupPowerRank
{}
myGroupPower
,
err
:=
groupPower_m
.
GetGroupPowerUserOrNil
(
model
,
userId
)
if
err
!=
nil
{
return
myContext
,
err
}
if
myGroupPower
!=
nil
{
ids
=
append
(
ids
,
myGroupPower
.
GroupPowerId
)
}
grades
,
err
:=
groupPower_m
.
MGetGroupPowerGrade
(
model
,
ids
)
if
err
!=
nil
{
return
myContext
,
err
}
if
myGroupPower
!=
nil
&&
myGroupPower
.
Role
==
groupPower_e
.
GroupPowerUserRoleMgr
{
myGroupPowerRank
,
err
:=
groupPower_m
.
GetGroupPowerExpMyRank
(
model
,
beginDate
,
endDate
,
myGroupPower
.
GroupPowerId
)
if
err
!=
nil
{
return
myContext
,
err
}
response
.
MyGroupPower
=
group_power_cv
.
CvGroupPowerRankData
{
GroupPowerId
:
myGroupPower
.
GroupPowerId
,
GroupPic
:
"todo"
,
Name
:
"todo"
,
Nameplate
:
"todo"
,
Grade
:
grades
[
myGroupPower
.
GroupPowerId
]
.
Grade
,
Exp
:
myGroupPowerRank
.
Exp
,
Rank
:
myGroupPowerRank
.
Rank
,
}
}
for
r
,
v
:=
range
rank
{
response
.
Items
=
append
(
response
.
Items
,
group_power_cv
.
CvGroupPowerRankData
{
GroupPowerId
:
v
.
GroupPowerId
,
GroupPic
:
"todo"
,
// todo
Name
:
"todo"
,
Nameplate
:
"todo"
,
Grade
:
grades
[
v
.
GroupPowerId
]
.
Grade
,
Exp
:
v
.
Exp
,
Rank
:
r
+
1
,
// 查询已做排序
})
}
resp
.
ResponseOk
(
c
,
response
)
return
myContext
,
nil
}
route/router.go
View file @
a6c36dee
...
...
@@ -125,6 +125,7 @@ func InitRouter() *gin.Engine {
groupPower
.
GET
(
"/team"
,
wrapper
(
group_power_r
.
GroupPowerTeam
))
groupPower
.
GET
(
"/billboard/week"
,
wrapper
(
group_power_r
.
GroupPowerBillboardWeek
))
groupPower
.
GET
(
"/billboard/owner/week"
,
wrapper
(
group_power_r
.
GroupPowerBillboardOwnerWeek
))
groupPower
.
GET
(
"/rank/:period"
,
wrapper
(
group_power_r
.
GroupPowerRank
))
}
return
r
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment