From 46b67fef7a0f4b6dfc659de47bc5d885acdd09f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Fri, 18 Jun 2021 15:28:43 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=A2=9E=E5=8A=A0=20ServicePlusImpl=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=BB=A5=E5=AE=9E=E7=8E=B0=E7=B1=BB=20?= =?UTF-8?q?=E9=87=8D=E5=86=99=E7=A7=BB=E9=99=A4=E4=BA=8B=E5=8A=A1=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E6=96=B9=E6=B3=95=20=E9=98=B2=E6=AD=A2=E5=A4=9A?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=BA=90=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisplus/core/ServicePlusImpl.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java 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(); + } + +}