shop_decoration.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package service
  2. import (
  3. "ecos/application/domain/shop_decoration"
  4. "git.sxidc.com/go-framework/baize/convenient/entity_crud"
  5. "git.sxidc.com/go-framework/baize/framework/binding"
  6. "git.sxidc.com/go-framework/baize/framework/core/api"
  7. "git.sxidc.com/go-framework/baize/framework/core/application"
  8. "git.sxidc.com/go-framework/baize/framework/core/domain"
  9. "git.sxidc.com/go-framework/baize/framework/core/domain/entity"
  10. "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database"
  11. "git.sxidc.com/go-framework/baize/framework/core/infrastructure/database/sql"
  12. "github.com/pkg/errors"
  13. )
  14. var shopDecorationService = &ShopDecorationService{}
  15. type ShopDecorationService struct{}
  16. func (svc *ShopDecorationService) Init(appInstance *application.App) error {
  17. svc.v1(appInstance)
  18. return nil
  19. }
  20. func (svc *ShopDecorationService) Destroy() error {
  21. return nil
  22. }
  23. func (svc *ShopDecorationService) v1(appInstance *application.App) {
  24. v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"),
  25. appInstance.Infrastructure())
  26. entity_crud.BindSimple[shop_decoration.Info](v1Binder, &entity_crud.Simple[shop_decoration.Info]{
  27. Entity: &shop_decoration.Entity{},
  28. Schema: dbSchema,
  29. CreateJsonBody: &shop_decoration.CreateShopDecorationJsonBody{},
  30. DeleteQueryParams: &shop_decoration.DeleteShopDecorationQueryParams{},
  31. UpdateJsonBody: &shop_decoration.UpdateShopDecorationJsonBody{},
  32. QueryQueryParams: &shop_decoration.GetShopDecorationsQueryParams{},
  33. GetByIDQueryParams: &shop_decoration.GetShopDecorationQueryParams{},
  34. }, entity_crud.WithQueryStringFieldQueryCondition[shop_decoration.Info](entity_crud.StringFieldQueryConditionTrimSpaceLike))
  35. }
  36. func (svc *ShopDecorationService) queryByKeyFields(e *shop_decoration.Entity, dbExecutor database.Executor) (*shop_decoration.Entity, error) {
  37. result, err := database.QueryOne(dbExecutor, &sql.QueryOneExecuteParams{
  38. TableName: domain.TableName(dbSchema, e),
  39. Conditions: sql.NewConditions().Equal(entity.ColumnID, e.ID),
  40. })
  41. if err != nil {
  42. if database.IsErrorDBRecordNotExist(err) {
  43. return nil, errors.New(e.DomainCNName() + "不存在")
  44. }
  45. return nil, err
  46. }
  47. existEntity := new(shop_decoration.Entity)
  48. err = sql.ParseSqlResult(result, existEntity)
  49. if err != nil {
  50. return nil, err
  51. }
  52. return existEntity, nil
  53. }
  54. func (svc *ShopDecorationService) checkExistByKeyFields(e *shop_decoration.Entity, dbExecutor database.Executor) error {
  55. exist, err := database.CheckExist(dbExecutor, &sql.CheckExistExecuteParams{
  56. TableName: domain.TableName(dbSchema, e),
  57. Conditions: sql.NewConditions().Equal(entity.ColumnID, e.ID),
  58. })
  59. if err != nil {
  60. return err
  61. }
  62. if !exist {
  63. return errors.New(e.DomainCNName() + "不存在")
  64. }
  65. return nil
  66. }