SSOUserDaoJdbc.java
2.87 KB
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
package weaver.authentication.dao;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import weaver.authentication.entity.SSOUser;
import javax.sql.DataSource;
import javax.validation.constraints.NotNull;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
/**
 * Created by crazyDream on 2018/9/17.
 */
public class SSOUserDaoJdbc {
    @NotNull
    private JdbcTemplate jdbcTemplate;
    @NotNull
    private DataSource dataSource;
    public final void setDataSource(final DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
        this.dataSource = dataSource;
    }
    //查询用户信息表SQL(以;分割的两句sql,第1句获取用户基本信息,第2句获取用户关联账号信息)
    @NotNull
    private String sql;
    public void setSql(String sql) {
        this.sql = sql;
    }
    public SSOUser getSSOUserByUsername(String username){
        return this.jdbcTemplate.queryForObject(this.sql.split(";")[0],new UserRowMapper(), username);
    }
    public Map<String,Object> getSSOUserByUsernameMap(String username){
        return this.jdbcTemplate.queryForMap(this.sql.split(";")[0], username);
    }
    /**
     * 获取关联账号信息
     * @param username
     * @return
     */
    public List getRelatedAccountByUsername(String username){
        String sql = this.sql.split(";")[1];
        return jdbcTemplate.queryForList(sql,new Object[]{username});
    }
    class UserRowMapper implements RowMapper<SSOUser> {
        @Override
        public SSOUser mapRow(ResultSet rs, int index) throws SQLException {
            SSOUser user = new SSOUser();
            user.setUid(rs.getInt("id"));
            user.setLoginid(rs.getString("loginid"));
            user.setLastname(rs.getString("lastname"));
            user.setSex(rs.getString("sex"));
            user.setLanguage(rs.getInt("systemlanguage"));
            user.setTelephone(rs.getString("telephone"));
            user.setMobile(rs.getString("mobile"));
            user.setMobilecall(rs.getString("mobilecall"));
            user.setEmail(rs.getString("email"));
            user.setLocationid(rs.getString("locationid"));
            user.setResourcetype(rs.getString("resourcetype"));
            user.setJobtitle(rs.getString("jobtitle"));
            user.setJoblevel(rs.getString("joblevel"));
            user.setDepartment(rs.getInt("departmentid"));
            user.setSubcompany1(rs.getInt("subcompanyid1"));
            user.setManagerid(rs.getString("managerid"));
            user.setAssistantid(rs.getString("assistantid"));
            user.setStatus(rs.getInt("status"));
            user.setAccount(rs.getString("account"));
            user.setNeedusb(rs.getInt("needusb"));
            user.setWorkcode(rs.getString("workcode"));
            return user;
        }
    }
}