Skip to content

feat: Add model API #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open

feat: Add model API #249

wants to merge 21 commits into from

Conversation

lu-yg
Copy link
Collaborator

@lu-yg lu-yg commented Jul 23, 2025

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Full CRUD for "Model" entities with paginated/filtered listing, API docs, standardized responses, and endpoints to retrieve/generated CREATE TABLE SQL.
  • Database

    • Added new "Model" table to store model metadata (names, version, URL, parameters, methods, description, audit/tenant/site fields) with a unique index; removed a deprecated component-library column.
  • Bug Fixes

    • Fixed SQL insert syntax in tenant creation.
  • Other

    • Added supporting DTOs, enums, mapper, service and controller layers for model management and API modeling.

Copy link

coderabbitai bot commented Jul 23, 2025

Walkthrough

Adds a new Model domain: SQL DDLs to create t_model, Java entity, DTOs, enums, MyBatis mapper (interface + XML), service interface and implementation, REST controller, and a small SQL mapper syntax fix. Also removes an earlier app_id ALTER in an H2 update script.

Changes

Cohort / File(s) Change Summary
SQL — create model tables
app/src/main/resources/sql/h2/create_model_ddl_2025_0717.sql, app/src/main/resources/sql/mysql/create_model_ddl_2025_0717.sql, docker-deploy-data/mysql/init/create_model_ddl_2025_0717.sql
Added drop-if-exists and CREATE TABLE DDL for t_model with columns (id, name_cn/name, name_en, version, model_url, parameters, method, description, created_by/created_time, last_updated_by/last_updated_time, tenant_id, renter_id, site_id), per-column comments, PK on id, unique index on (name/name_cn, version), engine/table comments.
SQL — updates
app/src/main/resources/sql/h2/update_all_tables_ddl.sql
Removed previously added app_id ALTER TABLE statement for t_component_library.
Java — enums
base/src/main/java/com/tinyengine/it/common/enums/Enums.java
Added enums methodName, paramType, and methodParam with string values and getValue() accessors.
Controller
base/src/main/java/com/tinyengine/it/controller/ModelController.java
New REST controller exposing endpoints for list (paginated), find, create, update, delete, detail, and model DDL retrieval; uses validation, logging annotations, and API docs; delegates to ModelService.
Mapper interface
base/src/main/java/com/tinyengine/it/mapper/ModelMapper.java
New ModelMapper extending BaseMapper<Model> with createModel(Model) and updateModelById(Model) methods.
MyBatis XML mapper
base/src/main/resources/mappers/ModelMapper.xml
New mapper XML with ResultMap, Base_Column_List, dynamic condition/update fragments, and CRUD SQL for t_model (select/insert/update/delete).
DTOs
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java, .../ParametersDto.java, .../RequestParameter.java, .../ResponseParameter.java
Added DTO classes modeling method metadata and nested parameter structures; annotated with Lombok @Data.
Entity
base/src/main/java/com/tinyengine/it/model/entity/Model.java
New Model entity mapped to t_model with fields nameCn/nameEn/version/modelUrl/parameters/method/description; list fields use ListTypeHandler.
Service interface
base/src/main/java/com/tinyengine/it/service/material/ModelService.java
Added ModelService interface declaring CRUD, paginated query, and DDL-generation methods (getTableById, getAllTable).
Service implementation
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java
New ModelServiceImpl implementing ModelService: CRUD, paginated queries, attaches MethodDto metadata on create/update, throws ServiceException on DB anomalies, and provides DDL generation utilities mapping DTO parameter types to SQL.
Mapper fix
base/src/main/resources/mappers/TenantMapper.xml
Fixed missing closing parenthesis in createTenant INSERT VALUES clause.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller as ModelController
    participant Service as ModelServiceImpl
    participant Mapper as ModelMapper
    participant DB

    Client->>Controller: HTTP request (Create/Update/Delete/Get/List/Find/GetDDL)
    Controller->>Service: validate & forward request
    Service->>Mapper: perform SQL (insert/update/delete/select)
    Mapper->>DB: execute query on t_model
    DB-->>Mapper: query result
    Mapper-->>Service: mapped Model(s) / row count
    Service-->>Controller: Model / Page / SQL string / status
    Controller-->>Client: Result wrapper response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I dug a little table neat and bright,
Columns and DTOs tucked in tight.
Controllers hop, services hum the tune,
Mappers whisper SQL by the moon.
A carrot nod for models taking flight.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

🧹 Nitpick comments (12)
base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (1)

22-26: LGTM! Simple and well-structured DTO.

The implementation follows established patterns and integrates well with the related DTOs (RequestParameter, ParametersDto, MethodDto). Consider adding validation annotations (e.g., @NotNull, @NotBlank) if these fields have business constraints.

base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (1)

22-29: LGTM! Comprehensive parameter DTO with good field selection.

The class effectively models parameter metadata with appropriate field types. The use of primitive boolean for required is acceptable since it defaults to false, but consider Boolean wrapper if you need to distinguish between unset and false values.

base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1)

20-20: Fix the documentation comment.

The comment incorrectly refers to "responseParameter dto" when this is actually the RequestParameter class.

- * The type responseParameter dto.
+ * The type RequestParameter dto.
base/src/main/java/com/tinyengine/it/service/material/ModelService.java (3)

46-48: Fix Javadoc parameter syntax.

The Javadoc parameter documentation uses incorrect syntax with spaces.

-     * @ param the model
+     * @param model the model

54-56: Fix Javadoc parameter syntax.

The Javadoc parameter documentation uses incorrect syntax with spaces.

-     * @ param the id
+     * @param id the id

62-64: Fix Javadoc parameter syntax.

The Javadoc parameter documentation uses incorrect syntax with spaces.

-     * @ param the model
+     * @param model the model
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (3)

1007-1043: Consider Java naming conventions for enum names.

The enum methodName should follow Java naming conventions and be named MethodName. However, I notice this is consistent with some existing enums in the file like paramType and methodParam.

For better adherence to Java conventions, consider:

