- 浏览: 31232 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
jieAmei:
http://hi.baidu.com/liheyuan87/ ...
function checkAll(){ -
jieAmei:
<?xml version="1.0" ...
function checkAll(){ -
jieAmei:
Severity and Description Path R ...
qqqqq -
geeksun:
很多不错的习惯都能对上号
九型人格----观察
package com.launch.yqyc.action.admin;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import com.launch.core.crypto.MD5Encoder;
import com.launch.core.util.DateUtil;
import com.launch.core.util.PagingHelper;
import com.launch.core.util.Struts2Util;
import com.launch.yqyc.Constants;
import com.launch.yqyc.action.BaseAction;
import com.launch.yqyc.common.UserCounterListener;
import com.launch.yqyc.model.AlgorithmFunc;
import com.launch.yqyc.model.DtcAlert;
import com.launch.yqyc.model.FlashFile;
import com.launch.yqyc.model.Menu;
import com.launch.yqyc.model.Role;
import com.launch.yqyc.model.SysUser;
import com.launch.yqyc.model.VehicleType;
import com.launch.yqyc.service.AlgorithmFuncManager;
import com.launch.yqyc.service.DtcAlertManager;
import com.launch.yqyc.service.FlashFileManager;
import com.launch.yqyc.service.SysUserManager;
import com.launch.yqyc.service.VehicleTypeManager;
import com.launch.yqyc.util.MenuComparator;
import com.launch.yqyc.util.YqycUtils;
import com.launch.yqyc.vo.OnLineUser;
/**
* <p>SysUserAction</p>
*
* <p>实现用户管理界面上的CRUD、登录、退出等操作</p>
*
* @author chenming
* @since 1.0
* @version $Id: SysUserAction.java 1.0 Aug 6, 2012 $
*/
public class SysUserAction extends BaseAction
{
private static final long serialVersionUID = 48L;
/**
* save(), update()..等操作执行的action redirectionUrl = LIST_ACTION
*/
public static final String LIST_ACTION = "sys_user!list.action";
/**
* 4s用户
*/
public static final String LIST_4S = "list4s";
/**
* 返回4s用户列表
*/
public static final String LIST_4S_ACTION = "sys_user!list4s.action";
/**
* 专家/4s用户远程协助
*/
public static final String VIEW_REMOTE_ASSIST = "remote_assist_view";
/**
* 技术员用户
*/
public static final String lIST_TECHNICIAN = "list_technician";
/**
* 4s用户禁用列表
*/
public static final String LIMIT_4S_ACTION = "sys_user!limit4slist.action";
/**
* 浏览4s用户禁用列表
*/
public static final String LIMIT_4S_LIST = "limit4slist";
/**
* 普通用户维护个人资料
*/
public static final String MAINTAIN_VIEW_ACTION = "sys_user!maintainview.action";
// serialNo, diskSerial, macAddr
private String serialNo;
private String diskSerial;
private String macAddr;
@Autowired
private SysUserManager sysUserManager;
@Autowired
private AlgorithmFuncManager algorithmFuncManager;
/**
* 算法功能对象
*/
private AlgorithmFunc algorithmFunc;
@Autowired
private FlashFileManager flashFileManager;
@Autowired
private DtcAlertManager dtcAlertManager;
@Autowired
private VehicleTypeManager vehicleTypeManager;
/**
* 刷写文件对象
*/
private FlashFile flashFile;
/**
* 用户名
*/
private String userName;
/**
* 用户类型
*/
private Integer userType;
/**
* 用户密码
*/
private String userPassword;
/**
* 旧用户名,用于编辑判断唯一性
*/
private String oldUserName;
/**
* 用户ID
*/
private String userId;
/**
* 获取页面上所有的记录ID
*/
private String[] pageIds;
/**
* 确认密码,用于校验两次输入密码是否一致
*/
private String reUserPassword;
/**
* 用户对象
*/
private SysUser sysUser;
/**
* 首页转来查询未审核用户记录数
*/
private int userStatus = -1;
/**
* 进入登录页面
* @return
*/
@Action(value = "go_login", interceptorRefs = { @InterceptorRef(value = "yqycCoreStack") }, results = { @Result(name = "success", location = "/WEB-INF/jsp/admin/login.jsp") })
public String goLogin()
{
return SUCCESS;
}
/**
* 登录操作
* @return
*/
@SuppressWarnings("unchecked")
@Action(value = "login", interceptorRefs = { @InterceptorRef("jCaptchaValidationIntercepter"), @InterceptorRef("logInterceptor"), @InterceptorRef(value = "yqycCoreStack") }, results = { @Result(name = "success", type = "redirect", location = "/admin/index.action") })
public String login()
{
// 根据登录用户的用户名和密码检查是否存在对应的用户对象
sysUser = sysUserManager.login(userName, userPassword);
if (sysUser == null)
{
addActionError(getText("common.userauth.error"));
return ERROR;
}
/*
* List<OnLineUser> onLineUsers = (List<OnLineUser>) Struts2Util.getServletContext().getAttribute(UserCounterListener.USERS_KEY);
if (onLineUsers.contains(onLineUser))
{
addActionError("用户["+sysUser.getUserName()+"]已经登录");
//Struts2Util.removeSession(Constants.SESSION_USER);
return ERROR;
}*/
//初始化在线用户信息;
Date loginTime = DateUtil.getCurrentDate();
OnLineUser onLineUser = new OnLineUser();
onLineUser.setId(sysUser.getId());
onLineUser.setLoginIp(YqycUtils.getRemortIP(Struts2Util.getRequest()));
onLineUser.setLoginTime(loginTime);
onLineUser.setUserName(sysUser.getUserName());
onLineUser.setUserType(sysUser.getUserType());
Struts2Util.setSession(UserCounterListener.EVENT_KEY, onLineUser);
// 保存登录用户的上次登录时间到session中
Struts2Util.setSession(Constants.SESSION_LAST_LOGIN_TIME, sysUser.getLastLoginTime());
// 保存登录用户的用户对象到session中
setSessionUser(sysUser);
// 保存登录用户的IP地址
Struts2Util.setSession(Constants.SESSION_LOGIN_IP, YqycUtils.getRemortIP(Struts2Util.getRequest()));
// 获取登录用户的菜单权限
Map<String, Menu> menuMap = new HashMap<String, Menu>();
Iterator roleIt = sysUser.getRoles().iterator();
while (roleIt.hasNext())
{
Role role = (Role) roleIt.next();
Iterator menuIt = role.getMenus().iterator();
while (menuIt.hasNext())
{
Menu menu = (Menu) menuIt.next();
menuMap.put(menu.getId(), menu);
}
}
List<Menu> menuList = new ArrayList<Menu>();
List<Entry<String, Menu>> menuEntryList = new ArrayList<Entry<String, Menu>>(menuMap.entrySet());
for (Entry<String, Menu> mEntry : menuEntryList)
{
menuList.add(mEntry.getValue());
}
// 将登录用户的菜单权限按索引排序
MenuComparator menuComparator = new MenuComparator();
Collections.sort(menuList, menuComparator);
// 保存登录用户的菜单权限List对象到session中
Struts2Util.setSession(Constants.SESSION_MENU_LIST, menuList);
// 更新登录用户的'上次登录时间'
sysUser.setLastLoginTime(loginTime);
sysUserManager.update(sysUser);
// 写入操作日志记录
operateContent = sysUser.getUserName() + "登录";
operateType = Constants.OPERATE_TYPE_LOGIN;
return SUCCESS;
}
@Action(value = "go_shop_login", interceptorRefs = { @InterceptorRef(value = "yqycCoreStack") }, results = { @Result(name = "success", location = "/WEB-INF/jsp/admin/shop_login.jsp") })
public String goShopLogin()
{
return SUCCESS;
}
/**
* 4s店登录
* @return
*/
@SuppressWarnings("unchecked")
@Action(
value = "shop_login",
interceptorRefs = {@InterceptorRef("logInterceptor"),@InterceptorRef(value = "yqycCoreStack") },
results = { @Result(name = "success", type = "redirect", location = "/admin/index.action"), @Result(name = "error", type="freemarker",location="/template/shopLoginError.ftl")}
)
public String shopLogin()
{
// 根据登录用户的用户名和密码检查是否存在对应的用户对象
sysUser = sysUserManager.getUser(serialNo, diskSerial, macAddr);
if (sysUser == null)
{
return ERROR;
}
//初始化在线用户信息;
Date loginTime = DateUtil.getCurrentDate();
OnLineUser onLineUser = new OnLineUser();
onLineUser.setId(sysUser.getId());
onLineUser.setLoginIp(YqycUtils.getRemortIP(Struts2Util.getRequest()));
onLineUser.setLoginTime(loginTime);
onLineUser.setUserName(sysUser.getRepairSite().getShopName());
onLineUser.setUserType(sysUser.getUserType());
Struts2Util.setSession(UserCounterListener.EVENT_KEY, onLineUser);
// 保存登录用户的上次登录时间到session中
Struts2Util.setSession(Constants.SESSION_LAST_LOGIN_TIME, sysUser.getLastLoginTime());
// 保存登录用户的用户对象到session中
setSessionUser(sysUser);
// 保存登录用户的IP地址
Struts2Util.setSession(Constants.SESSION_LOGIN_IP, YqycUtils.getRemortIP(Struts2Util.getRequest()));
// 获取登录用户的菜单权限
Map<String, Menu> menuMap = new HashMap<String, Menu>();
Iterator roleIt = sysUser.getRoles().iterator();
while (roleIt.hasNext())
{
Role role = (Role) roleIt.next();
Iterator menuIt = role.getMenus().iterator();
while (menuIt.hasNext())
{
Menu menu = (Menu) menuIt.next();
menuMap.put(menu.getId(), menu);
}
}
List<Menu> menuList = new ArrayList<Menu>();
List<Entry<String, Menu>> menuEntryList = new ArrayList<Entry<String, Menu>>(menuMap.entrySet());
for (Entry<String, Menu> mEntry : menuEntryList)
{
menuList.add(mEntry.getValue());
}
// 将登录用户的菜单权限按索引排序
MenuComparator menuComparator = new MenuComparator();
Collections.sort(menuList, menuComparator);
// 保存登录用户的菜单权限List对象到session中
Struts2Util.setSession(Constants.SESSION_MENU_LIST, menuList);
// 更新登录用户的'上次登录时间'
sysUser.setLastLoginTime(loginTime);
sysUserManager.update(sysUser);
// 写入操作日志记录
operateContent = sysUser.getUserName() + "登录";
operateType = Constants.OPERATE_TYPE_LOGIN;
return SUCCESS;
}
/**
* 退出
* @return
*/
@Action(value = "logout", interceptorRefs = { @InterceptorRef("logInterceptor"), @InterceptorRef(value = "yqycCoreStack") }, results = { @Result(name = "success", type = "redirect", location = "/admin/index.action") })
public String logout()
{
operateContent = Struts2Util.getSession().get(Constants.SESSION_USER_NAME) + "退出";
operateType = Constants.OPERATE_TYPE_LOGOUT;
Struts2Util.getSession().remove(Constants.SESSION_USER);
Struts2Util.getSession().remove(Constants.SESSION_USER_NAME);
Struts2Util.getSession().remove(Constants.SESSION_LOGIN_IP);
Struts2Util.getSession().remove(UserCounterListener.EVENT_KEY);
Struts2Util.getSession().remove(Constants.SESSION_MENU_LIST);
return SUCCESS;
}
/**
* 显示菜单
* @return
*/
@Action(value = "page_menu", results = { @Result(location = "/page/pagemenu.jsp") })
public String pageMenu()
{
return SUCCESS;
}
/**
* 显示首页信息 (不包括)
* @return
*/
@Action(value = "page_index", results = { @Result(location = "/page/pageindex.jsp") })
public String pageIndex()
{
SysUser sysUser = getSessionUser();
Integer userType = sysUser.getUserType();
if ((Constants.USER_TYPE_EXPERT != userType) || (Constants.USER_TYPE_SHOP == userType))
{
// 4s用户--未审核数
int unAuditedUserCount = sysUserManager.getTotalCount(Constants.USER_TYPE_SHOP, Constants.USER_STATUS_UNAUDITED);
Struts2Util.setSession(Constants.UNAUDITED_USER_COUNT, unAuditedUserCount);
// 获取未审核刷写文件目录数
FlashFile flashFile = new FlashFile();
flashFile.setStatus(Constants.FLASH_FILE_STATUS_UNAUDITED);
long unAuditedFlashFileCount = flashFileManager.getTotalCount(flashFile);
Struts2Util.setSession(Constants.UNAUDITED_FLASH_FILE_COUNT, unAuditedFlashFileCount);
//获取用户预警记录数:
DtcAlert dtcAlert = new DtcAlert();
dtcAlert.setSysUser(getSessionUser());
dtcAlert.setStatus(Constants.YES);
long userDtcAlertCount = dtcAlertManager.getTotalCount(dtcAlert);
Struts2Util.setSession(Constants.USER_DTC_ALERT_COUNT, userDtcAlertCount);
}
return SUCCESS;
}
/**
* 进入新增页面
* @return
*/
public String add()
{
return ADD;
}
/**
* 保存普通用户
* @return
*/
@Action("save_user")
public String save()
{
// 默认用户状态为'已审核'
sysUser.setStatus(Constants.USER_STATUS_APPROVED);
// 默认当前时间为'创建时间'
sysUser.setCreateTime(new Date());
if (sysUser.getUserType().intValue() == Constants.USER_TYPE_EXPERT)
{
sysUser.setVideoSystemId(sysUserManager.getVideoSystemId());
}
// MD5加密
sysUser.setUserPassword(MD5Encoder.getMD5(sysUser.getUserPassword()));
sysUserManager.save(sysUser);
operateContent = "添加用户[id=" + sysUser.getId() + "]";
operateType = Constants.OPERATE_TYPE_SAVE;
redirectionUrl = LIST_ACTION;
return SUCCESS;
}
/**
* 逻辑删除用户,但保留与这些用户相关的所有信息 该用户已不再使用,但改变用户状态为'已删除',保存该用户记录,以便日后备查
* @return
*/
public String delete()
{
sysUserManager.deleteUser(ids);
operateContent = "批量删除多个用户[ids=" + YqycUtils.arrayToSqlIn(ids) + "]";
operateType = Constants.OPERATE_TYPE_DELETE;
redirectionUrl = LIST_ACTION;
return SUCCESS;
}
/**
* 物理删除选中的4S用户
* @return
*/
public String delete4s()
{
sysUserManager.delete(ids);
operateContent = "批量删除多个4S用户[ids=" + YqycUtils.arrayToSqlIn(ids) + "]";
operateType = Constants.OPERATE_TYPE_DELETE;
redirectionUrl = LIST_4S_ACTION;
return SUCCESS;
}
/**
* 进入编辑页面
*/
public String edit()
{
sysUser = sysUserManager.get(id);
return EDIT;
}
/**
* 更新普通用户
* @return
*/
@Action("update_user")
public String update()
{
SysUser su = sysUserManager.get(id);
su.setUserName(sysUser.getUserName());
if (StringUtils.isNotBlank(sysUser.getUserPassword()))
{
su.setUserPassword(MD5Encoder.getMD5(sysUser.getUserPassword()));
}
su.setUserType(sysUser.getUserType());
su.setEmail(sysUser.getEmail());
su.setRemarks(sysUser.getRemarks());
sysUserManager.update(su);
operateContent = "更新用户[id=" + id + "]";
operateType = Constants.OPERATE_TYPE_UPDATE;
redirectionUrl = LIST_ACTION;
return SUCCESS;
}
/**
* 进入维护普通用户个人资料页面
* @return
*/
public String maintainview()
{
sysUser = (SysUser)Struts2Util.getSession(Constants.SESSION_USER);
return "maintain";
}
/**
* 维护普通用户个人资料
* @return
*/
@Action(value = "maintain_user")
public String maintain()
{
SysUser su = sysUserManager.get(sysUser.getId());
su.setUserName(sysUser.getUserName());
if (StringUtils.isNotBlank(sysUser.getUserPassword()))
{
su.setUserPassword(MD5Encoder.getMD5(sysUser.getUserPassword()));
}
su.setEmail(sysUser.getEmail());
su.setRemarks(sysUser.getRemarks());
sysUserManager.update(su);
// 保存登录用户的用户对象到session中
setSessionUser(sysUser);
redirectionUrl = "sys_user!maintainview.action";
operateContent = "维护用户个人资料[id=" + sysUser.getId() + "]";
operateType = Constants.OPERATE_TYPE_UPDATE;
return SUCCESS;
}
/**
* 验证用户名是否存在
* @return
*/
@Action(value = "check_user_name_exists", results = { @Result(name = "success", type = "json", params = { "root", RESULT }) })
public String checkUserNameExists()
{
boolean flag = sysUserManager.isExists("userName", sysUser.getUserName(), oldUserName);
Struts2Util.setObjToValueStack(RESULT, !flag);
return SUCCESS;
}
/**
* 浏览用户信息
* @return
*/
public String view()
{
if (StringUtils.isBlank(id))
{
id = ((SysUser) Struts2Util.getSession().get(Constants.SESSION_USER)).getId();
}
sysUser = sysUserManager.get(id);
return VIEW;
}
/**
* 进入4s用户审核页面
*/
public String audit()
{
sysUser = sysUserManager.get(id);
return AUDIT;
}
/**
* 审核4s用户
* @return
*/
@Action("audit_user")
public String auditUser()
{
SysUser su = sysUserManager.get(id);
// 修改审核人
su.setAuditUser((String) Struts2Util.getSession().get(Constants.SESSION_USER_NAME));
sysUserManager.auditUser(su);
operateContent = "审核4s用户[id=" + id + "]";
operateType = Constants.OPERATE_TYPE_AUDIT;
redirectionUrl = LIST_4S_ACTION;
return SUCCESS;
}
/**
* 远程协助--视频+桌面
*/
@Action("remote_assist")
public String remoteAssist()
{
return VIEW_REMOTE_ASSIST;
}
/**
* 浏览普通用户列表
*/
public String list()
{
if (sysUser == null)
{
sysUser = new SysUser();
sysUser.setUserType(Constants.USER_TYPE_COMMON);
}
setDefaultPageOrder(page, "createTime", PagingHelper.DESC);
page = sysUserManager.findPage(page, sysUser);
return LIST;
}
/**
* 浏览4s用户列表
*/
public String list4s()
{
if (sysUser == null)
{
sysUser = new SysUser();
sysUser.setUserType(Constants.USER_TYPE_SHOP);
if (userStatus != -1)
{
sysUser.setStatus(Constants.USER_STATUS_UNAUDITED);
}
}
setDefaultPageOrder(page, "createTime", PagingHelper.DESC);
page = sysUserManager.findPage(page, sysUser);
return LIST_4S;
}
/**
* 在线用户列表
* 默认按登录时间倒序
* @return
*/
@SuppressWarnings("unchecked")
public String listOnlineUser()
{
List<OnLineUser> onLineUsersx = (List<OnLineUser>)Struts2Util.getServletContext().getAttribute(UserCounterListener.USERS_KEY);
List<OnLineUser> onLineUsers = new LinkedList<OnLineUser>();
CollectionUtils.addAll(onLineUsers, onLineUsersx.iterator());
if (StringUtils.isNotBlank(userName) && userType != null)
{
for (Iterator<OnLineUser> iterator = onLineUsers.iterator(); iterator.hasNext();)
{
OnLineUser onLineUser = iterator.next();
if (!(StringUtils.equals(onLineUser.getUserName(), userName) && (onLineUser.getUserType().equals(userType))))
{
iterator.remove();
}
}
}
else if (StringUtils.isNotBlank(userName) && userType == null)
{
for (Iterator<OnLineUser> iterator = onLineUsers.iterator(); iterator.hasNext();)
{
if (!StringUtils.equals(iterator.next().getUserName(), userName))
{
iterator.remove();
}
}
}
else if (StringUtils.isBlank(userName) && userType != null)
{
for (Iterator<OnLineUser> iterator = onLineUsers.iterator(); iterator.hasNext();)
{
if (!(iterator.next().getUserType().equals(userType)))
{
iterator.remove();
}
}
}
Collections.sort(onLineUsers, new Comparator<OnLineUser>(){
@Override
public int compare(OnLineUser o1, OnLineUser o2)
{
return -(o1.getLoginTime().compareTo(o2.getLoginTime()));
}
});
page.setSize(onLineUsers.size());
int total = page.getSize();
int pageNo = page.getPageNo();
int pageSize = page.getPageSize();
int offset = (pageNo - 1) * pageSize;
int leftSize = total - pageSize*(pageNo-1);
if (page.getSize() > 0 && leftSize > pageSize )
{
onLineUsers = onLineUsers.subList(offset, offset+pageSize);
}
else if (page.getSize() > 0 && leftSize <= pageSize )
{
onLineUsers = onLineUsers.subList(offset, leftSize);
}
page.setDataList(onLineUsers);
page.setOrderBy("loginTime");
page.setOrder(PagingHelper.DESC);
return "listonlineuser";
}
/**
* 剔除用户
* @return
*/
@SuppressWarnings("unchecked")
public String evictOnlineUser()
{
ServletContext servletContext = Struts2Util.getServletContext();
HashMap<String, HttpSession> sessionMap = (HashMap<String, HttpSession>) servletContext.getAttribute(UserCounterListener.SESSIONS_KEY);
HttpSession session = sessionMap.get(id);
if (session != null)
{
session.invalidate();
}
List<OnLineUser> onLineUsersx = (List<OnLineUser>)Struts2Util.getServletContext().getAttribute(UserCounterListener.USERS_KEY);
List<OnLineUser> onLineUsers = new LinkedList<OnLineUser>();
CollectionUtils.addAll(onLineUsers, onLineUsersx.iterator());
Collections.sort(onLineUsers, new Comparator<OnLineUser>(){
@Override
public int compare(OnLineUser o1, OnLineUser o2)
{
return -(o1.getLoginTime().compareTo(o2.getLoginTime()));
}
});
page.setSize(onLineUsers.size());
int total = page.getSize();
int pageNo = page.getPageNo();
int pageSize = page.getPageSize();
int offset = (pageNo - 1) * pageSize;
int leftSize = total - pageSize*(pageNo-1);
if (page.getSize() > 0 && leftSize > pageSize )
{
onLineUsers = onLineUsers.subList(offset, offset+pageSize);
}
else if (page.getSize() > 0 && leftSize <= pageSize )
{
onLineUsers = onLineUsers.subList(offset, leftSize);
}
page.setDataList(onLineUsers);
redirectionUrl = "sys_user!listOnlineUser.action";
return SUCCESS;
}
/**
* 浏览技术员列表
*/
public String listTechnician()
{
System.out.println("SysUserAction.listTechnician()"+sysUser);
if (sysUser == null)
{
sysUser = new SysUser();
sysUser.setUserType(Constants.USER_TYPE_TECHNICIAN);
sysUser.setStatus(Constants.USER_STATUS_APPROVED);
}
setDefaultPageOrder(page, "createTime", PagingHelper.DESC);
page = sysUserManager.findPage(page, sysUser);
return lIST_TECHNICIAN;
}
/**
* 浏览4s用户禁用列表
*/
public String limit4slist()
{
System.out.println("SysUserAction.limit4slist()"+sysUser);
if (sysUser == null)
{
sysUser = new SysUser();
sysUser.setUserType(Constants.USER_TYPE_SHOP);
sysUser.setStatus(Constants.USER_STATUS_APPROVED);
}
setDefaultPageOrder(page, "createTime", PagingHelper.DESC);
page = sysUserManager.findPage(page, sysUser);
return LIMIT_4S_LIST;
}
/**
* 禁用刷写文件
*/
@Action(value = "update_limit_flash_file")
public String updateLimitFlashFile()
{
try
{
// 保存选择的算法到关联表中
SysUser sysUser = sysUserManager.get(userId);
Set<FlashFile> flashFiles = sysUser.getFlashFiles();
Collection<String> checkedIds = new ArrayList<String>();
CollectionUtils.addAll(checkedIds, ids);
Collection<String> aPageIds = new ArrayList<String>();
CollectionUtils.addAll(aPageIds, pageIds);
YqycUtils.mergeByCheckedIds(flashFiles, checkedIds, aPageIds, FlashFile.class);
sysUser.setFlashFiles(flashFiles);
sysUserManager.update(sysUser);
operateContent = "禁用刷写文件[id=" + StringUtils.join(aPageIds, ",") + "]";
operateType = Constants.OPERATE_TYPE_UPDATE;
}
catch (Exception e)
{
addActionError("操作失败");
return ERROR;
}
redirectionUrl = LIMIT_4S_ACTION;
return SUCCESS;
}
/**
* 刷写文件权限禁用
*/
public String limitFlashFile()
{
// 获取用户算法禁用列表
SysUser sysUser = sysUserManager.get(userId);
List<String> selectIds = new ArrayList<String>();
Set<FlashFile> flashFiles = sysUser.getFlashFiles();
if (CollectionUtils.isNotEmpty(flashFiles))
{
for (FlashFile flashFile : flashFiles)
{
selectIds.add(flashFile.getId());
}
}
List<VehicleType> vehicleTypes = vehicleTypeManager.getAll();
Struts2Util.setObjToValueStack("vehicleTypes", vehicleTypes);
Struts2Util.setObjToValueStack("selectIds", StringUtils.join(selectIds, ","));
flashFileManager.findPage(page, flashFile);
return "limitflashfile";
}
/**
* 禁用算法
*/
@Action(value = "update_limit_algorithm_func")
public String updateLiminAlgorithmFunc()
{
try
{
// 保存选择的算法到关联表中
SysUser sysUser = sysUserManager.get(userId);
Set<AlgorithmFunc> algorithmFuncs = sysUser.getAlgorithmFuncs();
Collection<String> checkedIds = new ArrayList<String>();
CollectionUtils.addAll(checkedIds, ids);
Collection<String> aPageIds = new ArrayList<String>();
CollectionUtils.addAll(aPageIds, pageIds);
YqycUtils.mergeByCheckedIds(algorithmFuncs, checkedIds, aPageIds, AlgorithmFunc.class);
sysUser.setAlgorithmFuncs(algorithmFuncs);
sysUserManager.update(sysUser);
operateContent = "禁用算法[id=" + StringUtils.join(aPageIds, ",") + "]";
operateType = Constants.OPERATE_TYPE_UPDATE;
}
catch (Exception e)
{
addActionError("操作失败");
return ERROR;
}
redirectionUrl = LIMIT_4S_ACTION;
return SUCCESS;
}
/**
* 算法权限禁用
*/
public String limitAlgorithmFunc()
{
// 获取用户算法禁用列表
SysUser sysUser = sysUserManager.get(userId);
List<String> selectIds = new ArrayList<String>();
Set<AlgorithmFunc> algorithmFuncs = sysUser.getAlgorithmFuncs();
if (CollectionUtils.isNotEmpty(algorithmFuncs))
{
for (AlgorithmFunc alg : algorithmFuncs)
{
selectIds.add(alg.getId());
}
}
Struts2Util.setObjToValueStack("selectIds", StringUtils.join(selectIds, ","));
setDefaultPageOrder(page, "functionName", PagingHelper.ASC);
algorithmFuncManager.findPage(page, algorithmFunc);
return "limitalgorithmfunc";
}
public SysUser getSysUser()
{
return sysUser;
}
public void setSysUser(SysUser sysUser)
{
this.sysUser = sysUser;
}
public String getReUserPassword()
{
return reUserPassword;
}
public void setReUserPassword(String reUserPassword)
{
this.reUserPassword = reUserPassword;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getOldUserName()
{
return oldUserName;
}
public void setOldUserName(String oldUserName)
{
this.oldUserName = oldUserName;
}
public String getUserPassword()
{
return userPassword;
}
public void setUserPassword(String userPassword)
{
this.userPassword = userPassword;
}
public String getUserId()
{
return userId;
}
public void setUserId(String userId)
{
this.userId = userId;
}
public String[] getPageIds()
{
return pageIds;
}
public void setPageIds(String[] pageIds)
{
this.pageIds = pageIds;
}
public AlgorithmFunc getAlgorithmFunc()
{
return algorithmFunc;
}
public void setAlgorithmFunc(AlgorithmFunc algorithmFunc)
{
this.algorithmFunc = algorithmFunc;
}
public FlashFile getFlashFile()
{
return flashFile;
}
public void setFlashFile(FlashFile flashFile)
{
this.flashFile = flashFile;
}
public int getUserStatus()
{
return userStatus;
}
public void setUserStatus(int userStatus)
{
this.userStatus = userStatus;
}
public Integer getUserType()
{
return userType;
}
public void setUserType(Integer userType)
{
this.userType = userType;
}
public String getSerialNo()
{
return serialNo;
}
public void setSerialNo(String serialNo)
{
this.serialNo = serialNo;
}
public String getDiskSerial()
{
return diskSerial;
}
public void setDiskSerial(String diskSerial)
{
this.diskSerial = diskSerial;
}
public String getMacAddr()
{
return macAddr;
}
public void setMacAddr(String macAddr)
{
this.macAddr = macAddr;
}
}
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import com.launch.core.crypto.MD5Encoder;
import com.launch.core.util.DateUtil;
import com.launch.core.util.PagingHelper;
import com.launch.core.util.Struts2Util;
import com.launch.yqyc.Constants;
import com.launch.yqyc.action.BaseAction;
import com.launch.yqyc.common.UserCounterListener;
import com.launch.yqyc.model.AlgorithmFunc;
import com.launch.yqyc.model.DtcAlert;
import com.launch.yqyc.model.FlashFile;
import com.launch.yqyc.model.Menu;
import com.launch.yqyc.model.Role;
import com.launch.yqyc.model.SysUser;
import com.launch.yqyc.model.VehicleType;
import com.launch.yqyc.service.AlgorithmFuncManager;
import com.launch.yqyc.service.DtcAlertManager;
import com.launch.yqyc.service.FlashFileManager;
import com.launch.yqyc.service.SysUserManager;
import com.launch.yqyc.service.VehicleTypeManager;
import com.launch.yqyc.util.MenuComparator;
import com.launch.yqyc.util.YqycUtils;
import com.launch.yqyc.vo.OnLineUser;
/**
* <p>SysUserAction</p>
*
* <p>实现用户管理界面上的CRUD、登录、退出等操作</p>
*
* @author chenming
* @since 1.0
* @version $Id: SysUserAction.java 1.0 Aug 6, 2012 $
*/
public class SysUserAction extends BaseAction
{
private static final long serialVersionUID = 48L;
/**
* save(), update()..等操作执行的action redirectionUrl = LIST_ACTION
*/
public static final String LIST_ACTION = "sys_user!list.action";
/**
* 4s用户
*/
public static final String LIST_4S = "list4s";
/**
* 返回4s用户列表
*/
public static final String LIST_4S_ACTION = "sys_user!list4s.action";
/**
* 专家/4s用户远程协助
*/
public static final String VIEW_REMOTE_ASSIST = "remote_assist_view";
/**
* 技术员用户
*/
public static final String lIST_TECHNICIAN = "list_technician";
/**
* 4s用户禁用列表
*/
public static final String LIMIT_4S_ACTION = "sys_user!limit4slist.action";
/**
* 浏览4s用户禁用列表
*/
public static final String LIMIT_4S_LIST = "limit4slist";
/**
* 普通用户维护个人资料
*/
public static final String MAINTAIN_VIEW_ACTION = "sys_user!maintainview.action";
// serialNo, diskSerial, macAddr
private String serialNo;
private String diskSerial;
private String macAddr;
@Autowired
private SysUserManager sysUserManager;
@Autowired
private AlgorithmFuncManager algorithmFuncManager;
/**
* 算法功能对象
*/
private AlgorithmFunc algorithmFunc;
@Autowired
private FlashFileManager flashFileManager;
@Autowired
private DtcAlertManager dtcAlertManager;
@Autowired
private VehicleTypeManager vehicleTypeManager;
/**
* 刷写文件对象
*/
private FlashFile flashFile;
/**
* 用户名
*/
private String userName;
/**
* 用户类型
*/
private Integer userType;
/**
* 用户密码
*/
private String userPassword;
/**
* 旧用户名,用于编辑判断唯一性
*/
private String oldUserName;
/**
* 用户ID
*/
private String userId;
/**
* 获取页面上所有的记录ID
*/
private String[] pageIds;
/**
* 确认密码,用于校验两次输入密码是否一致
*/
private String reUserPassword;
/**
* 用户对象
*/
private SysUser sysUser;
/**
* 首页转来查询未审核用户记录数
*/
private int userStatus = -1;
/**
* 进入登录页面
* @return
*/
@Action(value = "go_login", interceptorRefs = { @InterceptorRef(value = "yqycCoreStack") }, results = { @Result(name = "success", location = "/WEB-INF/jsp/admin/login.jsp") })
public String goLogin()
{
return SUCCESS;
}
/**
* 登录操作
* @return
*/
@SuppressWarnings("unchecked")
@Action(value = "login", interceptorRefs = { @InterceptorRef("jCaptchaValidationIntercepter"), @InterceptorRef("logInterceptor"), @InterceptorRef(value = "yqycCoreStack") }, results = { @Result(name = "success", type = "redirect", location = "/admin/index.action") })
public String login()
{
// 根据登录用户的用户名和密码检查是否存在对应的用户对象
sysUser = sysUserManager.login(userName, userPassword);
if (sysUser == null)
{
addActionError(getText("common.userauth.error"));
return ERROR;
}
/*
* List<OnLineUser> onLineUsers = (List<OnLineUser>) Struts2Util.getServletContext().getAttribute(UserCounterListener.USERS_KEY);
if (onLineUsers.contains(onLineUser))
{
addActionError("用户["+sysUser.getUserName()+"]已经登录");
//Struts2Util.removeSession(Constants.SESSION_USER);
return ERROR;
}*/
//初始化在线用户信息;
Date loginTime = DateUtil.getCurrentDate();
OnLineUser onLineUser = new OnLineUser();
onLineUser.setId(sysUser.getId());
onLineUser.setLoginIp(YqycUtils.getRemortIP(Struts2Util.getRequest()));
onLineUser.setLoginTime(loginTime);
onLineUser.setUserName(sysUser.getUserName());
onLineUser.setUserType(sysUser.getUserType());
Struts2Util.setSession(UserCounterListener.EVENT_KEY, onLineUser);
// 保存登录用户的上次登录时间到session中
Struts2Util.setSession(Constants.SESSION_LAST_LOGIN_TIME, sysUser.getLastLoginTime());
// 保存登录用户的用户对象到session中
setSessionUser(sysUser);
// 保存登录用户的IP地址
Struts2Util.setSession(Constants.SESSION_LOGIN_IP, YqycUtils.getRemortIP(Struts2Util.getRequest()));
// 获取登录用户的菜单权限
Map<String, Menu> menuMap = new HashMap<String, Menu>();
Iterator roleIt = sysUser.getRoles().iterator();
while (roleIt.hasNext())
{
Role role = (Role) roleIt.next();
Iterator menuIt = role.getMenus().iterator();
while (menuIt.hasNext())
{
Menu menu = (Menu) menuIt.next();
menuMap.put(menu.getId(), menu);
}
}
List<Menu> menuList = new ArrayList<Menu>();
List<Entry<String, Menu>> menuEntryList = new ArrayList<Entry<String, Menu>>(menuMap.entrySet());
for (Entry<String, Menu> mEntry : menuEntryList)
{
menuList.add(mEntry.getValue());
}
// 将登录用户的菜单权限按索引排序
MenuComparator menuComparator = new MenuComparator();
Collections.sort(menuList, menuComparator);
// 保存登录用户的菜单权限List对象到session中
Struts2Util.setSession(Constants.SESSION_MENU_LIST, menuList);
// 更新登录用户的'上次登录时间'
sysUser.setLastLoginTime(loginTime);
sysUserManager.update(sysUser);
// 写入操作日志记录
operateContent = sysUser.getUserName() + "登录";
operateType = Constants.OPERATE_TYPE_LOGIN;
return SUCCESS;
}
@Action(value = "go_shop_login", interceptorRefs = { @InterceptorRef(value = "yqycCoreStack") }, results = { @Result(name = "success", location = "/WEB-INF/jsp/admin/shop_login.jsp") })
public String goShopLogin()
{
return SUCCESS;
}
/**
* 4s店登录
* @return
*/
@SuppressWarnings("unchecked")
@Action(
value = "shop_login",
interceptorRefs = {@InterceptorRef("logInterceptor"),@InterceptorRef(value = "yqycCoreStack") },
results = { @Result(name = "success", type = "redirect", location = "/admin/index.action"), @Result(name = "error", type="freemarker",location="/template/shopLoginError.ftl")}
)
public String shopLogin()
{
// 根据登录用户的用户名和密码检查是否存在对应的用户对象
sysUser = sysUserManager.getUser(serialNo, diskSerial, macAddr);
if (sysUser == null)
{
return ERROR;
}
//初始化在线用户信息;
Date loginTime = DateUtil.getCurrentDate();
OnLineUser onLineUser = new OnLineUser();
onLineUser.setId(sysUser.getId());
onLineUser.setLoginIp(YqycUtils.getRemortIP(Struts2Util.getRequest()));
onLineUser.setLoginTime(loginTime);
onLineUser.setUserName(sysUser.getRepairSite().getShopName());
onLineUser.setUserType(sysUser.getUserType());
Struts2Util.setSession(UserCounterListener.EVENT_KEY, onLineUser);
// 保存登录用户的上次登录时间到session中
Struts2Util.setSession(Constants.SESSION_LAST_LOGIN_TIME, sysUser.getLastLoginTime());
// 保存登录用户的用户对象到session中
setSessionUser(sysUser);
// 保存登录用户的IP地址
Struts2Util.setSession(Constants.SESSION_LOGIN_IP, YqycUtils.getRemortIP(Struts2Util.getRequest()));
// 获取登录用户的菜单权限
Map<String, Menu> menuMap = new HashMap<String, Menu>();
Iterator roleIt = sysUser.getRoles().iterator();
while (roleIt.hasNext())
{
Role role = (Role) roleIt.next();
Iterator menuIt = role.getMenus().iterator();
while (menuIt.hasNext())
{
Menu menu = (Menu) menuIt.next();
menuMap.put(menu.getId(), menu);
}
}
List<Menu> menuList = new ArrayList<Menu>();
List<Entry<String, Menu>> menuEntryList = new ArrayList<Entry<String, Menu>>(menuMap.entrySet());
for (Entry<String, Menu> mEntry : menuEntryList)
{
menuList.add(mEntry.getValue());
}
// 将登录用户的菜单权限按索引排序
MenuComparator menuComparator = new MenuComparator();
Collections.sort(menuList, menuComparator);
// 保存登录用户的菜单权限List对象到session中
Struts2Util.setSession(Constants.SESSION_MENU_LIST, menuList);
// 更新登录用户的'上次登录时间'
sysUser.setLastLoginTime(loginTime);
sysUserManager.update(sysUser);
// 写入操作日志记录
operateContent = sysUser.getUserName() + "登录";
operateType = Constants.OPERATE_TYPE_LOGIN;
return SUCCESS;
}
/**
* 退出
* @return
*/
@Action(value = "logout", interceptorRefs = { @InterceptorRef("logInterceptor"), @InterceptorRef(value = "yqycCoreStack") }, results = { @Result(name = "success", type = "redirect", location = "/admin/index.action") })
public String logout()
{
operateContent = Struts2Util.getSession().get(Constants.SESSION_USER_NAME) + "退出";
operateType = Constants.OPERATE_TYPE_LOGOUT;
Struts2Util.getSession().remove(Constants.SESSION_USER);
Struts2Util.getSession().remove(Constants.SESSION_USER_NAME);
Struts2Util.getSession().remove(Constants.SESSION_LOGIN_IP);
Struts2Util.getSession().remove(UserCounterListener.EVENT_KEY);
Struts2Util.getSession().remove(Constants.SESSION_MENU_LIST);
return SUCCESS;
}
/**
* 显示菜单
* @return
*/
@Action(value = "page_menu", results = { @Result(location = "/page/pagemenu.jsp") })
public String pageMenu()
{
return SUCCESS;
}
/**
* 显示首页信息 (不包括)
* @return
*/
@Action(value = "page_index", results = { @Result(location = "/page/pageindex.jsp") })
public String pageIndex()
{
SysUser sysUser = getSessionUser();
Integer userType = sysUser.getUserType();
if ((Constants.USER_TYPE_EXPERT != userType) || (Constants.USER_TYPE_SHOP == userType))
{
// 4s用户--未审核数
int unAuditedUserCount = sysUserManager.getTotalCount(Constants.USER_TYPE_SHOP, Constants.USER_STATUS_UNAUDITED);
Struts2Util.setSession(Constants.UNAUDITED_USER_COUNT, unAuditedUserCount);
// 获取未审核刷写文件目录数
FlashFile flashFile = new FlashFile();
flashFile.setStatus(Constants.FLASH_FILE_STATUS_UNAUDITED);
long unAuditedFlashFileCount = flashFileManager.getTotalCount(flashFile);
Struts2Util.setSession(Constants.UNAUDITED_FLASH_FILE_COUNT, unAuditedFlashFileCount);
//获取用户预警记录数:
DtcAlert dtcAlert = new DtcAlert();
dtcAlert.setSysUser(getSessionUser());
dtcAlert.setStatus(Constants.YES);
long userDtcAlertCount = dtcAlertManager.getTotalCount(dtcAlert);
Struts2Util.setSession(Constants.USER_DTC_ALERT_COUNT, userDtcAlertCount);
}
return SUCCESS;
}
/**
* 进入新增页面
* @return
*/
public String add()
{
return ADD;
}
/**
* 保存普通用户
* @return
*/
@Action("save_user")
public String save()
{
// 默认用户状态为'已审核'
sysUser.setStatus(Constants.USER_STATUS_APPROVED);
// 默认当前时间为'创建时间'
sysUser.setCreateTime(new Date());
if (sysUser.getUserType().intValue() == Constants.USER_TYPE_EXPERT)
{
sysUser.setVideoSystemId(sysUserManager.getVideoSystemId());
}
// MD5加密
sysUser.setUserPassword(MD5Encoder.getMD5(sysUser.getUserPassword()));
sysUserManager.save(sysUser);
operateContent = "添加用户[id=" + sysUser.getId() + "]";
operateType = Constants.OPERATE_TYPE_SAVE;
redirectionUrl = LIST_ACTION;
return SUCCESS;
}
/**
* 逻辑删除用户,但保留与这些用户相关的所有信息 该用户已不再使用,但改变用户状态为'已删除',保存该用户记录,以便日后备查
* @return
*/
public String delete()
{
sysUserManager.deleteUser(ids);
operateContent = "批量删除多个用户[ids=" + YqycUtils.arrayToSqlIn(ids) + "]";
operateType = Constants.OPERATE_TYPE_DELETE;
redirectionUrl = LIST_ACTION;
return SUCCESS;
}
/**
* 物理删除选中的4S用户
* @return
*/
public String delete4s()
{
sysUserManager.delete(ids);
operateContent = "批量删除多个4S用户[ids=" + YqycUtils.arrayToSqlIn(ids) + "]";
operateType = Constants.OPERATE_TYPE_DELETE;
redirectionUrl = LIST_4S_ACTION;
return SUCCESS;
}
/**
* 进入编辑页面
*/
public String edit()
{
sysUser = sysUserManager.get(id);
return EDIT;
}
/**
* 更新普通用户
* @return
*/
@Action("update_user")
public String update()
{
SysUser su = sysUserManager.get(id);
su.setUserName(sysUser.getUserName());
if (StringUtils.isNotBlank(sysUser.getUserPassword()))
{
su.setUserPassword(MD5Encoder.getMD5(sysUser.getUserPassword()));
}
su.setUserType(sysUser.getUserType());
su.setEmail(sysUser.getEmail());
su.setRemarks(sysUser.getRemarks());
sysUserManager.update(su);
operateContent = "更新用户[id=" + id + "]";
operateType = Constants.OPERATE_TYPE_UPDATE;
redirectionUrl = LIST_ACTION;
return SUCCESS;
}
/**
* 进入维护普通用户个人资料页面
* @return
*/
public String maintainview()
{
sysUser = (SysUser)Struts2Util.getSession(Constants.SESSION_USER);
return "maintain";
}
/**
* 维护普通用户个人资料
* @return
*/
@Action(value = "maintain_user")
public String maintain()
{
SysUser su = sysUserManager.get(sysUser.getId());
su.setUserName(sysUser.getUserName());
if (StringUtils.isNotBlank(sysUser.getUserPassword()))
{
su.setUserPassword(MD5Encoder.getMD5(sysUser.getUserPassword()));
}
su.setEmail(sysUser.getEmail());
su.setRemarks(sysUser.getRemarks());
sysUserManager.update(su);
// 保存登录用户的用户对象到session中
setSessionUser(sysUser);
redirectionUrl = "sys_user!maintainview.action";
operateContent = "维护用户个人资料[id=" + sysUser.getId() + "]";
operateType = Constants.OPERATE_TYPE_UPDATE;
return SUCCESS;
}
/**
* 验证用户名是否存在
* @return
*/
@Action(value = "check_user_name_exists", results = { @Result(name = "success", type = "json", params = { "root", RESULT }) })
public String checkUserNameExists()
{
boolean flag = sysUserManager.isExists("userName", sysUser.getUserName(), oldUserName);
Struts2Util.setObjToValueStack(RESULT, !flag);
return SUCCESS;
}
/**
* 浏览用户信息
* @return
*/
public String view()
{
if (StringUtils.isBlank(id))
{
id = ((SysUser) Struts2Util.getSession().get(Constants.SESSION_USER)).getId();
}
sysUser = sysUserManager.get(id);
return VIEW;
}
/**
* 进入4s用户审核页面
*/
public String audit()
{
sysUser = sysUserManager.get(id);
return AUDIT;
}
/**
* 审核4s用户
* @return
*/
@Action("audit_user")
public String auditUser()
{
SysUser su = sysUserManager.get(id);
// 修改审核人
su.setAuditUser((String) Struts2Util.getSession().get(Constants.SESSION_USER_NAME));
sysUserManager.auditUser(su);
operateContent = "审核4s用户[id=" + id + "]";
operateType = Constants.OPERATE_TYPE_AUDIT;
redirectionUrl = LIST_4S_ACTION;
return SUCCESS;
}
/**
* 远程协助--视频+桌面
*/
@Action("remote_assist")
public String remoteAssist()
{
return VIEW_REMOTE_ASSIST;
}
/**
* 浏览普通用户列表
*/
public String list()
{
if (sysUser == null)
{
sysUser = new SysUser();
sysUser.setUserType(Constants.USER_TYPE_COMMON);
}
setDefaultPageOrder(page, "createTime", PagingHelper.DESC);
page = sysUserManager.findPage(page, sysUser);
return LIST;
}
/**
* 浏览4s用户列表
*/
public String list4s()
{
if (sysUser == null)
{
sysUser = new SysUser();
sysUser.setUserType(Constants.USER_TYPE_SHOP);
if (userStatus != -1)
{
sysUser.setStatus(Constants.USER_STATUS_UNAUDITED);
}
}
setDefaultPageOrder(page, "createTime", PagingHelper.DESC);
page = sysUserManager.findPage(page, sysUser);
return LIST_4S;
}
/**
* 在线用户列表
* 默认按登录时间倒序
* @return
*/
@SuppressWarnings("unchecked")
public String listOnlineUser()
{
List<OnLineUser> onLineUsersx = (List<OnLineUser>)Struts2Util.getServletContext().getAttribute(UserCounterListener.USERS_KEY);
List<OnLineUser> onLineUsers = new LinkedList<OnLineUser>();
CollectionUtils.addAll(onLineUsers, onLineUsersx.iterator());
if (StringUtils.isNotBlank(userName) && userType != null)
{
for (Iterator<OnLineUser> iterator = onLineUsers.iterator(); iterator.hasNext();)
{
OnLineUser onLineUser = iterator.next();
if (!(StringUtils.equals(onLineUser.getUserName(), userName) && (onLineUser.getUserType().equals(userType))))
{
iterator.remove();
}
}
}
else if (StringUtils.isNotBlank(userName) && userType == null)
{
for (Iterator<OnLineUser> iterator = onLineUsers.iterator(); iterator.hasNext();)
{
if (!StringUtils.equals(iterator.next().getUserName(), userName))
{
iterator.remove();
}
}
}
else if (StringUtils.isBlank(userName) && userType != null)
{
for (Iterator<OnLineUser> iterator = onLineUsers.iterator(); iterator.hasNext();)
{
if (!(iterator.next().getUserType().equals(userType)))
{
iterator.remove();
}
}
}
Collections.sort(onLineUsers, new Comparator<OnLineUser>(){
@Override
public int compare(OnLineUser o1, OnLineUser o2)
{
return -(o1.getLoginTime().compareTo(o2.getLoginTime()));
}
});
page.setSize(onLineUsers.size());
int total = page.getSize();
int pageNo = page.getPageNo();
int pageSize = page.getPageSize();
int offset = (pageNo - 1) * pageSize;
int leftSize = total - pageSize*(pageNo-1);
if (page.getSize() > 0 && leftSize > pageSize )
{
onLineUsers = onLineUsers.subList(offset, offset+pageSize);
}
else if (page.getSize() > 0 && leftSize <= pageSize )
{
onLineUsers = onLineUsers.subList(offset, leftSize);
}
page.setDataList(onLineUsers);
page.setOrderBy("loginTime");
page.setOrder(PagingHelper.DESC);
return "listonlineuser";
}
/**
* 剔除用户
* @return
*/
@SuppressWarnings("unchecked")
public String evictOnlineUser()
{
ServletContext servletContext = Struts2Util.getServletContext();
HashMap<String, HttpSession> sessionMap = (HashMap<String, HttpSession>) servletContext.getAttribute(UserCounterListener.SESSIONS_KEY);
HttpSession session = sessionMap.get(id);
if (session != null)
{
session.invalidate();
}
List<OnLineUser> onLineUsersx = (List<OnLineUser>)Struts2Util.getServletContext().getAttribute(UserCounterListener.USERS_KEY);
List<OnLineUser> onLineUsers = new LinkedList<OnLineUser>();
CollectionUtils.addAll(onLineUsers, onLineUsersx.iterator());
Collections.sort(onLineUsers, new Comparator<OnLineUser>(){
@Override
public int compare(OnLineUser o1, OnLineUser o2)
{
return -(o1.getLoginTime().compareTo(o2.getLoginTime()));
}
});
page.setSize(onLineUsers.size());
int total = page.getSize();
int pageNo = page.getPageNo();
int pageSize = page.getPageSize();
int offset = (pageNo - 1) * pageSize;
int leftSize = total - pageSize*(pageNo-1);
if (page.getSize() > 0 && leftSize > pageSize )
{
onLineUsers = onLineUsers.subList(offset, offset+pageSize);
}
else if (page.getSize() > 0 && leftSize <= pageSize )
{
onLineUsers = onLineUsers.subList(offset, leftSize);
}
page.setDataList(onLineUsers);
redirectionUrl = "sys_user!listOnlineUser.action";
return SUCCESS;
}
/**
* 浏览技术员列表
*/
public String listTechnician()
{
System.out.println("SysUserAction.listTechnician()"+sysUser);
if (sysUser == null)
{
sysUser = new SysUser();
sysUser.setUserType(Constants.USER_TYPE_TECHNICIAN);
sysUser.setStatus(Constants.USER_STATUS_APPROVED);
}
setDefaultPageOrder(page, "createTime", PagingHelper.DESC);
page = sysUserManager.findPage(page, sysUser);
return lIST_TECHNICIAN;
}
/**
* 浏览4s用户禁用列表
*/
public String limit4slist()
{
System.out.println("SysUserAction.limit4slist()"+sysUser);
if (sysUser == null)
{
sysUser = new SysUser();
sysUser.setUserType(Constants.USER_TYPE_SHOP);
sysUser.setStatus(Constants.USER_STATUS_APPROVED);
}
setDefaultPageOrder(page, "createTime", PagingHelper.DESC);
page = sysUserManager.findPage(page, sysUser);
return LIMIT_4S_LIST;
}
/**
* 禁用刷写文件
*/
@Action(value = "update_limit_flash_file")
public String updateLimitFlashFile()
{
try
{
// 保存选择的算法到关联表中
SysUser sysUser = sysUserManager.get(userId);
Set<FlashFile> flashFiles = sysUser.getFlashFiles();
Collection<String> checkedIds = new ArrayList<String>();
CollectionUtils.addAll(checkedIds, ids);
Collection<String> aPageIds = new ArrayList<String>();
CollectionUtils.addAll(aPageIds, pageIds);
YqycUtils.mergeByCheckedIds(flashFiles, checkedIds, aPageIds, FlashFile.class);
sysUser.setFlashFiles(flashFiles);
sysUserManager.update(sysUser);
operateContent = "禁用刷写文件[id=" + StringUtils.join(aPageIds, ",") + "]";
operateType = Constants.OPERATE_TYPE_UPDATE;
}
catch (Exception e)
{
addActionError("操作失败");
return ERROR;
}
redirectionUrl = LIMIT_4S_ACTION;
return SUCCESS;
}
/**
* 刷写文件权限禁用
*/
public String limitFlashFile()
{
// 获取用户算法禁用列表
SysUser sysUser = sysUserManager.get(userId);
List<String> selectIds = new ArrayList<String>();
Set<FlashFile> flashFiles = sysUser.getFlashFiles();
if (CollectionUtils.isNotEmpty(flashFiles))
{
for (FlashFile flashFile : flashFiles)
{
selectIds.add(flashFile.getId());
}
}
List<VehicleType> vehicleTypes = vehicleTypeManager.getAll();
Struts2Util.setObjToValueStack("vehicleTypes", vehicleTypes);
Struts2Util.setObjToValueStack("selectIds", StringUtils.join(selectIds, ","));
flashFileManager.findPage(page, flashFile);
return "limitflashfile";
}
/**
* 禁用算法
*/
@Action(value = "update_limit_algorithm_func")
public String updateLiminAlgorithmFunc()
{
try
{
// 保存选择的算法到关联表中
SysUser sysUser = sysUserManager.get(userId);
Set<AlgorithmFunc> algorithmFuncs = sysUser.getAlgorithmFuncs();
Collection<String> checkedIds = new ArrayList<String>();
CollectionUtils.addAll(checkedIds, ids);
Collection<String> aPageIds = new ArrayList<String>();
CollectionUtils.addAll(aPageIds, pageIds);
YqycUtils.mergeByCheckedIds(algorithmFuncs, checkedIds, aPageIds, AlgorithmFunc.class);
sysUser.setAlgorithmFuncs(algorithmFuncs);
sysUserManager.update(sysUser);
operateContent = "禁用算法[id=" + StringUtils.join(aPageIds, ",") + "]";
operateType = Constants.OPERATE_TYPE_UPDATE;
}
catch (Exception e)
{
addActionError("操作失败");
return ERROR;
}
redirectionUrl = LIMIT_4S_ACTION;
return SUCCESS;
}
/**
* 算法权限禁用
*/
public String limitAlgorithmFunc()
{
// 获取用户算法禁用列表
SysUser sysUser = sysUserManager.get(userId);
List<String> selectIds = new ArrayList<String>();
Set<AlgorithmFunc> algorithmFuncs = sysUser.getAlgorithmFuncs();
if (CollectionUtils.isNotEmpty(algorithmFuncs))
{
for (AlgorithmFunc alg : algorithmFuncs)
{
selectIds.add(alg.getId());
}
}
Struts2Util.setObjToValueStack("selectIds", StringUtils.join(selectIds, ","));
setDefaultPageOrder(page, "functionName", PagingHelper.ASC);
algorithmFuncManager.findPage(page, algorithmFunc);
return "limitalgorithmfunc";
}
public SysUser getSysUser()
{
return sysUser;
}
public void setSysUser(SysUser sysUser)
{
this.sysUser = sysUser;
}
public String getReUserPassword()
{
return reUserPassword;
}
public void setReUserPassword(String reUserPassword)
{
this.reUserPassword = reUserPassword;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getOldUserName()
{
return oldUserName;
}
public void setOldUserName(String oldUserName)
{
this.oldUserName = oldUserName;
}
public String getUserPassword()
{
return userPassword;
}
public void setUserPassword(String userPassword)
{
this.userPassword = userPassword;
}
public String getUserId()
{
return userId;
}
public void setUserId(String userId)
{
this.userId = userId;
}
public String[] getPageIds()
{
return pageIds;
}
public void setPageIds(String[] pageIds)
{
this.pageIds = pageIds;
}
public AlgorithmFunc getAlgorithmFunc()
{
return algorithmFunc;
}
public void setAlgorithmFunc(AlgorithmFunc algorithmFunc)
{
this.algorithmFunc = algorithmFunc;
}
public FlashFile getFlashFile()
{
return flashFile;
}
public void setFlashFile(FlashFile flashFile)
{
this.flashFile = flashFile;
}
public int getUserStatus()
{
return userStatus;
}
public void setUserStatus(int userStatus)
{
this.userStatus = userStatus;
}
public Integer getUserType()
{
return userType;
}
public void setUserType(Integer userType)
{
this.userType = userType;
}
public String getSerialNo()
{
return serialNo;
}
public void setSerialNo(String serialNo)
{
this.serialNo = serialNo;
}
public String getDiskSerial()
{
return diskSerial;
}
public void setDiskSerial(String diskSerial)
{
this.diskSerial = diskSerial;
}
public String getMacAddr()
{
return macAddr;
}
public void setMacAddr(String macAddr)
{
this.macAddr = macAddr;
}
}
相关推荐
标题提到的"Struts2注解开发jar"主要指的是`struts2-convention-plugin`,这是一个Struts2的插件,它的主要作用是支持基于约定优于配置(Convention over Configuration)的开发模式。描述中提到的`struts2-...
Struts2注解登录是Java Web开发中一种简化配置的方式,它允许开发者在代码中直接定义控制器、动作和结果页面的映射,从而避免了传统方式下需要在`struts.xml`配置文件中的繁琐设置。这种做法提高了代码的可读性和可...
本教程将通过一个"Struts2注解Demo"来深入探讨Struts2中的注解用法,帮助开发者更高效地配置和管理Action类。 首先,Struts2的注解允许我们避免传统的XML配置,从而实现更加简洁、直观的编程方式。在`Struts2Demo`...
<constant name="struts.objectFactory" value="struts注解工厂类全限定名,比如:org.apache.struts2.spring.StrutsSpringObjectFactory" /> <package name="default" extends="struts-default"> ...
该例子为struts2注解与拦截器demo,利用myEclipse8.5开发,导入刚才后,自动加载所需struts2的jar包,可以直接运行,是初学struts2注解、拦截器很好的例子,保证10分钟学会2种技术,愿意分享给大家。
### Struts2 注解详解 #### 一、Struts2 Convention 插件介绍与使用 在 Struts2 框架的发展过程中,随着版本的更新和技术的演进,其配置方式也发生了变化。从 Struts2.1 版本开始,官方不再推荐使用 Codebehind ...
### Struts2注解详细说明 #### 一、概述 Struts2框架是Apache软件基金会下的一个开源项目,它提供了一种构建企业级Java Web应用的解决方案。自Struts2.1版本开始,引入了一个重要的插件——Convention Plugin,该...
"struts2注解必须包"指的是Struts2提供的一系列注解,它们对于简化Struts2应用的配置和增强其功能至关重要。 标题中的"struts2-convention-plugin-2.1.8.1.jar"是Struts2的约定插件(Convention Plugin)的一个特定...
"Struts2 注解配置 Action 及拦截器几种不同方式写法对应的路径指向" Struts2 注解配置 Action 及拦截器是 Struts2 框架中的核心组件之一,负责处理用户请求并返回响应结果。下面,我们将通过详细的解释和示例代码...
### Struts2注解配置全面解析 #### 一、引言 随着Struts2框架的不断更新和发展,很多开发者在尝试使用注解方式进行配置时往往会遇到不少难题。尤其是在使用Struts2.1及以上版本时,由于大部分教程和资料仍然基于...
Struts2注解配置是Java Web开发中一种高效、简洁的框架配置方式,它允许开发者在类或方法级别上直接定义Action、结果类型、参数映射等信息,从而避免了传统XML配置文件的繁琐。本资料集合了关于Struts2注解配置的...
Struts2注解配置教程是指导开发者如何使用Java注解替代传统的XML配置来配置Struts2框架的一个教程系列。本文档主要涵盖了Struts2中注解配置的一些基本知识点以及如何通过注解实现零配置。 ### 注解配置之前 在介绍...
### Struts2注解使用详解 #### 一、引言 在Java Web开发领域,Struts2框架以其灵活的架构和强大的功能深受开发者喜爱。传统上,Struts2的配置依赖于XML文件,如`struts.xml`,这在大型项目中可能会导致配置文件...
在这个小实例中,我们将深入探讨如何利用Struts2的注解来构建一个简洁而高效的Web应用。 首先,让我们了解什么是注解。在Java中,注解是一种元数据,它提供了一种安全的方法来向编译器、JVM或框架提供信息。Struts2...
在IT领域,特别是Java开发框架中,Spring和Struts2都是极为重要的技术栈,它们各自通过注解(Annotation)机制提供了强大的功能扩展性和代码简洁性。以下是对Spring和Struts2注解的深入解析和使用指南。 ### Spring...
Struts2注解是Struts2框架中的一种简化配置的方式,允许开发者在代码中直接进行配置,无需在XML文件中进行繁琐的设置。这提高了开发效率,并使得代码更具有可读性。 一、配置web.xml 在Struts2中,web.xml是部署...
Struts2 和 Spring 的整合是企业级 Java Web 开发中常见的技术栈,通过注解配置可以使项目更加简洁、易于维护。Struts2 提供了一种使用注解替代 XML 配置的方式,使得开发者无需编写繁琐的 struts.xml 文件,即可...