chenjiahe
2022-01-28 b1097dce55d857ae1ae63798911c1e7027c00de4
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.hx.common.service.impl;
 
import com.hx.common.dao.CommonDao;
import com.hx.common.dao.CommonMapper;
import com.hx.mybatisTool.SqlSentence;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
 
/**当前是没有事务处理,切勿直接使用*/
@Service
public class CommonDaoImpl implements CommonDao {
 
    @Resource(name = "sqlSessionFactory")
    protected SqlSessionFactory sqlSessionFactory;
 
    /**组拼XML文件sql的id*/
    private <T> String getStatement(Class<T> clazz, String prefix){
        return clazz.getName()+"."+prefix;
    }
 
    /**插入*/
    @Override
    public <T extends Serializable> int insert(Class<?> mapperClass,T entity) {
        return sqlSessionFactory.openSession().insert(getStatement(mapperClass,"insert"),entity);
    }
 
    /**获取条数
     * @return*/
    @Override
    public <T extends Serializable> int selectCount(Class<?> mapperClass, SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCount"),sqlSentence);
    }
 
    /**获取条数
     * @return*/
    @Override
    public <T extends Serializable> int selectCountSql(Class<?> mapperClass, SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectCountSql"),sqlSentence);
    }
 
    /**获取列表*/
    @Override
    public <T extends Serializable> List<T> selectList(Class<?> mapperClass, SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().selectList(getStatement(mapperClass,"selectList"),sqlSentence);
    }
 
    /**获取列表*/
    @Override
    public <T extends Serializable> List<Map<String, Object>> selectListMap(Class<?> mapperClass, SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().selectList(getStatement(mapperClass,"selectListMap"),sqlSentence);
    }
 
    /**获取单条数据*/
    @Override
    public <T extends Serializable> T selectOne(Class<?> mapperClass, SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOne"),sqlSentence);
    }
 
    /**获取单条数据*/
    @Override
    public <T extends Serializable> Map<String, Object> selectOneMap(Class<?> mapperClass, SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneMap"),sqlSentence);
    }
 
    /**获取单条数据-不含longText的数据*/
    @Override
    public <T extends Serializable> T selectOneByKey(Class<?> mapperClass,Object object) {
        return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneByKey"),object);
    }
 
    /**获取单条数据-含longText的数据*/
    @Override
    public <T extends Serializable> T selectOneByKeyBlob(Class<?> mapperClass,Object object) {
        return sqlSessionFactory.openSession().selectOne(getStatement(mapperClass,"selectOneByKeyBlob"),object);
    }
 
    /**更新*/
    @Override
    public <T extends Serializable> int updateWhere(Class<?> mapperClass,SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateWhere"),sqlSentence);
    }
 
    /**全部字段更新*/
    @Override
    public <T extends Serializable> int updateAll(Class<?> mapperClass,T entity) {
        return sqlSessionFactory.openSession().update(getStatement(mapperClass,"updateAll"),entity);
    }
 
    /**删除*/
    @Override
    public <T extends Serializable> int deleteWhere(Class<?> mapperClass,SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteWhere"),sqlSentence);
    }
 
    /**删除*/
    @Override
    public <T extends Serializable> int deleteById(Class<?> mapperClass,Object object) {
        return sqlSessionFactory.openSession().delete(getStatement(mapperClass,"deleteById"),object);
    }
 
    /**更新sql语句(全语句)*/
    @Override
    public <T extends Serializable> int updateSentence(SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().delete(getStatement(CommonMapper.class,"updateSentence"),sqlSentence);
    }
 
    /**查询条数(全语句)*/
    @Override
    public <T extends Serializable> int selectCountSql(SqlSentence sqlSentence) {
        return sqlSessionFactory.openSession().delete(getStatement(CommonMapper.class,"selectCountSql"),sqlSentence);
    }
 
}