incubator-streampark icon indicating copy to clipboard operation
incubator-streampark copied to clipboard

[Improvement] MyBatis-Plus Enum Refactoring Implementation Plan

Open GOODBOY008 opened this issue 5 months ago โ€ข 1 comments

๐Ÿš€ Enum Refactoring Plan Discussion

Hi team! I've created a comprehensive refactoring plan for migrating to MyBatis-Plus automatic enum conversion using @EnumValue annotations. This will improve maintainability and consistency across the codebase.

๐Ÿ“‹ Migration Overview

Goal: Leverage MyBatis-Plus's automatic enum conversion by using @EnumValue annotation for better maintainability and consistency.

๐Ÿ“Š Analysis Summary

Phase 1: Enums in streampark-common (12 enums to refactor)

  • ApplicationType.java โ†’ Annotate type (int)
  • ClusterState.java โ†’ Annotate state (Integer)
  • FlinkDeployMode.java โ†’ Annotate mode (Integer)
  • FlinkJobType.java โ†’ Annotate mode (Integer)
  • FlinkK8sRestExposedType.java โ†’ Annotate type (Integer)
  • FlinkRestoreMode.java โ†’ Annotate mode (int)
  • FlinkSqlValidationFailedType.java โ†’ Annotate failedType (int)
  • ResolveOrder.java โ†’ Annotate order (Integer)
  • SparkDeployMode.java โ†’ Annotate mode (Integer)
  • SparkJobType.java โ†’ Annotate mode (Integer)
  • SparkSqlValidationFailedType.java โ†’ Annotate failedType (int)
  • StorageType.java โ†’ Annotate type (String)

Phase 2: Enums in streampark-console (~25 enums to refactor)

Including: AccessTokenStateEnum, AlertTypeEnum, AppExistsStateEnum, AuthenticationType, BuildStateEnum, etc.

Note: Some enums already have @EnumValue annotation and just need verification.

๐ŸŽฏ Implementation Strategy

  1. Apply @EnumValue annotations to identified enum fields
  2. Refactor entity classes to use enum types directly instead of primitive values
  3. Update mapper interfaces and remove manual conversion logic
  4. Configure Jackson globally for consistent enum serialization to frontend

๐Ÿงช Testing & Verification Plan

  • Unit tests for enum value mapping
  • Integration tests for database persistence
  • Full build verification: mvn clean install
  • Existing test suite validation

๐Ÿ”ง Frontend Serialization (Bonus)

Recommend global Jackson configuration:

@Bean
public Jackson2ObjectMapperBuilderCustomizer customizer() {
    return builder -> builder.featuresToEnable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
}

๐Ÿค Next Steps

I'm ready to begin implementation following community feedback. Please let me know:

  • Your thoughts on the approach
  • Any concerns or suggestions
  • Preferred implementation order
  • Review preferences

Looking forward to your feedback! ๐Ÿ™Œ

Reference: MyBatis-Plus Official Docs - Auto Enum Conversion

GOODBOY008 avatar Aug 07 '25 07:08 GOODBOY008

Good proposal ๐Ÿ™Œ

wolfboys avatar Aug 07 '25 13:08 wolfboys