📄 iuserimpl.java
字号:
package com.hiiso.crm.common.authority.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
import com.hiiso.crm.common.authority.IUser;
import com.hiiso.crm.common.exception.AuthorityException;
import com.hiiso.crm.common.jdbc.JdbcCallback;
import com.hiiso.crm.common.jdbc.JdbcTemplate;
import com.hiiso.crm.common.jdbc.NextValue;
import com.hiiso.crm.common.jdbc.PreparedStatementSetter;
import com.hiiso.crm.common.pojo.User;
/*************************************************************************
* SYSTEM: 基金CRM系统
* SUBSYS: CRM权限管理模块
* DESCRIPTION: CRM菜单管理接口数据访问实现
* AUTHOR: YAOYI
* CREATE DATE: 2008/11/18
* COPYRIGHT: (c)Copyright 2008 HISUN Corporation. All rights reserved.
* VERSION: V1.0G
* EDIT HISTORY:
*************************************************************************/
public class IUserImpl implements IUser {
static Logger logger = Logger.getLogger("crm.operator");
private DataSource dataSource;
private Connection conn;
private NextValue nextValue;
private User user;
private String roleId;
private List list;
public DataSource getDataSource() {
return dataSource;
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public Connection getConn() {
return conn;
}
public void setConn(Connection conn) {
this.conn = conn;
}
public NextValue getNextValue() {
return nextValue;
}
public void setNextValue(NextValue nextValue) {
this.nextValue = nextValue;
}
public void addUser(User user) throws AuthorityException {
// TODO Auto-generated method stub
}
public void deleteUser(String userId) throws AuthorityException {
// TODO Auto-generated method stub
}
public void editUser(final User user,final String oldId) throws AuthorityException {
try{
conn = dataSource.getConnection();
}catch(Exception ex){
throw new AuthorityException("获取连接失败!");
}
JdbcTemplate tmp = new JdbcTemplate(conn);
String sql ="update TBL_SYSUSER set CUSERID=?,CUSERNAME=?,CPARENT=?,CPASSWORD=?,CPOSITION=? where CUSERID=?";
logger.info(IUserImpl.class.getName()+"sql语句"+sql);
tmp.save(sql, new PreparedStatementSetter(){
public void setter(PreparedStatement pstmt) throws SQLException {
pstmt.setString(1, user.getUserId());
pstmt.setString(2, user.getUserName());
pstmt.setString(3, user.getParentId());
pstmt.setString(4, user.getPassword());
pstmt.setString(5, user.getPosition());
pstmt.setString(6, oldId);
}
});
}
public List getAllUser() throws AuthorityException {
list = new ArrayList();
try{
conn = dataSource.getConnection();
}catch(Exception ex){
throw new AuthorityException("获取连接失败!");
}
JdbcTemplate tmp = new JdbcTemplate(conn);
String sql ="select * from TBL_SYSUSER";
logger.info(IUserImpl.class.getName()+"sql语句"+sql);
tmp.find(sql, new JdbcCallback(){
public void doExecute(ResultSet rs) throws SQLException {
while(rs.next()){
User allUser = new User();
allUser.setUserName(rs.getString("CUSERNAME"));
allUser.setPassword(rs.getString("CPASSWORD"));
allUser.setUserId(rs.getString("CUSERID"));
allUser.setParentId(rs.getString("CPARENT"));
allUser.setPosition(rs.getString("CPOSITION"));
list.add(allUser);
}
}
});
return list;
}
//根据用户名获取用户
public User getLoginUser(final String userId) throws AuthorityException {
try{
conn = dataSource.getConnection();
}catch(Exception ex){
throw new AuthorityException("获取连接失败!");
}
JdbcTemplate tmp = new JdbcTemplate(conn);
String sql ="select * from TBL_SYSUSER where upper(CUSERID)=UPPER(?)";
logger.info(IUserImpl.class.getName()+"sql语句"+sql);
tmp.find(sql, new JdbcCallback(){
public void doExecute(ResultSet rs) throws SQLException {
if(rs.next()){
user = new User();
user.setUserName(rs.getString("CUSERNAME"));
user.setPassword(rs.getString("CPASSWORD"));
user.setUserId(rs.getString("CUSERID"));
user.setParentId(rs.getString("CPARENT"));
user.setPosition(rs.getString("CPOSITION"));
}
}
}, new PreparedStatementSetter(){
public void setter(PreparedStatement pstmt) throws SQLException {
pstmt.setString(1, userId);
}
});
return user;
}
public List getUser(String roleId) throws AuthorityException {
// TODO Auto-generated method stub
return null;
}
public void grantRole(String userId, String roleId)
throws AuthorityException {
// TODO Auto-generated method stub
}
//获取角色ID号
public String getRoleId(final String userId) throws AuthorityException {
try{
conn = dataSource.getConnection();
}catch(Exception ex){
throw new AuthorityException("获取连接失败!");
}
JdbcTemplate tmp = new JdbcTemplate(conn);
String sql ="select CROLEID from TBL_ROLEUSER where upper(CUSERID)=UPPER(?)";
tmp.find(sql, new JdbcCallback(){
public void doExecute(ResultSet rs) throws SQLException {
if(rs.next()){
roleId = new String(rs.getString("CROLEID"));
}
}
}, new PreparedStatementSetter(){
public void setter(PreparedStatement pstmt) throws SQLException {
pstmt.setString(1, userId);
}
});
return roleId;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -