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
9068f714
Commit
9068f714
authored
Aug 27, 2023
by
JiebinHu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
todo 一次性脚本
parent
1ccc8c2f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
+63
-0
inner.go
route/group_power_r/inner.go
+62
-0
router.go
route/router.go
+1
-0
No files found.
route/group_power_r/inner.go
View file @
9068f714
package
group_power_r
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin"
"github.com/jinzhu/now"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/_const/redis_key/groupPower_k"
"hilo-group/cv/group_power_cv"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/msg_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/service/group_power_s"
"hilo-group/myerr/bizerr"
"hilo-group/resp"
"time"
)
type
MGetGroupPowerReq
struct
{
...
...
@@ -93,3 +98,60 @@ func Test(c *gin.Context) (*mycontext.MyContext, error) {
//}
return
nil
,
nil
}
type
GroupPowerDayStar
struct
{
Date
string
GroupPowerId
uint64
Type
groupPower_e
.
GroupPowerStarType
UserId
uint64
Score
uint64
}
// @Tags 国家势力-内部
// @Summary 同步家族之星到redis
// @Success 200
// @Router /inner/groupPower/sync/star [get]
func
SyncStar
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
start
:=
c
.
Query
(
"start"
)
end
:=
c
.
Query
(
"end"
)
if
len
(
start
)
<=
0
||
len
(
end
)
<=
0
{
return
myCtx
,
bizerr
.
InvalidParameter
}
var
model
=
domain
.
CreateModelContext
(
myCtx
)
var
stars
[]
GroupPowerDayStar
if
err
:=
model
.
DB
()
.
Table
(
"group_power_day_star"
)
.
Select
(
"`date`,group_power_id,type,user_id,SUM(score) score"
)
.
Where
(
"`date` BETWEEN ? AND ?"
,
start
,
end
)
.
Group
(
"`date`,group_power_id,type,user_id"
)
.
Find
(
&
stars
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"SyncStar fail:%v"
,
err
)
return
myCtx
,
err
}
ttl
:=
map
[
string
]
time
.
Duration
{
"day"
:
time
.
Hour
*
24
*
7
,
"week"
:
time
.
Hour
*
24
*
7
*
30
,
"month"
:
time
.
Hour
*
24
*
7
*
30
*
2
,
}
for
_
,
star
:=
range
stars
{
date
,
err
:=
time
.
Parse
(
"2006-01-02"
,
star
.
Date
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"SyncStar date fail:%v"
,
err
)
continue
}
for
_
,
period
:=
range
[]
string
{
"day"
,
"week"
,
"month"
}
{
var
dateStr
string
switch
period
{
case
"day"
:
dateStr
=
date
.
Format
(
"2006-01-02"
)
case
"week"
:
dateStr
=
now
.
With
(
date
)
.
BeginningOfWeek
()
.
Format
(
"2006-01-02"
)
case
"month"
:
dateStr
=
now
.
With
(
date
)
.
BeginningOfMonth
()
.
Format
(
"2006-01-02"
)
}
key
:=
groupPower_k
.
GetGroupPowerStarRankKey
(
star
.
Type
,
period
,
star
.
GroupPowerId
,
dateStr
)
model
.
RedisCluster
.
ZIncrBy
(
model
,
key
,
float64
(
star
.
Score
),
fmt
.
Sprintf
(
"%d"
,
star
.
UserId
))
model
.
RedisCluster
.
Expire
(
model
,
key
,
ttl
[
period
])
}
}
return
myCtx
,
nil
}
route/router.go
View file @
9068f714
...
...
@@ -159,6 +159,7 @@ func InitRouter() *gin.Engine {
innerGroupPower
:=
inner
.
Group
(
"/groupPower"
)
{
innerGroupPower
.
GET
(
"/infos"
,
wrapper
(
group_power_r
.
MGetGroupPowers
))
innerGroupPower
.
GET
(
"/sync/star"
,
wrapper
(
group_power_r
.
SyncStar
))
// todo 一次性脚本
}
innerMic
:=
inner
.
Group
(
"/mic"
)
{
...
...
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