soptask_update.go 27 KB

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