agent_update.go 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  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. }
  607. if au.mutation.KeyAgentCleared() {
  608. edge := &sqlgraph.EdgeSpec{
  609. Rel: sqlgraph.O2M,
  610. Inverse: false,
  611. Table: agent.KeyAgentTable,
  612. Columns: []string{agent.KeyAgentColumn},
  613. Bidi: false,
  614. Target: &sqlgraph.EdgeTarget{
  615. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  616. },
  617. }
  618. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  619. }
  620. if nodes := au.mutation.RemovedXjsAgentIDs(); len(nodes) > 0 && !au.mutation.XjsAgentCleared() {
  621. edge := &sqlgraph.EdgeSpec{
  622. Rel: sqlgraph.O2M,
  623. Inverse: false,
  624. Table: agent.XjsAgentTable,
  625. Columns: []string{agent.XjsAgentColumn},
  626. Bidi: false,
  627. Target: &sqlgraph.EdgeTarget{
  628. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  629. },
  630. }
  631. }
  632. if nodes := au.mutation.RemovedKeyAgentIDs(); len(nodes) > 0 && !au.mutation.KeyAgentCleared() {
  633. edge := &sqlgraph.EdgeSpec{
  634. Rel: sqlgraph.O2M,
  635. Inverse: false,
  636. Table: agent.KeyAgentTable,
  637. Columns: []string{agent.KeyAgentColumn},
  638. Bidi: false,
  639. Target: &sqlgraph.EdgeTarget{
  640. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  641. },
  642. }
  643. for _, k := range nodes {
  644. edge.Target.Nodes = append(edge.Target.Nodes, k)
  645. }
  646. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  647. }
  648. if nodes := au.mutation.XjsAgentIDs(); len(nodes) > 0 {
  649. edge := &sqlgraph.EdgeSpec{
  650. Rel: sqlgraph.O2M,
  651. Inverse: false,
  652. Table: agent.XjsAgentTable,
  653. Columns: []string{agent.XjsAgentColumn},
  654. Bidi: false,
  655. Target: &sqlgraph.EdgeTarget{
  656. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  657. },
  658. }
  659. }
  660. if nodes := au.mutation.KeyAgentIDs(); len(nodes) > 0 {
  661. edge := &sqlgraph.EdgeSpec{
  662. Rel: sqlgraph.O2M,
  663. Inverse: false,
  664. Table: agent.KeyAgentTable,
  665. Columns: []string{agent.KeyAgentColumn},
  666. Bidi: false,
  667. Target: &sqlgraph.EdgeTarget{
  668. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  669. },
  670. }
  671. for _, k := range nodes {
  672. edge.Target.Nodes = append(edge.Target.Nodes, k)
  673. }
  674. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  675. }
  676. if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil {
  677. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  678. err = &NotFoundError{agent.Label}
  679. } else if sqlgraph.IsConstraintError(err) {
  680. err = &ConstraintError{msg: err.Error(), wrap: err}
  681. }
  682. return 0, err
  683. }
  684. au.mutation.done = true
  685. return n, nil
  686. }
  687. // AgentUpdateOne is the builder for updating a single Agent entity.
  688. type AgentUpdateOne struct {
  689. config
  690. fields []string
  691. hooks []Hook
  692. mutation *AgentMutation
  693. }
  694. // SetUpdatedAt sets the "updated_at" field.
  695. func (auo *AgentUpdateOne) SetUpdatedAt(t time.Time) *AgentUpdateOne {
  696. auo.mutation.SetUpdatedAt(t)
  697. return auo
  698. }
  699. // SetDeletedAt sets the "deleted_at" field.
  700. func (auo *AgentUpdateOne) SetDeletedAt(t time.Time) *AgentUpdateOne {
  701. auo.mutation.SetDeletedAt(t)
  702. return auo
  703. }
  704. // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
  705. func (auo *AgentUpdateOne) SetNillableDeletedAt(t *time.Time) *AgentUpdateOne {
  706. if t != nil {
  707. auo.SetDeletedAt(*t)
  708. }
  709. return auo
  710. }
  711. // ClearDeletedAt clears the value of the "deleted_at" field.
  712. func (auo *AgentUpdateOne) ClearDeletedAt() *AgentUpdateOne {
  713. auo.mutation.ClearDeletedAt()
  714. return auo
  715. }
  716. // SetName sets the "name" field.
  717. func (auo *AgentUpdateOne) SetName(s string) *AgentUpdateOne {
  718. auo.mutation.SetName(s)
  719. return auo
  720. }
  721. // SetNillableName sets the "name" field if the given value is not nil.
  722. func (auo *AgentUpdateOne) SetNillableName(s *string) *AgentUpdateOne {
  723. if s != nil {
  724. auo.SetName(*s)
  725. }
  726. return auo
  727. }
  728. // SetRole sets the "role" field.
  729. func (auo *AgentUpdateOne) SetRole(s string) *AgentUpdateOne {
  730. auo.mutation.SetRole(s)
  731. return auo
  732. }
  733. // SetNillableRole sets the "role" field if the given value is not nil.
  734. func (auo *AgentUpdateOne) SetNillableRole(s *string) *AgentUpdateOne {
  735. if s != nil {
  736. auo.SetRole(*s)
  737. }
  738. return auo
  739. }
  740. // SetStatus sets the "status" field.
  741. func (auo *AgentUpdateOne) SetStatus(i int) *AgentUpdateOne {
  742. auo.mutation.ResetStatus()
  743. auo.mutation.SetStatus(i)
  744. return auo
  745. }
  746. // SetNillableStatus sets the "status" field if the given value is not nil.
  747. func (auo *AgentUpdateOne) SetNillableStatus(i *int) *AgentUpdateOne {
  748. if i != nil {
  749. auo.SetStatus(*i)
  750. }
  751. return auo
  752. }
  753. // AddStatus adds i to the "status" field.
  754. func (auo *AgentUpdateOne) AddStatus(i int) *AgentUpdateOne {
  755. auo.mutation.AddStatus(i)
  756. return auo
  757. }
  758. // ClearStatus clears the value of the "status" field.
  759. func (auo *AgentUpdateOne) ClearStatus() *AgentUpdateOne {
  760. auo.mutation.ClearStatus()
  761. return auo
  762. }
  763. // SetBackground sets the "background" field.
  764. func (auo *AgentUpdateOne) SetBackground(s string) *AgentUpdateOne {
  765. auo.mutation.SetBackground(s)
  766. return auo
  767. }
  768. // SetNillableBackground sets the "background" field if the given value is not nil.
  769. func (auo *AgentUpdateOne) SetNillableBackground(s *string) *AgentUpdateOne {
  770. if s != nil {
  771. auo.SetBackground(*s)
  772. }
  773. return auo
  774. }
  775. // ClearBackground clears the value of the "background" field.
  776. func (auo *AgentUpdateOne) ClearBackground() *AgentUpdateOne {
  777. auo.mutation.ClearBackground()
  778. return auo
  779. }
  780. // SetExamples sets the "examples" field.
  781. func (auo *AgentUpdateOne) SetExamples(s string) *AgentUpdateOne {
  782. auo.mutation.SetExamples(s)
  783. return auo
  784. }
  785. // SetNillableExamples sets the "examples" field if the given value is not nil.
  786. func (auo *AgentUpdateOne) SetNillableExamples(s *string) *AgentUpdateOne {
  787. if s != nil {
  788. auo.SetExamples(*s)
  789. }
  790. return auo
  791. }
  792. // ClearExamples clears the value of the "examples" field.
  793. func (auo *AgentUpdateOne) ClearExamples() *AgentUpdateOne {
  794. auo.mutation.ClearExamples()
  795. return auo
  796. }
  797. // SetOrganizationID sets the "organization_id" field.
  798. func (auo *AgentUpdateOne) SetOrganizationID(u uint64) *AgentUpdateOne {
  799. auo.mutation.ResetOrganizationID()
  800. auo.mutation.SetOrganizationID(u)
  801. return auo
  802. }
  803. // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
  804. func (auo *AgentUpdateOne) SetNillableOrganizationID(u *uint64) *AgentUpdateOne {
  805. if u != nil {
  806. auo.SetOrganizationID(*u)
  807. }
  808. return auo
  809. }
  810. // AddOrganizationID adds u to the "organization_id" field.
  811. func (auo *AgentUpdateOne) AddOrganizationID(u int64) *AgentUpdateOne {
  812. auo.mutation.AddOrganizationID(u)
  813. return auo
  814. }
  815. // SetDatasetID sets the "dataset_id" field.
  816. func (auo *AgentUpdateOne) SetDatasetID(s string) *AgentUpdateOne {
  817. auo.mutation.SetDatasetID(s)
  818. return auo
  819. }
  820. // SetNillableDatasetID sets the "dataset_id" field if the given value is not nil.
  821. func (auo *AgentUpdateOne) SetNillableDatasetID(s *string) *AgentUpdateOne {
  822. if s != nil {
  823. auo.SetDatasetID(*s)
  824. }
  825. return auo
  826. }
  827. // SetCollectionID sets the "collection_id" field.
  828. func (auo *AgentUpdateOne) SetCollectionID(s string) *AgentUpdateOne {
  829. auo.mutation.SetCollectionID(s)
  830. return auo
  831. }
  832. // SetNillableCollectionID sets the "collection_id" field if the given value is not nil.
  833. func (auo *AgentUpdateOne) SetNillableCollectionID(s *string) *AgentUpdateOne {
  834. if s != nil {
  835. auo.SetCollectionID(*s)
  836. }
  837. return auo
  838. }
  839. // AddWxAgentIDs adds the "wx_agent" edge to the Wx entity by IDs.
  840. func (auo *AgentUpdateOne) AddWxAgentIDs(ids ...uint64) *AgentUpdateOne {
  841. auo.mutation.AddWxAgentIDs(ids...)
  842. return auo
  843. }
  844. // AddWxAgent adds the "wx_agent" edges to the Wx entity.
  845. func (auo *AgentUpdateOne) AddWxAgent(w ...*Wx) *AgentUpdateOne {
  846. ids := make([]uint64, len(w))
  847. for i := range w {
  848. ids[i] = w[i].ID
  849. }
  850. return auo.AddWxAgentIDs(ids...)
  851. }
  852. // AddTokenAgentIDs adds the "token_agent" edge to the Token entity by IDs.
  853. func (auo *AgentUpdateOne) AddTokenAgentIDs(ids ...uint64) *AgentUpdateOne {
  854. auo.mutation.AddTokenAgentIDs(ids...)
  855. return auo
  856. }
  857. // AddTokenAgent adds the "token_agent" edges to the Token entity.
  858. func (auo *AgentUpdateOne) AddTokenAgent(t ...*Token) *AgentUpdateOne {
  859. ids := make([]uint64, len(t))
  860. for i := range t {
  861. ids[i] = t[i].ID
  862. }
  863. return auo.AddTokenAgentIDs(ids...)
  864. }
  865. // AddWaAgentIDs adds the "wa_agent" edge to the Whatsapp entity by IDs.
  866. func (auo *AgentUpdateOne) AddWaAgentIDs(ids ...uint64) *AgentUpdateOne {
  867. auo.mutation.AddWaAgentIDs(ids...)
  868. return auo
  869. }
  870. // AddWaAgent adds the "wa_agent" edges to the Whatsapp entity.
  871. func (auo *AgentUpdateOne) AddWaAgent(w ...*Whatsapp) *AgentUpdateOne {
  872. ids := make([]uint64, len(w))
  873. for i := range w {
  874. ids[i] = w[i].ID
  875. }
  876. return auo.AddWaAgentIDs(ids...)
  877. }
  878. // AddXjsAgentIDs adds the "xjs_agent" edge to the XunjiService entity by IDs.
  879. func (auo *AgentUpdateOne) AddXjsAgentIDs(ids ...uint64) *AgentUpdateOne {
  880. auo.mutation.AddXjsAgentIDs(ids...)
  881. return auo
  882. }
  883. // AddXjsAgent adds the "xjs_agent" edges to the XunjiService entity.
  884. func (auo *AgentUpdateOne) AddXjsAgent(x ...*XunjiService) *AgentUpdateOne {
  885. ids := make([]uint64, len(x))
  886. for i := range x {
  887. ids[i] = x[i].ID
  888. }
  889. return auo.AddXjsAgentIDs(ids...)
  890. }
  891. // AddKeyAgentIDs adds the "key_agent" edge to the ApiKey entity by IDs.
  892. func (auo *AgentUpdateOne) AddKeyAgentIDs(ids ...uint64) *AgentUpdateOne {
  893. auo.mutation.AddKeyAgentIDs(ids...)
  894. return auo
  895. }
  896. // AddKeyAgent adds the "key_agent" edges to the ApiKey entity.
  897. func (auo *AgentUpdateOne) AddKeyAgent(a ...*ApiKey) *AgentUpdateOne {
  898. ids := make([]uint64, len(a))
  899. for i := range a {
  900. ids[i] = a[i].ID
  901. }
  902. return auo.AddKeyAgentIDs(ids...)
  903. }
  904. // Mutation returns the AgentMutation object of the builder.
  905. func (auo *AgentUpdateOne) Mutation() *AgentMutation {
  906. return auo.mutation
  907. }
  908. // ClearWxAgent clears all "wx_agent" edges to the Wx entity.
  909. func (auo *AgentUpdateOne) ClearWxAgent() *AgentUpdateOne {
  910. auo.mutation.ClearWxAgent()
  911. return auo
  912. }
  913. // RemoveWxAgentIDs removes the "wx_agent" edge to Wx entities by IDs.
  914. func (auo *AgentUpdateOne) RemoveWxAgentIDs(ids ...uint64) *AgentUpdateOne {
  915. auo.mutation.RemoveWxAgentIDs(ids...)
  916. return auo
  917. }
  918. // RemoveWxAgent removes "wx_agent" edges to Wx entities.
  919. func (auo *AgentUpdateOne) RemoveWxAgent(w ...*Wx) *AgentUpdateOne {
  920. ids := make([]uint64, len(w))
  921. for i := range w {
  922. ids[i] = w[i].ID
  923. }
  924. return auo.RemoveWxAgentIDs(ids...)
  925. }
  926. // ClearTokenAgent clears all "token_agent" edges to the Token entity.
  927. func (auo *AgentUpdateOne) ClearTokenAgent() *AgentUpdateOne {
  928. auo.mutation.ClearTokenAgent()
  929. return auo
  930. }
  931. // RemoveTokenAgentIDs removes the "token_agent" edge to Token entities by IDs.
  932. func (auo *AgentUpdateOne) RemoveTokenAgentIDs(ids ...uint64) *AgentUpdateOne {
  933. auo.mutation.RemoveTokenAgentIDs(ids...)
  934. return auo
  935. }
  936. // RemoveTokenAgent removes "token_agent" edges to Token entities.
  937. func (auo *AgentUpdateOne) RemoveTokenAgent(t ...*Token) *AgentUpdateOne {
  938. ids := make([]uint64, len(t))
  939. for i := range t {
  940. ids[i] = t[i].ID
  941. }
  942. return auo.RemoveTokenAgentIDs(ids...)
  943. }
  944. // ClearWaAgent clears all "wa_agent" edges to the Whatsapp entity.
  945. func (auo *AgentUpdateOne) ClearWaAgent() *AgentUpdateOne {
  946. auo.mutation.ClearWaAgent()
  947. return auo
  948. }
  949. // RemoveWaAgentIDs removes the "wa_agent" edge to Whatsapp entities by IDs.
  950. func (auo *AgentUpdateOne) RemoveWaAgentIDs(ids ...uint64) *AgentUpdateOne {
  951. auo.mutation.RemoveWaAgentIDs(ids...)
  952. return auo
  953. }
  954. // RemoveWaAgent removes "wa_agent" edges to Whatsapp entities.
  955. func (auo *AgentUpdateOne) RemoveWaAgent(w ...*Whatsapp) *AgentUpdateOne {
  956. ids := make([]uint64, len(w))
  957. for i := range w {
  958. ids[i] = w[i].ID
  959. }
  960. return auo.RemoveWaAgentIDs(ids...)
  961. }
  962. // ClearXjsAgent clears all "xjs_agent" edges to the XunjiService entity.
  963. func (auo *AgentUpdateOne) ClearXjsAgent() *AgentUpdateOne {
  964. auo.mutation.ClearXjsAgent()
  965. return auo
  966. }
  967. // RemoveXjsAgentIDs removes the "xjs_agent" edge to XunjiService entities by IDs.
  968. func (auo *AgentUpdateOne) RemoveXjsAgentIDs(ids ...uint64) *AgentUpdateOne {
  969. auo.mutation.RemoveXjsAgentIDs(ids...)
  970. return auo
  971. }
  972. // RemoveXjsAgent removes "xjs_agent" edges to XunjiService entities.
  973. func (auo *AgentUpdateOne) RemoveXjsAgent(x ...*XunjiService) *AgentUpdateOne {
  974. ids := make([]uint64, len(x))
  975. for i := range x {
  976. ids[i] = x[i].ID
  977. }
  978. return auo.RemoveXjsAgentIDs(ids...)
  979. }
  980. // ClearKeyAgent clears all "key_agent" edges to the ApiKey entity.
  981. func (auo *AgentUpdateOne) ClearKeyAgent() *AgentUpdateOne {
  982. auo.mutation.ClearKeyAgent()
  983. return auo
  984. }
  985. // RemoveKeyAgentIDs removes the "key_agent" edge to ApiKey entities by IDs.
  986. func (auo *AgentUpdateOne) RemoveKeyAgentIDs(ids ...uint64) *AgentUpdateOne {
  987. auo.mutation.RemoveKeyAgentIDs(ids...)
  988. return auo
  989. }
  990. // RemoveKeyAgent removes "key_agent" edges to ApiKey entities.
  991. func (auo *AgentUpdateOne) RemoveKeyAgent(a ...*ApiKey) *AgentUpdateOne {
  992. ids := make([]uint64, len(a))
  993. for i := range a {
  994. ids[i] = a[i].ID
  995. }
  996. return auo.RemoveKeyAgentIDs(ids...)
  997. }
  998. // Where appends a list predicates to the AgentUpdate builder.
  999. func (auo *AgentUpdateOne) Where(ps ...predicate.Agent) *AgentUpdateOne {
  1000. auo.mutation.Where(ps...)
  1001. return auo
  1002. }
  1003. // Select allows selecting one or more fields (columns) of the returned entity.
  1004. // The default is selecting all fields defined in the entity schema.
  1005. func (auo *AgentUpdateOne) Select(field string, fields ...string) *AgentUpdateOne {
  1006. auo.fields = append([]string{field}, fields...)
  1007. return auo
  1008. }
  1009. // Save executes the query and returns the updated Agent entity.
  1010. func (auo *AgentUpdateOne) Save(ctx context.Context) (*Agent, error) {
  1011. if err := auo.defaults(); err != nil {
  1012. return nil, err
  1013. }
  1014. return withHooks(ctx, auo.sqlSave, auo.mutation, auo.hooks)
  1015. }
  1016. // SaveX is like Save, but panics if an error occurs.
  1017. func (auo *AgentUpdateOne) SaveX(ctx context.Context) *Agent {
  1018. node, err := auo.Save(ctx)
  1019. if err != nil {
  1020. panic(err)
  1021. }
  1022. return node
  1023. }
  1024. // Exec executes the query on the entity.
  1025. func (auo *AgentUpdateOne) Exec(ctx context.Context) error {
  1026. _, err := auo.Save(ctx)
  1027. return err
  1028. }
  1029. // ExecX is like Exec, but panics if an error occurs.
  1030. func (auo *AgentUpdateOne) ExecX(ctx context.Context) {
  1031. if err := auo.Exec(ctx); err != nil {
  1032. panic(err)
  1033. }
  1034. }
  1035. // defaults sets the default values of the builder before save.
  1036. func (auo *AgentUpdateOne) defaults() error {
  1037. if _, ok := auo.mutation.UpdatedAt(); !ok {
  1038. if agent.UpdateDefaultUpdatedAt == nil {
  1039. return fmt.Errorf("ent: uninitialized agent.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
  1040. }
  1041. v := agent.UpdateDefaultUpdatedAt()
  1042. auo.mutation.SetUpdatedAt(v)
  1043. }
  1044. return nil
  1045. }
  1046. // check runs all checks and user-defined validators on the builder.
  1047. func (auo *AgentUpdateOne) check() error {
  1048. if v, ok := auo.mutation.Name(); ok {
  1049. if err := agent.NameValidator(v); err != nil {
  1050. return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Agent.name": %w`, err)}
  1051. }
  1052. }
  1053. if v, ok := auo.mutation.Status(); ok {
  1054. if err := agent.StatusValidator(v); err != nil {
  1055. return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Agent.status": %w`, err)}
  1056. }
  1057. }
  1058. if v, ok := auo.mutation.OrganizationID(); ok {
  1059. if err := agent.OrganizationIDValidator(v); err != nil {
  1060. return &ValidationError{Name: "organization_id", err: fmt.Errorf(`ent: validator failed for field "Agent.organization_id": %w`, err)}
  1061. }
  1062. }
  1063. if v, ok := auo.mutation.DatasetID(); ok {
  1064. if err := agent.DatasetIDValidator(v); err != nil {
  1065. return &ValidationError{Name: "dataset_id", err: fmt.Errorf(`ent: validator failed for field "Agent.dataset_id": %w`, err)}
  1066. }
  1067. }
  1068. if v, ok := auo.mutation.CollectionID(); ok {
  1069. if err := agent.CollectionIDValidator(v); err != nil {
  1070. return &ValidationError{Name: "collection_id", err: fmt.Errorf(`ent: validator failed for field "Agent.collection_id": %w`, err)}
  1071. }
  1072. }
  1073. return nil
  1074. }
  1075. func (auo *AgentUpdateOne) sqlSave(ctx context.Context) (_node *Agent, err error) {
  1076. if err := auo.check(); err != nil {
  1077. return _node, err
  1078. }
  1079. _spec := sqlgraph.NewUpdateSpec(agent.Table, agent.Columns, sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64))
  1080. id, ok := auo.mutation.ID()
  1081. if !ok {
  1082. return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Agent.id" for update`)}
  1083. }
  1084. _spec.Node.ID.Value = id
  1085. if fields := auo.fields; len(fields) > 0 {
  1086. _spec.Node.Columns = make([]string, 0, len(fields))
  1087. _spec.Node.Columns = append(_spec.Node.Columns, agent.FieldID)
  1088. for _, f := range fields {
  1089. if !agent.ValidColumn(f) {
  1090. return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  1091. }
  1092. if f != agent.FieldID {
  1093. _spec.Node.Columns = append(_spec.Node.Columns, f)
  1094. }
  1095. }
  1096. }
  1097. if ps := auo.mutation.predicates; len(ps) > 0 {
  1098. _spec.Predicate = func(selector *sql.Selector) {
  1099. for i := range ps {
  1100. ps[i](selector)
  1101. }
  1102. }
  1103. }
  1104. if value, ok := auo.mutation.UpdatedAt(); ok {
  1105. _spec.SetField(agent.FieldUpdatedAt, field.TypeTime, value)
  1106. }
  1107. if value, ok := auo.mutation.DeletedAt(); ok {
  1108. _spec.SetField(agent.FieldDeletedAt, field.TypeTime, value)
  1109. }
  1110. if auo.mutation.DeletedAtCleared() {
  1111. _spec.ClearField(agent.FieldDeletedAt, field.TypeTime)
  1112. }
  1113. if value, ok := auo.mutation.Name(); ok {
  1114. _spec.SetField(agent.FieldName, field.TypeString, value)
  1115. }
  1116. if value, ok := auo.mutation.Role(); ok {
  1117. _spec.SetField(agent.FieldRole, field.TypeString, value)
  1118. }
  1119. if value, ok := auo.mutation.Status(); ok {
  1120. _spec.SetField(agent.FieldStatus, field.TypeInt, value)
  1121. }
  1122. if value, ok := auo.mutation.AddedStatus(); ok {
  1123. _spec.AddField(agent.FieldStatus, field.TypeInt, value)
  1124. }
  1125. if auo.mutation.StatusCleared() {
  1126. _spec.ClearField(agent.FieldStatus, field.TypeInt)
  1127. }
  1128. if value, ok := auo.mutation.Background(); ok {
  1129. _spec.SetField(agent.FieldBackground, field.TypeString, value)
  1130. }
  1131. if auo.mutation.BackgroundCleared() {
  1132. _spec.ClearField(agent.FieldBackground, field.TypeString)
  1133. }
  1134. if value, ok := auo.mutation.Examples(); ok {
  1135. _spec.SetField(agent.FieldExamples, field.TypeString, value)
  1136. }
  1137. if auo.mutation.ExamplesCleared() {
  1138. _spec.ClearField(agent.FieldExamples, field.TypeString)
  1139. }
  1140. if value, ok := auo.mutation.OrganizationID(); ok {
  1141. _spec.SetField(agent.FieldOrganizationID, field.TypeUint64, value)
  1142. }
  1143. if value, ok := auo.mutation.AddedOrganizationID(); ok {
  1144. _spec.AddField(agent.FieldOrganizationID, field.TypeUint64, value)
  1145. }
  1146. if value, ok := auo.mutation.DatasetID(); ok {
  1147. _spec.SetField(agent.FieldDatasetID, field.TypeString, value)
  1148. }
  1149. if value, ok := auo.mutation.CollectionID(); ok {
  1150. _spec.SetField(agent.FieldCollectionID, field.TypeString, value)
  1151. }
  1152. if auo.mutation.WxAgentCleared() {
  1153. edge := &sqlgraph.EdgeSpec{
  1154. Rel: sqlgraph.O2M,
  1155. Inverse: false,
  1156. Table: agent.WxAgentTable,
  1157. Columns: []string{agent.WxAgentColumn},
  1158. Bidi: false,
  1159. Target: &sqlgraph.EdgeTarget{
  1160. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  1161. },
  1162. }
  1163. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1164. }
  1165. if nodes := auo.mutation.RemovedWxAgentIDs(); len(nodes) > 0 && !auo.mutation.WxAgentCleared() {
  1166. edge := &sqlgraph.EdgeSpec{
  1167. Rel: sqlgraph.O2M,
  1168. Inverse: false,
  1169. Table: agent.WxAgentTable,
  1170. Columns: []string{agent.WxAgentColumn},
  1171. Bidi: false,
  1172. Target: &sqlgraph.EdgeTarget{
  1173. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  1174. },
  1175. }
  1176. for _, k := range nodes {
  1177. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1178. }
  1179. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1180. }
  1181. if nodes := auo.mutation.WxAgentIDs(); len(nodes) > 0 {
  1182. edge := &sqlgraph.EdgeSpec{
  1183. Rel: sqlgraph.O2M,
  1184. Inverse: false,
  1185. Table: agent.WxAgentTable,
  1186. Columns: []string{agent.WxAgentColumn},
  1187. Bidi: false,
  1188. Target: &sqlgraph.EdgeTarget{
  1189. IDSpec: sqlgraph.NewFieldSpec(wx.FieldID, field.TypeUint64),
  1190. },
  1191. }
  1192. for _, k := range nodes {
  1193. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1194. }
  1195. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1196. }
  1197. if auo.mutation.TokenAgentCleared() {
  1198. edge := &sqlgraph.EdgeSpec{
  1199. Rel: sqlgraph.O2M,
  1200. Inverse: false,
  1201. Table: agent.TokenAgentTable,
  1202. Columns: []string{agent.TokenAgentColumn},
  1203. Bidi: false,
  1204. Target: &sqlgraph.EdgeTarget{
  1205. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  1206. },
  1207. }
  1208. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1209. }
  1210. if nodes := auo.mutation.RemovedTokenAgentIDs(); len(nodes) > 0 && !auo.mutation.TokenAgentCleared() {
  1211. edge := &sqlgraph.EdgeSpec{
  1212. Rel: sqlgraph.O2M,
  1213. Inverse: false,
  1214. Table: agent.TokenAgentTable,
  1215. Columns: []string{agent.TokenAgentColumn},
  1216. Bidi: false,
  1217. Target: &sqlgraph.EdgeTarget{
  1218. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  1219. },
  1220. }
  1221. for _, k := range nodes {
  1222. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1223. }
  1224. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1225. }
  1226. if nodes := auo.mutation.TokenAgentIDs(); len(nodes) > 0 {
  1227. edge := &sqlgraph.EdgeSpec{
  1228. Rel: sqlgraph.O2M,
  1229. Inverse: false,
  1230. Table: agent.TokenAgentTable,
  1231. Columns: []string{agent.TokenAgentColumn},
  1232. Bidi: false,
  1233. Target: &sqlgraph.EdgeTarget{
  1234. IDSpec: sqlgraph.NewFieldSpec(token.FieldID, field.TypeUint64),
  1235. },
  1236. }
  1237. for _, k := range nodes {
  1238. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1239. }
  1240. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1241. }
  1242. if auo.mutation.WaAgentCleared() {
  1243. edge := &sqlgraph.EdgeSpec{
  1244. Rel: sqlgraph.O2M,
  1245. Inverse: false,
  1246. Table: agent.WaAgentTable,
  1247. Columns: []string{agent.WaAgentColumn},
  1248. Bidi: false,
  1249. Target: &sqlgraph.EdgeTarget{
  1250. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  1251. },
  1252. }
  1253. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1254. }
  1255. if nodes := auo.mutation.RemovedWaAgentIDs(); len(nodes) > 0 && !auo.mutation.WaAgentCleared() {
  1256. edge := &sqlgraph.EdgeSpec{
  1257. Rel: sqlgraph.O2M,
  1258. Inverse: false,
  1259. Table: agent.WaAgentTable,
  1260. Columns: []string{agent.WaAgentColumn},
  1261. Bidi: false,
  1262. Target: &sqlgraph.EdgeTarget{
  1263. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  1264. },
  1265. }
  1266. for _, k := range nodes {
  1267. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1268. }
  1269. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1270. }
  1271. if nodes := auo.mutation.WaAgentIDs(); len(nodes) > 0 {
  1272. edge := &sqlgraph.EdgeSpec{
  1273. Rel: sqlgraph.O2M,
  1274. Inverse: false,
  1275. Table: agent.WaAgentTable,
  1276. Columns: []string{agent.WaAgentColumn},
  1277. Bidi: false,
  1278. Target: &sqlgraph.EdgeTarget{
  1279. IDSpec: sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64),
  1280. },
  1281. }
  1282. for _, k := range nodes {
  1283. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1284. }
  1285. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1286. }
  1287. if auo.mutation.XjsAgentCleared() {
  1288. edge := &sqlgraph.EdgeSpec{
  1289. Rel: sqlgraph.O2M,
  1290. Inverse: false,
  1291. Table: agent.XjsAgentTable,
  1292. Columns: []string{agent.XjsAgentColumn},
  1293. Bidi: false,
  1294. Target: &sqlgraph.EdgeTarget{
  1295. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1296. },
  1297. }
  1298. }
  1299. if auo.mutation.KeyAgentCleared() {
  1300. edge := &sqlgraph.EdgeSpec{
  1301. Rel: sqlgraph.O2M,
  1302. Inverse: false,
  1303. Table: agent.KeyAgentTable,
  1304. Columns: []string{agent.KeyAgentColumn},
  1305. Bidi: false,
  1306. Target: &sqlgraph.EdgeTarget{
  1307. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  1308. },
  1309. }
  1310. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1311. }
  1312. if nodes := auo.mutation.RemovedXjsAgentIDs(); len(nodes) > 0 && !auo.mutation.XjsAgentCleared() {
  1313. edge := &sqlgraph.EdgeSpec{
  1314. Rel: sqlgraph.O2M,
  1315. Inverse: false,
  1316. Table: agent.XjsAgentTable,
  1317. Columns: []string{agent.XjsAgentColumn},
  1318. Bidi: false,
  1319. Target: &sqlgraph.EdgeTarget{
  1320. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1321. },
  1322. }
  1323. }
  1324. if nodes := auo.mutation.RemovedKeyAgentIDs(); len(nodes) > 0 && !auo.mutation.KeyAgentCleared() {
  1325. edge := &sqlgraph.EdgeSpec{
  1326. Rel: sqlgraph.O2M,
  1327. Inverse: false,
  1328. Table: agent.KeyAgentTable,
  1329. Columns: []string{agent.KeyAgentColumn},
  1330. Bidi: false,
  1331. Target: &sqlgraph.EdgeTarget{
  1332. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  1333. },
  1334. }
  1335. for _, k := range nodes {
  1336. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1337. }
  1338. _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
  1339. }
  1340. if nodes := auo.mutation.XjsAgentIDs(); len(nodes) > 0 {
  1341. edge := &sqlgraph.EdgeSpec{
  1342. Rel: sqlgraph.O2M,
  1343. Inverse: false,
  1344. Table: agent.XjsAgentTable,
  1345. Columns: []string{agent.XjsAgentColumn},
  1346. Bidi: false,
  1347. Target: &sqlgraph.EdgeTarget{
  1348. IDSpec: sqlgraph.NewFieldSpec(xunjiservice.FieldID, field.TypeUint64),
  1349. },
  1350. }
  1351. }
  1352. if nodes := auo.mutation.KeyAgentIDs(); len(nodes) > 0 {
  1353. edge := &sqlgraph.EdgeSpec{
  1354. Rel: sqlgraph.O2M,
  1355. Inverse: false,
  1356. Table: agent.KeyAgentTable,
  1357. Columns: []string{agent.KeyAgentColumn},
  1358. Bidi: false,
  1359. Target: &sqlgraph.EdgeTarget{
  1360. IDSpec: sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64),
  1361. },
  1362. }
  1363. for _, k := range nodes {
  1364. edge.Target.Nodes = append(edge.Target.Nodes, k)
  1365. }
  1366. _spec.Edges.Add = append(_spec.Edges.Add, edge)
  1367. }
  1368. _node = &Agent{config: auo.config}
  1369. _spec.Assign = _node.assignValues
  1370. _spec.ScanValues = _node.scanValues
  1371. if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
  1372. if _, ok := err.(*sqlgraph.NotFoundError); ok {
  1373. err = &NotFoundError{agent.Label}
  1374. } else if sqlgraph.IsConstraintError(err) {
  1375. err = &ConstraintError{msg: err.Error(), wrap: err}
  1376. }
  1377. return nil, err
  1378. }
  1379. auo.mutation.done = true
  1380. return _node, nil
  1381. }