package com.fgkj.actions;
|
|
|
import java.net.URLEncoder;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.servlet.http.Cookie;
|
|
import com.fgkj.dao.BaseDAO;
|
import com.fgkj.dao.BaseDAOFactory;
|
import com.fgkj.db.DBUtil;
|
import com.fgkj.db.IDatabaseName;
|
import com.fgkj.dto.ServiceModel;
|
import com.fgkj.dto.User;
|
import com.fgkj.dto.UserClient;
|
import com.fgkj.dto.User_Chart;
|
import com.fgkj.dto.User_inf;
|
import com.fgkj.dto.User_log;
|
import com.fgkj.services.UserService;
|
import com.fgkj.services.User_ChartService;
|
import com.fgkj.services.User_battgroup_baojigroup_battgroupService;
|
import com.fgkj.services.User_infService;
|
import com.fgkj.services.User_logService;
|
import com.fgkj.services.Vip_userService;
|
import com.opensymphony.xwork2.ActionSupport;
|
|
|
public class LoginAction extends ActionSupport{
|
private User_inf uinf;
|
private ServiceModel model;
|
//private String user;
|
//private String password;
|
private String json;
|
private String result;
|
|
private User_infService service=new User_infService();
|
private Vip_userService vservice=new Vip_userService();
|
|
//web版登录
|
public String login() {
|
model=vservice.login(uinf);
|
//System.out.println(model);
|
if(model.getCode()!=1){
|
model=service.login(uinf);
|
if(model.code == 1){
|
User_inf u = (User_inf) ActionUtil.getUser();
|
//System.out.println(u);
|
if(u!=null){
|
//setUserBaoji(u); //存储当前用户的包机组
|
|
recordUserlogin(u); //记录当前用户的登录记录
|
|
setUserLogo(u); //记录当前用户的所属部门的logo
|
}
|
}
|
}
|
if(model.getCode()==1){
|
Cookie c = null;
|
//System.out.println(ActionUtil.DecryptionBase64());
|
if(uinf.getUId() == 1){
|
c = new Cookie("user", ActionUtil.EncryptionBase64(ActionUtil.getGson().toJson(uinf)).toString());
|
}else{
|
c = new Cookie("user", "");
|
}
|
//让Cookie保留30天
|
c.setMaxAge(30*24*60*60);
|
ActionUtil.getResponse().addCookie(c);
|
}
|
result=ActionUtil.tojson(model);
|
return "success";
|
}
|
|
//手机端登录action
|
public String MobileLogin(){
|
System.out.println(uinf);
|
String usnId64=(String) ActionUtil.EncryptionBase64(uinf.getUpassword());
|
uinf.setUpassword(usnId64);
|
//System.out.println(usnId64+" : action");
|
model=service.login(uinf);
|
//System.out.println(model);
|
if(model.code==1){
|
User_logService logservice= new User_logService();
|
User_log log = new User_log();
|
User_inf uinf = (User_inf) ActionUtil.getUser();
|
if(uinf!=null){
|
log.setuId(uinf.getUId());
|
log.setUOprateDay(new Date());
|
log.setuOprateMsg("登录移动系统");
|
log.setUOprateType(UserUtil.LOGIN);
|
log.setuTerminalIp(ActionUtil.getRequest().getRemoteAddr());
|
logservice.add(log);
|
}
|
}
|
//System.out.println(model);
|
result=ActionUtil.tojson(model);
|
//System.out.println(result);
|
return "success";
|
}
|
|
//检查超级管理员是否
|
public String checkVip(){
|
Map<String, UserClient> map = (Map) ActionUtil.getApplication().getAttribute("vips");
|
model=vservice.checkVip();
|
result=ActionUtil.tojson(model);
|
return SUCCESS;
|
}
|
|
/**
|
* 判断是否有另一同一账号登陆的用户
|
* @return
|
*/
|
public String check(){
|
//System.out.println("开始检查");
|
model=service.checkUser();
|
uinf=(User_inf)ActionUtil.getSession().getAttribute("user");
|
if(model.code == 1){
|
ActionUtil.getSession().invalidate(); //清除当前的session; //清除session
|
}
|
result=ActionUtil.tojson(model);
|
return "success";
|
}
|
|
/**
|
* 退出登录
|
* @return
|
*/
|
|
public String exitUser(){
|
//将当前用户从所有的登陆用户中移除
|
Map<String, UserClient> map = (Map) ActionUtil.getApplication().getAttribute("users");
|
if(map!=null && map.size()>0){
|
User_inf user = (User_inf) ActionUtil.getSession().getAttribute("user");
|
if(user!=null){
|
//System.out.println(user);
|
UserClient client = map.get(user.getUName());
|
//System.out.println(client);
|
if(client!=null){
|
map.remove(user.getUName());
|
}
|
User_logService logservice= new User_logService();
|
User_log log = new User_log();
|
log.setuId(user.getUId());
|
log.setUOprateDay(new Date());
|
log.setuOprateMsg("登出系统");
|
log.setUOprateType(UserUtil.LOGOUT);
|
log.setuTerminalIp(ActionUtil.getRequest().getLocalAddr());
|
logservice.add(log);
|
}
|
ActionUtil.getSession().invalidate(); //清除session
|
}
|
|
return "success";
|
}
|
|
/**
|
* 存储当前用户的包机组信息
|
* @param u
|
*/
|
public void setUserBaoji(User_inf u){
|
User_battgroup_baojigroup_battgroupService se = new User_battgroup_baojigroup_battgroupService();
|
try {
|
Object batts = se.serchByCondition(u).getData();
|
//System.out.println(batts.toString());
|
Cookie b = new Cookie("batts",URLEncoder.encode(ActionUtil.tojson(batts),"UTF-8"));
|
b.setMaxAge(30*24*60*60);
|
ActionUtil.getResponse().addCookie(b);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 记录用户的登录记录
|
* @param u
|
*/
|
public void recordUserlogin(User_inf u){
|
try {
|
User_logService logservice= new User_logService();
|
User_log log = new User_log();
|
log.setuId(u.getUId());
|
log.setUOprateDay(new Date());
|
log.setuOprateMsg("登录PC系统");
|
log.setUOprateType(UserUtil.LOGIN);
|
log.setuTerminalIp(ActionUtil.getRequest().getRemoteAddr());
|
logservice.add(log);
|
} catch (Exception e) {
|
System.out.println("记录用户的登录信息出错");
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 查询用户所述的部门 对应的logo
|
*/
|
public void setUserLogo(User_inf u){
|
try {
|
BaseDAO dao = BaseDAOFactory.getBaseDAO(BaseDAO.USER_CHART);
|
List ls = dao.serchByCondition(u);
|
String uc = "whyc";
|
if(ls != null && ls.size()>0){
|
uc = ((User_Chart)ls.get(0)).getChart_file();
|
}
|
Cookie c = new Cookie("user_logo",uc);
|
c.setMaxAge(30*24*60*60);
|
ActionUtil.getResponse().addCookie(c);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 退出登录
|
* @return
|
*/
|
public String exitVUser(){
|
ActionUtil.getSession().invalidate();
|
return SUCCESS;
|
}
|
|
//通过制定的字符串获取session
|
public String getSessionByString(){
|
Object obj = ActionUtil.getSession().getAttribute(json);
|
if(obj != null){
|
result = ActionUtil.tojson(obj);
|
}else{
|
result = "";
|
}
|
return SUCCESS;
|
}
|
|
/**
|
* 初始化数据库连接池
|
* @return
|
*/
|
public String initDBPool(){
|
DBUtil.initPool();
|
return SUCCESS;
|
}
|
|
public String getResult() {
|
return result;
|
}
|
|
public void setResult(String result) {
|
this.result = result;
|
}
|
|
|
public User_inf getUinf() {
|
return uinf;
|
}
|
|
public void setJson(String json) {
|
this.json = json;
|
}
|
|
public void setUinf(User_inf uinf) {
|
this.uinf = uinf;
|
}
|
|
}
|