|
|
@@ -0,0 +1,583 @@
|
|
|
+package service
|
|
|
+
|
|
|
+import (
|
|
|
+ "ecos/application/domain/mini_carousel_config"
|
|
|
+ "ecos/application/domain/mini_live_config"
|
|
|
+ "ecos/application/domain/mini_page_component"
|
|
|
+ "ecos/application/domain/mini_quality_product_config"
|
|
|
+ "ecos/application/domain/mini_video_config"
|
|
|
+ "ecos/osm"
|
|
|
+ "encoding/json"
|
|
|
+ "git.sxidc.com/go-framework/baize/convenient/entity_crud"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/binding"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/api"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/api/request"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/api/response"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/application"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/domain"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/domain/entity"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/infrastructure"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database"
|
|
|
+ "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database/sql"
|
|
|
+ "git.sxidc.com/go-tools/utils/strutils"
|
|
|
+ "github.com/pkg/errors"
|
|
|
+)
|
|
|
+
|
|
|
+var miniPageComponentService = &MiniPageComponentService{}
|
|
|
+
|
|
|
+type MiniPageComponentService struct{}
|
|
|
+
|
|
|
+func (svc *MiniPageComponentService) Init(appInstance *application.App) error {
|
|
|
+ svc.v1(appInstance)
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (svc *MiniPageComponentService) Destroy() error {
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (svc *MiniPageComponentService) v1(appInstance *application.App) {
|
|
|
+ v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"),
|
|
|
+ appInstance.Infrastructure())
|
|
|
+
|
|
|
+ entity_crud.BindSimple[mini_page_component.Info](v1Binder, &entity_crud.Simple[mini_page_component.Info]{
|
|
|
+ Entity: &mini_page_component.Entity{},
|
|
|
+ Schema: dbSchema,
|
|
|
+ CreateJsonBody: &mini_page_component.CreateMiniPageComponentJsonBody{},
|
|
|
+ DeleteQueryParams: &mini_page_component.DeleteMiniPageComponentQueryParams{},
|
|
|
+ UpdateJsonBody: &mini_page_component.UpdateMiniPageComponentJsonBody{},
|
|
|
+ QueryQueryParams: &mini_page_component.GetMiniPageComponentsQueryParams{},
|
|
|
+ GetByIDQueryParams: &mini_page_component.GetMiniPageComponentQueryParams{},
|
|
|
+ },
|
|
|
+ entity_crud.WithCreateTx(),
|
|
|
+ entity_crud.WithUpdateTx(),
|
|
|
+ entity_crud.WithCreateCallbacks(&entity_crud.CreateCallbacks{
|
|
|
+ Before: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
|
|
|
+ requestParams, err := request.ToConcrete[*mini_page_component.CreateMiniPageComponentJsonBody](params)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ record, err := domain.ToConcrete[*mini_page_component.Entity](e)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(requestParams.ComponentConfig) {
|
|
|
+ if requestParams.ComponentTypeID == "1" { //轮播图
|
|
|
+ var config mini_page_component.CarouselConfig
|
|
|
+ if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if len(config.Items) > 0 {
|
|
|
+ for idx := range config.Items {
|
|
|
+ if strutils.IsStringNotEmpty(config.Items[idx].ImageUrl) {
|
|
|
+ newFilePath, err := osm.MultipleFileMv(config.Items[idx].ImageUrl)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ config.Items[idx].ImageUrl = newFilePath
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ record.ComponentConfig = string(updatedConfig)
|
|
|
+ } else if requestParams.ComponentTypeID == "2" { //2是直播
|
|
|
+ var config mini_page_component.LiveWindowConfig
|
|
|
+ if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(config.LiveCoverUrl) {
|
|
|
+ newFilePath, err := osm.MultipleFileMv(config.LiveCoverUrl)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ config.LiveCoverUrl = newFilePath
|
|
|
+ }
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ record.ComponentConfig = string(updatedConfig)
|
|
|
+ } else if requestParams.ComponentTypeID == "3" { //3是宣传视频
|
|
|
+ var config mini_page_component.VideoComponentConfig
|
|
|
+ if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(config.VideoUrlStr) {
|
|
|
+ newFilePath, err := osm.MultipleFileMv(config.VideoUrlStr)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ config.VideoUrlStr = newFilePath
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(config.VideoCoverStr) {
|
|
|
+ newFilePath, err := osm.MultipleFileMv(config.VideoCoverStr)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ config.VideoCoverStr = newFilePath
|
|
|
+ }
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ record.ComponentConfig = string(updatedConfig)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ After: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
|
|
|
+ record, err := domain.ToConcrete[*mini_page_component.Entity](e)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if record.IsEnabled == Enabled {
|
|
|
+ //当前启用 把别的关掉
|
|
|
+ err = database.Update(tx, &sql.UpdateExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
|
|
|
+ Conditions: sql.NewConditions().Not(entity.ColumnID, e.GetID()).Equal(mini_page_component.ColumnComponentTypeID, record.ComponentTypeID),
|
|
|
+ TableRow: sql.NewTableRow().Add(mini_page_component.ColumnIsEnabled, Disable),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ entity_crud.WithUpdateCallbacks(&entity_crud.UpdateCallbacks{
|
|
|
+ Before: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
|
|
|
+ requestParams, err := request.ToConcrete[*mini_page_component.UpdateMiniPageComponentJsonBody](params)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ record, err := domain.ToConcrete[*mini_page_component.Entity](e)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(requestParams.ComponentConfig) {
|
|
|
+ if requestParams.ComponentTypeID == "1" { //轮播图
|
|
|
+ var config mini_page_component.CarouselConfig
|
|
|
+ if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if len(config.Items) > 0 {
|
|
|
+ for idx := range config.Items {
|
|
|
+ if strutils.IsStringNotEmpty(config.Items[idx].ImageUrl) {
|
|
|
+ newFilePath, err := osm.MultipleFileMv(config.Items[idx].ImageUrl)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ config.Items[idx].ImageUrl = newFilePath
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ record.ComponentConfig = string(updatedConfig)
|
|
|
+ } else if requestParams.ComponentTypeID == "2" { //2是直播
|
|
|
+ var config mini_page_component.LiveWindowConfig
|
|
|
+ if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(config.LiveCoverUrl) {
|
|
|
+ newFilePath, err := osm.MultipleFileMv(config.LiveCoverUrl)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ config.LiveCoverUrl = newFilePath
|
|
|
+ }
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ record.ComponentConfig = string(updatedConfig)
|
|
|
+ } else if requestParams.ComponentTypeID == "3" { //3是宣传视频
|
|
|
+ var config mini_page_component.VideoComponentConfig
|
|
|
+ if err := json.Unmarshal([]byte(requestParams.ComponentConfig), &config); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(config.VideoUrlStr) {
|
|
|
+ newFilePath, err := osm.MultipleFileMv(config.VideoUrlStr)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ config.VideoUrlStr = newFilePath
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(config.VideoCoverStr) {
|
|
|
+ newFilePath, err := osm.MultipleFileMv(config.VideoCoverStr)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ config.VideoCoverStr = newFilePath
|
|
|
+ }
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ record.ComponentConfig = string(updatedConfig)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ After: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
|
|
|
+ record, err := domain.ToConcrete[*mini_page_component.Entity](e)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if record.IsEnabled == Enabled {
|
|
|
+ //当前启用 把别的同code的关掉
|
|
|
+ err = database.Update(tx, &sql.UpdateExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
|
|
|
+ Conditions: sql.NewConditions().Not(entity.ColumnID, e.GetID()).Equal(mini_page_component.ColumnComponentTypeID, record.ComponentTypeID),
|
|
|
+ TableRow: sql.NewTableRow().Add(mini_page_component.ColumnIsEnabled, Disable),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ entity_crud.WithQueryFormCustomConditionFunc[mini_page_component.Info](func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure) (*entity_crud.CustomCondition, error) {
|
|
|
+ requestParams, err := request.ToConcrete[*mini_page_component.GetMiniPageComponentsQueryParams](params)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ conditions := sql.NewConditions()
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(requestParams.TenantID) {
|
|
|
+ conditions = conditions.Equal(entity.ColumnTenantID, requestParams.TenantID)
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(requestParams.PageID) {
|
|
|
+ conditions = conditions.Equal(mini_page_component.ColumnPageID, requestParams.PageID)
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(requestParams.ComponentTypeID) {
|
|
|
+ conditions = conditions.Equal(mini_page_component.ColumnComponentTypeID, requestParams.ComponentTypeID)
|
|
|
+ }
|
|
|
+ if strutils.IsStringNotEmpty(requestParams.TypeName) {
|
|
|
+ conditions = conditions.Like(mini_page_component.ColumnTypeName, "%"+requestParams.TypeName+"%")
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(requestParams.IsEnabled) {
|
|
|
+ conditions = conditions.Equal(mini_page_component.ColumnPageID, requestParams.IsEnabled)
|
|
|
+ }
|
|
|
+
|
|
|
+ return &entity_crud.CustomCondition{
|
|
|
+ Conditions: conditions,
|
|
|
+ OrderBy: mini_page_component.ColumnSortOrder,
|
|
|
+ }, nil
|
|
|
+ }),
|
|
|
+ entity_crud.WithGetByIDCallbacks(&entity_crud.GetByIDCallbacks[mini_page_component.Info]{
|
|
|
+ OnSuccessReturn: func(c *api.Context, params request.Params, e entity.Entity, i *infrastructure.Infrastructure, output mini_page_component.Info) (mini_page_component.Info, error) {
|
|
|
+ if strutils.IsStringNotEmpty(output.ComponentConfig) {
|
|
|
+ if output.ComponentTypeID == "1" { //轮播图
|
|
|
+ var config mini_page_component.CarouselConfig
|
|
|
+ if err := json.Unmarshal([]byte(output.ComponentConfig), &config); err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+ if len(config.Items) > 0 {
|
|
|
+ for idx := range config.Items {
|
|
|
+ if strutils.IsStringNotEmpty(config.Items[idx].ImageUrl) {
|
|
|
+ fileObjects, err := osm.MultipleFileUrl(config.Items[idx].ImageUrl)
|
|
|
+ if err != nil {
|
|
|
+ return output, err
|
|
|
+ }
|
|
|
+ config.Items[idx].ImageUrls = fileObjects
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+ output.ComponentConfig = string(updatedConfig)
|
|
|
+ } else if output.ComponentTypeID == "2" { //2是直播
|
|
|
+
|
|
|
+ var config mini_page_component.LiveWindowConfig
|
|
|
+ if err := json.Unmarshal([]byte(output.ComponentConfig), &config); err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(config.LiveCoverUrl) {
|
|
|
+ fileObjects, err := osm.MultipleFileUrl(config.LiveCoverUrl)
|
|
|
+ if err != nil {
|
|
|
+ return output, err
|
|
|
+ }
|
|
|
+ config.LiveCoverUrlFile = fileObjects
|
|
|
+ }
|
|
|
+
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+ output.ComponentConfig = string(updatedConfig)
|
|
|
+
|
|
|
+ } else if output.ComponentTypeID == "3" { //3是宣传视频
|
|
|
+ var config mini_page_component.VideoComponentConfig
|
|
|
+ if err := json.Unmarshal([]byte(output.ComponentConfig), &config); err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(config.VideoUrlStr) {
|
|
|
+ fileObjects, err := osm.MultipleFileUrl(config.VideoUrlStr)
|
|
|
+ if err != nil {
|
|
|
+ return output, err
|
|
|
+ }
|
|
|
+ config.VideoUrlFile = fileObjects
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(config.VideoCoverStr) {
|
|
|
+ fileObjects, err := osm.MultipleFileUrl(config.VideoCoverStr)
|
|
|
+ if err != nil {
|
|
|
+ return output, err
|
|
|
+ }
|
|
|
+ config.VideoCoverFile = fileObjects
|
|
|
+ }
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+ output.ComponentConfig = string(updatedConfig)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return output, nil
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ entity_crud.WithQueryCallbacks(&entity_crud.QueryCallbacks[mini_page_component.Info]{
|
|
|
+ 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) {
|
|
|
+ infos := output.Infos
|
|
|
+ for i1 := range infos {
|
|
|
+ info := &infos[i1]
|
|
|
+ if strutils.IsStringNotEmpty(info.ComponentConfig) {
|
|
|
+ if info.ComponentTypeID == "1" { //轮播图
|
|
|
+ var config mini_page_component.CarouselConfig
|
|
|
+ if err := json.Unmarshal([]byte(info.ComponentConfig), &config); err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+ if len(config.Items) > 0 {
|
|
|
+ for idx := range config.Items {
|
|
|
+ if strutils.IsStringNotEmpty(config.Items[idx].ImageUrl) {
|
|
|
+ fileObjects, err := osm.MultipleFileUrl(config.Items[idx].ImageUrl)
|
|
|
+ if err != nil {
|
|
|
+ return output, err
|
|
|
+ }
|
|
|
+ config.Items[idx].ImageUrls = fileObjects
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+ info.ComponentConfig = string(updatedConfig)
|
|
|
+ } else if info.ComponentTypeID == "2" { //2是直播
|
|
|
+
|
|
|
+ var config mini_page_component.LiveWindowConfig
|
|
|
+ if err := json.Unmarshal([]byte(info.ComponentConfig), &config); err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(config.LiveCoverUrl) {
|
|
|
+ fileObjects, err := osm.MultipleFileUrl(config.LiveCoverUrl)
|
|
|
+ if err != nil {
|
|
|
+ return output, err
|
|
|
+ }
|
|
|
+ config.LiveCoverUrlFile = fileObjects
|
|
|
+ }
|
|
|
+
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+ info.ComponentConfig = string(updatedConfig)
|
|
|
+
|
|
|
+ } else if info.ComponentTypeID == "3" { //3是宣传视频
|
|
|
+ var config mini_page_component.VideoComponentConfig
|
|
|
+ if err := json.Unmarshal([]byte(info.ComponentConfig), &config); err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(config.VideoUrlStr) {
|
|
|
+ fileObjects, err := osm.MultipleFileUrl(config.VideoUrlStr)
|
|
|
+ if err != nil {
|
|
|
+ return output, err
|
|
|
+ }
|
|
|
+ config.VideoUrlFile = fileObjects
|
|
|
+ }
|
|
|
+
|
|
|
+ if strutils.IsStringNotEmpty(config.VideoCoverStr) {
|
|
|
+ fileObjects, err := osm.MultipleFileUrl(config.VideoCoverStr)
|
|
|
+ if err != nil {
|
|
|
+ return output, err
|
|
|
+ }
|
|
|
+ config.VideoCoverFile = fileObjects
|
|
|
+ }
|
|
|
+ updatedConfig, err := json.Marshal(config)
|
|
|
+ if err != nil {
|
|
|
+ return output, nil
|
|
|
+ }
|
|
|
+ info.ComponentConfig = string(updatedConfig)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return output, nil
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ entity_crud.WithDeleteTx(),
|
|
|
+ entity_crud.WithDeleteCallbacks(&entity_crud.DeleteCallbacks{
|
|
|
+ After: func(c *api.Context, params request.Params, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
|
|
|
+
|
|
|
+ requestParams, err := request.ToConcrete[*mini_page_component.DeleteMiniPageComponentQueryParams](params)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = database.Delete(tx, &sql.DeleteExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, &mini_carousel_config.Entity{}),
|
|
|
+ Conditions: sql.NewConditions().Equal(mini_carousel_config.ColumnComponentID, requestParams.ID),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = database.Delete(tx, &sql.DeleteExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, &mini_live_config.Entity{}),
|
|
|
+ Conditions: sql.NewConditions().Equal(mini_live_config.ColumnComponentID, requestParams.ID),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = database.Delete(tx, &sql.DeleteExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, &mini_quality_product_config.Entity{}),
|
|
|
+ Conditions: sql.NewConditions().Equal(mini_quality_product_config.ColumnComponentID, requestParams.ID),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = database.Delete(tx, &sql.DeleteExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, &mini_video_config.Entity{}),
|
|
|
+ Conditions: sql.NewConditions().Equal(mini_video_config.ColumnComponentID, requestParams.ID),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ )
|
|
|
+
|
|
|
+ binding.PutBind(v1Binder, &binding.SimpleBindItem[any]{
|
|
|
+ Path: "/miniPageComponent/enabledOrDisable",
|
|
|
+ SendResponseFunc: response.SendMsgResponse,
|
|
|
+ RequestParams: &mini_page_component.EnabledOrDisableJsonBody{},
|
|
|
+ ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
|
|
|
+ requestParams, err := request.ToConcrete[*mini_page_component.EnabledOrDisableJsonBody](params)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ err = database.Transaction(i.DBExecutor(), func(tx database.Executor) error {
|
|
|
+ err = database.Update(tx, &sql.UpdateExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
|
|
|
+ Conditions: sql.NewConditions().Equal(entity.ColumnID, requestParams.ID),
|
|
|
+ TableRow: sql.NewTableRow().Add(mini_page_component.ColumnIsEnabled, requestParams.IsEnabled),
|
|
|
+ })
|
|
|
+ //这个启用 别的都关掉
|
|
|
+ if requestParams.IsEnabled == Enabled {
|
|
|
+ err = database.Update(tx, &sql.UpdateExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
|
|
|
+ Conditions: sql.NewConditions().Not(entity.ColumnID, requestParams.ID).Equal(mini_page_component.ColumnComponentTypeID, requestParams.ComponentTypeID),
|
|
|
+ TableRow: sql.NewTableRow().Add(mini_page_component.ColumnIsEnabled, Disable),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+ return nil, nil
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ binding.PutBind(v1Binder, &binding.SimpleBindItem[any]{
|
|
|
+ Path: "/miniPageComponent/sortOrder",
|
|
|
+ SendResponseFunc: response.SendMsgResponse,
|
|
|
+ RequestParams: &mini_page_component.SortOrderJsonBody{},
|
|
|
+ ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
|
|
|
+ requestParams, err := request.ToConcrete[*mini_page_component.SortOrderJsonBody](params)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ err = database.Transaction(i.DBExecutor(), func(tx database.Executor) error {
|
|
|
+ for i2 := range requestParams.SortOrders {
|
|
|
+ sortOrder := requestParams.SortOrders[i2]
|
|
|
+ err = database.Update(tx, &sql.UpdateExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, &mini_page_component.Entity{}),
|
|
|
+ Conditions: sql.NewConditions().Equal(entity.ColumnID, sortOrder.ID),
|
|
|
+ TableRow: sql.NewTableRow().Add(mini_page_component.ColumnSortOrder, sortOrder.SortOrder),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return nil, nil
|
|
|
+
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (svc *MiniPageComponentService) queryByKeyFields(e *mini_page_component.Entity, dbExecutor database.Executor) (*mini_page_component.Entity, error) {
|
|
|
+ result, err := database.QueryOne(dbExecutor, &sql.QueryOneExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, e),
|
|
|
+ Conditions: sql.NewConditions().Equal(entity.ColumnID, e.ID),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ if database.IsErrorDBRecordNotExist(err) {
|
|
|
+ return nil, errors.New(e.DomainCNName() + "不存在")
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ existEntity := new(mini_page_component.Entity)
|
|
|
+ err = sql.ParseSqlResult(result, existEntity)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return existEntity, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (svc *MiniPageComponentService) checkExistByKeyFields(e *mini_page_component.Entity, dbExecutor database.Executor) error {
|
|
|
+ exist, err := database.CheckExist(dbExecutor, &sql.CheckExistExecuteParams{
|
|
|
+ TableName: domain.TableName(dbSchema, e),
|
|
|
+ Conditions: sql.NewConditions().Equal(entity.ColumnID, e.ID),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ if !exist {
|
|
|
+ return errors.New(e.DomainCNName() + "不存在")
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|