ai-engineering-init 1.3.3 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/hooks/skill-forced-eval.js +4 -1
- package/.claude/settings.json +3 -3
- package/.claude/skills/add-skill/SKILL.md +252 -116
- package/.claude/skills/api-development/SKILL.md +83 -377
- package/.claude/skills/architecture-design/SKILL.md +138 -632
- package/.claude/skills/backend-annotations/SKILL.md +134 -506
- package/.claude/skills/banana-image/SKILL.md +10 -3
- package/.claude/skills/brainstorm/SKILL.md +103 -535
- package/.claude/skills/bug-detective/SKILL.md +147 -1097
- package/.claude/skills/bug-detective/references/error-patterns.md +242 -0
- package/.claude/skills/code-patterns/SKILL.md +116 -426
- package/.claude/skills/code-patterns/references/leniu-code-patterns.md +87 -0
- package/.claude/skills/crud-development/SKILL.md +64 -304
- package/.claude/skills/data-permission/SKILL.md +105 -412
- package/.claude/skills/data-permission/references/custom-data-scope.md +90 -0
- package/.claude/skills/file-oss-management/SKILL.md +106 -714
- package/.claude/skills/file-oss-management/references/entities.md +105 -0
- package/.claude/skills/file-oss-management/references/service-impl.md +104 -0
- package/.claude/skills/leniu-api-development/SKILL.md +142 -626
- package/.claude/skills/leniu-api-development/references/real-examples.md +273 -0
- package/.claude/skills/leniu-architecture-design/SKILL.md +176 -391
- package/.claude/skills/leniu-backend-annotations/SKILL.md +132 -519
- package/.claude/skills/leniu-brainstorm/SKILL.md +132 -541
- package/.claude/skills/leniu-brainstorm/references/business-scenarios.md +162 -0
- package/.claude/skills/leniu-crud-development/SKILL.md +232 -938
- package/.claude/skills/leniu-crud-development/references/templates.md +597 -0
- package/.claude/skills/leniu-customization-location/SKILL.md +410 -0
- package/.claude/skills/leniu-data-permission/SKILL.md +70 -0
- package/.claude/skills/leniu-java-entity/SKILL.md +76 -590
- package/.claude/skills/leniu-java-entity/references/templates.md +237 -0
- package/.claude/skills/leniu-java-export/SKILL.md +94 -379
- package/.claude/skills/leniu-java-logging/SKILL.md +106 -709
- package/.claude/skills/leniu-java-logging/references/data-mask.md +46 -0
- package/.claude/skills/leniu-java-logging/references/logging-scenarios.md +113 -0
- package/.claude/skills/leniu-java-mybatis/SKILL.md +73 -446
- package/.claude/skills/leniu-java-mybatis/references/report-mapper.md +88 -0
- package/.claude/skills/leniu-report-customization/SKILL.md +111 -325
- package/.claude/skills/leniu-report-customization/references/table-fields.md +93 -0
- package/.claude/skills/leniu-report-standard-customization/SKILL.md +328 -0
- package/.claude/skills/leniu-report-standard-customization/references/analysis-module.md +64 -0
- package/.claude/skills/leniu-report-standard-customization/references/table-fields.md +113 -0
- package/.claude/skills/leniu-security-guard/SKILL.md +133 -347
- package/.claude/skills/mysql-debug/SKILL.md +364 -0
- package/.claude/skills/openspec-apply-change/SKILL.md +10 -1
- package/.claude/skills/openspec-archive-change/SKILL.md +9 -1
- package/.claude/skills/openspec-bulk-archive-change/SKILL.md +9 -1
- package/.claude/skills/openspec-continue-change/SKILL.md +9 -1
- package/.claude/skills/openspec-explore/SKILL.md +10 -1
- package/.claude/skills/openspec-ff-change/SKILL.md +9 -1
- package/.claude/skills/openspec-new-change/SKILL.md +9 -1
- package/.claude/skills/openspec-onboard/SKILL.md +15 -130
- package/.claude/skills/openspec-sync-specs/SKILL.md +9 -1
- package/.claude/skills/openspec-verify-change/SKILL.md +9 -1
- package/.claude/skills/performance-doctor/SKILL.md +110 -434
- package/.claude/skills/redis-cache/SKILL.md +89 -595
- package/.claude/skills/redis-cache/references/listeners.md +23 -0
- package/.claude/skills/scheduled-jobs/SKILL.md +88 -407
- package/.claude/skills/security-guard/SKILL.md +137 -532
- package/.claude/skills/security-guard/references/encrypt-config.md +103 -0
- package/.claude/skills/security-guard/references/sensitive-strategies.md +42 -0
- package/.claude/skills/sms-mail/SKILL.md +116 -574
- package/.claude/skills/sms-mail/references/mail-config.md +88 -0
- package/.claude/skills/sms-mail/references/sms-config.md +74 -0
- package/.claude/skills/social-login/SKILL.md +112 -514
- package/.claude/skills/social-login/references/provider-configs.md +118 -0
- package/.claude/skills/tenant-management/SKILL.md +129 -444
- package/.claude/skills/tenant-management/references/tenant-scenarios.md +91 -0
- package/.claude/skills/test-development/SKILL.md +86 -540
- package/.claude/skills/test-development/references/parameterized-examples.md +119 -0
- package/.claude/skills/utils-toolkit/SKILL.md +52 -305
- package/.claude/skills/utils-toolkit/references/redis-utils-api.md +56 -0
- package/.claude/skills/websocket-sse/SKILL.md +105 -550
- package/.claude/skills/workflow-engine/SKILL.md +147 -502
- package/.codex/skills/add-skill/SKILL.md +252 -116
- package/.codex/skills/api-development/SKILL.md +172 -599
- package/.codex/skills/architecture-design/SKILL.md +138 -504
- package/.codex/skills/backend-annotations/SKILL.md +134 -496
- package/.codex/skills/banana-image/SKILL.md +10 -3
- package/.codex/skills/brainstorm/SKILL.md +103 -535
- package/.codex/skills/bug-detective/SKILL.md +147 -1097
- package/.codex/skills/bug-detective/references/error-patterns.md +242 -0
- package/.codex/skills/code-patterns/SKILL.md +120 -282
- package/.codex/skills/code-patterns/references/leniu-code-patterns.md +87 -0
- package/.codex/skills/crud-development/SKILL.md +64 -292
- package/.codex/skills/data-permission/SKILL.md +108 -407
- package/.codex/skills/data-permission/references/custom-data-scope.md +90 -0
- package/.codex/skills/database-ops/SKILL.md +8 -154
- package/.codex/skills/error-handler/SKILL.md +10 -0
- package/.codex/skills/file-oss-management/SKILL.md +106 -714
- package/.codex/skills/file-oss-management/references/entities.md +105 -0
- package/.codex/skills/file-oss-management/references/service-impl.md +104 -0
- package/.codex/skills/git-workflow/SKILL.md +27 -5
- package/.codex/skills/leniu-api-development/SKILL.md +142 -626
- package/.codex/skills/leniu-api-development/references/real-examples.md +273 -0
- package/.codex/skills/leniu-architecture-design/SKILL.md +176 -391
- package/.codex/skills/leniu-backend-annotations/SKILL.md +132 -519
- package/.codex/skills/leniu-brainstorm/SKILL.md +132 -541
- package/.codex/skills/leniu-brainstorm/references/business-scenarios.md +162 -0
- package/.codex/skills/leniu-crud-development/SKILL.md +232 -938
- package/.codex/skills/leniu-crud-development/references/templates.md +597 -0
- package/.codex/skills/leniu-customization-location/SKILL.md +410 -0
- package/.codex/skills/leniu-data-permission/SKILL.md +70 -0
- package/.codex/skills/leniu-java-code-style/SKILL.md +510 -0
- package/.codex/skills/leniu-java-entity/SKILL.md +76 -590
- package/.codex/skills/leniu-java-entity/references/templates.md +237 -0
- package/.codex/skills/leniu-java-export/SKILL.md +94 -379
- package/.codex/skills/leniu-java-logging/SKILL.md +106 -709
- package/.codex/skills/leniu-java-logging/references/data-mask.md +46 -0
- package/.codex/skills/leniu-java-logging/references/logging-scenarios.md +113 -0
- package/.codex/skills/leniu-java-mybatis/SKILL.md +73 -446
- package/.codex/skills/leniu-java-mybatis/references/report-mapper.md +88 -0
- package/.codex/skills/leniu-report-customization/SKILL.md +111 -325
- package/.codex/skills/leniu-report-customization/references/table-fields.md +93 -0
- package/.codex/skills/leniu-report-standard-customization/SKILL.md +328 -0
- package/.codex/skills/leniu-report-standard-customization/references/analysis-module.md +64 -0
- package/.codex/skills/leniu-report-standard-customization/references/table-fields.md +113 -0
- package/.codex/skills/leniu-security-guard/SKILL.md +133 -347
- package/.codex/skills/mysql-debug/SKILL.md +364 -0
- package/.codex/skills/openspec-apply-change/SKILL.md +10 -1
- package/.codex/skills/openspec-archive-change/SKILL.md +9 -1
- package/.codex/skills/openspec-bulk-archive-change/SKILL.md +9 -1
- package/.codex/skills/openspec-continue-change/SKILL.md +9 -1
- package/.codex/skills/openspec-explore/SKILL.md +10 -1
- package/.codex/skills/openspec-ff-change/SKILL.md +9 -1
- package/.codex/skills/openspec-new-change/SKILL.md +9 -1
- package/.codex/skills/openspec-onboard/SKILL.md +15 -130
- package/.codex/skills/openspec-sync-specs/SKILL.md +9 -1
- package/.codex/skills/openspec-verify-change/SKILL.md +9 -1
- package/.codex/skills/performance-doctor/SKILL.md +110 -434
- package/.codex/skills/project-navigator/SKILL.md +20 -1
- package/.codex/skills/redis-cache/SKILL.md +93 -589
- package/.codex/skills/redis-cache/references/listeners.md +23 -0
- package/.codex/skills/scheduled-jobs/SKILL.md +88 -407
- package/.codex/skills/security-guard/SKILL.md +141 -527
- package/.codex/skills/security-guard/references/encrypt-config.md +103 -0
- package/.codex/skills/security-guard/references/sensitive-strategies.md +42 -0
- package/.codex/skills/sms-mail/SKILL.md +116 -574
- package/.codex/skills/sms-mail/references/mail-config.md +88 -0
- package/.codex/skills/sms-mail/references/sms-config.md +74 -0
- package/.codex/skills/social-login/SKILL.md +112 -514
- package/.codex/skills/social-login/references/provider-configs.md +118 -0
- package/.codex/skills/store-pc/SKILL.md +258 -383
- package/.codex/skills/tenant-management/SKILL.md +129 -444
- package/.codex/skills/tenant-management/references/tenant-scenarios.md +91 -0
- package/.codex/skills/test-development/SKILL.md +86 -540
- package/.codex/skills/test-development/references/parameterized-examples.md +119 -0
- package/.codex/skills/ui-pc/SKILL.md +350 -387
- package/.codex/skills/utils-toolkit/SKILL.md +52 -283
- package/.codex/skills/utils-toolkit/references/redis-utils-api.md +56 -0
- package/.codex/skills/websocket-sse/SKILL.md +105 -550
- package/.codex/skills/workflow-engine/SKILL.md +147 -502
- package/.cursor/hooks.json +3 -3
- package/.cursor/rules/skill-activation.mdc +2 -0
- package/.cursor/skills/add-skill/SKILL.md +252 -116
- package/.cursor/skills/api-development/SKILL.md +83 -377
- package/.cursor/skills/architecture-design/SKILL.md +138 -632
- package/.cursor/skills/backend-annotations/SKILL.md +134 -506
- package/.cursor/skills/banana-image/SKILL.md +10 -3
- package/.cursor/skills/brainstorm/SKILL.md +103 -535
- package/.cursor/skills/bug-detective/SKILL.md +147 -1097
- package/.cursor/skills/bug-detective/references/error-patterns.md +242 -0
- package/.cursor/skills/code-patterns/SKILL.md +116 -426
- package/.cursor/skills/code-patterns/references/leniu-code-patterns.md +87 -0
- package/.cursor/skills/crud-development/SKILL.md +64 -304
- package/.cursor/skills/data-permission/SKILL.md +105 -412
- package/.cursor/skills/data-permission/references/custom-data-scope.md +90 -0
- package/.cursor/skills/file-oss-management/SKILL.md +106 -714
- package/.cursor/skills/file-oss-management/references/entities.md +105 -0
- package/.cursor/skills/file-oss-management/references/service-impl.md +104 -0
- package/.cursor/skills/git-workflow/SKILL.md +27 -5
- package/.cursor/skills/leniu-api-development/SKILL.md +142 -626
- package/.cursor/skills/leniu-api-development/references/real-examples.md +273 -0
- package/.cursor/skills/leniu-architecture-design/SKILL.md +176 -391
- package/.cursor/skills/leniu-backend-annotations/SKILL.md +132 -519
- package/.cursor/skills/leniu-brainstorm/SKILL.md +132 -541
- package/.cursor/skills/leniu-brainstorm/references/business-scenarios.md +162 -0
- package/.cursor/skills/leniu-crud-development/SKILL.md +232 -938
- package/.cursor/skills/leniu-crud-development/references/templates.md +597 -0
- package/.cursor/skills/leniu-customization-location/SKILL.md +410 -0
- package/.cursor/skills/leniu-data-permission/SKILL.md +70 -0
- package/.cursor/skills/leniu-java-code-style/SKILL.md +510 -0
- package/.cursor/skills/leniu-java-entity/SKILL.md +76 -590
- package/.cursor/skills/leniu-java-entity/references/templates.md +237 -0
- package/.cursor/skills/leniu-java-export/SKILL.md +94 -379
- package/.cursor/skills/leniu-java-logging/SKILL.md +106 -709
- package/.cursor/skills/leniu-java-logging/references/data-mask.md +46 -0
- package/.cursor/skills/leniu-java-logging/references/logging-scenarios.md +113 -0
- package/.cursor/skills/leniu-java-mybatis/SKILL.md +73 -446
- package/.cursor/skills/leniu-java-mybatis/references/report-mapper.md +88 -0
- package/.cursor/skills/leniu-report-customization/SKILL.md +111 -325
- package/.cursor/skills/leniu-report-customization/references/table-fields.md +93 -0
- package/.cursor/skills/leniu-report-standard-customization/SKILL.md +328 -0
- package/.cursor/skills/leniu-report-standard-customization/references/analysis-module.md +64 -0
- package/.cursor/skills/leniu-report-standard-customization/references/table-fields.md +113 -0
- package/.cursor/skills/leniu-security-guard/SKILL.md +133 -347
- package/.cursor/skills/mysql-debug/SKILL.md +364 -0
- package/.cursor/skills/openspec-apply-change/SKILL.md +10 -1
- package/.cursor/skills/openspec-archive-change/SKILL.md +9 -1
- package/.cursor/skills/openspec-bulk-archive-change/SKILL.md +9 -1
- package/.cursor/skills/openspec-continue-change/SKILL.md +9 -1
- package/.cursor/skills/openspec-explore/SKILL.md +10 -1
- package/.cursor/skills/openspec-ff-change/SKILL.md +9 -1
- package/.cursor/skills/openspec-new-change/SKILL.md +9 -1
- package/.cursor/skills/openspec-onboard/SKILL.md +15 -130
- package/.cursor/skills/openspec-sync-specs/SKILL.md +9 -1
- package/.cursor/skills/openspec-verify-change/SKILL.md +9 -1
- package/.cursor/skills/performance-doctor/SKILL.md +110 -434
- package/.cursor/skills/redis-cache/SKILL.md +89 -595
- package/.cursor/skills/redis-cache/references/listeners.md +23 -0
- package/.cursor/skills/scheduled-jobs/SKILL.md +88 -407
- package/.cursor/skills/security-guard/SKILL.md +137 -532
- package/.cursor/skills/security-guard/references/encrypt-config.md +103 -0
- package/.cursor/skills/security-guard/references/sensitive-strategies.md +42 -0
- package/.cursor/skills/sms-mail/SKILL.md +116 -574
- package/.cursor/skills/sms-mail/references/mail-config.md +88 -0
- package/.cursor/skills/sms-mail/references/sms-config.md +74 -0
- package/.cursor/skills/social-login/SKILL.md +112 -514
- package/.cursor/skills/social-login/references/provider-configs.md +118 -0
- package/.cursor/skills/tenant-management/SKILL.md +129 -444
- package/.cursor/skills/tenant-management/references/tenant-scenarios.md +91 -0
- package/.cursor/skills/test-development/SKILL.md +86 -540
- package/.cursor/skills/test-development/references/parameterized-examples.md +119 -0
- package/.cursor/skills/utils-toolkit/SKILL.md +52 -305
- package/.cursor/skills/utils-toolkit/references/redis-utils-api.md +56 -0
- package/.cursor/skills/websocket-sse/SKILL.md +105 -550
- package/.cursor/skills/workflow-engine/SKILL.md +147 -502
- package/AGENTS.md +1 -0
- package/package.json +1 -1
|
@@ -1,41 +1,35 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: leniu-java-mybatis
|
|
3
3
|
description: |
|
|
4
|
-
leniu-tengyun-core 项目 MyBatis
|
|
4
|
+
leniu-tengyun-core 项目 MyBatis/MyBatis-Plus 使用规范。当编写 Mapper、XML 映射、分页查询时使用此 skill。
|
|
5
5
|
|
|
6
6
|
触发场景:
|
|
7
7
|
- 编写 Mapper 接口(extends BaseMapper)
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
8
|
+
- 编写 MyBatis XML 映射文件(动态 SQL)
|
|
9
|
+
- 使用 LambdaQueryWrapper 构建查询
|
|
10
|
+
- 分页查询(PageHelper + PageVO)
|
|
11
|
+
- 租户隔离控制(@InterceptorIgnore)
|
|
12
12
|
|
|
13
|
-
触发词:MyBatis、MyBatisPlus、Mapper、LambdaQueryWrapper、XML映射、动态SQL、BaseMapper
|
|
13
|
+
触发词:MyBatis、MyBatisPlus、Mapper、LambdaQueryWrapper、XML映射、动态SQL、BaseMapper、分页查询、租户隔离、报表Mapper、PageHelper
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
# leniu
|
|
16
|
+
# leniu MyBatis 规范
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## 项目特征速查
|
|
19
19
|
|
|
20
|
-
|
|
|
21
|
-
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
| **租户隔离** | 租户行级隔离 |
|
|
28
|
-
| **逻辑删除** | 1=删除,2=正常(与 RuoYi 相反) |
|
|
20
|
+
| 项 | 值 |
|
|
21
|
+
|---|---|
|
|
22
|
+
| XML 位置 | **与 Mapper 接口同目录**(非 `resources/mapper/`) |
|
|
23
|
+
| 分页 | PageHelper → `PageMethod.startPage(PageDTO)` → `PageVO.of(list)` |
|
|
24
|
+
| 逻辑删除 | **1=删除,2=正常**(与 RuoYi 相反) |
|
|
25
|
+
| Service | 无接口,直接 `@Service` 类,Mapper 字段名统一用 `baseMapper` |
|
|
26
|
+
| 循环依赖 | 跨模块依赖用 `@Autowired @Lazy` |
|
|
29
27
|
|
|
30
28
|
## Mapper 接口模板
|
|
31
29
|
|
|
32
30
|
### 基础 Mapper
|
|
33
31
|
|
|
34
32
|
```java
|
|
35
|
-
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
36
|
-
import net.xnzn.core.xxx.model.XxxEntity;
|
|
37
|
-
import org.apache.ibatis.annotations.Mapper;
|
|
38
|
-
|
|
39
33
|
@Mapper
|
|
40
34
|
public interface XxxMapper extends BaseMapper<XxxEntity> {
|
|
41
35
|
|
|
@@ -43,12 +37,9 @@ public interface XxxMapper extends BaseMapper<XxxEntity> {
|
|
|
43
37
|
}
|
|
44
38
|
```
|
|
45
39
|
|
|
46
|
-
###
|
|
40
|
+
### 忽略租户隔离(方法级)
|
|
47
41
|
|
|
48
42
|
```java
|
|
49
|
-
import com.baomidou.mybatisplus.core.interceptor.InterceptorIgnore;
|
|
50
|
-
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
51
|
-
|
|
52
43
|
@Mapper
|
|
53
44
|
public interface XxxMapper extends BaseMapper<XxxEntity> {
|
|
54
45
|
|
|
@@ -57,153 +48,25 @@ public interface XxxMapper extends BaseMapper<XxxEntity> {
|
|
|
57
48
|
}
|
|
58
49
|
```
|
|
59
50
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
### 全量忽略拦截器(类级别,来自 OrderInfoMapper 真实代码)
|
|
51
|
+
### 全量忽略拦截器(类级别)
|
|
63
52
|
|
|
64
53
|
```java
|
|
65
|
-
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
|
66
|
-
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
67
|
-
import net.xnzn.framework.data.exists.BaseExistsMapper;
|
|
68
|
-
import org.apache.ibatis.annotations.Mapper;
|
|
69
|
-
|
|
70
54
|
@Mapper
|
|
71
|
-
@InterceptorIgnore //
|
|
55
|
+
@InterceptorIgnore // 无参数,跳过所有拦截器(租户、数据权限等)
|
|
72
56
|
public interface XxxMapper extends BaseMapper<XxxEntity>, BaseExistsMapper<XxxEntity> {
|
|
73
57
|
|
|
74
|
-
// 自定义 XML 查询方法
|
|
75
58
|
List<XxxVO> listVoByIds(@Param("orderIds") List<Long> ids, @Param("tenantId") String tenantId);
|
|
76
59
|
|
|
77
60
|
@QueryExtension
|
|
78
|
-
List<XxxIdDateVO> queryXxx(@Param("param") XxxSearchParam param,
|
|
61
|
+
List<XxxIdDateVO> queryXxx(@Param("param") XxxSearchParam param,
|
|
62
|
+
@Param("permission") XxxUserPermissionDTO permission);
|
|
79
63
|
}
|
|
80
64
|
```
|
|
81
65
|
|
|
82
|
-
|
|
83
|
-
-
|
|
84
|
-
- `BaseExistsMapper<XxxEntity>` 提供 `existsOne(Wrapper)` 方法,用于检查记录是否存在,比 `selectCount > 0` 更高效
|
|
85
|
-
- 适用于:订单等核心表(数据量大、需要全量跨租户查询的场景)
|
|
86
|
-
|
|
87
|
-
### BaseExistsMapper 使用示例
|
|
88
|
-
|
|
89
|
-
```java
|
|
90
|
-
// 检查订单是否存在
|
|
91
|
-
boolean exists = baseMapper.existsOne(
|
|
92
|
-
Wrappers.lambdaQuery(OrderInfo.class)
|
|
93
|
-
.eq(OrderInfo::getMacOrderId, macOrderId)
|
|
94
|
-
.eq(OrderInfo::getDelFlag, 2)
|
|
95
|
-
);
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Entity 实体类模板
|
|
99
|
-
|
|
100
|
-
### 基础 Entity
|
|
101
|
-
|
|
102
|
-
```java
|
|
103
|
-
import com.baomidou.mybatisplus.annotation.*;
|
|
104
|
-
import io.swagger.annotations.ApiModel;
|
|
105
|
-
import io.swagger.annotations.ApiModelProperty;
|
|
106
|
-
import lombok.Data;
|
|
107
|
-
|
|
108
|
-
import java.time.LocalDateTime;
|
|
109
|
-
|
|
110
|
-
@Data
|
|
111
|
-
@TableName(value = "table_name", autoResultMap = true)
|
|
112
|
-
public class XxxEntity {
|
|
113
|
-
|
|
114
|
-
@TableId
|
|
115
|
-
@ApiModelProperty(value = "主键ID")
|
|
116
|
-
private Long id;
|
|
117
|
-
|
|
118
|
-
@ApiModelProperty(value = "删除标识(1-删除,2-正常)")
|
|
119
|
-
private Integer delFlag;
|
|
120
|
-
|
|
121
|
-
@ApiModelProperty(value = "创建人")
|
|
122
|
-
private String crby;
|
|
123
|
-
|
|
124
|
-
@ApiModelProperty(value = "创建时间")
|
|
125
|
-
private LocalDateTime crtime;
|
|
126
|
-
|
|
127
|
-
@ApiModelProperty(value = "更新人")
|
|
128
|
-
private String upby;
|
|
129
|
-
|
|
130
|
-
@ApiModelProperty(value = "更新时间")
|
|
131
|
-
private LocalDateTime uptime;
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### 自动填充字段
|
|
136
|
-
|
|
137
|
-
```java
|
|
138
|
-
import com.baomidou.mybatisplus.annotation.FieldFill;
|
|
139
|
-
import com.baomidou.mybatisplus.annotation.TableField;
|
|
140
|
-
import com.baomidou.mybatisplus.annotation.TableId;
|
|
141
|
-
import com.baomidou.mybatisplus.annotation.TableName;
|
|
142
|
-
import lombok.Data;
|
|
143
|
-
|
|
144
|
-
import java.time.LocalDateTime;
|
|
145
|
-
|
|
146
|
-
@Data
|
|
147
|
-
@TableName(value = "table_name", autoResultMap = true)
|
|
148
|
-
public class XxxEntity {
|
|
149
|
-
|
|
150
|
-
@TableId
|
|
151
|
-
private Long id;
|
|
152
|
-
|
|
153
|
-
// 插入时自动填充
|
|
154
|
-
@TableField(fill = FieldFill.INSERT)
|
|
155
|
-
private String crby;
|
|
156
|
-
|
|
157
|
-
@TableField(fill = FieldFill.INSERT)
|
|
158
|
-
private LocalDateTime crtime;
|
|
159
|
-
|
|
160
|
-
// 插入或更新时自动填充
|
|
161
|
-
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
162
|
-
private String upby;
|
|
163
|
-
|
|
164
|
-
@TableField(fill = FieldFill.INSERT_UPDATE)
|
|
165
|
-
private LocalDateTime uptime;
|
|
166
|
-
}
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
## LambdaQuery 使用
|
|
170
|
-
|
|
171
|
-
### 条件查询
|
|
172
|
-
|
|
173
|
-
```java
|
|
174
|
-
import cn.hutool.core.util.StrUtil;
|
|
175
|
-
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
176
|
-
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
177
|
-
|
|
178
|
-
// 条件查询
|
|
179
|
-
List<XxxEntity> list = mapper.selectList(
|
|
180
|
-
Wrappers.lambdaQuery(XxxEntity.class)
|
|
181
|
-
.eq(XxxEntity::getStatus, 1)
|
|
182
|
-
.eq(XxxEntity::getDelFlag, 2) // 2=正常
|
|
183
|
-
.in(XxxEntity::getId, idList)
|
|
184
|
-
.like(StrUtil.isNotBlank(name), XxxEntity::getName, name)
|
|
185
|
-
.orderByDesc(XxxEntity::getCrtime)
|
|
186
|
-
);
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
### 字段非空判断
|
|
66
|
+
- `BaseExistsMapper` 提供 `existsOne(Wrapper)` 方法(比 `selectCount > 0` 高效)
|
|
67
|
+
- 适用于数据量大、需跨租户查询的核心表
|
|
190
68
|
|
|
191
|
-
|
|
192
|
-
import cn.hutool.core.util.ObjectUtil;
|
|
193
|
-
import cn.hutool.core.util.StrUtil;
|
|
194
|
-
|
|
195
|
-
LambdaQueryWrapper<XxxEntity> wrapper = Wrappers.lambdaQuery();
|
|
196
|
-
|
|
197
|
-
// 使用 Hutool 工具类
|
|
198
|
-
wrapper.eq(ObjectUtil.isNotNull(status), XxxEntity::getStatus, status);
|
|
199
|
-
wrapper.like(StrUtil.isNotBlank(keyword), XxxEntity::getName, keyword);
|
|
200
|
-
wrapper.ge(startDate != null, XxxEntity::getCrtime, startDate);
|
|
201
|
-
wrapper.le(endDate != null, XxxEntity::getCrtime, endDate);
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
## XML 编写模板
|
|
205
|
-
|
|
206
|
-
### 基本结构
|
|
69
|
+
## XML 模板
|
|
207
70
|
|
|
208
71
|
```xml
|
|
209
72
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -231,26 +94,20 @@ wrapper.le(endDate != null, XxxEntity::getCrtime, endDate);
|
|
|
231
94
|
</mapper>
|
|
232
95
|
```
|
|
233
96
|
|
|
234
|
-
### XML
|
|
97
|
+
### XML 编写规则
|
|
235
98
|
|
|
236
99
|
| 规则 | 说明 |
|
|
237
100
|
|------|------|
|
|
238
101
|
| 禁止 `SELECT *` | 必须明确指定字段 |
|
|
239
|
-
|
|
|
240
|
-
|
|
|
241
|
-
|
|
|
242
|
-
|
|
|
243
|
-
| 逻辑删除条件 | `del_flag = 2` 表示正常数据 |
|
|
102
|
+
| `del_flag = 2` | 正常数据条件 |
|
|
103
|
+
| `#{}` 占位符 | 禁止 `${}`(SQL 注入) |
|
|
104
|
+
| `<where>` 标签 | 自动处理 AND 前缀 |
|
|
105
|
+
| 特殊字符 | `<` / `>` 或 `<![CDATA[ ]]>` |
|
|
244
106
|
|
|
245
|
-
###
|
|
107
|
+
### 常用动态 SQL 片段
|
|
246
108
|
|
|
247
109
|
```xml
|
|
248
|
-
<!--
|
|
249
|
-
<if test="param.status != null">
|
|
250
|
-
AND t.status = #{param.status}
|
|
251
|
-
</if>
|
|
252
|
-
|
|
253
|
-
<!-- 集合遍历(IN 查询) -->
|
|
110
|
+
<!-- IN 查询 -->
|
|
254
111
|
<if test="param.ids != null and param.ids.size() > 0">
|
|
255
112
|
AND t.id IN
|
|
256
113
|
<foreach collection="param.ids" item="id" open="(" separator="," close=")">
|
|
@@ -260,10 +117,8 @@ wrapper.le(endDate != null, XxxEntity::getCrtime, endDate);
|
|
|
260
117
|
|
|
261
118
|
<!-- 多条件 OR -->
|
|
262
119
|
<if test="param.keyword != null and param.keyword != ''">
|
|
263
|
-
AND (
|
|
264
|
-
|
|
265
|
-
OR t.code LIKE CONCAT('%', #{param.keyword}, '%')
|
|
266
|
-
)
|
|
120
|
+
AND (t.name LIKE CONCAT('%', #{param.keyword}, '%')
|
|
121
|
+
OR t.code LIKE CONCAT('%', #{param.keyword}, '%'))
|
|
267
122
|
</if>
|
|
268
123
|
|
|
269
124
|
<!-- 时间范围 -->
|
|
@@ -273,28 +128,24 @@ wrapper.le(endDate != null, XxxEntity::getCrtime, endDate);
|
|
|
273
128
|
<if test="param.endDate != null">
|
|
274
129
|
AND t.crtime <= #{param.endDate}
|
|
275
130
|
</if>
|
|
276
|
-
|
|
277
|
-
<!-- 特殊字符 -->
|
|
278
|
-
< <!-- 小于 < -->
|
|
279
|
-
> <!-- 大于 > -->
|
|
280
|
-
& <!-- 和 & -->
|
|
281
131
|
```
|
|
282
132
|
|
|
283
|
-
##
|
|
284
|
-
|
|
285
|
-
### leniu 项目规范
|
|
133
|
+
## LambdaQuery 使用
|
|
286
134
|
|
|
135
|
+
```java
|
|
136
|
+
List<XxxEntity> list = mapper.selectList(
|
|
137
|
+
Wrappers.lambdaQuery(XxxEntity.class)
|
|
138
|
+
.eq(XxxEntity::getStatus, 1)
|
|
139
|
+
.eq(XxxEntity::getDelFlag, 2) // 2=正常
|
|
140
|
+
.in(CollUtil.isNotEmpty(idList), XxxEntity::getId, idList)
|
|
141
|
+
.like(StrUtil.isNotBlank(name), XxxEntity::getName, name)
|
|
142
|
+
.ge(startDate != null, XxxEntity::getCrtime, startDate)
|
|
143
|
+
.le(endDate != null, XxxEntity::getCrtime, endDate)
|
|
144
|
+
.orderByDesc(XxxEntity::getCrtime)
|
|
145
|
+
);
|
|
287
146
|
```
|
|
288
|
-
net.xnzn.core.xxx.mapper
|
|
289
|
-
├── XxxMapper.java # Mapper 接口
|
|
290
|
-
└── XxxMapper.xml # XML 文件(与接口同目录)
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
**注意**:leniu 项目的 Mapper XML 文件放在与 Mapper 接口同目录下,不是 `resources/mapper/`。
|
|
294
147
|
|
|
295
|
-
## Service
|
|
296
|
-
|
|
297
|
-
### 字段命名(来自 OrderInfoService 真实代码)
|
|
148
|
+
## Service 注入规范
|
|
298
149
|
|
|
299
150
|
```java
|
|
300
151
|
@Slf4j
|
|
@@ -302,23 +153,16 @@ net.xnzn.core.xxx.mapper
|
|
|
302
153
|
@Validated
|
|
303
154
|
public class XxxService {
|
|
304
155
|
|
|
305
|
-
// ✅ 正确:Mapper 字段命名为 baseMapper
|
|
306
156
|
@Autowired
|
|
307
|
-
private XxxMapper baseMapper;
|
|
157
|
+
private XxxMapper baseMapper; // ✅ 统一命名 baseMapper
|
|
308
158
|
|
|
309
|
-
|
|
310
|
-
@
|
|
311
|
-
@Lazy
|
|
312
|
-
private XxxDetailService xxxDetailService;
|
|
159
|
+
@Autowired @Lazy
|
|
160
|
+
private XxxDetailService xxxDetailService; // ✅ 跨模块用 @Lazy
|
|
313
161
|
|
|
314
162
|
public XxxEntity getOne(Long id) {
|
|
315
163
|
return baseMapper.selectById(id);
|
|
316
164
|
}
|
|
317
165
|
|
|
318
|
-
public List<XxxVO> listByIds(List<Long> ids) {
|
|
319
|
-
return baseMapper.listVoByIds(ids, TenantContextHolder.getTenantId());
|
|
320
|
-
}
|
|
321
|
-
|
|
322
166
|
public boolean exists(String macOrderId) {
|
|
323
167
|
return baseMapper.existsOne(
|
|
324
168
|
Wrappers.lambdaQuery(XxxEntity.class)
|
|
@@ -329,140 +173,51 @@ public class XxxService {
|
|
|
329
173
|
}
|
|
330
174
|
```
|
|
331
175
|
|
|
332
|
-
**规范要点**:
|
|
333
|
-
- Service **无接口**(不用 `IXxxService`),直接 `@Service` 类
|
|
334
|
-
- Service 类上加 `@Validated` 支持方法参数的 `@NotNull` 校验
|
|
335
|
-
- Mapper 注入字段名统一用 `baseMapper`(不用 `xxxMapper`)
|
|
336
|
-
- 跨模块依赖(其他 Service/Client)用 `@Autowired @Lazy` 防循环依赖
|
|
337
|
-
|
|
338
176
|
## 分页查询
|
|
339
177
|
|
|
340
|
-
### PageHelper 分页
|
|
341
|
-
|
|
342
178
|
```java
|
|
343
|
-
import com.github.pagehelper.page.PageMethod;
|
|
344
|
-
import net.xnzn.core.common.page.PageVO;
|
|
345
|
-
|
|
346
179
|
public PageVO<XxxVO> pageList(XxxParam param) {
|
|
347
|
-
// ✅
|
|
180
|
+
// ✅ 传入 PageDTO 对象(不要拆 pageNum/pageSize)
|
|
348
181
|
if (Objects.nonNull(param.getPage())) {
|
|
349
182
|
PageMethod.startPage(param.getPage());
|
|
350
183
|
}
|
|
351
184
|
|
|
352
|
-
// 执行查询,Mapper 返回 List 即可,PageHelper 自动附加分页信息
|
|
353
185
|
List<XxxVO> records = xxxMapper.listByParam(param);
|
|
354
186
|
|
|
355
|
-
//
|
|
356
|
-
return PageVO.of(records);
|
|
187
|
+
return PageVO.of(records); // 自动提取 total 等信息
|
|
357
188
|
}
|
|
358
189
|
```
|
|
359
190
|
|
|
360
|
-
|
|
361
|
-
- `PageMethod.startPage(param.getPage())` 传 `PageDTO` 对象,不要拆开传 `pageNum`/`pageSize`
|
|
362
|
-
- Mapper 方法返回 `List<XxxVO>` 即可,PageHelper 拦截器自动处理分页
|
|
363
|
-
- `PageVO.of(records)` 自动从 PageHelper 的 Page 代理对象提取总数等信息
|
|
191
|
+
Mapper 方法返回 `List<XxxVO>` 即可,PageHelper 拦截器自动处理分页。
|
|
364
192
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
```java
|
|
368
|
-
@Data
|
|
369
|
-
public class XxxParam implements Serializable {
|
|
370
|
-
|
|
371
|
-
@ApiModelProperty(value = "分页参数", required = true)
|
|
372
|
-
@NotNull(message = "分页参数不能为空")
|
|
373
|
-
private PageDTO page;
|
|
374
|
-
|
|
375
|
-
@ApiModelProperty("关键字")
|
|
376
|
-
private String keyword;
|
|
377
|
-
}
|
|
378
|
-
```
|
|
379
|
-
|
|
380
|
-
## 报表 Mapper 规范(来自 ReportAnalysisTurnoverMapper 真实代码)
|
|
381
|
-
|
|
382
|
-
报表模块的 Mapper **不继承 BaseMapper**(纯 SQL 查询,无 CRUD),固定三个参数:`param`、`authPO`、`dataPermission`:
|
|
193
|
+
## 报表 Mapper(无 BaseMapper)
|
|
383
194
|
|
|
384
195
|
```java
|
|
385
196
|
@Mapper
|
|
386
|
-
public interface ReportXxxMapper {
|
|
197
|
+
public interface ReportXxxMapper { // ✅ 不继承 BaseMapper
|
|
387
198
|
|
|
388
|
-
// ✅ 分页列表查询(PageHelper 拦截,方法返回 List)
|
|
389
199
|
List<XxxVO> listSummary(
|
|
390
200
|
@Param("param") XxxParam param,
|
|
391
201
|
@Param("authPO") MgrUserAuthPO authPO,
|
|
392
202
|
@Param("dataPermission") ReportDataPermissionParam dataPermission
|
|
393
203
|
);
|
|
394
204
|
|
|
395
|
-
//
|
|
396
|
-
XxxVO getSummaryTotal(
|
|
205
|
+
XxxVO getSummaryTotal( // 合计行
|
|
397
206
|
@Param("param") XxxParam param,
|
|
398
207
|
@Param("authPO") MgrUserAuthPO authPO,
|
|
399
208
|
@Param("dataPermission") ReportDataPermissionParam dataPermission
|
|
400
209
|
);
|
|
401
|
-
|
|
402
|
-
// ✅ 按日/按月分组(对应 dateType 参数)
|
|
403
|
-
List<XxxVO> listSummaryByDay(
|
|
404
|
-
@Param("param") XxxParam param,
|
|
405
|
-
@Param("authPO") MgrUserAuthPO authPO,
|
|
406
|
-
@Param("dataPermission") ReportDataPermissionParam dataPermission
|
|
407
|
-
);
|
|
408
|
-
List<XxxVO> listSummaryByMonth(
|
|
409
|
-
@Param("param") XxxParam param,
|
|
410
|
-
@Param("authPO") MgrUserAuthPO authPO,
|
|
411
|
-
@Param("dataPermission") ReportDataPermissionParam dataPermission
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
// ✅ 汇总数据(总金额、人次等)
|
|
415
|
-
ReportTurnoverPO getTurnoverTotal(
|
|
416
|
-
@Param("param") XxxParam param,
|
|
417
|
-
@Param("authPO") MgrUserAuthPO authPO,
|
|
418
|
-
@Param("dataPermission") ReportDataPermissionParam dataPermission
|
|
419
|
-
);
|
|
420
|
-
|
|
421
|
-
// ✅ 排行榜类(不需要 authPO 时可省略)
|
|
422
|
-
List<RankVO> getXxxRank(
|
|
423
|
-
@Param("param") RankParam param,
|
|
424
|
-
@Param("dataPermission") ReportDataPermissionParam dataPermission
|
|
425
|
-
);
|
|
426
210
|
}
|
|
427
211
|
```
|
|
428
212
|
|
|
429
|
-
|
|
430
|
-
1. `@Mapper` 注解,**不继承 BaseMapper**(报表无 CRUD)
|
|
431
|
-
2. 所有参数必须加 `@Param`,顺序:`param` → `authPO` → `dataPermission`
|
|
432
|
-
3. 分页列表返回 `List<VO>`,由 Service 层调用 `PageMethod.startPage()` 控制
|
|
433
|
-
4. 合计行返回单个 PO/VO 对象
|
|
434
|
-
5. COUNT 方法(`listXxx_COUNT`)配合 `CompletableFuture` 并发使用
|
|
435
|
-
|
|
436
|
-
**命名规律**:
|
|
437
|
-
- 分页数据方法:`listXxx()`
|
|
438
|
-
- 对应 COUNT 方法:`listXxx_COUNT()`(下划线 + COUNT)
|
|
439
|
-
- 合计行方法:`getSummaryTotal()` / `getSummaryXxxTotal()`
|
|
440
|
-
- 按维度变体:`listXxxByDay()` / `listXxxByDay_COUNT()`
|
|
213
|
+
**命名规律**:`listXxx()` 分页数据 / `listXxx_COUNT()` 计数 / `getSummaryTotal()` 合计行 / `listXxxByDay()` 按维度
|
|
441
214
|
|
|
442
215
|
## 合计行查询
|
|
443
216
|
|
|
444
|
-
### Mapper 接口(普通 CRUD 模块)
|
|
445
|
-
|
|
446
|
-
```java
|
|
447
|
-
@Mapper
|
|
448
|
-
public interface XxxMapper extends BaseMapper<XxxEntity> {
|
|
449
|
-
|
|
450
|
-
List<XxxVO> listByParam(@Param("param") XxxParam param);
|
|
451
|
-
|
|
452
|
-
XxxVO getSummaryTotal(@Param("param") XxxParam param);
|
|
453
|
-
}
|
|
454
|
-
```
|
|
455
|
-
|
|
456
|
-
### XML 实现
|
|
457
|
-
|
|
458
217
|
```xml
|
|
459
218
|
<!-- 列表查询 -->
|
|
460
219
|
<select id="listByParam" resultType="XxxVO">
|
|
461
|
-
SELECT
|
|
462
|
-
id,
|
|
463
|
-
name,
|
|
464
|
-
amount,
|
|
465
|
-
count
|
|
220
|
+
SELECT id, name, amount, count
|
|
466
221
|
FROM table_name
|
|
467
222
|
<where>...</where>
|
|
468
223
|
ORDER BY id DESC
|
|
@@ -470,171 +225,43 @@ public interface XxxMapper extends BaseMapper<XxxEntity> {
|
|
|
470
225
|
|
|
471
226
|
<!-- 合计查询:只返回数值字段 -->
|
|
472
227
|
<select id="getSummaryTotal" resultType="XxxVO">
|
|
473
|
-
SELECT
|
|
474
|
-
SUM(amount) AS amount,
|
|
475
|
-
SUM(count) AS count
|
|
228
|
+
SELECT SUM(amount) AS amount, SUM(count) AS count
|
|
476
229
|
FROM table_name
|
|
477
230
|
<where>...</where>
|
|
478
231
|
</select>
|
|
479
232
|
```
|
|
480
233
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
### 常用合计函数
|
|
484
|
-
|
|
485
|
-
| 函数 | 用途 | 示例 |
|
|
486
|
-
|------|------|------|
|
|
487
|
-
| `SUM()` | 求和 | `SUM(amount)` |
|
|
488
|
-
| `COUNT()` | 计数 | `COUNT(*)` |
|
|
489
|
-
| `AVG()` | 平均值 | `AVG(price)` |
|
|
490
|
-
| `MAX()` | 最大值 | `MAX(amount)` |
|
|
491
|
-
| `MIN()` | 最小值 | `MIN(amount)` |
|
|
492
|
-
|
|
493
|
-
### 特殊处理
|
|
494
|
-
|
|
234
|
+
除零处理:
|
|
495
235
|
```xml
|
|
496
|
-
|
|
497
|
-
CASE
|
|
498
|
-
WHEN SUM(count) = 0 THEN 0
|
|
499
|
-
ELSE SUM(amount) / SUM(count)
|
|
500
|
-
END AS avgAmount
|
|
501
|
-
|
|
502
|
-
<!-- 按维度平均 -->
|
|
503
|
-
CASE
|
|
504
|
-
WHEN SUM(staff_count) = 0 THEN 0
|
|
505
|
-
ELSE SUM(avg_salary) / COUNT(DISTINCT tenant_id)
|
|
506
|
-
END AS avgSalary
|
|
236
|
+
CASE WHEN SUM(count) = 0 THEN 0 ELSE SUM(amount) / SUM(count) END AS avgAmount
|
|
507
237
|
```
|
|
508
238
|
|
|
509
|
-
##
|
|
510
|
-
|
|
511
|
-
### 自动隔离
|
|
512
|
-
|
|
513
|
-
默认情况下,MyBatis-Plus 会自动为查询添加租户条件:
|
|
514
|
-
|
|
515
|
-
```sql
|
|
516
|
-
SELECT * FROM table_name WHERE del_flag = 2 AND tenant_id = ?
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
### 忽略租户隔离
|
|
520
|
-
|
|
521
|
-
```java
|
|
522
|
-
@InterceptorIgnore(tenantLine = "true")
|
|
523
|
-
List<XxxVO> queryWithoutTenant(@Param("param") XxxParam param);
|
|
524
|
-
```
|
|
525
|
-
|
|
526
|
-
**使用场景**:
|
|
527
|
-
- 查询系统级配置数据
|
|
528
|
-
- 跨租户数据汇总
|
|
529
|
-
- 导出所有租户数据
|
|
530
|
-
|
|
531
|
-
## 逻辑删除
|
|
532
|
-
|
|
533
|
-
### 删除标识
|
|
534
|
-
|
|
535
|
-
| 值 | 含义 |
|
|
536
|
-
|-----|------|
|
|
537
|
-
| 1 | 已删除 |
|
|
538
|
-
| 2 | 正常 |
|
|
539
|
-
|
|
540
|
-
**注意**:与 RuoYi-Vue-Plus 相反(RuoYi: 0=正常, 2=删除)
|
|
541
|
-
|
|
542
|
-
### 查询过滤
|
|
543
|
-
|
|
544
|
-
```java
|
|
545
|
-
// 查询时自动过滤已删除数据
|
|
546
|
-
LambdaQueryWrapper<XxxEntity> wrapper = Wrappers.lambdaQuery();
|
|
547
|
-
wrapper.eq(XxxEntity::getDelFlag, 2); // 2=正常
|
|
548
|
-
|
|
549
|
-
// XML 中手动添加
|
|
550
|
-
SELECT * FROM table_name WHERE del_flag = 2
|
|
551
|
-
```
|
|
552
|
-
|
|
553
|
-
## 常用工具类
|
|
554
|
-
|
|
555
|
-
### Hutool 工具类
|
|
556
|
-
|
|
557
|
-
```java
|
|
558
|
-
import cn.hutool.core.util.ObjectUtil;
|
|
559
|
-
import cn.hutool.core.util.StrUtil;
|
|
560
|
-
import cn.hutool.core.collection.CollUtil;
|
|
561
|
-
|
|
562
|
-
// 对象判空
|
|
563
|
-
if (ObjectUtil.isNull(entity)) { }
|
|
564
|
-
if (ObjectUtil.isNotNull(entity)) { }
|
|
565
|
-
|
|
566
|
-
// 字符串判空
|
|
567
|
-
if (StrUtil.isBlank(str)) { }
|
|
568
|
-
if (StrUtil.isNotBlank(str)) { }
|
|
569
|
-
|
|
570
|
-
// 集合判空
|
|
571
|
-
if (CollUtil.isEmpty(list)) { }
|
|
572
|
-
if (CollUtil.isNotEmpty(list)) { }
|
|
573
|
-
```
|
|
574
|
-
|
|
575
|
-
### MyBatis-Plus 工具类
|
|
576
|
-
|
|
577
|
-
```java
|
|
578
|
-
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
579
|
-
|
|
580
|
-
// 创建 Lambda 查询包装器
|
|
581
|
-
LambdaQueryWrapper<XxxEntity> wrapper = Wrappers.lambdaQuery();
|
|
582
|
-
LambdaUpdateWrapper<XxxEntity> updateWrapper = Wrappers.lambdaUpdate();
|
|
583
|
-
```
|
|
584
|
-
|
|
585
|
-
## 常见错误
|
|
586
|
-
|
|
587
|
-
### 错误1:使用 RuoYi 的 TenantEntity
|
|
239
|
+
## 禁止项
|
|
588
240
|
|
|
589
241
|
```java
|
|
590
|
-
// ❌
|
|
242
|
+
// ❌ 继承 RuoYi TenantEntity
|
|
591
243
|
import org.dromara.common.mybatis.core.domain.TenantEntity;
|
|
592
244
|
|
|
593
|
-
//
|
|
594
|
-
@Data
|
|
595
|
-
@TableName("table_name")
|
|
596
|
-
public class XxxEntity {
|
|
597
|
-
@TableId
|
|
598
|
-
private Long id;
|
|
599
|
-
}
|
|
600
|
-
```
|
|
601
|
-
|
|
602
|
-
### 错误2:delFlag 判断错误
|
|
603
|
-
|
|
604
|
-
```java
|
|
605
|
-
// ❌ 错误:使用 RuoYi 的值
|
|
245
|
+
// ❌ delFlag: 0=正常(leniu 是 2=正常)
|
|
606
246
|
wrapper.eq(XxxEntity::getDelFlag, 0);
|
|
607
247
|
|
|
608
|
-
//
|
|
609
|
-
wrapper.eq(XxxEntity::getDelFlag, 2);
|
|
610
|
-
```
|
|
248
|
+
// ❌ XML 放 resources/mapper/(必须与 Mapper 接口同目录)
|
|
611
249
|
|
|
612
|
-
|
|
250
|
+
// ❌ MapstructUtils(用 BeanUtil.copyProperties)
|
|
251
|
+
MapstructUtils.convert(source, Target.class);
|
|
613
252
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
net.xnzn.core.xxx.mapper
|
|
617
|
-
└── XxxMapper.java
|
|
618
|
-
src/main/resources/mapper/
|
|
619
|
-
└── XxxMapper.xml
|
|
620
|
-
|
|
621
|
-
# ✅ 正确:XML 与接口同目录
|
|
622
|
-
net.xnzn.core.xxx.mapper
|
|
623
|
-
├── XxxMapper.java
|
|
624
|
-
└── XxxMapper.xml
|
|
253
|
+
// ❌ Service 继承 IService / ServiceImpl
|
|
254
|
+
public interface IXxxService extends IService<XxxEntity> {}
|
|
625
255
|
```
|
|
626
256
|
|
|
627
|
-
|
|
257
|
+
## XML 文件位置
|
|
628
258
|
|
|
629
|
-
```
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
// ✅ 正确:leniu 使用 Hutool
|
|
634
|
-
import cn.hutool.core.bean.BeanUtil;
|
|
635
|
-
Target target = BeanUtil.copyProperties(source, Target.class);
|
|
259
|
+
```
|
|
260
|
+
net.xnzn.core.xxx.mapper/
|
|
261
|
+
├── XxxMapper.java # 接口
|
|
262
|
+
└── XxxMapper.xml # XML(同目录!)
|
|
636
263
|
```
|
|
637
264
|
|
|
638
265
|
## 参考文档
|
|
639
266
|
|
|
640
|
-
|
|
267
|
+
- 报表 Mapper 完整示例:详见 `references/report-mapper.md`
|