From 1a051a72bf4d1c5bb771e5634985071e7e3b83cb Mon Sep 17 00:00:00 2001 From: Jonson Petard <41122242+greenhat616@users.noreply.github.com> Date: Sun, 10 Sep 2023 12:13:19 +0800 Subject: [PATCH] chore: use floor value as threshold --- internal/logic/poll/ruling.go | 15 ++++++++++----- internal/service/poll.go | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/logic/poll/ruling.go b/internal/logic/poll/ruling.go index ed8b6ef..be385e0 100644 --- a/internal/logic/poll/ruling.go +++ b/internal/logic/poll/ruling.go @@ -25,22 +25,27 @@ func (s *sPoll) GetRulingThreshold(isExpandedPoll bool, totalTickets int) int { if totalTickets < consts.PollRulingNeedForCommonUserPollThreshold { threshold = 100000 // 设置一个不可能达到的值 } else { - threshold = int(math.Round(float64(totalTickets) * consts.PollRulingNeedForCommonUserPollRate)) + threshold = int(math.Floor(float64(totalTickets) * consts.PollRulingNeedForCommonUserPollRate)) } } else { if totalTickets < consts.PollRulingNormalThreshold { threshold = consts.PollRulingInitThreshold } else { - threshold = int(math.Round(float64(totalTickets) * consts.PollRulingNormalRate)) + threshold = int(math.Floor(float64(totalTickets) * consts.PollRulingNormalRate)) } } return threshold } // DoRuling 处理投票 -// nolint:gocyclo -func (s *sPoll) DoRuling(ctx context.Context, poll *entity.Poll, target consts.PollStatus) error { - if target != consts.PollStatusRejected && target != consts.PollStatusApproved && target != consts.PollStatusNeedModify { +// +//nolint:gocyclo +func (s *sPoll) DoRuling( + ctx context.Context, + poll *entity.Poll, + target consts.PollStatus, +) error { + if target != consts.PollStatusRejected && target != consts.PollStatusApproved && target != consts.PollStatusNeedModify { //nolint:lll return gerror.New("无效的投票状态") } // 判断是否需要修改 diff --git a/internal/service/poll.go b/internal/service/poll.go index 95bcd2b..878811d 100644 --- a/internal/service/poll.go +++ b/internal/service/poll.go @@ -37,7 +37,8 @@ type ( GetPollMarksByPollIDAndUserID(ctx context.Context, pid, userID int) ([]int, error) GetRulingThreshold(isExpandedPoll bool, totalTickets int) int // DoRuling 处理投票 - // nolint:gocyclo + // + //nolint:gocyclo DoRuling(ctx context.Context, poll *entity.Poll, target consts.PollStatus) error } )