yangys
2024-04-09 5e7afb7c22b702b3ab725d0a762e6f5b8119a9df
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
package com.qianwen.core.mp.service.impl;
 
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import java.util.Collection;
import com.qianwen.core.mp.base.BaseEntity;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.core.mp.injector.BladeSqlMethod;
import com.qianwen.core.mp.mapper.BladeMapper;
import com.qianwen.core.mp.service.BladeService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
 
@Validated
/* loaded from: blade-starter-mybatis-9.3.0.0-SNAPSHOT.jar:org/springblade/core/mp/service/impl/BladeServiceImpl.class */
public class BladeServiceImpl<M extends BladeMapper<T>, T extends BaseEntity> extends BaseServiceImpl<M, T> implements BladeService<T> {
    
 
    public boolean saveIgnore(T entity) {
        return SqlHelper.retBool(Integer.valueOf(((BladeMapper) this.baseMapper).insertIgnore(entity)));
    }
 
    public boolean saveReplace(T entity) {
        return SqlHelper.retBool(Integer.valueOf(((BladeMapper) this.baseMapper).replace(entity)));
    }
 
    @Override // org.springblade.core.mp.service.BladeService
    @Transactional(rollbackFor = {Exception.class})
    public boolean saveIgnoreBatch(Collection<T> entityList, int batchSize) {
        return saveBatch(entityList, batchSize, BladeSqlMethod.INSERT_IGNORE_ONE);
    }
 
    @Override // org.springblade.core.mp.service.BladeService
    @Transactional(rollbackFor = {Exception.class})
    public boolean saveReplaceBatch(Collection<T> entityList, int batchSize) {
        return saveBatch(entityList, batchSize, BladeSqlMethod.REPLACE_ONE);
    }
 
    private boolean saveBatch(Collection<T> entityList, int batchSize, BladeSqlMethod sqlMethod) {
        String sqlStatement = bladeSqlStatement(sqlMethod);
        
        executeBatch(entityList, batchSize, (sqlSession, entity) -> sqlSession.insert(sqlStatement, entity));
        
        return true;
    }
 
    protected String bladeSqlStatement(BladeSqlMethod sqlMethod) {
        return SqlHelper.table(currentModelClass()).getSqlStatement(sqlMethod.getMethod());
    }
}