-
Notifications
You must be signed in to change notification settings - Fork 52
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
base: develop
Are you sure you want to change the base?
feat: Add model API #249
Conversation
WalkthroughAdds a new Model domain: SQL DDL scripts (MySQL/H2/Docker) to create Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Controller as ModelController
participant Service as ModelServiceImpl
participant Mapper as ModelMapper
participant DB
Client->>Controller: HTTP (Create/Update/Delete/Get/List/Find)
Controller->>Service: validate & forward request
Service->>Mapper: execute SQL (insert/update/delete/select)
Mapper->>DB: run query against t_model
DB-->>Mapper: results
Mapper-->>Service: mapped Model(s)
Service-->>Controller: result / Page / list / status
Controller-->>Client: Result wrapper response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
forrequired
is acceptable since it defaults tofalse
, but considerBoolean
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 modelbase/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 namedMethodName
. However, I notice this is consistent with some existing enums in the file likeparamType
andmethodParam
.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 fieldsThe current conditions use exact equality checks for text fields like
parameters
,method
, anddescription
. 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 descriptionsThe 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 filtersThe 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
📒 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. Theint
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
andResponseParameter
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 descriptionsparamType
: Covers essential data types for API parametersmethodParam
: Provides common parameter names for consistencyThe 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
andversion
ensures data integrity by preventing duplicate models.base/src/main/resources/mappers/ModelMapper.xml (1)
151-158
: Potential trailing comma issue in dynamic SET clauseThe
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.
base/src/main/java/com/tinyengine/it/controller/ModelController.java
Outdated
Show resolved
Hide resolved
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java
Outdated
Show resolved
Hide resolved
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java
Outdated
Show resolved
Hide resolved
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java
Show resolved
Hide resolved
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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 fieldsThe method only searches the Chinese name field, but based on the schema having both
name_cn
andname_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 logicThe same method generation code is duplicated in both
createModel
andupdateModelById
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 parameterThe 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 parameterSame 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 exceptionsBoth 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 logicThe 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
📒 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 builderThe static method correctly builds standard API response structures with appropriate fields for different operation types.
108-108
: No changes needed for custom mapper methodsThe
createModel
andupdateModelById
XML mappings use dynamic SQL fragments (ModelSetColumns
, conditional<if>
blocks) and explicitly enable generated keys. The standardinsert
/updateById
provided by MyBatis-Plus would generate static SQL (updating all columns, possibly overwriting fields withnull
) 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
There was a problem hiding this 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
andupdateModelById
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 isnameCn
. 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
andupdateModelById
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
anddeleteModelById
methods.Also applies to: 142-158
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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)
base/src/main/java/com/tinyengine/it/service/material/impl/ModelServiceImpl.java
Show resolved
Hide resolved
There was a problem hiding this 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
andupdateModelById
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
andupdateModelById
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
📒 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.
There was a problem hiding this 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 H2H2 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 ambiguityIf 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 namingUse 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 whitespaceDouble space before List.
- private List<MethodDto> method; + private List<MethodDto> method;
50-56
: Validate column sizes vs JSON payload sizeparameters 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
📒 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 modeThe DDL’s MySQL-specific syntax (backticks, inline comments, LONGTEXT, USING BTREE, ENGINE) is supported because in
application-local.yml
(line 6) H2 is started withMODE=MySQL
.
11-11
: No changes needed for LONGTEXT
Your H2 configuration (application-local.yml
) runs in MySQL compatibility mode (MODE=MySQL
), which supports theLONGTEXT
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 setsMODE=MySQL
on the H2 JDBC URL, soAUTO_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', |
There was a problem hiding this comment.
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.
`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.
primary key (`id`) using btree, | ||
unique index `u_idx_model` (`name_cn`,`version`) using btree |
There was a problem hiding this comment.
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.
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).
@TableName("t_model") | ||
@Schema(name = "Model", description = "模型表") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@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.
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Database
Other