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
902884c1
Commit
902884c1
authored
Aug 09, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
尝试获取锁
parent
6a10396f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
0 deletions
+87
-0
util.go
resource/redisCli/util.go
+19
-0
Makefile
script/Makefile
+2
-0
fruit_fix.go
script/fruit_fix.go
+66
-0
No files found.
resource/redisCli/util.go
View file @
902884c1
...
@@ -36,6 +36,25 @@ func Lock(key string, expiration time.Duration) bool {
...
@@ -36,6 +36,25 @@ func Lock(key string, expiration time.Duration) bool {
return
true
return
true
}
}
// 尝试获取锁
func
TryLock
(
key
string
,
expiration
time
.
Duration
)
bool
{
deadline
:=
time
.
Now
()
.
Add
(
expiration
)
for
{
if
time
.
Now
()
.
After
(
deadline
)
{
return
false
// 超时无法获取锁
}
if
Lock
(
key
,
expiration
)
{
return
true
}
time
.
Sleep
(
time
.
Millisecond
)
}
}
// 删除锁
func
DelLock
(
key
string
)
{
RedisClient
.
Del
(
context
.
Background
(),
key
)
}
func
GetCacheInt64
(
key
string
)
(
int64
,
error
)
{
func
GetCacheInt64
(
key
string
)
(
int64
,
error
)
{
data
,
err
:=
RedisClient
.
Get
(
context
.
Background
(),
key
)
.
Int64
()
data
,
err
:=
RedisClient
.
Get
(
context
.
Background
(),
key
)
.
Int64
()
if
err
!=
nil
&&
err
!=
redis
.
Nil
{
if
err
!=
nil
&&
err
!=
redis
.
Nil
{
...
...
script/Makefile
View file @
902884c1
...
@@ -18,4 +18,6 @@ user_register_stat:
...
@@ -18,4 +18,6 @@ user_register_stat:
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
user_register_stat user_register_stat.go
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
user_register_stat user_register_stat.go
h5_game_yellow
:
h5_game_yellow
:
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
h5_game_yellow h5_game_yellow.go
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
h5_game_yellow h5_game_yellow.go
fruit_fix
:
CGO_ENABLED
=
0
GOOS
=
linux
GOARCH
=
amd64 go build
-o
fruit_fix fruit_fix.go
script/fruit_fix.go
0 → 100644
View file @
902884c1
package
main
import
(
"fmt"
"git.hilo.cn/hilo-common/script/mysql"
"github.com/tealeg/xlsx"
"gorm.io/gorm"
)
var
userIds
=
[]
uint64
{
3117191
}
type
FruitMachine
struct
{
Date
string
Round
int64
FruitId
int
}
type
FruitMachineStake2
struct
{
Stake
int64
}
func
main
()
{
var
Plus
=
make
(
map
[
int
]
int64
)
// fruitId->plush
Plus
[
1
]
=
5
Plus
[
2
]
=
5
Plus
[
3
]
=
5
Plus
[
4
]
=
5
Plus
[
5
]
=
10
Plus
[
6
]
=
15
Plus
[
7
]
=
25
Plus
[
8
]
=
45
var
data
=
make
(
map
[
uint64
]
int64
)
for
round
:=
194
;
round
<=
216
;
round
++
{
var
fm
=
new
(
FruitMachine
)
if
err
:=
mysql
.
ProdReadOnlyDB
.
Model
(
FruitMachine
{})
.
Where
(
"`date` = '2023-08-09'"
)
.
Where
(
"round = ?"
,
round
)
.
First
(
fm
)
.
Error
;
err
!=
nil
{
panic
(
err
)
}
for
_
,
userId
:=
range
userIds
{
var
fs
=
new
(
FruitMachineStake2
)
if
err
:=
mysql
.
ProdReadOnlyDB
.
Table
(
"fruit_machine_stake"
)
.
Where
(
"`date` = '2023-08-09'"
)
.
Where
(
"round = ?"
,
round
)
.
Where
(
"fruit_id = ?"
,
fm
.
FruitId
)
.
Where
(
"user_id = ?"
,
userId
)
.
First
(
&
fs
)
.
Error
;
err
!=
nil
{
if
err
!=
gorm
.
ErrRecordNotFound
{
panic
(
err
)
}
continue
}
data
[
userId
]
+=
fs
.
Stake
*
Plus
[
fm
.
FruitId
]
}
}
excelFileName
:=
fmt
.
Sprintf
(
"./水果机.xlsx"
)
xlFile
:=
xlsx
.
NewFile
()
sheet
,
_
:=
xlFile
.
AddSheet
(
"charge"
)
row
:=
sheet
.
AddRow
()
c1
,
c2
:=
row
.
AddCell
(),
row
.
AddCell
()
c1
.
Value
,
c2
.
Value
=
"userId"
,
"should"
for
userId
,
award
:=
range
data
{
row
:=
sheet
.
AddRow
()
c1
,
c2
:=
row
.
AddCell
(),
row
.
AddCell
()
c1
.
Value
,
c2
.
Value
=
fmt
.
Sprintf
(
"%d"
,
userId
),
fmt
.
Sprintf
(
"%d"
,
award
)
}
_
=
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