diff --git a/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java b/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java index e46d4a3..37a4672 100644 --- a/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java +++ b/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java @@ -754,4 +754,27 @@ public class UserInfoController { } 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 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; + } } \ No newline at end of file diff --git a/src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java b/src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java index 3530dd6..922e2b0 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java @@ -157,7 +157,7 @@ public interface UserInfoMapper { List loginsGetStaffSchoolInfo(Integer userId,Integer schoolId); //登陆查询学生学校信息/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 loginsGetStudentSchoolInfo(Integer userId, Integer schoolId); //查询用户员工组织关系 diff --git a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java index f486acc..21bc901 100644 --- a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java +++ b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java @@ -13,6 +13,7 @@ import com.yipin.liuwanr.mapper.StaffMapper; import com.yipin.liuwanr.mapper.StudentMapper; import com.yipin.liuwanr.mapper.UserInfoMapper; import com.yipin.liuwanr.vo.UserInfoReceiveVo; +import org.apache.poi.ss.formula.functions.T; import org.jboss.logging.Logger; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -443,13 +444,15 @@ public class UserInfoService { String token = user.getToken(); Integer userId = user.getUserId(); 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) { List staffList = userInfoMapper.queryStaffAll(id,roleId,schoolId); obj.put("staffList",staffList); List studentList = userInfoMapper.queryStudentAll(id,roleId,schoolId); obj.put("studentList",studentList); ValueOperations 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("retvalue", obj); }else { @@ -774,4 +777,26 @@ public class UserInfoService { } return resp; } + + //查询token + public HashMapqueryToken(String token) { + HashMap resp = new HashMap(); + 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; + } }