📄 userbo.java
字号:
package com.hisoft.cottonbusiness.service;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import com.hisoft.cottonbusiness.core.bo.BaseBO;
import com.hisoft.cottonbusiness.core.common.SqlMap;
import com.hisoft.cottonbusiness.core.exception.BusinessException;
public class UserBO extends BaseBO
{
private static final Logger log = Logger.getLogger(UserBO.class);
private static final String ENTITY_USER = "TUser";
private static final String ENTITY_ROLE = "TRole";
private static final String ENTITY_CONTACT = "TContact";
/**
* 创建用户页面的预处理
*
* @return
*/
public Map initCreateUser()
{
Map result = new HashMap();
List listRole = hpm.listAll(ENTITY_ROLE);
result.put("listRole",listRole);
return result;
}
/**
* 更新页面的预处理
*该Map比较复杂,里面又有很多项
*
*
* @param id
* @return
*/
public Map initUpdateUser(Serializable id)
{
Map result = new HashMap();
List listRole = hpm.listAll(ENTITY_ROLE);
Map user = load(id);
result.put("listRole",listRole);
result.put("user",user);
return result;
}
public boolean userExsited(String username) throws Exception
{
Thread.sleep(1000);
String sql = SqlMap.getProperty("user_checkUser");
List listUser = qm.find(sql,new Object[] {username});
log.debug("listUser: " + listUser);
if (listUser.size() >= 1)
{
return true;
}
return false;
}
public Map load(Serializable id) throws BusinessException
{
Map mapUser = hpm.loadById(ENTITY_USER,id);
if ((null == mapUser) || mapUser.isEmpty())
{
throw new BusinessException("用户[" + id + "]不存在!");
}
Map mapContact = hpm.loadById(ENTITY_CONTACT,id);
mapUser.putAll(mapContact);
Serializable roleId = (Serializable) mapUser.get("roleId");
Map mapRole = hpm.loadById(ENTITY_ROLE,roleId);
mapUser.put("role",mapRole);
return mapUser;
}
public void insert(Map map)
{
//处理插入用户表
Timestamp createdTime = new Timestamp(System.currentTimeMillis());
map.put("createdTime",createdTime);
map.put("updatedTime",createdTime);
Serializable id = hpm.save(ENTITY_USER,map);
//处理插入用户联系信息
map.put("id",id);
hpm.save(ENTITY_CONTACT,map);
}
public void update(Map map)
{
Timestamp updatedTime = new Timestamp(System.currentTimeMillis());
Serializable id = (Serializable) map.get("id");
Map mapNew = load(id);
mapNew.putAll(map);
mapNew.put("updatedTime",updatedTime);
//更新用户基本信息
hpm.update(ENTITY_USER,mapNew);
//更新联系信息
hpm.update(ENTITY_CONTACT,mapNew);
}
/**
* 分页查询所有用户列表
*
* @param begin
* @param pageSize
* @return
*/
public List listUsers(int begin,int pageSize)
{
String sql = SqlMap.getProperty("user_list");
String sql_count = SqlMap.getProperty("user_list_count");
Integer[] params = {new Integer(begin),new Integer(pageSize)};
//这是让给List页面一个序号
List listOut = qm.find(sql,params,"sequence",begin+1);
int count = qm.findCount(sql_count);
setCount(count);
return listOut;
}
public void remove(Serializable id)
{
Map mapInput = load(id);
hpm.remove(ENTITY_USER,mapInput);
hpm.remove(ENTITY_CONTACT,mapInput);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -