From 46b67fef7a0f4b6dfc659de47bc5d885acdd09f5 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期五, 18 六月 2021 15:28:43 +0800
Subject: [PATCH] add 增加 ServicePlusImpl 自动以实现类 重写移除事务注解方法 防止多数据源失效
---
ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java | 90 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 90 insertions(+), 0 deletions(-)
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 0000000..77b9c28
--- /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<M extends BaseMapperPlus<T>, T> extends ServiceImpl<M, T> implements IServicePlus<T> {
+
+ @Autowired
+ protected M baseMapper;
+
+ @Override
+ public M getBaseMapper() {
+ return baseMapper;
+ }
+
+
+ protected Class<T> entityClass = currentModelClass();
+
+ @Override
+ public Class<T> getEntityClass() {
+ return entityClass;
+ }
+
+ protected Class<T> mapperClass = currentMapperClass();
+
+ @Override
+ protected Class<T> currentMapperClass() {
+ return (Class<T>) this.getResolvableType().as(ServicePlusImpl.class).getGeneric(0).getType();
+ }
+
+ @Override
+ protected Class<T> currentModelClass() {
+ return (Class<T>) 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<T> 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<T> entityList, int batchSize) {
+ return super.saveOrUpdateBatch(entityList, batchSize);
+ }
+
+ @Override
+ public boolean updateBatchById(Collection<T> entityList, int batchSize) {
+ return super.updateBatchById(entityList, batchSize);
+ }
+
+ @Override
+ public boolean saveAll(Collection<T> entityList) {
+ return baseMapper.insertAll(entityList) == entityList.size();
+ }
+
+}
--
Gitblit v1.9.3