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
40dfe214
Commit
40dfe214
authored
Jun 21, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
2e543c09
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
0 deletions
+108
-0
Makefile
script/Makefile
+2
-0
cp_pairs_stat.go
script/cp_pairs_stat.go
+106
-0
No files found.
script/Makefile
View file @
40dfe214
...
...
@@ -10,4 +10,6 @@ charge_max:
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
charge_max charge_max.go
group_power_data
:
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
group_power_data group_power_data.go
cp_pairs_stat
:
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
cp_pairs_stat cp_pairs_stat.go
script/cp_pairs_stat.go
0 → 100644
View file @
40dfe214
package
main
import
(
"fmt"
"git.hilo.cn/hilo-common/script/model"
"git.hilo.cn/hilo-common/script/mysql"
"github.com/tealeg/xlsx"
)
type
CpPairData
struct
{
Level
string
Cnt
int
KsaCnt
int
NotKsaCnt
int
}
func
ats26
(
a
interface
{})
string
{
return
fmt
.
Sprintf
(
"%v"
,
a
)
}
func
getAreaByCode2
(
code
string
)
string
{
sql
:=
"SELECT area FROM res_country c,user u WHERE u.country = c.name AND u.code = ?"
var
area
int
if
err
:=
mysql
.
ProdReadOnlyDB
.
Raw
(
sql
,
code
)
.
Scan
(
&
area
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
if
area
==
1
{
return
"阿语区"
}
return
"非阿语区"
}
type
CpInfo
struct
{
Id
uint64
UserId1
uint64
UserId2
uint64
Code1
string
Code2
string
UserId1Area
string
UserId2Area
string
Level
uint64
}
type
CpLevel
struct
{
CpId
uint64
Level
uint64
}
func
main
()
{
var
cpInfos
[]
CpInfo
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"cp_relation"
)
.
Select
(
"id,user_id1,user_id2"
)
.
Find
(
&
cpInfos
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
var
cpIds
[]
uint64
for
_
,
v
:=
range
cpInfos
{
cpIds
=
append
(
cpIds
,
v
.
Id
)
}
var
cpLevels
[]
CpLevel
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"cp_level"
)
.
Select
(
"cp_id,level"
)
.
Where
(
"cp_id in ?"
,
cpIds
)
.
Find
(
&
cpLevels
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
var
userIds
[]
uint64
var
users
[]
model
.
User
for
i
,
v
:=
range
cpInfos
{
userIds
=
append
(
userIds
,
v
.
UserId1
)
userIds
=
append
(
userIds
,
v
.
UserId2
)
for
_
,
v2
:=
range
cpLevels
{
if
v
.
Id
==
v2
.
CpId
{
cpInfos
[
i
]
.
Level
=
v2
.
Level
break
}
}
}
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"user"
)
.
Where
(
"id in ?"
,
userIds
)
.
Find
(
&
users
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
uM
:=
make
(
map
[
uint64
]
model
.
User
)
for
i
,
v
:=
range
users
{
uM
[
v
.
Id
]
=
users
[
i
]
}
for
i
,
v
:=
range
cpInfos
{
cpInfos
[
i
]
.
Code1
=
uM
[
v
.
UserId1
]
.
Code
cpInfos
[
i
]
.
Code2
=
uM
[
v
.
UserId2
]
.
Code
cpInfos
[
i
]
.
UserId1Area
=
getAreaByCode2
(
uM
[
v
.
UserId1
]
.
Code
)
cpInfos
[
i
]
.
UserId2Area
=
getAreaByCode2
(
uM
[
v
.
UserId2
]
.
Code
)
}
excelFileName
:=
fmt
.
Sprintf
(
"./cp数据.xlsx"
)
xlFile
:=
xlsx
.
NewFile
()
sheet
,
err
:=
xlFile
.
AddSheet
(
"cp"
)
if
err
!=
nil
{
panic
(
err
)
}
row
:=
sheet
.
AddRow
()
c1
,
c2
,
c3
,
c4
,
c5
,
c6
:=
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
()
c1
.
Value
,
c2
.
Value
,
c3
.
Value
,
c4
.
Value
,
c5
.
Value
,
c6
.
Value
=
"cp ID"
,
"userId1"
,
"userId2"
,
"user1区域"
,
"user2区域"
,
"等级"
for
_
,
d
:=
range
cpInfos
{
row
:=
sheet
.
AddRow
()
c1
,
c2
,
c3
,
c4
,
c5
,
c6
:=
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
(),
row
.
AddCell
()
c1
.
Value
,
c2
.
Value
,
c3
.
Value
,
c4
.
Value
,
c5
.
Value
,
c6
.
Value
=
ats26
(
d
.
Id
),
ats26
(
d
.
UserId1
),
ats26
(
d
.
UserId2
),
ats26
(
d
.
UserId1Area
),
ats26
(
d
.
UserId2Area
),
ats26
(
d
.
Level
)
}
_
=
xlFile
.
Save
(
excelFileName
)
//var data []CpPairData
}
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