msg.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/msg"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // Msg is the model entity for the Msg schema.
  12. type Msg struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID uint64 `json:"id,omitempty"`
  16. // Create Time | 创建日期
  17. CreatedAt time.Time `json:"created_at,omitempty"`
  18. // Update Time | 修改日期
  19. UpdatedAt time.Time `json:"updated_at,omitempty"`
  20. // Delete Time | 删除日期
  21. DeletedAt time.Time `json:"deleted_at,omitempty"`
  22. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  23. Status uint8 `json:"status,omitempty"`
  24. // 发送方微信ID
  25. Fromwxid string `json:"fromwxid,omitempty"`
  26. // 接收人微信ID/群ID
  27. Toid string `json:"toid,omitempty"`
  28. // 消息类型
  29. Msgtype int32 `json:"msgtype,omitempty"`
  30. // 消息
  31. Msg string `json:"msg,omitempty"`
  32. // 批次号
  33. BatchNo string `json:"batch_no,omitempty"`
  34. // 内容类型:1-微信 2-whatsapp
  35. Ctype uint64 `json:"ctype,omitempty"`
  36. // 国家区号
  37. Cc string `json:"cc,omitempty"`
  38. // 手机号
  39. Phone string `json:"phone,omitempty"`
  40. selectValues sql.SelectValues
  41. }
  42. // scanValues returns the types for scanning values from sql.Rows.
  43. func (*Msg) scanValues(columns []string) ([]any, error) {
  44. values := make([]any, len(columns))
  45. for i := range columns {
  46. switch columns[i] {
  47. case msg.FieldID, msg.FieldStatus, msg.FieldMsgtype, msg.FieldCtype:
  48. values[i] = new(sql.NullInt64)
  49. case msg.FieldFromwxid, msg.FieldToid, msg.FieldMsg, msg.FieldBatchNo, msg.FieldCc, msg.FieldPhone:
  50. values[i] = new(sql.NullString)
  51. case msg.FieldCreatedAt, msg.FieldUpdatedAt, msg.FieldDeletedAt:
  52. values[i] = new(sql.NullTime)
  53. default:
  54. values[i] = new(sql.UnknownType)
  55. }
  56. }
  57. return values, nil
  58. }
  59. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  60. // to the Msg fields.
  61. func (m *Msg) assignValues(columns []string, values []any) error {
  62. if m, n := len(values), len(columns); m < n {
  63. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  64. }
  65. for i := range columns {
  66. switch columns[i] {
  67. case msg.FieldID:
  68. value, ok := values[i].(*sql.NullInt64)
  69. if !ok {
  70. return fmt.Errorf("unexpected type %T for field id", value)
  71. }
  72. m.ID = uint64(value.Int64)
  73. case msg.FieldCreatedAt:
  74. if value, ok := values[i].(*sql.NullTime); !ok {
  75. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  76. } else if value.Valid {
  77. m.CreatedAt = value.Time
  78. }
  79. case msg.FieldUpdatedAt:
  80. if value, ok := values[i].(*sql.NullTime); !ok {
  81. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  82. } else if value.Valid {
  83. m.UpdatedAt = value.Time
  84. }
  85. case msg.FieldDeletedAt:
  86. if value, ok := values[i].(*sql.NullTime); !ok {
  87. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  88. } else if value.Valid {
  89. m.DeletedAt = value.Time
  90. }
  91. case msg.FieldStatus:
  92. if value, ok := values[i].(*sql.NullInt64); !ok {
  93. return fmt.Errorf("unexpected type %T for field status", values[i])
  94. } else if value.Valid {
  95. m.Status = uint8(value.Int64)
  96. }
  97. case msg.FieldFromwxid:
  98. if value, ok := values[i].(*sql.NullString); !ok {
  99. return fmt.Errorf("unexpected type %T for field fromwxid", values[i])
  100. } else if value.Valid {
  101. m.Fromwxid = value.String
  102. }
  103. case msg.FieldToid:
  104. if value, ok := values[i].(*sql.NullString); !ok {
  105. return fmt.Errorf("unexpected type %T for field toid", values[i])
  106. } else if value.Valid {
  107. m.Toid = value.String
  108. }
  109. case msg.FieldMsgtype:
  110. if value, ok := values[i].(*sql.NullInt64); !ok {
  111. return fmt.Errorf("unexpected type %T for field msgtype", values[i])
  112. } else if value.Valid {
  113. m.Msgtype = int32(value.Int64)
  114. }
  115. case msg.FieldMsg:
  116. if value, ok := values[i].(*sql.NullString); !ok {
  117. return fmt.Errorf("unexpected type %T for field msg", values[i])
  118. } else if value.Valid {
  119. m.Msg = value.String
  120. }
  121. case msg.FieldBatchNo:
  122. if value, ok := values[i].(*sql.NullString); !ok {
  123. return fmt.Errorf("unexpected type %T for field batch_no", values[i])
  124. } else if value.Valid {
  125. m.BatchNo = value.String
  126. }
  127. case msg.FieldCtype:
  128. if value, ok := values[i].(*sql.NullInt64); !ok {
  129. return fmt.Errorf("unexpected type %T for field ctype", values[i])
  130. } else if value.Valid {
  131. m.Ctype = uint64(value.Int64)
  132. }
  133. case msg.FieldCc:
  134. if value, ok := values[i].(*sql.NullString); !ok {
  135. return fmt.Errorf("unexpected type %T for field cc", values[i])
  136. } else if value.Valid {
  137. m.Cc = value.String
  138. }
  139. case msg.FieldPhone:
  140. if value, ok := values[i].(*sql.NullString); !ok {
  141. return fmt.Errorf("unexpected type %T for field phone", values[i])
  142. } else if value.Valid {
  143. m.Phone = value.String
  144. }
  145. default:
  146. m.selectValues.Set(columns[i], values[i])
  147. }
  148. }
  149. return nil
  150. }
  151. // Value returns the ent.Value that was dynamically selected and assigned to the Msg.
  152. // This includes values selected through modifiers, order, etc.
  153. func (m *Msg) Value(name string) (ent.Value, error) {
  154. return m.selectValues.Get(name)
  155. }
  156. // Update returns a builder for updating this Msg.
  157. // Note that you need to call Msg.Unwrap() before calling this method if this Msg
  158. // was returned from a transaction, and the transaction was committed or rolled back.
  159. func (m *Msg) Update() *MsgUpdateOne {
  160. return NewMsgClient(m.config).UpdateOne(m)
  161. }
  162. // Unwrap unwraps the Msg entity that was returned from a transaction after it was closed,
  163. // so that all future queries will be executed through the driver which created the transaction.
  164. func (m *Msg) Unwrap() *Msg {
  165. _tx, ok := m.config.driver.(*txDriver)
  166. if !ok {
  167. panic("ent: Msg is not a transactional entity")
  168. }
  169. m.config.driver = _tx.drv
  170. return m
  171. }
  172. // String implements the fmt.Stringer.
  173. func (m *Msg) String() string {
  174. var builder strings.Builder
  175. builder.WriteString("Msg(")
  176. builder.WriteString(fmt.Sprintf("id=%v, ", m.ID))
  177. builder.WriteString("created_at=")
  178. builder.WriteString(m.CreatedAt.Format(time.ANSIC))
  179. builder.WriteString(", ")
  180. builder.WriteString("updated_at=")
  181. builder.WriteString(m.UpdatedAt.Format(time.ANSIC))
  182. builder.WriteString(", ")
  183. builder.WriteString("deleted_at=")
  184. builder.WriteString(m.DeletedAt.Format(time.ANSIC))
  185. builder.WriteString(", ")
  186. builder.WriteString("status=")
  187. builder.WriteString(fmt.Sprintf("%v", m.Status))
  188. builder.WriteString(", ")
  189. builder.WriteString("fromwxid=")
  190. builder.WriteString(m.Fromwxid)
  191. builder.WriteString(", ")
  192. builder.WriteString("toid=")
  193. builder.WriteString(m.Toid)
  194. builder.WriteString(", ")
  195. builder.WriteString("msgtype=")
  196. builder.WriteString(fmt.Sprintf("%v", m.Msgtype))
  197. builder.WriteString(", ")
  198. builder.WriteString("msg=")
  199. builder.WriteString(m.Msg)
  200. builder.WriteString(", ")
  201. builder.WriteString("batch_no=")
  202. builder.WriteString(m.BatchNo)
  203. builder.WriteString(", ")
  204. builder.WriteString("ctype=")
  205. builder.WriteString(fmt.Sprintf("%v", m.Ctype))
  206. builder.WriteString(", ")
  207. builder.WriteString("cc=")
  208. builder.WriteString(m.Cc)
  209. builder.WriteString(", ")
  210. builder.WriteString("phone=")
  211. builder.WriteString(m.Phone)
  212. builder.WriteByte(')')
  213. return builder.String()
  214. }
  215. // Msgs is a parsable slice of Msg.
  216. type Msgs []*Msg