refactor(ticket): rename TicketNoService to TicketNoSequenceService and update references

This commit is contained in:
mlogclub
2026-05-03 12:20:44 +08:00
parent d75f9f05a7
commit ac0f25f10c
5 changed files with 87 additions and 93 deletions
+10 -10
View File
@@ -11,29 +11,29 @@ import (
"gorm.io/gorm"
)
var TicketNoService = newTicketNoService()
var TicketNoSequenceService = newTicketNoSequenceService()
var ticketNoSQLiteMu sync.Mutex
func newTicketNoService() *ticketNoService {
return &ticketNoService{}
func newTicketNoSequenceService() *ticketNoSequenceService {
return &ticketNoSequenceService{}
}
type ticketNoService struct{}
type ticketNoSequenceService struct {
ticketNoSQLiteMu sync.Mutex
}
func (s *ticketNoService) Next(tx *gorm.DB, now time.Time) (string, error) {
func (s *ticketNoSequenceService) Next(tx *gorm.DB, now time.Time) (string, error) {
if tx == nil {
return "", fmt.Errorf("ticket number transaction is required")
}
if tx.Dialector.Name() == "sqlite" {
ticketNoSQLiteMu.Lock()
defer ticketNoSQLiteMu.Unlock()
s.ticketNoSQLiteMu.Lock()
defer s.ticketNoSQLiteMu.Unlock()
return s.nextWithRetry(tx, now)
}
return s.nextWithRetry(tx, now)
}
func (s *ticketNoService) nextWithRetry(tx *gorm.DB, now time.Time) (string, error) {
func (s *ticketNoSequenceService) nextWithRetry(tx *gorm.DB, now time.Time) (string, error) {
dateKey := now.Format("20060102")
for attempt := 0; attempt < 100; attempt++ {
current, err := repositories.TicketNoSequenceRepository.GetByDateKeyForUpdate(tx, dateKey)