-    public enum methodName {
+    public enum MethodName {

1045-1081: Consider Java naming conventions for enum names.

Same naming convention issue as with methodName.

-    public enum paramType {
+    public enum ParamType {

1083-1149: Consider Java naming conventions for enum names.

Same naming convention issue as with the other new enums.

-    public enum methodParam {
+    public enum MethodParam {
base/src/main/resources/mappers/ModelMapper.xml (1)

24-32: Use parameterized LIKE queries for text search fields

The current conditions use exact equality checks for text fields like parameters, method, and description. These should typically use LIKE queries for better search functionality.

-        <if test="parameters!=null and parameters!=''">
-            AND parameters = #{parameters}
-        </if>
-        <if test="method!=null and method!=''">
-            AND `method` = #{method}
-        </if>
-        <if test="description!=null and description!=''">
-            AND description = #{description}
-        </if>
+        <if test="parameters!=null and parameters!=''">
+            AND parameters LIKE CONCAT('%', #{parameters}, '%')
+        </if>
+        <if test="method!=null and method!=''">
+            AND `method` LIKE CONCAT('%', #{method}, '%')
+        </if>
+        <if test="description!=null and description!=''">
+            AND description LIKE CONCAT('%', #{description}, '%')
+        </if>
base/src/main/java/com/tinyengine/it/controller/ModelController.java (1)

129-129: Fix incorrect parameter descriptions

The parameter descriptions incorrectly refer to "appId" instead of "id" or "modelId".

-        @Parameter(name = "id", description = "appId"),
+        @Parameter(name = "id", description = "Model ID"),

And in line 171:

-        @Parameter(name = "id", description = "appId")
+        @Parameter(name = "id", description = "Model ID")

Also applies to: 171-171

base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)

70-90: Simplify query logic for name filters

The current implementation has complex conditional logic for OR queries that could be simplified.

 public Page<Model> pageQuery(int currentPage, int pageSize, String nameCn, String nameEn) {
     Page<Model> page = new Page<>(currentPage, pageSize);
     QueryWrapper<Model> queryWrapper = new QueryWrapper<>();
 
-    // 判断 nameCn 是否存在
-    if (nameCn != null && !nameCn.isEmpty()) {
-        queryWrapper.like("name_cn", nameCn);
-    }
-
-    // 判断 nameEn 是否存在
-    if (nameEn != null && !nameEn.isEmpty()) {
-        if (nameCn != null && !nameCn.isEmpty()) {
-            queryWrapper.or().like("name_en", nameEn);
-        } else {
-            queryWrapper.like("name_en", nameEn);
-        }
-    }
+    if (nameCn != null && !nameCn.isEmpty() && nameEn != null && !nameEn.isEmpty()) {
+        queryWrapper.and(wrapper -> wrapper
+            .like("name_cn", nameCn)
+            .or()
+            .like("name_en", nameEn));
+    } else if (nameCn != null && !nameCn.isEmpty()) {
+        queryWrapper.like("name_cn", nameCn);
+    } else if (nameEn != null && !nameEn.isEmpty()) {
+        queryWrapper.like("name_en", nameEn);
+    }
 
     page(page, queryWrapper);
     return page;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24cfb66 and 216177b.

📒 Files selected for processing (16)
  • app/src/main/resources/sql/h2/create_model_ddl_2025_0717.sql (1 hunks)
  • app/src/main/resources/sql/h2/update_all_tables_ddl.sql (0 hunks)
  • app/src/main/resources/sql/mysql/create_model_ddl_2025_0717.sql (1 hunks)
  • base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/controller/ModelController.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/mapper/ModelMapper.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/model/entity/Model.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/material/ModelService.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1 hunks)
  • base/src/main/resources/mappers/ModelMapper.xml (1 hunks)
  • base/src/main/resources/mappers/TenantMapper.xml (1 hunks)
  • docker-deploy-data/mysql/init/create_model_ddl_2025_0717.sql (1 hunks)
🧬 Code Graph Analysis (5)
base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (3)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (1)
  • Data (22-29)
base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (1)
  • Data (22-26)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (3)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (1)
  • Data (22-29)
base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (1)
  • Data (22-26)
base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (3)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (1)
  • Data (22-29)
base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (3)
base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (1)
  • Data (22-26)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1)
  • Enums (20-1150)
💤 Files with no reviewable changes (1)
  • app/src/main/resources/sql/h2/update_all_tables_ddl.sql
🧰 Additional context used
🧬 Code Graph Analysis (5)
base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (3)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (1)
  • Data (22-29)
base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (1)
  • Data (22-26)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (3)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (1)
  • Data (22-29)
base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (1)
  • Data (22-26)
base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (3)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (1)
  • Data (22-29)
base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (3)
base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (1)
  • Data (22-26)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1)
  • Enums (20-1150)
🔇 Additional comments (9)
base/src/main/resources/mappers/TenantMapper.xml (1)

145-145: LGTM! Critical SQL syntax fix.

The missing closing parenthesis would have caused SQL execution failures. This fix properly matches the opening parenthesis in the INSERT statement.

base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1)

24-29: LGTM! Well-designed hierarchical parameter structure.

The class effectively models request parameters with support for nested children through List<ParametersDto>. This design enables complex API parameter modeling while maintaining clean separation of concerns.

base/src/main/java/com/tinyengine/it/mapper/ModelMapper.java (1)

23-40: LGTM! Well-designed mapper interface following MyBatis-Plus patterns.

The interface properly extends BaseMapper<Model> and adds domain-specific methods with appropriate signatures. The Chinese documentation is comprehensive and follows the project's documentation standards. The int return type correctly indicates affected row counts for the persistence operations.

base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1)

24-29: LGTM! Clean DTO implementation.

The DTO follows standard patterns with appropriate field types and Lombok integration. The structure aligns well with the referenced RequestParameter and ResponseParameter DTOs from the relevant code snippets.

base/src/main/java/com/tinyengine/it/service/material/ModelService.java (1)

21-66: Well-designed service interface.

The interface follows standard patterns with appropriate CRUD methods and extends MyBatis-Plus IService correctly. Method signatures and return types are consistent and appropriate for model management operations.

base/src/main/java/com/tinyengine/it/model/entity/Model.java (1)

33-58: Well-designed entity class.

The entity follows best practices:

  • Proper MyBatis-Plus annotations with custom type handlers for complex fields
  • Comprehensive Swagger documentation for API generation
  • Appropriate use of Lombok for boilerplate reduction
  • Clean field naming and types that align with the database schema
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1)

1007-1149: Well-structured enums for model API support.

The three new enums provide good constants for the model API feature:

  • methodName: Defines CRUD operations with Chinese descriptions
  • paramType: Covers essential data types for API parameters
  • methodParam: Provides common parameter names for consistency

The implementation follows the established pattern in the file with proper encapsulation and accessor methods.

app/src/main/resources/sql/mysql/create_model_ddl_2025_0717.sql (1)

1-21: Well-designed database schema.

The table structure is thoughtfully designed with:

  • Appropriate data types and sizes for each field
  • Proper primary key and unique constraints
  • Comprehensive audit trail fields
  • Multi-tenancy support fields
  • Alignment with the Model entity class structure

The unique index on name_cn and version ensures data integrity by preventing duplicate models.

base/src/main/resources/mappers/ModelMapper.xml (1)

151-158: Potential trailing comma issue in dynamic SET clause

The ModelSetColumns SQL fragment could generate a trailing comma if all conditions are met, which would cause a SQL syntax error.

MyBatis <set> tag automatically handles trailing commas, so the update statement is correctly structured. The SQL fragment itself has commas but when used within <set> tags, MyBatis manages them properly.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (6)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (6)

55-61: Incomplete fix from previous review - search both name fields

The method only searches the Chinese name field, but based on the schema having both name_cn and name_en columns, it should search both fields as suggested in the previous review.

 public List<Model> getModelByName(String nameCn) {
     QueryWrapper<Model> queryWrapper = new QueryWrapper<>();
-    queryWrapper.like("name_cn", nameCn);
+    queryWrapper.like("name_cn", nameCn)
+               .or()
+               .like("name_en", nameCn);
     return this.baseMapper.selectList(queryWrapper);
 }

102-107: Extract duplicate method generation logic

The same method generation code is duplicated in both createModel and updateModelById methods.

Extract this logic into a private method:

+private List<MethodDto> generateStandardMethods(Model model) {
+    List<MethodDto> methodDtos = new ArrayList<>();
+    methodDtos.add(getMethodDto(Enums.methodName.CREATED.getValue(), model));
+    methodDtos.add(getMethodDto(Enums.methodName.UPDATE.getValue(), model));
+    methodDtos.add(getMethodDto(Enums.methodName.QUERY.getValue(), model));
+    methodDtos.add(getMethodDto(Enums.methodName.DELETE.getValue(), model));
+    return methodDtos;
+}

 public Model createModel(Model model) {
-    List<MethodDto> methodDtos = new ArrayList<>();
-    methodDtos.add(getMethodDto(Enums.methodName.CREATED.getValue(), model));
-    methodDtos.add(getMethodDto(Enums.methodName.UPDATE.getValue(), model));
-    methodDtos.add(getMethodDto(Enums.methodName.QUERY.getValue(), model));
-    methodDtos.add(getMethodDto(Enums.methodName.DELETE.getValue(), model));
-    model.setMethod(methodDtos);
+    model.setMethod(generateStandardMethods(model));
     int result = this.baseMapper.createModel(model);
     // ... rest of the method

110-110: Fix error message parameter

The error handling uses the same error code for both parameters, which doesn't provide meaningful error information.

-            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultCode());
+            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());

128-128: Fix error message parameter

Same issue as in createModel - using error code for message parameter.

-            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultCode());
+            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());

