usagestatisticday_update.go 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "errors"
  6. "fmt"
  7. "time"
  8. "wechat-api/ent/predicate"
  9. "wechat-api/ent/usagestatisticday"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // UsageStatisticDayUpdate is the builder for updating UsageStatisticDay entities.
  15. type UsageStatisticDayUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *UsageStatisticDayMutation
  19. }
  20. // Where appends a list predicates to the UsageStatisticDayUpdate builder.
  21. func (usdu *UsageStatisticDayUpdate) Where(ps ...predicate.UsageStatisticDay) *UsageStatisticDayUpdate {
  22. usdu.mutation.Where(ps...)
  23. return usdu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (usdu *UsageStatisticDayUpdate) SetUpdatedAt(t time.Time) *UsageStatisticDayUpdate {
  27. usdu.mutation.SetUpdatedAt(t)
  28. return usdu
  29. }
  30. // SetStatus sets the "status" field.
  31. func (usdu *UsageStatisticDayUpdate) SetStatus(u uint8) *UsageStatisticDayUpdate {
  32. usdu.mutation.ResetStatus()
  33. usdu.mutation.SetStatus(u)
  34. return usdu
  35. }
  36. // SetNillableStatus sets the "status" field if the given value is not nil.
  37. func (usdu *UsageStatisticDayUpdate) SetNillableStatus(u *uint8) *UsageStatisticDayUpdate {
  38. if u != nil {
  39. usdu.SetStatus(*u)
  40. }
  41. return usdu
  42. }
  43. // AddStatus adds u to the "status" field.
  44. func (usdu *UsageStatisticDayUpdate) AddStatus(u int8) *UsageStatisticDayUpdate {
  45. usdu.mutation.AddStatus(u)
  46. return usdu
  47. }
  48. // ClearStatus clears the value of the "status" field.
  49. func (usdu *UsageStatisticDayUpdate) ClearStatus() *UsageStatisticDayUpdate {
  50. usdu.mutation.ClearStatus()
  51. return usdu
  52. }
  53. // SetDeletedAt sets the "deleted_at" field.
  54. func (usdu *UsageStatisticDayUpdate) SetDeletedAt(t time.Time) *UsageStatisticDayUpdate {
  55. usdu.mutation.SetDeletedAt(t)
  56. return usdu
  57. }
  58. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  59. func (usdu *UsageStatisticDayUpdate) SetNillableDeletedAt(t *time.Time) *UsageStatisticDayUpdate {
  60. if t != nil {
  61. usdu.SetDeletedAt(*t)
  62. }
  63. return usdu
  64. }
  65. // ClearDeletedAt clears the value of the "deleted_at" field.
  66. func (usdu *UsageStatisticDayUpdate) ClearDeletedAt() *UsageStatisticDayUpdate {
  67. usdu.mutation.ClearDeletedAt()
  68. return usdu
  69. }
  70. // SetAddtime sets the "addtime" field.
  71. func (usdu *UsageStatisticDayUpdate) SetAddtime(u uint64) *UsageStatisticDayUpdate {
  72. usdu.mutation.ResetAddtime()
  73. usdu.mutation.SetAddtime(u)
  74. return usdu
  75. }
  76. // SetNillableAddtime sets the "addtime" field if the given value is not nil.
  77. func (usdu *UsageStatisticDayUpdate) SetNillableAddtime(u *uint64) *UsageStatisticDayUpdate {
  78. if u != nil {
  79. usdu.SetAddtime(*u)
  80. }
  81. return usdu
  82. }
  83. // AddAddtime adds u to the "addtime" field.
  84. func (usdu *UsageStatisticDayUpdate) AddAddtime(u int64) *UsageStatisticDayUpdate {
  85. usdu.mutation.AddAddtime(u)
  86. return usdu
  87. }
  88. // SetType sets the "type" field.
  89. func (usdu *UsageStatisticDayUpdate) SetType(i int) *UsageStatisticDayUpdate {
  90. usdu.mutation.ResetType()
  91. usdu.mutation.SetType(i)
  92. return usdu
  93. }
  94. // SetNillableType sets the "type" field if the given value is not nil.
  95. func (usdu *UsageStatisticDayUpdate) SetNillableType(i *int) *UsageStatisticDayUpdate {
  96. if i != nil {
  97. usdu.SetType(*i)
  98. }
  99. return usdu
  100. }
  101. // AddType adds i to the "type" field.
  102. func (usdu *UsageStatisticDayUpdate) AddType(i int) *UsageStatisticDayUpdate {
  103. usdu.mutation.AddType(i)
  104. return usdu
  105. }
  106. // SetBotID sets the "bot_id" field.
  107. func (usdu *UsageStatisticDayUpdate) SetBotID(s string) *UsageStatisticDayUpdate {
  108. usdu.mutation.SetBotID(s)
  109. return usdu
  110. }
  111. // SetNillableBotID sets the "bot_id" field if the given value is not nil.
  112. func (usdu *UsageStatisticDayUpdate) SetNillableBotID(s *string) *UsageStatisticDayUpdate {
  113. if s != nil {
  114. usdu.SetBotID(*s)
  115. }
  116. return usdu
  117. }
  118. // SetOrganizationID sets the "organization_id" field.
  119. func (usdu *UsageStatisticDayUpdate) SetOrganizationID(u uint64) *UsageStatisticDayUpdate {
  120. usdu.mutation.ResetOrganizationID()
  121. usdu.mutation.SetOrganizationID(u)
  122. return usdu
  123. }
  124. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  125. func (usdu *UsageStatisticDayUpdate) SetNillableOrganizationID(u *uint64) *UsageStatisticDayUpdate {
  126. if u != nil {
  127. usdu.SetOrganizationID(*u)
  128. }
  129. return usdu
  130. }
  131. // AddOrganizationID adds u to the "organization_id" field.
  132. func (usdu *UsageStatisticDayUpdate) AddOrganizationID(u int64) *UsageStatisticDayUpdate {
  133. usdu.mutation.AddOrganizationID(u)
  134. return usdu
  135. }
  136. // ClearOrganizationID clears the value of the "organization_id" field.
  137. func (usdu *UsageStatisticDayUpdate) ClearOrganizationID() *UsageStatisticDayUpdate {
  138. usdu.mutation.ClearOrganizationID()
  139. return usdu
  140. }
  141. // SetAiResponse sets the "ai_response" field.
  142. func (usdu *UsageStatisticDayUpdate) SetAiResponse(u uint64) *UsageStatisticDayUpdate {
  143. usdu.mutation.ResetAiResponse()
  144. usdu.mutation.SetAiResponse(u)
  145. return usdu
  146. }
  147. // SetNillableAiResponse sets the "ai_response" field if the given value is not nil.
  148. func (usdu *UsageStatisticDayUpdate) SetNillableAiResponse(u *uint64) *UsageStatisticDayUpdate {
  149. if u != nil {
  150. usdu.SetAiResponse(*u)
  151. }
  152. return usdu
  153. }
  154. // AddAiResponse adds u to the "ai_response" field.
  155. func (usdu *UsageStatisticDayUpdate) AddAiResponse(u int64) *UsageStatisticDayUpdate {
  156. usdu.mutation.AddAiResponse(u)
  157. return usdu
  158. }
  159. // SetSopRun sets the "sop_run" field.
  160. func (usdu *UsageStatisticDayUpdate) SetSopRun(u uint64) *UsageStatisticDayUpdate {
  161. usdu.mutation.ResetSopRun()
  162. usdu.mutation.SetSopRun(u)
  163. return usdu
  164. }
  165. // SetNillableSopRun sets the "sop_run" field if the given value is not nil.
  166. func (usdu *UsageStatisticDayUpdate) SetNillableSopRun(u *uint64) *UsageStatisticDayUpdate {
  167. if u != nil {
  168. usdu.SetSopRun(*u)
  169. }
  170. return usdu
  171. }
  172. // AddSopRun adds u to the "sop_run" field.
  173. func (usdu *UsageStatisticDayUpdate) AddSopRun(u int64) *UsageStatisticDayUpdate {
  174. usdu.mutation.AddSopRun(u)
  175. return usdu
  176. }
  177. // SetTotalFriend sets the "total_friend" field.
  178. func (usdu *UsageStatisticDayUpdate) SetTotalFriend(u uint64) *UsageStatisticDayUpdate {
  179. usdu.mutation.ResetTotalFriend()
  180. usdu.mutation.SetTotalFriend(u)
  181. return usdu
  182. }
  183. // SetNillableTotalFriend sets the "total_friend" field if the given value is not nil.
  184. func (usdu *UsageStatisticDayUpdate) SetNillableTotalFriend(u *uint64) *UsageStatisticDayUpdate {
  185. if u != nil {
  186. usdu.SetTotalFriend(*u)
  187. }
  188. return usdu
  189. }
  190. // AddTotalFriend adds u to the "total_friend" field.
  191. func (usdu *UsageStatisticDayUpdate) AddTotalFriend(u int64) *UsageStatisticDayUpdate {
  192. usdu.mutation.AddTotalFriend(u)
  193. return usdu
  194. }
  195. // SetTotalGroup sets the "total_group" field.
  196. func (usdu *UsageStatisticDayUpdate) SetTotalGroup(u uint64) *UsageStatisticDayUpdate {
  197. usdu.mutation.ResetTotalGroup()
  198. usdu.mutation.SetTotalGroup(u)
  199. return usdu
  200. }
  201. // SetNillableTotalGroup sets the "total_group" field if the given value is not nil.
  202. func (usdu *UsageStatisticDayUpdate) SetNillableTotalGroup(u *uint64) *UsageStatisticDayUpdate {
  203. if u != nil {
  204. usdu.SetTotalGroup(*u)
  205. }
  206. return usdu
  207. }
  208. // AddTotalGroup adds u to the "total_group" field.
  209. func (usdu *UsageStatisticDayUpdate) AddTotalGroup(u int64) *UsageStatisticDayUpdate {
  210. usdu.mutation.AddTotalGroup(u)
  211. return usdu
  212. }
  213. // SetAccountBalance sets the "account_balance" field.
  214. func (usdu *UsageStatisticDayUpdate) SetAccountBalance(u uint64) *UsageStatisticDayUpdate {
  215. usdu.mutation.ResetAccountBalance()
  216. usdu.mutation.SetAccountBalance(u)
  217. return usdu
  218. }
  219. // SetNillableAccountBalance sets the "account_balance" field if the given value is not nil.
  220. func (usdu *UsageStatisticDayUpdate) SetNillableAccountBalance(u *uint64) *UsageStatisticDayUpdate {
  221. if u != nil {
  222. usdu.SetAccountBalance(*u)
  223. }
  224. return usdu
  225. }
  226. // AddAccountBalance adds u to the "account_balance" field.
  227. func (usdu *UsageStatisticDayUpdate) AddAccountBalance(u int64) *UsageStatisticDayUpdate {
  228. usdu.mutation.AddAccountBalance(u)
  229. return usdu
  230. }
  231. // SetConsumeToken sets the "consume_token" field.
  232. func (usdu *UsageStatisticDayUpdate) SetConsumeToken(u uint64) *UsageStatisticDayUpdate {
  233. usdu.mutation.ResetConsumeToken()
  234. usdu.mutation.SetConsumeToken(u)
  235. return usdu
  236. }
  237. // SetNillableConsumeToken sets the "consume_token" field if the given value is not nil.
  238. func (usdu *UsageStatisticDayUpdate) SetNillableConsumeToken(u *uint64) *UsageStatisticDayUpdate {
  239. if u != nil {
  240. usdu.SetConsumeToken(*u)
  241. }
  242. return usdu
  243. }
  244. // AddConsumeToken adds u to the "consume_token" field.
  245. func (usdu *UsageStatisticDayUpdate) AddConsumeToken(u int64) *UsageStatisticDayUpdate {
  246. usdu.mutation.AddConsumeToken(u)
  247. return usdu
  248. }
  249. // SetActiveUser sets the "active_user" field.
  250. func (usdu *UsageStatisticDayUpdate) SetActiveUser(u uint64) *UsageStatisticDayUpdate {
  251. usdu.mutation.ResetActiveUser()
  252. usdu.mutation.SetActiveUser(u)
  253. return usdu
  254. }
  255. // SetNillableActiveUser sets the "active_user" field if the given value is not nil.
  256. func (usdu *UsageStatisticDayUpdate) SetNillableActiveUser(u *uint64) *UsageStatisticDayUpdate {
  257. if u != nil {
  258. usdu.SetActiveUser(*u)
  259. }
  260. return usdu
  261. }
  262. // AddActiveUser adds u to the "active_user" field.
  263. func (usdu *UsageStatisticDayUpdate) AddActiveUser(u int64) *UsageStatisticDayUpdate {
  264. usdu.mutation.AddActiveUser(u)
  265. return usdu
  266. }
  267. // SetNewUser sets the "new_user" field.
  268. func (usdu *UsageStatisticDayUpdate) SetNewUser(i int64) *UsageStatisticDayUpdate {
  269. usdu.mutation.ResetNewUser()
  270. usdu.mutation.SetNewUser(i)
  271. return usdu
  272. }
  273. // SetNillableNewUser sets the "new_user" field if the given value is not nil.
  274. func (usdu *UsageStatisticDayUpdate) SetNillableNewUser(i *int64) *UsageStatisticDayUpdate {
  275. if i != nil {
  276. usdu.SetNewUser(*i)
  277. }
  278. return usdu
  279. }
  280. // AddNewUser adds i to the "new_user" field.
  281. func (usdu *UsageStatisticDayUpdate) AddNewUser(i int64) *UsageStatisticDayUpdate {
  282. usdu.mutation.AddNewUser(i)
  283. return usdu
  284. }
  285. // Mutation returns the UsageStatisticDayMutation object of the builder.
  286. func (usdu *UsageStatisticDayUpdate) Mutation() *UsageStatisticDayMutation {
  287. return usdu.mutation
  288. }
  289. // Save executes the query and returns the number of nodes affected by the update operation.
  290. func (usdu *UsageStatisticDayUpdate) Save(ctx context.Context) (int, error) {
  291. if err := usdu.defaults(); err != nil {
  292. return 0, err
  293. }
  294. return withHooks(ctx, usdu.sqlSave, usdu.mutation, usdu.hooks)
  295. }
  296. // SaveX is like Save, but panics if an error occurs.
  297. func (usdu *UsageStatisticDayUpdate) SaveX(ctx context.Context) int {
  298. affected, err := usdu.Save(ctx)
  299. if err != nil {
  300. panic(err)
  301. }
  302. return affected
  303. }
  304. // Exec executes the query.
  305. func (usdu *UsageStatisticDayUpdate) Exec(ctx context.Context) error {
  306. _, err := usdu.Save(ctx)
  307. return err
  308. }
  309. // ExecX is like Exec, but panics if an error occurs.
  310. func (usdu *UsageStatisticDayUpdate) ExecX(ctx context.Context) {
  311. if err := usdu.Exec(ctx); err != nil {
  312. panic(err)
  313. }
  314. }
  315. // defaults sets the default values of the builder before save.
  316. func (usdu *UsageStatisticDayUpdate) defaults() error {
  317. if _, ok := usdu.mutation.UpdatedAt(); !ok {
  318. if usagestatisticday.UpdateDefaultUpdatedAt == nil {
  319. return fmt.Errorf("ent: uninitialized usagestatisticday.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  320. }
  321. v := usagestatisticday.UpdateDefaultUpdatedAt()
  322. usdu.mutation.SetUpdatedAt(v)
  323. }
  324. return nil
  325. }
  326. func (usdu *UsageStatisticDayUpdate) sqlSave(ctx context.Context) (n int, err error) {
  327. _spec := sqlgraph.NewUpdateSpec(usagestatisticday.Table, usagestatisticday.Columns, sqlgraph.NewFieldSpec(usagestatisticday.FieldID, field.TypeUint64))
  328. if ps := usdu.mutation.predicates; len(ps) > 0 {
  329. _spec.Predicate = func(selector *sql.Selector) {
  330. for i := range ps {
  331. ps[i](selector)
  332. }
  333. }
  334. }
  335. if value, ok := usdu.mutation.UpdatedAt(); ok {
  336. _spec.SetField(usagestatisticday.FieldUpdatedAt, field.TypeTime, value)
  337. }
  338. if value, ok := usdu.mutation.Status(); ok {
  339. _spec.SetField(usagestatisticday.FieldStatus, field.TypeUint8, value)
  340. }
  341. if value, ok := usdu.mutation.AddedStatus(); ok {
  342. _spec.AddField(usagestatisticday.FieldStatus, field.TypeUint8, value)
  343. }
  344. if usdu.mutation.StatusCleared() {
  345. _spec.ClearField(usagestatisticday.FieldStatus, field.TypeUint8)
  346. }
  347. if value, ok := usdu.mutation.DeletedAt(); ok {
  348. _spec.SetField(usagestatisticday.FieldDeletedAt, field.TypeTime, value)
  349. }
  350. if usdu.mutation.DeletedAtCleared() {
  351. _spec.ClearField(usagestatisticday.FieldDeletedAt, field.TypeTime)
  352. }
  353. if value, ok := usdu.mutation.Addtime(); ok {
  354. _spec.SetField(usagestatisticday.FieldAddtime, field.TypeUint64, value)
  355. }
  356. if value, ok := usdu.mutation.AddedAddtime(); ok {
  357. _spec.AddField(usagestatisticday.FieldAddtime, field.TypeUint64, value)
  358. }
  359. if value, ok := usdu.mutation.GetType(); ok {
  360. _spec.SetField(usagestatisticday.FieldType, field.TypeInt, value)
  361. }
  362. if value, ok := usdu.mutation.AddedType(); ok {
  363. _spec.AddField(usagestatisticday.FieldType, field.TypeInt, value)
  364. }
  365. if value, ok := usdu.mutation.BotID(); ok {
  366. _spec.SetField(usagestatisticday.FieldBotID, field.TypeString, value)
  367. }
  368. if value, ok := usdu.mutation.OrganizationID(); ok {
  369. _spec.SetField(usagestatisticday.FieldOrganizationID, field.TypeUint64, value)
  370. }
  371. if value, ok := usdu.mutation.AddedOrganizationID(); ok {
  372. _spec.AddField(usagestatisticday.FieldOrganizationID, field.TypeUint64, value)
  373. }
  374. if usdu.mutation.OrganizationIDCleared() {
  375. _spec.ClearField(usagestatisticday.FieldOrganizationID, field.TypeUint64)
  376. }
  377. if value, ok := usdu.mutation.AiResponse(); ok {
  378. _spec.SetField(usagestatisticday.FieldAiResponse, field.TypeUint64, value)
  379. }
  380. if value, ok := usdu.mutation.AddedAiResponse(); ok {
  381. _spec.AddField(usagestatisticday.FieldAiResponse, field.TypeUint64, value)
  382. }
  383. if value, ok := usdu.mutation.SopRun(); ok {
  384. _spec.SetField(usagestatisticday.FieldSopRun, field.TypeUint64, value)
  385. }
  386. if value, ok := usdu.mutation.AddedSopRun(); ok {
  387. _spec.AddField(usagestatisticday.FieldSopRun, field.TypeUint64, value)
  388. }
  389. if value, ok := usdu.mutation.TotalFriend(); ok {
  390. _spec.SetField(usagestatisticday.FieldTotalFriend, field.TypeUint64, value)
  391. }
  392. if value, ok := usdu.mutation.AddedTotalFriend(); ok {
  393. _spec.AddField(usagestatisticday.FieldTotalFriend, field.TypeUint64, value)
  394. }
  395. if value, ok := usdu.mutation.TotalGroup(); ok {
  396. _spec.SetField(usagestatisticday.FieldTotalGroup, field.TypeUint64, value)
  397. }
  398. if value, ok := usdu.mutation.AddedTotalGroup(); ok {
  399. _spec.AddField(usagestatisticday.FieldTotalGroup, field.TypeUint64, value)
  400. }
  401. if value, ok := usdu.mutation.AccountBalance(); ok {
  402. _spec.SetField(usagestatisticday.FieldAccountBalance, field.TypeUint64, value)
  403. }
  404. if value, ok := usdu.mutation.AddedAccountBalance(); ok {
  405. _spec.AddField(usagestatisticday.FieldAccountBalance, field.TypeUint64, value)
  406. }
  407. if value, ok := usdu.mutation.ConsumeToken(); ok {
  408. _spec.SetField(usagestatisticday.FieldConsumeToken, field.TypeUint64, value)
  409. }
  410. if value, ok := usdu.mutation.AddedConsumeToken(); ok {
  411. _spec.AddField(usagestatisticday.FieldConsumeToken, field.TypeUint64, value)
  412. }
  413. if value, ok := usdu.mutation.ActiveUser(); ok {
  414. _spec.SetField(usagestatisticday.FieldActiveUser, field.TypeUint64, value)
  415. }
  416. if value, ok := usdu.mutation.AddedActiveUser(); ok {
  417. _spec.AddField(usagestatisticday.FieldActiveUser, field.TypeUint64, value)
  418. }
  419. if value, ok := usdu.mutation.NewUser(); ok {
  420. _spec.SetField(usagestatisticday.FieldNewUser, field.TypeInt64, value)
  421. }
  422. if value, ok := usdu.mutation.AddedNewUser(); ok {
  423. _spec.AddField(usagestatisticday.FieldNewUser, field.TypeInt64, value)
  424. }
  425. if n, err = sqlgraph.UpdateNodes(ctx, usdu.driver, _spec); err != nil {
  426. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  427. err = &NotFoundError{usagestatisticday.Label}
  428. } else if sqlgraph.IsConstraintError(err) {
  429. err = &ConstraintError{msg: err.Error(), wrap: err}
  430. }
  431. return 0, err
  432. }
  433. usdu.mutation.done = true
  434. return n, nil
  435. }
  436. // UsageStatisticDayUpdateOne is the builder for updating a single UsageStatisticDay entity.
  437. type UsageStatisticDayUpdateOne struct {
  438. config
  439. fields []string
  440. hooks []Hook
  441. mutation *UsageStatisticDayMutation
  442. }
  443. // SetUpdatedAt sets the "updated_at" field.
  444. func (usduo *UsageStatisticDayUpdateOne) SetUpdatedAt(t time.Time) *UsageStatisticDayUpdateOne {
  445. usduo.mutation.SetUpdatedAt(t)
  446. return usduo
  447. }
  448. // SetStatus sets the "status" field.
  449. func (usduo *UsageStatisticDayUpdateOne) SetStatus(u uint8) *UsageStatisticDayUpdateOne {
  450. usduo.mutation.ResetStatus()
  451. usduo.mutation.SetStatus(u)
  452. return usduo
  453. }
  454. // SetNillableStatus sets the "status" field if the given value is not nil.
  455. func (usduo *UsageStatisticDayUpdateOne) SetNillableStatus(u *uint8) *UsageStatisticDayUpdateOne {
  456. if u != nil {
  457. usduo.SetStatus(*u)
  458. }
  459. return usduo
  460. }
  461. // AddStatus adds u to the "status" field.
  462. func (usduo *UsageStatisticDayUpdateOne) AddStatus(u int8) *UsageStatisticDayUpdateOne {
  463. usduo.mutation.AddStatus(u)
  464. return usduo
  465. }
  466. // ClearStatus clears the value of the "status" field.
  467. func (usduo *UsageStatisticDayUpdateOne) ClearStatus() *UsageStatisticDayUpdateOne {
  468. usduo.mutation.ClearStatus()
  469. return usduo
  470. }
  471. // SetDeletedAt sets the "deleted_at" field.
  472. func (usduo *UsageStatisticDayUpdateOne) SetDeletedAt(t time.Time) *UsageStatisticDayUpdateOne {
  473. usduo.mutation.SetDeletedAt(t)
  474. return usduo
  475. }
  476. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  477. func (usduo *UsageStatisticDayUpdateOne) SetNillableDeletedAt(t *time.Time) *UsageStatisticDayUpdateOne {
  478. if t != nil {
  479. usduo.SetDeletedAt(*t)
  480. }
  481. return usduo
  482. }
  483. // ClearDeletedAt clears the value of the "deleted_at" field.
  484. func (usduo *UsageStatisticDayUpdateOne) ClearDeletedAt() *UsageStatisticDayUpdateOne {
  485. usduo.mutation.ClearDeletedAt()
  486. return usduo
  487. }
  488. // SetAddtime sets the "addtime" field.
  489. func (usduo *UsageStatisticDayUpdateOne) SetAddtime(u uint64) *UsageStatisticDayUpdateOne {
  490. usduo.mutation.ResetAddtime()
  491. usduo.mutation.SetAddtime(u)
  492. return usduo
  493. }
  494. // SetNillableAddtime sets the "addtime" field if the given value is not nil.
  495. func (usduo *UsageStatisticDayUpdateOne) SetNillableAddtime(u *uint64) *UsageStatisticDayUpdateOne {
  496. if u != nil {
  497. usduo.SetAddtime(*u)
  498. }
  499. return usduo
  500. }
  501. // AddAddtime adds u to the "addtime" field.
  502. func (usduo *UsageStatisticDayUpdateOne) AddAddtime(u int64) *UsageStatisticDayUpdateOne {
  503. usduo.mutation.AddAddtime(u)
  504. return usduo
  505. }
  506. // SetType sets the "type" field.
  507. func (usduo *UsageStatisticDayUpdateOne) SetType(i int) *UsageStatisticDayUpdateOne {
  508. usduo.mutation.ResetType()
  509. usduo.mutation.SetType(i)
  510. return usduo
  511. }
  512. // SetNillableType sets the "type" field if the given value is not nil.
  513. func (usduo *UsageStatisticDayUpdateOne) SetNillableType(i *int) *UsageStatisticDayUpdateOne {
  514. if i != nil {
  515. usduo.SetType(*i)
  516. }
  517. return usduo
  518. }
  519. // AddType adds i to the "type" field.
  520. func (usduo *UsageStatisticDayUpdateOne) AddType(i int) *UsageStatisticDayUpdateOne {
  521. usduo.mutation.AddType(i)
  522. return usduo
  523. }
  524. // SetBotID sets the "bot_id" field.
  525. func (usduo *UsageStatisticDayUpdateOne) SetBotID(s string) *UsageStatisticDayUpdateOne {
  526. usduo.mutation.SetBotID(s)
  527. return usduo
  528. }
  529. // SetNillableBotID sets the "bot_id" field if the given value is not nil.
  530. func (usduo *UsageStatisticDayUpdateOne) SetNillableBotID(s *string) *UsageStatisticDayUpdateOne {
  531. if s != nil {
  532. usduo.SetBotID(*s)
  533. }
  534. return usduo
  535. }
  536. // SetOrganizationID sets the "organization_id" field.
  537. func (usduo *UsageStatisticDayUpdateOne) SetOrganizationID(u uint64) *UsageStatisticDayUpdateOne {
  538. usduo.mutation.ResetOrganizationID()
  539. usduo.mutation.SetOrganizationID(u)
  540. return usduo
  541. }
  542. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  543. func (usduo *UsageStatisticDayUpdateOne) SetNillableOrganizationID(u *uint64) *UsageStatisticDayUpdateOne {
  544. if u != nil {
  545. usduo.SetOrganizationID(*u)
  546. }
  547. return usduo
  548. }
  549. // AddOrganizationID adds u to the "organization_id" field.
  550. func (usduo *UsageStatisticDayUpdateOne) AddOrganizationID(u int64) *UsageStatisticDayUpdateOne {
  551. usduo.mutation.AddOrganizationID(u)
  552. return usduo
  553. }
  554. // ClearOrganizationID clears the value of the "organization_id" field.
  555. func (usduo *UsageStatisticDayUpdateOne) ClearOrganizationID() *UsageStatisticDayUpdateOne {
  556. usduo.mutation.ClearOrganizationID()
  557. return usduo
  558. }
  559. // SetAiResponse sets the "ai_response" field.
  560. func (usduo *UsageStatisticDayUpdateOne) SetAiResponse(u uint64) *UsageStatisticDayUpdateOne {
  561. usduo.mutation.ResetAiResponse()
  562. usduo.mutation.SetAiResponse(u)
  563. return usduo
  564. }
  565. // SetNillableAiResponse sets the "ai_response" field if the given value is not nil.
  566. func (usduo *UsageStatisticDayUpdateOne) SetNillableAiResponse(u *uint64) *UsageStatisticDayUpdateOne {
  567. if u != nil {
  568. usduo.SetAiResponse(*u)
  569. }
  570. return usduo
  571. }
  572. // AddAiResponse adds u to the "ai_response" field.
  573. func (usduo *UsageStatisticDayUpdateOne) AddAiResponse(u int64) *UsageStatisticDayUpdateOne {
  574. usduo.mutation.AddAiResponse(u)
  575. return usduo
  576. }
  577. // SetSopRun sets the "sop_run" field.
  578. func (usduo *UsageStatisticDayUpdateOne) SetSopRun(u uint64) *UsageStatisticDayUpdateOne {
  579. usduo.mutation.ResetSopRun()
  580. usduo.mutation.SetSopRun(u)
  581. return usduo
  582. }
  583. // SetNillableSopRun sets the "sop_run" field if the given value is not nil.
  584. func (usduo *UsageStatisticDayUpdateOne) SetNillableSopRun(u *uint64) *UsageStatisticDayUpdateOne {
  585. if u != nil {
  586. usduo.SetSopRun(*u)
  587. }
  588. return usduo
  589. }
  590. // AddSopRun adds u to the "sop_run" field.
  591. func (usduo *UsageStatisticDayUpdateOne) AddSopRun(u int64) *UsageStatisticDayUpdateOne {
  592. usduo.mutation.AddSopRun(u)
  593. return usduo
  594. }
  595. // SetTotalFriend sets the "total_friend" field.
  596. func (usduo *UsageStatisticDayUpdateOne) SetTotalFriend(u uint64) *UsageStatisticDayUpdateOne {
  597. usduo.mutation.ResetTotalFriend()
  598. usduo.mutation.SetTotalFriend(u)
  599. return usduo
  600. }
  601. // SetNillableTotalFriend sets the "total_friend" field if the given value is not nil.
  602. func (usduo *UsageStatisticDayUpdateOne) SetNillableTotalFriend(u *uint64) *UsageStatisticDayUpdateOne {
  603. if u != nil {
  604. usduo.SetTotalFriend(*u)
  605. }
  606. return usduo
  607. }
  608. // AddTotalFriend adds u to the "total_friend" field.
  609. func (usduo *UsageStatisticDayUpdateOne) AddTotalFriend(u int64) *UsageStatisticDayUpdateOne {
  610. usduo.mutation.AddTotalFriend(u)
  611. return usduo
  612. }
  613. // SetTotalGroup sets the "total_group" field.
  614. func (usduo *UsageStatisticDayUpdateOne) SetTotalGroup(u uint64) *UsageStatisticDayUpdateOne {
  615. usduo.mutation.ResetTotalGroup()
  616. usduo.mutation.SetTotalGroup(u)
  617. return usduo
  618. }
  619. // SetNillableTotalGroup sets the "total_group" field if the given value is not nil.
  620. func (usduo *UsageStatisticDayUpdateOne) SetNillableTotalGroup(u *uint64) *UsageStatisticDayUpdateOne {
  621. if u != nil {
  622. usduo.SetTotalGroup(*u)
  623. }
  624. return usduo
  625. }
  626. // AddTotalGroup adds u to the "total_group" field.
  627. func (usduo *UsageStatisticDayUpdateOne) AddTotalGroup(u int64) *UsageStatisticDayUpdateOne {
  628. usduo.mutation.AddTotalGroup(u)
  629. return usduo
  630. }
  631. // SetAccountBalance sets the "account_balance" field.
  632. func (usduo *UsageStatisticDayUpdateOne) SetAccountBalance(u uint64) *UsageStatisticDayUpdateOne {
  633. usduo.mutation.ResetAccountBalance()
  634. usduo.mutation.SetAccountBalance(u)
  635. return usduo
  636. }
  637. // SetNillableAccountBalance sets the "account_balance" field if the given value is not nil.
  638. func (usduo *UsageStatisticDayUpdateOne) SetNillableAccountBalance(u *uint64) *UsageStatisticDayUpdateOne {
  639. if u != nil {
  640. usduo.SetAccountBalance(*u)
  641. }
  642. return usduo
  643. }
  644. // AddAccountBalance adds u to the "account_balance" field.
  645. func (usduo *UsageStatisticDayUpdateOne) AddAccountBalance(u int64) *UsageStatisticDayUpdateOne {
  646. usduo.mutation.AddAccountBalance(u)
  647. return usduo
  648. }
  649. // SetConsumeToken sets the "consume_token" field.
  650. func (usduo *UsageStatisticDayUpdateOne) SetConsumeToken(u uint64) *UsageStatisticDayUpdateOne {
  651. usduo.mutation.ResetConsumeToken()
  652. usduo.mutation.SetConsumeToken(u)
  653. return usduo
  654. }
  655. // SetNillableConsumeToken sets the "consume_token" field if the given value is not nil.
  656. func (usduo *UsageStatisticDayUpdateOne) SetNillableConsumeToken(u *uint64) *UsageStatisticDayUpdateOne {
  657. if u != nil {
  658. usduo.SetConsumeToken(*u)
  659. }
  660. return usduo
  661. }
  662. // AddConsumeToken adds u to the "consume_token" field.
  663. func (usduo *UsageStatisticDayUpdateOne) AddConsumeToken(u int64) *UsageStatisticDayUpdateOne {
  664. usduo.mutation.AddConsumeToken(u)
  665. return usduo
  666. }
  667. // SetActiveUser sets the "active_user" field.
  668. func (usduo *UsageStatisticDayUpdateOne) SetActiveUser(u uint64) *UsageStatisticDayUpdateOne {
  669. usduo.mutation.ResetActiveUser()
  670. usduo.mutation.SetActiveUser(u)
  671. return usduo
  672. }
  673. // SetNillableActiveUser sets the "active_user" field if the given value is not nil.
  674. func (usduo *UsageStatisticDayUpdateOne) SetNillableActiveUser(u *uint64) *UsageStatisticDayUpdateOne {
  675. if u != nil {
  676. usduo.SetActiveUser(*u)
  677. }
  678. return usduo
  679. }
  680. // AddActiveUser adds u to the "active_user" field.
  681. func (usduo *UsageStatisticDayUpdateOne) AddActiveUser(u int64) *UsageStatisticDayUpdateOne {
  682. usduo.mutation.AddActiveUser(u)
  683. return usduo
  684. }
  685. // SetNewUser sets the "new_user" field.
  686. func (usduo *UsageStatisticDayUpdateOne) SetNewUser(i int64) *UsageStatisticDayUpdateOne {
  687. usduo.mutation.ResetNewUser()
  688. usduo.mutation.SetNewUser(i)
  689. return usduo
  690. }
  691. // SetNillableNewUser sets the "new_user" field if the given value is not nil.
  692. func (usduo *UsageStatisticDayUpdateOne) SetNillableNewUser(i *int64) *UsageStatisticDayUpdateOne {
  693. if i != nil {
  694. usduo.SetNewUser(*i)
  695. }
  696. return usduo
  697. }
  698. // AddNewUser adds i to the "new_user" field.
  699. func (usduo *UsageStatisticDayUpdateOne) AddNewUser(i int64) *UsageStatisticDayUpdateOne {
  700. usduo.mutation.AddNewUser(i)
  701. return usduo
  702. }
  703. // Mutation returns the UsageStatisticDayMutation object of the builder.
  704. func (usduo *UsageStatisticDayUpdateOne) Mutation() *UsageStatisticDayMutation {
  705. return usduo.mutation
  706. }
  707. // Where appends a list predicates to the UsageStatisticDayUpdate builder.
  708. func (usduo *UsageStatisticDayUpdateOne) Where(ps ...predicate.UsageStatisticDay) *UsageStatisticDayUpdateOne {
  709. usduo.mutation.Where(ps...)
  710. return usduo
  711. }
  712. // Select allows selecting one or more fields (columns) of the returned entity.
  713. // The default is selecting all fields defined in the entity schema.
  714. func (usduo *UsageStatisticDayUpdateOne) Select(field string, fields ...string) *UsageStatisticDayUpdateOne {
  715. usduo.fields = append([]string{field}, fields...)
  716. return usduo
  717. }
  718. // Save executes the query and returns the updated UsageStatisticDay entity.
  719. func (usduo *UsageStatisticDayUpdateOne) Save(ctx context.Context) (*UsageStatisticDay, error) {
  720. if err := usduo.defaults(); err != nil {
  721. return nil, err
  722. }
  723. return withHooks(ctx, usduo.sqlSave, usduo.mutation, usduo.hooks)
  724. }
  725. // SaveX is like Save, but panics if an error occurs.
  726. func (usduo *UsageStatisticDayUpdateOne) SaveX(ctx context.Context) *UsageStatisticDay {
  727. node, err := usduo.Save(ctx)
  728. if err != nil {
  729. panic(err)
  730. }
  731. return node
  732. }
  733. // Exec executes the query on the entity.
  734. func (usduo *UsageStatisticDayUpdateOne) Exec(ctx context.Context) error {
  735. _, err := usduo.Save(ctx)
  736. return err
  737. }
  738. // ExecX is like Exec, but panics if an error occurs.
  739. func (usduo *UsageStatisticDayUpdateOne) ExecX(ctx context.Context) {
  740. if err := usduo.Exec(ctx); err != nil {
  741. panic(err)
  742. }
  743. }
  744. // defaults sets the default values of the builder before save.
  745. func (usduo *UsageStatisticDayUpdateOne) defaults() error {
  746. if _, ok := usduo.mutation.UpdatedAt(); !ok {
  747. if usagestatisticday.UpdateDefaultUpdatedAt == nil {
  748. return fmt.Errorf("ent: uninitialized usagestatisticday.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  749. }
  750. v := usagestatisticday.UpdateDefaultUpdatedAt()
  751. usduo.mutation.SetUpdatedAt(v)
  752. }
  753. return nil
  754. }
  755. func (usduo *UsageStatisticDayUpdateOne) sqlSave(ctx context.Context) (_node *UsageStatisticDay, err error) {
  756. _spec := sqlgraph.NewUpdateSpec(usagestatisticday.Table, usagestatisticday.Columns, sqlgraph.NewFieldSpec(usagestatisticday.FieldID, field.TypeUint64))
  757. id, ok := usduo.mutation.ID()
  758. if !ok {
  759. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UsageStatisticDay.id" for update`)}
  760. }
  761. _spec.Node.ID.Value = id
  762. if fields := usduo.fields; len(fields) > 0 {
  763. _spec.Node.Columns = make([]string, 0, len(fields))
  764. _spec.Node.Columns = append(_spec.Node.Columns, usagestatisticday.FieldID)
  765. for _, f := range fields {
  766. if !usagestatisticday.ValidColumn(f) {
  767. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  768. }
  769. if f != usagestatisticday.FieldID {
  770. _spec.Node.Columns = append(_spec.Node.Columns, f)
  771. }
  772. }
  773. }
  774. if ps := usduo.mutation.predicates; len(ps) > 0 {
  775. _spec.Predicate = func(selector *sql.Selector) {
  776. for i := range ps {
  777. ps[i](selector)
  778. }
  779. }
  780. }
  781. if value, ok := usduo.mutation.UpdatedAt(); ok {
  782. _spec.SetField(usagestatisticday.FieldUpdatedAt, field.TypeTime, value)
  783. }
  784. if value, ok := usduo.mutation.Status(); ok {
  785. _spec.SetField(usagestatisticday.FieldStatus, field.TypeUint8, value)
  786. }
  787. if value, ok := usduo.mutation.AddedStatus(); ok {
  788. _spec.AddField(usagestatisticday.FieldStatus, field.TypeUint8, value)
  789. }
  790. if usduo.mutation.StatusCleared() {
  791. _spec.ClearField(usagestatisticday.FieldStatus, field.TypeUint8)
  792. }
  793. if value, ok := usduo.mutation.DeletedAt(); ok {
  794. _spec.SetField(usagestatisticday.FieldDeletedAt, field.TypeTime, value)
  795. }
  796. if usduo.mutation.DeletedAtCleared() {
  797. _spec.ClearField(usagestatisticday.FieldDeletedAt, field.TypeTime)
  798. }
  799. if value, ok := usduo.mutation.Addtime(); ok {
  800. _spec.SetField(usagestatisticday.FieldAddtime, field.TypeUint64, value)
  801. }
  802. if value, ok := usduo.mutation.AddedAddtime(); ok {
  803. _spec.AddField(usagestatisticday.FieldAddtime, field.TypeUint64, value)
  804. }
  805. if value, ok := usduo.mutation.GetType(); ok {
  806. _spec.SetField(usagestatisticday.FieldType, field.TypeInt, value)
  807. }
  808. if value, ok := usduo.mutation.AddedType(); ok {
  809. _spec.AddField(usagestatisticday.FieldType, field.TypeInt, value)
  810. }
  811. if value, ok := usduo.mutation.BotID(); ok {
  812. _spec.SetField(usagestatisticday.FieldBotID, field.TypeString, value)
  813. }
  814. if value, ok := usduo.mutation.OrganizationID(); ok {
  815. _spec.SetField(usagestatisticday.FieldOrganizationID, field.TypeUint64, value)
  816. }
  817. if value, ok := usduo.mutation.AddedOrganizationID(); ok {
  818. _spec.AddField(usagestatisticday.FieldOrganizationID, field.TypeUint64, value)
  819. }
  820. if usduo.mutation.OrganizationIDCleared() {
  821. _spec.ClearField(usagestatisticday.FieldOrganizationID, field.TypeUint64)
  822. }
  823. if value, ok := usduo.mutation.AiResponse(); ok {
  824. _spec.SetField(usagestatisticday.FieldAiResponse, field.TypeUint64, value)
  825. }
  826. if value, ok := usduo.mutation.AddedAiResponse(); ok {
  827. _spec.AddField(usagestatisticday.FieldAiResponse, field.TypeUint64, value)
  828. }
  829. if value, ok := usduo.mutation.SopRun(); ok {
  830. _spec.SetField(usagestatisticday.FieldSopRun, field.TypeUint64, value)
  831. }
  832. if value, ok := usduo.mutation.AddedSopRun(); ok {
  833. _spec.AddField(usagestatisticday.FieldSopRun, field.TypeUint64, value)
  834. }
  835. if value, ok := usduo.mutation.TotalFriend(); ok {
  836. _spec.SetField(usagestatisticday.FieldTotalFriend, field.TypeUint64, value)
  837. }
  838. if value, ok := usduo.mutation.AddedTotalFriend(); ok {
  839. _spec.AddField(usagestatisticday.FieldTotalFriend, field.TypeUint64, value)
  840. }
  841. if value, ok := usduo.mutation.TotalGroup(); ok {
  842. _spec.SetField(usagestatisticday.FieldTotalGroup, field.TypeUint64, value)
  843. }
  844. if value, ok := usduo.mutation.AddedTotalGroup(); ok {
  845. _spec.AddField(usagestatisticday.FieldTotalGroup, field.TypeUint64, value)
  846. }
  847. if value, ok := usduo.mutation.AccountBalance(); ok {
  848. _spec.SetField(usagestatisticday.FieldAccountBalance, field.TypeUint64, value)
  849. }
  850. if value, ok := usduo.mutation.AddedAccountBalance(); ok {
  851. _spec.AddField(usagestatisticday.FieldAccountBalance, field.TypeUint64, value)
  852. }
  853. if value, ok := usduo.mutation.ConsumeToken(); ok {
  854. _spec.SetField(usagestatisticday.FieldConsumeToken, field.TypeUint64, value)
  855. }
  856. if value, ok := usduo.mutation.AddedConsumeToken(); ok {
  857. _spec.AddField(usagestatisticday.FieldConsumeToken, field.TypeUint64, value)
  858. }
  859. if value, ok := usduo.mutation.ActiveUser(); ok {
  860. _spec.SetField(usagestatisticday.FieldActiveUser, field.TypeUint64, value)
  861. }
  862. if value, ok := usduo.mutation.AddedActiveUser(); ok {
  863. _spec.AddField(usagestatisticday.FieldActiveUser, field.TypeUint64, value)
  864. }
  865. if value, ok := usduo.mutation.NewUser(); ok {
  866. _spec.SetField(usagestatisticday.FieldNewUser, field.TypeInt64, value)
  867. }
  868. if value, ok := usduo.mutation.AddedNewUser(); ok {
  869. _spec.AddField(usagestatisticday.FieldNewUser, field.TypeInt64, value)
  870. }
  871. _node = &UsageStatisticDay{config: usduo.config}
  872. _spec.Assign = _node.assignValues
  873. _spec.ScanValues = _node.scanValues
  874. if err = sqlgraph.UpdateNode(ctx, usduo.driver, _spec); err != nil {
  875. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  876. err = &NotFoundError{usagestatisticday.Label}
  877. } else if sqlgraph.IsConstraintError(err) {
  878. err = &ConstraintError{msg: err.Error(), wrap: err}
  879. }
  880. return nil, err
  881. }
  882. usduo.mutation.done = true
  883. return _node, nil
  884. }