mini_page_component.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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.TenantID) {
  246. conditions = conditions.Equal(entity.ColumnTenantID, requestParams.TenantID)
  247. }
  248. if strutils.IsStringNotEmpty(requestParams.PageID) {
  249. conditions = conditions.Equal(mini_page_component.ColumnPageID, requestParams.PageID)
  250. }
  251. if strutils.IsStringNotEmpty(requestParams.ComponentTypeID) {
  252. conditions = conditions.Equal(mini_page_component.ColumnComponentTypeID, requestParams.ComponentTypeID)
  253. }
  254. if strutils.IsStringNotEmpty(requestParams.TypeName) {
  255. conditions = conditions.Like(mini_page_component.ColumnTypeName, "%"+requestParams.TypeName+"%")
  256. }
  257. if strutils.IsStringNotEmpty(requestParams.IsEnabled) {
  258. conditions = conditions.Equal(mini_page_component.ColumnPageID, requestParams.IsEnabled)
  259. }
  260. return &entity_crud.CustomCondition{
  261. Conditions: conditions,
  262. OrderBy: mini_page_component.ColumnSortOrder,
  263. }, nil
  264. }),
  265. entity_crud.WithGetByIDCallbacks(&entity_crud.GetByIDCallbacks[mini_page_component.Info]{
  266. OnSuccessReturn: func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure, output mini_page_component.Info) (mini_page_component.Info, error) {
  267. if strutils.IsStringNotEmpty(output.ComponentConfig) {
  268. if output.ComponentTypeID == "1" { //轮播图
  269. var config mini_page_component.CarouselConfig
  270. if err := json.Unmarshal([]byte(output.ComponentConfig), &config); err != nil {
  271. return output, nil
  272. }
  273. if len(config.Items) > 0 {
  274. for idx := range config.Items {
  275. if strutils.IsStringNotEmpty(config.Items[idx].ImageUrl) {
  276. fileObjects, err := osm.MultipleFileUrl(config.Items[idx].ImageUrl)
  277. if err != nil {
  278. return output, err
  279. }
  280. config.Items[idx].ImageUrls = fileObjects
  281. }
  282. }
  283. }
  284. updatedConfig, err := json.Marshal(config)
  285. if err != nil {
  286. return output, nil
  287. }
  288. output.ComponentConfig = string(updatedConfig)
  289. } else if output.ComponentTypeID == "2" { //2是直播
  290. var config mini_page_component.LiveWindowConfig
  291. if err := json.Unmarshal([]byte(output.ComponentConfig), &config); err != nil {
  292. return output, nil
  293. }
  294. if strutils.IsStringNotEmpty(config.LiveCoverUrl) {
  295. fileObjects, err := osm.MultipleFileUrl(config.LiveCoverUrl)
  296. if err != nil {
  297. return output, err
  298. }
  299. config.LiveCoverUrlFile = fileObjects
  300. }
  301. updatedConfig, err := json.Marshal(config)
  302. if err != nil {
  303. return output, nil
  304. }
  305. output.ComponentConfig = string(updatedConfig)
  306. } else if output.ComponentTypeID == "3" { //3是宣传视频
  307. var config mini_page_component.VideoComponentConfig
  308. if err := json.Unmarshal([]byte(output.ComponentConfig), &config); err != nil {
  309. return output, nil
  310. }
  311. if strutils.IsStringNotEmpty(config.VideoUrlStr) {
  312. fileObjects, err := osm.MultipleFileUrl(config.VideoUrlStr)
  313. if err != nil {
  314. return output, err
  315. }
  316. config.VideoUrlFile = fileObjects
  317. }
  318. if strutils.IsStringNotEmpty(config.VideoCoverStr) {
  319. fileObjects, err := osm.MultipleFileUrl(config.VideoCoverStr)
  320. if err != nil {
  321. return output, err
  322. }
  323. config.VideoCoverFile = fileObjects
  324. }
  325. updatedConfig, err := json.Marshal(config)
  326. if err != nil {
  327. return output, nil
  328. }
  329. output.ComponentConfig = string(updatedConfig)
  330. }
  331. }
  332. return output, nil
  333. },
  334. }),
  335. entity_crud.WithQueryCallbacks(&entity_crud.QueryCallbacks[mini_page_component.Info]{
  336. 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) {
  337. infos := output.Infos
  338. for i1 := range infos {
  339. info := &infos[i1]
  340. if strutils.IsStringNotEmpty(info.ComponentConfig) {
  341. if info.ComponentTypeID == "1" { //轮播图
  342. var config mini_page_component.CarouselConfig
  343. if err := json.Unmarshal([]byte(info.ComponentConfig), &config); err != nil {
  344. return output, nil
  345. }
  346. if len(config.Items) > 0 {
  347. for idx := range config.Items {
  348. if strutils.IsStringNotEmpty(config.Items[idx].ImageUrl) {
  349. fileObjects, err := osm.MultipleFileUrl(config.Items[idx].ImageUrl)
  350. if err != nil {
  351. return output, err
  352. }
  353. config.Items[idx].ImageUrls = fileObjects
  354. }
  355. }
  356. }
  357. updatedConfig, err := json.Marshal(config)
  358. if err != nil {
  359. return output, nil
  360. }
  361. info.ComponentConfig = string(updatedConfig)
  362. } else if info.ComponentTypeID == "2" { //2是直播
  363. var config mini_page_component.LiveWindowConfig
  364. if err := json.Unmarshal([]byte(info.ComponentConfig), &config); err != nil {
  365. return output, nil
  366. }
  367. if strutils.IsStringNotEmpty(config.LiveCoverUrl) {
  368. fileObjects, err := osm.MultipleFileUrl(config.LiveCoverUrl)
  369. if err != nil {
  370. return output, err
  371. }
  372. config.LiveCoverUrlFile = fileObjects
  373. }
  374. updatedConfig, err := json.Marshal(config)
  375. if err != nil {
  376. return output, nil
  377. }
  378. info.ComponentConfig = string(updatedConfig)
  379. } else if info.ComponentTypeID == "3" { //3是宣传视频
  380. var config mini_page_component.VideoComponentConfig
  381. if err := json.Unmarshal([]byte(info.ComponentConfig), &config); err != nil {
  382. return output, nil
  383. }
  384. if strutils.IsStringNotEmpty(config.VideoUrlStr) {
  385. fileObjects, err := osm.MultipleFileUrl(config.VideoUrlStr)
  386. if err != nil {
  387. return output, err
  388. }
  389. config.VideoUrlFile = fileObjects
  390. }
  391. if strutils.IsStringNotEmpty(config.VideoCoverStr) {
  392. fileObjects, err := osm.MultipleFileUrl(config.VideoCoverStr)
  393. if err != nil {
  394. return output, err
  395. }
  396. config.VideoCoverFile = fileObjects
  397. }
  398. updatedConfig, err := json.Marshal(config)
  399. if err != nil {
  400. return output, nil
  401. }
  402. info.ComponentConfig = string(updatedConfig)
  403. }
  404. }
  405. }
  406. return output, nil
  407. },
  408. }),
  409. entity_crud.WithDeleteTx(),
  410. entity_crud.WithDeleteCallbacks(&entity_crud.DeleteCallbacks{
  411. After: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
  412. requestParams, err := request.ToConcrete[*mini_page_component.DeleteMiniPageComponentQueryParams](params)
  413. if err != nil {
  414. return err
  415. }
  416. err = database.Delete(tx, &sql.DeleteExecuteParams{
  417. TableName: domain.TableName(dbSchema, &mini_carousel_config.Entity{}),
  418. Conditions: sql.NewConditions().Equal(mini_carousel_config.ColumnComponentID, requestParams.ID),
  419. })
  420. if err != nil {
  421. return err
  422. }
  423. err = database.Delete(tx, &sql.DeleteExecuteParams{
  424. TableName: domain.TableName(dbSchema, &mini_live_config.Entity{}),
  425. Conditions: sql.NewConditions().Equal(mini_live_config.ColumnComponentID, requestParams.ID),
  426. })
  427. if err != nil {
  428. return err
  429. }
  430. err = database.Delete(tx, &sql.DeleteExecuteParams{
  431. TableName: domain.TableName(dbSchema, &mini_quality_product_config.Entity{}),
  432. Conditions: sql.NewConditions().Equal(mini_quality_product_config.ColumnComponentID, requestParams.ID),
  433. })
  434. if err != nil {
  435. return err
  436. }
  437. err = database.Delete(tx, &sql.DeleteExecuteParams{
  438. TableName: domain.TableName(dbSchema, &mini_video_config.Entity{}),
  439. Conditions: sql.NewConditions().Equal(mini_video_config.ColumnComponentID, requestParams.ID),
  440. })
  441. if err != nil {
  442. return err
  443. }
  444. return nil
  445. },
  446. }),
  447. )
  448. binding.PutBind(v1Binder, &binding.SimpleBindItem[any]{
  449. Path: "/miniPageComponent/enabledOrDisable",
  450. SendResponseFunc: response.SendMsgResponse,
  451. RequestParams: &mini_page_component.EnabledOrDisableJsonBody{},
  452. ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
  453. requestParams, err := request.ToConcrete[*mini_page_component.EnabledOrDisableJsonBody](params)
  454. if err != nil {
  455. return nil, err
  456. }
  457. err = database.Transaction(i.DBExecutor(), func(tx database.Executor) error {
  458. err = database.Update(tx, &sql.UpdateExecuteParams{
  459. TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
  460. Conditions: sql.NewConditions().Equal(entity.ColumnID, requestParams.ID),
  461. TableRow: sql.NewTableRow().Add(mini_page_component.ColumnIsEnabled, requestParams.IsEnabled),
  462. })
  463. //这个启用 别的都关掉
  464. if requestParams.IsEnabled == Enabled {
  465. err = database.Update(tx, &sql.UpdateExecuteParams{
  466. TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
  467. Conditions: sql.NewConditions().Not(entity.ColumnID, requestParams.ID).Equal(mini_page_component.ColumnComponentTypeID, requestParams.ComponentTypeID),
  468. TableRow: sql.NewTableRow().Add(mini_page_component.ColumnIsEnabled, Disable),
  469. })
  470. if err != nil {
  471. return err
  472. }
  473. }
  474. return nil
  475. })
  476. return nil, nil
  477. },
  478. })
  479. binding.PutBind(v1Binder, &binding.SimpleBindItem[any]{
  480. Path: "/miniPageComponent/sortOrder",
  481. SendResponseFunc: response.SendMsgResponse,
  482. RequestParams: &mini_page_component.SortOrderJsonBody{},
  483. ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
  484. requestParams, err := request.ToConcrete[*mini_page_component.SortOrderJsonBody](params)
  485. if err != nil {
  486. return nil, err
  487. }
  488. err = database.Transaction(i.DBExecutor(), func(tx database.Executor) error {
  489. for i2 := range requestParams.SortOrders {
  490. sortOrder := requestParams.SortOrders[i2]
  491. err = database.Update(tx, &sql.UpdateExecuteParams{
  492. TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
  493. Conditions: sql.NewConditions().Equal(entity.ColumnID, sortOrder.ID),
  494. TableRow: sql.NewTableRow().Add(mini_page_component.ColumnSortOrder, sortOrder.SortOrder),
  495. })
  496. if err != nil {
  497. return err
  498. }
  499. }
  500. return nil
  501. })
  502. if err != nil {
  503. return nil, err
  504. }
  505. return nil, nil
  506. },
  507. })
  508. }
  509. func (svc *MiniPageComponentService) queryByKeyFields(e *mini_page_component.Entity, dbExecutor database.Executor) (*mini_page_component.Entity, error) {
  510. result, err := database.QueryOne(dbExecutor, &sql.QueryOneExecuteParams{
  511. TableName: domain.TableName(dbSchema, e),
  512. Conditions: sql.NewConditions().Equal(entity.ColumnID, e.ID),
  513. })
  514. if err != nil {
  515. if database.IsErrorDBRecordNotExist(err) {
  516. return nil, errors.New(e.DomainCNName() + "不存在")
  517. }
  518. return nil, err
  519. }
  520. existEntity := new(mini_page_component.Entity)
  521. err = sql.ParseSqlResult(result, existEntity)
  522. if err != nil {
  523. return nil, err
  524. }
  525. return existEntity, nil
  526. }
  527. func (svc *MiniPageComponentService) checkExistByKeyFields(e *mini_page_component.Entity, dbExecutor database.Executor) error {
  528. exist, err := database.CheckExist(dbExecutor, &sql.CheckExistExecuteParams{
  529. TableName: domain.TableName(dbSchema, e),
  530. Conditions: sql.NewConditions().Equal(entity.ColumnID, e.ID),
  531. })
  532. if err != nil {
  533. return err
  534. }
  535. if !exist {
  536. return errors.New(e.DomainCNName() + "不存在")
  537. }
  538. return nil
  539. }