150-150: Fix error message parameters in both exceptions

Both ServiceException calls use error code for the message parameter.

-        throw new ServiceException(ExceptionEnum.CM002.getResultCode(), ExceptionEnum.CM002.getResultCode());
+        throw new ServiceException(ExceptionEnum.CM002.getResultCode(), ExceptionEnum.CM002.getResultMsg());
         
-        throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultCode());
+        throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());

Also applies to: 154-154


187-187: Use proper string comparison with equals()

String comparison should use .equals() method instead of != operator.

-        if (name != Enums.methodName.DELETE.getValue()) {
+        if (!name.equals(Enums.methodName.DELETE.getValue())) {
🧹 Nitpick comments (1)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)

70-90: Consider simplifying the query builder logic

The implementation is correct, but the nested conditionals could be simplified for better readability.

 public Page<Model> pageQuery(int currentPage, int pageSize, String nameCn, String nameEn) {
     Page<Model> page = new Page<>(currentPage, pageSize);
     QueryWrapper<Model> queryWrapper = new QueryWrapper<>();

-    // 判断 nameCn 是否存在
-    if (nameCn != null && !nameCn.isEmpty()) {
-        queryWrapper.like("name_cn", nameCn);
-    }
-
-    // 判断 nameEn 是否存在
-    if (nameEn != null && !nameEn.isEmpty()) {
-        if (nameCn != null && !nameCn.isEmpty()) {
-            queryWrapper.or().like("name_en", nameEn);
-        } else {
-            queryWrapper.like("name_en", nameEn);
-        }
-    }
+    boolean hasNameCn = nameCn != null && !nameCn.isEmpty();
+    boolean hasNameEn = nameEn != null && !nameEn.isEmpty();
+    
+    if (hasNameCn) {
+        queryWrapper.like("name_cn", nameCn);
+    }
+    
+    if (hasNameEn) {
+        if (hasNameCn) {
+            queryWrapper.or();
+        }
+        queryWrapper.like("name_en", nameEn);
+    }

     page(page, queryWrapper);
     return page;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 216177b and b6ae13e.

📒 Files selected for processing (3)
  • base/src/main/java/com/tinyengine/it/controller/ModelController.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/material/ModelService.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1 hunks)
🧬 Code Graph Analysis (1)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1)
  • Enums (20-1150)
🚧 Files skipped from review as they are similar to previous changes (2)
  • base/src/main/java/com/tinyengine/it/service/material/ModelService.java
  • base/src/main/java/com/tinyengine/it/controller/ModelController.java
🧰 Additional context used
🧬 Code Graph Analysis (1)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1)
  • Enums (20-1150)
🔇 Additional comments (3)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (3)

43-47: LGTM!

The queryModelById method implementation is clean and follows MyBatis Plus conventions correctly.


204-227: Well-structured response parameter builder

The static method correctly builds standard API response structures with appropriate fields for different operation types.


108-108: No changes needed for custom mapper methods

The createModel and updateModelById XML mappings use dynamic SQL fragments (ModelSetColumns, conditional <if> blocks) and explicitly enable generated keys. The standard insert/updateById provided by MyBatis-Plus would generate static SQL (updating all columns, possibly overwriting fields with null) and relies on annotations for key generation. Your custom mapper methods are justified to support:

  • Partial updates (only non-null fields)
  • Explicit control over generated keys

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (3)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (3)

102-107: Extract duplicate method generation logic.

The same method generation code is duplicated in both createModel and updateModelById methods.

Extract this logic into a private method:

+private List<MethodDto> generateStandardMethods(Model model) {
+    List<MethodDto> methodDtos = new ArrayList<>();
+    methodDtos.add(getMethodDto(Enums.methodName.CREATED.getValue(), model));
+    methodDtos.add(getMethodDto(Enums.methodName.UPDATE.getValue(), model));
+    methodDtos.add(getMethodDto(Enums.methodName.QUERY.getValue(), model));
+    methodDtos.add(getMethodDto(Enums.methodName.DELETE.getValue(), model));
+    return methodDtos;
+}

 public Model createModel(Model model) {
-    List<MethodDto> methodDtos = new ArrayList<>();
-    methodDtos.add(getMethodDto(Enums.methodName.CREATED.getValue(), model));
-    methodDtos.add(getMethodDto(Enums.methodName.UPDATE.getValue(), model));
-    methodDtos.add(getMethodDto(Enums.methodName.QUERY.getValue(), model));
-    methodDtos.add(getMethodDto(Enums.methodName.DELETE.getValue(), model));
-    model.setMethod(methodDtos);
+    model.setMethod(generateStandardMethods(model));
     int result = this.baseMapper.createModel(model);

And apply the same change in updateModelById.

Also applies to: 143-148


110-110: Improve error messages for better debugging.

The error handling uses the same error code for the message parameter, which doesn't provide meaningful information.

-            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultCode());
+            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());

Apply this fix to all three occurrences at lines 110, 128, and 154.

Also applies to: 128-128, 154-154


187-187: Use proper string comparison with equals().

String comparison should use .equals() method instead of != operator.

-        if (!name.equals(Enums.methodName.DELETE.getValue())) {
+        if (!name.equals(Enums.methodName.DELETE.getValue())) {

Wait, I see the code already uses !name.equals() which is correct. There might have been a misunderstanding in the past review. The current code is correct.

🧹 Nitpick comments (2)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (2)

50-61: Fix javadoc parameter name inconsistency.

The javadoc mentions @param name but the actual parameter is nameCn. Update the javadoc to match the parameter name.

     /**
      * 根据name查询表t_model信息
      *
-     * @param name
+     * @param nameCn
      * @return the model list
      */

101-113: Consider adding transaction management for data consistency.

The createModel and updateModelById methods perform database operations that might benefit from explicit transaction management to ensure data consistency.

Add @Transactional annotation to ensure atomicity:

+import org.springframework.transaction.annotation.Transactional;

 @Override
 @SystemServiceLog(description = "创建model实现方法")
+@Transactional
 public Model createModel(Model model) {

Apply the same to updateModelById and deleteModelById methods.

Also applies to: 142-158

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6ae13e and ee3ae16.

📒 Files selected for processing (1)
  • base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1 hunks)
🧬 Code Graph Analysis (1)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1)
  • Enums (20-1150)
🧰 Additional context used
🧬 Code Graph Analysis (1)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1)
  • Enums (20-1150)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (6)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (6)

