Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ApiToKafkaBill
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
李伟@五瓣科技
ApiToKafkaBill
Commits
8d3acd93
Commit
8d3acd93
authored
Jan 19, 2024
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix charge is 0
parent
5d23461f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
56 deletions
+55
-56
dao.go
dao.go
+30
-31
dao_test.go
dao_test.go
+25
-25
No files found.
dao.go
View file @
8d3acd93
...
@@ -92,28 +92,29 @@ func (d *Dao) GetBalanceSubCharge(users []string) (map[string]decimal.Decimal, e
...
@@ -92,28 +92,29 @@ func (d *Dao) GetBalanceSubCharge(users []string) (map[string]decimal.Decimal, e
break
break
}
}
//fmt.Println("l", l, "idx", idx, "l+idx", l+idx, "len(redisValueRes)", len(redisValueRes), "v", v, "redisValueRes[l+idx]", redisValueRes[l+idx])
fmt
.
Println
(
"l"
,
l
,
"idx"
,
idx
,
"l+idx"
,
l
+
idx
,
"len(redisValueRes)"
,
len
(
redisValueRes
),
"v"
,
v
,
"redisValueRes[l+idx]"
,
redisValueRes
[
l
+
idx
])
if
v
!=
nil
&&
redisValueRes
[
l
+
idx
]
!=
nil
{
//if v != nil && redisValueRes[l+idx] != nil {
balanceStr
,
ok
:=
v
.
(
string
)
if
balanceStr
,
ok
:=
v
.
(
string
);
ok
{
if
ok
{
chargeStr
,
ok
:=
redisValueRes
[
l
+
idx
]
.
(
string
)
if
ok
{
balanceDec
,
err
:=
decimal
.
NewFromString
(
balanceStr
)
balanceDec
,
err
:=
decimal
.
NewFromString
(
balanceStr
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"user balance error"
,
users
[
idx
],
err
.
Error
())
fmt
.
Println
(
"user balance error"
,
users
[
idx
],
err
.
Error
())
res
[
users
[
idx
]]
=
decimal
.
NewFromInt
(
0
)
res
[
users
[
idx
]]
=
decimal
.
NewFromInt
(
0
)
continue
continue
}
}
chargeDec
,
err
:=
decimal
.
NewFromString
(
chargeStr
)
var
chargeDec
decimal
.
Decimal
if
chargeStr
,
ok
:=
redisValueRes
[
l
+
idx
]
.
(
string
);
ok
{
var
err
error
chargeDec
,
err
=
decimal
.
NewFromString
(
chargeStr
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"user charge error"
,
users
[
idx
],
err
.
Error
())
fmt
.
Println
(
"user charge error"
,
users
[
idx
],
err
.
Error
())
res
[
users
[
idx
]]
=
decimal
.
NewFromInt
(
0
)
res
[
users
[
idx
]]
=
decimal
.
NewFromInt
(
0
)
continue
continue
}
}
}
else
{
chargeDec
=
decimal
.
NewFromInt
(
0
)
}
if
balanceDec
.
Cmp
(
chargeDec
)
==
1
{
if
balanceDec
.
Cmp
(
chargeDec
)
==
1
{
realBalance
:=
balanceDec
.
Sub
(
chargeDec
)
realBalance
:=
balanceDec
.
Sub
(
chargeDec
)
...
@@ -125,8 +126,6 @@ func (d *Dao) GetBalanceSubCharge(users []string) (map[string]decimal.Decimal, e
...
@@ -125,8 +126,6 @@ func (d *Dao) GetBalanceSubCharge(users []string) (map[string]decimal.Decimal, e
}
}
continue
continue
}
}
}
}
fmt
.
Println
(
"user balance or charge is nil"
,
"user"
,
users
[
idx
],
"balance"
,
v
,
"charge"
,
redisValueRes
[
l
+
idx
])
fmt
.
Println
(
"user balance or charge is nil"
,
"user"
,
users
[
idx
],
"balance"
,
v
,
"charge"
,
redisValueRes
[
l
+
idx
])
...
...
dao_test.go
View file @
8d3acd93
...
@@ -36,30 +36,30 @@ func TestRedis(t *testing.T) {
...
@@ -36,30 +36,30 @@ func TestRedis(t *testing.T) {
}
}
func
TestChargeIncreaseBy
(
t
*
testing
.
T
)
{
//
func TestChargeIncreaseBy(t *testing.T) {
d
:=
&
Dao
{
//
d := &Dao{
redis
.
NewClient
(
&
redis
.
Options
{
//
redis.NewClient(&redis.Options{
Addr
:
"localhost:6379"
,
//
Addr: "localhost:6379",
Password
:
""
,
// no password set
//
Password: "", // no password set
DB
:
0
,
// use default DB
//
DB: 0, // use default DB
Protocol
:
3
,
// specify 2 for RESP 2 or 3 for RESP 3
//
Protocol: 3, // specify 2 for RESP 2 or 3 for RESP 3
}),
//
}),
}
//
}
usersFee
:=
make
([]
UserFee
,
0
,
100
)
//
usersFee := make([]UserFee, 0, 100)
for
i
:=
0
;
i
<
10
;
i
++
{
//
for i := 0; i < 10; i++ {
usersFee
=
append
(
usersFee
,
UserFee
{
//
usersFee = append(usersFee, UserFee{
User
:
fmt
.
Sprintf
(
"user-%v"
,
i
),
//
User: fmt.Sprintf("user-%v", i),
Fee
:
decimal
.
NewFromInt
(
int64
(
i
)),
//
Fee: decimal.NewFromInt(int64(i)),
})
//
})
}
//
}
if
err
:=
d
.
ChargeIncrby
(
context
.
Background
(),
usersFee
);
err
!=
nil
{
//
if err := d.ChargeIncrby(context.Background(), usersFee); err != nil {
t
.
Fatal
(
err
)
//
t.Fatal(err)
}
//
}
}
//
}
func
TestBalanceIncreaseBy
(
t
*
testing
.
T
)
{
func
TestBalanceIncreaseBy
(
t
*
testing
.
T
)
{
...
@@ -77,7 +77,7 @@ func TestBalanceIncreaseBy(t *testing.T) {
...
@@ -77,7 +77,7 @@ func TestBalanceIncreaseBy(t *testing.T) {
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
10
;
i
++
{
usersFee
=
append
(
usersFee
,
UserFee
{
usersFee
=
append
(
usersFee
,
UserFee
{
User
:
fmt
.
Sprintf
(
"user-%v"
,
i
),
User
:
fmt
.
Sprintf
(
"user-%v"
,
i
),
Fee
:
decimal
.
NewFromInt
(
int64
(
i
*
10
)),
Fee
:
decimal
.
NewFromInt
(
int64
(
i
*
10
000000
)),
})
})
}
}
...
...
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