whatsapp.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "wechat-api/ent/whatsapp"
  9. "entgo.io/ent"
  10. "entgo.io/ent/dialect/sql"
  11. )
  12. // Whatsapp is the model entity for the Whatsapp schema.
  13. type Whatsapp struct {
  14. config `json:"-"`
  15. // ID of the ent.
  16. ID uint64 `json:"id,omitempty"`
  17. // Create Time | 创建日期
  18. CreatedAt time.Time `json:"created_at,omitempty"`
  19. // Update Time | 修改日期
  20. UpdatedAt time.Time `json:"updated_at,omitempty"`
  21. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  22. Status uint8 `json:"status,omitempty"`
  23. // Delete Time | 删除日期
  24. DeletedAt time.Time `json:"deleted_at,omitempty"`
  25. // ak
  26. Ak string `json:"ak,omitempty"`
  27. // 端口号
  28. Sk string `json:"sk,omitempty"`
  29. // 回调地址
  30. Callback string `json:"callback,omitempty"`
  31. // 微信账号
  32. Account string `json:"account,omitempty"`
  33. // 昵称
  34. Nickname string `json:"nickname,omitempty"`
  35. // 手机号
  36. Phone string `json:"phone,omitempty"`
  37. // 机构 ID
  38. OrganizationID uint64 `json:"organization_id,omitempty"`
  39. // 模式ID
  40. AgentID uint64 `json:"agent_id,omitempty"`
  41. // 大模型服务地址
  42. APIBase string `json:"api_base,omitempty"`
  43. // 大模型服务密钥
  44. APIKey string `json:"api_key,omitempty"`
  45. // 白名单
  46. AllowList []string `json:"allow_list,omitempty"`
  47. // 群白名单
  48. GroupAllowList []string `json:"group_allow_list,omitempty"`
  49. // 黑名单
  50. BlockList []string `json:"block_list,omitempty"`
  51. // 群黑名单
  52. GroupBlockList []string `json:"group_block_list,omitempty"`
  53. selectValues sql.SelectValues
  54. }
  55. // scanValues returns the types for scanning values from sql.Rows.
  56. func (*Whatsapp) scanValues(columns []string) ([]any, error) {
  57. values := make([]any, len(columns))
  58. for i := range columns {
  59. switch columns[i] {
  60. case whatsapp.FieldAllowList, whatsapp.FieldGroupAllowList, whatsapp.FieldBlockList, whatsapp.FieldGroupBlockList:
  61. values[i] = new([]byte)
  62. case whatsapp.FieldID, whatsapp.FieldStatus, whatsapp.FieldOrganizationID, whatsapp.FieldAgentID:
  63. values[i] = new(sql.NullInt64)
  64. case whatsapp.FieldAk, whatsapp.FieldSk, whatsapp.FieldCallback, whatsapp.FieldAccount, whatsapp.FieldNickname, whatsapp.FieldPhone, whatsapp.FieldAPIBase, whatsapp.FieldAPIKey:
  65. values[i] = new(sql.NullString)
  66. case whatsapp.FieldCreatedAt, whatsapp.FieldUpdatedAt, whatsapp.FieldDeletedAt:
  67. values[i] = new(sql.NullTime)
  68. default:
  69. values[i] = new(sql.UnknownType)
  70. }
  71. }
  72. return values, nil
  73. }
  74. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  75. // to the Whatsapp fields.
  76. func (w *Whatsapp) assignValues(columns []string, values []any) error {
  77. if m, n := len(values), len(columns); m < n {
  78. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  79. }
  80. for i := range columns {
  81. switch columns[i] {
  82. case whatsapp.FieldID:
  83. value, ok := values[i].(*sql.NullInt64)
  84. if !ok {
  85. return fmt.Errorf("unexpected type %T for field id", value)
  86. }
  87. w.ID = uint64(value.Int64)
  88. case whatsapp.FieldCreatedAt:
  89. if value, ok := values[i].(*sql.NullTime); !ok {
  90. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  91. } else if value.Valid {
  92. w.CreatedAt = value.Time
  93. }
  94. case whatsapp.FieldUpdatedAt:
  95. if value, ok := values[i].(*sql.NullTime); !ok {
  96. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  97. } else if value.Valid {
  98. w.UpdatedAt = value.Time
  99. }
  100. case whatsapp.FieldStatus:
  101. if value, ok := values[i].(*sql.NullInt64); !ok {
  102. return fmt.Errorf("unexpected type %T for field status", values[i])
  103. } else if value.Valid {
  104. w.Status = uint8(value.Int64)
  105. }
  106. case whatsapp.FieldDeletedAt:
  107. if value, ok := values[i].(*sql.NullTime); !ok {
  108. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  109. } else if value.Valid {
  110. w.DeletedAt = value.Time
  111. }
  112. case whatsapp.FieldAk:
  113. if value, ok := values[i].(*sql.NullString); !ok {
  114. return fmt.Errorf("unexpected type %T for field ak", values[i])
  115. } else if value.Valid {
  116. w.Ak = value.String
  117. }
  118. case whatsapp.FieldSk:
  119. if value, ok := values[i].(*sql.NullString); !ok {
  120. return fmt.Errorf("unexpected type %T for field sk", values[i])
  121. } else if value.Valid {
  122. w.Sk = value.String
  123. }
  124. case whatsapp.FieldCallback:
  125. if value, ok := values[i].(*sql.NullString); !ok {
  126. return fmt.Errorf("unexpected type %T for field callback", values[i])
  127. } else if value.Valid {
  128. w.Callback = value.String
  129. }
  130. case whatsapp.FieldAccount:
  131. if value, ok := values[i].(*sql.NullString); !ok {
  132. return fmt.Errorf("unexpected type %T for field account", values[i])
  133. } else if value.Valid {
  134. w.Account = value.String
  135. }
  136. case whatsapp.FieldNickname:
  137. if value, ok := values[i].(*sql.NullString); !ok {
  138. return fmt.Errorf("unexpected type %T for field nickname", values[i])
  139. } else if value.Valid {
  140. w.Nickname = value.String
  141. }
  142. case whatsapp.FieldPhone:
  143. if value, ok := values[i].(*sql.NullString); !ok {
  144. return fmt.Errorf("unexpected type %T for field phone", values[i])
  145. } else if value.Valid {
  146. w.Phone = value.String
  147. }
  148. case whatsapp.FieldOrganizationID:
  149. if value, ok := values[i].(*sql.NullInt64); !ok {
  150. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  151. } else if value.Valid {
  152. w.OrganizationID = uint64(value.Int64)
  153. }
  154. case whatsapp.FieldAgentID:
  155. if value, ok := values[i].(*sql.NullInt64); !ok {
  156. return fmt.Errorf("unexpected type %T for field agent_id", values[i])
  157. } else if value.Valid {
  158. w.AgentID = uint64(value.Int64)
  159. }
  160. case whatsapp.FieldAPIBase:
  161. if value, ok := values[i].(*sql.NullString); !ok {
  162. return fmt.Errorf("unexpected type %T for field api_base", values[i])
  163. } else if value.Valid {
  164. w.APIBase = value.String
  165. }
  166. case whatsapp.FieldAPIKey:
  167. if value, ok := values[i].(*sql.NullString); !ok {
  168. return fmt.Errorf("unexpected type %T for field api_key", values[i])
  169. } else if value.Valid {
  170. w.APIKey = value.String
  171. }
  172. case whatsapp.FieldAllowList:
  173. if value, ok := values[i].(*[]byte); !ok {
  174. return fmt.Errorf("unexpected type %T for field allow_list", values[i])
  175. } else if value != nil && len(*value) > 0 {
  176. if err := json.Unmarshal(*value, &w.AllowList); err != nil {
  177. return fmt.Errorf("unmarshal field allow_list: %w", err)
  178. }
  179. }
  180. case whatsapp.FieldGroupAllowList:
  181. if value, ok := values[i].(*[]byte); !ok {
  182. return fmt.Errorf("unexpected type %T for field group_allow_list", values[i])
  183. } else if value != nil && len(*value) > 0 {
  184. if err := json.Unmarshal(*value, &w.GroupAllowList); err != nil {
  185. return fmt.Errorf("unmarshal field group_allow_list: %w", err)
  186. }
  187. }
  188. case whatsapp.FieldBlockList:
  189. if value, ok := values[i].(*[]byte); !ok {
  190. return fmt.Errorf("unexpected type %T for field block_list", values[i])
  191. } else if value != nil && len(*value) > 0 {
  192. if err := json.Unmarshal(*value, &w.BlockList); err != nil {
  193. return fmt.Errorf("unmarshal field block_list: %w", err)
  194. }
  195. }
  196. case whatsapp.FieldGroupBlockList:
  197. if value, ok := values[i].(*[]byte); !ok {
  198. return fmt.Errorf("unexpected type %T for field group_block_list", values[i])
  199. } else if value != nil && len(*value) > 0 {
  200. if err := json.Unmarshal(*value, &w.GroupBlockList); err != nil {
  201. return fmt.Errorf("unmarshal field group_block_list: %w", err)
  202. }
  203. }
  204. default:
  205. w.selectValues.Set(columns[i], values[i])
  206. }
  207. }
  208. return nil
  209. }
  210. // Value returns the ent.Value that was dynamically selected and assigned to the Whatsapp.
  211. // This includes values selected through modifiers, order, etc.
  212. func (w *Whatsapp) Value(name string) (ent.Value, error) {
  213. return w.selectValues.Get(name)
  214. }
  215. // Update returns a builder for updating this Whatsapp.
  216. // Note that you need to call Whatsapp.Unwrap() before calling this method if this Whatsapp
  217. // was returned from a transaction, and the transaction was committed or rolled back.
  218. func (w *Whatsapp) Update() *WhatsappUpdateOne {
  219. return NewWhatsappClient(w.config).UpdateOne(w)
  220. }
  221. // Unwrap unwraps the Whatsapp entity that was returned from a transaction after it was closed,
  222. // so that all future queries will be executed through the driver which created the transaction.
  223. func (w *Whatsapp) Unwrap() *Whatsapp {
  224. _tx, ok := w.config.driver.(*txDriver)
  225. if !ok {
  226. panic("ent: Whatsapp is not a transactional entity")
  227. }
  228. w.config.driver = _tx.drv
  229. return w
  230. }
  231. // String implements the fmt.Stringer.
  232. func (w *Whatsapp) String() string {
  233. var builder strings.Builder
  234. builder.WriteString("Whatsapp(")
  235. builder.WriteString(fmt.Sprintf("id=%v, ", w.ID))
  236. builder.WriteString("created_at=")
  237. builder.WriteString(w.CreatedAt.Format(time.ANSIC))
  238. builder.WriteString(", ")
  239. builder.WriteString("updated_at=")
  240. builder.WriteString(w.UpdatedAt.Format(time.ANSIC))
  241. builder.WriteString(", ")
  242. builder.WriteString("status=")
  243. builder.WriteString(fmt.Sprintf("%v", w.Status))
  244. builder.WriteString(", ")
  245. builder.WriteString("deleted_at=")
  246. builder.WriteString(w.DeletedAt.Format(time.ANSIC))
  247. builder.WriteString(", ")
  248. builder.WriteString("ak=")
  249. builder.WriteString(w.Ak)
  250. builder.WriteString(", ")
  251. builder.WriteString("sk=")
  252. builder.WriteString(w.Sk)
  253. builder.WriteString(", ")
  254. builder.WriteString("callback=")
  255. builder.WriteString(w.Callback)
  256. builder.WriteString(", ")
  257. builder.WriteString("account=")
  258. builder.WriteString(w.Account)
  259. builder.WriteString(", ")
  260. builder.WriteString("nickname=")
  261. builder.WriteString(w.Nickname)
  262. builder.WriteString(", ")
  263. builder.WriteString("phone=")
  264. builder.WriteString(w.Phone)
  265. builder.WriteString(", ")
  266. builder.WriteString("organization_id=")
  267. builder.WriteString(fmt.Sprintf("%v", w.OrganizationID))
  268. builder.WriteString(", ")
  269. builder.WriteString("agent_id=")
  270. builder.WriteString(fmt.Sprintf("%v", w.AgentID))
  271. builder.WriteString(", ")
  272. builder.WriteString("api_base=")
  273. builder.WriteString(w.APIBase)
  274. builder.WriteString(", ")
  275. builder.WriteString("api_key=")
  276. builder.WriteString(w.APIKey)
  277. builder.WriteString(", ")
  278. builder.WriteString("allow_list=")
  279. builder.WriteString(fmt.Sprintf("%v", w.AllowList))
  280. builder.WriteString(", ")
  281. builder.WriteString("group_allow_list=")
  282. builder.WriteString(fmt.Sprintf("%v", w.GroupAllowList))
  283. builder.WriteString(", ")
  284. builder.WriteString("block_list=")
  285. builder.WriteString(fmt.Sprintf("%v", w.BlockList))
  286. builder.WriteString(", ")
  287. builder.WriteString("group_block_list=")
  288. builder.WriteString(fmt.Sprintf("%v", w.GroupBlockList))
  289. builder.WriteByte(')')
  290. return builder.String()
  291. }
  292. // Whatsapps is a parsable slice of Whatsapp.
  293. type Whatsapps []*Whatsapp