liujie
2026-05-20 7dae6f1ae2a3c6ba6c27ca7508e4d23ddb08cede
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.estate.expert.admin.service.common;
 
import com.estate.expert.admin.domain.common.EntityBase;
import com.estate.expert.admin.domain.common.IDtoBase;
import com.estate.expert.admin.domain.user.User;
 
import java.util.List;
 
/**
 * 基础的Service接口
 * 包含了增删改查的基本操作
 * 避免重复编写基础的增删改查代码以及不必要的测试
 */
public interface CrudServiceBase<T extends EntityBase, D extends IDtoBase> {
 
    /**
     * 添加
     * 
     * @param creator 创建者
     * @param dto 数据对象
     * @return 添加后的数据对象
     */
    T add(User creator, D dto);
 
    /**
     * 添加多个
     * 
     * @param creator 创建者
     * @param entityList 数据对象列表
     */
    void addEntities(User creator, List<T> entityList);
 
    /**
     * 添加多个
     * 
     * @param creator 创建者
     * @param dtoList 数据对象列表
     */
    void addDtos(User creator, List<D> dtoList);
 
    /**
     * 批量导入实体(自动处理重名)
     * 专门用于 Excel 导入等批量导入场景
     * 
     * @param creator 创建者
     * @param entityList 实体列表
     */
    void importEntities(User creator, List<T> entityList);
 
    /**
     * 添加
     * 
     * @param creator 创建者
     * @param entity 数据对象
     * @return 添加后的数据对象
     */
    T add(User creator, T entity);
 
    /**
     * 编辑
     * 
     * @param dto 数据对象
     * @return 编辑后的数据对象
     */
    T edit(D dto);
 
    /**
     * 编辑
     * 
     * @param entity 数据对象
     * @return 编辑后的数据对象
     */
    T edit(T entity);
 
    /**
     * 删除多个
     * 
     * @param request 数据对象列表
     */
    void deleteAllById(Iterable<Integer> request);
 
    /**
     * 物理删除
     * 
     * @param id 数据对象ID
     */
    void deletePhysical(Integer id);
 
    /**
     * 获取
     * 
     * @param id 数据对象ID
     * @return 数据对象
     */
    T get(Integer id);
 
    /**
     * 获取
     * 
     * @param id 数据对象ID
     * @param withDeleted 是否包含已删除
     * @return 数据对象
     */
    T get(Integer id, boolean withDeleted);
 
    /**
     * 获取
     * 
     * @param id 数据对象ID
     * @return 数据对象
     */
    D detail(Integer id);
 
    /**
     * 保存
     * 
     * @param entity 数据对象
     * @return 保存后的数据对象
     */
    T save(T entity);
 
    /**
     * 克隆
     * 
     * @param id 数据对象ID
     * @return 克隆后的数据对象
     */
    T clone(Integer id);
 
    /**
     * 获取所有
     * 
     * @return 数据对象列表
     */
    List<T> findAll();
 
    /**
     * 获取所有
     * 
     * @param ids 数据对象ID列表
     * @return 数据对象列表
     */
    List<T> findAllById(Iterable<Integer> ids);
 
    // Mapper Functions
 
    /**
     * 转换为DTO
     * 
     * @param entityList 数据对象列表
     * @return DTO对象列表
     */
    List<D> toDto(List<T> entityList);
 
    /**
     * 转换为DTO
     * 
     * @param entity 数据对象
     * @return DTO对象
     */
    D toDto(T entity);
 
    /**
     * 转换为实体
     * 
     * @param dto DTO对象
     * @return 数据对象
     */
    T toEntity(D dto);
 
    /**
     * 获取
     * 
     * @param name 数据对象名称
     * @return 数据对象
     */
    T getByName(String name);
 
    /**
     * 是否存在
     * 
     * @param id 数据对象ID
     * @return 是否存在
     */
    boolean existsById(Integer id);
 
    /**
     * 是否存在
     * 
     * @param name 数据对象名称
     * @return 是否存在
     */
    boolean existsByName(String name);
}