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;
}
}