📄 userinfomanager.java
字号:
package com.zxx.tsh.service.impl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.zxx.common.dao.IBaseHibernateDAO;
import com.zxx.common.exception.DataAccessException;
import com.zxx.tsh.model.userinfo.dao.UserDAO;
import com.zxx.tsh.model.userinfo.pojo.UserInfo;
import com.zxx.tsh.model.userinfo.pojo.UserType;
import com.zxx.tsh.service.IUserInfoManager;
import com.zxx.tsh.view.userinfo.vo.UserInfoVO;
import com.zxx.tsh.view.userinfo.vo.UserTypeVO;
public class UserInfoManager implements IUserInfoManager {
/** 错误信息:参数接口为空 */
static final String ERRMSG_EMPTY_PARA = "参数接口为空";
private IBaseHibernateDAO basicDAO;
public IBaseHibernateDAO getBasicDAO() {
return basicDAO;
}
public void setBasicDAO(IBaseHibernateDAO baseDAO) {
this.basicDAO = baseDAO;
}
private UserDAO userDAO;
public UserDAO getUserDAO() {
return userDAO;
}
public void setUserDAO(UserDAO userDAO) {
this.userDAO = userDAO;
}
/**
* 方法描述:添加用户类型
* @param userTypeVO 用户类型VO对象
* @return 用户类型ID
* @throws DataAccessException
*/
public Serializable addUserType(UserTypeVO userTypeVO) throws DataAccessException{
if(userTypeVO==null)
throw new DataAccessException(ERRMSG_EMPTY_PARA);
UserType po = new UserType();
po.setTypeName(userTypeVO.getTypeName());
po.setTypeDescription(userTypeVO.getTypeDescription());
return this.getBasicDAO().save(po);
}
/**
* 方法描述:删除用户类型
* @param id 用户类型ID
* @return 删除是否成功的状态True或False
* @throws DataAccessException
*/
public boolean deleteUserType(Serializable id) throws DataAccessException{
if(id == null || "".equals(id))
throw new DataAccessException(ERRMSG_EMPTY_PARA);
UserType ut = (UserType) this.getBasicDAO().findById(UserType.class, id);
boolean bln = true;
if(ut!=null)
bln = this.getBasicDAO().delete(ut);
else
bln = false;
return bln;
}
/**
* 方法描述:编辑用户类型
* @param userTypeVo 用户类型Vo对象
* @return 编辑是否成功的状态True或False
* @throws DataAccessException
*/
public boolean editUserType(UserTypeVO userTypeVo) throws DataAccessException{
if(userTypeVo == null || userTypeVo.getTypeId()== null || "".equals(userTypeVo.getTypeId()))
throw new DataAccessException(ERRMSG_EMPTY_PARA);
UserType ut = (UserType) this.getBasicDAO().findById(UserType.class, userTypeVo.getTypeId());
ut.setTypeName(userTypeVo.getTypeName());
ut.setTypeDescription(userTypeVo.getTypeDescription());
return this.getBasicDAO().edit(ut);
}
/**
* 方法描述:根据类型Id获得用户类型
* @param id 用户类型ID
* @return 指定类型的对象
* @throws DataAccessException
*/
public UserTypeVO getUserTypeById(Serializable id) throws DataAccessException{
if(id == null || "".equals(id))
throw new DataAccessException(ERRMSG_EMPTY_PARA);
return this.userTypePO2VO((UserType)this.getBasicDAO().findById(UserType.class, id)) ;
}
/**
* 方法描述:用户类型的PO转VO
* @param userType
* @return 用户类型VO对象
*/
private UserTypeVO userTypePO2VO(UserType userType){
UserTypeVO _vo = null;
if(userType != null){
_vo = new UserTypeVO();
_vo.setTypeId(userType.getTypeId());
_vo.setTypeName(userType.getTypeName());
_vo.setTypeDescription(userType.getTypeDescription());
}
return _vo;
}
/**
* 方法描述:获得用户类型列表
* @return 全部类型列表
* @throws DataAccessException
*/
public List<UserTypeVO> listAllUserType() throws DataAccessException{
UserType userType = new UserType();
List list = this.getBasicDAO().findByExample(userType);
if(list==null || list.isEmpty())return null;
UserTypeVO utVo = null;
List<UserTypeVO> utList = new ArrayList<UserTypeVO>();
for(int i=0,j=list.size();i<j;i++){
UserType ut = (UserType)list.get(i);
utVo=this.userTypePO2VO(ut);
if(utVo!=null)utList.add(utVo);
}
return utList ;
}
/**
* 方法描述:根据属性名及值查找相应用户类型
* @param propertyName 属性名
* @param value 属性名对应的值
* @return 查找到的结果列表
* @throws DataAccessException
*/
public List<UserTypeVO> listUserTypeByProperty(String propertyName, Object value)
throws DataAccessException{
List list = this.getBasicDAO().findByProperty(UserType.class, propertyName, value);
if(list==null || list.isEmpty())return null;
UserTypeVO utVo = null;
List<UserTypeVO> utList = new ArrayList<UserTypeVO>();
for(int i=0,j=list.size();i<j;i++){
UserType ut = (UserType)list.get(i);
utVo=userTypePO2VO(ut);
if(utVo!=null)utList.add(utVo);
}
return utList ;
}
/**
* 方法描述:添加用户
* @param userInfoVO 用户信息VO对象
* @return 用户ID
* @throws DataAccessException
*/
public Serializable addUser(UserInfoVO userInfoVO) throws DataAccessException{
userInfo_Validate(userInfoVO);
userInfoVO.setUserCreatedDate(new Date());
UserInfo po = userInfoVO2PO(userInfoVO);
if(po!=null)
return this.getBasicDAO().save(po);
else
return "";
}
private void userInfo_Validate(UserInfoVO userInfoVO) throws DataAccessException{
if(userInfoVO==null || userInfoVO.getUserName()==null
|| "".equals(userInfoVO.getUserName())
|| userInfoVO.getUserPwd()==null
|| "".equals(userInfoVO.getUserPwd()))
throw new DataAccessException(ERRMSG_EMPTY_PARA);
}
/**
* 方法描述:用户信息对象PO转VO
* @param userInfo
* @return 用户信息VO对象
*/
private UserInfoVO userInfoPO2VO(UserInfo userInfo){
UserInfoVO _vo = null;
if(userInfo != null){
_vo = new UserInfoVO();
_vo.setUserName(userInfo.getUserName());
_vo.setUserPwd(userInfo.getUserPwd());
_vo.setUserRealName(userInfo.getUserRealName());
_vo.setUserSex(userInfo.getUserSex());
_vo.setUserType(userInfo.getUserType());
_vo.setUserCreatedDate(userInfo.getUserCreatedDate());
}
return _vo;
}
/**
* 方法描述:用户信息对象VO转PO
* @param userInfoVO
* @return 用户信息PO对象
*/
private UserInfo userInfoVO2PO(UserInfoVO userInfoVO){
UserInfo _po = null;
if(userInfoVO != null){
_po = new UserInfo();
_po.setUserName(userInfoVO.getUserName());
_po.setUserPwd(userInfoVO.getUserPwd());
_po.setUserRealName(userInfoVO.getUserRealName());
_po.setUserSex(userInfoVO.getUserSex());
_po.setUserType(userInfoVO.getUserType());
_po.setUserCreatedDate(userInfoVO.getUserCreatedDate());
}
return _po;
}
/**
* 方法描述:删除用户
* @param id 用户ID
* @return 删除是否成功的状态True或False
* @throws DataAccessException
*/
public boolean deleteUserInfo(Serializable id) throws DataAccessException{
if(id == null || "".equals(id))
throw new DataAccessException(ERRMSG_EMPTY_PARA);
UserInfo ut = (UserInfo) this.getBasicDAO().findById(UserInfo.class, id);
boolean bln = true;
if(ut!=null)
bln = this.getBasicDAO().delete(ut);
else
bln = false;
return bln;
}
/**
* 方法描述:根据用户Id获得用户信息实体
* @param id 用户ID
* @return 指定Id的用户VO对象
* @throws DataAccessException
*/
public UserInfoVO getUserInfoById(Serializable id) throws DataAccessException{
if(id == null || "".equals(id))
throw new DataAccessException(ERRMSG_EMPTY_PARA);
return this.userInfoPO2VO((UserInfo)this.getBasicDAO().findById(UserInfo.class, id)) ;
}
/**
* 方法描述:用户登录的方法
* 实现逻辑:检查用户与userName和password相匹配的记录,如果存在则允许登录,即登录成功!
* @param vo 用户信息VO对象
* @return 是否登录成功 True|False
* @throws DataAccessException
*/
public boolean getUserInfoByLogin(UserInfoVO vo) throws DataAccessException{
if( vo == null || vo.getUserName()==null || "".equals(vo.getUserName())
|| vo.getUserPwd()==null || "".equals(vo.getUserPwd()))
throw new DataAccessException(ERRMSG_EMPTY_PARA);
boolean loginResult = false;
List userInfoList = this.getBasicDAO().findByExample(userInfoVO2PO(vo));
if(userInfoList!=null && !userInfoList.isEmpty() && userInfoList.size()>0){
System.out.println("查询到的记录条数是:"+userInfoList.size());
UserInfo u = (UserInfo) userInfoList.get(0);
if(u!=null && u.getUserId()!=null && !"".equals(u.getUserId()))
loginResult=true;
}
return loginResult;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -