8
0

mini_page_component.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. package service
  2. import (
  3. "ecos/application/domain/mini_carousel_config"
  4. "ecos/application/domain/mini_live_config"
  5. "ecos/application/domain/mini_page_component"
  6. "ecos/application/domain/mini_quality_product_config"
  7. "ecos/application/domain/mini_video_config"
  8. "ecos/osm"
  9. "encoding/json"
  10. "git.sxidc.com/go-framework/baize/convenient/entity_crud"
  11. "git.sxidc.com/go-framework/baize/framework/binding"
  12. "git.sxidc.com/go-framework/baize/framework/core/api"
  13. "git.sxidc.com/go-framework/baize/framework/core/api/request"
  14. "git.sxidc.com/go-framework/baize/framework/core/api/response"
  15. "git.sxidc.com/go-framework/baize/framework/core/application"
  16. "git.sxidc.com/go-framework/baize/framework/core/domain"
  17. "git.sxidc.com/go-framework/baize/framework/core/domain/entity"
  18. "git.sxidc.com/go-framework/baize/framework/core/infrastructure"
  19. "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database"
  20. "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database/sql"
  21. "git.sxidc.com/go-tools/utils/strutils"
  22. "github.com/pkg/errors"
  23. )
  24. var miniPageComponentService = &MiniPageComponentService{}
  25. type MiniPageComponentService struct{}
  26. func (svc *MiniPageComponentService) Init(appInstance *application.App) error {
  27. svc.v1(appInstance)
  28. return nil
  29. }
  30. func (svc *MiniPageComponentService) Destroy() error {
  31. return nil
  32. }
  33. func (svc *MiniPageComponentService) v1(appInstance *application.App) {
  34. v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"),
  35. appInstance.Infrastructure())
  36. entity_crud.BindSimple[mini_page_component.Info](v1Binder, &entity_crud.Simple[mini_page_component.Info]{
  37. Entity: &mini_page_component.Entity{},
  38. Schema: dbSchema,
  39. CreateJsonBody: &mini_page_component.CreateMiniPageComponentJsonBody{},
  40. DeleteQueryParams: &mini_page_component.DeleteMiniPageComponentQueryParams{},
  41. UpdateJsonBody: &mini_page_component.UpdateMiniPageComponentJsonBody{},
  42. QueryQueryParams: &mini_page_component.GetMiniPageComponentsQueryParams{},
  43. GetByIDQueryParams: &mini_page_component.GetMiniPageComponentQueryParams{},
  44. },
  45. entity_crud.WithCreateTx(),
  46. entity_crud.WithUpdateTx(),
  47. entity_crud.WithCreateCallbacks(&entity_crud.CreateCallbacks{
  48. Before: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
  49. requestParams, err := request.ToConcrete[*mini_page_component.CreateMiniPageComponentJsonBody](params)
  50. if err != nil {
  51. return err
  52. }
  53. record, err := domain.ToConcrete[*mini_page_component.Entity](e)
  54. if err != nil {
  55. return err
  56. }
  57. if strutils.IsStringNotEmpty(requestParams.ComponentConfig) {
  58. if requestParams.ComponentTypeID == "1" { //轮播图
  59. var config mini_page_component.CarouselConfig
  60. if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
  61. return err
  62. }
  63. if len(config.Items) > 0 {
  64. for idx := range config.Items {
  65. if strutils.IsStringNotEmpty(config.Items[idx].ImageUrl) {
  66. newFilePath, err := osm.MultipleFileMv(config.Items[idx].ImageUrl)
  67. if err != nil {
  68. return err
  69. }
  70. config.Items[idx].ImageUrl = newFilePath
  71. }
  72. }
  73. }
  74. updatedConfig, err := json.Marshal(config)
  75. if err != nil {
  76. return err
  77. }
  78. record.ComponentConfig = string(updatedConfig)
  79. } else if requestParams.ComponentTypeID == "2" { //2是直播
  80. var config mini_page_component.LiveWindowConfig
  81. if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
  82. return err
  83. }
  84. if strutils.IsStringNotEmpty(config.LiveCoverUrl) {
  85. newFilePath, err := osm.MultipleFileMv(config.LiveCoverUrl)
  86. if err != nil {
  87. return err
  88. }
  89. config.LiveCoverUrl = newFilePath
  90. }
  91. updatedConfig, err := json.Marshal(config)
  92. if err != nil {
  93. return err
  94. }
  95. record.ComponentConfig = string(updatedConfig)
  96. } else if requestParams.ComponentTypeID == "3" { //3是宣传视频
  97. var config mini_page_component.VideoComponentConfig
  98. if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
  99. return err
  100. }
  101. if strutils.IsStringNotEmpty(config.VideoUrlStr) {
  102. newFilePath, err := osm.MultipleFileMv(config.VideoUrlStr)
  103. if err != nil {
  104. return err
  105. }
  106. config.VideoUrlStr = newFilePath
  107. }
  108. if strutils.IsStringNotEmpty(config.VideoCoverStr) {
  109. newFilePath, err := osm.MultipleFileMv(config.VideoCoverStr)
  110. if err != nil {
  111. return err
  112. }
  113. config.VideoCoverStr = newFilePath
  114. }
  115. updatedConfig, err := json.Marshal(config)
  116. if err != nil {
  117. return err
  118. }
  119. record.ComponentConfig = string(updatedConfig)
  120. }
  121. }
  122. return nil
  123. },
  124. After: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
  125. record, err := domain.ToConcrete[*mini_page_component.Entity](e)
  126. if err != nil {
  127. return err
  128. }
  129. if record.IsEnabled == Enabled {
  130. //当前启用 把别的关掉
  131. err = database.Update(tx, &sql.UpdateExecuteParams{
  132. TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
  133. Conditions: sql.NewConditions().Not(entity.ColumnID, e.GetID()).Equal(mini_page_component.ColumnComponentTypeID, record.ComponentTypeID),
  134. TableRow: sql.NewTableRow().Add(mini_page_component.ColumnIsEnabled, Disable),
  135. })
  136. if err != nil {
  137. return err
  138. }
  139. }
  140. return nil
  141. },
  142. }),
  143. entity_crud.WithUpdateCallbacks(&entity_crud.UpdateCallbacks{
  144. Before: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
  145. requestParams, err := request.ToConcrete[*mini_page_component.UpdateMiniPageComponentJsonBody](params)
  146. if err != nil {
  147. return err
  148. }
  149. record, err := domain.ToConcrete[*mini_page_component.Entity](e)
  150. if err != nil {
  151. return err
  152. }
  153. if strutils.IsStringNotEmpty(requestParams.ComponentConfig) {
  154. if requestParams.ComponentTypeID == "1" { //轮播图
  155. var config mini_page_component.CarouselConfig
  156. if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
  157. return err
  158. }
  159. if len(config.Items) > 0 {
  160. for idx := range config.Items {
  161. if strutils.IsStringNotEmpty(config.Items[idx].ImageUrl) {
  162. newFilePath, err := osm.MultipleFileMv(config.Items[idx].ImageUrl)
  163. if err != nil {
  164. return err
  165. }
  166. config.Items[idx].ImageUrl = newFilePath
  167. }
  168. }
  169. }
  170. updatedConfig, err := json.Marshal(config)
  171. if err != nil {
  172. return err
  173. }
  174. record.ComponentConfig = string(updatedConfig)
  175. } else if requestParams.ComponentTypeID == "2" { //2是直播
  176. var config mini_page_component.LiveWindowConfig
  177. if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
  178. return err
  179. }
  180. if strutils.IsStringNotEmpty(config.LiveCoverUrl) {
  181. newFilePath, err := osm.MultipleFileMv(config.LiveCoverUrl)
  182. if err != nil {
  183. return err
  184. }
  185. config.LiveCoverUrl = newFilePath
  186. }
  187. updatedConfig, err := json.Marshal(config)
  188. if err != nil {
  189. return err
  190. }
  191. record.ComponentConfig = string(updatedConfig)
  192. } else if requestParams.ComponentTypeID == "3" { //3是宣传视频
  193. var config mini_page_component.VideoComponentConfig
  194. if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
  195. return err
  196. }
  197. if strutils.IsStringNotEmpty(config.VideoUrlStr) {
  198. newFilePath, err := osm.MultipleFileMv(config.VideoUrlStr)
  199. if err != nil {
  200. return err
  201. }
  202. config.VideoUrlStr = newFilePath
  203. }
  204. if strutils.IsStringNotEmpty(config.VideoCoverStr) {
  205. newFilePath, err := osm.MultipleFileMv(config.VideoCoverStr)
  206. if err != nil {
  207. return err
  208. }
  209. config.VideoCoverStr = newFilePath
  210. }
  211. updatedConfig, err := json.Marshal(config)
  212. if err != nil {
  213. return err
  214. }
  215. record.ComponentConfig = string(updatedConfig)
  216. }
  217. }
  218. return nil
  219. },
  220. After: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
  221. record, err := domain.ToConcrete[*mini_page_component.Entity](e)
  222. if err != nil {
  223. return err
  224. }
  225. if record.IsEnabled == Enabled {
  226. //当前启用 把别的同code的关掉
  227. err = database.Update(tx, &sql.UpdateExecuteParams{
  228. TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
  229. Conditions: sql.NewConditions().Not(entity.ColumnID, e.GetID()).Equal(mini_page_component.ColumnComponentTypeID, record.ComponentTypeID),
  230. TableRow: sql.NewTableRow().Add(mini_page_component.ColumnIsEnabled, Disable),
  231. })
  232. if err != nil {
  233. return err
  234. }
  235. }
  236. return nil
  237. },
  238. }),
  239. entity_crud.WithQueryFormCustomConditionFunc[mini_page_component.Info](func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) (*entity_crud.CustomCondition, error) {
  240. requestParams, err := request.ToConcrete[*mini_page_component.GetMiniPageComponentsQueryParams](params)
  241. if err != nil {
  242. return nil, err
  243. }
  244. conditions := sql.NewConditions()
  245. if strutils.IsStringNotEmpty(requestParams.PageID) {
  246. conditions = conditions.Equal(mini_page_component.ColumnPageID, requestParams.PageID)
  247. }
  248. if strutils.IsStringNotEmpty(requestParams.ComponentTypeID) {
  249. conditions = conditions.Equal(mini_page_component.ColumnComponentTypeID, requestParams.ComponentTypeID)
  250. }
  251. if strutils.IsStringNotEmpty(requestParams.TypeName) {
  252. conditions = conditions.Like(mini_page_component.ColumnTypeName, "%"+requestParams.TypeName+"%")
  253. }
  254. if strutils.IsStringNotEmpty(requestParams.IsEnabled) {
  255. conditions = conditions.Equal(mini_page_component.ColumnPageID, requestParams.IsEnabled)
  256. }
  257. return &entity_crud.CustomCondition{
  258. Conditions: conditions,
  259. OrderBy: mini_page_component.ColumnSortOrder,
  260. }, nil
  261. }),
  262. entity_crud.WithGetByIDCallbacks(&entity_crud.GetByIDCallbacks[mini_page_component.Info]{
  263. OnSuccessReturn: func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure, output mini_page_component.Info) (mini_page_component.Info, error) {
  264. if strutils.IsStringNotEmpty(output.ComponentConfig) {
  265. if output.ComponentTypeID == "1" { //轮播图
  266. var config mini_page_component.CarouselConfig
  267. if err := json.Unmarshal([]byte(output.ComponentConfig), &config); err != nil {
  268. return output, nil
  269. }
  270. if len(config.Items) > 0 {
  271. for idx := range config.Items {
  272. if strutils.IsStringNotEmpty(config.Items[idx].ImageUrl) {
  273. fileObjects, err := osm.MultipleFileUrl(config.Items[idx].ImageUrl)
  274. if err != nil {
  275. return output, err
  276. }
  277. config.Items[idx].ImageUrls = fileObjects
  278. }
  279. }
  280. }
  281. updatedConfig, err := json.Marshal(config)
  282. if err != nil {
  283. return output, nil
  284. }
  285. output.ComponentConfig = string(updatedConfig)
  286. } else if output.ComponentTypeID == "2" { //2是直播
  287. var config mini_page_component.LiveWindowConfig
  288. if err := json.Unmarshal([]byte(output.ComponentConfig), &config); err != nil {
  289. return output, nil
  290. }
  291. if strutils.IsStringNotEmpty(config.LiveCoverUrl) {
  292. fileObjects, err := osm.MultipleFileUrl(config.LiveCoverUrl)
  293. if err != nil {
  294. return output, err
  295. }
  296. config.LiveCoverUrlFile = fileObjects
  297. }
  298. updatedConfig, err := json.Marshal(config)
  299. if err != nil {
  300. return output, nil
  301. }
  302. output.ComponentConfig = string(updatedConfig)
  303. } else if output.ComponentTypeID == "3" { //3是宣传视频
  304. var config mini_page_component.VideoComponentConfig
  305. if err := json.Unmarshal([]byte(output.ComponentConfig), &config); err != nil {
  306. return output, nil
  307. }
  308. if strutils.IsStringNotEmpty(config.VideoUrlStr) {
  309. fileObjects, err := osm.MultipleFileUrl(config.VideoUrlStr)
  310. if err != nil {
  311. return output, err
  312. }
  313. config.VideoUrlFile = fileObjects
  314. }
  315. if strutils.IsStringNotEmpty(config.VideoCoverStr) {
  316. fileObjects, err := osm.MultipleFileUrl(config.VideoCoverStr)
  317. if err != nil {
  318. return output, err
  319. }
  320. config.VideoCoverFile = fileObjects
  321. }
  322. updatedConfig, err := json.Marshal(config)
  323. if err != nil {
  324. return output, nil
  325. }
  326. output.ComponentConfig = string(updatedConfig)
  327. }
  328. }
  329. return output, nil
  330. },
  331. }),
  332. entity_crud.WithQueryCallbacks(&entity_crud.QueryCallbacks[mini_page_component.Info]{
  333. OnSuccessReturn: func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure, output response.InfosData[mini_page_component.Info]) (response.InfosData[mini_page_component.Info], error) {
  334. infos := output.Infos
  335. for i1 := range infos {
  336. info := &infos[i1]
  337. if strutils.IsStringNotEmpty(info.ComponentConfig) {
  338. if info.ComponentTypeID == "1" { //轮播图
  339. var config mini_page_component.CarouselConfig
  340. if err := json.Unmarshal([]byte(info.ComponentConfig), &config); err != nil {
  341. return output, nil
  342. }
  343. if len(config.Items) > 0 {
  344. for idx := range config.Items {
  345. if strutils.IsStringNotEmpty(config.Items[idx].ImageUrl) {
  346. fileObjects, err := osm.MultipleFileUrl(config.Items[idx].ImageUrl)
  347. if err != nil {
  348. return output, err
  349. }
  350. config.Items[idx].ImageUrls = fileObjects
  351. }
  352. }
  353. }
  354. updatedConfig, err := json.Marshal(config)
  355. if err != nil {
  356. return output, nil
  357. }
  358. info.ComponentConfig = string(updatedConfig)
  359. } else if info.ComponentTypeID == "2" { //2是直播
  360. var config mini_page_component.LiveWindowConfig
  361. if err := json.Unmarshal([]byte(info.ComponentConfig), &config); err != nil {
  362. return output, nil
  363. }
  364. if strutils.IsStringNotEmpty(config.LiveCoverUrl) {
  365. fileObjects, err := osm.MultipleFileUrl(config.LiveCoverUrl)
  366. if err != nil {
  367. return output, err
  368. }
  369. config.LiveCoverUrlFile = fileObjects
  370. }
  371. updatedConfig, err := json.Marshal(config)
  372. if err != nil {
  373. return output, nil
  374. }
  375. info.ComponentConfig = string(updatedConfig)
  376. } else if info.ComponentTypeID == "3" { //3是宣传视频
  377. var config mini_page_component.VideoComponentConfig
  378. if err := json.Unmarshal([]byte(info.ComponentConfig), &config); err != nil {
  379. return output, nil
  380. }
  381. if strutils.IsStringNotEmpty(config.VideoUrlStr) {
  382. fileObjects, err := osm.MultipleFileUrl(config.VideoUrlStr)
  383. if err != nil {
  384. return output, err
  385. }
  386. config.VideoUrlFile = fileObjects
  387. }
  388. if strutils.IsStringNotEmpty(config.VideoCoverStr) {
  389. fileObjects, err := osm.MultipleFileUrl(config.VideoCoverStr)
  390. if err != nil {
  391. return output, err
  392. }
  393. config.VideoCoverFile = fileObjects
  394. }
  395. updatedConfig, err := json.Marshal(config)
  396. if err != nil {
  397. return output, nil
  398. }
  399. info.ComponentConfig = string(updatedConfig)
  400. }
  401. }
  402. }
  403. return output, nil
  404. },
  405. }),
  406. entity_crud.WithDeleteTx(),
  407. entity_crud.WithDeleteCallbacks(&entity_crud.DeleteCallbacks{
  408. After: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
  409. requestParams, err := request.ToConcrete[*mini_page_component.DeleteMiniPageComponentQueryParams](params)
  410. if err != nil {
  411. return err
  412. }
  413. err = database.Delete(tx, &sql.DeleteExecuteParams{
  414. TableName: domain.TableName(dbSchema, &mini_carousel_config.Entity{}),
  415. Conditions: sql.NewConditions().Equal(mini_carousel_config.ColumnComponentID, requestParams.ID),
  416. })
  417. if err != nil {
  418. return err
  419. }
  420. err = database.Delete(tx, &sql.DeleteExecuteParams{
  421. TableName: domain.TableName(dbSchema, &mini_live_config.Entity{}),
  422. Conditions: sql.NewConditions().Equal(mini_live_config.ColumnComponentID, requestParams.ID),
  423. })
  424. if err != nil {
  425. return err
  426. }
  427. err = database.Delete(tx, &sql.DeleteExecuteParams{
  428. TableName: domain.TableName(dbSchema, &mini_quality_product_config.Entity{}),
  429. Conditions: sql.NewConditions().Equal(mini_quality_product_config.ColumnComponentID, requestParams.ID),
  430. })
  431. if err != nil {
  432. return err
  433. }
  434. err = database.Delete(tx, &sql.DeleteExecuteParams{
  435. TableName: domain.TableName(dbSchema, &mini_video_config.Entity{}),
  436. Conditions: sql.NewConditions().Equal(mini_video_config.ColumnComponentID, requestParams.ID),
  437. })
  438. if err != nil {
  439. return err
  440. }
  441. return nil
  442. },
  443. }),
  444. )
  445. binding.PutBind(v1Binder, &binding.SimpleBindItem[any]{
  446. Path: "/miniPageComponent/enabledOrDisable",
  447. SendResponseFunc: response.SendMsgResponse,
  448. RequestParams: &mini_page_component.EnabledOrDisableJsonBody{},
  449. ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
  450. requestParams, err := request.ToConcrete[*mini_page_component.EnabledOrDisableJsonBody](params)
  451. if err != nil {
  452. return nil, err
  453. }
  454. err = database.Transaction(i.DBExecutor(), func(tx database.Executor) error {
  455. err = database.Update(tx, &sql.UpdateExecuteParams{
  456. TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
  457. Conditions: sql.NewConditions().Equal(entity.ColumnID, requestParams.ID),
  458. TableRow: sql.NewTableRow().Add(mini_page_component.ColumnIsEnabled, requestParams.IsEnabled),
  459. })
  460. //这个启用 别的都关掉
  461. if requestParams.IsEnabled == Enabled {
  462. err = database.Update(tx, &sql.UpdateExecuteParams{
  463. TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
  464. Conditions: sql.NewConditions().Not(entity.ColumnID, requestParams.ID).Equal(mini_page_component.ColumnComponentTypeID, requestParams.ComponentTypeID),
  465. TableRow: sql.NewTableRow().Add(mini_page_component.ColumnIsEnabled, Disable),
  466. })
  467. if err != nil {
  468. return err
  469. }
  470. }
  471. return nil
  472. })
  473. return nil, nil
  474. },
  475. })
  476. binding.PutBind(v1Binder, &binding.SimpleBindItem[any]{
  477. Path: "/miniPageComponent/sortOrder",
  478. SendResponseFunc: response.SendMsgResponse,
  479. RequestParams: &mini_page_component.SortOrderJsonBody{},
  480. ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
  481. requestParams, err := request.ToConcrete[*mini_page_component.SortOrderJsonBody](params)
  482. if err != nil {
  483. return nil, err
  484. }
  485. err = database.Transaction(i.DBExecutor(), func(tx database.Executor) error {
  486. for _, sortOrder := range requestParams.SortOrders {
  487. err = database.Update(tx, &sql.UpdateExecuteParams{
  488. TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
  489. Conditions: sql.NewConditions().Equal(entity.ColumnID, sortOrder.ID),
  490. TableRow: sql.NewTableRow().Add(mini_page_component.ColumnSortOrder, sortOrder.SortOrder),
  491. })
  492. if err != nil {
  493. return err
  494. }
  495. }
  496. return nil
  497. })
  498. if err != nil {
  499. return nil, err
  500. }
  501. return nil, nil
  502. },
  503. })
  504. }
  505. func (svc *MiniPageComponentService) queryByKeyFields(e *mini_page_component.Entity, dbExecutor database.Executor) (*mini_page_component.Entity, error) {
  506. result, err := database.QueryOne(dbExecutor, &sql.QueryOneExecuteParams{
  507. TableName: domain.TableName(dbSchema, e),
  508. Conditions: sql.NewConditions().Equal(entity.ColumnID, e.ID),
  509. })
  510. if err != nil {
  511. if database.IsErrorDBRecordNotExist(err) {
  512. return nil, errors.New(e.DomainCNName() + "不存在")
  513. }
  514. return nil, err
  515. }
  516. existEntity := new(mini_page_component.Entity)
  517. err = sql.ParseSqlResult(result, existEntity)
  518. if err != nil {
  519. return nil, err
  520. }
  521. return existEntity, nil
  522. }
  523. func (svc *MiniPageComponentService) checkExistByKeyFields(e *mini_page_component.Entity, dbExecutor database.Executor) error {
  524. exist, err := database.CheckExist(dbExecutor, &sql.CheckExistExecuteParams{
  525. TableName: domain.TableName(dbSchema, e),
  526. Conditions: sql.NewConditions().Equal(entity.ColumnID, e.ID),
  527. })
  528. if err != nil {
  529. return err
  530. }
  531. if !exist {
  532. return errors.New(e.DomainCNName() + "不存在")
  533. }
  534. return nil
  535. }