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);
|
}
|