agent_update.go 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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/agent"
  9. "wechat-api/ent/apikey"
  10. "wechat-api/ent/predicate"
  11. "wechat-api/ent/token"
  12. "wechat-api/ent/whatsapp"
  13. "wechat-api/ent/wx"
  14. "wechat-api/ent/xunjiservice"
  15. "entgo.io/ent/dialect/sql"
  16. "entgo.io/ent/dialect/sql/sqlgraph"
  17. "entgo.io/ent/schema/field"
  18. )
  19. // AgentUpdate is the builder for updating Agent entities.
  20. type AgentUpdate struct {
  21. config
  22. hooks []Hook
  23. mutation *AgentMutation
  24. }
  25. // Where appends a list predicates to the AgentUpdate builder.
  26. func (au *AgentUpdate) Where(ps ...predicate.Agent) *AgentUpdate {
  27. au.mutation.Where(ps...)
  28. return au
  29. }
  30. // SetUpdatedAt sets the "updated_at" field.
  31. func (au *AgentUpdate) SetUpdatedAt(t time.Time) *AgentUpdate {
  32. au.mutation.SetUpdatedAt(t)
  33. return au
  34. }
  35. // SetDeletedAt sets the "deleted_at" field.
  36. func (au *AgentUpdate) SetDeletedAt(t time.Time) *AgentUpdate {
  37. au.mutation.SetDeletedAt(t)
  38. return au
  39. }
  40. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  41. func (au *AgentUpdate) SetNillableDeletedAt(t *time.Time) *AgentUpdate {
  42. if t != nil {
  43. au.SetDeletedAt(*t)
  44. }
  45. return au
  46. }
  47. // ClearDeletedAt clears the value of the "deleted_at" field.
  48. func (au *AgentUpdate) ClearDeletedAt() *AgentUpdate {
  49. au.mutation.ClearDeletedAt()
  50. return au
  51. }
  52. // SetName sets the "name" field.
  53. func (au *AgentUpdate) SetName(s string) *AgentUpdate {
  54. au.mutation.SetName(s)
  55. return au
  56. }
  57. // SetNillableName sets the "name" field if the given value is not nil.
  58. func (au *AgentUpdate) SetNillableName(s *string) *AgentUpdate {
  59. if s != nil {
  60. au.SetName(*s)
  61. }
  62. return au
  63. }
  64. // SetRole sets the "role" field.
  65. func (au *AgentUpdate) SetRole(s string) *AgentUpdate {
  66. au.mutation.SetRole(s)
  67. return au
  68. }
  69. // SetNillableRole sets the "role" field if the given value is not nil.
  70. func (au *AgentUpdate) SetNillableRole(s *string) *AgentUpdate {
  71. if s != nil {
  72. au.SetRole(*s)
  73. }
  74. return au
  75. }
  76. // SetStatus sets the "status" field.
  77. func (au *AgentUpdate) SetStatus(i int) *AgentUpdate {
  78. au.mutation.ResetStatus()
  79. au.mutation.SetStatus(i)
  80. return au
  81. }
  82. // SetNillableStatus sets the "status" field if the given value is not nil.
  83. func (au *AgentUpdate) SetNillableStatus(i *int) *AgentUpdate {
  84. if i != nil {
  85. au.SetStatus(*i)
  86. }
  87. return au
  88. }
  89. // AddStatus adds i to the "status" field.
  90. func (au *AgentUpdate) AddStatus(i int) *AgentUpdate {
  91. au.mutation.AddStatus(i)
  92. return au
  93. }
  94. // ClearStatus clears the value of the "status" field.
  95. func (au *AgentUpdate) ClearStatus() *AgentUpdate {
  96. au.mutation.ClearStatus()
  97. return au
  98. }
  99. // SetBackground sets the "background" field.
  100. func (au *AgentUpdate) SetBackground(s string) *AgentUpdate {
  101. au.mutation.SetBackground(s)
  102. return au
  103. }
  104. // SetNillableBackground sets the "background" field if the given value is not nil.
  105. func (au *AgentUpdate) SetNillableBackground(s *string) *AgentUpdate {
  106. if s != nil {
  107. au.SetBackground(*s)
  108. }
  109. return au
  110. }
  111. // ClearBackground clears the value of the "background" field.
  112. func (au *AgentUpdate) ClearBackground() *AgentUpdate {
  113. au.mutation.ClearBackground()
  114. return au
  115. }
  116. // SetExamples sets the "examples" field.
  117. func (au *AgentUpdate) SetExamples(s string) *AgentUpdate {
  118. au.mutation.SetExamples(s)
  119. return au
  120. }
  121. // SetNillableExamples sets the "examples" field if the given value is not nil.
  122. func (au *AgentUpdate) SetNillableExamples(s *string) *AgentUpdate {
  123. if s != nil {
  124. au.SetExamples(*s)
  125. }
  126. return au
  127. }
  128. // ClearExamples clears the value of the "examples" field.
  129. func (au *AgentUpdate) ClearExamples() *AgentUpdate {
  130. au.mutation.ClearExamples()
  131. return au
  132. }
  133. // SetOrganizationID sets the "organization_id" field.
  134. func (au *AgentUpdate) SetOrganizationID(u uint64) *AgentUpdate {
  135. au.mutation.ResetOrganizationID()
  136. au.mutation.SetOrganizationID(u)
  137. return au
  138. }
  139. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  140. func (au *AgentUpdate) SetNillableOrganizationID(u *uint64) *AgentUpdate {
  141. if u != nil {
  142. au.SetOrganizationID(*u)
  143. }
  144. return au
  145. }
  146. // AddOrganizationID adds u to the "organization_id" field.
  147. func (au *AgentUpdate) AddOrganizationID(u int64) *AgentUpdate {
  148. au.mutation.AddOrganizationID(u)
  149. return au
  150. }
  151. // SetDatasetID sets the "dataset_id" field.
  152. func (au *AgentUpdate) SetDatasetID(s string) *AgentUpdate {
  153. au.mutation.SetDatasetID(s)
  154. return au
  155. }
  156. // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
  157. func (au *AgentUpdate) SetNillableDatasetID(s *string) *AgentUpdate {
  158. if s != nil {
  159. au.SetDatasetID(*s)
  160. }
  161. return au
  162. }
  163. // SetCollectionID sets the "collection_id" field.
  164. func (au *AgentUpdate) SetCollectionID(s string) *AgentUpdate {
  165. au.mutation.SetCollectionID(s)
  166. return au
  167. }
  168. // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
  169. func (au *AgentUpdate) SetNillableCollectionID(s *string) *AgentUpdate {
  170. if s != nil {
  171. au.SetCollectionID(*s)
  172. }
  173. return au
  174. }
  175. // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
  176. func (au *AgentUpdate) AddWxAgentIDs(ids ...uint64) *AgentUpdate {
  177. au.mutation.AddWxAgentIDs(ids...)
  178. return au
  179. }
  180. // AddWxAgent adds the "wx_agent" edges to the Wx entity.
  181. func (au *AgentUpdate) AddWxAgent(w ...*Wx) *AgentUpdate {
  182. ids := make([]uint64, len(w))
  183. for i := range w {
  184. ids[i] = w[i].ID
  185. }
  186. return au.AddWxAgentIDs(ids...)
  187. }
  188. // AddTokenAgentIDs adds the "token_agent" edge to the Token entity by IDs.
  189. func (au *AgentUpdate) AddTokenAgentIDs(ids ...uint64) *AgentUpdate {
  190. au.mutation.AddTokenAgentIDs(ids...)
  191. return au
  192. }
  193. // AddTokenAgent adds the "token_agent" edges to the Token entity.
  194. func (au *AgentUpdate) AddTokenAgent(t ...*Token) *AgentUpdate {
  195. ids := make([]uint64, len(t))
  196. for i := range t {
  197. ids[i] = t[i].ID
  198. }
  199. return au.AddTokenAgentIDs(ids...)
  200. }
  201. // AddWaAgentIDs adds the "wa_agent" edge to the Whatsapp entity by IDs.
  202. func (au *AgentUpdate) AddWaAgentIDs(ids ...uint64) *AgentUpdate {
  203. au.mutation.AddWaAgentIDs(ids...)
  204. return au
  205. }
  206. // AddWaAgent adds the "wa_agent" edges to the Whatsapp entity.
  207. func (au *AgentUpdate) AddWaAgent(w ...*Whatsapp) *AgentUpdate {
  208. ids := make([]uint64, len(w))
  209. for i := range w {
  210. ids[i] = w[i].ID
  211. }
  212. return au.AddWaAgentIDs(ids...)
  213. }
  214. // AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by IDs.
  215. func (au *AgentUpdate) AddXjsAgentIDs(ids ...uint64) *AgentUpdate {
  216. au.mutation.AddXjsAgentIDs(ids...)
  217. return au
  218. }
  219. // AddXjsAgent adds the "xjs_agent" edges to the XunjiService entity.
  220. func (au *AgentUpdate) AddXjsAgent(x ...*XunjiService) *AgentUpdate {
  221. ids := make([]uint64, len(x))
  222. for i := range x {
  223. ids[i] = x[i].ID
  224. }
  225. return au.AddXjsAgentIDs(ids...)
  226. }
  227. // AddKeyAgentIDs adds the "key_agent" edge to the ApiKey entity by IDs.
  228. func (au *AgentUpdate) AddKeyAgentIDs(ids ...uint64) *AgentUpdate {
  229. au.mutation.AddKeyAgentIDs(ids...)
  230. return au
  231. }
  232. // AddKeyAgent adds the "key_agent" edges to the ApiKey entity.
  233. func (au *AgentUpdate) AddKeyAgent(a ...*ApiKey) *AgentUpdate {
  234. ids := make([]uint64, len(a))
  235. for i := range a {
  236. ids[i] = a[i].ID
  237. }
  238. return au.AddKeyAgentIDs(ids...)
  239. }
  240. // Mutation returns the AgentMutation object of the builder.
  241. func (au *AgentUpdate) Mutation() *AgentMutation {
  242. return au.mutation
  243. }
  244. // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
  245. func (au *AgentUpdate) ClearWxAgent() *AgentUpdate {
  246. au.mutation.ClearWxAgent()
  247. return au
  248. }
  249. // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
  250. func (au *AgentUpdate) RemoveWxAgentIDs(ids ...uint64) *AgentUpdate {
  251. au.mutation.RemoveWxAgentIDs(ids...)
  252. return au
  253. }
  254. // RemoveWxAgent removes "wx_agent" edges to Wx entities.
  255. func (au *AgentUpdate) RemoveWxAgent(w ...*Wx) *AgentUpdate {
  256. ids := make([]uint64, len(w))
  257. for i := range w {
  258. ids[i] = w[i].ID
  259. }
  260. return au.RemoveWxAgentIDs(ids...)
  261. }
  262. // ClearTokenAgent clears all "token_agent" edges to the Token entity.
  263. func (au *AgentUpdate) ClearTokenAgent() *AgentUpdate {
  264. au.mutation.ClearTokenAgent()
  265. return au
  266. }
  267. // RemoveTokenAgentIDs removes the "token_agent" edge to Token entities by IDs.
  268. func (au *AgentUpdate) RemoveTokenAgentIDs(ids ...uint64) *AgentUpdate {
  269. au.mutation.RemoveTokenAgentIDs(ids...)
  270. return au
  271. }
  272. // RemoveTokenAgent removes "token_agent" edges to Token entities.
  273. func (au *AgentUpdate) RemoveTokenAgent(t ...*Token) *AgentUpdate {
  274. ids := make([]uint64, len(t))
  275. for i := range t {
  276. ids[i] = t[i].ID
  277. }
  278. return au.RemoveTokenAgentIDs(ids...)
  279. }
  280. // ClearWaAgent clears all "wa_agent" edges to the Whatsapp entity.
  281. func (au *AgentUpdate) ClearWaAgent() *AgentUpdate {
  282. au.mutation.ClearWaAgent()
  283. return au
  284. }
  285. // RemoveWaAgentIDs removes the "wa_agent" edge to Whatsapp entities by IDs.
  286. func (au *AgentUpdate) RemoveWaAgentIDs(ids ...uint64) *AgentUpdate {
  287. au.mutation.RemoveWaAgentIDs(ids...)
  288. return au
  289. }
  290. // RemoveWaAgent removes "wa_agent" edges to Whatsapp entities.
  291. func (au *AgentUpdate) RemoveWaAgent(w ...*Whatsapp) *AgentUpdate {
  292. ids := make([]uint64, len(w))
  293. for i := range w {
  294. ids[i] = w[i].ID
  295. }
  296. return au.RemoveWaAgentIDs(ids...)
  297. }
  298. // ClearXjsAgent clears all "xjs_agent" edges to the XunjiService entity.
  299. func (au *AgentUpdate) ClearXjsAgent() *AgentUpdate {
  300. au.mutation.ClearXjsAgent()
  301. return au
  302. }
  303. // RemoveXjsAgentIDs removes the "xjs_agent" edge to XunjiService entities by IDs.
  304. func (au *AgentUpdate) RemoveXjsAgentIDs(ids ...uint64) *AgentUpdate {
  305. au.mutation.RemoveXjsAgentIDs(ids...)
  306. return au
  307. }
  308. // RemoveXjsAgent removes "xjs_agent" edges to XunjiService entities.
  309. func (au *AgentUpdate) RemoveXjsAgent(x ...*XunjiService) *AgentUpdate {
  310. ids := make([]uint64, len(x))
  311. for i := range x {
  312. ids[i] = x[i].ID
  313. }
  314. return au.RemoveXjsAgentIDs(ids...)
  315. }
  316. // ClearKeyAgent clears all "key_agent" edges to the ApiKey entity.
  317. func (au *AgentUpdate) ClearKeyAgent() *AgentUpdate {
  318. au.mutation.ClearKeyAgent()
  319. return au
  320. }
  321. // RemoveKeyAgentIDs removes the "key_agent" edge to ApiKey entities by IDs.
  322. func (au *AgentUpdate) RemoveKeyAgentIDs(ids ...uint64) *AgentUpdate {
  323. au.mutation.RemoveKeyAgentIDs(ids...)
  324. return au
  325. }
  326. // RemoveKeyAgent removes "key_agent" edges to ApiKey entities.
  327. func (au *AgentUpdate) RemoveKeyAgent(a ...*ApiKey) *AgentUpdate {
  328. ids := make([]uint64, len(a))
  329. for i := range a {
  330. ids[i] = a[i].ID
  331. }
  332. return au.RemoveKeyAgentIDs(ids...)
  333. }
  334. // Save executes the query and returns the number of nodes affected by the update operation.
  335. func (au *AgentUpdate) Save(ctx context.Context) (int, error) {
  336. if err := au.defaults(); err != nil {
  337. return 0, err
  338. }
  339. return withHooks(ctx, au.sqlSave, au.mutation, au.hooks)
  340. }
  341. // SaveX is like Save, but panics if an error occurs.
  342. func (au *AgentUpdate) SaveX(ctx context.Context) int {
  343. affected, err := au.Save(ctx)
  344. if err != nil {
  345. panic(err)
  346. }
  347. return affected
  348. }
  349. // Exec executes the query.
  350. func (au *AgentUpdate) Exec(ctx context.Context) error {
  351. _, err := au.Save(ctx)
  352. return err
  353. }
  354. // ExecX is like Exec, but panics if an error occurs.
  355. func (au *AgentUpdate) ExecX(ctx context.Context) {
  356. if err := au.Exec(ctx); err != nil {
  357. panic(err)
  358. }
  359. }
  360. // defaults sets the default values of the builder before save.
  361. func (au *AgentUpdate) defaults() error {
  362. if _, ok := au.mutation.UpdatedAt(); !ok {
  363. if agent.UpdateDefaultUpdatedAt == nil {
  364. return fmt.Errorf("ent: uninitialized agent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  365. }
  366. v := agent.UpdateDefaultUpdatedAt()
  367. au.mutation.SetUpdatedAt(v)
  368. }
  369. return nil
  370. }
  371. // check runs all checks and user-defined validators on the builder.
  372. func (au *AgentUpdate) check() error {
  373. if v, ok := au.mutation.Name(); ok {
  374. if err := agent.NameValidator(v); err != nil {
  375. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
  376. }
  377. }
  378. if v, ok := au.mutation.Status(); ok {
  379. if err := agent.StatusValidator(v); err != nil {
  380. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
  381. }
  382. }
  383. if v, ok := au.mutation.OrganizationID(); ok {
  384. if err := agent.OrganizationIDValidator(v); err != nil {
  385. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
  386. }
  387. }
  388. if v, ok := au.mutation.DatasetID(); ok {
  389. if err := agent.DatasetIDValidator(v); err != nil {
  390. return &ValidationError{Name: "dataset_id", err: fmt.Errorf(`ent: validator failed for field "Agent.dataset_id": %w`, err)}
  391. }
  392. }
  393. if v, ok := au.mutation.CollectionID(); ok {
  394. if err := agent.CollectionIDValidator(v); err != nil {
  395. return &ValidationError{Name: "collection_id", err: fmt.Errorf(`ent: validator failed for field "Agent.collection_id": %w`, err)}
  396. }
  397. }
  398. return nil
  399. }
  400. func (au *AgentUpdate) sqlSave(ctx context.Context) (n int, err error) {
  401. if err := au.check(); err != nil {
  402. return n, err
  403. }
  404. _spec := sqlgraph.NewUpdateSpec(agent.Table, agent.Columns, sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64))
  405. if ps := au.mutation.predicates; len(ps) > 0 {
  406. _spec.Predicate = func(selector *sql.Selector) {
  407. for i := range ps {
  408. ps[i](selector)
  409. }
  410. }
  411. }
  412. if value, ok := au.mutation.UpdatedAt(); ok {
  413. _spec.SetField(agent.FieldUpdatedAt, field.TypeTime, value)
  414. }
  415. if value, ok := au.mutation.DeletedAt(); ok {
  416. _spec.SetField(agent.FieldDeletedAt, field.TypeTime, value)
  417. }
  418. if au.mutation.DeletedAtCleared() {
  419. _spec.ClearField(agent.FieldDeletedAt, field.TypeTime)
  420. }
  421. if value, ok := au.mutation.Name(); ok {
  422. _spec.SetField(agent.FieldName, field.TypeString, value)
  423. }
  424. if value, ok := au.mutation.Role(); ok {
  425. _spec.SetField(agent.FieldRole, field.TypeString, value)
  426. }
  427. if value, ok := au.mutation.Status(); ok {
  428. _spec.SetField(agent.FieldStatus, field.TypeInt, value)
  429. }
  430. if value, ok := au.mutation.AddedStatus(); ok {
  431. _spec.AddField(agent.FieldStatus, field.TypeInt, value)
  432. }
  433. if au.mutation.StatusCleared() {
  434. _spec.ClearField(agent.FieldStatus, field.TypeInt)
  435. }
  436. if value, ok := au.mutation.Background(); ok {
  437. _spec.SetField(agent.FieldBackground, field.TypeString, value)
  438. }
  439. if au.mutation.BackgroundCleared() {
  440. _spec.ClearField(agent.FieldBackground, field.TypeString)
  441. }
  442. if value, ok := au.mutation.Examples(); ok {
  443. _spec.SetField(agent.FieldExamples, field.TypeString, value)
  444. }
  445. if au.mutation.ExamplesCleared() {
  446. _spec.ClearField(agent.FieldExamples, field.TypeString)
  447. }
  448. if value, ok := au.mutation.OrganizationID(); ok {
  449. _spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
  450. }
  451. if value, ok := au.mutation.AddedOrganizationID(); ok {
  452. _spec.AddField(agent.FieldOrganizationID, field.TypeUint64, value)
  453. }
  454. if value, ok := au.mutation.DatasetID(); ok {
  455. _spec.SetField(agent.FieldDatasetID, field.TypeString, value)
  456. }
  457. if value, ok := au.mutation.CollectionID(); ok {
  458. _spec.SetField(agent.FieldCollectionID, field.TypeString, value)
  459. }
  460. if au.mutation.WxAgentCleared() {
  461. edge := &sqlgraph.EdgeSpec{
  462. Rel: sqlgraph.O2M,
  463. Inverse: false,
  464. Table: agent.WxAgentTable,
  465. Columns: []string{agent.WxAgentColumn},
  466. Bidi: false,
  467. Target: &sqlgraph.EdgeTarget{
  468. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  469. },
  470. }
  471. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  472. }
  473. if nodes := au.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !au.mutation.WxAgentCleared() {
  474. edge := &sqlgraph.EdgeSpec{
  475. Rel: sqlgraph.O2M,
  476. Inverse: false,
  477. Table: agent.WxAgentTable,
  478. Columns: []string{agent.WxAgentColumn},
  479. Bidi: false,
  480. Target: &sqlgraph.EdgeTarget{
  481. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  482. },
  483. }
  484. for _, k := range nodes {
  485. edge.Target.Nodes = append(edge.Target.Nodes, k)
  486. }
  487. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  488. }
  489. if nodes := au.mutation.WxAgentIDs(); len(nodes) > 0 {
  490. edge := &sqlgraph.EdgeSpec{
  491. Rel: sqlgraph.O2M,
  492. Inverse: false,
  493. Table: agent.WxAgentTable,
  494. Columns: []string{agent.WxAgentColumn},
  495. Bidi: false,
  496. Target: &sqlgraph.EdgeTarget{
  497. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  498. },
  499. }
  500. for _, k := range nodes {
  501. edge.Target.Nodes = append(edge.Target.Nodes, k)
  502. }
  503. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  504. }
  505. if au.mutation.TokenAgentCleared() {
  506. edge := &sqlgraph.EdgeSpec{
  507. Rel: sqlgraph.O2M,
  508. Inverse: false,
  509. Table: agent.TokenAgentTable,
  510. Columns: []string{agent.TokenAgentColumn},
  511. Bidi: false,
  512. Target: &sqlgraph.EdgeTarget{
  513. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  514. },
  515. }
  516. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  517. }
  518. if nodes := au.mutation.RemovedTokenAgentIDs(); len(nodes) > 0 && !au.mutation.TokenAgentCleared() {
  519. edge := &sqlgraph.EdgeSpec{
  520. Rel: sqlgraph.O2M,
  521. Inverse: false,
  522. Table: agent.TokenAgentTable,
  523. Columns: []string{agent.TokenAgentColumn},
  524. Bidi: false,
  525. Target: &sqlgraph.EdgeTarget{
  526. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  527. },
  528. }
  529. for _, k := range nodes {
  530. edge.Target.Nodes = append(edge.Target.Nodes, k)
  531. }
  532. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  533. }
  534. if nodes := au.mutation.TokenAgentIDs(); len(nodes) > 0 {
  535. edge := &sqlgraph.EdgeSpec{
  536. Rel: sqlgraph.O2M,
  537. Inverse: false,
  538. Table: agent.TokenAgentTable,
  539. Columns: []string{agent.TokenAgentColumn},
  540. Bidi: false,
  541. Target: &sqlgraph.EdgeTarget{
  542. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  543. },
  544. }
  545. for _, k := range nodes {
  546. edge.Target.Nodes = append(edge.Target.Nodes, k)
  547. }
  548. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  549. }
  550. if au.mutation.WaAgentCleared() {
  551. edge := &sqlgraph.EdgeSpec{
  552. Rel: sqlgraph.O2M,
  553. Inverse: false,
  554. Table: agent.WaAgentTable,
  555. Columns: []string{agent.WaAgentColumn},
  556. Bidi: false,
  557. Target: &sqlgraph.EdgeTarget{
  558. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  559. },
  560. }
  561. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  562. }
  563. if nodes := au.mutation.RemovedWaAgentIDs(); len(nodes) > 0 && !au.mutation.WaAgentCleared() {
  564. edge := &sqlgraph.EdgeSpec{
  565. Rel: sqlgraph.O2M,
  566. Inverse: false,
  567. Table: agent.WaAgentTable,
  568. Columns: []string{agent.WaAgentColumn},
  569. Bidi: false,
  570. Target: &sqlgraph.EdgeTarget{
  571. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  572. },
  573. }
  574. for _, k := range nodes {
  575. edge.Target.Nodes = append(edge.Target.Nodes, k)
  576. }
  577. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  578. }
  579. if nodes := au.mutation.WaAgentIDs(); len(nodes) > 0 {
  580. edge := &sqlgraph.EdgeSpec{
  581. Rel: sqlgraph.O2M,
  582. Inverse: false,
  583. Table: agent.WaAgentTable,
  584. Columns: []string{agent.WaAgentColumn},
  585. Bidi: false,
  586. Target: &sqlgraph.EdgeTarget{
  587. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  588. },
  589. }
  590. for _, k := range nodes {
  591. edge.Target.Nodes = append(edge.Target.Nodes, k)
  592. }
  593. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  594. }
  595. if au.mutation.XjsAgentCleared() {
  596. edge := &sqlgraph.EdgeSpec{
  597. Rel: sqlgraph.O2M,
  598. Inverse: false,
  599. Table: agent.XjsAgentTable,
  600. Columns: []string{agent.XjsAgentColumn},
  601. Bidi: false,
  602. Target: &sqlgraph.EdgeTarget{
  603. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  604. },
  605. }
  606. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  607. }
  608. if nodes := au.mutation.RemovedXjsAgentIDs(); len(nodes) > 0 && !au.mutation.XjsAgentCleared() {
  609. edge := &sqlgraph.EdgeSpec{
  610. Rel: sqlgraph.O2M,
  611. Inverse: false,
  612. Table: agent.XjsAgentTable,
  613. Columns: []string{agent.XjsAgentColumn},
  614. Bidi: false,
  615. Target: &sqlgraph.EdgeTarget{
  616. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  617. },
  618. }
  619. for _, k := range nodes {
  620. edge.Target.Nodes = append(edge.Target.Nodes, k)
  621. }
  622. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  623. }
  624. if nodes := au.mutation.XjsAgentIDs(); len(nodes) > 0 {
  625. edge := &sqlgraph.EdgeSpec{
  626. Rel: sqlgraph.O2M,
  627. Inverse: false,
  628. Table: agent.XjsAgentTable,
  629. Columns: []string{agent.XjsAgentColumn},
  630. Bidi: false,
  631. Target: &sqlgraph.EdgeTarget{
  632. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  633. },
  634. }
  635. for _, k := range nodes {
  636. edge.Target.Nodes = append(edge.Target.Nodes, k)
  637. }
  638. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  639. }
  640. if au.mutation.KeyAgentCleared() {
  641. edge := &sqlgraph.EdgeSpec{
  642. Rel: sqlgraph.O2M,
  643. Inverse: false,
  644. Table: agent.KeyAgentTable,
  645. Columns: []string{agent.KeyAgentColumn},
  646. Bidi: false,
  647. Target: &sqlgraph.EdgeTarget{
  648. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  649. },
  650. }
  651. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  652. }
  653. if nodes := au.mutation.RemovedKeyAgentIDs(); len(nodes) > 0 && !au.mutation.KeyAgentCleared() {
  654. edge := &sqlgraph.EdgeSpec{
  655. Rel: sqlgraph.O2M,
  656. Inverse: false,
  657. Table: agent.KeyAgentTable,
  658. Columns: []string{agent.KeyAgentColumn},
  659. Bidi: false,
  660. Target: &sqlgraph.EdgeTarget{
  661. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  662. },
  663. }
  664. for _, k := range nodes {
  665. edge.Target.Nodes = append(edge.Target.Nodes, k)
  666. }
  667. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  668. }
  669. if nodes := au.mutation.KeyAgentIDs(); len(nodes) > 0 {
  670. edge := &sqlgraph.EdgeSpec{
  671. Rel: sqlgraph.O2M,
  672. Inverse: false,
  673. Table: agent.KeyAgentTable,
  674. Columns: []string{agent.KeyAgentColumn},
  675. Bidi: false,
  676. Target: &sqlgraph.EdgeTarget{
  677. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  678. },
  679. }
  680. for _, k := range nodes {
  681. edge.Target.Nodes = append(edge.Target.Nodes, k)
  682. }
  683. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  684. }
  685. if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil {
  686. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  687. err = &NotFoundError{agent.Label}
  688. } else if sqlgraph.IsConstraintError(err) {
  689. err = &ConstraintError{msg: err.Error(), wrap: err}
  690. }
  691. return 0, err
  692. }
  693. au.mutation.done = true
  694. return n, nil
  695. }
  696. // AgentUpdateOne is the builder for updating a single Agent entity.
  697. type AgentUpdateOne struct {
  698. config
  699. fields []string
  700. hooks []Hook
  701. mutation *AgentMutation
  702. }
  703. // SetUpdatedAt sets the "updated_at" field.
  704. func (auo *AgentUpdateOne) SetUpdatedAt(t time.Time) *AgentUpdateOne {
  705. auo.mutation.SetUpdatedAt(t)
  706. return auo
  707. }
  708. // SetDeletedAt sets the "deleted_at" field.
  709. func (auo *AgentUpdateOne) SetDeletedAt(t time.Time) *AgentUpdateOne {
  710. auo.mutation.SetDeletedAt(t)
  711. return auo
  712. }
  713. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  714. func (auo *AgentUpdateOne) SetNillableDeletedAt(t *time.Time) *AgentUpdateOne {
  715. if t != nil {
  716. auo.SetDeletedAt(*t)
  717. }
  718. return auo
  719. }
  720. // ClearDeletedAt clears the value of the "deleted_at" field.
  721. func (auo *AgentUpdateOne) ClearDeletedAt() *AgentUpdateOne {
  722. auo.mutation.ClearDeletedAt()
  723. return auo
  724. }
  725. // SetName sets the "name" field.
  726. func (auo *AgentUpdateOne) SetName(s string) *AgentUpdateOne {
  727. auo.mutation.SetName(s)
  728. return auo
  729. }
  730. // SetNillableName sets the "name" field if the given value is not nil.
  731. func (auo *AgentUpdateOne) SetNillableName(s *string) *AgentUpdateOne {
  732. if s != nil {
  733. auo.SetName(*s)
  734. }
  735. return auo
  736. }
  737. // SetRole sets the "role" field.
  738. func (auo *AgentUpdateOne) SetRole(s string) *AgentUpdateOne {
  739. auo.mutation.SetRole(s)
  740. return auo
  741. }
  742. // SetNillableRole sets the "role" field if the given value is not nil.
  743. func (auo *AgentUpdateOne) SetNillableRole(s *string) *AgentUpdateOne {
  744. if s != nil {
  745. auo.SetRole(*s)
  746. }
  747. return auo
  748. }
  749. // SetStatus sets the "status" field.
  750. func (auo *AgentUpdateOne) SetStatus(i int) *AgentUpdateOne {
  751. auo.mutation.ResetStatus()
  752. auo.mutation.SetStatus(i)
  753. return auo
  754. }
  755. // SetNillableStatus sets the "status" field if the given value is not nil.
  756. func (auo *AgentUpdateOne) SetNillableStatus(i *int) *AgentUpdateOne {
  757. if i != nil {
  758. auo.SetStatus(*i)
  759. }
  760. return auo
  761. }
  762. // AddStatus adds i to the "status" field.
  763. func (auo *AgentUpdateOne) AddStatus(i int) *AgentUpdateOne {
  764. auo.mutation.AddStatus(i)
  765. return auo
  766. }
  767. // ClearStatus clears the value of the "status" field.
  768. func (auo *AgentUpdateOne) ClearStatus() *AgentUpdateOne {
  769. auo.mutation.ClearStatus()
  770. return auo
  771. }
  772. // SetBackground sets the "background" field.
  773. func (auo *AgentUpdateOne) SetBackground(s string) *AgentUpdateOne {
  774. auo.mutation.SetBackground(s)
  775. return auo
  776. }
  777. // SetNillableBackground sets the "background" field if the given value is not nil.
  778. func (auo *AgentUpdateOne) SetNillableBackground(s *string) *AgentUpdateOne {
  779. if s != nil {
  780. auo.SetBackground(*s)
  781. }
  782. return auo
  783. }
  784. // ClearBackground clears the value of the "background" field.
  785. func (auo *AgentUpdateOne) ClearBackground() *AgentUpdateOne {
  786. auo.mutation.ClearBackground()
  787. return auo
  788. }
  789. // SetExamples sets the "examples" field.
  790. func (auo *AgentUpdateOne) SetExamples(s string) *AgentUpdateOne {
  791. auo.mutation.SetExamples(s)
  792. return auo
  793. }
  794. // SetNillableExamples sets the "examples" field if the given value is not nil.
  795. func (auo *AgentUpdateOne) SetNillableExamples(s *string) *AgentUpdateOne {
  796. if s != nil {
  797. auo.SetExamples(*s)
  798. }
  799. return auo
  800. }
  801. // ClearExamples clears the value of the "examples" field.
  802. func (auo *AgentUpdateOne) ClearExamples() *AgentUpdateOne {
  803. auo.mutation.ClearExamples()
  804. return auo
  805. }
  806. // SetOrganizationID sets the "organization_id" field.
  807. func (auo *AgentUpdateOne) SetOrganizationID(u uint64) *AgentUpdateOne {
  808. auo.mutation.ResetOrganizationID()
  809. auo.mutation.SetOrganizationID(u)
  810. return auo
  811. }
  812. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  813. func (auo *AgentUpdateOne) SetNillableOrganizationID(u *uint64) *AgentUpdateOne {
  814. if u != nil {
  815. auo.SetOrganizationID(*u)
  816. }
  817. return auo
  818. }
  819. // AddOrganizationID adds u to the "organization_id" field.
  820. func (auo *AgentUpdateOne) AddOrganizationID(u int64) *AgentUpdateOne {
  821. auo.mutation.AddOrganizationID(u)
  822. return auo
  823. }
  824. // SetDatasetID sets the "dataset_id" field.
  825. func (auo *AgentUpdateOne) SetDatasetID(s string) *AgentUpdateOne {
  826. auo.mutation.SetDatasetID(s)
  827. return auo
  828. }
  829. // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
  830. func (auo *AgentUpdateOne) SetNillableDatasetID(s *string) *AgentUpdateOne {
  831. if s != nil {
  832. auo.SetDatasetID(*s)
  833. }
  834. return auo
  835. }
  836. // SetCollectionID sets the "collection_id" field.
  837. func (auo *AgentUpdateOne) SetCollectionID(s string) *AgentUpdateOne {
  838. auo.mutation.SetCollectionID(s)
  839. return auo
  840. }
  841. // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
  842. func (auo *AgentUpdateOne) SetNillableCollectionID(s *string) *AgentUpdateOne {
  843. if s != nil {
  844. auo.SetCollectionID(*s)
  845. }
  846. return auo
  847. }
  848. // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
  849. func (auo *AgentUpdateOne) AddWxAgentIDs(ids ...uint64) *AgentUpdateOne {
  850. auo.mutation.AddWxAgentIDs(ids...)
  851. return auo
  852. }
  853. // AddWxAgent adds the "wx_agent" edges to the Wx entity.
  854. func (auo *AgentUpdateOne) AddWxAgent(w ...*Wx) *AgentUpdateOne {
  855. ids := make([]uint64, len(w))
  856. for i := range w {
  857. ids[i] = w[i].ID
  858. }
  859. return auo.AddWxAgentIDs(ids...)
  860. }
  861. // AddTokenAgentIDs adds the "token_agent" edge to the Token entity by IDs.
  862. func (auo *AgentUpdateOne) AddTokenAgentIDs(ids ...uint64) *AgentUpdateOne {
  863. auo.mutation.AddTokenAgentIDs(ids...)
  864. return auo
  865. }
  866. // AddTokenAgent adds the "token_agent" edges to the Token entity.
  867. func (auo *AgentUpdateOne) AddTokenAgent(t ...*Token) *AgentUpdateOne {
  868. ids := make([]uint64, len(t))
  869. for i := range t {
  870. ids[i] = t[i].ID
  871. }
  872. return auo.AddTokenAgentIDs(ids...)
  873. }
  874. // AddWaAgentIDs adds the "wa_agent" edge to the Whatsapp entity by IDs.
  875. func (auo *AgentUpdateOne) AddWaAgentIDs(ids ...uint64) *AgentUpdateOne {
  876. auo.mutation.AddWaAgentIDs(ids...)
  877. return auo
  878. }
  879. // AddWaAgent adds the "wa_agent" edges to the Whatsapp entity.
  880. func (auo *AgentUpdateOne) AddWaAgent(w ...*Whatsapp) *AgentUpdateOne {
  881. ids := make([]uint64, len(w))
  882. for i := range w {
  883. ids[i] = w[i].ID
  884. }
  885. return auo.AddWaAgentIDs(ids...)
  886. }
  887. // AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by IDs.
  888. func (auo *AgentUpdateOne) AddXjsAgentIDs(ids ...uint64) *AgentUpdateOne {
  889. auo.mutation.AddXjsAgentIDs(ids...)
  890. return auo
  891. }
  892. // AddXjsAgent adds the "xjs_agent" edges to the XunjiService entity.
  893. func (auo *AgentUpdateOne) AddXjsAgent(x ...*XunjiService) *AgentUpdateOne {
  894. ids := make([]uint64, len(x))
  895. for i := range x {
  896. ids[i] = x[i].ID
  897. }
  898. return auo.AddXjsAgentIDs(ids...)
  899. }
  900. // AddKeyAgentIDs adds the "key_agent" edge to the ApiKey entity by IDs.
  901. func (auo *AgentUpdateOne) AddKeyAgentIDs(ids ...uint64) *AgentUpdateOne {
  902. auo.mutation.AddKeyAgentIDs(ids...)
  903. return auo
  904. }
  905. // AddKeyAgent adds the "key_agent" edges to the ApiKey entity.
  906. func (auo *AgentUpdateOne) AddKeyAgent(a ...*ApiKey) *AgentUpdateOne {
  907. ids := make([]uint64, len(a))
  908. for i := range a {
  909. ids[i] = a[i].ID
  910. }
  911. return auo.AddKeyAgentIDs(ids...)
  912. }
  913. // Mutation returns the AgentMutation object of the builder.
  914. func (auo *AgentUpdateOne) Mutation() *AgentMutation {
  915. return auo.mutation
  916. }
  917. // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
  918. func (auo *AgentUpdateOne) ClearWxAgent() *AgentUpdateOne {
  919. auo.mutation.ClearWxAgent()
  920. return auo
  921. }
  922. // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
  923. func (auo *AgentUpdateOne) RemoveWxAgentIDs(ids ...uint64) *AgentUpdateOne {
  924. auo.mutation.RemoveWxAgentIDs(ids...)
  925. return auo
  926. }
  927. // RemoveWxAgent removes "wx_agent" edges to Wx entities.
  928. func (auo *AgentUpdateOne) RemoveWxAgent(w ...*Wx) *AgentUpdateOne {
  929. ids := make([]uint64, len(w))
  930. for i := range w {
  931. ids[i] = w[i].ID
  932. }
  933. return auo.RemoveWxAgentIDs(ids...)
  934. }
  935. // ClearTokenAgent clears all "token_agent" edges to the Token entity.
  936. func (auo *AgentUpdateOne) ClearTokenAgent() *AgentUpdateOne {
  937. auo.mutation.ClearTokenAgent()
  938. return auo
  939. }
  940. // RemoveTokenAgentIDs removes the "token_agent" edge to Token entities by IDs.
  941. func (auo *AgentUpdateOne) RemoveTokenAgentIDs(ids ...uint64) *AgentUpdateOne {
  942. auo.mutation.RemoveTokenAgentIDs(ids...)
  943. return auo
  944. }
  945. // RemoveTokenAgent removes "token_agent" edges to Token entities.
  946. func (auo *AgentUpdateOne) RemoveTokenAgent(t ...*Token) *AgentUpdateOne {
  947. ids := make([]uint64, len(t))
  948. for i := range t {
  949. ids[i] = t[i].ID
  950. }
  951. return auo.RemoveTokenAgentIDs(ids...)
  952. }
  953. // ClearWaAgent clears all "wa_agent" edges to the Whatsapp entity.
  954. func (auo *AgentUpdateOne) ClearWaAgent() *AgentUpdateOne {
  955. auo.mutation.ClearWaAgent()
  956. return auo
  957. }
  958. // RemoveWaAgentIDs removes the "wa_agent" edge to Whatsapp entities by IDs.
  959. func (auo *AgentUpdateOne) RemoveWaAgentIDs(ids ...uint64) *AgentUpdateOne {
  960. auo.mutation.RemoveWaAgentIDs(ids...)
  961. return auo
  962. }
  963. // RemoveWaAgent removes "wa_agent" edges to Whatsapp entities.
  964. func (auo *AgentUpdateOne) RemoveWaAgent(w ...*Whatsapp) *AgentUpdateOne {
  965. ids := make([]uint64, len(w))
  966. for i := range w {
  967. ids[i] = w[i].ID
  968. }
  969. return auo.RemoveWaAgentIDs(ids...)
  970. }
  971. // ClearXjsAgent clears all "xjs_agent" edges to the XunjiService entity.
  972. func (auo *AgentUpdateOne) ClearXjsAgent() *AgentUpdateOne {
  973. auo.mutation.ClearXjsAgent()
  974. return auo
  975. }
  976. // RemoveXjsAgentIDs removes the "xjs_agent" edge to XunjiService entities by IDs.
  977. func (auo *AgentUpdateOne) RemoveXjsAgentIDs(ids ...uint64) *AgentUpdateOne {
  978. auo.mutation.RemoveXjsAgentIDs(ids...)
  979. return auo
  980. }
  981. // RemoveXjsAgent removes "xjs_agent" edges to XunjiService entities.
  982. func (auo *AgentUpdateOne) RemoveXjsAgent(x ...*XunjiService) *AgentUpdateOne {
  983. ids := make([]uint64, len(x))
  984. for i := range x {
  985. ids[i] = x[i].ID
  986. }
  987. return auo.RemoveXjsAgentIDs(ids...)
  988. }
  989. // ClearKeyAgent clears all "key_agent" edges to the ApiKey entity.
  990. func (auo *AgentUpdateOne) ClearKeyAgent() *AgentUpdateOne {
  991. auo.mutation.ClearKeyAgent()
  992. return auo
  993. }
  994. // RemoveKeyAgentIDs removes the "key_agent" edge to ApiKey entities by IDs.
  995. func (auo *AgentUpdateOne) RemoveKeyAgentIDs(ids ...uint64) *AgentUpdateOne {
  996. auo.mutation.RemoveKeyAgentIDs(ids...)
  997. return auo
  998. }
  999. // RemoveKeyAgent removes "key_agent" edges to ApiKey entities.
  1000. func (auo *AgentUpdateOne) RemoveKeyAgent(a ...*ApiKey) *AgentUpdateOne {
  1001. ids := make([]uint64, len(a))
  1002. for i := range a {
  1003. ids[i] = a[i].ID
  1004. }
  1005. return auo.RemoveKeyAgentIDs(ids...)
  1006. }
  1007. // Where appends a list predicates to the AgentUpdate builder.
  1008. func (auo *AgentUpdateOne) Where(ps ...predicate.Agent) *AgentUpdateOne {
  1009. auo.mutation.Where(ps...)
  1010. return auo
  1011. }
  1012. // Select allows selecting one or more fields (columns) of the returned entity.
  1013. // The default is selecting all fields defined in the entity schema.
  1014. func (auo *AgentUpdateOne) Select(field string, fields ...string) *AgentUpdateOne {
  1015. auo.fields = append([]string{field}, fields...)
  1016. return auo
  1017. }
  1018. // Save executes the query and returns the updated Agent entity.
  1019. func (auo *AgentUpdateOne) Save(ctx context.Context) (*Agent, error) {
  1020. if err := auo.defaults(); err != nil {
  1021. return nil, err
  1022. }
  1023. return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks)
  1024. }
  1025. // SaveX is like Save, but panics if an error occurs.
  1026. func (auo *AgentUpdateOne) SaveX(ctx context.Context) *Agent {
  1027. node, err := auo.Save(ctx)
  1028. if err != nil {
  1029. panic(err)
  1030. }
  1031. return node
  1032. }
  1033. // Exec executes the query on the entity.
  1034. func (auo *AgentUpdateOne) Exec(ctx context.Context) error {
  1035. _, err := auo.Save(ctx)
  1036. return err
  1037. }
  1038. // ExecX is like Exec, but panics if an error occurs.
  1039. func (auo *AgentUpdateOne) ExecX(ctx context.Context) {
  1040. if err := auo.Exec(ctx); err != nil {
  1041. panic(err)
  1042. }
  1043. }
  1044. // defaults sets the default values of the builder before save.
  1045. func (auo *AgentUpdateOne) defaults() error {
  1046. if _, ok := auo.mutation.UpdatedAt(); !ok {
  1047. if agent.UpdateDefaultUpdatedAt == nil {
  1048. return fmt.Errorf("ent: uninitialized agent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  1049. }
  1050. v := agent.UpdateDefaultUpdatedAt()
  1051. auo.mutation.SetUpdatedAt(v)
  1052. }
  1053. return nil
  1054. }
  1055. // check runs all checks and user-defined validators on the builder.
  1056. func (auo *AgentUpdateOne) check() error {
  1057. if v, ok := auo.mutation.Name(); ok {
  1058. if err := agent.NameValidator(v); err != nil {
  1059. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
  1060. }
  1061. }
  1062. if v, ok := auo.mutation.Status(); ok {
  1063. if err := agent.StatusValidator(v); err != nil {
  1064. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
  1065. }
  1066. }
  1067. if v, ok := auo.mutation.OrganizationID(); ok {
  1068. if err := agent.OrganizationIDValidator(v); err != nil {
  1069. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
  1070. }
  1071. }
  1072. if v, ok := auo.mutation.DatasetID(); ok {
  1073. if err := agent.DatasetIDValidator(v); err != nil {
  1074. return &ValidationError{Name: "dataset_id", err: fmt.Errorf(`ent: validator failed for field "Agent.dataset_id": %w`, err)}
  1075. }
  1076. }
  1077. if v, ok := auo.mutation.CollectionID(); ok {
  1078. if err := agent.CollectionIDValidator(v); err != nil {
  1079. return &ValidationError{Name: "collection_id", err: fmt.Errorf(`ent: validator failed for field "Agent.collection_id": %w`, err)}
  1080. }
  1081. }
  1082. return nil
  1083. }
  1084. func (auo *AgentUpdateOne) sqlSave(ctx context.Context) (_node *Agent, err error) {
  1085. if err := auo.check(); err != nil {
  1086. return _node, err
  1087. }
  1088. _spec := sqlgraph.NewUpdateSpec(agent.Table, agent.Columns, sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64))
  1089. id, ok := auo.mutation.ID()
  1090. if !ok {
  1091. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Agent.id" for update`)}
  1092. }
  1093. _spec.Node.ID.Value = id
  1094. if fields := auo.fields; len(fields) > 0 {
  1095. _spec.Node.Columns = make([]string, 0, len(fields))
  1096. _spec.Node.Columns = append(_spec.Node.Columns, agent.FieldID)
  1097. for _, f := range fields {
  1098. if !agent.ValidColumn(f) {
  1099. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  1100. }
  1101. if f != agent.FieldID {
  1102. _spec.Node.Columns = append(_spec.Node.Columns, f)
  1103. }
  1104. }
  1105. }
  1106. if ps := auo.mutation.predicates; len(ps) > 0 {
  1107. _spec.Predicate = func(selector *sql.Selector) {
  1108. for i := range ps {
  1109. ps[i](selector)
  1110. }
  1111. }
  1112. }
  1113. if value, ok := auo.mutation.UpdatedAt(); ok {
  1114. _spec.SetField(agent.FieldUpdatedAt, field.TypeTime, value)
  1115. }
  1116. if value, ok := auo.mutation.DeletedAt(); ok {
  1117. _spec.SetField(agent.FieldDeletedAt, field.TypeTime, value)
  1118. }
  1119. if auo.mutation.DeletedAtCleared() {
  1120. _spec.ClearField(agent.FieldDeletedAt, field.TypeTime)
  1121. }
  1122. if value, ok := auo.mutation.Name(); ok {
  1123. _spec.SetField(agent.FieldName, field.TypeString, value)
  1124. }
  1125. if value, ok := auo.mutation.Role(); ok {
  1126. _spec.SetField(agent.FieldRole, field.TypeString, value)
  1127. }
  1128. if value, ok := auo.mutation.Status(); ok {
  1129. _spec.SetField(agent.FieldStatus, field.TypeInt, value)
  1130. }
  1131. if value, ok := auo.mutation.AddedStatus(); ok {
  1132. _spec.AddField(agent.FieldStatus, field.TypeInt, value)
  1133. }
  1134. if auo.mutation.StatusCleared() {
  1135. _spec.ClearField(agent.FieldStatus, field.TypeInt)
  1136. }
  1137. if value, ok := auo.mutation.Background(); ok {
  1138. _spec.SetField(agent.FieldBackground, field.TypeString, value)
  1139. }
  1140. if auo.mutation.BackgroundCleared() {
  1141. _spec.ClearField(agent.FieldBackground, field.TypeString)
  1142. }
  1143. if value, ok := auo.mutation.Examples(); ok {
  1144. _spec.SetField(agent.FieldExamples, field.TypeString, value)
  1145. }
  1146. if auo.mutation.ExamplesCleared() {
  1147. _spec.ClearField(agent.FieldExamples, field.TypeString)
  1148. }
  1149. if value, ok := auo.mutation.OrganizationID(); ok {
  1150. _spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
  1151. }
  1152. if value, ok := auo.mutation.AddedOrganizationID(); ok {
  1153. _spec.AddField(agent.FieldOrganizationID, field.TypeUint64, value)
  1154. }
  1155. if value, ok := auo.mutation.DatasetID(); ok {
  1156. _spec.SetField(agent.FieldDatasetID, field.TypeString, value)
  1157. }
  1158. if value, ok := auo.mutation.CollectionID(); ok {
  1159. _spec.SetField(agent.FieldCollectionID, field.TypeString, value)
  1160. }
  1161. if auo.mutation.WxAgentCleared() {
  1162. edge := &sqlgraph.EdgeSpec{
  1163. Rel: sqlgraph.O2M,
  1164. Inverse: false,
  1165. Table: agent.WxAgentTable,
  1166. Columns: []string{agent.WxAgentColumn},
  1167. Bidi: false,
  1168. Target: &sqlgraph.EdgeTarget{
  1169. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  1170. },
  1171. }
  1172. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1173. }
  1174. if nodes := auo.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !auo.mutation.WxAgentCleared() {
  1175. edge := &sqlgraph.EdgeSpec{
  1176. Rel: sqlgraph.O2M,
  1177. Inverse: false,
  1178. Table: agent.WxAgentTable,
  1179. Columns: []string{agent.WxAgentColumn},
  1180. Bidi: false,
  1181. Target: &sqlgraph.EdgeTarget{
  1182. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  1183. },
  1184. }
  1185. for _, k := range nodes {
  1186. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1187. }
  1188. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1189. }
  1190. if nodes := auo.mutation.WxAgentIDs(); len(nodes) > 0 {
  1191. edge := &sqlgraph.EdgeSpec{
  1192. Rel: sqlgraph.O2M,
  1193. Inverse: false,
  1194. Table: agent.WxAgentTable,
  1195. Columns: []string{agent.WxAgentColumn},
  1196. Bidi: false,
  1197. Target: &sqlgraph.EdgeTarget{
  1198. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  1199. },
  1200. }
  1201. for _, k := range nodes {
  1202. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1203. }
  1204. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1205. }
  1206. if auo.mutation.TokenAgentCleared() {
  1207. edge := &sqlgraph.EdgeSpec{
  1208. Rel: sqlgraph.O2M,
  1209. Inverse: false,
  1210. Table: agent.TokenAgentTable,
  1211. Columns: []string{agent.TokenAgentColumn},
  1212. Bidi: false,
  1213. Target: &sqlgraph.EdgeTarget{
  1214. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  1215. },
  1216. }
  1217. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1218. }
  1219. if nodes := auo.mutation.RemovedTokenAgentIDs(); len(nodes) > 0 && !auo.mutation.TokenAgentCleared() {
  1220. edge := &sqlgraph.EdgeSpec{
  1221. Rel: sqlgraph.O2M,
  1222. Inverse: false,
  1223. Table: agent.TokenAgentTable,
  1224. Columns: []string{agent.TokenAgentColumn},
  1225. Bidi: false,
  1226. Target: &sqlgraph.EdgeTarget{
  1227. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  1228. },
  1229. }
  1230. for _, k := range nodes {
  1231. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1232. }
  1233. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1234. }
  1235. if nodes := auo.mutation.TokenAgentIDs(); len(nodes) > 0 {
  1236. edge := &sqlgraph.EdgeSpec{
  1237. Rel: sqlgraph.O2M,
  1238. Inverse: false,
  1239. Table: agent.TokenAgentTable,
  1240. Columns: []string{agent.TokenAgentColumn},
  1241. Bidi: false,
  1242. Target: &sqlgraph.EdgeTarget{
  1243. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  1244. },
  1245. }
  1246. for _, k := range nodes {
  1247. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1248. }
  1249. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1250. }
  1251. if auo.mutation.WaAgentCleared() {
  1252. edge := &sqlgraph.EdgeSpec{
  1253. Rel: sqlgraph.O2M,
  1254. Inverse: false,
  1255. Table: agent.WaAgentTable,
  1256. Columns: []string{agent.WaAgentColumn},
  1257. Bidi: false,
  1258. Target: &sqlgraph.EdgeTarget{
  1259. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  1260. },
  1261. }
  1262. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1263. }
  1264. if nodes := auo.mutation.RemovedWaAgentIDs(); len(nodes) > 0 && !auo.mutation.WaAgentCleared() {
  1265. edge := &sqlgraph.EdgeSpec{
  1266. Rel: sqlgraph.O2M,
  1267. Inverse: false,
  1268. Table: agent.WaAgentTable,
  1269. Columns: []string{agent.WaAgentColumn},
  1270. Bidi: false,
  1271. Target: &sqlgraph.EdgeTarget{
  1272. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  1273. },
  1274. }
  1275. for _, k := range nodes {
  1276. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1277. }
  1278. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1279. }
  1280. if nodes := auo.mutation.WaAgentIDs(); len(nodes) > 0 {
  1281. edge := &sqlgraph.EdgeSpec{
  1282. Rel: sqlgraph.O2M,
  1283. Inverse: false,
  1284. Table: agent.WaAgentTable,
  1285. Columns: []string{agent.WaAgentColumn},
  1286. Bidi: false,
  1287. Target: &sqlgraph.EdgeTarget{
  1288. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  1289. },
  1290. }
  1291. for _, k := range nodes {
  1292. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1293. }
  1294. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1295. }
  1296. if auo.mutation.XjsAgentCleared() {
  1297. edge := &sqlgraph.EdgeSpec{
  1298. Rel: sqlgraph.O2M,
  1299. Inverse: false,
  1300. Table: agent.XjsAgentTable,
  1301. Columns: []string{agent.XjsAgentColumn},
  1302. Bidi: false,
  1303. Target: &sqlgraph.EdgeTarget{
  1304. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1305. },
  1306. }
  1307. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1308. }
  1309. if nodes := auo.mutation.RemovedXjsAgentIDs(); len(nodes) > 0 && !auo.mutation.XjsAgentCleared() {
  1310. edge := &sqlgraph.EdgeSpec{
  1311. Rel: sqlgraph.O2M,
  1312. Inverse: false,
  1313. Table: agent.XjsAgentTable,
  1314. Columns: []string{agent.XjsAgentColumn},
  1315. Bidi: false,
  1316. Target: &sqlgraph.EdgeTarget{
  1317. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1318. },
  1319. }
  1320. for _, k := range nodes {
  1321. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1322. }
  1323. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1324. }
  1325. if nodes := auo.mutation.XjsAgentIDs(); len(nodes) > 0 {
  1326. edge := &sqlgraph.EdgeSpec{
  1327. Rel: sqlgraph.O2M,
  1328. Inverse: false,
  1329. Table: agent.XjsAgentTable,
  1330. Columns: []string{agent.XjsAgentColumn},
  1331. Bidi: false,
  1332. Target: &sqlgraph.EdgeTarget{
  1333. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1334. },
  1335. }
  1336. for _, k := range nodes {
  1337. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1338. }
  1339. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1340. }
  1341. if auo.mutation.KeyAgentCleared() {
  1342. edge := &sqlgraph.EdgeSpec{
  1343. Rel: sqlgraph.O2M,
  1344. Inverse: false,
  1345. Table: agent.KeyAgentTable,
  1346. Columns: []string{agent.KeyAgentColumn},
  1347. Bidi: false,
  1348. Target: &sqlgraph.EdgeTarget{
  1349. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  1350. },
  1351. }
  1352. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1353. }
  1354. if nodes := auo.mutation.RemovedKeyAgentIDs(); len(nodes) > 0 && !auo.mutation.KeyAgentCleared() {
  1355. edge := &sqlgraph.EdgeSpec{
  1356. Rel: sqlgraph.O2M,
  1357. Inverse: false,
  1358. Table: agent.KeyAgentTable,
  1359. Columns: []string{agent.KeyAgentColumn},
  1360. Bidi: false,
  1361. Target: &sqlgraph.EdgeTarget{
  1362. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  1363. },
  1364. }
  1365. for _, k := range nodes {
  1366. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1367. }
  1368. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1369. }
  1370. if nodes := auo.mutation.KeyAgentIDs(); len(nodes) > 0 {
  1371. edge := &sqlgraph.EdgeSpec{
  1372. Rel: sqlgraph.O2M,
  1373. Inverse: false,
  1374. Table: agent.KeyAgentTable,
  1375. Columns: []string{agent.KeyAgentColumn},
  1376. Bidi: false,
  1377. Target: &sqlgraph.EdgeTarget{
  1378. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  1379. },
  1380. }
  1381. for _, k := range nodes {
  1382. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1383. }
  1384. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1385. }
  1386. _node = &Agent{config: auo.config}
  1387. _spec.Assign = _node.assignValues
  1388. _spec.ScanValues = _node.scanValues
  1389. if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
  1390. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1391. err = &NotFoundError{agent.Label}
  1392. } else if sqlgraph.IsConstraintError(err) {
  1393. err = &ConstraintError{msg: err.Error(), wrap: err}
  1394. }
  1395. return nil, err
  1396. }
  1397. auo.mutation.done = true
  1398. return _node, nil
  1399. }