event.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package model
  2. import (
  3. "net/url"
  4. "strings"
  5. xtime "go-common/library/time"
  6. )
  7. // consts for workflow event
  8. const (
  9. // EventAdminReply 管理员回复
  10. EventAdminReply = 1
  11. // EventAdminNote 管理员回复并记录
  12. EventAdminNote = 2
  13. // EventUserReply 用户回复
  14. EventUserReply = 3
  15. // EventSystem 系统回复
  16. EventSystem = 4
  17. )
  18. // EventSlice is a Event slice struct
  19. type EventSlice []*Event
  20. // Event model is the model for challenge changes
  21. type Event struct {
  22. Eid int64 `json:"eid" gorm:"column:id"`
  23. Cid int64 `json:"cid" gorm:"column:cid"`
  24. AdminID int64 `json:"adminid" gorm:"column:adminid"`
  25. Content string `json:"content" gorm:"column:content"`
  26. Attachments string `json:"attachments" gorm:"column:attachments"`
  27. Event int8 `json:"event" gorm:"column:event"`
  28. CTime xtime.Time `json:"ctime" gorm:"column:ctime"`
  29. MTime xtime.Time `json:"mtime" gorm:"column:mtime"`
  30. Admin string `json:"admin" gorm:"-"`
  31. }
  32. // TableName is used to identify table name in gorm
  33. func (Event) TableName() string {
  34. return "workflow_event"
  35. }
  36. // FixAttachments will fix attachments url as user friendly
  37. // ignore https case
  38. // FIXME: this should be removed after attachment url is be normed
  39. func (e *Event) FixAttachments() {
  40. if len(e.Attachments) <= 0 {
  41. return
  42. }
  43. sep := ";"
  44. atts := strings.Split(e.Attachments, sep)
  45. fixed := make([]string, 0, len(atts))
  46. for _, a := range atts {
  47. u, err := url.Parse(a)
  48. if err != nil {
  49. continue
  50. }
  51. u.Scheme = "http"
  52. fixed = append(fixed, u.String())
  53. }
  54. e.Attachments = strings.Join(fixed, sep)
  55. }