102-107: Extract duplicate method generation logic.

The same method generation code is duplicated in both createModel and updateModelById methods.

Extract this logic into a private method:

+private List<MethodDto> generateStandardMethods(Model model) {
+    List<MethodDto> methodDtos = new ArrayList<>();
+    methodDtos.add(getMethodDto(Enums.methodName.CREATED.getValue(), Enums.methodName.INSERTAPI.getValue(), model));
+    methodDtos.add(getMethodDto(Enums.methodName.UPDATE.getValue(), Enums.methodName.UPDATEAPI.getValue(), model));
+    methodDtos.add(getMethodDto(Enums.methodName.QUERY.getValue(), Enums.methodName.QUERYAPI.getValue(), model));
+    methodDtos.add(getMethodDto(Enums.methodName.DELETE.getValue(), Enums.methodName.DELETEAPI.getValue(), model));
+    return methodDtos;
+}

 public Model createModel(Model model) {
-    List<MethodDto> methodDtos = new ArrayList<>();
-    methodDtos.add(getMethodDto(Enums.methodName.CREATED.getValue(), Enums.methodName.INSERTAPI.getValue(), model));
-    methodDtos.add(getMethodDto(Enums.methodName.UPDATE.getValue(), Enums.methodName.UPDATEAPI.getValue(), model));
-    methodDtos.add(getMethodDto(Enums.methodName.QUERY.getValue(), Enums.methodName.QUERYAPI.getValue(), model));
-    methodDtos.add(getMethodDto(Enums.methodName.DELETE.getValue(), Enums.methodName.DELETEAPI.getValue(), model));
-    model.setMethod(methodDtos);
+    model.setMethod(generateStandardMethods(model));
     int result = this.baseMapper.createModel(model);
     // ... rest of the method

110-110: Improve error messages for better debugging.

The error handling uses the same error code for the message parameter, which doesn't provide meaningful information.

-            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultCode());
+            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());

128-128: Improve error messages for better debugging.

The error handling uses the same error code for the message parameter, which doesn't provide meaningful information.

-            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultCode());
+            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());

143-148: Extract duplicate method generation logic.

The same method generation code is duplicated in both createModel and updateModelById methods.


150-150: Use appropriate error message for null ID validation.

The null ID validation throws an error with the same code used for both parameters.

-            throw new ServiceException(ExceptionEnum.CM002.getResultCode(), ExceptionEnum.CM002.getResultCode());
+            throw new ServiceException(ExceptionEnum.CM002.getResultCode(), ExceptionEnum.CM002.getResultMsg());

154-154: Improve error messages for better debugging.

The error handling uses the same error code for the message parameter, which doesn't provide meaningful information.

-            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultCode());
+            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());
🧹 Nitpick comments (1)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)

57-61: Consider searching both Chinese and English name fields.

While the method now correctly queries the name_cn field, consider enhancing the search to include both Chinese and English names for better flexibility.

 public List<Model> getModelByName(String nameCn) {
     QueryWrapper<Model> queryWrapper = new QueryWrapper<>();
-    queryWrapper.like("name_cn", nameCn);
+    queryWrapper.like("name_cn", nameCn)
+               .or()
+               .like("name_en", nameCn);
     return this.baseMapper.selectList(queryWrapper);
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee3ae16 and da990da.

📒 Files selected for processing (3)
  • base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • base/src/main/java/com/tinyengine/it/common/enums/Enums.java
🧰 Additional context used
🧬 Code Graph Analysis (2)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (3)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (1)
  • Data (22-29)
base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/model/dto/ResponseParameter.java (1)
  • Data (22-26)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1)
  • Enums (20-1170)
🔇 Additional comments (5)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1)

24-30: Well-designed DTO class for method metadata.

The MethodDto class is cleanly implemented with appropriate field types and naming conventions. The use of Lombok's @Data annotation reduces boilerplate code while maintaining readability.

base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (4)

43-47: Simple and correct query implementation.

The method properly uses the inherited baseMapper to query by ID with appropriate logging annotation.


70-90: Well-implemented pagination with conditional filtering.

The method correctly handles optional filtering parameters and properly constructs the QueryWrapper with conditional OR logic.


160-203: Well-implemented method DTO generation with proper string comparison.

The method correctly uses .equals() for string comparison and handles different method types appropriately. The logic for generating request/response parameters based on method type is sound.


205-228: Clean implementation of response parameter generation.

The static method provides a consistent way to generate standard response parameters with appropriate conditional logic for query methods.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (2)
app/src/main/resources/sql/h2/create_model_ddl_2025_0717.sql (2)

22-22: Remove MySQL-specific ENGINE clause for H2

H2 doesn't support "engine = innodb". Drop it to avoid syntax errors.

-) engine = innodb comment = '模型表';
+) comment = '模型表';

14-16: Add auto-update for last_updated_time (H2 lacks ON UPDATE)

last_updated_time won't auto-update on UPDATE with only DEFAULT CURRENT_TIMESTAMP. Implement app-level update or an H2-compatible trigger solution.

Options:

  • App-level: always set last_updated_time = CURRENT_TIMESTAMP in UPDATE statements.
  • H2 trigger: if you use Java triggers, register a BEFORE UPDATE trigger to set NEW.last_updated_time.

Please confirm which approach you prefer and I can provide the exact implementation for your stack.

🧹 Nitpick comments (4)
base/src/main/java/com/tinyengine/it/model/entity/Model.java (4)

51-56: Optional: specify JDBC type for JSON columns to avoid driver ambiguity

If your ListTypeHandler stores JSON as text, hinting JDBC type improves portability (MySQL TEXT/LONGTEXT, H2 CLOB).

-    @TableField(typeHandler = ListTypeHandler.class)
+    @TableField(typeHandler = ListTypeHandler.class/*, jdbcType = org.apache.ibatis.type.JdbcType.CLOB*/)
     private List<ParametersDto> parameters;

-    @TableField(typeHandler = ListTypeHandler.class)
+    @TableField(typeHandler = ListTypeHandler.class/*, jdbcType = org.apache.ibatis.type.JdbcType.CLOB*/)
     private  List<MethodDto> method;

If you choose to enable jdbcType, add the import:
import org.apache.ibatis.type.JdbcType;


41-42: Fix Swagger schema name casing to match column naming

Use name_en (lowercase) for consistency with DDL and camelCase-to-underscore mapping.

-    @Schema(name = "name_En", description = "英文名称")
+    @Schema(name = "name_en", description = "英文名称")

56-56: Nit: remove extra whitespace

Double space before List.

-    private  List<MethodDto> method;
+    private List<MethodDto> method;

50-56: Validate column sizes vs JSON payload size

parameters is VARCHAR(2000) in H2 DDL; complex JSON arrays may exceed 2000 chars. Consider TEXT/LONGTEXT (MySQL) / CLOB (H2) for both parameters and method columns.

If you want, I can produce aligned DDL changes for MySQL and H2 to switch parameters to TEXT/CLOB and keep method as LONGTEXT/CLOB.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dbd88d6 and 7b1230c.

