usagestatisticmonth.go 11 KB

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