package com.fgkj.controller;
|
|
import com.fgkj.util.*;
|
|
import com.fgkj.dto.*;
|
import com.fgkj.mapper.impl.User_ChartMapper;
|
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 io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.Cookie;
|
import javax.servlet.http.HttpSession;
|
import java.net.URLEncoder;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
@RequestMapping("login")
|
@RestController
|
@Api(tags = "login接口")
|
public class LoginController{
|
|
// private User_inf uinf;
|
ServiceModel model = new ServiceModel();
|
//private String user;
|
//private String password;
|
|
@Resource
|
private User_infService service;
|
@Resource
|
private Vip_userService vservice;
|
@Resource
|
private User_ChartMapper userChartMapper;
|
|
//web版登录
|
@PostMapping("login")
|
@ApiOperation(notes = "",value="web版登录")
|
public ServiceModel login(@RequestBody User_inf uinf) {
|
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);
|
}
|
return model;
|
}
|
|
//手机端登录action
|
@PostMapping("mobileLogin")
|
@ApiOperation(notes = "",value="手机端登录action")
|
public ServiceModel MobileLogin(@RequestBody User_inf uinf){
|
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 uinf2 = (User_inf) ActionUtil.getUser();
|
if(uinf!=null){
|
log.setuId(uinf2.getuId());
|
log.setuOprateDay(new Date());
|
log.setuOprateMsg("登录移动系统");
|
log.setuOprateType(UserUtil.LOGIN);
|
log.setuTerminalIp(ActionUtil.getRequest().getRemoteAddr());
|
logservice.add(log);
|
}
|
}
|
return model;
|
}
|
|
//检查超级管理员是否
|
@GetMapping("checkVip")
|
@ApiOperation(notes = "",value="检查超级管理员是否")
|
public ServiceModel checkVip(){
|
Map<String, UserClient> map = (Map) ActionUtil.getApplication().getAttribute("vips");
|
model=vservice.checkVip();
|
|
return model;
|
}
|
|
/**
|
* 判断是否有另一同一账号登陆的用户
|
* @return
|
*/
|
@GetMapping("check")
|
@ApiOperation(notes = "",value="判断是否有另一同一账号登陆的用户")
|
public ServiceModel check(){
|
//System.out.println("开始检查");
|
model=service.checkUser();
|
//当前用户
|
HttpSession session = ActionUtil.getSession();
|
User_inf uinf=(User_inf) session.getAttribute("user");
|
if(model.code == 1){
|
session.invalidate(); //清除当前的session; //清除session
|
}
|
|
return model;
|
}
|
|
/**
|
* 退出登录
|
* @return
|
*/
|
@PutMapping("/userExit")
|
@ApiOperation(notes = "",value="退出登录")
|
public ServiceModel 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 model;
|
}
|
|
/**
|
* 存储当前用户的包机组信息
|
* @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 {
|
List ls = userChartMapper.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 ServiceModel exitVUser(){
|
ActionUtil.getSession().invalidate();
|
return model;
|
}
|
|
/*//通过制定的字符串获取session
|
public ServiceModel getSessionByString(){
|
Object obj = ActionUtil.getSession().getAttribute(json);
|
if(obj != null){
|
result = ActionUtil.tojson(obj);
|
}else{
|
result = "";
|
}
|
return model;
|
}*/
|
|
/**
|
* 初始化数据库连接池
|
* @return
|
*//*
|
public ServiceModel initDBPool(){
|
DBUtil.initPool();
|
return model;
|
}*/
|
|
}
|