soptask_update.go 29 KB

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