batchmsg_update.go 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342
  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. // SetTagids sets the "tagids" field.
  156. func (bmu *BatchMsgUpdate) SetTagids(s string) *BatchMsgUpdate {
  157. bmu.mutation.SetTagids(s)
  158. return bmu
  159. }
  160. // SetNillableTagids sets the "tagids" field if the given value is not nil.
  161. func (bmu *BatchMsgUpdate) SetNillableTagids(s *string) *BatchMsgUpdate {
  162. if s != nil {
  163. bmu.SetTagids(*s)
  164. }
  165. return bmu
  166. }
  167. // ClearTagids clears the value of the "tagids" field.
  168. func (bmu *BatchMsgUpdate) ClearTagids() *BatchMsgUpdate {
  169. bmu.mutation.ClearTagids()
  170. return bmu
  171. }
  172. // SetTotal sets the "total" field.
  173. func (bmu *BatchMsgUpdate) SetTotal(i int32) *BatchMsgUpdate {
  174. bmu.mutation.ResetTotal()
  175. bmu.mutation.SetTotal(i)
  176. return bmu
  177. }
  178. // SetNillableTotal sets the "total" field if the given value is not nil.
  179. func (bmu *BatchMsgUpdate) SetNillableTotal(i *int32) *BatchMsgUpdate {
  180. if i != nil {
  181. bmu.SetTotal(*i)
  182. }
  183. return bmu
  184. }
  185. // AddTotal adds i to the "total" field.
  186. func (bmu *BatchMsgUpdate) AddTotal(i int32) *BatchMsgUpdate {
  187. bmu.mutation.AddTotal(i)
  188. return bmu
  189. }
  190. // ClearTotal clears the value of the "total" field.
  191. func (bmu *BatchMsgUpdate) ClearTotal() *BatchMsgUpdate {
  192. bmu.mutation.ClearTotal()
  193. return bmu
  194. }
  195. // SetSuccess sets the "success" field.
  196. func (bmu *BatchMsgUpdate) SetSuccess(i int32) *BatchMsgUpdate {
  197. bmu.mutation.ResetSuccess()
  198. bmu.mutation.SetSuccess(i)
  199. return bmu
  200. }
  201. // SetNillableSuccess sets the "success" field if the given value is not nil.
  202. func (bmu *BatchMsgUpdate) SetNillableSuccess(i *int32) *BatchMsgUpdate {
  203. if i != nil {
  204. bmu.SetSuccess(*i)
  205. }
  206. return bmu
  207. }
  208. // AddSuccess adds i to the "success" field.
  209. func (bmu *BatchMsgUpdate) AddSuccess(i int32) *BatchMsgUpdate {
  210. bmu.mutation.AddSuccess(i)
  211. return bmu
  212. }
  213. // ClearSuccess clears the value of the "success" field.
  214. func (bmu *BatchMsgUpdate) ClearSuccess() *BatchMsgUpdate {
  215. bmu.mutation.ClearSuccess()
  216. return bmu
  217. }
  218. // SetFail sets the "fail" field.
  219. func (bmu *BatchMsgUpdate) SetFail(i int32) *BatchMsgUpdate {
  220. bmu.mutation.ResetFail()
  221. bmu.mutation.SetFail(i)
  222. return bmu
  223. }
  224. // SetNillableFail sets the "fail" field if the given value is not nil.
  225. func (bmu *BatchMsgUpdate) SetNillableFail(i *int32) *BatchMsgUpdate {
  226. if i != nil {
  227. bmu.SetFail(*i)
  228. }
  229. return bmu
  230. }
  231. // AddFail adds i to the "fail" field.
  232. func (bmu *BatchMsgUpdate) AddFail(i int32) *BatchMsgUpdate {
  233. bmu.mutation.AddFail(i)
  234. return bmu
  235. }
  236. // ClearFail clears the value of the "fail" field.
  237. func (bmu *BatchMsgUpdate) ClearFail() *BatchMsgUpdate {
  238. bmu.mutation.ClearFail()
  239. return bmu
  240. }
  241. // SetStartTime sets the "start_time" field.
  242. func (bmu *BatchMsgUpdate) SetStartTime(t time.Time) *BatchMsgUpdate {
  243. bmu.mutation.SetStartTime(t)
  244. return bmu
  245. }
  246. // SetNillableStartTime sets the "start_time" field if the given value is not nil.
  247. func (bmu *BatchMsgUpdate) SetNillableStartTime(t *time.Time) *BatchMsgUpdate {
  248. if t != nil {
  249. bmu.SetStartTime(*t)
  250. }
  251. return bmu
  252. }
  253. // ClearStartTime clears the value of the "start_time" field.
  254. func (bmu *BatchMsgUpdate) ClearStartTime() *BatchMsgUpdate {
  255. bmu.mutation.ClearStartTime()
  256. return bmu
  257. }
  258. // SetStopTime sets the "stop_time" field.
  259. func (bmu *BatchMsgUpdate) SetStopTime(t time.Time) *BatchMsgUpdate {
  260. bmu.mutation.SetStopTime(t)
  261. return bmu
  262. }
  263. // SetNillableStopTime sets the "stop_time" field if the given value is not nil.
  264. func (bmu *BatchMsgUpdate) SetNillableStopTime(t *time.Time) *BatchMsgUpdate {
  265. if t != nil {
  266. bmu.SetStopTime(*t)
  267. }
  268. return bmu
  269. }
  270. // ClearStopTime clears the value of the "stop_time" field.
  271. func (bmu *BatchMsgUpdate) ClearStopTime() *BatchMsgUpdate {
  272. bmu.mutation.ClearStopTime()
  273. return bmu
  274. }
  275. // SetSendTime sets the "send_time" field.
  276. func (bmu *BatchMsgUpdate) SetSendTime(t time.Time) *BatchMsgUpdate {
  277. bmu.mutation.SetSendTime(t)
  278. return bmu
  279. }
  280. // SetNillableSendTime sets the "send_time" field if the given value is not nil.
  281. func (bmu *BatchMsgUpdate) SetNillableSendTime(t *time.Time) *BatchMsgUpdate {
  282. if t != nil {
  283. bmu.SetSendTime(*t)
  284. }
  285. return bmu
  286. }
  287. // ClearSendTime clears the value of the "send_time" field.
  288. func (bmu *BatchMsgUpdate) ClearSendTime() *BatchMsgUpdate {
  289. bmu.mutation.ClearSendTime()
  290. return bmu
  291. }
  292. // SetType sets the "type" field.
  293. func (bmu *BatchMsgUpdate) SetType(i int32) *BatchMsgUpdate {
  294. bmu.mutation.ResetType()
  295. bmu.mutation.SetType(i)
  296. return bmu
  297. }
  298. // SetNillableType sets the "type" field if the given value is not nil.
  299. func (bmu *BatchMsgUpdate) SetNillableType(i *int32) *BatchMsgUpdate {
  300. if i != nil {
  301. bmu.SetType(*i)
  302. }
  303. return bmu
  304. }
  305. // AddType adds i to the "type" field.
  306. func (bmu *BatchMsgUpdate) AddType(i int32) *BatchMsgUpdate {
  307. bmu.mutation.AddType(i)
  308. return bmu
  309. }
  310. // ClearType clears the value of the "type" field.
  311. func (bmu *BatchMsgUpdate) ClearType() *BatchMsgUpdate {
  312. bmu.mutation.ClearType()
  313. return bmu
  314. }
  315. // SetOrganizationID sets the "organization_id" field.
  316. func (bmu *BatchMsgUpdate) SetOrganizationID(u uint64) *BatchMsgUpdate {
  317. bmu.mutation.ResetOrganizationID()
  318. bmu.mutation.SetOrganizationID(u)
  319. return bmu
  320. }
  321. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  322. func (bmu *BatchMsgUpdate) SetNillableOrganizationID(u *uint64) *BatchMsgUpdate {
  323. if u != nil {
  324. bmu.SetOrganizationID(*u)
  325. }
  326. return bmu
  327. }
  328. // AddOrganizationID adds u to the "organization_id" field.
  329. func (bmu *BatchMsgUpdate) AddOrganizationID(u int64) *BatchMsgUpdate {
  330. bmu.mutation.AddOrganizationID(u)
  331. return bmu
  332. }
  333. // SetCtype sets the "ctype" field.
  334. func (bmu *BatchMsgUpdate) SetCtype(u uint64) *BatchMsgUpdate {
  335. bmu.mutation.ResetCtype()
  336. bmu.mutation.SetCtype(u)
  337. return bmu
  338. }
  339. // SetNillableCtype sets the "ctype" field if the given value is not nil.
  340. func (bmu *BatchMsgUpdate) SetNillableCtype(u *uint64) *BatchMsgUpdate {
  341. if u != nil {
  342. bmu.SetCtype(*u)
  343. }
  344. return bmu
  345. }
  346. // AddCtype adds u to the "ctype" field.
  347. func (bmu *BatchMsgUpdate) AddCtype(u int64) *BatchMsgUpdate {
  348. bmu.mutation.AddCtype(u)
  349. return bmu
  350. }
  351. // SetCc sets the "cc" field.
  352. func (bmu *BatchMsgUpdate) SetCc(s string) *BatchMsgUpdate {
  353. bmu.mutation.SetCc(s)
  354. return bmu
  355. }
  356. // SetNillableCc sets the "cc" field if the given value is not nil.
  357. func (bmu *BatchMsgUpdate) SetNillableCc(s *string) *BatchMsgUpdate {
  358. if s != nil {
  359. bmu.SetCc(*s)
  360. }
  361. return bmu
  362. }
  363. // ClearCc clears the value of the "cc" field.
  364. func (bmu *BatchMsgUpdate) ClearCc() *BatchMsgUpdate {
  365. bmu.mutation.ClearCc()
  366. return bmu
  367. }
  368. // SetPhone sets the "phone" field.
  369. func (bmu *BatchMsgUpdate) SetPhone(s string) *BatchMsgUpdate {
  370. bmu.mutation.SetPhone(s)
  371. return bmu
  372. }
  373. // SetNillablePhone sets the "phone" field if the given value is not nil.
  374. func (bmu *BatchMsgUpdate) SetNillablePhone(s *string) *BatchMsgUpdate {
  375. if s != nil {
  376. bmu.SetPhone(*s)
  377. }
  378. return bmu
  379. }
  380. // ClearPhone clears the value of the "phone" field.
  381. func (bmu *BatchMsgUpdate) ClearPhone() *BatchMsgUpdate {
  382. bmu.mutation.ClearPhone()
  383. return bmu
  384. }
  385. // Mutation returns the BatchMsgMutation object of the builder.
  386. func (bmu *BatchMsgUpdate) Mutation() *BatchMsgMutation {
  387. return bmu.mutation
  388. }
  389. // Save executes the query and returns the number of nodes affected by the update operation.
  390. func (bmu *BatchMsgUpdate) Save(ctx context.Context) (int, error) {
  391. if err := bmu.defaults(); err != nil {
  392. return 0, err
  393. }
  394. return withHooks(ctx, bmu.sqlSave, bmu.mutation, bmu.hooks)
  395. }
  396. // SaveX is like Save, but panics if an error occurs.
  397. func (bmu *BatchMsgUpdate) SaveX(ctx context.Context) int {
  398. affected, err := bmu.Save(ctx)
  399. if err != nil {
  400. panic(err)
  401. }
  402. return affected
  403. }
  404. // Exec executes the query.
  405. func (bmu *BatchMsgUpdate) Exec(ctx context.Context) error {
  406. _, err := bmu.Save(ctx)
  407. return err
  408. }
  409. // ExecX is like Exec, but panics if an error occurs.
  410. func (bmu *BatchMsgUpdate) ExecX(ctx context.Context) {
  411. if err := bmu.Exec(ctx); err != nil {
  412. panic(err)
  413. }
  414. }
  415. // defaults sets the default values of the builder before save.
  416. func (bmu *BatchMsgUpdate) defaults() error {
  417. if _, ok := bmu.mutation.UpdatedAt(); !ok {
  418. if batchmsg.UpdateDefaultUpdatedAt == nil {
  419. return fmt.Errorf("ent: uninitialized batchmsg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  420. }
  421. v := batchmsg.UpdateDefaultUpdatedAt()
  422. bmu.mutation.SetUpdatedAt(v)
  423. }
  424. return nil
  425. }
  426. // check runs all checks and user-defined validators on the builder.
  427. func (bmu *BatchMsgUpdate) check() error {
  428. if v, ok := bmu.mutation.OrganizationID(); ok {
  429. if err := batchmsg.OrganizationIDValidator(v); err != nil {
  430. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "BatchMsg.organization_id": %w`, err)}
  431. }
  432. }
  433. return nil
  434. }
  435. func (bmu *BatchMsgUpdate) sqlSave(ctx context.Context) (n int, err error) {
  436. if err := bmu.check(); err != nil {
  437. return n, err
  438. }
  439. _spec := sqlgraph.NewUpdateSpec(batchmsg.Table, batchmsg.Columns, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
  440. if ps := bmu.mutation.predicates; len(ps) > 0 {
  441. _spec.Predicate = func(selector *sql.Selector) {
  442. for i := range ps {
  443. ps[i](selector)
  444. }
  445. }
  446. }
  447. if value, ok := bmu.mutation.UpdatedAt(); ok {
  448. _spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
  449. }
  450. if value, ok := bmu.mutation.DeletedAt(); ok {
  451. _spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
  452. }
  453. if bmu.mutation.DeletedAtCleared() {
  454. _spec.ClearField(batchmsg.FieldDeletedAt, field.TypeTime)
  455. }
  456. if value, ok := bmu.mutation.Status(); ok {
  457. _spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
  458. }
  459. if value, ok := bmu.mutation.AddedStatus(); ok {
  460. _spec.AddField(batchmsg.FieldStatus, field.TypeUint8, value)
  461. }
  462. if bmu.mutation.StatusCleared() {
  463. _spec.ClearField(batchmsg.FieldStatus, field.TypeUint8)
  464. }
  465. if value, ok := bmu.mutation.BatchNo(); ok {
  466. _spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
  467. }
  468. if bmu.mutation.BatchNoCleared() {
  469. _spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
  470. }
  471. if value, ok := bmu.mutation.TaskName(); ok {
  472. _spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
  473. }
  474. if bmu.mutation.TaskNameCleared() {
  475. _spec.ClearField(batchmsg.FieldTaskName, field.TypeString)
  476. }
  477. if value, ok := bmu.mutation.Fromwxid(); ok {
  478. _spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
  479. }
  480. if bmu.mutation.FromwxidCleared() {
  481. _spec.ClearField(batchmsg.FieldFromwxid, field.TypeString)
  482. }
  483. if value, ok := bmu.mutation.Msg(); ok {
  484. _spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
  485. }
  486. if bmu.mutation.MsgCleared() {
  487. _spec.ClearField(batchmsg.FieldMsg, field.TypeString)
  488. }
  489. if value, ok := bmu.mutation.Tag(); ok {
  490. _spec.SetField(batchmsg.FieldTag, field.TypeString, value)
  491. }
  492. if bmu.mutation.TagCleared() {
  493. _spec.ClearField(batchmsg.FieldTag, field.TypeString)
  494. }
  495. if value, ok := bmu.mutation.Tagids(); ok {
  496. _spec.SetField(batchmsg.FieldTagids, field.TypeString, value)
  497. }
  498. if bmu.mutation.TagidsCleared() {
  499. _spec.ClearField(batchmsg.FieldTagids, field.TypeString)
  500. }
  501. if value, ok := bmu.mutation.Total(); ok {
  502. _spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
  503. }
  504. if value, ok := bmu.mutation.AddedTotal(); ok {
  505. _spec.AddField(batchmsg.FieldTotal, field.TypeInt32, value)
  506. }
  507. if bmu.mutation.TotalCleared() {
  508. _spec.ClearField(batchmsg.FieldTotal, field.TypeInt32)
  509. }
  510. if value, ok := bmu.mutation.Success(); ok {
  511. _spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
  512. }
  513. if value, ok := bmu.mutation.AddedSuccess(); ok {
  514. _spec.AddField(batchmsg.FieldSuccess, field.TypeInt32, value)
  515. }
  516. if bmu.mutation.SuccessCleared() {
  517. _spec.ClearField(batchmsg.FieldSuccess, field.TypeInt32)
  518. }
  519. if value, ok := bmu.mutation.Fail(); ok {
  520. _spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
  521. }
  522. if value, ok := bmu.mutation.AddedFail(); ok {
  523. _spec.AddField(batchmsg.FieldFail, field.TypeInt32, value)
  524. }
  525. if bmu.mutation.FailCleared() {
  526. _spec.ClearField(batchmsg.FieldFail, field.TypeInt32)
  527. }
  528. if value, ok := bmu.mutation.StartTime(); ok {
  529. _spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
  530. }
  531. if bmu.mutation.StartTimeCleared() {
  532. _spec.ClearField(batchmsg.FieldStartTime, field.TypeTime)
  533. }
  534. if value, ok := bmu.mutation.StopTime(); ok {
  535. _spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
  536. }
  537. if bmu.mutation.StopTimeCleared() {
  538. _spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
  539. }
  540. if value, ok := bmu.mutation.SendTime(); ok {
  541. _spec.SetField(batchmsg.FieldSendTime, field.TypeTime, value)
  542. }
  543. if bmu.mutation.SendTimeCleared() {
  544. _spec.ClearField(batchmsg.FieldSendTime, field.TypeTime)
  545. }
  546. if value, ok := bmu.mutation.GetType(); ok {
  547. _spec.SetField(batchmsg.FieldType, field.TypeInt32, value)
  548. }
  549. if value, ok := bmu.mutation.AddedType(); ok {
  550. _spec.AddField(batchmsg.FieldType, field.TypeInt32, value)
  551. }
  552. if bmu.mutation.TypeCleared() {
  553. _spec.ClearField(batchmsg.FieldType, field.TypeInt32)
  554. }
  555. if value, ok := bmu.mutation.OrganizationID(); ok {
  556. _spec.SetField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
  557. }
  558. if value, ok := bmu.mutation.AddedOrganizationID(); ok {
  559. _spec.AddField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
  560. }
  561. if value, ok := bmu.mutation.Ctype(); ok {
  562. _spec.SetField(batchmsg.FieldCtype, field.TypeUint64, value)
  563. }
  564. if value, ok := bmu.mutation.AddedCtype(); ok {
  565. _spec.AddField(batchmsg.FieldCtype, field.TypeUint64, value)
  566. }
  567. if value, ok := bmu.mutation.Cc(); ok {
  568. _spec.SetField(batchmsg.FieldCc, field.TypeString, value)
  569. }
  570. if bmu.mutation.CcCleared() {
  571. _spec.ClearField(batchmsg.FieldCc, field.TypeString)
  572. }
  573. if value, ok := bmu.mutation.Phone(); ok {
  574. _spec.SetField(batchmsg.FieldPhone, field.TypeString, value)
  575. }
  576. if bmu.mutation.PhoneCleared() {
  577. _spec.ClearField(batchmsg.FieldPhone, field.TypeString)
  578. }
  579. if n, err = sqlgraph.UpdateNodes(ctx, bmu.driver, _spec); err != nil {
  580. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  581. err = &NotFoundError{batchmsg.Label}
  582. } else if sqlgraph.IsConstraintError(err) {
  583. err = &ConstraintError{msg: err.Error(), wrap: err}
  584. }
  585. return 0, err
  586. }
  587. bmu.mutation.done = true
  588. return n, nil
  589. }
  590. // BatchMsgUpdateOne is the builder for updating a single BatchMsg entity.
  591. type BatchMsgUpdateOne struct {
  592. config
  593. fields []string
  594. hooks []Hook
  595. mutation *BatchMsgMutation
  596. }
  597. // SetUpdatedAt sets the "updated_at" field.
  598. func (bmuo *BatchMsgUpdateOne) SetUpdatedAt(t time.Time) *BatchMsgUpdateOne {
  599. bmuo.mutation.SetUpdatedAt(t)
  600. return bmuo
  601. }
  602. // SetDeletedAt sets the "deleted_at" field.
  603. func (bmuo *BatchMsgUpdateOne) SetDeletedAt(t time.Time) *BatchMsgUpdateOne {
  604. bmuo.mutation.SetDeletedAt(t)
  605. return bmuo
  606. }
  607. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  608. func (bmuo *BatchMsgUpdateOne) SetNillableDeletedAt(t *time.Time) *BatchMsgUpdateOne {
  609. if t != nil {
  610. bmuo.SetDeletedAt(*t)
  611. }
  612. return bmuo
  613. }
  614. // ClearDeletedAt clears the value of the "deleted_at" field.
  615. func (bmuo *BatchMsgUpdateOne) ClearDeletedAt() *BatchMsgUpdateOne {
  616. bmuo.mutation.ClearDeletedAt()
  617. return bmuo
  618. }
  619. // SetStatus sets the "status" field.
  620. func (bmuo *BatchMsgUpdateOne) SetStatus(u uint8) *BatchMsgUpdateOne {
  621. bmuo.mutation.ResetStatus()
  622. bmuo.mutation.SetStatus(u)
  623. return bmuo
  624. }
  625. // SetNillableStatus sets the "status" field if the given value is not nil.
  626. func (bmuo *BatchMsgUpdateOne) SetNillableStatus(u *uint8) *BatchMsgUpdateOne {
  627. if u != nil {
  628. bmuo.SetStatus(*u)
  629. }
  630. return bmuo
  631. }
  632. // AddStatus adds u to the "status" field.
  633. func (bmuo *BatchMsgUpdateOne) AddStatus(u int8) *BatchMsgUpdateOne {
  634. bmuo.mutation.AddStatus(u)
  635. return bmuo
  636. }
  637. // ClearStatus clears the value of the "status" field.
  638. func (bmuo *BatchMsgUpdateOne) ClearStatus() *BatchMsgUpdateOne {
  639. bmuo.mutation.ClearStatus()
  640. return bmuo
  641. }
  642. // SetBatchNo sets the "batch_no" field.
  643. func (bmuo *BatchMsgUpdateOne) SetBatchNo(s string) *BatchMsgUpdateOne {
  644. bmuo.mutation.SetBatchNo(s)
  645. return bmuo
  646. }
  647. // SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
  648. func (bmuo *BatchMsgUpdateOne) SetNillableBatchNo(s *string) *BatchMsgUpdateOne {
  649. if s != nil {
  650. bmuo.SetBatchNo(*s)
  651. }
  652. return bmuo
  653. }
  654. // ClearBatchNo clears the value of the "batch_no" field.
  655. func (bmuo *BatchMsgUpdateOne) ClearBatchNo() *BatchMsgUpdateOne {
  656. bmuo.mutation.ClearBatchNo()
  657. return bmuo
  658. }
  659. // SetTaskName sets the "task_name" field.
  660. func (bmuo *BatchMsgUpdateOne) SetTaskName(s string) *BatchMsgUpdateOne {
  661. bmuo.mutation.SetTaskName(s)
  662. return bmuo
  663. }
  664. // SetNillableTaskName sets the "task_name" field if the given value is not nil.
  665. func (bmuo *BatchMsgUpdateOne) SetNillableTaskName(s *string) *BatchMsgUpdateOne {
  666. if s != nil {
  667. bmuo.SetTaskName(*s)
  668. }
  669. return bmuo
  670. }
  671. // ClearTaskName clears the value of the "task_name" field.
  672. func (bmuo *BatchMsgUpdateOne) ClearTaskName() *BatchMsgUpdateOne {
  673. bmuo.mutation.ClearTaskName()
  674. return bmuo
  675. }
  676. // SetFromwxid sets the "fromwxid" field.
  677. func (bmuo *BatchMsgUpdateOne) SetFromwxid(s string) *BatchMsgUpdateOne {
  678. bmuo.mutation.SetFromwxid(s)
  679. return bmuo
  680. }
  681. // SetNillableFromwxid sets the "fromwxid" field if the given value is not nil.
  682. func (bmuo *BatchMsgUpdateOne) SetNillableFromwxid(s *string) *BatchMsgUpdateOne {
  683. if s != nil {
  684. bmuo.SetFromwxid(*s)
  685. }
  686. return bmuo
  687. }
  688. // ClearFromwxid clears the value of the "fromwxid" field.
  689. func (bmuo *BatchMsgUpdateOne) ClearFromwxid() *BatchMsgUpdateOne {
  690. bmuo.mutation.ClearFromwxid()
  691. return bmuo
  692. }
  693. // SetMsg sets the "msg" field.
  694. func (bmuo *BatchMsgUpdateOne) SetMsg(s string) *BatchMsgUpdateOne {
  695. bmuo.mutation.SetMsg(s)
  696. return bmuo
  697. }
  698. // SetNillableMsg sets the "msg" field if the given value is not nil.
  699. func (bmuo *BatchMsgUpdateOne) SetNillableMsg(s *string) *BatchMsgUpdateOne {
  700. if s != nil {
  701. bmuo.SetMsg(*s)
  702. }
  703. return bmuo
  704. }
  705. // ClearMsg clears the value of the "msg" field.
  706. func (bmuo *BatchMsgUpdateOne) ClearMsg() *BatchMsgUpdateOne {
  707. bmuo.mutation.ClearMsg()
  708. return bmuo
  709. }
  710. // SetTag sets the "tag" field.
  711. func (bmuo *BatchMsgUpdateOne) SetTag(s string) *BatchMsgUpdateOne {
  712. bmuo.mutation.SetTag(s)
  713. return bmuo
  714. }
  715. // SetNillableTag sets the "tag" field if the given value is not nil.
  716. func (bmuo *BatchMsgUpdateOne) SetNillableTag(s *string) *BatchMsgUpdateOne {
  717. if s != nil {
  718. bmuo.SetTag(*s)
  719. }
  720. return bmuo
  721. }
  722. // ClearTag clears the value of the "tag" field.
  723. func (bmuo *BatchMsgUpdateOne) ClearTag() *BatchMsgUpdateOne {
  724. bmuo.mutation.ClearTag()
  725. return bmuo
  726. }
  727. // SetTagids sets the "tagids" field.
  728. func (bmuo *BatchMsgUpdateOne) SetTagids(s string) *BatchMsgUpdateOne {
  729. bmuo.mutation.SetTagids(s)
  730. return bmuo
  731. }
  732. // SetNillableTagids sets the "tagids" field if the given value is not nil.
  733. func (bmuo *BatchMsgUpdateOne) SetNillableTagids(s *string) *BatchMsgUpdateOne {
  734. if s != nil {
  735. bmuo.SetTagids(*s)
  736. }
  737. return bmuo
  738. }
  739. // ClearTagids clears the value of the "tagids" field.
  740. func (bmuo *BatchMsgUpdateOne) ClearTagids() *BatchMsgUpdateOne {
  741. bmuo.mutation.ClearTagids()
  742. return bmuo
  743. }
  744. // SetTotal sets the "total" field.
  745. func (bmuo *BatchMsgUpdateOne) SetTotal(i int32) *BatchMsgUpdateOne {
  746. bmuo.mutation.ResetTotal()
  747. bmuo.mutation.SetTotal(i)
  748. return bmuo
  749. }
  750. // SetNillableTotal sets the "total" field if the given value is not nil.
  751. func (bmuo *BatchMsgUpdateOne) SetNillableTotal(i *int32) *BatchMsgUpdateOne {
  752. if i != nil {
  753. bmuo.SetTotal(*i)
  754. }
  755. return bmuo
  756. }
  757. // AddTotal adds i to the "total" field.
  758. func (bmuo *BatchMsgUpdateOne) AddTotal(i int32) *BatchMsgUpdateOne {
  759. bmuo.mutation.AddTotal(i)
  760. return bmuo
  761. }
  762. // ClearTotal clears the value of the "total" field.
  763. func (bmuo *BatchMsgUpdateOne) ClearTotal() *BatchMsgUpdateOne {
  764. bmuo.mutation.ClearTotal()
  765. return bmuo
  766. }
  767. // SetSuccess sets the "success" field.
  768. func (bmuo *BatchMsgUpdateOne) SetSuccess(i int32) *BatchMsgUpdateOne {
  769. bmuo.mutation.ResetSuccess()
  770. bmuo.mutation.SetSuccess(i)
  771. return bmuo
  772. }
  773. // SetNillableSuccess sets the "success" field if the given value is not nil.
  774. func (bmuo *BatchMsgUpdateOne) SetNillableSuccess(i *int32) *BatchMsgUpdateOne {
  775. if i != nil {
  776. bmuo.SetSuccess(*i)
  777. }
  778. return bmuo
  779. }
  780. // AddSuccess adds i to the "success" field.
  781. func (bmuo *BatchMsgUpdateOne) AddSuccess(i int32) *BatchMsgUpdateOne {
  782. bmuo.mutation.AddSuccess(i)
  783. return bmuo
  784. }
  785. // ClearSuccess clears the value of the "success" field.
  786. func (bmuo *BatchMsgUpdateOne) ClearSuccess() *BatchMsgUpdateOne {
  787. bmuo.mutation.ClearSuccess()
  788. return bmuo
  789. }
  790. // SetFail sets the "fail" field.
  791. func (bmuo *BatchMsgUpdateOne) SetFail(i int32) *BatchMsgUpdateOne {
  792. bmuo.mutation.ResetFail()
  793. bmuo.mutation.SetFail(i)
  794. return bmuo
  795. }
  796. // SetNillableFail sets the "fail" field if the given value is not nil.
  797. func (bmuo *BatchMsgUpdateOne) SetNillableFail(i *int32) *BatchMsgUpdateOne {
  798. if i != nil {
  799. bmuo.SetFail(*i)
  800. }
  801. return bmuo
  802. }
  803. // AddFail adds i to the "fail" field.
  804. func (bmuo *BatchMsgUpdateOne) AddFail(i int32) *BatchMsgUpdateOne {
  805. bmuo.mutation.AddFail(i)
  806. return bmuo
  807. }
  808. // ClearFail clears the value of the "fail" field.
  809. func (bmuo *BatchMsgUpdateOne) ClearFail() *BatchMsgUpdateOne {
  810. bmuo.mutation.ClearFail()
  811. return bmuo
  812. }
  813. // SetStartTime sets the "start_time" field.
  814. func (bmuo *BatchMsgUpdateOne) SetStartTime(t time.Time) *BatchMsgUpdateOne {
  815. bmuo.mutation.SetStartTime(t)
  816. return bmuo
  817. }
  818. // SetNillableStartTime sets the "start_time" field if the given value is not nil.
  819. func (bmuo *BatchMsgUpdateOne) SetNillableStartTime(t *time.Time) *BatchMsgUpdateOne {
  820. if t != nil {
  821. bmuo.SetStartTime(*t)
  822. }
  823. return bmuo
  824. }
  825. // ClearStartTime clears the value of the "start_time" field.
  826. func (bmuo *BatchMsgUpdateOne) ClearStartTime() *BatchMsgUpdateOne {
  827. bmuo.mutation.ClearStartTime()
  828. return bmuo
  829. }
  830. // SetStopTime sets the "stop_time" field.
  831. func (bmuo *BatchMsgUpdateOne) SetStopTime(t time.Time) *BatchMsgUpdateOne {
  832. bmuo.mutation.SetStopTime(t)
  833. return bmuo
  834. }
  835. // SetNillableStopTime sets the "stop_time" field if the given value is not nil.
  836. func (bmuo *BatchMsgUpdateOne) SetNillableStopTime(t *time.Time) *BatchMsgUpdateOne {
  837. if t != nil {
  838. bmuo.SetStopTime(*t)
  839. }
  840. return bmuo
  841. }
  842. // ClearStopTime clears the value of the "stop_time" field.
  843. func (bmuo *BatchMsgUpdateOne) ClearStopTime() *BatchMsgUpdateOne {
  844. bmuo.mutation.ClearStopTime()
  845. return bmuo
  846. }
  847. // SetSendTime sets the "send_time" field.
  848. func (bmuo *BatchMsgUpdateOne) SetSendTime(t time.Time) *BatchMsgUpdateOne {
  849. bmuo.mutation.SetSendTime(t)
  850. return bmuo
  851. }
  852. // SetNillableSendTime sets the "send_time" field if the given value is not nil.
  853. func (bmuo *BatchMsgUpdateOne) SetNillableSendTime(t *time.Time) *BatchMsgUpdateOne {
  854. if t != nil {
  855. bmuo.SetSendTime(*t)
  856. }
  857. return bmuo
  858. }
  859. // ClearSendTime clears the value of the "send_time" field.
  860. func (bmuo *BatchMsgUpdateOne) ClearSendTime() *BatchMsgUpdateOne {
  861. bmuo.mutation.ClearSendTime()
  862. return bmuo
  863. }
  864. // SetType sets the "type" field.
  865. func (bmuo *BatchMsgUpdateOne) SetType(i int32) *BatchMsgUpdateOne {
  866. bmuo.mutation.ResetType()
  867. bmuo.mutation.SetType(i)
  868. return bmuo
  869. }
  870. // SetNillableType sets the "type" field if the given value is not nil.
  871. func (bmuo *BatchMsgUpdateOne) SetNillableType(i *int32) *BatchMsgUpdateOne {
  872. if i != nil {
  873. bmuo.SetType(*i)
  874. }
  875. return bmuo
  876. }
  877. // AddType adds i to the "type" field.
  878. func (bmuo *BatchMsgUpdateOne) AddType(i int32) *BatchMsgUpdateOne {
  879. bmuo.mutation.AddType(i)
  880. return bmuo
  881. }
  882. // ClearType clears the value of the "type" field.
  883. func (bmuo *BatchMsgUpdateOne) ClearType() *BatchMsgUpdateOne {
  884. bmuo.mutation.ClearType()
  885. return bmuo
  886. }
  887. // SetOrganizationID sets the "organization_id" field.
  888. func (bmuo *BatchMsgUpdateOne) SetOrganizationID(u uint64) *BatchMsgUpdateOne {
  889. bmuo.mutation.ResetOrganizationID()
  890. bmuo.mutation.SetOrganizationID(u)
  891. return bmuo
  892. }
  893. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  894. func (bmuo *BatchMsgUpdateOne) SetNillableOrganizationID(u *uint64) *BatchMsgUpdateOne {
  895. if u != nil {
  896. bmuo.SetOrganizationID(*u)
  897. }
  898. return bmuo
  899. }
  900. // AddOrganizationID adds u to the "organization_id" field.
  901. func (bmuo *BatchMsgUpdateOne) AddOrganizationID(u int64) *BatchMsgUpdateOne {
  902. bmuo.mutation.AddOrganizationID(u)
  903. return bmuo
  904. }
  905. // SetCtype sets the "ctype" field.
  906. func (bmuo *BatchMsgUpdateOne) SetCtype(u uint64) *BatchMsgUpdateOne {
  907. bmuo.mutation.ResetCtype()
  908. bmuo.mutation.SetCtype(u)
  909. return bmuo
  910. }
  911. // SetNillableCtype sets the "ctype" field if the given value is not nil.
  912. func (bmuo *BatchMsgUpdateOne) SetNillableCtype(u *uint64) *BatchMsgUpdateOne {
  913. if u != nil {
  914. bmuo.SetCtype(*u)
  915. }
  916. return bmuo
  917. }
  918. // AddCtype adds u to the "ctype" field.
  919. func (bmuo *BatchMsgUpdateOne) AddCtype(u int64) *BatchMsgUpdateOne {
  920. bmuo.mutation.AddCtype(u)
  921. return bmuo
  922. }
  923. // SetCc sets the "cc" field.
  924. func (bmuo *BatchMsgUpdateOne) SetCc(s string) *BatchMsgUpdateOne {
  925. bmuo.mutation.SetCc(s)
  926. return bmuo
  927. }
  928. // SetNillableCc sets the "cc" field if the given value is not nil.
  929. func (bmuo *BatchMsgUpdateOne) SetNillableCc(s *string) *BatchMsgUpdateOne {
  930. if s != nil {
  931. bmuo.SetCc(*s)
  932. }
  933. return bmuo
  934. }
  935. // ClearCc clears the value of the "cc" field.
  936. func (bmuo *BatchMsgUpdateOne) ClearCc() *BatchMsgUpdateOne {
  937. bmuo.mutation.ClearCc()
  938. return bmuo
  939. }
  940. // SetPhone sets the "phone" field.
  941. func (bmuo *BatchMsgUpdateOne) SetPhone(s string) *BatchMsgUpdateOne {
  942. bmuo.mutation.SetPhone(s)
  943. return bmuo
  944. }
  945. // SetNillablePhone sets the "phone" field if the given value is not nil.
  946. func (bmuo *BatchMsgUpdateOne) SetNillablePhone(s *string) *BatchMsgUpdateOne {
  947. if s != nil {
  948. bmuo.SetPhone(*s)
  949. }
  950. return bmuo
  951. }
  952. // ClearPhone clears the value of the "phone" field.
  953. func (bmuo *BatchMsgUpdateOne) ClearPhone() *BatchMsgUpdateOne {
  954. bmuo.mutation.ClearPhone()
  955. return bmuo
  956. }
  957. // Mutation returns the BatchMsgMutation object of the builder.
  958. func (bmuo *BatchMsgUpdateOne) Mutation() *BatchMsgMutation {
  959. return bmuo.mutation
  960. }
  961. // Where appends a list predicates to the BatchMsgUpdate builder.
  962. func (bmuo *BatchMsgUpdateOne) Where(ps ...predicate.BatchMsg) *BatchMsgUpdateOne {
  963. bmuo.mutation.Where(ps...)
  964. return bmuo
  965. }
  966. // Select allows selecting one or more fields (columns) of the returned entity.
  967. // The default is selecting all fields defined in the entity schema.
  968. func (bmuo *BatchMsgUpdateOne) Select(field string, fields ...string) *BatchMsgUpdateOne {
  969. bmuo.fields = append([]string{field}, fields...)
  970. return bmuo
  971. }
  972. // Save executes the query and returns the updated BatchMsg entity.
  973. func (bmuo *BatchMsgUpdateOne) Save(ctx context.Context) (*BatchMsg, error) {
  974. if err := bmuo.defaults(); err != nil {
  975. return nil, err
  976. }
  977. return withHooks(ctx, bmuo.sqlSave, bmuo.mutation, bmuo.hooks)
  978. }
  979. // SaveX is like Save, but panics if an error occurs.
  980. func (bmuo *BatchMsgUpdateOne) SaveX(ctx context.Context) *BatchMsg {
  981. node, err := bmuo.Save(ctx)
  982. if err != nil {
  983. panic(err)
  984. }
  985. return node
  986. }
  987. // Exec executes the query on the entity.
  988. func (bmuo *BatchMsgUpdateOne) Exec(ctx context.Context) error {
  989. _, err := bmuo.Save(ctx)
  990. return err
  991. }
  992. // ExecX is like Exec, but panics if an error occurs.
  993. func (bmuo *BatchMsgUpdateOne) ExecX(ctx context.Context) {
  994. if err := bmuo.Exec(ctx); err != nil {
  995. panic(err)
  996. }
  997. }
  998. // defaults sets the default values of the builder before save.
  999. func (bmuo *BatchMsgUpdateOne) defaults() error {
  1000. if _, ok := bmuo.mutation.UpdatedAt(); !ok {
  1001. if batchmsg.UpdateDefaultUpdatedAt == nil {
  1002. return fmt.Errorf("ent: uninitialized batchmsg.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  1003. }
  1004. v := batchmsg.UpdateDefaultUpdatedAt()
  1005. bmuo.mutation.SetUpdatedAt(v)
  1006. }
  1007. return nil
  1008. }
  1009. // check runs all checks and user-defined validators on the builder.
  1010. func (bmuo *BatchMsgUpdateOne) check() error {
  1011. if v, ok := bmuo.mutation.OrganizationID(); ok {
  1012. if err := batchmsg.OrganizationIDValidator(v); err != nil {
  1013. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "BatchMsg.organization_id": %w`, err)}
  1014. }
  1015. }
  1016. return nil
  1017. }
  1018. func (bmuo *BatchMsgUpdateOne) sqlSave(ctx context.Context) (_node *BatchMsg, err error) {
  1019. if err := bmuo.check(); err != nil {
  1020. return _node, err
  1021. }
  1022. _spec := sqlgraph.NewUpdateSpec(batchmsg.Table, batchmsg.Columns, sqlgraph.NewFieldSpec(batchmsg.FieldID, field.TypeUint64))
  1023. id, ok := bmuo.mutation.ID()
  1024. if !ok {
  1025. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BatchMsg.id" for update`)}
  1026. }
  1027. _spec.Node.ID.Value = id
  1028. if fields := bmuo.fields; len(fields) > 0 {
  1029. _spec.Node.Columns = make([]string, 0, len(fields))
  1030. _spec.Node.Columns = append(_spec.Node.Columns, batchmsg.FieldID)
  1031. for _, f := range fields {
  1032. if !batchmsg.ValidColumn(f) {
  1033. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  1034. }
  1035. if f != batchmsg.FieldID {
  1036. _spec.Node.Columns = append(_spec.Node.Columns, f)
  1037. }
  1038. }
  1039. }
  1040. if ps := bmuo.mutation.predicates; len(ps) > 0 {
  1041. _spec.Predicate = func(selector *sql.Selector) {
  1042. for i := range ps {
  1043. ps[i](selector)
  1044. }
  1045. }
  1046. }
  1047. if value, ok := bmuo.mutation.UpdatedAt(); ok {
  1048. _spec.SetField(batchmsg.FieldUpdatedAt, field.TypeTime, value)
  1049. }
  1050. if value, ok := bmuo.mutation.DeletedAt(); ok {
  1051. _spec.SetField(batchmsg.FieldDeletedAt, field.TypeTime, value)
  1052. }
  1053. if bmuo.mutation.DeletedAtCleared() {
  1054. _spec.ClearField(batchmsg.FieldDeletedAt, field.TypeTime)
  1055. }
  1056. if value, ok := bmuo.mutation.Status(); ok {
  1057. _spec.SetField(batchmsg.FieldStatus, field.TypeUint8, value)
  1058. }
  1059. if value, ok := bmuo.mutation.AddedStatus(); ok {
  1060. _spec.AddField(batchmsg.FieldStatus, field.TypeUint8, value)
  1061. }
  1062. if bmuo.mutation.StatusCleared() {
  1063. _spec.ClearField(batchmsg.FieldStatus, field.TypeUint8)
  1064. }
  1065. if value, ok := bmuo.mutation.BatchNo(); ok {
  1066. _spec.SetField(batchmsg.FieldBatchNo, field.TypeString, value)
  1067. }
  1068. if bmuo.mutation.BatchNoCleared() {
  1069. _spec.ClearField(batchmsg.FieldBatchNo, field.TypeString)
  1070. }
  1071. if value, ok := bmuo.mutation.TaskName(); ok {
  1072. _spec.SetField(batchmsg.FieldTaskName, field.TypeString, value)
  1073. }
  1074. if bmuo.mutation.TaskNameCleared() {
  1075. _spec.ClearField(batchmsg.FieldTaskName, field.TypeString)
  1076. }
  1077. if value, ok := bmuo.mutation.Fromwxid(); ok {
  1078. _spec.SetField(batchmsg.FieldFromwxid, field.TypeString, value)
  1079. }
  1080. if bmuo.mutation.FromwxidCleared() {
  1081. _spec.ClearField(batchmsg.FieldFromwxid, field.TypeString)
  1082. }
  1083. if value, ok := bmuo.mutation.Msg(); ok {
  1084. _spec.SetField(batchmsg.FieldMsg, field.TypeString, value)
  1085. }
  1086. if bmuo.mutation.MsgCleared() {
  1087. _spec.ClearField(batchmsg.FieldMsg, field.TypeString)
  1088. }
  1089. if value, ok := bmuo.mutation.Tag(); ok {
  1090. _spec.SetField(batchmsg.FieldTag, field.TypeString, value)
  1091. }
  1092. if bmuo.mutation.TagCleared() {
  1093. _spec.ClearField(batchmsg.FieldTag, field.TypeString)
  1094. }
  1095. if value, ok := bmuo.mutation.Tagids(); ok {
  1096. _spec.SetField(batchmsg.FieldTagids, field.TypeString, value)
  1097. }
  1098. if bmuo.mutation.TagidsCleared() {
  1099. _spec.ClearField(batchmsg.FieldTagids, field.TypeString)
  1100. }
  1101. if value, ok := bmuo.mutation.Total(); ok {
  1102. _spec.SetField(batchmsg.FieldTotal, field.TypeInt32, value)
  1103. }
  1104. if value, ok := bmuo.mutation.AddedTotal(); ok {
  1105. _spec.AddField(batchmsg.FieldTotal, field.TypeInt32, value)
  1106. }
  1107. if bmuo.mutation.TotalCleared() {
  1108. _spec.ClearField(batchmsg.FieldTotal, field.TypeInt32)
  1109. }
  1110. if value, ok := bmuo.mutation.Success(); ok {
  1111. _spec.SetField(batchmsg.FieldSuccess, field.TypeInt32, value)
  1112. }
  1113. if value, ok := bmuo.mutation.AddedSuccess(); ok {
  1114. _spec.AddField(batchmsg.FieldSuccess, field.TypeInt32, value)
  1115. }
  1116. if bmuo.mutation.SuccessCleared() {
  1117. _spec.ClearField(batchmsg.FieldSuccess, field.TypeInt32)
  1118. }
  1119. if value, ok := bmuo.mutation.Fail(); ok {
  1120. _spec.SetField(batchmsg.FieldFail, field.TypeInt32, value)
  1121. }
  1122. if value, ok := bmuo.mutation.AddedFail(); ok {
  1123. _spec.AddField(batchmsg.FieldFail, field.TypeInt32, value)
  1124. }
  1125. if bmuo.mutation.FailCleared() {
  1126. _spec.ClearField(batchmsg.FieldFail, field.TypeInt32)
  1127. }
  1128. if value, ok := bmuo.mutation.StartTime(); ok {
  1129. _spec.SetField(batchmsg.FieldStartTime, field.TypeTime, value)
  1130. }
  1131. if bmuo.mutation.StartTimeCleared() {
  1132. _spec.ClearField(batchmsg.FieldStartTime, field.TypeTime)
  1133. }
  1134. if value, ok := bmuo.mutation.StopTime(); ok {
  1135. _spec.SetField(batchmsg.FieldStopTime, field.TypeTime, value)
  1136. }
  1137. if bmuo.mutation.StopTimeCleared() {
  1138. _spec.ClearField(batchmsg.FieldStopTime, field.TypeTime)
  1139. }
  1140. if value, ok := bmuo.mutation.SendTime(); ok {
  1141. _spec.SetField(batchmsg.FieldSendTime, field.TypeTime, value)
  1142. }
  1143. if bmuo.mutation.SendTimeCleared() {
  1144. _spec.ClearField(batchmsg.FieldSendTime, field.TypeTime)
  1145. }
  1146. if value, ok := bmuo.mutation.GetType(); ok {
  1147. _spec.SetField(batchmsg.FieldType, field.TypeInt32, value)
  1148. }
  1149. if value, ok := bmuo.mutation.AddedType(); ok {
  1150. _spec.AddField(batchmsg.FieldType, field.TypeInt32, value)
  1151. }
  1152. if bmuo.mutation.TypeCleared() {
  1153. _spec.ClearField(batchmsg.FieldType, field.TypeInt32)
  1154. }
  1155. if value, ok := bmuo.mutation.OrganizationID(); ok {
  1156. _spec.SetField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
  1157. }
  1158. if value, ok := bmuo.mutation.AddedOrganizationID(); ok {
  1159. _spec.AddField(batchmsg.FieldOrganizationID, field.TypeUint64, value)
  1160. }
  1161. if value, ok := bmuo.mutation.Ctype(); ok {
  1162. _spec.SetField(batchmsg.FieldCtype, field.TypeUint64, value)
  1163. }
  1164. if value, ok := bmuo.mutation.AddedCtype(); ok {
  1165. _spec.AddField(batchmsg.FieldCtype, field.TypeUint64, value)
  1166. }
  1167. if value, ok := bmuo.mutation.Cc(); ok {
  1168. _spec.SetField(batchmsg.FieldCc, field.TypeString, value)
  1169. }
  1170. if bmuo.mutation.CcCleared() {
  1171. _spec.ClearField(batchmsg.FieldCc, field.TypeString)
  1172. }
  1173. if value, ok := bmuo.mutation.Phone(); ok {
  1174. _spec.SetField(batchmsg.FieldPhone, field.TypeString, value)
  1175. }
  1176. if bmuo.mutation.PhoneCleared() {
  1177. _spec.ClearField(batchmsg.FieldPhone, field.TypeString)
  1178. }
  1179. _node = &BatchMsg{config: bmuo.config}
  1180. _spec.Assign = _node.assignValues
  1181. _spec.ScanValues = _node.scanValues
  1182. if err = sqlgraph.UpdateNode(ctx, bmuo.driver, _spec); err != nil {
  1183. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1184. err = &NotFoundError{batchmsg.Label}
  1185. } else if sqlgraph.IsConstraintError(err) {
  1186. err = &ConstraintError{msg: err.Error(), wrap: err}
  1187. }
  1188. return nil, err
  1189. }
  1190. bmuo.mutation.done = true
  1191. return _node, nil
  1192. }