segments_create.go 736 B

12345678910111213141516171819202122232425262728
  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) SegmentsCreate(s *entity.Segments) (data *entity.Segments, err error) {
  9. var has bool
  10. data = new(entity.Segments)
  11. if has, err = r.db.Where("biz_tag = ?", s.BizTag).Get(data); err != nil {
  12. log.GetLogger().Error("[SegmentsCreate] Exist", zap.Any("req", s), zap.Error(err))
  13. return
  14. }
  15. if has {
  16. return
  17. }
  18. s.CreateTime = tool.GetTimeUnix()
  19. s.UpdateTime = tool.GetTimeUnix()
  20. if _, err = r.db.Insert(s); err != nil {
  21. log.GetLogger().Error("[SegmentsCreate] Create", zap.Any("req", s), zap.Error(err))
  22. return
  23. }
  24. data = s
  25. return
  26. }