📒 Files selected for processing (3)
  • app/src/main/resources/sql/h2/create_model_ddl_2025_0717.sql (1 hunks)
  • base/src/main/java/com/tinyengine/it/model/entity/Model.java (1 hunks)
  • base/src/main/resources/mappers/ModelMapper.xml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • base/src/main/resources/mappers/ModelMapper.xml
🔇 Additional comments (3)
app/src/main/resources/sql/h2/create_model_ddl_2025_0717.sql (3)

1-22: No changes needed—H2 is already in MySQL compatibility mode

The DDL’s MySQL-specific syntax (backticks, inline comments, LONGTEXT, USING BTREE, ENGINE) is supported because in application-local.yml (line 6) H2 is started with MODE=MySQL.


11-11: No changes needed for LONGTEXT
Your H2 configuration (application-local.yml) runs in MySQL compatibility mode (MODE=MySQL), which supports the LONGTEXT type. You can safely keep the existing column definition as-is.


5-5: No changes needed: H2 is running in MySQL compatibility mode
Your application-local.yml sets MODE=MySQL on the H2 JDBC URL, so AUTO_INCREMENT is valid in this context.

`name_cn` varchar(255) comment '中文名称',
`name_en` varchar(255) comment '英文名称',
`version` varchar(255) comment '版本',
`model_url` varchar(255) comment '模型url',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Cross-DB consistency: ensure MySQL DDL also includes model_url

Entity and mapper use model_url. Verify MySQL DDL defines it to avoid runtime SQL errors in MySQL environments.

Expected: MySQL DDL should contain a column named model_url with a compatible type (e.g., VARCHAR(255)).


🏁 Script executed:

#!/bin/bash
# Check MySQL DDLs include model_url
fd -a create_model_ddl_*.sql app/src/main/resources/sql/mysql | xargs -I {} sh -c 'echo "---- {}"; cat "{}"'
rg -n --glob 'app/src/main/resources/sql/mysql/**' 'model_url'

Length of output: 177


🏁 Script executed:

#!/bin/bash
# List all SQL files under the MySQL DDL directory
echo "=== SQL files under app/src/main/resources/sql/mysql ==="
fd -t f -e sql app/src/main/resources/sql/mysql

# List any create_model_ddl SQL files specifically
echo "=== create_model_ddl SQL files under MySQL DDL ==="
fd -t f -e sql 'create_model_ddl' app/src/main/resources/sql/mysql

# Search for model_url occurrences in all MySQL SQL files
echo "=== Searching for model_url in MySQL DDL SQL files ==="
rg -n 'model_url' -R app/src/main/resources/sql/mysql

Length of output: 1426


🏁 Script executed:

#!/bin/bash
# Display the MySQL create_model_ddl file and check for model_url
echo "---- app/src/main/resources/sql/mysql/create_model_ddl_2025_0717.sql ----"
cat app/src/main/resources/sql/mysql/create_model_ddl_2025_0717.sql

echo
echo "---- Searching for model_url in that file ----"
grep -n 'model_url' app/src/main/resources/sql/mysql/create_model_ddl_2025_0717.sql || echo "model_url not found in MySQL DDL"

Length of output: 1582


Add model_url to MySQL DDL for cross-DB consistency

The MySQL DDL file for t_model is missing the model_url column present in H2. Please update:

• File:
app/src/main/resources/sql/mysql/create_model_ddl_2025_0717.sql

• Location:
In the column list, immediately after the site_id definition and before the primary-key clause.

• Diff to apply:

     `site_id`            varchar(60) comment '站点id,设计预留字段',
+    `model_url`          varchar(255) comment '模型url',
     primary key (`id`) using btree,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`model_url` varchar(255) comment '模型url',
`site_id` varchar(60) comment '站点id,设计预留字段',
`model_url` varchar(255) comment '模型url',
primary key (`id`) using btree,
🤖 Prompt for AI Agents
In app/src/main/resources/sql/mysql/create_model_ddl_2025_0717.sql, in the
t_model table column list immediately after the site_id definition and before
the primary-key clause, add a model_url column matching H2: a varchar(255) with
the same comment '模型url' and correct comma placement; ensure the column syntax
follows the surrounding MySQL style (backticks or no backticks consistent with
the file) and that the trailing commas around the primary-key clause remain
valid.

Comment on lines +20 to +21
primary key (`id`) using btree,
unique index `u_idx_model` (`name_cn`,`version`) using btree
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

❓ Verification inconclusive

Drop "USING BTREE" and prefer a standard unique constraint

"USING BTREE" is MySQL-specific and unnecessary. Use a portable unique constraint inline.

-    primary key (`id`) using btree,
-    unique index `u_idx_model` (`name_cn`,`version`) using btree
+    primary key (`id`),
+    constraint `u_idx_model` unique (`name_cn`, `version`)

Remove MySQL-specific “USING BTREE” and use standard constraint in H2 DDL

H2 does not support the MySQL-only USING BTREE clause—defining the key and a unique constraint is sufficient.

File: app/src/main/resources/sql/h2/create_model_ddl_2025_0717.sql
Lines: 20–21

-    primary key (`id`) using btree,
-    unique index `u_idx_model` (`name_cn`,`version`) using btree
+    primary key (`id`),
+    constraint `u_idx_model` unique (`name_cn`, `version`)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
primary key (`id`) using btree,
unique index `u_idx_model` (`name_cn`,`version`) using btree
primary key (`id`),
constraint `u_idx_model` unique (`name_cn`, `version`)
🤖 Prompt for AI Agents
In app/src/main/resources/sql/h2/create_model_ddl_2025_0717.sql around lines 20
to 21, the DDL uses MySQL-specific "USING BTREE" on the primary key and unique
index; remove the "USING BTREE" clauses and declare the constraints using
standard H2 syntax (keep primary key on `id` and define the unique
constraint/index on (`name_cn`,`version`) without engine-specific clauses).

Comment on lines +35 to +36
@TableName("t_model")
@Schema(name = "Model", description = "模型表")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Enable autoResultMap so ListTypeHandler works on read/write

Without autoResultMap=true, MyBatis-Plus may not apply custom type handlers for result mapping, causing serialization/deserialization issues for parameters/method fields.

-@TableName("t_model")
+@TableName(value = "t_model", autoResultMap = true)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@TableName("t_model")
@Schema(name = "Model", description = "模型表")
@TableName(value = "t_model", autoResultMap = true)
@Schema(name = "Model", description = "模型表")
🤖 Prompt for AI Agents
In base/src/main/java/com/tinyengine/it/model/entity/Model.java around lines 35
to 36, the @TableName annotation lacks autoResultMap=true so custom
ListTypeHandler won't be applied on result mapping; update the annotation to
enable autoResultMap (e.g. set autoResultMap = true on @TableName) so
MyBatis-Plus uses custom type handlers for read/write, or alternatively enable
autoResultMap in global MyBatis-Plus configuration if preferred.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

♻️ Duplicate comments (2)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (2)

117-118: Use descriptive exception messages, not codes for both fields

Throwing ServiceException with code for both code and message hides the real error.

-            throw new ServiceException(ExceptionEnum.Cm001.getResultCode(), ExceptionEnum.CM001.getResultCode());
+            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());

Apply similarly at delete and update failure branches.

Also applies to: 135-136, 161-162


156-158: Use proper message for null ID validation

