账号互踢

master
zhiyong.ning 4 years ago
parent dadc75c1d2
commit f52dec538d
  1. 23
      src/main/java/com/yipin/liuwanr/controller/UserInfoController.java
  2. 2
      src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java
  3. 27
      src/main/java/com/yipin/liuwanr/service/UserInfoService.java

@ -754,4 +754,27 @@ public class UserInfoController {
} }
return resp; return resp;
} }
/**
* 查询token是否存在
*/
@GetMapping("/queryToken")
Response queryToken(@RequestParam String token) {
Response resp = new Response();
if (token==null||token=="") {//前台传来的值是否为空
resp.setStatus(300);
resp.setErrmessage("token为空,查询失败!");
}else {
HashMap<String, Object> ret = userInfoService.queryToken(token);
int status = (int) ret.get("retcode");
if (200 == status) {
resp.setStatus(status);
resp.setMessage(ret.get("retvalue"));
} else {
resp.setStatus(status);
resp.setErrmessage(ret.get("retvalue").toString());
}
}
return resp;
}
} }

@ -157,7 +157,7 @@ public interface UserInfoMapper {
List<UserInfo> loginsGetStaffSchoolInfo(Integer userId,Integer schoolId); List<UserInfo> loginsGetStaffSchoolInfo(Integer userId,Integer schoolId);
//登陆查询学生学校信息/dianzikeda //登陆查询学生学校信息/dianzikeda
@Select("SELECT stu.schoolId,sch.schoolName,stu.userId,stu.studentId from student stu,school sch where stu.userId = #{userId} and stu.schoolId = sch.schoolId and sch.schoolId=#{schoolId} GROUP BY stu.schoolId") @Select("SELECT stu.schoolId,sch.schoolName,stu.userId,stu.studentId from student stu,school sch where stu.userId = #{userId} and stu.schoolId = sch.schoolId and stu.schoolId=#{schoolId}")
List<UserInfoReceiveVo> loginsGetStudentSchoolInfo(Integer userId, Integer schoolId); List<UserInfoReceiveVo> loginsGetStudentSchoolInfo(Integer userId, Integer schoolId);
//查询用户员工组织关系 //查询用户员工组织关系

@ -13,6 +13,7 @@ import com.yipin.liuwanr.mapper.StaffMapper;
import com.yipin.liuwanr.mapper.StudentMapper; import com.yipin.liuwanr.mapper.StudentMapper;
import com.yipin.liuwanr.mapper.UserInfoMapper; import com.yipin.liuwanr.mapper.UserInfoMapper;
import com.yipin.liuwanr.vo.UserInfoReceiveVo; import com.yipin.liuwanr.vo.UserInfoReceiveVo;
import org.apache.poi.ss.formula.functions.T;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -443,13 +444,15 @@ public class UserInfoService {
String token = user.getToken(); String token = user.getToken();
Integer userId = user.getUserId(); Integer userId = user.getUserId();
obj.put("user",user); obj.put("user",user);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
String date = df.format(new Date());// new Date()为获取当前系统时间,也可使用当前时间戳
if(id!=null) { if(id!=null) {
List<Staff> staffList = userInfoMapper.queryStaffAll(id,roleId,schoolId); List<Staff> staffList = userInfoMapper.queryStaffAll(id,roleId,schoolId);
obj.put("staffList",staffList); obj.put("staffList",staffList);
List<Student> studentList = userInfoMapper.queryStudentAll(id,roleId,schoolId); List<Student> studentList = userInfoMapper.queryStudentAll(id,roleId,schoolId);
obj.put("studentList",studentList); obj.put("studentList",studentList);
ValueOperations<String, String> redis = stringRedisTemplate.opsForValue(); ValueOperations<String, String> redis = stringRedisTemplate.opsForValue();
redis.set(token,userId+"", 30 * 60, TimeUnit.SECONDS); redis.set(token,date, 30 * 60, TimeUnit.SECONDS);
resp.put("retcode", 200); resp.put("retcode", 200);
resp.put("retvalue", obj); resp.put("retvalue", obj);
}else { }else {
@ -774,4 +777,26 @@ public class UserInfoService {
} }
return resp; return resp;
} }
//查询token
public HashMap<String, Object>queryToken(String token) {
HashMap<String, Object> resp = new HashMap<String, Object>();
try {
boolean tokens = stringRedisTemplate.hasKey(token);
String data = stringRedisTemplate.opsForValue().get(token);
if (!tokens){
resp.put("retvalue",data);
resp.put("retcode", 200);
}else{
resp.put("retvalue",data);
resp.put("retcode", 200);
}
} catch (RuntimeException e) {
logger.error(e.getMessage());
resp.put("retcode", 500);
resp.put("retvalue", "查询token失败!");
return resp;
}
return resp;
}
} }

Loading…
Cancel
Save