allocagent_update.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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/allocagent"
  9. "wechat-api/ent/predicate"
  10. "entgo.io/ent/dialect/sql"
  11. "entgo.io/ent/dialect/sql/sqlgraph"
  12. "entgo.io/ent/dialect/sql/sqljson"
  13. "entgo.io/ent/schema/field"
  14. )
  15. // AllocAgentUpdate is the builder for updating AllocAgent entities.
  16. type AllocAgentUpdate struct {
  17. config
  18. hooks []Hook
  19. mutation *AllocAgentMutation
  20. }
  21. // Where appends a list predicates to the AllocAgentUpdate builder.
  22. func (aau *AllocAgentUpdate) Where(ps ...predicate.AllocAgent) *AllocAgentUpdate {
  23. aau.mutation.Where(ps...)
  24. return aau
  25. }
  26. // SetUpdatedAt sets the "updated_at" field.
  27. func (aau *AllocAgentUpdate) SetUpdatedAt(t time.Time) *AllocAgentUpdate {
  28. aau.mutation.SetUpdatedAt(t)
  29. return aau
  30. }
  31. // SetDeletedAt sets the "deleted_at" field.
  32. func (aau *AllocAgentUpdate) SetDeletedAt(t time.Time) *AllocAgentUpdate {
  33. aau.mutation.SetDeletedAt(t)
  34. return aau
  35. }
  36. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  37. func (aau *AllocAgentUpdate) SetNillableDeletedAt(t *time.Time) *AllocAgentUpdate {
  38. if t != nil {
  39. aau.SetDeletedAt(*t)
  40. }
  41. return aau
  42. }
  43. // ClearDeletedAt clears the value of the "deleted_at" field.
  44. func (aau *AllocAgentUpdate) ClearDeletedAt() *AllocAgentUpdate {
  45. aau.mutation.ClearDeletedAt()
  46. return aau
  47. }
  48. // SetUserID sets the "user_id" field.
  49. func (aau *AllocAgentUpdate) SetUserID(s string) *AllocAgentUpdate {
  50. aau.mutation.SetUserID(s)
  51. return aau
  52. }
  53. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  54. func (aau *AllocAgentUpdate) SetNillableUserID(s *string) *AllocAgentUpdate {
  55. if s != nil {
  56. aau.SetUserID(*s)
  57. }
  58. return aau
  59. }
  60. // ClearUserID clears the value of the "user_id" field.
  61. func (aau *AllocAgentUpdate) ClearUserID() *AllocAgentUpdate {
  62. aau.mutation.ClearUserID()
  63. return aau
  64. }
  65. // SetOrganizationID sets the "organization_id" field.
  66. func (aau *AllocAgentUpdate) SetOrganizationID(u uint64) *AllocAgentUpdate {
  67. aau.mutation.ResetOrganizationID()
  68. aau.mutation.SetOrganizationID(u)
  69. return aau
  70. }
  71. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  72. func (aau *AllocAgentUpdate) SetNillableOrganizationID(u *uint64) *AllocAgentUpdate {
  73. if u != nil {
  74. aau.SetOrganizationID(*u)
  75. }
  76. return aau
  77. }
  78. // AddOrganizationID adds u to the "organization_id" field.
  79. func (aau *AllocAgentUpdate) AddOrganizationID(u int64) *AllocAgentUpdate {
  80. aau.mutation.AddOrganizationID(u)
  81. return aau
  82. }
  83. // ClearOrganizationID clears the value of the "organization_id" field.
  84. func (aau *AllocAgentUpdate) ClearOrganizationID() *AllocAgentUpdate {
  85. aau.mutation.ClearOrganizationID()
  86. return aau
  87. }
  88. // SetAgents sets the "agents" field.
  89. func (aau *AllocAgentUpdate) SetAgents(u []uint64) *AllocAgentUpdate {
  90. aau.mutation.SetAgents(u)
  91. return aau
  92. }
  93. // AppendAgents appends u to the "agents" field.
  94. func (aau *AllocAgentUpdate) AppendAgents(u []uint64) *AllocAgentUpdate {
  95. aau.mutation.AppendAgents(u)
  96. return aau
  97. }
  98. // SetStatus sets the "status" field.
  99. func (aau *AllocAgentUpdate) SetStatus(i int) *AllocAgentUpdate {
  100. aau.mutation.ResetStatus()
  101. aau.mutation.SetStatus(i)
  102. return aau
  103. }
  104. // SetNillableStatus sets the "status" field if the given value is not nil.
  105. func (aau *AllocAgentUpdate) SetNillableStatus(i *int) *AllocAgentUpdate {
  106. if i != nil {
  107. aau.SetStatus(*i)
  108. }
  109. return aau
  110. }
  111. // AddStatus adds i to the "status" field.
  112. func (aau *AllocAgentUpdate) AddStatus(i int) *AllocAgentUpdate {
  113. aau.mutation.AddStatus(i)
  114. return aau
  115. }
  116. // ClearStatus clears the value of the "status" field.
  117. func (aau *AllocAgentUpdate) ClearStatus() *AllocAgentUpdate {
  118. aau.mutation.ClearStatus()
  119. return aau
  120. }
  121. // Mutation returns the AllocAgentMutation object of the builder.
  122. func (aau *AllocAgentUpdate) Mutation() *AllocAgentMutation {
  123. return aau.mutation
  124. }
  125. // Save executes the query and returns the number of nodes affected by the update operation.
  126. func (aau *AllocAgentUpdate) Save(ctx context.Context) (int, error) {
  127. if err := aau.defaults(); err != nil {
  128. return 0, err
  129. }
  130. return withHooks(ctx, aau.sqlSave, aau.mutation, aau.hooks)
  131. }
  132. // SaveX is like Save, but panics if an error occurs.
  133. func (aau *AllocAgentUpdate) SaveX(ctx context.Context) int {
  134. affected, err := aau.Save(ctx)
  135. if err != nil {
  136. panic(err)
  137. }
  138. return affected
  139. }
  140. // Exec executes the query.
  141. func (aau *AllocAgentUpdate) Exec(ctx context.Context) error {
  142. _, err := aau.Save(ctx)
  143. return err
  144. }
  145. // ExecX is like Exec, but panics if an error occurs.
  146. func (aau *AllocAgentUpdate) ExecX(ctx context.Context) {
  147. if err := aau.Exec(ctx); err != nil {
  148. panic(err)
  149. }
  150. }
  151. // defaults sets the default values of the builder before save.
  152. func (aau *AllocAgentUpdate) defaults() error {
  153. if _, ok := aau.mutation.UpdatedAt(); !ok {
  154. if allocagent.UpdateDefaultUpdatedAt == nil {
  155. return fmt.Errorf("ent: uninitialized allocagent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  156. }
  157. v := allocagent.UpdateDefaultUpdatedAt()
  158. aau.mutation.SetUpdatedAt(v)
  159. }
  160. return nil
  161. }
  162. // check runs all checks and user-defined validators on the builder.
  163. func (aau *AllocAgentUpdate) check() error {
  164. if v, ok := aau.mutation.Status(); ok {
  165. if err := allocagent.StatusValidator(v); err != nil {
  166. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "AllocAgent.status": %w`, err)}
  167. }
  168. }
  169. return nil
  170. }
  171. func (aau *AllocAgentUpdate) sqlSave(ctx context.Context) (n int, err error) {
  172. if err := aau.check(); err != nil {
  173. return n, err
  174. }
  175. _spec := sqlgraph.NewUpdateSpec(allocagent.Table, allocagent.Columns, sqlgraph.NewFieldSpec(allocagent.FieldID, field.TypeUint64))
  176. if ps := aau.mutation.predicates; len(ps) > 0 {
  177. _spec.Predicate = func(selector *sql.Selector) {
  178. for i := range ps {
  179. ps[i](selector)
  180. }
  181. }
  182. }
  183. if value, ok := aau.mutation.UpdatedAt(); ok {
  184. _spec.SetField(allocagent.FieldUpdatedAt, field.TypeTime, value)
  185. }
  186. if value, ok := aau.mutation.DeletedAt(); ok {
  187. _spec.SetField(allocagent.FieldDeletedAt, field.TypeTime, value)
  188. }
  189. if aau.mutation.DeletedAtCleared() {
  190. _spec.ClearField(allocagent.FieldDeletedAt, field.TypeTime)
  191. }
  192. if value, ok := aau.mutation.UserID(); ok {
  193. _spec.SetField(allocagent.FieldUserID, field.TypeString, value)
  194. }
  195. if aau.mutation.UserIDCleared() {
  196. _spec.ClearField(allocagent.FieldUserID, field.TypeString)
  197. }
  198. if value, ok := aau.mutation.OrganizationID(); ok {
  199. _spec.SetField(allocagent.FieldOrganizationID, field.TypeUint64, value)
  200. }
  201. if value, ok := aau.mutation.AddedOrganizationID(); ok {
  202. _spec.AddField(allocagent.FieldOrganizationID, field.TypeUint64, value)
  203. }
  204. if aau.mutation.OrganizationIDCleared() {
  205. _spec.ClearField(allocagent.FieldOrganizationID, field.TypeUint64)
  206. }
  207. if value, ok := aau.mutation.Agents(); ok {
  208. _spec.SetField(allocagent.FieldAgents, field.TypeJSON, value)
  209. }
  210. if value, ok := aau.mutation.AppendedAgents(); ok {
  211. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  212. sqljson.Append(u, allocagent.FieldAgents, value)
  213. })
  214. }
  215. if value, ok := aau.mutation.Status(); ok {
  216. _spec.SetField(allocagent.FieldStatus, field.TypeInt, value)
  217. }
  218. if value, ok := aau.mutation.AddedStatus(); ok {
  219. _spec.AddField(allocagent.FieldStatus, field.TypeInt, value)
  220. }
  221. if aau.mutation.StatusCleared() {
  222. _spec.ClearField(allocagent.FieldStatus, field.TypeInt)
  223. }
  224. if n, err = sqlgraph.UpdateNodes(ctx, aau.driver, _spec); err != nil {
  225. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  226. err = &NotFoundError{allocagent.Label}
  227. } else if sqlgraph.IsConstraintError(err) {
  228. err = &ConstraintError{msg: err.Error(), wrap: err}
  229. }
  230. return 0, err
  231. }
  232. aau.mutation.done = true
  233. return n, nil
  234. }
  235. // AllocAgentUpdateOne is the builder for updating a single AllocAgent entity.
  236. type AllocAgentUpdateOne struct {
  237. config
  238. fields []string
  239. hooks []Hook
  240. mutation *AllocAgentMutation
  241. }
  242. // SetUpdatedAt sets the "updated_at" field.
  243. func (aauo *AllocAgentUpdateOne) SetUpdatedAt(t time.Time) *AllocAgentUpdateOne {
  244. aauo.mutation.SetUpdatedAt(t)
  245. return aauo
  246. }
  247. // SetDeletedAt sets the "deleted_at" field.
  248. func (aauo *AllocAgentUpdateOne) SetDeletedAt(t time.Time) *AllocAgentUpdateOne {
  249. aauo.mutation.SetDeletedAt(t)
  250. return aauo
  251. }
  252. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  253. func (aauo *AllocAgentUpdateOne) SetNillableDeletedAt(t *time.Time) *AllocAgentUpdateOne {
  254. if t != nil {
  255. aauo.SetDeletedAt(*t)
  256. }
  257. return aauo
  258. }
  259. // ClearDeletedAt clears the value of the "deleted_at" field.
  260. func (aauo *AllocAgentUpdateOne) ClearDeletedAt() *AllocAgentUpdateOne {
  261. aauo.mutation.ClearDeletedAt()
  262. return aauo
  263. }
  264. // SetUserID sets the "user_id" field.
  265. func (aauo *AllocAgentUpdateOne) SetUserID(s string) *AllocAgentUpdateOne {
  266. aauo.mutation.SetUserID(s)
  267. return aauo
  268. }
  269. // SetNillableUserID sets the "user_id" field if the given value is not nil.
  270. func (aauo *AllocAgentUpdateOne) SetNillableUserID(s *string) *AllocAgentUpdateOne {
  271. if s != nil {
  272. aauo.SetUserID(*s)
  273. }
  274. return aauo
  275. }
  276. // ClearUserID clears the value of the "user_id" field.
  277. func (aauo *AllocAgentUpdateOne) ClearUserID() *AllocAgentUpdateOne {
  278. aauo.mutation.ClearUserID()
  279. return aauo
  280. }
  281. // SetOrganizationID sets the "organization_id" field.
  282. func (aauo *AllocAgentUpdateOne) SetOrganizationID(u uint64) *AllocAgentUpdateOne {
  283. aauo.mutation.ResetOrganizationID()
  284. aauo.mutation.SetOrganizationID(u)
  285. return aauo
  286. }
  287. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  288. func (aauo *AllocAgentUpdateOne) SetNillableOrganizationID(u *uint64) *AllocAgentUpdateOne {
  289. if u != nil {
  290. aauo.SetOrganizationID(*u)
  291. }
  292. return aauo
  293. }
  294. // AddOrganizationID adds u to the "organization_id" field.
  295. func (aauo *AllocAgentUpdateOne) AddOrganizationID(u int64) *AllocAgentUpdateOne {
  296. aauo.mutation.AddOrganizationID(u)
  297. return aauo
  298. }
  299. // ClearOrganizationID clears the value of the "organization_id" field.
  300. func (aauo *AllocAgentUpdateOne) ClearOrganizationID() *AllocAgentUpdateOne {
  301. aauo.mutation.ClearOrganizationID()
  302. return aauo
  303. }
  304. // SetAgents sets the "agents" field.
  305. func (aauo *AllocAgentUpdateOne) SetAgents(u []uint64) *AllocAgentUpdateOne {
  306. aauo.mutation.SetAgents(u)
  307. return aauo
  308. }
  309. // AppendAgents appends u to the "agents" field.
  310. func (aauo *AllocAgentUpdateOne) AppendAgents(u []uint64) *AllocAgentUpdateOne {
  311. aauo.mutation.AppendAgents(u)
  312. return aauo
  313. }
  314. // SetStatus sets the "status" field.
  315. func (aauo *AllocAgentUpdateOne) SetStatus(i int) *AllocAgentUpdateOne {
  316. aauo.mutation.ResetStatus()
  317. aauo.mutation.SetStatus(i)
  318. return aauo
  319. }
  320. // SetNillableStatus sets the "status" field if the given value is not nil.
  321. func (aauo *AllocAgentUpdateOne) SetNillableStatus(i *int) *AllocAgentUpdateOne {
  322. if i != nil {
  323. aauo.SetStatus(*i)
  324. }
  325. return aauo
  326. }
  327. // AddStatus adds i to the "status" field.
  328. func (aauo *AllocAgentUpdateOne) AddStatus(i int) *AllocAgentUpdateOne {
  329. aauo.mutation.AddStatus(i)
  330. return aauo
  331. }
  332. // ClearStatus clears the value of the "status" field.
  333. func (aauo *AllocAgentUpdateOne) ClearStatus() *AllocAgentUpdateOne {
  334. aauo.mutation.ClearStatus()
  335. return aauo
  336. }
  337. // Mutation returns the AllocAgentMutation object of the builder.
  338. func (aauo *AllocAgentUpdateOne) Mutation() *AllocAgentMutation {
  339. return aauo.mutation
  340. }
  341. // Where appends a list predicates to the AllocAgentUpdate builder.
  342. func (aauo *AllocAgentUpdateOne) Where(ps ...predicate.AllocAgent) *AllocAgentUpdateOne {
  343. aauo.mutation.Where(ps...)
  344. return aauo
  345. }
  346. // Select allows selecting one or more fields (columns) of the returned entity.
  347. // The default is selecting all fields defined in the entity schema.
  348. func (aauo *AllocAgentUpdateOne) Select(field string, fields ...string) *AllocAgentUpdateOne {
  349. aauo.fields = append([]string{field}, fields...)
  350. return aauo
  351. }
  352. // Save executes the query and returns the updated AllocAgent entity.
  353. func (aauo *AllocAgentUpdateOne) Save(ctx context.Context) (*AllocAgent, error) {
  354. if err := aauo.defaults(); err != nil {
  355. return nil, err
  356. }
  357. return withHooks(ctx, aauo.sqlSave, aauo.mutation, aauo.hooks)
  358. }
  359. // SaveX is like Save, but panics if an error occurs.
  360. func (aauo *AllocAgentUpdateOne) SaveX(ctx context.Context) *AllocAgent {
  361. node, err := aauo.Save(ctx)
  362. if err != nil {
  363. panic(err)
  364. }
  365. return node
  366. }
  367. // Exec executes the query on the entity.
  368. func (aauo *AllocAgentUpdateOne) Exec(ctx context.Context) error {
  369. _, err := aauo.Save(ctx)
  370. return err
  371. }
  372. // ExecX is like Exec, but panics if an error occurs.
  373. func (aauo *AllocAgentUpdateOne) ExecX(ctx context.Context) {
  374. if err := aauo.Exec(ctx); err != nil {
  375. panic(err)
  376. }
  377. }
  378. // defaults sets the default values of the builder before save.
  379. func (aauo *AllocAgentUpdateOne) defaults() error {
  380. if _, ok := aauo.mutation.UpdatedAt(); !ok {
  381. if allocagent.UpdateDefaultUpdatedAt == nil {
  382. return fmt.Errorf("ent: uninitialized allocagent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  383. }
  384. v := allocagent.UpdateDefaultUpdatedAt()
  385. aauo.mutation.SetUpdatedAt(v)
  386. }
  387. return nil
  388. }
  389. // check runs all checks and user-defined validators on the builder.
  390. func (aauo *AllocAgentUpdateOne) check() error {
  391. if v, ok := aauo.mutation.Status(); ok {
  392. if err := allocagent.StatusValidator(v); err != nil {
  393. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "AllocAgent.status": %w`, err)}
  394. }
  395. }
  396. return nil
  397. }
  398. func (aauo *AllocAgentUpdateOne) sqlSave(ctx context.Context) (_node *AllocAgent, err error) {
  399. if err := aauo.check(); err != nil {
  400. return _node, err
  401. }
  402. _spec := sqlgraph.NewUpdateSpec(allocagent.Table, allocagent.Columns, sqlgraph.NewFieldSpec(allocagent.FieldID, field.TypeUint64))
  403. id, ok := aauo.mutation.ID()
  404. if !ok {
  405. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AllocAgent.id" for update`)}
  406. }
  407. _spec.Node.ID.Value = id
  408. if fields := aauo.fields; len(fields) > 0 {
  409. _spec.Node.Columns = make([]string, 0, len(fields))
  410. _spec.Node.Columns = append(_spec.Node.Columns, allocagent.FieldID)
  411. for _, f := range fields {
  412. if !allocagent.ValidColumn(f) {
  413. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  414. }
  415. if f != allocagent.FieldID {
  416. _spec.Node.Columns = append(_spec.Node.Columns, f)
  417. }
  418. }
  419. }
  420. if ps := aauo.mutation.predicates; len(ps) > 0 {
  421. _spec.Predicate = func(selector *sql.Selector) {
  422. for i := range ps {
  423. ps[i](selector)
  424. }
  425. }
  426. }
  427. if value, ok := aauo.mutation.UpdatedAt(); ok {
  428. _spec.SetField(allocagent.FieldUpdatedAt, field.TypeTime, value)
  429. }
  430. if value, ok := aauo.mutation.DeletedAt(); ok {
  431. _spec.SetField(allocagent.FieldDeletedAt, field.TypeTime, value)
  432. }
  433. if aauo.mutation.DeletedAtCleared() {
  434. _spec.ClearField(allocagent.FieldDeletedAt, field.TypeTime)
  435. }
  436. if value, ok := aauo.mutation.UserID(); ok {
  437. _spec.SetField(allocagent.FieldUserID, field.TypeString, value)
  438. }
  439. if aauo.mutation.UserIDCleared() {
  440. _spec.ClearField(allocagent.FieldUserID, field.TypeString)
  441. }
  442. if value, ok := aauo.mutation.OrganizationID(); ok {
  443. _spec.SetField(allocagent.FieldOrganizationID, field.TypeUint64, value)
  444. }
  445. if value, ok := aauo.mutation.AddedOrganizationID(); ok {
  446. _spec.AddField(allocagent.FieldOrganizationID, field.TypeUint64, value)
  447. }
  448. if aauo.mutation.OrganizationIDCleared() {
  449. _spec.ClearField(allocagent.FieldOrganizationID, field.TypeUint64)
  450. }
  451. if value, ok := aauo.mutation.Agents(); ok {
  452. _spec.SetField(allocagent.FieldAgents, field.TypeJSON, value)
  453. }
  454. if value, ok := aauo.mutation.AppendedAgents(); ok {
  455. _spec.AddModifier(func(u *sql.UpdateBuilder) {
  456. sqljson.Append(u, allocagent.FieldAgents, value)
  457. })
  458. }
  459. if value, ok := aauo.mutation.Status(); ok {
  460. _spec.SetField(allocagent.FieldStatus, field.TypeInt, value)
  461. }
  462. if value, ok := aauo.mutation.AddedStatus(); ok {
  463. _spec.AddField(allocagent.FieldStatus, field.TypeInt, value)
  464. }
  465. if aauo.mutation.StatusCleared() {
  466. _spec.ClearField(allocagent.FieldStatus, field.TypeInt)
  467. }
  468. _node = &AllocAgent{config: aauo.config}
  469. _spec.Assign = _node.assignValues
  470. _spec.ScanValues = _node.scanValues
  471. if err = sqlgraph.UpdateNode(ctx, aauo.driver, _spec); err != nil {
  472. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  473. err = &NotFoundError{allocagent.Label}
  474. } else if sqlgraph.IsConstraintError(err) {
  475. err = &ConstraintError{msg: err.Error(), wrap: err}
  476. }
  477. return nil, err
  478. }
  479. aauo.mutation.done = true
  480. return _node, nil
  481. }