Use the enum’s message rather than duplicating the code.

-        if (model.getId() == null) {
-            throw new ServiceException(ExceptionEnum.CM002.getResultCode(), ExceptionEnum.CM002.getResultCode());
-        }
+        if (model.getId() == null) {
+            throw new ServiceException(ExceptionEnum.CM002.getResultCode(), ExceptionEnum.CM002.getResultMsg());
+        }
🧹 Nitpick comments (8)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (2)

23-31: Prefer Serializable DTO and nullable required flag

  • Persisted/list-typed DTOs benefit from implementing Serializable.
  • Use Boolean instead of primitive boolean to preserve tri-state (unset vs false).

Apply this diff:

-public class ParametersDto {
+public class ParametersDto implements java.io.Serializable {
+    private static final long serialVersionUID = 1L;
@@
-    private boolean required;
+    private Boolean required;

24-30: Validate field semantics: options/defaultValue typing

If options encode enum choices, a structured type (e.g., List or List) is less error-prone than a raw String. Similarly, defaultValue as String pushes parsing downstream and complicates type safety.

Would you like to switch:

  • options → List (or a dedicated Option DTO)
  • defaultValue → Object (or typed per field type), with JSON serialization?
    I can draft a migration-compatible DTO if needed.
base/src/main/java/com/tinyengine/it/controller/ModelController.java (2)

206-207: Clean up inaccurate Javadoc

This method has no id parameter.

-     * @param id the id
      * @return the result

55-56: Prefer constructor injection over field injection

Constructor injection improves testability and immutability, avoids reflection-based field injection.

Example:

private final ModelService modelService;

public ModelController(ModelService modelService) {
    this.modelService = modelService;
}

Remove @Autowired on the field.

base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (4)

76-97: Confirm OR semantics and add defensive defaults

Current logic uses OR when both nameCn and nameEn are provided. If the intended behavior is to match both, use AND. Also consider guarding page params against invalid values.

If AND is desired:

-        if (nameEn != null && !nameEn.isEmpty()) {
-            if (nameCn != null && !nameCn.isEmpty()) {
-                queryWrapper.or().like("name_en", nameEn);
-            } else {
-                queryWrapper.like("name_en", nameEn);
-            }
-        }
+        if (nameEn != null && !nameEn.isEmpty()) {
+            if (nameCn != null && !nameCn.isEmpty()) {
+                queryWrapper.and(w -> w.like("name_cn", nameCn).like("name_en", nameEn));
+            } else {
+                queryWrapper.like("name_en", nameEn);
+            }
+        }

Additionally, to be robust against invalid inputs:

-        Page<Model> page = new Page<>(currentPage, pageSize);
+        int cp = currentPage <= 0 ? 1 : currentPage;
+        int ps = pageSize <= 0 ? 10 : pageSize;
+        Page<Model> page = new Page<>(cp, ps);

241-259: Make SQL type mapping dialect-aware

mapJavaTypeToSQL returns LONGTEXT and BOOLEAN which are not portable (e.g., H2 vs MySQL). If these CREATE TABLE statements are intended for multiple DBs, plumb a dialect and map accordingly (e.g., VARCHAR/CLOB for H2, LONGTEXT for MySQL, BOOLEAN → TINYINT(1) in MySQL).

I can help extract a TypeMapper interface with MySQL/H2 implementations and select it by profile/config.


100-106: Fix copy-paste typos in Javadoc

“创建t_material” and stray “@ param” are inaccurate for this class.

-     * 创建t_material
+     * 创建t_model
@@
-     * @ param the model
+     * @param model the model
@@
-     * @ param the id
+     * @param id the id

Also applies to: 141-146, 168-173


305-328: Optional: standardize response parameter order

Currently total is added first for QUERY; consider consistent order: code, message, data, total.

-        if (name.equals(Enums.methodName.QUERY.getValue())) {
-            ResponseParameter total = new ResponseParameter();
-            total.setProp(Enums.methodParam.TOTAL.getValue());
-            total.setType(Enums.paramType.NUMBER.getValue());
-            responseParameterList.add(total);
-        }
-
-        responseParameterList.add(code);
-        responseParameterList.add(message);
-        responseParameterList.add(data);
+        responseParameterList.add(code);
+        responseParameterList.add(message);
+        responseParameterList.add(data);
+        if (name.equals(Enums.methodName.QUERY.getValue())) {
+            ResponseParameter total = new ResponseParameter();
+            total.setProp(Enums.methodParam.TOTAL.getValue());
+            total.setType(Enums.paramType.NUMBER.getValue());
+            responseParameterList.add(total);
+        }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b78d2f2 and bf0c9d7.

📒 Files selected for processing (5)
  • base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/controller/ModelController.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/material/ModelService.java (1 hunks)
  • base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • base/src/main/java/com/tinyengine/it/service/material/ModelService.java
  • base/src/main/java/com/tinyengine/it/common/enums/Enums.java
🧰 Additional context used
🧬 Code Graph Analysis (3)
base/src/main/java/com/tinyengine/it/model/dto/ParametersDto.java (2)
base/src/main/java/com/tinyengine/it/model/dto/MethodDto.java (1)
  • Data (24-30)
base/src/main/java/com/tinyengine/it/model/dto/RequestParameter.java (1)
  • Data (24-29)
base/src/main/java/com/tinyengine/it/controller/ModelController.java (1)
base/src/main/java/com/tinyengine/it/controller/HomeController.java (1)
  • RestController (28-41)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (2)
base/src/main/java/com/tinyengine/it/common/enums/Enums.java (1)
  • Enums (20-1170)
base/src/main/java/com/tinyengine/it/common/utils/JsonUtils.java (1)
  • JsonUtils (45-349)
🔇 Additional comments (1)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java (1)

65-68: LGTM: fixed non-existent column issue

Querying by name_cn resolves the previous bug querying “name”.

Comment on lines +75 to +81
public Result<Page<Model>> getAllModel(@RequestParam(value = "currentPage", required = false) Integer currentPage,
@RequestParam(value = "pageSize", required = false) Integer pageSize,
@RequestParam(value = "nameCn", required = false) String nameCn,
@RequestParam(value = "nameEn", required = false) String nameEn) {
Page<Model> modelPage = modelService.pageQuery(currentPage, pageSize, nameCn, nameEn);
return Result.success(modelPage);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix potential NPE due to autounboxing null currentPage/pageSize

currentPage and pageSize are optional (required=false) but passed to a service method with primitive ints. Null will autounbox and NPE.

Add defaults at the controller boundary:

-    public Result<Page<Model>> getAllModel(@RequestParam(value = "currentPage", required = false) Integer currentPage,
-        @RequestParam(value = "pageSize", required = false) Integer pageSize,
+    public Result<Page<Model>> getAllModel(@RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage,
+        @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
         @RequestParam(value = "nameCn", required = false) String nameCn,
         @RequestParam(value = "nameEn", required = false) String nameEn) {

Alternatively, change the service signature to accept Integer and handle defaults, but the above is minimally invasive.

🤖 Prompt for AI Agents
In base/src/main/java/com/tinyengine/it/controller/ModelController.java around
lines 75 to 81, currentPage and pageSize are optional Integers and may be null
causing an NPE when autounboxed by modelService.pageQuery which expects
primitives; before calling the service, assign safe defaults (e.g. currentPage =
(currentPage == null ? 1 : currentPage); pageSize = (pageSize == null ? 10 :
pageSize);) or otherwise coalesce them, then pass those non-null int values to
modelService.pageQuery so autounboxing cannot throw.

Comment on lines +88 to +98
@Operation(summary = "根据name查询表Model信息", description = "根据name查询表Model信息", parameters = {
@Parameter(name = "name", description = "名称"),
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Model.class))),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "根据name查询表Model信息")
@GetMapping("/model/find")
public Result<List<Model>> getModelByName(@RequestParam(value = "nameCn", required = false) String nameCn) {
List<Model> modelPage = modelService.getModelByName(nameCn);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Align OpenAPI parameter name and summary with actual method parameter

The API doc references “name” while the method accepts “nameCn”. This causes confusing Swagger docs and client generation issues.

-    @Operation(summary = "根据name查询表Model信息", description = "根据name查询表Model信息", parameters = {
-        @Parameter(name = "name", description = "名称"),
+    @Operation(summary = "根据nameCn查询表Model信息", description = "根据nameCn查询表Model信息", parameters = {
+        @Parameter(name = "nameCn", description = "模型中文名称"),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Operation(summary = "根据name查询表Model信息", description = "根据name查询表Model信息", parameters = {
@Parameter(name = "name", description = "名称"),
}, responses = {
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Model.class))),
@ApiResponse(responseCode = "400", description = "请求失败")
})
@SystemControllerLog(description = "根据name查询表Model信息")
@GetMapping("/model/find")
public Result<List<Model>> getModelByName(@RequestParam(value = "nameCn", required = false) String nameCn) {
List<Model> modelPage = modelService.getModelByName(nameCn);
@Operation(
summary = "根据nameCn查询表Model信息",
description = "根据nameCn查询表Model信息",
parameters = {
@Parameter(name = "nameCn", description = "模型中文名称"),
},
responses = {
@ApiResponse(
responseCode = "200",
description = "返回信息",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = Model.class)
)
),
@ApiResponse(responseCode = "400", description = "请求失败")
}
)
@SystemControllerLog(description = "根据name查询表Model信息")
@GetMapping("/model/find")
public Result<List<Model>> getModelByName(@RequestParam(value = "nameCn", required = false) String nameCn) {
List<Model> modelPage = modelService.getModelByName(nameCn);
// ...
}
🤖 Prompt for AI Agents
In base/src/main/java/com/tinyengine/it/controller/ModelController.java around
lines 88 to 98, the OpenAPI/Swagger metadata and @Parameter use "name" while the
actual method parameter is named "nameCn", causing mismatched docs; update the
@Operation summary/description/parameters and @Parameter name to "nameCn" (or
change the method parameter to "name" if preferred) so the documented parameter
name matches the method signature, and ensure the @Parameter description matches
the semantic meaning of nameCn.

Comment on lines +193 to +196
@ApiResponse(responseCode = "200", description = "返回信息",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Model.class))),
@ApiResponse(responseCode = "400", description = "请求失败")})
@SystemControllerLog(description = "获取Model建表sql")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Wrong schema in String-returning endpoints

