soptask_update.go 25 KB

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