soptask_update.go 28 KB

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