The responses for getTable and getAllTable return Result but the OpenAPI schema is Model. This breaks API documentation and client codegen.

Update the schema types:

-        @ApiResponse(responseCode = "200", description = "返回信息",
-        content = @Content(mediaType = "application/json", schema = @Schema(implementation = Model.class))),
+        @ApiResponse(responseCode = "200", description = "返回信息",
+        content = @Content(mediaType = "application/json", schema = @Schema(implementation = String.class))),

Apply the same change to both endpoints.

Also applies to: 211-214

🤖 Prompt for AI Agents
In base/src/main/java/com/tinyengine/it/controller/ModelController.java around
lines 193-196 and 211-214, the @ApiResponse annotations declare schema =
@Schema(implementation = Model.class) while the methods return Result<String>;
update those annotations to use schema = @Schema(implementation = String.class)
(or an appropriate Result-wrapped schema if you use a custom Result model in
OpenAPI), and apply the same change to both endpoints so the OpenAPI doc and
client codegen reflect the actual String return type.

Comment on lines +109 to +114
List<MethodDto> methodDtos = new ArrayList<>();
methodDtos.add(getMethodDto(Enums.methodName.CREATED.getValue(), Enums.methodName.INSERTAPI.getValue(), model));
methodDtos.add(getMethodDto(Enums.methodName.UPDATE.getValue(), Enums.methodName.UPDATEAPI.getValue(), model));
methodDtos.add(getMethodDto(Enums.methodName.QUERY.getValue(), Enums.methodName.QUERYAPI.getValue(), model));
methodDtos.add(getMethodDto(Enums.methodName.DELETE.getValue(), Enums.methodName.DELETEAPI.getValue(), model));
model.setMethod(methodDtos);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Extract duplicated method generation logic

The CRUD MethodDto assembly is duplicated in createModel and updateModelById. Extract into a private helper for maintainability.

Apply this diff in both locations:

-        List<MethodDto> methodDtos = new ArrayList<>();
-        methodDtos.add(getMethodDto(Enums.methodName.CREATED.getValue(), Enums.methodName.INSERTAPI.getValue(), model));
-        methodDtos.add(getMethodDto(Enums.methodName.UPDATE.getValue(), Enums.methodName.UPDATEAPI.getValue(), model));
-        methodDtos.add(getMethodDto(Enums.methodName.QUERY.getValue(), Enums.methodName.QUERYAPI.getValue(), model));
-        methodDtos.add(getMethodDto(Enums.methodName.DELETE.getValue(), Enums.methodName.DELETEAPI.getValue(), model));
-        model.setMethod(methodDtos);
+        model.setMethod(generateStandardMethods(model));

Add this helper outside the shown ranges:

private List<MethodDto> generateStandardMethods(Model model) {
    List<MethodDto> list = new ArrayList<>();
    list.add(getMethodDto(Enums.methodName.CREATED.getValue(), Enums.methodName.INSERTAPI.getValue(), model));
    list.add(getMethodDto(Enums.methodName.UPDATE.getValue(), Enums.methodName.UPDATEAPI.getValue(), model));
    list.add(getMethodDto(Enums.methodName.QUERY.getValue(), Enums.methodName.QUERYAPI.getValue(), model));
    list.add(getMethodDto(Enums.methodName.DELETE.getValue(), Enums.methodName.DELETEAPI.getValue(), model));
    return list;
}

Also applies to: 150-155

🤖 Prompt for AI Agents
In
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java
around lines 109-114 (and similarly at 150-155), the CRUD MethodDto construction
is duplicated; extract that repeated block into a private helper method (e.g.,
generateStandardMethods(Model model)) placed in the class, have it return the
List<MethodDto>, and replace both inline blocks with
model.setMethod(generateStandardMethods(model)); ensure imports and visibility
are correct and the helper uses the existing getMethodDto and Enums references.

Comment on lines +132 to +138
Model model = this.baseMapper.selectById(id);
int result = this.baseMapper.deleteById(id);
if (result != 1) {
throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultCode());
}
return model;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle delete-by-id when record does not exist

When selectById returns null, deleteById likely returns 0; throwing a generic CM001 masks the real cause. Validate existence first and return a clear error.

