Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
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-common
Commits
6ce9fdf6
Commit
6ce9fdf6
authored
Dec 09, 2022
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 机器人周一上线前跑脚本
parent
dd8cc98f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
156 additions
and
24 deletions
+156
-24
go.mod
go.mod
+1
-0
go.sum
go.sum
+2
-0
user.go
model/user.go
+50
-0
mysql.go
mysql/mysql.go
+36
-4
group_power_india.go
script/group_power_india.go
+14
-20
prod_game_robot.go
script/prod_game_robot.go
+36
-0
test_game_robot.go
script/test_game_robot.go
+17
-0
No files found.
go.mod
View file @
6ce9fdf6
...
...
@@ -6,6 +6,7 @@ require (
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/tealeg/xlsx v1.0.5 // indirect
gorm.io/driver/mysql v1.4.3 // indirect
...
...
go.sum
View file @
6ce9fdf6
...
...
@@ -9,6 +9,8 @@ github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
...
...
model/user.go
0 → 100644
View file @
6ce9fdf6
package
model
import
"time"
type
User
struct
{
Id
uint64
ExternalId
string
Avatar
string
DefaultAvatar
bool
Nick
string
Sex
uint8
Birthday
uint64
Country
string
CountryIcon
string
Language
string
Description
string
Code
string
OriginCode
string
IsPush
int
IsShowAge
int
Status
int
DeviceType
string
LogoutTime
int64
CreatedTime
time
.
Time
}
type
UserNoId
struct
{
ExternalId
string
Avatar
string
DefaultAvatar
bool
Nick
string
Sex
uint8
Birthday
uint64
Country
string
CountryIcon
string
Language
string
Description
string
Code
string
OriginCode
string
IsPush
int
IsShowAge
int
Status
int
DeviceType
string
LogoutTime
int64
CreatedTime
time
.
Time
}
func
(
UserNoId
)
TableName
()
string
{
return
"user"
}
mysql/mysql.go
View file @
6ce9fdf6
...
...
@@ -10,14 +10,16 @@ import (
"net/url"
)
var
Db
*
gorm
.
DB
var
ProdReadOnlyDB
*
gorm
.
DB
var
ProdWriteDB
*
gorm
.
DB
var
TestDB
*
gorm
.
DB
func
init
()
{
var
err
error
options
:=
"?charset=utf8mb4&parseTime=True&loc=Local&time_zone="
+
url
.
QueryEscape
(
"'+8:00'"
)
dsn
:=
"read_only:hilo1632@(rm-eb3w787dzn9c8g07vuo.mysql.dubai.rds.aliyuncs.com)/hilo"
+
options
Db
,
err
=
gorm
.
Open
(
mysql
.
Open
(
dsn
),
&
gorm
.
Config
{
ProdReadOnlyDB
,
err
=
gorm
.
Open
(
mysql
.
Open
(
dsn
),
&
gorm
.
Config
{
NamingStrategy
:
schema
.
NamingStrategy
{
SingularTable
:
true
},
})
if
err
!=
nil
{
...
...
@@ -26,7 +28,37 @@ func init() {
log
.
Println
(
"mysql connect success"
)
}
if
Db
.
Error
!=
nil
{
fmt
.
Printf
(
"database error %v"
,
Db
.
Error
)
if
ProdReadOnlyDB
.
Error
!=
nil
{
fmt
.
Printf
(
"database error %v"
,
ProdReadOnlyDB
.
Error
)
}
dsn
=
"root:yX0jPAhO0I4s2zlA@(47.244.34.27:3306)/hilo"
+
options
TestDB
,
err
=
gorm
.
Open
(
mysql
.
Open
(
dsn
),
&
gorm
.
Config
{
NamingStrategy
:
schema
.
NamingStrategy
{
SingularTable
:
true
},
})
if
err
!=
nil
{
log
.
Fatalf
(
"mysql connect error %v"
,
err
)
}
else
{
log
.
Println
(
"mysql connect success"
)
}
if
TestDB
.
Error
!=
nil
{
fmt
.
Printf
(
"database error %v"
,
TestDB
.
Error
)
}
dsn
=
"nextvideo:ihlUwI4nhi9W88MI@(rm-eb3w787dzn9c8g07vuo.mysql.dubai.rds.aliyuncs.com)/hilo"
+
options
ProdWriteDB
,
err
=
gorm
.
Open
(
mysql
.
Open
(
dsn
),
&
gorm
.
Config
{
NamingStrategy
:
schema
.
NamingStrategy
{
SingularTable
:
true
},
})
if
err
!=
nil
{
log
.
Fatalf
(
"mysql connect error %v"
,
err
)
}
else
{
log
.
Println
(
"mysql connect success"
)
}
if
ProdWriteDB
.
Error
!=
nil
{
fmt
.
Printf
(
"database error %v"
,
ProdWriteDB
.
Error
)
}
}
script/group_power_india.go
View file @
6ce9fdf6
...
...
@@ -2,6 +2,7 @@ package main
import
(
"fmt"
"github.com/hilo-common/model"
"github.com/hilo-common/mysql"
"github.com/spf13/cast"
"github.com/tealeg/xlsx"
...
...
@@ -27,13 +28,6 @@ type GroupPower struct {
UserChargeSum11
float64
// 11月1号后注册所有势力成员累积充值
}
type
User
struct
{
Id
uint64
Code
string
Country
string
CreatedTime
time
.
Time
}
type
GroupPowerUser
struct
{
GroupPowerId
uint64
UserId
uint64
...
...
@@ -42,7 +36,7 @@ type GroupPowerUser struct {
func
main
()
{
groupPowerSql
:=
"SELECT p.id as group_power_id,g.`owner` from group_power p,group_info g where p.group_uid = g.im_group_id"
var
groupPowers
[]
GroupPower
if
err
:=
mysql
.
Db
.
Raw
(
groupPowerSql
)
.
Find
(
&
groupPowers
)
.
Error
;
err
!=
nil
{
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
groupPowerSql
)
.
Find
(
&
groupPowers
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -50,11 +44,11 @@ func main() {
for
_
,
v
:=
range
groupPowers
{
userIds
=
append
(
userIds
,
v
.
Owner
)
}
var
users
[]
User
if
err
:=
mysql
.
Db
.
Model
(
User
{})
.
Where
(
"id in ?"
,
userIds
)
.
Find
(
&
users
)
.
Error
;
err
!=
nil
{
var
users
[]
model
.
User
if
err
:=
mysql
.
ProdReadOnlyDB
.
Model
(
model
.
User
{})
.
Where
(
"id in ?"
,
userIds
)
.
Find
(
&
users
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
userMap
:=
make
(
map
[
uint64
]
User
)
userMap
:=
make
(
map
[
uint64
]
model
.
User
)
for
i
:=
range
users
{
userMap
[
users
[
i
]
.
Id
]
=
users
[
i
]
}
...
...
@@ -71,7 +65,7 @@ func main() {
}
groupPowerUsersSql
:=
"SELECT group_power_id,user_id FROM `group_power_user` where group_power_id in (?);"
var
groupPowerUsers
[]
GroupPowerUser
if
err
:=
mysql
.
Db
.
Raw
(
groupPowerUsersSql
,
targetGroupPowerId
)
.
Find
(
&
groupPowerUsers
)
.
Error
;
err
!=
nil
{
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
groupPowerUsersSql
,
targetGroupPowerId
)
.
Find
(
&
groupPowerUsers
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
var
groupPowerUserMap
=
make
(
map
[
uint64
][]
uint64
)
// group_power_id -> []userId
...
...
@@ -102,7 +96,7 @@ func main() {
for
i
,
groupPower
:=
range
targetGroupPower
{
userChargeNumSql
:=
"SELECT count(DISTINCT user_id) as count,sum(price) as price FROM `pay_order` where status = 2 AND platform in (1,2,3,4,5) AND user_id in ? ;"
var
userChargeNumSum
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds
)
.
First
(
&
userChargeNumSum
)
.
Error
;
err
!=
nil
{
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds
)
.
First
(
&
userChargeNumSum
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum
+=
userChargeNumSum
.
Count
...
...
@@ -110,7 +104,7 @@ func main() {
}
if
len
(
groupPower
.
UserIds9
)
>
0
{
var
userChargeNumSum9
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds9
)
.
First
(
&
userChargeNumSum9
)
.
Error
;
err
!=
nil
{
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds9
)
.
First
(
&
userChargeNumSum9
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum9
+=
userChargeNumSum9
.
Count
...
...
@@ -119,7 +113,7 @@ func main() {
}
if
len
(
groupPower
.
UserIds10
)
>
0
{
var
userChargeNumSum10
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds10
)
.
First
(
&
userChargeNumSum10
)
.
Error
;
err
!=
nil
{
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds10
)
.
First
(
&
userChargeNumSum10
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum10
+=
userChargeNumSum10
.
Count
...
...
@@ -128,7 +122,7 @@ func main() {
}
if
len
(
groupPower
.
UserIds11
)
>
0
{
var
userChargeNumSum11
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds11
)
.
First
(
&
userChargeNumSum11
)
.
Error
;
err
!=
nil
{
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds11
)
.
First
(
&
userChargeNumSum11
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum11
+=
userChargeNumSum11
.
Count
...
...
@@ -140,7 +134,7 @@ func main() {
for
i
,
groupPower
:=
range
targetGroupPower
{
userChargeNumSql
:=
"SELECT count(DISTINCT receiver_id) as count,sum(dollar) as price FROM `dealer_transfer_detail` where receiver_id in ? ;"
var
userChargeNumSum
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds
)
.
First
(
&
userChargeNumSum
)
.
Error
;
err
!=
nil
{
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds
)
.
First
(
&
userChargeNumSum
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum
+=
userChargeNumSum
.
Count
...
...
@@ -148,7 +142,7 @@ func main() {
}
if
len
(
groupPower
.
UserIds9
)
>
0
{
var
userChargeNumSum9
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds9
)
.
First
(
&
userChargeNumSum9
)
.
Error
;
err
!=
nil
{
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds9
)
.
First
(
&
userChargeNumSum9
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum9
+=
userChargeNumSum9
.
Count
...
...
@@ -157,7 +151,7 @@ func main() {
}
if
len
(
groupPower
.
UserIds10
)
>
0
{
var
userChargeNumSum10
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds10
)
.
First
(
&
userChargeNumSum10
)
.
Error
;
err
!=
nil
{
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds10
)
.
First
(
&
userChargeNumSum10
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum10
+=
userChargeNumSum10
.
Count
...
...
@@ -166,7 +160,7 @@ func main() {
}
if
len
(
groupPower
.
UserIds11
)
>
0
{
var
userChargeNumSum11
NumSum
if
err
:=
mysql
.
Db
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds11
)
.
First
(
&
userChargeNumSum11
)
.
Error
;
err
!=
nil
{
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
userChargeNumSql
,
groupPower
.
UserIds11
)
.
First
(
&
userChargeNumSum11
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
else
{
targetGroupPower
[
i
]
.
UserChargeNum11
+=
userChargeNumSum11
.
Count
...
...
script/prod_game_robot.go
0 → 100644
View file @
6ce9fdf6
package
main
import
(
"github.com/hilo-common/model"
"github.com/hilo-common/mysql"
uuid
"github.com/satori/go.uuid"
"strings"
)
/*
# redis 事务拿出3000个code
MULTI
LRANGE USER_CODE 0 2999
LTRIM USER_CODE 3000 -1
exec
*/
var
codes
=
[]
string
{
"123997623"
,
"88912321"
}
// 3000个from redis pop USER_CODE todo
func
main
()
{
var
testRobots
[]
model
.
UserNoId
sql
:=
"SELECT * FROM `user` where id BETWEEN 4564 and 7615 limit 3000"
if
err
:=
mysql
.
TestDB
.
Raw
(
sql
)
.
Find
(
&
testRobots
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
for
i
,
user
:=
range
testRobots
{
user
.
ExternalId
=
GetUUID
()
// 重新生成新的externalId
user
.
Code
=
codes
[
i
]
// code赋值
user
.
OriginCode
=
user
.
Code
break
//mysql.ProdWriteDB.Create(user) // todo final
}
}
func
GetUUID
()
string
{
return
strings
.
Replace
(
uuid
.
NewV4
()
.
String
(),
"-"
,
""
,
-
1
)
}
script/test_game_robot.go
0 → 100644
View file @
6ce9fdf6
package
main
import
(
"github.com/hilo-common/model"
"github.com/hilo-common/mysql"
)
func
main
()
{
var
prodUser
[]
model
.
UserNoId
sql
:=
"SELECT * FROM `user` where id BETWEEN 888888 and 999999 AND avatar <> '' and default_avatar = 0 limit 10000 ;"
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
sql
)
.
Find
(
&
prodUser
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
for
_
,
user
:=
range
prodUser
{
mysql
.
TestDB
.
Create
(
user
)
}
}
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