whatsapp.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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/agent"
  9. "wechat-api/ent/whatsapp"
  10. "entgo.io/ent"
  11. "entgo.io/ent/dialect/sql"
  12. )
  13. // Whatsapp is the model entity for the Whatsapp schema.
  14. type Whatsapp struct {
  15. config `json:"-"`
  16. // ID of the ent.
  17. ID uint64 `json:"id,omitempty"`
  18. // Create Time | 创建日期
  19. CreatedAt time.Time `json:"created_at,omitempty"`
  20. // Update Time | 修改日期
  21. UpdatedAt time.Time `json:"updated_at,omitempty"`
  22. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  23. Status uint8 `json:"status,omitempty"`
  24. // Delete Time | 删除日期
  25. DeletedAt time.Time `json:"deleted_at,omitempty"`
  26. // 通道ID
  27. WaID string `json:"wa_id,omitempty"`
  28. // 通道名
  29. WaName string `json:"wa_name,omitempty"`
  30. // 回调地址
  31. Callback string `json:"callback,omitempty"`
  32. // AI角色ID
  33. AgentID uint64 `json:"agent_id,omitempty"`
  34. // 账号
  35. Account string `json:"account,omitempty"`
  36. // 国家区号
  37. Cc string `json:"cc,omitempty"`
  38. // 手机号
  39. Phone string `json:"phone,omitempty"`
  40. // 号码名称
  41. PhoneName string `json:"phone_name,omitempty"`
  42. // 号码状态
  43. PhoneStatus int8 `json:"phone_status,omitempty"`
  44. // 机构 ID
  45. OrganizationID uint64 `json:"organization_id,omitempty"`
  46. // 大模型服务账号
  47. APIBase string `json:"api_base,omitempty"`
  48. // 大模型服务密钥
  49. APIKey string `json:"api_key,omitempty"`
  50. // 白名单
  51. AllowList []string `json:"allow_list,omitempty"`
  52. // 群白名单
  53. GroupAllowList []string `json:"group_allow_list,omitempty"`
  54. // 黑名单
  55. BlockList []string `json:"block_list,omitempty"`
  56. // 群黑名单
  57. GroupBlockList []string `json:"group_block_list,omitempty"`
  58. // Edges holds the relations/edges for other nodes in the graph.
  59. // The values are being populated by the WhatsappQuery when eager-loading is set.
  60. Edges WhatsappEdges `json:"edges"`
  61. selectValues sql.SelectValues
  62. }
  63. // WhatsappEdges holds the relations/edges for other nodes in the graph.
  64. type WhatsappEdges struct {
  65. // Agent holds the value of the agent edge.
  66. Agent *Agent `json:"agent,omitempty"`
  67. // loadedTypes holds the information for reporting if a
  68. // type was loaded (or requested) in eager-loading or not.
  69. loadedTypes [1]bool
  70. }
  71. // AgentOrErr returns the Agent value or an error if the edge
  72. // was not loaded in eager-loading, or loaded but was not found.
  73. func (e WhatsappEdges) AgentOrErr() (*Agent, error) {
  74. if e.Agent != nil {
  75. return e.Agent, nil
  76. } else if e.loadedTypes[0] {
  77. return nil, &NotFoundError{label: agent.Label}
  78. }
  79. return nil, &NotLoadedError{edge: "agent"}
  80. }
  81. // scanValues returns the types for scanning values from sql.Rows.
  82. func (*Whatsapp) scanValues(columns []string) ([]any, error) {
  83. values := make([]any, len(columns))
  84. for i := range columns {
  85. switch columns[i] {
  86. case whatsapp.FieldAllowList, whatsapp.FieldGroupAllowList, whatsapp.FieldBlockList, whatsapp.FieldGroupBlockList:
  87. values[i] = new([]byte)
  88. case whatsapp.FieldID, whatsapp.FieldStatus, whatsapp.FieldAgentID, whatsapp.FieldPhoneStatus, whatsapp.FieldOrganizationID:
  89. values[i] = new(sql.NullInt64)
  90. case whatsapp.FieldWaID, whatsapp.FieldWaName, whatsapp.FieldCallback, whatsapp.FieldAccount, whatsapp.FieldCc, whatsapp.FieldPhone, whatsapp.FieldPhoneName, whatsapp.FieldAPIBase, whatsapp.FieldAPIKey:
  91. values[i] = new(sql.NullString)
  92. case whatsapp.FieldCreatedAt, whatsapp.FieldUpdatedAt, whatsapp.FieldDeletedAt:
  93. values[i] = new(sql.NullTime)
  94. default:
  95. values[i] = new(sql.UnknownType)
  96. }
  97. }
  98. return values, nil
  99. }
  100. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  101. // to the Whatsapp fields.
  102. func (w *Whatsapp) assignValues(columns []string, values []any) error {
  103. if m, n := len(values), len(columns); m < n {
  104. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  105. }
  106. for i := range columns {
  107. switch columns[i] {
  108. case whatsapp.FieldID:
  109. value, ok := values[i].(*sql.NullInt64)
  110. if !ok {
  111. return fmt.Errorf("unexpected type %T for field id", value)
  112. }
  113. w.ID = uint64(value.Int64)
  114. case whatsapp.FieldCreatedAt:
  115. if value, ok := values[i].(*sql.NullTime); !ok {
  116. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  117. } else if value.Valid {
  118. w.CreatedAt = value.Time
  119. }
  120. case whatsapp.FieldUpdatedAt:
  121. if value, ok := values[i].(*sql.NullTime); !ok {
  122. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  123. } else if value.Valid {
  124. w.UpdatedAt = value.Time
  125. }
  126. case whatsapp.FieldStatus:
  127. if value, ok := values[i].(*sql.NullInt64); !ok {
  128. return fmt.Errorf("unexpected type %T for field status", values[i])
  129. } else if value.Valid {
  130. w.Status = uint8(value.Int64)
  131. }
  132. case whatsapp.FieldDeletedAt:
  133. if value, ok := values[i].(*sql.NullTime); !ok {
  134. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  135. } else if value.Valid {
  136. w.DeletedAt = value.Time
  137. }
  138. case whatsapp.FieldWaID:
  139. if value, ok := values[i].(*sql.NullString); !ok {
  140. return fmt.Errorf("unexpected type %T for field wa_id", values[i])
  141. } else if value.Valid {
  142. w.WaID = value.String
  143. }
  144. case whatsapp.FieldWaName:
  145. if value, ok := values[i].(*sql.NullString); !ok {
  146. return fmt.Errorf("unexpected type %T for field wa_name", values[i])
  147. } else if value.Valid {
  148. w.WaName = value.String
  149. }
  150. case whatsapp.FieldCallback:
  151. if value, ok := values[i].(*sql.NullString); !ok {
  152. return fmt.Errorf("unexpected type %T for field callback", values[i])
  153. } else if value.Valid {
  154. w.Callback = value.String
  155. }
  156. case whatsapp.FieldAgentID:
  157. if value, ok := values[i].(*sql.NullInt64); !ok {
  158. return fmt.Errorf("unexpected type %T for field agent_id", values[i])
  159. } else if value.Valid {
  160. w.AgentID = uint64(value.Int64)
  161. }
  162. case whatsapp.FieldAccount:
  163. if value, ok := values[i].(*sql.NullString); !ok {
  164. return fmt.Errorf("unexpected type %T for field account", values[i])
  165. } else if value.Valid {
  166. w.Account = value.String
  167. }
  168. case whatsapp.FieldCc:
  169. if value, ok := values[i].(*sql.NullString); !ok {
  170. return fmt.Errorf("unexpected type %T for field cc", values[i])
  171. } else if value.Valid {
  172. w.Cc = value.String
  173. }
  174. case whatsapp.FieldPhone:
  175. if value, ok := values[i].(*sql.NullString); !ok {
  176. return fmt.Errorf("unexpected type %T for field phone", values[i])
  177. } else if value.Valid {
  178. w.Phone = value.String
  179. }
  180. case whatsapp.FieldPhoneName:
  181. if value, ok := values[i].(*sql.NullString); !ok {
  182. return fmt.Errorf("unexpected type %T for field phone_name", values[i])
  183. } else if value.Valid {
  184. w.PhoneName = value.String
  185. }
  186. case whatsapp.FieldPhoneStatus:
  187. if value, ok := values[i].(*sql.NullInt64); !ok {
  188. return fmt.Errorf("unexpected type %T for field phone_status", values[i])
  189. } else if value.Valid {
  190. w.PhoneStatus = int8(value.Int64)
  191. }
  192. case whatsapp.FieldOrganizationID:
  193. if value, ok := values[i].(*sql.NullInt64); !ok {
  194. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  195. } else if value.Valid {
  196. w.OrganizationID = uint64(value.Int64)
  197. }
  198. case whatsapp.FieldAPIBase:
  199. if value, ok := values[i].(*sql.NullString); !ok {
  200. return fmt.Errorf("unexpected type %T for field api_base", values[i])
  201. } else if value.Valid {
  202. w.APIBase = value.String
  203. }
  204. case whatsapp.FieldAPIKey:
  205. if value, ok := values[i].(*sql.NullString); !ok {
  206. return fmt.Errorf("unexpected type %T for field api_key", values[i])
  207. } else if value.Valid {
  208. w.APIKey = value.String
  209. }
  210. case whatsapp.FieldAllowList:
  211. if value, ok := values[i].(*[]byte); !ok {
  212. return fmt.Errorf("unexpected type %T for field allow_list", values[i])
  213. } else if value != nil && len(*value) > 0 {
  214. if err := json.Unmarshal(*value, &w.AllowList); err != nil {
  215. return fmt.Errorf("unmarshal field allow_list: %w", err)
  216. }
  217. }
  218. case whatsapp.FieldGroupAllowList:
  219. if value, ok := values[i].(*[]byte); !ok {
  220. return fmt.Errorf("unexpected type %T for field group_allow_list", values[i])
  221. } else if value != nil && len(*value) > 0 {
  222. if err := json.Unmarshal(*value, &w.GroupAllowList); err != nil {
  223. return fmt.Errorf("unmarshal field group_allow_list: %w", err)
  224. }
  225. }
  226. case whatsapp.FieldBlockList:
  227. if value, ok := values[i].(*[]byte); !ok {
  228. return fmt.Errorf("unexpected type %T for field block_list", values[i])
  229. } else if value != nil && len(*value) > 0 {
  230. if err := json.Unmarshal(*value, &w.BlockList); err != nil {
  231. return fmt.Errorf("unmarshal field block_list: %w", err)
  232. }
  233. }
  234. case whatsapp.FieldGroupBlockList:
  235. if value, ok := values[i].(*[]byte); !ok {
  236. return fmt.Errorf("unexpected type %T for field group_block_list", values[i])
  237. } else if value != nil && len(*value) > 0 {
  238. if err := json.Unmarshal(*value, &w.GroupBlockList); err != nil {
  239. return fmt.Errorf("unmarshal field group_block_list: %w", err)
  240. }
  241. }
  242. default:
  243. w.selectValues.Set(columns[i], values[i])
  244. }
  245. }
  246. return nil
  247. }
  248. // Value returns the ent.Value that was dynamically selected and assigned to the Whatsapp.
  249. // This includes values selected through modifiers, order, etc.
  250. func (w *Whatsapp) Value(name string) (ent.Value, error) {
  251. return w.selectValues.Get(name)
  252. }
  253. // QueryAgent queries the "agent" edge of the Whatsapp entity.
  254. func (w *Whatsapp) QueryAgent() *AgentQuery {
  255. return NewWhatsappClient(w.config).QueryAgent(w)
  256. }
  257. // Update returns a builder for updating this Whatsapp.
  258. // Note that you need to call Whatsapp.Unwrap() before calling this method if this Whatsapp
  259. // was returned from a transaction, and the transaction was committed or rolled back.
  260. func (w *Whatsapp) Update() *WhatsappUpdateOne {
  261. return NewWhatsappClient(w.config).UpdateOne(w)
  262. }
  263. // Unwrap unwraps the Whatsapp entity that was returned from a transaction after it was closed,
  264. // so that all future queries will be executed through the driver which created the transaction.
  265. func (w *Whatsapp) Unwrap() *Whatsapp {
  266. _tx, ok := w.config.driver.(*txDriver)
  267. if !ok {
  268. panic("ent: Whatsapp is not a transactional entity")
  269. }
  270. w.config.driver = _tx.drv
  271. return w
  272. }
  273. // String implements the fmt.Stringer.
  274. func (w *Whatsapp) String() string {
  275. var builder strings.Builder
  276. builder.WriteString("Whatsapp(")
  277. builder.WriteString(fmt.Sprintf("id=%v, ", w.ID))
  278. builder.WriteString("created_at=")
  279. builder.WriteString(w.CreatedAt.Format(time.ANSIC))
  280. builder.WriteString(", ")
  281. builder.WriteString("updated_at=")
  282. builder.WriteString(w.UpdatedAt.Format(time.ANSIC))
  283. builder.WriteString(", ")
  284. builder.WriteString("status=")
  285. builder.WriteString(fmt.Sprintf("%v", w.Status))
  286. builder.WriteString(", ")
  287. builder.WriteString("deleted_at=")
  288. builder.WriteString(w.DeletedAt.Format(time.ANSIC))
  289. builder.WriteString(", ")
  290. builder.WriteString("wa_id=")
  291. builder.WriteString(w.WaID)
  292. builder.WriteString(", ")
  293. builder.WriteString("wa_name=")
  294. builder.WriteString(w.WaName)
  295. builder.WriteString(", ")
  296. builder.WriteString("callback=")
  297. builder.WriteString(w.Callback)
  298. builder.WriteString(", ")
  299. builder.WriteString("agent_id=")
  300. builder.WriteString(fmt.Sprintf("%v", w.AgentID))
  301. builder.WriteString(", ")
  302. builder.WriteString("account=")
  303. builder.WriteString(w.Account)
  304. builder.WriteString(", ")
  305. builder.WriteString("cc=")
  306. builder.WriteString(w.Cc)
  307. builder.WriteString(", ")
  308. builder.WriteString("phone=")
  309. builder.WriteString(w.Phone)
  310. builder.WriteString(", ")
  311. builder.WriteString("phone_name=")
  312. builder.WriteString(w.PhoneName)
  313. builder.WriteString(", ")
  314. builder.WriteString("phone_status=")
  315. builder.WriteString(fmt.Sprintf("%v", w.PhoneStatus))
  316. builder.WriteString(", ")
  317. builder.WriteString("organization_id=")
  318. builder.WriteString(fmt.Sprintf("%v", w.OrganizationID))
  319. builder.WriteString(", ")
  320. builder.WriteString("api_base=")
  321. builder.WriteString(w.APIBase)
  322. builder.WriteString(", ")
  323. builder.WriteString("api_key=")
  324. builder.WriteString(w.APIKey)
  325. builder.WriteString(", ")
  326. builder.WriteString("allow_list=")
  327. builder.WriteString(fmt.Sprintf("%v", w.AllowList))
  328. builder.WriteString(", ")
  329. builder.WriteString("group_allow_list=")
  330. builder.WriteString(fmt.Sprintf("%v", w.GroupAllowList))
  331. builder.WriteString(", ")
  332. builder.WriteString("block_list=")
  333. builder.WriteString(fmt.Sprintf("%v", w.BlockList))
  334. builder.WriteString(", ")
  335. builder.WriteString("group_block_list=")
  336. builder.WriteString(fmt.Sprintf("%v", w.GroupBlockList))
  337. builder.WriteByte(')')
  338. return builder.String()
  339. }
  340. // Whatsapps is a parsable slice of Whatsapp.
  341. type Whatsapps []*Whatsapp