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
04a53fe2
Commit
04a53fe2
authored
Jul 21, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new script
parent
c5cf2f64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
0 deletions
+98
-0
Makefile
script/Makefile
+2
-0
user_register_stat.go
script/user_register_stat.go
+96
-0
No files found.
script/Makefile
View file @
04a53fe2
...
...
@@ -14,4 +14,6 @@ cp_pairs_stat:
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
cp_pairs_stat cp_pairs_stat.go
charge_month
:
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
charge_month charge_month.go
user_register_stat
:
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
user_register_stat user_register_stat.go
script/user_register_stat.go
0 → 100644
View file @
04a53fe2
package
main
import
(
"fmt"
"git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/script/mysql"
"github.com/tealeg/xlsx"
)
type
UserRegisterData
struct
{
RegisterTime
string
// 注册时间
Code
string
// 逻辑ID
Country
string
// 国籍
Imei
string
// 设备码
SameImei
int64
// 同设备码用户数
IP
string
// IP
SameIp
int64
// 同IP用户数
}
func
ats30
(
a
interface
{})
string
{
return
fmt
.
Sprintf
(
"%v"
,
a
)
}
func
getImei
(
userId
uint64
)
string
{
var
imei
string
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"user_imei"
)
.
Where
(
"user_id = ?"
,
userId
)
.
Select
(
"imei"
)
.
Scan
(
&
imei
)
.
Error
;
err
!=
nil
{
}
return
imei
}
func
getSameImei
(
imei
string
)
int64
{
var
cnt
int64
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"user_imei"
)
.
Where
(
"imei = ?"
,
imei
)
.
Count
(
&
cnt
)
.
Error
;
err
!=
nil
{
}
return
cnt
}
func
getIp
(
userId
uint64
)
string
{
var
ip
string
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"user_ip"
)
.
Where
(
"user_id = ?"
,
userId
)
.
Select
(
"ip"
)
.
Scan
(
&
ip
)
.
Error
;
err
!=
nil
{
}
return
ip
}
func
getSameIp
(
ip
string
)
int64
{
var
cnt
int64
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"user_ip"
)
.
Where
(
"ip = ?"
,
ip
)
.
Count
(
&
cnt
)
.
Error
;
err
!=
nil
{
}
return
cnt
}
func
main
()
{
var
users
[]
model
.
User
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"user"
)
.
Where
(
"created_time >= ? AND created_time < ?"
,
"2023-06-18"
,
"2023-07-19"
)
.
Find
(
&
users
)
.
Error
;
err
!=
nil
{
//if err := mysql.ProdReadOnlyDB.Table("user").Where("created_time >= ? AND created_time < ?", "2023-07-18", "2023-07-19").Limit(10).Find(&users).Error; err != nil {
panic
(
err
)
}
var
data
[]
UserRegisterData
for
i
,
u
:=
range
users
{
imei
:=
getImei
(
u
.
Id
)
imeiCnt
:=
int64
(
0
)
if
len
(
imei
)
>
0
{
imeiCnt
=
getSameImei
(
imei
)
}
ip
:=
getIp
(
u
.
Id
)
ipCnt
:=
int64
(
0
)
if
len
(
ip
)
>
0
{
ipCnt
=
getSameIp
(
ip
)
}
data
=
append
(
data
,
UserRegisterData
{
RegisterTime
:
u
.
CreatedTime
.
Format
(
"2006-01-02"
),
Code
:
u
.
Code
,
Country
:
u
.
Country
,
Imei
:
imei
,
SameImei
:
imeiCnt
,
IP
:
ip
,
SameIp
:
ipCnt
,
})
println
(
i
)
}
excelFileName
:=
fmt
.
Sprintf
(
"./hilo新增用户信息-6.18-7.18.xlsx"
)
xlFile
:=
xlsx
.
NewFile
()
sheet
,
err
:=
xlFile
.
AddSheet
(
"slot"
)
if
err
!=
nil
{
panic
(
err
)
}
row
:=
sheet
.
AddRow
()
c1
,
c2
,
c3
,
c4
,
c5
,
c6
,
c7
:=
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
()
c1
.
Value
,
c2
.
Value
,
c3
.
Value
,
c4
.
Value
,
c5
.
Value
,
c6
.
Value
,
c7
.
Value
=
"注册时间"
,
"逻辑ID"
,
"国籍"
,
"设备码"
,
"同设备码用户数"
,
"IP"
,
"同IP用户数"
for
_
,
d
:=
range
data
{
row
:=
sheet
.
AddRow
()
c1
,
c2
,
c3
,
c4
,
c5
,
c6
,
c7
:=
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
()
c1
.
Value
,
c2
.
Value
,
c3
.
Value
,
c4
.
Value
,
c5
.
Value
,
c6
.
Value
,
c7
.
Value
=
ats30
(
d
.
RegisterTime
),
ats30
(
d
.
Code
),
ats30
(
d
.
Country
),
ats30
(
d
.
Imei
),
ats30
(
d
.
SameImei
),
ats30
(
d
.
IP
),
ats30
(
d
.
SameIp
)
}
_
=
xlFile
.
Save
(
excelFileName
)
}
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