-        Model model = this.baseMapper.selectById(id);
-        int result = this.baseMapper.deleteById(id);
+        Model model = this.baseMapper.selectById(id);
+        if (model == null) {
+            throw new ServiceException(ExceptionEnum.CM002.getResultCode(), ExceptionEnum.CM002.getResultMsg());
+        }
+        int result = this.baseMapper.deleteById(id);
         if (result != 1) {
-            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultCode());
+            throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());
         }

If CM002 is not the appropriate “not found” code in your enum, replace accordingly.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Model model = this.baseMapper.selectById(id);
int result = this.baseMapper.deleteById(id);
if (result != 1) {
throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultCode());
}
return model;
}
Model model = this.baseMapper.selectById(id);
if (model == null) {
throw new ServiceException(ExceptionEnum.CM002.getResultCode(), ExceptionEnum.CM002.getResultMsg());
}
int result = this.baseMapper.deleteById(id);
if (result != 1) {
throw new ServiceException(ExceptionEnum.CM001.getResultCode(), ExceptionEnum.CM001.getResultMsg());
}
return model;
}
🤖 Prompt for AI Agents
In
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java
around lines 132 to 138, validate that model returned by
this.baseMapper.selectById(id) is not null before attempting delete; if null
throw the “not found” ServiceException (e.g. ExceptionEnum.CM002) with the
appropriate result code/message, otherwise proceed to delete and handle
deleteById != 1 as now; replace duplicate getResultCode usage with the correct
code/message getters for clearer errors.

Comment on lines +175 to +209
public String getTableById(Integer id) throws IOException {
Model model = this.baseMapper.selectById(id);
List<?> rawList = model.getParameters();
List<ParametersDto> fields = rawList.stream()
.map(item -> JsonUtils.MAPPER.convertValue(item, ParametersDto.class))
.collect(Collectors.toList());

StringBuilder sql = new StringBuilder("CREATE TABLE " + model.getNameEn() + " (");

for (int i = 0; i < fields.size(); i++) {
ParametersDto field = fields.get(i);

String prop = field.getProp();
String type = field.getType();
String defaultValue = field.getDefaultValue();

// 根据字段类型映射为 SQL 数据类型
String sqlType = mapJavaTypeToSQL(type);

sql.append(prop).append(" ").append(sqlType);

if (defaultValue != null && !defaultValue.isEmpty()) {
sql.append(" DEFAULT ").append(defaultValue);
}

// 如果不是最后一个字段,添加逗号
if (i != fields.size() - 1) {
sql.append(", ");
}
}

sql.append(")");

return sql.toString();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Sanitize identifiers and quote default values to prevent SQL injection and invalid SQL

  • Table/column names and default values are concatenated into SQL without sanitization or quoting.
  • String/TIMESTAMP defaults require quotes; current code produces invalid SQL and risks injection if values contain special chars.

Apply targeted changes:

-        StringBuilder sql = new StringBuilder("CREATE TABLE " + model.getNameEn() + " (");
+        StringBuilder sql = new StringBuilder("CREATE TABLE " + quoteIdent(model.getNameEn()) + " (");
@@
-            String prop = field.getProp();
+            String prop = field.getProp();
@@
-            sql.append(prop).append(" ").append(sqlType);
+            sql.append(quoteIdent(prop)).append(" ").append(sqlType);
@@
-            if (defaultValue != null && !defaultValue.isEmpty()) {
-                sql.append(" DEFAULT ").append(defaultValue);
-            }
+            if (defaultValue != null && !defaultValue.isEmpty()) {
+                sql.append(" DEFAULT ").append(formatDefaultValue(defaultValue, sqlType));
+            }

Add the following helpers outside the shown range:

private static String quoteIdent(String ident) {
    if (ident == null) throw new ServiceException(ExceptionEnum.CM002.getResultCode(), "Identifier cannot be null");
    // allow only letters, digits and underscore; adjust as needed
    String sanitized = ident.replaceAll("[^A-Za-z0-9_]", "");
    if (sanitized.isEmpty()) {
        throw new ServiceException(ExceptionEnum.CM002.getResultCode(), "Invalid identifier: " + ident);
    }
    // MySQL-style quoting; if targeting H2 or others, adapt or use dialect-aware quoting
    return "`" + sanitized + "`";
}

private static String formatDefaultValue(String value, String sqlType) {
    if (sqlType == null) return "'" + escapeSql(value) + "'";
    String upper = sqlType.toUpperCase();
    // numeric and boolean types: no quotes
    if (upper.startsWith("INT") || upper.startsWith("BIGINT") || upper.startsWith("SMALLINT")
        || upper.startsWith("DECIMAL") || upper.startsWith("FLOAT") || upper.startsWith("DOUBLE")
        || upper.startsWith("BOOLEAN")) {
        return value;
    }
    // otherwise quote (VARCHAR, LONGTEXT, TIMESTAMP, DATE, etc.)
    return "'" + escapeSql(value) + "'";
}

private static String escapeSql(String s) {
    return s.replace("'", "''");
}

Note: mapJavaTypeToSQL mixes MySQL-specific LONGTEXT with types like BOOLEAN. If the generated DDL must support multiple databases (e.g., H2 and MySQL), consider introducing a dialect parameter or strategy to emit compatible types and quoting per target DB.

🤖 Prompt for AI Agents
In
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java
around lines 175 to 209, the generated CREATE TABLE concatenates raw
table/column identifiers and default values into SQL unquoted and unsanitized,
risking invalid SQL and injection; add helper methods quoteIdent,
formatDefaultValue and escapeSql (as described in the review) outside the shown
range, call quoteIdent on model.getNameEn() and every field.getProp() before
appending to the SQL, call mapJavaTypeToSQL to obtain sqlType then use
formatDefaultValue(defaultValue, sqlType) to append DEFAULT values (only when
defaultValue is non-empty) and ensure default strings are escaped/quoted while
numeric/boolean remain unquoted; throw ServiceException for null/invalid
identifiers per the helper and adapt quoting to your target dialect if needed.

Comment on lines +178 to +180
List<ParametersDto> fields = rawList.stream()
.map(item -> JsonUtils.MAPPER.convertValue(item, ParametersDto.class))
.collect(Collectors.toList());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use JsonUtils.convertValue to centralize error handling

By calling JsonUtils.MAPPER directly, you bypass the utility’s error-wrapping behavior. Use the provided helper to get consistent exceptions.

-        List<ParametersDto> fields = rawList.stream()
-                .map(item -> JsonUtils.MAPPER.convertValue(item, ParametersDto.class))
+        List<ParametersDto> fields = rawList.stream()
+                .map(item -> JsonUtils.convertValue(item, ParametersDto.class))
                 .collect(Collectors.toList());
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
List<ParametersDto> fields = rawList.stream()
.map(item -> JsonUtils.MAPPER.convertValue(item, ParametersDto.class))
.collect(Collectors.toList());
List<ParametersDto> fields = rawList.stream()
.map(item -> JsonUtils.convertValue(item, ParametersDto.class))
.collect(Collectors.toList());
🤖 Prompt for AI Agents
In
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java
around lines 178 to 180, you're calling JsonUtils.MAPPER.convertValue(...)
directly which bypasses JsonUtils' centralized error handling; replace that call
with JsonUtils.convertValue(item, ParametersDto.class) so the utility's
error-wrapping and consistent exception behavior are used when converting each
item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant