001/*
002 *    Copyright 2024-2025, Warm-Flow (290631660@qq.com).
003 *
004 *    Licensed under the Apache License, Version 2.0 (the "License");
005 *    you may not use this file except in compliance with the License.
006 *    You may obtain a copy of the License at
007 *
008 *       https://www.apache.org/licenses/LICENSE-2.0
009 *
010 *    Unless required by applicable law or agreed to in writing, software
011 *    distributed under the License is distributed on an "AS IS" BASIS,
012 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *    See the License for the specific language governing permissions and
014 *    limitations under the License.
015 */
016package org.dromara.warm.flow.core.orm.service;
017
018
019import org.dromara.warm.flow.core.dao.WarmDao;
020import org.dromara.warm.flow.core.orm.agent.WarmQuery;
021import org.dromara.warm.flow.core.utils.page.Page;
022
023import java.io.Serializable;
024import java.util.Collection;
025import java.util.List;
026
027/**
028 * Service接口
029 *
030 * @author warm
031 * @since 2023-03-17
032 */
033public interface IWarmService<T> {
034
035    public <M extends WarmDao<T>> M getDao();
036
037    /**
038     * 根据id查询
039     *
040     * @param id 主键
041     * @return 实体
042     */
043    T getById(Serializable id);
044
045    /**
046     * 根据ids查询
047     *
048     * @param ids 主键
049     * @return 实体
050     */
051    List<T> getByIds(Collection<? extends Serializable> ids);
052
053    /**
054     * 分页查询
055     *
056     * @param entity 查询实体
057     * @param page 分页对象
058     * @return 集合
059     */
060    Page<T> page(T entity, Page<T> page);
061
062    /**
063     * 查询列表
064     *
065     * @param entity 查询实体
066     * @return 集合
067     */
068    List<T> list(T entity);
069
070    /**
071     * 查询列表,可排序
072     *
073     * @param entity 查询实体
074     * @param query
075     * @return 集合
076     */
077    List<T> list(T entity, WarmQuery<T> query);
078
079    /**
080     * 查询一条记录
081     *
082     * @param entity 查询实体
083     * @return 结果
084     */
085    T getOne(T entity);
086
087    /**
088     * 获取总数量
089     *
090     * @param entity 查询实体
091     * @return 结果
092     */
093    long selectCount(T entity);
094
095    /**
096     * 判断是否存在
097     *
098     * @param entity 查询实体
099     * @return 结果
100     */
101    Boolean exists(T entity);
102
103    /**
104     * 新增
105     *
106     * @param entity 实体
107     * @return 结果
108     */
109    boolean save(T entity);
110
111    /**
112     * 根据id修改
113     *
114     * @param entity 实体
115     * @return 结果
116     */
117    boolean updateById(T entity);
118
119    /**
120     * 根据id删除
121     *
122     * @param id 主键
123     * @return 结果
124     */
125    boolean removeById(Serializable id);
126
127    /**
128     * 根据entity删除
129     *
130     * @param entity 实体
131     * @return 结果
132     */
133    boolean remove(T entity);
134
135    /**
136     * 根据ids批量删除
137     *
138     * @param ids 需要删除的数据主键集合
139     * @return 结果
140     */
141    boolean removeByIds(Collection<? extends Serializable> ids);
142
143    /**
144     * 批量新增
145     *
146     * @param list 实体集合
147     */
148    void saveBatch(List<T> list);
149
150    /**
151     * 批量新增
152     *
153     * @param list      需要插入的集合数据
154     * @param batchSize 插入大小
155     */
156    void saveBatch(List<T> list, int batchSize);
157
158    /**
159     * 批量更新
160     *
161     * @param list 集合数据
162     */
163    void updateBatch(List<T> list);
164
165    /**
166     * id设置正序排列
167     *
168     * @return 集合
169     */
170    WarmQuery<T> orderById();
171
172    /**
173     * 创建时间设置正序排列
174     *
175     * @return 集合
176     */
177    WarmQuery<T> orderByCreateTime();
178
179    /**
180     * 更新时间设置正序排列
181     *
182     * @return 集合
183     */
184    WarmQuery<T> orderByUpdateTime();
185
186    /**
187     * 设置正序排列
188     *
189     * @param orderByField 排序字段
190     * @return 集合
191     */
192    WarmQuery<T> orderByAsc(String orderByField);
193
194    /**
195     * 设置倒序排列
196     *
197     * @param orderByField 排序字段
198     * @return 集合
199     */
200    WarmQuery<T> orderByDesc(String orderByField);
201
202    /**
203     * 用户自定义排序方案
204     *
205     * @param orderByField 排序字段
206     * @return 集合
207     */
208    WarmQuery<T> orderBy(String orderByField);
209}