usagestatisticmonth.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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/custom_types"
  9. "wechat-api/ent/usagestatisticmonth"
  10. "entgo.io/ent"
  11. "entgo.io/ent/dialect/sql"
  12. )
  13. // UsageStatisticMonth is the model entity for the UsageStatisticMonth schema.
  14. type UsageStatisticMonth 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. // 写入年月
  27. Addtime uint64 `json:"addtime,omitempty"`
  28. // 1-微信 2-名片
  29. Type int `json:"type,omitempty"`
  30. // 微信或名片id
  31. BotID string `json:"bot_id,omitempty"`
  32. // 机构ID
  33. OrganizationID uint64 `json:"organization_id,omitempty"`
  34. // AI回复次数
  35. AiResponse uint64 `json:"ai_response,omitempty"`
  36. // SOP运行次数
  37. SopRun uint64 `json:"sop_run,omitempty"`
  38. // 好友总数
  39. TotalFriend uint64 `json:"total_friend,omitempty"`
  40. // 群总数
  41. TotalGroup uint64 `json:"total_group,omitempty"`
  42. // 账户余额(单位:分)
  43. AccountBalance uint64 `json:"account_balance,omitempty"`
  44. // 消耗token数
  45. ConsumeToken uint64 `json:"consume_token,omitempty"`
  46. // 活跃用户数
  47. ActiveUser uint64 `json:"active_user,omitempty"`
  48. // 新增用户数
  49. NewUser int64 `json:"new_user,omitempty"`
  50. // 标签分布
  51. LabelDist []custom_types.LabelDist `json:"label_dist,omitempty"`
  52. // 消耗积分
  53. ConsumeCoin uint64 `json:"consume_coin,omitempty"`
  54. selectValues sql.SelectValues
  55. }
  56. // scanValues returns the types for scanning values from sql.Rows.
  57. func (*UsageStatisticMonth) scanValues(columns []string) ([]any, error) {
  58. values := make([]any, len(columns))
  59. for i := range columns {
  60. switch columns[i] {
  61. case usagestatisticmonth.FieldLabelDist:
  62. values[i] = new([]byte)
  63. case usagestatisticmonth.FieldID, usagestatisticmonth.FieldStatus, usagestatisticmonth.FieldAddtime, usagestatisticmonth.FieldType, usagestatisticmonth.FieldOrganizationID, usagestatisticmonth.FieldAiResponse, usagestatisticmonth.FieldSopRun, usagestatisticmonth.FieldTotalFriend, usagestatisticmonth.FieldTotalGroup, usagestatisticmonth.FieldAccountBalance, usagestatisticmonth.FieldConsumeToken, usagestatisticmonth.FieldActiveUser, usagestatisticmonth.FieldNewUser, usagestatisticmonth.FieldConsumeCoin:
  64. values[i] = new(sql.NullInt64)
  65. case usagestatisticmonth.FieldBotID:
  66. values[i] = new(sql.NullString)
  67. case usagestatisticmonth.FieldCreatedAt, usagestatisticmonth.FieldUpdatedAt, usagestatisticmonth.FieldDeletedAt:
  68. values[i] = new(sql.NullTime)
  69. default:
  70. values[i] = new(sql.UnknownType)
  71. }
  72. }
  73. return values, nil
  74. }
  75. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  76. // to the UsageStatisticMonth fields.
  77. func (usm *UsageStatisticMonth) assignValues(columns []string, values []any) error {
  78. if m, n := len(values), len(columns); m < n {
  79. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  80. }
  81. for i := range columns {
  82. switch columns[i] {
  83. case usagestatisticmonth.FieldID:
  84. value, ok := values[i].(*sql.NullInt64)
  85. if !ok {
  86. return fmt.Errorf("unexpected type %T for field id", value)
  87. }
  88. usm.ID = uint64(value.Int64)
  89. case usagestatisticmonth.FieldCreatedAt:
  90. if value, ok := values[i].(*sql.NullTime); !ok {
  91. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  92. } else if value.Valid {
  93. usm.CreatedAt = value.Time
  94. }
  95. case usagestatisticmonth.FieldUpdatedAt:
  96. if value, ok := values[i].(*sql.NullTime); !ok {
  97. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  98. } else if value.Valid {
  99. usm.UpdatedAt = value.Time
  100. }
  101. case usagestatisticmonth.FieldStatus:
  102. if value, ok := values[i].(*sql.NullInt64); !ok {
  103. return fmt.Errorf("unexpected type %T for field status", values[i])
  104. } else if value.Valid {
  105. usm.Status = uint8(value.Int64)
  106. }
  107. case usagestatisticmonth.FieldDeletedAt:
  108. if value, ok := values[i].(*sql.NullTime); !ok {
  109. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  110. } else if value.Valid {
  111. usm.DeletedAt = value.Time
  112. }
  113. case usagestatisticmonth.FieldAddtime:
  114. if value, ok := values[i].(*sql.NullInt64); !ok {
  115. return fmt.Errorf("unexpected type %T for field addtime", values[i])
  116. } else if value.Valid {
  117. usm.Addtime = uint64(value.Int64)
  118. }
  119. case usagestatisticmonth.FieldType:
  120. if value, ok := values[i].(*sql.NullInt64); !ok {
  121. return fmt.Errorf("unexpected type %T for field type", values[i])
  122. } else if value.Valid {
  123. usm.Type = int(value.Int64)
  124. }
  125. case usagestatisticmonth.FieldBotID:
  126. if value, ok := values[i].(*sql.NullString); !ok {
  127. return fmt.Errorf("unexpected type %T for field bot_id", values[i])
  128. } else if value.Valid {
  129. usm.BotID = value.String
  130. }
  131. case usagestatisticmonth.FieldOrganizationID:
  132. if value, ok := values[i].(*sql.NullInt64); !ok {
  133. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  134. } else if value.Valid {
  135. usm.OrganizationID = uint64(value.Int64)
  136. }
  137. case usagestatisticmonth.FieldAiResponse:
  138. if value, ok := values[i].(*sql.NullInt64); !ok {
  139. return fmt.Errorf("unexpected type %T for field ai_response", values[i])
  140. } else if value.Valid {
  141. usm.AiResponse = uint64(value.Int64)
  142. }
  143. case usagestatisticmonth.FieldSopRun:
  144. if value, ok := values[i].(*sql.NullInt64); !ok {
  145. return fmt.Errorf("unexpected type %T for field sop_run", values[i])
  146. } else if value.Valid {
  147. usm.SopRun = uint64(value.Int64)
  148. }
  149. case usagestatisticmonth.FieldTotalFriend:
  150. if value, ok := values[i].(*sql.NullInt64); !ok {
  151. return fmt.Errorf("unexpected type %T for field total_friend", values[i])
  152. } else if value.Valid {
  153. usm.TotalFriend = uint64(value.Int64)
  154. }
  155. case usagestatisticmonth.FieldTotalGroup:
  156. if value, ok := values[i].(*sql.NullInt64); !ok {
  157. return fmt.Errorf("unexpected type %T for field total_group", values[i])
  158. } else if value.Valid {
  159. usm.TotalGroup = uint64(value.Int64)
  160. }
  161. case usagestatisticmonth.FieldAccountBalance:
  162. if value, ok := values[i].(*sql.NullInt64); !ok {
  163. return fmt.Errorf("unexpected type %T for field account_balance", values[i])
  164. } else if value.Valid {
  165. usm.AccountBalance = uint64(value.Int64)
  166. }
  167. case usagestatisticmonth.FieldConsumeToken:
  168. if value, ok := values[i].(*sql.NullInt64); !ok {
  169. return fmt.Errorf("unexpected type %T for field consume_token", values[i])
  170. } else if value.Valid {
  171. usm.ConsumeToken = uint64(value.Int64)
  172. }
  173. case usagestatisticmonth.FieldActiveUser:
  174. if value, ok := values[i].(*sql.NullInt64); !ok {
  175. return fmt.Errorf("unexpected type %T for field active_user", values[i])
  176. } else if value.Valid {
  177. usm.ActiveUser = uint64(value.Int64)
  178. }
  179. case usagestatisticmonth.FieldNewUser:
  180. if value, ok := values[i].(*sql.NullInt64); !ok {
  181. return fmt.Errorf("unexpected type %T for field new_user", values[i])
  182. } else if value.Valid {
  183. usm.NewUser = value.Int64
  184. }
  185. case usagestatisticmonth.FieldLabelDist:
  186. if value, ok := values[i].(*[]byte); !ok {
  187. return fmt.Errorf("unexpected type %T for field label_dist", values[i])
  188. } else if value != nil && len(*value) > 0 {
  189. if err := json.Unmarshal(*value, &usm.LabelDist); err != nil {
  190. return fmt.Errorf("unmarshal field label_dist: %w", err)
  191. }
  192. }
  193. case usagestatisticmonth.FieldConsumeCoin:
  194. if value, ok := values[i].(*sql.NullInt64); !ok {
  195. return fmt.Errorf("unexpected type %T for field consume_coin", values[i])
  196. } else if value.Valid {
  197. usm.ConsumeCoin = uint64(value.Int64)
  198. }
  199. default:
  200. usm.selectValues.Set(columns[i], values[i])
  201. }
  202. }
  203. return nil
  204. }
  205. // Value returns the ent.Value that was dynamically selected and assigned to the UsageStatisticMonth.
  206. // This includes values selected through modifiers, order, etc.
  207. func (usm *UsageStatisticMonth) Value(name string) (ent.Value, error) {
  208. return usm.selectValues.Get(name)
  209. }
  210. // Update returns a builder for updating this UsageStatisticMonth.
  211. // Note that you need to call UsageStatisticMonth.Unwrap() before calling this method if this UsageStatisticMonth
  212. // was returned from a transaction, and the transaction was committed or rolled back.
  213. func (usm *UsageStatisticMonth) Update() *UsageStatisticMonthUpdateOne {
  214. return NewUsageStatisticMonthClient(usm.config).UpdateOne(usm)
  215. }
  216. // Unwrap unwraps the UsageStatisticMonth entity that was returned from a transaction after it was closed,
  217. // so that all future queries will be executed through the driver which created the transaction.
  218. func (usm *UsageStatisticMonth) Unwrap() *UsageStatisticMonth {
  219. _tx, ok := usm.config.driver.(*txDriver)
  220. if !ok {
  221. panic("ent: UsageStatisticMonth is not a transactional entity")
  222. }
  223. usm.config.driver = _tx.drv
  224. return usm
  225. }
  226. // String implements the fmt.Stringer.
  227. func (usm *UsageStatisticMonth) String() string {
  228. var builder strings.Builder
  229. builder.WriteString("UsageStatisticMonth(")
  230. builder.WriteString(fmt.Sprintf("id=%v, ", usm.ID))
  231. builder.WriteString("created_at=")
  232. builder.WriteString(usm.CreatedAt.Format(time.ANSIC))
  233. builder.WriteString(", ")
  234. builder.WriteString("updated_at=")
  235. builder.WriteString(usm.UpdatedAt.Format(time.ANSIC))
  236. builder.WriteString(", ")
  237. builder.WriteString("status=")
  238. builder.WriteString(fmt.Sprintf("%v", usm.Status))
  239. builder.WriteString(", ")
  240. builder.WriteString("deleted_at=")
  241. builder.WriteString(usm.DeletedAt.Format(time.ANSIC))
  242. builder.WriteString(", ")
  243. builder.WriteString("addtime=")
  244. builder.WriteString(fmt.Sprintf("%v", usm.Addtime))
  245. builder.WriteString(", ")
  246. builder.WriteString("type=")
  247. builder.WriteString(fmt.Sprintf("%v", usm.Type))
  248. builder.WriteString(", ")
  249. builder.WriteString("bot_id=")
  250. builder.WriteString(usm.BotID)
  251. builder.WriteString(", ")
  252. builder.WriteString("organization_id=")
  253. builder.WriteString(fmt.Sprintf("%v", usm.OrganizationID))
  254. builder.WriteString(", ")
  255. builder.WriteString("ai_response=")
  256. builder.WriteString(fmt.Sprintf("%v", usm.AiResponse))
  257. builder.WriteString(", ")
  258. builder.WriteString("sop_run=")
  259. builder.WriteString(fmt.Sprintf("%v", usm.SopRun))
  260. builder.WriteString(", ")
  261. builder.WriteString("total_friend=")
  262. builder.WriteString(fmt.Sprintf("%v", usm.TotalFriend))
  263. builder.WriteString(", ")
  264. builder.WriteString("total_group=")
  265. builder.WriteString(fmt.Sprintf("%v", usm.TotalGroup))
  266. builder.WriteString(", ")
  267. builder.WriteString("account_balance=")
  268. builder.WriteString(fmt.Sprintf("%v", usm.AccountBalance))
  269. builder.WriteString(", ")
  270. builder.WriteString("consume_token=")
  271. builder.WriteString(fmt.Sprintf("%v", usm.ConsumeToken))
  272. builder.WriteString(", ")
  273. builder.WriteString("active_user=")
  274. builder.WriteString(fmt.Sprintf("%v", usm.ActiveUser))
  275. builder.WriteString(", ")
  276. builder.WriteString("new_user=")
  277. builder.WriteString(fmt.Sprintf("%v", usm.NewUser))
  278. builder.WriteString(", ")
  279. builder.WriteString("label_dist=")
  280. builder.WriteString(fmt.Sprintf("%v", usm.LabelDist))
  281. builder.WriteString(", ")
  282. builder.WriteString("consume_coin=")
  283. builder.WriteString(fmt.Sprintf("%v", usm.ConsumeCoin))
  284. builder.WriteByte(')')
  285. return builder.String()
  286. }
  287. // UsageStatisticMonths is a parsable slice of UsageStatisticMonth.
  288. type UsageStatisticMonths []*UsageStatisticMonth