batchmsg_update.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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/batchmsg"
  9. "wechat-api/ent/predicate"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/schema/field"
  13. )
  14. // BatchMsgUpdate is the builder for updating BatchMsg entities.
  15. type BatchMsgUpdate struct {
  16. config
  17. hooks []Hook
  18. mutation *BatchMsgMutation
  19. }
  20. // Where appends a list predicates to the BatchMsgUpdate builder.
  21. func (bmu *BatchMsgUpdate) Where(ps ...predicate.BatchMsg) *BatchMsgUpdate {
  22. bmu.mutation.Where(ps...)
  23. return bmu
  24. }
  25. // SetUpdatedAt sets the "updated_at" field.
  26. func (bmu *BatchMsgUpdate) SetUpdatedAt(t time.Time) *BatchMsgUpdate {
  27. bmu.mutation.SetUpdatedAt(t)
  28. return bmu
  29. }
  30. // SetDeletedAt sets the "deleted_at" field.
  31. func (bmu *BatchMsgUpdate) SetDeletedAt(t time.Time) *BatchMsgUpdate {
  32. bmu.mutation.SetDeletedAt(t)
  33. return bmu
  34. }
  35. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  36. func (bmu *BatchMsgUpdate) SetNillableDeletedAt(t *time.Time) *BatchMsgUpdate {
  37. if t != nil {
  38. bmu.SetDeletedAt(*t)
  39. }
  40. return bmu
  41. }
  42. // ClearDeletedAt clears the value of the "deleted_at" field.
  43. func (bmu *BatchMsgUpdate) ClearDeletedAt() *BatchMsgUpdate {
  44. bmu.mutation.ClearDeletedAt()
  45. return bmu
  46. }
  47. // SetStatus sets the "status" field.
  48. func (bmu *BatchMsgUpdate) SetStatus(u uint8) *BatchMsgUpdate {
  49. bmu.mutation.ResetStatus()
  50. bmu.mutation.SetStatus(u)
  51. return bmu
  52. }
  53. // SetNillableStatus sets the "status" field if the given value is not nil.
  54. func (bmu *BatchMsgUpdate) SetNillableStatus(u *uint8) *BatchMsgUpdate {
  55. if u != nil {
  56. bmu.SetStatus(*u)
  57. }
  58. return bmu
  59. }
  60. // AddStatus adds u to the "status" field.
  61. func (bmu *BatchMsgUpdate) AddStatus(u int8) *BatchMsgUpdate {
  62. bmu.mutation.AddStatus(u)
  63. return bmu
  64. }
  65. // ClearStatus clears the value of the "status" field.
  66. func (bmu *BatchMsgUpdate) ClearStatus() *BatchMsgUpdate {
  67. bmu.mutation.ClearStatus()
  68. return bmu
  69. }
  70. // SetBatchNo sets the "batch_no" field.
  71. func (bmu *BatchMsgUpdate) SetBatchNo(s string) *BatchMsgUpdate {
  72. bmu.mutation.SetBatchNo(s)
  73. return bmu
  74. }
  75. // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
  76. func (bmu *BatchMsgUpdate) SetNillableBatchNo(s *string) *BatchMsgUpdate {
  77. if s != nil {
  78. bmu.SetBatchNo(*s)
  79. }
  80. return bmu
  81. }
  82. // ClearBatchNo clears the value of the "batch_no" field.
  83. func (bmu *BatchMsgUpdate) ClearBatchNo() *BatchMsgUpdate {
  84. bmu.mutation.ClearBatchNo()
  85. return bmu
  86. }
  87. // SetTaskName sets the "task_name" field.
  88. func (bmu *BatchMsgUpdate) SetTaskName(s string) *BatchMsgUpdate {
  89. bmu.mutation.SetTaskName(s)
  90. return bmu
  91. }
  92. // SetNillableTaskName sets the "task_name" field if the given value is not nil.
  93. func (bmu *BatchMsgUpdate) SetNillableTaskName(s *string) *BatchMsgUpdate {
  94. if s != nil {
  95. bmu.SetTaskName(*s)
  96. }
  97. return bmu
  98. }
  99. // ClearTaskName clears the value of the "task_name" field.
  100. func (bmu *BatchMsgUpdate) ClearTaskName() *BatchMsgUpdate {
  101. bmu.mutation.ClearTaskName()
  102. return bmu
  103. }
  104. // SetFromwxid sets the "fromwxid" field.
  105. func (bmu *BatchMsgUpdate) SetFromwxid(s string) *BatchMsgUpdate {
  106. bmu.mutation.SetFromwxid(s)
  107. return bmu
  108. }
  109. // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
  110. func (bmu *BatchMsgUpdate) SetNillableFromwxid(s *string) *BatchMsgUpdate {
  111. if s != nil {
  112. bmu.SetFromwxid(*s)
  113. }
  114. return bmu
  115. }
  116. // ClearFromwxid clears the value of the "fromwxid" field.
  117. func (bmu *BatchMsgUpdate) ClearFromwxid() *BatchMsgUpdate {
  118. bmu.mutation.ClearFromwxid()
  119. return bmu
  120. }
  121. // SetMsg sets the "msg" field.
  122. func (bmu *BatchMsgUpdate) SetMsg(s string) *BatchMsgUpdate {
  123. bmu.mutation.SetMsg(s)
  124. return bmu
  125. }
  126. // SetNillableMsg sets the "msg" field if the given value is not nil.
  127. func (bmu *BatchMsgUpdate) SetNillableMsg(s *string) *BatchMsgUpdate {
  128. if s != nil {
  129. bmu.SetMsg(*s)
  130. }
  131. return bmu
  132. }
  133. // ClearMsg clears the value of the "msg" field.
  134. func (bmu *BatchMsgUpdate) ClearMsg() *BatchMsgUpdate {
  135. bmu.mutation.ClearMsg()
  136. return bmu
  137. }
  138. // SetTag sets the "tag" field.
  139. func (bmu *BatchMsgUpdate) SetTag(s string) *BatchMsgUpdate {
  140. bmu.mutation.SetTag(s)
  141. return bmu
  142. }
  143. // SetNillableTag sets the "tag" field if the given value is not nil.
  144. func (bmu *BatchMsgUpdate) SetNillableTag(s *string) *BatchMsgUpdate {
  145. if s != nil {
  146. bmu.SetTag(*s)
  147. }
  148. return bmu
  149. }
  150. // ClearTag clears the value of the "tag" field.
  151. func (bmu *BatchMsgUpdate) ClearTag() *BatchMsgUpdate {
  152. bmu.mutation.ClearTag()
  153. return bmu
  154. }
  155. // SetTotal sets the "total" field.
  156. func (bmu *BatchMsgUpdate) SetTotal(i int32) *BatchMsgUpdate {
  157. bmu.mutation.ResetTotal()
  158. bmu.mutation.SetTotal(i)
  159. return bmu
  160. }
  161. // SetNillableTotal sets the "total" field if the given value is not nil.
  162. func (bmu *BatchMsgUpdate) SetNillableTotal(i *int32) *BatchMsgUpdate {
  163. if i != nil {
  164. bmu.SetTotal(*i)
  165. }
  166. return bmu
  167. }
  168. // AddTotal adds i to the "total" field.
  169. func (bmu *BatchMsgUpdate) AddTotal(i int32) *BatchMsgUpdate {
  170. bmu.mutation.AddTotal(i)
  171. return bmu
  172. }
  173. // ClearTotal clears the value of the "total" field.
  174. func (bmu *BatchMsgUpdate) ClearTotal() *BatchMsgUpdate {
  175. bmu.mutation.ClearTotal()
  176. return bmu
  177. }
  178. // SetSuccess sets the "success" field.
  179. func (bmu *BatchMsgUpdate) SetSuccess(i int32) *BatchMsgUpdate {
  180. bmu.mutation.ResetSuccess()
  181. bmu.mutation.SetSuccess(i)
  182. return bmu
  183. }
  184. // SetNillableSuccess sets the "success" field if the given value is not nil.
  185. func (bmu *BatchMsgUpdate) SetNillableSuccess(i *int32) *BatchMsgUpdate {
  186. if i != nil {
  187. bmu.SetSuccess(*i)
  188. }
  189. return bmu
  190. }
  191. // AddSuccess adds i to the "success" field.
  192. func (bmu *BatchMsgUpdate) AddSuccess(i int32) *BatchMsgUpdate {
  193. bmu.mutation.AddSuccess(i)
  194. return bmu
  195. }
  196. // ClearSuccess clears the value of the "success" field.
  197. func (bmu *BatchMsgUpdate) ClearSuccess() *BatchMsgUpdate {
  198. bmu.mutation.ClearSuccess()
  199. return bmu
  200. }
  201. // SetFail sets the "fail" field.
  202. func (bmu *BatchMsgUpdate) SetFail(i int32) *BatchMsgUpdate {
  203. bmu.mutation.ResetFail()
  204. bmu.mutation.SetFail(i)
  205. return bmu
  206. }
  207. // SetNillableFail sets the "fail" field if the given value is not nil.
  208. func (bmu *BatchMsgUpdate) SetNillableFail(i *int32) *BatchMsgUpdate {
  209. if i != nil {
  210. bmu.SetFail(*i)
  211. }
  212. return bmu
  213. }
  214. // AddFail adds i to the "fail" field.
  215. func (bmu *BatchMsgUpdate) AddFail(i int32) *BatchMsgUpdate {
  216. bmu.mutation.AddFail(i)
  217. return bmu
  218. }
  219. // ClearFail clears the value of the "fail" field.
  220. func (bmu *BatchMsgUpdate) ClearFail() *BatchMsgUpdate {
  221. bmu.mutation.ClearFail()
  222. return bmu
  223. }
  224. // SetStartTime sets the "start_time" field.
  225. func (bmu *BatchMsgUpdate) SetStartTime(t time.Time) *BatchMsgUpdate {
  226. bmu.mutation.SetStartTime(t)
  227. return bmu
  228. }
  229. // SetNillableStartTime sets the "start_time" field if the given value is not nil.
  230. func (bmu *BatchMsgUpdate) SetNillableStartTime(t *time.Time) *BatchMsgUpdate {
  231. if t != nil {
  232. bmu.SetStartTime(*t)
  233. }
  234. return bmu
  235. }
  236. // ClearStartTime clears the value of the "start_time" field.
  237. func (bmu *BatchMsgUpdate) ClearStartTime() *BatchMsgUpdate {
  238. bmu.mutation.ClearStartTime()
  239. return bmu
  240. }
  241. // SetStopTime sets the "stop_time" field.
  242. func (bmu *BatchMsgUpdate) SetStopTime(t time.Time) *BatchMsgUpdate {
  243. bmu.mutation.SetStopTime(t)
  244. return bmu
  245. }
  246. // SetNillableStopTime sets the "stop_time" field if the given value is not nil.
  247. func (bmu *BatchMsgUpdate) SetNillableStopTime(t *time.Time) *BatchMsgUpdate {
  248. if t != nil {
  249. bmu.SetStopTime(*t)
  250. }
  251. return bmu
  252. }
  253. // ClearStopTime clears the value of the "stop_time" field.
  254. func (bmu *BatchMsgUpdate) ClearStopTime() *BatchMsgUpdate {
  255. bmu.mutation.ClearStopTime()
  256. return bmu
  257. }
  258. // SetType sets the "type" field.
  259. func (bmu *BatchMsgUpdate) SetType(i int32) *BatchMsgUpdate {
  260. bmu.mutation.ResetType()
  261. bmu.mutation.SetType(i)
  262. return bmu
  263. }
  264. // SetNillableType sets the "type" field if the given value is not nil.
  265. func (bmu *BatchMsgUpdate) SetNillableType(i *int32) *BatchMsgUpdate {
  266. if i != nil {
  267. bmu.SetType(*i)
  268. }
  269. return bmu
  270. }
  271. // AddType adds i to the "type" field.
  272. func (bmu *BatchMsgUpdate) AddType(i int32) *BatchMsgUpdate {
  273. bmu.mutation.AddType(i)
  274. return bmu
  275. }
  276. // ClearType clears the value of the "type" field.
  277. func (bmu *BatchMsgUpdate) ClearType() *BatchMsgUpdate {
  278. bmu.mutation.ClearType()
  279. return bmu
  280. }
  281. // SetOrganizationID sets the "organization_id" field.
  282. func (bmu *BatchMsgUpdate) SetOrganizationID(u uint64) *BatchMsgUpdate {
  283. bmu.mutation.ResetOrganizationID()
  284. bmu.mutation.SetOrganizationID(u)
  285. return bmu
  286. }
  287. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  288. func (bmu *BatchMsgUpdate) SetNillableOrganizationID(u *uint64) *BatchMsgUpdate {
  289. if u != nil {
  290. bmu.SetOrganizationID(*u)
  291. }
  292. return bmu
  293. }
  294. // AddOrganizationID adds u to the "organization_id" field.
  295. func (bmu *BatchMsgUpdate) AddOrganizationID(u int64) *BatchMsgUpdate {
  296. bmu.mutation.AddOrganizationID(u)
  297. return bmu
  298. }
  299. // Mutation returns the BatchMsgMutation object of the builder.
  300. func (bmu *BatchMsgUpdate) Mutation() *BatchMsgMutation {
  301. return bmu.mutation
  302. }
  303. // Save executes the query and returns the number of nodes affected by the update operation.
  304. func (bmu *BatchMsgUpdate) Save(ctx context.Context) (int, error) {
  305. if err := bmu.defaults(); err != nil {
  306. return 0, err
  307. }
  308. return withHooks(ctx, bmu.sqlSave, bmu.mutation, bmu.hooks)
  309. }
  310. // SaveX is like Save, but panics if an error occurs.
  311. func (bmu *BatchMsgUpdate) SaveX(ctx context.Context) int {
  312. affected, err := bmu.Save(ctx)
  313. if err != nil {
  314. panic(err)
  315. }
  316. return affected
  317. }
  318. // Exec executes the query.
  319. func (bmu *BatchMsgUpdate) Exec(ctx context.Context) error {
  320. _, err := bmu.Save(ctx)
  321. return err
  322. }
  323. // ExecX is like Exec, but panics if an error occurs.
  324. func (bmu *BatchMsgUpdate) ExecX(ctx context.Context) {
  325. if err := bmu.Exec(ctx); err != nil {
  326. panic(err)
  327. }
  328. }
  329. // defaults sets the default values of the builder before save.
  330. func (bmu *BatchMsgUpdate) defaults() error {
  331. if _, ok := bmu.mutation.UpdatedAt(); !ok {
  332. if batchmsg.UpdateDefaultUpdatedAt == nil {
  333. return fmt.Errorf("ent: uninitialized batchmsg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  334. }
  335. v := batchmsg.UpdateDefaultUpdatedAt()
  336. bmu.mutation.SetUpdatedAt(v)
  337. }
  338. return nil
  339. }
  340. // check runs all checks and user-defined validators on the builder.
  341. func (bmu *BatchMsgUpdate) check() error {
  342. if v, ok := bmu.mutation.OrganizationID(); ok {
  343. if err := batchmsg.OrganizationIDValidator(v); err != nil {
  344. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "BatchMsg.organization_id": %w`, err)}
  345. }
  346. }
  347. return nil
  348. }
  349. func (bmu *BatchMsgUpdate) sqlSave(ctx context.Context) (n int, err error) {
  350. if err := bmu.check(); err != nil {
  351. return n, err
  352. }
  353. _spec := sqlgraph.NewUpdateSpec(batchmsg.Table, batchmsg.Columns, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
  354. if ps := bmu.mutation.predicates; len(ps) > 0 {
  355. _spec.Predicate = func(selector *sql.Selector) {
  356. for i := range ps {
  357. ps[i](selector)
  358. }
  359. }
  360. }
  361. if value, ok := bmu.mutation.UpdatedAt(); ok {
  362. _spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
  363. }
  364. if value, ok := bmu.mutation.DeletedAt(); ok {
  365. _spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
  366. }
  367. if bmu.mutation.DeletedAtCleared() {
  368. _spec.ClearField(batchmsg.FieldDeletedAt, field.TypeTime)
  369. }
  370. if value, ok := bmu.mutation.Status(); ok {
  371. _spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
  372. }
  373. if value, ok := bmu.mutation.AddedStatus(); ok {
  374. _spec.AddField(batchmsg.FieldStatus, field.TypeUint8, value)
  375. }
  376. if bmu.mutation.StatusCleared() {
  377. _spec.ClearField(batchmsg.FieldStatus, field.TypeUint8)
  378. }
  379. if value, ok := bmu.mutation.BatchNo(); ok {
  380. _spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
  381. }
  382. if bmu.mutation.BatchNoCleared() {
  383. _spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
  384. }
  385. if value, ok := bmu.mutation.TaskName(); ok {
  386. _spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
  387. }
  388. if bmu.mutation.TaskNameCleared() {
  389. _spec.ClearField(batchmsg.FieldTaskName, field.TypeString)
  390. }
  391. if value, ok := bmu.mutation.Fromwxid(); ok {
  392. _spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
  393. }
  394. if bmu.mutation.FromwxidCleared() {
  395. _spec.ClearField(batchmsg.FieldFromwxid, field.TypeString)
  396. }
  397. if value, ok := bmu.mutation.Msg(); ok {
  398. _spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
  399. }
  400. if bmu.mutation.MsgCleared() {
  401. _spec.ClearField(batchmsg.FieldMsg, field.TypeString)
  402. }
  403. if value, ok := bmu.mutation.Tag(); ok {
  404. _spec.SetField(batchmsg.FieldTag, field.TypeString, value)
  405. }
  406. if bmu.mutation.TagCleared() {
  407. _spec.ClearField(batchmsg.FieldTag, field.TypeString)
  408. }
  409. if value, ok := bmu.mutation.Total(); ok {
  410. _spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
  411. }
  412. if value, ok := bmu.mutation.AddedTotal(); ok {
  413. _spec.AddField(batchmsg.FieldTotal, field.TypeInt32, value)
  414. }
  415. if bmu.mutation.TotalCleared() {
  416. _spec.ClearField(batchmsg.FieldTotal, field.TypeInt32)
  417. }
  418. if value, ok := bmu.mutation.Success(); ok {
  419. _spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
  420. }
  421. if value, ok := bmu.mutation.AddedSuccess(); ok {
  422. _spec.AddField(batchmsg.FieldSuccess, field.TypeInt32, value)
  423. }
  424. if bmu.mutation.SuccessCleared() {
  425. _spec.ClearField(batchmsg.FieldSuccess, field.TypeInt32)
  426. }
  427. if value, ok := bmu.mutation.Fail(); ok {
  428. _spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
  429. }
  430. if value, ok := bmu.mutation.AddedFail(); ok {
  431. _spec.AddField(batchmsg.FieldFail, field.TypeInt32, value)
  432. }
  433. if bmu.mutation.FailCleared() {
  434. _spec.ClearField(batchmsg.FieldFail, field.TypeInt32)
  435. }
  436. if value, ok := bmu.mutation.StartTime(); ok {
  437. _spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
  438. }
  439. if bmu.mutation.StartTimeCleared() {
  440. _spec.ClearField(batchmsg.FieldStartTime, field.TypeTime)
  441. }
  442. if value, ok := bmu.mutation.StopTime(); ok {
  443. _spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
  444. }
  445. if bmu.mutation.StopTimeCleared() {
  446. _spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
  447. }
  448. if value, ok := bmu.mutation.GetType(); ok {
  449. _spec.SetField(batchmsg.FieldType, field.TypeInt32, value)
  450. }
  451. if value, ok := bmu.mutation.AddedType(); ok {
  452. _spec.AddField(batchmsg.FieldType, field.TypeInt32, value)
  453. }
  454. if bmu.mutation.TypeCleared() {
  455. _spec.ClearField(batchmsg.FieldType, field.TypeInt32)
  456. }
  457. if value, ok := bmu.mutation.OrganizationID(); ok {
  458. _spec.SetField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
  459. }
  460. if value, ok := bmu.mutation.AddedOrganizationID(); ok {
  461. _spec.AddField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
  462. }
  463. if n, err = sqlgraph.UpdateNodes(ctx, bmu.driver, _spec); err != nil {
  464. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  465. err = &NotFoundError{batchmsg.Label}
  466. } else if sqlgraph.IsConstraintError(err) {
  467. err = &ConstraintError{msg: err.Error(), wrap: err}
  468. }
  469. return 0, err
  470. }
  471. bmu.mutation.done = true
  472. return n, nil
  473. }
  474. // BatchMsgUpdateOne is the builder for updating a single BatchMsg entity.
  475. type BatchMsgUpdateOne struct {
  476. config
  477. fields []string
  478. hooks []Hook
  479. mutation *BatchMsgMutation
  480. }
  481. // SetUpdatedAt sets the "updated_at" field.
  482. func (bmuo *BatchMsgUpdateOne) SetUpdatedAt(t time.Time) *BatchMsgUpdateOne {
  483. bmuo.mutation.SetUpdatedAt(t)
  484. return bmuo
  485. }
  486. // SetDeletedAt sets the "deleted_at" field.
  487. func (bmuo *BatchMsgUpdateOne) SetDeletedAt(t time.Time) *BatchMsgUpdateOne {
  488. bmuo.mutation.SetDeletedAt(t)
  489. return bmuo
  490. }
  491. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  492. func (bmuo *BatchMsgUpdateOne) SetNillableDeletedAt(t *time.Time) *BatchMsgUpdateOne {
  493. if t != nil {
  494. bmuo.SetDeletedAt(*t)
  495. }
  496. return bmuo
  497. }
  498. // ClearDeletedAt clears the value of the "deleted_at" field.
  499. func (bmuo *BatchMsgUpdateOne) ClearDeletedAt() *BatchMsgUpdateOne {
  500. bmuo.mutation.ClearDeletedAt()
  501. return bmuo
  502. }
  503. // SetStatus sets the "status" field.
  504. func (bmuo *BatchMsgUpdateOne) SetStatus(u uint8) *BatchMsgUpdateOne {
  505. bmuo.mutation.ResetStatus()
  506. bmuo.mutation.SetStatus(u)
  507. return bmuo
  508. }
  509. // SetNillableStatus sets the "status" field if the given value is not nil.
  510. func (bmuo *BatchMsgUpdateOne) SetNillableStatus(u *uint8) *BatchMsgUpdateOne {
  511. if u != nil {
  512. bmuo.SetStatus(*u)
  513. }
  514. return bmuo
  515. }
  516. // AddStatus adds u to the "status" field.
  517. func (bmuo *BatchMsgUpdateOne) AddStatus(u int8) *BatchMsgUpdateOne {
  518. bmuo.mutation.AddStatus(u)
  519. return bmuo
  520. }
  521. // ClearStatus clears the value of the "status" field.
  522. func (bmuo *BatchMsgUpdateOne) ClearStatus() *BatchMsgUpdateOne {
  523. bmuo.mutation.ClearStatus()
  524. return bmuo
  525. }
  526. // SetBatchNo sets the "batch_no" field.
  527. func (bmuo *BatchMsgUpdateOne) SetBatchNo(s string) *BatchMsgUpdateOne {
  528. bmuo.mutation.SetBatchNo(s)
  529. return bmuo
  530. }
  531. // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
  532. func (bmuo *BatchMsgUpdateOne) SetNillableBatchNo(s *string) *BatchMsgUpdateOne {
  533. if s != nil {
  534. bmuo.SetBatchNo(*s)
  535. }
  536. return bmuo
  537. }
  538. // ClearBatchNo clears the value of the "batch_no" field.
  539. func (bmuo *BatchMsgUpdateOne) ClearBatchNo() *BatchMsgUpdateOne {
  540. bmuo.mutation.ClearBatchNo()
  541. return bmuo
  542. }
  543. // SetTaskName sets the "task_name" field.
  544. func (bmuo *BatchMsgUpdateOne) SetTaskName(s string) *BatchMsgUpdateOne {
  545. bmuo.mutation.SetTaskName(s)
  546. return bmuo
  547. }
  548. // SetNillableTaskName sets the "task_name" field if the given value is not nil.
  549. func (bmuo *BatchMsgUpdateOne) SetNillableTaskName(s *string) *BatchMsgUpdateOne {
  550. if s != nil {
  551. bmuo.SetTaskName(*s)
  552. }
  553. return bmuo
  554. }
  555. // ClearTaskName clears the value of the "task_name" field.
  556. func (bmuo *BatchMsgUpdateOne) ClearTaskName() *BatchMsgUpdateOne {
  557. bmuo.mutation.ClearTaskName()
  558. return bmuo
  559. }
  560. // SetFromwxid sets the "fromwxid" field.
  561. func (bmuo *BatchMsgUpdateOne) SetFromwxid(s string) *BatchMsgUpdateOne {
  562. bmuo.mutation.SetFromwxid(s)
  563. return bmuo
  564. }
  565. // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
  566. func (bmuo *BatchMsgUpdateOne) SetNillableFromwxid(s *string) *BatchMsgUpdateOne {
  567. if s != nil {
  568. bmuo.SetFromwxid(*s)
  569. }
  570. return bmuo
  571. }
  572. // ClearFromwxid clears the value of the "fromwxid" field.
  573. func (bmuo *BatchMsgUpdateOne) ClearFromwxid() *BatchMsgUpdateOne {
  574. bmuo.mutation.ClearFromwxid()
  575. return bmuo
  576. }
  577. // SetMsg sets the "msg" field.
  578. func (bmuo *BatchMsgUpdateOne) SetMsg(s string) *BatchMsgUpdateOne {
  579. bmuo.mutation.SetMsg(s)
  580. return bmuo
  581. }
  582. // SetNillableMsg sets the "msg" field if the given value is not nil.
  583. func (bmuo *BatchMsgUpdateOne) SetNillableMsg(s *string) *BatchMsgUpdateOne {
  584. if s != nil {
  585. bmuo.SetMsg(*s)
  586. }
  587. return bmuo
  588. }
  589. // ClearMsg clears the value of the "msg" field.
  590. func (bmuo *BatchMsgUpdateOne) ClearMsg() *BatchMsgUpdateOne {
  591. bmuo.mutation.ClearMsg()
  592. return bmuo
  593. }
  594. // SetTag sets the "tag" field.
  595. func (bmuo *BatchMsgUpdateOne) SetTag(s string) *BatchMsgUpdateOne {
  596. bmuo.mutation.SetTag(s)
  597. return bmuo
  598. }
  599. // SetNillableTag sets the "tag" field if the given value is not nil.
  600. func (bmuo *BatchMsgUpdateOne) SetNillableTag(s *string) *BatchMsgUpdateOne {
  601. if s != nil {
  602. bmuo.SetTag(*s)
  603. }
  604. return bmuo
  605. }
  606. // ClearTag clears the value of the "tag" field.
  607. func (bmuo *BatchMsgUpdateOne) ClearTag() *BatchMsgUpdateOne {
  608. bmuo.mutation.ClearTag()
  609. return bmuo
  610. }
  611. // SetTotal sets the "total" field.
  612. func (bmuo *BatchMsgUpdateOne) SetTotal(i int32) *BatchMsgUpdateOne {
  613. bmuo.mutation.ResetTotal()
  614. bmuo.mutation.SetTotal(i)
  615. return bmuo
  616. }
  617. // SetNillableTotal sets the "total" field if the given value is not nil.
  618. func (bmuo *BatchMsgUpdateOne) SetNillableTotal(i *int32) *BatchMsgUpdateOne {
  619. if i != nil {
  620. bmuo.SetTotal(*i)
  621. }
  622. return bmuo
  623. }
  624. // AddTotal adds i to the "total" field.
  625. func (bmuo *BatchMsgUpdateOne) AddTotal(i int32) *BatchMsgUpdateOne {
  626. bmuo.mutation.AddTotal(i)
  627. return bmuo
  628. }
  629. // ClearTotal clears the value of the "total" field.
  630. func (bmuo *BatchMsgUpdateOne) ClearTotal() *BatchMsgUpdateOne {
  631. bmuo.mutation.ClearTotal()
  632. return bmuo
  633. }
  634. // SetSuccess sets the "success" field.
  635. func (bmuo *BatchMsgUpdateOne) SetSuccess(i int32) *BatchMsgUpdateOne {
  636. bmuo.mutation.ResetSuccess()
  637. bmuo.mutation.SetSuccess(i)
  638. return bmuo
  639. }
  640. // SetNillableSuccess sets the "success" field if the given value is not nil.
  641. func (bmuo *BatchMsgUpdateOne) SetNillableSuccess(i *int32) *BatchMsgUpdateOne {
  642. if i != nil {
  643. bmuo.SetSuccess(*i)
  644. }
  645. return bmuo
  646. }
  647. // AddSuccess adds i to the "success" field.
  648. func (bmuo *BatchMsgUpdateOne) AddSuccess(i int32) *BatchMsgUpdateOne {
  649. bmuo.mutation.AddSuccess(i)
  650. return bmuo
  651. }
  652. // ClearSuccess clears the value of the "success" field.
  653. func (bmuo *BatchMsgUpdateOne) ClearSuccess() *BatchMsgUpdateOne {
  654. bmuo.mutation.ClearSuccess()
  655. return bmuo
  656. }
  657. // SetFail sets the "fail" field.
  658. func (bmuo *BatchMsgUpdateOne) SetFail(i int32) *BatchMsgUpdateOne {
  659. bmuo.mutation.ResetFail()
  660. bmuo.mutation.SetFail(i)
  661. return bmuo
  662. }
  663. // SetNillableFail sets the "fail" field if the given value is not nil.
  664. func (bmuo *BatchMsgUpdateOne) SetNillableFail(i *int32) *BatchMsgUpdateOne {
  665. if i != nil {
  666. bmuo.SetFail(*i)
  667. }
  668. return bmuo
  669. }
  670. // AddFail adds i to the "fail" field.
  671. func (bmuo *BatchMsgUpdateOne) AddFail(i int32) *BatchMsgUpdateOne {
  672. bmuo.mutation.AddFail(i)
  673. return bmuo
  674. }
  675. // ClearFail clears the value of the "fail" field.
  676. func (bmuo *BatchMsgUpdateOne) ClearFail() *BatchMsgUpdateOne {
  677. bmuo.mutation.ClearFail()
  678. return bmuo
  679. }
  680. // SetStartTime sets the "start_time" field.
  681. func (bmuo *BatchMsgUpdateOne) SetStartTime(t time.Time) *BatchMsgUpdateOne {
  682. bmuo.mutation.SetStartTime(t)
  683. return bmuo
  684. }
  685. // SetNillableStartTime sets the "start_time" field if the given value is not nil.
  686. func (bmuo *BatchMsgUpdateOne) SetNillableStartTime(t *time.Time) *BatchMsgUpdateOne {
  687. if t != nil {
  688. bmuo.SetStartTime(*t)
  689. }
  690. return bmuo
  691. }
  692. // ClearStartTime clears the value of the "start_time" field.
  693. func (bmuo *BatchMsgUpdateOne) ClearStartTime() *BatchMsgUpdateOne {
  694. bmuo.mutation.ClearStartTime()
  695. return bmuo
  696. }
  697. // SetStopTime sets the "stop_time" field.
  698. func (bmuo *BatchMsgUpdateOne) SetStopTime(t time.Time) *BatchMsgUpdateOne {
  699. bmuo.mutation.SetStopTime(t)
  700. return bmuo
  701. }
  702. // SetNillableStopTime sets the "stop_time" field if the given value is not nil.
  703. func (bmuo *BatchMsgUpdateOne) SetNillableStopTime(t *time.Time) *BatchMsgUpdateOne {
  704. if t != nil {
  705. bmuo.SetStopTime(*t)
  706. }
  707. return bmuo
  708. }
  709. // ClearStopTime clears the value of the "stop_time" field.
  710. func (bmuo *BatchMsgUpdateOne) ClearStopTime() *BatchMsgUpdateOne {
  711. bmuo.mutation.ClearStopTime()
  712. return bmuo
  713. }
  714. // SetType sets the "type" field.
  715. func (bmuo *BatchMsgUpdateOne) SetType(i int32) *BatchMsgUpdateOne {
  716. bmuo.mutation.ResetType()
  717. bmuo.mutation.SetType(i)
  718. return bmuo
  719. }
  720. // SetNillableType sets the "type" field if the given value is not nil.
  721. func (bmuo *BatchMsgUpdateOne) SetNillableType(i *int32) *BatchMsgUpdateOne {
  722. if i != nil {
  723. bmuo.SetType(*i)
  724. }
  725. return bmuo
  726. }
  727. // AddType adds i to the "type" field.
  728. func (bmuo *BatchMsgUpdateOne) AddType(i int32) *BatchMsgUpdateOne {
  729. bmuo.mutation.AddType(i)
  730. return bmuo
  731. }
  732. // ClearType clears the value of the "type" field.
  733. func (bmuo *BatchMsgUpdateOne) ClearType() *BatchMsgUpdateOne {
  734. bmuo.mutation.ClearType()
  735. return bmuo
  736. }
  737. // SetOrganizationID sets the "organization_id" field.
  738. func (bmuo *BatchMsgUpdateOne) SetOrganizationID(u uint64) *BatchMsgUpdateOne {
  739. bmuo.mutation.ResetOrganizationID()
  740. bmuo.mutation.SetOrganizationID(u)
  741. return bmuo
  742. }
  743. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  744. func (bmuo *BatchMsgUpdateOne) SetNillableOrganizationID(u *uint64) *BatchMsgUpdateOne {
  745. if u != nil {
  746. bmuo.SetOrganizationID(*u)
  747. }
  748. return bmuo
  749. }
  750. // AddOrganizationID adds u to the "organization_id" field.
  751. func (bmuo *BatchMsgUpdateOne) AddOrganizationID(u int64) *BatchMsgUpdateOne {
  752. bmuo.mutation.AddOrganizationID(u)
  753. return bmuo
  754. }
  755. // Mutation returns the BatchMsgMutation object of the builder.
  756. func (bmuo *BatchMsgUpdateOne) Mutation() *BatchMsgMutation {
  757. return bmuo.mutation
  758. }
  759. // Where appends a list predicates to the BatchMsgUpdate builder.
  760. func (bmuo *BatchMsgUpdateOne) Where(ps ...predicate.BatchMsg) *BatchMsgUpdateOne {
  761. bmuo.mutation.Where(ps...)
  762. return bmuo
  763. }
  764. // Select allows selecting one or more fields (columns) of the returned entity.
  765. // The default is selecting all fields defined in the entity schema.
  766. func (bmuo *BatchMsgUpdateOne) Select(field string, fields ...string) *BatchMsgUpdateOne {
  767. bmuo.fields = append([]string{field}, fields...)
  768. return bmuo
  769. }
  770. // Save executes the query and returns the updated BatchMsg entity.
  771. func (bmuo *BatchMsgUpdateOne) Save(ctx context.Context) (*BatchMsg, error) {
  772. if err := bmuo.defaults(); err != nil {
  773. return nil, err
  774. }
  775. return withHooks(ctx, bmuo.sqlSave, bmuo.mutation, bmuo.hooks)
  776. }
  777. // SaveX is like Save, but panics if an error occurs.
  778. func (bmuo *BatchMsgUpdateOne) SaveX(ctx context.Context) *BatchMsg {
  779. node, err := bmuo.Save(ctx)
  780. if err != nil {
  781. panic(err)
  782. }
  783. return node
  784. }
  785. // Exec executes the query on the entity.
  786. func (bmuo *BatchMsgUpdateOne) Exec(ctx context.Context) error {
  787. _, err := bmuo.Save(ctx)
  788. return err
  789. }
  790. // ExecX is like Exec, but panics if an error occurs.
  791. func (bmuo *BatchMsgUpdateOne) ExecX(ctx context.Context) {
  792. if err := bmuo.Exec(ctx); err != nil {
  793. panic(err)
  794. }
  795. }
  796. // defaults sets the default values of the builder before save.
  797. func (bmuo *BatchMsgUpdateOne) defaults() error {
  798. if _, ok := bmuo.mutation.UpdatedAt(); !ok {
  799. if batchmsg.UpdateDefaultUpdatedAt == nil {
  800. return fmt.Errorf("ent: uninitialized batchmsg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  801. }
  802. v := batchmsg.UpdateDefaultUpdatedAt()
  803. bmuo.mutation.SetUpdatedAt(v)
  804. }
  805. return nil
  806. }
  807. // check runs all checks and user-defined validators on the builder.
  808. func (bmuo *BatchMsgUpdateOne) check() error {
  809. if v, ok := bmuo.mutation.OrganizationID(); ok {
  810. if err := batchmsg.OrganizationIDValidator(v); err != nil {
  811. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "BatchMsg.organization_id": %w`, err)}
  812. }
  813. }
  814. return nil
  815. }
  816. func (bmuo *BatchMsgUpdateOne) sqlSave(ctx context.Context) (_node *BatchMsg, err error) {
  817. if err := bmuo.check(); err != nil {
  818. return _node, err
  819. }
  820. _spec := sqlgraph.NewUpdateSpec(batchmsg.Table, batchmsg.Columns, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
  821. id, ok := bmuo.mutation.ID()
  822. if !ok {
  823. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BatchMsg.id" for update`)}
  824. }
  825. _spec.Node.ID.Value = id
  826. if fields := bmuo.fields; len(fields) > 0 {
  827. _spec.Node.Columns = make([]string, 0, len(fields))
  828. _spec.Node.Columns = append(_spec.Node.Columns, batchmsg.FieldID)
  829. for _, f := range fields {
  830. if !batchmsg.ValidColumn(f) {
  831. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  832. }
  833. if f != batchmsg.FieldID {
  834. _spec.Node.Columns = append(_spec.Node.Columns, f)
  835. }
  836. }
  837. }
  838. if ps := bmuo.mutation.predicates; len(ps) > 0 {
  839. _spec.Predicate = func(selector *sql.Selector) {
  840. for i := range ps {
  841. ps[i](selector)
  842. }
  843. }
  844. }
  845. if value, ok := bmuo.mutation.UpdatedAt(); ok {
  846. _spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
  847. }
  848. if value, ok := bmuo.mutation.DeletedAt(); ok {
  849. _spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
  850. }
  851. if bmuo.mutation.DeletedAtCleared() {
  852. _spec.ClearField(batchmsg.FieldDeletedAt, field.TypeTime)
  853. }
  854. if value, ok := bmuo.mutation.Status(); ok {
  855. _spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
  856. }
  857. if value, ok := bmuo.mutation.AddedStatus(); ok {
  858. _spec.AddField(batchmsg.FieldStatus, field.TypeUint8, value)
  859. }
  860. if bmuo.mutation.StatusCleared() {
  861. _spec.ClearField(batchmsg.FieldStatus, field.TypeUint8)
  862. }
  863. if value, ok := bmuo.mutation.BatchNo(); ok {
  864. _spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
  865. }
  866. if bmuo.mutation.BatchNoCleared() {
  867. _spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
  868. }
  869. if value, ok := bmuo.mutation.TaskName(); ok {
  870. _spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
  871. }
  872. if bmuo.mutation.TaskNameCleared() {
  873. _spec.ClearField(batchmsg.FieldTaskName, field.TypeString)
  874. }
  875. if value, ok := bmuo.mutation.Fromwxid(); ok {
  876. _spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
  877. }
  878. if bmuo.mutation.FromwxidCleared() {
  879. _spec.ClearField(batchmsg.FieldFromwxid, field.TypeString)
  880. }
  881. if value, ok := bmuo.mutation.Msg(); ok {
  882. _spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
  883. }
  884. if bmuo.mutation.MsgCleared() {
  885. _spec.ClearField(batchmsg.FieldMsg, field.TypeString)
  886. }
  887. if value, ok := bmuo.mutation.Tag(); ok {
  888. _spec.SetField(batchmsg.FieldTag, field.TypeString, value)
  889. }
  890. if bmuo.mutation.TagCleared() {
  891. _spec.ClearField(batchmsg.FieldTag, field.TypeString)
  892. }
  893. if value, ok := bmuo.mutation.Total(); ok {
  894. _spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
  895. }
  896. if value, ok := bmuo.mutation.AddedTotal(); ok {
  897. _spec.AddField(batchmsg.FieldTotal, field.TypeInt32, value)
  898. }
  899. if bmuo.mutation.TotalCleared() {
  900. _spec.ClearField(batchmsg.FieldTotal, field.TypeInt32)
  901. }
  902. if value, ok := bmuo.mutation.Success(); ok {
  903. _spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
  904. }
  905. if value, ok := bmuo.mutation.AddedSuccess(); ok {
  906. _spec.AddField(batchmsg.FieldSuccess, field.TypeInt32, value)
  907. }
  908. if bmuo.mutation.SuccessCleared() {
  909. _spec.ClearField(batchmsg.FieldSuccess, field.TypeInt32)
  910. }
  911. if value, ok := bmuo.mutation.Fail(); ok {
  912. _spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
  913. }
  914. if value, ok := bmuo.mutation.AddedFail(); ok {
  915. _spec.AddField(batchmsg.FieldFail, field.TypeInt32, value)
  916. }
  917. if bmuo.mutation.FailCleared() {
  918. _spec.ClearField(batchmsg.FieldFail, field.TypeInt32)
  919. }
  920. if value, ok := bmuo.mutation.StartTime(); ok {
  921. _spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
  922. }
  923. if bmuo.mutation.StartTimeCleared() {
  924. _spec.ClearField(batchmsg.FieldStartTime, field.TypeTime)
  925. }
  926. if value, ok := bmuo.mutation.StopTime(); ok {
  927. _spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
  928. }
  929. if bmuo.mutation.StopTimeCleared() {
  930. _spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
  931. }
  932. if value, ok := bmuo.mutation.GetType(); ok {
  933. _spec.SetField(batchmsg.FieldType, field.TypeInt32, value)
  934. }
  935. if value, ok := bmuo.mutation.AddedType(); ok {
  936. _spec.AddField(batchmsg.FieldType, field.TypeInt32, value)
  937. }
  938. if bmuo.mutation.TypeCleared() {
  939. _spec.ClearField(batchmsg.FieldType, field.TypeInt32)
  940. }
  941. if value, ok := bmuo.mutation.OrganizationID(); ok {
  942. _spec.SetField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
  943. }
  944. if value, ok := bmuo.mutation.AddedOrganizationID(); ok {
  945. _spec.AddField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
  946. }
  947. _node = &BatchMsg{config: bmuo.config}
  948. _spec.Assign = _node.assignValues
  949. _spec.ScanValues = _node.scanValues
  950. if err = sqlgraph.UpdateNode(ctx, bmuo.driver, _spec); err != nil {
  951. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  952. err = &NotFoundError{batchmsg.Label}
  953. } else if sqlgraph.IsConstraintError(err) {
  954. err = &ConstraintError{msg: err.Error(), wrap: err}
  955. }
  956. return nil, err
  957. }
  958. bmuo.mutation.done = true
  959. return _node, nil
  960. }