📄 userdaoimpl.java
字号:
package com.cownew.PIS.base.permission.bizLayer;
import java.sql.SQLException;
import com.cownew.PIS.base.permission.common.IUserDAO;
import com.cownew.PIS.base.permission.common.UserException;
import com.cownew.PIS.base.permission.common.UserInfo;
import com.cownew.PIS.framework.bizLayer.BaseDAOImpl;
import com.cownew.PIS.framework.bizLayer.CompositeEntityUtils;
import com.cownew.PIS.framework.common.IValueObject;
import com.cownew.PIS.framework.common.utils.KeyValueList;
import com.cownew.PIS.framework.server.helper.ServerSQLExecutorUtils;
import com.cownew.ctk.common.ExceptionUtils;
import com.cownew.ctk.security.MD5Utils;
public class UserDAOImpl extends BaseDAOImpl implements IUserDAO
{
public UserDAOImpl()
{
super();
}
protected void personUniCheck(UserInfo userInfo, String pk)
{
if (userInfo.getPerson() == null)
{
return;
}
StringBuffer sql = new StringBuffer();
sql.append("from ").append(UserInfo.class.getName()).append("\n");
sql.append("where person.id=:personId and id<>:id");
KeyValueList kvList = new KeyValueList();
kvList.add("personId", userInfo.getPerson().getId());
kvList.add("id", pk);
if (exists(sql.toString(), kvList))
{
throw new UserException(UserException.ONEPERSONCANONLYCORRONEUSER);
}
}
public String save(IValueObject value)
{
String pk = super.save(value);
personUniCheck((UserInfo) value, pk);
return pk;
}
public void update(IValueObject valueObject)
{
personUniCheck((UserInfo) valueObject, valueObject.getId());
CompositeEntityUtils.updateChild(this, valueObject, "permissions");
super.update(valueObject);
}
protected Class getPersistObjectClass()
{
return UserInfo.class;
}
public void changePassword(String userId, String password)
throws UserException
{
try
{
ServerSQLExecutorUtils.execute(
"update T_BS_User set FPassword=? where FId=?",
new Object[] { MD5Utils.digest(password),userId });
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
}
public void changePassword(String userId, String oldPassword,
String password) throws UserException
{
UserInfo user = loadUserByPK(userId);
if (!user.getPassword().equals(MD5Utils.digest(oldPassword)))
{
throw new UserException(UserException.OLDPASSWORDWRONG);
}
changePassword(userId, password);
}
private UserInfo loadUserByPK(String userId)
{
UserInfo user = (UserInfo) loadByPK(userId);
if (user == null)
{
throw new UserException(UserException.NOSUCHUSER);
}
return user;
}
public void freeze(String userId) throws UserException
{
try
{
ServerSQLExecutorUtils.execute(
"update T_BS_User set FIsFreezed=? where FId=?",
new Object[] { Boolean.TRUE, userId });
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
}
public boolean isFreeze(String userId) throws UserException
{
UserInfo user = loadUserByPK(userId);
return user.getIsFreezed();
}
public void unFreeze(String userId) throws UserException
{
try
{
ServerSQLExecutorUtils.execute(
"update T_BS_User set FIsFreezed=? where FId=?",
new Object[] { Boolean.FALSE, userId });
} catch (SQLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -