batchmsg_update.go 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  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. // SetSendTime sets the "send_time" field.
  259. func (bmu *BatchMsgUpdate) SetSendTime(t time.Time) *BatchMsgUpdate {
  260. bmu.mutation.SetSendTime(t)
  261. return bmu
  262. }
  263. // SetNillableSendTime sets the "send_time" field if the given value is not nil.
  264. func (bmu *BatchMsgUpdate) SetNillableSendTime(t *time.Time) *BatchMsgUpdate {
  265. if t != nil {
  266. bmu.SetSendTime(*t)
  267. }
  268. return bmu
  269. }
  270. // ClearSendTime clears the value of the "send_time" field.
  271. func (bmu *BatchMsgUpdate) ClearSendTime() *BatchMsgUpdate {
  272. bmu.mutation.ClearSendTime()
  273. return bmu
  274. }
  275. // SetType sets the "type" field.
  276. func (bmu *BatchMsgUpdate) SetType(i int32) *BatchMsgUpdate {
  277. bmu.mutation.ResetType()
  278. bmu.mutation.SetType(i)
  279. return bmu
  280. }
  281. // SetNillableType sets the "type" field if the given value is not nil.
  282. func (bmu *BatchMsgUpdate) SetNillableType(i *int32) *BatchMsgUpdate {
  283. if i != nil {
  284. bmu.SetType(*i)
  285. }
  286. return bmu
  287. }
  288. // AddType adds i to the "type" field.
  289. func (bmu *BatchMsgUpdate) AddType(i int32) *BatchMsgUpdate {
  290. bmu.mutation.AddType(i)
  291. return bmu
  292. }
  293. // ClearType clears the value of the "type" field.
  294. func (bmu *BatchMsgUpdate) ClearType() *BatchMsgUpdate {
  295. bmu.mutation.ClearType()
  296. return bmu
  297. }
  298. // Mutation returns the BatchMsgMutation object of the builder.
  299. func (bmu *BatchMsgUpdate) Mutation() *BatchMsgMutation {
  300. return bmu.mutation
  301. }
  302. // Save executes the query and returns the number of nodes affected by the update operation.
  303. func (bmu *BatchMsgUpdate) Save(ctx context.Context) (int, error) {
  304. if err := bmu.defaults(); err != nil {
  305. return 0, err
  306. }
  307. return withHooks(ctx, bmu.sqlSave, bmu.mutation, bmu.hooks)
  308. }
  309. // SaveX is like Save, but panics if an error occurs.
  310. func (bmu *BatchMsgUpdate) SaveX(ctx context.Context) int {
  311. affected, err := bmu.Save(ctx)
  312. if err != nil {
  313. panic(err)
  314. }
  315. return affected
  316. }
  317. // Exec executes the query.
  318. func (bmu *BatchMsgUpdate) Exec(ctx context.Context) error {
  319. _, err := bmu.Save(ctx)
  320. return err
  321. }
  322. // ExecX is like Exec, but panics if an error occurs.
  323. func (bmu *BatchMsgUpdate) ExecX(ctx context.Context) {
  324. if err := bmu.Exec(ctx); err != nil {
  325. panic(err)
  326. }
  327. }
  328. // defaults sets the default values of the builder before save.
  329. func (bmu *BatchMsgUpdate) defaults() error {
  330. if _, ok := bmu.mutation.UpdatedAt(); !ok {
  331. if batchmsg.UpdateDefaultUpdatedAt == nil {
  332. return fmt.Errorf("ent: uninitialized batchmsg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  333. }
  334. v := batchmsg.UpdateDefaultUpdatedAt()
  335. bmu.mutation.SetUpdatedAt(v)
  336. }
  337. return nil
  338. }
  339. func (bmu *BatchMsgUpdate) sqlSave(ctx context.Context) (n int, err error) {
  340. _spec := sqlgraph.NewUpdateSpec(batchmsg.Table, batchmsg.Columns, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
  341. if ps := bmu.mutation.predicates; len(ps) > 0 {
  342. _spec.Predicate = func(selector *sql.Selector) {
  343. for i := range ps {
  344. ps[i](selector)
  345. }
  346. }
  347. }
  348. if value, ok := bmu.mutation.UpdatedAt(); ok {
  349. _spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
  350. }
  351. if value, ok := bmu.mutation.DeletedAt(); ok {
  352. _spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
  353. }
  354. if bmu.mutation.DeletedAtCleared() {
  355. _spec.ClearField(batchmsg.FieldDeletedAt, field.TypeTime)
  356. }
  357. if value, ok := bmu.mutation.Status(); ok {
  358. _spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
  359. }
  360. if value, ok := bmu.mutation.AddedStatus(); ok {
  361. _spec.AddField(batchmsg.FieldStatus, field.TypeUint8, value)
  362. }
  363. if bmu.mutation.StatusCleared() {
  364. _spec.ClearField(batchmsg.FieldStatus, field.TypeUint8)
  365. }
  366. if value, ok := bmu.mutation.BatchNo(); ok {
  367. _spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
  368. }
  369. if bmu.mutation.BatchNoCleared() {
  370. _spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
  371. }
  372. if value, ok := bmu.mutation.TaskName(); ok {
  373. _spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
  374. }
  375. if bmu.mutation.TaskNameCleared() {
  376. _spec.ClearField(batchmsg.FieldTaskName, field.TypeString)
  377. }
  378. if value, ok := bmu.mutation.Fromwxid(); ok {
  379. _spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
  380. }
  381. if bmu.mutation.FromwxidCleared() {
  382. _spec.ClearField(batchmsg.FieldFromwxid, field.TypeString)
  383. }
  384. if value, ok := bmu.mutation.Msg(); ok {
  385. _spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
  386. }
  387. if bmu.mutation.MsgCleared() {
  388. _spec.ClearField(batchmsg.FieldMsg, field.TypeString)
  389. }
  390. if value, ok := bmu.mutation.Tag(); ok {
  391. _spec.SetField(batchmsg.FieldTag, field.TypeString, value)
  392. }
  393. if bmu.mutation.TagCleared() {
  394. _spec.ClearField(batchmsg.FieldTag, field.TypeString)
  395. }
  396. if value, ok := bmu.mutation.Total(); ok {
  397. _spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
  398. }
  399. if value, ok := bmu.mutation.AddedTotal(); ok {
  400. _spec.AddField(batchmsg.FieldTotal, field.TypeInt32, value)
  401. }
  402. if bmu.mutation.TotalCleared() {
  403. _spec.ClearField(batchmsg.FieldTotal, field.TypeInt32)
  404. }
  405. if value, ok := bmu.mutation.Success(); ok {
  406. _spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
  407. }
  408. if value, ok := bmu.mutation.AddedSuccess(); ok {
  409. _spec.AddField(batchmsg.FieldSuccess, field.TypeInt32, value)
  410. }
  411. if bmu.mutation.SuccessCleared() {
  412. _spec.ClearField(batchmsg.FieldSuccess, field.TypeInt32)
  413. }
  414. if value, ok := bmu.mutation.Fail(); ok {
  415. _spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
  416. }
  417. if value, ok := bmu.mutation.AddedFail(); ok {
  418. _spec.AddField(batchmsg.FieldFail, field.TypeInt32, value)
  419. }
  420. if bmu.mutation.FailCleared() {
  421. _spec.ClearField(batchmsg.FieldFail, field.TypeInt32)
  422. }
  423. if value, ok := bmu.mutation.StartTime(); ok {
  424. _spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
  425. }
  426. if bmu.mutation.StartTimeCleared() {
  427. _spec.ClearField(batchmsg.FieldStartTime, field.TypeTime)
  428. }
  429. if value, ok := bmu.mutation.StopTime(); ok {
  430. _spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
  431. }
  432. if bmu.mutation.StopTimeCleared() {
  433. _spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
  434. }
  435. if value, ok := bmu.mutation.SendTime(); ok {
  436. _spec.SetField(batchmsg.FieldSendTime, field.TypeTime, value)
  437. }
  438. if bmu.mutation.SendTimeCleared() {
  439. _spec.ClearField(batchmsg.FieldSendTime, field.TypeTime)
  440. }
  441. if value, ok := bmu.mutation.GetType(); ok {
  442. _spec.SetField(batchmsg.FieldType, field.TypeInt32, value)
  443. }
  444. if value, ok := bmu.mutation.AddedType(); ok {
  445. _spec.AddField(batchmsg.FieldType, field.TypeInt32, value)
  446. }
  447. if bmu.mutation.TypeCleared() {
  448. _spec.ClearField(batchmsg.FieldType, field.TypeInt32)
  449. }
  450. if n, err = sqlgraph.UpdateNodes(ctx, bmu.driver, _spec); err != nil {
  451. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  452. err = &NotFoundError{batchmsg.Label}
  453. } else if sqlgraph.IsConstraintError(err) {
  454. err = &ConstraintError{msg: err.Error(), wrap: err}
  455. }
  456. return 0, err
  457. }
  458. bmu.mutation.done = true
  459. return n, nil
  460. }
  461. // BatchMsgUpdateOne is the builder for updating a single BatchMsg entity.
  462. type BatchMsgUpdateOne struct {
  463. config
  464. fields []string
  465. hooks []Hook
  466. mutation *BatchMsgMutation
  467. }
  468. // SetUpdatedAt sets the "updated_at" field.
  469. func (bmuo *BatchMsgUpdateOne) SetUpdatedAt(t time.Time) *BatchMsgUpdateOne {
  470. bmuo.mutation.SetUpdatedAt(t)
  471. return bmuo
  472. }
  473. // SetDeletedAt sets the "deleted_at" field.
  474. func (bmuo *BatchMsgUpdateOne) SetDeletedAt(t time.Time) *BatchMsgUpdateOne {
  475. bmuo.mutation.SetDeletedAt(t)
  476. return bmuo
  477. }
  478. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  479. func (bmuo *BatchMsgUpdateOne) SetNillableDeletedAt(t *time.Time) *BatchMsgUpdateOne {
  480. if t != nil {
  481. bmuo.SetDeletedAt(*t)
  482. }
  483. return bmuo
  484. }
  485. // ClearDeletedAt clears the value of the "deleted_at" field.
  486. func (bmuo *BatchMsgUpdateOne) ClearDeletedAt() *BatchMsgUpdateOne {
  487. bmuo.mutation.ClearDeletedAt()
  488. return bmuo
  489. }
  490. // SetStatus sets the "status" field.
  491. func (bmuo *BatchMsgUpdateOne) SetStatus(u uint8) *BatchMsgUpdateOne {
  492. bmuo.mutation.ResetStatus()
  493. bmuo.mutation.SetStatus(u)
  494. return bmuo
  495. }
  496. // SetNillableStatus sets the "status" field if the given value is not nil.
  497. func (bmuo *BatchMsgUpdateOne) SetNillableStatus(u *uint8) *BatchMsgUpdateOne {
  498. if u != nil {
  499. bmuo.SetStatus(*u)
  500. }
  501. return bmuo
  502. }
  503. // AddStatus adds u to the "status" field.
  504. func (bmuo *BatchMsgUpdateOne) AddStatus(u int8) *BatchMsgUpdateOne {
  505. bmuo.mutation.AddStatus(u)
  506. return bmuo
  507. }
  508. // ClearStatus clears the value of the "status" field.
  509. func (bmuo *BatchMsgUpdateOne) ClearStatus() *BatchMsgUpdateOne {
  510. bmuo.mutation.ClearStatus()
  511. return bmuo
  512. }
  513. // SetBatchNo sets the "batch_no" field.
  514. func (bmuo *BatchMsgUpdateOne) SetBatchNo(s string) *BatchMsgUpdateOne {
  515. bmuo.mutation.SetBatchNo(s)
  516. return bmuo
  517. }
  518. // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
  519. func (bmuo *BatchMsgUpdateOne) SetNillableBatchNo(s *string) *BatchMsgUpdateOne {
  520. if s != nil {
  521. bmuo.SetBatchNo(*s)
  522. }
  523. return bmuo
  524. }
  525. // ClearBatchNo clears the value of the "batch_no" field.
  526. func (bmuo *BatchMsgUpdateOne) ClearBatchNo() *BatchMsgUpdateOne {
  527. bmuo.mutation.ClearBatchNo()
  528. return bmuo
  529. }
  530. // SetTaskName sets the "task_name" field.
  531. func (bmuo *BatchMsgUpdateOne) SetTaskName(s string) *BatchMsgUpdateOne {
  532. bmuo.mutation.SetTaskName(s)
  533. return bmuo
  534. }
  535. // SetNillableTaskName sets the "task_name" field if the given value is not nil.
  536. func (bmuo *BatchMsgUpdateOne) SetNillableTaskName(s *string) *BatchMsgUpdateOne {
  537. if s != nil {
  538. bmuo.SetTaskName(*s)
  539. }
  540. return bmuo
  541. }
  542. // ClearTaskName clears the value of the "task_name" field.
  543. func (bmuo *BatchMsgUpdateOne) ClearTaskName() *BatchMsgUpdateOne {
  544. bmuo.mutation.ClearTaskName()
  545. return bmuo
  546. }
  547. // SetFromwxid sets the "fromwxid" field.
  548. func (bmuo *BatchMsgUpdateOne) SetFromwxid(s string) *BatchMsgUpdateOne {
  549. bmuo.mutation.SetFromwxid(s)
  550. return bmuo
  551. }
  552. // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
  553. func (bmuo *BatchMsgUpdateOne) SetNillableFromwxid(s *string) *BatchMsgUpdateOne {
  554. if s != nil {
  555. bmuo.SetFromwxid(*s)
  556. }
  557. return bmuo
  558. }
  559. // ClearFromwxid clears the value of the "fromwxid" field.
  560. func (bmuo *BatchMsgUpdateOne) ClearFromwxid() *BatchMsgUpdateOne {
  561. bmuo.mutation.ClearFromwxid()
  562. return bmuo
  563. }
  564. // SetMsg sets the "msg" field.
  565. func (bmuo *BatchMsgUpdateOne) SetMsg(s string) *BatchMsgUpdateOne {
  566. bmuo.mutation.SetMsg(s)
  567. return bmuo
  568. }
  569. // SetNillableMsg sets the "msg" field if the given value is not nil.
  570. func (bmuo *BatchMsgUpdateOne) SetNillableMsg(s *string) *BatchMsgUpdateOne {
  571. if s != nil {
  572. bmuo.SetMsg(*s)
  573. }
  574. return bmuo
  575. }
  576. // ClearMsg clears the value of the "msg" field.
  577. func (bmuo *BatchMsgUpdateOne) ClearMsg() *BatchMsgUpdateOne {
  578. bmuo.mutation.ClearMsg()
  579. return bmuo
  580. }
  581. // SetTag sets the "tag" field.
  582. func (bmuo *BatchMsgUpdateOne) SetTag(s string) *BatchMsgUpdateOne {
  583. bmuo.mutation.SetTag(s)
  584. return bmuo
  585. }
  586. // SetNillableTag sets the "tag" field if the given value is not nil.
  587. func (bmuo *BatchMsgUpdateOne) SetNillableTag(s *string) *BatchMsgUpdateOne {
  588. if s != nil {
  589. bmuo.SetTag(*s)
  590. }
  591. return bmuo
  592. }
  593. // ClearTag clears the value of the "tag" field.
  594. func (bmuo *BatchMsgUpdateOne) ClearTag() *BatchMsgUpdateOne {
  595. bmuo.mutation.ClearTag()
  596. return bmuo
  597. }
  598. // SetTotal sets the "total" field.
  599. func (bmuo *BatchMsgUpdateOne) SetTotal(i int32) *BatchMsgUpdateOne {
  600. bmuo.mutation.ResetTotal()
  601. bmuo.mutation.SetTotal(i)
  602. return bmuo
  603. }
  604. // SetNillableTotal sets the "total" field if the given value is not nil.
  605. func (bmuo *BatchMsgUpdateOne) SetNillableTotal(i *int32) *BatchMsgUpdateOne {
  606. if i != nil {
  607. bmuo.SetTotal(*i)
  608. }
  609. return bmuo
  610. }
  611. // AddTotal adds i to the "total" field.
  612. func (bmuo *BatchMsgUpdateOne) AddTotal(i int32) *BatchMsgUpdateOne {
  613. bmuo.mutation.AddTotal(i)
  614. return bmuo
  615. }
  616. // ClearTotal clears the value of the "total" field.
  617. func (bmuo *BatchMsgUpdateOne) ClearTotal() *BatchMsgUpdateOne {
  618. bmuo.mutation.ClearTotal()
  619. return bmuo
  620. }
  621. // SetSuccess sets the "success" field.
  622. func (bmuo *BatchMsgUpdateOne) SetSuccess(i int32) *BatchMsgUpdateOne {
  623. bmuo.mutation.ResetSuccess()
  624. bmuo.mutation.SetSuccess(i)
  625. return bmuo
  626. }
  627. // SetNillableSuccess sets the "success" field if the given value is not nil.
  628. func (bmuo *BatchMsgUpdateOne) SetNillableSuccess(i *int32) *BatchMsgUpdateOne {
  629. if i != nil {
  630. bmuo.SetSuccess(*i)
  631. }
  632. return bmuo
  633. }
  634. // AddSuccess adds i to the "success" field.
  635. func (bmuo *BatchMsgUpdateOne) AddSuccess(i int32) *BatchMsgUpdateOne {
  636. bmuo.mutation.AddSuccess(i)
  637. return bmuo
  638. }
  639. // ClearSuccess clears the value of the "success" field.
  640. func (bmuo *BatchMsgUpdateOne) ClearSuccess() *BatchMsgUpdateOne {
  641. bmuo.mutation.ClearSuccess()
  642. return bmuo
  643. }
  644. // SetFail sets the "fail" field.
  645. func (bmuo *BatchMsgUpdateOne) SetFail(i int32) *BatchMsgUpdateOne {
  646. bmuo.mutation.ResetFail()
  647. bmuo.mutation.SetFail(i)
  648. return bmuo
  649. }
  650. // SetNillableFail sets the "fail" field if the given value is not nil.
  651. func (bmuo *BatchMsgUpdateOne) SetNillableFail(i *int32) *BatchMsgUpdateOne {
  652. if i != nil {
  653. bmuo.SetFail(*i)
  654. }
  655. return bmuo
  656. }
  657. // AddFail adds i to the "fail" field.
  658. func (bmuo *BatchMsgUpdateOne) AddFail(i int32) *BatchMsgUpdateOne {
  659. bmuo.mutation.AddFail(i)
  660. return bmuo
  661. }
  662. // ClearFail clears the value of the "fail" field.
  663. func (bmuo *BatchMsgUpdateOne) ClearFail() *BatchMsgUpdateOne {
  664. bmuo.mutation.ClearFail()
  665. return bmuo
  666. }
  667. // SetStartTime sets the "start_time" field.
  668. func (bmuo *BatchMsgUpdateOne) SetStartTime(t time.Time) *BatchMsgUpdateOne {
  669. bmuo.mutation.SetStartTime(t)
  670. return bmuo
  671. }
  672. // SetNillableStartTime sets the "start_time" field if the given value is not nil.
  673. func (bmuo *BatchMsgUpdateOne) SetNillableStartTime(t *time.Time) *BatchMsgUpdateOne {
  674. if t != nil {
  675. bmuo.SetStartTime(*t)
  676. }
  677. return bmuo
  678. }
  679. // ClearStartTime clears the value of the "start_time" field.
  680. func (bmuo *BatchMsgUpdateOne) ClearStartTime() *BatchMsgUpdateOne {
  681. bmuo.mutation.ClearStartTime()
  682. return bmuo
  683. }
  684. // SetStopTime sets the "stop_time" field.
  685. func (bmuo *BatchMsgUpdateOne) SetStopTime(t time.Time) *BatchMsgUpdateOne {
  686. bmuo.mutation.SetStopTime(t)
  687. return bmuo
  688. }
  689. // SetNillableStopTime sets the "stop_time" field if the given value is not nil.
  690. func (bmuo *BatchMsgUpdateOne) SetNillableStopTime(t *time.Time) *BatchMsgUpdateOne {
  691. if t != nil {
  692. bmuo.SetStopTime(*t)
  693. }
  694. return bmuo
  695. }
  696. // ClearStopTime clears the value of the "stop_time" field.
  697. func (bmuo *BatchMsgUpdateOne) ClearStopTime() *BatchMsgUpdateOne {
  698. bmuo.mutation.ClearStopTime()
  699. return bmuo
  700. }
  701. // SetSendTime sets the "send_time" field.
  702. func (bmuo *BatchMsgUpdateOne) SetSendTime(t time.Time) *BatchMsgUpdateOne {
  703. bmuo.mutation.SetSendTime(t)
  704. return bmuo
  705. }
  706. // SetNillableSendTime sets the "send_time" field if the given value is not nil.
  707. func (bmuo *BatchMsgUpdateOne) SetNillableSendTime(t *time.Time) *BatchMsgUpdateOne {
  708. if t != nil {
  709. bmuo.SetSendTime(*t)
  710. }
  711. return bmuo
  712. }
  713. // ClearSendTime clears the value of the "send_time" field.
  714. func (bmuo *BatchMsgUpdateOne) ClearSendTime() *BatchMsgUpdateOne {
  715. bmuo.mutation.ClearSendTime()
  716. return bmuo
  717. }
  718. // SetType sets the "type" field.
  719. func (bmuo *BatchMsgUpdateOne) SetType(i int32) *BatchMsgUpdateOne {
  720. bmuo.mutation.ResetType()
  721. bmuo.mutation.SetType(i)
  722. return bmuo
  723. }
  724. // SetNillableType sets the "type" field if the given value is not nil.
  725. func (bmuo *BatchMsgUpdateOne) SetNillableType(i *int32) *BatchMsgUpdateOne {
  726. if i != nil {
  727. bmuo.SetType(*i)
  728. }
  729. return bmuo
  730. }
  731. // AddType adds i to the "type" field.
  732. func (bmuo *BatchMsgUpdateOne) AddType(i int32) *BatchMsgUpdateOne {
  733. bmuo.mutation.AddType(i)
  734. return bmuo
  735. }
  736. // ClearType clears the value of the "type" field.
  737. func (bmuo *BatchMsgUpdateOne) ClearType() *BatchMsgUpdateOne {
  738. bmuo.mutation.ClearType()
  739. return bmuo
  740. }
  741. // Mutation returns the BatchMsgMutation object of the builder.
  742. func (bmuo *BatchMsgUpdateOne) Mutation() *BatchMsgMutation {
  743. return bmuo.mutation
  744. }
  745. // Where appends a list predicates to the BatchMsgUpdate builder.
  746. func (bmuo *BatchMsgUpdateOne) Where(ps ...predicate.BatchMsg) *BatchMsgUpdateOne {
  747. bmuo.mutation.Where(ps...)
  748. return bmuo
  749. }
  750. // Select allows selecting one or more fields (columns) of the returned entity.
  751. // The default is selecting all fields defined in the entity schema.
  752. func (bmuo *BatchMsgUpdateOne) Select(field string, fields ...string) *BatchMsgUpdateOne {
  753. bmuo.fields = append([]string{field}, fields...)
  754. return bmuo
  755. }
  756. // Save executes the query and returns the updated BatchMsg entity.
  757. func (bmuo *BatchMsgUpdateOne) Save(ctx context.Context) (*BatchMsg, error) {
  758. if err := bmuo.defaults(); err != nil {
  759. return nil, err
  760. }
  761. return withHooks(ctx, bmuo.sqlSave, bmuo.mutation, bmuo.hooks)
  762. }
  763. // SaveX is like Save, but panics if an error occurs.
  764. func (bmuo *BatchMsgUpdateOne) SaveX(ctx context.Context) *BatchMsg {
  765. node, err := bmuo.Save(ctx)
  766. if err != nil {
  767. panic(err)
  768. }
  769. return node
  770. }
  771. // Exec executes the query on the entity.
  772. func (bmuo *BatchMsgUpdateOne) Exec(ctx context.Context) error {
  773. _, err := bmuo.Save(ctx)
  774. return err
  775. }
  776. // ExecX is like Exec, but panics if an error occurs.
  777. func (bmuo *BatchMsgUpdateOne) ExecX(ctx context.Context) {
  778. if err := bmuo.Exec(ctx); err != nil {
  779. panic(err)
  780. }
  781. }
  782. // defaults sets the default values of the builder before save.
  783. func (bmuo *BatchMsgUpdateOne) defaults() error {
  784. if _, ok := bmuo.mutation.UpdatedAt(); !ok {
  785. if batchmsg.UpdateDefaultUpdatedAt == nil {
  786. return fmt.Errorf("ent: uninitialized batchmsg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  787. }
  788. v := batchmsg.UpdateDefaultUpdatedAt()
  789. bmuo.mutation.SetUpdatedAt(v)
  790. }
  791. return nil
  792. }
  793. func (bmuo *BatchMsgUpdateOne) sqlSave(ctx context.Context) (_node *BatchMsg, err error) {
  794. _spec := sqlgraph.NewUpdateSpec(batchmsg.Table, batchmsg.Columns, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
  795. id, ok := bmuo.mutation.ID()
  796. if !ok {
  797. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BatchMsg.id" for update`)}
  798. }
  799. _spec.Node.ID.Value = id
  800. if fields := bmuo.fields; len(fields) > 0 {
  801. _spec.Node.Columns = make([]string, 0, len(fields))
  802. _spec.Node.Columns = append(_spec.Node.Columns, batchmsg.FieldID)
  803. for _, f := range fields {
  804. if !batchmsg.ValidColumn(f) {
  805. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  806. }
  807. if f != batchmsg.FieldID {
  808. _spec.Node.Columns = append(_spec.Node.Columns, f)
  809. }
  810. }
  811. }
  812. if ps := bmuo.mutation.predicates; len(ps) > 0 {
  813. _spec.Predicate = func(selector *sql.Selector) {
  814. for i := range ps {
  815. ps[i](selector)
  816. }
  817. }
  818. }
  819. if value, ok := bmuo.mutation.UpdatedAt(); ok {
  820. _spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
  821. }
  822. if value, ok := bmuo.mutation.DeletedAt(); ok {
  823. _spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
  824. }
  825. if bmuo.mutation.DeletedAtCleared() {
  826. _spec.ClearField(batchmsg.FieldDeletedAt, field.TypeTime)
  827. }
  828. if value, ok := bmuo.mutation.Status(); ok {
  829. _spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
  830. }
  831. if value, ok := bmuo.mutation.AddedStatus(); ok {
  832. _spec.AddField(batchmsg.FieldStatus, field.TypeUint8, value)
  833. }
  834. if bmuo.mutation.StatusCleared() {
  835. _spec.ClearField(batchmsg.FieldStatus, field.TypeUint8)
  836. }
  837. if value, ok := bmuo.mutation.BatchNo(); ok {
  838. _spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
  839. }
  840. if bmuo.mutation.BatchNoCleared() {
  841. _spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
  842. }
  843. if value, ok := bmuo.mutation.TaskName(); ok {
  844. _spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
  845. }
  846. if bmuo.mutation.TaskNameCleared() {
  847. _spec.ClearField(batchmsg.FieldTaskName, field.TypeString)
  848. }
  849. if value, ok := bmuo.mutation.Fromwxid(); ok {
  850. _spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
  851. }
  852. if bmuo.mutation.FromwxidCleared() {
  853. _spec.ClearField(batchmsg.FieldFromwxid, field.TypeString)
  854. }
  855. if value, ok := bmuo.mutation.Msg(); ok {
  856. _spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
  857. }
  858. if bmuo.mutation.MsgCleared() {
  859. _spec.ClearField(batchmsg.FieldMsg, field.TypeString)
  860. }
  861. if value, ok := bmuo.mutation.Tag(); ok {
  862. _spec.SetField(batchmsg.FieldTag, field.TypeString, value)
  863. }
  864. if bmuo.mutation.TagCleared() {
  865. _spec.ClearField(batchmsg.FieldTag, field.TypeString)
  866. }
  867. if value, ok := bmuo.mutation.Total(); ok {
  868. _spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
  869. }
  870. if value, ok := bmuo.mutation.AddedTotal(); ok {
  871. _spec.AddField(batchmsg.FieldTotal, field.TypeInt32, value)
  872. }
  873. if bmuo.mutation.TotalCleared() {
  874. _spec.ClearField(batchmsg.FieldTotal, field.TypeInt32)
  875. }
  876. if value, ok := bmuo.mutation.Success(); ok {
  877. _spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
  878. }
  879. if value, ok := bmuo.mutation.AddedSuccess(); ok {
  880. _spec.AddField(batchmsg.FieldSuccess, field.TypeInt32, value)
  881. }
  882. if bmuo.mutation.SuccessCleared() {
  883. _spec.ClearField(batchmsg.FieldSuccess, field.TypeInt32)
  884. }
  885. if value, ok := bmuo.mutation.Fail(); ok {
  886. _spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
  887. }
  888. if value, ok := bmuo.mutation.AddedFail(); ok {
  889. _spec.AddField(batchmsg.FieldFail, field.TypeInt32, value)
  890. }
  891. if bmuo.mutation.FailCleared() {
  892. _spec.ClearField(batchmsg.FieldFail, field.TypeInt32)
  893. }
  894. if value, ok := bmuo.mutation.StartTime(); ok {
  895. _spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
  896. }
  897. if bmuo.mutation.StartTimeCleared() {
  898. _spec.ClearField(batchmsg.FieldStartTime, field.TypeTime)
  899. }
  900. if value, ok := bmuo.mutation.StopTime(); ok {
  901. _spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
  902. }
  903. if bmuo.mutation.StopTimeCleared() {
  904. _spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
  905. }
  906. if value, ok := bmuo.mutation.SendTime(); ok {
  907. _spec.SetField(batchmsg.FieldSendTime, field.TypeTime, value)
  908. }
  909. if bmuo.mutation.SendTimeCleared() {
  910. _spec.ClearField(batchmsg.FieldSendTime, field.TypeTime)
  911. }
  912. if value, ok := bmuo.mutation.GetType(); ok {
  913. _spec.SetField(batchmsg.FieldType, field.TypeInt32, value)
  914. }
  915. if value, ok := bmuo.mutation.AddedType(); ok {
  916. _spec.AddField(batchmsg.FieldType, field.TypeInt32, value)
  917. }
  918. if bmuo.mutation.TypeCleared() {
  919. _spec.ClearField(batchmsg.FieldType, field.TypeInt32)
  920. }
  921. _node = &BatchMsg{config: bmuo.config}
  922. _spec.Assign = _node.assignValues
  923. _spec.ScanValues = _node.scanValues
  924. if err = sqlgraph.UpdateNode(ctx, bmuo.driver, _spec); err != nil {
  925. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  926. err = &NotFoundError{batchmsg.Label}
  927. } else if sqlgraph.IsConstraintError(err) {
  928. err = &ConstraintError{msg: err.Error(), wrap: err}
  929. }
  930. return nil, err
  931. }
  932. bmuo.mutation.done = true
  933. return _node, nil
  934. }