diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java new file mode 100644 index 00000000..77b9c286 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java @@ -0,0 +1,90 @@ +package com.ruoyi.common.core.mybatisplus.core; + +import com.baomidou.mybatisplus.core.toolkit.ClassUtils; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ResolvableType; + +import java.util.Collection; + +/** + * IServicePlus 实现类 + * + * @author Lion Li + */ +@Slf4j +@SuppressWarnings("unchecked") +public class ServicePlusImpl, T> extends ServiceImpl implements IServicePlus { + + @Autowired + protected M baseMapper; + + @Override + public M getBaseMapper() { + return baseMapper; + } + + + protected Class entityClass = currentModelClass(); + + @Override + public Class getEntityClass() { + return entityClass; + } + + protected Class mapperClass = currentMapperClass(); + + @Override + protected Class currentMapperClass() { + return (Class) this.getResolvableType().as(ServicePlusImpl.class).getGeneric(0).getType(); + } + + @Override + protected Class currentModelClass() { + return (Class) this.getResolvableType().as(ServicePlusImpl.class).getGeneric(1).getType(); + } + + @Override + protected ResolvableType getResolvableType() { + return ResolvableType.forClass(ClassUtils.getUserClass(getClass())); + } + + /** + * 单条执行性能差 + * + * {@link #saveAll(Collection)} + */ + @Deprecated + @Override + public boolean saveBatch(Collection entityList, int batchSize) { + return super.saveBatch(entityList, batchSize); + } + + @Override + public boolean saveOrUpdate(T entity) { + return super.saveOrUpdate(entity); + } + + /** + * 单条执行性能差 + * + * {@link #saveAll(Collection)} + */ + @Deprecated + @Override + public boolean saveOrUpdateBatch(Collection entityList, int batchSize) { + return super.saveOrUpdateBatch(entityList, batchSize); + } + + @Override + public boolean updateBatchById(Collection entityList, int batchSize) { + return super.updateBatchById(entityList, batchSize); + } + + @Override + public boolean saveAll(Collection entityList) { + return baseMapper.insertAll(entityList) == entityList.size(); + } + +}