bengbengbalabalabeng commented on issue #854:
URL: https://github.com/apache/fesod/issues/854#issuecomment-4214821946

   Below is my updated design proposal:
   
   ### Proposal (NEW)
   
   This proposal aims to introduce a Java Type-based/String-based grouping 
feature for data export.
   
   **Use Case:**
   
   This addresses the issue of proliferating redundant VO classes caused by 
varying field filtering logic across different export scenarios. By 
implementing a grouping mechanism, a single DTO model can flexibly adapt to 
multiple business export templates.
   
   **Advantages:**
   
   - Compatible with both Type-based (Utilizes **Interface Inheritance** to 
establish nested and inclusive relationships between groups) and String-based 
grouping modes.
   - Reduce maintenance of redundant VO classes.
   
   ### API Usage Example
   
   #### By Type-based
   
   ##### 1. Basic Grouping
   Define simple **Marker Interfaces** to filter fields for different scenarios.
   
   - Define Group Interfaces and Entity
   
   ```java
   public interface SchoolGroup {}
   public interface StudentGroup {}
   
   @Data
   public class SchoolWholeStatData {
       
       @ExcelView(asTypes = SchoolGroup.class)
       @ExcelProperty(value = "School Name")
       private String schoolName;
   
       @ExcelView(asTypes = StudentGroup.class)
       @ExcelProperty(value = "Student Name")
       private String studentName;
   
       // Fields not annotated with '@ExcelView' will not be processed for 
export.
       @ExcelProperty(value = "Update Time")
       private Date updateTime;
   }
   ```
   
   - Demo
   
   ```java
   // Export only School-related fields.
   FesodSheet.write(fileName, SchoolWholeStatData.class)
       .groups(SchoolGroup.class) 
       .sheet()
       .doWrite(dataList);
   ```
   
   ##### 2. Hierarchical Grouping
   Leverage interface inheritance to implement a "Base Group + Extended Group" 
export pattern.
   
   - Define Group Interfaces with Inheritance and Entity
   
   ```java
   public interface BaseGroup {}
    // DetailGroup includes all fields from BaseGroup
   public interface DetailGroup extends BaseGroup {}
   
   @Data
   public class OrderData {
       
       @ExcelView(asTypes = BaseGroup.class)
       @ExcelProperty(value = "Order No")
       private String orderNo;
   
       @ExcelView(asTypes = DetailGroup.class)
       @ExcelProperty(value = "Payment Transaction No")
       private String paymentNo;
   }
   ```
   
   - Demo
   
   ```java
   // By passing DetailGroup.class, both orderNo (inherited) and paymentNo are 
exported.
   FesodSheet.write(fileName, OrderData.class)
       .groups(DetailGroup.class)
       .sheet()
       .doWrite(dataList);
   ```
   
   ##### 3. Multiple Groups Activation
   Supports activating multiple grouping logics within a single export session.
   
   - Demo
   
   ```java
   // Export both School and Student fields simultaneously
   FesodSheet.write(fileName, SchoolWholeStatData.class)
       .groups(SchoolGroup.class, StudentGroup.class)
       .sheet()
       .doWrite(dataList);
   ```
   
   #### By String-based
   
   ##### 1. Basic Grouping
   
   - Define Entity
   
   ```java
   @Data
   public class SchoolWholeStatData {
       
       @ExcelView(asStrings = "SchoolGroup")
       @ExcelProperty(value = "School Name")
       private String schoolName;
   
       @ExcelView(asStrings = "StudentGroup")
       @ExcelProperty(value = "Student Name")
       private String studentName;
   
       // Fields not annotated with '@ExcelView' will not be processed for 
export.
       @ExcelProperty(value = "Update Time")
       private Date updateTime;
   }
   ```
   
   - Demo
   
   ```java
   // Export only School-related fields.
   FesodSheet.write(fileName, SchoolWholeStatData.class)
       .tags("SchoolGroup") 
       .sheet()
       .doWrite(dataList);
   ```
   
   ##### 2. Multiple Groups Activation
   Supports activating multiple tags logics within a single export session.
   
   - Demo
   
   ```java
   // Export both School and Student fields simultaneously
   FesodSheet.write(fileName, SchoolWholeStatData.class)
       .tags("SchoolGroup", "StudentGroup")
       .sheet()
       .doWrite(dataList);
   ```
   
   #### Override Strategies
   When mixing `groups` and `tags`, the last assigned strategy takes effect.
   
   - Demo
   
   ```java
   // Export both School and Student fields simultaneously
   FesodSheet.write(fileName, SchoolWholeStatData.class)
       .groups(SchoolGroup.class)
       // takes effect
       .tags("SchoolGroup", "StudentGroup")
       .sheet()
       .doWrite(dataList);
   ```
   
   ### More
   
   - Fields not annotated with '@ExcelView' will not be processed for export.
   - This feature is fully compatible with Fesod's existing `@ExcelIgnore`, 
`@ExcelIgnoreUnannotated`, and `includeColumn*`/`excludeColumn*` logic.
   
   Filtering Priority:
   
   `@ExcelIgnore` / `@ExcelIgnoreUnannotated` > `@ExcelView` > `includeColumn*` 
/ `excludeColumn*`
   
   ---
   
   Feel free to let me know if you have any suggestions :)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to