疯狂的狮子li
2021-06-21 f48d708e2846e8730c81577e6233bce5e44e28f0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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();
    }
 
}