segments_next.go 810 B

123456789101112131415161718192021222324252627
  1. package repository
  2. import (
  3. "github.com/hwholiday/gid/v2/entity"
  4. "github.com/hwholiday/gid/v2/library/log"
  5. "github.com/hwholiday/gid/v2/library/tool"
  6. "go.uber.org/zap"
  7. )
  8. func (r *Repository) SegmentsIdNext(tag string) (id *entity.Segments, err error) {
  9. var (
  10. tx = r.db.Prepare()
  11. )
  12. id = &entity.Segments{}
  13. if _, err = tx.Exec("update segments set max_id=max_id+step,update_time = ? where biz_tag = ?", tool.GetTimeUnix(), tag); err != nil {
  14. log.GetLogger().Error("[Repository] SegmentsIdNext Update", zap.String("tag", tag), zap.Error(err))
  15. _ = tx.Rollback()
  16. return
  17. }
  18. if _, err = tx.Where("biz_tag = ?", tag).Get(id); err != nil {
  19. log.GetLogger().Error("[Repository] SegmentsIdNext Get", zap.String("tag", tag), zap.Error(err))
  20. _ = tx.Rollback()
  21. return
  22. }
  23. err = tx.Commit()
  24. return
  25. }